1 # Win::Hivex::Regedit test -*- perl -*-
2 # Copyright (C) 2010 Red Hat Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 use Test::More tests => 16;
26 use Win::Hivex::Regedit qw(reg_import reg_export);
28 my $srcdir = $ENV{srcdir} || ".";
30 my $h = Win::Hivex->open ("$srcdir/../images/minimal", write => 1);
33 my ($data, $expected);
35 # Note that we don't clear the hive between tests, so results of
36 # next test depend on the previous test.
44 "Key1"=hex(2):48,00,65,00,6c,00,6c,00,6f,00
46 "Key3"=hex:48,00,65,00,6c,00,6c,00,6f,00,\
47 48,00,65,00,6c,00,6c,00,6f,00
48 "Key4"=dword:ff123456';
56 "Key1"=hex(2):48,00,65,00,6c,00,6c,00,6f,00
57 "Key2"=hex(2):48,00,65,00,6c,00,6c,00,6f,00,00,00
58 "Key3"=hex(3):48,00,65,00,6c,00,6c,00,6f,00,48,00,65,00,6c,00,6c,00,6f,00
63 run_test ($data, $expected);
74 @=hex(1):48,00,65,00,6c,00,6c,00,6f,00,00,00
77 "Key1"=hex(2):48,00,65,00,6c,00,6c,00,6f,00
78 "Key2"=hex(2):48,00,65,00,6c,00,6c,00,6f,00,00,00
79 "Key3"=hex(3):48,00,65,00,6c,00,6c,00,6f,00,48,00,65,00,6c,00,6c,00,6f,00
84 run_test ($data, $expected);
102 run_test ($data, $expected);
104 # In the next test, the value of ValueContainingEscapes in the
105 # imported data is \\W\\, which will become \W\ in the final hive.
106 # However Perl has complex and inconsistent rules on quoting
108 # http://en.wikibooks.org/wiki/Perl_Programming/Strings#Single_Quoted_Strings
114 "Key\"Containing\"Quotes"=hex(0):
115 "ValueContainingEscapes"="\\\\W\\\\"
122 "Key\"Containing\"Quotes"=hex(0):
123 "ValueContainingEscapes"=hex(1):5c,00,57,00,5c,00,00,00
127 run_test ($data, $expected);
131 "Key\"Containing\"Quotes"=-
132 "ValueContainingEscapes"=-
140 run_test ($data, $expected);
142 #----------------------------------------------------------------------
146 my $expected = shift;
148 my $fh = new IO::Scalar \$data;
149 reg_import ($fh, $h);
152 $fh = new IO::Scalar;
153 reg_export ($h, "\\", $fh);
156 my $actual = ${$fh->sref};
157 warn "\n\n----- ACTUAL -----\n$actual\n----- EXPECTED -----\n$expected\n\n"
158 if $actual ne $expected;
160 ok ($actual eq $expected)