From f5aad76936778219968255ca93f901b1d995811c Mon Sep 17 00:00:00 2001 From: Andriy Palamarchuk Date: Thu, 20 Jun 2002 23:09:33 +0000 Subject: [PATCH] Added regedit unit test, a couple minor changes to regedit. --- configure | 5 + configure.ac | 1 + programs/regedit/Makefile.in | 5 + programs/regedit/regedit.c | 1 + programs/regedit/tests/.cvsignore | 1 + programs/regedit/tests/orig.reg | 40 ++++++ programs/regedit/tests/regedit.pl | 212 ++++++++++++++++++++++++++++++ 7 files changed, 265 insertions(+) create mode 100644 programs/regedit/tests/.cvsignore create mode 100644 programs/regedit/tests/orig.reg create mode 100644 programs/regedit/tests/regedit.pl diff --git a/configure b/configure index 04eb09b19df..031f01d3757 100755 --- a/configure +++ b/configure @@ -13105,6 +13105,8 @@ ac_config_commands="$ac_config_commands objects" ac_config_commands="$ac_config_commands programs/regapi/tests" +ac_config_commands="$ac_config_commands programs/regedit/tests" + ac_config_commands="$ac_config_commands programs/winetest/tests" ac_config_commands="$ac_config_commands relay32" @@ -13771,6 +13773,7 @@ do "msdos" ) CONFIG_COMMANDS="$CONFIG_COMMANDS msdos" ;; "objects" ) CONFIG_COMMANDS="$CONFIG_COMMANDS objects" ;; "programs/regapi/tests" ) CONFIG_COMMANDS="$CONFIG_COMMANDS programs/regapi/tests" ;; + "programs/regedit/tests" ) CONFIG_COMMANDS="$CONFIG_COMMANDS programs/regedit/tests" ;; "programs/winetest/tests" ) CONFIG_COMMANDS="$CONFIG_COMMANDS programs/winetest/tests" ;; "relay32" ) CONFIG_COMMANDS="$CONFIG_COMMANDS relay32" ;; "scheduler" ) CONFIG_COMMANDS="$CONFIG_COMMANDS scheduler" ;; @@ -14481,6 +14484,8 @@ echo "$as_me: creating msdos" >&6;} && mkdir "msdos") ;; echo "$as_me: creating objects" >&6;} && mkdir "objects") ;; programs/regapi/tests ) test -d "programs/regapi/tests" || ({ echo "$as_me:$LINENO: creating programs/regapi/tests" >&5 echo "$as_me: creating programs/regapi/tests" >&6;} && mkdir "programs/regapi/tests") ;; + programs/regedit/tests ) test -d "programs/regedit/tests" || ({ echo "$as_me:$LINENO: creating programs/regedit/tests" >&5 +echo "$as_me: creating programs/regedit/tests" >&6;} && mkdir "programs/regedit/tests") ;; programs/winetest/tests ) test -d "programs/winetest/tests" || ({ echo "$as_me:$LINENO: creating programs/winetest/tests" >&5 echo "$as_me: creating programs/winetest/tests" >&6;} && mkdir "programs/winetest/tests") ;; relay32 ) test -d "relay32" || ({ echo "$as_me:$LINENO: creating relay32" >&5 diff --git a/configure.ac b/configure.ac index 7bf712eeb1d..5a89e5544c1 100644 --- a/configure.ac +++ b/configure.ac @@ -1213,6 +1213,7 @@ WINE_CONFIG_EXTRA_DIR(misc) WINE_CONFIG_EXTRA_DIR(msdos) WINE_CONFIG_EXTRA_DIR(objects) WINE_CONFIG_EXTRA_DIR(programs/regapi/tests) +WINE_CONFIG_EXTRA_DIR(programs/regedit/tests) WINE_CONFIG_EXTRA_DIR(programs/winetest/tests) WINE_CONFIG_EXTRA_DIR(relay32) WINE_CONFIG_EXTRA_DIR(scheduler) diff --git a/programs/regedit/Makefile.in b/programs/regedit/Makefile.in index 2feea04424a..13ff18bf2b0 100644 --- a/programs/regedit/Makefile.in +++ b/programs/regedit/Makefile.in @@ -10,6 +10,11 @@ C_SRCS = \ regedit.c \ regproc.c +PLTESTS = \ + tests/regedit.pl + +EXTRASUBDIRS = tests + @MAKE_PROG_RULES@ ### Dependencies: diff --git a/programs/regedit/regedit.c b/programs/regedit/regedit.c index 823604433c6..821aa1b4c47 100644 --- a/programs/regedit/regedit.c +++ b/programs/regedit/regedit.c @@ -180,6 +180,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, } else { perror(""); printf("%s: Can't open file \"%s\"\n", getAppName(), filename); + exit(1); } get_file_name(&s, filename); } diff --git a/programs/regedit/tests/.cvsignore b/programs/regedit/tests/.cvsignore new file mode 100644 index 00000000000..6fe4b48d57e --- /dev/null +++ b/programs/regedit/tests/.cvsignore @@ -0,0 +1 @@ +regedit.ok diff --git a/programs/regedit/tests/orig.reg b/programs/regedit/tests/orig.reg new file mode 100644 index 00000000000..0295d4350e1 --- /dev/null +++ b/programs/regedit/tests/orig.reg @@ -0,0 +1,40 @@ +REGEDIT4 + +[HKEY_CURRENT_USER\Test Regapi] + +[HKEY_CURRENT_USER\Test Regapi\New Key #1] +@="222Sample default value data, very long, very long, very long, very long, very long, very long, very long, very long, very long, very long, very long, very long, very long, very long, very long, very long, very long,end" +"A- \" Binary Value #1, long name \\ []= long long long long long long long long long long long long end"=hex:30,\ + 31,32,33,34,35,36,37,38,39,30,31,32,33,34,35,36,37,38,39,30,31,32,33,34,35,\ + 36,37,38,39,30,31,32,33,34,35,36,37,38,39,30,31,32,33,34,35,36,37,38,39,30,\ + 31,32,33,34,35,36,37,38,39,30,31,32,33,34,35,36,37,38,39,30,31,32,33,34,35,\ + 36,37,38,39,30,31,32,33,34,35,36,37,38,39,30,31,32,33,34,35,36,37,38,39,30,\ + 31,32,33,34,35,36,37,38,39,30,31,32,33,34,35,36,37,38,39,30,31,32,33,34,35,\ + 36,37,38,39,30,31,32,33,34,35,36,37,38,39,30,31,32,33,34,35,36,37,38,39,30,\ + 31,32,33,34,35,36,37,38,39,30,31,32,33,34,35,36,37,38,39,30,31,32,33,34,35,\ + 36,37,38,39,30,31,32,33,34,35,36,37,38,39,30,31,32,33,34,35,36,37,38,39,30,\ + 31,32,33,34,35,36,37,38,39,30,31,32,33,34,35,36,37,38,39,30,31,32,33,34,35,\ + 36,37,38,39,30,31,32,33,34,35,36,37,38,39,30,31,32,33,34,35,36,37,38,39,30,\ + 31,32,33,34,35,36,37,38,39,30,31,32,33,34,35,36,37,38,39,30,31,32,33,34,35,\ + 36 +"a1"="" +"New Binary Value #2"=hex: +"New DWORD Value #1"=dword:00000200 +"New DWORD Value #2"=dword:000000c9 +"New DWORD Value #3"=dword:00000000 +"New String Value #1"="One more long string value 1,2,3,4,5,6,7,8,9,0 1,2,3,4,5,6,7,8,9,0 1,2,3,4,5,6,7,8,9,0 1,2,3,4,5,6,7,8,9,0 1,2,3,4,5,6,7,8,9,0 1,2,3,4,5,6,7,8,9,0 1,2,3,4,5,6,7,8,9,0 1,2,3,4,5,6,7,8,9,0 1,2,3,4,5,6 end" +"New String Value #2"="" +"v1"="\" \\,=[]" + +[HKEY_CURRENT_USER\Test Regapi\New Key #1\New Key #2] + +[HKEY_CURRENT_USER\Test Regapi\New Key #1\New Key #2\New Key #3] + +[HKEY_CURRENT_USER\Test Regapi\New Key #1\New Key #2\New Key #3\New Key #4] +@="" + +[HKEY_CURRENT_USER\Test Regapi\New Key #1\New Key #2\New Key #3\New Key #4\New Key #5] + +[HKEY_CURRENT_USER\Test Regapi\New Key #1\New Key #2\New Key #3\New Key #4.1] + +[HKEY_CURRENT_USER\Test Regapi\New Key #1\New Key #2\New Key #3\New Key #6] diff --git a/programs/regedit/tests/regedit.pl b/programs/regedit/tests/regedit.pl new file mode 100644 index 00000000000..1e19cec327a --- /dev/null +++ b/programs/regedit/tests/regedit.pl @@ -0,0 +1,212 @@ +#!/usr/bin/perl -w +# +# This script tests regapi functionality +# +# Copyright 2002 Andriy Palamarchuk +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +use strict; +use diagnostics; +use wine; + +$main::orig_reg = './tests/orig.reg'; + +test_regedit(); + +# Imitation of test framework "ok". +# Uncomment when running on Windows without testing framework +#sub ok($;$) +#{ +# my ($condition, $message) = @_; +# if (!$condition) +# { +# die $message; +# } +#} + +# Checks if the files are equal regardless of the encoding. +# Returns 0 if the files are different, otherwise returns 1 +# params - list of file names +sub files_are_equal +{ + my @file_names = @_; + my @files = (); + + die "At least 2 file names expected" unless ($#file_names); + + #compare the files sizes + my $sizes_are_equal = 1; + foreach my $file_name (@file_names) + { + -e $file_name || die "Error! File $file_name does not exist"; + if (-s $file_names[0] != -s $file_name) + { + $sizes_are_equal = 0; + last; + } + } + return 1 if $sizes_are_equal; + + #compare file contents + foreach my $file_name (@file_names) + { + my $file; + open($file, "<$file_name") || die "Error! can't open file $file_name"; + push(@files, $file); + } + + my $first_file = shift(@files); + my $line1; + my $line2; + while ($line1 = <$first_file>) + { + $line1 =~ s/\r//; + chomp($line1); + foreach my $file (@files) + { + $line2 = <$file>; + $line2 =~ s/\r//; + chomp($line2); + return 0 if $line1 ne $line2; + } + } + return 1; +} + +#removes all test output files +sub clear_output +{ + unlink "${main::orig_reg}.exported"; + unlink "${main::orig_reg}.exported2"; +} + +#tests compatibility with regedit +sub test_regedit +{ + my $error_no_file_name = "regedit: No file name is specified"; + my $error_undefined_switch = "regedit: Undefined switch /"; + my $error_no_registry_key = "regedit: No registry key is specified"; + my $error_file_not_found = 'regedit: Can\'t open file "dummy_file_name"'; + my $error_bad_reg_class_name = 'regedit: Incorrect registry class specification in'; + my $error_dont_delete_class = 'regedit: Can\'t delete registry class'; + + my $test_reg_key = 'HKEY_CURRENT_USER\Test Regapi'; + + my $s; + my $regedit = -e "./regedit.exe" ? ".\\regedit.exe" : "./regedit"; + + #no parameters + my $command = "$regedit 2>&1"; + $s = qx/$command/; + ok($?, "regedit.exe return code check"); + ok($s =~ /$error_no_file_name/, + 'Should raise an error on missed file name'); + + #ignored parameters + $command = "$regedit /S /V /R:1.reg /L:ss_ss.reg 2>&1"; + $s = qx/$command/; + ok($?, "regedit.exe return code check"); + ok($s =~ /$error_no_file_name/, + 'Should raise an error on missed file name'); + + #incorrect form for /L, /R parameters + for my $switch ('L', 'R') + { + $command = "$regedit /$switch 2>&1"; + $s = qx/$command/; + ok($?, "regedit.exe return code check"); + ok($s =~ /$error_undefined_switch/, "Incorrect switch format check"); + #with ':' + $command = "$regedit /$switch: 2>&1"; + $s = qx/$command/; + ok($?, "regedit.exe return code check"); + ok($s =~ /$error_no_file_name/, "Incorrect switch format check"); + } + + #file does not exist + $command = "$regedit dummy_file_name 2>&1"; + $s = qx/$command/; + ok($?, "regedit.exe return code check"); + ok($s =~ /$error_file_not_found/, 'Incorrect processing of not-existing file'); + + #incorrect registry class is specified + $command = "$regedit /e ${main::orig_reg}.exported \"BAD_CLASS_HKEY\" 2>&1"; + $s = qx/$command/; + ok($?, "regedit.exe return code check"); + ok($s =~ /$error_bad_reg_class_name/, 'Incorrect processing of not-existing file'); + + #import registry file, export registry file, compare the files + $command = "$regedit ${main::orig_reg} 2>&1"; + $s = qx/$command/; + ok(!$?, "regedit.exe return code check"); + $command = "$regedit /e ${main::orig_reg}.exported \"$test_reg_key\" 2>&1"; + $s = qx/$command/; + ok(!$?, "regedit.exe return code check"); + ok(files_are_equal("${main::orig_reg}.exported", $main::orig_reg), + "Original and generated registry files " . + "(${main::orig_reg}.exported and ${main::orig_reg}) " . + "are different"); + clear_output(); + + #export bare registry class (2 formats of command line parameter) + #XXX works fine under wine, but commented out because does not handle all key types + #existing on Windows and Windows registry is *very* big +# $command = "$regedit /e ${main::orig_reg}.exported HKEY_CURRENT_USER 2>&1"; +# $s = qx/$command/; +# print("DEBUG\t result: $s, return code - $?\n"); +# ok(!$?, "regedit.exe return code check"); +# $command = "$regedit /e ${main::orig_reg}.exported2 HKEY_CURRENT_USER 2>&1"; +# qx/$command/; +# ok(!$?, "regedit.exe return code check"); +# ok(files_are_equal("${main::orig_reg}.exported", "${main::orig_reg}.exported2"), +# "Original and generated registry files " . +# "(${main::orig_reg}.exported and ${main::orig_reg}.exported2) " . +# "are different"); + + ##test removal + + #incorrect format + $command = "$regedit /d 2>&1"; + $s = qx/$command/; + ok($?, "regedit.exe return code check"); + ok($s =~ /$error_no_registry_key/, + 'No registry key name is specified for removal'); + + #try to delete class + $command = "$regedit /d HKEY_CURRENT_USER 2>&1"; + $s = qx/$command/; + ok($?, "regedit.exe return code check"); + ok($s =~ /$error_dont_delete_class/, 'Try to remove registry class'); + + #try to delete registry key with incorrect name + $command = "$regedit /d BAD_HKEY 2>&1"; + $s = qx/$command/; + ok($?, "regedit.exe return code check"); + + #should not export anything after removal because the key does not exist + clear_output(); + ok(!-e("${main::orig_reg}.exported"), "Be sure the file is deleted"); + $command = "$regedit /d \"$test_reg_key\" 2>&1"; + $s = qx/$command/; + $command = "$regedit /e ${main::orig_reg}.exported \"$test_reg_key\" 2>&1"; + $s = qx/$command/; + ok(!-e("${main::orig_reg}.exported"), + "File ${main::orig_reg}.exported should not exist"); + ok($?, "regedit.exe return code check"); + + clear_output(); +}