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