summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarin Adler <darin@src.gnome.org>2001-08-03 19:25:53 +0000
committerDarin Adler <darin@src.gnome.org>2001-08-03 19:25:53 +0000
commit669974f6d79a58f19c583995b41a3e0bf8b1cbf4 (patch)
treebf720d85eafeb347f4da5ffc59e243e8f18ee0e7
parentc2ec77f534b5d1082471cff101de3b43c3a7edc0 (diff)
Improve strfunc test to test the split function in a way that demonstrates
* tests/.cvsignore: * tests/strfunc-test.c: (strv_check), (main): Improve strfunc test to test the split function in a way that demonstrates its idiosyncrasies.
-rw-r--r--ChangeLog7
-rw-r--r--ChangeLog.pre-2-07
-rw-r--r--ChangeLog.pre-2-107
-rw-r--r--ChangeLog.pre-2-127
-rw-r--r--ChangeLog.pre-2-27
-rw-r--r--ChangeLog.pre-2-47
-rw-r--r--ChangeLog.pre-2-67
-rw-r--r--ChangeLog.pre-2-87
-rw-r--r--glib/giochannel.c4
-rw-r--r--glib/giochannel.h2
-rw-r--r--tests/.cvsignore1
-rw-r--r--tests/strfunc-test.c122
12 files changed, 149 insertions, 36 deletions
diff --git a/ChangeLog b/ChangeLog
index 8768e4373..d8929d1fd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2001-08-03 Darin Adler <darin@bentspoon.com>
+
+ * tests/strfunc-test.c: (strv_check), (main):
+ Improve strfunc test to test the split function in a way that
+ demonstrates its idiosyncrasies.
+ * tests/.cvsignore:
+
2001-08-03 Sven Neumann <sven@gimp.org>
* configure.in: beautified configure help output.
diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0
index 8768e4373..d8929d1fd 100644
--- a/ChangeLog.pre-2-0
+++ b/ChangeLog.pre-2-0
@@ -1,3 +1,10 @@
+2001-08-03 Darin Adler <darin@bentspoon.com>
+
+ * tests/strfunc-test.c: (strv_check), (main):
+ Improve strfunc test to test the split function in a way that
+ demonstrates its idiosyncrasies.
+ * tests/.cvsignore:
+
2001-08-03 Sven Neumann <sven@gimp.org>
* configure.in: beautified configure help output.
diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10
index 8768e4373..d8929d1fd 100644
--- a/ChangeLog.pre-2-10
+++ b/ChangeLog.pre-2-10
@@ -1,3 +1,10 @@
+2001-08-03 Darin Adler <darin@bentspoon.com>
+
+ * tests/strfunc-test.c: (strv_check), (main):
+ Improve strfunc test to test the split function in a way that
+ demonstrates its idiosyncrasies.
+ * tests/.cvsignore:
+
2001-08-03 Sven Neumann <sven@gimp.org>
* configure.in: beautified configure help output.
diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12
index 8768e4373..d8929d1fd 100644
--- a/ChangeLog.pre-2-12
+++ b/ChangeLog.pre-2-12
@@ -1,3 +1,10 @@
+2001-08-03 Darin Adler <darin@bentspoon.com>
+
+ * tests/strfunc-test.c: (strv_check), (main):
+ Improve strfunc test to test the split function in a way that
+ demonstrates its idiosyncrasies.
+ * tests/.cvsignore:
+
2001-08-03 Sven Neumann <sven@gimp.org>
* configure.in: beautified configure help output.
diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2
index 8768e4373..d8929d1fd 100644
--- a/ChangeLog.pre-2-2
+++ b/ChangeLog.pre-2-2
@@ -1,3 +1,10 @@
+2001-08-03 Darin Adler <darin@bentspoon.com>
+
+ * tests/strfunc-test.c: (strv_check), (main):
+ Improve strfunc test to test the split function in a way that
+ demonstrates its idiosyncrasies.
+ * tests/.cvsignore:
+
2001-08-03 Sven Neumann <sven@gimp.org>
* configure.in: beautified configure help output.
diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4
index 8768e4373..d8929d1fd 100644
--- a/ChangeLog.pre-2-4
+++ b/ChangeLog.pre-2-4
@@ -1,3 +1,10 @@
+2001-08-03 Darin Adler <darin@bentspoon.com>
+
+ * tests/strfunc-test.c: (strv_check), (main):
+ Improve strfunc test to test the split function in a way that
+ demonstrates its idiosyncrasies.
+ * tests/.cvsignore:
+
2001-08-03 Sven Neumann <sven@gimp.org>
* configure.in: beautified configure help output.
diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6
index 8768e4373..d8929d1fd 100644
--- a/ChangeLog.pre-2-6
+++ b/ChangeLog.pre-2-6
@@ -1,3 +1,10 @@
+2001-08-03 Darin Adler <darin@bentspoon.com>
+
+ * tests/strfunc-test.c: (strv_check), (main):
+ Improve strfunc test to test the split function in a way that
+ demonstrates its idiosyncrasies.
+ * tests/.cvsignore:
+
2001-08-03 Sven Neumann <sven@gimp.org>
* configure.in: beautified configure help output.
diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8
index 8768e4373..d8929d1fd 100644
--- a/ChangeLog.pre-2-8
+++ b/ChangeLog.pre-2-8
@@ -1,3 +1,10 @@
+2001-08-03 Darin Adler <darin@bentspoon.com>
+
+ * tests/strfunc-test.c: (strv_check), (main):
+ Improve strfunc test to test the split function in a way that
+ demonstrates its idiosyncrasies.
+ * tests/.cvsignore:
+
2001-08-03 Sven Neumann <sven@gimp.org>
* configure.in: beautified configure help output.
diff --git a/glib/giochannel.c b/glib/giochannel.c
index b9608f6ee..01f741681 100644
--- a/glib/giochannel.c
+++ b/glib/giochannel.c
@@ -31,10 +31,12 @@
* MT safe
*/
+#include "config.h"
+#include "giochannel.h"
+
#include <string.h>
#include <errno.h>
-#include "config.h"
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
diff --git a/glib/giochannel.h b/glib/giochannel.h
index 4e605257f..2c31ee8e6 100644
--- a/glib/giochannel.h
+++ b/glib/giochannel.h
@@ -27,8 +27,8 @@
#ifndef __G_IOCHANNEL_H__
#define __G_IOCHANNEL_H__
+#include <glib/gconvert.h>
#include <glib/gmain.h>
-#include <glib/gtypes.h>
#include <glib/gstring.h>
G_BEGIN_DECLS
diff --git a/tests/.cvsignore b/tests/.cvsignore
index be029496e..614a73d32 100644
--- a/tests/.cvsignore
+++ b/tests/.cvsignore
@@ -18,6 +18,7 @@ date-test
dirname-test
hash-test
iochannel-test
+iochannel-test-outfile
list-test
mainloop-test
markup-test
diff --git a/tests/strfunc-test.c b/tests/strfunc-test.c
index 504195d82..3f335a432 100644
--- a/tests/strfunc-test.c
+++ b/tests/strfunc-test.c
@@ -30,9 +30,10 @@
#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) \
@@ -40,14 +41,12 @@ 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"
@@ -56,6 +55,35 @@ typedef struct {
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[])
@@ -64,20 +92,20 @@ main (int argc,
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);
@@ -98,34 +126,60 @@ main (int argc,
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;
+}