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 <string.h>
|
sl@0
|
30 |
#include "glib.h"
|
sl@0
|
31 |
|
sl@0
|
32 |
#ifdef SYMBIAN
|
sl@0
|
33 |
#include "mrt2_glib2_test.h"
|
sl@0
|
34 |
#endif /*SYMBIAN*/
|
sl@0
|
35 |
|
sl@0
|
36 |
struct data
|
sl@0
|
37 |
{
|
sl@0
|
38 |
char a[50],b[50],c[50];
|
sl@0
|
39 |
};
|
sl@0
|
40 |
|
sl@0
|
41 |
void function(GQuark key_id,gpointer data,gpointer user_data)
|
sl@0
|
42 |
{
|
sl@0
|
43 |
int *i = (int *)user_data;
|
sl@0
|
44 |
(*i)++;
|
sl@0
|
45 |
}
|
sl@0
|
46 |
|
sl@0
|
47 |
void dataset_test()
|
sl@0
|
48 |
{
|
sl@0
|
49 |
struct data *d = g_malloc(sizeof(struct data));
|
sl@0
|
50 |
gchar *str1,*str2,*str3,*str4,*str5,*str6;
|
sl@0
|
51 |
int user_data = 0;
|
sl@0
|
52 |
|
sl@0
|
53 |
GQuark q1,q2,q3;
|
sl@0
|
54 |
|
sl@0
|
55 |
strcpy(d->a,"test1");
|
sl@0
|
56 |
strcpy(d->b,"test2");
|
sl@0
|
57 |
strcpy(d->c,"test3");
|
sl@0
|
58 |
|
sl@0
|
59 |
q1 = g_quark_from_string(d->a);
|
sl@0
|
60 |
q2 = g_quark_from_string(d->b);
|
sl@0
|
61 |
q3 = g_quark_from_string(d->c);
|
sl@0
|
62 |
|
sl@0
|
63 |
g_dataset_id_set_data_full(d,q1,d->a,NULL);
|
sl@0
|
64 |
g_dataset_id_set_data_full(d,q2,d->b,NULL);
|
sl@0
|
65 |
g_dataset_id_set_data_full(d,q3,d->c,NULL);
|
sl@0
|
66 |
|
sl@0
|
67 |
str1 = g_dataset_id_get_data(d,q1);
|
sl@0
|
68 |
str2 = g_dataset_id_get_data(d,q2);
|
sl@0
|
69 |
str3 = g_dataset_id_get_data(d,q3);
|
sl@0
|
70 |
|
sl@0
|
71 |
// These assertions will check whether g_dataset_id_set_data_full &
|
sl@0
|
72 |
// g_dataset_id_get_data is sucessful or not
|
sl@0
|
73 |
g_assert(!strcmp(str1,d->a));
|
sl@0
|
74 |
g_assert(!strcmp(str2,d->b));
|
sl@0
|
75 |
g_assert(!strcmp(str3,d->c));
|
sl@0
|
76 |
|
sl@0
|
77 |
str4 = g_dataset_id_remove_no_notify(d,q1);
|
sl@0
|
78 |
str5 = g_dataset_id_get_data(d,q1);
|
sl@0
|
79 |
|
sl@0
|
80 |
//This assertion will check if g_dataset_id_remove_no_notify is sucessful or not
|
sl@0
|
81 |
g_assert(!strcmp(str4,d->a));
|
sl@0
|
82 |
g_assert(str5 == NULL);
|
sl@0
|
83 |
|
sl@0
|
84 |
g_dataset_foreach(d,function,&user_data);
|
sl@0
|
85 |
|
sl@0
|
86 |
|
sl@0
|
87 |
//This assertion will check if g_dataset_foreach is sucessful or not
|
sl@0
|
88 |
g_assert(user_data == 2);
|
sl@0
|
89 |
|
sl@0
|
90 |
g_dataset_destroy(d);
|
sl@0
|
91 |
|
sl@0
|
92 |
str6 = g_dataset_id_get_data(d,q2);
|
sl@0
|
93 |
|
sl@0
|
94 |
//This assertion will check if g_dataset_destroy is successful or not
|
sl@0
|
95 |
g_assert(str5 == NULL);
|
sl@0
|
96 |
|
sl@0
|
97 |
}
|
sl@0
|
98 |
|
sl@0
|
99 |
|
sl@0
|
100 |
int main (int argc,
|
sl@0
|
101 |
char *argv[])
|
sl@0
|
102 |
{
|
sl@0
|
103 |
#ifdef SYMBIAN
|
sl@0
|
104 |
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
|
105 |
#endif /*SYMBIAN*/
|
sl@0
|
106 |
|
sl@0
|
107 |
dataset_test();
|
sl@0
|
108 |
|
sl@0
|
109 |
#if SYMBIAN
|
sl@0
|
110 |
testResultXml("dataset_test");
|
sl@0
|
111 |
#endif /* EMULATOR */
|
sl@0
|
112 |
|
sl@0
|
113 |
return 0;
|
sl@0
|
114 |
} |