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:  *
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: #undef G_DISABLE_ASSERT
sl@0: #undef G_LOG_DOMAIN
sl@0: 
sl@0: #include <stdio.h>
sl@0: #include <string.h>
sl@0: #include "glib.h"
sl@0: 
sl@0: #ifdef SYMBIAN
sl@0: #include "mrt2_glib2_test.h"
sl@0: #endif /*SYMBIAN*/
sl@0: 
sl@0: static void 
sl@0: sum_up (gpointer data, 
sl@0: 	gpointer user_data)
sl@0: {
sl@0:   gint *sum = (gint *)user_data;
sl@0: 
sl@0:   *sum += GPOINTER_TO_INT (data);
sl@0: }
sl@0: 
sl@0: int
sl@0: main (int   argc,
sl@0:       char *argv[])
sl@0: {
sl@0:   gint i;
sl@0:   GArray *garray;
sl@0:   GPtrArray *gparray;
sl@0:   GByteArray *gbarray;
sl@0:   gint sum = 0;
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:   /* array tests */
sl@0:   garray = g_array_new (FALSE, FALSE, sizeof (gint));
sl@0:   for (i = 0; i < 10000; i++)
sl@0:     g_array_append_val (garray, i);
sl@0: 
sl@0:   for (i = 0; i < 10000; i++)
sl@0:     g_assert (g_array_index (garray, gint, i) == i);
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:     g_assert (g_array_index (garray, gint, i) == (100 - i - 1));
sl@0: 
sl@0:   g_array_free (garray, TRUE);
sl@0: 
sl@0:   /* pointer arrays */
sl@0:   gparray = g_ptr_array_new ();
sl@0:   for (i = 0; i < 10000; i++)
sl@0:     g_ptr_array_add (gparray, GINT_TO_POINTER (i));
sl@0: 
sl@0:   for (i = 0; i < 10000; i++)
sl@0:     if (g_ptr_array_index (gparray, i) != GINT_TO_POINTER (i))
sl@0:       g_print ("array fails: %p ( %p )\n",
sl@0: 	       g_ptr_array_index (gparray, i),
sl@0: 	       GINT_TO_POINTER (i));
sl@0:   
sl@0:   g_ptr_array_foreach (gparray, sum_up, &sum);
sl@0:   g_assert (sum == 49995000);
sl@0:  
sl@0: 
sl@0: 
sl@0: 
sl@0:   g_ptr_array_free (gparray, TRUE);
sl@0: 
sl@0:   /* byte arrays */
sl@0:   gbarray = g_byte_array_new ();
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: 
sl@0:   g_byte_array_free (gbarray, TRUE);
sl@0:   
sl@0:   #if SYMBIAN
sl@0:   testResultXml("array-test");
sl@0:   #endif /* EMULATOR */
sl@0: 
sl@0:   return 0;
sl@0: }
sl@0: