inserted additional note to look for ChangeLog and AUTHORS file for a log
[platform/upstream/glib.git] / tests / string-test.c
1 /* GLIB - Library of useful routines for C programming
2  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 /*
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/. 
25  */
26
27 #undef G_LOG_DOMAIN
28
29 #include <stdio.h>
30 #include <string.h>
31 #include "glib.h"
32
33 int array[10000];
34 gboolean failed = FALSE;
35
36 #define TEST(m,cond)    G_STMT_START { failed = !(cond); \
37 if (failed) \
38   { if (!m) \
39       g_print ("\n(%s:%d) failed for: %s\n", __FILE__, __LINE__, ( # cond )); \
40     else \
41       g_print ("\n(%s:%d) failed for: %s: (%s)\n", __FILE__, __LINE__, ( # cond ), (gchar*)m); \
42   } \
43 else \
44   g_print ("."); fflush (stdout); \
45 } G_STMT_END
46
47 #define C2P(c)          ((gpointer) ((long) (c)))
48 #define P2C(p)          ((gchar) ((long) (p)))
49
50 #define GLIB_TEST_STRING "el dorado "
51 #define GLIB_TEST_STRING_5 "el do"
52
53 typedef struct {
54         guint age;
55         gchar name[40];
56 } GlibTestInfo;
57
58 int
59 main (int   argc,
60       char *argv[])
61 {
62   GStringChunk *string_chunk;
63
64   gchar *tmp_string = NULL, *tmp_string_2;
65   gint i;
66   GString *string1, *string2;
67
68   string_chunk = g_string_chunk_new (1024);
69
70   for (i = 0; i < 100000; i ++)
71     {
72       tmp_string = g_string_chunk_insert (string_chunk, "hi pete");
73
74       if (strcmp ("hi pete", tmp_string) != 0)
75         g_error ("string chunks are broken.\n");
76     }
77
78   tmp_string_2 = g_string_chunk_insert_const (string_chunk, tmp_string);
79
80   g_assert (tmp_string_2 != tmp_string &&
81             strcmp(tmp_string_2, tmp_string) == 0);
82
83   tmp_string = g_string_chunk_insert_const (string_chunk, tmp_string);
84
85   g_assert (tmp_string_2 == tmp_string);
86
87   g_string_chunk_free (string_chunk);
88
89   string1 = g_string_new ("hi pete!");
90   string2 = g_string_new ("");
91
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);
99
100   for (i = 0; i < 10000; i++)
101     g_string_append_c (string1, 'a'+(i%26));
102
103   g_assert((strlen("hi pete!") + 10000) == string1->len);
104   g_assert((strlen("hi pete!") + 10000) == strlen(string1->str));
105
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 ",
111                     1,
112                     " wuss.  everyone agrees.\n",
113                     string1->str,
114                     10, 666, 15, 15, 666.666666666, 666.666666666);
115 #else
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 ",
118                     1,
119                     " wuss.  everyone agrees.\n",
120                     string1->str,
121                     10, 666, 15, 15, 666.666666666, 666.666666666);
122 #endif
123
124   return 0;
125 }
126