s3-torture: a very simple test for convert_string_error()
authorAndrew Tridgell <tridge@samba.org>
Wed, 30 Mar 2011 06:30:08 +0000 (17:30 +1100)
committerAndrew Tridgell <tridge@samba.org>
Thu, 31 Mar 2011 10:51:24 +0000 (12:51 +0200)
this is a very simple test based on the example volker gave in
1e50f9a5. A more sophisticated test will also be worthwhile, but this
at least gives us a basic test while changes are being made

source3/selftest/tests.py
source3/torture/torture.c

index 19ea34a910d93941a291a0b646afaec494045e63..cf6f8a76d0660175099108cf23f0aeca49152087 100755 (executable)
@@ -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"])
index 175c2179444f5a299fcda3638c25b502d00e004e..87b03b4d44ebcf5338d9c83cf0e62a0242160d27 100644 (file)
@@ -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}};