|
1 /* |
|
2 * Copyright (c) 2006 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 #undef G_DISABLE_ASSERT |
|
20 #undef G_LOG_DOMAIN |
|
21 |
|
22 |
|
23 #include <stdio.h> |
|
24 #include <string.h> |
|
25 #include <glib.h> |
|
26 #include <fcntl.h> |
|
27 #include <goption.h> |
|
28 |
|
29 #ifdef SYMBIAN |
|
30 #include "mrt2_glib2_test.h" |
|
31 #endif /*SYMBIAN*/ |
|
32 |
|
33 #define C2P(c) ((gpointer) ((long) (c))) |
|
34 #define GINT_TO_POINTER(i) ((gpointer) (i)) |
|
35 #define GPOINTER_TO_INT(p) ((gint) (p)) |
|
36 #define TESTPASS 1 |
|
37 #define TESTFAIL 0 |
|
38 |
|
39 //Test for g_nullify_pointer |
|
40 void tg_nullify_pointer() |
|
41 { |
|
42 char nullify_pointer[]="abcd"; |
|
43 g_nullify_pointer((void*)nullify_pointer); |
|
44 g_assert(!strcmp(nullify_pointer,"\0")); |
|
45 } |
|
46 |
|
47 //Ascending |
|
48 gint compare_fun_gr(gconstpointer a,gconstpointer b) |
|
49 { |
|
50 return ((*(int *)a==*(int *)b)?0:((*(int *)a>*(int *)b)?1:-1)); |
|
51 } |
|
52 |
|
53 //Data |
|
54 gint compare_fun_gr_data(gconstpointer a,gconstpointer b,gpointer data) |
|
55 { |
|
56 return ((*(int *)a==*(int *)b)?0:((*(int *)a>*(int *)b)?1:-1)); |
|
57 } |
|
58 |
|
59 |
|
60 //Tests for g_ptr_array |
|
61 void tg_ptr_array_tests() |
|
62 { |
|
63 GPtrArray *gparray; |
|
64 int i; |
|
65 gint str_ds[12]= |
|
66 { |
|
67 12,11,10,9,8,7,6,5,4,3,2,1 |
|
68 }; |
|
69 |
|
70 gparray = g_ptr_array_new (); |
|
71 for(i=0;i<12;i++) |
|
72 { |
|
73 g_ptr_array_add (gparray, (gpointer)str_ds[i] ); |
|
74 } |
|
75 |
|
76 g_ptr_array_sort(gparray,compare_fun_gr); |
|
77 g_ptr_array_remove_range(gparray,2,4); |
|
78 g_ptr_array_sort_with_data(gparray,compare_fun_gr_data,0); |
|
79 |
|
80 |
|
81 } |
|
82 |
|
83 int cmp_func(gconstpointer a,gconstpointer b) |
|
84 { |
|
85 if(a==b) |
|
86 return 0; |
|
87 else |
|
88 return -1; |
|
89 } |
|
90 |
|
91 //Test for g_queue_find_custom |
|
92 void tg_queue_find_custom() |
|
93 { |
|
94 GQueue *q; |
|
95 GList *node; |
|
96 gpointer data; |
|
97 gpointer srch_data=GINT_TO_POINTER(5); |
|
98 int i; |
|
99 int j=10; |
|
100 int g_queue_find_custom_pass=TESTFAIL; |
|
101 |
|
102 q = g_queue_new (); |
|
103 for(i=0;i<10;i++) |
|
104 { |
|
105 g_queue_push_head (q, GINT_TO_POINTER (j)); |
|
106 j--; |
|
107 } |
|
108 g_queue_push_nth(q,GINT_TO_POINTER (5),9); |
|
109 |
|
110 node= g_queue_find_custom(q,GINT_TO_POINTER (5),cmp_func); |
|
111 |
|
112 if(node->data==srch_data) |
|
113 { |
|
114 g_queue_find_custom_pass=TESTPASS; |
|
115 } |
|
116 |
|
117 g_assert(g_queue_find_custom_pass==TESTPASS); |
|
118 } |
|
119 |
|
120 |
|
121 //Test for g_timer_reset |
|
122 void tg_timer_test() |
|
123 { |
|
124 int i=0; |
|
125 GTimer *timer; |
|
126 timer = g_timer_new (); |
|
127 g_timer_start (timer); |
|
128 do |
|
129 { |
|
130 while (g_timer_elapsed (timer, NULL) < 1); |
|
131 g_timer_reset(timer); |
|
132 i++; |
|
133 }while(i<3); |
|
134 |
|
135 g_timer_stop (timer); |
|
136 g_timer_destroy (timer); |
|
137 |
|
138 } |
|
139 |
|
140 //Test for g_try_malloc0 |
|
141 void tg_try_malloc0() |
|
142 { |
|
143 char* s; |
|
144 gpointer try = g_try_malloc0 (sizeof(s)); |
|
145 g_assert (try != NULL); |
|
146 } |
|
147 |
|
148 int main (int argc,char *argv[]) |
|
149 { |
|
150 |
|
151 #ifdef SYMBIAN |
|
152 |
|
153 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); |
|
154 #endif /*SYMBIAN*/ |
|
155 |
|
156 tg_nullify_pointer(); |
|
157 tg_ptr_array_tests(); |
|
158 tg_queue_find_custom(); |
|
159 tg_timer_test(); |
|
160 tg_try_malloc0(); |
|
161 |
|
162 #ifdef SYMBIAN |
|
163 testResultXml("tmisc"); |
|
164 #endif /* EMULATOR */ |
|
165 return 0; |
|
166 } |