s4-torture: add some NDR tests for validating ndr_push_charset behavior.
authorGünther Deschner <gd@samba.org>
Fri, 13 Jan 2017 12:16:22 +0000 (13:16 +0100)
committerGünther Deschner <gd@samba.org>
Tue, 24 Jan 2017 09:53:17 +0000 (10:53 +0100)
Guenther

Signed-off-by: Guenther Deschner <gd@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
source4/torture/ndr/charset.c [new file with mode: 0644]
source4/torture/ndr/ndr.c
source4/torture/wscript_build

diff --git a/source4/torture/ndr/charset.c b/source4/torture/ndr/charset.c
new file mode 100644 (file)
index 0000000..7062ce1
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+   Unix SMB/CIFS implementation.
+   test suite for charset ndr operations
+
+   Copyright (C) Guenther Deschner 2017
+
+   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 3 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, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "torture/ndr/ndr.h"
+#include "torture/ndr/proto.h"
+
+static bool test_ndr_push_charset(struct torture_context *tctx)
+{
+       const char *strs[] = {
+               NULL,
+               "",
+               "test"
+       };
+       int i;
+
+       struct ndr_push *ndr;
+
+       ndr = talloc_zero(tctx, struct ndr_push);
+
+       for (i = 0; i < ARRAY_SIZE(strs); i++) {
+
+               enum ndr_err_code expected_ndr_err = NDR_ERR_SUCCESS;
+
+               if (strs[i] == NULL) {
+                       expected_ndr_err = NDR_ERR_INVALID_POINTER;
+               }
+
+               torture_assert_ndr_err_equal(tctx,
+                       ndr_push_charset(ndr, NDR_SCALARS, strs[i], 256, 2, CH_UTF16LE),
+                       expected_ndr_err,
+                       "failed to push charset");
+       }
+
+       return true;
+}
+
+static bool test_ndr_push_charset_to_null(struct torture_context *tctx)
+{
+       const char *strs[] = {
+               NULL,
+               "",
+               "test"
+       };
+       int i;
+
+       struct ndr_push *ndr;
+
+       ndr = talloc_zero(tctx, struct ndr_push);
+
+
+       for (i = 0; i < ARRAY_SIZE(strs); i++) {
+
+               torture_assert_ndr_success(tctx,
+                       ndr_push_charset_to_null(ndr, NDR_SCALARS, strs[i], 256, 2, CH_UTF16LE),
+                       "failed to push charset to null");
+       }
+
+       return true;
+}
+
+
+struct torture_suite *ndr_charset_suite(TALLOC_CTX *ctx)
+{
+       struct torture_suite *suite = torture_suite_create(ctx, "charset");
+
+       suite->description = talloc_strdup(suite, "NDR - charset focused push/pull tests");
+
+       torture_suite_add_simple_test(suite, "push", test_ndr_push_charset);
+       torture_suite_add_simple_test(suite, "push_to_null", test_ndr_push_charset_to_null);
+
+       return suite;
+}
+
index d67585c723ab9a47a10158ebfb9f8bbdc35a0340..17c3b1915d6d43a67ea3213d377f533077e5ed4f 100644 (file)
@@ -570,6 +570,7 @@ struct torture_suite *torture_local_ndr(TALLOC_CTX *mem_ctx)
        torture_suite_add_suite(suite, ndr_string_suite(suite));
        torture_suite_add_suite(suite, ndr_krb5pac_suite(suite));
        torture_suite_add_suite(suite, ndr_cabinet_suite(suite));
+       torture_suite_add_suite(suite, ndr_charset_suite(suite));
 
        torture_suite_add_simple_test(suite, "string terminator",
                                      test_check_string_terminator);
index 72d3d292074bf9f4f3d03ab0bbaeac2631e47a6e..c065eaaa5ec73999ebef3d9a3ec1c519783e5fb5 100644 (file)
@@ -64,6 +64,7 @@ bld.SAMBA_SUBSYSTEM('TORTURE_NDR',
                   ndr/krb5pac.c
                   ndr/winspool.c
                   ndr/cabinet.c
+                  ndr/charset.c
                  ''',
        autoproto='ndr/proto.h',
        deps='torture krb5samba'