1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/glib/tsrc/BC/tests/list-test.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,172 @@
1.4 +/* GLIB - Library of useful routines for C programming
1.5 + * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
1.6 + * Portion Copyright © 2008-09 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
1.7 + * This library is free software; you can redistribute it and/or
1.8 + * modify it under the terms of the GNU Lesser General Public
1.9 + * License as published by the Free Software Foundation; either
1.10 + * version 2 of the License, or (at your option) any later version.
1.11 + *
1.12 + * This library is distributed in the hope that it will be useful,
1.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1.15 + * Lesser General Public License for more details.
1.16 + *
1.17 + * You should have received a copy of the GNU Lesser General Public
1.18 + * License along with this library; if not, write to the
1.19 + * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
1.20 + * Boston, MA 02111-1307, USA.
1.21 + */
1.22 +
1.23 +/*
1.24 + * Modified by the GLib Team and others 1997-2000. See the AUTHORS
1.25 + * file for a list of people on the GLib Team. See the ChangeLog
1.26 + * files for a list of changes. These files are distributed with
1.27 + * GLib at ftp://ftp.gtk.org/pub/gtk/.
1.28 + */
1.29 +
1.30 +#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 +
1.42 +int array[10000];
1.43 +gboolean failed = FALSE;
1.44 +
1.45 +#define TEST(m,cond) G_STMT_START { failed = !(cond); \
1.46 +if (failed) \
1.47 + { assert_failed = TRUE;\
1.48 + if (!m) \
1.49 + g_print ("\n(%s:%d) failed for: %s\n", __FILE__, __LINE__, ( # cond )); \
1.50 + else \
1.51 + g_print ("\n(%s:%d) failed for: %s: (%s)\n", __FILE__, __LINE__, ( # cond ), (gchar*)m); \
1.52 + } \
1.53 +else \
1.54 + g_print ("."); fflush (stdout); \
1.55 +} G_STMT_END
1.56 +
1.57 +#define C2P(c) ((gpointer) ((long) (c)))
1.58 +#define P2C(p) ((gchar) ((long) (p)))
1.59 +
1.60 +#define GLIB_TEST_STRING "el dorado "
1.61 +#define GLIB_TEST_STRING_5 "el do"
1.62 +
1.63 +typedef struct {
1.64 + guint age;
1.65 + gchar name[40];
1.66 +} GlibTestInfo;
1.67 +
1.68 +static gint
1.69 +my_list_compare_one (gconstpointer a, gconstpointer b)
1.70 +{
1.71 + gint one = *((const gint*)a);
1.72 + gint two = *((const gint*)b);
1.73 + return one-two;
1.74 +}
1.75 +
1.76 +static gint
1.77 +my_list_compare_two (gconstpointer a, gconstpointer b)
1.78 +{
1.79 + gint one = *((const gint*)a);
1.80 + gint two = *((const gint*)b);
1.81 + return two-one;
1.82 +}
1.83 +
1.84 +int
1.85 +main (int argc,
1.86 + char *argv[])
1.87 +{
1.88 + GList *list, *t;
1.89 + gint nums[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
1.90 + gint morenums[10] = { 8, 9, 7, 0, 3, 2, 5, 1, 4, 6};
1.91 + gint i;
1.92 +
1.93 + list = NULL;
1.94 +
1.95 + #ifdef SYMBIAN
1.96 + 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.97 + g_set_print_handler(mrtPrintHandler);
1.98 + #endif /*SYMBIAN*/
1.99 +
1.100 +
1.101 + for (i = 0; i < 10; i++)
1.102 + list = g_list_append (list, &nums[i]);
1.103 + list = g_list_reverse (list);
1.104 +
1.105 + for (i = 0; i < 10; i++)
1.106 + {
1.107 + t = g_list_nth (list, i);
1.108 + g_assert (*((gint*) t->data) == (9 - i));
1.109 + }
1.110 +
1.111 + for (i = 0; i < 10; i++)
1.112 + g_assert (g_list_position(list, g_list_nth (list, i)) == i);
1.113 +
1.114 + g_list_free (list);
1.115 + list = NULL;
1.116 +
1.117 + for (i = 0; i < 10; i++)
1.118 + list = g_list_insert_sorted (list, &morenums[i], my_list_compare_one);
1.119 +
1.120 + /*
1.121 + g_print("\n");
1.122 + g_list_foreach (list, my_list_print, NULL);
1.123 + */
1.124 +
1.125 + for (i = 0; i < 10; i++)
1.126 + {
1.127 + t = g_list_nth (list, i);
1.128 + g_assert (*((gint*) t->data) == i);
1.129 + }
1.130 +
1.131 + g_list_free (list);
1.132 + list = NULL;
1.133 +
1.134 + for (i = 0; i < 10; i++)
1.135 + list = g_list_insert_sorted (list, &morenums[i], my_list_compare_two);
1.136 +
1.137 + /*
1.138 + g_print("\n");
1.139 + g_list_foreach (list, my_list_print, NULL);
1.140 + */
1.141 +
1.142 + for (i = 0; i < 10; i++)
1.143 + {
1.144 + t = g_list_nth (list, i);
1.145 + g_assert (*((gint*) t->data) == (9 - i));
1.146 + }
1.147 +
1.148 + g_list_free (list);
1.149 + list = NULL;
1.150 +
1.151 + for (i = 0; i < 10; i++)
1.152 + list = g_list_prepend (list, &morenums[i]);
1.153 +
1.154 + list = g_list_sort (list, my_list_compare_two);
1.155 +
1.156 + /*
1.157 + g_print("\n");
1.158 + g_list_foreach (list, my_list_print, NULL);
1.159 + */
1.160 +
1.161 + for (i = 0; i < 10; i++)
1.162 + {
1.163 + t = g_list_nth (list, i);
1.164 + g_assert (*((gint*) t->data) == (9 - i));
1.165 + }
1.166 +
1.167 + g_list_free (list);
1.168 +
1.169 + #ifdef SYMBIAN
1.170 + testResultXml("list-test");
1.171 + #endif /* EMULATOR */
1.172 +
1.173 + return 0;
1.174 +}
1.175 +