summaryrefslogtreecommitdiff
path: root/source4/torture/ndr
diff options
context:
space:
mode:
authorGünther Deschner <gd@samba.org>2017-01-13 13:16:22 +0100
committerGünther Deschner <gd@samba.org>2017-01-24 10:53:17 +0100
commit56255c1c602fa24654ac41c518a6aaa75bc6415b (patch)
tree2a95762a0b4c27506784712683bacc9bfa72f361 /source4/torture/ndr
parentd30b008a642c9bb0d85519f42aef56a53e44cc77 (diff)
downloadsamba-56255c1c602fa24654ac41c518a6aaa75bc6415b.tar.gz
s4-torture: add some NDR tests for validating ndr_push_charset behavior.
Guenther Signed-off-by: Guenther Deschner <gd@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
Diffstat (limited to 'source4/torture/ndr')
-rw-r--r--source4/torture/ndr/charset.c91
-rw-r--r--source4/torture/ndr/ndr.c1
2 files changed, 92 insertions, 0 deletions
diff --git a/source4/torture/ndr/charset.c b/source4/torture/ndr/charset.c
new file mode 100644
index 00000000000..7062ce15c90
--- /dev/null
+++ b/source4/torture/ndr/charset.c
@@ -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;
+}
+
diff --git a/source4/torture/ndr/ndr.c b/source4/torture/ndr/ndr.c
index d67585c723a..17c3b1915d6 100644
--- a/source4/torture/ndr/ndr.c
+++ b/source4/torture/ndr/ndr.c
@@ -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);