s4:registry - local testsuite - add a test for REG_QWORD
[Samba/nascimento.git] / source4 / lib / registry / tests / generic.c
bloba881c3d1d2defd4f0544b7f223386866ca64c80e
1 /*
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/>.
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"
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");
38 torture_assert_str_equal(ctx, str_regtype(11),
39 "REG_QWORD", "REG_QWORD failed");
41 return true;
45 static bool test_reg_val_data_string_dword(struct torture_context *ctx)
47 uint32_t d = 0x20;
48 DATA_BLOB db = { (uint8_t *)&d, sizeof(d) };
49 torture_assert_str_equal(ctx, "0x00000020",
50 reg_val_data_string(ctx, lp_iconv_convenience(ctx->lp_ctx), REG_DWORD, db),
51 "dword failed");
52 return true;
55 static bool test_reg_val_data_string_qword(struct torture_context *ctx)
57 uint64_t d = 0x20;
58 DATA_BLOB db = { (uint8_t *)&d, sizeof(d) };
59 torture_assert_str_equal(ctx, "0x0000000000000020",
60 reg_val_data_string(ctx, lp_iconv_convenience(ctx->lp_ctx), REG_QWORD, db),
61 "qword failed");
62 return true;
65 static bool test_reg_val_data_string_sz(struct torture_context *ctx)
67 DATA_BLOB db;
68 convert_string_talloc_convenience(ctx, lp_iconv_convenience(ctx->lp_ctx), CH_UTF8, CH_UTF16,
69 "bla", 3, (void **)&db.data, &db.length, false);
70 torture_assert_str_equal(ctx, "bla",
71 reg_val_data_string(ctx, lp_iconv_convenience(ctx->lp_ctx), REG_SZ, db),
72 "sz failed");
73 db.length = 4;
74 torture_assert_str_equal(ctx, "bl",
75 reg_val_data_string(ctx, lp_iconv_convenience(ctx->lp_ctx), REG_SZ, db),
76 "sz failed");
77 return true;
80 static bool test_reg_val_data_string_binary(struct torture_context *ctx)
82 uint8_t x[] = { 0x1, 0x2, 0x3, 0x4 };
83 DATA_BLOB db = { x, 4 };
84 torture_assert_str_equal(ctx, "01020304",
85 reg_val_data_string(ctx, lp_iconv_convenience(ctx->lp_ctx), REG_BINARY, db),
86 "binary failed");
87 return true;
91 static bool test_reg_val_data_string_empty(struct torture_context *ctx)
93 DATA_BLOB db = { NULL, 0 };
94 torture_assert_str_equal(ctx, "",
95 reg_val_data_string(ctx, lp_iconv_convenience(ctx->lp_ctx), REG_BINARY, db),
96 "empty failed");
97 return true;
100 static bool test_reg_val_description(struct torture_context *ctx)
102 DATA_BLOB data;
103 convert_string_talloc_convenience(ctx, lp_iconv_convenience(ctx->lp_ctx), CH_UTF8, CH_UTF16,
104 "stationary traveller",
105 strlen("stationary traveller"),
106 (void **)&data.data, &data.length, false);
107 torture_assert_str_equal(ctx, "camel = REG_SZ : stationary traveller",
108 reg_val_description(ctx, lp_iconv_convenience(ctx->lp_ctx), "camel", REG_SZ, data),
109 "reg_val_description failed");
110 return true;
114 static bool test_reg_val_description_nullname(struct torture_context *ctx)
116 DATA_BLOB data;
117 convert_string_talloc_convenience(ctx, lp_iconv_convenience(ctx->lp_ctx), CH_UTF8, CH_UTF16,
118 "west berlin",
119 strlen("west berlin"),
120 (void **)&data.data, &data.length, false);
121 torture_assert_str_equal(ctx, "<No Name> = REG_SZ : west berlin",
122 reg_val_description(ctx, lp_iconv_convenience(ctx->lp_ctx), NULL, REG_SZ, data),
123 "description with null name failed");
124 return true;
127 struct torture_suite *torture_registry(TALLOC_CTX *mem_ctx)
129 struct torture_suite *suite = torture_suite_create(mem_ctx, "REGISTRY");
130 torture_suite_add_simple_test(suite, "str_regtype",
131 test_str_regtype);
132 torture_suite_add_simple_test(suite, "reg_val_data_string dword",
133 test_reg_val_data_string_dword);
134 torture_suite_add_simple_test(suite, "reg_val_data_string qword",
135 test_reg_val_data_string_qword);
136 torture_suite_add_simple_test(suite, "reg_val_data_string sz",
137 test_reg_val_data_string_sz);
138 torture_suite_add_simple_test(suite, "reg_val_data_string binary",
139 test_reg_val_data_string_binary);
140 torture_suite_add_simple_test(suite, "reg_val_data_string empty",
141 test_reg_val_data_string_empty);
142 torture_suite_add_simple_test(suite, "reg_val_description",
143 test_reg_val_description);
144 torture_suite_add_simple_test(suite, "reg_val_description null",
145 test_reg_val_description_nullname);
147 torture_suite_add_suite(suite, torture_registry_hive(suite));
148 torture_suite_add_suite(suite, torture_registry_registry(suite));
149 torture_suite_add_suite(suite, torture_registry_diff(suite));
151 return suite;