1use strict; 2use warnings; 3 4use Data::Dumper; 5use Test::More 'no_plan'; 6use Parse::Win32Registry 0.60 qw(make_multiple_subtree_iterator 7 compare_multiple_keys 8 compare_multiple_values); 9 10$Data::Dumper::Useqq = 1; 11$Data::Dumper::Terse = 1; 12$Data::Dumper::Indent = 0; 13 14sub find_file 15{ 16 my $filename = shift; 17 return -d 't' ? "t/$filename" : $filename; 18} 19 20sub run_compare_tests 21{ 22 my @registries = @{shift @_}; 23 my @tests = @_; 24 25 my $any_registry = (grep { defined } @registries)[0]; 26 27 my ($os) = ref($any_registry) =~ /Win(NT|95)/; 28 29 my @root_keys = map { $_->get_root_key } @registries; 30 my $subtree_iter = make_multiple_subtree_iterator(@root_keys); 31 32 foreach my $test (@tests) { 33 my $key_path = $test->[0]; 34 my $value_name = $test->[1]; 35 my @changes = @{$test->[2]}; 36 my $changes_as_text = join ", ", map { "'$_'" } @changes; 37 38 my $desc = "$os"; 39 40 my ($keys_ref, $values_ref) = $subtree_iter->get_next; 41 my @keys = @$keys_ref; 42 my $any_key = (grep { defined } @keys)[0]; 43 44 if (defined $values_ref) { 45 my @values = @$values_ref; 46 my $any_value = (grep { defined } @values)[0]; 47 48 is($any_value->get_name, $value_name, 49 "$desc comparing values " . Dumper($value_name)); 50 51 is_deeply([compare_multiple_values(@values)], \@changes, 52 "$desc ...changes are ($changes_as_text)"); 53 } 54 else { 55 is($any_key->get_path, $key_path, 56 "$desc comparing keys " . Dumper($key_path)); 57 58 is_deeply([compare_multiple_keys(@keys)], \@changes, 59 "$desc ...changes are ($changes_as_text)"); 60 61 } 62 } 63} 64 65{ 66 my @filenames = map { find_file($_) } qw(win95_compare_tests1.rf 67 win95_compare_tests2.rf 68 win95_compare_tests3.rf); 69 70 my @registries = map { Parse::Win32Registry->new($_) } @filenames; 71 72 my $num = 0; 73 foreach my $registry (@registries) { 74 ok(defined($registry), 'registry '.++$num.' defined'); 75 isa_ok($registry, 'Parse::Win32Registry::Win95::File'); 76 } 77 78 my @tests = ( 79 ['', '', ['', '', ''],], 80 ['\key1', '', ['', '', ''],], 81 ['\key1', 'value1', ['', '', ''],], 82 ['\key1', 'value2', ['', '', ''],], 83 ['\key1', 'value3', ['', '', ''],], 84 ['\key1', 'value4', ['', 'DELETED', ''],], 85 ['\key1', 'value5', ['', '', 'ADDED'],], 86 ['\key2', '', ['', '', ''],], 87 ['\key2\key3', '', ['', '', ''],], 88 ['\key2\key4', '', ['', 'DELETED', ''],], 89 ['\key2\key5', '', ['', '', 'ADDED'],], 90 ); 91 92 run_compare_tests(\@registries, @tests); 93} 94 95{ 96 my @filenames = map { find_file($_) } qw(winnt_compare_tests1.rf 97 winnt_compare_tests2.rf 98 winnt_compare_tests3.rf); 99 100 my @registries = map { Parse::Win32Registry->new($_) } @filenames; 101 102 my $num = 0; 103 foreach my $registry (@registries) { 104 ok(defined($registry), 'registry '.++$num.' defined'); 105 isa_ok($registry, 'Parse::Win32Registry::WinNT::File'); 106 } 107 108 my @tests = ( 109 ['$$$PROTO.HIV', '', ['', '', ''],], 110 ['$$$PROTO.HIV\key1', '', ['', '', ''],], 111 ['$$$PROTO.HIV\key1', 'value1', ['', '', ''],], 112 ['$$$PROTO.HIV\key1', 'value2', ['', '', ''],], 113 ['$$$PROTO.HIV\key1', 'value3', ['', '', ''],], 114 ['$$$PROTO.HIV\key1', 'value4', ['', 'DELETED', ''],], 115 ['$$$PROTO.HIV\key1', 'value5', ['', '', 'ADDED'],], 116 ['$$$PROTO.HIV\key2', '', ['', '', ''],], 117 ['$$$PROTO.HIV\key2\key3', '', ['', '', ''],], 118 ['$$$PROTO.HIV\key2\key4', '', ['', 'DELETED', ''],], 119 ['$$$PROTO.HIV\key2\key5', '', ['', '', 'ADDED'],], 120 ); 121 122 run_compare_tests(\@registries, @tests); 123} 124