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.
21 * Modified by the GLib Team and others 1997-1999. See the AUTHORS
22 * file for a list of people on the GLib Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GLib at ftp://ftp.gtk.org/pub/gtk/.
34 gboolean failed = FALSE;
36 #define TEST(m,cond) G_STMT_START { failed = !(cond); \
39 g_print ("\n(%s:%d) failed for: %s\n", __FILE__, __LINE__, ( # cond )); \
41 g_print ("\n(%s:%d) failed for: %s: (%s)\n", __FILE__, __LINE__, ( # cond ), (gchar*)m); \
44 g_print ("."); fflush (stdout); \
47 #define C2P(c) ((gpointer) ((long) (c)))
48 #define P2C(p) ((gchar) ((long) (p)))
50 #define GLIB_TEST_STRING "el dorado "
51 #define GLIB_TEST_STRING_5 "el do"
62 GStringChunk *string_chunk;
64 gchar *tmp_string = NULL, *tmp_string_2;
66 GString *string1, *string2;
68 string_chunk = g_string_chunk_new (1024);
70 for (i = 0; i < 100000; i ++)
72 tmp_string = g_string_chunk_insert (string_chunk, "hi pete");
74 if (strcmp ("hi pete", tmp_string) != 0)
75 g_error ("string chunks are broken.\n");
78 tmp_string_2 = g_string_chunk_insert_const (string_chunk, tmp_string);
80 g_assert (tmp_string_2 != tmp_string &&
81 strcmp(tmp_string_2, tmp_string) == 0);
83 tmp_string = g_string_chunk_insert_const (string_chunk, tmp_string);
85 g_assert (tmp_string_2 == tmp_string);
87 g_string_chunk_free (string_chunk);
89 string1 = g_string_new ("hi pete!");
90 string2 = g_string_new ("");
92 g_assert (string1 != NULL);
93 g_assert (string2 != NULL);
94 g_assert (strlen (string1->str) == string1->len);
95 g_assert (strlen (string2->str) == string2->len);
96 g_assert (string2->len == 0);
97 g_assert (strcmp ("hi pete!", string1->str) == 0);
98 g_assert (strcmp ("", string2->str) == 0);
100 for (i = 0; i < 10000; i++)
101 g_string_append_c (string1, 'a'+(i%26));
103 g_assert((strlen("hi pete!") + 10000) == string1->len);
104 g_assert((strlen("hi pete!") + 10000) == strlen(string1->str));
106 #if !(defined (_MSC_VER) || defined (__LCC__))
107 /* MSVC and LCC use the same run-time C library, which doesn't like
108 the %10000.10000f format... */
109 g_string_sprintf (string2, "%s|%0100d|%s|%s|%0*d|%*.*f|%10000.10000f",
110 "this pete guy sure is a wuss, like he's the number ",
112 " wuss. everyone agrees.\n",
114 10, 666, 15, 15, 666.666666666, 666.666666666);
116 g_string_sprintf (string2, "%s|%0100d|%s|%s|%0*d|%*.*f|%100.100f",
117 "this pete guy sure is a wuss, like he's the number ",
119 " wuss. everyone agrees.\n",
121 10, 666, 15, 15, 666.666666666, 666.666666666);