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