os/ossrv/glib/tsrc/BC/src/mem_test.c
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/glib/tsrc/BC/src/mem_test.c	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,106 @@
     1.4 +/*
     1.5 +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
     1.6 +*
     1.7 +* This library is free software; you can redistribute it and/or
     1.8 +* modify it under the terms of the GNU Lesser General Public
     1.9 +* License as published by the Free Software Foundation; either
    1.10 +* version 2 of the License, or (at your option) any later version.
    1.11 +*
    1.12 +* This library is distributed in the hope that it will be useful,
    1.13 +* but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.14 +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.15 +* Lesser General Public License for more details.
    1.16 +*
    1.17 +* You should have received a copy of the GNU Lesser General Public
    1.18 +* License along with this library; if not, write to the
    1.19 +* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    1.20 +* Boston, MA 02111-1307, USA.
    1.21 +*
    1.22 +* Description:
    1.23 +*
    1.24 +*/
    1.25 +
    1.26 +
    1.27 +
    1.28 +#undef G_DISABLE_ASSERT
    1.29 +#undef G_LOG_DOMAIN
    1.30 +
    1.31 +#include <stdio.h>
    1.32 +#include <glib.h>
    1.33 +#include <stdlib.h>
    1.34 +#include <glib_global.h>
    1.35 +
    1.36 +#ifdef SYMBIAN
    1.37 +#include "mrt2_glib2_test.h"
    1.38 +#endif /*SYMBIAN*/
    1.39 +
    1.40 +void myLogHandler(const gchar* log_domain, GLogLevelFlags log_level,
    1.41 +					const gchar* message, gpointer user_data)
    1.42 +{
    1.43 +	FILE *fp;
    1.44 +	fp = fopen("c:\\meminfo.txt","a");
    1.45 +	
    1.46 +	if(fp)
    1.47 +	{
    1.48 +		fprintf(fp,message);
    1.49 +		fprintf(fp,"\n");
    1.50 +		fclose(fp);
    1.51 +	}
    1.52 +}
    1.53 +
    1.54 +void g_mem_is_system_malloc_test()
    1.55 +{
    1.56 +	g_assert(g_mem_is_system_malloc());
    1.57 +}
    1.58 +
    1.59 +void g_mem_chunk_reset_test()
    1.60 +{
    1.61 +	gchar *name = "chunk";
    1.62 +	GMemChunk *mem_chunk = g_mem_chunk_new(name,2,10,G_ALLOC_AND_FREE);
    1.63 +	guint16 *x = g_mem_chunk_alloc(mem_chunk);
    1.64 +	*x = 50;
    1.65 +	g_mem_chunk_reset(mem_chunk);
    1.66 +	*x = 10;
    1.67 +}
    1.68 +
    1.69 +void g_mem_test()
    1.70 +{
    1.71 +	GMemVTable temp_glib_mem_vtable = {
    1.72 +		malloc,
    1.73 +		realloc,
    1.74 +		free,
    1.75 +		calloc,
    1.76 +		malloc,
    1.77 +		realloc,
    1.78 +	};
    1.79 +	
    1.80 +	gchar *name = "chunk";
    1.81 +	GMemChunk *mem_chunk;
    1.82 +	guint16 *x = NULL;
    1.83 +	
    1.84 +	FILE *fp;
    1.85 +	
    1.86 +	g_mem_set_vtable(&temp_glib_mem_vtable);
    1.87 +	mem_chunk = g_mem_chunk_new(name,2,10,G_ALLOC_AND_FREE);
    1.88 +	x = g_mem_chunk_alloc(mem_chunk);
    1.89 +	g_assert(x != NULL);
    1.90 +}
    1.91 +
    1.92 +int
    1.93 +main (int argc, char *argv[])
    1.94 +{
    1.95 +	#ifdef SYMBIAN
    1.96 +	
    1.97 +	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);
    1.98 +	#endif /*SYMBIAN*/
    1.99 +	
   1.100 +	g_mem_is_system_malloc_test();
   1.101 +	g_mem_chunk_reset_test();
   1.102 +	g_mem_test();
   1.103 +	
   1.104 +	#ifdef SYMBIAN
   1.105 +  	testResultXml("mem_test");
   1.106 +  	#endif /* EMULATOR */
   1.107 +  
   1.108 +	return 0;
   1.109 +}