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