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