xref: /trunk/main/registry/workben/regtest.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_registry.hxx"
30 
31 #include <iostream>
32 #include <stdio.h>
33 
34 #include "registry/registry.h"
35 #include	<rtl/ustring.hxx>
36 #include	<rtl/alloc.h>
37 
38 using namespace std;
39 using namespace rtl;
40 
41 #if (defined UNX) || (defined OS2)
42 int main()
43 #else
44 int _cdecl main()
45 #endif
46 {
47 	RegHandle 		hReg;
48 	RegKeyHandle	hRootKey, hKey1, hKey2, hKey3, hKey4, hKey5;
49 
50 	cout << "\n     Simple Registry Test !!!     \n\n";
51 
52 	if (reg_createRegistry(OUString::createFromAscii("test4.rdb").pData, &hReg))
53 		cout << "\t0. creating registry \"test4.rdb\" failed\n";
54 	else
55 		cout << "0. registry test4.rdb is created\n";
56 
57 	if (reg_openRootKey(hReg, &hRootKey))
58 		cout << "1. open root key \"test4.rdb\" failed\n";
59 	else
60 		cout << "1. root key of \"test4.rdb\" is opened\n";
61 
62 	if (reg_createKey(hRootKey, OUString::createFromAscii("myFirstKey").pData, &hKey1))
63 		cout << "\t2. creating key \"myFirstKey\" failed\n";
64 	else
65 		cout << "2. key \"myFirstKey\" is created\n";
66 	if (reg_createKey(hRootKey, OUString::createFromAscii("mySecondKey").pData, &hKey2))
67 		cout << "\t3. creating key \"mySecondKey\" failed\n";
68 	else
69 		cout << "3. key \"mySecondKey\" is created\n";
70 	if (reg_createKey(hKey1, OUString::createFromAscii("myFirstSubKey").pData, &hKey3))
71 		cout << "\t4. creating subkey \"myFirstSubKey\" failed\n";
72 	else
73 		cout << "4. subkey \"myFirstSubKey\" is created\n";
74 	if (reg_createKey(hKey1, OUString::createFromAscii("mySecondSubKey").pData, &hKey4))
75 		cout << "\t5. creating subkey \"mySecondSubKey\" failed\n";
76 	else
77 		cout << "5. subkey \"mySecondSubKey\" is created\n";
78 	if (reg_createKey(hRootKey, OUString::createFromAscii("myThirdKey").pData, &hKey5))
79 		cout << "\t6. creating key \"myThirdKey\" is created\n\n";
80 	else
81 		cout << "6. key \"myThirdKey\" is created\n\n";
82 
83 
84 	RegKeyHandle* 	phSubKeys;
85 	sal_uInt32		nSubKeys;
86 	if (reg_openSubKeys(hRootKey, OUString::createFromAscii("myFirstKey").pData, &phSubKeys, &nSubKeys))
87 		cout << "\t7. open subkeys of \"myfirstKey\" failed\n";
88 	else
89 		cout << "7. open " << nSubKeys << "subkeys of \"myfirstKey\"\n";
90 
91 	OUString keyName;
92 	if (reg_getKeyName(phSubKeys[0], &keyName.pData))
93 		cout << "\tname of subkey 1 = " << OUStringToOString(keyName, RTL_TEXTENCODING_ASCII_US).getStr() << "\n";
94 	if (reg_getKeyName(phSubKeys[1], &keyName.pData))
95 		cout << "\tname of subkey 2 = " << OUStringToOString(keyName, RTL_TEXTENCODING_ASCII_US).getStr() << "\n";
96 
97 	if (reg_closeSubKeys(phSubKeys, nSubKeys))
98 		cout << "\t8. close subkeys of \"myfirstKey\" failed\n\n";
99 	else
100 		cout << "8. close " << nSubKeys << "subkeys of \"myfirstKey\"\n\n";
101 
102 
103 	char* Value=(char*)"Mein erster Value";
104 	if (reg_setValue(hRootKey, OUString::createFromAscii("mySecondKey").pData, RG_VALUETYPE_STRING, Value, 18))
105 		cout << "\t9. setValue of key \"mySecondKey\" failed\n";
106 	else
107 		cout << "9. setValue (string Value)  of key \"mySecondKey\"\n";
108 
109 	RegValueType 	valueType;
110 	sal_uInt32		valueSize;
111 	sal_Char*		readValue;
112 	if (reg_getValueInfo(hRootKey, OUString::createFromAscii("mySecondKey").pData, &valueType, &valueSize))
113 		cout << "\t10. getValueInfo of key \"mySecondKey\" failed\n";
114 	else
115 		cout << "10. getValueInfo of key \"mySecondKey\"\n";
116 
117 	readValue = (sal_Char*)rtl_allocateMemory(valueSize);
118 	if (reg_getValue(hKey2, OUString().pData, readValue))
119 		cout << "\t11. getValue of key \"mySecondKey\" failed\n";
120 	else
121 	{
122 		cout << "11. getValue of key \"mySecondKey\"\n";
123 
124 		cout << "read Value,\n\tvalueType = " << (long)valueType
125 		 	 << "\n\tvalueSize = " << valueSize
126 			 << "\n\tvalue = " << readValue << "\n\n";
127 	}
128 	rtl_freeMemory(readValue);
129 
130 	if (reg_closeKey(hKey1) ||
131 		reg_closeKey(hKey3) ||
132 		reg_closeKey(hKey4))
133 		cout << "\t12. closing \"myFirstKey\" \"myfistSubKey\" \"mySecondSubKey\" failed\n";
134 	else
135 		cout << "12. keys \"myFirstKey\" \"myfistSubKey\" \"mySecondSubKey\" are closed\n";
136 
137 	if (reg_deleteKey(hRootKey, OUString::createFromAscii("myFirstKey").pData))
138 		cout << "13.\t delete key \"myFirstKey\" failed\n";
139 	else
140 		cout << "13. key \"myFirstKey\" is deleted\n";
141 
142 	if (reg_closeKey(hKey2))
143 		cout << "\t14. closing key \"mySecondKey\" failed\n";
144 	else
145 		cout << "14. key \"mySecondKey\" is closed\n";
146 
147 	if (reg_openKey(hRootKey, OUString::createFromAscii("mySecondKey").pData, &hKey2))
148 		cout << "\n15. open key \"mySecondKey\" failed\n";
149 	else
150 		cout << "15. key \"mySecondKey\" is opended\n";
151 
152 	if (reg_closeKey(hKey5))
153 		cout << "\t15. closing key \"myThirdSubKey\" failed\n";
154 	else
155 		cout << "15. key \"myThirdSubKey\" is closed\n";
156 	if (reg_deleteKey(hRootKey, OUString::createFromAscii("myThirdKey").pData))
157 		cout << "\t16. delete key \"myThirdKey\" failed\n";
158 	else
159 		cout << "16. key \"myThirdKey\" is deleted\n";
160 
161 	if (reg_openKey(hRootKey, OUString::createFromAscii("myThirdKey").pData, &hKey5))
162 		cout << "\t17. open key \"myThirdKey\" failed\n";
163 	else
164 		cout << "17. key \"myThirdKey\" is opened\n";
165 
166 	cout << "\n close open keys\n\n";
167 
168 	if (reg_closeKey(hKey2))
169 		cout << "\t18. closing key \"mySecondKey\" failed\n";
170 	else
171 		cout << "18. key \"mySecondKey\" is closed\n";
172 
173 	if (reg_closeKey(hRootKey))
174 		cout << "\t19. closing root key failed\n";
175 	else
176 		cout << "19. root key is closed\n";
177 
178 	if (reg_closeRegistry(hReg))
179 		cout << "\t20. closing registry \"test4.rdb\" failed\n";
180 	else
181 		cout << "20. registry \"test4.rdb\" is closed\n";
182 
183 	// Test loadkey
184 	cout << "\nTest load key\n\n";
185 
186 	RegHandle 		hReg2;
187 	RegKeyHandle	hRootKey2, h2Key1, h2Key2, h2Key3, h2Key4, h2Key5;
188 
189 	if (reg_createRegistry(OUString::createFromAscii("test5.rdb").pData, &hReg2))
190 		cout << "\t21. creating registry \"test5.rdb\" failed\n";
191 	else
192 		cout << "21. registry \"test5.rdb\" is created\n";
193 
194 	if (reg_openRootKey(hReg2, &hRootKey2))
195 		cout << "\t22. open root key of \"test5.rdb\" failed\n";
196 	else
197 		cout << "22. root key of \"test5.rdb\" is opened\n";
198 
199 	if (reg_createKey(hRootKey2, OUString::createFromAscii("reg2FirstKey").pData, &h2Key1))
200 		cout << "\t23. creating key \"reg2FirstKey\" failed\n";
201 	else
202 		cout << "23. key \"reg2FirstKey\" is created\n";
203 	if (reg_createKey(hRootKey2, OUString::createFromAscii("reg2SecondKey").pData, &h2Key2))
204 		cout << "\t24. creating key \"reg2SecondKey\" failed\n";
205 	else
206 		cout << "24. key \"reg2SecondKey\" is created\n";
207 	if (reg_createKey(h2Key1, OUString::createFromAscii("reg2FirstSubKey").pData, &h2Key3))
208 		cout << "\t25. creating key \"reg2FirstSubKey\" failed\n";
209 	else
210 		cout << "25. key \"reg2FirstSubKey\" is created\n";
211 	if (reg_createKey(h2Key1, OUString::createFromAscii("reg2SecondSubKey").pData, &h2Key4))
212 		cout << "\26. creating key \"reg2SecondSubKey\" failed\n";
213 	else
214 		cout << "26. key \"reg2SecondSubKey\" is created\n";
215 	if (reg_createKey(hRootKey2, OUString::createFromAscii("reg2ThirdKey").pData, &h2Key5))
216 		cout << "\n27. creating key \"reg2ThirdKey\" failed\n";
217 	else
218 		cout << "27. key \"reg2ThirdKey\" is created\n";
219 
220 	sal_uInt32 nValue= 123456789;
221 	if (reg_setValue(h2Key3, OUString().pData, RG_VALUETYPE_LONG, &nValue, sizeof(sal_uInt32)))
222 		cout << "\t27.b) setValue of key \"reg2FirstSubKey\" failed\n";
223 	else
224 		cout << "27.b). setValue (long Value)  of key \"reg2FirstSubKey\"\n";
225 
226 	if (reg_closeKey(h2Key1) ||
227 		reg_closeKey(h2Key2) ||
228 		reg_closeKey(h2Key3) ||
229 		reg_closeKey(h2Key4) ||
230 		reg_closeKey(h2Key5))
231 		cout << "\n\t28. closing keys of \"test5.rdb\" failed\n";
232 	else
233 		cout << "\n28. all keys of \"test5.rdb\" closed\n";
234 
235 	if (reg_closeKey(hRootKey2))
236 		cout << "\t29. root key of \"test5.rdb\" failed\n";
237 	else
238 		cout << "29. root key of \"test5.rdb\" is closed\n";
239 
240 	if (reg_closeRegistry(hReg2))
241 		cout << "\t30. registry test5.rdb is closed\n";
242 	else
243 		cout << "30. registry test5.rdb is closed\n";
244 
245 	if (reg_openRegistry(OUString::createFromAscii("test4.rdb").pData, &hReg, REG_READWRITE))
246 		cout << "\t31. registry test4.rdb is opened\n";
247 	else
248 		cout << "31. registry test4.rdb is opened\n";
249 
250 	if (reg_openRootKey(hReg, &hRootKey))
251 		cout << "\t32. open root key of \"test4.rdb\" is failed\n";
252 	else
253 		cout << "32. root key of \"test4.rdb\" is opened\n";
254 
255 	if (reg_loadKey(hRootKey, OUString::createFromAscii("allFromTest2").pData,
256 					OUString::createFromAscii("test5.rdb").pData))
257 		cout << "\n\t33. load all keys from \"test5.rdb\" under key \"allFromTest2\" failed\n";
258 	else
259 		cout << "\n33. load all keys from test5.rdb under key \"allFromTest2\"\n";
260 
261 	if (reg_saveKey(hRootKey, OUString::createFromAscii("allFromTest2").pData,
262 					OUString::createFromAscii("test6.rdb").pData))
263 		cout << "\n\t34. save all keys under \"allFromTest2\" in test6.rdb\n";
264 	else
265 		cout << "\n34. save all keys under \"allFromTest2\" in test6.rdb\n";
266 
267 
268 	if (reg_createKey(hRootKey, OUString::createFromAscii("allFromTest3").pData, &hKey1))
269 		cout << "\t35. creating key \"allFromTest3\" failed\n";
270 	else
271 		cout << "36. key \"allFromTest3\" is created\n";
272 	if (reg_createKey(hKey1, OUString::createFromAscii("myFirstKey2").pData, &hKey2))
273 		cout << "\t37. creating key \"myFirstKey2\" failed\n";
274 	else
275 		cout << "37. key \"myFirstKey2\" is created\n";
276 	if (reg_createKey(hKey1, OUString::createFromAscii("mySecondKey2").pData, &hKey3))
277 		cout << "\t38. creating key \"mySecondKey2\" failed\n";
278 	else
279 		cout << "38. key \"mySecondKey2\" is created\n";
280 
281 	if (reg_mergeKey(hRootKey, OUString::createFromAscii("allFromTest3").pData,
282 					OUString::createFromAscii("test6.rdb").pData, sal_False, sal_False))
283 		cout << "\n\t39. merge all keys under \"allFromTest2\" with all in test6.rdb\n";
284 	else
285 		cout << "\n39. merge all keys under \"allFromTest2\" with all in test6.rdb\n";
286 
287 	if (reg_closeKey(hKey1))
288 		cout << "\n\t40. closing key \"allFromTest3\" of \"test5.rdb\" failed\n";
289 	else
290 		cout << "\n40. closing key \"allFromTest3\" of \"test5.rdb\"\n";
291 	if (reg_closeKey(hKey2))
292 		cout << "\n\t41. closing key \"myFirstKey2\" of \"test5.rdb\" failed\n";
293 	else
294 		cout << "\n41. closing key \"myFirstKey2\" of \"test5.rdb\"\n";
295 	if (reg_closeKey(hKey3))
296 		cout << "\n\t42. closing key \"mySecondKey2\" of \"test5.rdb\" failed\n";
297 	else
298 		cout << "\n42. closing key \"mySecondKey2\" of \"test5.rdb\"\n";
299 
300 
301 	if (reg_deleteKey(hRootKey, OUString::createFromAscii("/allFromTest3/reg2FirstKey/reg2FirstSubKey").pData))
302 		cout << "\n\t43. delete key \"/allFromTest3/reg2FirstKey/reg2FirstSubKey\" failed\n";
303 	else
304 		cout << "\n43. key \"/allFromTest3/reg2FirstKey/reg2FirstSubKey\" is deleted\n";
305 
306 	if (reg_openRegistry(OUString::createFromAscii("test4.rdb").pData, &hReg2, REG_READONLY))
307 		cout << "\n\t44. registry test4.rdb is opened for read only\n";
308 	else
309 		cout << "\n44. registry test4.rdb is opened for read only\n";
310 
311 	RegHandle hReg3;
312 	if (reg_openRegistry(OUString::createFromAscii("test4.rdb").pData, &hReg3, REG_READONLY))
313 		cout << "\n\t44.a). registry test4.rdb is opened for read only\n";
314 	else
315 		cout << "\n44.a). registry test4.rdb is opened for read only\n";
316 
317 	if (reg_closeRegistry(hReg2))
318 		cout << "\t45. closing registry \"test4.rdb\" failed\n";
319 	else
320 		cout << "45. registry \"test4.rdb\" is closed\n";
321 
322 	if (reg_closeKey(hRootKey))
323 		cout << "\n\t46. closing root key of \"test4.rdb\" failed\n";
324 	else
325 		cout << "\n46. root key of \"test4.rdb\" is closed\n";
326 
327 	if (reg_closeRegistry(hReg))
328 		cout << "\t47. closing registry \"test4.rdb\" failed\n";
329 	else
330 		cout << "47. registry \"test4.rdb\" is closed\n";
331 
332 	if (reg_closeRegistry(hReg3))
333 		cout << "\t47.a). closing registry \"test4.rdb\" failed\n";
334 	else
335 		cout << "47.a). registry \"test4.rdb\" is closed\n";
336 
337 	return(0);
338 }
339 
340 
341