fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / registry / workben / regtest.cxx
blobcf6b06dfd03e007fd8294ddca56a07e8ccbf439a
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>
24 #include "registry/registry.h"
25 #include <rtl/ustring.hxx>
26 #include <rtl/alloc.h>
28 using namespace std;
31 #if (defined UNX)
32 int main()
33 #else
34 int _cdecl main()
35 #endif
37 RegHandle hReg;
38 RegKeyHandle hRootKey, hKey1, hKey2, hKey3, hKey4, hKey5;
40 cout << "\n Simple Registry Test !!! \n\n";
42 if (reg_createRegistry(OUString("test4.rdb").pData, &hReg))
43 cout << "\t0. creating registry \"test4.rdb\" failed\n";
44 else
45 cout << "0. registry test4.rdb is created\n";
47 if (reg_openRootKey(hReg, &hRootKey))
48 cout << "1. open root key \"test4.rdb\" failed\n";
49 else
50 cout << "1. root key of \"test4.rdb\" is opened\n";
52 if (reg_createKey(hRootKey, OUString("myFirstKey").pData, &hKey1))
53 cout << "\t2. creating key \"myFirstKey\" failed\n";
54 else
55 cout << "2. key \"myFirstKey\" is created\n";
56 if (reg_createKey(hRootKey, OUString("mySecondKey").pData, &hKey2))
57 cout << "\t3. creating key \"mySecondKey\" failed\n";
58 else
59 cout << "3. key \"mySecondKey\" is created\n";
60 if (reg_createKey(hKey1, OUString("myFirstSubKey").pData, &hKey3))
61 cout << "\t4. creating subkey \"myFirstSubKey\" failed\n";
62 else
63 cout << "4. subkey \"myFirstSubKey\" is created\n";
64 if (reg_createKey(hKey1, OUString("mySecondSubKey").pData, &hKey4))
65 cout << "\t5. creating subkey \"mySecondSubKey\" failed\n";
66 else
67 cout << "5. subkey \"mySecondSubKey\" is created\n";
68 if (reg_createKey(hRootKey, OUString("myThirdKey").pData, &hKey5))
69 cout << "\t6. creating key \"myThirdKey\" is created\n\n";
70 else
71 cout << "6. key \"myThirdKey\" is created\n\n";
74 RegKeyHandle* phSubKeys;
75 sal_uInt32 nSubKeys;
76 if (reg_openSubKeys(hRootKey, OUString("myFirstKey").pData, &phSubKeys, &nSubKeys))
77 cout << "\t7. open subkeys of \"myfirstKey\" failed\n";
78 else
79 cout << "7. open " << nSubKeys << "subkeys of \"myfirstKey\"\n";
81 OUString keyName;
82 if (reg_getKeyName(phSubKeys[0], &keyName.pData))
83 cout << "\tname of subkey 1 = " << OUStringToOString(keyName, RTL_TEXTENCODING_ASCII_US).getStr() << "\n";
84 if (reg_getKeyName(phSubKeys[1], &keyName.pData))
85 cout << "\tname of subkey 2 = " << OUStringToOString(keyName, RTL_TEXTENCODING_ASCII_US).getStr() << "\n";
87 if (reg_closeSubKeys(phSubKeys, nSubKeys))
88 cout << "\t8. close subkeys of \"myfirstKey\" failed\n\n";
89 else
90 cout << "8. close " << nSubKeys << "subkeys of \"myfirstKey\"\n\n";
93 char* Value=(char*)"Mein erster Value";
94 if (reg_setValue(hRootKey, OUString("mySecondKey").pData, RegValueType::STRING, Value, 18))
95 cout << "\t9. setValue of key \"mySecondKey\" failed\n";
96 else
97 cout << "9. setValue (string Value) of key \"mySecondKey\"\n";
99 RegValueType valueType;
100 sal_uInt32 valueSize;
101 sal_Char* readValue;
102 if (reg_getValueInfo(hRootKey, OUString("mySecondKey").pData, &valueType, &valueSize))
103 cout << "\t10. getValueInfo of key \"mySecondKey\" failed\n";
104 else
105 cout << "10. getValueInfo of key \"mySecondKey\"\n";
107 readValue = (sal_Char*)rtl_allocateMemory(valueSize);
108 if (reg_getValue(hKey2, OUString().pData, readValue))
109 cout << "\t11. getValue of key \"mySecondKey\" failed\n";
110 else
112 cout << "11. getValue of key \"mySecondKey\"\n";
114 cout << "read Value,\n\tvalueType = " << (long)valueType
115 << "\n\tvalueSize = " << valueSize
116 << "\n\tvalue = " << readValue << "\n\n";
118 rtl_freeMemory(readValue);
120 if (reg_closeKey(hKey1) ||
121 reg_closeKey(hKey3) ||
122 reg_closeKey(hKey4))
123 cout << "\t12. closing \"myFirstKey\" \"myfistSubKey\" \"mySecondSubKey\" failed\n";
124 else
125 cout << "12. keys \"myFirstKey\" \"myfistSubKey\" \"mySecondSubKey\" are closed\n";
127 if (reg_deleteKey(hRootKey, OUString("myFirstKey").pData))
128 cout << "13.\t delete key \"myFirstKey\" failed\n";
129 else
130 cout << "13. key \"myFirstKey\" is deleted\n";
132 if (reg_closeKey(hKey2))
133 cout << "\t14. closing key \"mySecondKey\" failed\n";
134 else
135 cout << "14. key \"mySecondKey\" is closed\n";
137 if (reg_openKey(hRootKey, OUString("mySecondKey").pData, &hKey2))
138 cout << "\n15. open key \"mySecondKey\" failed\n";
139 else
140 cout << "15. key \"mySecondKey\" is opended\n";
142 if (reg_closeKey(hKey5))
143 cout << "\t15. closing key \"myThirdSubKey\" failed\n";
144 else
145 cout << "15. key \"myThirdSubKey\" is closed\n";
146 if (reg_deleteKey(hRootKey, OUString("myThirdKey").pData))
147 cout << "\t16. delete key \"myThirdKey\" failed\n";
148 else
149 cout << "16. key \"myThirdKey\" is deleted\n";
151 if (reg_openKey(hRootKey, OUString("myThirdKey").pData, &hKey5))
152 cout << "\t17. open key \"myThirdKey\" failed\n";
153 else
154 cout << "17. key \"myThirdKey\" is opened\n";
156 cout << "\n close open keys\n\n";
158 if (reg_closeKey(hKey2))
159 cout << "\t18. closing key \"mySecondKey\" failed\n";
160 else
161 cout << "18. key \"mySecondKey\" is closed\n";
163 if (reg_closeKey(hRootKey))
164 cout << "\t19. closing root key failed\n";
165 else
166 cout << "19. root key is closed\n";
168 if (reg_closeRegistry(hReg))
169 cout << "\t20. closing registry \"test4.rdb\" failed\n";
170 else
171 cout << "20. registry \"test4.rdb\" is closed\n";
173 // Test loadkey
174 cout << "\nTest load key\n\n";
176 RegHandle hReg2;
177 RegKeyHandle hRootKey2, h2Key1, h2Key2, h2Key3, h2Key4, h2Key5;
179 if (reg_createRegistry(OUString("test5.rdb").pData, &hReg2))
180 cout << "\t21. creating registry \"test5.rdb\" failed\n";
181 else
182 cout << "21. registry \"test5.rdb\" is created\n";
184 if (reg_openRootKey(hReg2, &hRootKey2))
185 cout << "\t22. open root key of \"test5.rdb\" failed\n";
186 else
187 cout << "22. root key of \"test5.rdb\" is opened\n";
189 if (reg_createKey(hRootKey2, OUString("reg2FirstKey").pData, &h2Key1))
190 cout << "\t23. creating key \"reg2FirstKey\" failed\n";
191 else
192 cout << "23. key \"reg2FirstKey\" is created\n";
193 if (reg_createKey(hRootKey2, OUString("reg2SecondKey").pData, &h2Key2))
194 cout << "\t24. creating key \"reg2SecondKey\" failed\n";
195 else
196 cout << "24. key \"reg2SecondKey\" is created\n";
197 if (reg_createKey(h2Key1, OUString("reg2FirstSubKey").pData, &h2Key3))
198 cout << "\t25. creating key \"reg2FirstSubKey\" failed\n";
199 else
200 cout << "25. key \"reg2FirstSubKey\" is created\n";
201 if (reg_createKey(h2Key1, OUString("reg2SecondSubKey").pData, &h2Key4))
202 cout << "\26. creating key \"reg2SecondSubKey\" failed\n";
203 else
204 cout << "26. key \"reg2SecondSubKey\" is created\n";
205 if (reg_createKey(hRootKey2, OUString("reg2ThirdKey").pData, &h2Key5))
206 cout << "\n27. creating key \"reg2ThirdKey\" failed\n";
207 else
208 cout << "27. key \"reg2ThirdKey\" is created\n";
210 sal_uInt32 nValue= 123456789;
211 if (reg_setValue(h2Key3, OUString().pData, RegValueType::LONG, &nValue, sizeof(sal_uInt32)))
212 cout << "\t27.b) setValue of key \"reg2FirstSubKey\" failed\n";
213 else
214 cout << "27.b). setValue (long Value) of key \"reg2FirstSubKey\"\n";
216 if (reg_closeKey(h2Key1) ||
217 reg_closeKey(h2Key2) ||
218 reg_closeKey(h2Key3) ||
219 reg_closeKey(h2Key4) ||
220 reg_closeKey(h2Key5))
221 cout << "\n\t28. closing keys of \"test5.rdb\" failed\n";
222 else
223 cout << "\n28. all keys of \"test5.rdb\" closed\n";
225 if (reg_closeKey(hRootKey2))
226 cout << "\t29. root key of \"test5.rdb\" failed\n";
227 else
228 cout << "29. root key of \"test5.rdb\" is closed\n";
230 if (reg_closeRegistry(hReg2))
231 cout << "\t30. registry test5.rdb is closed\n";
232 else
233 cout << "30. registry test5.rdb is closed\n";
235 if (reg_openRegistry(OUString("test4.rdb").pData, &hReg, RegAccessMode::READWRITE))
236 cout << "\t31. registry test4.rdb is opened\n";
237 else
238 cout << "31. registry test4.rdb is opened\n";
240 if (reg_openRootKey(hReg, &hRootKey))
241 cout << "\t32. open root key of \"test4.rdb\" is failed\n";
242 else
243 cout << "32. root key of \"test4.rdb\" is opened\n";
245 if (reg_loadKey(hRootKey, OUString("allFromTest2").pData,
246 OUString("test5.rdb").pData))
247 cout << "\n\t33. load all keys from \"test5.rdb\" under key \"allFromTest2\" failed\n";
248 else
249 cout << "\n33. load all keys from test5.rdb under key \"allFromTest2\"\n";
251 if (reg_saveKey(hRootKey, OUString("allFromTest2").pData,
252 OUString("test6.rdb").pData))
253 cout << "\n\t34. save all keys under \"allFromTest2\" in test6.rdb\n";
254 else
255 cout << "\n34. save all keys under \"allFromTest2\" in test6.rdb\n";
258 if (reg_createKey(hRootKey, OUString("allFromTest3").pData, &hKey1))
259 cout << "\t35. creating key \"allFromTest3\" failed\n";
260 else
261 cout << "36. key \"allFromTest3\" is created\n";
262 if (reg_createKey(hKey1, OUString("myFirstKey2").pData, &hKey2))
263 cout << "\t37. creating key \"myFirstKey2\" failed\n";
264 else
265 cout << "37. key \"myFirstKey2\" is created\n";
266 if (reg_createKey(hKey1, OUString("mySecondKey2").pData, &hKey3))
267 cout << "\t38. creating key \"mySecondKey2\" failed\n";
268 else
269 cout << "38. key \"mySecondKey2\" is created\n";
271 if (reg_mergeKey(hRootKey, OUString("allFromTest3").pData,
272 OUString("test6.rdb").pData, sal_False, sal_False))
273 cout << "\n\t39. merge all keys under \"allFromTest2\" with all in test6.rdb\n";
274 else
275 cout << "\n39. merge all keys under \"allFromTest2\" with all in test6.rdb\n";
277 if (reg_closeKey(hKey1))
278 cout << "\n\t40. closing key \"allFromTest3\" of \"test5.rdb\" failed\n";
279 else
280 cout << "\n40. closing key \"allFromTest3\" of \"test5.rdb\"\n";
281 if (reg_closeKey(hKey2))
282 cout << "\n\t41. closing key \"myFirstKey2\" of \"test5.rdb\" failed\n";
283 else
284 cout << "\n41. closing key \"myFirstKey2\" of \"test5.rdb\"\n";
285 if (reg_closeKey(hKey3))
286 cout << "\n\t42. closing key \"mySecondKey2\" of \"test5.rdb\" failed\n";
287 else
288 cout << "\n42. closing key \"mySecondKey2\" of \"test5.rdb\"\n";
291 if (reg_deleteKey(hRootKey, OUString("/allFromTest3/reg2FirstKey/reg2FirstSubKey").pData))
292 cout << "\n\t43. delete key \"/allFromTest3/reg2FirstKey/reg2FirstSubKey\" failed\n";
293 else
294 cout << "\n43. key \"/allFromTest3/reg2FirstKey/reg2FirstSubKey\" is deleted\n";
296 if (reg_openRegistry(OUString("test4.rdb").pData, &hReg2, RegAccessMode::READONLY))
297 cout << "\n\t44. registry test4.rdb is opened for read only\n";
298 else
299 cout << "\n44. registry test4.rdb is opened for read only\n";
301 RegHandle hReg3;
302 if (reg_openRegistry(OUString("test4.rdb").pData, &hReg3, RegAccessMode::READONLY))
303 cout << "\n\t44.a). registry test4.rdb is opened for read only\n";
304 else
305 cout << "\n44.a). registry test4.rdb is opened for read only\n";
307 if (reg_closeRegistry(hReg2))
308 cout << "\t45. closing registry \"test4.rdb\" failed\n";
309 else
310 cout << "45. registry \"test4.rdb\" is closed\n";
312 if (reg_closeKey(hRootKey))
313 cout << "\n\t46. closing root key of \"test4.rdb\" failed\n";
314 else
315 cout << "\n46. root key of \"test4.rdb\" is closed\n";
317 if (reg_closeRegistry(hReg))
318 cout << "\t47. closing registry \"test4.rdb\" failed\n";
319 else
320 cout << "47. registry \"test4.rdb\" is closed\n";
322 if (reg_closeRegistry(hReg3))
323 cout << "\t47.a). closing registry \"test4.rdb\" failed\n";
324 else
325 cout << "47.a). registry \"test4.rdb\" is closed\n";
327 return 0;
331 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */