|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. |
|
3 * |
|
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 * Description: ?Description |
|
20 * |
|
21 */ |
|
22 |
|
23 |
|
24 #undef G_DISABLE_ASSERT |
|
25 #undef G_LOG_DOMAIN |
|
26 |
|
27 |
|
28 #include <stdio.h> |
|
29 #include <string.h> |
|
30 #include <glib.h> |
|
31 #include <fcntl.h> |
|
32 #include <goption.h> |
|
33 |
|
34 #ifdef SYMBIAN |
|
35 #include "mrt2_glib2_test.h" |
|
36 #endif /*SYMBIAN*/ |
|
37 |
|
38 #define C2P(c) ((gpointer) ((long) (c))) |
|
39 #define GINT_TO_POINTER(i) ((gpointer) (i)) |
|
40 #define GPOINTER_TO_INT(p) ((gint) (p)) |
|
41 #define TESTPASS 1 |
|
42 #define TESTFAIL 0 |
|
43 |
|
44 //Support for gtree |
|
45 static gint my_compare (gconstpointer a,gconstpointer b,gpointer data) |
|
46 { |
|
47 const char *cha = a; |
|
48 const char *chb = b; |
|
49 |
|
50 return *cha - *chb; |
|
51 } |
|
52 |
|
53 static gint my_traverse (gpointer key,gpointer value,gpointer data) |
|
54 { |
|
55 char *ch = key; |
|
56 char *ch1 = value; |
|
57 g_assert (key == value); |
|
58 return FALSE; |
|
59 } |
|
60 |
|
61 //Tests for gtree |
|
62 void tg_tree_tests () |
|
63 { |
|
64 |
|
65 GTree *tree; |
|
66 char chars[62]; |
|
67 char c='a'; |
|
68 char err='1'; |
|
69 gpointer d,op; |
|
70 int i,j; |
|
71 char del='c'; |
|
72 char key='f'; |
|
73 char val='z'; |
|
74 |
|
75 tree = g_tree_new_with_data (my_compare,&c); |
|
76 i = 0; |
|
77 for (j = 0; j < 26; j++, i++) |
|
78 { |
|
79 chars[i] = 'A' + j; |
|
80 g_tree_insert (tree, &chars[i], &chars[i]); |
|
81 } |
|
82 |
|
83 for (j = 0; j < 26; j++, i++) |
|
84 { |
|
85 chars[i] = 'a' + j; |
|
86 g_tree_insert (tree, &chars[i], &chars[i]); |
|
87 } |
|
88 |
|
89 //Test for g_tree_lookup...srch for value for 'a' |
|
90 g_assert(*(gchar*)( g_tree_lookup (tree ,&c)) == 'a'); |
|
91 g_assert(g_tree_lookup (tree ,&err) == NULL); |
|
92 |
|
93 //Test for g_tree_lookup_extended...srch for value for 'a' |
|
94 g_assert( g_tree_lookup_extended(tree ,&c ,&d ,&op)); |
|
95 g_assert( !g_tree_lookup_extended(tree ,&err ,&d ,&op)); |
|
96 |
|
97 //Test for g_tree_replace...replace f/f with f/z |
|
98 g_tree_replace(tree,&key,&val); |
|
99 g_assert(*(gchar*)( g_tree_lookup (tree ,&key)) == 'z'); |
|
100 |
|
101 //Test for g_tree_steal...remove f/z |
|
102 g_assert(g_tree_steal(tree ,&key)); |
|
103 |
|
104 //Test for g_tree_traverse...logging occurs in the traversal function |
|
105 g_tree_traverse(tree,my_traverse,G_IN_ORDER,&del); |
|
106 |
|
107 } |
|
108 |
|
109 int main (int argc,char *argv[]) |
|
110 { |
|
111 |
|
112 #ifdef SYMBIAN |
|
113 |
|
114 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); |
|
115 #endif /*SYMBIAN*/ |
|
116 |
|
117 tg_tree_tests(); |
|
118 #ifdef SYMBIAN |
|
119 testResultXml("ttree"); |
|
120 #endif /* EMULATOR */ |
|
121 return 0; |
|
122 } |