1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
26 gboolean failed = FALSE;
28 #define TEST(m,cond) G_STMT_START { failed = !(cond); \
31 g_print ("\n(%s:%d) failed for: %s\n", __FILE__, __LINE__, ( # cond )); \
33 g_print ("\n(%s:%d) failed for: %s: (%s)\n", __FILE__, __LINE__, ( # cond ), (gchar*)m); \
36 g_print ("."); fflush (stdout); \
39 #define C2P(c) ((gpointer) ((long) (c)))
40 #define P2C(p) ((gchar) ((long) (p)))
42 #define GLIB_TEST_STRING "el dorado "
43 #define GLIB_TEST_STRING_5 "el do"
54 GStringChunk *string_chunk;
57 gchar *tmp_string, *tmp_string_2;
59 GString *string1, *string2;
61 string_chunk = g_string_chunk_new (1024);
63 for (i = 0; i < 100000; i ++)
65 tmp_string = g_string_chunk_insert (string_chunk, "hi pete");
67 if (strcmp ("hi pete", tmp_string) != 0)
68 g_error ("string chunks are broken.\n");
71 tmp_string_2 = g_string_chunk_insert_const (string_chunk, tmp_string);
73 g_assert (tmp_string_2 != tmp_string &&
74 strcmp(tmp_string_2, tmp_string) == 0);
76 tmp_string = g_string_chunk_insert_const (string_chunk, tmp_string);
78 g_assert (tmp_string_2 == tmp_string);
80 g_string_chunk_free (string_chunk);
82 string1 = g_string_new ("hi pete!");
83 string2 = g_string_new ("");
85 g_assert (string1 != NULL);
86 g_assert (string2 != NULL);
87 g_assert (strcmp ("hi pete!", string1->str) == 0);
88 g_assert (strcmp ("", string2->str) == 0);
90 for (i = 0; i < 10000; i++)
91 g_string_append_c (string1, 'a'+(i%26));
93 g_assert((strlen("hi pete!") + 10000) == string1->len);
94 g_assert((strlen("hi pete!") + 10000) == strlen(string1->str));
96 #if !(defined (_MSC_VER) || defined (__LCC__))
97 /* MSVC and LCC use the same run-time C library, which doesn't like
98 the %10000.10000f format... */
99 g_string_sprintf (string2, "%s|%0100d|%s|%s|%0*d|%*.*f|%10000.10000f",
100 "this pete guy sure is a wuss, like he's the number ",
102 " wuss. everyone agrees.\n",
104 10, 666, 15, 15, 666.666666666, 666.666666666);
106 g_string_sprintf (string2, "%s|%0100d|%s|%s|%0*d|%*.*f|%100.100f",
107 "this pete guy sure is a wuss, like he's the number ",
109 " wuss. everyone agrees.\n",
111 10, 666, 15, 15, 666.666666666, 666.666666666);
114 g_assert (g_strcasecmp ("FroboZZ", "frobozz") == 0);
115 g_assert (g_strcasecmp ("frobozz", "frobozz") == 0);
116 g_assert (g_strcasecmp ("frobozz", "FROBOZZ") == 0);
117 g_assert (g_strcasecmp ("FROBOZZ", "froboz") != 0);
118 g_assert (g_strcasecmp ("", "") == 0);
119 g_assert (g_strcasecmp ("!#%&/()", "!#%&/()") == 0);
120 g_assert (g_strcasecmp ("a", "b") < 0);
121 g_assert (g_strcasecmp ("a", "B") < 0);
122 g_assert (g_strcasecmp ("A", "b") < 0);
123 g_assert (g_strcasecmp ("A", "B") < 0);
124 g_assert (g_strcasecmp ("b", "a") > 0);
125 g_assert (g_strcasecmp ("b", "A") > 0);
126 g_assert (g_strcasecmp ("B", "a") > 0);
127 g_assert (g_strcasecmp ("B", "A") > 0);
129 g_assert(g_strdup(NULL) == NULL);
130 string = g_strdup(GLIB_TEST_STRING);
131 g_assert(string != NULL);
132 g_assert(strcmp(string, GLIB_TEST_STRING) == 0);
135 string = g_strconcat(GLIB_TEST_STRING, NULL);
136 g_assert(string != NULL);
137 g_assert(strcmp(string, GLIB_TEST_STRING) == 0);
140 string = g_strconcat(GLIB_TEST_STRING, GLIB_TEST_STRING,
141 GLIB_TEST_STRING, NULL);
142 g_assert(string != NULL);
143 g_assert(strcmp(string, GLIB_TEST_STRING GLIB_TEST_STRING
144 GLIB_TEST_STRING) == 0);
147 string = g_strdup_printf ("%05d %-5s", 21, "test");
148 g_assert (string != NULL);
149 g_assert (strcmp(string, "00021 test ") == 0);