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