#include <stdio.h>
#include <string.h>
#include "glib.h"
+#include <stdarg.h>
-int array[10000];
-gboolean failed = FALSE;
+static gboolean any_failed = FALSE;
+static gboolean failed = FALSE;
#define TEST(m,cond) G_STMT_START { failed = !(cond); \
if (failed) \
g_print ("\n(%s:%d) failed for: %s\n", __FILE__, __LINE__, ( # cond )); \
else \
g_print ("\n(%s:%d) failed for: %s: (%s)\n", __FILE__, __LINE__, ( # cond ), (gchar*)m); \
+ any_failed = TRUE; \
} \
else \
g_print ("."); fflush (stdout); \
} G_STMT_END
-#define C2P(c) ((gpointer) ((long) (c)))
-#define P2C(p) ((gchar) ((long) (p)))
-
#define GLIB_TEST_STRING "el dorado "
#define GLIB_TEST_STRING_5 "el do"
gchar name[40];
} GlibTestInfo;
+static gboolean
+strv_check (gchar **strv, ...)
+{
+ gboolean ok = TRUE;
+ gint i = 0;
+ va_list list;
+
+ va_start (list, strv);
+ while (ok)
+ {
+ const gchar *str = va_arg (list, const char *);
+ if (strv[i] == NULL)
+ {
+ ok = str == NULL;
+ break;
+ }
+ if (str == NULL)
+ ok = FALSE;
+ else if (strcmp (strv[i], str) != 0)
+ ok = FALSE;
+ i++;
+ }
+ va_end (list);
+
+ g_strfreev (strv);
+
+ return ok;
+}
+
int
main (int argc,
char *argv[])
gchar *vec[] = { "Foo", "Bar", NULL };
gchar **copy;
- g_assert (g_strcasecmp ("FroboZZ", "frobozz") == 0);
- g_assert (g_strcasecmp ("frobozz", "frobozz") == 0);
- g_assert (g_strcasecmp ("frobozz", "FROBOZZ") == 0);
- g_assert (g_strcasecmp ("FROBOZZ", "froboz") != 0);
- g_assert (g_strcasecmp ("", "") == 0);
- g_assert (g_strcasecmp ("!#%&/()", "!#%&/()") == 0);
- g_assert (g_strcasecmp ("a", "b") < 0);
- g_assert (g_strcasecmp ("a", "B") < 0);
- g_assert (g_strcasecmp ("A", "b") < 0);
- g_assert (g_strcasecmp ("A", "B") < 0);
- g_assert (g_strcasecmp ("b", "a") > 0);
- g_assert (g_strcasecmp ("b", "A") > 0);
- g_assert (g_strcasecmp ("B", "a") > 0);
- g_assert (g_strcasecmp ("B", "A") > 0);
+ TEST (NULL, g_ascii_strcasecmp ("FroboZZ", "frobozz") == 0);
+ TEST (NULL, g_ascii_strcasecmp ("frobozz", "frobozz") == 0);
+ TEST (NULL, g_ascii_strcasecmp ("frobozz", "FROBOZZ") == 0);
+ TEST (NULL, g_ascii_strcasecmp ("FROBOZZ", "froboz") != 0);
+ TEST (NULL, g_ascii_strcasecmp ("", "") == 0);
+ TEST (NULL, g_ascii_strcasecmp ("!#%&/()", "!#%&/()") == 0);
+ TEST (NULL, g_ascii_strcasecmp ("a", "b") < 0);
+ TEST (NULL, g_ascii_strcasecmp ("a", "B") < 0);
+ TEST (NULL, g_ascii_strcasecmp ("A", "b") < 0);
+ TEST (NULL, g_ascii_strcasecmp ("A", "B") < 0);
+ TEST (NULL, g_ascii_strcasecmp ("b", "a") > 0);
+ TEST (NULL, g_ascii_strcasecmp ("b", "A") > 0);
+ TEST (NULL, g_ascii_strcasecmp ("B", "a") > 0);
+ TEST (NULL, g_ascii_strcasecmp ("B", "A") > 0);
g_assert(g_strdup(NULL) == NULL);
string = g_strdup(GLIB_TEST_STRING);
g_free(string);
string = g_strdup_printf ("%05d %-5s", 21, "test");
- g_assert (string != NULL);
- g_assert (strcmp(string, "00021 test ") == 0);
+ TEST (NULL, string != NULL);
+ TEST (NULL, strcmp(string, "00021 test ") == 0);
g_free (string);
- g_assert (strcmp
+ TEST (NULL, strcmp
(g_strcompress("abc\\\\\\\"\\b\\f\\n\\r\\t\\003\\177\\234\\313\\12345z"),
"abc\\\"\b\f\n\r\t\003\177\234\313\12345z") == 0);
- g_assert (strcmp(g_strescape("abc\\\"\b\f\n\r\t\003\177\234\313",
+ TEST (NULL, strcmp(g_strescape("abc\\\"\b\f\n\r\t\003\177\234\313",
NULL),
"abc\\\\\\\"\\b\\f\\n\\r\\t\\003\\177\\234\\313") == 0);
- g_assert (strcmp(g_strescape("abc\\\"\b\f\n\r\t\003\177\234\313",
+ TEST (NULL, strcmp(g_strescape("abc\\\"\b\f\n\r\t\003\177\234\313",
"\b\f\001\002\003\004"),
"abc\\\\\\\"\b\f\\n\\r\\t\003\\177\\234\\313") == 0);
copy = g_strdupv (vec);
- g_assert (strcmp (copy[0], "Foo") == 0);
- g_assert (strcmp (copy[1], "Bar") == 0);
- g_assert (copy[2] == NULL);
+ TEST (NULL, strcmp (copy[0], "Foo") == 0);
+ TEST (NULL, strcmp (copy[1], "Bar") == 0);
+ TEST (NULL, copy[2] == NULL);
g_strfreev (copy);
- g_assert (strcmp (g_strstr_len ("FooBarFooBarFoo", 6, "Bar"),
+ TEST (NULL, strcmp (g_strstr_len ("FooBarFooBarFoo", 6, "Bar"),
"BarFooBarFoo") == 0);
- g_assert (strcmp (g_strrstr ("FooBarFooBarFoo", "Bar"),
+ TEST (NULL, strcmp (g_strrstr ("FooBarFooBarFoo", "Bar"),
"BarFoo") == 0);
- g_assert (strcmp (g_strrstr_len ("FooBarFooBarFoo", 14, "BarFoo"),
+ TEST (NULL, strcmp (g_strrstr_len ("FooBarFooBarFoo", 14, "BarFoo"),
"BarFooBarFoo") == 0);
- return 0;
-}
-
-
+ TEST (NULL, strv_check (g_strsplit ("", ",", 0), "", NULL));
+ TEST (NULL, strv_check (g_strsplit ("x", ",", 0), "x", NULL));
+ TEST (NULL, strv_check (g_strsplit ("x,y", ",", 0), "x", "y", NULL));
+ TEST (NULL, strv_check (g_strsplit ("x,y,", ",", 0), "x", "y", "", NULL));
+ TEST (NULL, strv_check (g_strsplit (",x,y", ",", 0), "", "x", "y", NULL));
+ TEST (NULL, strv_check (g_strsplit (",x,y,", ",", 0), "", "x", "y", "", NULL));
+ TEST (NULL, strv_check (g_strsplit ("x,y,z", ",", 0), "x", "y", "z", NULL));
+ TEST (NULL, strv_check (g_strsplit ("x,y,z,", ",", 0), "x", "y", "z", "", NULL));
+ TEST (NULL, strv_check (g_strsplit (",x,y,z", ",", 0), "", "x", "y", "z", NULL));
+ TEST (NULL, strv_check (g_strsplit (",x,y,z,", ",", 0), "", "x", "y", "z", "", NULL));
+ TEST (NULL, strv_check (g_strsplit (",,x,,y,,z,,", ",", 0), "", "", "x", "", "y", "", "z", "", "", NULL));
+ TEST (NULL, strv_check (g_strsplit (",,x,,y,,z,,", ",,", 0), "", "x", "y", "z", "", NULL));
+
+ TEST (NULL, strv_check (g_strsplit ("", ",", 2), "", NULL));
+ TEST (NULL, strv_check (g_strsplit ("x", ",", 2), "x", NULL));
+ TEST (NULL, strv_check (g_strsplit ("x,y", ",", 2), "x", "y", NULL));
+ TEST (NULL, strv_check (g_strsplit ("x,y,", ",", 2), "x", "y", "", NULL));
+ TEST (NULL, strv_check (g_strsplit (",x,y", ",", 2), "", "x", "y", NULL));
+ TEST (NULL, strv_check (g_strsplit (",x,y,", ",", 2), "", "x", "y,", NULL));
+ TEST (NULL, strv_check (g_strsplit ("x,y,z", ",", 2), "x", "y", "z", NULL));
+ TEST (NULL, strv_check (g_strsplit ("x,y,z,", ",", 2), "x", "y", "z,", NULL));
+ TEST (NULL, strv_check (g_strsplit (",x,y,z", ",", 2), "", "x", "y,z", NULL));
+ TEST (NULL, strv_check (g_strsplit (",x,y,z,", ",", 2), "", "x", "y,z,", NULL));
+ TEST (NULL, strv_check (g_strsplit (",,x,,y,,z,,", ",", 2), "", "", "x,,y,,z,,", NULL));
+ TEST (NULL, strv_check (g_strsplit (",,x,,y,,z,,", ",,", 2), "", "x", "y,,z,,", NULL));
+
+ g_print ("\n");
+
+ return any_failed;
+}