xref: /aoo41x/main/registry/test/testregcpp.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_registry.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <iostream>
32*cdf0e10cSrcweir #include <stdio.h>
33*cdf0e10cSrcweir #include <string.h>
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include "registry/registry.hxx"
36*cdf0e10cSrcweir #include "registry/reflread.hxx"
37*cdf0e10cSrcweir #include "registry/reflwrit.hxx"
38*cdf0e10cSrcweir #include "regdiagnose.h"
39*cdf0e10cSrcweir #include <rtl/alloc.h>
40*cdf0e10cSrcweir #include <rtl/ustring.hxx>
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir using namespace std;
43*cdf0e10cSrcweir using namespace rtl;
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir void test_coreReflection()
46*cdf0e10cSrcweir {
47*cdf0e10cSrcweir     Registry *myRegistry = new Registry();
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir     RegistryKey rootKey, key1, key2, key3, key4 ,key5, key6, key7, key8;
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir     REG_ENSURE(!myRegistry->create(OUString::createFromAscii("ucrtest.rdb")), "testCoreReflection error 1");
52*cdf0e10cSrcweir     REG_ENSURE(!myRegistry->openRootKey(rootKey), "testCoreReflection error 2");
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir     REG_ENSURE(!rootKey.createKey(OUString::createFromAscii("UCR"), key1), "testCoreReflection error 3");
55*cdf0e10cSrcweir     REG_ENSURE(!key1.createKey(OUString::createFromAscii("ModuleA"), key2), "testCoreReflection error 4");
56*cdf0e10cSrcweir     REG_ENSURE(!key2.createKey(OUString::createFromAscii("StructA"), key3), "testCoreReflection error 5");
57*cdf0e10cSrcweir     REG_ENSURE(!key2.createKey(OUString::createFromAscii("EnumA"), key4), "testCoreReflection error 6");
58*cdf0e10cSrcweir     REG_ENSURE(!key2.createKey(OUString::createFromAscii("XInterfaceA"), key5), "testCoreReflection error 7");
59*cdf0e10cSrcweir     REG_ENSURE(!key2.createKey(OUString::createFromAscii("ExceptionA"), key6), "testCoreReflection error 8");
60*cdf0e10cSrcweir     REG_ENSURE(!key2.createKey(OUString::createFromAscii("ServiceA"), key7), "testCoreReflection error 8a");
61*cdf0e10cSrcweir     REG_ENSURE(!key2.createKey(OUString::createFromAscii("ConstantsA"), key8), "testCoreReflection error 8b");
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir     {
64*cdf0e10cSrcweir         RegistryTypeWriter writer(RT_TYPE_MODULE,
65*cdf0e10cSrcweir                                   OUString::createFromAscii("ModuleA"),
66*cdf0e10cSrcweir                                   OUString(), 11, 0, 0);
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir         RTConstValue aConst;
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir         writer.setDoku(OUString::createFromAscii("Hallo ich bin ein Modul"));
71*cdf0e10cSrcweir         writer.setFileName(OUString::createFromAscii("DummyFile"));
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir         aConst.m_type = RT_TYPE_BOOL;
74*cdf0e10cSrcweir         aConst.m_value.aBool = sal_True;
75*cdf0e10cSrcweir         writer.setFieldData(0, OUString::createFromAscii("aConstBool"),
76*cdf0e10cSrcweir 							OUString::createFromAscii("boolean"),
77*cdf0e10cSrcweir 							OUString::createFromAscii("ich bin ein boolean"),
78*cdf0e10cSrcweir 							OUString::createFromAscii("DummyFile"), RT_ACCESS_CONST, aConst);
79*cdf0e10cSrcweir         aConst.m_type = RT_TYPE_BYTE;
80*cdf0e10cSrcweir         aConst.m_value.aByte = 127;
81*cdf0e10cSrcweir         writer.setFieldData(1, OUString::createFromAscii("aConstByte"),
82*cdf0e10cSrcweir 							OUString::createFromAscii("byte"),
83*cdf0e10cSrcweir 							OUString::createFromAscii("ich bin ein byte"),
84*cdf0e10cSrcweir 							OUString::createFromAscii("DummyFile"),  RT_ACCESS_CONST, aConst);
85*cdf0e10cSrcweir         aConst.m_type = RT_TYPE_INT16;
86*cdf0e10cSrcweir         aConst.m_value.aShort = -10;
87*cdf0e10cSrcweir         writer.setFieldData(2, OUString::createFromAscii("aConstShort"),
88*cdf0e10cSrcweir 							OUString::createFromAscii("short"),
89*cdf0e10cSrcweir 							OUString::createFromAscii("ich bin ein short"),
90*cdf0e10cSrcweir 							OUString::createFromAscii("DummyFile"),  RT_ACCESS_CONST, aConst);
91*cdf0e10cSrcweir         aConst.m_type = RT_TYPE_UINT16;
92*cdf0e10cSrcweir         aConst.m_value.aUShort = 10;
93*cdf0e10cSrcweir         writer.setFieldData(3, OUString::createFromAscii("aConstUShort"),
94*cdf0e10cSrcweir 							OUString::createFromAscii("unsigned short"),
95*cdf0e10cSrcweir 							OUString::createFromAscii("ich bin ein unsigned short"),
96*cdf0e10cSrcweir 							OUString::createFromAscii("DummyFile"), RT_ACCESS_CONST, aConst);
97*cdf0e10cSrcweir         aConst.m_type = RT_TYPE_INT32;
98*cdf0e10cSrcweir         aConst.m_value.aLong = -100000;
99*cdf0e10cSrcweir         writer.setFieldData(4, OUString::createFromAscii("aConstLong"),
100*cdf0e10cSrcweir 							OUString::createFromAscii("long"),
101*cdf0e10cSrcweir 							OUString::createFromAscii("ich bin ein long"),
102*cdf0e10cSrcweir 							OUString::createFromAscii("DummyFile"), RT_ACCESS_CONST, aConst);
103*cdf0e10cSrcweir         aConst.m_type = RT_TYPE_UINT32;
104*cdf0e10cSrcweir         aConst.m_value.aULong = 100000;
105*cdf0e10cSrcweir         writer.setFieldData(5, OUString::createFromAscii("aConstULong"),
106*cdf0e10cSrcweir 							OUString::createFromAscii("unsigned long"),
107*cdf0e10cSrcweir 							OUString::createFromAscii("ich bin ein unsigned long"),
108*cdf0e10cSrcweir 							OUString::createFromAscii("DummyFile"), RT_ACCESS_CONST, aConst);
109*cdf0e10cSrcweir         aConst.m_type = RT_TYPE_INT64;
110*cdf0e10cSrcweir         aConst.m_value.aHyper = -100000000;
111*cdf0e10cSrcweir         writer.setFieldData(6, OUString::createFromAscii("aConstHyper"),
112*cdf0e10cSrcweir 							OUString::createFromAscii("hyper"),
113*cdf0e10cSrcweir 							OUString::createFromAscii("ich bin ein hyper"),
114*cdf0e10cSrcweir 							OUString::createFromAscii("DummyFile"), RT_ACCESS_CONST, aConst);
115*cdf0e10cSrcweir         aConst.m_type = RT_TYPE_UINT64;
116*cdf0e10cSrcweir         aConst.m_value.aUHyper = 100000000;
117*cdf0e10cSrcweir         writer.setFieldData(7, OUString::createFromAscii("aConstULong"),
118*cdf0e10cSrcweir 							OUString::createFromAscii("unsigned long"),
119*cdf0e10cSrcweir 							OUString::createFromAscii("ich bin ein unsigned long"),
120*cdf0e10cSrcweir 							OUString::createFromAscii("DummyFile"), RT_ACCESS_CONST, aConst);
121*cdf0e10cSrcweir         aConst.m_type = RT_TYPE_FLOAT;
122*cdf0e10cSrcweir         aConst.m_value.aFloat = -2e-10f;
123*cdf0e10cSrcweir         writer.setFieldData(8, OUString::createFromAscii("aConstFloat"),
124*cdf0e10cSrcweir 							OUString::createFromAscii("float"),
125*cdf0e10cSrcweir 							OUString::createFromAscii("ich bin ein float"),
126*cdf0e10cSrcweir 							OUString::createFromAscii("DummyFile"), RT_ACCESS_CONST, aConst);
127*cdf0e10cSrcweir         aConst.m_type = RT_TYPE_DOUBLE;
128*cdf0e10cSrcweir         aConst.m_value.aDouble = -2e-100; writer.setFieldData(9, OUString::createFromAscii("aConstDouble"),
129*cdf0e10cSrcweir 															  OUString::createFromAscii("double"),
130*cdf0e10cSrcweir 															  OUString::createFromAscii("ich bin ein double"),
131*cdf0e10cSrcweir 															  OUString::createFromAscii("DummyFile"), RT_ACCESS_CONST, aConst);
132*cdf0e10cSrcweir         aConst.m_type = RT_TYPE_STRING;
133*cdf0e10cSrcweir         OUString tmpStr(OUString::createFromAscii( "dies ist ein unicode string" ));
134*cdf0e10cSrcweir 		aConst.m_value.aString = tmpStr.getStr();
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir 		writer.setFieldData(10, OUString::createFromAscii("aConstString"),
137*cdf0e10cSrcweir 							OUString::createFromAscii("string"),
138*cdf0e10cSrcweir 							OUString::createFromAscii("ich bin ein string"),
139*cdf0e10cSrcweir 							OUString::createFromAscii("DummyFile"), RT_ACCESS_CONST, aConst);
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir         const sal_uInt8* pBlop = writer.getBlop();
142*cdf0e10cSrcweir         sal_uInt32      aBlopSize = writer.getBlopSize();
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir         REG_ENSURE(!key2.setValue(OUString(), RG_VALUETYPE_BINARY, (void*)pBlop, aBlopSize), "testCoreReflection error 9");
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir 		sal_uInt8* readBlop = (sal_uInt8*)rtl_allocateMemory(aBlopSize);
147*cdf0e10cSrcweir 		REG_ENSURE(!key2.getValue(OUString(), (void*)readBlop) , "testCoreReflection error 9a");
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir         RegistryTypeReader reader(readBlop, aBlopSize, sal_True);
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir 		if (reader.isValid())
152*cdf0e10cSrcweir 		{
153*cdf0e10cSrcweir 			REG_ENSURE(reader.getTypeName().equals(OUString::createFromAscii("ModuleA")), "testCoreReflection error 9a2");
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir 			RTConstValue aReadConst = reader.getFieldConstValue(4);
156*cdf0e10cSrcweir 			REG_ENSURE( aReadConst.m_type == RT_TYPE_INT32, "testCoreReflection error 9a3");
157*cdf0e10cSrcweir 			REG_ENSURE( aReadConst.m_value.aLong == -100000, "testCoreReflection error 9a4");
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir 			aReadConst = reader.getFieldConstValue(6);
160*cdf0e10cSrcweir 			REG_ENSURE( aReadConst.m_type == RT_TYPE_INT64, "testCoreReflection error 9a5");
161*cdf0e10cSrcweir 			REG_ENSURE( aReadConst.m_value.aHyper == -100000000, "testCoreReflection error 9a6");
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir 			aReadConst = reader.getFieldConstValue(10);
164*cdf0e10cSrcweir 			OString aConstStr = OUStringToOString(aConst.m_value.aString, RTL_TEXTENCODING_ASCII_US);
165*cdf0e10cSrcweir 			REG_ENSURE(aConstStr.equals("dies ist ein unicode string"), "testCoreReflection error 9b");
166*cdf0e10cSrcweir 		}
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir 	}
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir     {
171*cdf0e10cSrcweir         RegistryTypeWriter writer(RT_TYPE_STRUCT,
172*cdf0e10cSrcweir                                   OUString::createFromAscii("ModuleA/StructA"),
173*cdf0e10cSrcweir                                   OUString(), 3, 0, 0);
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir         writer.setDoku(OUString::createFromAscii("Hallo ich bin eine Struktur"));
176*cdf0e10cSrcweir         writer.setFileName(OUString::createFromAscii("DummyFile"));
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir         writer.setFieldData(0, OUString::createFromAscii("asal_uInt32"),
179*cdf0e10cSrcweir 							OUString::createFromAscii("unsigned long"),
180*cdf0e10cSrcweir 							OUString(), OUString(), RT_ACCESS_READWRITE);
181*cdf0e10cSrcweir         writer.setFieldData(1, OUString::createFromAscii("aXInterface"),
182*cdf0e10cSrcweir 							OUString::createFromAscii("stardiv/uno/XInterface"),
183*cdf0e10cSrcweir 							OUString(), OUString(), RT_ACCESS_READWRITE);
184*cdf0e10cSrcweir         writer.setFieldData(2, OUString::createFromAscii("aSequence"),
185*cdf0e10cSrcweir 							OUString::createFromAscii("[]ModuleA/EnumA"),
186*cdf0e10cSrcweir 							OUString(), OUString(), RT_ACCESS_READWRITE);
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir         const sal_uInt8* pBlop = writer.getBlop();
189*cdf0e10cSrcweir         sal_uInt32      aBlopSize = writer.getBlopSize();
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir         REG_ENSURE(!key3.setValue(OUString(), RG_VALUETYPE_BINARY, (void*)pBlop, aBlopSize), "testCoreReflection error 9a");
192*cdf0e10cSrcweir 	}
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir     {
195*cdf0e10cSrcweir         RegistryTypeWriter writer(RT_TYPE_ENUM,
196*cdf0e10cSrcweir                                   OUString::createFromAscii("ModuleA/EnumA"),
197*cdf0e10cSrcweir                                   OUString(), 2, 0, 0);
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir         RTConstValue aConst;
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir         aConst.m_type = RT_TYPE_UINT32;
202*cdf0e10cSrcweir         aConst.m_value.aULong = 10;
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir         writer.setDoku(OUString::createFromAscii("Hallo ich bin ein Enum"));
205*cdf0e10cSrcweir         writer.setFileName(OUString::createFromAscii("DummyFile"));
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir         writer.setFieldData(0, OUString::createFromAscii("ENUM_VAL_1"),
208*cdf0e10cSrcweir 							OUString(), OUString::createFromAscii("ich bin ein enum value"),
209*cdf0e10cSrcweir 							OUString(), RT_ACCESS_CONST, aConst);
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir         aConst.m_value.aULong = 10;
212*cdf0e10cSrcweir         writer.setFieldData(1, OUString::createFromAscii("ENUM_VAL_2"),
213*cdf0e10cSrcweir 							OUString(), OUString(), OUString(), RT_ACCESS_CONST, aConst);
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir         const sal_uInt8* pBlop = writer.getBlop();
216*cdf0e10cSrcweir         sal_uInt32      aBlopSize = writer.getBlopSize();
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir         REG_ENSURE(!key4.setValue(OUString(), RG_VALUETYPE_BINARY, (void*)pBlop, aBlopSize), "testCoreReflection error 9b");
219*cdf0e10cSrcweir     }
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir     {
222*cdf0e10cSrcweir         RegistryTypeWriter writer(RT_TYPE_INTERFACE,
223*cdf0e10cSrcweir                                   OUString::createFromAscii("ModuleA/XInterfaceA"),
224*cdf0e10cSrcweir                                   OUString::createFromAscii("stardiv/uno/XInterface"),
225*cdf0e10cSrcweir                                   4, 1, 0);
226*cdf0e10cSrcweir         RTConstValue aConst;
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir         RTUik aUik = {1,2,3,4,5};
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir         writer.setUik(aUik);
231*cdf0e10cSrcweir         writer.setDoku(OUString::createFromAscii("Hallo ich bin ein Interface"));
232*cdf0e10cSrcweir         writer.setFileName(OUString::createFromAscii("DummyFile"));
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir         writer.setFieldData(0, OUString::createFromAscii("aString"),
235*cdf0e10cSrcweir 							OUString::createFromAscii("string"), OUString(), OUString(), RT_ACCESS_READWRITE);
236*cdf0e10cSrcweir         writer.setFieldData(1, OUString::createFromAscii("aStruct"),
237*cdf0e10cSrcweir 							OUString::createFromAscii("ModuleA/StructA"),
238*cdf0e10cSrcweir 							OUString(), OUString(), RT_ACCESS_READONLY);
239*cdf0e10cSrcweir         writer.setFieldData(2, OUString::createFromAscii("aEnum"),
240*cdf0e10cSrcweir 							OUString::createFromAscii("ModuleA/EnumA"), OUString(), OUString(), RT_ACCESS_BOUND);
241*cdf0e10cSrcweir         aConst.m_type = RT_TYPE_UINT16;
242*cdf0e10cSrcweir         aConst.m_value.aUShort = 12;
243*cdf0e10cSrcweir         writer.setFieldData(3, OUString::createFromAscii("aConstUShort"),
244*cdf0e10cSrcweir 							OUString::createFromAscii("unsigned short"), OUString(),
245*cdf0e10cSrcweir 							OUString::createFromAscii("DummyFile"), RT_ACCESS_CONST, aConst);
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir         writer.setMethodData(0, OUString::createFromAscii("methodA"),
248*cdf0e10cSrcweir 							 OUString::createFromAscii("double"), RT_MODE_TWOWAY, 2, 1,
249*cdf0e10cSrcweir 							 OUString::createFromAscii("Hallo ich bin die methodA"));
250*cdf0e10cSrcweir         writer.setParamData(0, 0, OUString::createFromAscii("ModuleA/StructA"),
251*cdf0e10cSrcweir 							OUString::createFromAscii("aStruct"), RT_PARAM_IN);
252*cdf0e10cSrcweir         writer.setParamData(0, 1, OUString::createFromAscii("unsigned short"),
253*cdf0e10cSrcweir 							OUString::createFromAscii("aShort"), RT_PARAM_INOUT);
254*cdf0e10cSrcweir         writer.setExcData(0, 0, OUString::createFromAscii("ModuleA/ExceptionA"));
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir         const sal_uInt8* pBlop = writer.getBlop();
257*cdf0e10cSrcweir         sal_uInt32      aBlopSize = writer.getBlopSize();
258*cdf0e10cSrcweir 
259*cdf0e10cSrcweir         REG_ENSURE(!key5.setValue(OUString(), RG_VALUETYPE_BINARY, (void*)pBlop, aBlopSize), "testCoreReflection error 9c");
260*cdf0e10cSrcweir 
261*cdf0e10cSrcweir 		sal_uInt8* readBlop = (sal_uInt8*)rtl_allocateMemory(aBlopSize);
262*cdf0e10cSrcweir 		REG_ENSURE(!key5.getValue(OUString(), (void*)readBlop) , "testCoreReflection error 9c1");
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir         RegistryTypeReader reader(readBlop, aBlopSize, sal_True);
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir 		if (reader.isValid())
267*cdf0e10cSrcweir 		{
268*cdf0e10cSrcweir 			REG_ENSURE(reader.getTypeName().equals(OUString::createFromAscii("ModuleA/XInterfaceA")), "testCoreReflection error 9c2");
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir 			RTUik retUik;
271*cdf0e10cSrcweir 			reader.getUik(retUik);
272*cdf0e10cSrcweir 			REG_ENSURE(retUik.m_Data1 = 1, "testCoreReflection error 9c3");
273*cdf0e10cSrcweir 			REG_ENSURE(retUik.m_Data2 = 2, "testCoreReflection error 9c4");
274*cdf0e10cSrcweir 			REG_ENSURE(retUik.m_Data3 = 3, "testCoreReflection error 9c5");
275*cdf0e10cSrcweir 			REG_ENSURE(retUik.m_Data4 = 4, "testCoreReflection error 9c6");
276*cdf0e10cSrcweir 			REG_ENSURE(retUik.m_Data5 = 5, "testCoreReflection error 9c7");
277*cdf0e10cSrcweir 		}
278*cdf0e10cSrcweir 
279*cdf0e10cSrcweir     }
280*cdf0e10cSrcweir 
281*cdf0e10cSrcweir     {
282*cdf0e10cSrcweir         RegistryTypeWriter writer(RT_TYPE_EXCEPTION,
283*cdf0e10cSrcweir                                   OUString::createFromAscii("ModuleA/ExceptionA"),
284*cdf0e10cSrcweir                                   OUString(), 1, 0, 0);
285*cdf0e10cSrcweir 
286*cdf0e10cSrcweir         writer.setDoku(OUString::createFromAscii("Hallo ich bin eine Exception"));
287*cdf0e10cSrcweir 
288*cdf0e10cSrcweir         writer.setFieldData(0, OUString::createFromAscii("aSource"),
289*cdf0e10cSrcweir 							OUString::createFromAscii("stardiv/uno/XInterface"),
290*cdf0e10cSrcweir 							OUString::createFromAscii("ich bin ein interface member"),
291*cdf0e10cSrcweir 							OUString(), RT_ACCESS_READWRITE);
292*cdf0e10cSrcweir 
293*cdf0e10cSrcweir         const sal_uInt8* pBlop = writer.getBlop();
294*cdf0e10cSrcweir         sal_uInt32      aBlopSize = writer.getBlopSize();
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir         REG_ENSURE(!key6.setValue(OUString(), RG_VALUETYPE_BINARY, (void*)pBlop, aBlopSize), "testCoreReflection error 9d");
297*cdf0e10cSrcweir     }
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir     {
300*cdf0e10cSrcweir         RegistryTypeWriter writer(RT_TYPE_SERVICE,
301*cdf0e10cSrcweir                                   OUString::createFromAscii("ModuleA/ServiceA"),
302*cdf0e10cSrcweir                                   OUString(), 1, 0, 4);
303*cdf0e10cSrcweir 
304*cdf0e10cSrcweir         writer.setDoku(OUString::createFromAscii("Hallo ich bin ein Service"));
305*cdf0e10cSrcweir         writer.setFileName(OUString::createFromAscii("DummyFile"));
306*cdf0e10cSrcweir 
307*cdf0e10cSrcweir         writer.setFieldData(0, OUString::createFromAscii("aProperty"),
308*cdf0e10cSrcweir 							OUString::createFromAscii("stardiv/uno/XInterface"),
309*cdf0e10cSrcweir 							OUString::createFromAscii("ich bin eine property"),
310*cdf0e10cSrcweir 							OUString(), RT_ACCESS_READWRITE);
311*cdf0e10cSrcweir 
312*cdf0e10cSrcweir         writer.setReferenceData(0, OUString::createFromAscii("ModuleA/XInterfaceA"), RT_REF_SUPPORTS,
313*cdf0e10cSrcweir                                 OUString::createFromAscii("Hallo ich eine Reference auf ein supported interface"),
314*cdf0e10cSrcweir 								RT_ACCESS_OPTIONAL);
315*cdf0e10cSrcweir         writer.setReferenceData(1, OUString::createFromAscii("ModuleA/XInterfaceA"), RT_REF_OBSERVES,
316*cdf0e10cSrcweir                                 OUString::createFromAscii("Hallo ich eine Reference auf ein observed interface"));
317*cdf0e10cSrcweir         writer.setReferenceData(2, OUString::createFromAscii("ModuleA/ServiceB"), RT_REF_EXPORTS,
318*cdf0e10cSrcweir                                 OUString::createFromAscii("Hallo ich eine Reference auf einen exported service"));
319*cdf0e10cSrcweir         writer.setReferenceData(3, OUString::createFromAscii("ModuleA/ServiceB"), RT_REF_NEEDS,
320*cdf0e10cSrcweir                                 OUString::createFromAscii("Hallo ich eine Reference auf einen needed service"));
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir         const sal_uInt8* pBlop = writer.getBlop();
323*cdf0e10cSrcweir         sal_uInt32      aBlopSize = writer.getBlopSize();
324*cdf0e10cSrcweir 
325*cdf0e10cSrcweir         REG_ENSURE(!key7.setValue(OUString(), RG_VALUETYPE_BINARY, (void*)pBlop, aBlopSize), "testCoreReflection error 9e");
326*cdf0e10cSrcweir 		sal_uInt8* readBlop = (sal_uInt8*)rtl_allocateMemory(aBlopSize);
327*cdf0e10cSrcweir 		REG_ENSURE(!key7.getValue(OUString(), (void*)readBlop) , "testCoreReflection error 9e2");
328*cdf0e10cSrcweir 
329*cdf0e10cSrcweir         RegistryTypeReader reader(readBlop, aBlopSize, sal_True);
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir 		if (reader.isValid())
332*cdf0e10cSrcweir 		{
333*cdf0e10cSrcweir 			REG_ENSURE(reader.getTypeName().equals(OUString::createFromAscii("ModuleA/ServiceA")), "testCoreReflection error 9e3");
334*cdf0e10cSrcweir 
335*cdf0e10cSrcweir 			sal_uInt32 referenceCount = reader.getReferenceCount();
336*cdf0e10cSrcweir 			REG_ENSURE( referenceCount == 4, "testCoreReflection error 9e4");
337*cdf0e10cSrcweir 
338*cdf0e10cSrcweir 			OUString refName = reader.getReferenceName(0);
339*cdf0e10cSrcweir 			REG_ENSURE(refName.equals(OUString::createFromAscii("ModuleA/XInterfaceA")), "testCoreReflection error 9e5");
340*cdf0e10cSrcweir 		}
341*cdf0e10cSrcweir     }
342*cdf0e10cSrcweir 
343*cdf0e10cSrcweir     {
344*cdf0e10cSrcweir         RegistryTypeWriter writer(RT_TYPE_CONSTANTS,
345*cdf0e10cSrcweir                                   OUString::createFromAscii("ModuleA/ConstansA"),
346*cdf0e10cSrcweir                                   OUString(), 3, 0, 0);
347*cdf0e10cSrcweir 
348*cdf0e10cSrcweir         RTConstValue aConst;
349*cdf0e10cSrcweir 
350*cdf0e10cSrcweir         writer.setDoku(OUString::createFromAscii("Hallo ich bin eine Constants Group"));
351*cdf0e10cSrcweir         writer.setFileName(OUString::createFromAscii("DummyFile"));
352*cdf0e10cSrcweir 
353*cdf0e10cSrcweir         aConst.m_type = RT_TYPE_BOOL;
354*cdf0e10cSrcweir         aConst.m_value.aBool = sal_True;
355*cdf0e10cSrcweir         writer.setFieldData(0, OUString::createFromAscii("ConstantsA_aConstBool"),
356*cdf0e10cSrcweir 							OUString::createFromAscii("boolean"),
357*cdf0e10cSrcweir 							OUString::createFromAscii("ich bin ein boolean"),
358*cdf0e10cSrcweir 							OUString::createFromAscii("DummyFile"), RT_ACCESS_CONST, aConst);
359*cdf0e10cSrcweir         aConst.m_type = RT_TYPE_BYTE;
360*cdf0e10cSrcweir         aConst.m_value.aByte = 127;
361*cdf0e10cSrcweir         writer.setFieldData(1, OUString::createFromAscii("ConstantsA_aConstByte"),
362*cdf0e10cSrcweir 							OUString::createFromAscii("byte"),
363*cdf0e10cSrcweir 							OUString::createFromAscii("ich bin ein byte"),
364*cdf0e10cSrcweir 							OUString::createFromAscii("DummyFile"),  RT_ACCESS_CONST, aConst);
365*cdf0e10cSrcweir         aConst.m_type = RT_TYPE_INT16;
366*cdf0e10cSrcweir         aConst.m_value.aShort = -10;
367*cdf0e10cSrcweir         writer.setFieldData(2, OUString::createFromAscii("ConstantsA_aConstShort"),
368*cdf0e10cSrcweir 							OUString::createFromAscii("short"),
369*cdf0e10cSrcweir 							OUString::createFromAscii("ich bin ein short"),
370*cdf0e10cSrcweir 							OUString::createFromAscii("DummyFile"),  RT_ACCESS_CONST, aConst);
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir         const sal_uInt8* pBlop = writer.getBlop();
373*cdf0e10cSrcweir         sal_uInt32      aBlopSize = writer.getBlopSize();
374*cdf0e10cSrcweir 
375*cdf0e10cSrcweir         REG_ENSURE(!key8.setValue(OUString(), RG_VALUETYPE_BINARY, (void*)pBlop, aBlopSize), "testCoreReflection error 9f");
376*cdf0e10cSrcweir     }
377*cdf0e10cSrcweir 
378*cdf0e10cSrcweir //  REG_ENSURE(!myRegistry->destroy(NULL), "testCoreReflection error 10");
379*cdf0e10cSrcweir     delete myRegistry;
380*cdf0e10cSrcweir 
381*cdf0e10cSrcweir     cout << "test_coreReflection() Ok!\n";
382*cdf0e10cSrcweir }
383*cdf0e10cSrcweir 
384*cdf0e10cSrcweir void test_registry_CppApi()
385*cdf0e10cSrcweir {
386*cdf0e10cSrcweir     Registry *myRegistry = new Registry();
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir     RegistryKey rootKey, key1, key2, key3, key4 ,key5, key6, key7, key8, key9;
389*cdf0e10cSrcweir 
390*cdf0e10cSrcweir     REG_ENSURE(!myRegistry->create(OUString::createFromAscii("test.rdb")), "test_registry_CppApi error 1");
391*cdf0e10cSrcweir     REG_ENSURE(!myRegistry->openRootKey(rootKey), "test_registry_CppApi error 2");
392*cdf0e10cSrcweir 
393*cdf0e10cSrcweir     REG_ENSURE(!rootKey.createKey(OUString::createFromAscii("myFirstKey"), key1), "test_registry_CppApi error 3");
394*cdf0e10cSrcweir     REG_ENSURE(!rootKey.createKey(OUString::createFromAscii("mySecondKey"), key2), "test_registry_CppApi error 4");
395*cdf0e10cSrcweir     REG_ENSURE(!key1.createKey(OUString::createFromAscii("X"), key3), "test_registry_CppApi error 5");
396*cdf0e10cSrcweir     REG_ENSURE(!key1.createKey(OUString::createFromAscii("mySecondSubKey"), key4), "test_registry_CppApi error 6");
397*cdf0e10cSrcweir     REG_ENSURE(!rootKey.createKey(OUString::createFromAscii("myThirdKey"), key5), "test_registry_CppApi error 6a");
398*cdf0e10cSrcweir 
399*cdf0e10cSrcweir     REG_ENSURE(!key5.createKey(OUString::createFromAscii("1"), key4), "test_registry_CppApi error 6b");
400*cdf0e10cSrcweir     REG_ENSURE(!key4.createKey(OUString::createFromAscii("2"), key3), "test_registry_CppApi error 6c");
401*cdf0e10cSrcweir     REG_ENSURE(!key5.openKey(OUString::createFromAscii("1"), key4), "test_registry_CppApi error 6d");
402*cdf0e10cSrcweir     REG_ENSURE(!rootKey.openKey(OUString::createFromAscii("/myThirdKey/1"), key4), "test_registry_CppApi error 6e");
403*cdf0e10cSrcweir     REG_ENSURE(key4.getName().equals(OUString::createFromAscii("/myThirdKey/1")), "test_registry_CppApi error 6f");
404*cdf0e10cSrcweir 
405*cdf0e10cSrcweir     REG_ENSURE(!rootKey.createKey(OUString::createFromAscii("myFourthKey"), key6), "test_registry_CppApi error 7");
406*cdf0e10cSrcweir     REG_ENSURE(!rootKey.createKey(OUString::createFromAscii("myFifthKey"), key6), "test_registry_CppApi error 7a");
407*cdf0e10cSrcweir     REG_ENSURE(!rootKey.createKey(OUString::createFromAscii("mySixthKey"), key6), "test_registry_CppApi error 7b");
408*cdf0e10cSrcweir 
409*cdf0e10cSrcweir     // Link Test
410*cdf0e10cSrcweir     //
411*cdf0e10cSrcweir 
412*cdf0e10cSrcweir     REG_ENSURE(!rootKey.createKey(OUString::createFromAscii("/myFourthKey/X"), key7), "test_registry_CppApi error 7c)");;
413*cdf0e10cSrcweir     REG_ENSURE(!key6.createLink(OUString::createFromAscii("myFirstLink"), OUString::createFromAscii("/myFourthKey/X")), "test_registry_CppApi error 7d");
414*cdf0e10cSrcweir     REG_ENSURE(!key6.createKey(OUString::createFromAscii("mySixthSubKey"), key7), "test_registry_CppApi error 7e");
415*cdf0e10cSrcweir 
416*cdf0e10cSrcweir     OUString linkTarget;
417*cdf0e10cSrcweir     REG_ENSURE(!key6.getLinkTarget(OUString::createFromAscii("myFirstLink"), linkTarget), "test_registry_CppApi error 7f");
418*cdf0e10cSrcweir     REG_ENSURE(linkTarget.equals(OUString::createFromAscii("/myFourthKey/X")), "test_registry_CppApi error 7g");
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir     RegistryKeyNames* pSubKeyNames = new RegistryKeyNames();
421*cdf0e10cSrcweir     sal_uInt32           nSubKeys=0;
422*cdf0e10cSrcweir 
423*cdf0e10cSrcweir     REG_ENSURE(!rootKey.getKeyNames(OUString::createFromAscii("mySixthKey"), *pSubKeyNames), "test_registry_CppApi error 7h)");
424*cdf0e10cSrcweir     REG_ENSURE(pSubKeyNames->getLength() == 2, "test_registry_CppApi error 7i)");
425*cdf0e10cSrcweir 
426*cdf0e10cSrcweir     for (sal_uInt32 i=0; i < pSubKeyNames->getLength(); i++)
427*cdf0e10cSrcweir     {
428*cdf0e10cSrcweir         if (pSubKeyNames->getElement(i).equals(OUString::createFromAscii("/mySixthKey/myFirstLink")))
429*cdf0e10cSrcweir         {
430*cdf0e10cSrcweir             RegKeyType keyType;
431*cdf0e10cSrcweir             REG_ENSURE(!rootKey.getKeyType(pSubKeyNames->getElement(i), &keyType), "test_registry_CppApi error 7j");
432*cdf0e10cSrcweir             REG_ENSURE(keyType == RG_LINKTYPE, "test_registry_CppApi error 7k");
433*cdf0e10cSrcweir         }
434*cdf0e10cSrcweir     }
435*cdf0e10cSrcweir 
436*cdf0e10cSrcweir     REG_ENSURE(!key7.closeKey(), "test_registry_CppApi error 7k1");
437*cdf0e10cSrcweir     delete pSubKeyNames;
438*cdf0e10cSrcweir 
439*cdf0e10cSrcweir     REG_ENSURE(!rootKey.openKey(OUString::createFromAscii("/mySixthKey/myFirstLink"), key6), "test_registry_CppApi error 7l");
440*cdf0e10cSrcweir //    REG_ENSURE(key6.getName().equals(OUString::createFromAscii("/myFourthKey/X")), "test_registry_CppApi error 7m");
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir     REG_ENSURE(!rootKey.openKey(OUString::createFromAscii("myFifthKey"), key6), "test_registry_CppApi error 7m1");
443*cdf0e10cSrcweir     REG_ENSURE(!key6.createLink(OUString::createFromAscii("mySecondLink"),
444*cdf0e10cSrcweir 								 OUString::createFromAscii("/mySixthKey/myFirstLink")), "test_registry_CppApi error 7m2");
445*cdf0e10cSrcweir 
446*cdf0e10cSrcweir     REG_ENSURE(!rootKey.openKey(OUString::createFromAscii("/myFifthKey/mySecondLink"), key6), "test_registry_CppApi error 7m3");
447*cdf0e10cSrcweir //    REG_ENSURE(key6.getName().equals(OUString::createFromAscii("/myFourthKey/X")), "test_registry_CppApi error 7m4");
448*cdf0e10cSrcweir 
449*cdf0e10cSrcweir     REG_ENSURE(!rootKey.createKey(OUString::createFromAscii("/myFifthKey/mySecondLink/myFirstLinkSubKey"), key7), "test_registry_CppApi error 7m5");
450*cdf0e10cSrcweir     REG_ENSURE(key7.getName().equals(OUString::createFromAscii("/myFourthKey/X/myFirstLinkSubKey")), "test_registry_CppApi error 7m6");
451*cdf0e10cSrcweir 
452*cdf0e10cSrcweir     REG_ENSURE(!key7.createLink(OUString::createFromAscii("myThirdLink"), OUString::createFromAscii("/myFifthKey/mySecondLink")), "test_registry_CppApi error 7m7");
453*cdf0e10cSrcweir     REG_ENSURE(!rootKey.openKey(OUString::createFromAscii("/myFourthKey/X/myFirstLinkSubKey/myThirdLink"), key7), "test_registry_CppApi error 7m8");
454*cdf0e10cSrcweir //    REG_ENSURE(!key7.openKey(OUString::createFromAscii("/myFirstLinkSubKey/myThirdLink/myFirstLinkSubKey/myThirdLink"), key6), "test_registry_CppApi error 7m9");
455*cdf0e10cSrcweir //    REG_ENSURE(key7.getName().equals(OUString::createFromAscii("/myFourthKey/X")), "test_registry_CppApi error 7m10");
456*cdf0e10cSrcweir     REG_ENSURE(!key7.closeKey(), "test_registry_CppApi error 7m11");
457*cdf0e10cSrcweir 
458*cdf0e10cSrcweir     REG_ENSURE(!rootKey.deleteLink(OUString::createFromAscii("/myFifthKey/mySecondLink")), "test_registry_CppApi error 7m12");
459*cdf0e10cSrcweir 
460*cdf0e10cSrcweir     REG_ENSURE(!rootKey.createLink(OUString::createFromAscii("/myFifthKey/mySecondLink"),
461*cdf0e10cSrcweir                                     OUString::createFromAscii("/myFourthKey/X/myFirstLinkSubKey/myThirdLink")),
462*cdf0e10cSrcweir                                     "test_registry_CppApi error 7m13");
463*cdf0e10cSrcweir 
464*cdf0e10cSrcweir //    REG_ENSURE(rootKey.openKey(OUString::createFromAscii("/myFourthKey/X/myFirstLinkSubKey/myThirdLink"), key7) == REG_DETECT_RECURSION,
465*cdf0e10cSrcweir //                "test_registry_CppApi error 7m14");
466*cdf0e10cSrcweir 
467*cdf0e10cSrcweir //    REG_ENSURE(key7.closeKey() == REG_INVALID_KEY, "test_registry_CppApi error 7m11");
468*cdf0e10cSrcweir 
469*cdf0e10cSrcweir     RegistryKeyNames subKeyNames;
470*cdf0e10cSrcweir     nSubKeys=0;
471*cdf0e10cSrcweir 
472*cdf0e10cSrcweir     REG_ENSURE(!rootKey.getKeyNames(OUString::createFromAscii("mySixthKey"), subKeyNames), "test_registry_CppApi error 7n");
473*cdf0e10cSrcweir 
474*cdf0e10cSrcweir     nSubKeys = subKeyNames.getLength();
475*cdf0e10cSrcweir     REG_ENSURE(nSubKeys == 2, "test_registry_CppApi error 7n1");
476*cdf0e10cSrcweir     REG_ENSURE(subKeyNames.getElement(0).equals(OUString::createFromAscii("/mySixthKey/myFirstLink")), "test_registry_CppApi error 7p1)");
477*cdf0e10cSrcweir     REG_ENSURE(subKeyNames.getElement(1).equals(OUString::createFromAscii("/mySixthKey/mySixthSubKey")), "test_registry_CppApi error 7p2");
478*cdf0e10cSrcweir 
479*cdf0e10cSrcweir 
480*cdf0e10cSrcweir     RegistryKeyArray subKeys;
481*cdf0e10cSrcweir     nSubKeys=0;
482*cdf0e10cSrcweir 
483*cdf0e10cSrcweir     REG_ENSURE(!rootKey.openSubKeys(OUString::createFromAscii("myFirstKey"), subKeys), "test_registry_CppApi error 7o");
484*cdf0e10cSrcweir 
485*cdf0e10cSrcweir     nSubKeys = subKeys.getLength();
486*cdf0e10cSrcweir     REG_ENSURE(nSubKeys == 2, "test_registry_CppApi error 7o1");
487*cdf0e10cSrcweir     REG_ENSURE(subKeys.getElement(0).getName().equals(OUString::createFromAscii("/myFirstKey/mySecondSubKey")), "test_registry_CppApi error 7p1)");
488*cdf0e10cSrcweir     REG_ENSURE(subKeys.getElement(1).getName().equals(OUString::createFromAscii("/myFirstKey/X")), "test_registry_CppApi error 7p2");
489*cdf0e10cSrcweir 
490*cdf0e10cSrcweir     REG_ENSURE(!rootKey.closeSubKeys(subKeys), "test_registry_CppApi error 7q)");
491*cdf0e10cSrcweir 
492*cdf0e10cSrcweir 
493*cdf0e10cSrcweir     REG_ENSURE(!rootKey.createKey(OUString::createFromAscii("/TEST"), key8), "test_registry_CppApi error 8");
494*cdf0e10cSrcweir     REG_ENSURE(!rootKey.createKey(OUString::createFromAscii("/TEST/Child1"), key8), "test_registry_CppApi error 8a");
495*cdf0e10cSrcweir     REG_ENSURE(!rootKey.createKey(OUString::createFromAscii("/TEST/Child2"), key8), "test_registry_CppApi error 8a1");
496*cdf0e10cSrcweir     REG_ENSURE(!rootKey.openKey(OUString::createFromAscii("/TEST"), key9), "test_registry_CppApi error 8b");
497*cdf0e10cSrcweir     REG_ENSURE(!key8.closeKey() && !key9.closeKey(),  "test_registry_CppApi error 8b1");
498*cdf0e10cSrcweir     REG_ENSURE(!rootKey.openKey(OUString::createFromAscii("/TEST"), key8), "test_registry_CppApi error 8b");
499*cdf0e10cSrcweir     REG_ENSURE(!key8.closeKey(),  "test_registry_CppApi error 8c");
500*cdf0e10cSrcweir     REG_ENSURE(!rootKey.openKey(OUString::createFromAscii("TEST"), key8), "test_registry_CppApi error 8c");
501*cdf0e10cSrcweir     REG_ENSURE(!key8.closeKey(),  "test_registry_CppApi error 8d");
502*cdf0e10cSrcweir 
503*cdf0e10cSrcweir 
504*cdf0e10cSrcweir     sal_Char* Value=(sal_Char*)"Mein erster Value";
505*cdf0e10cSrcweir     REG_ENSURE(!rootKey.setValue(OUString::createFromAscii("mySecondKey"), RG_VALUETYPE_STRING, Value, 18), "test_registry_CppApi error 9");
506*cdf0e10cSrcweir 
507*cdf0e10cSrcweir     RegValueType    valueType;
508*cdf0e10cSrcweir     sal_uInt32          valueSize;
509*cdf0e10cSrcweir     sal_Char*           readValue;
510*cdf0e10cSrcweir     REG_ENSURE(!rootKey.getValueInfo(OUString::createFromAscii("mySecondKey"), &valueType, &valueSize), "test_registry_CppApi error 9a");
511*cdf0e10cSrcweir 
512*cdf0e10cSrcweir     readValue = (sal_Char*)rtl_allocateMemory(valueSize);
513*cdf0e10cSrcweir     REG_ENSURE(!key2.getValue(OUString(), readValue), "test_registry_CppApi error 10");
514*cdf0e10cSrcweir 
515*cdf0e10cSrcweir     REG_ENSURE(valueType == RG_VALUETYPE_STRING, "test_registry_CppApi error 11");
516*cdf0e10cSrcweir     REG_ENSURE(valueSize == 18, "test_registry_CppApi error 12");
517*cdf0e10cSrcweir     REG_ENSURE(strcmp(readValue, Value) == 0, "test_registry_CppApi error 13");
518*cdf0e10cSrcweir     rtl_freeMemory(readValue);
519*cdf0e10cSrcweir 
520*cdf0e10cSrcweir     const sal_Char* pList[3];
521*cdf0e10cSrcweir     const sal_Char* n1= "Hallo";
522*cdf0e10cSrcweir     const sal_Char* n2= "jetzt komm";
523*cdf0e10cSrcweir     const sal_Char* n3= "ich";
524*cdf0e10cSrcweir 
525*cdf0e10cSrcweir     pList[0]=n1;
526*cdf0e10cSrcweir     pList[1]=n2;
527*cdf0e10cSrcweir     pList[2]=n3;
528*cdf0e10cSrcweir 
529*cdf0e10cSrcweir     REG_ENSURE(!rootKey.setStringListValue(OUString::createFromAscii("myFourthKey"), (sal_Char**)pList, 3), "test_registry_CppApi error 13a");
530*cdf0e10cSrcweir 
531*cdf0e10cSrcweir     RegistryValueList<sal_Char*> valueList;
532*cdf0e10cSrcweir     REG_ENSURE(!rootKey.getStringListValue(OUString::createFromAscii("myFourthKey"), valueList), "test_registry_CppApi error 13b");
533*cdf0e10cSrcweir 
534*cdf0e10cSrcweir     REG_ENSURE(strcmp(n1, valueList.getElement(0)) == 0, "test_registry_CppApi error 13c");
535*cdf0e10cSrcweir     REG_ENSURE(strcmp(n2, valueList.getElement(1)) == 0, "test_registry_CppApi error 13d");
536*cdf0e10cSrcweir     REG_ENSURE(strcmp(n3, valueList.getElement(2)) == 0, "test_registry_CppApi error 13e");
537*cdf0e10cSrcweir 
538*cdf0e10cSrcweir     REG_ENSURE(!rootKey.getValueInfo(OUString::createFromAscii("myFourthKey"), &valueType, &valueSize), "test_registry_CppApi error 13e1");
539*cdf0e10cSrcweir     REG_ENSURE(valueType == RG_VALUETYPE_STRINGLIST, "test_registry_CppApi error 13e2");
540*cdf0e10cSrcweir     REG_ENSURE(valueSize == 3, "test_registry_CppApi error 13e3");
541*cdf0e10cSrcweir 
542*cdf0e10cSrcweir     sal_Int32 pLong[3];
543*cdf0e10cSrcweir     pLong[0] = 123;
544*cdf0e10cSrcweir     pLong[1] = 456;
545*cdf0e10cSrcweir     pLong[2] = 789;
546*cdf0e10cSrcweir 
547*cdf0e10cSrcweir     REG_ENSURE(!rootKey.setLongListValue(OUString::createFromAscii("myFifthKey"), pLong, 3), "test_registry_CppApi error 13f");
548*cdf0e10cSrcweir 
549*cdf0e10cSrcweir     RegistryValueList<sal_Int32> longList;
550*cdf0e10cSrcweir     REG_ENSURE(!rootKey.getLongListValue(OUString::createFromAscii("myFifthKey"), longList), "test_registry_CppApi error 13g");
551*cdf0e10cSrcweir 
552*cdf0e10cSrcweir     REG_ENSURE(pLong[0] == longList.getElement(0), "test_registry_CppApi error 13h");
553*cdf0e10cSrcweir     REG_ENSURE(pLong[1] == longList.getElement(1), "test_registry_CppApi error 13i");
554*cdf0e10cSrcweir     REG_ENSURE(pLong[2] == longList.getElement(2), "test_registry_CppApi error 13j");
555*cdf0e10cSrcweir 
556*cdf0e10cSrcweir 
557*cdf0e10cSrcweir     OUString sWTestValue(OUString::createFromAscii( "Mein erster Unicode Value" ));
558*cdf0e10cSrcweir 	const sal_Unicode* wTestValue= sWTestValue.getStr();
559*cdf0e10cSrcweir     REG_ENSURE(!rootKey.setValue(OUString::createFromAscii("mySixthKey"), RG_VALUETYPE_UNICODE, (void*)wTestValue,
560*cdf0e10cSrcweir                 (rtl_ustr_getLength(wTestValue)+1)*sizeof(sal_Unicode)), "test_registry_CppApi error 13j1");
561*cdf0e10cSrcweir 
562*cdf0e10cSrcweir     REG_ENSURE(!rootKey.getValueInfo(OUString::createFromAscii("mySixthKey"), &valueType, &valueSize), "test_registry_CppApi error 13j2");
563*cdf0e10cSrcweir 	sal_Unicode* pTmpValue = (sal_Unicode*)rtl_allocateMemory(valueSize);
564*cdf0e10cSrcweir     REG_ENSURE(!rootKey.getValue(OUString::createFromAscii("mySixthKey"), pTmpValue), "test_registry_CppApi error 13j3");
565*cdf0e10cSrcweir     REG_ENSURE(rtl_ustr_getLength(wTestValue) == rtl_ustr_getLength(pTmpValue), "test_registry_CppApi error 13j4");
566*cdf0e10cSrcweir     REG_ENSURE(rtl_ustr_compare(wTestValue, pTmpValue) == 0, "test_registry_CppApi error 13j4");
567*cdf0e10cSrcweir 
568*cdf0e10cSrcweir     const sal_Unicode* pUnicode[3];
569*cdf0e10cSrcweir     OUString w1(OUString::createFromAscii( "Hallo" ));
570*cdf0e10cSrcweir     OUString w2(OUString::createFromAscii( "jetzt komm" ));
571*cdf0e10cSrcweir     OUString w3(OUString::createFromAscii( "ich als unicode" ));
572*cdf0e10cSrcweir 
573*cdf0e10cSrcweir     pUnicode[0]=w1.getStr();
574*cdf0e10cSrcweir     pUnicode[1]=w2.getStr();
575*cdf0e10cSrcweir     pUnicode[2]=w3.getStr();
576*cdf0e10cSrcweir 
577*cdf0e10cSrcweir 	REG_ENSURE(!rootKey.setUnicodeListValue(OUString::createFromAscii("mySixthKey"), (sal_Unicode**)pUnicode, 3), "test_registry_CppApi error 13k");
578*cdf0e10cSrcweir 
579*cdf0e10cSrcweir     RegistryValueList<sal_Unicode*> unicodeList;
580*cdf0e10cSrcweir     REG_ENSURE(!rootKey.getUnicodeListValue(OUString::createFromAscii("mySixthKey"), unicodeList), "test_registry_CppApi error 13l");
581*cdf0e10cSrcweir 
582*cdf0e10cSrcweir     REG_ENSURE(rtl_ustr_compare(w1, unicodeList.getElement(0)) == 0, "test_registry_CppApi error 13m");
583*cdf0e10cSrcweir     REG_ENSURE(rtl_ustr_compare(w2, unicodeList.getElement(1)) == 0, "test_registry_CppApi error 13n");
584*cdf0e10cSrcweir     REG_ENSURE(rtl_ustr_compare(w3, unicodeList.getElement(2)) == 0, "test_registry_CppApi error 13o");
585*cdf0e10cSrcweir 
586*cdf0e10cSrcweir     REG_ENSURE(!key6.closeKey(),  "test_registry_CppApi error 14");
587*cdf0e10cSrcweir 
588*cdf0e10cSrcweir     REG_ENSURE(!key1.closeKey() &&
589*cdf0e10cSrcweir                !key3.closeKey() &&
590*cdf0e10cSrcweir                !key4.closeKey(),  "test_registry_CppApi error 14");
591*cdf0e10cSrcweir 
592*cdf0e10cSrcweir     REG_ENSURE(!rootKey.deleteKey(OUString::createFromAscii("myFirstKey")), "test_registry_CppApi error 15");
593*cdf0e10cSrcweir 
594*cdf0e10cSrcweir     REG_ENSURE(!key2.closeKey(), "test_registry_CppApi error 16");
595*cdf0e10cSrcweir     REG_ENSURE(!rootKey.openKey(OUString::createFromAscii("mySecondKey"), key2), "test_registry_CppApi error 17");
596*cdf0e10cSrcweir 
597*cdf0e10cSrcweir     REG_ENSURE(!key5.closeKey(), "test_registry_CppApi error 18");
598*cdf0e10cSrcweir 
599*cdf0e10cSrcweir     REG_ENSURE(!rootKey.deleteKey(OUString::createFromAscii("myThirdKey")), "test_registry_CppApi error 19");
600*cdf0e10cSrcweir 
601*cdf0e10cSrcweir     REG_ENSURE(rootKey.openKey(OUString::createFromAscii("myThirdKey"), key5), "test_registry_CppApi error 20");
602*cdf0e10cSrcweir 
603*cdf0e10cSrcweir     REG_ENSURE(!key2.closeKey() &&
604*cdf0e10cSrcweir                 !rootKey.closeKey(),  "test_registry_CppApi error 21");
605*cdf0e10cSrcweir 
606*cdf0e10cSrcweir 	REG_ENSURE(!myRegistry->close(), "test_registry_CppApi error 22");
607*cdf0e10cSrcweir 
608*cdf0e10cSrcweir     // Test loadkey
609*cdf0e10cSrcweir     RegistryKey rootKey2, key21, key22, key23, key24 , key25;
610*cdf0e10cSrcweir 
611*cdf0e10cSrcweir     REG_ENSURE(!myRegistry->create(OUString::createFromAscii("test2.rdb")), "test_registry_CppApi error 23");
612*cdf0e10cSrcweir     REG_ENSURE(!myRegistry->openRootKey(rootKey2), "test_registry_CppApi error 24");
613*cdf0e10cSrcweir 
614*cdf0e10cSrcweir     REG_ENSURE(!rootKey2.createKey(OUString::createFromAscii("reg2FirstKey"), key21), "test_registry_CppApi error 25");
615*cdf0e10cSrcweir     REG_ENSURE(!rootKey2.createKey(OUString::createFromAscii("reg2SecondKey"), key22), "test_registry_CppApi error 26");
616*cdf0e10cSrcweir     REG_ENSURE(!key21.createKey(OUString::createFromAscii("reg2FirstSubKey"), key23), "test_registry_CppApi error 27");
617*cdf0e10cSrcweir     REG_ENSURE(!key21.createKey(OUString::createFromAscii("reg2SecondSubKey"), key24), "test_registry_CppApi error 28");
618*cdf0e10cSrcweir     REG_ENSURE(!rootKey2.createKey(OUString::createFromAscii("reg2ThirdKey"), key25), "test_registry_CppApi error 29");
619*cdf0e10cSrcweir 
620*cdf0e10cSrcweir     sal_uInt32 nValue= 123456789;
621*cdf0e10cSrcweir     REG_ENSURE(!key23.setValue(OUString(), RG_VALUETYPE_LONG, &nValue, sizeof(sal_uInt32)), "test_registry_CppApi error 30");
622*cdf0e10cSrcweir 
623*cdf0e10cSrcweir     REG_ENSURE(!key21.closeKey() &&
624*cdf0e10cSrcweir                !key22.closeKey() &&
625*cdf0e10cSrcweir                !key23.closeKey() &&
626*cdf0e10cSrcweir                !key24.closeKey() &&
627*cdf0e10cSrcweir                !key25.closeKey() &&
628*cdf0e10cSrcweir                !rootKey2.closeKey(), "test_registry_CppApi error 31");
629*cdf0e10cSrcweir 
630*cdf0e10cSrcweir     REG_ENSURE(!myRegistry->close(), "test_registry_CppApi error 32");
631*cdf0e10cSrcweir 
632*cdf0e10cSrcweir     REG_ENSURE(!myRegistry->open(OUString::createFromAscii("test.rdb"), REG_READWRITE), "test_registry_CppApi error 33");
633*cdf0e10cSrcweir     REG_ENSURE(!myRegistry->openRootKey(rootKey), "test_registry_CppApi error 34");
634*cdf0e10cSrcweir 
635*cdf0e10cSrcweir     REG_ENSURE(!myRegistry->loadKey(rootKey, OUString::createFromAscii("allFromTest2"),
636*cdf0e10cSrcweir 					OUString::createFromAscii("test2.rdb")), "test_registry_CppApi error 35");
637*cdf0e10cSrcweir     REG_ENSURE(!myRegistry->saveKey(rootKey, OUString::createFromAscii("allFromTest2"),
638*cdf0e10cSrcweir 					OUString::createFromAscii("test3.rdb")), "test_registry_CppApi error 36");
639*cdf0e10cSrcweir 
640*cdf0e10cSrcweir     REG_ENSURE(!rootKey.createKey(OUString::createFromAscii("allFromTest3"), key1), "test_registry_CppApi error 37");
641*cdf0e10cSrcweir     REG_ENSURE(!key1.createKey(OUString::createFromAscii("myFirstKey2"), key2), "test_registry_CppApi error 38");
642*cdf0e10cSrcweir     REG_ENSURE(!key1.createKey(OUString::createFromAscii("mySecondKey2"), key3), "test_registry_CppApi error 39");
643*cdf0e10cSrcweir 
644*cdf0e10cSrcweir     REG_ENSURE(!myRegistry->mergeKey(rootKey, OUString::createFromAscii("allFromTest3"),
645*cdf0e10cSrcweir 					OUString::createFromAscii("test3.rdb")), "test_registry_CppApi error 40");
646*cdf0e10cSrcweir     REG_ENSURE(!myRegistry->mergeKey(rootKey, OUString::createFromAscii("allFromTest3"),
647*cdf0e10cSrcweir 					OUString::createFromAscii("ucrtest.rdb"), sal_True), "test_registry_CppApi error 40.a)");
648*cdf0e10cSrcweir 
649*cdf0e10cSrcweir //     REG_ENSURE(myRegistry->mergeKey(rootKey, OUString::createFromAscii("allFromTest3"), OUString::createFromAscii("ucrtest.rdb"), sal_True)
650*cdf0e10cSrcweir //                  == REG_NO_ERROR/*REG_MERGE_CONFLICT*/, "test_registry_CppApi error 40.b)");
651*cdf0e10cSrcweir 
652*cdf0e10cSrcweir     REG_ENSURE(!key1.closeKey() &&
653*cdf0e10cSrcweir                 !key2.closeKey(), "test_registry_CppApi error 41");
654*cdf0e10cSrcweir 
655*cdf0e10cSrcweir     const sal_Unicode* wValue= OUString::createFromAscii( "Mein erster Unicode Value" ).getStr();
656*cdf0e10cSrcweir     REG_ENSURE(!key3.setValue(OUString(), RG_VALUETYPE_UNICODE, (void*)wValue,
657*cdf0e10cSrcweir                 (rtl_ustr_getLength(wValue)+1)*sizeof(sal_Unicode)), "test_registry_CppApi error 42");
658*cdf0e10cSrcweir 
659*cdf0e10cSrcweir     REG_ENSURE(!key3.closeKey(), "test_registry_CppApi error 43");
660*cdf0e10cSrcweir 
661*cdf0e10cSrcweir     REG_ENSURE(!rootKey.openKey(OUString::createFromAscii("/allFromTest3/reg2FirstKey/reg2FirstSubKey"), key1),
662*cdf0e10cSrcweir                 "test_registry_CppApi error 43.a)");
663*cdf0e10cSrcweir     REG_ENSURE(!rootKey.deleteKey(OUString::createFromAscii("/allFromTest3/reg2FirstKey/reg2FirstSubKey")), "test_registry_CppApi error 44");
664*cdf0e10cSrcweir     REG_ENSURE(key1.getValueInfo(OUString(), &valueType, &valueSize) == REG_INVALID_KEY,
665*cdf0e10cSrcweir                 "test_registry_CppApi error 44.a)");
666*cdf0e10cSrcweir     REG_ENSURE(!key1.closeKey(), "test_registry_CppApi error 44.b)");
667*cdf0e10cSrcweir 
668*cdf0e10cSrcweir     REG_ENSURE(!rootKey.closeKey(), "test_registry_CppApi error 45");
669*cdf0e10cSrcweir 
670*cdf0e10cSrcweir     REG_ENSURE(!myRegistry->close(), "test_registry_CppApi error 46");
671*cdf0e10cSrcweir 
672*cdf0e10cSrcweir     REG_ENSURE(!myRegistry->open(OUString::createFromAscii("test.rdb"), REG_READWRITE), "test_registry_CppApi error 47");
673*cdf0e10cSrcweir 
674*cdf0e10cSrcweir     REG_ENSURE(!myRegistry->destroy(OUString::createFromAscii("test2.rdb")), "test_registry_CppApi error 48");
675*cdf0e10cSrcweir //  REG_ENSURE(!myRegistry->destroy("test3.rdb"), "test_registry_CppApi error 49");
676*cdf0e10cSrcweir 
677*cdf0e10cSrcweir     Registry *myRegistry2 = new Registry(*myRegistry);
678*cdf0e10cSrcweir 
679*cdf0e10cSrcweir     REG_ENSURE(myRegistry->destroy(OUString()), "test_registry_CppApi error 50");
680*cdf0e10cSrcweir 
681*cdf0e10cSrcweir     delete(myRegistry2);
682*cdf0e10cSrcweir 
683*cdf0e10cSrcweir     REG_ENSURE(!myRegistry->create(OUString::createFromAscii("destroytest.rdb")), "test_registry_CppApi error 51");
684*cdf0e10cSrcweir     REG_ENSURE(!myRegistry->close(), "test_registry_CppApi error 52");
685*cdf0e10cSrcweir     REG_ENSURE(!myRegistry->open(OUString::createFromAscii("destroytest.rdb"), REG_READONLY), "test_registry_CppApi error 53");
686*cdf0e10cSrcweir     REG_ENSURE(!myRegistry->openRootKey(rootKey), "test_registry_CppApi error 54");
687*cdf0e10cSrcweir 
688*cdf0e10cSrcweir     REG_ENSURE(myRegistry->mergeKey(rootKey, OUString::createFromAscii("allFromTest3"),
689*cdf0e10cSrcweir 					OUString::createFromAscii("test3.rdb")), "test_registry_CppApi error 55");
690*cdf0e10cSrcweir     REG_ENSURE(!myRegistry->destroy(OUString::createFromAscii("test3.rdb")), "test_registry_CppApi error 56");
691*cdf0e10cSrcweir 
692*cdf0e10cSrcweir     REG_ENSURE(!rootKey.closeKey(), "test_registry_CppApi error 57");
693*cdf0e10cSrcweir     REG_ENSURE(!myRegistry->close(), "test_registry_CppApi error 58");
694*cdf0e10cSrcweir     REG_ENSURE(!myRegistry->open(OUString::createFromAscii("destroytest.rdb"), REG_READWRITE), "test_registry_CppApi error 59");
695*cdf0e10cSrcweir     REG_ENSURE(!myRegistry->destroy(OUString()), "test_registry_CppApi error 60");
696*cdf0e10cSrcweir 
697*cdf0e10cSrcweir     REG_ENSURE(!myRegistry->open(OUString::createFromAscii("test.rdb"), REG_READWRITE), "test_registry_CppApi error 61");
698*cdf0e10cSrcweir     REG_ENSURE(!myRegistry->destroy(OUString::createFromAscii("ucrtest.rdb")), "test_registry_CppApi error 62");
699*cdf0e10cSrcweir     REG_ENSURE(!myRegistry->destroy(OUString()), "test_registry_CppApi error 63");
700*cdf0e10cSrcweir     delete(myRegistry);
701*cdf0e10cSrcweir 
702*cdf0e10cSrcweir     cout << "test_registry_CppApi() Ok!\n";
703*cdf0e10cSrcweir 
704*cdf0e10cSrcweir     return;
705*cdf0e10cSrcweir }
706*cdf0e10cSrcweir 
707*cdf0e10cSrcweir 
708