X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=eglib%2Ftest%2Fstring-util.c;h=73efd13f4de91ecfbbe8a8139f139d2e56cc795e;hb=45a6bc149df2618dc0f31c4cce8f56dd5efed7f6;hp=12050bd57d939c36c890a7119141e1eee48fe253;hpb=d3b95b39e8e56275cea6e6e1cfd439c3bdbe9c35;p=mono.git diff --git a/eglib/test/string-util.c b/eglib/test/string-util.c index 12050bd57d9..73efd13f4de 100644 --- a/eglib/test/string-util.c +++ b/eglib/test/string-util.c @@ -90,33 +90,253 @@ test_split () g_strfreev (v); + v = g_strsplit ("abcXYdefXghiXYjklYmno", "XY", 4); + if (strcmp (v [0], "abc") != 0) + return FAILED ("Invalid value 0"); + + if (strcmp (v [1], "defXghi") != 0) + return FAILED ("Invalid value 1"); + + if (strcmp (v [2], "jklYmno") != 0) + return FAILED ("Invalid value 2"); + + if (v [3] != NULL) + return FAILED ("Expected only 3 elements (1)"); + + g_strfreev (v); + + v = g_strsplit ("abcXYdefXghiXYjklYmno", "XY", 2); + if (strcmp (v [0], "abc") != 0) + return FAILED ("Invalid value 3"); + + if (strcmp (v [1], "defXghiXYjklYmno") != 0) + return FAILED ("Invalid value 4"); + + if (v [2] != NULL) + return FAILED ("Expected only 2 elements (2)"); + + g_strfreev (v); + + v = g_strsplit ("abcXYdefXghiXYjklYmnoXY", "XY", 3); + if (strcmp (v [0], "abc") != 0) + return FAILED ("Invalid value 5"); + + if (strcmp (v [1], "defXghi") != 0) + return FAILED ("Invalid value 6"); + + if (strcmp (v [2], "jklYmnoXY") != 0) + return FAILED ("Invalid value 7"); + + if (v [3] != NULL) + return FAILED ("Expected only 3 elements (3)"); + + g_strfreev (v); + + v = g_strsplit ("abcXYXYXYdefXY", "XY", -1); + if (strcmp (v [0], "abc") != 0) + return FAILED ("Invalid value 8"); + + if (strcmp (v [1], "") != 0) + return FAILED ("Invalid value 9"); + + if (strcmp (v [2], "") != 0) + return FAILED ("Invalid value 10"); + + if (strcmp (v [3], "def") != 0) + return FAILED ("Invalid value 11"); + + if (strcmp (v [4], "") != 0) + return FAILED ("Invalid value 12"); + + if (v [5] != NULL) + return FAILED ("Expected only 5 elements (4)"); + + g_strfreev (v); + + v = g_strsplit ("XYXYXYabcXYdef", "XY", -1); + if (strcmp (v [0], "") != 0) + return FAILED ("Invalid value 13"); + + if (strcmp (v [1], "") != 0) + return FAILED ("Invalid value 14"); + + if (strcmp (v [2], "") != 0) + return FAILED ("Invalid value 15"); + + if (strcmp (v [3], "abc") != 0) + return FAILED ("Invalid value 16"); + + if (strcmp (v [4], "def") != 0) + return FAILED ("Invalid value 17"); + + if (v [5] != NULL) + return FAILED ("Expected only 5 elements (5)"); + + g_strfreev (v); + + v = g_strsplit ("value=", "=", 2); + if (strcmp (v [0], "value") != 0) + return FAILED ("Invalid value 18; expected 'value', got '%s'", v [0]); + if (strcmp (v [1], "") != 0) + return FAILED ("Invalid value 19; expected '', got '%s'", v [1]); + if (v [2] != NULL) + return FAILED ("Expected only 2 elements (6)"); + + g_strfreev (v); + + return OK; +} + +RESULT +test_split_set () +{ + gchar **v; + + v = g_strsplit_set ("abcXYdefXghiXYjklYmno", "XY", 6); + if (strcmp (v [0], "abc") != 0) + return FAILED ("Invalid value 0"); + + if (strcmp (v [1], "") != 0) + return FAILED ("Invalid value 1"); + + if (strcmp (v [2], "def") != 0) + return FAILED ("Invalid value 2"); + + if (strcmp (v [3], "ghi") != 0) + return FAILED ("Invalid value 3"); + + if (strcmp (v [4], "") != 0) + return FAILED ("Invalid value 4"); + + if (strcmp (v [5], "jklYmno") != 0) + return FAILED ("Invalid value 5"); + + if (v [6] != NULL) + return FAILED ("Expected only 6 elements (1)"); + + g_strfreev (v); + + v = g_strsplit_set ("abcXYdefXghiXYjklYmno", "XY", 3); + if (strcmp (v [0], "abc") != 0) + return FAILED ("Invalid value 6"); + + if (strcmp (v [1], "") != 0) + return FAILED ("Invalid value 7"); + + if (strcmp (v [2], "defXghiXYjklYmno") != 0) + return FAILED ("Invalid value 8"); + + if (v [3] != NULL) + return FAILED ("Expected only 3 elements (2)"); + + g_strfreev (v); + + v = g_strsplit_set ("abcXdefYghiXjklYmnoX", "XY", 5); + if (strcmp (v [0], "abc") != 0) + return FAILED ("Invalid value 9"); + + if (strcmp (v [1], "def") != 0) + return FAILED ("Invalid value 10"); + + if (strcmp (v [2], "ghi") != 0) + return FAILED ("Invalid value 11"); + + if (strcmp (v [3], "jkl") != 0) + return FAILED ("Invalid value 12"); + + if (strcmp (v [4], "mnoX") != 0) + return FAILED ("Invalid value 13"); + + if (v [5] != NULL) + return FAILED ("Expected only 5 elements (5)"); + + g_strfreev (v); + + v = g_strsplit_set ("abcXYXdefXY", "XY", -1); + if (strcmp (v [0], "abc") != 0) + return FAILED ("Invalid value 14"); + + if (strcmp (v [1], "") != 0) + return FAILED ("Invalid value 15"); + + if (strcmp (v [2], "") != 0) + return FAILED ("Invalid value 16"); + + if (strcmp (v [3], "def") != 0) + return FAILED ("Invalid value 17"); + + if (strcmp (v [4], "") != 0) + return FAILED ("Invalid value 18"); + + if (strcmp (v [5], "") != 0) + return FAILED ("Invalid value 19"); + + if (v [6] != NULL) + return FAILED ("Expected only 6 elements (4)"); + + g_strfreev (v); + + v = g_strsplit_set ("XYXabcXYdef", "XY", -1); + if (strcmp (v [0], "") != 0) + return FAILED ("Invalid value 20"); + + if (strcmp (v [1], "") != 0) + return FAILED ("Invalid value 21"); + + if (strcmp (v [2], "") != 0) + return FAILED ("Invalid value 22"); + + if (strcmp (v [3], "abc") != 0) + return FAILED ("Invalid value 23"); + + if (strcmp (v [4], "") != 0) + return FAILED ("Invalid value 24"); + + if (strcmp (v [5], "def") != 0) + return FAILED ("Invalid value 25"); + + if (v [6] != NULL) + return FAILED ("Expected only 6 elements (5)"); + + g_strfreev (v); + return OK; } 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 @@ -204,6 +424,8 @@ test_strstrip () RESULT test_filename_to_uri () { +#ifdef G_OS_WIN32 +#else char *s; urit ("/a", "file:///a"); @@ -222,6 +444,7 @@ test_filename_to_uri () urit ("/@ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", "file:///@ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"); errit ("a"); errit ("./hola"); +#endif return OK; } @@ -233,6 +456,8 @@ test_filename_to_uri () RESULT test_filename_from_uri () { +#ifdef G_OS_WIN32 +#else char *s; fileit ("file:///a", "/a"); @@ -246,6 +471,7 @@ test_filename_from_uri () ferrit ("file:///%"); ferrit ("file:///%0"); ferrit ("file:///%jj"); +#endif return OK; } @@ -408,7 +634,7 @@ test_ascii_strdown () gchar *c; gint n, l; - l = strlen (b); + l = (gint)strlen (b); c = g_ascii_strdown (a, l); n = g_ascii_strncasecmp (b, c, l); @@ -421,10 +647,35 @@ 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}, {"g_strsplit", test_split}, + {"g_strsplit_set", test_split_set}, {"g_strreverse", test_strreverse}, {"g_strjoin", test_strjoin}, {"g_strchug", test_strchug}, @@ -438,6 +689,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} };