cut out noise in junit stacktrace for output, but keep them in log
[LibreOffice.git] / registry / workben / regtest.cxx
blobef9c106fd0ccee0e97a6a830f6da8ddb07a1d9db
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 // MARKER(update_precomp.py): autogen include statement, do not remove
30 #include "precompiled_registry.hxx"
32 #include <iostream>
33 #include <stdio.h>
35 #include "registry/registry.h"
36 #include <rtl/ustring.hxx>
37 #include <rtl/alloc.h>
39 using namespace std;
41 using ::rtl::OUString;
42 using ::rtl::OUStringToOString;
44 #if (defined UNX)
45 int main()
46 #else
47 int _cdecl main()
48 #endif
50 RegHandle hReg;
51 RegKeyHandle hRootKey, hKey1, hKey2, hKey3, hKey4, hKey5;
53 cout << "\n Simple Registry Test !!! \n\n";
55 if (reg_createRegistry(OUString(RTL_CONSTASCII_USTRINGPARAM("test4.rdb")).pData, &hReg))
56 cout << "\t0. creating registry \"test4.rdb\" failed\n";
57 else
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";
62 else
63 cout << "1. root key of \"test4.rdb\" is opened\n";
65 if (reg_createKey(hRootKey, OUString(RTL_CONSTASCII_USTRINGPARAM("myFirstKey")).pData, &hKey1))
66 cout << "\t2. creating key \"myFirstKey\" failed\n";
67 else
68 cout << "2. key \"myFirstKey\" is created\n";
69 if (reg_createKey(hRootKey, OUString(RTL_CONSTASCII_USTRINGPARAM("mySecondKey")).pData, &hKey2))
70 cout << "\t3. creating key \"mySecondKey\" failed\n";
71 else
72 cout << "3. key \"mySecondKey\" is created\n";
73 if (reg_createKey(hKey1, OUString(RTL_CONSTASCII_USTRINGPARAM("myFirstSubKey")).pData, &hKey3))
74 cout << "\t4. creating subkey \"myFirstSubKey\" failed\n";
75 else
76 cout << "4. subkey \"myFirstSubKey\" is created\n";
77 if (reg_createKey(hKey1, OUString(RTL_CONSTASCII_USTRINGPARAM("mySecondSubKey")).pData, &hKey4))
78 cout << "\t5. creating subkey \"mySecondSubKey\" failed\n";
79 else
80 cout << "5. subkey \"mySecondSubKey\" is created\n";
81 if (reg_createKey(hRootKey, OUString(RTL_CONSTASCII_USTRINGPARAM("myThirdKey")).pData, &hKey5))
82 cout << "\t6. creating key \"myThirdKey\" is created\n\n";
83 else
84 cout << "6. key \"myThirdKey\" is created\n\n";
87 RegKeyHandle* phSubKeys;
88 sal_uInt32 nSubKeys;
89 if (reg_openSubKeys(hRootKey, OUString(RTL_CONSTASCII_USTRINGPARAM("myFirstKey")).pData, &phSubKeys, &nSubKeys))
90 cout << "\t7. open subkeys of \"myfirstKey\" failed\n";
91 else
92 cout << "7. open " << nSubKeys << "subkeys of \"myfirstKey\"\n";
94 OUString keyName;
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";
102 else
103 cout << "8. close " << nSubKeys << "subkeys of \"myfirstKey\"\n\n";
106 char* Value=(char*)"Mein erster Value";
107 if (reg_setValue(hRootKey, OUString(RTL_CONSTASCII_USTRINGPARAM("mySecondKey")).pData, RG_VALUETYPE_STRING, Value, 18))
108 cout << "\t9. setValue of key \"mySecondKey\" failed\n";
109 else
110 cout << "9. setValue (string Value) of key \"mySecondKey\"\n";
112 RegValueType valueType;
113 sal_uInt32 valueSize;
114 sal_Char* readValue;
115 if (reg_getValueInfo(hRootKey, OUString(RTL_CONSTASCII_USTRINGPARAM("mySecondKey")).pData, &valueType, &valueSize))
116 cout << "\t10. getValueInfo of key \"mySecondKey\" failed\n";
117 else
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";
123 else
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) ||
135 reg_closeKey(hKey4))
136 cout << "\t12. closing \"myFirstKey\" \"myfistSubKey\" \"mySecondSubKey\" failed\n";
137 else
138 cout << "12. keys \"myFirstKey\" \"myfistSubKey\" \"mySecondSubKey\" are closed\n";
140 if (reg_deleteKey(hRootKey, OUString(RTL_CONSTASCII_USTRINGPARAM("myFirstKey")).pData))
141 cout << "13.\t delete key \"myFirstKey\" failed\n";
142 else
143 cout << "13. key \"myFirstKey\" is deleted\n";
145 if (reg_closeKey(hKey2))
146 cout << "\t14. closing key \"mySecondKey\" failed\n";
147 else
148 cout << "14. key \"mySecondKey\" is closed\n";
150 if (reg_openKey(hRootKey, OUString(RTL_CONSTASCII_USTRINGPARAM("mySecondKey")).pData, &hKey2))
151 cout << "\n15. open key \"mySecondKey\" failed\n";
152 else
153 cout << "15. key \"mySecondKey\" is opended\n";
155 if (reg_closeKey(hKey5))
156 cout << "\t15. closing key \"myThirdSubKey\" failed\n";
157 else
158 cout << "15. key \"myThirdSubKey\" is closed\n";
159 if (reg_deleteKey(hRootKey, OUString(RTL_CONSTASCII_USTRINGPARAM("myThirdKey")).pData))
160 cout << "\t16. delete key \"myThirdKey\" failed\n";
161 else
162 cout << "16. key \"myThirdKey\" is deleted\n";
164 if (reg_openKey(hRootKey, OUString(RTL_CONSTASCII_USTRINGPARAM("myThirdKey")).pData, &hKey5))
165 cout << "\t17. open key \"myThirdKey\" failed\n";
166 else
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";
173 else
174 cout << "18. key \"mySecondKey\" is closed\n";
176 if (reg_closeKey(hRootKey))
177 cout << "\t19. closing root key failed\n";
178 else
179 cout << "19. root key is closed\n";
181 if (reg_closeRegistry(hReg))
182 cout << "\t20. closing registry \"test4.rdb\" failed\n";
183 else
184 cout << "20. registry \"test4.rdb\" is closed\n";
186 // Test loadkey
187 cout << "\nTest load key\n\n";
189 RegHandle hReg2;
190 RegKeyHandle hRootKey2, h2Key1, h2Key2, h2Key3, h2Key4, h2Key5;
192 if (reg_createRegistry(OUString(RTL_CONSTASCII_USTRINGPARAM("test5.rdb")).pData, &hReg2))
193 cout << "\t21. creating registry \"test5.rdb\" failed\n";
194 else
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";
199 else
200 cout << "22. root key of \"test5.rdb\" is opened\n";
202 if (reg_createKey(hRootKey2, OUString(RTL_CONSTASCII_USTRINGPARAM("reg2FirstKey")).pData, &h2Key1))
203 cout << "\t23. creating key \"reg2FirstKey\" failed\n";
204 else
205 cout << "23. key \"reg2FirstKey\" is created\n";
206 if (reg_createKey(hRootKey2, OUString(RTL_CONSTASCII_USTRINGPARAM("reg2SecondKey")).pData, &h2Key2))
207 cout << "\t24. creating key \"reg2SecondKey\" failed\n";
208 else
209 cout << "24. key \"reg2SecondKey\" is created\n";
210 if (reg_createKey(h2Key1, OUString(RTL_CONSTASCII_USTRINGPARAM("reg2FirstSubKey")).pData, &h2Key3))
211 cout << "\t25. creating key \"reg2FirstSubKey\" failed\n";
212 else
213 cout << "25. key \"reg2FirstSubKey\" is created\n";
214 if (reg_createKey(h2Key1, OUString(RTL_CONSTASCII_USTRINGPARAM("reg2SecondSubKey")).pData, &h2Key4))
215 cout << "\26. creating key \"reg2SecondSubKey\" failed\n";
216 else
217 cout << "26. key \"reg2SecondSubKey\" is created\n";
218 if (reg_createKey(hRootKey2, OUString(RTL_CONSTASCII_USTRINGPARAM("reg2ThirdKey")).pData, &h2Key5))
219 cout << "\n27. creating key \"reg2ThirdKey\" failed\n";
220 else
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";
226 else
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";
235 else
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";
240 else
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";
245 else
246 cout << "30. registry test5.rdb is closed\n";
248 if (reg_openRegistry(OUString(RTL_CONSTASCII_USTRINGPARAM("test4.rdb")).pData, &hReg, REG_READWRITE))
249 cout << "\t31. registry test4.rdb is opened\n";
250 else
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";
255 else
256 cout << "32. root key of \"test4.rdb\" is opened\n";
258 if (reg_loadKey(hRootKey, OUString(RTL_CONSTASCII_USTRINGPARAM("allFromTest2")).pData,
259 OUString(RTL_CONSTASCII_USTRINGPARAM("test5.rdb")).pData))
260 cout << "\n\t33. load all keys from \"test5.rdb\" under key \"allFromTest2\" failed\n";
261 else
262 cout << "\n33. load all keys from test5.rdb under key \"allFromTest2\"\n";
264 if (reg_saveKey(hRootKey, OUString(RTL_CONSTASCII_USTRINGPARAM("allFromTest2")).pData,
265 OUString(RTL_CONSTASCII_USTRINGPARAM("test6.rdb")).pData))
266 cout << "\n\t34. save all keys under \"allFromTest2\" in test6.rdb\n";
267 else
268 cout << "\n34. save all keys under \"allFromTest2\" in test6.rdb\n";
271 if (reg_createKey(hRootKey, OUString(RTL_CONSTASCII_USTRINGPARAM("allFromTest3")).pData, &hKey1))
272 cout << "\t35. creating key \"allFromTest3\" failed\n";
273 else
274 cout << "36. key \"allFromTest3\" is created\n";
275 if (reg_createKey(hKey1, OUString(RTL_CONSTASCII_USTRINGPARAM("myFirstKey2")).pData, &hKey2))
276 cout << "\t37. creating key \"myFirstKey2\" failed\n";
277 else
278 cout << "37. key \"myFirstKey2\" is created\n";
279 if (reg_createKey(hKey1, OUString(RTL_CONSTASCII_USTRINGPARAM("mySecondKey2")).pData, &hKey3))
280 cout << "\t38. creating key \"mySecondKey2\" failed\n";
281 else
282 cout << "38. key \"mySecondKey2\" is created\n";
284 if (reg_mergeKey(hRootKey, OUString(RTL_CONSTASCII_USTRINGPARAM("allFromTest3")).pData,
285 OUString(RTL_CONSTASCII_USTRINGPARAM("test6.rdb")).pData, sal_False, sal_False))
286 cout << "\n\t39. merge all keys under \"allFromTest2\" with all in test6.rdb\n";
287 else
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";
292 else
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";
296 else
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";
300 else
301 cout << "\n42. closing key \"mySecondKey2\" of \"test5.rdb\"\n";
304 if (reg_deleteKey(hRootKey, OUString(RTL_CONSTASCII_USTRINGPARAM("/allFromTest3/reg2FirstKey/reg2FirstSubKey")).pData))
305 cout << "\n\t43. delete key \"/allFromTest3/reg2FirstKey/reg2FirstSubKey\" failed\n";
306 else
307 cout << "\n43. key \"/allFromTest3/reg2FirstKey/reg2FirstSubKey\" is deleted\n";
309 if (reg_openRegistry(OUString(RTL_CONSTASCII_USTRINGPARAM("test4.rdb")).pData, &hReg2, REG_READONLY))
310 cout << "\n\t44. registry test4.rdb is opened for read only\n";
311 else
312 cout << "\n44. registry test4.rdb is opened for read only\n";
314 RegHandle hReg3;
315 if (reg_openRegistry(OUString(RTL_CONSTASCII_USTRINGPARAM("test4.rdb")).pData, &hReg3, REG_READONLY))
316 cout << "\n\t44.a). registry test4.rdb is opened for read only\n";
317 else
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";
322 else
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";
327 else
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";
332 else
333 cout << "47. registry \"test4.rdb\" is closed\n";
335 if (reg_closeRegistry(hReg3))
336 cout << "\t47.a). closing registry \"test4.rdb\" failed\n";
337 else
338 cout << "47.a). registry \"test4.rdb\" is closed\n";
340 return(0);
344 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */