r21347: All current tests in the testsuite mainly test the RPC code in general. Since
[Samba/ekacnet.git] / source / torture / ndr / ndr.c
blobc1179395c1170dc8c77d148f8e4976726d08cd93
1 /*
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.
22 #include "includes.h"
23 #include "torture/ndr/ndr.h"
24 #include "torture/ndr/proto.h"
25 #include "util/dlinklist.h"
27 struct ndr_pull_test_data {
28 DATA_BLOB data;
29 size_t struct_size;
30 ndr_pull_flags_fn_t pull_fn;
31 int ndr_flags;
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),
46 "pulling");
48 return check_fn(tctx, ds);
51 _PUBLIC_ struct torture_test *_torture_suite_add_ndr_pull_test(
52 struct torture_suite *suite,
53 const char *name, ndr_pull_flags_fn_t pull_fn,
54 DATA_BLOB db,
55 size_t struct_size,
56 int ndr_flags,
57 bool (*check_fn) (struct torture_context *ctx, void *data))
59 struct torture_test *test;
60 struct torture_tcase *tcase;
61 struct ndr_pull_test_data *data;
63 tcase = torture_suite_add_tcase(suite, name);
65 test = talloc(tcase, struct torture_test);
67 test->name = talloc_strdup(test, name);
68 test->description = NULL;
69 test->run = wrap_ndr_pull_test;
70 data = talloc(test, struct ndr_pull_test_data);
71 data->data = db;
72 data->ndr_flags = ndr_flags;
73 data->struct_size = struct_size;
74 data->pull_fn = pull_fn;
75 test->data = data;
76 test->fn = check_fn;
77 test->dangerous = false;
79 DLIST_ADD_END(tcase->tests, test, struct torture_test *);
81 return test;
84 NTSTATUS torture_ndr_init(void)
86 struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "NDR");
88 torture_suite_add_suite(suite, ndr_winreg_suite(suite));
90 torture_register_suite(suite);
92 return NT_STATUS_OK;