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