sl@0: /*
sl@0: * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
sl@0: *
sl@0: * This library is free software; you can redistribute it and/or
sl@0: * modify it under the terms of the GNU Lesser General Public
sl@0: * License as published by the Free Software Foundation; either
sl@0: * version 2 of the License, or (at your option) any later version.
sl@0: *
sl@0: * This library is distributed in the hope that it will be useful,
sl@0: * but WITHOUT ANY WARRANTY; without even the implied warranty of
sl@0: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
sl@0: * Lesser General Public License for more details.
sl@0: *
sl@0: * You should have received a copy of the GNU Lesser General Public
sl@0: * License along with this library; if not, write to the
sl@0: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
sl@0: * Boston, MA 02111-1307, USA.
sl@0: *
sl@0: * Description:
sl@0: *
sl@0: */
sl@0: 
sl@0: 
sl@0: 
sl@0: #undef G_DISABLE_ASSERT
sl@0: #undef G_LOG_DOMAIN
sl@0: 
sl@0: #include <stdio.h>
sl@0: #include <string.h>
sl@0: #include "glib.h"
sl@0: 
sl@0: #ifdef SYMBIAN
sl@0: #include "mrt2_glib2_test.h"
sl@0: #endif /*SYMBIAN*/
sl@0: 
sl@0: void function(gchar *key,gchar *value,gint *user_data)
sl@0: {
sl@0: 	// give the count of the number of times the function was called
sl@0: 	(*user_data)++;
sl@0: }
sl@0: 
sl@0: void cache_test()
sl@0: {
sl@0: 	char *str1,*str2,*str3;
sl@0: 	GCache *cache = NULL;
sl@0: 	gint user_data = 0;
sl@0: 	
sl@0: 	g_assert((cache = g_cache_new( (GCacheNewFunc) g_ascii_strup,
sl@0: 					g_free, (GCacheDupFunc) g_strdup, g_free, g_str_hash, 
sl@0:     				g_str_hash, g_str_equal)) != NULL);
sl@0:     				
sl@0:     str1 = g_cache_insert(cache,"test");
sl@0:     
sl@0:     g_assert(!strcmp("TEST",str1));
sl@0:     
sl@0: 	str2 = g_cache_insert(cache,"test");
sl@0: 
sl@0: 	g_assert(!strcmp("TEST",str1));
sl@0: 	
sl@0: 	str3 = g_cache_insert(cache,"glib");
sl@0: 	
sl@0: 	g_assert(!strcmp("GLIB",str3));
sl@0: 	
sl@0: 	g_cache_key_foreach (cache,(GHFunc)function,&user_data);
sl@0: 	
sl@0: 	//g_cache_key_foreach would call function twice and make user_data == 2
sl@0: 	g_assert(user_data == 2);
sl@0: 	
sl@0: 	g_cache_value_foreach (cache,(GHFunc)function,&user_data);
sl@0: 	
sl@0: 	//g_cache_value_foreach would call function twice and make user_data == 4
sl@0: 	g_assert(user_data == 4);
sl@0: 	
sl@0: 	g_cache_remove(cache,str1);
sl@0: 	g_cache_remove(cache,str2);	
sl@0: 	g_cache_remove(cache,str3);	
sl@0: 	
sl@0: 	g_cache_destroy(cache);
sl@0: 	
sl@0: }
sl@0: 
sl@0: 
sl@0: int main (int   argc,
sl@0:       char *argv[])
sl@0: {
sl@0: 	#ifdef SYMBIAN
sl@0: 	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);
sl@0: 	#endif /*SYMBIAN*/
sl@0: 	
sl@0: 	cache_test();
sl@0: 	
sl@0: 	#if SYMBIAN
sl@0:   	testResultXml("cache_test");
sl@0:   	#endif /* EMULATOR */
sl@0: 	
sl@0: 	return 0;
sl@0: }