Branch data Line data Source code
1 : : /* GLIB - Library of useful routines for C programming
2 : : * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3 : : *
4 : : * SPDX-License-Identifier: LGPL-2.1-or-later
5 : : *
6 : : * This library is free software; you can redistribute it and/or
7 : : * modify it under the terms of the GNU Lesser General Public
8 : : * License as published by the Free Software Foundation; either
9 : : * version 2.1 of the License, or (at your option) any later version.
10 : : *
11 : : * This library is distributed in the hope that it will be useful,
12 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 : : * Lesser General Public License for more details.
15 : : *
16 : : * You should have received a copy of the GNU Lesser General Public
17 : : * License along with this library; if not, see <http://www.gnu.org/licenses/>.
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 : : /* we know we are deprecated here, no need for warnings */
28 : : #ifndef GLIB_DISABLE_DEPRECATION_WARNINGS
29 : : #define GLIB_DISABLE_DEPRECATION_WARNINGS
30 : : #endif
31 : :
32 : : #include <glib.h>
33 : :
34 : : int array[10000];
35 : : gboolean failed = FALSE;
36 : :
37 : : #define TEST(m,cond) G_STMT_START { failed = !(cond); \
38 : : if (failed) \
39 : : { if (!m) \
40 : : g_print ("\n(%s:%d) failed for: %s\n", __FILE__, __LINE__, ( # cond )); \
41 : : else \
42 : : g_print ("\n(%s:%d) failed for: %s: (%s)\n", __FILE__, __LINE__, ( # cond ), (gchar*)m); \
43 : : } \
44 : : else \
45 : : g_print ("."); fflush (stdout); \
46 : : } G_STMT_END
47 : :
48 : : #define C2P(c) ((gpointer) ((long) (c)))
49 : : #define P2C(p) ((gchar) ((long) (p)))
50 : :
51 : : #define GLIB_TEST_STRING "el dorado "
52 : : #define GLIB_TEST_STRING_5 "el do"
53 : :
54 : : typedef struct {
55 : : guint age;
56 : : gchar name[40];
57 : : } GlibTestInfo;
58 : :
59 : : static void
60 : 1 : test_relation (void)
61 : : {
62 : : gint i;
63 : : GRelation *relation;
64 : : GTuples *tuples;
65 : : gint data [1024];
66 : :
67 : 1 : relation = g_relation_new (2);
68 : :
69 : 1 : g_relation_index (relation, 0, g_int_hash, g_int_equal);
70 : 1 : g_relation_index (relation, 1, g_int_hash, g_int_equal);
71 : :
72 [ + + ]: 1025 : for (i = 0; i < 1024; i += 1)
73 : 1024 : data[i] = i;
74 : :
75 [ + + ]: 1023 : for (i = 1; i < 1023; i += 1)
76 : : {
77 : 1022 : g_relation_insert (relation, data + i, data + i + 1);
78 : 1022 : g_relation_insert (relation, data + i, data + i - 1);
79 : : }
80 : :
81 [ + + ]: 1021 : for (i = 2; i < 1022; i += 1)
82 : : {
83 : 1020 : g_assert_false (g_relation_exists (relation, data + i, data + i));
84 : 1020 : g_assert_false (g_relation_exists (relation, data + i, data + i + 2));
85 : 1020 : g_assert_false (g_relation_exists (relation, data + i, data + i - 2));
86 : : }
87 : :
88 [ + + ]: 1023 : for (i = 1; i < 1023; i += 1)
89 : : {
90 : 1022 : g_assert_true (g_relation_exists (relation, data + i, data + i + 1));
91 : 1022 : g_assert_true (g_relation_exists (relation, data + i, data + i - 1));
92 : : }
93 : :
94 [ + + ]: 1021 : for (i = 2; i < 1022; i += 1)
95 : : {
96 : 1020 : g_assert_cmpint (g_relation_count (relation, data + i, 0), ==, 2);
97 : 1020 : g_assert_cmpint (g_relation_count (relation, data + i, 1), ==, 2);
98 : : }
99 : :
100 : 1 : g_assert_cmpint (g_relation_count (relation, data, 0), ==, 0);
101 : :
102 : 1 : g_assert_cmpint (g_relation_count (relation, data + 42, 0), ==, 2);
103 : 1 : g_assert_cmpint (g_relation_count (relation, data + 43, 1), ==, 2);
104 : 1 : g_assert_cmpint (g_relation_count (relation, data + 41, 1), ==, 2);
105 : :
106 : 1 : g_relation_delete (relation, data + 42, 0);
107 : :
108 : 1 : g_assert_cmpint (g_relation_count (relation, data + 42, 0), ==, 0);
109 : 1 : g_assert_cmpint (g_relation_count (relation, data + 43, 1), ==, 1);
110 : 1 : g_assert_cmpint (g_relation_count (relation, data + 41, 1), ==, 1);
111 : :
112 : 1 : tuples = g_relation_select (relation, data + 200, 0);
113 : :
114 : 1 : g_assert_cmpint (tuples->len, ==, 2);
115 : :
116 : 1 : g_assert_true (g_relation_exists (relation, data + 300, data + 301));
117 : 1 : g_relation_delete (relation, data + 300, 0);
118 : 1 : g_assert_false (g_relation_exists (relation, data + 300, data + 301));
119 : :
120 : 1 : g_tuples_destroy (tuples);
121 : 1 : g_relation_destroy (relation);
122 : 1 : }
123 : :
124 : : int
125 : 1 : main (int argc,
126 : : char *argv[])
127 : : {
128 : 1 : g_test_init (&argc, &argv, NULL);
129 : :
130 : 1 : g_test_add_func ("/glib/relation", test_relation);
131 : :
132 : 1 : return g_test_run ();
133 : : }
|