sl@0
|
1 |
/* GLIB - Library of useful routines for C programming
|
sl@0
|
2 |
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
sl@0
|
3 |
* Portion Copyright © 2008-09 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
|
sl@0
|
4 |
* This library is free software; you can redistribute it and/or
|
sl@0
|
5 |
* modify it under the terms of the GNU Lesser General Public
|
sl@0
|
6 |
* License as published by the Free Software Foundation; either
|
sl@0
|
7 |
* version 2 of the License, or (at your option) any later version.
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* This library is distributed in the hope that it will be useful,
|
sl@0
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
sl@0
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
sl@0
|
12 |
* Lesser General Public License for more details.
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* You should have received a copy of the GNU Lesser General Public
|
sl@0
|
15 |
* License along with this library; if not, write to the
|
sl@0
|
16 |
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
sl@0
|
17 |
* Boston, MA 02111-1307, USA.
|
sl@0
|
18 |
*/
|
sl@0
|
19 |
|
sl@0
|
20 |
/*
|
sl@0
|
21 |
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
sl@0
|
22 |
* file for a list of people on the GLib Team. See the ChangeLog
|
sl@0
|
23 |
* files for a list of changes. These files are distributed with
|
sl@0
|
24 |
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
sl@0
|
25 |
*/
|
sl@0
|
26 |
|
sl@0
|
27 |
#include "config.h"
|
sl@0
|
28 |
|
sl@0
|
29 |
#undef GLIB_COMPILATION
|
sl@0
|
30 |
|
sl@0
|
31 |
#include <stdio.h>
|
sl@0
|
32 |
#include <string.h>
|
sl@0
|
33 |
#include <errno.h>
|
sl@0
|
34 |
|
sl@0
|
35 |
#include "glib.h"
|
sl@0
|
36 |
#include <glib/gstdio.h>
|
sl@0
|
37 |
|
sl@0
|
38 |
#ifdef __SYMBIAN32__
|
sl@0
|
39 |
#include <sys/stat.h>
|
sl@0
|
40 |
#include <glib_global.h>
|
sl@0
|
41 |
#include "mrt2_glib2_test.h"
|
sl@0
|
42 |
#endif /*__SYMBIAN32__*/
|
sl@0
|
43 |
|
sl@0
|
44 |
#ifdef HAVE_UNISTD_H
|
sl@0
|
45 |
#include <unistd.h>
|
sl@0
|
46 |
#endif
|
sl@0
|
47 |
|
sl@0
|
48 |
#ifdef G_OS_WIN32
|
sl@0
|
49 |
#include <io.h> /* For read(), write() etc */
|
sl@0
|
50 |
#endif
|
sl@0
|
51 |
|
sl@0
|
52 |
|
sl@0
|
53 |
#define GLIB_TEST_STRING "el dorado "
|
sl@0
|
54 |
#define GLIB_TEST_STRING_5 "el do"
|
sl@0
|
55 |
|
sl@0
|
56 |
|
sl@0
|
57 |
/* --- variables --- */
|
sl@0
|
58 |
static gint test_nums[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
sl@0
|
59 |
static gint more_nums[10] = { 8, 9, 7, 0, 3, 2, 5, 1, 4, 6};
|
sl@0
|
60 |
|
sl@0
|
61 |
/* --- functions --- */
|
sl@0
|
62 |
static gint
|
sl@0
|
63 |
my_list_compare_one (gconstpointer a, gconstpointer b)
|
sl@0
|
64 |
{
|
sl@0
|
65 |
gint one = *((const gint*)a);
|
sl@0
|
66 |
gint two = *((const gint*)b);
|
sl@0
|
67 |
return one-two;
|
sl@0
|
68 |
}
|
sl@0
|
69 |
|
sl@0
|
70 |
static gint
|
sl@0
|
71 |
my_list_compare_two (gconstpointer a, gconstpointer b)
|
sl@0
|
72 |
{
|
sl@0
|
73 |
gint one = *((const gint*)a);
|
sl@0
|
74 |
gint two = *((const gint*)b);
|
sl@0
|
75 |
return two-one;
|
sl@0
|
76 |
}
|
sl@0
|
77 |
|
sl@0
|
78 |
/* static void
|
sl@0
|
79 |
my_list_print (gpointer a, gpointer b)
|
sl@0
|
80 |
{
|
sl@0
|
81 |
gint three = *((gint*)a);
|
sl@0
|
82 |
g_print("%d", three);
|
sl@0
|
83 |
}; */
|
sl@0
|
84 |
|
sl@0
|
85 |
static void
|
sl@0
|
86 |
glist_test (void)
|
sl@0
|
87 |
{
|
sl@0
|
88 |
GList *list = NULL;
|
sl@0
|
89 |
guint i;
|
sl@0
|
90 |
|
sl@0
|
91 |
for (i = 0; i < 10; i++)
|
sl@0
|
92 |
list = g_list_append (list, &test_nums[i]);
|
sl@0
|
93 |
list = g_list_reverse (list);
|
sl@0
|
94 |
|
sl@0
|
95 |
for (i = 0; i < 10; i++)
|
sl@0
|
96 |
{
|
sl@0
|
97 |
GList *t = g_list_nth (list, i);
|
sl@0
|
98 |
if (*((gint*) t->data) != (9 - i))
|
sl@0
|
99 |
g_error ("Regular insert failed");
|
sl@0
|
100 |
}
|
sl@0
|
101 |
|
sl@0
|
102 |
for (i = 0; i < 10; i++)
|
sl@0
|
103 |
if (g_list_position (list, g_list_nth (list, i)) != i)
|
sl@0
|
104 |
g_error ("g_list_position does not seem to be the inverse of g_list_nth\n");
|
sl@0
|
105 |
|
sl@0
|
106 |
g_list_free (list);
|
sl@0
|
107 |
list = NULL;
|
sl@0
|
108 |
|
sl@0
|
109 |
for (i = 0; i < 10; i++)
|
sl@0
|
110 |
list = g_list_insert_sorted (list, &more_nums[i], my_list_compare_one);
|
sl@0
|
111 |
|
sl@0
|
112 |
/*
|
sl@0
|
113 |
g_print("\n");
|
sl@0
|
114 |
g_list_foreach (list, my_list_print, NULL);
|
sl@0
|
115 |
*/
|
sl@0
|
116 |
|
sl@0
|
117 |
for (i = 0; i < 10; i++)
|
sl@0
|
118 |
{
|
sl@0
|
119 |
GList *t = g_list_nth (list, i);
|
sl@0
|
120 |
if (*((gint*) t->data) != i)
|
sl@0
|
121 |
g_error ("Sorted insert failed");
|
sl@0
|
122 |
}
|
sl@0
|
123 |
|
sl@0
|
124 |
g_list_free (list);
|
sl@0
|
125 |
list = NULL;
|
sl@0
|
126 |
|
sl@0
|
127 |
for (i = 0; i < 10; i++)
|
sl@0
|
128 |
list = g_list_insert_sorted (list, &more_nums[i], my_list_compare_two);
|
sl@0
|
129 |
|
sl@0
|
130 |
/*
|
sl@0
|
131 |
g_print("\n");
|
sl@0
|
132 |
g_list_foreach (list, my_list_print, NULL);
|
sl@0
|
133 |
*/
|
sl@0
|
134 |
|
sl@0
|
135 |
for (i = 0; i < 10; i++)
|
sl@0
|
136 |
{
|
sl@0
|
137 |
GList *t = g_list_nth (list, i);
|
sl@0
|
138 |
if (*((gint*) t->data) != (9 - i))
|
sl@0
|
139 |
g_error ("Sorted insert failed");
|
sl@0
|
140 |
}
|
sl@0
|
141 |
|
sl@0
|
142 |
g_list_free (list);
|
sl@0
|
143 |
list = NULL;
|
sl@0
|
144 |
|
sl@0
|
145 |
for (i = 0; i < 10; i++)
|
sl@0
|
146 |
list = g_list_prepend (list, &more_nums[i]);
|
sl@0
|
147 |
|
sl@0
|
148 |
list = g_list_sort (list, my_list_compare_two);
|
sl@0
|
149 |
|
sl@0
|
150 |
/*
|
sl@0
|
151 |
g_print("\n");
|
sl@0
|
152 |
g_list_foreach (list, my_list_print, NULL);
|
sl@0
|
153 |
*/
|
sl@0
|
154 |
|
sl@0
|
155 |
for (i = 0; i < 10; i++)
|
sl@0
|
156 |
{
|
sl@0
|
157 |
GList *t = g_list_nth (list, i);
|
sl@0
|
158 |
if (*((gint*) t->data) != (9 - i))
|
sl@0
|
159 |
g_error ("Merge sort failed");
|
sl@0
|
160 |
}
|
sl@0
|
161 |
|
sl@0
|
162 |
g_list_free (list);
|
sl@0
|
163 |
}
|
sl@0
|
164 |
|
sl@0
|
165 |
static void
|
sl@0
|
166 |
gslist_test (void)
|
sl@0
|
167 |
{
|
sl@0
|
168 |
GSList *slist = NULL;
|
sl@0
|
169 |
guint i;
|
sl@0
|
170 |
|
sl@0
|
171 |
for (i = 0; i < 10; i++)
|
sl@0
|
172 |
slist = g_slist_append (slist, &test_nums[i]);
|
sl@0
|
173 |
slist = g_slist_reverse (slist);
|
sl@0
|
174 |
|
sl@0
|
175 |
for (i = 0; i < 10; i++)
|
sl@0
|
176 |
{
|
sl@0
|
177 |
GSList *st = g_slist_nth (slist, i);
|
sl@0
|
178 |
if (*((gint*) st->data) != (9 - i))
|
sl@0
|
179 |
g_error ("failed");
|
sl@0
|
180 |
}
|
sl@0
|
181 |
|
sl@0
|
182 |
g_slist_free (slist);
|
sl@0
|
183 |
slist = NULL;
|
sl@0
|
184 |
|
sl@0
|
185 |
for (i = 0; i < 10; i++)
|
sl@0
|
186 |
slist = g_slist_insert_sorted (slist, &more_nums[i], my_list_compare_one);
|
sl@0
|
187 |
|
sl@0
|
188 |
/*
|
sl@0
|
189 |
g_print("\n");
|
sl@0
|
190 |
g_slist_foreach (slist, my_list_print, NULL);
|
sl@0
|
191 |
*/
|
sl@0
|
192 |
|
sl@0
|
193 |
for (i = 0; i < 10; i++)
|
sl@0
|
194 |
{
|
sl@0
|
195 |
GSList *st = g_slist_nth (slist, i);
|
sl@0
|
196 |
if (*((gint*) st->data) != i)
|
sl@0
|
197 |
g_error ("Sorted insert failed");
|
sl@0
|
198 |
}
|
sl@0
|
199 |
|
sl@0
|
200 |
g_slist_free (slist);
|
sl@0
|
201 |
slist = NULL;
|
sl@0
|
202 |
|
sl@0
|
203 |
for (i = 0; i < 10; i++)
|
sl@0
|
204 |
slist = g_slist_insert_sorted (slist, &more_nums[i], my_list_compare_two);
|
sl@0
|
205 |
|
sl@0
|
206 |
/*
|
sl@0
|
207 |
g_print("\n");
|
sl@0
|
208 |
g_slist_foreach (slist, my_list_print, NULL);
|
sl@0
|
209 |
*/
|
sl@0
|
210 |
|
sl@0
|
211 |
for (i = 0; i < 10; i++)
|
sl@0
|
212 |
{
|
sl@0
|
213 |
GSList *st = g_slist_nth (slist, i);
|
sl@0
|
214 |
if (*((gint*) st->data) != (9 - i))
|
sl@0
|
215 |
g_error("Sorted insert failed");
|
sl@0
|
216 |
}
|
sl@0
|
217 |
|
sl@0
|
218 |
g_slist_free(slist);
|
sl@0
|
219 |
slist = NULL;
|
sl@0
|
220 |
|
sl@0
|
221 |
for (i = 0; i < 10; i++)
|
sl@0
|
222 |
slist = g_slist_prepend (slist, &more_nums[i]);
|
sl@0
|
223 |
|
sl@0
|
224 |
slist = g_slist_sort (slist, my_list_compare_two);
|
sl@0
|
225 |
|
sl@0
|
226 |
/*
|
sl@0
|
227 |
g_print("\n");
|
sl@0
|
228 |
g_slist_foreach (slist, my_list_print, NULL);
|
sl@0
|
229 |
*/
|
sl@0
|
230 |
|
sl@0
|
231 |
for (i = 0; i < 10; i++)
|
sl@0
|
232 |
{
|
sl@0
|
233 |
GSList *st = g_slist_nth (slist, i);
|
sl@0
|
234 |
if (*((gint*) st->data) != (9 - i))
|
sl@0
|
235 |
g_error("Sorted insert failed");
|
sl@0
|
236 |
}
|
sl@0
|
237 |
|
sl@0
|
238 |
g_slist_free(slist);
|
sl@0
|
239 |
}
|
sl@0
|
240 |
|
sl@0
|
241 |
static gboolean
|
sl@0
|
242 |
node_build_string (GNode *node,
|
sl@0
|
243 |
gpointer data)
|
sl@0
|
244 |
{
|
sl@0
|
245 |
gchar **p = data;
|
sl@0
|
246 |
gchar *string;
|
sl@0
|
247 |
gchar c[2] = "_";
|
sl@0
|
248 |
|
sl@0
|
249 |
c[0] = ((gchar) ((gintptr) (node->data)));
|
sl@0
|
250 |
|
sl@0
|
251 |
string = g_strconcat (*p ? *p : "", c, NULL);
|
sl@0
|
252 |
g_free (*p);
|
sl@0
|
253 |
*p = string;
|
sl@0
|
254 |
|
sl@0
|
255 |
return FALSE;
|
sl@0
|
256 |
}
|
sl@0
|
257 |
|
sl@0
|
258 |
static void
|
sl@0
|
259 |
gnode_test (void)
|
sl@0
|
260 |
{
|
sl@0
|
261 |
#define C2P(c) ((gpointer) ((long) (c)))
|
sl@0
|
262 |
#define P2C(p) ((gchar) ((gintptr) (p)))
|
sl@0
|
263 |
GNode *root;
|
sl@0
|
264 |
GNode *node;
|
sl@0
|
265 |
GNode *node_B;
|
sl@0
|
266 |
GNode *node_F;
|
sl@0
|
267 |
GNode *node_G;
|
sl@0
|
268 |
GNode *node_J;
|
sl@0
|
269 |
guint i;
|
sl@0
|
270 |
gchar *tstring, *cstring;
|
sl@0
|
271 |
|
sl@0
|
272 |
root = g_node_new (C2P ('A'));
|
sl@0
|
273 |
g_assert (g_node_depth (root) == 1 && g_node_max_height (root) == 1);
|
sl@0
|
274 |
|
sl@0
|
275 |
node_B = g_node_new (C2P ('B'));
|
sl@0
|
276 |
g_node_append (root, node_B);
|
sl@0
|
277 |
g_assert (root->children == node_B);
|
sl@0
|
278 |
|
sl@0
|
279 |
g_node_append_data (node_B, C2P ('E'));
|
sl@0
|
280 |
g_node_prepend_data (node_B, C2P ('C'));
|
sl@0
|
281 |
g_node_insert (node_B, 1, g_node_new (C2P ('D')));
|
sl@0
|
282 |
|
sl@0
|
283 |
node_F = g_node_new (C2P ('F'));
|
sl@0
|
284 |
g_node_append (root, node_F);
|
sl@0
|
285 |
g_assert (root->children->next == node_F);
|
sl@0
|
286 |
|
sl@0
|
287 |
node_G = g_node_new (C2P ('G'));
|
sl@0
|
288 |
g_node_append (node_F, node_G);
|
sl@0
|
289 |
node_J = g_node_new (C2P ('J'));
|
sl@0
|
290 |
g_node_prepend (node_G, node_J);
|
sl@0
|
291 |
g_node_insert (node_G, 42, g_node_new (C2P ('K')));
|
sl@0
|
292 |
g_node_insert_data (node_G, 0, C2P ('H'));
|
sl@0
|
293 |
g_node_insert (node_G, 1, g_node_new (C2P ('I')));
|
sl@0
|
294 |
|
sl@0
|
295 |
g_assert (g_node_depth (root) == 1);
|
sl@0
|
296 |
g_assert (g_node_max_height (root) == 4);
|
sl@0
|
297 |
g_assert (g_node_depth (node_G->children->next) == 4);
|
sl@0
|
298 |
g_assert (g_node_n_nodes (root, G_TRAVERSE_LEAFS) == 7);
|
sl@0
|
299 |
g_assert (g_node_n_nodes (root, G_TRAVERSE_NON_LEAFS) == 4);
|
sl@0
|
300 |
g_assert (g_node_n_nodes (root, G_TRAVERSE_ALL) == 11);
|
sl@0
|
301 |
g_assert (g_node_max_height (node_F) == 3);
|
sl@0
|
302 |
g_assert (g_node_n_children (node_G) == 4);
|
sl@0
|
303 |
g_assert (g_node_find_child (root, G_TRAVERSE_ALL, C2P ('F')) == node_F);
|
sl@0
|
304 |
g_assert (g_node_find (root, G_LEVEL_ORDER, G_TRAVERSE_NON_LEAFS, C2P ('I')) == NULL);
|
sl@0
|
305 |
g_assert (g_node_find (root, G_IN_ORDER, G_TRAVERSE_LEAFS, C2P ('J')) == node_J);
|
sl@0
|
306 |
|
sl@0
|
307 |
for (i = 0; i < g_node_n_children (node_B); i++)
|
sl@0
|
308 |
{
|
sl@0
|
309 |
node = g_node_nth_child (node_B, i);
|
sl@0
|
310 |
g_assert (P2C (node->data) == ('C' + i));
|
sl@0
|
311 |
}
|
sl@0
|
312 |
|
sl@0
|
313 |
for (i = 0; i < g_node_n_children (node_G); i++)
|
sl@0
|
314 |
g_assert (g_node_child_position (node_G, g_node_nth_child (node_G, i)) == i);
|
sl@0
|
315 |
|
sl@0
|
316 |
/* we have built: A
|
sl@0
|
317 |
* / \
|
sl@0
|
318 |
* B F
|
sl@0
|
319 |
* / | \ \
|
sl@0
|
320 |
* C D E G
|
sl@0
|
321 |
* / /\ \
|
sl@0
|
322 |
* H I J K
|
sl@0
|
323 |
*
|
sl@0
|
324 |
* for in-order traversal, 'G' is considered to be the "left"
|
sl@0
|
325 |
* child of 'F', which will cause 'F' to be the last node visited.
|
sl@0
|
326 |
*/
|
sl@0
|
327 |
|
sl@0
|
328 |
tstring = NULL;
|
sl@0
|
329 |
g_node_traverse (root, G_PRE_ORDER, G_TRAVERSE_ALL, -1, node_build_string, &tstring);
|
sl@0
|
330 |
g_assert_cmpstr (tstring, ==, "ABCDEFGHIJK");
|
sl@0
|
331 |
g_free (tstring); tstring = NULL;
|
sl@0
|
332 |
g_node_traverse (root, G_POST_ORDER, G_TRAVERSE_ALL, -1, node_build_string, &tstring);
|
sl@0
|
333 |
g_assert_cmpstr (tstring, ==, "CDEBHIJKGFA");
|
sl@0
|
334 |
g_free (tstring); tstring = NULL;
|
sl@0
|
335 |
g_node_traverse (root, G_IN_ORDER, G_TRAVERSE_ALL, -1, node_build_string, &tstring);
|
sl@0
|
336 |
g_assert_cmpstr (tstring, ==, "CBDEAHGIJKF");
|
sl@0
|
337 |
g_free (tstring); tstring = NULL;
|
sl@0
|
338 |
g_node_traverse (root, G_LEVEL_ORDER, G_TRAVERSE_ALL, -1, node_build_string, &tstring);
|
sl@0
|
339 |
g_assert_cmpstr (tstring, ==, "ABFCDEGHIJK");
|
sl@0
|
340 |
g_free (tstring); tstring = NULL;
|
sl@0
|
341 |
|
sl@0
|
342 |
g_node_traverse (root, G_LEVEL_ORDER, G_TRAVERSE_LEAFS, -1, node_build_string, &tstring);
|
sl@0
|
343 |
g_assert_cmpstr (tstring, ==, "CDEHIJK");
|
sl@0
|
344 |
g_free (tstring); tstring = NULL;
|
sl@0
|
345 |
g_node_traverse (root, G_PRE_ORDER, G_TRAVERSE_NON_LEAFS, -1, node_build_string, &tstring);
|
sl@0
|
346 |
g_assert_cmpstr (tstring, ==, "ABFG");
|
sl@0
|
347 |
g_free (tstring); tstring = NULL;
|
sl@0
|
348 |
|
sl@0
|
349 |
g_node_reverse_children (node_B);
|
sl@0
|
350 |
g_node_reverse_children (node_G);
|
sl@0
|
351 |
|
sl@0
|
352 |
g_node_traverse (root, G_LEVEL_ORDER, G_TRAVERSE_ALL, -1, node_build_string, &tstring);
|
sl@0
|
353 |
g_assert_cmpstr (tstring, ==, "ABFEDCGKJIH");
|
sl@0
|
354 |
g_free (tstring); tstring = NULL;
|
sl@0
|
355 |
|
sl@0
|
356 |
cstring = NULL;
|
sl@0
|
357 |
node = g_node_copy (root);
|
sl@0
|
358 |
g_assert (g_node_n_nodes (root, G_TRAVERSE_ALL) == g_node_n_nodes (node, G_TRAVERSE_ALL));
|
sl@0
|
359 |
g_assert (g_node_max_height (root) == g_node_max_height (node));
|
sl@0
|
360 |
g_node_traverse (root, G_IN_ORDER, G_TRAVERSE_ALL, -1, node_build_string, &tstring);
|
sl@0
|
361 |
g_node_traverse (node, G_IN_ORDER, G_TRAVERSE_ALL, -1, node_build_string, &cstring);
|
sl@0
|
362 |
g_assert_cmpstr (tstring, ==, cstring);
|
sl@0
|
363 |
g_free (tstring); tstring = NULL;
|
sl@0
|
364 |
g_free (cstring); cstring = NULL;
|
sl@0
|
365 |
g_node_destroy (node);
|
sl@0
|
366 |
|
sl@0
|
367 |
g_node_destroy (root);
|
sl@0
|
368 |
|
sl@0
|
369 |
/* allocation tests */
|
sl@0
|
370 |
|
sl@0
|
371 |
root = g_node_new (NULL);
|
sl@0
|
372 |
node = root;
|
sl@0
|
373 |
|
sl@0
|
374 |
for (i = 0; i < 2048; i++)
|
sl@0
|
375 |
{
|
sl@0
|
376 |
g_node_append (node, g_node_new (NULL));
|
sl@0
|
377 |
if ((i%5) == 4)
|
sl@0
|
378 |
node = node->children->next;
|
sl@0
|
379 |
}
|
sl@0
|
380 |
g_assert (g_node_max_height (root) > 100);
|
sl@0
|
381 |
g_assert (g_node_n_nodes (root, G_TRAVERSE_ALL) == 1 + 2048);
|
sl@0
|
382 |
|
sl@0
|
383 |
g_node_destroy (root);
|
sl@0
|
384 |
#undef C2P
|
sl@0
|
385 |
#undef P2C
|
sl@0
|
386 |
}
|
sl@0
|
387 |
|
sl@0
|
388 |
static gint
|
sl@0
|
389 |
my_compare (gconstpointer a,
|
sl@0
|
390 |
gconstpointer b)
|
sl@0
|
391 |
{
|
sl@0
|
392 |
const char *cha = a;
|
sl@0
|
393 |
const char *chb = b;
|
sl@0
|
394 |
|
sl@0
|
395 |
return *cha - *chb;
|
sl@0
|
396 |
}
|
sl@0
|
397 |
|
sl@0
|
398 |
static gint
|
sl@0
|
399 |
my_traverse (gpointer key,
|
sl@0
|
400 |
gpointer value,
|
sl@0
|
401 |
gpointer data)
|
sl@0
|
402 |
{
|
sl@0
|
403 |
char *ch = key;
|
sl@0
|
404 |
g_print ("%c ", *ch);
|
sl@0
|
405 |
return FALSE;
|
sl@0
|
406 |
}
|
sl@0
|
407 |
|
sl@0
|
408 |
static void
|
sl@0
|
409 |
binary_tree_test (void)
|
sl@0
|
410 |
{
|
sl@0
|
411 |
GTree *tree;
|
sl@0
|
412 |
char chars[62];
|
sl@0
|
413 |
guint i, j;
|
sl@0
|
414 |
|
sl@0
|
415 |
tree = g_tree_new (my_compare);
|
sl@0
|
416 |
i = 0;
|
sl@0
|
417 |
for (j = 0; j < 10; j++, i++)
|
sl@0
|
418 |
{
|
sl@0
|
419 |
chars[i] = '0' + j;
|
sl@0
|
420 |
g_tree_insert (tree, &chars[i], &chars[i]);
|
sl@0
|
421 |
}
|
sl@0
|
422 |
for (j = 0; j < 26; j++, i++)
|
sl@0
|
423 |
{
|
sl@0
|
424 |
chars[i] = 'A' + j;
|
sl@0
|
425 |
g_tree_insert (tree, &chars[i], &chars[i]);
|
sl@0
|
426 |
}
|
sl@0
|
427 |
for (j = 0; j < 26; j++, i++)
|
sl@0
|
428 |
{
|
sl@0
|
429 |
chars[i] = 'a' + j;
|
sl@0
|
430 |
g_tree_insert (tree, &chars[i], &chars[i]);
|
sl@0
|
431 |
}
|
sl@0
|
432 |
|
sl@0
|
433 |
g_assert_cmpint (g_tree_nnodes (tree), ==, 10 + 26 + 26);
|
sl@0
|
434 |
g_assert_cmpint (g_tree_height (tree), ==, 6);
|
sl@0
|
435 |
|
sl@0
|
436 |
if (g_test_verbose())
|
sl@0
|
437 |
{
|
sl@0
|
438 |
g_print ("tree: ");
|
sl@0
|
439 |
g_tree_foreach (tree, my_traverse, NULL);
|
sl@0
|
440 |
g_print ("\n");
|
sl@0
|
441 |
}
|
sl@0
|
442 |
|
sl@0
|
443 |
for (i = 0; i < 10; i++)
|
sl@0
|
444 |
g_tree_remove (tree, &chars[i]);
|
sl@0
|
445 |
|
sl@0
|
446 |
g_assert_cmpint (g_tree_nnodes (tree), ==, 26 + 26);
|
sl@0
|
447 |
g_assert_cmpint (g_tree_height (tree), ==, 6);
|
sl@0
|
448 |
|
sl@0
|
449 |
if (g_test_verbose())
|
sl@0
|
450 |
{
|
sl@0
|
451 |
g_print ("tree: ");
|
sl@0
|
452 |
g_tree_foreach (tree, my_traverse, NULL);
|
sl@0
|
453 |
g_print ("\n");
|
sl@0
|
454 |
}
|
sl@0
|
455 |
}
|
sl@0
|
456 |
|
sl@0
|
457 |
static gboolean
|
sl@0
|
458 |
my_hash_callback_remove (gpointer key,
|
sl@0
|
459 |
gpointer value,
|
sl@0
|
460 |
gpointer user_data)
|
sl@0
|
461 |
{
|
sl@0
|
462 |
int *d = value;
|
sl@0
|
463 |
|
sl@0
|
464 |
if ((*d) % 2)
|
sl@0
|
465 |
return TRUE;
|
sl@0
|
466 |
|
sl@0
|
467 |
return FALSE;
|
sl@0
|
468 |
}
|
sl@0
|
469 |
|
sl@0
|
470 |
static void
|
sl@0
|
471 |
my_hash_callback_remove_test (gpointer key,
|
sl@0
|
472 |
gpointer value,
|
sl@0
|
473 |
gpointer user_data)
|
sl@0
|
474 |
{
|
sl@0
|
475 |
int *d = value;
|
sl@0
|
476 |
|
sl@0
|
477 |
if ((*d) % 2)
|
sl@0
|
478 |
g_print ("bad!\n");
|
sl@0
|
479 |
}
|
sl@0
|
480 |
|
sl@0
|
481 |
static void
|
sl@0
|
482 |
my_hash_callback (gpointer key,
|
sl@0
|
483 |
gpointer value,
|
sl@0
|
484 |
gpointer user_data)
|
sl@0
|
485 |
{
|
sl@0
|
486 |
int *d = value;
|
sl@0
|
487 |
*d = 1;
|
sl@0
|
488 |
}
|
sl@0
|
489 |
|
sl@0
|
490 |
static guint
|
sl@0
|
491 |
my_hash (gconstpointer key)
|
sl@0
|
492 |
{
|
sl@0
|
493 |
return (guint) *((const gint*) key);
|
sl@0
|
494 |
}
|
sl@0
|
495 |
|
sl@0
|
496 |
static gboolean
|
sl@0
|
497 |
my_hash_equal (gconstpointer a,
|
sl@0
|
498 |
gconstpointer b)
|
sl@0
|
499 |
{
|
sl@0
|
500 |
return *((const gint*) a) == *((const gint*) b);
|
sl@0
|
501 |
}
|
sl@0
|
502 |
|
sl@0
|
503 |
static gboolean
|
sl@0
|
504 |
find_first_that(gpointer key,
|
sl@0
|
505 |
gpointer value,
|
sl@0
|
506 |
gpointer user_data)
|
sl@0
|
507 |
{
|
sl@0
|
508 |
gint *v = value;
|
sl@0
|
509 |
gint *test = user_data;
|
sl@0
|
510 |
return (*v == *test);
|
sl@0
|
511 |
}
|
sl@0
|
512 |
|
sl@0
|
513 |
static void
|
sl@0
|
514 |
test_g_parse_debug_string (void)
|
sl@0
|
515 |
{
|
sl@0
|
516 |
GDebugKey keys[3] = {
|
sl@0
|
517 |
{ "foo", 1 },
|
sl@0
|
518 |
{ "bar", 2 },
|
sl@0
|
519 |
{ "baz", 4 }
|
sl@0
|
520 |
};
|
sl@0
|
521 |
guint n_keys = 3;
|
sl@0
|
522 |
guint result;
|
sl@0
|
523 |
|
sl@0
|
524 |
result = g_parse_debug_string ("bar:foo:blubb", keys, n_keys);
|
sl@0
|
525 |
g_assert (result == 3);
|
sl@0
|
526 |
|
sl@0
|
527 |
result = g_parse_debug_string (":baz::_E@~!_::", keys, n_keys);
|
sl@0
|
528 |
g_assert (result == 4);
|
sl@0
|
529 |
|
sl@0
|
530 |
result = g_parse_debug_string ("", keys, n_keys);
|
sl@0
|
531 |
g_assert (result == 0);
|
sl@0
|
532 |
|
sl@0
|
533 |
result = g_parse_debug_string (" : ", keys, n_keys);
|
sl@0
|
534 |
g_assert (result == 0);
|
sl@0
|
535 |
}
|
sl@0
|
536 |
|
sl@0
|
537 |
static void
|
sl@0
|
538 |
log_warning_error_tests (void)
|
sl@0
|
539 |
{
|
sl@0
|
540 |
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR))
|
sl@0
|
541 |
{
|
sl@0
|
542 |
g_message ("this is a g_message test.");
|
sl@0
|
543 |
g_message ("non-printable UTF-8: \"\xc3\xa4\xda\x85\"");
|
sl@0
|
544 |
g_message ("unsafe chars: \"\x10\x11\x12\n\t\x7f\x81\x82\x83\"");
|
sl@0
|
545 |
exit (0);
|
sl@0
|
546 |
}
|
sl@0
|
547 |
g_test_trap_assert_passed();
|
sl@0
|
548 |
g_test_trap_assert_stderr ("*is a g_message test*");
|
sl@0
|
549 |
g_test_trap_assert_stderr ("*non-printable UTF-8*");
|
sl@0
|
550 |
g_test_trap_assert_stderr ("*unsafe chars*");
|
sl@0
|
551 |
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR))
|
sl@0
|
552 |
{
|
sl@0
|
553 |
g_warning ("harmless warning with parameters: %d %s %#x", 42, "Boo", 12345);
|
sl@0
|
554 |
exit (0);
|
sl@0
|
555 |
}
|
sl@0
|
556 |
g_test_trap_assert_failed(); /* we have fatal-warnings enabled */
|
sl@0
|
557 |
g_test_trap_assert_stderr ("*harmless warning*");
|
sl@0
|
558 |
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR))
|
sl@0
|
559 |
{
|
sl@0
|
560 |
g_print (NULL);
|
sl@0
|
561 |
exit (0);
|
sl@0
|
562 |
}
|
sl@0
|
563 |
g_test_trap_assert_failed(); /* we have fatal-warnings enabled */
|
sl@0
|
564 |
g_test_trap_assert_stderr ("*g_print*assertion*failed*");
|
sl@0
|
565 |
g_test_trap_assert_stderr ("*NULL*");
|
sl@0
|
566 |
}
|
sl@0
|
567 |
|
sl@0
|
568 |
static void
|
sl@0
|
569 |
timer_tests (void)
|
sl@0
|
570 |
{
|
sl@0
|
571 |
GTimer *timer, *timer2;
|
sl@0
|
572 |
gdouble elapsed;
|
sl@0
|
573 |
|
sl@0
|
574 |
/* basic testing */
|
sl@0
|
575 |
timer = g_timer_new ();
|
sl@0
|
576 |
g_timer_start (timer);
|
sl@0
|
577 |
elapsed = g_timer_elapsed (timer, NULL);
|
sl@0
|
578 |
g_timer_stop (timer);
|
sl@0
|
579 |
g_assert_cmpfloat (elapsed, <=, g_timer_elapsed (timer, NULL));
|
sl@0
|
580 |
g_timer_destroy (timer);
|
sl@0
|
581 |
|
sl@0
|
582 |
if (g_test_slow())
|
sl@0
|
583 |
{
|
sl@0
|
584 |
if (g_test_verbose())
|
sl@0
|
585 |
g_print ("checking timers...\n");
|
sl@0
|
586 |
timer = g_timer_new ();
|
sl@0
|
587 |
if (g_test_verbose())
|
sl@0
|
588 |
g_print (" spinning for 3 seconds...\n");
|
sl@0
|
589 |
g_timer_start (timer);
|
sl@0
|
590 |
while (g_timer_elapsed (timer, NULL) < 3)
|
sl@0
|
591 |
;
|
sl@0
|
592 |
g_timer_stop (timer);
|
sl@0
|
593 |
g_timer_destroy (timer);
|
sl@0
|
594 |
if (g_test_verbose())
|
sl@0
|
595 |
g_print ("ok\n");
|
sl@0
|
596 |
}
|
sl@0
|
597 |
|
sl@0
|
598 |
if (g_test_slow())
|
sl@0
|
599 |
{
|
sl@0
|
600 |
gulong elapsed_usecs;
|
sl@0
|
601 |
if (g_test_verbose())
|
sl@0
|
602 |
g_print ("checking g_timer_continue...\n");
|
sl@0
|
603 |
timer2 = g_timer_new ();
|
sl@0
|
604 |
if (g_test_verbose())
|
sl@0
|
605 |
g_print ("\trun for 1 second...\n");
|
sl@0
|
606 |
timer = g_timer_new();
|
sl@0
|
607 |
g_usleep (G_USEC_PER_SEC); /* run timer for 1 second */
|
sl@0
|
608 |
g_timer_stop (timer);
|
sl@0
|
609 |
if (g_test_verbose())
|
sl@0
|
610 |
g_print ("\tstop for 1 second...\n");
|
sl@0
|
611 |
g_usleep (G_USEC_PER_SEC); /* wait for 1 second */
|
sl@0
|
612 |
if (g_test_verbose())
|
sl@0
|
613 |
g_print ("\trun for 2 seconds...\n");
|
sl@0
|
614 |
g_timer_continue (timer);
|
sl@0
|
615 |
g_usleep (2 * G_USEC_PER_SEC); /* run timer for 2 seconds */
|
sl@0
|
616 |
g_timer_stop(timer);
|
sl@0
|
617 |
if (g_test_verbose())
|
sl@0
|
618 |
g_print ("\tstop for 1.5 seconds...\n");
|
sl@0
|
619 |
g_usleep ((3 * G_USEC_PER_SEC) / 2); /* wait for 1.5 seconds */
|
sl@0
|
620 |
if (g_test_verbose())
|
sl@0
|
621 |
g_print ("\trun for 0.2 seconds...\n");
|
sl@0
|
622 |
g_timer_continue (timer);
|
sl@0
|
623 |
g_usleep (G_USEC_PER_SEC / 5); /* run timer for 0.2 seconds */
|
sl@0
|
624 |
g_timer_stop (timer);
|
sl@0
|
625 |
if (g_test_verbose())
|
sl@0
|
626 |
g_print ("\tstop for 4 seconds...\n");
|
sl@0
|
627 |
g_usleep (4 * G_USEC_PER_SEC); /* wait for 4 seconds */
|
sl@0
|
628 |
if (g_test_verbose())
|
sl@0
|
629 |
g_print ("\trun for 5.8 seconds...\n");
|
sl@0
|
630 |
g_timer_continue (timer);
|
sl@0
|
631 |
g_usleep ((29 * G_USEC_PER_SEC) / 5); /* run timer for 5.8 seconds */
|
sl@0
|
632 |
g_timer_stop(timer);
|
sl@0
|
633 |
elapsed = g_timer_elapsed (timer, &elapsed_usecs);
|
sl@0
|
634 |
if (g_test_verbose())
|
sl@0
|
635 |
g_print ("\t=> timer = %.6f = %d.%06ld (should be: 9.000000) (%.6f off)\n", elapsed, (int) elapsed, elapsed_usecs, ABS (elapsed - 9.));
|
sl@0
|
636 |
g_assert_cmpfloat (elapsed, >, 8.8);
|
sl@0
|
637 |
g_assert_cmpfloat (elapsed, <, 9.2);
|
sl@0
|
638 |
if (g_test_verbose())
|
sl@0
|
639 |
g_print ("g_timer_continue ... ok\n\n");
|
sl@0
|
640 |
g_timer_stop (timer2);
|
sl@0
|
641 |
elapsed = g_timer_elapsed (timer2, &elapsed_usecs);
|
sl@0
|
642 |
if (g_test_verbose())
|
sl@0
|
643 |
g_print ("\t=> timer2 = %.6f = %d.%06ld (should be: %.6f) (%.6f off)\n\n", elapsed, (int) elapsed, elapsed_usecs, 9.+6.5, ABS (elapsed - (9.+6.5)));
|
sl@0
|
644 |
g_assert_cmpfloat (elapsed, >, 8.8 + 6.5);
|
sl@0
|
645 |
g_assert_cmpfloat (elapsed, <, 9.2 + 6.5);
|
sl@0
|
646 |
if (g_test_verbose())
|
sl@0
|
647 |
g_print ("timer2 ... ok\n\n");
|
sl@0
|
648 |
g_timer_destroy (timer);
|
sl@0
|
649 |
g_timer_destroy (timer2);
|
sl@0
|
650 |
}
|
sl@0
|
651 |
}
|
sl@0
|
652 |
|
sl@0
|
653 |
static void
|
sl@0
|
654 |
type_sizes (void)
|
sl@0
|
655 |
{
|
sl@0
|
656 |
guint16 gu16t1 = 0x44afU, gu16t2 = 0xaf44U;
|
sl@0
|
657 |
guint32 gu32t1 = 0x02a7f109U, gu32t2 = 0x09f1a702U;
|
sl@0
|
658 |
guint64 gu64t1 = G_GINT64_CONSTANT(0x1d636b02300a7aa7U),
|
sl@0
|
659 |
gu64t2 = G_GINT64_CONSTANT(0xa77a0a30026b631dU);
|
sl@0
|
660 |
/* type sizes */
|
sl@0
|
661 |
g_assert_cmpint (sizeof (gint8), ==, 1);
|
sl@0
|
662 |
g_assert_cmpint (sizeof (gint16), ==, 2);
|
sl@0
|
663 |
g_assert_cmpint (sizeof (gint32), ==, 4);
|
sl@0
|
664 |
g_assert_cmpint (sizeof (gint64), ==, 8);
|
sl@0
|
665 |
/* endian macros */
|
sl@0
|
666 |
if (g_test_verbose())
|
sl@0
|
667 |
g_print ("checking endian macros (host is %s)...\n",
|
sl@0
|
668 |
G_BYTE_ORDER == G_BIG_ENDIAN ? "big endian" : "little endian");
|
sl@0
|
669 |
g_assert (GUINT16_SWAP_LE_BE (gu16t1) == gu16t2);
|
sl@0
|
670 |
g_assert (GUINT32_SWAP_LE_BE (gu32t1) == gu32t2);
|
sl@0
|
671 |
g_assert (GUINT64_SWAP_LE_BE (gu64t1) == gu64t2);
|
sl@0
|
672 |
}
|
sl@0
|
673 |
|
sl@0
|
674 |
static void
|
sl@0
|
675 |
test_info (void)
|
sl@0
|
676 |
{
|
sl@0
|
677 |
const gchar *un, *rn, *hn;
|
sl@0
|
678 |
const gchar *tmpdir, *homedir, *userdatadir, *uconfdir, *ucachedir;
|
sl@0
|
679 |
const gchar *uddesktop, *udddocs, *uddpubshare;
|
sl@0
|
680 |
gchar **sv, *cwd, *sdatadirs, *sconfdirs, *langnames;
|
sl@0
|
681 |
if (g_test_verbose())
|
sl@0
|
682 |
g_print ("TestGLib v%u.%u.%u (i:%u b:%u)\n",
|
sl@0
|
683 |
glib_major_version,
|
sl@0
|
684 |
glib_minor_version,
|
sl@0
|
685 |
glib_micro_version,
|
sl@0
|
686 |
glib_interface_age,
|
sl@0
|
687 |
glib_binary_age);
|
sl@0
|
688 |
|
sl@0
|
689 |
cwd = g_get_current_dir ();
|
sl@0
|
690 |
un = g_get_user_name();
|
sl@0
|
691 |
rn = g_get_real_name();
|
sl@0
|
692 |
hn = g_get_host_name();
|
sl@0
|
693 |
if (g_test_verbose())
|
sl@0
|
694 |
{
|
sl@0
|
695 |
g_print ("cwd: %s\n", cwd);
|
sl@0
|
696 |
g_print ("user: %s\n", un);
|
sl@0
|
697 |
g_print ("real: %s\n", rn);
|
sl@0
|
698 |
g_print ("host: %s\n", hn);
|
sl@0
|
699 |
}
|
sl@0
|
700 |
g_free (cwd);
|
sl@0
|
701 |
|
sl@0
|
702 |
tmpdir = g_get_tmp_dir();
|
sl@0
|
703 |
g_assert (tmpdir != NULL);
|
sl@0
|
704 |
homedir = g_get_home_dir ();
|
sl@0
|
705 |
g_assert (homedir != NULL);
|
sl@0
|
706 |
userdatadir = g_get_user_data_dir ();
|
sl@0
|
707 |
g_assert (userdatadir != NULL);
|
sl@0
|
708 |
uconfdir = g_get_user_config_dir ();
|
sl@0
|
709 |
g_assert (uconfdir != NULL);
|
sl@0
|
710 |
ucachedir = g_get_user_cache_dir ();
|
sl@0
|
711 |
g_assert (ucachedir != NULL);
|
sl@0
|
712 |
|
sl@0
|
713 |
uddesktop = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
|
sl@0
|
714 |
g_assert (uddesktop != NULL);
|
sl@0
|
715 |
udddocs = g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS);
|
sl@0
|
716 |
uddpubshare = g_get_user_special_dir (G_USER_DIRECTORY_PUBLIC_SHARE);
|
sl@0
|
717 |
|
sl@0
|
718 |
sv = (gchar **) g_get_system_data_dirs ();
|
sl@0
|
719 |
sdatadirs = g_strjoinv (G_SEARCHPATH_SEPARATOR_S, sv);
|
sl@0
|
720 |
sv = (gchar **) g_get_system_config_dirs ();
|
sl@0
|
721 |
sconfdirs = g_strjoinv (G_SEARCHPATH_SEPARATOR_S, sv);
|
sl@0
|
722 |
sv = (gchar **) g_get_language_names ();
|
sl@0
|
723 |
langnames = g_strjoinv (":", sv);
|
sl@0
|
724 |
|
sl@0
|
725 |
if (g_test_verbose())
|
sl@0
|
726 |
{
|
sl@0
|
727 |
g_print ("tmp-dir: %s\n", tmpdir);
|
sl@0
|
728 |
g_print ("home: %s\n", homedir);
|
sl@0
|
729 |
g_print ("user_data: %s\n", userdatadir);
|
sl@0
|
730 |
g_print ("user_config: %s\n", uconfdir);
|
sl@0
|
731 |
g_print ("user_cache: %s\n", ucachedir);
|
sl@0
|
732 |
g_print ("system_data: %s\n", sdatadirs);
|
sl@0
|
733 |
g_print ("system_config: %s\n", sconfdirs);
|
sl@0
|
734 |
g_print ("languages: %s\n", langnames);
|
sl@0
|
735 |
g_print ("user_special[DESKTOP]: %s\n", uddesktop);
|
sl@0
|
736 |
g_print ("user_special[DOCUMENTS]: %s\n", udddocs);
|
sl@0
|
737 |
g_print ("user_special[PUBLIC_SHARE]: %s\n", uddpubshare);
|
sl@0
|
738 |
}
|
sl@0
|
739 |
g_free (sdatadirs);
|
sl@0
|
740 |
g_free (sconfdirs);
|
sl@0
|
741 |
g_free (langnames);
|
sl@0
|
742 |
|
sl@0
|
743 |
if (g_test_verbose())
|
sl@0
|
744 |
{
|
sl@0
|
745 |
#ifdef G_PLATFORM_WIN32
|
sl@0
|
746 |
gchar *glib_dll;
|
sl@0
|
747 |
#endif
|
sl@0
|
748 |
const gchar *charset;
|
sl@0
|
749 |
if (g_get_charset ((G_CONST_RETURN char**)&charset))
|
sl@0
|
750 |
g_print ("current charset is UTF-8: %s\n", charset);
|
sl@0
|
751 |
else
|
sl@0
|
752 |
g_print ("current charset is not UTF-8: %s\n", charset);
|
sl@0
|
753 |
|
sl@0
|
754 |
#ifdef G_PLATFORM_WIN32
|
sl@0
|
755 |
#ifdef G_OS_WIN32
|
sl@0
|
756 |
/* Can't calculate GLib DLL name at runtime. */
|
sl@0
|
757 |
glib_dll = "libglib-2.0-0.dll";
|
sl@0
|
758 |
#endif
|
sl@0
|
759 |
#ifdef G_WITH_CYGWIN
|
sl@0
|
760 |
glib_dll = "cygglib-2.0-0.dll";
|
sl@0
|
761 |
#endif
|
sl@0
|
762 |
|
sl@0
|
763 |
g_print ("current locale: %s\n", g_win32_getlocale ());
|
sl@0
|
764 |
g_print ("GLib DLL name tested for: %s\n", glib_dll);
|
sl@0
|
765 |
|
sl@0
|
766 |
g_print ("GLib installation directory, from Registry entry for %s if available: %s\n",
|
sl@0
|
767 |
GETTEXT_PACKAGE,
|
sl@0
|
768 |
g_win32_get_package_installation_directory (GETTEXT_PACKAGE, NULL));
|
sl@0
|
769 |
g_print ("Ditto, or from GLib DLL name: %s\n",
|
sl@0
|
770 |
g_win32_get_package_installation_directory (GETTEXT_PACKAGE, glib_dll));
|
sl@0
|
771 |
g_print ("Ditto, only from GLib DLL name: %s\n",
|
sl@0
|
772 |
g_win32_get_package_installation_directory (NULL, glib_dll));
|
sl@0
|
773 |
g_print ("locale subdirectory of GLib installation directory: %s\n",
|
sl@0
|
774 |
g_win32_get_package_installation_subdirectory (NULL, glib_dll, "lib\\locale"));
|
sl@0
|
775 |
g_print ("GTK+ 2.0 installation directory, if available: %s\n",
|
sl@0
|
776 |
g_win32_get_package_installation_directory ("gtk20", NULL));
|
sl@0
|
777 |
|
sl@0
|
778 |
g_print ("found more.com as %s\n", g_find_program_in_path ("more.com"));
|
sl@0
|
779 |
g_print ("found regedit as %s\n", g_find_program_in_path ("regedit"));
|
sl@0
|
780 |
|
sl@0
|
781 |
g_print ("a Win32 error message: %s\n", g_win32_error_message (2));
|
sl@0
|
782 |
#endif
|
sl@0
|
783 |
}
|
sl@0
|
784 |
}
|
sl@0
|
785 |
|
sl@0
|
786 |
static void
|
sl@0
|
787 |
test_paths (void)
|
sl@0
|
788 |
{
|
sl@0
|
789 |
struct {
|
sl@0
|
790 |
gchar *filename;
|
sl@0
|
791 |
gchar *dirname;
|
sl@0
|
792 |
} dirname_checks[] = {
|
sl@0
|
793 |
{ "/", "/" },
|
sl@0
|
794 |
{ "////", "/" },
|
sl@0
|
795 |
{ ".////", "." },
|
sl@0
|
796 |
{ "../", ".." },
|
sl@0
|
797 |
{ "..////", ".." },
|
sl@0
|
798 |
{ "a/b", "a" },
|
sl@0
|
799 |
{ "a/b/", "a/b" },
|
sl@0
|
800 |
{ "c///", "c" },
|
sl@0
|
801 |
#ifdef G_OS_WIN32
|
sl@0
|
802 |
{ "\\", "\\" },
|
sl@0
|
803 |
{ ".\\\\\\\\", "." },
|
sl@0
|
804 |
{ "..\\", ".." },
|
sl@0
|
805 |
{ "..\\\\\\\\", ".." },
|
sl@0
|
806 |
{ "a\\b", "a" },
|
sl@0
|
807 |
{ "a\\b/", "a\\b" },
|
sl@0
|
808 |
{ "a/b\\", "a/b" },
|
sl@0
|
809 |
{ "c\\\\/", "c" },
|
sl@0
|
810 |
{ "//\\", "/" },
|
sl@0
|
811 |
#endif
|
sl@0
|
812 |
#ifdef G_WITH_CYGWIN
|
sl@0
|
813 |
{ "//server/share///x", "//server/share" },
|
sl@0
|
814 |
#endif
|
sl@0
|
815 |
{ ".", "." },
|
sl@0
|
816 |
{ "..", "." },
|
sl@0
|
817 |
{ "", "." },
|
sl@0
|
818 |
};
|
sl@0
|
819 |
const guint n_dirname_checks = G_N_ELEMENTS (dirname_checks);
|
sl@0
|
820 |
struct {
|
sl@0
|
821 |
gchar *filename;
|
sl@0
|
822 |
gchar *without_root;
|
sl@0
|
823 |
} skip_root_checks[] = {
|
sl@0
|
824 |
{ "/", "" },
|
sl@0
|
825 |
{ "//", "" },
|
sl@0
|
826 |
{ "/foo", "foo" },
|
sl@0
|
827 |
{ "//foo", "foo" },
|
sl@0
|
828 |
{ "a/b", NULL },
|
sl@0
|
829 |
#ifdef G_OS_WIN32
|
sl@0
|
830 |
{ "\\", "" },
|
sl@0
|
831 |
{ "\\foo", "foo" },
|
sl@0
|
832 |
{ "\\\\server\\foo", "" },
|
sl@0
|
833 |
{ "\\\\server\\foo\\bar", "bar" },
|
sl@0
|
834 |
{ "a\\b", NULL },
|
sl@0
|
835 |
#endif
|
sl@0
|
836 |
#ifdef G_WITH_CYGWIN
|
sl@0
|
837 |
{ "//server/share///x", "//x" },
|
sl@0
|
838 |
#endif
|
sl@0
|
839 |
{ ".", NULL },
|
sl@0
|
840 |
{ "", NULL },
|
sl@0
|
841 |
};
|
sl@0
|
842 |
const guint n_skip_root_checks = G_N_ELEMENTS (skip_root_checks);
|
sl@0
|
843 |
gchar *string;
|
sl@0
|
844 |
guint i;
|
sl@0
|
845 |
if (g_test_verbose())
|
sl@0
|
846 |
g_print ("checking g_path_get_basename()...");
|
sl@0
|
847 |
string = g_path_get_basename (G_DIR_SEPARATOR_S "foo" G_DIR_SEPARATOR_S "dir" G_DIR_SEPARATOR_S);
|
sl@0
|
848 |
g_assert (strcmp (string, "dir") == 0);
|
sl@0
|
849 |
g_free (string);
|
sl@0
|
850 |
string = g_path_get_basename (G_DIR_SEPARATOR_S "foo" G_DIR_SEPARATOR_S "file");
|
sl@0
|
851 |
g_assert (strcmp (string, "file") == 0);
|
sl@0
|
852 |
g_free (string);
|
sl@0
|
853 |
if (g_test_verbose())
|
sl@0
|
854 |
g_print ("ok\n");
|
sl@0
|
855 |
|
sl@0
|
856 |
#ifdef G_OS_WIN32
|
sl@0
|
857 |
string = g_path_get_basename ("/foo/dir/");
|
sl@0
|
858 |
g_assert (strcmp (string, "dir") == 0);
|
sl@0
|
859 |
g_free (string);
|
sl@0
|
860 |
string = g_path_get_basename ("/foo/file");
|
sl@0
|
861 |
g_assert (strcmp (string, "file") == 0);
|
sl@0
|
862 |
g_free (string);
|
sl@0
|
863 |
#endif
|
sl@0
|
864 |
|
sl@0
|
865 |
if (g_test_verbose())
|
sl@0
|
866 |
g_print ("checking g_path_get_dirname()...");
|
sl@0
|
867 |
for (i = 0; i < n_dirname_checks; i++)
|
sl@0
|
868 |
{
|
sl@0
|
869 |
gchar *dirname = g_path_get_dirname (dirname_checks[i].filename);
|
sl@0
|
870 |
if (strcmp (dirname, dirname_checks[i].dirname) != 0)
|
sl@0
|
871 |
{
|
sl@0
|
872 |
g_error ("\nfailed for \"%s\"==\"%s\" (returned: \"%s\")\n",
|
sl@0
|
873 |
dirname_checks[i].filename,
|
sl@0
|
874 |
dirname_checks[i].dirname,
|
sl@0
|
875 |
dirname);
|
sl@0
|
876 |
}
|
sl@0
|
877 |
g_free (dirname);
|
sl@0
|
878 |
}
|
sl@0
|
879 |
if (g_test_verbose())
|
sl@0
|
880 |
g_print ("ok\n");
|
sl@0
|
881 |
|
sl@0
|
882 |
if (g_test_verbose())
|
sl@0
|
883 |
g_print ("checking g_path_skip_root()...");
|
sl@0
|
884 |
for (i = 0; i < n_skip_root_checks; i++)
|
sl@0
|
885 |
{
|
sl@0
|
886 |
const gchar *skipped = g_path_skip_root (skip_root_checks[i].filename);
|
sl@0
|
887 |
if ((skipped && !skip_root_checks[i].without_root) ||
|
sl@0
|
888 |
(!skipped && skip_root_checks[i].without_root) ||
|
sl@0
|
889 |
((skipped && skip_root_checks[i].without_root) &&
|
sl@0
|
890 |
strcmp (skipped, skip_root_checks[i].without_root)))
|
sl@0
|
891 |
{
|
sl@0
|
892 |
g_error ("\nfailed for \"%s\"==\"%s\" (returned: \"%s\")\n",
|
sl@0
|
893 |
skip_root_checks[i].filename,
|
sl@0
|
894 |
(skip_root_checks[i].without_root ?
|
sl@0
|
895 |
skip_root_checks[i].without_root : "<NULL>"),
|
sl@0
|
896 |
(skipped ? skipped : "<NULL>"));
|
sl@0
|
897 |
}
|
sl@0
|
898 |
}
|
sl@0
|
899 |
if (g_test_verbose())
|
sl@0
|
900 |
g_print ("ok\n");
|
sl@0
|
901 |
}
|
sl@0
|
902 |
|
sl@0
|
903 |
static void
|
sl@0
|
904 |
test_file_functions (void)
|
sl@0
|
905 |
{
|
sl@0
|
906 |
const char hello[] = "Hello, World";
|
sl@0
|
907 |
const int hellolen = sizeof (hello) - 1;
|
sl@0
|
908 |
GError *error;
|
sl@0
|
909 |
char template[32];
|
sl@0
|
910 |
char *name_used, chars[62];
|
sl@0
|
911 |
gint fd, n;
|
sl@0
|
912 |
|
sl@0
|
913 |
strcpy (template, "c:\\foobar");
|
sl@0
|
914 |
fd = g_mkstemp (template);
|
sl@0
|
915 |
if (g_test_verbose() && fd != -1)
|
sl@0
|
916 |
g_print ("g_mkstemp works even if template doesn't end in XXXXXX\n");
|
sl@0
|
917 |
close (fd);
|
sl@0
|
918 |
strcpy (template, "c:\\fooXXXXXX");
|
sl@0
|
919 |
fd = g_mkstemp (template);
|
sl@0
|
920 |
if (fd == -1)
|
sl@0
|
921 |
g_error ("g_mkstemp didn't work for template %s\n", template);
|
sl@0
|
922 |
n = write (fd, hello, hellolen);
|
sl@0
|
923 |
if (n == -1)
|
sl@0
|
924 |
g_error ("write() failed: %s\n", g_strerror (errno));
|
sl@0
|
925 |
else if (n != hellolen)
|
sl@0
|
926 |
g_error ("write() should have written %d bytes, wrote %d\n", hellolen, n);
|
sl@0
|
927 |
|
sl@0
|
928 |
lseek (fd, 0, 0);
|
sl@0
|
929 |
n = read (fd, chars, sizeof (chars));
|
sl@0
|
930 |
if (n == -1)
|
sl@0
|
931 |
g_error ("read() failed: %s\n", g_strerror (errno));
|
sl@0
|
932 |
else if (n != hellolen)
|
sl@0
|
933 |
g_error ("read() should have read %d bytes, got %d\n", hellolen, n);
|
sl@0
|
934 |
|
sl@0
|
935 |
chars[n] = 0;
|
sl@0
|
936 |
if (strcmp (chars, hello) != 0)
|
sl@0
|
937 |
g_error ("wrote '%s', but got '%s'\n", hello, chars);
|
sl@0
|
938 |
|
sl@0
|
939 |
close (fd);
|
sl@0
|
940 |
remove (template);
|
sl@0
|
941 |
|
sl@0
|
942 |
error = NULL;
|
sl@0
|
943 |
strcpy (template, "zap" G_DIR_SEPARATOR_S "barXXXXXX");
|
sl@0
|
944 |
fd = g_file_open_tmp (template, &name_used, &error);
|
sl@0
|
945 |
if (g_test_verbose())
|
sl@0
|
946 |
{
|
sl@0
|
947 |
if (fd != -1)
|
sl@0
|
948 |
g_print ("g_file_open_tmp works even if template contains '%s'\n", G_DIR_SEPARATOR_S);
|
sl@0
|
949 |
else
|
sl@0
|
950 |
g_print ("g_file_open_tmp correctly returns error: %s\n", error->message);
|
sl@0
|
951 |
}
|
sl@0
|
952 |
close (fd);
|
sl@0
|
953 |
g_clear_error (&error);
|
sl@0
|
954 |
|
sl@0
|
955 |
#ifdef G_OS_WIN32
|
sl@0
|
956 |
strcpy (template, "zap/barXXXXXX");
|
sl@0
|
957 |
fd = g_file_open_tmp (template, &name_used, &error);
|
sl@0
|
958 |
if (g_test_verbose())
|
sl@0
|
959 |
{
|
sl@0
|
960 |
if (fd != -1)
|
sl@0
|
961 |
g_print ("g_file_open_tmp works even if template contains '/'\n");
|
sl@0
|
962 |
else
|
sl@0
|
963 |
g_print ("g_file_open_tmp correctly returns error: %s\n", error->message);
|
sl@0
|
964 |
}
|
sl@0
|
965 |
close (fd);
|
sl@0
|
966 |
g_clear_error (&error);
|
sl@0
|
967 |
#endif
|
sl@0
|
968 |
|
sl@0
|
969 |
strcpy (template, "zapXXXXXX");
|
sl@0
|
970 |
fd = g_file_open_tmp (template, &name_used, &error);
|
sl@0
|
971 |
if (fd == -1)
|
sl@0
|
972 |
g_error ("g_file_open_tmp didn't work for template '%s': %s\n", template, error->message);
|
sl@0
|
973 |
else if (g_test_verbose())
|
sl@0
|
974 |
g_print ("g_file_open_tmp for template '%s' used name '%s'\n", template, name_used);
|
sl@0
|
975 |
close (fd);
|
sl@0
|
976 |
g_clear_error (&error);
|
sl@0
|
977 |
remove (name_used);
|
sl@0
|
978 |
|
sl@0
|
979 |
fd = g_file_open_tmp (NULL, &name_used, &error);
|
sl@0
|
980 |
if (fd == -1)
|
sl@0
|
981 |
g_error ("g_file_open_tmp didn't work for a NULL template: %s\n", error->message);
|
sl@0
|
982 |
close (fd);
|
sl@0
|
983 |
g_clear_error (&error);
|
sl@0
|
984 |
remove (name_used);
|
sl@0
|
985 |
}
|
sl@0
|
986 |
|
sl@0
|
987 |
static void
|
sl@0
|
988 |
test_arrays (void)
|
sl@0
|
989 |
{
|
sl@0
|
990 |
GByteArray *gbarray;
|
sl@0
|
991 |
GPtrArray *gparray;
|
sl@0
|
992 |
GArray *garray;
|
sl@0
|
993 |
guint i;
|
sl@0
|
994 |
|
sl@0
|
995 |
gparray = g_ptr_array_new ();
|
sl@0
|
996 |
for (i = 0; i < 10000; i++)
|
sl@0
|
997 |
g_ptr_array_add (gparray, GINT_TO_POINTER (i));
|
sl@0
|
998 |
for (i = 0; i < 10000; i++)
|
sl@0
|
999 |
if (g_ptr_array_index (gparray, i) != GINT_TO_POINTER (i))
|
sl@0
|
1000 |
g_error ("array fails: %p ( %p )\n", g_ptr_array_index (gparray, i), GINT_TO_POINTER (i));
|
sl@0
|
1001 |
g_ptr_array_free (gparray, TRUE);
|
sl@0
|
1002 |
|
sl@0
|
1003 |
gbarray = g_byte_array_new ();
|
sl@0
|
1004 |
for (i = 0; i < 10000; i++)
|
sl@0
|
1005 |
g_byte_array_append (gbarray, (guint8*) "abcd", 4);
|
sl@0
|
1006 |
for (i = 0; i < 10000; i++)
|
sl@0
|
1007 |
{
|
sl@0
|
1008 |
g_assert (gbarray->data[4*i] == 'a');
|
sl@0
|
1009 |
g_assert (gbarray->data[4*i+1] == 'b');
|
sl@0
|
1010 |
g_assert (gbarray->data[4*i+2] == 'c');
|
sl@0
|
1011 |
g_assert (gbarray->data[4*i+3] == 'd');
|
sl@0
|
1012 |
}
|
sl@0
|
1013 |
g_byte_array_free (gbarray, TRUE);
|
sl@0
|
1014 |
|
sl@0
|
1015 |
garray = g_array_new (FALSE, FALSE, sizeof (gint));
|
sl@0
|
1016 |
for (i = 0; i < 10000; i++)
|
sl@0
|
1017 |
g_array_append_val (garray, i);
|
sl@0
|
1018 |
for (i = 0; i < 10000; i++)
|
sl@0
|
1019 |
if (g_array_index (garray, gint, i) != i)
|
sl@0
|
1020 |
g_error ("failure: %d ( %d )\n", g_array_index (garray, gint, i), i);
|
sl@0
|
1021 |
g_array_free (garray, TRUE);
|
sl@0
|
1022 |
|
sl@0
|
1023 |
garray = g_array_new (FALSE, FALSE, sizeof (gint));
|
sl@0
|
1024 |
for (i = 0; i < 100; i++)
|
sl@0
|
1025 |
g_array_prepend_val (garray, i);
|
sl@0
|
1026 |
for (i = 0; i < 100; i++)
|
sl@0
|
1027 |
if (g_array_index (garray, gint, i) != (100 - i - 1))
|
sl@0
|
1028 |
g_error ("failure: %d ( %d )\n", g_array_index (garray, gint, i), 100 - i - 1);
|
sl@0
|
1029 |
g_array_free (garray, TRUE);
|
sl@0
|
1030 |
}
|
sl@0
|
1031 |
|
sl@0
|
1032 |
static void
|
sl@0
|
1033 |
hash_table_tests (void)
|
sl@0
|
1034 |
{
|
sl@0
|
1035 |
GHashTable *hash_table;
|
sl@0
|
1036 |
int array[10000];
|
sl@0
|
1037 |
gint *pvalue = NULL;
|
sl@0
|
1038 |
gint value = 120;
|
sl@0
|
1039 |
guint i;
|
sl@0
|
1040 |
|
sl@0
|
1041 |
hash_table = g_hash_table_new (my_hash, my_hash_equal);
|
sl@0
|
1042 |
for (i = 0; i < 10000; i++)
|
sl@0
|
1043 |
{
|
sl@0
|
1044 |
array[i] = i;
|
sl@0
|
1045 |
g_hash_table_insert (hash_table, &array[i], &array[i]);
|
sl@0
|
1046 |
}
|
sl@0
|
1047 |
pvalue = g_hash_table_find (hash_table, find_first_that, &value);
|
sl@0
|
1048 |
if (*pvalue != value)
|
sl@0
|
1049 |
g_error ("g_hash_table_find failed");
|
sl@0
|
1050 |
g_hash_table_foreach (hash_table, my_hash_callback, NULL);
|
sl@0
|
1051 |
for (i = 0; i < 10000; i++)
|
sl@0
|
1052 |
if (array[i] == 0)
|
sl@0
|
1053 |
g_error ("hashtable-test: wrong value: %d\n", i);
|
sl@0
|
1054 |
for (i = 0; i < 10000; i++)
|
sl@0
|
1055 |
g_hash_table_remove (hash_table, &array[i]);
|
sl@0
|
1056 |
for (i = 0; i < 10000; i++)
|
sl@0
|
1057 |
{
|
sl@0
|
1058 |
array[i] = i;
|
sl@0
|
1059 |
g_hash_table_insert (hash_table, &array[i], &array[i]);
|
sl@0
|
1060 |
}
|
sl@0
|
1061 |
if (g_hash_table_foreach_remove (hash_table, my_hash_callback_remove, NULL) != 5000 ||
|
sl@0
|
1062 |
g_hash_table_size (hash_table) != 5000)
|
sl@0
|
1063 |
g_error ("hashtable removal failed\n");
|
sl@0
|
1064 |
g_hash_table_foreach (hash_table, my_hash_callback_remove_test, NULL);
|
sl@0
|
1065 |
g_hash_table_destroy (hash_table);
|
sl@0
|
1066 |
}
|
sl@0
|
1067 |
|
sl@0
|
1068 |
static void
|
sl@0
|
1069 |
relation_test (void)
|
sl@0
|
1070 |
{
|
sl@0
|
1071 |
GRelation *relation = g_relation_new (2);
|
sl@0
|
1072 |
GTuples *tuples;
|
sl@0
|
1073 |
gint data [1024];
|
sl@0
|
1074 |
guint i;
|
sl@0
|
1075 |
|
sl@0
|
1076 |
g_relation_index (relation, 0, g_int_hash, g_int_equal);
|
sl@0
|
1077 |
g_relation_index (relation, 1, g_int_hash, g_int_equal);
|
sl@0
|
1078 |
|
sl@0
|
1079 |
for (i = 0; i < 1024; i += 1)
|
sl@0
|
1080 |
data[i] = i;
|
sl@0
|
1081 |
|
sl@0
|
1082 |
for (i = 1; i < 1023; i += 1)
|
sl@0
|
1083 |
{
|
sl@0
|
1084 |
g_relation_insert (relation, data + i, data + i + 1);
|
sl@0
|
1085 |
g_relation_insert (relation, data + i, data + i - 1);
|
sl@0
|
1086 |
}
|
sl@0
|
1087 |
|
sl@0
|
1088 |
for (i = 2; i < 1022; i += 1)
|
sl@0
|
1089 |
{
|
sl@0
|
1090 |
g_assert (! g_relation_exists (relation, data + i, data + i));
|
sl@0
|
1091 |
g_assert (! g_relation_exists (relation, data + i, data + i + 2));
|
sl@0
|
1092 |
g_assert (! g_relation_exists (relation, data + i, data + i - 2));
|
sl@0
|
1093 |
}
|
sl@0
|
1094 |
|
sl@0
|
1095 |
for (i = 1; i < 1023; i += 1)
|
sl@0
|
1096 |
{
|
sl@0
|
1097 |
g_assert (g_relation_exists (relation, data + i, data + i + 1));
|
sl@0
|
1098 |
g_assert (g_relation_exists (relation, data + i, data + i - 1));
|
sl@0
|
1099 |
}
|
sl@0
|
1100 |
|
sl@0
|
1101 |
for (i = 2; i < 1022; i += 1)
|
sl@0
|
1102 |
{
|
sl@0
|
1103 |
g_assert (g_relation_count (relation, data + i, 0) == 2);
|
sl@0
|
1104 |
g_assert (g_relation_count (relation, data + i, 1) == 2);
|
sl@0
|
1105 |
}
|
sl@0
|
1106 |
|
sl@0
|
1107 |
g_assert (g_relation_count (relation, data, 0) == 0);
|
sl@0
|
1108 |
|
sl@0
|
1109 |
g_assert (g_relation_count (relation, data + 42, 0) == 2);
|
sl@0
|
1110 |
g_assert (g_relation_count (relation, data + 43, 1) == 2);
|
sl@0
|
1111 |
g_assert (g_relation_count (relation, data + 41, 1) == 2);
|
sl@0
|
1112 |
g_relation_delete (relation, data + 42, 0);
|
sl@0
|
1113 |
g_assert (g_relation_count (relation, data + 42, 0) == 0);
|
sl@0
|
1114 |
g_assert (g_relation_count (relation, data + 43, 1) == 1);
|
sl@0
|
1115 |
g_assert (g_relation_count (relation, data + 41, 1) == 1);
|
sl@0
|
1116 |
|
sl@0
|
1117 |
tuples = g_relation_select (relation, data + 200, 0);
|
sl@0
|
1118 |
|
sl@0
|
1119 |
g_assert (tuples->len == 2);
|
sl@0
|
1120 |
|
sl@0
|
1121 |
#if 0
|
sl@0
|
1122 |
for (i = 0; i < tuples->len; i += 1)
|
sl@0
|
1123 |
{
|
sl@0
|
1124 |
printf ("%d %d\n",
|
sl@0
|
1125 |
*(gint*) g_tuples_index (tuples, i, 0),
|
sl@0
|
1126 |
*(gint*) g_tuples_index (tuples, i, 1));
|
sl@0
|
1127 |
}
|
sl@0
|
1128 |
#endif
|
sl@0
|
1129 |
|
sl@0
|
1130 |
g_assert (g_relation_exists (relation, data + 300, data + 301));
|
sl@0
|
1131 |
g_relation_delete (relation, data + 300, 0);
|
sl@0
|
1132 |
g_assert (!g_relation_exists (relation, data + 300, data + 301));
|
sl@0
|
1133 |
|
sl@0
|
1134 |
g_tuples_destroy (tuples);
|
sl@0
|
1135 |
|
sl@0
|
1136 |
g_relation_destroy (relation);
|
sl@0
|
1137 |
|
sl@0
|
1138 |
relation = NULL;
|
sl@0
|
1139 |
}
|
sl@0
|
1140 |
|
sl@0
|
1141 |
static void
|
sl@0
|
1142 |
gstring_tests (void)
|
sl@0
|
1143 |
{
|
sl@0
|
1144 |
GString *string1, *string2;
|
sl@0
|
1145 |
guint i;
|
sl@0
|
1146 |
|
sl@0
|
1147 |
if (g_test_verbose())
|
sl@0
|
1148 |
g_print ("test GString basics\n");
|
sl@0
|
1149 |
|
sl@0
|
1150 |
string1 = g_string_new ("hi pete!");
|
sl@0
|
1151 |
string2 = g_string_new ("");
|
sl@0
|
1152 |
|
sl@0
|
1153 |
g_assert (strcmp ("hi pete!", string1->str) == 0);
|
sl@0
|
1154 |
|
sl@0
|
1155 |
for (i = 0; i < 10000; i++)
|
sl@0
|
1156 |
g_string_append_c (string1, 'a'+(i%26));
|
sl@0
|
1157 |
|
sl@0
|
1158 |
#ifndef G_OS_WIN32
|
sl@0
|
1159 |
/* MSVC, mingw32 and LCC use the same run-time C library, which doesn't like
|
sl@0
|
1160 |
the %10000.10000f format... */
|
sl@0
|
1161 |
g_string_printf (string2, "%s|%0100d|%s|%s|%0*d|%*.*f|%10000.10000f",
|
sl@0
|
1162 |
"this pete guy sure is a wuss, like he's the number ",
|
sl@0
|
1163 |
1,
|
sl@0
|
1164 |
" wuss. everyone agrees.\n",
|
sl@0
|
1165 |
string1->str,
|
sl@0
|
1166 |
10, 666, 15, 15, 666.666666666, 666.666666666);
|
sl@0
|
1167 |
#else
|
sl@0
|
1168 |
g_string_printf (string2, "%s|%0100d|%s|%s|%0*d|%*.*f|%100.100f",
|
sl@0
|
1169 |
"this pete guy sure is a wuss, like he's the number ",
|
sl@0
|
1170 |
1,
|
sl@0
|
1171 |
" wuss. everyone agrees.\n",
|
sl@0
|
1172 |
string1->str,
|
sl@0
|
1173 |
10, 666, 15, 15, 666.666666666, 666.666666666);
|
sl@0
|
1174 |
#endif
|
sl@0
|
1175 |
|
sl@0
|
1176 |
if (g_test_verbose())
|
sl@0
|
1177 |
g_print ("string2 length = %lu...\n", (gulong)string2->len);
|
sl@0
|
1178 |
string2->str[70] = '\0';
|
sl@0
|
1179 |
if (g_test_verbose())
|
sl@0
|
1180 |
g_print ("first 70 chars:\n%s\n", string2->str);
|
sl@0
|
1181 |
string2->str[141] = '\0';
|
sl@0
|
1182 |
if (g_test_verbose())
|
sl@0
|
1183 |
g_print ("next 70 chars:\n%s\n", string2->str+71);
|
sl@0
|
1184 |
string2->str[212] = '\0';
|
sl@0
|
1185 |
if (g_test_verbose())
|
sl@0
|
1186 |
g_print ("and next 70:\n%s\n", string2->str+142);
|
sl@0
|
1187 |
if (g_test_verbose())
|
sl@0
|
1188 |
g_print ("last 70 chars:\n%s\n", string2->str+string2->len - 70);
|
sl@0
|
1189 |
|
sl@0
|
1190 |
g_string_free (string1, TRUE);
|
sl@0
|
1191 |
g_string_free (string2, TRUE);
|
sl@0
|
1192 |
|
sl@0
|
1193 |
/* append */
|
sl@0
|
1194 |
string1 = g_string_new ("firsthalf");
|
sl@0
|
1195 |
g_string_append (string1, "lasthalf");
|
sl@0
|
1196 |
g_assert (strcmp (string1->str, "firsthalflasthalf") == 0);
|
sl@0
|
1197 |
g_string_free (string1, TRUE);
|
sl@0
|
1198 |
|
sl@0
|
1199 |
/* append_len */
|
sl@0
|
1200 |
string1 = g_string_new ("firsthalf");
|
sl@0
|
1201 |
g_string_append_len (string1, "lasthalfjunkjunk", strlen ("lasthalf"));
|
sl@0
|
1202 |
g_assert (strcmp (string1->str, "firsthalflasthalf") == 0);
|
sl@0
|
1203 |
g_string_free (string1, TRUE);
|
sl@0
|
1204 |
|
sl@0
|
1205 |
/* prepend */
|
sl@0
|
1206 |
string1 = g_string_new ("lasthalf");
|
sl@0
|
1207 |
g_string_prepend (string1, "firsthalf");
|
sl@0
|
1208 |
g_assert (strcmp (string1->str, "firsthalflasthalf") == 0);
|
sl@0
|
1209 |
g_string_free (string1, TRUE);
|
sl@0
|
1210 |
|
sl@0
|
1211 |
/* prepend_len */
|
sl@0
|
1212 |
string1 = g_string_new ("lasthalf");
|
sl@0
|
1213 |
g_string_prepend_len (string1, "firsthalfjunkjunk", strlen ("firsthalf"));
|
sl@0
|
1214 |
g_assert (strcmp (string1->str, "firsthalflasthalf") == 0);
|
sl@0
|
1215 |
g_string_free (string1, TRUE);
|
sl@0
|
1216 |
|
sl@0
|
1217 |
/* insert */
|
sl@0
|
1218 |
string1 = g_string_new ("firstlast");
|
sl@0
|
1219 |
g_string_insert (string1, 5, "middle");
|
sl@0
|
1220 |
g_assert (strcmp (string1->str, "firstmiddlelast") == 0);
|
sl@0
|
1221 |
g_string_free (string1, TRUE);
|
sl@0
|
1222 |
|
sl@0
|
1223 |
/* insert with pos == end of the string */
|
sl@0
|
1224 |
string1 = g_string_new ("firstmiddle");
|
sl@0
|
1225 |
g_string_insert (string1, strlen ("firstmiddle"), "last");
|
sl@0
|
1226 |
g_assert (strcmp (string1->str, "firstmiddlelast") == 0);
|
sl@0
|
1227 |
g_string_free (string1, TRUE);
|
sl@0
|
1228 |
|
sl@0
|
1229 |
/* insert_len */
|
sl@0
|
1230 |
string1 = g_string_new ("firstlast");
|
sl@0
|
1231 |
g_string_insert_len (string1, 5, "middlejunkjunk", strlen ("middle"));
|
sl@0
|
1232 |
g_assert (strcmp (string1->str, "firstmiddlelast") == 0);
|
sl@0
|
1233 |
g_string_free (string1, TRUE);
|
sl@0
|
1234 |
|
sl@0
|
1235 |
/* insert_len with magic -1 pos for append */
|
sl@0
|
1236 |
string1 = g_string_new ("first");
|
sl@0
|
1237 |
g_string_insert_len (string1, -1, "lastjunkjunk", strlen ("last"));
|
sl@0
|
1238 |
g_assert (strcmp (string1->str, "firstlast") == 0);
|
sl@0
|
1239 |
g_string_free (string1, TRUE);
|
sl@0
|
1240 |
|
sl@0
|
1241 |
/* insert_len with magic -1 len for strlen-the-string */
|
sl@0
|
1242 |
string1 = g_string_new ("first");
|
sl@0
|
1243 |
g_string_insert_len (string1, 5, "last", -1);
|
sl@0
|
1244 |
g_assert (strcmp (string1->str, "firstlast") == 0);
|
sl@0
|
1245 |
g_string_free (string1, TRUE);
|
sl@0
|
1246 |
|
sl@0
|
1247 |
/* g_string_equal */
|
sl@0
|
1248 |
string1 = g_string_new ("test");
|
sl@0
|
1249 |
string2 = g_string_new ("te");
|
sl@0
|
1250 |
g_assert (! g_string_equal(string1, string2));
|
sl@0
|
1251 |
g_string_append (string2, "st");
|
sl@0
|
1252 |
g_assert (g_string_equal(string1, string2));
|
sl@0
|
1253 |
g_string_free (string1, TRUE);
|
sl@0
|
1254 |
g_string_free (string2, TRUE);
|
sl@0
|
1255 |
|
sl@0
|
1256 |
/* Check handling of embedded ASCII 0 (NUL) characters in GString. */
|
sl@0
|
1257 |
if (g_test_verbose())
|
sl@0
|
1258 |
g_print ("test embedded ASCII 0 (NUL) characters in GString\n");
|
sl@0
|
1259 |
string1 = g_string_new ("fiddle");
|
sl@0
|
1260 |
string2 = g_string_new ("fiddle");
|
sl@0
|
1261 |
g_assert (g_string_equal(string1, string2));
|
sl@0
|
1262 |
g_string_append_c(string1, '\0');
|
sl@0
|
1263 |
g_assert (! g_string_equal(string1, string2));
|
sl@0
|
1264 |
g_string_append_c(string2, '\0');
|
sl@0
|
1265 |
g_assert (g_string_equal(string1, string2));
|
sl@0
|
1266 |
g_string_append_c(string1, 'x');
|
sl@0
|
1267 |
g_string_append_c(string2, 'y');
|
sl@0
|
1268 |
g_assert (! g_string_equal(string1, string2));
|
sl@0
|
1269 |
g_assert (string1->len == 8);
|
sl@0
|
1270 |
g_string_append(string1, "yzzy");
|
sl@0
|
1271 |
g_assert (string1->len == 12);
|
sl@0
|
1272 |
g_assert ( memcmp(string1->str, "fiddle\0xyzzy", 13) == 0);
|
sl@0
|
1273 |
g_string_insert(string1, 1, "QED");
|
sl@0
|
1274 |
g_assert ( memcmp(string1->str, "fQEDiddle\0xyzzy", 16) == 0);
|
sl@0
|
1275 |
g_string_free (string1, TRUE);
|
sl@0
|
1276 |
g_string_free (string2, TRUE);
|
sl@0
|
1277 |
}
|
sl@0
|
1278 |
|
sl@0
|
1279 |
static void
|
sl@0
|
1280 |
various_string_tests (void)
|
sl@0
|
1281 |
{
|
sl@0
|
1282 |
GStringChunk *string_chunk;
|
sl@0
|
1283 |
GTimeVal ref_date, date;
|
sl@0
|
1284 |
gchar *tmp_string = NULL, *tmp_string_2, *string, *date_str;
|
sl@0
|
1285 |
guint i;
|
sl@0
|
1286 |
|
sl@0
|
1287 |
if (g_test_verbose())
|
sl@0
|
1288 |
g_print ("checking string chunks...");
|
sl@0
|
1289 |
string_chunk = g_string_chunk_new (1024);
|
sl@0
|
1290 |
for (i = 0; i < 100000; i ++)
|
sl@0
|
1291 |
{
|
sl@0
|
1292 |
tmp_string = g_string_chunk_insert (string_chunk, "hi pete");
|
sl@0
|
1293 |
if (strcmp ("hi pete", tmp_string) != 0)
|
sl@0
|
1294 |
g_error ("string chunks are broken.\n");
|
sl@0
|
1295 |
}
|
sl@0
|
1296 |
tmp_string_2 = g_string_chunk_insert_const (string_chunk, tmp_string);
|
sl@0
|
1297 |
g_assert (tmp_string_2 != tmp_string && strcmp (tmp_string_2, tmp_string) == 0);
|
sl@0
|
1298 |
tmp_string = g_string_chunk_insert_const (string_chunk, tmp_string);
|
sl@0
|
1299 |
g_assert (tmp_string_2 == tmp_string);
|
sl@0
|
1300 |
g_string_chunk_free (string_chunk);
|
sl@0
|
1301 |
|
sl@0
|
1302 |
if (g_test_verbose())
|
sl@0
|
1303 |
g_print ("test positional printf formats (not supported):");
|
sl@0
|
1304 |
string = g_strdup_printf ("%.*s%s", 5, "a", "b");
|
sl@0
|
1305 |
tmp_string = g_strdup_printf ("%2$*1$s", 5, "c");
|
sl@0
|
1306 |
if (g_test_verbose())
|
sl@0
|
1307 |
g_print ("%s%s\n", string, tmp_string);
|
sl@0
|
1308 |
g_free (tmp_string);
|
sl@0
|
1309 |
g_free (string);
|
sl@0
|
1310 |
|
sl@0
|
1311 |
#define REF_INVALID1 "Wed Dec 19 17:20:20 GMT 2007"
|
sl@0
|
1312 |
#define REF_INVALID2 "1980-02-22T10:36:00Zulu"
|
sl@0
|
1313 |
#define REF_SEC_UTC 320063760
|
sl@0
|
1314 |
#define REF_STR_UTC "1980-02-22T10:36:00Z"
|
sl@0
|
1315 |
#define REF_STR_CEST "1980-02-22T12:36:00+02:00"
|
sl@0
|
1316 |
#define REF_STR_EST "19800222T053600-0500"
|
sl@0
|
1317 |
#define REF_STR_NST "1980-02-22T07:06:00-03:30"
|
sl@0
|
1318 |
#define REF_USEC_UTC 50000
|
sl@0
|
1319 |
#define REF_STR_USEC_UTC "1980-02-22T10:36:00.050000Z"
|
sl@0
|
1320 |
#define REF_STR_USEC_CEST "19800222T123600.050000000+0200"
|
sl@0
|
1321 |
#define REF_STR_USEC_EST "1980-02-22T05:36:00,05-05:00"
|
sl@0
|
1322 |
#define REF_STR_USEC_NST "19800222T070600,0500-0330"
|
sl@0
|
1323 |
|
sl@0
|
1324 |
if (g_test_verbose())
|
sl@0
|
1325 |
g_print ("checking g_time_val_from_iso8601...\n");
|
sl@0
|
1326 |
ref_date.tv_sec = REF_SEC_UTC;
|
sl@0
|
1327 |
ref_date.tv_usec = 0;
|
sl@0
|
1328 |
g_assert (g_time_val_from_iso8601 (REF_INVALID1, &date) == FALSE);
|
sl@0
|
1329 |
g_assert (g_time_val_from_iso8601 (REF_INVALID2, &date) == FALSE);
|
sl@0
|
1330 |
g_assert (g_time_val_from_iso8601 (REF_STR_UTC, &date) != FALSE);
|
sl@0
|
1331 |
if (g_test_verbose())
|
sl@0
|
1332 |
g_print ("\t=> UTC stamp = %ld.%06ld (should be: %ld.%06ld) (%ld.%06ld off)\n",
|
sl@0
|
1333 |
date.tv_sec, date.tv_usec, ref_date.tv_sec, ref_date.tv_usec,
|
sl@0
|
1334 |
date.tv_sec - ref_date.tv_sec, date.tv_usec - ref_date.tv_usec);
|
sl@0
|
1335 |
g_assert (date.tv_sec == ref_date.tv_sec && date.tv_usec == ref_date.tv_usec);
|
sl@0
|
1336 |
|
sl@0
|
1337 |
g_assert (g_time_val_from_iso8601 (REF_STR_CEST, &date) != FALSE);
|
sl@0
|
1338 |
if (g_test_verbose())
|
sl@0
|
1339 |
g_print ("\t=> CEST stamp = %ld.%06ld (should be: %ld.%06ld) (%ld.%06ld off)\n",
|
sl@0
|
1340 |
date.tv_sec, date.tv_usec, ref_date.tv_sec, ref_date.tv_usec,
|
sl@0
|
1341 |
date.tv_sec - ref_date.tv_sec, date.tv_usec - ref_date.tv_usec);
|
sl@0
|
1342 |
g_assert (date.tv_sec == ref_date.tv_sec && date.tv_usec == ref_date.tv_usec);
|
sl@0
|
1343 |
|
sl@0
|
1344 |
g_assert (g_time_val_from_iso8601 (REF_STR_EST, &date) != FALSE);
|
sl@0
|
1345 |
if (g_test_verbose())
|
sl@0
|
1346 |
g_print ("\t=> EST stamp = %ld.%06ld (should be: %ld.%06ld) (%ld.%06ld off)\n",
|
sl@0
|
1347 |
date.tv_sec, date.tv_usec, ref_date.tv_sec, ref_date.tv_usec,
|
sl@0
|
1348 |
date.tv_sec - ref_date.tv_sec, date.tv_usec - ref_date.tv_usec);
|
sl@0
|
1349 |
g_assert (date.tv_sec == ref_date.tv_sec && date.tv_usec == ref_date.tv_usec);
|
sl@0
|
1350 |
|
sl@0
|
1351 |
g_assert (g_time_val_from_iso8601 (REF_STR_NST, &date) != FALSE);
|
sl@0
|
1352 |
if (g_test_verbose())
|
sl@0
|
1353 |
g_print ("\t=> NST stamp = %ld.%06ld (should be: %ld.%06ld) (%ld.%06ld off)\n",
|
sl@0
|
1354 |
date.tv_sec, date.tv_usec, ref_date.tv_sec, ref_date.tv_usec,
|
sl@0
|
1355 |
date.tv_sec - ref_date.tv_sec, date.tv_usec - ref_date.tv_usec);
|
sl@0
|
1356 |
g_assert (date.tv_sec == ref_date.tv_sec && date.tv_usec == ref_date.tv_usec);
|
sl@0
|
1357 |
|
sl@0
|
1358 |
ref_date.tv_usec = REF_USEC_UTC;
|
sl@0
|
1359 |
g_assert (g_time_val_from_iso8601 (REF_STR_USEC_UTC, &date) != FALSE);
|
sl@0
|
1360 |
if (g_test_verbose())
|
sl@0
|
1361 |
g_print ("\t=> UTC stamp = %ld.%06ld (should be: %ld.%06ld) (%ld.%06ld off)\n",
|
sl@0
|
1362 |
date.tv_sec, date.tv_usec, ref_date.tv_sec, ref_date.tv_usec,
|
sl@0
|
1363 |
date.tv_sec - ref_date.tv_sec, date.tv_usec - ref_date.tv_usec);
|
sl@0
|
1364 |
g_assert (date.tv_sec == ref_date.tv_sec && date.tv_usec == ref_date.tv_usec);
|
sl@0
|
1365 |
|
sl@0
|
1366 |
g_assert (g_time_val_from_iso8601 (REF_STR_USEC_CEST, &date) != FALSE);
|
sl@0
|
1367 |
if (g_test_verbose())
|
sl@0
|
1368 |
g_print ("\t=> CEST stamp = %ld.%06ld (should be: %ld.%06ld) (%ld.%06ld off)\n",
|
sl@0
|
1369 |
date.tv_sec, date.tv_usec, ref_date.tv_sec, ref_date.tv_usec,
|
sl@0
|
1370 |
date.tv_sec - ref_date.tv_sec, date.tv_usec - ref_date.tv_usec);
|
sl@0
|
1371 |
g_assert (date.tv_sec == ref_date.tv_sec && date.tv_usec == ref_date.tv_usec);
|
sl@0
|
1372 |
|
sl@0
|
1373 |
g_assert (g_time_val_from_iso8601 (REF_STR_USEC_EST, &date) != FALSE);
|
sl@0
|
1374 |
if (g_test_verbose())
|
sl@0
|
1375 |
g_print ("\t=> EST stamp = %ld.%06ld (should be: %ld.%06ld) (%ld.%06ld off)\n",
|
sl@0
|
1376 |
date.tv_sec, date.tv_usec, ref_date.tv_sec, ref_date.tv_usec,
|
sl@0
|
1377 |
date.tv_sec - ref_date.tv_sec, date.tv_usec - ref_date.tv_usec);
|
sl@0
|
1378 |
g_assert (date.tv_sec == ref_date.tv_sec && date.tv_usec == ref_date.tv_usec);
|
sl@0
|
1379 |
|
sl@0
|
1380 |
g_assert (g_time_val_from_iso8601 (REF_STR_USEC_NST, &date) != FALSE);
|
sl@0
|
1381 |
if (g_test_verbose())
|
sl@0
|
1382 |
g_print ("\t=> NST stamp = %ld.%06ld (should be: %ld.%06ld) (%ld.%06ld off)\n",
|
sl@0
|
1383 |
date.tv_sec, date.tv_usec, ref_date.tv_sec, ref_date.tv_usec,
|
sl@0
|
1384 |
date.tv_sec - ref_date.tv_sec, date.tv_usec - ref_date.tv_usec);
|
sl@0
|
1385 |
g_assert (date.tv_sec == ref_date.tv_sec && date.tv_usec == ref_date.tv_usec);
|
sl@0
|
1386 |
|
sl@0
|
1387 |
if (g_test_verbose())
|
sl@0
|
1388 |
g_print ("checking g_time_val_to_iso8601...\n");
|
sl@0
|
1389 |
ref_date.tv_sec = REF_SEC_UTC;
|
sl@0
|
1390 |
ref_date.tv_usec = 0;
|
sl@0
|
1391 |
date_str = g_time_val_to_iso8601 (&ref_date);
|
sl@0
|
1392 |
g_assert (date_str != NULL);
|
sl@0
|
1393 |
if (g_test_verbose())
|
sl@0
|
1394 |
g_print ("\t=> date string = %s (should be: %s)\n", date_str, REF_STR_UTC);
|
sl@0
|
1395 |
g_assert (strcmp (date_str, REF_STR_UTC) == 0);
|
sl@0
|
1396 |
g_free (date_str);
|
sl@0
|
1397 |
|
sl@0
|
1398 |
ref_date.tv_usec = REF_USEC_UTC;
|
sl@0
|
1399 |
date_str = g_time_val_to_iso8601 (&ref_date);
|
sl@0
|
1400 |
g_assert (date_str != NULL);
|
sl@0
|
1401 |
if (g_test_verbose())
|
sl@0
|
1402 |
g_print ("\t=> date string = %s (should be: %s)\n", date_str, REF_STR_USEC_UTC);
|
sl@0
|
1403 |
g_assert (strcmp (date_str, REF_STR_USEC_UTC) == 0);
|
sl@0
|
1404 |
g_free (date_str);
|
sl@0
|
1405 |
|
sl@0
|
1406 |
if (g_test_verbose())
|
sl@0
|
1407 |
g_print ("checking g_ascii_strcasecmp...");
|
sl@0
|
1408 |
g_assert (g_ascii_strcasecmp ("FroboZZ", "frobozz") == 0);
|
sl@0
|
1409 |
g_assert (g_ascii_strcasecmp ("frobozz", "frobozz") == 0);
|
sl@0
|
1410 |
g_assert (g_ascii_strcasecmp ("frobozz", "FROBOZZ") == 0);
|
sl@0
|
1411 |
g_assert (g_ascii_strcasecmp ("FROBOZZ", "froboz") > 0);
|
sl@0
|
1412 |
g_assert (g_ascii_strcasecmp ("", "") == 0);
|
sl@0
|
1413 |
g_assert (g_ascii_strcasecmp ("!#%&/()", "!#%&/()") == 0);
|
sl@0
|
1414 |
g_assert (g_ascii_strcasecmp ("a", "b") < 0);
|
sl@0
|
1415 |
g_assert (g_ascii_strcasecmp ("a", "B") < 0);
|
sl@0
|
1416 |
g_assert (g_ascii_strcasecmp ("A", "b") < 0);
|
sl@0
|
1417 |
g_assert (g_ascii_strcasecmp ("A", "B") < 0);
|
sl@0
|
1418 |
g_assert (g_ascii_strcasecmp ("b", "a") > 0);
|
sl@0
|
1419 |
g_assert (g_ascii_strcasecmp ("b", "A") > 0);
|
sl@0
|
1420 |
g_assert (g_ascii_strcasecmp ("B", "a") > 0);
|
sl@0
|
1421 |
g_assert (g_ascii_strcasecmp ("B", "A") > 0);
|
sl@0
|
1422 |
|
sl@0
|
1423 |
if (g_test_verbose())
|
sl@0
|
1424 |
g_print ("checking g_strdup...\n");
|
sl@0
|
1425 |
g_assert (g_strdup (NULL) == NULL);
|
sl@0
|
1426 |
string = g_strdup (GLIB_TEST_STRING);
|
sl@0
|
1427 |
g_assert (string != NULL);
|
sl@0
|
1428 |
g_assert (strcmp(string, GLIB_TEST_STRING) == 0);
|
sl@0
|
1429 |
g_free (string);
|
sl@0
|
1430 |
|
sl@0
|
1431 |
if (g_test_verbose())
|
sl@0
|
1432 |
g_print ("checking g_strconcat...\n");
|
sl@0
|
1433 |
string = g_strconcat (GLIB_TEST_STRING, NULL);
|
sl@0
|
1434 |
g_assert (string != NULL);
|
sl@0
|
1435 |
g_assert (strcmp (string, GLIB_TEST_STRING) == 0);
|
sl@0
|
1436 |
g_free (string);
|
sl@0
|
1437 |
string = g_strconcat (GLIB_TEST_STRING, GLIB_TEST_STRING,
|
sl@0
|
1438 |
GLIB_TEST_STRING, NULL);
|
sl@0
|
1439 |
g_assert (string != NULL);
|
sl@0
|
1440 |
g_assert (strcmp (string, GLIB_TEST_STRING GLIB_TEST_STRING
|
sl@0
|
1441 |
GLIB_TEST_STRING) == 0);
|
sl@0
|
1442 |
g_free (string);
|
sl@0
|
1443 |
|
sl@0
|
1444 |
if (g_test_verbose())
|
sl@0
|
1445 |
g_print ("checking g_strlcpy/g_strlcat...");
|
sl@0
|
1446 |
/* The following is a torture test for strlcpy/strlcat, with lots of
|
sl@0
|
1447 |
* checking; normal users wouldn't use them this way!
|
sl@0
|
1448 |
*/
|
sl@0
|
1449 |
string = g_malloc (6);
|
sl@0
|
1450 |
*(string + 5) = 'Z'; /* guard value, shouldn't change during test */
|
sl@0
|
1451 |
*string = 'q';
|
sl@0
|
1452 |
g_assert (g_strlcpy(string, "" , 5) == 0);
|
sl@0
|
1453 |
g_assert ( *string == '\0' );
|
sl@0
|
1454 |
*string = 'q';
|
sl@0
|
1455 |
g_assert (g_strlcpy(string, "abc" , 5) == 3);
|
sl@0
|
1456 |
g_assert ( *(string + 3) == '\0' );
|
sl@0
|
1457 |
g_assert (g_str_equal(string, "abc"));
|
sl@0
|
1458 |
g_assert (g_strlcpy(string, "abcd" , 5) == 4);
|
sl@0
|
1459 |
g_assert ( *(string + 4) == '\0' );
|
sl@0
|
1460 |
g_assert ( *(string + 5) == 'Z' );
|
sl@0
|
1461 |
g_assert (g_str_equal(string, "abcd"));
|
sl@0
|
1462 |
g_assert (g_strlcpy(string, "abcde" , 5) == 5);
|
sl@0
|
1463 |
g_assert ( *(string + 4) == '\0' );
|
sl@0
|
1464 |
g_assert ( *(string + 5) == 'Z' );
|
sl@0
|
1465 |
g_assert (g_str_equal(string, "abcd"));
|
sl@0
|
1466 |
g_assert (g_strlcpy(string, "abcdef" , 5) == 6);
|
sl@0
|
1467 |
g_assert ( *(string + 4) == '\0' );
|
sl@0
|
1468 |
g_assert ( *(string + 5) == 'Z' );
|
sl@0
|
1469 |
g_assert (g_str_equal(string, "abcd"));
|
sl@0
|
1470 |
*string = 'Y';
|
sl@0
|
1471 |
*(string + 1)= '\0';
|
sl@0
|
1472 |
g_assert (g_strlcpy(string, "Hello" , 0) == 5);
|
sl@0
|
1473 |
g_assert (*string == 'Y');
|
sl@0
|
1474 |
*string = '\0';
|
sl@0
|
1475 |
g_assert (g_strlcat(string, "123" , 5) == 3);
|
sl@0
|
1476 |
g_assert ( *(string + 3) == '\0' );
|
sl@0
|
1477 |
g_assert (g_str_equal(string, "123"));
|
sl@0
|
1478 |
g_assert (g_strlcat(string, "" , 5) == 3);
|
sl@0
|
1479 |
g_assert ( *(string + 3) == '\0' );
|
sl@0
|
1480 |
g_assert (g_str_equal(string, "123"));
|
sl@0
|
1481 |
g_assert (g_strlcat(string, "4", 5) == 4);
|
sl@0
|
1482 |
g_assert (g_str_equal(string, "1234"));
|
sl@0
|
1483 |
g_assert (g_strlcat(string, "5", 5) == 5);
|
sl@0
|
1484 |
g_assert ( *(string + 4) == '\0' );
|
sl@0
|
1485 |
g_assert (g_str_equal(string, "1234"));
|
sl@0
|
1486 |
g_assert ( *(string + 5) == 'Z' );
|
sl@0
|
1487 |
*string = 'Y';
|
sl@0
|
1488 |
*(string + 1)= '\0';
|
sl@0
|
1489 |
g_assert (g_strlcat(string, "123" , 0) == 3);
|
sl@0
|
1490 |
g_assert (*string == 'Y');
|
sl@0
|
1491 |
|
sl@0
|
1492 |
/* A few more tests, demonstrating more "normal" use */
|
sl@0
|
1493 |
g_assert (g_strlcpy(string, "hi", 5) == 2);
|
sl@0
|
1494 |
g_assert (g_str_equal(string, "hi"));
|
sl@0
|
1495 |
g_assert (g_strlcat(string, "t", 5) == 3);
|
sl@0
|
1496 |
g_assert (g_str_equal(string, "hit"));
|
sl@0
|
1497 |
g_free(string);
|
sl@0
|
1498 |
|
sl@0
|
1499 |
if (g_test_verbose())
|
sl@0
|
1500 |
g_print ("checking g_strdup_printf...\n");
|
sl@0
|
1501 |
string = g_strdup_printf ("%05d %-5s", 21, "test");
|
sl@0
|
1502 |
g_assert (string != NULL);
|
sl@0
|
1503 |
g_assert (strcmp(string, "00021 test ") == 0);
|
sl@0
|
1504 |
g_free (string);
|
sl@0
|
1505 |
|
sl@0
|
1506 |
/* g_debug (argv[0]); */
|
sl@0
|
1507 |
}
|
sl@0
|
1508 |
|
sl@0
|
1509 |
#ifndef G_DISABLE_DEPRECATED
|
sl@0
|
1510 |
static void
|
sl@0
|
1511 |
test_mem_chunks (void)
|
sl@0
|
1512 |
{
|
sl@0
|
1513 |
GMemChunk *mem_chunk = g_mem_chunk_new ("test mem chunk", 50, 100, G_ALLOC_AND_FREE);
|
sl@0
|
1514 |
gchar *mem[10000];
|
sl@0
|
1515 |
guint i;
|
sl@0
|
1516 |
for (i = 0; i < 10000; i++)
|
sl@0
|
1517 |
{
|
sl@0
|
1518 |
guint j;
|
sl@0
|
1519 |
mem[i] = g_chunk_new (gchar, mem_chunk);
|
sl@0
|
1520 |
for (j = 0; j < 50; j++)
|
sl@0
|
1521 |
mem[i][j] = i * j;
|
sl@0
|
1522 |
}
|
sl@0
|
1523 |
for (i = 0; i < 10000; i++)
|
sl@0
|
1524 |
g_mem_chunk_free (mem_chunk, mem[i]);
|
sl@0
|
1525 |
}
|
sl@0
|
1526 |
#endif
|
sl@0
|
1527 |
|
sl@0
|
1528 |
int
|
sl@0
|
1529 |
main (int argc,
|
sl@0
|
1530 |
char *argv[])
|
sl@0
|
1531 |
{
|
sl@0
|
1532 |
#ifdef __SYMBIAN32__
|
sl@0
|
1533 |
g_log_set_handler (NULL, G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, &mrtLogHandler, NULL);
|
sl@0
|
1534 |
g_set_print_handler(mrtPrintHandler);
|
sl@0
|
1535 |
#endif /*__SYMBIAN32__*/
|
sl@0
|
1536 |
g_test_init (&argc, &argv, NULL);
|
sl@0
|
1537 |
|
sl@0
|
1538 |
g_test_add_func ("/testglib/Infos", test_info);
|
sl@0
|
1539 |
g_test_add_func ("/testglib/Types Sizes", type_sizes);
|
sl@0
|
1540 |
g_test_add_func ("/testglib/GStrings", gstring_tests);
|
sl@0
|
1541 |
g_test_add_func ("/testglib/Various Strings", various_string_tests);
|
sl@0
|
1542 |
g_test_add_func ("/testglib/GList", glist_test);
|
sl@0
|
1543 |
g_test_add_func ("/testglib/GSList", gslist_test);
|
sl@0
|
1544 |
g_test_add_func ("/testglib/GNode", gnode_test);
|
sl@0
|
1545 |
g_test_add_func ("/testglib/GTree", binary_tree_test);
|
sl@0
|
1546 |
g_test_add_func ("/testglib/Arrays", test_arrays);
|
sl@0
|
1547 |
g_test_add_func ("/testglib/GHashTable", hash_table_tests);
|
sl@0
|
1548 |
g_test_add_func ("/testglib/Relation", relation_test);
|
sl@0
|
1549 |
g_test_add_func ("/testglib/File Paths", test_paths);
|
sl@0
|
1550 |
g_test_add_func ("/testglib/File Functions", test_file_functions);
|
sl@0
|
1551 |
g_test_add_func ("/testglib/Parse Debug Strings", test_g_parse_debug_string);
|
sl@0
|
1552 |
|
sl@0
|
1553 |
#ifndef G_DISABLE_DEPRECATED
|
sl@0
|
1554 |
g_test_add_func ("/testglib/GMemChunk (deprecated)", test_mem_chunks);
|
sl@0
|
1555 |
#endif
|
sl@0
|
1556 |
g_test_add_func ("/testglib/Warnings & Errors", log_warning_error_tests);
|
sl@0
|
1557 |
g_test_add_func ("/testglib/Timers (slow)", timer_tests);
|
sl@0
|
1558 |
/* return */g_test_run();
|
sl@0
|
1559 |
#ifdef __SYMBIAN32__
|
sl@0
|
1560 |
testResultXml("testglib");
|
sl@0
|
1561 |
#endif /* EMULATOR */
|
sl@0
|
1562 |
return 0;
|
sl@0
|
1563 |
|
sl@0
|
1564 |
}
|