3 # This script tests regedit functionality
5 # Copyright 2002 Andriy Palamarchuk
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License, or (at your option) any later version.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 $main::orig_reg
= './tests/orig.reg';
30 # Imitation of test framework "ok".
31 # Uncomment when running on Windows without testing framework
34 # my ($condition, $message) = @_;
41 # Checks if the files are equal regardless of the end-of-line encoding.
42 # Returns 0 if the files are different, otherwise returns 1
43 # params - list of file names
49 die "At least 2 file names expected" unless ($#file_names);
51 #compare file contents
52 foreach my $file_name (@file_names)
55 open($file, "<$file_name") || die "Error! can't open file $file_name";
59 my $first_file = shift(@files);
62 while ($line1 = <$first_file>)
66 foreach my $file (@files)
71 return 0 if $line1 ne $line2;
77 #removes all test output files
80 unlink "${main::orig_reg}.exported";
81 unlink "${main::orig_reg}.exported2";
84 #tests compatibility with regedit
87 my $error_no_file_name = "regedit: No file name is specified";
88 my $error_undefined_switch = "regedit: Undefined switch /";
89 my $error_no_registry_key = "regedit: No registry key is specified";
90 my $error_file_not_found = 'regedit: Can\'t open file "dummy_file_name"';
91 my $error_bad_reg_class_name = 'regedit: Incorrect registry class specification in';
92 my $error_dont_delete_class = 'regedit: Can\'t delete registry class';
94 my $test_reg_key = 'HKEY_CURRENT_USER\Test Regedit';
97 my $regedit = -e
"./regedit.exe" ?
".\\regedit.exe" : "./regedit";
100 my $command = "$regedit 2>&1";
102 ok
($?
, "regedit.exe return code check");
103 ok
($s =~ /$error_no_file_name/,
104 'Should raise an error on missed file name');
107 $command = "$regedit /S /V /R:1.reg /L:ss_ss.reg 2>&1";
109 ok
($?
, "regedit.exe return code check");
110 ok
($s =~ /$error_no_file_name/,
111 'Should raise an error on missed file name');
113 #incorrect form for /L, /R parameters
114 for my $switch ('L', 'R')
116 $command = "$regedit /$switch 2>&1";
118 ok
($?
, "regedit.exe return code check");
119 ok
($s =~ /$error_undefined_switch/, "Incorrect switch format check");
121 $command = "$regedit /$switch: 2>&1";
123 ok
($?
, "regedit.exe return code check");
124 ok
($s =~ /$error_no_file_name/, "Incorrect switch format check");
128 $command = "$regedit dummy_file_name 2>&1";
130 ok
($?
, "regedit.exe return code check");
131 ok
($s =~ /$error_file_not_found/, 'Incorrect processing of not-existing file');
133 #incorrect registry class is specified
134 $command = "$regedit /e ${main::orig_reg}.exported \"BAD_CLASS_HKEY\" 2>&1";
136 ok
($?
, "regedit.exe return code check");
137 ok
($s =~ /$error_bad_reg_class_name/, 'Incorrect processing of not-existing file');
139 #import registry file, export registry file, compare the files
140 $command = "$regedit ${main::orig_reg} 2>&1";
142 ok
(!$?
, "regedit.exe return code check");
143 $command = "$regedit /e ${main::orig_reg}.exported \"$test_reg_key\" 2>&1";
145 ok
(!$?
, "regedit.exe return code check");
146 ok
(files_are_equal
("${main::orig_reg}.exported", $main::orig_reg
),
147 "Original and generated registry files " .
148 "(${main::orig_reg}.exported and ${main::orig_reg}) " .
152 #export bare registry class (2 formats of command line parameter)
153 #XXX works fine under wine, but commented out because does not handle all key types
154 #existing on Windows and Windows registry is *very* big
155 # $command = "$regedit /e ${main::orig_reg}.exported HKEY_CURRENT_USER 2>&1";
157 # print("DEBUG\t result: $s, return code - $?\n");
158 # ok(!$?, "regedit.exe return code check");
159 # $command = "$regedit /e ${main::orig_reg}.exported2 HKEY_CURRENT_USER 2>&1";
161 # ok(!$?, "regedit.exe return code check");
162 # ok(files_are_equal("${main::orig_reg}.exported", "${main::orig_reg}.exported2"),
163 # "Original and generated registry files " .
164 # "(${main::orig_reg}.exported and ${main::orig_reg}.exported2) " .
170 $command = "$regedit /d 2>&1";
172 ok
($?
, "regedit.exe return code check");
173 ok
($s =~ /$error_no_registry_key/,
174 'No registry key name is specified for removal');
177 $command = "$regedit /d HKEY_CURRENT_USER 2>&1";
179 ok
($?
, "regedit.exe return code check");
180 ok
($s =~ /$error_dont_delete_class/, 'Try to remove registry class');
182 #try to delete registry key with incorrect name
183 $command = "$regedit /d BAD_HKEY 2>&1";
185 ok
($?
, "regedit.exe return code check");
187 #should not export anything after removal because the key does not exist
189 ok
(!-e
("${main::orig_reg}.exported"), "Be sure the file is deleted");
190 $command = "$regedit /d \"$test_reg_key\" 2>&1";
192 $command = "$regedit /e ${main::orig_reg}.exported \"$test_reg_key\" 2>&1";
194 ok
(!-e
("${main::orig_reg}.exported"),
195 "File ${main::orig_reg}.exported should not exist");
196 ok
($?
, "regedit.exe return code check");