1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
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>
33 void test_coreReflection()
35 Registry
*myRegistry
= new Registry();
37 RegistryKey rootKey
, key1
, key2
, key3
, key4
,key5
, key6
, key7
, key8
;
39 REG_ENSURE(!myRegistry
->create(OUString("ucrtest.rdb")), "testCoreReflection error 1");
40 REG_ENSURE(!myRegistry
->openRootKey(rootKey
), "testCoreReflection error 2");
42 REG_ENSURE(!rootKey
.createKey(OUString("UCR"), key1
), "testCoreReflection error 3");
43 REG_ENSURE(!key1
.createKey(OUString("ModuleA"), key2
), "testCoreReflection error 4");
44 REG_ENSURE(!key2
.createKey(OUString("StructA"), key3
), "testCoreReflection error 5");
45 REG_ENSURE(!key2
.createKey(OUString("EnumA"), key4
), "testCoreReflection error 6");
46 REG_ENSURE(!key2
.createKey(OUString("XInterfaceA"), key5
), "testCoreReflection error 7");
47 REG_ENSURE(!key2
.createKey(OUString("ExceptionA"), key6
), "testCoreReflection error 8");
48 REG_ENSURE(!key2
.createKey(OUString("ServiceA"), key7
), "testCoreReflection error 8a");
49 REG_ENSURE(!key2
.createKey(OUString("ConstantsA"), key8
), "testCoreReflection error 8b");
52 RegistryTypeWriter
writer(RT_TYPE_MODULE
,
54 OUString(), 11, 0, 0);
58 writer
.setDoku(OUString("Hello I am a module"));
59 writer
.setFileName(OUString("DummyFile"));
61 aConst
.m_type
= RT_TYPE_BOOL
;
62 aConst
.m_value
.aBool
= sal_True
;
63 writer
.setFieldData(0, OUString("aConstBool"),
65 OUString("I am a boolean"),
66 OUString("DummyFile"), RTFieldAccess::CONST
, aConst
);
67 aConst
.m_type
= RT_TYPE_BYTE
;
68 aConst
.m_value
.aByte
= 127;
69 writer
.setFieldData(1, OUString("aConstByte"),
71 OUString("I am a byte"),
72 OUString("DummyFile"), RTFieldAccess::CONST
, aConst
);
73 aConst
.m_type
= RT_TYPE_INT16
;
74 aConst
.m_value
.aShort
= -10;
75 writer
.setFieldData(2, OUString("aConstShort"),
77 OUString("I am a short"),
78 OUString("DummyFile"), RTFieldAccess::CONST
, aConst
);
79 aConst
.m_type
= RT_TYPE_UINT16
;
80 aConst
.m_value
.aUShort
= 10;
81 writer
.setFieldData(3, OUString("aConstUShort"),
82 OUString("unsigned short"),
83 OUString("I am an unsigned short"),
84 OUString("DummyFile"), RTFieldAccess::CONST
, aConst
);
85 aConst
.m_type
= RT_TYPE_INT32
;
86 aConst
.m_value
.aLong
= -100000;
87 writer
.setFieldData(4, OUString("aConstLong"),
89 OUString("I am a long"),
90 OUString("DummyFile"), RTFieldAccess::CONST
, aConst
);
91 aConst
.m_type
= RT_TYPE_UINT32
;
92 aConst
.m_value
.aULong
= 100000;
93 writer
.setFieldData(5, OUString("aConstULong"),
94 OUString("unsigned long"),
95 OUString("I am an unsigned long"),
96 OUString("DummyFile"), RTFieldAccess::CONST
, aConst
);
97 aConst
.m_type
= RT_TYPE_INT64
;
98 aConst
.m_value
.aHyper
= -100000000;
99 writer
.setFieldData(6, OUString("aConstHyper"),
101 OUString("I am an hyper"),
102 OUString("DummyFile"), RTFieldAccess::CONST
, aConst
);
103 aConst
.m_type
= RT_TYPE_UINT64
;
104 aConst
.m_value
.aUHyper
= 100000000;
105 writer
.setFieldData(7, OUString("aConstULong"),
106 OUString("unsigned long"),
107 OUString("I am an unsigned long"),
108 OUString("DummyFile"), RTFieldAccess::CONST
, aConst
);
109 aConst
.m_type
= RT_TYPE_FLOAT
;
110 aConst
.m_value
.aFloat
= -2e-10f
;
111 writer
.setFieldData(8, OUString("aConstFloat"),
113 OUString("I am a float"),
114 OUString("DummyFile"), RTFieldAccess::CONST
, aConst
);
115 aConst
.m_type
= RT_TYPE_DOUBLE
;
116 aConst
.m_value
.aDouble
= -2e-100; writer
.setFieldData(9, OUString("aConstDouble"),
118 OUString("I am a double"),
119 OUString("DummyFile"), RTFieldAccess::CONST
, aConst
);
120 aConst
.m_type
= RT_TYPE_STRING
;
121 OUString
tmpStr("this is a unicode string");
122 aConst
.m_value
.aString
= tmpStr
.getStr();
124 writer
.setFieldData(10, OUString("aConstString"),
126 OUString("I am a string"),
127 OUString("DummyFile"), RTFieldAccess::CONST
, aConst
);
129 const sal_uInt8
* pBlop
= writer
.getBlop();
130 sal_uInt32 aBlopSize
= writer
.getBlopSize();
132 REG_ENSURE(!key2
.setValue(OUString(), RegValueType::BINARY
, (void*)pBlop
, aBlopSize
), "testCoreReflection error 9");
134 sal_uInt8
* readBlop
= (sal_uInt8
*)std::malloc(aBlopSize
);
135 REG_ENSURE(!key2
.getValue(OUString(), (void*)readBlop
) , "testCoreReflection error 9a");
137 RegistryTypeReader
reader(readBlop
, aBlopSize
, sal_True
);
139 if (reader
.isValid())
141 REG_ENSURE(reader
.getTypeName() == "ModuleA", "testCoreReflection error 9a2");
143 RTConstValue aReadConst
= reader
.getFieldConstValue(4);
144 REG_ENSURE( aReadConst
.m_type
== RT_TYPE_INT32
, "testCoreReflection error 9a3");
145 REG_ENSURE( aReadConst
.m_value
.aLong
== -100000, "testCoreReflection error 9a4");
147 aReadConst
= reader
.getFieldConstValue(6);
148 REG_ENSURE( aReadConst
.m_type
== RT_TYPE_INT64
, "testCoreReflection error 9a5");
149 REG_ENSURE( aReadConst
.m_value
.aHyper
== -100000000, "testCoreReflection error 9a6");
151 aReadConst
= reader
.getFieldConstValue(10);
152 OString aConstStr
= OUStringToOString(aConst
.m_value
.aString
, RTL_TEXTENCODING_ASCII_US
);
153 REG_ENSURE(aConstStr
.equals("this is a unicode string"), "testCoreReflection error 9b");
159 RegistryTypeWriter
writer(RT_TYPE_STRUCT
,
160 OUString("ModuleA/StructA"),
161 OUString(), 3, 0, 0);
163 writer
.setDoku(OUString("Hello I am a structure"));
164 writer
.setFileName(OUString("DummyFile"));
166 writer
.setFieldData(0, OUString("asal_uInt32"),
167 OUString("unsigned long"),
168 OUString(), OUString(), RTFieldAccess::READWRITE
);
169 writer
.setFieldData(1, OUString("aXInterface"),
170 OUString("stardiv/uno/XInterface"),
171 OUString(), OUString(), RTFieldAccess::READWRITE
);
172 writer
.setFieldData(2, OUString("aSequence"),
173 OUString("[]ModuleA/EnumA"),
174 OUString(), OUString(), RTFieldAccess::READWRITE
);
176 const sal_uInt8
* pBlop
= writer
.getBlop();
177 sal_uInt32 aBlopSize
= writer
.getBlopSize();
179 REG_ENSURE(!key3
.setValue(OUString(), RegValueType::BINARY
, (void*)pBlop
, aBlopSize
), "testCoreReflection error 9a");
183 RegistryTypeWriter
writer(RT_TYPE_ENUM
,
184 OUString("ModuleA/EnumA"),
185 OUString(), 2, 0, 0);
189 aConst
.m_type
= RT_TYPE_UINT32
;
190 aConst
.m_value
.aULong
= 10;
192 writer
.setDoku(OUString("Hello I am an enum"));
193 writer
.setFileName(OUString("DummyFile"));
195 writer
.setFieldData(0, OUString("ENUM_VAL_1"),
196 OUString(), OUString("I am an enum value"),
197 OUString(), RTFieldAccess::CONST
, aConst
);
199 aConst
.m_value
.aULong
= 10;
200 writer
.setFieldData(1, OUString("ENUM_VAL_2"),
201 OUString(), OUString(), OUString(), RTFieldAccess::CONST
, aConst
);
203 const sal_uInt8
* pBlop
= writer
.getBlop();
204 sal_uInt32 aBlopSize
= writer
.getBlopSize();
206 REG_ENSURE(!key4
.setValue(OUString(), RegValueType::BINARY
, (void*)pBlop
, aBlopSize
), "testCoreReflection error 9b");
210 RegistryTypeWriter
writer(RT_TYPE_INTERFACE
,
211 OUString("ModuleA/XInterfaceA"),
212 OUString("stardiv/uno/XInterface"),
216 RTUik aUik
= {1,2,3,4,5};
219 writer
.setDoku(OUString("Hello I am an interface"));
220 writer
.setFileName(OUString("DummyFile"));
222 writer
.setFieldData(0, OUString("aString"),
223 OUString("string"), OUString(), OUString(), RTFieldAccess::READWRITE
);
224 writer
.setFieldData(1, OUString("aStruct"),
225 OUString("ModuleA/StructA"),
226 OUString(), OUString(), RTFieldAccess::READONLY
);
227 writer
.setFieldData(2, OUString("aEnum"),
228 OUString("ModuleA/EnumA"), OUString(), OUString(), RTFieldAccess::BOUND
);
229 aConst
.m_type
= RT_TYPE_UINT16
;
230 aConst
.m_value
.aUShort
= 12;
231 writer
.setFieldData(3, OUString("aConstUShort"),
232 OUString("unsigned short"), OUString(),
233 OUString("DummyFile"), RTFieldAccess::CONST
, aConst
);
235 writer
.setMethodData(0, OUString("methodA"),
236 OUString("double"), RTMethodMode::TWOWAY
, 2, 1,
237 OUString("Hello I am the methodA"));
238 writer
.setParamData(0, 0, OUString("ModuleA/StructA"),
239 OUString("aStruct"), RT_PARAM_IN
);
240 writer
.setParamData(0, 1, OUString("unsigned short"),
241 OUString("aShort"), RT_PARAM_INOUT
);
242 writer
.setExcData(0, 0, OUString("ModuleA/ExceptionA"));
244 const sal_uInt8
* pBlop
= writer
.getBlop();
245 sal_uInt32 aBlopSize
= writer
.getBlopSize();
247 REG_ENSURE(!key5
.setValue(OUString(), RegValueType::BINARY
, (void*)pBlop
, aBlopSize
), "testCoreReflection error 9c");
249 sal_uInt8
* readBlop
= (sal_uInt8
*)std::malloc(aBlopSize
);
250 REG_ENSURE(!key5
.getValue(OUString(), (void*)readBlop
) , "testCoreReflection error 9c1");
252 RegistryTypeReader
reader(readBlop
, aBlopSize
, sal_True
);
254 if (reader
.isValid())
256 REG_ENSURE(reader
.getTypeName() == "ModuleA/XInterfaceA", "testCoreReflection error 9c2");
259 reader
.getUik(retUik
);
260 REG_ENSURE(retUik
.m_Data1
= 1, "testCoreReflection error 9c3");
261 REG_ENSURE(retUik
.m_Data2
= 2, "testCoreReflection error 9c4");
262 REG_ENSURE(retUik
.m_Data3
= 3, "testCoreReflection error 9c5");
263 REG_ENSURE(retUik
.m_Data4
= 4, "testCoreReflection error 9c6");
264 REG_ENSURE(retUik
.m_Data5
= 5, "testCoreReflection error 9c7");
270 RegistryTypeWriter
writer(RT_TYPE_EXCEPTION
,
271 OUString("ModuleA/ExceptionA"),
272 OUString(), 1, 0, 0);
274 writer
.setDoku(OUString("Hello I am an exception"));
276 writer
.setFieldData(0, OUString("aSource"),
277 OUString("stardiv/uno/XInterface"),
278 OUString("I am an interface member"),
279 OUString(), RTFieldAccess::READWRITE
);
281 const sal_uInt8
* pBlop
= writer
.getBlop();
282 sal_uInt32 aBlopSize
= writer
.getBlopSize();
284 REG_ENSURE(!key6
.setValue(OUString(), RegValueType::BINARY
, (void*)pBlop
, aBlopSize
), "testCoreReflection error 9d");
288 RegistryTypeWriter
writer(RT_TYPE_SERVICE
,
289 OUString("ModuleA/ServiceA"),
290 OUString(), 1, 0, 4);
292 writer
.setDoku(OUString("Hello I am a service"));
293 writer
.setFileName(OUString("DummyFile"));
295 writer
.setFieldData(0, OUString("aProperty"),
296 OUString("stardiv/uno/XInterface"),
297 OUString("I am a property"),
298 OUString(), RTFieldAccess::READWRITE
);
300 writer
.setReferenceData(0, OUString("ModuleA/XInterfaceA"), RTReferenceType::SUPPORTS
,
301 OUString("Hello I am a reference to a supported interface"),
302 RTFieldAccess::OPTIONAL
);
303 writer
.setReferenceData(1, OUString("ModuleA/XInterfaceA"), RTReferenceType::OBSERVES
,
304 OUString("Hello I am a reference to an observed interface"));
305 writer
.setReferenceData(2, OUString("ModuleA/ServiceB"), RTReferenceType::EXPORTS
,
306 OUString("Hello I am a reference to an exported service"));
307 writer
.setReferenceData(3, OUString("ModuleA/ServiceB"), RTReferenceType::NEEDS
,
308 OUString("Hello I am a reference to a needed service"));
310 const sal_uInt8
* pBlop
= writer
.getBlop();
311 sal_uInt32 aBlopSize
= writer
.getBlopSize();
313 REG_ENSURE(!key7
.setValue(OUString(), RegValueType::BINARY
, (void*)pBlop
, aBlopSize
), "testCoreReflection error 9e");
314 sal_uInt8
* readBlop
= (sal_uInt8
*)std::malloc(aBlopSize
);
315 REG_ENSURE(!key7
.getValue(OUString(), (void*)readBlop
) , "testCoreReflection error 9e2");
317 RegistryTypeReader
reader(readBlop
, aBlopSize
, sal_True
);
319 if (reader
.isValid())
321 REG_ENSURE(reader
.getTypeName() == "ModuleA/ServiceA", "testCoreReflection error 9e3");
323 sal_uInt32 referenceCount
= reader
.getReferenceCount();
324 REG_ENSURE( referenceCount
== 4, "testCoreReflection error 9e4");
326 OUString refName
= reader
.getReferenceName(0);
327 REG_ENSURE(refName
== "ModuleA/XInterfaceA", "testCoreReflection error 9e5");
332 RegistryTypeWriter
writer(RT_TYPE_CONSTANTS
,
333 OUString("ModuleA/ConstansA"),
334 OUString(), 3, 0, 0);
338 writer
.setDoku(OUString("Hello I am a constants group"));
339 writer
.setFileName(OUString("DummyFile"));
341 aConst
.m_type
= RT_TYPE_BOOL
;
342 aConst
.m_value
.aBool
= sal_True
;
343 writer
.setFieldData(0, OUString("ConstantsA_aConstBool"),
345 OUString("I am a boolean"),
346 OUString("DummyFile"), RTFieldAccess::CONST
, aConst
);
347 aConst
.m_type
= RT_TYPE_BYTE
;
348 aConst
.m_value
.aByte
= 127;
349 writer
.setFieldData(1, OUString("ConstantsA_aConstByte"),
351 OUString("I am a byte"),
352 OUString("DummyFile"), RTFieldAccess::CONST
, aConst
);
353 aConst
.m_type
= RT_TYPE_INT16
;
354 aConst
.m_value
.aShort
= -10;
355 writer
.setFieldData(2, OUString("ConstantsA_aConstShort"),
357 OUString("I am a short"),
358 OUString("DummyFile"), RTFieldAccess::CONST
, aConst
);
360 const sal_uInt8
* pBlop
= writer
.getBlop();
361 sal_uInt32 aBlopSize
= writer
.getBlopSize();
363 REG_ENSURE(!key8
.setValue(OUString(), RegValueType::BINARY
, (void*)pBlop
, aBlopSize
), "testCoreReflection error 9f");
366 // REG_ENSURE(!myRegistry->destroy(NULL), "testCoreReflection error 10");
369 std::cout
<< "test_coreReflection() Ok!\n";
372 void test_registry_CppApi()
374 Registry
*myRegistry
= new Registry();
376 RegistryKey rootKey
, key1
, key2
, key3
, key4
,key5
, key6
, key7
, key8
, key9
;
378 REG_ENSURE(!myRegistry
->create(OUString("test.rdb")), "test_registry_CppApi error 1");
379 REG_ENSURE(!myRegistry
->openRootKey(rootKey
), "test_registry_CppApi error 2");
381 REG_ENSURE(!rootKey
.createKey(OUString("myFirstKey"), key1
), "test_registry_CppApi error 3");
382 REG_ENSURE(!rootKey
.createKey(OUString("mySecondKey"), key2
), "test_registry_CppApi error 4");
383 REG_ENSURE(!key1
.createKey(OUString("X"), key3
), "test_registry_CppApi error 5");
384 REG_ENSURE(!key1
.createKey(OUString("mySecondSubKey"), key4
), "test_registry_CppApi error 6");
385 REG_ENSURE(!rootKey
.createKey(OUString("myThirdKey"), key5
), "test_registry_CppApi error 6a");
387 REG_ENSURE(!key5
.createKey(OUString("1"), key4
), "test_registry_CppApi error 6b");
388 REG_ENSURE(!key4
.createKey(OUString("2"), key3
), "test_registry_CppApi error 6c");
389 REG_ENSURE(!key5
.openKey("1", key4
), "test_registry_CppApi error 6d");
390 REG_ENSURE(!rootKey
.openKey("/myThirdKey/1", key4
), "test_registry_CppApi error 6e");
391 REG_ENSURE(key4
.getName() == "/myThirdKey/1", "test_registry_CppApi error 6f");
393 REG_ENSURE(!rootKey
.createKey(OUString("myFourthKey"), key6
), "test_registry_CppApi error 7");
394 REG_ENSURE(!rootKey
.createKey(OUString("myFifthKey"), key6
), "test_registry_CppApi error 7a");
395 REG_ENSURE(!rootKey
.createKey(OUString("mySixthKey"), key6
), "test_registry_CppApi error 7b");
400 REG_ENSURE(!rootKey
.createKey(OUString("/myFourthKey/X"), key7
), "test_registry_CppApi error 7c)");
401 REG_ENSURE(!key6
.createLink(OUString("myFirstLink"), OUString("/myFourthKey/X")), "test_registry_CppApi error 7d");
402 REG_ENSURE(!key6
.createKey(OUString("mySixthSubKey"), key7
), "test_registry_CppApi error 7e");
405 REG_ENSURE(!key6
.getLinkTarget(OUString("myFirstLink"), linkTarget
), "test_registry_CppApi error 7f");
406 REG_ENSURE(linkTarget
== "/myFourthKey/X", "test_registry_CppApi error 7g");
408 RegistryKeyNames
* pSubKeyNames
= new RegistryKeyNames();
409 sal_uInt32 nSubKeys
=0;
411 REG_ENSURE(!rootKey
.getKeyNames(OUString("mySixthKey"), *pSubKeyNames
), "test_registry_CppApi error 7h)");
412 REG_ENSURE(pSubKeyNames
->getLength() == 2, "test_registry_CppApi error 7i)");
414 for (sal_uInt32 i
=0; i
< pSubKeyNames
->getLength(); i
++)
416 if ( pSubKeyNames
->getElement(i
) == "/mySixthKey/myFirstLink" )
419 REG_ENSURE(!rootKey
.getKeyType(pSubKeyNames
->getElement(i
), &keyType
), "test_registry_CppApi error 7j");
420 REG_ENSURE(keyType
== RG_LINKTYPE
, "test_registry_CppApi error 7k");
424 REG_ENSURE(!key7
.closeKey(), "test_registry_CppApi error 7k1");
427 REG_ENSURE(!rootKey
.openKey("/mySixthKey/myFirstLink", key6
), "test_registry_CppApi error 7l");
428 // REG_ENSURE(key6.getName() == "/myFourthKey/X", "test_registry_CppApi error 7m");
430 REG_ENSURE(!rootKey
.openKey("myFifthKey", key6
), "test_registry_CppApi error 7m1");
431 REG_ENSURE(!key6
.createLink(OUString("mySecondLink"),
432 OUString("/mySixthKey/myFirstLink")), "test_registry_CppApi error 7m2");
434 REG_ENSURE(!rootKey
.openKey("/myFifthKey/mySecondLink", key6
), "test_registry_CppApi error 7m3");
435 // REG_ENSURE(key6.getName() == "/myFourthKey/X", "test_registry_CppApi error 7m4");
437 REG_ENSURE(!rootKey
.createKey(OUString("/myFifthKey/mySecondLink/myFirstLinkSubKey"), key7
), "test_registry_CppApi error 7m5");
438 REG_ENSURE(key7
.getName() == "/myFourthKey/X/myFirstLinkSubKey", "test_registry_CppApi error 7m6");
440 REG_ENSURE(!key7
.createLink(OUString("myThirdLink"), OUString("/myFifthKey/mySecondLink")), "test_registry_CppApi error 7m7");
441 REG_ENSURE(!rootKey
.openKey("/myFourthKey/X/myFirstLinkSubKey/myThirdLink", key7
), "test_registry_CppApi error 7m8");
442 // REG_ENSURE(!key7.openKey("/myFirstLinkSubKey/myThirdLink/myFirstLinkSubKey/myThirdLink", key6), "test_registry_CppApi error 7m9");
443 // REG_ENSURE(key7.getName() == "/myFourthKey/X", "test_registry_CppApi error 7m10");
444 REG_ENSURE(!key7
.closeKey(), "test_registry_CppApi error 7m11");
446 REG_ENSURE(!rootKey
.deleteLink(OUString("/myFifthKey/mySecondLink")), "test_registry_CppApi error 7m12");
448 REG_ENSURE(!rootKey
.createLink(OUString("/myFifthKey/mySecondLink"),
449 OUString("/myFourthKey/X/myFirstLinkSubKey/myThirdLink")),
450 "test_registry_CppApi error 7m13");
452 // REG_ENSURE(rootKey.openKey("/myFourthKey/X/myFirstLinkSubKey/myThirdLink", key7) == REG_DETECT_RECURSION,
453 // "test_registry_CppApi error 7m14");
455 // REG_ENSURE(key7.closeKey() == REG_INVALID_KEY, "test_registry_CppApi error 7m11");
457 RegistryKeyNames subKeyNames
;
460 REG_ENSURE(!rootKey
.getKeyNames(OUString("mySixthKey"), subKeyNames
), "test_registry_CppApi error 7n");
462 nSubKeys
= subKeyNames
.getLength();
463 REG_ENSURE(nSubKeys
== 2, "test_registry_CppApi error 7n1");
464 REG_ENSURE(subKeyNames
.getElement(0) == "/mySixthKey/myFirstLink", "test_registry_CppApi error 7p1)");
465 REG_ENSURE(subKeyNames
.getElement(1) =="/mySixthKey/mySixthSubKey", "test_registry_CppApi error 7p2");
468 RegistryKeyArray subKeys
;
471 REG_ENSURE(!rootKey
.openSubKeys(OUString("myFirstKey"), subKeys
), "test_registry_CppApi error 7o");
473 nSubKeys
= subKeys
.getLength();
474 REG_ENSURE(nSubKeys
== 2, "test_registry_CppApi error 7o1");
475 REG_ENSURE(subKeys
.getElement(0).getName() == "/myFirstKey/mySecondSubKey", "test_registry_CppApi error 7p1)");
476 REG_ENSURE(subKeys
.getElement(1).getName() == "/myFirstKey/X", "test_registry_CppApi error 7p2");
478 REG_ENSURE(!rootKey
.closeSubKeys(subKeys
), "test_registry_CppApi error 7q)");
481 REG_ENSURE(!rootKey
.createKey(OUString("/TEST"), key8
), "test_registry_CppApi error 8");
482 REG_ENSURE(!rootKey
.createKey(OUString("/TEST/Child1"), key8
), "test_registry_CppApi error 8a");
483 REG_ENSURE(!rootKey
.createKey(OUString("/TEST/Child2"), key8
), "test_registry_CppApi error 8a1");
484 REG_ENSURE(!rootKey
.openKey("/TEST", key9
), "test_registry_CppApi error 8b");
485 REG_ENSURE(!key8
.closeKey() && !key9
.closeKey(), "test_registry_CppApi error 8b1");
486 REG_ENSURE(!rootKey
.openKey("/TEST", key8
), "test_registry_CppApi error 8b");
487 REG_ENSURE(!key8
.closeKey(), "test_registry_CppApi error 8c");
488 REG_ENSURE(!rootKey
.openKey("TEST", key8
), "test_registry_CppApi error 8c");
489 REG_ENSURE(!key8
.closeKey(), "test_registry_CppApi error 8d");
492 char* Value
=(char*)"My first value";
493 REG_ENSURE(!rootKey
.setValue(OUString("mySecondKey"), RegValueType::STRING
, Value
, 18), "test_registry_CppApi error 9");
495 RegValueType valueType
;
496 sal_uInt32 valueSize
;
498 REG_ENSURE(!rootKey
.getValueInfo(OUString("mySecondKey"), &valueType
, &valueSize
), "test_registry_CppApi error 9a");
500 readValue
= (char*)std::malloc(valueSize
);
501 REG_ENSURE(!key2
.getValue(OUString(), readValue
), "test_registry_CppApi error 10");
503 REG_ENSURE(valueType
== RegValueType::STRING
, "test_registry_CppApi error 11");
504 REG_ENSURE(valueSize
== 18, "test_registry_CppApi error 12");
505 REG_ENSURE(strcmp(readValue
, Value
) == 0, "test_registry_CppApi error 13");
506 std::free(readValue
);
508 const char* pList
[3];
509 const char* n1
= "Hello";
510 const char* n2
= "now I";
511 const char* n3
= "come";
517 REG_ENSURE(!rootKey
.setStringListValue(OUString("myFourthKey"), (char**)pList
, 3), "test_registry_CppApi error 13a");
519 RegistryValueList
<char*> valueList
;
520 REG_ENSURE(!rootKey
.getStringListValue(OUString("myFourthKey"), valueList
), "test_registry_CppApi error 13b");
522 REG_ENSURE(strcmp(n1
, valueList
.getElement(0)) == 0, "test_registry_CppApi error 13c");
523 REG_ENSURE(strcmp(n2
, valueList
.getElement(1)) == 0, "test_registry_CppApi error 13d");
524 REG_ENSURE(strcmp(n3
, valueList
.getElement(2)) == 0, "test_registry_CppApi error 13e");
526 REG_ENSURE(!rootKey
.getValueInfo(OUString("myFourthKey"), &valueType
, &valueSize
), "test_registry_CppApi error 13e1");
527 REG_ENSURE(valueType
== RegValueType::STRINGLIST
, "test_registry_CppApi error 13e2");
528 REG_ENSURE(valueSize
== 3, "test_registry_CppApi error 13e3");
535 REG_ENSURE(!rootKey
.setLongListValue(OUString("myFifthKey"), pLong
, 3), "test_registry_CppApi error 13f");
537 RegistryValueList
<sal_Int32
> longList
;
538 REG_ENSURE(!rootKey
.getLongListValue(OUString("myFifthKey"), longList
), "test_registry_CppApi error 13g");
540 REG_ENSURE(pLong
[0] == longList
.getElement(0), "test_registry_CppApi error 13h");
541 REG_ENSURE(pLong
[1] == longList
.getElement(1), "test_registry_CppApi error 13i");
542 REG_ENSURE(pLong
[2] == longList
.getElement(2), "test_registry_CppApi error 13j");
545 OUString
sWTestValue("My first unicode value");
546 const sal_Unicode
* wTestValue
= sWTestValue
.getStr();
547 REG_ENSURE(!rootKey
.setValue(OUString("mySixthKey"), RegValueType::UNICODE
, (void*)wTestValue
,
548 (rtl_ustr_getLength(wTestValue
)+1)*sizeof(sal_Unicode
)), "test_registry_CppApi error 13j1");
550 REG_ENSURE(!rootKey
.getValueInfo(OUString("mySixthKey"), &valueType
, &valueSize
), "test_registry_CppApi error 13j2");
551 sal_Unicode
* pTmpValue
= (sal_Unicode
*)std::malloc(valueSize
);
552 REG_ENSURE(!rootKey
.getValue(OUString("mySixthKey"), pTmpValue
), "test_registry_CppApi error 13j3");
553 REG_ENSURE(rtl_ustr_getLength(wTestValue
) == rtl_ustr_getLength(pTmpValue
), "test_registry_CppApi error 13j4");
554 REG_ENSURE(rtl_ustr_compare(wTestValue
, pTmpValue
) == 0, "test_registry_CppApi error 13j4");
556 const sal_Unicode
* pUnicode
[3];
557 OUString
w1("Hello");
558 OUString
w2("now I");
559 OUString
w3("come as unicode");
561 pUnicode
[0]=w1
.getStr();
562 pUnicode
[1]=w2
.getStr();
563 pUnicode
[2]=w3
.getStr();
565 REG_ENSURE(!rootKey
.setUnicodeListValue(OUString("mySixthKey"), (sal_Unicode
**)pUnicode
, 3), "test_registry_CppApi error 13k");
567 RegistryValueList
<sal_Unicode
*> unicodeList
;
568 REG_ENSURE(!rootKey
.getUnicodeListValue(OUString("mySixthKey"), unicodeList
), "test_registry_CppApi error 13l");
570 REG_ENSURE(rtl_ustr_compare(w1
, unicodeList
.getElement(0)) == 0, "test_registry_CppApi error 13m");
571 REG_ENSURE(rtl_ustr_compare(w2
, unicodeList
.getElement(1)) == 0, "test_registry_CppApi error 13n");
572 REG_ENSURE(rtl_ustr_compare(w3
, unicodeList
.getElement(2)) == 0, "test_registry_CppApi error 13o");
574 REG_ENSURE(!key6
.closeKey(), "test_registry_CppApi error 14");
576 REG_ENSURE(!key1
.closeKey() &&
578 !key4
.closeKey(), "test_registry_CppApi error 14");
580 REG_ENSURE(!rootKey
.deleteKey(OUString("myFirstKey")), "test_registry_CppApi error 15");
582 REG_ENSURE(!key2
.closeKey(), "test_registry_CppApi error 16");
583 REG_ENSURE(!rootKey
.openKey("mySecondKey", key2
), "test_registry_CppApi error 17");
585 REG_ENSURE(!key5
.closeKey(), "test_registry_CppApi error 18");
587 REG_ENSURE(!rootKey
.deleteKey(OUString("myThirdKey")), "test_registry_CppApi error 19");
589 REG_ENSURE(rootKey
.openKey("myThirdKey", key5
), "test_registry_CppApi error 20");
591 REG_ENSURE(!key2
.closeKey() &&
592 !rootKey
.closeKey(), "test_registry_CppApi error 21");
594 REG_ENSURE(!myRegistry
->close(), "test_registry_CppApi error 22");
597 RegistryKey rootKey2
, key21
, key22
, key23
, key24
, key25
;
599 REG_ENSURE(!myRegistry
->create(OUString("test2.rdb")), "test_registry_CppApi error 23");
600 REG_ENSURE(!myRegistry
->openRootKey(rootKey2
), "test_registry_CppApi error 24");
602 REG_ENSURE(!rootKey2
.createKey(OUString("reg2FirstKey"), key21
), "test_registry_CppApi error 25");
603 REG_ENSURE(!rootKey2
.createKey(OUString("reg2SecondKey"), key22
), "test_registry_CppApi error 26");
604 REG_ENSURE(!key21
.createKey(OUString("reg2FirstSubKey"), key23
), "test_registry_CppApi error 27");
605 REG_ENSURE(!key21
.createKey(OUString("reg2SecondSubKey"), key24
), "test_registry_CppApi error 28");
606 REG_ENSURE(!rootKey2
.createKey(OUString("reg2ThirdKey"), key25
), "test_registry_CppApi error 29");
608 sal_uInt32 nValue
= 123456789;
609 REG_ENSURE(!key23
.setValue(OUString(), RegValueType::LONG
, &nValue
, sizeof(sal_uInt32
)), "test_registry_CppApi error 30");
611 REG_ENSURE(!key21
.closeKey() &&
616 !rootKey2
.closeKey(), "test_registry_CppApi error 31");
618 REG_ENSURE(!myRegistry
->close(), "test_registry_CppApi error 32");
620 REG_ENSURE(!myRegistry
->open(OUString("test.rdb"), RegAccessMode::READWRITE
), "test_registry_CppApi error 33");
621 REG_ENSURE(!myRegistry
->openRootKey(rootKey
), "test_registry_CppApi error 34");
623 REG_ENSURE(!myRegistry
->loadKey(rootKey
, OUString("allFromTest2"),
624 OUString("test2.rdb")), "test_registry_CppApi error 35");
625 REG_ENSURE(!myRegistry
->saveKey(rootKey
, OUString("allFromTest2"),
626 OUString("test3.rdb")), "test_registry_CppApi error 36");
628 REG_ENSURE(!rootKey
.createKey(OUString("allFromTest3"), key1
), "test_registry_CppApi error 37");
629 REG_ENSURE(!key1
.createKey(OUString("myFirstKey2"), key2
), "test_registry_CppApi error 38");
630 REG_ENSURE(!key1
.createKey(OUString("mySecondKey2"), key3
), "test_registry_CppApi error 39");
632 REG_ENSURE(!myRegistry
->mergeKey(rootKey
, OUString("allFromTest3"),
633 OUString("test3.rdb")), "test_registry_CppApi error 40");
634 REG_ENSURE(!myRegistry
->mergeKey(rootKey
, OUString("allFromTest3"),
635 OUString("ucrtest.rdb"), sal_True
), "test_registry_CppApi error 40.a)");
637 // REG_ENSURE(myRegistry->mergeKey(rootKey, OUString("allFromTest3"), OUString("ucrtest.rdb"), sal_True)
638 // == REG_NO_ERROR/*REG_MERGE_CONFLICT*/, "test_registry_CppApi error 40.b)");
640 REG_ENSURE(!key1
.closeKey() &&
641 !key2
.closeKey(), "test_registry_CppApi error 41");
643 const sal_Unicode
* wValue
= OUString("My first unicode value").getStr();
644 REG_ENSURE(!key3
.setValue(OUString(), RegValueType::UNICODE
, (void*)wValue
,
645 (rtl_ustr_getLength(wValue
)+1)*sizeof(sal_Unicode
)), "test_registry_CppApi error 42");
647 REG_ENSURE(!key3
.closeKey(), "test_registry_CppApi error 43");
649 REG_ENSURE(!rootKey
.openKey("/allFromTest3/reg2FirstKey/reg2FirstSubKey", key1
),
650 "test_registry_CppApi error 43.a)");
651 REG_ENSURE(!rootKey
.deleteKey(OUString("/allFromTest3/reg2FirstKey/reg2FirstSubKey")), "test_registry_CppApi error 44");
652 REG_ENSURE(key1
.getValueInfo(OUString(), &valueType
, &valueSize
) == REG_INVALID_KEY
,
653 "test_registry_CppApi error 44.a)");
654 REG_ENSURE(!key1
.closeKey(), "test_registry_CppApi error 44.b)");
656 REG_ENSURE(!rootKey
.closeKey(), "test_registry_CppApi error 45");
658 REG_ENSURE(!myRegistry
->close(), "test_registry_CppApi error 46");
660 REG_ENSURE(!myRegistry
->open(OUString("test.rdb"), RegAccessMode::READWRITE
), "test_registry_CppApi error 47");
662 REG_ENSURE(!myRegistry
->destroy(OUString("test2.rdb")), "test_registry_CppApi error 48");
663 // REG_ENSURE(!myRegistry->destroy("test3.rdb"), "test_registry_CppApi error 49");
665 Registry
*myRegistry2
= new Registry(*myRegistry
);
667 REG_ENSURE(myRegistry
->destroy(OUString()), "test_registry_CppApi error 50");
671 REG_ENSURE(!myRegistry
->create(OUString("destroytest.rdb")), "test_registry_CppApi error 51");
672 REG_ENSURE(!myRegistry
->close(), "test_registry_CppApi error 52");
673 REG_ENSURE(!myRegistry
->open(OUString("destroytest.rdb"), RegAccessMode::READONLY
), "test_registry_CppApi error 53");
674 REG_ENSURE(!myRegistry
->openRootKey(rootKey
), "test_registry_CppApi error 54");
676 REG_ENSURE(myRegistry
->mergeKey(rootKey
, OUString("allFromTest3"),
677 OUString("test3.rdb")), "test_registry_CppApi error 55");
678 REG_ENSURE(!myRegistry
->destroy(OUString("test3.rdb")), "test_registry_CppApi error 56");
680 REG_ENSURE(!rootKey
.closeKey(), "test_registry_CppApi error 57");
681 REG_ENSURE(!myRegistry
->close(), "test_registry_CppApi error 58");
682 REG_ENSURE(!myRegistry
->open(OUString("destroytest.rdb"), RegAccessMode::READWRITE
), "test_registry_CppApi error 59");
683 REG_ENSURE(!myRegistry
->destroy(OUString()), "test_registry_CppApi error 60");
685 REG_ENSURE(!myRegistry
->open(OUString("test.rdb"), RegAccessMode::READWRITE
), "test_registry_CppApi error 61");
686 REG_ENSURE(!myRegistry
->destroy(OUString("ucrtest.rdb")), "test_registry_CppApi error 62");
687 REG_ENSURE(!myRegistry
->destroy(OUString()), "test_registry_CppApi error 63");
690 std::cout
<< "test_registry_CppApi() Ok!\n";
696 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */