torture-ndr: added support for testing push functions
authorAndrew Tridgell <tridge@samba.org>
Wed, 7 Sep 2011 05:35:55 +0000 (15:35 +1000)
committerAndrew Tridgell <tridge@samba.org>
Thu, 8 Sep 2011 01:35:27 +0000 (03:35 +0200)
this allows us to check the symmetry of pull/push functions in NDR
tests

Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>

source4/torture/ndr/ndr.c
source4/torture/ndr/ndr.h

index 6c564d3310a12cd6714c55d17a09f365393b873c..22905f2f67209939c83a39e4c5ccac534744c296 100644 (file)
@@ -29,17 +29,19 @@ struct ndr_pull_test_data {
        DATA_BLOB data_context;
        size_t struct_size;
        ndr_pull_flags_fn_t pull_fn;
        DATA_BLOB data_context;
        size_t struct_size;
        ndr_pull_flags_fn_t pull_fn;
+       ndr_push_flags_fn_t push_fn;
        int ndr_flags;
 };
 
        int ndr_flags;
 };
 
-static bool wrap_ndr_pull_test(struct torture_context *tctx,
-                              struct torture_tcase *tcase,
-                              struct torture_test *test)
+static bool wrap_ndr_pullpush_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 = (const struct ndr_pull_test_data *)test->data;
 {
        bool (*check_fn) (struct torture_context *ctx, void *data) = test->fn;
        const struct ndr_pull_test_data *data = (const struct ndr_pull_test_data *)test->data;
-       void *ds = talloc_zero_size(tctx, data->struct_size);
        struct ndr_pull *ndr = ndr_pull_init_blob(&(data->data), tctx);
        struct ndr_pull *ndr = ndr_pull_init_blob(&(data->data), tctx);
+       void *ds = talloc_zero_size(ndr, data->struct_size);
+       bool ret;
 
        ndr->flags |= LIBNDR_FLAG_REF_ALLOC;
 
 
        ndr->flags |= LIBNDR_FLAG_REF_ALLOC;
 
@@ -50,19 +52,31 @@ static bool wrap_ndr_pull_test(struct torture_context *tctx,
                                   talloc_asprintf(tctx,
                                           "%d unread bytes", ndr->data_size - ndr->offset));
 
                                   talloc_asprintf(tctx,
                                           "%d unread bytes", ndr->data_size - ndr->offset));
 
-       if (check_fn != NULL)
-               return check_fn(tctx, ds);
-       else
-               return true;
+       if (check_fn != NULL) {
+               ret = check_fn(tctx, ds);
+       } else {
+               ret = true;
+       }
+
+       if (data->push_fn != NULL) {
+               DATA_BLOB outblob;
+               torture_assert_ndr_success(tctx, ndr_push_struct_blob(&outblob, ndr, ds, data->push_fn), "pushing");
+               torture_assert_data_blob_equal(tctx, outblob, data->data, "ndr push compare");
+       }
+
+       talloc_free(ndr);
+       return ret;
 }
 
 }
 
-_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))
+_PUBLIC_ struct torture_test *_torture_suite_add_ndr_pullpush_test(
+       struct torture_suite *suite,
+       const char *name,
+       ndr_pull_flags_fn_t pull_fn,
+       ndr_push_flags_fn_t push_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 torture_test *test;
        struct torture_tcase *tcase;
@@ -74,12 +88,15 @@ _PUBLIC_ struct torture_test *_torture_suite_add_ndr_pull_test(
 
        test->name = talloc_strdup(test, name);
        test->description = NULL;
 
        test->name = talloc_strdup(test, name);
        test->description = NULL;
-       test->run = wrap_ndr_pull_test;
+       test->run = wrap_ndr_pullpush_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;
        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;
+       data->push_fn = push_fn;
+
        test->data = data;
        test->fn = check_fn;
        test->dangerous = false;
        test->data = data;
        test->fn = check_fn;
        test->dangerous = false;
@@ -89,6 +106,7 @@ _PUBLIC_ struct torture_test *_torture_suite_add_ndr_pull_test(
        return test;
 }
 
        return test;
 }
 
+
 static bool wrap_ndr_inout_pull_test(struct torture_context *tctx,
                                     struct torture_tcase *tcase,
                                     struct torture_test *test)
 static bool wrap_ndr_inout_pull_test(struct torture_context *tctx,
                                     struct torture_tcase *tcase,
                                     struct torture_test *test)
index 3de6b8b0d348b2a028541c302cdf7eb2fb72c32d..ee4db0aa68a7c6710f94ea3de5cb3632d4cad81b 100644 (file)
 #include "librpc/ndr/libndr.h"
 #include "libcli/security/security.h"
 
 #include "librpc/ndr/libndr.h"
 #include "libcli/security/security.h"
 
-_PUBLIC_ struct torture_test *_torture_suite_add_ndr_pull_test(
+_PUBLIC_ struct torture_test *_torture_suite_add_ndr_pullpush_test(
                                        struct torture_suite *suite,
                                        struct torture_suite *suite,
-                                       const char *name, ndr_pull_flags_fn_t fn,
+                                       const char *name,
+                                       ndr_pull_flags_fn_t pull_fn,
+                                       ndr_push_flags_fn_t push_fn,
                                        DATA_BLOB db,
                                        size_t struct_size,
                                        int ndr_flags,
                                        DATA_BLOB db,
                                        size_t struct_size,
                                        int ndr_flags,
@@ -41,20 +43,27 @@ _PUBLIC_ struct torture_test *_torture_suite_add_ndr_pull_inout_test(
                                        bool (*check_fn) (struct torture_context *ctx, void *data));
 
 #define torture_suite_add_ndr_pull_test(suite,name,data,check_fn) \
                                        bool (*check_fn) (struct torture_context *ctx, void *data));
 
 #define torture_suite_add_ndr_pull_test(suite,name,data,check_fn) \
-               _torture_suite_add_ndr_pull_test(suite, #name, \
-                        (ndr_pull_flags_fn_t)ndr_pull_ ## name, data_blob_talloc(suite, data, sizeof(data)), \
-                        sizeof(struct name), 0, (bool (*) (struct torture_context *, void *)) check_fn);
+               _torture_suite_add_ndr_pullpush_test(suite, #name, \
+                        (ndr_pull_flags_fn_t)ndr_pull_ ## name, NULL, data_blob_const(data, sizeof(data)), \
+                        sizeof(struct name), NDR_SCALARS|NDR_BUFFERS, (bool (*) (struct torture_context *, void *)) check_fn);
 
 #define torture_suite_add_ndr_pull_fn_test(suite,name,data,flags,check_fn) \
 
 #define torture_suite_add_ndr_pull_fn_test(suite,name,data,flags,check_fn) \
-               _torture_suite_add_ndr_pull_test(suite, #name "_" #flags, \
-                        (ndr_pull_flags_fn_t)ndr_pull_ ## name, data_blob_talloc(suite, data, sizeof(data)), \
+               _torture_suite_add_ndr_pullpush_test(suite, #name "_" #flags, \
+                        (ndr_pull_flags_fn_t)ndr_pull_ ## name, NULL, data_blob_const(data, sizeof(data)), \
                         sizeof(struct name), flags, (bool (*) (struct torture_context *, void *)) check_fn);
 
                         sizeof(struct name), flags, (bool (*) (struct torture_context *, void *)) check_fn);
 
+#define torture_suite_add_ndr_pullpush_test(suite,name,data_blob,check_fn) \
+               _torture_suite_add_ndr_pullpush_test(suite, #name, \
+                        (ndr_pull_flags_fn_t)ndr_pull_ ## name, \
+                        (ndr_push_flags_fn_t)ndr_push_ ## name, \
+                        data_blob, \
+                        sizeof(struct name), NDR_SCALARS|NDR_BUFFERS, (bool (*) (struct torture_context *, void *)) check_fn);
+
 #define torture_suite_add_ndr_pull_io_test(suite,name,data_in,data_out,check_fn_out) \
                _torture_suite_add_ndr_pull_inout_test(suite, #name "_INOUT", \
                         (ndr_pull_flags_fn_t)ndr_pull_ ## name, \
 #define torture_suite_add_ndr_pull_io_test(suite,name,data_in,data_out,check_fn_out) \
                _torture_suite_add_ndr_pull_inout_test(suite, #name "_INOUT", \
                         (ndr_pull_flags_fn_t)ndr_pull_ ## name, \
-                        data_blob_talloc(suite, data_in, sizeof(data_in)), \
-                        data_blob_talloc(suite, data_out, sizeof(data_out)), \
+                        data_blob_const(data_in, sizeof(data_in)), \
+                        data_blob_const(data_out, sizeof(data_out)), \
                         sizeof(struct name), \
                         (bool (*) (struct torture_context *, void *)) check_fn_out);
 
                         sizeof(struct name), \
                         (bool (*) (struct torture_context *, void *)) check_fn_out);