r21381: dfs tests.
[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         if (check_fn != NULL) 
49                 return check_fn(tctx, ds);
50         else
51                 return true;
52 }
53
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,
57                                         DATA_BLOB db, 
58                                         size_t struct_size,
59                                         int ndr_flags,
60                                         bool (*check_fn) (struct torture_context *ctx, void *data))
61 {
62         struct torture_test *test; 
63         struct torture_tcase *tcase;
64         struct ndr_pull_test_data *data;
65         
66         tcase = torture_suite_add_tcase(suite, name);
67
68         test = talloc(tcase, struct torture_test);
69
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);
74         data->data = db;
75         data->ndr_flags = ndr_flags;
76         data->struct_size = struct_size;
77         data->pull_fn = pull_fn;
78         test->data = data;
79         test->fn = check_fn;
80         test->dangerous = false;
81
82         DLIST_ADD_END(tcase->tests, test, struct torture_test *);
83
84         return test;
85 }
86
87 NTSTATUS torture_ndr_init(void)
88 {
89         struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "NDR");
90
91         torture_suite_add_suite(suite, ndr_winreg_suite(suite));
92         torture_suite_add_suite(suite, ndr_atsvc_suite(suite));
93         torture_suite_add_suite(suite, ndr_lsa_suite(suite));
94         torture_suite_add_suite(suite, ndr_epmap_suite(suite));
95         torture_suite_add_suite(suite, ndr_dfs_suite(suite));
96
97         torture_register_suite(suite);
98
99         return NT_STATUS_OK;
100 }
101