mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-27 14:36:16 +01:00
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.
This commit is contained in:
parent
c2ec77f534
commit
669974f6d7
@ -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>
|
2001-08-03 Sven Neumann <sven@gimp.org>
|
||||||
|
|
||||||
* configure.in: beautified configure help output.
|
* configure.in: beautified configure help output.
|
||||||
|
@ -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>
|
2001-08-03 Sven Neumann <sven@gimp.org>
|
||||||
|
|
||||||
* configure.in: beautified configure help output.
|
* configure.in: beautified configure help output.
|
||||||
|
@ -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>
|
2001-08-03 Sven Neumann <sven@gimp.org>
|
||||||
|
|
||||||
* configure.in: beautified configure help output.
|
* configure.in: beautified configure help output.
|
||||||
|
@ -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>
|
2001-08-03 Sven Neumann <sven@gimp.org>
|
||||||
|
|
||||||
* configure.in: beautified configure help output.
|
* configure.in: beautified configure help output.
|
||||||
|
@ -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>
|
2001-08-03 Sven Neumann <sven@gimp.org>
|
||||||
|
|
||||||
* configure.in: beautified configure help output.
|
* configure.in: beautified configure help output.
|
||||||
|
@ -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>
|
2001-08-03 Sven Neumann <sven@gimp.org>
|
||||||
|
|
||||||
* configure.in: beautified configure help output.
|
* configure.in: beautified configure help output.
|
||||||
|
@ -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>
|
2001-08-03 Sven Neumann <sven@gimp.org>
|
||||||
|
|
||||||
* configure.in: beautified configure help output.
|
* configure.in: beautified configure help output.
|
||||||
|
@ -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>
|
2001-08-03 Sven Neumann <sven@gimp.org>
|
||||||
|
|
||||||
* configure.in: beautified configure help output.
|
* configure.in: beautified configure help output.
|
||||||
|
@ -31,10 +31,12 @@
|
|||||||
* MT safe
|
* MT safe
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
#include "giochannel.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
#ifdef HAVE_UNISTD_H
|
#ifdef HAVE_UNISTD_H
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -27,8 +27,8 @@
|
|||||||
#ifndef __G_IOCHANNEL_H__
|
#ifndef __G_IOCHANNEL_H__
|
||||||
#define __G_IOCHANNEL_H__
|
#define __G_IOCHANNEL_H__
|
||||||
|
|
||||||
|
#include <glib/gconvert.h>
|
||||||
#include <glib/gmain.h>
|
#include <glib/gmain.h>
|
||||||
#include <glib/gtypes.h>
|
|
||||||
#include <glib/gstring.h>
|
#include <glib/gstring.h>
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
@ -18,6 +18,7 @@ date-test
|
|||||||
dirname-test
|
dirname-test
|
||||||
hash-test
|
hash-test
|
||||||
iochannel-test
|
iochannel-test
|
||||||
|
iochannel-test-outfile
|
||||||
list-test
|
list-test
|
||||||
mainloop-test
|
mainloop-test
|
||||||
markup-test
|
markup-test
|
||||||
|
@ -30,9 +30,10 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "glib.h"
|
#include "glib.h"
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
int array[10000];
|
static gboolean any_failed = FALSE;
|
||||||
gboolean failed = FALSE;
|
static gboolean failed = FALSE;
|
||||||
|
|
||||||
#define TEST(m,cond) G_STMT_START { failed = !(cond); \
|
#define TEST(m,cond) G_STMT_START { failed = !(cond); \
|
||||||
if (failed) \
|
if (failed) \
|
||||||
@ -40,14 +41,12 @@ if (failed) \
|
|||||||
g_print ("\n(%s:%d) failed for: %s\n", __FILE__, __LINE__, ( # cond )); \
|
g_print ("\n(%s:%d) failed for: %s\n", __FILE__, __LINE__, ( # cond )); \
|
||||||
else \
|
else \
|
||||||
g_print ("\n(%s:%d) failed for: %s: (%s)\n", __FILE__, __LINE__, ( # cond ), (gchar*)m); \
|
g_print ("\n(%s:%d) failed for: %s: (%s)\n", __FILE__, __LINE__, ( # cond ), (gchar*)m); \
|
||||||
|
any_failed = TRUE; \
|
||||||
} \
|
} \
|
||||||
else \
|
else \
|
||||||
g_print ("."); fflush (stdout); \
|
g_print ("."); fflush (stdout); \
|
||||||
} G_STMT_END
|
} 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 "el dorado "
|
||||||
#define GLIB_TEST_STRING_5 "el do"
|
#define GLIB_TEST_STRING_5 "el do"
|
||||||
|
|
||||||
@ -56,6 +55,35 @@ typedef struct {
|
|||||||
gchar name[40];
|
gchar name[40];
|
||||||
} GlibTestInfo;
|
} 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
|
int
|
||||||
main (int argc,
|
main (int argc,
|
||||||
char *argv[])
|
char *argv[])
|
||||||
@ -64,20 +92,20 @@ main (int argc,
|
|||||||
gchar *vec[] = { "Foo", "Bar", NULL };
|
gchar *vec[] = { "Foo", "Bar", NULL };
|
||||||
gchar **copy;
|
gchar **copy;
|
||||||
|
|
||||||
g_assert (g_strcasecmp ("FroboZZ", "frobozz") == 0);
|
TEST (NULL, g_ascii_strcasecmp ("FroboZZ", "frobozz") == 0);
|
||||||
g_assert (g_strcasecmp ("frobozz", "frobozz") == 0);
|
TEST (NULL, g_ascii_strcasecmp ("frobozz", "frobozz") == 0);
|
||||||
g_assert (g_strcasecmp ("frobozz", "FROBOZZ") == 0);
|
TEST (NULL, g_ascii_strcasecmp ("frobozz", "FROBOZZ") == 0);
|
||||||
g_assert (g_strcasecmp ("FROBOZZ", "froboz") != 0);
|
TEST (NULL, g_ascii_strcasecmp ("FROBOZZ", "froboz") != 0);
|
||||||
g_assert (g_strcasecmp ("", "") == 0);
|
TEST (NULL, g_ascii_strcasecmp ("", "") == 0);
|
||||||
g_assert (g_strcasecmp ("!#%&/()", "!#%&/()") == 0);
|
TEST (NULL, g_ascii_strcasecmp ("!#%&/()", "!#%&/()") == 0);
|
||||||
g_assert (g_strcasecmp ("a", "b") < 0);
|
TEST (NULL, g_ascii_strcasecmp ("a", "b") < 0);
|
||||||
g_assert (g_strcasecmp ("a", "B") < 0);
|
TEST (NULL, g_ascii_strcasecmp ("a", "B") < 0);
|
||||||
g_assert (g_strcasecmp ("A", "b") < 0);
|
TEST (NULL, g_ascii_strcasecmp ("A", "b") < 0);
|
||||||
g_assert (g_strcasecmp ("A", "B") < 0);
|
TEST (NULL, g_ascii_strcasecmp ("A", "B") < 0);
|
||||||
g_assert (g_strcasecmp ("b", "a") > 0);
|
TEST (NULL, g_ascii_strcasecmp ("b", "a") > 0);
|
||||||
g_assert (g_strcasecmp ("b", "A") > 0);
|
TEST (NULL, g_ascii_strcasecmp ("b", "A") > 0);
|
||||||
g_assert (g_strcasecmp ("B", "a") > 0);
|
TEST (NULL, g_ascii_strcasecmp ("B", "a") > 0);
|
||||||
g_assert (g_strcasecmp ("B", "A") > 0);
|
TEST (NULL, g_ascii_strcasecmp ("B", "A") > 0);
|
||||||
|
|
||||||
g_assert(g_strdup(NULL) == NULL);
|
g_assert(g_strdup(NULL) == NULL);
|
||||||
string = g_strdup(GLIB_TEST_STRING);
|
string = g_strdup(GLIB_TEST_STRING);
|
||||||
@ -98,34 +126,60 @@ main (int argc,
|
|||||||
g_free(string);
|
g_free(string);
|
||||||
|
|
||||||
string = g_strdup_printf ("%05d %-5s", 21, "test");
|
string = g_strdup_printf ("%05d %-5s", 21, "test");
|
||||||
g_assert (string != NULL);
|
TEST (NULL, string != NULL);
|
||||||
g_assert (strcmp(string, "00021 test ") == 0);
|
TEST (NULL, strcmp(string, "00021 test ") == 0);
|
||||||
g_free (string);
|
g_free (string);
|
||||||
|
|
||||||
g_assert (strcmp
|
TEST (NULL, strcmp
|
||||||
(g_strcompress("abc\\\\\\\"\\b\\f\\n\\r\\t\\003\\177\\234\\313\\12345z"),
|
(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);
|
"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),
|
NULL),
|
||||||
"abc\\\\\\\"\\b\\f\\n\\r\\t\\003\\177\\234\\313") == 0);
|
"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"),
|
"\b\f\001\002\003\004"),
|
||||||
"abc\\\\\\\"\b\f\\n\\r\\t\003\\177\\234\\313") == 0);
|
"abc\\\\\\\"\b\f\\n\\r\\t\003\\177\\234\\313") == 0);
|
||||||
|
|
||||||
copy = g_strdupv (vec);
|
copy = g_strdupv (vec);
|
||||||
g_assert (strcmp (copy[0], "Foo") == 0);
|
TEST (NULL, strcmp (copy[0], "Foo") == 0);
|
||||||
g_assert (strcmp (copy[1], "Bar") == 0);
|
TEST (NULL, strcmp (copy[1], "Bar") == 0);
|
||||||
g_assert (copy[2] == NULL);
|
TEST (NULL, copy[2] == NULL);
|
||||||
g_strfreev (copy);
|
g_strfreev (copy);
|
||||||
|
|
||||||
g_assert (strcmp (g_strstr_len ("FooBarFooBarFoo", 6, "Bar"),
|
TEST (NULL, strcmp (g_strstr_len ("FooBarFooBarFoo", 6, "Bar"),
|
||||||
"BarFooBarFoo") == 0);
|
"BarFooBarFoo") == 0);
|
||||||
g_assert (strcmp (g_strrstr ("FooBarFooBarFoo", "Bar"),
|
TEST (NULL, strcmp (g_strrstr ("FooBarFooBarFoo", "Bar"),
|
||||||
"BarFoo") == 0);
|
"BarFoo") == 0);
|
||||||
g_assert (strcmp (g_strrstr_len ("FooBarFooBarFoo", 14, "BarFoo"),
|
TEST (NULL, strcmp (g_strrstr_len ("FooBarFooBarFoo", 14, "BarFoo"),
|
||||||
"BarFooBarFoo") == 0);
|
"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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user