home *** CD-ROM | disk | FTP | other *** search
- print "1..14\n";
-
- unshift(@INC, "d:\\perl-4.036\\lib");
-
- require "registry.pl";
-
- #
- # test the NT Registry access functions
- #
-
- # create a key
-
- $subkey_string = "SOFTWARE\\Intergraph\\PerlTest";
-
- if (&RegOpenKeyEx ($HKEY_LOCAL_MACHINE, $subkey_string, 0,
- $KEY_ALL_ACCESS, $key)) {
- &DeleteAllKeys($key);
- &RegCloseKey($key);
- &RegDeleteKey($HKEY_LOCAL_MACHINE, $subkey_string) ||
- die "Can't delete $subkey_string: $!\n";
- }
-
- $return = &RegCreateKeyEx($HKEY_LOCAL_MACHINE, $subkey_string, 0, "testclass",
- $REG_OPTION_NON_VOLATILE, $KEY_ALL_ACCESS, 0, $key,
- $disposition);
- if ($return != 1) {
- print "not ok 1 # $!\n";
- exit(0);
- }
- print "ok 1\n";
-
- # set a value
-
- $return = &RegSetValueEx ($key, "Test1", 0, $REG_SZ, "foobar");
- if ($return != 1) {
- print "not ok 2\n";
- exit(0);
- }
- print "ok 2\n";
-
- $return = &RegCloseKey ($key);
- if ($return != 1) {
- print "not ok 3\n";
- exit(0);
- }
- print "ok 3\n";
-
- $return = &RegOpenKey($HKEY_LOCAL_MACHINE, $subkey_string, $key);
- if ($return != 1) {
- print "not ok 4\n";
- exit(0);
- }
- print "ok 4\n";
-
- $return = &RegQueryValue ($key, "Test1", $val);
- if ($return != 1) {
- print "not ok 5\n";
- exit(0);
- }
- print "ok 5\n";
-
- $return = &RegSaveKey($key, "save.$$");
- # check for privledge violation
- if ($return != 0 && $! != 1314) {
- print "not ok 6\n";
- exit(0);
- }
- print "ok 6\n";
-
- unlink "save.$$" if -e "save.$$";
-
- &RegCloseKey($key);
-
- if ($val eq "foobar") {
- print "ok 7\n";
- }
- else {
- print "not ok 7\n";
- }
-
- $return = &RegCreateKey($HKEY_LOCAL_MACHINE, $subkey_string, $key);
- if ($return != 1) {
- print "not ok 8\n";
- exit(0);
- }
- print "ok 8\n";
-
- $return = &RegDeleteKey($HKEY_LOCAL_MACHINE, $subkey_string);
- if ($return != 1) {
- print "not ok 9\n";
- exit(0);
- }
- print "ok 9\n";
-
- #
- # shouldn't be able to open it now
- #
-
- $return = &RegOpenKey($HKEY_LOCAL_MACHINE,
- "SOFTWARE\\Intergraph\\PerlTest", $key);
- if ($return == 0) {print "ok 10\n";} else {print "not ok 10\n";}
-
-
- #
- # Now make a few keys and values, then test the enumerating functions
- #
-
- $return = &RegCreateKey($HKEY_LOCAL_MACHINE, $subkey_string, $key);
- if ($return != 1) {
- print "not ok 11\n";
- exit(0);
- }
- print "ok 11\n";
-
- $return = &RegCreateKey($key, "Key1", $nkey);
- if ($return != 1) {
- print "not ok 12\n";
- exit(0);
- }
- print "ok 12\n";
- &RegCloseKey($nkey);
-
- $return = &RegCreateKey($key, "Key2", $nkey);
- if ($return != 1) {
- print "not ok 13\n";
- exit(0);
- }
- print "ok 13\n";
- &RegCloseKey($nkey);
-
- $idx = 0;
- $cnt = 0;
-
- while(&RegEnumKeyEx($key, $idx++, $name,0, $class, $time)) {
- if ($name ne "Key$idx") {
- print "not ok 14\n";
- exit;
- }
- &RegDeleteKey($key, $name);
- }
- print "ok 14\n";
-
- #
- # clean up
- #
-
- &DeleteAllKeys($key);
- &RegCloseKey($key);
- &RegDeleteKey($HKEY_LOCAL_MACHINE, $subkey_string);
-
- exit;
-
- sub DeleteAllKeys {
- local($key) = @_;
- local($idx) = 0;
- local($newkey, $name);
-
- $idx = 0;
- while (&RegEnumKey($key, $idx++, $name)) {
- &RegOpenKeyEx($key, $name, 0, $KEY_ALL_ACCESS, $newkey) ||
- die "Can't open $name subkey: $!\n";
- &DeleteAllKeys($newkey);
- &RegCloseKey($newkey);
- &RegDeleteKey($key, $name) ||
- die "Can't delete key $name: $!\n";
- }
- }
-
-