summaryrefslogtreecommitdiff
path: root/source4/torture/ndr/ndr.c
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2007-02-14 19:30:05 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:48:17 -0500
commit25a0c9146eb66ee4b336af8c3ae12ffa9a2da62c (patch)
treefd3f5544fc8e32db63a2f6ac37ce5db34027b2fe /source4/torture/ndr/ndr.c
parent6d18b574e52c59e6ca495f0eb62737342cd90ae0 (diff)
downloadsamba-25a0c9146eb66ee4b336af8c3ae12ffa9a2da62c.tar.gz
samba-25a0c9146eb66ee4b336af8c3ae12ffa9a2da62c.tar.bz2
samba-25a0c9146eb66ee4b336af8c3ae12ffa9a2da62c.zip
r21347: All current tests in the testsuite mainly test the RPC code in general. Since
we're running the testsuite mainly against ourselves, we only check that the push/pull functions work in our own environment, not whether they generate/parse the same data that other systems do. This commit adds the infrastructure for a testsuite for just the marshalling code. The idea is that you provide a data blob, a function name and a function to check the resulting struct for correctness. (This used to be commit 9bd2421e44dcfcaf08ad61cf25bb7714cf885517)
Diffstat (limited to 'source4/torture/ndr/ndr.c')
-rw-r--r--source4/torture/ndr/ndr.c94
1 files changed, 94 insertions, 0 deletions
diff --git a/source4/torture/ndr/ndr.c b/source4/torture/ndr/ndr.c
new file mode 100644
index 0000000000..c1179395c1
--- /dev/null
+++ b/source4/torture/ndr/ndr.c
@@ -0,0 +1,94 @@
+/*
+ Unix SMB/CIFS implementation.
+ test suite for winreg ndr operations
+
+ Copyright (C) Jelmer Vernooij 2007
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include "includes.h"
+#include "torture/ndr/ndr.h"
+#include "torture/ndr/proto.h"
+#include "util/dlinklist.h"
+
+struct ndr_pull_test_data {
+ DATA_BLOB data;
+ size_t struct_size;
+ ndr_pull_flags_fn_t pull_fn;
+ int ndr_flags;
+};
+
+static bool wrap_ndr_pull_test(struct torture_context *tctx,
+ struct torture_tcase *tcase,
+ struct torture_test *test)
+{
+ bool (*check_fn) (struct torture_context *ctx, void *data) = test->fn;
+ const struct ndr_pull_test_data *data = test->data;
+ void *ds = talloc_zero_size(tctx, data->struct_size);
+ struct ndr_pull *ndr = ndr_pull_init_blob(&(data->data), tctx);
+
+ ndr->flags |= LIBNDR_FLAG_REF_ALLOC;
+
+ torture_assert_ntstatus_ok(tctx, data->pull_fn(ndr, data->ndr_flags, ds),
+ "pulling");
+
+ return check_fn(tctx, ds);
+}
+
+_PUBLIC_ struct torture_test *_torture_suite_add_ndr_pull_test(
+ struct torture_suite *suite,
+ const char *name, ndr_pull_flags_fn_t pull_fn,
+ DATA_BLOB db,
+ size_t struct_size,
+ int ndr_flags,
+ bool (*check_fn) (struct torture_context *ctx, void *data))
+{
+ struct torture_test *test;
+ struct torture_tcase *tcase;
+ struct ndr_pull_test_data *data;
+
+ tcase = torture_suite_add_tcase(suite, name);
+
+ test = talloc(tcase, struct torture_test);
+
+ test->name = talloc_strdup(test, name);
+ test->description = NULL;
+ test->run = wrap_ndr_pull_test;
+ data = talloc(test, struct ndr_pull_test_data);
+ data->data = db;
+ data->ndr_flags = ndr_flags;
+ data->struct_size = struct_size;
+ data->pull_fn = pull_fn;
+ test->data = data;
+ test->fn = check_fn;
+ test->dangerous = false;
+
+ DLIST_ADD_END(tcase->tests, test, struct torture_test *);
+
+ return test;
+}
+
+NTSTATUS torture_ndr_init(void)
+{
+ struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "NDR");
+
+ torture_suite_add_suite(suite, ndr_winreg_suite(suite));
+
+ torture_register_suite(suite);
+
+ return NT_STATUS_OK;
+}
+