1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/glib/tests/testglib.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,1564 @@
1.4 +/* GLIB - Library of useful routines for C programming
1.5 + * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
1.6 + * Portion Copyright © 2008-09 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
1.7 + * This library is free software; you can redistribute it and/or
1.8 + * modify it under the terms of the GNU Lesser General Public
1.9 + * License as published by the Free Software Foundation; either
1.10 + * version 2 of the License, or (at your option) any later version.
1.11 + *
1.12 + * This library is distributed in the hope that it will be useful,
1.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1.15 + * Lesser General Public License for more details.
1.16 + *
1.17 + * You should have received a copy of the GNU Lesser General Public
1.18 + * License along with this library; if not, write to the
1.19 + * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
1.20 + * Boston, MA 02111-1307, USA.
1.21 + */
1.22 +
1.23 +/*
1.24 + * Modified by the GLib Team and others 1997-2000. See the AUTHORS
1.25 + * file for a list of people on the GLib Team. See the ChangeLog
1.26 + * files for a list of changes. These files are distributed with
1.27 + * GLib at ftp://ftp.gtk.org/pub/gtk/.
1.28 + */
1.29 +
1.30 +#include "config.h"
1.31 +
1.32 +#undef GLIB_COMPILATION
1.33 +
1.34 +#include <stdio.h>
1.35 +#include <string.h>
1.36 +#include <errno.h>
1.37 +
1.38 +#include "glib.h"
1.39 +#include <glib/gstdio.h>
1.40 +
1.41 +#ifdef __SYMBIAN32__
1.42 +#include <sys/stat.h>
1.43 +#include <glib_global.h>
1.44 +#include "mrt2_glib2_test.h"
1.45 +#endif /*__SYMBIAN32__*/
1.46 +
1.47 +#ifdef HAVE_UNISTD_H
1.48 +#include <unistd.h>
1.49 +#endif
1.50 +
1.51 +#ifdef G_OS_WIN32
1.52 +#include <io.h> /* For read(), write() etc */
1.53 +#endif
1.54 +
1.55 +
1.56 +#define GLIB_TEST_STRING "el dorado "
1.57 +#define GLIB_TEST_STRING_5 "el do"
1.58 +
1.59 +
1.60 +/* --- variables --- */
1.61 +static gint test_nums[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
1.62 +static gint more_nums[10] = { 8, 9, 7, 0, 3, 2, 5, 1, 4, 6};
1.63 +
1.64 +/* --- functions --- */
1.65 +static gint
1.66 +my_list_compare_one (gconstpointer a, gconstpointer b)
1.67 +{
1.68 + gint one = *((const gint*)a);
1.69 + gint two = *((const gint*)b);
1.70 + return one-two;
1.71 +}
1.72 +
1.73 +static gint
1.74 +my_list_compare_two (gconstpointer a, gconstpointer b)
1.75 +{
1.76 + gint one = *((const gint*)a);
1.77 + gint two = *((const gint*)b);
1.78 + return two-one;
1.79 +}
1.80 +
1.81 +/* static void
1.82 +my_list_print (gpointer a, gpointer b)
1.83 +{
1.84 + gint three = *((gint*)a);
1.85 + g_print("%d", three);
1.86 +}; */
1.87 +
1.88 +static void
1.89 +glist_test (void)
1.90 +{
1.91 + GList *list = NULL;
1.92 + guint i;
1.93 +
1.94 + for (i = 0; i < 10; i++)
1.95 + list = g_list_append (list, &test_nums[i]);
1.96 + list = g_list_reverse (list);
1.97 +
1.98 + for (i = 0; i < 10; i++)
1.99 + {
1.100 + GList *t = g_list_nth (list, i);
1.101 + if (*((gint*) t->data) != (9 - i))
1.102 + g_error ("Regular insert failed");
1.103 + }
1.104 +
1.105 + for (i = 0; i < 10; i++)
1.106 + if (g_list_position (list, g_list_nth (list, i)) != i)
1.107 + g_error ("g_list_position does not seem to be the inverse of g_list_nth\n");
1.108 +
1.109 + g_list_free (list);
1.110 + list = NULL;
1.111 +
1.112 + for (i = 0; i < 10; i++)
1.113 + list = g_list_insert_sorted (list, &more_nums[i], my_list_compare_one);
1.114 +
1.115 + /*
1.116 + g_print("\n");
1.117 + g_list_foreach (list, my_list_print, NULL);
1.118 + */
1.119 +
1.120 + for (i = 0; i < 10; i++)
1.121 + {
1.122 + GList *t = g_list_nth (list, i);
1.123 + if (*((gint*) t->data) != i)
1.124 + g_error ("Sorted insert failed");
1.125 + }
1.126 +
1.127 + g_list_free (list);
1.128 + list = NULL;
1.129 +
1.130 + for (i = 0; i < 10; i++)
1.131 + list = g_list_insert_sorted (list, &more_nums[i], my_list_compare_two);
1.132 +
1.133 + /*
1.134 + g_print("\n");
1.135 + g_list_foreach (list, my_list_print, NULL);
1.136 + */
1.137 +
1.138 + for (i = 0; i < 10; i++)
1.139 + {
1.140 + GList *t = g_list_nth (list, i);
1.141 + if (*((gint*) t->data) != (9 - i))
1.142 + g_error ("Sorted insert failed");
1.143 + }
1.144 +
1.145 + g_list_free (list);
1.146 + list = NULL;
1.147 +
1.148 + for (i = 0; i < 10; i++)
1.149 + list = g_list_prepend (list, &more_nums[i]);
1.150 +
1.151 + list = g_list_sort (list, my_list_compare_two);
1.152 +
1.153 + /*
1.154 + g_print("\n");
1.155 + g_list_foreach (list, my_list_print, NULL);
1.156 + */
1.157 +
1.158 + for (i = 0; i < 10; i++)
1.159 + {
1.160 + GList *t = g_list_nth (list, i);
1.161 + if (*((gint*) t->data) != (9 - i))
1.162 + g_error ("Merge sort failed");
1.163 + }
1.164 +
1.165 + g_list_free (list);
1.166 +}
1.167 +
1.168 +static void
1.169 +gslist_test (void)
1.170 +{
1.171 + GSList *slist = NULL;
1.172 + guint i;
1.173 +
1.174 + for (i = 0; i < 10; i++)
1.175 + slist = g_slist_append (slist, &test_nums[i]);
1.176 + slist = g_slist_reverse (slist);
1.177 +
1.178 + for (i = 0; i < 10; i++)
1.179 + {
1.180 + GSList *st = g_slist_nth (slist, i);
1.181 + if (*((gint*) st->data) != (9 - i))
1.182 + g_error ("failed");
1.183 + }
1.184 +
1.185 + g_slist_free (slist);
1.186 + slist = NULL;
1.187 +
1.188 + for (i = 0; i < 10; i++)
1.189 + slist = g_slist_insert_sorted (slist, &more_nums[i], my_list_compare_one);
1.190 +
1.191 + /*
1.192 + g_print("\n");
1.193 + g_slist_foreach (slist, my_list_print, NULL);
1.194 + */
1.195 +
1.196 + for (i = 0; i < 10; i++)
1.197 + {
1.198 + GSList *st = g_slist_nth (slist, i);
1.199 + if (*((gint*) st->data) != i)
1.200 + g_error ("Sorted insert failed");
1.201 + }
1.202 +
1.203 + g_slist_free (slist);
1.204 + slist = NULL;
1.205 +
1.206 + for (i = 0; i < 10; i++)
1.207 + slist = g_slist_insert_sorted (slist, &more_nums[i], my_list_compare_two);
1.208 +
1.209 + /*
1.210 + g_print("\n");
1.211 + g_slist_foreach (slist, my_list_print, NULL);
1.212 + */
1.213 +
1.214 + for (i = 0; i < 10; i++)
1.215 + {
1.216 + GSList *st = g_slist_nth (slist, i);
1.217 + if (*((gint*) st->data) != (9 - i))
1.218 + g_error("Sorted insert failed");
1.219 + }
1.220 +
1.221 + g_slist_free(slist);
1.222 + slist = NULL;
1.223 +
1.224 + for (i = 0; i < 10; i++)
1.225 + slist = g_slist_prepend (slist, &more_nums[i]);
1.226 +
1.227 + slist = g_slist_sort (slist, my_list_compare_two);
1.228 +
1.229 + /*
1.230 + g_print("\n");
1.231 + g_slist_foreach (slist, my_list_print, NULL);
1.232 + */
1.233 +
1.234 + for (i = 0; i < 10; i++)
1.235 + {
1.236 + GSList *st = g_slist_nth (slist, i);
1.237 + if (*((gint*) st->data) != (9 - i))
1.238 + g_error("Sorted insert failed");
1.239 + }
1.240 +
1.241 + g_slist_free(slist);
1.242 +}
1.243 +
1.244 +static gboolean
1.245 +node_build_string (GNode *node,
1.246 + gpointer data)
1.247 +{
1.248 + gchar **p = data;
1.249 + gchar *string;
1.250 + gchar c[2] = "_";
1.251 +
1.252 + c[0] = ((gchar) ((gintptr) (node->data)));
1.253 +
1.254 + string = g_strconcat (*p ? *p : "", c, NULL);
1.255 + g_free (*p);
1.256 + *p = string;
1.257 +
1.258 + return FALSE;
1.259 +}
1.260 +
1.261 +static void
1.262 +gnode_test (void)
1.263 +{
1.264 +#define C2P(c) ((gpointer) ((long) (c)))
1.265 +#define P2C(p) ((gchar) ((gintptr) (p)))
1.266 + GNode *root;
1.267 + GNode *node;
1.268 + GNode *node_B;
1.269 + GNode *node_F;
1.270 + GNode *node_G;
1.271 + GNode *node_J;
1.272 + guint i;
1.273 + gchar *tstring, *cstring;
1.274 +
1.275 + root = g_node_new (C2P ('A'));
1.276 + g_assert (g_node_depth (root) == 1 && g_node_max_height (root) == 1);
1.277 +
1.278 + node_B = g_node_new (C2P ('B'));
1.279 + g_node_append (root, node_B);
1.280 + g_assert (root->children == node_B);
1.281 +
1.282 + g_node_append_data (node_B, C2P ('E'));
1.283 + g_node_prepend_data (node_B, C2P ('C'));
1.284 + g_node_insert (node_B, 1, g_node_new (C2P ('D')));
1.285 +
1.286 + node_F = g_node_new (C2P ('F'));
1.287 + g_node_append (root, node_F);
1.288 + g_assert (root->children->next == node_F);
1.289 +
1.290 + node_G = g_node_new (C2P ('G'));
1.291 + g_node_append (node_F, node_G);
1.292 + node_J = g_node_new (C2P ('J'));
1.293 + g_node_prepend (node_G, node_J);
1.294 + g_node_insert (node_G, 42, g_node_new (C2P ('K')));
1.295 + g_node_insert_data (node_G, 0, C2P ('H'));
1.296 + g_node_insert (node_G, 1, g_node_new (C2P ('I')));
1.297 +
1.298 + g_assert (g_node_depth (root) == 1);
1.299 + g_assert (g_node_max_height (root) == 4);
1.300 + g_assert (g_node_depth (node_G->children->next) == 4);
1.301 + g_assert (g_node_n_nodes (root, G_TRAVERSE_LEAFS) == 7);
1.302 + g_assert (g_node_n_nodes (root, G_TRAVERSE_NON_LEAFS) == 4);
1.303 + g_assert (g_node_n_nodes (root, G_TRAVERSE_ALL) == 11);
1.304 + g_assert (g_node_max_height (node_F) == 3);
1.305 + g_assert (g_node_n_children (node_G) == 4);
1.306 + g_assert (g_node_find_child (root, G_TRAVERSE_ALL, C2P ('F')) == node_F);
1.307 + g_assert (g_node_find (root, G_LEVEL_ORDER, G_TRAVERSE_NON_LEAFS, C2P ('I')) == NULL);
1.308 + g_assert (g_node_find (root, G_IN_ORDER, G_TRAVERSE_LEAFS, C2P ('J')) == node_J);
1.309 +
1.310 + for (i = 0; i < g_node_n_children (node_B); i++)
1.311 + {
1.312 + node = g_node_nth_child (node_B, i);
1.313 + g_assert (P2C (node->data) == ('C' + i));
1.314 + }
1.315 +
1.316 + for (i = 0; i < g_node_n_children (node_G); i++)
1.317 + g_assert (g_node_child_position (node_G, g_node_nth_child (node_G, i)) == i);
1.318 +
1.319 + /* we have built: A
1.320 + * / \
1.321 + * B F
1.322 + * / | \ \
1.323 + * C D E G
1.324 + * / /\ \
1.325 + * H I J K
1.326 + *
1.327 + * for in-order traversal, 'G' is considered to be the "left"
1.328 + * child of 'F', which will cause 'F' to be the last node visited.
1.329 + */
1.330 +
1.331 + tstring = NULL;
1.332 + g_node_traverse (root, G_PRE_ORDER, G_TRAVERSE_ALL, -1, node_build_string, &tstring);
1.333 + g_assert_cmpstr (tstring, ==, "ABCDEFGHIJK");
1.334 + g_free (tstring); tstring = NULL;
1.335 + g_node_traverse (root, G_POST_ORDER, G_TRAVERSE_ALL, -1, node_build_string, &tstring);
1.336 + g_assert_cmpstr (tstring, ==, "CDEBHIJKGFA");
1.337 + g_free (tstring); tstring = NULL;
1.338 + g_node_traverse (root, G_IN_ORDER, G_TRAVERSE_ALL, -1, node_build_string, &tstring);
1.339 + g_assert_cmpstr (tstring, ==, "CBDEAHGIJKF");
1.340 + g_free (tstring); tstring = NULL;
1.341 + g_node_traverse (root, G_LEVEL_ORDER, G_TRAVERSE_ALL, -1, node_build_string, &tstring);
1.342 + g_assert_cmpstr (tstring, ==, "ABFCDEGHIJK");
1.343 + g_free (tstring); tstring = NULL;
1.344 +
1.345 + g_node_traverse (root, G_LEVEL_ORDER, G_TRAVERSE_LEAFS, -1, node_build_string, &tstring);
1.346 + g_assert_cmpstr (tstring, ==, "CDEHIJK");
1.347 + g_free (tstring); tstring = NULL;
1.348 + g_node_traverse (root, G_PRE_ORDER, G_TRAVERSE_NON_LEAFS, -1, node_build_string, &tstring);
1.349 + g_assert_cmpstr (tstring, ==, "ABFG");
1.350 + g_free (tstring); tstring = NULL;
1.351 +
1.352 + g_node_reverse_children (node_B);
1.353 + g_node_reverse_children (node_G);
1.354 +
1.355 + g_node_traverse (root, G_LEVEL_ORDER, G_TRAVERSE_ALL, -1, node_build_string, &tstring);
1.356 + g_assert_cmpstr (tstring, ==, "ABFEDCGKJIH");
1.357 + g_free (tstring); tstring = NULL;
1.358 +
1.359 + cstring = NULL;
1.360 + node = g_node_copy (root);
1.361 + g_assert (g_node_n_nodes (root, G_TRAVERSE_ALL) == g_node_n_nodes (node, G_TRAVERSE_ALL));
1.362 + g_assert (g_node_max_height (root) == g_node_max_height (node));
1.363 + g_node_traverse (root, G_IN_ORDER, G_TRAVERSE_ALL, -1, node_build_string, &tstring);
1.364 + g_node_traverse (node, G_IN_ORDER, G_TRAVERSE_ALL, -1, node_build_string, &cstring);
1.365 + g_assert_cmpstr (tstring, ==, cstring);
1.366 + g_free (tstring); tstring = NULL;
1.367 + g_free (cstring); cstring = NULL;
1.368 + g_node_destroy (node);
1.369 +
1.370 + g_node_destroy (root);
1.371 +
1.372 + /* allocation tests */
1.373 +
1.374 + root = g_node_new (NULL);
1.375 + node = root;
1.376 +
1.377 + for (i = 0; i < 2048; i++)
1.378 + {
1.379 + g_node_append (node, g_node_new (NULL));
1.380 + if ((i%5) == 4)
1.381 + node = node->children->next;
1.382 + }
1.383 + g_assert (g_node_max_height (root) > 100);
1.384 + g_assert (g_node_n_nodes (root, G_TRAVERSE_ALL) == 1 + 2048);
1.385 +
1.386 + g_node_destroy (root);
1.387 +#undef C2P
1.388 +#undef P2C
1.389 +}
1.390 +
1.391 +static gint
1.392 +my_compare (gconstpointer a,
1.393 + gconstpointer b)
1.394 +{
1.395 + const char *cha = a;
1.396 + const char *chb = b;
1.397 +
1.398 + return *cha - *chb;
1.399 +}
1.400 +
1.401 +static gint
1.402 +my_traverse (gpointer key,
1.403 + gpointer value,
1.404 + gpointer data)
1.405 +{
1.406 + char *ch = key;
1.407 + g_print ("%c ", *ch);
1.408 + return FALSE;
1.409 +}
1.410 +
1.411 +static void
1.412 +binary_tree_test (void)
1.413 +{
1.414 + GTree *tree;
1.415 + char chars[62];
1.416 + guint i, j;
1.417 +
1.418 + tree = g_tree_new (my_compare);
1.419 + i = 0;
1.420 + for (j = 0; j < 10; j++, i++)
1.421 + {
1.422 + chars[i] = '0' + j;
1.423 + g_tree_insert (tree, &chars[i], &chars[i]);
1.424 + }
1.425 + for (j = 0; j < 26; j++, i++)
1.426 + {
1.427 + chars[i] = 'A' + j;
1.428 + g_tree_insert (tree, &chars[i], &chars[i]);
1.429 + }
1.430 + for (j = 0; j < 26; j++, i++)
1.431 + {
1.432 + chars[i] = 'a' + j;
1.433 + g_tree_insert (tree, &chars[i], &chars[i]);
1.434 + }
1.435 +
1.436 + g_assert_cmpint (g_tree_nnodes (tree), ==, 10 + 26 + 26);
1.437 + g_assert_cmpint (g_tree_height (tree), ==, 6);
1.438 +
1.439 + if (g_test_verbose())
1.440 + {
1.441 + g_print ("tree: ");
1.442 + g_tree_foreach (tree, my_traverse, NULL);
1.443 + g_print ("\n");
1.444 + }
1.445 +
1.446 + for (i = 0; i < 10; i++)
1.447 + g_tree_remove (tree, &chars[i]);
1.448 +
1.449 + g_assert_cmpint (g_tree_nnodes (tree), ==, 26 + 26);
1.450 + g_assert_cmpint (g_tree_height (tree), ==, 6);
1.451 +
1.452 + if (g_test_verbose())
1.453 + {
1.454 + g_print ("tree: ");
1.455 + g_tree_foreach (tree, my_traverse, NULL);
1.456 + g_print ("\n");
1.457 + }
1.458 +}
1.459 +
1.460 +static gboolean
1.461 +my_hash_callback_remove (gpointer key,
1.462 + gpointer value,
1.463 + gpointer user_data)
1.464 +{
1.465 + int *d = value;
1.466 +
1.467 + if ((*d) % 2)
1.468 + return TRUE;
1.469 +
1.470 + return FALSE;
1.471 +}
1.472 +
1.473 +static void
1.474 +my_hash_callback_remove_test (gpointer key,
1.475 + gpointer value,
1.476 + gpointer user_data)
1.477 +{
1.478 + int *d = value;
1.479 +
1.480 + if ((*d) % 2)
1.481 + g_print ("bad!\n");
1.482 +}
1.483 +
1.484 +static void
1.485 +my_hash_callback (gpointer key,
1.486 + gpointer value,
1.487 + gpointer user_data)
1.488 +{
1.489 + int *d = value;
1.490 + *d = 1;
1.491 +}
1.492 +
1.493 +static guint
1.494 +my_hash (gconstpointer key)
1.495 +{
1.496 + return (guint) *((const gint*) key);
1.497 +}
1.498 +
1.499 +static gboolean
1.500 +my_hash_equal (gconstpointer a,
1.501 + gconstpointer b)
1.502 +{
1.503 + return *((const gint*) a) == *((const gint*) b);
1.504 +}
1.505 +
1.506 +static gboolean
1.507 +find_first_that(gpointer key,
1.508 + gpointer value,
1.509 + gpointer user_data)
1.510 +{
1.511 + gint *v = value;
1.512 + gint *test = user_data;
1.513 + return (*v == *test);
1.514 +}
1.515 +
1.516 +static void
1.517 +test_g_parse_debug_string (void)
1.518 +{
1.519 + GDebugKey keys[3] = {
1.520 + { "foo", 1 },
1.521 + { "bar", 2 },
1.522 + { "baz", 4 }
1.523 + };
1.524 + guint n_keys = 3;
1.525 + guint result;
1.526 +
1.527 + result = g_parse_debug_string ("bar:foo:blubb", keys, n_keys);
1.528 + g_assert (result == 3);
1.529 +
1.530 + result = g_parse_debug_string (":baz::_E@~!_::", keys, n_keys);
1.531 + g_assert (result == 4);
1.532 +
1.533 + result = g_parse_debug_string ("", keys, n_keys);
1.534 + g_assert (result == 0);
1.535 +
1.536 + result = g_parse_debug_string (" : ", keys, n_keys);
1.537 + g_assert (result == 0);
1.538 +}
1.539 +
1.540 +static void
1.541 +log_warning_error_tests (void)
1.542 +{
1.543 + if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR))
1.544 + {
1.545 + g_message ("this is a g_message test.");
1.546 + g_message ("non-printable UTF-8: \"\xc3\xa4\xda\x85\"");
1.547 + g_message ("unsafe chars: \"\x10\x11\x12\n\t\x7f\x81\x82\x83\"");
1.548 + exit (0);
1.549 + }
1.550 + g_test_trap_assert_passed();
1.551 + g_test_trap_assert_stderr ("*is a g_message test*");
1.552 + g_test_trap_assert_stderr ("*non-printable UTF-8*");
1.553 + g_test_trap_assert_stderr ("*unsafe chars*");
1.554 + if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR))
1.555 + {
1.556 + g_warning ("harmless warning with parameters: %d %s %#x", 42, "Boo", 12345);
1.557 + exit (0);
1.558 + }
1.559 + g_test_trap_assert_failed(); /* we have fatal-warnings enabled */
1.560 + g_test_trap_assert_stderr ("*harmless warning*");
1.561 + if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR))
1.562 + {
1.563 + g_print (NULL);
1.564 + exit (0);
1.565 + }
1.566 + g_test_trap_assert_failed(); /* we have fatal-warnings enabled */
1.567 + g_test_trap_assert_stderr ("*g_print*assertion*failed*");
1.568 + g_test_trap_assert_stderr ("*NULL*");
1.569 +}
1.570 +
1.571 +static void
1.572 +timer_tests (void)
1.573 +{
1.574 + GTimer *timer, *timer2;
1.575 + gdouble elapsed;
1.576 +
1.577 + /* basic testing */
1.578 + timer = g_timer_new ();
1.579 + g_timer_start (timer);
1.580 + elapsed = g_timer_elapsed (timer, NULL);
1.581 + g_timer_stop (timer);
1.582 + g_assert_cmpfloat (elapsed, <=, g_timer_elapsed (timer, NULL));
1.583 + g_timer_destroy (timer);
1.584 +
1.585 + if (g_test_slow())
1.586 + {
1.587 + if (g_test_verbose())
1.588 + g_print ("checking timers...\n");
1.589 + timer = g_timer_new ();
1.590 + if (g_test_verbose())
1.591 + g_print (" spinning for 3 seconds...\n");
1.592 + g_timer_start (timer);
1.593 + while (g_timer_elapsed (timer, NULL) < 3)
1.594 + ;
1.595 + g_timer_stop (timer);
1.596 + g_timer_destroy (timer);
1.597 + if (g_test_verbose())
1.598 + g_print ("ok\n");
1.599 + }
1.600 +
1.601 + if (g_test_slow())
1.602 + {
1.603 + gulong elapsed_usecs;
1.604 + if (g_test_verbose())
1.605 + g_print ("checking g_timer_continue...\n");
1.606 + timer2 = g_timer_new ();
1.607 + if (g_test_verbose())
1.608 + g_print ("\trun for 1 second...\n");
1.609 + timer = g_timer_new();
1.610 + g_usleep (G_USEC_PER_SEC); /* run timer for 1 second */
1.611 + g_timer_stop (timer);
1.612 + if (g_test_verbose())
1.613 + g_print ("\tstop for 1 second...\n");
1.614 + g_usleep (G_USEC_PER_SEC); /* wait for 1 second */
1.615 + if (g_test_verbose())
1.616 + g_print ("\trun for 2 seconds...\n");
1.617 + g_timer_continue (timer);
1.618 + g_usleep (2 * G_USEC_PER_SEC); /* run timer for 2 seconds */
1.619 + g_timer_stop(timer);
1.620 + if (g_test_verbose())
1.621 + g_print ("\tstop for 1.5 seconds...\n");
1.622 + g_usleep ((3 * G_USEC_PER_SEC) / 2); /* wait for 1.5 seconds */
1.623 + if (g_test_verbose())
1.624 + g_print ("\trun for 0.2 seconds...\n");
1.625 + g_timer_continue (timer);
1.626 + g_usleep (G_USEC_PER_SEC / 5); /* run timer for 0.2 seconds */
1.627 + g_timer_stop (timer);
1.628 + if (g_test_verbose())
1.629 + g_print ("\tstop for 4 seconds...\n");
1.630 + g_usleep (4 * G_USEC_PER_SEC); /* wait for 4 seconds */
1.631 + if (g_test_verbose())
1.632 + g_print ("\trun for 5.8 seconds...\n");
1.633 + g_timer_continue (timer);
1.634 + g_usleep ((29 * G_USEC_PER_SEC) / 5); /* run timer for 5.8 seconds */
1.635 + g_timer_stop(timer);
1.636 + elapsed = g_timer_elapsed (timer, &elapsed_usecs);
1.637 + if (g_test_verbose())
1.638 + g_print ("\t=> timer = %.6f = %d.%06ld (should be: 9.000000) (%.6f off)\n", elapsed, (int) elapsed, elapsed_usecs, ABS (elapsed - 9.));
1.639 + g_assert_cmpfloat (elapsed, >, 8.8);
1.640 + g_assert_cmpfloat (elapsed, <, 9.2);
1.641 + if (g_test_verbose())
1.642 + g_print ("g_timer_continue ... ok\n\n");
1.643 + g_timer_stop (timer2);
1.644 + elapsed = g_timer_elapsed (timer2, &elapsed_usecs);
1.645 + if (g_test_verbose())
1.646 + 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)));
1.647 + g_assert_cmpfloat (elapsed, >, 8.8 + 6.5);
1.648 + g_assert_cmpfloat (elapsed, <, 9.2 + 6.5);
1.649 + if (g_test_verbose())
1.650 + g_print ("timer2 ... ok\n\n");
1.651 + g_timer_destroy (timer);
1.652 + g_timer_destroy (timer2);
1.653 + }
1.654 +}
1.655 +
1.656 +static void
1.657 +type_sizes (void)
1.658 +{
1.659 + guint16 gu16t1 = 0x44afU, gu16t2 = 0xaf44U;
1.660 + guint32 gu32t1 = 0x02a7f109U, gu32t2 = 0x09f1a702U;
1.661 + guint64 gu64t1 = G_GINT64_CONSTANT(0x1d636b02300a7aa7U),
1.662 + gu64t2 = G_GINT64_CONSTANT(0xa77a0a30026b631dU);
1.663 + /* type sizes */
1.664 + g_assert_cmpint (sizeof (gint8), ==, 1);
1.665 + g_assert_cmpint (sizeof (gint16), ==, 2);
1.666 + g_assert_cmpint (sizeof (gint32), ==, 4);
1.667 + g_assert_cmpint (sizeof (gint64), ==, 8);
1.668 + /* endian macros */
1.669 + if (g_test_verbose())
1.670 + g_print ("checking endian macros (host is %s)...\n",
1.671 + G_BYTE_ORDER == G_BIG_ENDIAN ? "big endian" : "little endian");
1.672 + g_assert (GUINT16_SWAP_LE_BE (gu16t1) == gu16t2);
1.673 + g_assert (GUINT32_SWAP_LE_BE (gu32t1) == gu32t2);
1.674 + g_assert (GUINT64_SWAP_LE_BE (gu64t1) == gu64t2);
1.675 +}
1.676 +
1.677 +static void
1.678 +test_info (void)
1.679 +{
1.680 + const gchar *un, *rn, *hn;
1.681 + const gchar *tmpdir, *homedir, *userdatadir, *uconfdir, *ucachedir;
1.682 + const gchar *uddesktop, *udddocs, *uddpubshare;
1.683 + gchar **sv, *cwd, *sdatadirs, *sconfdirs, *langnames;
1.684 + if (g_test_verbose())
1.685 + g_print ("TestGLib v%u.%u.%u (i:%u b:%u)\n",
1.686 + glib_major_version,
1.687 + glib_minor_version,
1.688 + glib_micro_version,
1.689 + glib_interface_age,
1.690 + glib_binary_age);
1.691 +
1.692 + cwd = g_get_current_dir ();
1.693 + un = g_get_user_name();
1.694 + rn = g_get_real_name();
1.695 + hn = g_get_host_name();
1.696 + if (g_test_verbose())
1.697 + {
1.698 + g_print ("cwd: %s\n", cwd);
1.699 + g_print ("user: %s\n", un);
1.700 + g_print ("real: %s\n", rn);
1.701 + g_print ("host: %s\n", hn);
1.702 + }
1.703 + g_free (cwd);
1.704 +
1.705 + tmpdir = g_get_tmp_dir();
1.706 + g_assert (tmpdir != NULL);
1.707 + homedir = g_get_home_dir ();
1.708 + g_assert (homedir != NULL);
1.709 + userdatadir = g_get_user_data_dir ();
1.710 + g_assert (userdatadir != NULL);
1.711 + uconfdir = g_get_user_config_dir ();
1.712 + g_assert (uconfdir != NULL);
1.713 + ucachedir = g_get_user_cache_dir ();
1.714 + g_assert (ucachedir != NULL);
1.715 +
1.716 + uddesktop = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
1.717 + g_assert (uddesktop != NULL);
1.718 + udddocs = g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS);
1.719 + uddpubshare = g_get_user_special_dir (G_USER_DIRECTORY_PUBLIC_SHARE);
1.720 +
1.721 + sv = (gchar **) g_get_system_data_dirs ();
1.722 + sdatadirs = g_strjoinv (G_SEARCHPATH_SEPARATOR_S, sv);
1.723 + sv = (gchar **) g_get_system_config_dirs ();
1.724 + sconfdirs = g_strjoinv (G_SEARCHPATH_SEPARATOR_S, sv);
1.725 + sv = (gchar **) g_get_language_names ();
1.726 + langnames = g_strjoinv (":", sv);
1.727 +
1.728 + if (g_test_verbose())
1.729 + {
1.730 + g_print ("tmp-dir: %s\n", tmpdir);
1.731 + g_print ("home: %s\n", homedir);
1.732 + g_print ("user_data: %s\n", userdatadir);
1.733 + g_print ("user_config: %s\n", uconfdir);
1.734 + g_print ("user_cache: %s\n", ucachedir);
1.735 + g_print ("system_data: %s\n", sdatadirs);
1.736 + g_print ("system_config: %s\n", sconfdirs);
1.737 + g_print ("languages: %s\n", langnames);
1.738 + g_print ("user_special[DESKTOP]: %s\n", uddesktop);
1.739 + g_print ("user_special[DOCUMENTS]: %s\n", udddocs);
1.740 + g_print ("user_special[PUBLIC_SHARE]: %s\n", uddpubshare);
1.741 + }
1.742 + g_free (sdatadirs);
1.743 + g_free (sconfdirs);
1.744 + g_free (langnames);
1.745 +
1.746 + if (g_test_verbose())
1.747 + {
1.748 +#ifdef G_PLATFORM_WIN32
1.749 + gchar *glib_dll;
1.750 +#endif
1.751 + const gchar *charset;
1.752 + if (g_get_charset ((G_CONST_RETURN char**)&charset))
1.753 + g_print ("current charset is UTF-8: %s\n", charset);
1.754 + else
1.755 + g_print ("current charset is not UTF-8: %s\n", charset);
1.756 +
1.757 +#ifdef G_PLATFORM_WIN32
1.758 +#ifdef G_OS_WIN32
1.759 + /* Can't calculate GLib DLL name at runtime. */
1.760 + glib_dll = "libglib-2.0-0.dll";
1.761 +#endif
1.762 +#ifdef G_WITH_CYGWIN
1.763 + glib_dll = "cygglib-2.0-0.dll";
1.764 +#endif
1.765 +
1.766 + g_print ("current locale: %s\n", g_win32_getlocale ());
1.767 + g_print ("GLib DLL name tested for: %s\n", glib_dll);
1.768 +
1.769 + g_print ("GLib installation directory, from Registry entry for %s if available: %s\n",
1.770 + GETTEXT_PACKAGE,
1.771 + g_win32_get_package_installation_directory (GETTEXT_PACKAGE, NULL));
1.772 + g_print ("Ditto, or from GLib DLL name: %s\n",
1.773 + g_win32_get_package_installation_directory (GETTEXT_PACKAGE, glib_dll));
1.774 + g_print ("Ditto, only from GLib DLL name: %s\n",
1.775 + g_win32_get_package_installation_directory (NULL, glib_dll));
1.776 + g_print ("locale subdirectory of GLib installation directory: %s\n",
1.777 + g_win32_get_package_installation_subdirectory (NULL, glib_dll, "lib\\locale"));
1.778 + g_print ("GTK+ 2.0 installation directory, if available: %s\n",
1.779 + g_win32_get_package_installation_directory ("gtk20", NULL));
1.780 +
1.781 + g_print ("found more.com as %s\n", g_find_program_in_path ("more.com"));
1.782 + g_print ("found regedit as %s\n", g_find_program_in_path ("regedit"));
1.783 +
1.784 + g_print ("a Win32 error message: %s\n", g_win32_error_message (2));
1.785 +#endif
1.786 + }
1.787 +}
1.788 +
1.789 +static void
1.790 +test_paths (void)
1.791 +{
1.792 + struct {
1.793 + gchar *filename;
1.794 + gchar *dirname;
1.795 + } dirname_checks[] = {
1.796 + { "/", "/" },
1.797 + { "////", "/" },
1.798 + { ".////", "." },
1.799 + { "../", ".." },
1.800 + { "..////", ".." },
1.801 + { "a/b", "a" },
1.802 + { "a/b/", "a/b" },
1.803 + { "c///", "c" },
1.804 +#ifdef G_OS_WIN32
1.805 + { "\\", "\\" },
1.806 + { ".\\\\\\\\", "." },
1.807 + { "..\\", ".." },
1.808 + { "..\\\\\\\\", ".." },
1.809 + { "a\\b", "a" },
1.810 + { "a\\b/", "a\\b" },
1.811 + { "a/b\\", "a/b" },
1.812 + { "c\\\\/", "c" },
1.813 + { "//\\", "/" },
1.814 +#endif
1.815 +#ifdef G_WITH_CYGWIN
1.816 + { "//server/share///x", "//server/share" },
1.817 +#endif
1.818 + { ".", "." },
1.819 + { "..", "." },
1.820 + { "", "." },
1.821 + };
1.822 + const guint n_dirname_checks = G_N_ELEMENTS (dirname_checks);
1.823 + struct {
1.824 + gchar *filename;
1.825 + gchar *without_root;
1.826 + } skip_root_checks[] = {
1.827 + { "/", "" },
1.828 + { "//", "" },
1.829 + { "/foo", "foo" },
1.830 + { "//foo", "foo" },
1.831 + { "a/b", NULL },
1.832 +#ifdef G_OS_WIN32
1.833 + { "\\", "" },
1.834 + { "\\foo", "foo" },
1.835 + { "\\\\server\\foo", "" },
1.836 + { "\\\\server\\foo\\bar", "bar" },
1.837 + { "a\\b", NULL },
1.838 +#endif
1.839 +#ifdef G_WITH_CYGWIN
1.840 + { "//server/share///x", "//x" },
1.841 +#endif
1.842 + { ".", NULL },
1.843 + { "", NULL },
1.844 + };
1.845 + const guint n_skip_root_checks = G_N_ELEMENTS (skip_root_checks);
1.846 + gchar *string;
1.847 + guint i;
1.848 + if (g_test_verbose())
1.849 + g_print ("checking g_path_get_basename()...");
1.850 + string = g_path_get_basename (G_DIR_SEPARATOR_S "foo" G_DIR_SEPARATOR_S "dir" G_DIR_SEPARATOR_S);
1.851 + g_assert (strcmp (string, "dir") == 0);
1.852 + g_free (string);
1.853 + string = g_path_get_basename (G_DIR_SEPARATOR_S "foo" G_DIR_SEPARATOR_S "file");
1.854 + g_assert (strcmp (string, "file") == 0);
1.855 + g_free (string);
1.856 + if (g_test_verbose())
1.857 + g_print ("ok\n");
1.858 +
1.859 +#ifdef G_OS_WIN32
1.860 + string = g_path_get_basename ("/foo/dir/");
1.861 + g_assert (strcmp (string, "dir") == 0);
1.862 + g_free (string);
1.863 + string = g_path_get_basename ("/foo/file");
1.864 + g_assert (strcmp (string, "file") == 0);
1.865 + g_free (string);
1.866 +#endif
1.867 +
1.868 + if (g_test_verbose())
1.869 + g_print ("checking g_path_get_dirname()...");
1.870 + for (i = 0; i < n_dirname_checks; i++)
1.871 + {
1.872 + gchar *dirname = g_path_get_dirname (dirname_checks[i].filename);
1.873 + if (strcmp (dirname, dirname_checks[i].dirname) != 0)
1.874 + {
1.875 + g_error ("\nfailed for \"%s\"==\"%s\" (returned: \"%s\")\n",
1.876 + dirname_checks[i].filename,
1.877 + dirname_checks[i].dirname,
1.878 + dirname);
1.879 + }
1.880 + g_free (dirname);
1.881 + }
1.882 + if (g_test_verbose())
1.883 + g_print ("ok\n");
1.884 +
1.885 + if (g_test_verbose())
1.886 + g_print ("checking g_path_skip_root()...");
1.887 + for (i = 0; i < n_skip_root_checks; i++)
1.888 + {
1.889 + const gchar *skipped = g_path_skip_root (skip_root_checks[i].filename);
1.890 + if ((skipped && !skip_root_checks[i].without_root) ||
1.891 + (!skipped && skip_root_checks[i].without_root) ||
1.892 + ((skipped && skip_root_checks[i].without_root) &&
1.893 + strcmp (skipped, skip_root_checks[i].without_root)))
1.894 + {
1.895 + g_error ("\nfailed for \"%s\"==\"%s\" (returned: \"%s\")\n",
1.896 + skip_root_checks[i].filename,
1.897 + (skip_root_checks[i].without_root ?
1.898 + skip_root_checks[i].without_root : "<NULL>"),
1.899 + (skipped ? skipped : "<NULL>"));
1.900 + }
1.901 + }
1.902 + if (g_test_verbose())
1.903 + g_print ("ok\n");
1.904 +}
1.905 +
1.906 +static void
1.907 +test_file_functions (void)
1.908 +{
1.909 + const char hello[] = "Hello, World";
1.910 + const int hellolen = sizeof (hello) - 1;
1.911 + GError *error;
1.912 + char template[32];
1.913 + char *name_used, chars[62];
1.914 + gint fd, n;
1.915 +
1.916 + strcpy (template, "c:\\foobar");
1.917 + fd = g_mkstemp (template);
1.918 + if (g_test_verbose() && fd != -1)
1.919 + g_print ("g_mkstemp works even if template doesn't end in XXXXXX\n");
1.920 + close (fd);
1.921 + strcpy (template, "c:\\fooXXXXXX");
1.922 + fd = g_mkstemp (template);
1.923 + if (fd == -1)
1.924 + g_error ("g_mkstemp didn't work for template %s\n", template);
1.925 + n = write (fd, hello, hellolen);
1.926 + if (n == -1)
1.927 + g_error ("write() failed: %s\n", g_strerror (errno));
1.928 + else if (n != hellolen)
1.929 + g_error ("write() should have written %d bytes, wrote %d\n", hellolen, n);
1.930 +
1.931 + lseek (fd, 0, 0);
1.932 + n = read (fd, chars, sizeof (chars));
1.933 + if (n == -1)
1.934 + g_error ("read() failed: %s\n", g_strerror (errno));
1.935 + else if (n != hellolen)
1.936 + g_error ("read() should have read %d bytes, got %d\n", hellolen, n);
1.937 +
1.938 + chars[n] = 0;
1.939 + if (strcmp (chars, hello) != 0)
1.940 + g_error ("wrote '%s', but got '%s'\n", hello, chars);
1.941 +
1.942 + close (fd);
1.943 + remove (template);
1.944 +
1.945 + error = NULL;
1.946 + strcpy (template, "zap" G_DIR_SEPARATOR_S "barXXXXXX");
1.947 + fd = g_file_open_tmp (template, &name_used, &error);
1.948 + if (g_test_verbose())
1.949 + {
1.950 + if (fd != -1)
1.951 + g_print ("g_file_open_tmp works even if template contains '%s'\n", G_DIR_SEPARATOR_S);
1.952 + else
1.953 + g_print ("g_file_open_tmp correctly returns error: %s\n", error->message);
1.954 + }
1.955 + close (fd);
1.956 + g_clear_error (&error);
1.957 +
1.958 +#ifdef G_OS_WIN32
1.959 + strcpy (template, "zap/barXXXXXX");
1.960 + fd = g_file_open_tmp (template, &name_used, &error);
1.961 + if (g_test_verbose())
1.962 + {
1.963 + if (fd != -1)
1.964 + g_print ("g_file_open_tmp works even if template contains '/'\n");
1.965 + else
1.966 + g_print ("g_file_open_tmp correctly returns error: %s\n", error->message);
1.967 + }
1.968 + close (fd);
1.969 + g_clear_error (&error);
1.970 +#endif
1.971 +
1.972 + strcpy (template, "zapXXXXXX");
1.973 + fd = g_file_open_tmp (template, &name_used, &error);
1.974 + if (fd == -1)
1.975 + g_error ("g_file_open_tmp didn't work for template '%s': %s\n", template, error->message);
1.976 + else if (g_test_verbose())
1.977 + g_print ("g_file_open_tmp for template '%s' used name '%s'\n", template, name_used);
1.978 + close (fd);
1.979 + g_clear_error (&error);
1.980 + remove (name_used);
1.981 +
1.982 + fd = g_file_open_tmp (NULL, &name_used, &error);
1.983 + if (fd == -1)
1.984 + g_error ("g_file_open_tmp didn't work for a NULL template: %s\n", error->message);
1.985 + close (fd);
1.986 + g_clear_error (&error);
1.987 + remove (name_used);
1.988 +}
1.989 +
1.990 +static void
1.991 +test_arrays (void)
1.992 +{
1.993 + GByteArray *gbarray;
1.994 + GPtrArray *gparray;
1.995 + GArray *garray;
1.996 + guint i;
1.997 +
1.998 + gparray = g_ptr_array_new ();
1.999 + for (i = 0; i < 10000; i++)
1.1000 + g_ptr_array_add (gparray, GINT_TO_POINTER (i));
1.1001 + for (i = 0; i < 10000; i++)
1.1002 + if (g_ptr_array_index (gparray, i) != GINT_TO_POINTER (i))
1.1003 + g_error ("array fails: %p ( %p )\n", g_ptr_array_index (gparray, i), GINT_TO_POINTER (i));
1.1004 + g_ptr_array_free (gparray, TRUE);
1.1005 +
1.1006 + gbarray = g_byte_array_new ();
1.1007 + for (i = 0; i < 10000; i++)
1.1008 + g_byte_array_append (gbarray, (guint8*) "abcd", 4);
1.1009 + for (i = 0; i < 10000; i++)
1.1010 + {
1.1011 + g_assert (gbarray->data[4*i] == 'a');
1.1012 + g_assert (gbarray->data[4*i+1] == 'b');
1.1013 + g_assert (gbarray->data[4*i+2] == 'c');
1.1014 + g_assert (gbarray->data[4*i+3] == 'd');
1.1015 + }
1.1016 + g_byte_array_free (gbarray, TRUE);
1.1017 +
1.1018 + garray = g_array_new (FALSE, FALSE, sizeof (gint));
1.1019 + for (i = 0; i < 10000; i++)
1.1020 + g_array_append_val (garray, i);
1.1021 + for (i = 0; i < 10000; i++)
1.1022 + if (g_array_index (garray, gint, i) != i)
1.1023 + g_error ("failure: %d ( %d )\n", g_array_index (garray, gint, i), i);
1.1024 + g_array_free (garray, TRUE);
1.1025 +
1.1026 + garray = g_array_new (FALSE, FALSE, sizeof (gint));
1.1027 + for (i = 0; i < 100; i++)
1.1028 + g_array_prepend_val (garray, i);
1.1029 + for (i = 0; i < 100; i++)
1.1030 + if (g_array_index (garray, gint, i) != (100 - i - 1))
1.1031 + g_error ("failure: %d ( %d )\n", g_array_index (garray, gint, i), 100 - i - 1);
1.1032 + g_array_free (garray, TRUE);
1.1033 +}
1.1034 +
1.1035 +static void
1.1036 +hash_table_tests (void)
1.1037 +{
1.1038 + GHashTable *hash_table;
1.1039 + int array[10000];
1.1040 + gint *pvalue = NULL;
1.1041 + gint value = 120;
1.1042 + guint i;
1.1043 +
1.1044 + hash_table = g_hash_table_new (my_hash, my_hash_equal);
1.1045 + for (i = 0; i < 10000; i++)
1.1046 + {
1.1047 + array[i] = i;
1.1048 + g_hash_table_insert (hash_table, &array[i], &array[i]);
1.1049 + }
1.1050 + pvalue = g_hash_table_find (hash_table, find_first_that, &value);
1.1051 + if (*pvalue != value)
1.1052 + g_error ("g_hash_table_find failed");
1.1053 + g_hash_table_foreach (hash_table, my_hash_callback, NULL);
1.1054 + for (i = 0; i < 10000; i++)
1.1055 + if (array[i] == 0)
1.1056 + g_error ("hashtable-test: wrong value: %d\n", i);
1.1057 + for (i = 0; i < 10000; i++)
1.1058 + g_hash_table_remove (hash_table, &array[i]);
1.1059 + for (i = 0; i < 10000; i++)
1.1060 + {
1.1061 + array[i] = i;
1.1062 + g_hash_table_insert (hash_table, &array[i], &array[i]);
1.1063 + }
1.1064 + if (g_hash_table_foreach_remove (hash_table, my_hash_callback_remove, NULL) != 5000 ||
1.1065 + g_hash_table_size (hash_table) != 5000)
1.1066 + g_error ("hashtable removal failed\n");
1.1067 + g_hash_table_foreach (hash_table, my_hash_callback_remove_test, NULL);
1.1068 + g_hash_table_destroy (hash_table);
1.1069 +}
1.1070 +
1.1071 +static void
1.1072 +relation_test (void)
1.1073 +{
1.1074 + GRelation *relation = g_relation_new (2);
1.1075 + GTuples *tuples;
1.1076 + gint data [1024];
1.1077 + guint i;
1.1078 +
1.1079 + g_relation_index (relation, 0, g_int_hash, g_int_equal);
1.1080 + g_relation_index (relation, 1, g_int_hash, g_int_equal);
1.1081 +
1.1082 + for (i = 0; i < 1024; i += 1)
1.1083 + data[i] = i;
1.1084 +
1.1085 + for (i = 1; i < 1023; i += 1)
1.1086 + {
1.1087 + g_relation_insert (relation, data + i, data + i + 1);
1.1088 + g_relation_insert (relation, data + i, data + i - 1);
1.1089 + }
1.1090 +
1.1091 + for (i = 2; i < 1022; i += 1)
1.1092 + {
1.1093 + g_assert (! g_relation_exists (relation, data + i, data + i));
1.1094 + g_assert (! g_relation_exists (relation, data + i, data + i + 2));
1.1095 + g_assert (! g_relation_exists (relation, data + i, data + i - 2));
1.1096 + }
1.1097 +
1.1098 + for (i = 1; i < 1023; i += 1)
1.1099 + {
1.1100 + g_assert (g_relation_exists (relation, data + i, data + i + 1));
1.1101 + g_assert (g_relation_exists (relation, data + i, data + i - 1));
1.1102 + }
1.1103 +
1.1104 + for (i = 2; i < 1022; i += 1)
1.1105 + {
1.1106 + g_assert (g_relation_count (relation, data + i, 0) == 2);
1.1107 + g_assert (g_relation_count (relation, data + i, 1) == 2);
1.1108 + }
1.1109 +
1.1110 + g_assert (g_relation_count (relation, data, 0) == 0);
1.1111 +
1.1112 + g_assert (g_relation_count (relation, data + 42, 0) == 2);
1.1113 + g_assert (g_relation_count (relation, data + 43, 1) == 2);
1.1114 + g_assert (g_relation_count (relation, data + 41, 1) == 2);
1.1115 + g_relation_delete (relation, data + 42, 0);
1.1116 + g_assert (g_relation_count (relation, data + 42, 0) == 0);
1.1117 + g_assert (g_relation_count (relation, data + 43, 1) == 1);
1.1118 + g_assert (g_relation_count (relation, data + 41, 1) == 1);
1.1119 +
1.1120 + tuples = g_relation_select (relation, data + 200, 0);
1.1121 +
1.1122 + g_assert (tuples->len == 2);
1.1123 +
1.1124 +#if 0
1.1125 + for (i = 0; i < tuples->len; i += 1)
1.1126 + {
1.1127 + printf ("%d %d\n",
1.1128 + *(gint*) g_tuples_index (tuples, i, 0),
1.1129 + *(gint*) g_tuples_index (tuples, i, 1));
1.1130 + }
1.1131 +#endif
1.1132 +
1.1133 + g_assert (g_relation_exists (relation, data + 300, data + 301));
1.1134 + g_relation_delete (relation, data + 300, 0);
1.1135 + g_assert (!g_relation_exists (relation, data + 300, data + 301));
1.1136 +
1.1137 + g_tuples_destroy (tuples);
1.1138 +
1.1139 + g_relation_destroy (relation);
1.1140 +
1.1141 + relation = NULL;
1.1142 +}
1.1143 +
1.1144 +static void
1.1145 +gstring_tests (void)
1.1146 +{
1.1147 + GString *string1, *string2;
1.1148 + guint i;
1.1149 +
1.1150 + if (g_test_verbose())
1.1151 + g_print ("test GString basics\n");
1.1152 +
1.1153 + string1 = g_string_new ("hi pete!");
1.1154 + string2 = g_string_new ("");
1.1155 +
1.1156 + g_assert (strcmp ("hi pete!", string1->str) == 0);
1.1157 +
1.1158 + for (i = 0; i < 10000; i++)
1.1159 + g_string_append_c (string1, 'a'+(i%26));
1.1160 +
1.1161 +#ifndef G_OS_WIN32
1.1162 + /* MSVC, mingw32 and LCC use the same run-time C library, which doesn't like
1.1163 + the %10000.10000f format... */
1.1164 + g_string_printf (string2, "%s|%0100d|%s|%s|%0*d|%*.*f|%10000.10000f",
1.1165 + "this pete guy sure is a wuss, like he's the number ",
1.1166 + 1,
1.1167 + " wuss. everyone agrees.\n",
1.1168 + string1->str,
1.1169 + 10, 666, 15, 15, 666.666666666, 666.666666666);
1.1170 +#else
1.1171 + g_string_printf (string2, "%s|%0100d|%s|%s|%0*d|%*.*f|%100.100f",
1.1172 + "this pete guy sure is a wuss, like he's the number ",
1.1173 + 1,
1.1174 + " wuss. everyone agrees.\n",
1.1175 + string1->str,
1.1176 + 10, 666, 15, 15, 666.666666666, 666.666666666);
1.1177 +#endif
1.1178 +
1.1179 + if (g_test_verbose())
1.1180 + g_print ("string2 length = %lu...\n", (gulong)string2->len);
1.1181 + string2->str[70] = '\0';
1.1182 + if (g_test_verbose())
1.1183 + g_print ("first 70 chars:\n%s\n", string2->str);
1.1184 + string2->str[141] = '\0';
1.1185 + if (g_test_verbose())
1.1186 + g_print ("next 70 chars:\n%s\n", string2->str+71);
1.1187 + string2->str[212] = '\0';
1.1188 + if (g_test_verbose())
1.1189 + g_print ("and next 70:\n%s\n", string2->str+142);
1.1190 + if (g_test_verbose())
1.1191 + g_print ("last 70 chars:\n%s\n", string2->str+string2->len - 70);
1.1192 +
1.1193 + g_string_free (string1, TRUE);
1.1194 + g_string_free (string2, TRUE);
1.1195 +
1.1196 + /* append */
1.1197 + string1 = g_string_new ("firsthalf");
1.1198 + g_string_append (string1, "lasthalf");
1.1199 + g_assert (strcmp (string1->str, "firsthalflasthalf") == 0);
1.1200 + g_string_free (string1, TRUE);
1.1201 +
1.1202 + /* append_len */
1.1203 + string1 = g_string_new ("firsthalf");
1.1204 + g_string_append_len (string1, "lasthalfjunkjunk", strlen ("lasthalf"));
1.1205 + g_assert (strcmp (string1->str, "firsthalflasthalf") == 0);
1.1206 + g_string_free (string1, TRUE);
1.1207 +
1.1208 + /* prepend */
1.1209 + string1 = g_string_new ("lasthalf");
1.1210 + g_string_prepend (string1, "firsthalf");
1.1211 + g_assert (strcmp (string1->str, "firsthalflasthalf") == 0);
1.1212 + g_string_free (string1, TRUE);
1.1213 +
1.1214 + /* prepend_len */
1.1215 + string1 = g_string_new ("lasthalf");
1.1216 + g_string_prepend_len (string1, "firsthalfjunkjunk", strlen ("firsthalf"));
1.1217 + g_assert (strcmp (string1->str, "firsthalflasthalf") == 0);
1.1218 + g_string_free (string1, TRUE);
1.1219 +
1.1220 + /* insert */
1.1221 + string1 = g_string_new ("firstlast");
1.1222 + g_string_insert (string1, 5, "middle");
1.1223 + g_assert (strcmp (string1->str, "firstmiddlelast") == 0);
1.1224 + g_string_free (string1, TRUE);
1.1225 +
1.1226 + /* insert with pos == end of the string */
1.1227 + string1 = g_string_new ("firstmiddle");
1.1228 + g_string_insert (string1, strlen ("firstmiddle"), "last");
1.1229 + g_assert (strcmp (string1->str, "firstmiddlelast") == 0);
1.1230 + g_string_free (string1, TRUE);
1.1231 +
1.1232 + /* insert_len */
1.1233 + string1 = g_string_new ("firstlast");
1.1234 + g_string_insert_len (string1, 5, "middlejunkjunk", strlen ("middle"));
1.1235 + g_assert (strcmp (string1->str, "firstmiddlelast") == 0);
1.1236 + g_string_free (string1, TRUE);
1.1237 +
1.1238 + /* insert_len with magic -1 pos for append */
1.1239 + string1 = g_string_new ("first");
1.1240 + g_string_insert_len (string1, -1, "lastjunkjunk", strlen ("last"));
1.1241 + g_assert (strcmp (string1->str, "firstlast") == 0);
1.1242 + g_string_free (string1, TRUE);
1.1243 +
1.1244 + /* insert_len with magic -1 len for strlen-the-string */
1.1245 + string1 = g_string_new ("first");
1.1246 + g_string_insert_len (string1, 5, "last", -1);
1.1247 + g_assert (strcmp (string1->str, "firstlast") == 0);
1.1248 + g_string_free (string1, TRUE);
1.1249 +
1.1250 + /* g_string_equal */
1.1251 + string1 = g_string_new ("test");
1.1252 + string2 = g_string_new ("te");
1.1253 + g_assert (! g_string_equal(string1, string2));
1.1254 + g_string_append (string2, "st");
1.1255 + g_assert (g_string_equal(string1, string2));
1.1256 + g_string_free (string1, TRUE);
1.1257 + g_string_free (string2, TRUE);
1.1258 +
1.1259 + /* Check handling of embedded ASCII 0 (NUL) characters in GString. */
1.1260 + if (g_test_verbose())
1.1261 + g_print ("test embedded ASCII 0 (NUL) characters in GString\n");
1.1262 + string1 = g_string_new ("fiddle");
1.1263 + string2 = g_string_new ("fiddle");
1.1264 + g_assert (g_string_equal(string1, string2));
1.1265 + g_string_append_c(string1, '\0');
1.1266 + g_assert (! g_string_equal(string1, string2));
1.1267 + g_string_append_c(string2, '\0');
1.1268 + g_assert (g_string_equal(string1, string2));
1.1269 + g_string_append_c(string1, 'x');
1.1270 + g_string_append_c(string2, 'y');
1.1271 + g_assert (! g_string_equal(string1, string2));
1.1272 + g_assert (string1->len == 8);
1.1273 + g_string_append(string1, "yzzy");
1.1274 + g_assert (string1->len == 12);
1.1275 + g_assert ( memcmp(string1->str, "fiddle\0xyzzy", 13) == 0);
1.1276 + g_string_insert(string1, 1, "QED");
1.1277 + g_assert ( memcmp(string1->str, "fQEDiddle\0xyzzy", 16) == 0);
1.1278 + g_string_free (string1, TRUE);
1.1279 + g_string_free (string2, TRUE);
1.1280 +}
1.1281 +
1.1282 +static void
1.1283 +various_string_tests (void)
1.1284 +{
1.1285 + GStringChunk *string_chunk;
1.1286 + GTimeVal ref_date, date;
1.1287 + gchar *tmp_string = NULL, *tmp_string_2, *string, *date_str;
1.1288 + guint i;
1.1289 +
1.1290 + if (g_test_verbose())
1.1291 + g_print ("checking string chunks...");
1.1292 + string_chunk = g_string_chunk_new (1024);
1.1293 + for (i = 0; i < 100000; i ++)
1.1294 + {
1.1295 + tmp_string = g_string_chunk_insert (string_chunk, "hi pete");
1.1296 + if (strcmp ("hi pete", tmp_string) != 0)
1.1297 + g_error ("string chunks are broken.\n");
1.1298 + }
1.1299 + tmp_string_2 = g_string_chunk_insert_const (string_chunk, tmp_string);
1.1300 + g_assert (tmp_string_2 != tmp_string && strcmp (tmp_string_2, tmp_string) == 0);
1.1301 + tmp_string = g_string_chunk_insert_const (string_chunk, tmp_string);
1.1302 + g_assert (tmp_string_2 == tmp_string);
1.1303 + g_string_chunk_free (string_chunk);
1.1304 +
1.1305 + if (g_test_verbose())
1.1306 + g_print ("test positional printf formats (not supported):");
1.1307 + string = g_strdup_printf ("%.*s%s", 5, "a", "b");
1.1308 + tmp_string = g_strdup_printf ("%2$*1$s", 5, "c");
1.1309 + if (g_test_verbose())
1.1310 + g_print ("%s%s\n", string, tmp_string);
1.1311 + g_free (tmp_string);
1.1312 + g_free (string);
1.1313 +
1.1314 +#define REF_INVALID1 "Wed Dec 19 17:20:20 GMT 2007"
1.1315 +#define REF_INVALID2 "1980-02-22T10:36:00Zulu"
1.1316 +#define REF_SEC_UTC 320063760
1.1317 +#define REF_STR_UTC "1980-02-22T10:36:00Z"
1.1318 +#define REF_STR_CEST "1980-02-22T12:36:00+02:00"
1.1319 +#define REF_STR_EST "19800222T053600-0500"
1.1320 +#define REF_STR_NST "1980-02-22T07:06:00-03:30"
1.1321 +#define REF_USEC_UTC 50000
1.1322 +#define REF_STR_USEC_UTC "1980-02-22T10:36:00.050000Z"
1.1323 +#define REF_STR_USEC_CEST "19800222T123600.050000000+0200"
1.1324 +#define REF_STR_USEC_EST "1980-02-22T05:36:00,05-05:00"
1.1325 +#define REF_STR_USEC_NST "19800222T070600,0500-0330"
1.1326 +
1.1327 + if (g_test_verbose())
1.1328 + g_print ("checking g_time_val_from_iso8601...\n");
1.1329 + ref_date.tv_sec = REF_SEC_UTC;
1.1330 + ref_date.tv_usec = 0;
1.1331 + g_assert (g_time_val_from_iso8601 (REF_INVALID1, &date) == FALSE);
1.1332 + g_assert (g_time_val_from_iso8601 (REF_INVALID2, &date) == FALSE);
1.1333 + g_assert (g_time_val_from_iso8601 (REF_STR_UTC, &date) != FALSE);
1.1334 + if (g_test_verbose())
1.1335 + g_print ("\t=> UTC stamp = %ld.%06ld (should be: %ld.%06ld) (%ld.%06ld off)\n",
1.1336 + date.tv_sec, date.tv_usec, ref_date.tv_sec, ref_date.tv_usec,
1.1337 + date.tv_sec - ref_date.tv_sec, date.tv_usec - ref_date.tv_usec);
1.1338 + g_assert (date.tv_sec == ref_date.tv_sec && date.tv_usec == ref_date.tv_usec);
1.1339 +
1.1340 + g_assert (g_time_val_from_iso8601 (REF_STR_CEST, &date) != FALSE);
1.1341 + if (g_test_verbose())
1.1342 + g_print ("\t=> CEST stamp = %ld.%06ld (should be: %ld.%06ld) (%ld.%06ld off)\n",
1.1343 + date.tv_sec, date.tv_usec, ref_date.tv_sec, ref_date.tv_usec,
1.1344 + date.tv_sec - ref_date.tv_sec, date.tv_usec - ref_date.tv_usec);
1.1345 + g_assert (date.tv_sec == ref_date.tv_sec && date.tv_usec == ref_date.tv_usec);
1.1346 +
1.1347 + g_assert (g_time_val_from_iso8601 (REF_STR_EST, &date) != FALSE);
1.1348 + if (g_test_verbose())
1.1349 + g_print ("\t=> EST stamp = %ld.%06ld (should be: %ld.%06ld) (%ld.%06ld off)\n",
1.1350 + date.tv_sec, date.tv_usec, ref_date.tv_sec, ref_date.tv_usec,
1.1351 + date.tv_sec - ref_date.tv_sec, date.tv_usec - ref_date.tv_usec);
1.1352 + g_assert (date.tv_sec == ref_date.tv_sec && date.tv_usec == ref_date.tv_usec);
1.1353 +
1.1354 + g_assert (g_time_val_from_iso8601 (REF_STR_NST, &date) != FALSE);
1.1355 + if (g_test_verbose())
1.1356 + g_print ("\t=> NST stamp = %ld.%06ld (should be: %ld.%06ld) (%ld.%06ld off)\n",
1.1357 + date.tv_sec, date.tv_usec, ref_date.tv_sec, ref_date.tv_usec,
1.1358 + date.tv_sec - ref_date.tv_sec, date.tv_usec - ref_date.tv_usec);
1.1359 + g_assert (date.tv_sec == ref_date.tv_sec && date.tv_usec == ref_date.tv_usec);
1.1360 +
1.1361 + ref_date.tv_usec = REF_USEC_UTC;
1.1362 + g_assert (g_time_val_from_iso8601 (REF_STR_USEC_UTC, &date) != FALSE);
1.1363 + if (g_test_verbose())
1.1364 + g_print ("\t=> UTC stamp = %ld.%06ld (should be: %ld.%06ld) (%ld.%06ld off)\n",
1.1365 + date.tv_sec, date.tv_usec, ref_date.tv_sec, ref_date.tv_usec,
1.1366 + date.tv_sec - ref_date.tv_sec, date.tv_usec - ref_date.tv_usec);
1.1367 + g_assert (date.tv_sec == ref_date.tv_sec && date.tv_usec == ref_date.tv_usec);
1.1368 +
1.1369 + g_assert (g_time_val_from_iso8601 (REF_STR_USEC_CEST, &date) != FALSE);
1.1370 + if (g_test_verbose())
1.1371 + g_print ("\t=> CEST stamp = %ld.%06ld (should be: %ld.%06ld) (%ld.%06ld off)\n",
1.1372 + date.tv_sec, date.tv_usec, ref_date.tv_sec, ref_date.tv_usec,
1.1373 + date.tv_sec - ref_date.tv_sec, date.tv_usec - ref_date.tv_usec);
1.1374 + g_assert (date.tv_sec == ref_date.tv_sec && date.tv_usec == ref_date.tv_usec);
1.1375 +
1.1376 + g_assert (g_time_val_from_iso8601 (REF_STR_USEC_EST, &date) != FALSE);
1.1377 + if (g_test_verbose())
1.1378 + g_print ("\t=> EST stamp = %ld.%06ld (should be: %ld.%06ld) (%ld.%06ld off)\n",
1.1379 + date.tv_sec, date.tv_usec, ref_date.tv_sec, ref_date.tv_usec,
1.1380 + date.tv_sec - ref_date.tv_sec, date.tv_usec - ref_date.tv_usec);
1.1381 + g_assert (date.tv_sec == ref_date.tv_sec && date.tv_usec == ref_date.tv_usec);
1.1382 +
1.1383 + g_assert (g_time_val_from_iso8601 (REF_STR_USEC_NST, &date) != FALSE);
1.1384 + if (g_test_verbose())
1.1385 + g_print ("\t=> NST stamp = %ld.%06ld (should be: %ld.%06ld) (%ld.%06ld off)\n",
1.1386 + date.tv_sec, date.tv_usec, ref_date.tv_sec, ref_date.tv_usec,
1.1387 + date.tv_sec - ref_date.tv_sec, date.tv_usec - ref_date.tv_usec);
1.1388 + g_assert (date.tv_sec == ref_date.tv_sec && date.tv_usec == ref_date.tv_usec);
1.1389 +
1.1390 + if (g_test_verbose())
1.1391 + g_print ("checking g_time_val_to_iso8601...\n");
1.1392 + ref_date.tv_sec = REF_SEC_UTC;
1.1393 + ref_date.tv_usec = 0;
1.1394 + date_str = g_time_val_to_iso8601 (&ref_date);
1.1395 + g_assert (date_str != NULL);
1.1396 + if (g_test_verbose())
1.1397 + g_print ("\t=> date string = %s (should be: %s)\n", date_str, REF_STR_UTC);
1.1398 + g_assert (strcmp (date_str, REF_STR_UTC) == 0);
1.1399 + g_free (date_str);
1.1400 +
1.1401 + ref_date.tv_usec = REF_USEC_UTC;
1.1402 + date_str = g_time_val_to_iso8601 (&ref_date);
1.1403 + g_assert (date_str != NULL);
1.1404 + if (g_test_verbose())
1.1405 + g_print ("\t=> date string = %s (should be: %s)\n", date_str, REF_STR_USEC_UTC);
1.1406 + g_assert (strcmp (date_str, REF_STR_USEC_UTC) == 0);
1.1407 + g_free (date_str);
1.1408 +
1.1409 + if (g_test_verbose())
1.1410 + g_print ("checking g_ascii_strcasecmp...");
1.1411 + g_assert (g_ascii_strcasecmp ("FroboZZ", "frobozz") == 0);
1.1412 + g_assert (g_ascii_strcasecmp ("frobozz", "frobozz") == 0);
1.1413 + g_assert (g_ascii_strcasecmp ("frobozz", "FROBOZZ") == 0);
1.1414 + g_assert (g_ascii_strcasecmp ("FROBOZZ", "froboz") > 0);
1.1415 + g_assert (g_ascii_strcasecmp ("", "") == 0);
1.1416 + g_assert (g_ascii_strcasecmp ("!#%&/()", "!#%&/()") == 0);
1.1417 + g_assert (g_ascii_strcasecmp ("a", "b") < 0);
1.1418 + g_assert (g_ascii_strcasecmp ("a", "B") < 0);
1.1419 + g_assert (g_ascii_strcasecmp ("A", "b") < 0);
1.1420 + g_assert (g_ascii_strcasecmp ("A", "B") < 0);
1.1421 + g_assert (g_ascii_strcasecmp ("b", "a") > 0);
1.1422 + g_assert (g_ascii_strcasecmp ("b", "A") > 0);
1.1423 + g_assert (g_ascii_strcasecmp ("B", "a") > 0);
1.1424 + g_assert (g_ascii_strcasecmp ("B", "A") > 0);
1.1425 +
1.1426 + if (g_test_verbose())
1.1427 + g_print ("checking g_strdup...\n");
1.1428 + g_assert (g_strdup (NULL) == NULL);
1.1429 + string = g_strdup (GLIB_TEST_STRING);
1.1430 + g_assert (string != NULL);
1.1431 + g_assert (strcmp(string, GLIB_TEST_STRING) == 0);
1.1432 + g_free (string);
1.1433 +
1.1434 + if (g_test_verbose())
1.1435 + g_print ("checking g_strconcat...\n");
1.1436 + string = g_strconcat (GLIB_TEST_STRING, NULL);
1.1437 + g_assert (string != NULL);
1.1438 + g_assert (strcmp (string, GLIB_TEST_STRING) == 0);
1.1439 + g_free (string);
1.1440 + string = g_strconcat (GLIB_TEST_STRING, GLIB_TEST_STRING,
1.1441 + GLIB_TEST_STRING, NULL);
1.1442 + g_assert (string != NULL);
1.1443 + g_assert (strcmp (string, GLIB_TEST_STRING GLIB_TEST_STRING
1.1444 + GLIB_TEST_STRING) == 0);
1.1445 + g_free (string);
1.1446 +
1.1447 + if (g_test_verbose())
1.1448 + g_print ("checking g_strlcpy/g_strlcat...");
1.1449 + /* The following is a torture test for strlcpy/strlcat, with lots of
1.1450 + * checking; normal users wouldn't use them this way!
1.1451 + */
1.1452 + string = g_malloc (6);
1.1453 + *(string + 5) = 'Z'; /* guard value, shouldn't change during test */
1.1454 + *string = 'q';
1.1455 + g_assert (g_strlcpy(string, "" , 5) == 0);
1.1456 + g_assert ( *string == '\0' );
1.1457 + *string = 'q';
1.1458 + g_assert (g_strlcpy(string, "abc" , 5) == 3);
1.1459 + g_assert ( *(string + 3) == '\0' );
1.1460 + g_assert (g_str_equal(string, "abc"));
1.1461 + g_assert (g_strlcpy(string, "abcd" , 5) == 4);
1.1462 + g_assert ( *(string + 4) == '\0' );
1.1463 + g_assert ( *(string + 5) == 'Z' );
1.1464 + g_assert (g_str_equal(string, "abcd"));
1.1465 + g_assert (g_strlcpy(string, "abcde" , 5) == 5);
1.1466 + g_assert ( *(string + 4) == '\0' );
1.1467 + g_assert ( *(string + 5) == 'Z' );
1.1468 + g_assert (g_str_equal(string, "abcd"));
1.1469 + g_assert (g_strlcpy(string, "abcdef" , 5) == 6);
1.1470 + g_assert ( *(string + 4) == '\0' );
1.1471 + g_assert ( *(string + 5) == 'Z' );
1.1472 + g_assert (g_str_equal(string, "abcd"));
1.1473 + *string = 'Y';
1.1474 + *(string + 1)= '\0';
1.1475 + g_assert (g_strlcpy(string, "Hello" , 0) == 5);
1.1476 + g_assert (*string == 'Y');
1.1477 + *string = '\0';
1.1478 + g_assert (g_strlcat(string, "123" , 5) == 3);
1.1479 + g_assert ( *(string + 3) == '\0' );
1.1480 + g_assert (g_str_equal(string, "123"));
1.1481 + g_assert (g_strlcat(string, "" , 5) == 3);
1.1482 + g_assert ( *(string + 3) == '\0' );
1.1483 + g_assert (g_str_equal(string, "123"));
1.1484 + g_assert (g_strlcat(string, "4", 5) == 4);
1.1485 + g_assert (g_str_equal(string, "1234"));
1.1486 + g_assert (g_strlcat(string, "5", 5) == 5);
1.1487 + g_assert ( *(string + 4) == '\0' );
1.1488 + g_assert (g_str_equal(string, "1234"));
1.1489 + g_assert ( *(string + 5) == 'Z' );
1.1490 + *string = 'Y';
1.1491 + *(string + 1)= '\0';
1.1492 + g_assert (g_strlcat(string, "123" , 0) == 3);
1.1493 + g_assert (*string == 'Y');
1.1494 +
1.1495 + /* A few more tests, demonstrating more "normal" use */
1.1496 + g_assert (g_strlcpy(string, "hi", 5) == 2);
1.1497 + g_assert (g_str_equal(string, "hi"));
1.1498 + g_assert (g_strlcat(string, "t", 5) == 3);
1.1499 + g_assert (g_str_equal(string, "hit"));
1.1500 + g_free(string);
1.1501 +
1.1502 + if (g_test_verbose())
1.1503 + g_print ("checking g_strdup_printf...\n");
1.1504 + string = g_strdup_printf ("%05d %-5s", 21, "test");
1.1505 + g_assert (string != NULL);
1.1506 + g_assert (strcmp(string, "00021 test ") == 0);
1.1507 + g_free (string);
1.1508 +
1.1509 + /* g_debug (argv[0]); */
1.1510 +}
1.1511 +
1.1512 +#ifndef G_DISABLE_DEPRECATED
1.1513 +static void
1.1514 +test_mem_chunks (void)
1.1515 +{
1.1516 + GMemChunk *mem_chunk = g_mem_chunk_new ("test mem chunk", 50, 100, G_ALLOC_AND_FREE);
1.1517 + gchar *mem[10000];
1.1518 + guint i;
1.1519 + for (i = 0; i < 10000; i++)
1.1520 + {
1.1521 + guint j;
1.1522 + mem[i] = g_chunk_new (gchar, mem_chunk);
1.1523 + for (j = 0; j < 50; j++)
1.1524 + mem[i][j] = i * j;
1.1525 + }
1.1526 + for (i = 0; i < 10000; i++)
1.1527 + g_mem_chunk_free (mem_chunk, mem[i]);
1.1528 +}
1.1529 +#endif
1.1530 +
1.1531 +int
1.1532 +main (int argc,
1.1533 + char *argv[])
1.1534 +{
1.1535 + #ifdef __SYMBIAN32__
1.1536 + 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);
1.1537 + g_set_print_handler(mrtPrintHandler);
1.1538 + #endif /*__SYMBIAN32__*/
1.1539 + g_test_init (&argc, &argv, NULL);
1.1540 +
1.1541 + g_test_add_func ("/testglib/Infos", test_info);
1.1542 + g_test_add_func ("/testglib/Types Sizes", type_sizes);
1.1543 + g_test_add_func ("/testglib/GStrings", gstring_tests);
1.1544 + g_test_add_func ("/testglib/Various Strings", various_string_tests);
1.1545 + g_test_add_func ("/testglib/GList", glist_test);
1.1546 + g_test_add_func ("/testglib/GSList", gslist_test);
1.1547 + g_test_add_func ("/testglib/GNode", gnode_test);
1.1548 + g_test_add_func ("/testglib/GTree", binary_tree_test);
1.1549 + g_test_add_func ("/testglib/Arrays", test_arrays);
1.1550 + g_test_add_func ("/testglib/GHashTable", hash_table_tests);
1.1551 + g_test_add_func ("/testglib/Relation", relation_test);
1.1552 + g_test_add_func ("/testglib/File Paths", test_paths);
1.1553 + g_test_add_func ("/testglib/File Functions", test_file_functions);
1.1554 + g_test_add_func ("/testglib/Parse Debug Strings", test_g_parse_debug_string);
1.1555 +
1.1556 +#ifndef G_DISABLE_DEPRECATED
1.1557 + g_test_add_func ("/testglib/GMemChunk (deprecated)", test_mem_chunks);
1.1558 +#endif
1.1559 + g_test_add_func ("/testglib/Warnings & Errors", log_warning_error_tests);
1.1560 + g_test_add_func ("/testglib/Timers (slow)", timer_tests);
1.1561 + /* return */g_test_run();
1.1562 + #ifdef __SYMBIAN32__
1.1563 + testResultXml("testglib");
1.1564 +#endif /* EMULATOR */
1.1565 + return 0;
1.1566 +
1.1567 +}