Commit 669974f6 authored by Darin Adler's avatar Darin Adler

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.
parent c2ec77f5
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.
......
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.
......
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.
......
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.
......
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.
......
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.
......
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.
......
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.
......
......@@ -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
......
......@@ -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
......
......@@ -18,6 +18,7 @@ date-test
dirname-test
hash-test
iochannel-test
iochannel-test-outfile
list-test
mainloop-test
markup-test
......
......@@ -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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment