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"
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),
35 "REG_SZ", "REG_SZ failed");
36 torture_assert_str_equal(ctx, str_regtype(4),
37 "REG_DWORD", "REG_DWORD failed");
43 static bool test_reg_val_data_string_dword(struct torture_context *ctx)
46 DATA_BLOB db = { (uint8_t *)&d, sizeof(d) };
47 torture_assert_str_equal(ctx, "0x20",
48 reg_val_data_string(ctx, lp_iconv_convenience(ctx->lp_ctx), REG_DWORD, db),
53 static bool test_reg_val_data_string_sz(struct torture_context *ctx)
56 db.length = convert_string_talloc(ctx, lp_iconv_convenience(ctx->lp_ctx), CH_UTF8, CH_UTF16,
57 "bla", 3, (void **)&db.data);
58 torture_assert_str_equal(ctx, "bla",
59 reg_val_data_string(ctx, lp_iconv_convenience(ctx->lp_ctx), REG_SZ, db),
62 torture_assert_str_equal(ctx, "bl",
63 reg_val_data_string(ctx, lp_iconv_convenience(ctx->lp_ctx), REG_SZ, db),
68 static bool test_reg_val_data_string_binary(struct torture_context *ctx)
70 uint8_t x[] = { 0x1, 0x2, 0x3, 0x4 };
71 DATA_BLOB db = { x, 4 };
72 torture_assert_str_equal(ctx, "01020304",
73 reg_val_data_string(ctx, lp_iconv_convenience(ctx->lp_ctx), REG_BINARY, db),
79 static bool test_reg_val_data_string_empty(struct torture_context *ctx)
81 DATA_BLOB db = { NULL, 0 };
82 torture_assert_str_equal(ctx, "",
83 reg_val_data_string(ctx, lp_iconv_convenience(ctx->lp_ctx), REG_BINARY, db),
88 static bool test_reg_val_description(struct torture_context *ctx)
91 data.length = convert_string_talloc(ctx, lp_iconv_convenience(ctx->lp_ctx), CH_UTF8, CH_UTF16,
92 "stationary traveller",
93 strlen("stationary traveller"),
95 torture_assert_str_equal(ctx, "camel = REG_SZ : stationary traveller",
96 reg_val_description(ctx, lp_iconv_convenience(ctx->lp_ctx), "camel", REG_SZ, data),
97 "reg_val_description failed");
102 static bool test_reg_val_description_nullname(struct torture_context *ctx)
105 data.length = convert_string_talloc(ctx, lp_iconv_convenience(ctx->lp_ctx), CH_UTF8, CH_UTF16,
107 strlen("west berlin"),
108 (void **)&data.data);
109 torture_assert_str_equal(ctx, "<No Name> = REG_SZ : west berlin",
110 reg_val_description(ctx, lp_iconv_convenience(ctx->lp_ctx), NULL, REG_SZ, data),
111 "description with null name failed");
115 struct torture_suite *torture_registry(TALLOC_CTX *mem_ctx)
117 struct torture_suite *suite = torture_suite_create(mem_ctx, "REGISTRY");
118 torture_suite_add_simple_test(suite, "str_regtype",
120 torture_suite_add_simple_test(suite, "reg_val_data_string dword",
121 test_reg_val_data_string_dword);
122 torture_suite_add_simple_test(suite, "reg_val_data_string sz",
123 test_reg_val_data_string_sz);
124 torture_suite_add_simple_test(suite, "reg_val_data_string binary",
125 test_reg_val_data_string_binary);
126 torture_suite_add_simple_test(suite, "reg_val_data_string empty",
127 test_reg_val_data_string_empty);
128 torture_suite_add_simple_test(suite, "reg_val_description",
129 test_reg_val_description);
130 torture_suite_add_simple_test(suite, "reg_val_description null",
131 test_reg_val_description_nullname);
133 torture_suite_add_suite(suite, torture_registry_hive(suite));
134 torture_suite_add_suite(suite, torture_registry_registry(suite));
135 torture_suite_add_suite(suite, torture_registry_diff(suite));