sl@0: /* GLIB - Library of useful routines for C programming
sl@0:  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
sl@0:  * Portion Copyright © 2008-09 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
sl@0:  * This library is free software; you can redistribute it and/or
sl@0:  * modify it under the terms of the GNU Lesser General Public
sl@0:  * License as published by the Free Software Foundation; either
sl@0:  * version 2 of the License, or (at your option) any later version.
sl@0:  *
sl@0:  * This library is distributed in the hope that it will be useful,
sl@0:  * but WITHOUT ANY WARRANTY; without even the implied warranty of
sl@0:  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
sl@0:  * Lesser General Public License for more details.
sl@0:  *
sl@0:  * You should have received a copy of the GNU Lesser General Public
sl@0:  * License along with this library; if not, write to the
sl@0:  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
sl@0:  * Boston, MA 02111-1307, USA.
sl@0:  */
sl@0: 
sl@0: /*
sl@0:  * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
sl@0:  * file for a list of people on the GLib Team.  See the ChangeLog
sl@0:  * files for a list of changes.  These files are distributed with
sl@0:  * GLib at ftp://ftp.gtk.org/pub/gtk/. 
sl@0:  */
sl@0: 
sl@0: #include "config.h"
sl@0: 
sl@0: #undef G_DISABLE_ASSERT
sl@0: #undef G_LOG_DOMAIN
sl@0: 
sl@0: #ifdef GLIB_COMPILATION
sl@0: #undef GLIB_COMPILATION
sl@0: #endif
sl@0: 
sl@0: #include <stdio.h>
sl@0: #include <string.h>
sl@0: #include <errno.h>
sl@0: 
sl@0: 
sl@0: #include "glib.h"
sl@0: #include "gstdio.h"
sl@0: 
sl@0: 
sl@0: #ifdef SYMBIAN
sl@0: #include <sys/stat.h>
sl@0: #include <glib_global.h>
sl@0: #include "mrt2_glib2_test.h"
sl@0: #endif /*SYMBIAN*/
sl@0: 
sl@0: 
sl@0: #ifdef HAVE_UNISTD_H
sl@0: #include <unistd.h>
sl@0: #endif
sl@0: 
sl@0: #ifdef G_OS_WIN32
sl@0: #include <io.h>			/* For read(), write() etc */
sl@0: #endif
sl@0: 
sl@0: 
sl@0: 
sl@0: static int array[10000];
sl@0: static gboolean failed = FALSE;
sl@0: 
sl@0: /* We write (m ? m : "") even in the m != NULL case to suppress a warning with GCC-3.1
sl@0:  */
sl@0: #define	TEST(m,cond)	G_STMT_START { failed = !(cond); \
sl@0: if (failed) \
sl@0:   { assert_failed = TRUE; \
sl@0:   	if (!m) \
sl@0:       g_print ("\n(%s:%d) failed for: %s\n", __FILE__, __LINE__, ( # cond )); \
sl@0:     else \
sl@0:       g_print ("\n(%s:%d) failed for: %s: (%s)\n", __FILE__, __LINE__, ( # cond ), (gchar*)(m ? m : "")); \
sl@0:   } \
sl@0: } G_STMT_END
sl@0: 
sl@0: #define	C2P(c)		((gpointer) ((long) (c)))
sl@0: #define	P2C(p)		((gchar) ((long) (p)))
sl@0: 
sl@0: #define GLIB_TEST_STRING "el dorado "
sl@0: #define GLIB_TEST_STRING_5 "el do"
sl@0: 
sl@0: static gboolean
sl@0: node_build_string (GNode    *node,
sl@0: 		   gpointer  data)
sl@0: {
sl@0:   gchar **p = data;
sl@0:   gchar *string;
sl@0:   gchar c[2] = "_";
sl@0: 
sl@0:   c[0] = P2C (node->data);
sl@0: 
sl@0:   string = g_strconcat (*p ? *p : "", c, NULL);
sl@0:   g_free (*p);
sl@0:   *p = string;
sl@0: 
sl@0:   return FALSE;
sl@0: }
sl@0: 
sl@0: static void
sl@0: g_node_test (void)
sl@0: {
sl@0:   GNode *root;
sl@0:   GNode *node;
sl@0:   GNode *node_B;
sl@0:   GNode *node_F;
sl@0:   GNode *node_G;
sl@0:   GNode *node_J;
sl@0:   guint i;
sl@0:   gchar *tstring, *cstring;
sl@0: 
sl@0:   //g_print ("checking n-way trees: ");
sl@0:   failed = FALSE;
sl@0: 
sl@0:   root = g_node_new (C2P ('A'));
sl@0:   TEST (NULL, g_node_depth (root) == 1 && g_node_max_height (root) == 1);
sl@0: 
sl@0:   node_B = g_node_new (C2P ('B'));
sl@0:   g_node_append (root, node_B);
sl@0:   TEST (NULL, root->children == node_B);
sl@0: 
sl@0:   g_node_append_data (node_B, C2P ('E'));
sl@0:   g_node_prepend_data (node_B, C2P ('C'));
sl@0:   g_node_insert (node_B, 1, g_node_new (C2P ('D')));
sl@0: 
sl@0:   node_F = g_node_new (C2P ('F'));
sl@0:   g_node_append (root, node_F);
sl@0:   TEST (NULL, root->children->next == node_F);
sl@0: 
sl@0:   node_G = g_node_new (C2P ('G'));
sl@0:   g_node_append (node_F, node_G);
sl@0:   node_J = g_node_new (C2P ('J'));
sl@0:   g_node_prepend (node_G, node_J);
sl@0:   g_node_insert (node_G, 42, g_node_new (C2P ('K')));
sl@0:   g_node_insert_data (node_G, 0, C2P ('H'));
sl@0:   g_node_insert (node_G, 1, g_node_new (C2P ('I')));
sl@0: 
sl@0:   TEST (NULL, g_node_depth (root) == 1);
sl@0:   TEST (NULL, g_node_max_height (root) == 4);
sl@0:   TEST (NULL, g_node_depth (node_G->children->next) == 4);
sl@0:   TEST (NULL, g_node_n_nodes (root, G_TRAVERSE_LEAFS) == 7);
sl@0:   TEST (NULL, g_node_n_nodes (root, G_TRAVERSE_NON_LEAFS) == 4);
sl@0:   TEST (NULL, g_node_n_nodes (root, G_TRAVERSE_ALL) == 11);
sl@0:   TEST (NULL, g_node_max_height (node_F) == 3);
sl@0:   TEST (NULL, g_node_n_children (node_G) == 4);
sl@0:   TEST (NULL, g_node_find_child (root, G_TRAVERSE_ALL, C2P ('F')) == node_F);
sl@0:   TEST (NULL, g_node_find (root, G_LEVEL_ORDER, G_TRAVERSE_NON_LEAFS, C2P ('I')) == NULL);
sl@0:   TEST (NULL, g_node_find (root, G_IN_ORDER, G_TRAVERSE_LEAFS, C2P ('J')) == node_J);
sl@0: 
sl@0:   for (i = 0; i < g_node_n_children (node_B); i++)
sl@0:     {
sl@0:       node = g_node_nth_child (node_B, i);
sl@0:       TEST (NULL, P2C (node->data) == ('C' + i));
sl@0:     }
sl@0:   
sl@0:   for (i = 0; i < g_node_n_children (node_G); i++)
sl@0:     TEST (NULL, g_node_child_position (node_G, g_node_nth_child (node_G, i)) == i);
sl@0: 
sl@0:   /* we have built:                    A
sl@0:    *                                 /   \
sl@0:    *                               B       F
sl@0:    *                             / | \       \
sl@0:    *                           C   D   E       G
sl@0:    *                                         / /\ \
sl@0:    *                                       H  I  J  K
sl@0:    *
sl@0:    * for in-order traversal, 'G' is considered to be the "left"
sl@0:    * child of 'F', which will cause 'F' to be the last node visited.
sl@0:    */
sl@0: 
sl@0:   tstring = NULL;
sl@0:   g_node_traverse (root, G_PRE_ORDER, G_TRAVERSE_ALL, -1, node_build_string, &tstring);
sl@0:   TEST (tstring, strcmp (tstring, "ABCDEFGHIJK") == 0);
sl@0:   g_free (tstring); tstring = NULL;
sl@0:   g_node_traverse (root, G_POST_ORDER, G_TRAVERSE_ALL, -1, node_build_string, &tstring);
sl@0:   TEST (tstring, strcmp (tstring, "CDEBHIJKGFA") == 0);
sl@0:   g_free (tstring); tstring = NULL;
sl@0:   g_node_traverse (root, G_IN_ORDER, G_TRAVERSE_ALL, -1, node_build_string, &tstring);
sl@0:   TEST (tstring, strcmp (tstring, "CBDEAHGIJKF") == 0);
sl@0:   g_free (tstring); tstring = NULL;
sl@0:   g_node_traverse (root, G_LEVEL_ORDER, G_TRAVERSE_ALL, -1, node_build_string, &tstring);
sl@0:   TEST (tstring, strcmp (tstring, "ABFCDEGHIJK") == 0);
sl@0:   g_free (tstring); tstring = NULL;
sl@0:   
sl@0:   g_node_traverse (root, G_LEVEL_ORDER, G_TRAVERSE_LEAFS, -1, node_build_string, &tstring);
sl@0:   TEST (tstring, strcmp (tstring, "CDEHIJK") == 0);
sl@0:   g_free (tstring); tstring = NULL;
sl@0:   g_node_traverse (root, G_PRE_ORDER, G_TRAVERSE_NON_LEAFS, -1, node_build_string, &tstring);
sl@0:   TEST (tstring, strcmp (tstring, "ABFG") == 0);
sl@0:   g_free (tstring); tstring = NULL;
sl@0: 
sl@0:   g_node_reverse_children (node_B);
sl@0:   g_node_reverse_children (node_G);
sl@0: 
sl@0:   g_node_traverse (root, G_LEVEL_ORDER, G_TRAVERSE_ALL, -1, node_build_string, &tstring);
sl@0:   TEST (tstring, strcmp (tstring, "ABFEDCGKJIH") == 0);
sl@0:   g_free (tstring); tstring = NULL;
sl@0: 
sl@0:   cstring = NULL;
sl@0:   node = g_node_copy (root);
sl@0:   TEST (NULL, g_node_n_nodes (root, G_TRAVERSE_ALL) == g_node_n_nodes (node, G_TRAVERSE_ALL));
sl@0:   TEST (NULL, g_node_max_height (root) == g_node_max_height (node));
sl@0:   g_node_traverse (root, G_IN_ORDER, G_TRAVERSE_ALL, -1, node_build_string, &tstring);
sl@0:   g_node_traverse (node, G_IN_ORDER, G_TRAVERSE_ALL, -1, node_build_string, &cstring);
sl@0:   TEST (cstring, strcmp (tstring, cstring) == 0);
sl@0:   g_free (tstring); tstring = NULL;
sl@0:   g_free (cstring); cstring = NULL;
sl@0:   g_node_destroy (node);
sl@0: 
sl@0:   g_node_destroy (root);
sl@0: 
sl@0:   /* allocation tests */
sl@0: 
sl@0:   root = g_node_new (NULL);
sl@0:   node = root;
sl@0: 
sl@0:   for (i = 0; i < 2048; i++)
sl@0:     {
sl@0:       g_node_append (node, g_node_new (NULL));
sl@0:       if ((i%5) == 4)
sl@0: 	node = node->children->next;
sl@0:     }
sl@0:   TEST (NULL, g_node_max_height (root) > 100);
sl@0:   TEST (NULL, g_node_n_nodes (root, G_TRAVERSE_ALL) == 1 + 2048);
sl@0: 
sl@0:   g_node_destroy (root);
sl@0:   
sl@0:   if (failed)
sl@0:     g_print ("g_node_test failed\n");
sl@0: }
sl@0: 
sl@0: static gboolean
sl@0: my_hash_callback_remove (gpointer key,
sl@0: 			 gpointer value,
sl@0: 			 gpointer user_data)
sl@0: {
sl@0:   int *d = value;
sl@0: 
sl@0:   if ((*d) % 2)
sl@0:     return TRUE;
sl@0: 
sl@0:   return FALSE;
sl@0: }
sl@0: 
sl@0: static void
sl@0: my_hash_callback_remove_test (gpointer key,
sl@0: 			      gpointer value,
sl@0: 			      gpointer user_data)
sl@0: {
sl@0:   int *d = value;
sl@0: 
sl@0:   if ((*d) % 2)
sl@0:     g_print ("bad!\n");
sl@0: }
sl@0: 
sl@0: static void
sl@0: my_hash_callback (gpointer key,
sl@0: 		  gpointer value,
sl@0: 		  gpointer user_data)
sl@0: {
sl@0:   int *d = value;
sl@0:   *d = 1;
sl@0: }
sl@0: 
sl@0: static guint
sl@0: my_hash (gconstpointer key)
sl@0: {
sl@0:   return (guint) *((const gint*) key);
sl@0: }
sl@0: 
sl@0: static gboolean
sl@0: my_hash_equal (gconstpointer a,
sl@0: 	       gconstpointer b)
sl@0: {
sl@0:   return *((const gint*) a) == *((const gint*) b);
sl@0: }
sl@0: 
sl@0: static gint
sl@0: my_list_compare_one (gconstpointer a, gconstpointer b)
sl@0: {
sl@0:   gint one = *((const gint*)a);
sl@0:   gint two = *((const gint*)b);
sl@0:   return one-two;
sl@0: }
sl@0: 
sl@0: static gint
sl@0: my_list_compare_two (gconstpointer a, gconstpointer b)
sl@0: {
sl@0:   gint one = *((const gint*)a);
sl@0:   gint two = *((const gint*)b);
sl@0:   return two-one;
sl@0: }
sl@0: 
sl@0: /* static void
sl@0: my_list_print (gpointer a, gpointer b)
sl@0: {
sl@0:   gint three = *((gint*)a);
sl@0:   g_print("%d", three);
sl@0: }; */
sl@0: 
sl@0: static gint
sl@0: my_compare (gconstpointer a,
sl@0: 	    gconstpointer b)
sl@0: {
sl@0:   const char *cha = a;
sl@0:   const char *chb = b;
sl@0: 
sl@0:   return *cha - *chb;
sl@0: }
sl@0: 
sl@0: static gint
sl@0: my_traverse (gpointer key,
sl@0: 	     gpointer value,
sl@0: 	     gpointer data)
sl@0: {
sl@0:   char *ch = key;
sl@0:   g_print ("%c ", *ch);
sl@0:   return FALSE;
sl@0: }
sl@0: 
sl@0: static gboolean 
sl@0: find_first_that(gpointer key, 
sl@0: 		gpointer value, 
sl@0: 		gpointer user_data)
sl@0: {
sl@0:   gint *v = value;
sl@0:   gint *test = user_data;
sl@0:   return (*v == *test);
sl@0: }
sl@0: 
sl@0: 
sl@0: static gboolean
sl@0: test_g_mkdir_with_parents_1 (const gchar *base)
sl@0: {
sl@0:   char *p0 = g_build_filename (base, "fum", NULL);
sl@0:   char *p1 = g_build_filename (p0, "tem", NULL);
sl@0:   char *p2 = g_build_filename (p1, "zap", NULL);
sl@0:   FILE *f;
sl@0: 
sl@0:   g_remove (p2);
sl@0:   g_remove (p1);
sl@0:   g_remove (p0);
sl@0: 
sl@0:   if (g_file_test (p0, G_FILE_TEST_EXISTS))
sl@0:     {
sl@0:       g_print ("failed, %s exists, cannot test g_mkdir_with_parents\n", p0);
sl@0:       return FALSE;
sl@0:     }
sl@0: 
sl@0:   if (g_file_test (p1, G_FILE_TEST_EXISTS))
sl@0:     {
sl@0:       g_print ("failed, %s exists, cannot test g_mkdir_with_parents\n", p1);
sl@0:       g_assert(FALSE && "testglib");
sl@0:       return FALSE;
sl@0:     }
sl@0: 
sl@0:   if (g_file_test (p2, G_FILE_TEST_EXISTS))
sl@0:     {
sl@0:       g_print ("failed, %s exists, cannot test g_mkdir_with_parents\n", p2);
sl@0:       g_assert(FALSE && "testglib");
sl@0:       return FALSE;
sl@0:     }
sl@0: 
sl@0: #ifdef SYMBIAN
sl@0:   if (g_mkdir_with_parents (p2, S_IWUSR) == -1)
sl@0:     {
sl@0:       g_print ("failed, g_mkdir_with_parents(%s) failed: %s\n", p2, g_strerror (errno));
sl@0:       g_assert(FALSE && "testglib");
sl@0:       return FALSE;
sl@0:     }
sl@0: #else
sl@0:   if (g_mkdir_with_parents (p2,  0666) == -1)
sl@0:     {
sl@0:       g_print ("failed, g_mkdir_with_parents(%s) failed: %s\n", p2, g_strerror (errno));
sl@0:       g_assert(FALSE && "testglib");
sl@0:       return FALSE;
sl@0:     }
sl@0: #endif
sl@0: 
sl@0:   if (!g_file_test (p2, G_FILE_TEST_IS_DIR))
sl@0:     {
sl@0:       g_print ("failed, g_mkdir_with_parents(%s) succeeded, but %s is not a directory\n", p2, p2);
sl@0:       g_assert(FALSE && "testglib");
sl@0:       return FALSE;
sl@0:     }
sl@0: 
sl@0:   if (!g_file_test (p1, G_FILE_TEST_IS_DIR))
sl@0:     {
sl@0:       g_print ("failed, g_mkdir_with_parents(%s) succeeded, but %s is not a directory\n", p2, p1);
sl@0:       g_assert(FALSE && "testglib");
sl@0:       return FALSE;
sl@0:     }
sl@0: 
sl@0:   if (!g_file_test (p0, G_FILE_TEST_IS_DIR))
sl@0:     {
sl@0:       g_print ("failed, g_mkdir_with_parents(%s) succeeded, but %s is not a directory\n", p2, p0);
sl@0:       g_assert(FALSE && "testglib");
sl@0:       return FALSE;
sl@0:     }
sl@0: 
sl@0:   g_rmdir (p2);
sl@0:   if (g_file_test (p2, G_FILE_TEST_EXISTS))
sl@0:     {
sl@0:       g_print ("failed, did g_rmdir(%s), but %s is still there\n", p2, p2);
sl@0:       g_assert(FALSE && "testglib");
sl@0:       return FALSE;
sl@0:     }
sl@0: 
sl@0:   g_rmdir (p1);
sl@0:   if (g_file_test (p1, G_FILE_TEST_EXISTS))
sl@0:     {
sl@0:       g_print ("failed, did g_rmdir(%s), but %s is still there\n", p1, p1);
sl@0:       g_assert(FALSE && "testglib");
sl@0:       return FALSE;
sl@0:     }
sl@0: 
sl@0:   f = g_fopen (p1, "w");
sl@0:   if (f == NULL)
sl@0:     {
sl@0:       g_print ("failed, couldn't create file %s\n", p1);
sl@0:       g_assert(FALSE && "testglib");
sl@0:       return FALSE;
sl@0:     }
sl@0:   fclose (f);
sl@0: 
sl@0:   #ifdef SYMBIAN
sl@0:   if (g_mkdir_with_parents (p1,S_IWUSR) == 0)
sl@0:     {
sl@0:       g_print ("failed, g_mkdir_with_parents(%s) succeeded, even if %s is a file\n", p1, p1);
sl@0:       g_assert(FALSE && "testglib");
sl@0:       return FALSE;
sl@0:     }
sl@0: #else
sl@0:   if (g_mkdir_with_parents (p1,  0666) == 0)
sl@0:     {
sl@0:       g_print ("failed, g_mkdir_with_parents(%s) succeeded, even if %s is a file\n", p1, p1);
sl@0:       g_assert(FALSE && "testglib");
sl@0:       return FALSE;
sl@0:     }
sl@0: #endif
sl@0: 
sl@0: #ifdef SYMBIAN
sl@0:   if (g_mkdir_with_parents (p2, S_IWUSR) == 0)
sl@0:     {
sl@0:       g_print ("failed, g_mkdir_with_parents(%s) succeeded, even if %s is a file\n", p2, p1);
sl@0:       g_assert(FALSE && "testglib");
sl@0:       return FALSE;
sl@0:     }
sl@0: #else
sl@0:   if (g_mkdir_with_parents (p2, 0666) == 0)
sl@0:     {
sl@0:       g_print ("failed, g_mkdir_with_parents(%s) succeeded, even if %s is a file\n", p2, p1);
sl@0:       g_assert(FALSE && "testglib");
sl@0:       return FALSE;
sl@0:     }
sl@0: #endif
sl@0: 
sl@0:   g_remove (p2);
sl@0:   g_remove (p1);
sl@0:   g_remove (p0);
sl@0: 
sl@0:   return TRUE;
sl@0: }
sl@0: 
sl@0: static gboolean
sl@0: test_g_mkdir_with_parents (void)
sl@0: {
sl@0:   #ifdef SYMBIAN
sl@0:   if (!test_g_mkdir_with_parents_1 ("c:\\hum")) 
sl@0:     return FALSE;
sl@0:   g_remove ("c:\\hum"); 
sl@0: #else
sl@0:   if (!test_g_mkdir_with_parents_1 ("hum")) 
sl@0:     return FALSE;
sl@0:   g_remove ("hum"); 
sl@0: #endif
sl@0: 
sl@0:   #ifndef SYMBIAN 
sl@0:   if (!test_g_mkdir_with_parents_1 ("hii///haa/hee"))
sl@0:     return FALSE;
sl@0:   g_remove ("hii/haa/hee");
sl@0:   g_remove ("hii/haa");
sl@0:   g_remove ("hii");
sl@0: 
sl@0:   #endif
sl@0:   
sl@0:   if (!test_g_mkdir_with_parents_1 (g_get_current_dir ()))
sl@0:     return FALSE;
sl@0: 
sl@0:   return TRUE;
sl@0: }
sl@0: 
sl@0: static void
sl@0: test_g_parse_debug_string (void)
sl@0: {
sl@0:   GDebugKey keys[3] = { 
sl@0:     { "foo", 1 },
sl@0:     { "bar", 2 },
sl@0:     { "baz", 4 }
sl@0:   };
sl@0:   guint n_keys = 3;
sl@0:   guint result;
sl@0:   
sl@0:   result = g_parse_debug_string ("bar:foo:blubb", keys, n_keys);
sl@0:   g_assert (result == 3);
sl@0: 
sl@0:   result = g_parse_debug_string (":baz::_E@~!_::", keys, n_keys);
sl@0:   g_assert (result == 4);
sl@0: 
sl@0:   result = g_parse_debug_string ("", keys, n_keys);
sl@0:   g_assert (result == 0);
sl@0: 
sl@0:   result = g_parse_debug_string (" : ", keys, n_keys);
sl@0:   g_assert (result == 0);
sl@0: }
sl@0: 
sl@0: 
sl@0: int
sl@0: main (int   argc,
sl@0:       char *argv[])
sl@0: {
sl@0:   const gchar *s;
sl@0:   gchar **sv;
sl@0:   GList *list, *t;
sl@0:   GSList *slist, *st;
sl@0:   GHashTable *hash_table;
sl@0:   GMemChunk *mem_chunk;
sl@0:   GStringChunk *string_chunk;
sl@0:   GTimer *timer, *timer2;
sl@0:   gdouble elapsed;
sl@0:   gulong elapsed_usecs;
sl@0:   gint nums[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
sl@0:   gint morenums[10] = { 8, 9, 7, 0, 3, 2, 5, 1, 4, 6};
sl@0:   gchar *string;
sl@0:   gint value = 120; 
sl@0:   gint *pvalue=NULL; 
sl@0:   
sl@0:   gchar *mem[10000], *tmp_string = NULL, *tmp_string_2;
sl@0:   gint i, j;
sl@0:   GArray *garray;
sl@0:   GPtrArray *gparray;
sl@0:   GByteArray *gbarray;
sl@0:   GString *string1, *string2;
sl@0:   const gchar *charset;
sl@0:   GTree *tree;
sl@0:   char chars[62];
sl@0:   GRelation *relation;
sl@0:   GTuples *tuples;
sl@0:   gint data [1024];
sl@0:   struct {
sl@0:     gchar *filename;
sl@0:     gchar *dirname;
sl@0:   } dirname_checks[] = {
sl@0:     { "/", "/" },
sl@0:     { "////", "/" },
sl@0:     { ".////", "." },
sl@0:     { "../", ".." },
sl@0:     { "..////", ".." },
sl@0:     { "a/b", "a" },
sl@0:     { "a/b/", "a/b" },
sl@0:     { "c///", "c" },
sl@0: #ifdef  G_OS_WIN32
sl@0:     { "\\", "\\" },
sl@0:     { ".\\\\\\\\", "." },
sl@0:     { "..\\", ".." },
sl@0:     { "..\\\\\\\\", ".." },
sl@0:     { "a\\b", "a" },
sl@0:     { "a\\b/", "a\\b" },
sl@0:     { "a/b\\", "a/b" },
sl@0:     { "c\\\\/", "c" },
sl@0:     { "//\\", "/" },
sl@0: #endif
sl@0: #ifdef G_WITH_CYGWIN
sl@0:     { "//server/share///x", "//server/share" },
sl@0: #endif
sl@0:     { ".", "." },
sl@0:     { "..", "." },
sl@0:     { "", "." },
sl@0:   };
sl@0:   guint n_dirname_checks = G_N_ELEMENTS (dirname_checks);
sl@0: 
sl@0:   struct {
sl@0:     gchar *filename;
sl@0:     gchar *without_root;
sl@0:   } skip_root_checks[] = {
sl@0:     { "/", "" },
sl@0:     { "//", "" },
sl@0:     { "/foo", "foo" },
sl@0:     { "//foo", "foo" },
sl@0:     { "a/b", NULL },
sl@0: #ifdef G_OS_WIN32
sl@0:     { "\\", "" },
sl@0:     { "\\foo", "foo" },
sl@0:     { "\\\\server\\foo", "" },
sl@0:     { "\\\\server\\foo\\bar", "bar" },
sl@0:     { "a\\b", NULL },
sl@0: #endif
sl@0: #ifdef G_WITH_CYGWIN
sl@0:     { "//server/share///x", "//x" },
sl@0: #endif
sl@0:     { ".", NULL },
sl@0:     { "", NULL },
sl@0:   };
sl@0:   guint n_skip_root_checks = G_N_ELEMENTS (skip_root_checks);
sl@0: 
sl@0: #ifndef G_DISABLE_ASSERT
sl@0:   guint16 gu16t1 = 0x44afU, gu16t2 = 0xaf44U;
sl@0:   guint32 gu32t1 = 0x02a7f109U, gu32t2 = 0x09f1a702U;
sl@0:   guint64 gu64t1 = G_GINT64_CONSTANT(0x1d636b02300a7aa7U),
sl@0: 	  gu64t2 = G_GINT64_CONSTANT(0xa77a0a30026b631dU);
sl@0: #endif
sl@0:   const char hello[] = "Hello, World";
sl@0:   const int hellolen = sizeof (hello) - 1;
sl@0:   int fd;
sl@0:   char template[32];
sl@0:   GError *error;
sl@0:   char *name_used;
sl@0: #ifdef G_OS_WIN32
sl@0:   /* Can't calculate GLib DLL name at runtime. */
sl@0:   gchar *glib_dll = "libglib-2.0-0.dll";
sl@0: #endif
sl@0: #ifdef G_WITH_CYGWIN
sl@0:   gchar *glib_dll = "cygglib-2.0-0.dll";
sl@0: #endif
sl@0: 
sl@0:   gchar hostname[256];
sl@0: 
sl@0:   #ifdef SYMBIAN
sl@0:   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:   g_set_print_handler(mrtPrintHandler);
sl@0:   #endif /*SYMBIAN*/
sl@0: 	  
sl@0:   #ifndef SYMBIAN
sl@0:   g_print ("TestGLib v%u.%u.%u (i:%u b:%u)\n",
sl@0: 	   glib_major_version,
sl@0: 	   glib_minor_version,
sl@0: 	   glib_micro_version,
sl@0: 	   glib_interface_age,
sl@0: 	   glib_binary_age);
sl@0:   #endif /* SYMBIAN */
sl@0: 
sl@0:   #ifndef EMULATOR
sl@0:   mkdir("C:\\Private\\e000002c", 0666);
sl@0:   chdir("C:\\Private\\e000002c");
sl@0:   #endif//EMULATOR
sl@0:   string = g_get_current_dir ();
sl@0:   g_assert(!strcmp(string,"C:\\Private\\e000002c"));
sl@0:     
sl@0:   string = (char *)g_get_user_name ();
sl@0:   g_assert(!strcmp(string,"root"));
sl@0:     
sl@0:   string = (char *)g_get_real_name ();
sl@0:   g_assert(!strcmp(string,"Unknown"));
sl@0:     
sl@0:   string = (char *)g_get_host_name ();
sl@0:   gethostname(hostname,256);
sl@0:   g_assert(!strcmp(string,hostname));
sl@0:     
sl@0:   s = g_get_home_dir ();
sl@0:   g_assert(!strcmp(s,"C:\\Private\\e000002c") && "Wrong value for g_get_home_dir()");
sl@0:   s = g_get_user_data_dir ();
sl@0:   g_assert(!strcmp(s,"C:\\Private\\e000002c"));
sl@0:   s = g_get_user_config_dir ();
sl@0:   g_assert(!strcmp(s,"C:\\Private\\e000002c"));
sl@0:   s = g_get_user_cache_dir ();
sl@0:   g_assert(!strcmp(s,"C:\\Private\\e000002c"));
sl@0:   sv = (gchar **) g_get_system_data_dirs ();
sl@0:   g_assert(!strcmp(sv[0],"C:\\Private\\e000002c"));
sl@0:   g_assert(sv[1] == NULL);
sl@0:   
sl@0:   sv = (gchar **) g_get_system_config_dirs ();
sl@0:   g_assert(!strcmp(sv[0],"C:\\Private\\e000002c"));
sl@0:   g_assert(sv[1] == NULL);
sl@0:   
sl@0:   string = (char *)g_get_tmp_dir ();
sl@0:   g_assert(!strcmp(string,"C:\\Private\\e000002c\\tmp") && "Wrong value for g_get_tmp_dir()");
sl@0:       
sl@0:   sv = (gchar **) g_get_language_names ();
sl@0:   g_assert(!strcmp(sv[0],"C"));
sl@0:   g_assert(!strcmp(sv[1],"C"));
sl@0:   g_assert(sv[2] == NULL);
sl@0:   
sl@0:   /* type sizes */
sl@0:   TEST (NULL, sizeof (gint8) == 1);
sl@0:   
sl@0:   TEST (NULL, sizeof (gint16) == 2);
sl@0:   
sl@0:   TEST (NULL, sizeof (gint32) == 4);
sl@0:   
sl@0:   TEST (NULL, sizeof (gint64) == 8);
sl@0:   
sl@0: 
sl@0:   string = g_path_get_basename (G_DIR_SEPARATOR_S "foo" G_DIR_SEPARATOR_S "dir" G_DIR_SEPARATOR_S);
sl@0:   g_assert (strcmp (string, "dir") == 0);
sl@0:   g_free (string);
sl@0:   
sl@0:   string = g_path_get_basename (G_DIR_SEPARATOR_S "foo" G_DIR_SEPARATOR_S "file");
sl@0:   g_assert (strcmp (string, "file") == 0);
sl@0:   g_free (string);
sl@0:   
sl@0: #ifdef G_OS_WIN32
sl@0:   string = g_path_get_basename ("/foo/dir/");
sl@0:   g_assert (strcmp (string, "dir") == 0);
sl@0:   g_free (string);
sl@0:   string = g_path_get_basename ("/foo/file");
sl@0:   g_assert (strcmp (string, "file") == 0);
sl@0:   g_free (string);
sl@0: #endif
sl@0: 
sl@0:   //g_print ("checking g_path_get_dirname()...");
sl@0:   for (i = 0; i < n_dirname_checks; i++)
sl@0:     {
sl@0:       gchar *dirname;
sl@0: 
sl@0:       dirname = g_path_get_dirname (dirname_checks[i].filename);
sl@0:       if (strcmp (dirname, dirname_checks[i].dirname) != 0)
sl@0: 	{
sl@0: 	  g_print ("\nfailed for \"%s\"==\"%s\" (returned: \"%s\")\n",
sl@0: 		   dirname_checks[i].filename,
sl@0: 		   dirname_checks[i].dirname,
sl@0: 		   dirname);
sl@0: 	  g_assert(FALSE && "testglib");
sl@0: 	  n_dirname_checks = 0;
sl@0: 	}
sl@0:       g_free (dirname);
sl@0:     }
sl@0:   g_assert(n_dirname_checks != 0 && "g_path_get_dirname failed" );
sl@0:   
sl@0:   //g_print ("checking g_path_skip_root()...");
sl@0:   for (i = 0; i < n_skip_root_checks; i++)
sl@0:     {
sl@0:       const gchar *skipped;
sl@0: 
sl@0:       skipped = g_path_skip_root (skip_root_checks[i].filename);
sl@0:       if ((skipped && !skip_root_checks[i].without_root) ||
sl@0: 	  (!skipped && skip_root_checks[i].without_root) ||
sl@0: 	  ((skipped && skip_root_checks[i].without_root) &&
sl@0: 	   strcmp (skipped, skip_root_checks[i].without_root)))
sl@0: 	{
sl@0: 	  g_print ("\nfailed for \"%s\"==\"%s\" (returned: \"%s\")\n",
sl@0: 		   skip_root_checks[i].filename,
sl@0: 		   (skip_root_checks[i].without_root ?
sl@0: 		    skip_root_checks[i].without_root : "<NULL>"),
sl@0: 		   (skipped ? skipped : "<NULL>"));
sl@0: 	  g_assert(FALSE && "testglib");
sl@0: 	  n_skip_root_checks = 0;
sl@0: 	}
sl@0:     }
sl@0:   g_assert(n_skip_root_checks != 0 && "g_path_skip_root failed" );
sl@0:   
sl@0:   g_assert(test_g_mkdir_with_parents());
sl@0:   //g_print ("checking doubly linked lists...");
sl@0: 
sl@0:   list = NULL;
sl@0:   for (i = 0; i < 10; i++)
sl@0:     list = g_list_append (list, &nums[i]);
sl@0:   list = g_list_reverse (list);
sl@0: 
sl@0:   for (i = 0; i < 10; i++)
sl@0:     {
sl@0:       t = g_list_nth (list, i);
sl@0:       if (*((gint*) t->data) != (9 - i))
sl@0: 	g_error ("Regular insert failed");
sl@0:     }
sl@0: 
sl@0:   for (i = 0; i < 10; i++)
sl@0:     if(g_list_position(list, g_list_nth (list, i)) != i)
sl@0:       g_error("g_list_position does not seem to be the inverse of g_list_nth\n");
sl@0: 
sl@0:   g_list_free (list);
sl@0:   list = NULL;
sl@0: 
sl@0:   for (i = 0; i < 10; i++)
sl@0:     list = g_list_insert_sorted (list, &morenums[i], my_list_compare_one);
sl@0: 
sl@0:   for (i = 0; i < 10; i++)
sl@0:     {
sl@0:       t = g_list_nth (list, i);
sl@0:       if (*((gint*) t->data) != i)
sl@0:          g_error ("Sorted insert failed");
sl@0:     }
sl@0: 
sl@0:   g_list_free (list);
sl@0:   list = NULL;
sl@0: 
sl@0:   for (i = 0; i < 10; i++)
sl@0:     list = g_list_insert_sorted (list, &morenums[i], my_list_compare_two);
sl@0: 
sl@0:     for (i = 0; i < 10; i++)
sl@0:     {
sl@0:       t = g_list_nth (list, i);
sl@0:       if (*((gint*) t->data) != (9 - i))
sl@0:          g_error ("Sorted insert failed");
sl@0:     }
sl@0: 
sl@0:   g_list_free (list);
sl@0:   list = NULL;
sl@0: 
sl@0:   for (i = 0; i < 10; i++)
sl@0:     list = g_list_prepend (list, &morenums[i]);
sl@0: 
sl@0:   list = g_list_sort (list, my_list_compare_two);
sl@0: 
sl@0:   
sl@0:   for (i = 0; i < 10; i++)
sl@0:     {
sl@0:       t = g_list_nth (list, i);
sl@0:       if (*((gint*) t->data) != (9 - i))
sl@0:          g_error ("Merge sort failed");
sl@0:     }
sl@0: 
sl@0:   g_list_free (list);
sl@0:   //g_print ("ok\n");
sl@0:   //g_print ("checking singly linked lists...");
sl@0: 
sl@0:   slist = NULL;
sl@0:   for (i = 0; i < 10; i++)
sl@0:     slist = g_slist_append (slist, &nums[i]);
sl@0:   slist = g_slist_reverse (slist);
sl@0: 
sl@0:   for (i = 0; i < 10; i++)
sl@0:     {
sl@0:       st = g_slist_nth (slist, i);
sl@0:       if (*((gint*) st->data) != (9 - i))
sl@0: 	g_error ("failed");
sl@0:     }
sl@0: 
sl@0:   g_slist_free (slist);
sl@0:   slist = NULL;
sl@0: 
sl@0:   for (i = 0; i < 10; i++)
sl@0:     slist = g_slist_insert_sorted (slist, &morenums[i], my_list_compare_one);
sl@0: 
sl@0:   for (i = 0; i < 10; i++)
sl@0:     {
sl@0:       st = g_slist_nth (slist, i);
sl@0:       if (*((gint*) st->data) != i)
sl@0:          g_error ("Sorted insert failed");
sl@0:     }
sl@0: 
sl@0:   g_slist_free(slist);
sl@0:   slist = NULL;
sl@0: 
sl@0:   for (i = 0; i < 10; i++)
sl@0:     slist = g_slist_insert_sorted (slist, &morenums[i], my_list_compare_two);
sl@0: 
sl@0: 
sl@0:   for (i = 0; i < 10; i++)
sl@0:     {
sl@0:       st = g_slist_nth (slist, i);
sl@0:       if (*((gint*) st->data) != (9 - i))
sl@0:          g_error("Sorted insert failed");
sl@0:     }
sl@0: 
sl@0:   g_slist_free(slist);
sl@0:   slist = NULL;
sl@0: 
sl@0:   for (i = 0; i < 10; i++)
sl@0:     slist = g_slist_prepend (slist, &morenums[i]);
sl@0: 
sl@0:   slist = g_slist_sort (slist, my_list_compare_two);
sl@0: 
sl@0: 
sl@0:   for (i = 0; i < 10; i++)
sl@0:     {
sl@0:       st = g_slist_nth (slist, i);
sl@0:       if (*((gint*) st->data) != (9 - i))
sl@0:          g_error("Sorted insert failed");
sl@0:     }
sl@0: 
sl@0:   g_slist_free(slist);
sl@0:   //g_print ("ok\n");
sl@0:   //g_print ("checking binary trees...\n");
sl@0: 
sl@0:   tree = g_tree_new (my_compare);
sl@0:   i = 0;
sl@0:   for (j = 0; j < 10; j++, i++)
sl@0:     {
sl@0:       chars[i] = '0' + j;
sl@0:       g_tree_insert (tree, &chars[i], &chars[i]);
sl@0:     }
sl@0:   for (j = 0; j < 26; j++, i++)
sl@0:     {
sl@0:       chars[i] = 'A' + j;
sl@0:       g_tree_insert (tree, &chars[i], &chars[i]);
sl@0:     }
sl@0:   for (j = 0; j < 26; j++, i++)
sl@0:     {
sl@0:       chars[i] = 'a' + j;
sl@0:       g_tree_insert (tree, &chars[i], &chars[i]);
sl@0:     }
sl@0: 
sl@0:   g_assert(g_tree_height(tree) == 6);
sl@0:   g_assert(g_tree_nnodes(tree) == 62);
sl@0: 
sl@0:   for (i = 0; i < 10; i++)
sl@0:     g_tree_remove (tree, &chars[i]);
sl@0: 
sl@0:   g_assert(g_tree_height(tree) == 6);
sl@0:   g_assert(g_tree_nnodes(tree) == 52);
sl@0: 
sl@0:   //g_print ("tree: ");
sl@0:   //g_tree_foreach (tree, my_traverse, NULL);
sl@0:   //g_print ("\n");
sl@0: 
sl@0:   //g_print ("ok\n");
sl@0:   /* check n-way trees */
sl@0:   g_node_test ();
sl@0: 
sl@0:   //g_print ("checking mem chunks...");
sl@0:   mem_chunk = g_mem_chunk_new ("test mem chunk", 50, 100, G_ALLOC_AND_FREE);
sl@0: 
sl@0: #ifdef SYMBIAN
sl@0:   for (i = 0; i < 6000 ; i++)
sl@0:     {
sl@0:       mem[i] = g_chunk_new (gchar, mem_chunk);
sl@0: 
sl@0:       for (j = 0; j < 50; j++)
sl@0: 	mem[i][j] = i * j;
sl@0:     }
sl@0: #else
sl@0:     for (i = 0; i <  10000 ; i++)
sl@0:     {
sl@0:       mem[i] = g_chunk_new (gchar, mem_chunk);
sl@0: 
sl@0:       for (j = 0; j < 50; j++)
sl@0: 	mem[i][j] = i * j;
sl@0:     }
sl@0: #endif
sl@0:    
sl@0: 
sl@0: #ifdef SYMBIAN
sl@0:   for (i = 0; i < 6000 ; i++)
sl@0:     {
sl@0:       g_mem_chunk_free (mem_chunk, mem[i]);
sl@0:     }
sl@0:   #else
sl@0:   for (i = 0; i < i  10000; i++)
sl@0:     {
sl@0:       g_mem_chunk_free (mem_chunk, mem[i]);
sl@0:     }
sl@0: #endif
sl@0:   //g_print ("checking hash tables...");
sl@0:   
sl@0:   hash_table = g_hash_table_new (my_hash, my_hash_equal);
sl@0: 
sl@0:   #ifdef SYMBIAN
sl@0:   for (i = 0; i < 3000 ; i++)
sl@0:     {
sl@0:       array[i] = i;
sl@0:       g_hash_table_insert (hash_table, &array[i], &array[i]);
sl@0:     }
sl@0:   #else
sl@0:     for (i = 0; i < i 10000 ; i++)
sl@0:     {
sl@0:       array[i] = i;
sl@0:       g_hash_table_insert (hash_table, &array[i], &array[i]);
sl@0:     }
sl@0: #endif
sl@0: 
sl@0:   pvalue = g_hash_table_find (hash_table, find_first_that, &value);
sl@0:   if (*pvalue != value)
sl@0:   {
sl@0:   	
sl@0: 	  g_print("g_hash_table_find failed");
sl@0: 	  g_assert(FALSE && "testglib");
sl@0:   }
sl@0:   g_hash_table_foreach (hash_table, my_hash_callback, NULL);
sl@0: 
sl@0: #ifdef SYMBIAN
sl@0:   for (i = 0; i < 3000 ; i++)
sl@0:     if (array[i] == 0)
sl@0:       g_print ("%d\n", i);
sl@0: #else
sl@0:   for (i = 0; i <  10000; i++)
sl@0:     if (array[i] == 0)
sl@0:       g_print ("%d\n", i);
sl@0: #endif
sl@0: 
sl@0: #ifdef SYMBIAN
sl@0:   for (i = 0; i < 3000 ; i++)
sl@0:     g_hash_table_remove (hash_table, &array[i]);
sl@0:   #else
sl@0:   for (i = 0; i < 10000; i++)
sl@0:     g_hash_table_remove (hash_table, &array[i]);
sl@0:   #endif
sl@0: 
sl@0: #ifdef SYMBIAN
sl@0:   for (i = 0; i < 3000 ; i++)
sl@0:     {
sl@0:       array[i] = i;
sl@0:       g_hash_table_insert (hash_table, &array[i], &array[i]);
sl@0:     }
sl@0:   #else
sl@0:     for (i = 0; i < 10000; i++)
sl@0:     {
sl@0:       array[i] = i;
sl@0:       g_hash_table_insert (hash_table, &array[i], &array[i]);
sl@0:     }
sl@0: #endif
sl@0: 
sl@0: #ifdef SYMBIAN
sl@0:   if (g_hash_table_foreach_remove (hash_table, my_hash_callback_remove, NULL) !=  1500  ||
sl@0:       g_hash_table_size (hash_table) != 1500 )
sl@0:     g_print ("bad!\n");
sl@0:   #else
sl@0:     if (g_hash_table_foreach_remove (hash_table, my_hash_callback_remove, NULL) !=   5000 ||
sl@0:       g_hash_table_size (hash_table) !=  5000)
sl@0:     g_print ("bad!\n");
sl@0: #endif
sl@0:   
sl@0: 
sl@0:   g_hash_table_foreach (hash_table, my_hash_callback_remove_test, NULL);
sl@0: 
sl@0: 
sl@0:   g_hash_table_destroy (hash_table);
sl@0: 
sl@0:   string_chunk = g_string_chunk_new (1024);
sl@0: 
sl@0: #ifdef SYMBIAN
sl@0:   for (i = 0; i < 3000; i ++)
sl@0:     {
sl@0:       tmp_string = g_string_chunk_insert (string_chunk, "hi pete");
sl@0: 
sl@0:       if (strcmp ("hi pete", tmp_string) != 0)
sl@0: 	g_error ("string chunks are broken.\n");
sl@0:     }
sl@0: #else
sl@0:   for (i = 0; i < 100000; i ++)
sl@0:     {
sl@0:       tmp_string = g_string_chunk_insert (string_chunk, "hi pete");
sl@0: 
sl@0:       if (strcmp ("hi pete", tmp_string) != 0)
sl@0: 	g_error ("string chunks are broken.\n");
sl@0:     }
sl@0: #endif
sl@0: 
sl@0:   tmp_string_2 = g_string_chunk_insert_const (string_chunk, tmp_string);
sl@0: 
sl@0:   g_assert (tmp_string_2 != tmp_string &&
sl@0: 	    strcmp(tmp_string_2, tmp_string) == 0);
sl@0: 
sl@0:   tmp_string = g_string_chunk_insert_const (string_chunk, tmp_string);
sl@0: 
sl@0:   g_assert (tmp_string_2 == tmp_string);
sl@0: 
sl@0:   g_string_chunk_free (string_chunk);
sl@0: 
sl@0:   //g_print ("ok\n");
sl@0:   //g_print ("checking arrays...");
sl@0:   garray = g_array_new (FALSE, FALSE, sizeof (gint));
sl@0: 
sl@0:   #ifdef SYMBIAN
sl@0:   for (i = 0; i < 3000; i++)
sl@0:     g_array_append_val (garray, i);
sl@0:   #else
sl@0:     for (i = 0; i < 10000; i++)
sl@0:     g_array_append_val (garray, i);
sl@0: #endif
sl@0: 
sl@0: #ifdef SYMBIAN
sl@0:   for (i = 0; i < 3000 ; i++)
sl@0:     if (g_array_index (garray, gint, i) != i)
sl@0:       g_print ("uh oh: %d ( %d )\n", g_array_index (garray, gint, i), i);
sl@0: #else
sl@0:   for (i = 0; i < i 10000; i++)
sl@0:     if (g_array_index (garray, gint, i) != i)
sl@0:       g_print ("uh oh: %d ( %d )\n", g_array_index (garray, gint, i), i);
sl@0: #endif
sl@0: 
sl@0:   g_array_free (garray, TRUE);
sl@0: 
sl@0:   garray = g_array_new (FALSE, FALSE, sizeof (gint));
sl@0:   for (i = 0; i < 100; i++)
sl@0:     g_array_prepend_val (garray, i);
sl@0: 
sl@0:   for (i = 0; i < 100; i++)
sl@0:     if (g_array_index (garray, gint, i) != (100 - i - 1))
sl@0:       g_print ("uh oh: %d ( %d )\n", g_array_index (garray, gint, i), 100 - i - 1);
sl@0: 
sl@0:   g_array_free (garray, TRUE);
sl@0: 
sl@0:   //g_print ("ok\n");
sl@0:   //g_print ("checking strings...");
sl@0:   string1 = g_string_new ("hi pete!");
sl@0:   string2 = g_string_new ("");
sl@0: 
sl@0:   g_assert (strcmp ("hi pete!", string1->str) == 0);
sl@0: 
sl@0:   for (i = 0; i < 10000; i++)
sl@0:     g_string_append_c (string1, 'a'+(i%26));
sl@0: 
sl@0: #ifdef SYMBIAN
sl@0:   g_string_printf (string2, "%s|%0100d|%s|%s|%0*d|%*.*f|%100.100f",
sl@0: 		   "this pete guy sure is a wuss, like he's the number ",
sl@0: 		   1,
sl@0: 		   " wuss.  everyone agrees.\n",
sl@0: 		   string1->str,
sl@0: 		   10, 666, 15, 15, 666.666666666, 666.666666666);
sl@0: #else
sl@0: #ifndef G_OS_WIN32
sl@0:   /* MSVC, mingw32 and LCC use the same run-time C library, which doesn't like
sl@0:      the %10000.10000f format... */
sl@0:   g_string_printf (string2, "%s|%0100d|%s|%s|%0*d|%*.*f|%10000.10000f",
sl@0: 		   "this pete guy sure is a wuss, like he's the number ",
sl@0: 		   1,
sl@0: 		   " wuss.  everyone agrees.\n",
sl@0: 		   string1->str,
sl@0: 		   10, 666, 15, 15, 666.666666666, 666.666666666);
sl@0: #else   
sl@0:   g_string_printf (string2, "%s|%0100d|%s|%s|%0*d|%*.*f|%100.100f",
sl@0: 		   "this pete guy sure is a wuss, like he's the number ",
sl@0: 		   1,
sl@0: 		   " wuss.  everyone agrees.\n",
sl@0: 		   string1->str,
sl@0: 		   10, 666, 15, 15, 666.666666666, 666.666666666);
sl@0:  #endif
sl@0: #endif  /* SYMBIAN */
sl@0: 
sl@0:   g_assert((gulong)string2->len == 10323);
sl@0:   g_string_free (string1, TRUE);
sl@0:   g_string_free (string2, TRUE);
sl@0: 
sl@0:   /* append */
sl@0:   string1 = g_string_new ("firsthalf");
sl@0:   g_string_append (string1, "lasthalf");
sl@0:   g_assert (strcmp (string1->str, "firsthalflasthalf") == 0);
sl@0:   g_string_free (string1, TRUE);
sl@0: 
sl@0:   /* append_len */
sl@0: 
sl@0:   string1 = g_string_new ("firsthalf");
sl@0:   g_string_append_len (string1, "lasthalfjunkjunk", strlen ("lasthalf"));
sl@0:   g_assert (strcmp (string1->str, "firsthalflasthalf") == 0);
sl@0:   g_string_free (string1, TRUE);  
sl@0:   
sl@0:   /* prepend */
sl@0:   string1 = g_string_new ("lasthalf");
sl@0:   g_string_prepend (string1, "firsthalf");
sl@0:   g_assert (strcmp (string1->str, "firsthalflasthalf") == 0);
sl@0:   g_string_free (string1, TRUE);
sl@0: 
sl@0:   /* prepend_len */
sl@0:   string1 = g_string_new ("lasthalf");
sl@0:   g_string_prepend_len (string1, "firsthalfjunkjunk", strlen ("firsthalf"));
sl@0:   g_assert (strcmp (string1->str, "firsthalflasthalf") == 0);
sl@0:   g_string_free (string1, TRUE);
sl@0:   
sl@0:   /* insert */
sl@0:   string1 = g_string_new ("firstlast");
sl@0:   g_string_insert (string1, 5, "middle");
sl@0:   g_assert (strcmp (string1->str, "firstmiddlelast") == 0);
sl@0:   g_string_free (string1, TRUE);
sl@0: 
sl@0:   /* insert with pos == end of the string */
sl@0:   string1 = g_string_new ("firstmiddle");
sl@0:   g_string_insert (string1, strlen ("firstmiddle"), "last");
sl@0:   g_assert (strcmp (string1->str, "firstmiddlelast") == 0);
sl@0:   g_string_free (string1, TRUE);
sl@0:   
sl@0:   /* insert_len */
sl@0: 
sl@0:   string1 = g_string_new ("firstlast");
sl@0:   g_string_insert_len (string1, 5, "middlejunkjunk", strlen ("middle"));
sl@0:   g_assert (strcmp (string1->str, "firstmiddlelast") == 0);
sl@0:   g_string_free (string1, TRUE);
sl@0: 
sl@0:   /* insert_len with magic -1 pos for append */
sl@0:   string1 = g_string_new ("first");
sl@0:   g_string_insert_len (string1, -1, "lastjunkjunk", strlen ("last"));
sl@0:   g_assert (strcmp (string1->str, "firstlast") == 0);
sl@0:   g_string_free (string1, TRUE);
sl@0:   
sl@0:   /* insert_len with magic -1 len for strlen-the-string */
sl@0:   string1 = g_string_new ("first");
sl@0:   g_string_insert_len (string1, 5, "last", -1);
sl@0:   g_assert (strcmp (string1->str, "firstlast") == 0);
sl@0:   g_string_free (string1, TRUE);
sl@0:   
sl@0:   /* g_string_equal */
sl@0:   string1 = g_string_new ("test");
sl@0:   string2 = g_string_new ("te");
sl@0:   g_assert (! g_string_equal(string1, string2));
sl@0:   g_string_append (string2, "st");
sl@0:   g_assert (g_string_equal(string1, string2));
sl@0:   g_string_free (string1, TRUE);
sl@0:   g_string_free (string2, TRUE);
sl@0:   
sl@0:   /* Check handling of embedded ASCII 0 (NUL) characters in GString. */
sl@0:   string1 = g_string_new ("fiddle");
sl@0:   string2 = g_string_new ("fiddle");
sl@0:   g_assert (g_string_equal(string1, string2));
sl@0:   g_string_append_c(string1, '\0');
sl@0:   g_assert (! g_string_equal(string1, string2));
sl@0:   g_string_append_c(string2, '\0');
sl@0:   g_assert (g_string_equal(string1, string2));
sl@0:   g_string_append_c(string1, 'x');
sl@0:   g_string_append_c(string2, 'y');
sl@0:   g_assert (! g_string_equal(string1, string2));
sl@0:   g_assert (string1->len == 8);
sl@0:   g_string_append(string1, "yzzy");
sl@0:   g_assert (string1->len == 12);
sl@0:   g_assert ( memcmp(string1->str, "fiddle\0xyzzy", 13) == 0);
sl@0:   g_string_insert(string1, 1, "QED");
sl@0:   g_assert ( memcmp(string1->str, "fQEDiddle\0xyzzy", 16) == 0);
sl@0:   g_string_free (string1, TRUE);
sl@0:   g_string_free (string2, TRUE);
sl@0:   
sl@0:   //g_print ("test positional printf formats (not supported): ");
sl@0:   string = g_strdup_printf ("%.*s%s", 5, "a", "b");
sl@0:   tmp_string = g_strdup_printf ("%2$*1$s", 5, "c");
sl@0:   g_assert(!strcmp(string,"ab"));
sl@0:   g_assert(!strcmp(tmp_string,"    c"));
sl@0:   g_free (tmp_string);
sl@0:   g_free (string);
sl@0: 
sl@0:   timer = g_timer_new ();
sl@0:   
sl@0:   g_timer_start (timer);
sl@0:   while (g_timer_elapsed (timer, NULL) < 3)
sl@0:     ;
sl@0: 
sl@0:   g_timer_stop (timer);
sl@0:   g_timer_destroy (timer);
sl@0: 
sl@0:   timer2 = g_timer_new ();
sl@0: 
sl@0:   timer = g_timer_new();
sl@0:   g_usleep(G_USEC_PER_SEC); /* run timer for 1 second */
sl@0:   g_timer_stop(timer);
sl@0: 
sl@0:   g_usleep(G_USEC_PER_SEC); /* wait for 1 second */
sl@0:   
sl@0:   g_timer_continue(timer);
sl@0:   g_usleep(2*G_USEC_PER_SEC); /* run timer for 2 seconds */
sl@0:   g_timer_stop(timer);
sl@0: 
sl@0:   g_usleep((3*G_USEC_PER_SEC)/2); /* wait for 1.5 seconds */
sl@0:   
sl@0:   g_timer_continue(timer);
sl@0:   g_usleep(G_USEC_PER_SEC/5); /* run timer for 0.2 seconds */
sl@0:   g_timer_stop(timer);
sl@0: 
sl@0:   g_usleep(4*G_USEC_PER_SEC); /* wait for 4 seconds */
sl@0:   
sl@0:   g_timer_continue(timer);
sl@0:   g_usleep((29*G_USEC_PER_SEC)/5); /* run timer for 5.8 seconds */
sl@0:   g_timer_stop(timer);
sl@0: 
sl@0:   elapsed = g_timer_elapsed (timer, &elapsed_usecs);
sl@0:   
sl@0:   if (elapsed > 8.8 && elapsed < 9.2);
sl@0:     
sl@0:   else
sl@0:   {
sl@0:   	g_assert(FALSE && "testglib");	
sl@0:     g_print ("g_timer_continue ... ***** FAILED *****\n\n");
sl@0:     g_print ("timer elapsed %d\n",elapsed);
sl@0:   }
sl@0:   g_timer_stop(timer2);
sl@0: 
sl@0:   elapsed = g_timer_elapsed(timer2, &elapsed_usecs);
sl@0:   
sl@0:   if (elapsed > (8.8+6.5) && elapsed < (9.2+6.5));
sl@0:     
sl@0:   else
sl@0:   {
sl@0:   	g_assert(FALSE && "testglib");	
sl@0:     g_print ("timer2 ... ***** FAILED *****\n\n");
sl@0:     g_print ("timer2 elapsed %d\n",elapsed);
sl@0:   }
sl@0:   g_timer_destroy(timer);
sl@0:   g_timer_destroy(timer2);
sl@0: 
sl@0:   g_assert (g_ascii_strcasecmp ("FroboZZ", "frobozz") == 0);
sl@0:   g_assert (g_ascii_strcasecmp ("frobozz", "frobozz") == 0);
sl@0:   g_assert (g_ascii_strcasecmp ("frobozz", "FROBOZZ") == 0);
sl@0:   g_assert (g_ascii_strcasecmp ("FROBOZZ", "froboz") > 0);
sl@0:   g_assert (g_ascii_strcasecmp ("", "") == 0);
sl@0:   g_assert (g_ascii_strcasecmp ("!#%&/()", "!#%&/()") == 0);
sl@0:   g_assert (g_ascii_strcasecmp ("a", "b") < 0);
sl@0:   g_assert (g_ascii_strcasecmp ("a", "B") < 0);
sl@0:   g_assert (g_ascii_strcasecmp ("A", "b") < 0);
sl@0:   g_assert (g_ascii_strcasecmp ("A", "B") < 0);
sl@0:   g_assert (g_ascii_strcasecmp ("b", "a") > 0);
sl@0:   g_assert (g_ascii_strcasecmp ("b", "A") > 0);
sl@0:   g_assert (g_ascii_strcasecmp ("B", "a") > 0);
sl@0:   g_assert (g_ascii_strcasecmp ("B", "A") > 0);
sl@0: 
sl@0:   g_assert(g_strdup(NULL) == NULL);
sl@0:   string = g_strdup(GLIB_TEST_STRING);
sl@0:   g_assert(string != NULL);
sl@0:   g_assert(strcmp(string, GLIB_TEST_STRING) == 0);
sl@0:   g_free(string);
sl@0: 
sl@0:   string = g_strconcat(GLIB_TEST_STRING, NULL);
sl@0:   g_assert(string != NULL);
sl@0:   g_assert(strcmp(string, GLIB_TEST_STRING) == 0);
sl@0:   g_free(string);
sl@0:   string = g_strconcat(GLIB_TEST_STRING, GLIB_TEST_STRING, 
sl@0:   		       GLIB_TEST_STRING, NULL);
sl@0:   g_assert(string != NULL);
sl@0:   g_assert(strcmp(string, GLIB_TEST_STRING GLIB_TEST_STRING
sl@0:   			  GLIB_TEST_STRING) == 0);
sl@0:   g_free(string);
sl@0:   
sl@0: 
sl@0:   /* The following is a torture test for strlcpy/strlcat, with lots of
sl@0:    * checking; normal users wouldn't use them this way!
sl@0:    */
sl@0:   string = g_malloc (6);
sl@0:   *(string + 5) = 'Z'; /* guard value, shouldn't change during test */
sl@0:   *string = 'q';
sl@0:   g_assert (g_strlcpy(string, "" , 5) == 0);
sl@0:   g_assert ( *string == '\0' );
sl@0:   *string = 'q';
sl@0:   g_assert (g_strlcpy(string, "abc" , 5) == 3);
sl@0:   g_assert ( *(string + 3) == '\0' );
sl@0:   g_assert (g_str_equal(string, "abc"));
sl@0:   g_assert (g_strlcpy(string, "abcd" , 5) == 4);
sl@0:   g_assert ( *(string + 4) == '\0' );
sl@0:   g_assert ( *(string + 5) == 'Z' );
sl@0:   g_assert (g_str_equal(string, "abcd"));
sl@0:   g_assert (g_strlcpy(string, "abcde" , 5) == 5);
sl@0:   g_assert ( *(string + 4) == '\0' );
sl@0:   g_assert ( *(string + 5) == 'Z' );
sl@0:   g_assert (g_str_equal(string, "abcd"));
sl@0:   g_assert (g_strlcpy(string, "abcdef" , 5) == 6);
sl@0:   g_assert ( *(string + 4) == '\0' );
sl@0:   g_assert ( *(string + 5) == 'Z' );
sl@0:   g_assert (g_str_equal(string, "abcd"));
sl@0:   *string = 'Y';
sl@0:   *(string + 1)= '\0';
sl@0:   g_assert (g_strlcpy(string, "Hello" , 0) == 5);
sl@0:   g_assert (*string == 'Y');
sl@0:   *string = '\0';
sl@0:   g_assert (g_strlcat(string, "123" , 5) == 3);
sl@0:   g_assert ( *(string + 3) == '\0' );
sl@0:   g_assert (g_str_equal(string, "123"));
sl@0:   g_assert (g_strlcat(string, "" , 5) == 3);
sl@0:   g_assert ( *(string + 3) == '\0' );
sl@0:   g_assert (g_str_equal(string, "123"));
sl@0:   g_assert (g_strlcat(string, "4", 5) == 4);
sl@0:   g_assert (g_str_equal(string, "1234"));
sl@0:   g_assert (g_strlcat(string, "5", 5) == 5);
sl@0:   g_assert ( *(string + 4) == '\0' );
sl@0:   g_assert (g_str_equal(string, "1234"));
sl@0:   g_assert ( *(string + 5) == 'Z' );
sl@0:   *string = 'Y';
sl@0:   *(string + 1)= '\0';
sl@0:   g_assert (g_strlcat(string, "123" , 0) == 3);
sl@0:   g_assert (*string == 'Y');
sl@0:   
sl@0:   /* A few more tests, demonstrating more "normal" use  */
sl@0:   g_assert (g_strlcpy(string, "hi", 5) == 2);
sl@0:   g_assert (g_str_equal(string, "hi"));
sl@0:   g_assert (g_strlcat(string, "t", 5) == 3);
sl@0:   g_assert (g_str_equal(string, "hit"));
sl@0:   g_free(string);
sl@0: 
sl@0:   string = g_strdup_printf ("%05d %-5s", 21, "test");
sl@0:   g_assert (string != NULL);
sl@0:   g_assert (strcmp(string, "00021 test ") == 0);
sl@0:   g_free (string);
sl@0: 
sl@0: 
sl@0:   /* g_debug (argv[0]); */
sl@0: 
sl@0:   /* Relation tests */
sl@0: 
sl@0:   relation = g_relation_new (2);
sl@0: 
sl@0:   g_relation_index (relation, 0, g_int_hash, g_int_equal);
sl@0:   g_relation_index (relation, 1, g_int_hash, g_int_equal);
sl@0: 
sl@0: #ifdef SYMBIAN
sl@0:   for (i = 0; i < 250 ; i += 1)
sl@0:     data[i] = i;
sl@0: #else    
sl@0:   for (i = 0; i <  1024; i += 1)
sl@0:     data[i] = i;
sl@0: #endif
sl@0: 
sl@0: #ifdef SYMBIAN
sl@0:   for (i = 1; i < 250 ; i += 1)
sl@0:     {
sl@0:       g_relation_insert (relation, data + i, data + i + 1);
sl@0:       g_relation_insert (relation, data + i, data + i - 1);
sl@0:     }
sl@0: #else
sl@0:   for (i = 1; i <  1023; i += 1)
sl@0:     {
sl@0:       g_relation_insert (relation, data + i, data + i + 1);
sl@0:       g_relation_insert (relation, data + i, data + i - 1);
sl@0:     }
sl@0: #endif
sl@0: 
sl@0: #ifdef SYMBIAN
sl@0:   for (i = 2; i < 249; i += 1)
sl@0:     {
sl@0:       g_assert (! g_relation_exists (relation, data + i, data + i));
sl@0:       g_assert (! g_relation_exists (relation, data + i, data + i + 2));
sl@0:       g_assert (! g_relation_exists (relation, data + i, data + i - 2));
sl@0:     }
sl@0: #else
sl@0:   for (i = 2; i <  1022; i += 1)
sl@0:     {
sl@0:       g_assert (! g_relation_exists (relation, data + i, data + i));
sl@0:       g_assert (! g_relation_exists (relation, data + i, data + i + 2));
sl@0:       g_assert (! g_relation_exists (relation, data + i, data + i - 2));
sl@0:     }
sl@0: #endif
sl@0: 
sl@0: #ifdef SYMBIAN
sl@0:   for (i = 1; i < 250 ; i += 1)
sl@0:     {
sl@0:       g_assert (g_relation_exists (relation, data + i, data + i + 1));
sl@0:       g_assert (g_relation_exists (relation, data + i, data + i - 1));
sl@0:     }
sl@0: #else
sl@0:   for (i = 1; i <  1023;  i += 1)
sl@0:     {
sl@0:       g_assert (g_relation_exists (relation, data + i, data + i + 1));
sl@0:       g_assert (g_relation_exists (relation, data + i, data + i - 1));
sl@0:     }
sl@0: #endif
sl@0: 
sl@0: #ifdef SYMBIAN
sl@0:   for (i = 2; i < 249; i += 1)
sl@0:     {
sl@0:       g_assert (g_relation_count (relation, data + i, 0) == 2);
sl@0:       g_assert (g_relation_count (relation, data + i, 1) == 2);
sl@0:     }
sl@0:   #else
sl@0:     for (i = 2; i <  1022; i += 1)
sl@0:     {
sl@0:       g_assert (g_relation_count (relation, data + i, 0) == 2);
sl@0:       g_assert (g_relation_count (relation, data + i, 1) == 2);
sl@0:     }
sl@0: #endif
sl@0:     
sl@0:   g_assert (g_relation_count (relation, data, 0) == 0);
sl@0: 
sl@0:   g_assert (g_relation_count (relation, data + 42, 0) == 2);
sl@0:   g_assert (g_relation_count (relation, data + 43, 1) == 2);
sl@0:   g_assert (g_relation_count (relation, data + 41, 1) == 2);
sl@0:   g_relation_delete (relation, data + 42, 0);
sl@0:   g_assert (g_relation_count (relation, data + 42, 0) == 0);
sl@0:   g_assert (g_relation_count (relation, data + 43, 1) == 1);
sl@0:   g_assert (g_relation_count (relation, data + 41, 1) == 1);
sl@0: 
sl@0:   tuples = g_relation_select (relation, data + 200, 0);
sl@0: 
sl@0:   g_assert (tuples->len == 2);
sl@0: 
sl@0: 
sl@0: #ifdef SYMBIAN
sl@0:   g_assert (g_relation_exists (relation, data + 100, data + 101 ));
sl@0:   g_relation_delete (relation, data + 100 , 0);
sl@0:   g_assert (!g_relation_exists (relation, data + 100 , data + 101 ));
sl@0: #else
sl@0:   g_assert (g_relation_exists (relation, data +  300, data + i 301));
sl@0:   g_relation_delete (relation, data + 300, 0);
sl@0:   g_assert (!g_relation_exists (relation, data +  300, data +  301));
sl@0: #endif
sl@0: 
sl@0:   g_tuples_destroy (tuples);
sl@0: 
sl@0:   g_relation_destroy (relation);
sl@0: 
sl@0:   relation = NULL;
sl@0: 
sl@0:   gparray = g_ptr_array_new ();
sl@0: 
sl@0:   #ifdef SYMBIAN
sl@0:   for (i = 0; i < 4000; i++)
sl@0:     g_ptr_array_add (gparray, GINT_TO_POINTER (i));
sl@0:   for (i = 0; i < 4000 ; i++)
sl@0:     if (g_ptr_array_index (gparray, i) != GINT_TO_POINTER (i))
sl@0:     {
sl@0:     	g_assert(FALSE && "testglib");	
sl@0:          g_print ("array fails: %p ( %p )\n", g_ptr_array_index (gparray, i), GINT_TO_POINTER (i));
sl@0:     }
sl@0: #else
sl@0:   for (i = 0; i < 10000; i++)
sl@0:     g_ptr_array_add (gparray, GINT_TO_POINTER (i));
sl@0:   for (i = 0; i <  10000; i++)
sl@0:     if (g_ptr_array_index (gparray, i) != GINT_TO_POINTER (i))
sl@0:     {
sl@0:     	g_assert(FALSE && "testglib");
sl@0:     	g_print ("array fails: %p ( %p )\n", g_ptr_array_index (gparray, i), GINT_TO_POINTER (i));
sl@0:     }
sl@0: #endif
sl@0: 
sl@0:   g_ptr_array_free (gparray, TRUE);
sl@0: 
sl@0: 
sl@0:   gbarray = g_byte_array_new ();
sl@0: 
sl@0:   #ifdef SYMBIAN
sl@0:   for (i = 0; i < 4000 ; i++)
sl@0:     g_byte_array_append (gbarray, (guint8*) "abcd", 4);
sl@0: 
sl@0:   for (i = 0; i < 4000 ; i++)
sl@0:     {
sl@0:       g_assert (gbarray->data[4*i] == 'a');
sl@0:       g_assert (gbarray->data[4*i+1] == 'b');
sl@0:       g_assert (gbarray->data[4*i+2] == 'c');
sl@0:       g_assert (gbarray->data[4*i+3] == 'd');
sl@0:     }
sl@0: #else
sl@0:   for (i = 0; i <  10000; i++)
sl@0:     g_byte_array_append (gbarray, (guint8*) "abcd", 4);
sl@0: 
sl@0:   for (i = 0; i <  10000; i++)
sl@0:     {
sl@0:       g_assert (gbarray->data[4*i] == 'a');
sl@0:       g_assert (gbarray->data[4*i+1] == 'b');
sl@0:       g_assert (gbarray->data[4*i+2] == 'c');
sl@0:       g_assert (gbarray->data[4*i+3] == 'd');
sl@0:     }
sl@0: #endif
sl@0: 
sl@0:   g_byte_array_free (gbarray, TRUE);
sl@0: 
sl@0:   string = NULL;
sl@0: 
sl@0:   g_assert (GUINT16_SWAP_LE_BE (gu16t1) == gu16t2);  
sl@0:   g_assert (GUINT32_SWAP_LE_BE (gu32t1) == gu32t2);  
sl@0:   g_assert (GUINT64_SWAP_LE_BE (gu64t1) == gu64t2);  
sl@0: 
sl@0:   //g_print ("ok\n");
sl@0:   g_get_charset ((G_CONST_RETURN char**)&charset);
sl@0:   g_assert(!strcmp(charset,"US-ASCII"));
sl@0: 
sl@0: #ifdef G_PLATFORM_WIN32
sl@0:   g_print ("current locale: %s\n", g_win32_getlocale ());
sl@0:   g_print ("GLib DLL name tested for: %s\n", glib_dll);
sl@0: 
sl@0:   g_print ("GLib installation directory, from Registry entry for %s if available: %s\n",
sl@0: 	   GETTEXT_PACKAGE,
sl@0: 	   g_win32_get_package_installation_directory (GETTEXT_PACKAGE, NULL));
sl@0:   g_print ("Ditto, or from GLib DLL name: %s\n",
sl@0: 	   g_win32_get_package_installation_directory (GETTEXT_PACKAGE, glib_dll));
sl@0:   g_print ("Ditto, only from GLib DLL name: %s\n",
sl@0: 	   g_win32_get_package_installation_directory (NULL, glib_dll));
sl@0:   g_print ("locale subdirectory of GLib installation directory: %s\n",
sl@0: 	   g_win32_get_package_installation_subdirectory (NULL, glib_dll, "lib\\locale"));
sl@0:   g_print ("GTK+ 2.0 installation directory, if available: %s\n",
sl@0: 	   g_win32_get_package_installation_directory ("gtk20", NULL));
sl@0: 
sl@0:   g_print ("found more.com as %s\n", g_find_program_in_path ("more.com"));
sl@0:   g_print ("found regedit as %s\n", g_find_program_in_path ("regedit"));
sl@0: 
sl@0:   g_print ("a Win32 error message: %s\n", g_win32_error_message (2));
sl@0: 
sl@0: #endif
sl@0: 
sl@0:   strcpy (template, "fooXXXXXX");
sl@0:   fd = g_mkstemp (template);
sl@0:   g_assert(fd != -1);
sl@0:   
sl@0:   i = write (fd, hello, hellolen);
sl@0:   g_assert(i != -1);
sl@0:   
sl@0:   lseek (fd, 0, 0);
sl@0:   i = read (fd, chars, sizeof (chars));
sl@0:   g_assert(i != -1);
sl@0:   
sl@0:   chars[i] = 0;
sl@0:   g_assert(!strcmp(chars, hello));
sl@0:   
sl@0:   close (fd);
sl@0:   remove (template);
sl@0: 
sl@0:   error = NULL;
sl@0:   strcpy (template, "zap" G_DIR_SEPARATOR_S "barXXXXXX");
sl@0:   fd = g_file_open_tmp (template, &name_used, &error);
sl@0:   
sl@0:   g_assert(fd == -1);
sl@0:   
sl@0:   close (fd);
sl@0:   g_clear_error (&error);
sl@0: 
sl@0: #ifdef G_OS_WIN32
sl@0:   strcpy (template, "zap/barXXXXXX");
sl@0:   fd = g_file_open_tmp (template, &name_used, &error);
sl@0:   if (fd != -1)
sl@0:     g_print ("g_file_open_tmp works even if template contains '/'\n");
sl@0:   else
sl@0:     g_print ("g_file_open_tmp correctly returns error: %s\n",
sl@0: 	     error->message);
sl@0:   close (fd);
sl@0:   g_clear_error (&error);
sl@0: #endif
sl@0: 
sl@0:   strcpy (template, "zapXXXXXX");
sl@0:   fd = g_file_open_tmp (template, &name_used, &error);
sl@0:   
sl@0:   g_assert(fd != -1);
sl@0:   
sl@0:   close (fd);
sl@0:   g_clear_error (&error);
sl@0:   remove (name_used);
sl@0: 
sl@0:   fd = g_file_open_tmp (NULL, &name_used, &error);
sl@0:   
sl@0:   g_assert(fd != -1);
sl@0:   
sl@0:   close (fd);
sl@0:   g_clear_error (&error);
sl@0:   remove (name_used);
sl@0:   
sl@0: #ifdef SYMBIAN
sl@0:   testResultXml("testglib");
sl@0: #endif /* EMULATOR */
sl@0:   return 0;
sl@0: }
sl@0: