2 Unix SMB/CIFS implementation.
4 local testing of registry library
6 Copyright (C) Jelmer Vernooij 2005-2007
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "lib/registry/registry.h"
24 #include "torture/torture.h"
25 #include "librpc/gen_ndr/winreg.h"
26 #include "param/param.h"
27 #include "lib/registry/tests/proto.h"
29 static bool test_str_regtype(struct torture_context
*ctx
)
31 torture_assert_str_equal(ctx
, str_regtype(0),
32 "REG_NONE", "REG_NONE failed");
33 torture_assert_str_equal(ctx
, str_regtype(1),
34 "REG_SZ", "REG_SZ failed");
35 torture_assert_str_equal(ctx
, str_regtype(2),
36 "REG_EXPAND_SZ", "REG_EXPAND_SZ failed");
37 torture_assert_str_equal(ctx
, str_regtype(3),
38 "REG_BINARY", "REG_BINARY failed");
39 torture_assert_str_equal(ctx
, str_regtype(4),
40 "REG_DWORD", "REG_DWORD failed");
41 torture_assert_str_equal(ctx
, str_regtype(5),
42 "REG_DWORD_BIG_ENDIAN", "REG_DWORD_BIG_ENDIAN failed");
43 torture_assert_str_equal(ctx
, str_regtype(6),
44 "REG_LINK", "REG_LINK failed");
45 torture_assert_str_equal(ctx
, str_regtype(7),
46 "REG_MULTI_SZ", "REG_MULTI_SZ failed");
47 torture_assert_str_equal(ctx
, str_regtype(8),
48 "REG_RESOURCE_LIST", "REG_RESOURCE_LIST failed");
49 torture_assert_str_equal(ctx
, str_regtype(9),
50 "REG_FULL_RESOURCE_DESCRIPTOR", "REG_FULL_RESOURCE_DESCRIPTOR failed");
51 torture_assert_str_equal(ctx
, str_regtype(10),
52 "REG_RESOURCE_REQUIREMENTS_LIST", "REG_RESOURCE_REQUIREMENTS_LIST failed");
53 torture_assert_str_equal(ctx
, str_regtype(11),
54 "REG_QWORD", "REG_QWORD failed");
60 static bool test_reg_val_data_string_dword(struct torture_context
*ctx
)
62 uint8_t d
[] = { 0x20, 0x00, 0x00, 0x00 };
63 DATA_BLOB db
= { d
, 4 };
64 torture_assert_str_equal(ctx
, "0x00000020",
65 reg_val_data_string(ctx
, REG_DWORD
, db
),
70 static bool test_reg_val_data_string_dword_big_endian(struct torture_context
*ctx
)
72 uint8_t d
[] = { 0x20, 0x00, 0x00, 0x00 };
73 DATA_BLOB db
= { d
, 4 };
74 torture_assert_str_equal(ctx
, "0x00000020",
75 reg_val_data_string(ctx
, REG_DWORD_BIG_ENDIAN
, db
),
80 static bool test_reg_val_data_string_qword(struct torture_context
*ctx
)
82 uint8_t d
[] = { 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
83 DATA_BLOB db
= { d
, 8 };
84 torture_assert_str_equal(ctx
, "0x0000000000000020",
85 reg_val_data_string(ctx
, REG_QWORD
, db
),
90 static bool test_reg_val_data_string_sz(struct torture_context
*ctx
)
93 convert_string_talloc(ctx
, CH_UTF8
, CH_UTF16
,
94 "bla", 3, (void **)&db
.data
, &db
.length
);
95 torture_assert_str_equal(ctx
, "bla",
96 reg_val_data_string(ctx
, REG_SZ
, db
),
99 torture_assert_str_equal(ctx
, "bl",
100 reg_val_data_string(ctx
, REG_SZ
, db
),
105 static bool test_reg_val_data_string_binary(struct torture_context
*ctx
)
107 uint8_t x
[] = { 0x1, 0x2, 0x3, 0x4 };
108 DATA_BLOB db
= { x
, 4 };
109 torture_assert_str_equal(ctx
, "01020304",
110 reg_val_data_string(ctx
, REG_BINARY
, db
),
116 static bool test_reg_val_data_string_empty(struct torture_context
*ctx
)
118 DATA_BLOB db
= { NULL
, 0 };
119 torture_assert_str_equal(ctx
, "",
120 reg_val_data_string(ctx
, REG_BINARY
, db
),
125 static bool test_reg_val_description(struct torture_context
*ctx
)
128 convert_string_talloc(ctx
, CH_UTF8
, CH_UTF16
,
129 "stationary traveller",
130 strlen("stationary traveller"),
131 (void **)&data
.data
, &data
.length
);
132 torture_assert_str_equal(ctx
, "camel = REG_SZ : stationary traveller",
133 reg_val_description(ctx
, "camel", REG_SZ
, data
),
134 "reg_val_description failed");
139 static bool test_reg_val_description_nullname(struct torture_context
*ctx
)
142 convert_string_talloc(ctx
, CH_UTF8
, CH_UTF16
,
144 strlen("west berlin"),
145 (void **)&data
.data
, &data
.length
);
146 torture_assert_str_equal(ctx
, "<No Name> = REG_SZ : west berlin",
147 reg_val_description(ctx
, NULL
, REG_SZ
, data
),
148 "description with null name failed");
152 struct torture_suite
*torture_registry(TALLOC_CTX
*mem_ctx
)
154 struct torture_suite
*suite
= torture_suite_create(mem_ctx
, "registry");
155 torture_suite_add_simple_test(suite
, "str_regtype",
157 torture_suite_add_simple_test(suite
, "reg_val_data_string dword",
158 test_reg_val_data_string_dword
);
159 torture_suite_add_simple_test(suite
, "reg_val_data_string dword_big_endian",
160 test_reg_val_data_string_dword_big_endian
);
161 torture_suite_add_simple_test(suite
, "reg_val_data_string qword",
162 test_reg_val_data_string_qword
);
163 torture_suite_add_simple_test(suite
, "reg_val_data_string sz",
164 test_reg_val_data_string_sz
);
165 torture_suite_add_simple_test(suite
, "reg_val_data_string binary",
166 test_reg_val_data_string_binary
);
167 torture_suite_add_simple_test(suite
, "reg_val_data_string empty",
168 test_reg_val_data_string_empty
);
169 torture_suite_add_simple_test(suite
, "reg_val_description",
170 test_reg_val_description
);
171 torture_suite_add_simple_test(suite
, "reg_val_description null",
172 test_reg_val_description_nullname
);
174 torture_suite_add_suite(suite
, torture_registry_hive(suite
));
175 torture_suite_add_suite(suite
, torture_registry_registry(suite
));
176 torture_suite_add_suite(suite
, torture_registry_diff(suite
));