r21378: Add simple NDR epmap test.
[obnox/samba/samba-obnox.git] / source4 / torture / ndr / ndr.c
1 /* 
2    Unix SMB/CIFS implementation.
3    test suite for winreg ndr operations
4
5    Copyright (C) Jelmer Vernooij 2007
6    
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.
11    
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.
16    
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.
20 */
21
22 #include "includes.h"
23 #include "torture/ndr/ndr.h"
24 #include "torture/ndr/proto.h"
25 #include "util/dlinklist.h"
26
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;
32 };
33
34 static bool wrap_ndr_pull_test(struct torture_context *tctx,
35                                                            struct torture_tcase *tcase,
36                                                            struct torture_test *test)
37 {
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);
42
43         ndr->flags |= LIBNDR_FLAG_REF_ALLOC;
44
45         torture_assert_ntstatus_ok(tctx, data->pull_fn(ndr, data->ndr_flags, ds), 
46                                                            "pulling");
47
48         return check_fn(tctx, ds);
49 }
50
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))
58 {
59         struct torture_test *test; 
60         struct torture_tcase *tcase;
61         struct ndr_pull_test_data *data;
62         
63         tcase = torture_suite_add_tcase(suite, name);
64
65         test = talloc(tcase, struct torture_test);
66
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;
78
79         DLIST_ADD_END(tcase->tests, test, struct torture_test *);
80
81         return test;
82 }
83
84 NTSTATUS torture_ndr_init(void)
85 {
86         struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "NDR");
87
88         torture_suite_add_suite(suite, ndr_winreg_suite(suite));
89         torture_suite_add_suite(suite, ndr_atsvc_suite(suite));
90         torture_suite_add_suite(suite, ndr_lsa_suite(suite));
91         torture_suite_add_suite(suite, ndr_epmap_suite(suite));
92
93         torture_register_suite(suite);
94
95         return NT_STATUS_OK;
96 }
97