|
1 /* GLIB - Library of useful routines for C programming |
|
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald |
|
3 * Portion Copyright © 2008-09 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. |
|
4 * This library is free software; you can redistribute it and/or |
|
5 * modify it under the terms of the GNU Lesser General Public |
|
6 * License as published by the Free Software Foundation; either |
|
7 * version 2 of the License, or (at your option) any later version. |
|
8 * |
|
9 * This library is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
12 * Lesser General Public License for more details. |
|
13 * |
|
14 * You should have received a copy of the GNU Lesser General Public |
|
15 * License along with this library; if not, write to the |
|
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
|
17 * Boston, MA 02111-1307, USA. |
|
18 */ |
|
19 |
|
20 /* |
|
21 * Modified by the GLib Team and others 1997-2000. See the AUTHORS |
|
22 * file for a list of people on the GLib Team. See the ChangeLog |
|
23 * files for a list of changes. These files are distributed with |
|
24 * GLib at ftp://ftp.gtk.org/pub/gtk/. |
|
25 */ |
|
26 |
|
27 #undef G_DISABLE_ASSERT |
|
28 #undef G_LOG_DOMAIN |
|
29 |
|
30 #include <stdio.h> |
|
31 #include <string.h> |
|
32 #include "glib.h" |
|
33 |
|
34 #ifdef SYMBIAN |
|
35 #include "mrt2_glib2_test.h" |
|
36 #endif /*SYMBIAN*/ |
|
37 |
|
38 |
|
39 int array[10000]; |
|
40 gboolean failed = FALSE; |
|
41 |
|
42 #define TEST(m,cond) G_STMT_START { failed = !(cond); \ |
|
43 if (failed) \ |
|
44 { assert_failed = TRUE; \ |
|
45 if (!m) \ |
|
46 g_print ("\n(%s:%d) failed for: %s\n", __FILE__, __LINE__, ( # cond )); \ |
|
47 else \ |
|
48 g_print ("\n(%s:%d) failed for: %s: (%s)\n", __FILE__, __LINE__, ( # cond ), (gchar*)m); \ |
|
49 } \ |
|
50 else \ |
|
51 g_print ("."); fflush (stdout); \ |
|
52 } G_STMT_END |
|
53 |
|
54 #define C2P(c) ((gpointer) ((long) (c))) |
|
55 #define P2C(p) ((gchar) ((long) (p))) |
|
56 |
|
57 #define GLIB_TEST_STRING "el dorado " |
|
58 #define GLIB_TEST_STRING_5 "el do" |
|
59 |
|
60 typedef struct { |
|
61 guint age; |
|
62 gchar name[40]; |
|
63 } GlibTestInfo; |
|
64 |
|
65 |
|
66 |
|
67 int |
|
68 main (int argc, |
|
69 char *argv[]) |
|
70 { |
|
71 gint i; |
|
72 GRelation *relation; |
|
73 |
|
74 GTuples *tuples; |
|
75 gint data [1024]; |
|
76 |
|
77 |
|
78 #ifdef SYMBIAN |
|
79 |
|
80 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); |
|
81 g_set_print_handler(mrtPrintHandler); |
|
82 #endif /*SYMBIAN*/ |
|
83 |
|
84 |
|
85 relation = g_relation_new (2); |
|
86 |
|
87 g_relation_index (relation, 0, g_int_hash, g_int_equal); |
|
88 g_relation_index (relation, 1, g_int_hash, g_int_equal); |
|
89 |
|
90 for (i = 0; i < 1024; i += 1) |
|
91 data[i] = i; |
|
92 |
|
93 for (i = 1; i < 1023; i += 1) |
|
94 { |
|
95 g_relation_insert (relation, data + i, data + i + 1); |
|
96 g_relation_insert (relation, data + i, data + i - 1); |
|
97 } |
|
98 |
|
99 for (i = 2; i < 1022; i += 1) |
|
100 { |
|
101 g_assert (! g_relation_exists (relation, data + i, data + i)); |
|
102 g_assert (! g_relation_exists (relation, data + i, data + i + 2)); |
|
103 g_assert (! g_relation_exists (relation, data + i, data + i - 2)); |
|
104 } |
|
105 |
|
106 for (i = 1; i < 1023; i += 1) |
|
107 { |
|
108 g_assert (g_relation_exists (relation, data + i, data + i + 1)); |
|
109 g_assert (g_relation_exists (relation, data + i, data + i - 1)); |
|
110 } |
|
111 |
|
112 for (i = 2; i < 1022; i += 1) |
|
113 { |
|
114 g_assert (g_relation_count (relation, data + i, 0) == 2); |
|
115 g_assert (g_relation_count (relation, data + i, 1) == 2); |
|
116 } |
|
117 |
|
118 g_assert (g_relation_count (relation, data, 0) == 0); |
|
119 |
|
120 g_assert (g_relation_count (relation, data + 42, 0) == 2); |
|
121 g_assert (g_relation_count (relation, data + 43, 1) == 2); |
|
122 g_assert (g_relation_count (relation, data + 41, 1) == 2); |
|
123 g_relation_delete (relation, data + 42, 0); |
|
124 g_assert (g_relation_count (relation, data + 42, 0) == 0); |
|
125 g_assert (g_relation_count (relation, data + 43, 1) == 1); |
|
126 g_assert (g_relation_count (relation, data + 41, 1) == 1); |
|
127 |
|
128 tuples = g_relation_select (relation, data + 200, 0); |
|
129 |
|
130 g_assert (tuples->len == 2); |
|
131 |
|
132 #if 0 |
|
133 for (i = 0; i < tuples->len; i += 1) |
|
134 { |
|
135 printf ("%d %d\n", |
|
136 *(gint*) g_tuples_index (tuples, i, 0), |
|
137 *(gint*) g_tuples_index (tuples, i, 1)); |
|
138 } |
|
139 #endif |
|
140 |
|
141 g_assert (g_relation_exists (relation, data + 300, data + 301)); |
|
142 g_relation_delete (relation, data + 300, 0); |
|
143 g_assert (!g_relation_exists (relation, data + 300, data + 301)); |
|
144 |
|
145 g_tuples_destroy (tuples); |
|
146 |
|
147 g_relation_destroy (relation); |
|
148 |
|
149 relation = NULL; |
|
150 #ifdef SYMBIAN |
|
151 testResultXml("relation-test"); |
|
152 #endif /* EMULATOR */ |
|
153 return 0; |
|
154 } |
|
155 |