1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/glib/tsrc/BC/tests/array-test.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,121 @@
1.4 +/* GLIB - Library of useful routines for C programming
1.5 + * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
1.6 + *
1.7 + * This library is free software; you can redistribute it and/or
1.8 + * modify it under the terms of the GNU Lesser General Public
1.9 + * License as published by the Free Software Foundation; either
1.10 + * version 2 of the License, or (at your option) any later version.
1.11 + *
1.12 + * This library is distributed in the hope that it will be useful,
1.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1.15 + * Lesser General Public License for more details.
1.16 + *
1.17 + * You should have received a copy of the GNU Lesser General Public
1.18 + * License along with this library; if not, write to the
1.19 + * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
1.20 + * Boston, MA 02111-1307, USA.
1.21 + */
1.22 +
1.23 +/*
1.24 + * Modified by the GLib Team and others 1997-2000. See the AUTHORS
1.25 + * file for a list of people on the GLib Team. See the ChangeLog
1.26 + * files for a list of changes. These files are distributed with
1.27 + * GLib at ftp://ftp.gtk.org/pub/gtk/.
1.28 + */
1.29 +
1.30 +#undef G_DISABLE_ASSERT
1.31 +#undef G_LOG_DOMAIN
1.32 +
1.33 +#include <stdio.h>
1.34 +#include <string.h>
1.35 +#include "glib.h"
1.36 +
1.37 +#ifdef SYMBIAN
1.38 +#include "mrt2_glib2_test.h"
1.39 +#endif /*SYMBIAN*/
1.40 +
1.41 +static void
1.42 +sum_up (gpointer data,
1.43 + gpointer user_data)
1.44 +{
1.45 + gint *sum = (gint *)user_data;
1.46 +
1.47 + *sum += GPOINTER_TO_INT (data);
1.48 +}
1.49 +
1.50 +int
1.51 +main (int argc,
1.52 + char *argv[])
1.53 +{
1.54 + gint i;
1.55 + GArray *garray;
1.56 + GPtrArray *gparray;
1.57 + GByteArray *gbarray;
1.58 + gint sum = 0;
1.59 +
1.60 + #ifdef SYMBIAN
1.61 + g_log_set_handler (NULL, G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, &mrtLogHandler, NULL);
1.62 + g_set_print_handler(mrtPrintHandler);
1.63 + #endif /*SYMBIAN*/
1.64 +
1.65 + /* array tests */
1.66 + garray = g_array_new (FALSE, FALSE, sizeof (gint));
1.67 + for (i = 0; i < 10000; i++)
1.68 + g_array_append_val (garray, i);
1.69 +
1.70 + for (i = 0; i < 10000; i++)
1.71 + g_assert (g_array_index (garray, gint, i) == i);
1.72 +
1.73 + g_array_free (garray, TRUE);
1.74 +
1.75 + garray = g_array_new (FALSE, FALSE, sizeof (gint));
1.76 + for (i = 0; i < 100; i++)
1.77 + g_array_prepend_val (garray, i);
1.78 +
1.79 + for (i = 0; i < 100; i++)
1.80 + g_assert (g_array_index (garray, gint, i) == (100 - i - 1));
1.81 +
1.82 + g_array_free (garray, TRUE);
1.83 +
1.84 + /* pointer arrays */
1.85 + gparray = g_ptr_array_new ();
1.86 + for (i = 0; i < 10000; i++)
1.87 + g_ptr_array_add (gparray, GINT_TO_POINTER (i));
1.88 +
1.89 + for (i = 0; i < 10000; i++)
1.90 + if (g_ptr_array_index (gparray, i) != GINT_TO_POINTER (i))
1.91 + g_print ("array fails: %p ( %p )\n",
1.92 + g_ptr_array_index (gparray, i),
1.93 + GINT_TO_POINTER (i));
1.94 +
1.95 + g_ptr_array_foreach (gparray, sum_up, &sum);
1.96 + g_assert (sum == 49995000);
1.97 +
1.98 +
1.99 +
1.100 +
1.101 + g_ptr_array_free (gparray, TRUE);
1.102 +
1.103 + /* byte arrays */
1.104 + gbarray = g_byte_array_new ();
1.105 + for (i = 0; i < 10000; i++)
1.106 + g_byte_array_append (gbarray, (guint8*) "abcd", 4);
1.107 +
1.108 + for (i = 0; i < 10000; i++)
1.109 + {
1.110 + g_assert (gbarray->data[4*i] == 'a');
1.111 + g_assert (gbarray->data[4*i+1] == 'b');
1.112 + g_assert (gbarray->data[4*i+2] == 'c');
1.113 + g_assert (gbarray->data[4*i+3] == 'd');
1.114 + }
1.115 +
1.116 + g_byte_array_free (gbarray, TRUE);
1.117 +
1.118 + #if SYMBIAN
1.119 + testResultXml("array-test");
1.120 + #endif /* EMULATOR */
1.121 +
1.122 + return 0;
1.123 +}
1.124 +