summaryrefslogtreecommitdiff
path: root/source4/torture/ndr
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2016-07-25 15:34:39 +1200
committerStefan Metzmacher <metze@samba.org>2016-07-28 10:06:12 +0200
commit00f77d10b6aa5ddf9704e12443093dab690d7a67 (patch)
tree6c7710d185f09ab379af8bae87ef0c5e94dcf838 /source4/torture/ndr
parenteeb594ce935190551d7d71812edef8ba506cd5d6 (diff)
downloadsamba-00f77d10b6aa5ddf9704e12443093dab690d7a67.tar.gz
torture: Add tests for ndr_push_struct_into_fixed_blob()
Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Garming Sam <garming@catalyst.net.nz>
Diffstat (limited to 'source4/torture/ndr')
-rw-r--r--source4/torture/ndr/ndr.c110
1 files changed, 110 insertions, 0 deletions
diff --git a/source4/torture/ndr/ndr.c b/source4/torture/ndr/ndr.c
index 30023a3f2eb..4541f9f0847 100644
--- a/source4/torture/ndr/ndr.c
+++ b/source4/torture/ndr/ndr.c
@@ -23,6 +23,7 @@
#include "torture/ndr/proto.h"
#include "../lib/util/dlinklist.h"
#include "param/param.h"
+#include "librpc/gen_ndr/ndr_misc.h"
struct ndr_pull_test_data {
DATA_BLOB data;
@@ -367,6 +368,106 @@ static bool test_guid_string2_valid(struct torture_context *tctx)
return true;
}
+static bool test_guid_into_blob(struct torture_context *tctx)
+{
+ enum ndr_err_code ndr_err;
+ static const char exp_guid[16] =
+ { 0x1, 0x0, 0x0, 0x0,
+ 0x2, 0x0, 0x3, 0x0,
+ 0x4, 0x5, 0x6, 0x7,
+ 0x8, 0x9, 0xa, 0xb };
+ DATA_BLOB exp = data_blob_const(exp_guid, 16);
+ char ndr_guid[16] =
+ { 0x0, 0x0, 0x0, 0x0,
+ 0x0, 0x0, 0x0, 0x0,
+ 0x0, 0x0, 0x0, 0x0,
+ 0x0, 0x0, 0x0, 0x0 };
+ DATA_BLOB b = data_blob_const(ndr_guid, 16);
+ struct GUID guid;
+ guid.time_low = 1;
+ guid.time_mid = 2;
+ guid.time_hi_and_version = 3;
+ guid.clock_seq[0] = 4;
+ guid.clock_seq[1] = 5;
+ guid.node[0] = 6;
+ guid.node[1] = 7;
+ guid.node[2] = 8;
+ guid.node[3] = 9;
+ guid.node[4] = 10;
+ guid.node[5] = 11;
+
+ ndr_err = ndr_push_struct_into_fixed_blob(&b, &guid,
+ (ndr_push_flags_fn_t)ndr_push_GUID);
+ torture_assert_ndr_err_equal(tctx, ndr_err, NDR_ERR_SUCCESS,
+ "wrong NDR error");
+ torture_assert_data_blob_equal(tctx, b, exp,
+ "GUID packed wrongly");
+
+ return true;
+}
+
+/* Really a test of ndr_push_struct_into_fixed_blob error handling */
+static bool test_guid_into_long_blob(struct torture_context *tctx)
+{
+ enum ndr_err_code ndr_err;
+ char ndr_guid[17] =
+ { 0x0, 0x0, 0x0, 0x0,
+ 0x0, 0x0, 0x0, 0x0,
+ 0x0, 0x0, 0x0, 0x0,
+ 0x0, 0x0, 0x0, 0x0, 0x0 };
+ DATA_BLOB b = data_blob_const(ndr_guid, 17);
+ struct GUID guid;
+ guid.time_low = 1;
+ guid.time_mid = 2;
+ guid.time_hi_and_version = 3;
+ guid.clock_seq[0] = 4;
+ guid.clock_seq[1] = 5;
+ guid.node[0] = 6;
+ guid.node[1] = 7;
+ guid.node[2] = 8;
+ guid.node[3] = 9;
+ guid.node[4] = 10;
+ guid.node[5] = 11;
+
+ torture_assert(tctx, b.data != NULL, "data_blob_talloc failed");
+ ndr_err = ndr_push_struct_into_fixed_blob(
+ &b, &guid, (ndr_push_flags_fn_t)ndr_push_GUID);
+ torture_assert_ndr_err_equal(tctx, ndr_err, NDR_ERR_BUFSIZE,
+ "wrong NDR error");
+
+ return true;
+}
+
+static bool test_guid_into_short_blob(struct torture_context *tctx)
+{
+ enum ndr_err_code ndr_err;
+ char ndr_guid[15] =
+ { 0x0, 0x0, 0x0, 0x0,
+ 0x0, 0x0, 0x0, 0x0,
+ 0x0, 0x0, 0x0, 0x0,
+ 0x0, 0x0, 0x0 };
+ DATA_BLOB b = data_blob_const(ndr_guid, 15);
+ struct GUID guid;
+ guid.time_low = 1;
+ guid.time_mid = 2;
+ guid.time_hi_and_version = 3;
+ guid.clock_seq[0] = 4;
+ guid.clock_seq[1] = 5;
+ guid.node[0] = 6;
+ guid.node[1] = 7;
+ guid.node[2] = 8;
+ guid.node[3] = 9;
+ guid.node[4] = 10;
+ guid.node[5] = 11;
+
+ ndr_err = ndr_push_struct_into_fixed_blob(
+ &b, &guid, (ndr_push_flags_fn_t)ndr_push_GUID);
+ torture_assert_ndr_err_equal(tctx, ndr_err, NDR_ERR_BUFSIZE,
+ "wrong NDR error");
+
+ return true;
+}
+
static bool test_compare_uuid(struct torture_context *tctx)
{
struct GUID g1, g2;
@@ -446,6 +547,15 @@ struct torture_suite *torture_local_ndr(TALLOC_CTX *mem_ctx)
torture_suite_add_simple_test(suite, "compare_uuid",
test_compare_uuid);
+ torture_suite_add_simple_test(suite, "guid_into_blob",
+ test_guid_into_blob);
+
+ torture_suite_add_simple_test(suite, "guid_into_short_blob",
+ test_guid_into_short_blob);
+
+ torture_suite_add_simple_test(suite, "guid_into_long_blob",
+ test_guid_into_long_blob);
+
return suite;
}