2 Unix SMB/CIFS implementation.
3 test suite for winreg ndr operations
5 Copyright (C) Jelmer Vernooij 2007
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "torture/ndr/ndr.h"
24 #include "torture/ndr/proto.h"
25 #include "util/dlinklist.h"
27 struct ndr_pull_test_data
{
30 ndr_pull_flags_fn_t pull_fn
;
34 static bool wrap_ndr_pull_test(struct torture_context
*tctx
,
35 struct torture_tcase
*tcase
,
36 struct torture_test
*test
)
38 bool (*check_fn
) (struct torture_context
*ctx
, void *data
) = test
->fn
;
39 const struct ndr_pull_test_data
*data
= test
->data
;
40 void *ds
= talloc_zero_size(tctx
, data
->struct_size
);
41 struct ndr_pull
*ndr
= ndr_pull_init_blob(&(data
->data
), tctx
);
43 ndr
->flags
|= LIBNDR_FLAG_REF_ALLOC
;
45 torture_assert_ntstatus_ok(tctx
, data
->pull_fn(ndr
, data
->ndr_flags
, ds
),
49 return check_fn(tctx
, ds
);
54 _PUBLIC_
struct torture_test
*_torture_suite_add_ndr_pull_test(
55 struct torture_suite
*suite
,
56 const char *name
, ndr_pull_flags_fn_t pull_fn
,
60 bool (*check_fn
) (struct torture_context
*ctx
, void *data
))
62 struct torture_test
*test
;
63 struct torture_tcase
*tcase
;
64 struct ndr_pull_test_data
*data
;
66 tcase
= torture_suite_add_tcase(suite
, name
);
68 test
= talloc(tcase
, struct torture_test
);
70 test
->name
= talloc_strdup(test
, name
);
71 test
->description
= NULL
;
72 test
->run
= wrap_ndr_pull_test
;
73 data
= talloc(test
, struct ndr_pull_test_data
);
75 data
->ndr_flags
= ndr_flags
;
76 data
->struct_size
= struct_size
;
77 data
->pull_fn
= pull_fn
;
80 test
->dangerous
= false;
82 DLIST_ADD_END(tcase
->tests
, test
, struct torture_test
*);
87 static bool test_check_string_terminator(struct torture_context
*tctx
)
91 TALLOC_CTX
*mem_ctx
= tctx
;
94 blob
= strhex_to_data_blob("0000");
96 ndr
= ndr_pull_init_blob(&blob
, mem_ctx
);
98 torture_assert_ntstatus_ok(tctx
, ndr_check_string_terminator(ndr
, 1, 2),
99 "simple check_string_terminator test failed");
101 torture_assert(tctx
, ndr
->offset
== 0,
102 "check_string_terminator did not reset offset");
104 if (NT_STATUS_IS_OK(ndr_check_string_terminator(ndr
, 1, 3))) {
105 torture_fail(tctx
, "check_string_terminator checked beyond string boundaries");
108 torture_assert(tctx
, ndr
->offset
== 0,
109 "check_string_terminator did not reset offset");
113 blob
= strhex_to_data_blob("11220000");
114 ndr
= ndr_pull_init_blob(&blob
, mem_ctx
);
116 torture_assert_ntstatus_ok(tctx
,
117 ndr_check_string_terminator(ndr
, 4, 1),
118 "check_string_terminator failed to recognize terminator");
120 torture_assert_ntstatus_ok(tctx
,
121 ndr_check_string_terminator(ndr
, 3, 1),
122 "check_string_terminator failed to recognize terminator");
124 if (NT_STATUS_IS_OK(ndr_check_string_terminator(ndr
, 2, 1))) {
126 "check_string_terminator erroneously reported terminator");
129 torture_assert(tctx
, ndr
->offset
== 0,
130 "check_string_terminator did not reset offset");
134 static bool test_guid_from_string_valid(struct torture_context
*tctx
)
140 static bool test_guid_from_string_null(struct torture_context
*tctx
)
143 torture_assert_ntstatus_equal(tctx
, NT_STATUS_INVALID_PARAMETER
,
144 GUID_from_string(NULL
, &guid
),
149 static bool test_guid_from_string_invalid(struct torture_context
*tctx
)
152 torture_assert_ntstatus_equal(tctx
, NT_STATUS_INVALID_PARAMETER
,
153 GUID_from_string("bla", &g1
),
154 "parameter not invalid");
158 static bool test_guid_from_string(struct torture_context
*tctx
)
161 torture_assert_ntstatus_ok(tctx
,
162 GUID_from_string("00000001-0002-0003-0405-060708090a0b", &g1
),
163 "invalid return code");
166 exp
.time_hi_and_version
= 3;
167 exp
.clock_seq
[0] = 4;
168 exp
.clock_seq
[1] = 5;
175 torture_assert(tctx
, GUID_equal(&g1
, &exp
), "UUID parsed incorrectly");
176 torture_assert_ntstatus_ok(tctx
,
177 GUID_from_string("{00000001-0002-0003-0405-060708090a0b}", &g1
),
178 "invalid return code");
179 torture_assert(tctx
, GUID_equal(&g1
, &exp
), "UUID parsed incorrectly");
184 static bool test_guid_string_valid(struct torture_context
*tctx
)
189 g
.time_hi_and_version
= 3;
198 torture_assert_str_equal(tctx
, "00000001-0002-0003-0405-060708090a0b", GUID_string(tctx
, &g
),
199 "parsing guid failed");
203 static bool test_guid_string2_valid(struct torture_context
*tctx
)
208 g
.time_hi_and_version
= 3;
217 torture_assert_str_equal(tctx
, "{00000001-0002-0003-0405-060708090a0b}", GUID_string2(tctx
, &g
),
218 "parsing guid failed");
222 static bool test_compare_uuid(struct torture_context
*tctx
)
225 ZERO_STRUCT(g1
); ZERO_STRUCT(g2
);
226 torture_assert_int_equal(tctx
, 0, GUID_compare(&g1
, &g2
),
229 torture_assert_int_equal(tctx
, 1, GUID_compare(&g1
, &g2
),
230 "GUID diff invalid");
233 torture_assert_int_equal(tctx
, 10, GUID_compare(&g1
, &g2
),
234 "GUID diff invalid");
237 g1
.clock_seq
[1] = 20;
238 torture_assert_int_equal(tctx
, 20, GUID_compare(&g1
, &g2
),
239 "GUID diff invalid");
243 struct torture_suite
*torture_local_ndr(void)
245 struct torture_suite
*suite
= torture_suite_create(talloc_autofree_context(), "NDR");
247 torture_suite_add_suite(suite
, ndr_winreg_suite(suite
));
248 torture_suite_add_suite(suite
, ndr_atsvc_suite(suite
));
249 torture_suite_add_suite(suite
, ndr_lsa_suite(suite
));
250 torture_suite_add_suite(suite
, ndr_epmap_suite(suite
));
251 torture_suite_add_suite(suite
, ndr_dfs_suite(suite
));
252 torture_suite_add_suite(suite
, ndr_netlogon_suite(suite
));
253 torture_suite_add_suite(suite
, ndr_drsuapi_suite(suite
));
254 torture_suite_add_suite(suite
, ndr_spoolss_suite(suite
));
256 torture_suite_add_simple_test(suite
, "string terminator",
257 test_check_string_terminator
);
259 torture_suite_add_simple_test(suite
, "guid_from_string_null",
260 test_guid_from_string_null
);
262 torture_suite_add_simple_test(suite
, "guid_from_string",
263 test_guid_from_string
);
265 torture_suite_add_simple_test(suite
, "guid_from_string_invalid",
266 test_guid_from_string_invalid
);
268 torture_suite_add_simple_test(suite
, "guid_string_valid",
269 test_guid_string_valid
);
271 torture_suite_add_simple_test(suite
, "guid_string2_valid",
272 test_guid_string2_valid
);
274 torture_suite_add_simple_test(suite
, "guid_from_string_valid",
275 test_guid_from_string_valid
);
277 torture_suite_add_simple_test(suite
, "compare_uuid",