1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: regtest.cxx,v $
10 * $Revision: 1.5.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"
37 #include "registry/registry.h"
38 #include <rtl/ustring.hxx>
39 #include <rtl/alloc.h>
44 #if (defined UNX) || (defined OS2)
51 RegKeyHandle hRootKey
, hKey1
, hKey2
, hKey3
, hKey4
, hKey5
;
53 cout
<< "\n Simple Registry Test !!! \n\n";
55 if (reg_createRegistry(OUString::createFromAscii("test4.rdb").pData
, &hReg
))
56 cout
<< "\t0. creating registry \"test4.rdb\" failed\n";
58 cout
<< "0. registry test4.rdb is created\n";
60 if (reg_openRootKey(hReg
, &hRootKey
))
61 cout
<< "1. open root key \"test4.rdb\" failed\n";
63 cout
<< "1. root key of \"test4.rdb\" is opened\n";
65 if (reg_createKey(hRootKey
, OUString::createFromAscii("myFirstKey").pData
, &hKey1
))
66 cout
<< "\t2. creating key \"myFirstKey\" failed\n";
68 cout
<< "2. key \"myFirstKey\" is created\n";
69 if (reg_createKey(hRootKey
, OUString::createFromAscii("mySecondKey").pData
, &hKey2
))
70 cout
<< "\t3. creating key \"mySecondKey\" failed\n";
72 cout
<< "3. key \"mySecondKey\" is created\n";
73 if (reg_createKey(hKey1
, OUString::createFromAscii("myFirstSubKey").pData
, &hKey3
))
74 cout
<< "\t4. creating subkey \"myFirstSubKey\" failed\n";
76 cout
<< "4. subkey \"myFirstSubKey\" is created\n";
77 if (reg_createKey(hKey1
, OUString::createFromAscii("mySecondSubKey").pData
, &hKey4
))
78 cout
<< "\t5. creating subkey \"mySecondSubKey\" failed\n";
80 cout
<< "5. subkey \"mySecondSubKey\" is created\n";
81 if (reg_createKey(hRootKey
, OUString::createFromAscii("myThirdKey").pData
, &hKey5
))
82 cout
<< "\t6. creating key \"myThirdKey\" is created\n\n";
84 cout
<< "6. key \"myThirdKey\" is created\n\n";
87 RegKeyHandle
* phSubKeys
;
89 if (reg_openSubKeys(hRootKey
, OUString::createFromAscii("myFirstKey").pData
, &phSubKeys
, &nSubKeys
))
90 cout
<< "\t7. open subkeys of \"myfirstKey\" failed\n";
92 cout
<< "7. open " << nSubKeys
<< "subkeys of \"myfirstKey\"\n";
95 if (reg_getKeyName(phSubKeys
[0], &keyName
.pData
))
96 cout
<< "\tname of subkey 1 = " << OUStringToOString(keyName
, RTL_TEXTENCODING_ASCII_US
).getStr() << "\n";
97 if (reg_getKeyName(phSubKeys
[1], &keyName
.pData
))
98 cout
<< "\tname of subkey 2 = " << OUStringToOString(keyName
, RTL_TEXTENCODING_ASCII_US
).getStr() << "\n";
100 if (reg_closeSubKeys(phSubKeys
, nSubKeys
))
101 cout
<< "\t8. close subkeys of \"myfirstKey\" failed\n\n";
103 cout
<< "8. close " << nSubKeys
<< "subkeys of \"myfirstKey\"\n\n";
106 char* Value
=(char*)"Mein erster Value";
107 if (reg_setValue(hRootKey
, OUString::createFromAscii("mySecondKey").pData
, RG_VALUETYPE_STRING
, Value
, 18))
108 cout
<< "\t9. setValue of key \"mySecondKey\" failed\n";
110 cout
<< "9. setValue (string Value) of key \"mySecondKey\"\n";
112 RegValueType valueType
;
113 sal_uInt32 valueSize
;
115 if (reg_getValueInfo(hRootKey
, OUString::createFromAscii("mySecondKey").pData
, &valueType
, &valueSize
))
116 cout
<< "\t10. getValueInfo of key \"mySecondKey\" failed\n";
118 cout
<< "10. getValueInfo of key \"mySecondKey\"\n";
120 readValue
= (sal_Char
*)rtl_allocateMemory(valueSize
);
121 if (reg_getValue(hKey2
, OUString().pData
, readValue
))
122 cout
<< "\t11. getValue of key \"mySecondKey\" failed\n";
125 cout
<< "11. getValue of key \"mySecondKey\"\n";
127 cout
<< "read Value,\n\tvalueType = " << (long)valueType
128 << "\n\tvalueSize = " << valueSize
129 << "\n\tvalue = " << readValue
<< "\n\n";
131 rtl_freeMemory(readValue
);
133 if (reg_closeKey(hKey1
) ||
134 reg_closeKey(hKey3
) ||
136 cout
<< "\t12. closing \"myFirstKey\" \"myfistSubKey\" \"mySecondSubKey\" failed\n";
138 cout
<< "12. keys \"myFirstKey\" \"myfistSubKey\" \"mySecondSubKey\" are closed\n";
140 if (reg_deleteKey(hRootKey
, OUString::createFromAscii("myFirstKey").pData
))
141 cout
<< "13.\t delete key \"myFirstKey\" failed\n";
143 cout
<< "13. key \"myFirstKey\" is deleted\n";
145 if (reg_closeKey(hKey2
))
146 cout
<< "\t14. closing key \"mySecondKey\" failed\n";
148 cout
<< "14. key \"mySecondKey\" is closed\n";
150 if (reg_openKey(hRootKey
, OUString::createFromAscii("mySecondKey").pData
, &hKey2
))
151 cout
<< "\n15. open key \"mySecondKey\" failed\n";
153 cout
<< "15. key \"mySecondKey\" is opended\n";
155 if (reg_closeKey(hKey5
))
156 cout
<< "\t15. closing key \"myThirdSubKey\" failed\n";
158 cout
<< "15. key \"myThirdSubKey\" is closed\n";
159 if (reg_deleteKey(hRootKey
, OUString::createFromAscii("myThirdKey").pData
))
160 cout
<< "\t16. delete key \"myThirdKey\" failed\n";
162 cout
<< "16. key \"myThirdKey\" is deleted\n";
164 if (reg_openKey(hRootKey
, OUString::createFromAscii("myThirdKey").pData
, &hKey5
))
165 cout
<< "\t17. open key \"myThirdKey\" failed\n";
167 cout
<< "17. key \"myThirdKey\" is opened\n";
169 cout
<< "\n close open keys\n\n";
171 if (reg_closeKey(hKey2
))
172 cout
<< "\t18. closing key \"mySecondKey\" failed\n";
174 cout
<< "18. key \"mySecondKey\" is closed\n";
176 if (reg_closeKey(hRootKey
))
177 cout
<< "\t19. closing root key failed\n";
179 cout
<< "19. root key is closed\n";
181 if (reg_closeRegistry(hReg
))
182 cout
<< "\t20. closing registry \"test4.rdb\" failed\n";
184 cout
<< "20. registry \"test4.rdb\" is closed\n";
187 cout
<< "\nTest load key\n\n";
190 RegKeyHandle hRootKey2
, h2Key1
, h2Key2
, h2Key3
, h2Key4
, h2Key5
;
192 if (reg_createRegistry(OUString::createFromAscii("test5.rdb").pData
, &hReg2
))
193 cout
<< "\t21. creating registry \"test5.rdb\" failed\n";
195 cout
<< "21. registry \"test5.rdb\" is created\n";
197 if (reg_openRootKey(hReg2
, &hRootKey2
))
198 cout
<< "\t22. open root key of \"test5.rdb\" failed\n";
200 cout
<< "22. root key of \"test5.rdb\" is opened\n";
202 if (reg_createKey(hRootKey2
, OUString::createFromAscii("reg2FirstKey").pData
, &h2Key1
))
203 cout
<< "\t23. creating key \"reg2FirstKey\" failed\n";
205 cout
<< "23. key \"reg2FirstKey\" is created\n";
206 if (reg_createKey(hRootKey2
, OUString::createFromAscii("reg2SecondKey").pData
, &h2Key2
))
207 cout
<< "\t24. creating key \"reg2SecondKey\" failed\n";
209 cout
<< "24. key \"reg2SecondKey\" is created\n";
210 if (reg_createKey(h2Key1
, OUString::createFromAscii("reg2FirstSubKey").pData
, &h2Key3
))
211 cout
<< "\t25. creating key \"reg2FirstSubKey\" failed\n";
213 cout
<< "25. key \"reg2FirstSubKey\" is created\n";
214 if (reg_createKey(h2Key1
, OUString::createFromAscii("reg2SecondSubKey").pData
, &h2Key4
))
215 cout
<< "\26. creating key \"reg2SecondSubKey\" failed\n";
217 cout
<< "26. key \"reg2SecondSubKey\" is created\n";
218 if (reg_createKey(hRootKey2
, OUString::createFromAscii("reg2ThirdKey").pData
, &h2Key5
))
219 cout
<< "\n27. creating key \"reg2ThirdKey\" failed\n";
221 cout
<< "27. key \"reg2ThirdKey\" is created\n";
223 sal_uInt32 nValue
= 123456789;
224 if (reg_setValue(h2Key3
, OUString().pData
, RG_VALUETYPE_LONG
, &nValue
, sizeof(sal_uInt32
)))
225 cout
<< "\t27.b) setValue of key \"reg2FirstSubKey\" failed\n";
227 cout
<< "27.b). setValue (long Value) of key \"reg2FirstSubKey\"\n";
229 if (reg_closeKey(h2Key1
) ||
230 reg_closeKey(h2Key2
) ||
231 reg_closeKey(h2Key3
) ||
232 reg_closeKey(h2Key4
) ||
233 reg_closeKey(h2Key5
))
234 cout
<< "\n\t28. closing keys of \"test5.rdb\" failed\n";
236 cout
<< "\n28. all keys of \"test5.rdb\" closed\n";
238 if (reg_closeKey(hRootKey2
))
239 cout
<< "\t29. root key of \"test5.rdb\" failed\n";
241 cout
<< "29. root key of \"test5.rdb\" is closed\n";
243 if (reg_closeRegistry(hReg2
))
244 cout
<< "\t30. registry test5.rdb is closed\n";
246 cout
<< "30. registry test5.rdb is closed\n";
248 if (reg_openRegistry(OUString::createFromAscii("test4.rdb").pData
, &hReg
, REG_READWRITE
))
249 cout
<< "\t31. registry test4.rdb is opened\n";
251 cout
<< "31. registry test4.rdb is opened\n";
253 if (reg_openRootKey(hReg
, &hRootKey
))
254 cout
<< "\t32. open root key of \"test4.rdb\" is failed\n";
256 cout
<< "32. root key of \"test4.rdb\" is opened\n";
258 if (reg_loadKey(hRootKey
, OUString::createFromAscii("allFromTest2").pData
,
259 OUString::createFromAscii("test5.rdb").pData
))
260 cout
<< "\n\t33. load all keys from \"test5.rdb\" under key \"allFromTest2\" failed\n";
262 cout
<< "\n33. load all keys from test5.rdb under key \"allFromTest2\"\n";
264 if (reg_saveKey(hRootKey
, OUString::createFromAscii("allFromTest2").pData
,
265 OUString::createFromAscii("test6.rdb").pData
))
266 cout
<< "\n\t34. save all keys under \"allFromTest2\" in test6.rdb\n";
268 cout
<< "\n34. save all keys under \"allFromTest2\" in test6.rdb\n";
271 if (reg_createKey(hRootKey
, OUString::createFromAscii("allFromTest3").pData
, &hKey1
))
272 cout
<< "\t35. creating key \"allFromTest3\" failed\n";
274 cout
<< "36. key \"allFromTest3\" is created\n";
275 if (reg_createKey(hKey1
, OUString::createFromAscii("myFirstKey2").pData
, &hKey2
))
276 cout
<< "\t37. creating key \"myFirstKey2\" failed\n";
278 cout
<< "37. key \"myFirstKey2\" is created\n";
279 if (reg_createKey(hKey1
, OUString::createFromAscii("mySecondKey2").pData
, &hKey3
))
280 cout
<< "\t38. creating key \"mySecondKey2\" failed\n";
282 cout
<< "38. key \"mySecondKey2\" is created\n";
284 if (reg_mergeKey(hRootKey
, OUString::createFromAscii("allFromTest3").pData
,
285 OUString::createFromAscii("test6.rdb").pData
, sal_False
, sal_False
))
286 cout
<< "\n\t39. merge all keys under \"allFromTest2\" with all in test6.rdb\n";
288 cout
<< "\n39. merge all keys under \"allFromTest2\" with all in test6.rdb\n";
290 if (reg_closeKey(hKey1
))
291 cout
<< "\n\t40. closing key \"allFromTest3\" of \"test5.rdb\" failed\n";
293 cout
<< "\n40. closing key \"allFromTest3\" of \"test5.rdb\"\n";
294 if (reg_closeKey(hKey2
))
295 cout
<< "\n\t41. closing key \"myFirstKey2\" of \"test5.rdb\" failed\n";
297 cout
<< "\n41. closing key \"myFirstKey2\" of \"test5.rdb\"\n";
298 if (reg_closeKey(hKey3
))
299 cout
<< "\n\t42. closing key \"mySecondKey2\" of \"test5.rdb\" failed\n";
301 cout
<< "\n42. closing key \"mySecondKey2\" of \"test5.rdb\"\n";
304 if (reg_deleteKey(hRootKey
, OUString::createFromAscii("/allFromTest3/reg2FirstKey/reg2FirstSubKey").pData
))
305 cout
<< "\n\t43. delete key \"/allFromTest3/reg2FirstKey/reg2FirstSubKey\" failed\n";
307 cout
<< "\n43. key \"/allFromTest3/reg2FirstKey/reg2FirstSubKey\" is deleted\n";
309 if (reg_openRegistry(OUString::createFromAscii("test4.rdb").pData
, &hReg2
, REG_READONLY
))
310 cout
<< "\n\t44. registry test4.rdb is opened for read only\n";
312 cout
<< "\n44. registry test4.rdb is opened for read only\n";
315 if (reg_openRegistry(OUString::createFromAscii("test4.rdb").pData
, &hReg3
, REG_READONLY
))
316 cout
<< "\n\t44.a). registry test4.rdb is opened for read only\n";
318 cout
<< "\n44.a). registry test4.rdb is opened for read only\n";
320 if (reg_closeRegistry(hReg2
))
321 cout
<< "\t45. closing registry \"test4.rdb\" failed\n";
323 cout
<< "45. registry \"test4.rdb\" is closed\n";
325 if (reg_closeKey(hRootKey
))
326 cout
<< "\n\t46. closing root key of \"test4.rdb\" failed\n";
328 cout
<< "\n46. root key of \"test4.rdb\" is closed\n";
330 if (reg_closeRegistry(hReg
))
331 cout
<< "\t47. closing registry \"test4.rdb\" failed\n";
333 cout
<< "47. registry \"test4.rdb\" is closed\n";
335 if (reg_closeRegistry(hReg3
))
336 cout
<< "\t47.a). closing registry \"test4.rdb\" failed\n";
338 cout
<< "47.a). registry \"test4.rdb\" is closed\n";