Update contrib.
2 * Copyright (c) 2009 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.
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.
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.
25 #undef G_DISABLE_ASSERT
33 #include "mrt2_glib2_test.h"
36 gboolean func1(int *data)
42 gboolean func2(int *data)
48 gboolean func3(int *data)
54 gboolean func4(int *data)
60 gint sort_func(GHook *new_hook,GHook *sibling)
62 if(new_hook->hook_id < sibling->hook_id)
68 gboolean find_func(GHook *hook,gpointer data)
70 if(hook->hook_id == 1)
76 void marshaller(GHook *hook,gpointer mashal_data)
78 gint *data = (int *)hook->data;
82 gboolean check_marshaller(GHook *hook,gpointer mashal_data)
84 if(hook->hook_id == 2) // for hook2 id is 2
94 GHook *hook1 = NULL,*hook2 = NULL,*hook3 = NULL,*hook4 = NULL,*temp_hook;
95 int data1 = 0,data2 = 0,data3 = 0,data4 = 0;
99 g_hook_list_init(&hooklist,sizeof(GHook));
101 hook1 = g_hook_alloc(&hooklist);
102 hook1->func = (gpointer)func1;
103 hook1->data = &data1;
105 hook2 = g_hook_alloc(&hooklist);
106 hook2->func = (gpointer)func2;
107 hook2->data = &data2;
109 hook3 = g_hook_alloc(&hooklist);
110 hook3->func = (gpointer)func3;
111 hook3->data = &data3;
113 hook4 = g_hook_alloc(&hooklist);
114 hook4->func = (gpointer)func4;
115 hook4->data = &data4;
117 g_hook_append(&hooklist,hook4);
118 g_hook_prepend(&hooklist,hook3);
119 g_hook_insert_before(&hooklist,hook3,hook2);
120 g_hook_insert_sorted(&hooklist,hook1,sort_func);
122 g_hook_list_invoke(&hooklist,FALSE);
124 // checks g_hook_list_init,g_hook_alloc,g_hook_append,g_hook_prepend,g_hook_insert_before,g_hook_insert_sorted
125 g_assert(data1 == 1 && data2 == 2 && data3 == 3 && data4 == 4);
127 comp_value = g_hook_compare_ids(hook2,hook1);
129 //checks g_hook_compare_ids
130 g_assert(comp_value < 0);
132 temp_hook = g_hook_get(&hooklist,10);
135 g_assert(temp_hook == NULL);
137 temp_hook = g_hook_get(&hooklist,1);
140 g_assert(temp_hook == hook4);
144 temp_hook = g_hook_find(&hooklist,TRUE,find_func,NULL);
147 g_assert(temp_hook == hook4);
151 temp_hook = g_hook_find_data(&hooklist,TRUE,&data1);
153 //checks g_hook_find_data
154 g_assert(temp_hook == hook1);
158 temp_hook = g_hook_find_func(&hooklist,TRUE,(gpointer)func2);
160 //checks g_hook_find_func
161 g_assert(temp_hook == hook2);
163 temp_hook = g_hook_find_func_data(&hooklist,TRUE,(gpointer)func2,&data1);
165 //checks g_hook_find_func_data
166 g_assert(temp_hook == NULL);
168 temp_hook = g_hook_find_func_data(&hooklist,TRUE,(gpointer)func1,&data1);
170 //checks g_hook_find_func_data
171 g_assert(temp_hook == hook1);
175 temp_hook = g_hook_ref(&hooklist,hook3);
178 g_assert(hook3->ref_count == 2);
180 g_hook_unref(&hooklist,hook3);
182 //checks g_hook_unref
183 g_assert(hook3->ref_count == 1);
185 g_hook_list_marshal(&hooklist,TRUE,marshaller,NULL);
187 //checks g_hook_list_marshal
188 g_assert(data1 == -1 && data2 == -1 && data3 == -1 && data4 == -1);
190 g_hook_list_marshal_check(&hooklist,TRUE,check_marshaller,NULL);
192 // checks g_hook_list_marshal_check
193 // func3 is for hook3 and the check_marshaller returns FALSE for hook3
194 // As a rsult the hook is deleted from the hook list.
195 g_assert(g_hook_find_func(&hooklist,TRUE,(gpointer)func3) == NULL);
197 g_hook_list_clear(&hooklist);
199 //checks g_hook_list_clear
200 g_assert(hooklist.hooks == NULL);
209 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);
215 testResultXml("hook_test");
216 #endif /* EMULATOR */