2 * Registry testing program
4 * The return codes were generated in an NT40 environment, using lcc-win32
6 * Copyright 1998 by Matthew Becker (mbecker@glasscity.net)
17 * NOTES: These individual routines are listed in alphabetical order.
20 /******************************************************************************
27 fprintf(stderr, "Testing RegCloseKey...\n");
30 lSts = RegCloseKey(hkey);
31 if (lSts != ERROR_INVALID_HANDLE) fprintf(stderr, " 1:%ld\n",lSts);
34 lSts = RegCloseKey(hkey);
35 if (lSts != ERROR_INVALID_HANDLE) fprintf(stderr, " 2:%ld\n",lSts);
37 lSts = RegCloseKey(HKEY_LOCAL_MACHINE);
38 if (lSts != ERROR_SUCCESS) fprintf(stderr, " 3:%ld\n",lSts);
40 lSts = RegCloseKey(HKEY_LOCAL_MACHINE);
41 if (lSts != ERROR_SUCCESS) fprintf(stderr, " 4:%ld\n",lSts);
44 /******************************************************************************
47 void TestConnectRegistry()
51 fprintf(stderr, "Testing RegConnectRegistry...\n");
53 lSts = RegConnectRegistry("",0,&hkey);
54 if (lSts != ERROR_SUCCESS) fprintf(stderr, " 1:%ld\n",lSts);
56 lSts = RegConnectRegistry("",HKEY_LOCAL_MACHINE,&hkey);
57 if (lSts != ERROR_SUCCESS) fprintf(stderr, " 2:%ld\n",lSts);
60 /******************************************************************************
69 fprintf(stderr, "Testing RegCreateKey...\n");
72 lSts = RegCreateKey(hKeyIn,"",&hkey);
73 if (lSts != ERROR_BADKEY) fprintf(stderr, " 1:%ld\n",lSts);
75 lSts = RegCreateKey(HKEY_LOCAL_MACHINE,"\\asdf",&hkey);
76 if (lSts != ERROR_BAD_PATHNAME) fprintf(stderr, " 2:%ld\n",lSts);
79 /******************************************************************************
82 void TestCreateKeyEx()
89 fprintf(stderr, "Testing RegCreateKeyEx...\n");
92 lSts = RegCreateKeyEx(hKeyIn,"",0,"",0,0,NULL,&hkey,&dwDisp);
93 if (lSts != ERROR_SUCCESS) fprintf(stderr, " 1:%ld\n",lSts);
95 lSts = RegCreateKeyEx(hKeyIn,"regtest",0,"",0,0,NULL,&hkey,&dwDisp);
96 if (lSts != ERROR_SUCCESS) fprintf(stderr, " 2:%ld\n",lSts);
98 lSts = RegCreateKeyEx(hKeyIn,"regtest",0,"asdf",0,KEY_ALL_ACCESS,NULL,&hkey,&dwDisp);
99 if (lSts != ERROR_SUCCESS) fprintf(stderr, " 3:%ld\n",lSts);
102 /******************************************************************************
109 fprintf(stderr, "Testing RegDeleteKey...\n");
112 lSts = RegDeleteKey(hkey, "asdf");
113 if (lSts != ERROR_INVALID_HANDLE) fprintf(stderr, " 1:%ld\n",lSts);
115 lSts = RegDeleteKey(HKEY_CURRENT_USER, "asdf");
116 if (lSts != ERROR_FILE_NOT_FOUND) fprintf(stderr, " 2:%ld\n",lSts);
119 /******************************************************************************
122 void TestDeleteValue()
126 fprintf(stderr, "Testing RegDeleteValue...\n");
129 lSts = RegDeleteValue(hkey, "asdf");
130 if (lSts != ERROR_INVALID_HANDLE) fprintf(stderr, " 1:%ld\n",lSts);
132 lSts = RegDeleteValue(HKEY_CURRENT_USER, "asdf");
133 if (lSts != ERROR_FILE_NOT_FOUND) fprintf(stderr, " 2:%ld\n",lSts);
136 /******************************************************************************
146 fprintf(stderr, "Testing RegEnumKey...\n");
147 sVal = (char *)malloc(1 * sizeof(char));
151 lSts = RegEnumKey(hkey,3,sVal,lVal);
152 if (lSts != ERROR_INVALID_HANDLE) fprintf(stderr, " 1:%ld\n",lSts);
154 lSts = RegEnumKey(HKEY_CURRENT_USER,-1,sVal,lVal);
155 if (lSts != ERROR_NO_MORE_ITEMS) fprintf(stderr, " 2:%ld\n",lSts);
157 lSts = RegEnumKey(HKEY_CURRENT_USER,0,sVal,lVal);
158 if (lSts != ERROR_MORE_DATA) fprintf(stderr, " 3:%ld\n",lSts);
161 /******************************************************************************
173 fprintf(stderr, "Testing RegEnumKeyEx...\n");
174 sVal = (char *)malloc(80 * sizeof(char));
176 sClass = (char *)malloc(10 * sizeof(char));
177 lLen2 = sizeof(sClass);
179 lSts = RegEnumKeyEx(0,0,sVal,&lLen1,0,sClass,&lLen2,&ft);
180 if (lSts != ERROR_INVALID_HANDLE) fprintf(stderr, " 1:%ld\n",lSts);
183 /******************************************************************************
196 fprintf(stderr, "Testing RegEnumValue...\n");
197 sVal = (char *)malloc(80 * sizeof(char));
198 bVal = (char *)malloc(80 * sizeof(char));
200 lLen1 = sizeof(bVal);
203 lSts = RegEnumValue(hkey,-1,sVal,&lVal,0,&lType,NULL,&lLen1);
204 if (lSts != ERROR_INVALID_HANDLE) fprintf(stderr, " 1:%ld\n",lSts);
206 lSts = RegEnumValue(HKEY_LOCAL_MACHINE,-1,sVal,&lVal,0,&lType,NULL,&lLen1);
207 if (lSts != ERROR_NO_MORE_ITEMS) fprintf(stderr, " 2:%ld\n",lSts);
209 lSts = RegEnumValue(HKEY_LOCAL_MACHINE,0,sVal,&lVal,0,&lType,NULL,&lLen1);
210 if (lSts != ERROR_NO_MORE_ITEMS) fprintf(stderr, " 3:%ld\n",lSts);
212 lSts = RegEnumValue(HKEY_LOCAL_MACHINE,1,sVal,&lVal,0,&lType,bVal,&lLen1);
213 if (lSts != ERROR_NO_MORE_ITEMS) fprintf(stderr, " 4:%ld\n",lSts);
216 /******************************************************************************
222 fprintf(stderr, "Testing RegFlushKey...\n");
224 lSts = RegFlushKey(0);
225 if (lSts != ERROR_INVALID_HANDLE) fprintf(stderr, " 1:%ld\n",lSts);
227 lSts = RegFlushKey(HKEY_LOCAL_MACHINE);
228 if (lSts != ERROR_SUCCESS) fprintf(stderr, " 2:%ld\n",lSts);
231 /******************************************************************************
234 void TestGetKeySecurity()
237 SECURITY_INFORMATION si;
238 SECURITY_DESCRIPTOR sd;
242 fprintf(stderr, "Testing RegGetKeySecurity...\n");
246 lSts = RegGetKeySecurity(hkey,si,&sd,&lLen);
247 if (lSts != ERROR_INVALID_HANDLE) fprintf(stderr, " 1:%ld\n",lSts);
249 lSts = RegGetKeySecurity(HKEY_LOCAL_MACHINE,si,&sd,&lLen);
250 if (lSts != ERROR_INSUFFICIENT_BUFFER) fprintf(stderr, " 2:%ld\n",lSts);
253 si = GROUP_SECURITY_INFORMATION;
255 lSts = RegGetKeySecurity(HKEY_LOCAL_MACHINE,si,&sd,&lLen);
256 if (lSts != ERROR_SUCCESS) fprintf(stderr, " 3:%ld\n",lSts);
259 /******************************************************************************
265 fprintf(stderr, "Testing RegLoadKey...\n");
267 lSts = RegLoadKey(0,"","");
268 if (lSts != ERROR_INVALID_HANDLE) fprintf(stderr, " 1:%ld\n",lSts);
270 lSts = RegLoadKey(HKEY_CURRENT_USER,"","");
271 if (lSts != ERROR_INVALID_PARAMETER) fprintf(stderr, " 2:%ld\n",lSts);
273 lSts = RegLoadKey(HKEY_CURRENT_USER,"regtest","");
274 if (lSts != ERROR_INVALID_PARAMETER) fprintf(stderr, " 3:%ld\n",lSts);
276 lSts = RegLoadKey(HKEY_CURRENT_USER,"regtest","regtest.dat");
277 if (lSts != ERROR_PRIVILEGE_NOT_HELD) fprintf(stderr, " 4:%ld\n",lSts);
280 /******************************************************************************
281 * TestNotifyChangeKeyValue
283 void TestNotifyChangeKeyValue()
289 fprintf(stderr, "Testing RegNotifyChangeKeyValue...\n");
293 lSts = RegNotifyChangeKeyValue(hkey, TRUE, REG_NOTIFY_CHANGE_NAME, 0, 0);
294 if (lSts != ERROR_INVALID_HANDLE) fprintf(stderr, " 1:%ld\n",lSts);
296 lSts = RegNotifyChangeKeyValue(HKEY_CURRENT_USER, TRUE, REG_NOTIFY_CHANGE_NAME, 0, 1);
297 if (lSts != ERROR_INVALID_PARAMETER) fprintf(stderr, " 2:%ld\n",lSts);
299 lSts = RegNotifyChangeKeyValue(HKEY_CURRENT_USER, TRUE, REG_NOTIFY_CHANGE_NAME, hEvent, 1);
300 if (lSts != ERROR_INVALID_PARAMETER) fprintf(stderr, " 3:%ld\n",lSts);
303 /******************************************************************************
310 fprintf(stderr, "Testing RegOpenKey...\n");
312 lSts = RegOpenKey(0, "",&hkey);
313 if (lSts != ERROR_SUCCESS) fprintf(stderr, " 1:%ld\n",lSts);
315 lSts = RegOpenKey(0, "regtest",&hkey);
316 if (lSts != ERROR_INVALID_HANDLE) fprintf(stderr, " 2:%ld\n",lSts);
318 lSts = RegOpenKey(HKEY_CURRENT_USER, "regtest1",&hkey);
319 if (lSts != ERROR_FILE_NOT_FOUND) fprintf(stderr, " 3:%ld\n",lSts);
321 lSts = RegOpenKey(HKEY_CURRENT_USER, "\\regtest",&hkey);
322 if (lSts != ERROR_BAD_PATHNAME) fprintf(stderr, " 4:%ld\n",lSts);
325 /******************************************************************************
333 fprintf(stderr, "Testing RegOpenKeyEx...\n");
336 lSts = RegOpenKeyEx(hkeyIn,"",0,KEY_ALL_ACCESS,&hkey);
337 if (lSts != ERROR_INVALID_HANDLE) fprintf(stderr, " 1:%ld\n",lSts);
339 lSts = RegOpenKeyEx(HKEY_CURRENT_USER,"\\regtest",0,KEY_ALL_ACCESS,&hkey);
340 if (lSts != ERROR_BAD_PATHNAME) fprintf(stderr, " 2:%ld\n",lSts);
343 /******************************************************************************
346 void TestQueryInfoKey()
348 fprintf(stderr, "Testing RegQueryInfoKey...\n");
351 /******************************************************************************
354 void TestQueryValue()
361 fprintf(stderr, "Testing RegQueryValue...\n");
363 sVal = (char *)malloc(80 * sizeof(char));
366 lSts = RegQueryValue(hkey,"",NULL,&lLen);
367 if (lSts != ERROR_INVALID_HANDLE) fprintf(stderr, " 1:%ld\n",lSts);
369 lSts = RegQueryValue(HKEY_CURRENT_USER,"",NULL,&lLen);
370 if (lSts != ERROR_SUCCESS) fprintf(stderr, " 2:%ld\n",lSts);
372 lSts = RegQueryValue(HKEY_CURRENT_USER,"\\regtest",NULL,&lLen);
373 if (lSts != ERROR_BAD_PATHNAME) fprintf(stderr, " 3:%ld\n",lSts);
375 lSts = RegQueryValue(HKEY_CURRENT_USER,"",sVal,&lLen);
376 if (lSts != ERROR_SUCCESS) fprintf(stderr, " 4:%ld\n",lSts);
379 /******************************************************************************
382 void TestQueryValueEx()
384 fprintf(stderr, "Testing RegQueryValueEx...\n");
387 /******************************************************************************
390 void TestReplaceKey()
392 fprintf(stderr, "Testing RegReplaceKey...\n");
395 /******************************************************************************
398 void TestRestoreKey()
400 fprintf(stderr, "Testing RegRestoreKey...\n");
408 fprintf(stderr, "Testing Sequence1...\n");
410 lSts = RegCreateKey(HKEY_CURRENT_USER,"regtest",&hkey);
411 if (lSts != ERROR_SUCCESS) fprintf(stderr, " 1:%ld\n",lSts);
415 int PASCAL WinMain (HANDLE inst, HANDLE prev, LPSTR cmdline, int show)
418 /* These can be in any order */
420 TestConnectRegistry();
429 TestGetKeySecurity();
431 TestNotifyChangeKeyValue();
441 TestSetKeySecurity();
447 /* Now we have some sequence testing */