summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsource3/selftest/tests.py2
-rw-r--r--source3/torture/torture.c98
2 files changed, 99 insertions, 1 deletions
diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py
index 19ea34a910..cf6f8a76d0 100755
--- a/source3/selftest/tests.py
+++ b/source3/selftest/tests.py
@@ -59,7 +59,7 @@ tests=[ "FDPASS", "LOCK1", "LOCK2", "LOCK3", "LOCK4", "LOCK5", "LOCK6", "LOCK7",
"TCON2", "IOCTL", "CHKPATH", "FDSESS", "LOCAL-SUBSTITUTE", "CHAIN1",
"GETADDRINFO", "POSIX", "UID-REGRESSION-TEST", "SHORTNAME-TEST",
"LOCAL-BASE64", "LOCAL-GENCACHE", "POSIX-APPEND",
- "LOCAL-string_to_sid" ]
+ "LOCAL-string_to_sid", "LOCAL-CONVERT-STRING" ]
for t in tests:
plantestsuite("samba3.smbtorture_s3.plain(dc).%s" % t, "dc", [os.path.join(samba3srcdir, "script/tests/test_smbtorture_s3.sh"), t, '//$SERVER_IP/tmp', '$USERNAME', '$PASSWORD', "", "-l $LOCAL_PATH"])
diff --git a/source3/torture/torture.c b/source3/torture/torture.c
index 175c217944..87b03b4d44 100644
--- a/source3/torture/torture.c
+++ b/source3/torture/torture.c
@@ -7259,6 +7259,103 @@ static bool run_local_rbtree(int dummy)
return ret;
}
+
+/*
+ local test for character set functions
+
+ This is a very simple test for the functionality in convert_string_error()
+ */
+static bool run_local_convert_string(int dummy)
+{
+ TALLOC_CTX *tmp_ctx = talloc_new(NULL);
+ const char *test_strings[2] = { "March", "M\303\244rz" };
+ char dst[7];
+ int i;
+
+ for (i=0; i<2; i++) {
+ const char *str = test_strings[i];
+ int len = strlen(str);
+ size_t converted_size;
+ bool ret;
+
+ memset(dst, 'X', sizeof(dst));
+
+ /* first try with real source length */
+ ret = convert_string_error(CH_UNIX, CH_UTF8,
+ str, len,
+ dst, sizeof(dst),
+ &converted_size);
+ if (ret != true) {
+ d_fprintf(stderr, "Failed to convert '%s' to CH_DISPLAY\n", str);
+ goto failed;
+ }
+
+ if (converted_size != len) {
+ d_fprintf(stderr, "Converted size of '%s' should be %d - got %d\n",
+ str, len, (int)converted_size);
+ goto failed;
+ }
+
+ if (strncmp(str, dst, converted_size) != 0) {
+ d_fprintf(stderr, "Expected '%s' to match '%s'\n", str, dst);
+ goto failed;
+ }
+
+ if (strlen(str) != converted_size) {
+ d_fprintf(stderr, "Expected '%s' length %d - got %d\n", str,
+ (int)strlen(str), (int)converted_size);
+ goto failed;
+ }
+
+ if (dst[converted_size] != 'X') {
+ d_fprintf(stderr, "Expected no termination of '%s'\n", dst);
+ goto failed;
+ }
+
+ /* now with srclen==-1, this causes the nul to be
+ * converted too */
+ ret = convert_string_error(CH_UNIX, CH_UTF8,
+ str, -1,
+ dst, sizeof(dst),
+ &converted_size);
+ if (ret != true) {
+ d_fprintf(stderr, "Failed to convert '%s' to CH_DISPLAY\n", str);
+ goto failed;
+ }
+
+ if (converted_size != len+1) {
+ d_fprintf(stderr, "Converted size of '%s' should be %d - got %d\n",
+ str, len, (int)converted_size);
+ goto failed;
+ }
+
+ if (strncmp(str, dst, converted_size) != 0) {
+ d_fprintf(stderr, "Expected '%s' to match '%s'\n", str, dst);
+ goto failed;
+ }
+
+ if (len+1 != converted_size) {
+ d_fprintf(stderr, "Expected '%s' length %d - got %d\n", str,
+ len+1, (int)converted_size);
+ goto failed;
+ }
+
+ if (dst[converted_size] != 'X') {
+ d_fprintf(stderr, "Expected no termination of '%s'\n", dst);
+ goto failed;
+ }
+
+ }
+
+
+ TALLOC_FREE(tmp_ctx);
+ return true;
+failed:
+ TALLOC_FREE(tmp_ctx);
+ return false;
+}
+
+
struct talloc_dict_test {
int content;
};
@@ -8176,6 +8273,7 @@ static struct {
{ "LOCAL-binary_to_sid", run_local_binary_to_sid, 0},
{ "LOCAL-DBTRANS", run_local_dbtrans, 0},
{ "LOCAL-TEVENT-SELECT", run_local_tevent_select, 0},
+ { "LOCAL-CONVERT-STRING", run_local_convert_string, 0},
{NULL, NULL, 0}};