2 * Registry testing program
4 * Copyright 1998 Matthew Becker
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * The return codes were generated in an NT40 environment, using lcc-win32
23 * When compiling under lcc-win32, I get three (3) warning, but they all
24 * seem to be issues with lcc.
26 * If creating a new testing sequence, please try to clean up any
27 * registry changes that are made.
38 #define __FUNCTION__ "<function>"
41 /* True this when security is implemented */
42 #define CHECK_SAM FALSE
44 #define xERROR(s,d) fprintf(stderr, "%s:#%d(Status=%ld)\n", __FUNCTION__,s,d)
47 * NOTES: These individual routines are listed in alphabetical order.
49 * They are meant to test error conditions. Success conditions are
50 * tested in the sequences found at the end.
53 /******************************************************************************
60 lSts = RegCloseKey((HKEY)2);
61 if (lSts != ERROR_INVALID_HANDLE) xERROR(1,lSts);
63 lSts = RegCloseKey(HKEY_LOCAL_MACHINE);
64 if (lSts != ERROR_SUCCESS) xERROR(2,lSts);
66 /* Check twice just for kicks */
67 lSts = RegCloseKey(HKEY_LOCAL_MACHINE);
68 if (lSts != ERROR_SUCCESS) xERROR(3,lSts);
71 /******************************************************************************
74 void TestConnectRegistry()
79 lSts = RegConnectRegistry("",(HKEY)2,&hkey);
80 if (lSts != ERROR_SUCCESS) xERROR(1,lSts);
82 lSts = RegConnectRegistry("",HKEY_LOCAL_MACHINE,&hkey);
83 if (lSts != ERROR_SUCCESS) xERROR(2,lSts);
86 lSts = RegConnectRegistry("\\\\regtest",HKEY_LOCAL_MACHINE,&hkey);
87 if (lSts != ERROR_BAD_NETPATH) xERROR(3,lSts);
91 /******************************************************************************
99 lSts = RegCreateKey((HKEY)2,"",&hkey);
100 if (lSts != ERROR_BADKEY) xERROR(1,lSts);
102 lSts = RegCreateKey(HKEY_LOCAL_MACHINE,"",&hkey);
103 if (lSts != ERROR_SUCCESS) xERROR(2,lSts);
106 lSts = RegCreateKey(HKEY_LOCAL_MACHINE,"\\asdf",&hkey);
107 if (lSts != ERROR_BAD_PATHNAME) xERROR(3,lSts);
110 lSts = RegCreateKey(HKEY_LOCAL_MACHINE,"asdf\\",&hkey);
111 if (lSts != ERROR_INVALID_PARAMETER) xERROR(4,lSts);
114 lSts = RegCreateKey(HKEY_LOCAL_MACHINE,"\\asdf\\",&hkey);
115 if (lSts != ERROR_BAD_PATHNAME) xERROR(5,lSts);
118 /******************************************************************************
121 void TestCreateKeyEx()
127 lSts = RegCreateKeyEx((HKEY)2,"",0,"",0,0,NULL,&hkey,&dwDisp);
128 if (lSts != ERROR_INVALID_HANDLE) xERROR(1,lSts);
130 lSts = RegCreateKeyEx(HKEY_LOCAL_MACHINE,"regtest",0,"",0,0,NULL,&hkey,
132 if (lSts != ERROR_INVALID_PARAMETER) xERROR(2,lSts);
134 lSts = RegCreateKeyEx(HKEY_LOCAL_MACHINE,"regtest",0,"asdf",0,
135 KEY_ALL_ACCESS,NULL,&hkey,&dwDisp);
136 if (lSts != ERROR_INVALID_PARAMETER) xERROR(3,lSts);
138 lSts = RegCreateKeyEx(HKEY_LOCAL_MACHINE,"regtest",0,"",0,
139 KEY_ALL_ACCESS,NULL,&hkey,&dwDisp);
140 if (lSts != ERROR_INVALID_PARAMETER) xERROR(4,lSts);
144 /******************************************************************************
147 void TestCreateKeyEx1()
152 char keyname[]="regtest1";
154 lSts = RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE",0,1,&hkeyP);
155 if (lSts != ERROR_SUCCESS)
160 lSts = RegCreateKeyEx(hkeyP,keyname,0,0,0,0xf003f,0,&hkey,&dwDisp);
161 if (lSts != ERROR_SUCCESS)
167 lSts = RegDeleteKey( hkeyP,keyname);
168 if (lSts != ERROR_SUCCESS) xERROR(3,lSts);
172 /******************************************************************************
179 lSts = RegDeleteKey((HKEY)2, "asdf");
180 if (lSts != ERROR_INVALID_HANDLE) xERROR(1,lSts);
182 lSts = RegDeleteKey(HKEY_CURRENT_USER, "asdf");
183 if (lSts != ERROR_FILE_NOT_FOUND) xERROR(2,lSts);
186 lSts = RegDeleteKey(HKEY_CURRENT_USER, "");
187 if (lSts != ERROR_ACCESS_DENIED) xERROR(3,lSts);
191 /******************************************************************************
194 void TestDeleteValue()
198 lSts = RegDeleteValue((HKEY)2, "asdf");
199 if (lSts != ERROR_INVALID_HANDLE) xERROR(1,lSts);
201 lSts = RegDeleteValue(HKEY_CURRENT_USER, "");
202 if (lSts != ERROR_FILE_NOT_FOUND) xERROR(2,lSts);
204 lSts = RegDeleteValue(HKEY_CURRENT_USER, "asdf");
205 if (lSts != ERROR_FILE_NOT_FOUND) xERROR(3,lSts);
207 lSts = RegDeleteValue(HKEY_CURRENT_USER, "\\asdf");
208 if (lSts != ERROR_FILE_NOT_FOUND) xERROR(4,lSts);
211 /******************************************************************************
221 sVal = (char *)malloc(lVal * sizeof(char));
223 lSts = RegEnumKey((HKEY)2,3,sVal,lVal);
224 if (lSts != ERROR_INVALID_HANDLE) xERROR(1,lSts);
226 lSts = RegEnumKey(HKEY_CURRENT_USER,-1,sVal,lVal);
227 if (lSts != ERROR_NO_MORE_ITEMS) xERROR(2,lSts);
229 lSts = RegEnumKey(HKEY_CURRENT_USER,0,sVal,lVal);
230 if (lSts != ERROR_MORE_DATA) xERROR(3,lSts);
235 /******************************************************************************
248 sVal = (char *)malloc(lLen1 * sizeof(char));
250 sClass = (char *)malloc(lLen2 * sizeof(char));
252 lSts = RegEnumKeyEx((HKEY)2,0,sVal,&lLen1,0,sClass,&lLen2,&ft);
253 if (lSts != ERROR_INVALID_HANDLE) xERROR(1,lSts);
255 lSts = RegEnumKeyEx(HKEY_LOCAL_MACHINE,0,sVal,&lLen1,0,sClass,&lLen2,&ft);
256 if (lSts != ERROR_MORE_DATA) xERROR(2,lSts);
258 lSts = RegEnumKeyEx(HKEY_LOCAL_MACHINE,0,sVal,&lLen1,0,sClass,&lLen2,&ft);
259 if (lSts != ERROR_MORE_DATA) xERROR(3,lSts);
265 /******************************************************************************
278 sVal = (char *)malloc(lVal * sizeof(char));
280 bVal = (char *)malloc(lLen1 * sizeof(char));
282 lSts = RegEnumValue((HKEY)2,-1,sVal,&lVal,0,&lType,NULL,&lLen1);
283 if (lSts != ERROR_INVALID_HANDLE) xERROR(1,lSts);
285 lSts = RegEnumValue(HKEY_LOCAL_MACHINE,-1,sVal,&lVal,0,&lType,NULL,&lLen1);
286 if (lSts != ERROR_NO_MORE_ITEMS) xERROR(2,lSts);
288 lSts = RegEnumValue(HKEY_LOCAL_MACHINE,0,sVal,&lVal,0,&lType,NULL,&lLen1);
289 if (lSts != ERROR_SUCCESS) xERROR(3,lSts);
291 lSts = RegEnumValue(HKEY_LOCAL_MACHINE,0,sVal,&lVal,0,NULL,NULL,&lLen1);
292 if (lSts != ERROR_SUCCESS) xERROR(4,lSts);
294 lSts = RegEnumValue(HKEY_LOCAL_MACHINE,1,sVal,&lVal,0,&lType,bVal,&lLen1);
295 if (lSts != ERROR_NO_MORE_ITEMS) xERROR(5,lSts);
301 /******************************************************************************
308 lSts = RegFlushKey((HKEY)2);
309 if (lSts != ERROR_INVALID_HANDLE) xERROR(1,lSts);
311 lSts = RegFlushKey(HKEY_LOCAL_MACHINE);
312 if (lSts != ERROR_SUCCESS) xERROR(2,lSts);
315 /******************************************************************************
318 void TestGetKeySecurity()
321 SECURITY_INFORMATION si;
322 SECURITY_DESCRIPTOR sd;
327 lSts = RegGetKeySecurity((HKEY)2,si,&sd,&lLen);
328 if (lSts != ERROR_INVALID_HANDLE) xERROR(1,lSts);
330 lSts = RegGetKeySecurity(HKEY_LOCAL_MACHINE,si,&sd,&lLen);
331 if (lSts != ERROR_INSUFFICIENT_BUFFER) xERROR(2,lSts);
333 si = GROUP_SECURITY_INFORMATION;
334 lSts = RegGetKeySecurity(HKEY_LOCAL_MACHINE,si,&sd,&lLen);
335 if (lSts != ERROR_SUCCESS) xERROR(3,lSts);
338 /******************************************************************************
345 lSts = RegLoadKey((HKEY)2,"","");
346 if (lSts != ERROR_INVALID_PARAMETER) xERROR(1,lSts);
348 lSts = RegLoadKey(HKEY_CURRENT_USER,"","");
349 if (lSts != ERROR_INVALID_PARAMETER) xERROR(2,lSts);
351 lSts = RegLoadKey(HKEY_CURRENT_USER,"regtest","");
352 if (lSts != ERROR_INVALID_PARAMETER) xERROR(3,lSts);
354 lSts = RegLoadKey(HKEY_CURRENT_USER,"\\regtest","");
355 if (lSts != ERROR_INVALID_PARAMETER) xERROR(4,lSts);
358 lSts = RegLoadKey(HKEY_CURRENT_USER,"regtest","regtest.dat");
359 if (lSts != ERROR_PRIVILEGE_NOT_HELD) xERROR(5,lSts);
361 lSts = RegLoadKey(HKEY_CURRENT_USER,"\\regtest","regtest.dat");
362 if (lSts != ERROR_PRIVILEGE_NOT_HELD) xERROR(6,lSts);
366 /******************************************************************************
367 * TestNotifyChangeKeyValue
369 void TestNotifyChangeKeyValue()
376 lSts = RegNotifyChangeKeyValue((HKEY)2, TRUE, REG_NOTIFY_CHANGE_NAME, 0, 0);
377 if (lSts != ERROR_INVALID_HANDLE) xERROR(1,lSts);
379 lSts = RegNotifyChangeKeyValue(HKEY_CURRENT_USER, TRUE, REG_NOTIFY_CHANGE_NAME, 0, 1);
380 if (lSts != ERROR_INVALID_PARAMETER) xERROR(2,lSts);
382 hEvent = (HANDLE)HKEY_CURRENT_USER;
383 lSts = RegNotifyChangeKeyValue(HKEY_CURRENT_USER, TRUE, REG_NOTIFY_CHANGE_NAME, hEvent, 1);
384 if (lSts != ERROR_INVALID_HANDLE) xERROR(3,lSts);
387 /******************************************************************************
395 lSts = RegOpenKey((HKEY)72, "",&hkey);
396 if (lSts != ERROR_SUCCESS) xERROR(1,lSts);
399 lSts = RegOpenKey((HKEY)2, "regtest",&hkey);
400 if (lSts != ERROR_INVALID_HANDLE) xERROR(2,lSts);
402 lSts = RegOpenKey(HKEY_CURRENT_USER, "regtest",&hkey);
403 if (lSts != ERROR_FILE_NOT_FOUND) xERROR(3,lSts);
405 lSts = RegOpenKey(HKEY_CURRENT_USER, "\\regtest",&hkey);
406 if (lSts != ERROR_BAD_PATHNAME) xERROR(4,lSts);
409 /******************************************************************************
417 lSts = RegOpenKeyEx((HKEY)2,"",0,KEY_ALL_ACCESS,&hkey);
418 if (lSts != ERROR_INVALID_HANDLE) xERROR(1,lSts);
420 lSts = RegOpenKeyEx(HKEY_CURRENT_USER,"\\regtest",0,KEY_ALL_ACCESS,&hkey);
421 if (lSts != ERROR_BAD_PATHNAME) xERROR(2,lSts);
423 lSts = RegOpenKeyEx(HKEY_CURRENT_USER,"regtest",0,0,&hkey);
424 if (lSts != ERROR_FILE_NOT_FOUND) xERROR(3,lSts);
426 lSts = RegOpenKeyEx(HKEY_CURRENT_USER,"regtest\\",0,0,&hkey);
427 if (lSts != ERROR_FILE_NOT_FOUND) xERROR(4,lSts);
430 /******************************************************************************
433 void TestQueryInfoKey()
437 unsigned long lClass;
438 unsigned long lSubKeys;
439 unsigned long lMaxSubLen;
440 unsigned long lMaxClassLen;
441 unsigned long lValues;
442 unsigned long lMaxValNameLen;
443 unsigned long lMaxValLen;
444 unsigned long lSecDescLen;
448 sClass = (char *)malloc(lClass * sizeof(char));
450 lSts = RegQueryInfoKey((HKEY)2,sClass,&lClass,0,&lSubKeys,&lMaxSubLen,
451 &lMaxClassLen,&lValues,&lMaxValNameLen,&lMaxValLen,
453 if (lSts != ERROR_INVALID_HANDLE) xERROR(1,lSts);
455 lSts = RegQueryInfoKey(HKEY_CURRENT_USER,sClass,&lClass,0,&lSubKeys,
456 &lMaxSubLen,&lMaxClassLen,&lValues,&lMaxValNameLen,
457 &lMaxValLen,&lSecDescLen, &ft);
458 if (lSts != ERROR_SUCCESS) xERROR(2,lSts);
463 /******************************************************************************
466 void TestQueryValue()
472 sVal = (char *)malloc(80 * sizeof(char));
475 lSts = RegQueryValue((HKEY)2,"",NULL,&lLen);
476 if (lSts != ERROR_INVALID_HANDLE) xERROR(1,lSts);
478 lSts = RegQueryValue(HKEY_CURRENT_USER,"",NULL,&lLen);
479 if (lSts != ERROR_SUCCESS) xERROR(2,lSts);
481 lSts = RegQueryValue(HKEY_CURRENT_USER,"\\regtest",NULL,&lLen);
482 if (lSts != ERROR_BAD_PATHNAME) xERROR(3,lSts);
484 lSts = RegQueryValue(HKEY_CURRENT_USER,"",sVal,&lLen);
485 if (lSts != ERROR_SUCCESS) xERROR(4,lSts);
490 /******************************************************************************
493 void TestQueryValueEx()
501 sVal = (char *)malloc(lLen * sizeof(char));
503 lSts = RegQueryValueEx((HKEY)2,"",0,&lType,sVal,&lLen);
504 if (lSts != ERROR_INVALID_HANDLE) xERROR(1,lSts);
506 lSts = RegQueryValueEx(HKEY_CURRENT_USER,"",(LPDWORD)1,&lType,sVal,&lLen);
507 if (lSts != ERROR_INVALID_PARAMETER) xERROR(2,lSts);
509 lSts = RegQueryValueEx(HKEY_LOCAL_MACHINE,"",0,&lType,sVal,&lLen);
510 if (lSts != ERROR_SUCCESS) xERROR(3,lSts);
515 /******************************************************************************
518 void TestReplaceKey()
522 lSts = RegReplaceKey((HKEY)2,"","","");
523 if (lSts != ERROR_INVALID_HANDLE) xERROR(1,lSts);
526 lSts = RegReplaceKey(HKEY_LOCAL_MACHINE,"","","");
527 if (lSts != ERROR_ACCESS_DENIED) xERROR(2,lSts);
529 lSts = RegReplaceKey(HKEY_LOCAL_MACHINE,"Software","","");
530 if (lSts != ERROR_ACCESS_DENIED) xERROR(3,lSts);
534 /******************************************************************************
537 void TestRestoreKey()
541 lSts = RegRestoreKey((HKEY)2,"",0);
542 if (lSts != ERROR_INVALID_PARAMETER) xERROR(1,lSts);
544 lSts = RegRestoreKey(HKEY_LOCAL_MACHINE,"",0);
545 if (lSts != ERROR_INVALID_PARAMETER) xERROR(2,lSts);
547 lSts = RegRestoreKey(HKEY_LOCAL_MACHINE,"a.a",0);
548 if (lSts != ERROR_FILE_NOT_FOUND) xERROR(3,lSts);
551 /******************************************************************************
558 lSts = RegSaveKey((HKEY)2,"",NULL);
559 if (lSts != ERROR_INVALID_PARAMETER) xERROR(1,lSts);
561 lSts = RegSaveKey(HKEY_LOCAL_MACHINE,"",NULL);
562 if (lSts != ERROR_INVALID_PARAMETER) xERROR(2,lSts);
565 lSts = RegSaveKey(HKEY_LOCAL_MACHINE,"a.a",NULL);
566 if (lSts != ERROR_PRIVILEGE_NOT_HELD) xERROR(3,lSts);
570 /******************************************************************************
573 void TestSetKeySecurity()
576 SECURITY_DESCRIPTOR sd;
578 lSts = RegSetKeySecurity((HKEY)2,0,NULL);
579 if (lSts != ERROR_INVALID_PARAMETER) xERROR(1,lSts);
581 lSts = RegSetKeySecurity(HKEY_LOCAL_MACHINE,0,NULL);
582 if (lSts != ERROR_INVALID_PARAMETER) xERROR(2,lSts);
584 lSts = RegSetKeySecurity(HKEY_LOCAL_MACHINE,OWNER_SECURITY_INFORMATION,NULL);
585 if (lSts != ERROR_INVALID_PARAMETER) xERROR(3,lSts);
587 lSts = RegSetKeySecurity(HKEY_LOCAL_MACHINE,OWNER_SECURITY_INFORMATION,&sd);
588 if (lSts != ERROR_INVALID_PARAMETER) xERROR(4,lSts);
591 /******************************************************************************
601 lSts = RegSetValue((HKEY)2,"",0,NULL,0);
602 if (lSts != ERROR_INVALID_PARAMETER) xERROR(1,lSts);
606 lSts = RegSetValue((HKEY)2,"regtest",0,NULL,0);
607 if (lSts != ERROR_INVALID_PARAMETER) xERROR(2,lSts);
611 lSts = RegSetValue((HKEY)2,"regtest",REG_SZ,NULL,0);
612 if (lSts != ERROR_INVALID_HANDLE) xERROR(3,lSts);
616 lSts = RegSetValue(HKEY_LOCAL_MACHINE,"regtest",REG_SZ,NULL,0);
617 if (lSts != ERROR_INVALID_HANDLE) xERROR(4,lSts);
621 /******************************************************************************
624 void TestSetValueEx()
628 lSts = RegSetValueEx((HKEY)2,"",0,0,NULL,0);
629 if (lSts != ERROR_INVALID_HANDLE) xERROR(1,lSts);
631 lSts = RegSetValueEx(HKEY_LOCAL_MACHINE,"",0,0,NULL,0);
632 if (lSts != ERROR_SUCCESS) xERROR(2,lSts);
635 /******************************************************************************
645 lSts = RegUnLoadKey((HKEY)2,"");
646 if (lSts != ERROR_PRIVILEGE_NOT_HELD) xERROR(1,lSts);
648 lSts = RegUnLoadKey(HKEY_LOCAL_MACHINE,"");
649 if (lSts != ERROR_PRIVILEGE_NOT_HELD) xERROR(2,lSts);
651 lSts = RegUnLoadKey(HKEY_LOCAL_MACHINE,"\\regtest");
652 if (lSts != ERROR_PRIVILEGE_NOT_HELD) xERROR(3,lSts);
656 /******************************************************************************
664 lSts = RegCreateKey(HKEY_CURRENT_USER,"regtest",&hkey);
665 if (lSts != ERROR_SUCCESS) xERROR(1,lSts);
667 /* fprintf(stderr, " hkey=0x%x\n", hkey); */
669 lSts = RegDeleteKey(HKEY_CURRENT_USER, "regtest");
670 if (lSts != ERROR_SUCCESS) xERROR(2,lSts);
671 lSts = RegCloseKey(hkey);
672 if (lSts != ERROR_SUCCESS) xERROR(3,lSts);
676 int PASCAL WinMain (HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
679 /* These can be in any order */
681 TestConnectRegistry();
690 TestGetKeySecurity();
692 TestNotifyChangeKeyValue();
701 TestSetKeySecurity();
707 /* Now we have some sequence testing */