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 |
#undef G_DISABLE_ASSERT
|
sl@0
|
28 |
#undef G_LOG_DOMAIN
|
sl@0
|
29 |
|
sl@0
|
30 |
#include <stdio.h>
|
sl@0
|
31 |
#include <string.h>
|
sl@0
|
32 |
#include "glib.h"
|
sl@0
|
33 |
|
sl@0
|
34 |
#ifdef SYMBIAN
|
sl@0
|
35 |
#include "mrt2_glib2_test.h"
|
sl@0
|
36 |
#endif /*SYMBIAN*/
|
sl@0
|
37 |
|
sl@0
|
38 |
|
sl@0
|
39 |
int array[10000];
|
sl@0
|
40 |
gboolean failed = FALSE;
|
sl@0
|
41 |
|
sl@0
|
42 |
#define TEST(m,cond) G_STMT_START { failed = !(cond); \
|
sl@0
|
43 |
if (failed) \
|
sl@0
|
44 |
{ assert_failed = TRUE;\
|
sl@0
|
45 |
if (!m) \
|
sl@0
|
46 |
g_print ("\n(%s:%d) failed for: %s\n", __FILE__, __LINE__, ( # cond )); \
|
sl@0
|
47 |
else \
|
sl@0
|
48 |
g_print ("\n(%s:%d) failed for: %s: (%s)\n", __FILE__, __LINE__, ( # cond ), (gchar*)m); \
|
sl@0
|
49 |
} \
|
sl@0
|
50 |
else \
|
sl@0
|
51 |
g_print ("."); fflush (stdout); \
|
sl@0
|
52 |
} G_STMT_END
|
sl@0
|
53 |
|
sl@0
|
54 |
#define C2P(c) ((gpointer) ((long) (c)))
|
sl@0
|
55 |
#define P2C(p) ((gchar) ((long) (p)))
|
sl@0
|
56 |
|
sl@0
|
57 |
#define GLIB_TEST_STRING "el dorado "
|
sl@0
|
58 |
#define GLIB_TEST_STRING_5 "el do"
|
sl@0
|
59 |
|
sl@0
|
60 |
typedef struct {
|
sl@0
|
61 |
guint age;
|
sl@0
|
62 |
gchar name[40];
|
sl@0
|
63 |
} GlibTestInfo;
|
sl@0
|
64 |
|
sl@0
|
65 |
static gint
|
sl@0
|
66 |
my_list_compare_one (gconstpointer a, gconstpointer b)
|
sl@0
|
67 |
{
|
sl@0
|
68 |
gint one = *((const gint*)a);
|
sl@0
|
69 |
gint two = *((const gint*)b);
|
sl@0
|
70 |
return one-two;
|
sl@0
|
71 |
}
|
sl@0
|
72 |
|
sl@0
|
73 |
static gint
|
sl@0
|
74 |
my_list_compare_two (gconstpointer a, gconstpointer b)
|
sl@0
|
75 |
{
|
sl@0
|
76 |
gint one = *((const gint*)a);
|
sl@0
|
77 |
gint two = *((const gint*)b);
|
sl@0
|
78 |
return two-one;
|
sl@0
|
79 |
}
|
sl@0
|
80 |
|
sl@0
|
81 |
int
|
sl@0
|
82 |
main (int argc,
|
sl@0
|
83 |
char *argv[])
|
sl@0
|
84 |
{
|
sl@0
|
85 |
GList *list, *t;
|
sl@0
|
86 |
gint nums[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
sl@0
|
87 |
gint morenums[10] = { 8, 9, 7, 0, 3, 2, 5, 1, 4, 6};
|
sl@0
|
88 |
gint i;
|
sl@0
|
89 |
|
sl@0
|
90 |
list = NULL;
|
sl@0
|
91 |
|
sl@0
|
92 |
#ifdef SYMBIAN
|
sl@0
|
93 |
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
|
94 |
g_set_print_handler(mrtPrintHandler);
|
sl@0
|
95 |
#endif /*SYMBIAN*/
|
sl@0
|
96 |
|
sl@0
|
97 |
|
sl@0
|
98 |
for (i = 0; i < 10; i++)
|
sl@0
|
99 |
list = g_list_append (list, &nums[i]);
|
sl@0
|
100 |
list = g_list_reverse (list);
|
sl@0
|
101 |
|
sl@0
|
102 |
for (i = 0; i < 10; i++)
|
sl@0
|
103 |
{
|
sl@0
|
104 |
t = g_list_nth (list, i);
|
sl@0
|
105 |
g_assert (*((gint*) t->data) == (9 - i));
|
sl@0
|
106 |
}
|
sl@0
|
107 |
|
sl@0
|
108 |
for (i = 0; i < 10; i++)
|
sl@0
|
109 |
g_assert (g_list_position(list, g_list_nth (list, i)) == i);
|
sl@0
|
110 |
|
sl@0
|
111 |
g_list_free (list);
|
sl@0
|
112 |
list = NULL;
|
sl@0
|
113 |
|
sl@0
|
114 |
for (i = 0; i < 10; i++)
|
sl@0
|
115 |
list = g_list_insert_sorted (list, &morenums[i], my_list_compare_one);
|
sl@0
|
116 |
|
sl@0
|
117 |
/*
|
sl@0
|
118 |
g_print("\n");
|
sl@0
|
119 |
g_list_foreach (list, my_list_print, NULL);
|
sl@0
|
120 |
*/
|
sl@0
|
121 |
|
sl@0
|
122 |
for (i = 0; i < 10; i++)
|
sl@0
|
123 |
{
|
sl@0
|
124 |
t = g_list_nth (list, i);
|
sl@0
|
125 |
g_assert (*((gint*) t->data) == i);
|
sl@0
|
126 |
}
|
sl@0
|
127 |
|
sl@0
|
128 |
g_list_free (list);
|
sl@0
|
129 |
list = NULL;
|
sl@0
|
130 |
|
sl@0
|
131 |
for (i = 0; i < 10; i++)
|
sl@0
|
132 |
list = g_list_insert_sorted (list, &morenums[i], my_list_compare_two);
|
sl@0
|
133 |
|
sl@0
|
134 |
/*
|
sl@0
|
135 |
g_print("\n");
|
sl@0
|
136 |
g_list_foreach (list, my_list_print, NULL);
|
sl@0
|
137 |
*/
|
sl@0
|
138 |
|
sl@0
|
139 |
for (i = 0; i < 10; i++)
|
sl@0
|
140 |
{
|
sl@0
|
141 |
t = g_list_nth (list, i);
|
sl@0
|
142 |
g_assert (*((gint*) t->data) == (9 - i));
|
sl@0
|
143 |
}
|
sl@0
|
144 |
|
sl@0
|
145 |
g_list_free (list);
|
sl@0
|
146 |
list = NULL;
|
sl@0
|
147 |
|
sl@0
|
148 |
for (i = 0; i < 10; i++)
|
sl@0
|
149 |
list = g_list_prepend (list, &morenums[i]);
|
sl@0
|
150 |
|
sl@0
|
151 |
list = g_list_sort (list, my_list_compare_two);
|
sl@0
|
152 |
|
sl@0
|
153 |
/*
|
sl@0
|
154 |
g_print("\n");
|
sl@0
|
155 |
g_list_foreach (list, my_list_print, NULL);
|
sl@0
|
156 |
*/
|
sl@0
|
157 |
|
sl@0
|
158 |
for (i = 0; i < 10; i++)
|
sl@0
|
159 |
{
|
sl@0
|
160 |
t = g_list_nth (list, i);
|
sl@0
|
161 |
g_assert (*((gint*) t->data) == (9 - i));
|
sl@0
|
162 |
}
|
sl@0
|
163 |
|
sl@0
|
164 |
g_list_free (list);
|
sl@0
|
165 |
|
sl@0
|
166 |
#ifdef SYMBIAN
|
sl@0
|
167 |
testResultXml("list-test");
|
sl@0
|
168 |
#endif /* EMULATOR */
|
sl@0
|
169 |
|
sl@0
|
170 |
return 0;
|
sl@0
|
171 |
}
|
sl@0
|
172 |
|