Merge pull request #249 from pcc/xgetinputfocus
[mono.git] / eglib / test / string-util.c
index 83f711516c975a7a55187de5eecba684e31165b7..3dbd738aba7fc7de580460d2a1942b9b573eab87 100644 (file)
@@ -296,27 +296,37 @@ test_split_set ()
 RESULT
 test_strreverse ()
 {
+       RESULT res = OK;
        gchar *a = g_strdup ("onetwothree");
        gchar *a_target = "eerhtowteno";
        gchar *b = g_strdup ("onetwothre");
        gchar *b_target = "erhtowteno";
+       gchar *c = g_strdup ("");
+       gchar *c_target = "";
 
        g_strreverse (a);
        if (strcmp (a, a_target)) {
-               g_free (b);
-               g_free (a);
-               return FAILED("strreverse failed. Expecting: '%s' and got '%s'\n", a, a_target);
+               res = FAILED("strreverse failed. Expecting: '%s' and got '%s'\n", a, a_target);
+               goto cleanup;
        }
 
        g_strreverse (b);
        if (strcmp (b, b_target)) {
-               g_free (b);
-               g_free (a);
-               return FAILED("strreverse failed. Expecting: '%s' and got '%s'\n", b, b_target);
+               res = FAILED("strreverse failed. Expecting: '%s' and got '%s'\n", b, b_target);
+               goto cleanup;
        }
+
+       g_strreverse (c);
+       if (strcmp (c, c_target)) {
+               res = FAILED("strreverse failed. Expecting: '%s' and got '%s'\n", b, b_target);
+               goto cleanup;
+       }
+
+cleanup:
+       g_free (c);
        g_free (b);
        g_free (a);
-       return OK;
+       return res;
 }
 
 RESULT
@@ -621,6 +631,30 @@ test_ascii_strdown ()
        return OK;
 }
 
+RESULT
+test_strdupv ()
+{
+       gchar **one;
+       gchar **two;
+       gint len;
+
+       one = g_strdupv (NULL);
+       if (one)
+               return FAILED ("Should have been NULL");
+
+       one = g_malloc (sizeof (gchar *));
+       *one = NULL;
+       two = g_strdupv (one);
+       if (!two)
+               FAILED ("Should have been not NULL");
+       len = g_strv_length (two);
+       if (len)
+               FAILED ("Should have been 0");
+       g_strfreev (two);
+       g_strfreev (one);
+       return NULL;
+}
+
 static Test strutil_tests [] = {
        {"g_strfreev", test_strfreev},
        {"g_strconcat", test_concat},
@@ -639,6 +673,7 @@ static Test strutil_tests [] = {
        {"g_strescape", test_strescape},
        {"g_ascii_strncasecmp", test_ascii_strncasecmp },
        {"g_ascii_strdown", test_ascii_strdown },
+       {"g_strdupv", test_strdupv },
        {NULL, NULL}
 };