Pull translations from Transifex.
[hivex.git] / perl / t / 550-regedit-export.t
1 # Win::Hivex::Regedit test -*- perl -*-
2 # Copyright (C) 2010 Red Hat Inc.
3 #
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.
8 #
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.
13 #
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.
17
18 use strict;
19 use warnings;
20
21 use Encode qw(from_to);
22 use IO::Scalar;
23
24 use Test::More tests => 8;
25
26 use Win::Hivex;
27 use Win::Hivex::Regedit qw(reg_export);
28
29 my $srcdir = $ENV{srcdir} || ".";
30
31 my $h = Win::Hivex->open ("$srcdir/../images/minimal", write => 1);
32 ok ($h);
33
34 my $root = $h->root ();
35 ok ($root);
36
37 $h->node_add_child ($root, "B");
38 ok (1);
39
40 $h->node_add_child ($root, "A");
41 ok (1);
42
43 my $b = $h->node_get_child ($root, "B");
44 ok ($b);
45
46 # Encode a string as UTF16-LE.
47 sub utf16le
48 {
49     my $s = shift;
50     from_to ($s, "ascii", "utf-16le");
51     $s;
52 }
53
54 # Convert a 32 bit integer to a little endian 4 byte data field.
55 sub dwordle
56 {
57     pack ("V", $_[0]);
58 }
59
60 my @values = (
61     # Values are entered in a random order here, but they should be
62     # sorted on export.
63     { key => "Key2", t => 2, value => utf16le ("DEF") },
64     { key => "", t => 1, value => "Default" },
65     { key => "Key3", t => 4, value => dwordle (0xff876543) },
66     { key => "Key1", t => 1, value => "ABC" },
67     );
68 $h->node_set_values ($b, \@values);
69 ok (1);
70
71 my $fh = new IO::Scalar;
72 reg_export ($h, "\\", $fh, prefix => "HKEY_LOCAL_MACHINE\\SOFTWARE\\");
73
74 my $expected = '[HKEY_LOCAL_MACHINE\\SOFTWARE\\]
75
76 [HKEY_LOCAL_MACHINE\\SOFTWARE\\A]
77
78 [HKEY_LOCAL_MACHINE\\SOFTWARE\\B]
79 @=hex(1):44,65,66,61,75,6c,74
80 "Key1"=hex(1):41,42,43
81 "Key2"=hex(2):44,00,45,00,46,00
82 "Key3"=dword:ff876543
83
84 ';
85
86 ok (${$fh->sref} eq $expected);
87
88 $fh = new IO::Scalar;
89 reg_export ($h, "\\B", $fh);
90
91 $expected = '[\\B]
92 @=hex(1):44,65,66,61,75,6c,74
93 "Key1"=hex(1):41,42,43
94 "Key2"=hex(2):44,00,45,00,46,00
95 "Key3"=dword:ff876543
96
97 ';
98
99 ok (${$fh->sref} eq $expected);
100
101 # don't commit because that would overwrite the original file
102 # $h->commit ();