sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
|
sl@0
|
3 |
*
|
sl@0
|
4 |
* This library is free software; you can redistribute it and/or
|
sl@0
|
5 |
* modify it under the terms of the GNU Lesser General Public
|
sl@0
|
6 |
* License as published by the Free Software Foundation; either
|
sl@0
|
7 |
* version 2 of the License, or (at your option) any later version.
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* This library is distributed in the hope that it will be useful,
|
sl@0
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
sl@0
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
sl@0
|
12 |
* Lesser General Public License for more details.
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* You should have received a copy of the GNU Lesser General Public
|
sl@0
|
15 |
* License along with this library; if not, write to the
|
sl@0
|
16 |
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
sl@0
|
17 |
* Boston, MA 02111-1307, USA.
|
sl@0
|
18 |
*
|
sl@0
|
19 |
* Description:
|
sl@0
|
20 |
*
|
sl@0
|
21 |
*/
|
sl@0
|
22 |
|
sl@0
|
23 |
|
sl@0
|
24 |
|
sl@0
|
25 |
#undef G_DISABLE_ASSERT
|
sl@0
|
26 |
#undef G_LOG_DOMAIN
|
sl@0
|
27 |
|
sl@0
|
28 |
#include <stdio.h>
|
sl@0
|
29 |
#include <glib.h>
|
sl@0
|
30 |
#include <stdlib.h>
|
sl@0
|
31 |
#include <glib_global.h>
|
sl@0
|
32 |
|
sl@0
|
33 |
#ifdef SYMBIAN
|
sl@0
|
34 |
#include "mrt2_glib2_test.h"
|
sl@0
|
35 |
#endif /*SYMBIAN*/
|
sl@0
|
36 |
|
sl@0
|
37 |
void myLogHandler(const gchar* log_domain, GLogLevelFlags log_level,
|
sl@0
|
38 |
const gchar* message, gpointer user_data)
|
sl@0
|
39 |
{
|
sl@0
|
40 |
FILE *fp;
|
sl@0
|
41 |
fp = fopen("c:\\meminfo.txt","a");
|
sl@0
|
42 |
|
sl@0
|
43 |
if(fp)
|
sl@0
|
44 |
{
|
sl@0
|
45 |
fprintf(fp,message);
|
sl@0
|
46 |
fprintf(fp,"\n");
|
sl@0
|
47 |
fclose(fp);
|
sl@0
|
48 |
}
|
sl@0
|
49 |
}
|
sl@0
|
50 |
|
sl@0
|
51 |
void g_mem_is_system_malloc_test()
|
sl@0
|
52 |
{
|
sl@0
|
53 |
g_assert(g_mem_is_system_malloc());
|
sl@0
|
54 |
}
|
sl@0
|
55 |
|
sl@0
|
56 |
void g_mem_chunk_reset_test()
|
sl@0
|
57 |
{
|
sl@0
|
58 |
gchar *name = "chunk";
|
sl@0
|
59 |
GMemChunk *mem_chunk = g_mem_chunk_new(name,2,10,G_ALLOC_AND_FREE);
|
sl@0
|
60 |
guint16 *x = g_mem_chunk_alloc(mem_chunk);
|
sl@0
|
61 |
*x = 50;
|
sl@0
|
62 |
g_mem_chunk_reset(mem_chunk);
|
sl@0
|
63 |
*x = 10;
|
sl@0
|
64 |
}
|
sl@0
|
65 |
|
sl@0
|
66 |
void g_mem_test()
|
sl@0
|
67 |
{
|
sl@0
|
68 |
GMemVTable temp_glib_mem_vtable = {
|
sl@0
|
69 |
malloc,
|
sl@0
|
70 |
realloc,
|
sl@0
|
71 |
free,
|
sl@0
|
72 |
calloc,
|
sl@0
|
73 |
malloc,
|
sl@0
|
74 |
realloc,
|
sl@0
|
75 |
};
|
sl@0
|
76 |
|
sl@0
|
77 |
gchar *name = "chunk";
|
sl@0
|
78 |
GMemChunk *mem_chunk;
|
sl@0
|
79 |
guint16 *x = NULL;
|
sl@0
|
80 |
|
sl@0
|
81 |
FILE *fp;
|
sl@0
|
82 |
|
sl@0
|
83 |
g_mem_set_vtable(&temp_glib_mem_vtable);
|
sl@0
|
84 |
mem_chunk = g_mem_chunk_new(name,2,10,G_ALLOC_AND_FREE);
|
sl@0
|
85 |
x = g_mem_chunk_alloc(mem_chunk);
|
sl@0
|
86 |
g_assert(x != NULL);
|
sl@0
|
87 |
}
|
sl@0
|
88 |
|
sl@0
|
89 |
int
|
sl@0
|
90 |
main (int argc, char *argv[])
|
sl@0
|
91 |
{
|
sl@0
|
92 |
#ifdef SYMBIAN
|
sl@0
|
93 |
|
sl@0
|
94 |
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
|
95 |
#endif /*SYMBIAN*/
|
sl@0
|
96 |
|
sl@0
|
97 |
g_mem_is_system_malloc_test();
|
sl@0
|
98 |
g_mem_chunk_reset_test();
|
sl@0
|
99 |
g_mem_test();
|
sl@0
|
100 |
|
sl@0
|
101 |
#ifdef SYMBIAN
|
sl@0
|
102 |
testResultXml("mem_test");
|
sl@0
|
103 |
#endif /* EMULATOR */
|
sl@0
|
104 |
|
sl@0
|
105 |
return 0;
|
sl@0
|
106 |
}
|