Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / registry / test / testregcpp.cxx
blobbc9d447724b2f880e0437a4f835221a96794b7d1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <iostream>
22 #include <stdio.h>
23 #include <string.h>
25 #include "registry/registry.hxx"
26 #include "registry/reflread.hxx"
27 #include "registry/reflwrit.hxx"
28 #include "regdiagnose.h"
29 #include <rtl/alloc.h>
30 #include <rtl/ustring.hxx>
32 using namespace std;
35 void test_coreReflection()
37 Registry *myRegistry = new Registry();
39 RegistryKey rootKey, key1, key2, key3, key4 ,key5, key6, key7, key8;
41 REG_ENSURE(!myRegistry->create(OUString("ucrtest.rdb")), "testCoreReflection error 1");
42 REG_ENSURE(!myRegistry->openRootKey(rootKey), "testCoreReflection error 2");
44 REG_ENSURE(!rootKey.createKey(OUString("UCR"), key1), "testCoreReflection error 3");
45 REG_ENSURE(!key1.createKey(OUString("ModuleA"), key2), "testCoreReflection error 4");
46 REG_ENSURE(!key2.createKey(OUString("StructA"), key3), "testCoreReflection error 5");
47 REG_ENSURE(!key2.createKey(OUString("EnumA"), key4), "testCoreReflection error 6");
48 REG_ENSURE(!key2.createKey(OUString("XInterfaceA"), key5), "testCoreReflection error 7");
49 REG_ENSURE(!key2.createKey(OUString("ExceptionA"), key6), "testCoreReflection error 8");
50 REG_ENSURE(!key2.createKey(OUString("ServiceA"), key7), "testCoreReflection error 8a");
51 REG_ENSURE(!key2.createKey(OUString("ConstantsA"), key8), "testCoreReflection error 8b");
54 RegistryTypeWriter writer(RT_TYPE_MODULE,
55 OUString("ModuleA"),
56 OUString(), 11, 0, 0);
58 RTConstValue aConst;
60 writer.setDoku(OUString("Hallo ich bin ein Modul"));
61 writer.setFileName(OUString("DummyFile"));
63 aConst.m_type = RT_TYPE_BOOL;
64 aConst.m_value.aBool = sal_True;
65 writer.setFieldData(0, OUString("aConstBool"),
66 OUString("boolean"),
67 OUString("ich bin ein boolean"),
68 OUString("DummyFile"), RTFieldAccess::CONST, aConst);
69 aConst.m_type = RT_TYPE_BYTE;
70 aConst.m_value.aByte = 127;
71 writer.setFieldData(1, OUString("aConstByte"),
72 OUString("byte"),
73 OUString("ich bin ein byte"),
74 OUString("DummyFile"), RTFieldAccess::CONST, aConst);
75 aConst.m_type = RT_TYPE_INT16;
76 aConst.m_value.aShort = -10;
77 writer.setFieldData(2, OUString("aConstShort"),
78 OUString("short"),
79 OUString("ich bin ein short"),
80 OUString("DummyFile"), RTFieldAccess::CONST, aConst);
81 aConst.m_type = RT_TYPE_UINT16;
82 aConst.m_value.aUShort = 10;
83 writer.setFieldData(3, OUString("aConstUShort"),
84 OUString("unsigned short"),
85 OUString("ich bin ein unsigned short"),
86 OUString("DummyFile"), RTFieldAccess::CONST, aConst);
87 aConst.m_type = RT_TYPE_INT32;
88 aConst.m_value.aLong = -100000;
89 writer.setFieldData(4, OUString("aConstLong"),
90 OUString("long"),
91 OUString("ich bin ein long"),
92 OUString("DummyFile"), RTFieldAccess::CONST, aConst);
93 aConst.m_type = RT_TYPE_UINT32;
94 aConst.m_value.aULong = 100000;
95 writer.setFieldData(5, OUString("aConstULong"),
96 OUString("unsigned long"),
97 OUString("ich bin ein unsigned long"),
98 OUString("DummyFile"), RTFieldAccess::CONST, aConst);
99 aConst.m_type = RT_TYPE_INT64;
100 aConst.m_value.aHyper = -100000000;
101 writer.setFieldData(6, OUString("aConstHyper"),
102 OUString("hyper"),
103 OUString("ich bin ein hyper"),
104 OUString("DummyFile"), RTFieldAccess::CONST, aConst);
105 aConst.m_type = RT_TYPE_UINT64;
106 aConst.m_value.aUHyper = 100000000;
107 writer.setFieldData(7, OUString("aConstULong"),
108 OUString("unsigned long"),
109 OUString("ich bin ein unsigned long"),
110 OUString("DummyFile"), RTFieldAccess::CONST, aConst);
111 aConst.m_type = RT_TYPE_FLOAT;
112 aConst.m_value.aFloat = -2e-10f;
113 writer.setFieldData(8, OUString("aConstFloat"),
114 OUString("float"),
115 OUString("ich bin ein float"),
116 OUString("DummyFile"), RTFieldAccess::CONST, aConst);
117 aConst.m_type = RT_TYPE_DOUBLE;
118 aConst.m_value.aDouble = -2e-100; writer.setFieldData(9, OUString("aConstDouble"),
119 OUString("double"),
120 OUString("ich bin ein double"),
121 OUString("DummyFile"), RTFieldAccess::CONST, aConst);
122 aConst.m_type = RT_TYPE_STRING;
123 OUString tmpStr("dies ist ein unicode string");
124 aConst.m_value.aString = tmpStr.getStr();
126 writer.setFieldData(10, OUString("aConstString"),
127 OUString("string"),
128 OUString("ich bin ein string"),
129 OUString("DummyFile"), RTFieldAccess::CONST, aConst);
131 const sal_uInt8* pBlop = writer.getBlop();
132 sal_uInt32 aBlopSize = writer.getBlopSize();
134 REG_ENSURE(!key2.setValue(OUString(), RegValueType::BINARY, (void*)pBlop, aBlopSize), "testCoreReflection error 9");
136 sal_uInt8* readBlop = (sal_uInt8*)rtl_allocateMemory(aBlopSize);
137 REG_ENSURE(!key2.getValue(OUString(), (void*)readBlop) , "testCoreReflection error 9a");
139 RegistryTypeReader reader(readBlop, aBlopSize, sal_True);
141 if (reader.isValid())
143 REG_ENSURE(reader.getTypeName() == "ModuleA", "testCoreReflection error 9a2");
145 RTConstValue aReadConst = reader.getFieldConstValue(4);
146 REG_ENSURE( aReadConst.m_type == RT_TYPE_INT32, "testCoreReflection error 9a3");
147 REG_ENSURE( aReadConst.m_value.aLong == -100000, "testCoreReflection error 9a4");
149 aReadConst = reader.getFieldConstValue(6);
150 REG_ENSURE( aReadConst.m_type == RT_TYPE_INT64, "testCoreReflection error 9a5");
151 REG_ENSURE( aReadConst.m_value.aHyper == -100000000, "testCoreReflection error 9a6");
153 aReadConst = reader.getFieldConstValue(10);
154 OString aConstStr = OUStringToOString(aConst.m_value.aString, RTL_TEXTENCODING_ASCII_US);
155 REG_ENSURE(aConstStr.equals("dies ist ein unicode string"), "testCoreReflection error 9b");
161 RegistryTypeWriter writer(RT_TYPE_STRUCT,
162 OUString("ModuleA/StructA"),
163 OUString(), 3, 0, 0);
165 writer.setDoku(OUString("Hallo ich bin eine Struktur"));
166 writer.setFileName(OUString("DummyFile"));
168 writer.setFieldData(0, OUString("asal_uInt32"),
169 OUString("unsigned long"),
170 OUString(), OUString(), RTFieldAccess::READWRITE);
171 writer.setFieldData(1, OUString("aXInterface"),
172 OUString("stardiv/uno/XInterface"),
173 OUString(), OUString(), RTFieldAccess::READWRITE);
174 writer.setFieldData(2, OUString("aSequence"),
175 OUString("[]ModuleA/EnumA"),
176 OUString(), OUString(), RTFieldAccess::READWRITE);
178 const sal_uInt8* pBlop = writer.getBlop();
179 sal_uInt32 aBlopSize = writer.getBlopSize();
181 REG_ENSURE(!key3.setValue(OUString(), RegValueType::BINARY, (void*)pBlop, aBlopSize), "testCoreReflection error 9a");
185 RegistryTypeWriter writer(RT_TYPE_ENUM,
186 OUString("ModuleA/EnumA"),
187 OUString(), 2, 0, 0);
189 RTConstValue aConst;
191 aConst.m_type = RT_TYPE_UINT32;
192 aConst.m_value.aULong = 10;
194 writer.setDoku(OUString("Hallo ich bin ein Enum"));
195 writer.setFileName(OUString("DummyFile"));
197 writer.setFieldData(0, OUString("ENUM_VAL_1"),
198 OUString(), OUString("ich bin ein enum value"),
199 OUString(), RTFieldAccess::CONST, aConst);
201 aConst.m_value.aULong = 10;
202 writer.setFieldData(1, OUString("ENUM_VAL_2"),
203 OUString(), OUString(), OUString(), RTFieldAccess::CONST, aConst);
205 const sal_uInt8* pBlop = writer.getBlop();
206 sal_uInt32 aBlopSize = writer.getBlopSize();
208 REG_ENSURE(!key4.setValue(OUString(), RegValueType::BINARY, (void*)pBlop, aBlopSize), "testCoreReflection error 9b");
212 RegistryTypeWriter writer(RT_TYPE_INTERFACE,
213 OUString("ModuleA/XInterfaceA"),
214 OUString("stardiv/uno/XInterface"),
215 4, 1, 0);
216 RTConstValue aConst;
218 RTUik aUik = {1,2,3,4,5};
220 writer.setUik(aUik);
221 writer.setDoku(OUString("Hallo ich bin ein Interface"));
222 writer.setFileName(OUString("DummyFile"));
224 writer.setFieldData(0, OUString("aString"),
225 OUString("string"), OUString(), OUString(), RTFieldAccess::READWRITE);
226 writer.setFieldData(1, OUString("aStruct"),
227 OUString("ModuleA/StructA"),
228 OUString(), OUString(), RTFieldAccess::READONLY);
229 writer.setFieldData(2, OUString("aEnum"),
230 OUString("ModuleA/EnumA"), OUString(), OUString(), RTFieldAccess::BOUND);
231 aConst.m_type = RT_TYPE_UINT16;
232 aConst.m_value.aUShort = 12;
233 writer.setFieldData(3, OUString("aConstUShort"),
234 OUString("unsigned short"), OUString(),
235 OUString("DummyFile"), RTFieldAccess::CONST, aConst);
237 writer.setMethodData(0, OUString("methodA"),
238 OUString("double"), RTMethodMode::TWOWAY, 2, 1,
239 OUString("Hallo ich bin die methodA"));
240 writer.setParamData(0, 0, OUString("ModuleA/StructA"),
241 OUString("aStruct"), RT_PARAM_IN);
242 writer.setParamData(0, 1, OUString("unsigned short"),
243 OUString("aShort"), RT_PARAM_INOUT);
244 writer.setExcData(0, 0, OUString("ModuleA/ExceptionA"));
246 const sal_uInt8* pBlop = writer.getBlop();
247 sal_uInt32 aBlopSize = writer.getBlopSize();
249 REG_ENSURE(!key5.setValue(OUString(), RegValueType::BINARY, (void*)pBlop, aBlopSize), "testCoreReflection error 9c");
251 sal_uInt8* readBlop = (sal_uInt8*)rtl_allocateMemory(aBlopSize);
252 REG_ENSURE(!key5.getValue(OUString(), (void*)readBlop) , "testCoreReflection error 9c1");
254 RegistryTypeReader reader(readBlop, aBlopSize, sal_True);
256 if (reader.isValid())
258 REG_ENSURE(reader.getTypeName() == "ModuleA/XInterfaceA", "testCoreReflection error 9c2");
260 RTUik retUik;
261 reader.getUik(retUik);
262 REG_ENSURE(retUik.m_Data1 = 1, "testCoreReflection error 9c3");
263 REG_ENSURE(retUik.m_Data2 = 2, "testCoreReflection error 9c4");
264 REG_ENSURE(retUik.m_Data3 = 3, "testCoreReflection error 9c5");
265 REG_ENSURE(retUik.m_Data4 = 4, "testCoreReflection error 9c6");
266 REG_ENSURE(retUik.m_Data5 = 5, "testCoreReflection error 9c7");
272 RegistryTypeWriter writer(RT_TYPE_EXCEPTION,
273 OUString("ModuleA/ExceptionA"),
274 OUString(), 1, 0, 0);
276 writer.setDoku(OUString("Hallo ich bin eine Exception"));
278 writer.setFieldData(0, OUString("aSource"),
279 OUString("stardiv/uno/XInterface"),
280 OUString("ich bin ein interface member"),
281 OUString(), RTFieldAccess::READWRITE);
283 const sal_uInt8* pBlop = writer.getBlop();
284 sal_uInt32 aBlopSize = writer.getBlopSize();
286 REG_ENSURE(!key6.setValue(OUString(), RegValueType::BINARY, (void*)pBlop, aBlopSize), "testCoreReflection error 9d");
290 RegistryTypeWriter writer(RT_TYPE_SERVICE,
291 OUString("ModuleA/ServiceA"),
292 OUString(), 1, 0, 4);
294 writer.setDoku(OUString("Hallo ich bin ein Service"));
295 writer.setFileName(OUString("DummyFile"));
297 writer.setFieldData(0, OUString("aProperty"),
298 OUString("stardiv/uno/XInterface"),
299 OUString("ich bin eine property"),
300 OUString(), RTFieldAccess::READWRITE);
302 writer.setReferenceData(0, OUString("ModuleA/XInterfaceA"), RTReferenceType::SUPPORTS,
303 OUString("Hallo ich eine Reference auf ein supported interface"),
304 RTFieldAccess::OPTIONAL);
305 writer.setReferenceData(1, OUString("ModuleA/XInterfaceA"), RTReferenceType::OBSERVES,
306 OUString("Hallo ich eine Reference auf ein observed interface"));
307 writer.setReferenceData(2, OUString("ModuleA/ServiceB"), RTReferenceType::EXPORTS,
308 OUString("Hallo ich eine Reference auf einen exported service"));
309 writer.setReferenceData(3, OUString("ModuleA/ServiceB"), RTReferenceType::NEEDS,
310 OUString("Hallo ich eine Reference auf einen needed service"));
312 const sal_uInt8* pBlop = writer.getBlop();
313 sal_uInt32 aBlopSize = writer.getBlopSize();
315 REG_ENSURE(!key7.setValue(OUString(), RegValueType::BINARY, (void*)pBlop, aBlopSize), "testCoreReflection error 9e");
316 sal_uInt8* readBlop = (sal_uInt8*)rtl_allocateMemory(aBlopSize);
317 REG_ENSURE(!key7.getValue(OUString(), (void*)readBlop) , "testCoreReflection error 9e2");
319 RegistryTypeReader reader(readBlop, aBlopSize, sal_True);
321 if (reader.isValid())
323 REG_ENSURE(reader.getTypeName() == "ModuleA/ServiceA", "testCoreReflection error 9e3");
325 sal_uInt32 referenceCount = reader.getReferenceCount();
326 REG_ENSURE( referenceCount == 4, "testCoreReflection error 9e4");
328 OUString refName = reader.getReferenceName(0);
329 REG_ENSURE(refName == "ModuleA/XInterfaceA", "testCoreReflection error 9e5");
334 RegistryTypeWriter writer(RT_TYPE_CONSTANTS,
335 OUString("ModuleA/ConstansA"),
336 OUString(), 3, 0, 0);
338 RTConstValue aConst;
340 writer.setDoku(OUString("Hallo ich bin eine Constants Group"));
341 writer.setFileName(OUString("DummyFile"));
343 aConst.m_type = RT_TYPE_BOOL;
344 aConst.m_value.aBool = sal_True;
345 writer.setFieldData(0, OUString("ConstantsA_aConstBool"),
346 OUString("boolean"),
347 OUString("ich bin ein boolean"),
348 OUString("DummyFile"), RTFieldAccess::CONST, aConst);
349 aConst.m_type = RT_TYPE_BYTE;
350 aConst.m_value.aByte = 127;
351 writer.setFieldData(1, OUString("ConstantsA_aConstByte"),
352 OUString("byte"),
353 OUString("ich bin ein byte"),
354 OUString("DummyFile"), RTFieldAccess::CONST, aConst);
355 aConst.m_type = RT_TYPE_INT16;
356 aConst.m_value.aShort = -10;
357 writer.setFieldData(2, OUString("ConstantsA_aConstShort"),
358 OUString("short"),
359 OUString("ich bin ein short"),
360 OUString("DummyFile"), RTFieldAccess::CONST, aConst);
362 const sal_uInt8* pBlop = writer.getBlop();
363 sal_uInt32 aBlopSize = writer.getBlopSize();
365 REG_ENSURE(!key8.setValue(OUString(), RegValueType::BINARY, (void*)pBlop, aBlopSize), "testCoreReflection error 9f");
368 // REG_ENSURE(!myRegistry->destroy(NULL), "testCoreReflection error 10");
369 delete myRegistry;
371 cout << "test_coreReflection() Ok!\n";
374 void test_registry_CppApi()
376 Registry *myRegistry = new Registry();
378 RegistryKey rootKey, key1, key2, key3, key4 ,key5, key6, key7, key8, key9;
380 REG_ENSURE(!myRegistry->create(OUString("test.rdb")), "test_registry_CppApi error 1");
381 REG_ENSURE(!myRegistry->openRootKey(rootKey), "test_registry_CppApi error 2");
383 REG_ENSURE(!rootKey.createKey(OUString("myFirstKey"), key1), "test_registry_CppApi error 3");
384 REG_ENSURE(!rootKey.createKey(OUString("mySecondKey"), key2), "test_registry_CppApi error 4");
385 REG_ENSURE(!key1.createKey(OUString("X"), key3), "test_registry_CppApi error 5");
386 REG_ENSURE(!key1.createKey(OUString("mySecondSubKey"), key4), "test_registry_CppApi error 6");
387 REG_ENSURE(!rootKey.createKey(OUString("myThirdKey"), key5), "test_registry_CppApi error 6a");
389 REG_ENSURE(!key5.createKey(OUString("1"), key4), "test_registry_CppApi error 6b");
390 REG_ENSURE(!key4.createKey(OUString("2"), key3), "test_registry_CppApi error 6c");
391 REG_ENSURE(!key5.openKey("1", key4), "test_registry_CppApi error 6d");
392 REG_ENSURE(!rootKey.openKey("/myThirdKey/1", key4), "test_registry_CppApi error 6e");
393 REG_ENSURE(key4.getName() == "/myThirdKey/1", "test_registry_CppApi error 6f");
395 REG_ENSURE(!rootKey.createKey(OUString("myFourthKey"), key6), "test_registry_CppApi error 7");
396 REG_ENSURE(!rootKey.createKey(OUString("myFifthKey"), key6), "test_registry_CppApi error 7a");
397 REG_ENSURE(!rootKey.createKey(OUString("mySixthKey"), key6), "test_registry_CppApi error 7b");
399 // Link Test
402 REG_ENSURE(!rootKey.createKey(OUString("/myFourthKey/X"), key7), "test_registry_CppApi error 7c)");
403 REG_ENSURE(!key6.createLink(OUString("myFirstLink"), OUString("/myFourthKey/X")), "test_registry_CppApi error 7d");
404 REG_ENSURE(!key6.createKey(OUString("mySixthSubKey"), key7), "test_registry_CppApi error 7e");
406 OUString linkTarget;
407 REG_ENSURE(!key6.getLinkTarget(OUString("myFirstLink"), linkTarget), "test_registry_CppApi error 7f");
408 REG_ENSURE(linkTarget == "/myFourthKey/X", "test_registry_CppApi error 7g");
410 RegistryKeyNames* pSubKeyNames = new RegistryKeyNames();
411 sal_uInt32 nSubKeys=0;
413 REG_ENSURE(!rootKey.getKeyNames(OUString("mySixthKey"), *pSubKeyNames), "test_registry_CppApi error 7h)");
414 REG_ENSURE(pSubKeyNames->getLength() == 2, "test_registry_CppApi error 7i)");
416 for (sal_uInt32 i=0; i < pSubKeyNames->getLength(); i++)
418 if ( pSubKeyNames->getElement(i) == "/mySixthKey/myFirstLink" )
420 RegKeyType keyType;
421 REG_ENSURE(!rootKey.getKeyType(pSubKeyNames->getElement(i), &keyType), "test_registry_CppApi error 7j");
422 REG_ENSURE(keyType == RG_LINKTYPE, "test_registry_CppApi error 7k");
426 REG_ENSURE(!key7.closeKey(), "test_registry_CppApi error 7k1");
427 delete pSubKeyNames;
429 REG_ENSURE(!rootKey.openKey("/mySixthKey/myFirstLink", key6), "test_registry_CppApi error 7l");
430 // REG_ENSURE(key6.getName() == "/myFourthKey/X", "test_registry_CppApi error 7m");
432 REG_ENSURE(!rootKey.openKey("myFifthKey", key6), "test_registry_CppApi error 7m1");
433 REG_ENSURE(!key6.createLink(OUString("mySecondLink"),
434 OUString("/mySixthKey/myFirstLink")), "test_registry_CppApi error 7m2");
436 REG_ENSURE(!rootKey.openKey("/myFifthKey/mySecondLink", key6), "test_registry_CppApi error 7m3");
437 // REG_ENSURE(key6.getName() == "/myFourthKey/X", "test_registry_CppApi error 7m4");
439 REG_ENSURE(!rootKey.createKey(OUString("/myFifthKey/mySecondLink/myFirstLinkSubKey"), key7), "test_registry_CppApi error 7m5");
440 REG_ENSURE(key7.getName() == "/myFourthKey/X/myFirstLinkSubKey", "test_registry_CppApi error 7m6");
442 REG_ENSURE(!key7.createLink(OUString("myThirdLink"), OUString("/myFifthKey/mySecondLink")), "test_registry_CppApi error 7m7");
443 REG_ENSURE(!rootKey.openKey("/myFourthKey/X/myFirstLinkSubKey/myThirdLink", key7), "test_registry_CppApi error 7m8");
444 // REG_ENSURE(!key7.openKey("/myFirstLinkSubKey/myThirdLink/myFirstLinkSubKey/myThirdLink", key6), "test_registry_CppApi error 7m9");
445 // REG_ENSURE(key7.getName() == "/myFourthKey/X", "test_registry_CppApi error 7m10");
446 REG_ENSURE(!key7.closeKey(), "test_registry_CppApi error 7m11");
448 REG_ENSURE(!rootKey.deleteLink(OUString("/myFifthKey/mySecondLink")), "test_registry_CppApi error 7m12");
450 REG_ENSURE(!rootKey.createLink(OUString("/myFifthKey/mySecondLink"),
451 OUString("/myFourthKey/X/myFirstLinkSubKey/myThirdLink")),
452 "test_registry_CppApi error 7m13");
454 // REG_ENSURE(rootKey.openKey("/myFourthKey/X/myFirstLinkSubKey/myThirdLink", key7) == REG_DETECT_RECURSION,
455 // "test_registry_CppApi error 7m14");
457 // REG_ENSURE(key7.closeKey() == REG_INVALID_KEY, "test_registry_CppApi error 7m11");
459 RegistryKeyNames subKeyNames;
460 nSubKeys=0;
462 REG_ENSURE(!rootKey.getKeyNames(OUString("mySixthKey"), subKeyNames), "test_registry_CppApi error 7n");
464 nSubKeys = subKeyNames.getLength();
465 REG_ENSURE(nSubKeys == 2, "test_registry_CppApi error 7n1");
466 REG_ENSURE(subKeyNames.getElement(0) == "/mySixthKey/myFirstLink", "test_registry_CppApi error 7p1)");
467 REG_ENSURE(subKeyNames.getElement(1) =="/mySixthKey/mySixthSubKey", "test_registry_CppApi error 7p2");
470 RegistryKeyArray subKeys;
471 nSubKeys=0;
473 REG_ENSURE(!rootKey.openSubKeys(OUString("myFirstKey"), subKeys), "test_registry_CppApi error 7o");
475 nSubKeys = subKeys.getLength();
476 REG_ENSURE(nSubKeys == 2, "test_registry_CppApi error 7o1");
477 REG_ENSURE(subKeys.getElement(0).getName() == "/myFirstKey/mySecondSubKey", "test_registry_CppApi error 7p1)");
478 REG_ENSURE(subKeys.getElement(1).getName() == "/myFirstKey/X", "test_registry_CppApi error 7p2");
480 REG_ENSURE(!rootKey.closeSubKeys(subKeys), "test_registry_CppApi error 7q)");
483 REG_ENSURE(!rootKey.createKey(OUString("/TEST"), key8), "test_registry_CppApi error 8");
484 REG_ENSURE(!rootKey.createKey(OUString("/TEST/Child1"), key8), "test_registry_CppApi error 8a");
485 REG_ENSURE(!rootKey.createKey(OUString("/TEST/Child2"), key8), "test_registry_CppApi error 8a1");
486 REG_ENSURE(!rootKey.openKey("/TEST", key9), "test_registry_CppApi error 8b");
487 REG_ENSURE(!key8.closeKey() && !key9.closeKey(), "test_registry_CppApi error 8b1");
488 REG_ENSURE(!rootKey.openKey("/TEST", key8), "test_registry_CppApi error 8b");
489 REG_ENSURE(!key8.closeKey(), "test_registry_CppApi error 8c");
490 REG_ENSURE(!rootKey.openKey("TEST", key8), "test_registry_CppApi error 8c");
491 REG_ENSURE(!key8.closeKey(), "test_registry_CppApi error 8d");
494 sal_Char* Value=(sal_Char*)"Mein erster Value";
495 REG_ENSURE(!rootKey.setValue(OUString("mySecondKey"), RegValueType::STRING, Value, 18), "test_registry_CppApi error 9");
497 RegValueType valueType;
498 sal_uInt32 valueSize;
499 sal_Char* readValue;
500 REG_ENSURE(!rootKey.getValueInfo(OUString("mySecondKey"), &valueType, &valueSize), "test_registry_CppApi error 9a");
502 readValue = (sal_Char*)rtl_allocateMemory(valueSize);
503 REG_ENSURE(!key2.getValue(OUString(), readValue), "test_registry_CppApi error 10");
505 REG_ENSURE(valueType == RegValueType::STRING, "test_registry_CppApi error 11");
506 REG_ENSURE(valueSize == 18, "test_registry_CppApi error 12");
507 REG_ENSURE(strcmp(readValue, Value) == 0, "test_registry_CppApi error 13");
508 rtl_freeMemory(readValue);
510 const sal_Char* pList[3];
511 const sal_Char* n1= "Hallo";
512 const sal_Char* n2= "jetzt komm";
513 const sal_Char* n3= "ich";
515 pList[0]=n1;
516 pList[1]=n2;
517 pList[2]=n3;
519 REG_ENSURE(!rootKey.setStringListValue(OUString("myFourthKey"), (sal_Char**)pList, 3), "test_registry_CppApi error 13a");
521 RegistryValueList<sal_Char*> valueList;
522 REG_ENSURE(!rootKey.getStringListValue(OUString("myFourthKey"), valueList), "test_registry_CppApi error 13b");
524 REG_ENSURE(strcmp(n1, valueList.getElement(0)) == 0, "test_registry_CppApi error 13c");
525 REG_ENSURE(strcmp(n2, valueList.getElement(1)) == 0, "test_registry_CppApi error 13d");
526 REG_ENSURE(strcmp(n3, valueList.getElement(2)) == 0, "test_registry_CppApi error 13e");
528 REG_ENSURE(!rootKey.getValueInfo(OUString("myFourthKey"), &valueType, &valueSize), "test_registry_CppApi error 13e1");
529 REG_ENSURE(valueType == RegValueType::STRINGLIST, "test_registry_CppApi error 13e2");
530 REG_ENSURE(valueSize == 3, "test_registry_CppApi error 13e3");
532 sal_Int32 pLong[3];
533 pLong[0] = 123;
534 pLong[1] = 456;
535 pLong[2] = 789;
537 REG_ENSURE(!rootKey.setLongListValue(OUString("myFifthKey"), pLong, 3), "test_registry_CppApi error 13f");
539 RegistryValueList<sal_Int32> longList;
540 REG_ENSURE(!rootKey.getLongListValue(OUString("myFifthKey"), longList), "test_registry_CppApi error 13g");
542 REG_ENSURE(pLong[0] == longList.getElement(0), "test_registry_CppApi error 13h");
543 REG_ENSURE(pLong[1] == longList.getElement(1), "test_registry_CppApi error 13i");
544 REG_ENSURE(pLong[2] == longList.getElement(2), "test_registry_CppApi error 13j");
547 OUString sWTestValue("Mein erster Unicode Value");
548 const sal_Unicode* wTestValue= sWTestValue.getStr();
549 REG_ENSURE(!rootKey.setValue(OUString("mySixthKey"), RegValueType::UNICODE, (void*)wTestValue,
550 (rtl_ustr_getLength(wTestValue)+1)*sizeof(sal_Unicode)), "test_registry_CppApi error 13j1");
552 REG_ENSURE(!rootKey.getValueInfo(OUString("mySixthKey"), &valueType, &valueSize), "test_registry_CppApi error 13j2");
553 sal_Unicode* pTmpValue = (sal_Unicode*)rtl_allocateMemory(valueSize);
554 REG_ENSURE(!rootKey.getValue(OUString("mySixthKey"), pTmpValue), "test_registry_CppApi error 13j3");
555 REG_ENSURE(rtl_ustr_getLength(wTestValue) == rtl_ustr_getLength(pTmpValue), "test_registry_CppApi error 13j4");
556 REG_ENSURE(rtl_ustr_compare(wTestValue, pTmpValue) == 0, "test_registry_CppApi error 13j4");
558 const sal_Unicode* pUnicode[3];
559 OUString w1("Hallo");
560 OUString w2("jetzt komm");
561 OUString w3("ich als unicode");
563 pUnicode[0]=w1.getStr();
564 pUnicode[1]=w2.getStr();
565 pUnicode[2]=w3.getStr();
567 REG_ENSURE(!rootKey.setUnicodeListValue(OUString("mySixthKey"), (sal_Unicode**)pUnicode, 3), "test_registry_CppApi error 13k");
569 RegistryValueList<sal_Unicode*> unicodeList;
570 REG_ENSURE(!rootKey.getUnicodeListValue(OUString("mySixthKey"), unicodeList), "test_registry_CppApi error 13l");
572 REG_ENSURE(rtl_ustr_compare(w1, unicodeList.getElement(0)) == 0, "test_registry_CppApi error 13m");
573 REG_ENSURE(rtl_ustr_compare(w2, unicodeList.getElement(1)) == 0, "test_registry_CppApi error 13n");
574 REG_ENSURE(rtl_ustr_compare(w3, unicodeList.getElement(2)) == 0, "test_registry_CppApi error 13o");
576 REG_ENSURE(!key6.closeKey(), "test_registry_CppApi error 14");
578 REG_ENSURE(!key1.closeKey() &&
579 !key3.closeKey() &&
580 !key4.closeKey(), "test_registry_CppApi error 14");
582 REG_ENSURE(!rootKey.deleteKey(OUString("myFirstKey")), "test_registry_CppApi error 15");
584 REG_ENSURE(!key2.closeKey(), "test_registry_CppApi error 16");
585 REG_ENSURE(!rootKey.openKey("mySecondKey", key2), "test_registry_CppApi error 17");
587 REG_ENSURE(!key5.closeKey(), "test_registry_CppApi error 18");
589 REG_ENSURE(!rootKey.deleteKey(OUString("myThirdKey")), "test_registry_CppApi error 19");
591 REG_ENSURE(rootKey.openKey("myThirdKey", key5), "test_registry_CppApi error 20");
593 REG_ENSURE(!key2.closeKey() &&
594 !rootKey.closeKey(), "test_registry_CppApi error 21");
596 REG_ENSURE(!myRegistry->close(), "test_registry_CppApi error 22");
598 // Test loadkey
599 RegistryKey rootKey2, key21, key22, key23, key24 , key25;
601 REG_ENSURE(!myRegistry->create(OUString("test2.rdb")), "test_registry_CppApi error 23");
602 REG_ENSURE(!myRegistry->openRootKey(rootKey2), "test_registry_CppApi error 24");
604 REG_ENSURE(!rootKey2.createKey(OUString("reg2FirstKey"), key21), "test_registry_CppApi error 25");
605 REG_ENSURE(!rootKey2.createKey(OUString("reg2SecondKey"), key22), "test_registry_CppApi error 26");
606 REG_ENSURE(!key21.createKey(OUString("reg2FirstSubKey"), key23), "test_registry_CppApi error 27");
607 REG_ENSURE(!key21.createKey(OUString("reg2SecondSubKey"), key24), "test_registry_CppApi error 28");
608 REG_ENSURE(!rootKey2.createKey(OUString("reg2ThirdKey"), key25), "test_registry_CppApi error 29");
610 sal_uInt32 nValue= 123456789;
611 REG_ENSURE(!key23.setValue(OUString(), RegValueType::LONG, &nValue, sizeof(sal_uInt32)), "test_registry_CppApi error 30");
613 REG_ENSURE(!key21.closeKey() &&
614 !key22.closeKey() &&
615 !key23.closeKey() &&
616 !key24.closeKey() &&
617 !key25.closeKey() &&
618 !rootKey2.closeKey(), "test_registry_CppApi error 31");
620 REG_ENSURE(!myRegistry->close(), "test_registry_CppApi error 32");
622 REG_ENSURE(!myRegistry->open(OUString("test.rdb"), RegAccessMode::READWRITE), "test_registry_CppApi error 33");
623 REG_ENSURE(!myRegistry->openRootKey(rootKey), "test_registry_CppApi error 34");
625 REG_ENSURE(!myRegistry->loadKey(rootKey, OUString("allFromTest2"),
626 OUString("test2.rdb")), "test_registry_CppApi error 35");
627 REG_ENSURE(!myRegistry->saveKey(rootKey, OUString("allFromTest2"),
628 OUString("test3.rdb")), "test_registry_CppApi error 36");
630 REG_ENSURE(!rootKey.createKey(OUString("allFromTest3"), key1), "test_registry_CppApi error 37");
631 REG_ENSURE(!key1.createKey(OUString("myFirstKey2"), key2), "test_registry_CppApi error 38");
632 REG_ENSURE(!key1.createKey(OUString("mySecondKey2"), key3), "test_registry_CppApi error 39");
634 REG_ENSURE(!myRegistry->mergeKey(rootKey, OUString("allFromTest3"),
635 OUString("test3.rdb")), "test_registry_CppApi error 40");
636 REG_ENSURE(!myRegistry->mergeKey(rootKey, OUString("allFromTest3"),
637 OUString("ucrtest.rdb"), sal_True), "test_registry_CppApi error 40.a)");
639 // REG_ENSURE(myRegistry->mergeKey(rootKey, OUString("allFromTest3"), OUString("ucrtest.rdb"), sal_True)
640 // == REG_NO_ERROR/*REG_MERGE_CONFLICT*/, "test_registry_CppApi error 40.b)");
642 REG_ENSURE(!key1.closeKey() &&
643 !key2.closeKey(), "test_registry_CppApi error 41");
645 const sal_Unicode* wValue= OUString("Mein erster Unicode Value").getStr();
646 REG_ENSURE(!key3.setValue(OUString(), RegValueType::UNICODE, (void*)wValue,
647 (rtl_ustr_getLength(wValue)+1)*sizeof(sal_Unicode)), "test_registry_CppApi error 42");
649 REG_ENSURE(!key3.closeKey(), "test_registry_CppApi error 43");
651 REG_ENSURE(!rootKey.openKey("/allFromTest3/reg2FirstKey/reg2FirstSubKey", key1),
652 "test_registry_CppApi error 43.a)");
653 REG_ENSURE(!rootKey.deleteKey(OUString("/allFromTest3/reg2FirstKey/reg2FirstSubKey")), "test_registry_CppApi error 44");
654 REG_ENSURE(key1.getValueInfo(OUString(), &valueType, &valueSize) == REG_INVALID_KEY,
655 "test_registry_CppApi error 44.a)");
656 REG_ENSURE(!key1.closeKey(), "test_registry_CppApi error 44.b)");
658 REG_ENSURE(!rootKey.closeKey(), "test_registry_CppApi error 45");
660 REG_ENSURE(!myRegistry->close(), "test_registry_CppApi error 46");
662 REG_ENSURE(!myRegistry->open(OUString("test.rdb"), RegAccessMode::READWRITE), "test_registry_CppApi error 47");
664 REG_ENSURE(!myRegistry->destroy(OUString("test2.rdb")), "test_registry_CppApi error 48");
665 // REG_ENSURE(!myRegistry->destroy("test3.rdb"), "test_registry_CppApi error 49");
667 Registry *myRegistry2 = new Registry(*myRegistry);
669 REG_ENSURE(myRegistry->destroy(OUString()), "test_registry_CppApi error 50");
671 delete(myRegistry2);
673 REG_ENSURE(!myRegistry->create(OUString("destroytest.rdb")), "test_registry_CppApi error 51");
674 REG_ENSURE(!myRegistry->close(), "test_registry_CppApi error 52");
675 REG_ENSURE(!myRegistry->open(OUString("destroytest.rdb"), RegAccessMode::READONLY), "test_registry_CppApi error 53");
676 REG_ENSURE(!myRegistry->openRootKey(rootKey), "test_registry_CppApi error 54");
678 REG_ENSURE(myRegistry->mergeKey(rootKey, OUString("allFromTest3"),
679 OUString("test3.rdb")), "test_registry_CppApi error 55");
680 REG_ENSURE(!myRegistry->destroy(OUString("test3.rdb")), "test_registry_CppApi error 56");
682 REG_ENSURE(!rootKey.closeKey(), "test_registry_CppApi error 57");
683 REG_ENSURE(!myRegistry->close(), "test_registry_CppApi error 58");
684 REG_ENSURE(!myRegistry->open(OUString("destroytest.rdb"), RegAccessMode::READWRITE), "test_registry_CppApi error 59");
685 REG_ENSURE(!myRegistry->destroy(OUString()), "test_registry_CppApi error 60");
687 REG_ENSURE(!myRegistry->open(OUString("test.rdb"), RegAccessMode::READWRITE), "test_registry_CppApi error 61");
688 REG_ENSURE(!myRegistry->destroy(OUString("ucrtest.rdb")), "test_registry_CppApi error 62");
689 REG_ENSURE(!myRegistry->destroy(OUString()), "test_registry_CppApi error 63");
690 delete(myRegistry);
692 cout << "test_registry_CppApi() Ok!\n";
694 return;
698 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */