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