2 * Registry testing program
4 * Copyright 1998 Matthew Becker
6 * The return codes were generated in an NT40 environment, using lcc-win32
9 * When compiling under lcc-win32, I get three (3) warning, but they all
10 * seem to be issues with lcc.
12 * If creating a new testing sequence, please try to clean up any
13 * registry changes that are made.
24 #define __FUNCTION__ "<function>"
27 /* True this when security is implemented */
28 #define CHECK_SAM FALSE
30 #define xERROR(s,d) fprintf(stderr, "%s:#%d(Status=%ld)\n", __FUNCTION__,s,d)
33 * NOTES: These individual routines are listed in alphabetical order.
35 * They are meant to test error conditions. Success conditions are
36 * tested in the sequences found at the end.
39 /******************************************************************************
46 lSts
= RegCloseKey((HKEY
)2);
47 if (lSts
!= ERROR_INVALID_HANDLE
) xERROR(1,lSts
);
49 lSts
= RegCloseKey(HKEY_LOCAL_MACHINE
);
50 if (lSts
!= ERROR_SUCCESS
) xERROR(2,lSts
);
52 /* Check twice just for kicks */
53 lSts
= RegCloseKey(HKEY_LOCAL_MACHINE
);
54 if (lSts
!= ERROR_SUCCESS
) xERROR(3,lSts
);
57 /******************************************************************************
60 void TestConnectRegistry()
65 lSts
= RegConnectRegistry("",(HKEY
)2,&hkey
);
66 if (lSts
!= ERROR_SUCCESS
) xERROR(1,lSts
);
68 lSts
= RegConnectRegistry("",HKEY_LOCAL_MACHINE
,&hkey
);
69 if (lSts
!= ERROR_SUCCESS
) xERROR(2,lSts
);
72 lSts
= RegConnectRegistry("\\\\regtest",HKEY_LOCAL_MACHINE
,&hkey
);
73 if (lSts
!= ERROR_BAD_NETPATH
) xERROR(3,lSts
);
77 /******************************************************************************
85 lSts
= RegCreateKey((HKEY
)2,"",&hkey
);
86 if (lSts
!= ERROR_BADKEY
) xERROR(1,lSts
);
88 lSts
= RegCreateKey(HKEY_LOCAL_MACHINE
,"",&hkey
);
89 if (lSts
!= ERROR_SUCCESS
) xERROR(2,lSts
);
92 lSts
= RegCreateKey(HKEY_LOCAL_MACHINE
,"\\asdf",&hkey
);
93 if (lSts
!= ERROR_BAD_PATHNAME
) xERROR(3,lSts
);
96 lSts
= RegCreateKey(HKEY_LOCAL_MACHINE
,"asdf\\",&hkey
);
97 if (lSts
!= ERROR_INVALID_PARAMETER
) xERROR(4,lSts
);
100 lSts
= RegCreateKey(HKEY_LOCAL_MACHINE
,"\\asdf\\",&hkey
);
101 if (lSts
!= ERROR_BAD_PATHNAME
) xERROR(5,lSts
);
104 /******************************************************************************
107 void TestCreateKeyEx()
113 lSts
= RegCreateKeyEx((HKEY
)2,"",0,"",0,0,NULL
,&hkey
,&dwDisp
);
114 if (lSts
!= ERROR_INVALID_HANDLE
) xERROR(1,lSts
);
116 lSts
= RegCreateKeyEx(HKEY_LOCAL_MACHINE
,"regtest",0,"",0,0,NULL
,&hkey
,
118 if (lSts
!= ERROR_INVALID_PARAMETER
) xERROR(2,lSts
);
120 lSts
= RegCreateKeyEx(HKEY_LOCAL_MACHINE
,"regtest",0,"asdf",0,
121 KEY_ALL_ACCESS
,NULL
,&hkey
,&dwDisp
);
122 if (lSts
!= ERROR_INVALID_PARAMETER
) xERROR(3,lSts
);
124 lSts
= RegCreateKeyEx(HKEY_LOCAL_MACHINE
,"regtest",0,"",0,
125 KEY_ALL_ACCESS
,NULL
,&hkey
,&dwDisp
);
126 if (lSts
!= ERROR_INVALID_PARAMETER
) xERROR(4,lSts
);
130 /******************************************************************************
133 void TestCreateKeyEx1()
138 char keyname
[]="regtest1";
140 lSts
= RegOpenKeyEx(HKEY_LOCAL_MACHINE
,"SOFTWARE",0,1,&hkeyP
);
141 if (lSts
!= ERROR_SUCCESS
)
146 lSts
= RegCreateKeyEx(hkeyP
,keyname
,0,0,0,0xf003f,0,&hkey
,&dwDisp
);
147 if (lSts
!= ERROR_SUCCESS
)
153 lSts
= RegDeleteKey( hkeyP
,keyname
);
154 if (lSts
!= ERROR_SUCCESS
) xERROR(3,lSts
);
158 /******************************************************************************
165 lSts
= RegDeleteKey((HKEY
)2, "asdf");
166 if (lSts
!= ERROR_INVALID_HANDLE
) xERROR(1,lSts
);
168 lSts
= RegDeleteKey(HKEY_CURRENT_USER
, "asdf");
169 if (lSts
!= ERROR_FILE_NOT_FOUND
) xERROR(2,lSts
);
172 lSts
= RegDeleteKey(HKEY_CURRENT_USER
, "");
173 if (lSts
!= ERROR_ACCESS_DENIED
) xERROR(3,lSts
);
177 /******************************************************************************
180 void TestDeleteValue()
184 lSts
= RegDeleteValue((HKEY
)2, "asdf");
185 if (lSts
!= ERROR_INVALID_HANDLE
) xERROR(1,lSts
);
187 lSts
= RegDeleteValue(HKEY_CURRENT_USER
, "");
188 if (lSts
!= ERROR_FILE_NOT_FOUND
) xERROR(2,lSts
);
190 lSts
= RegDeleteValue(HKEY_CURRENT_USER
, "asdf");
191 if (lSts
!= ERROR_FILE_NOT_FOUND
) xERROR(3,lSts
);
193 lSts
= RegDeleteValue(HKEY_CURRENT_USER
, "\\asdf");
194 if (lSts
!= ERROR_FILE_NOT_FOUND
) xERROR(4,lSts
);
197 /******************************************************************************
207 sVal
= (char *)malloc(lVal
* sizeof(char));
209 lSts
= RegEnumKey((HKEY
)2,3,sVal
,lVal
);
210 if (lSts
!= ERROR_INVALID_HANDLE
) xERROR(1,lSts
);
212 lSts
= RegEnumKey(HKEY_CURRENT_USER
,-1,sVal
,lVal
);
213 if (lSts
!= ERROR_NO_MORE_ITEMS
) xERROR(2,lSts
);
215 lSts
= RegEnumKey(HKEY_CURRENT_USER
,0,sVal
,lVal
);
216 if (lSts
!= ERROR_MORE_DATA
) xERROR(3,lSts
);
219 /******************************************************************************
232 sVal
= (char *)malloc(lLen1
* sizeof(char));
234 sClass
= (char *)malloc(lLen2
* sizeof(char));
236 lSts
= RegEnumKeyEx((HKEY
)2,0,sVal
,&lLen1
,0,sClass
,&lLen2
,&ft
);
237 if (lSts
!= ERROR_INVALID_HANDLE
) xERROR(1,lSts
);
239 lSts
= RegEnumKeyEx(HKEY_LOCAL_MACHINE
,0,sVal
,&lLen1
,0,sClass
,&lLen2
,&ft
);
240 if (lSts
!= ERROR_MORE_DATA
) xERROR(2,lSts
);
242 lSts
= RegEnumKeyEx(HKEY_LOCAL_MACHINE
,0,sVal
,&lLen1
,0,sClass
,&lLen2
,&ft
);
243 if (lSts
!= ERROR_MORE_DATA
) xERROR(3,lSts
);
246 /******************************************************************************
259 sVal
= (char *)malloc(lVal
* sizeof(char));
261 bVal
= (char *)malloc(lLen1
* sizeof(char));
263 lSts
= RegEnumValue((HKEY
)2,-1,sVal
,&lVal
,0,&lType
,NULL
,&lLen1
);
264 if (lSts
!= ERROR_INVALID_HANDLE
) xERROR(1,lSts
);
266 lSts
= RegEnumValue(HKEY_LOCAL_MACHINE
,-1,sVal
,&lVal
,0,&lType
,NULL
,&lLen1
);
267 if (lSts
!= ERROR_NO_MORE_ITEMS
) xERROR(2,lSts
);
269 lSts
= RegEnumValue(HKEY_LOCAL_MACHINE
,0,sVal
,&lVal
,0,&lType
,NULL
,&lLen1
);
270 if (lSts
!= ERROR_SUCCESS
) xERROR(3,lSts
);
272 lSts
= RegEnumValue(HKEY_LOCAL_MACHINE
,0,sVal
,&lVal
,0,NULL
,NULL
,&lLen1
);
273 if (lSts
!= ERROR_SUCCESS
) xERROR(4,lSts
);
275 lSts
= RegEnumValue(HKEY_LOCAL_MACHINE
,1,sVal
,&lVal
,0,&lType
,bVal
,&lLen1
);
276 if (lSts
!= ERROR_NO_MORE_ITEMS
) xERROR(5,lSts
);
279 /******************************************************************************
286 lSts
= RegFlushKey((HKEY
)2);
287 if (lSts
!= ERROR_INVALID_HANDLE
) xERROR(1,lSts
);
289 lSts
= RegFlushKey(HKEY_LOCAL_MACHINE
);
290 if (lSts
!= ERROR_SUCCESS
) xERROR(2,lSts
);
293 /******************************************************************************
296 void TestGetKeySecurity()
299 SECURITY_INFORMATION si
;
300 SECURITY_DESCRIPTOR sd
;
305 lSts
= RegGetKeySecurity((HKEY
)2,si
,&sd
,&lLen
);
306 if (lSts
!= ERROR_INVALID_HANDLE
) xERROR(1,lSts
);
308 lSts
= RegGetKeySecurity(HKEY_LOCAL_MACHINE
,si
,&sd
,&lLen
);
309 if (lSts
!= ERROR_INSUFFICIENT_BUFFER
) xERROR(2,lSts
);
311 si
= GROUP_SECURITY_INFORMATION
;
312 lSts
= RegGetKeySecurity(HKEY_LOCAL_MACHINE
,si
,&sd
,&lLen
);
313 if (lSts
!= ERROR_SUCCESS
) xERROR(3,lSts
);
316 /******************************************************************************
323 lSts
= RegLoadKey((HKEY
)2,"","");
324 if (lSts
!= ERROR_INVALID_PARAMETER
) xERROR(1,lSts
);
326 lSts
= RegLoadKey(HKEY_CURRENT_USER
,"","");
327 if (lSts
!= ERROR_INVALID_PARAMETER
) xERROR(2,lSts
);
329 lSts
= RegLoadKey(HKEY_CURRENT_USER
,"regtest","");
330 if (lSts
!= ERROR_INVALID_PARAMETER
) xERROR(3,lSts
);
332 lSts
= RegLoadKey(HKEY_CURRENT_USER
,"\\regtest","");
333 if (lSts
!= ERROR_INVALID_PARAMETER
) xERROR(4,lSts
);
336 lSts
= RegLoadKey(HKEY_CURRENT_USER
,"regtest","regtest.dat");
337 if (lSts
!= ERROR_PRIVILEGE_NOT_HELD
) xERROR(5,lSts
);
339 lSts
= RegLoadKey(HKEY_CURRENT_USER
,"\\regtest","regtest.dat");
340 if (lSts
!= ERROR_PRIVILEGE_NOT_HELD
) xERROR(6,lSts
);
344 /******************************************************************************
345 * TestNotifyChangeKeyValue
347 void TestNotifyChangeKeyValue()
354 lSts
= RegNotifyChangeKeyValue((HKEY
)2, TRUE
, REG_NOTIFY_CHANGE_NAME
, 0, 0);
355 if (lSts
!= ERROR_INVALID_HANDLE
) xERROR(1,lSts
);
357 lSts
= RegNotifyChangeKeyValue(HKEY_CURRENT_USER
, TRUE
, REG_NOTIFY_CHANGE_NAME
, 0, 1);
358 if (lSts
!= ERROR_INVALID_PARAMETER
) xERROR(2,lSts
);
360 hEvent
= (HANDLE
)HKEY_CURRENT_USER
;
361 lSts
= RegNotifyChangeKeyValue(HKEY_CURRENT_USER
, TRUE
, REG_NOTIFY_CHANGE_NAME
, hEvent
, 1);
362 if (lSts
!= ERROR_INVALID_HANDLE
) xERROR(3,lSts
);
365 /******************************************************************************
373 lSts
= RegOpenKey((HKEY
)72, "",&hkey
);
374 if (lSts
!= ERROR_SUCCESS
) xERROR(1,lSts
);
377 lSts
= RegOpenKey((HKEY
)2, "regtest",&hkey
);
378 if (lSts
!= ERROR_INVALID_HANDLE
) xERROR(2,lSts
);
380 lSts
= RegOpenKey(HKEY_CURRENT_USER
, "regtest",&hkey
);
381 if (lSts
!= ERROR_FILE_NOT_FOUND
) xERROR(3,lSts
);
383 lSts
= RegOpenKey(HKEY_CURRENT_USER
, "\\regtest",&hkey
);
384 if (lSts
!= ERROR_BAD_PATHNAME
) xERROR(4,lSts
);
387 /******************************************************************************
395 lSts
= RegOpenKeyEx((HKEY
)2,"",0,KEY_ALL_ACCESS
,&hkey
);
396 if (lSts
!= ERROR_INVALID_HANDLE
) xERROR(1,lSts
);
398 lSts
= RegOpenKeyEx(HKEY_CURRENT_USER
,"\\regtest",0,KEY_ALL_ACCESS
,&hkey
);
399 if (lSts
!= ERROR_BAD_PATHNAME
) xERROR(2,lSts
);
401 lSts
= RegOpenKeyEx(HKEY_CURRENT_USER
,"regtest",0,0,&hkey
);
402 if (lSts
!= ERROR_FILE_NOT_FOUND
) xERROR(3,lSts
);
404 lSts
= RegOpenKeyEx(HKEY_CURRENT_USER
,"regtest\\",0,0,&hkey
);
405 if (lSts
!= ERROR_FILE_NOT_FOUND
) xERROR(4,lSts
);
408 /******************************************************************************
411 void TestQueryInfoKey()
415 unsigned long lClass
;
416 unsigned long lSubKeys
;
417 unsigned long lMaxSubLen
;
418 unsigned long lMaxClassLen
;
419 unsigned long lValues
;
420 unsigned long lMaxValNameLen
;
421 unsigned long lMaxValLen
;
422 unsigned long lSecDescLen
;
426 sClass
= (char *)malloc(lClass
* sizeof(char));
428 lSts
= RegQueryInfoKey((HKEY
)2,sClass
,&lClass
,0,&lSubKeys
,&lMaxSubLen
,
429 &lMaxClassLen
,&lValues
,&lMaxValNameLen
,&lMaxValLen
,
431 if (lSts
!= ERROR_INVALID_HANDLE
) xERROR(1,lSts
);
433 lSts
= RegQueryInfoKey(HKEY_CURRENT_USER
,sClass
,&lClass
,0,&lSubKeys
,
434 &lMaxSubLen
,&lMaxClassLen
,&lValues
,&lMaxValNameLen
,
435 &lMaxValLen
,&lSecDescLen
, &ft
);
436 if (lSts
!= ERROR_SUCCESS
) xERROR(2,lSts
);
439 /******************************************************************************
442 void TestQueryValue()
448 sVal
= (char *)malloc(80 * sizeof(char));
451 lSts
= RegQueryValue((HKEY
)2,"",NULL
,&lLen
);
452 if (lSts
!= ERROR_INVALID_HANDLE
) xERROR(1,lSts
);
454 lSts
= RegQueryValue(HKEY_CURRENT_USER
,"",NULL
,&lLen
);
455 if (lSts
!= ERROR_SUCCESS
) xERROR(2,lSts
);
457 lSts
= RegQueryValue(HKEY_CURRENT_USER
,"\\regtest",NULL
,&lLen
);
458 if (lSts
!= ERROR_BAD_PATHNAME
) xERROR(3,lSts
);
460 lSts
= RegQueryValue(HKEY_CURRENT_USER
,"",sVal
,&lLen
);
461 if (lSts
!= ERROR_SUCCESS
) xERROR(4,lSts
);
464 /******************************************************************************
467 void TestQueryValueEx()
475 sVal
= (char *)malloc(lLen
* sizeof(char));
477 lSts
= RegQueryValueEx((HKEY
)2,"",0,&lType
,sVal
,&lLen
);
478 if (lSts
!= ERROR_INVALID_HANDLE
) xERROR(1,lSts
);
480 lSts
= RegQueryValueEx(HKEY_CURRENT_USER
,"",(LPDWORD
)1,&lType
,sVal
,&lLen
);
481 if (lSts
!= ERROR_INVALID_PARAMETER
) xERROR(2,lSts
);
483 lSts
= RegQueryValueEx(HKEY_LOCAL_MACHINE
,"",0,&lType
,sVal
,&lLen
);
484 if (lSts
!= ERROR_SUCCESS
) xERROR(3,lSts
);
487 /******************************************************************************
490 void TestReplaceKey()
494 lSts
= RegReplaceKey((HKEY
)2,"","","");
495 if (lSts
!= ERROR_INVALID_HANDLE
) xERROR(1,lSts
);
498 lSts
= RegReplaceKey(HKEY_LOCAL_MACHINE
,"","","");
499 if (lSts
!= ERROR_ACCESS_DENIED
) xERROR(2,lSts
);
501 lSts
= RegReplaceKey(HKEY_LOCAL_MACHINE
,"Software","","");
502 if (lSts
!= ERROR_ACCESS_DENIED
) xERROR(3,lSts
);
506 /******************************************************************************
509 void TestRestoreKey()
513 lSts
= RegRestoreKey((HKEY
)2,"",0);
514 if (lSts
!= ERROR_INVALID_PARAMETER
) xERROR(1,lSts
);
516 lSts
= RegRestoreKey(HKEY_LOCAL_MACHINE
,"",0);
517 if (lSts
!= ERROR_INVALID_PARAMETER
) xERROR(2,lSts
);
519 lSts
= RegRestoreKey(HKEY_LOCAL_MACHINE
,"a.a",0);
520 if (lSts
!= ERROR_FILE_NOT_FOUND
) xERROR(3,lSts
);
523 /******************************************************************************
530 lSts
= RegSaveKey((HKEY
)2,"",NULL
);
531 if (lSts
!= ERROR_INVALID_PARAMETER
) xERROR(1,lSts
);
533 lSts
= RegSaveKey(HKEY_LOCAL_MACHINE
,"",NULL
);
534 if (lSts
!= ERROR_INVALID_PARAMETER
) xERROR(2,lSts
);
537 lSts
= RegSaveKey(HKEY_LOCAL_MACHINE
,"a.a",NULL
);
538 if (lSts
!= ERROR_PRIVILEGE_NOT_HELD
) xERROR(3,lSts
);
542 /******************************************************************************
545 void TestSetKeySecurity()
548 SECURITY_DESCRIPTOR sd
;
550 lSts
= RegSetKeySecurity((HKEY
)2,0,NULL
);
551 if (lSts
!= ERROR_INVALID_PARAMETER
) xERROR(1,lSts
);
553 lSts
= RegSetKeySecurity(HKEY_LOCAL_MACHINE
,0,NULL
);
554 if (lSts
!= ERROR_INVALID_PARAMETER
) xERROR(2,lSts
);
556 lSts
= RegSetKeySecurity(HKEY_LOCAL_MACHINE
,OWNER_SECURITY_INFORMATION
,NULL
);
557 if (lSts
!= ERROR_INVALID_PARAMETER
) xERROR(3,lSts
);
559 lSts
= RegSetKeySecurity(HKEY_LOCAL_MACHINE
,OWNER_SECURITY_INFORMATION
,&sd
);
560 if (lSts
!= ERROR_INVALID_PARAMETER
) xERROR(4,lSts
);
563 /******************************************************************************
573 lSts
= RegSetValue((HKEY
)2,"",0,NULL
,0);
574 if (lSts
!= ERROR_INVALID_PARAMETER
) xERROR(1,lSts
);
578 lSts
= RegSetValue((HKEY
)2,"regtest",0,NULL
,0);
579 if (lSts
!= ERROR_INVALID_PARAMETER
) xERROR(2,lSts
);
583 lSts
= RegSetValue((HKEY
)2,"regtest",REG_SZ
,NULL
,0);
584 if (lSts
!= ERROR_INVALID_HANDLE
) xERROR(3,lSts
);
588 lSts
= RegSetValue(HKEY_LOCAL_MACHINE
,"regtest",REG_SZ
,NULL
,0);
589 if (lSts
!= ERROR_INVALID_HANDLE
) xERROR(4,lSts
);
593 /******************************************************************************
596 void TestSetValueEx()
600 lSts
= RegSetValueEx((HKEY
)2,"",0,0,NULL
,0);
601 if (lSts
!= ERROR_INVALID_HANDLE
) xERROR(1,lSts
);
603 lSts
= RegSetValueEx(HKEY_LOCAL_MACHINE
,"",0,0,NULL
,0);
604 if (lSts
!= ERROR_SUCCESS
) xERROR(2,lSts
);
607 /******************************************************************************
617 lSts
= RegUnLoadKey((HKEY
)2,"");
618 if (lSts
!= ERROR_PRIVILEGE_NOT_HELD
) xERROR(1,lSts
);
620 lSts
= RegUnLoadKey(HKEY_LOCAL_MACHINE
,"");
621 if (lSts
!= ERROR_PRIVILEGE_NOT_HELD
) xERROR(2,lSts
);
623 lSts
= RegUnLoadKey(HKEY_LOCAL_MACHINE
,"\\regtest");
624 if (lSts
!= ERROR_PRIVILEGE_NOT_HELD
) xERROR(3,lSts
);
628 /******************************************************************************
636 lSts
= RegCreateKey(HKEY_CURRENT_USER
,"regtest",&hkey
);
637 if (lSts
!= ERROR_SUCCESS
) xERROR(1,lSts
);
639 /* fprintf(stderr, " hkey=0x%x\n", hkey); */
641 lSts
= RegDeleteKey(HKEY_CURRENT_USER
, "regtest");
642 if (lSts
!= ERROR_SUCCESS
) xERROR(2,lSts
);
643 lSts
= RegCloseKey(hkey
);
644 if (lSts
!= ERROR_SUCCESS
) xERROR(3,lSts
);
648 int PASCAL
WinMain (HINSTANCE inst
, HINSTANCE prev
, LPSTR cmdline
, int show
)
651 /* These can be in any order */
653 TestConnectRegistry();
662 TestGetKeySecurity();
664 TestNotifyChangeKeyValue();
673 TestSetKeySecurity();
679 /* Now we have some sequence testing */