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 "lib/cmdline/popt_common.h"
25 #include "torture/torture.h"
26 #include "librpc/gen_ndr/winreg.h"
28 struct torture_suite *torture_registry_hive(TALLOC_CTX *mem_ctx);
29 struct torture_suite *torture_registry_registry(TALLOC_CTX *mem_ctx);
30 struct torture_suite *torture_registry_diff(TALLOC_CTX *mem_ctx);
32 static bool test_str_regtype(struct torture_context *ctx)
34 torture_assert_str_equal(ctx, str_regtype(1), "REG_SZ", "REG_SZ failed");
35 torture_assert_str_equal(ctx, str_regtype(4), "REG_DWORD", "REG_DWORD failed");
41 static bool test_reg_val_data_string_dword(struct torture_context *ctx)
44 DATA_BLOB db = { (uint8_t *)&d, sizeof(d) };
45 torture_assert_str_equal(ctx, "0x20",
46 reg_val_data_string(ctx, REG_DWORD, db), "dword failed");
50 static bool test_reg_val_data_string_sz(struct torture_context *ctx)
53 db.length = convert_string_talloc(ctx, CH_UNIX, CH_UTF16, "bla", 3, (void **)&db.data);
54 torture_assert_str_equal(ctx, "bla", reg_val_data_string(ctx, REG_SZ, db), "sz failed");
56 torture_assert_str_equal(ctx, "bl", reg_val_data_string(ctx, REG_SZ, db), "sz failed");
60 static bool test_reg_val_data_string_binary(struct torture_context *ctx)
62 uint8_t x[] = { 0x1, 0x2, 0x3, 0x4 };
63 DATA_BLOB db = { x, 4 };
64 torture_assert_str_equal(ctx, "01020304",
65 reg_val_data_string(ctx, REG_BINARY, db),
71 static bool test_reg_val_data_string_empty(struct torture_context *ctx)
73 DATA_BLOB db = { NULL, 0 };
74 torture_assert_str_equal(ctx, "",
75 reg_val_data_string(ctx, REG_BINARY, db), "empty failed");
79 static bool test_reg_val_description(struct torture_context *ctx)
82 data.length = convert_string_talloc(ctx, CH_UNIX, CH_UTF16,
83 "stationary traveller",
84 strlen("stationary traveller"),
86 torture_assert_str_equal(ctx, "camel = REG_SZ : stationary traveller",
87 reg_val_description(ctx, "camel", REG_SZ, data),
88 "reg_val_description failed");
93 static bool test_reg_val_description_nullname(struct torture_context *ctx)
96 data.length = convert_string_talloc(ctx, CH_UNIX, CH_UTF16, "west berlin",
97 strlen("west berlin"), (void **)&data.data);
98 torture_assert_str_equal(ctx, "<No Name> = REG_SZ : west berlin",
99 reg_val_description(ctx, NULL, REG_SZ, data),
100 "description with null name failed");
106 struct torture_suite *torture_registry(TALLOC_CTX *mem_ctx)
108 struct torture_suite *suite = torture_suite_create(mem_ctx,
110 torture_suite_add_simple_test(suite, "str_regtype", test_str_regtype);
111 torture_suite_add_simple_test(suite, "reg_val_data_string dword",
112 test_reg_val_data_string_dword);
113 torture_suite_add_simple_test(suite, "reg_val_data_string sz",
114 test_reg_val_data_string_sz);
115 torture_suite_add_simple_test(suite, "reg_val_data_string binary",
116 test_reg_val_data_string_binary);
117 torture_suite_add_simple_test(suite, "reg_val_data_string empty",
118 test_reg_val_data_string_empty);
119 torture_suite_add_simple_test(suite, "reg_val_description",
120 test_reg_val_description);
121 torture_suite_add_simple_test(suite, "reg_val_description null",
122 test_reg_val_description_nullname);
124 torture_suite_add_suite(suite, torture_registry_hive(mem_ctx));
125 torture_suite_add_suite(suite, torture_registry_registry(mem_ctx));
126 torture_suite_add_suite(suite, torture_registry_diff(mem_ctx));