glib/tsrc/glib_nonstif/src/mem_test.c
branchRCL_3
changeset 57 2efc27d87e1c
parent 0 e4d67989cc36
equal deleted inserted replaced
56:acd3cd4aaceb 57:2efc27d87e1c
       
     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 <glib.h>
       
    26 #include <stdlib.h>
       
    27 #include <glib_global.h>
       
    28 
       
    29 #ifdef __SYMBIAN32__
       
    30 #include "mrt2_glib2_test.h"
       
    31 #endif /*____SYMBIAN32__32__*/
       
    32 
       
    33 void myLogHandler(const gchar* log_domain, GLogLevelFlags log_level,
       
    34 					const gchar* message, gpointer user_data)
       
    35 {
       
    36 	FILE *fp;
       
    37 	fp = fopen("c:\\meminfo.txt","a");
       
    38 	
       
    39 	if(fp)
       
    40 	{
       
    41 		fprintf(fp,message);
       
    42 		fprintf(fp,"\n");
       
    43 		fclose(fp);
       
    44 	}
       
    45 }
       
    46 
       
    47 void g_mem_is_system_malloc_test()
       
    48 {
       
    49 	g_assert(g_mem_is_system_malloc());
       
    50 }
       
    51 
       
    52 void g_mem_chunk_reset_test()
       
    53 {
       
    54 	gchar *name = "chunk";
       
    55 	GMemChunk *mem_chunk = g_mem_chunk_new(name,2,10,G_ALLOC_AND_FREE);
       
    56 	guint16 *x = g_mem_chunk_alloc(mem_chunk);
       
    57 	*x = 50;
       
    58 	g_mem_chunk_reset(mem_chunk);
       
    59 	*x = 10;
       
    60 }
       
    61 
       
    62 void g_mem_test()
       
    63 {
       
    64 	GMemVTable temp_glib_mem_vtable = {
       
    65 		malloc,
       
    66 		realloc,
       
    67 		free,
       
    68 		calloc,
       
    69 		malloc,
       
    70 		realloc,
       
    71 	};
       
    72 	
       
    73 	gchar *name = "chunk";
       
    74 	GMemChunk *mem_chunk;
       
    75 	guint16 *x = NULL;
       
    76 	
       
    77 	FILE *fp;
       
    78 	
       
    79 	g_mem_set_vtable(&temp_glib_mem_vtable);
       
    80 	mem_chunk = g_mem_chunk_new(name,2,10,G_ALLOC_AND_FREE);
       
    81 	x = g_mem_chunk_alloc(mem_chunk);
       
    82 	g_assert(x != NULL);
       
    83 }
       
    84 
       
    85 int
       
    86 main (int argc, char *argv[])
       
    87 {
       
    88 	#ifdef __SYMBIAN32__
       
    89 	
       
    90 	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);
       
    91 	#endif /*____SYMBIAN32__*/
       
    92 	
       
    93 	g_mem_is_system_malloc_test();
       
    94 	g_mem_chunk_reset_test();
       
    95 	g_mem_test();
       
    96 	
       
    97 	#ifdef __SYMBIAN32__
       
    98   	testResultXml("mem_test");
       
    99   	#endif /* EMULATOR */
       
   100   
       
   101 	return 0;
       
   102 }