Split routines that don't rely on C functions into winetest.pm so that
[wine/multimedia.git] / programs / regedit / tests / regedit.pl
blob374d3ea101fbeae96058d7b08262421fd6a62404
1 #!/usr/bin/perl -w
3 # This script tests regapi 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
22 use strict;
23 use diagnostics;
24 use winetest;
26 $main::orig_reg = './tests/orig.reg';
28 test_regedit();
30 # Imitation of test framework "ok".
31 # Uncomment when running on Windows without testing framework
32 # sub ok($;$)
33 # {
34 # my ($condition, $message) = @_;
35 # if (!$condition)
36 # {
37 # die $message;
38 # }
39 # }
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
44 sub files_are_equal
46 my @file_names = @_;
47 my @files = ();
49 die "At least 2 file names expected" unless ($#file_names);
51 #compare file contents
52 foreach my $file_name (@file_names)
54 my $file;
55 open($file, "<$file_name") || die "Error! can't open file $file_name";
56 push(@files, $file);
59 my $first_file = shift(@files);
60 my $line1;
61 my $line2;
62 while ($line1 = <$first_file>)
64 $line1 =~ s/\r//;
65 chomp($line1);
66 foreach my $file (@files)
68 $line2 = <$file>;
69 $line2 =~ s/\r//;
70 chomp($line2);
71 return 0 if $line1 ne $line2;
74 return 1;
77 #removes all test output files
78 sub clear_output
80 unlink "${main::orig_reg}.exported";
81 unlink "${main::orig_reg}.exported2";
84 #tests compatibility with regedit
85 sub test_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 Regapi';
96 my $s;
97 my $regedit = -e "./regedit.exe" ? ".\\regedit.exe" : "./regedit";
99 #no parameters
100 my $command = "$regedit 2>&1";
101 $s = qx/$command/;
102 ok($?, "regedit.exe return code check");
103 ok($s =~ /$error_no_file_name/,
104 'Should raise an error on missed file name');
106 #ignored parameters
107 $command = "$regedit /S /V /R:1.reg /L:ss_ss.reg 2>&1";
108 $s = qx/$command/;
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";
117 $s = qx/$command/;
118 ok($?, "regedit.exe return code check");
119 ok($s =~ /$error_undefined_switch/, "Incorrect switch format check");
120 #with ':'
121 $command = "$regedit /$switch: 2>&1";
122 $s = qx/$command/;
123 ok($?, "regedit.exe return code check");
124 ok($s =~ /$error_no_file_name/, "Incorrect switch format check");
127 #file does not exist
128 $command = "$regedit dummy_file_name 2>&1";
129 $s = qx/$command/;
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";
135 $s = qx/$command/;
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";
141 $s = qx/$command/;
142 ok(!$?, "regedit.exe return code check");
143 $command = "$regedit /e ${main::orig_reg}.exported \"$test_reg_key\" 2>&1";
144 $s = qx/$command/;
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}) " .
149 "are different");
150 clear_output();
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";
156 # $s = qx/$command/;
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";
160 # qx/$command/;
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) " .
165 # "are different");
167 ##test removal
169 #incorrect format
170 $command = "$regedit /d 2>&1";
171 $s = qx/$command/;
172 ok($?, "regedit.exe return code check");
173 ok($s =~ /$error_no_registry_key/,
174 'No registry key name is specified for removal');
176 #try to delete class
177 $command = "$regedit /d HKEY_CURRENT_USER 2>&1";
178 $s = qx/$command/;
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";
184 $s = qx/$command/;
185 ok($?, "regedit.exe return code check");
187 #should not export anything after removal because the key does not exist
188 clear_output();
189 ok(!-e("${main::orig_reg}.exported"), "Be sure the file is deleted");
190 $command = "$regedit /d \"$test_reg_key\" 2>&1";
191 $s = qx/$command/;
192 $command = "$regedit /e ${main::orig_reg}.exported \"$test_reg_key\" 2>&1";
193 $s = qx/$command/;
194 ok(!-e("${main::orig_reg}.exported"),
195 "File ${main::orig_reg}.exported should not exist");
196 ok($?, "regedit.exe return code check");
198 clear_output();