|
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: |
|
20 * |
|
21 */ |
|
22 |
|
23 |
|
24 |
|
25 #undef G_DISABLE_ASSERT |
|
26 #undef G_LOG_DOMAIN |
|
27 |
|
28 #include <stdio.h> |
|
29 #include <string.h> |
|
30 #include "glib.h" |
|
31 |
|
32 #ifdef SYMBIAN |
|
33 #include "mrt2_glib2_test.h" |
|
34 #endif /*SYMBIAN*/ |
|
35 |
|
36 void function(gchar *key,gchar *value,gint *user_data) |
|
37 { |
|
38 // give the count of the number of times the function was called |
|
39 (*user_data)++; |
|
40 } |
|
41 |
|
42 void cache_test() |
|
43 { |
|
44 char *str1,*str2,*str3; |
|
45 GCache *cache = NULL; |
|
46 gint user_data = 0; |
|
47 |
|
48 g_assert((cache = g_cache_new( (GCacheNewFunc) g_ascii_strup, |
|
49 g_free, (GCacheDupFunc) g_strdup, g_free, g_str_hash, |
|
50 g_str_hash, g_str_equal)) != NULL); |
|
51 |
|
52 str1 = g_cache_insert(cache,"test"); |
|
53 |
|
54 g_assert(!strcmp("TEST",str1)); |
|
55 |
|
56 str2 = g_cache_insert(cache,"test"); |
|
57 |
|
58 g_assert(!strcmp("TEST",str1)); |
|
59 |
|
60 str3 = g_cache_insert(cache,"glib"); |
|
61 |
|
62 g_assert(!strcmp("GLIB",str3)); |
|
63 |
|
64 g_cache_key_foreach (cache,(GHFunc)function,&user_data); |
|
65 |
|
66 //g_cache_key_foreach would call function twice and make user_data == 2 |
|
67 g_assert(user_data == 2); |
|
68 |
|
69 g_cache_value_foreach (cache,(GHFunc)function,&user_data); |
|
70 |
|
71 //g_cache_value_foreach would call function twice and make user_data == 4 |
|
72 g_assert(user_data == 4); |
|
73 |
|
74 g_cache_remove(cache,str1); |
|
75 g_cache_remove(cache,str2); |
|
76 g_cache_remove(cache,str3); |
|
77 |
|
78 g_cache_destroy(cache); |
|
79 |
|
80 } |
|
81 |
|
82 |
|
83 int main (int argc, |
|
84 char *argv[]) |
|
85 { |
|
86 #ifdef SYMBIAN |
|
87 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); |
|
88 #endif /*SYMBIAN*/ |
|
89 |
|
90 cache_test(); |
|
91 |
|
92 #if SYMBIAN |
|
93 testResultXml("cache_test"); |
|
94 #endif /* EMULATOR */ |
|
95 |
|
96 return 0; |
|
97 } |