• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt/router/samba-3.5.8/source4/lib/registry/tests/
1/*
2   Unix SMB/CIFS implementation.
3
4   local testing of registry library
5
6   Copyright (C) Jelmer Vernooij 2005-2007
7
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.
12
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.
17
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/>.
20*/
21
22#include "includes.h"
23#include "lib/registry/registry.h"
24#include "torture/torture.h"
25#include "librpc/gen_ndr/winreg.h"
26#include "param/param.h"
27
28struct torture_suite *torture_registry_hive(TALLOC_CTX *mem_ctx);
29struct torture_suite *torture_registry_registry(TALLOC_CTX *mem_ctx);
30struct torture_suite *torture_registry_diff(TALLOC_CTX *mem_ctx);
31
32static bool test_str_regtype(struct torture_context *ctx)
33{
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");
38
39	return true;
40}
41
42
43static bool test_reg_val_data_string_dword(struct torture_context *ctx)
44{
45	uint32_t d = 0x20;
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),
49				 "dword failed");
50	return true;
51}
52
53static bool test_reg_val_data_string_sz(struct torture_context *ctx)
54{
55	DATA_BLOB db;
56	convert_string_talloc_convenience(ctx, lp_iconv_convenience(ctx->lp_ctx), CH_UTF8, CH_UTF16,
57					  "bla", 3, (void **)&db.data, &db.length, false);
58	torture_assert_str_equal(ctx, "bla",
59				 reg_val_data_string(ctx, lp_iconv_convenience(ctx->lp_ctx), REG_SZ, db),
60				 "sz failed");
61	db.length = 4;
62	torture_assert_str_equal(ctx, "bl",
63				 reg_val_data_string(ctx, lp_iconv_convenience(ctx->lp_ctx), REG_SZ, db),
64				 "sz failed");
65	return true;
66}
67
68static bool test_reg_val_data_string_binary(struct torture_context *ctx)
69{
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),
74				 "binary failed");
75	return true;
76}
77
78
79static bool test_reg_val_data_string_empty(struct torture_context *ctx)
80{
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),
84				 "empty failed");
85	return true;
86}
87
88static bool test_reg_val_description(struct torture_context *ctx)
89{
90	DATA_BLOB data;
91	convert_string_talloc_convenience(ctx, lp_iconv_convenience(ctx->lp_ctx), CH_UTF8, CH_UTF16,
92					    "stationary traveller",
93					    strlen("stationary traveller"),
94					    (void **)&data.data, &data.length, false);
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");
98	return true;
99}
100
101
102static bool test_reg_val_description_nullname(struct torture_context *ctx)
103{
104	DATA_BLOB data;
105	convert_string_talloc_convenience(ctx, lp_iconv_convenience(ctx->lp_ctx), CH_UTF8, CH_UTF16,
106					    "west berlin",
107					    strlen("west berlin"),
108					    (void **)&data.data, &data.length, false);
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");
112	return true;
113}
114
115struct torture_suite *torture_registry(TALLOC_CTX *mem_ctx)
116{
117	struct torture_suite *suite = torture_suite_create(mem_ctx, "REGISTRY");
118	torture_suite_add_simple_test(suite, "str_regtype",
119				      test_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);
132
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));
136
137	return suite;
138}
139