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);
233 /******************************************************************************
246 sVal = (char *)malloc(lLen1 * sizeof(char));
248 sClass = (char *)malloc(lLen2 * sizeof(char));
250 lSts = RegEnumKeyEx((HKEY)2,0,sVal,&lLen1,0,sClass,&lLen2,&ft);
251 if (lSts != ERROR_INVALID_HANDLE) xERROR(1,lSts);
253 lSts = RegEnumKeyEx(HKEY_LOCAL_MACHINE,0,sVal,&lLen1,0,sClass,&lLen2,&ft);
254 if (lSts != ERROR_MORE_DATA) xERROR(2,lSts);
256 lSts = RegEnumKeyEx(HKEY_LOCAL_MACHINE,0,sVal,&lLen1,0,sClass,&lLen2,&ft);
257 if (lSts != ERROR_MORE_DATA) xERROR(3,lSts);
260 /******************************************************************************
273 sVal = (char *)malloc(lVal * sizeof(char));
275 bVal = (char *)malloc(lLen1 * sizeof(char));
277 lSts = RegEnumValue((HKEY)2,-1,sVal,&lVal,0,&lType,NULL,&lLen1);
278 if (lSts != ERROR_INVALID_HANDLE) xERROR(1,lSts);
280 lSts = RegEnumValue(HKEY_LOCAL_MACHINE,-1,sVal,&lVal,0,&lType,NULL,&lLen1);
281 if (lSts != ERROR_NO_MORE_ITEMS) xERROR(2,lSts);
283 lSts = RegEnumValue(HKEY_LOCAL_MACHINE,0,sVal,&lVal,0,&lType,NULL,&lLen1);
284 if (lSts != ERROR_SUCCESS) xERROR(3,lSts);
286 lSts = RegEnumValue(HKEY_LOCAL_MACHINE,0,sVal,&lVal,0,NULL,NULL,&lLen1);
287 if (lSts != ERROR_SUCCESS) xERROR(4,lSts);
289 lSts = RegEnumValue(HKEY_LOCAL_MACHINE,1,sVal,&lVal,0,&lType,bVal,&lLen1);
290 if (lSts != ERROR_NO_MORE_ITEMS) xERROR(5,lSts);
293 /******************************************************************************
300 lSts = RegFlushKey((HKEY)2);
301 if (lSts != ERROR_INVALID_HANDLE) xERROR(1,lSts);
303 lSts = RegFlushKey(HKEY_LOCAL_MACHINE);
304 if (lSts != ERROR_SUCCESS) xERROR(2,lSts);
307 /******************************************************************************
310 void TestGetKeySecurity()
313 SECURITY_INFORMATION si;
314 SECURITY_DESCRIPTOR sd;
319 lSts = RegGetKeySecurity((HKEY)2,si,&sd,&lLen);
320 if (lSts != ERROR_INVALID_HANDLE) xERROR(1,lSts);
322 lSts = RegGetKeySecurity(HKEY_LOCAL_MACHINE,si,&sd,&lLen);
323 if (lSts != ERROR_INSUFFICIENT_BUFFER) xERROR(2,lSts);
325 si = GROUP_SECURITY_INFORMATION;
326 lSts = RegGetKeySecurity(HKEY_LOCAL_MACHINE,si,&sd,&lLen);
327 if (lSts != ERROR_SUCCESS) xERROR(3,lSts);
330 /******************************************************************************
337 lSts = RegLoadKey((HKEY)2,"","");
338 if (lSts != ERROR_INVALID_PARAMETER) xERROR(1,lSts);
340 lSts = RegLoadKey(HKEY_CURRENT_USER,"","");
341 if (lSts != ERROR_INVALID_PARAMETER) xERROR(2,lSts);
343 lSts = RegLoadKey(HKEY_CURRENT_USER,"regtest","");
344 if (lSts != ERROR_INVALID_PARAMETER) xERROR(3,lSts);
346 lSts = RegLoadKey(HKEY_CURRENT_USER,"\\regtest","");
347 if (lSts != ERROR_INVALID_PARAMETER) xERROR(4,lSts);
350 lSts = RegLoadKey(HKEY_CURRENT_USER,"regtest","regtest.dat");
351 if (lSts != ERROR_PRIVILEGE_NOT_HELD) xERROR(5,lSts);
353 lSts = RegLoadKey(HKEY_CURRENT_USER,"\\regtest","regtest.dat");
354 if (lSts != ERROR_PRIVILEGE_NOT_HELD) xERROR(6,lSts);
358 /******************************************************************************
359 * TestNotifyChangeKeyValue
361 void TestNotifyChangeKeyValue()
368 lSts = RegNotifyChangeKeyValue((HKEY)2, TRUE, REG_NOTIFY_CHANGE_NAME, 0, 0);
369 if (lSts != ERROR_INVALID_HANDLE) xERROR(1,lSts);
371 lSts = RegNotifyChangeKeyValue(HKEY_CURRENT_USER, TRUE, REG_NOTIFY_CHANGE_NAME, 0, 1);
372 if (lSts != ERROR_INVALID_PARAMETER) xERROR(2,lSts);
374 hEvent = (HANDLE)HKEY_CURRENT_USER;
375 lSts = RegNotifyChangeKeyValue(HKEY_CURRENT_USER, TRUE, REG_NOTIFY_CHANGE_NAME, hEvent, 1);
376 if (lSts != ERROR_INVALID_HANDLE) xERROR(3,lSts);
379 /******************************************************************************
387 lSts = RegOpenKey((HKEY)72, "",&hkey);
388 if (lSts != ERROR_SUCCESS) xERROR(1,lSts);
391 lSts = RegOpenKey((HKEY)2, "regtest",&hkey);
392 if (lSts != ERROR_INVALID_HANDLE) xERROR(2,lSts);
394 lSts = RegOpenKey(HKEY_CURRENT_USER, "regtest",&hkey);
395 if (lSts != ERROR_FILE_NOT_FOUND) xERROR(3,lSts);
397 lSts = RegOpenKey(HKEY_CURRENT_USER, "\\regtest",&hkey);
398 if (lSts != ERROR_BAD_PATHNAME) xERROR(4,lSts);
401 /******************************************************************************
409 lSts = RegOpenKeyEx((HKEY)2,"",0,KEY_ALL_ACCESS,&hkey);
410 if (lSts != ERROR_INVALID_HANDLE) xERROR(1,lSts);
412 lSts = RegOpenKeyEx(HKEY_CURRENT_USER,"\\regtest",0,KEY_ALL_ACCESS,&hkey);
413 if (lSts != ERROR_BAD_PATHNAME) xERROR(2,lSts);
415 lSts = RegOpenKeyEx(HKEY_CURRENT_USER,"regtest",0,0,&hkey);
416 if (lSts != ERROR_FILE_NOT_FOUND) xERROR(3,lSts);
418 lSts = RegOpenKeyEx(HKEY_CURRENT_USER,"regtest\\",0,0,&hkey);
419 if (lSts != ERROR_FILE_NOT_FOUND) xERROR(4,lSts);
422 /******************************************************************************
425 void TestQueryInfoKey()
429 unsigned long lClass;
430 unsigned long lSubKeys;
431 unsigned long lMaxSubLen;
432 unsigned long lMaxClassLen;
433 unsigned long lValues;
434 unsigned long lMaxValNameLen;
435 unsigned long lMaxValLen;
436 unsigned long lSecDescLen;
440 sClass = (char *)malloc(lClass * sizeof(char));
442 lSts = RegQueryInfoKey((HKEY)2,sClass,&lClass,0,&lSubKeys,&lMaxSubLen,
443 &lMaxClassLen,&lValues,&lMaxValNameLen,&lMaxValLen,
445 if (lSts != ERROR_INVALID_HANDLE) xERROR(1,lSts);
447 lSts = RegQueryInfoKey(HKEY_CURRENT_USER,sClass,&lClass,0,&lSubKeys,
448 &lMaxSubLen,&lMaxClassLen,&lValues,&lMaxValNameLen,
449 &lMaxValLen,&lSecDescLen, &ft);
450 if (lSts != ERROR_SUCCESS) xERROR(2,lSts);
453 /******************************************************************************
456 void TestQueryValue()
462 sVal = (char *)malloc(80 * sizeof(char));
465 lSts = RegQueryValue((HKEY)2,"",NULL,&lLen);
466 if (lSts != ERROR_INVALID_HANDLE) xERROR(1,lSts);
468 lSts = RegQueryValue(HKEY_CURRENT_USER,"",NULL,&lLen);
469 if (lSts != ERROR_SUCCESS) xERROR(2,lSts);
471 lSts = RegQueryValue(HKEY_CURRENT_USER,"\\regtest",NULL,&lLen);
472 if (lSts != ERROR_BAD_PATHNAME) xERROR(3,lSts);
474 lSts = RegQueryValue(HKEY_CURRENT_USER,"",sVal,&lLen);
475 if (lSts != ERROR_SUCCESS) xERROR(4,lSts);
478 /******************************************************************************
481 void TestQueryValueEx()
489 sVal = (char *)malloc(lLen * sizeof(char));
491 lSts = RegQueryValueEx((HKEY)2,"",0,&lType,sVal,&lLen);
492 if (lSts != ERROR_INVALID_HANDLE) xERROR(1,lSts);
494 lSts = RegQueryValueEx(HKEY_CURRENT_USER,"",(LPDWORD)1,&lType,sVal,&lLen);
495 if (lSts != ERROR_INVALID_PARAMETER) xERROR(2,lSts);
497 lSts = RegQueryValueEx(HKEY_LOCAL_MACHINE,"",0,&lType,sVal,&lLen);
498 if (lSts != ERROR_SUCCESS) xERROR(3,lSts);
501 /******************************************************************************
504 void TestReplaceKey()
508 lSts = RegReplaceKey((HKEY)2,"","","");
509 if (lSts != ERROR_INVALID_HANDLE) xERROR(1,lSts);
512 lSts = RegReplaceKey(HKEY_LOCAL_MACHINE,"","","");
513 if (lSts != ERROR_ACCESS_DENIED) xERROR(2,lSts);
515 lSts = RegReplaceKey(HKEY_LOCAL_MACHINE,"Software","","");
516 if (lSts != ERROR_ACCESS_DENIED) xERROR(3,lSts);
520 /******************************************************************************
523 void TestRestoreKey()
527 lSts = RegRestoreKey((HKEY)2,"",0);
528 if (lSts != ERROR_INVALID_PARAMETER) xERROR(1,lSts);
530 lSts = RegRestoreKey(HKEY_LOCAL_MACHINE,"",0);
531 if (lSts != ERROR_INVALID_PARAMETER) xERROR(2,lSts);
533 lSts = RegRestoreKey(HKEY_LOCAL_MACHINE,"a.a",0);
534 if (lSts != ERROR_FILE_NOT_FOUND) xERROR(3,lSts);
537 /******************************************************************************
544 lSts = RegSaveKey((HKEY)2,"",NULL);
545 if (lSts != ERROR_INVALID_PARAMETER) xERROR(1,lSts);
547 lSts = RegSaveKey(HKEY_LOCAL_MACHINE,"",NULL);
548 if (lSts != ERROR_INVALID_PARAMETER) xERROR(2,lSts);
551 lSts = RegSaveKey(HKEY_LOCAL_MACHINE,"a.a",NULL);
552 if (lSts != ERROR_PRIVILEGE_NOT_HELD) xERROR(3,lSts);
556 /******************************************************************************
559 void TestSetKeySecurity()
562 SECURITY_DESCRIPTOR sd;
564 lSts = RegSetKeySecurity((HKEY)2,0,NULL);
565 if (lSts != ERROR_INVALID_PARAMETER) xERROR(1,lSts);
567 lSts = RegSetKeySecurity(HKEY_LOCAL_MACHINE,0,NULL);
568 if (lSts != ERROR_INVALID_PARAMETER) xERROR(2,lSts);
570 lSts = RegSetKeySecurity(HKEY_LOCAL_MACHINE,OWNER_SECURITY_INFORMATION,NULL);
571 if (lSts != ERROR_INVALID_PARAMETER) xERROR(3,lSts);
573 lSts = RegSetKeySecurity(HKEY_LOCAL_MACHINE,OWNER_SECURITY_INFORMATION,&sd);
574 if (lSts != ERROR_INVALID_PARAMETER) xERROR(4,lSts);
577 /******************************************************************************
587 lSts = RegSetValue((HKEY)2,"",0,NULL,0);
588 if (lSts != ERROR_INVALID_PARAMETER) xERROR(1,lSts);
592 lSts = RegSetValue((HKEY)2,"regtest",0,NULL,0);
593 if (lSts != ERROR_INVALID_PARAMETER) xERROR(2,lSts);
597 lSts = RegSetValue((HKEY)2,"regtest",REG_SZ,NULL,0);
598 if (lSts != ERROR_INVALID_HANDLE) xERROR(3,lSts);
602 lSts = RegSetValue(HKEY_LOCAL_MACHINE,"regtest",REG_SZ,NULL,0);
603 if (lSts != ERROR_INVALID_HANDLE) xERROR(4,lSts);
607 /******************************************************************************
610 void TestSetValueEx()
614 lSts = RegSetValueEx((HKEY)2,"",0,0,NULL,0);
615 if (lSts != ERROR_INVALID_HANDLE) xERROR(1,lSts);
617 lSts = RegSetValueEx(HKEY_LOCAL_MACHINE,"",0,0,NULL,0);
618 if (lSts != ERROR_SUCCESS) xERROR(2,lSts);
621 /******************************************************************************
631 lSts = RegUnLoadKey((HKEY)2,"");
632 if (lSts != ERROR_PRIVILEGE_NOT_HELD) xERROR(1,lSts);
634 lSts = RegUnLoadKey(HKEY_LOCAL_MACHINE,"");
635 if (lSts != ERROR_PRIVILEGE_NOT_HELD) xERROR(2,lSts);
637 lSts = RegUnLoadKey(HKEY_LOCAL_MACHINE,"\\regtest");
638 if (lSts != ERROR_PRIVILEGE_NOT_HELD) xERROR(3,lSts);
642 /******************************************************************************
650 lSts = RegCreateKey(HKEY_CURRENT_USER,"regtest",&hkey);
651 if (lSts != ERROR_SUCCESS) xERROR(1,lSts);
653 /* fprintf(stderr, " hkey=0x%x\n", hkey); */
655 lSts = RegDeleteKey(HKEY_CURRENT_USER, "regtest");
656 if (lSts != ERROR_SUCCESS) xERROR(2,lSts);
657 lSts = RegCloseKey(hkey);
658 if (lSts != ERROR_SUCCESS) xERROR(3,lSts);
662 int PASCAL WinMain (HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
665 /* These can be in any order */
667 TestConnectRegistry();
676 TestGetKeySecurity();
678 TestNotifyChangeKeyValue();
687 TestSetKeySecurity();
693 /* Now we have some sequence testing */