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 |
|
sl@0
|
37 |
int main (int argc,char *argv[])
|
sl@0
|
38 |
{
|
sl@0
|
39 |
|
sl@0
|
40 |
GList *list1 = NULL,*list2 = NULL,*l,*l1,*list3 = NULL;
|
sl@0
|
41 |
int i;
|
sl@0
|
42 |
int *value;
|
sl@0
|
43 |
const char mem_allocator[] = "mem_allocator";
|
sl@0
|
44 |
GAllocator *allocator;
|
sl@0
|
45 |
|
sl@0
|
46 |
int num1[] =
|
sl@0
|
47 |
{
|
sl@0
|
48 |
1,2,3
|
sl@0
|
49 |
};
|
sl@0
|
50 |
|
sl@0
|
51 |
int num2[] =
|
sl@0
|
52 |
{
|
sl@0
|
53 |
4,5,6
|
sl@0
|
54 |
};
|
sl@0
|
55 |
|
sl@0
|
56 |
#ifdef SYMBIAN
|
sl@0
|
57 |
|
sl@0
|
58 |
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
|
59 |
#endif /*SYMBIAN*/
|
sl@0
|
60 |
|
sl@0
|
61 |
allocator = g_allocator_new(mem_allocator,500);
|
sl@0
|
62 |
|
sl@0
|
63 |
for(i=0;i<3;i++)
|
sl@0
|
64 |
list1 = g_list_append (list1, &num1[i]);
|
sl@0
|
65 |
|
sl@0
|
66 |
for(i=0;i<3;i++)
|
sl@0
|
67 |
list2 = g_list_append (list2, &num2[i]);
|
sl@0
|
68 |
|
sl@0
|
69 |
|
sl@0
|
70 |
list1 = g_list_concat(list1,list2);
|
sl@0
|
71 |
|
sl@0
|
72 |
for(i=0;i<6;i++)
|
sl@0
|
73 |
{
|
sl@0
|
74 |
l = g_list_nth(list1,i);
|
sl@0
|
75 |
g_assert(*(gint *)(l->data) == i+1);
|
sl@0
|
76 |
}
|
sl@0
|
77 |
|
sl@0
|
78 |
list2 = g_list_copy(list1);
|
sl@0
|
79 |
|
sl@0
|
80 |
for(i=0;i<3;i++)
|
sl@0
|
81 |
{
|
sl@0
|
82 |
l = g_list_nth(list2,i);
|
sl@0
|
83 |
g_assert(*(gint *)(l->data) == i+1);
|
sl@0
|
84 |
}
|
sl@0
|
85 |
|
sl@0
|
86 |
l = g_list_first(list2);
|
sl@0
|
87 |
g_assert(*(gint *)(l->data) == 1);
|
sl@0
|
88 |
|
sl@0
|
89 |
value = (int *)g_list_nth_data(list1,1);
|
sl@0
|
90 |
|
sl@0
|
91 |
g_assert(*value == 2);
|
sl@0
|
92 |
|
sl@0
|
93 |
l = g_list_nth(list1,3);
|
sl@0
|
94 |
|
sl@0
|
95 |
l1 = g_list_nth_prev(l,2);
|
sl@0
|
96 |
|
sl@0
|
97 |
for(i=0;i<5;i++)
|
sl@0
|
98 |
{
|
sl@0
|
99 |
l = g_list_nth(l1,i);
|
sl@0
|
100 |
g_assert(*(gint *)(l->data) == i+2);
|
sl@0
|
101 |
}
|
sl@0
|
102 |
|
sl@0
|
103 |
g_list_push_allocator(allocator);
|
sl@0
|
104 |
|
sl@0
|
105 |
list3 = g_list_append(list3,&num1[2]);
|
sl@0
|
106 |
|
sl@0
|
107 |
g_assert(*(gint *)(list3->data) == 3);
|
sl@0
|
108 |
|
sl@0
|
109 |
g_list_pop_allocator();
|
sl@0
|
110 |
|
sl@0
|
111 |
list3 = g_list_append(list3,&num1[0]);
|
sl@0
|
112 |
|
sl@0
|
113 |
g_assert(*(gint *)(list3->next->data) == 1);
|
sl@0
|
114 |
|
sl@0
|
115 |
list1 = g_list_append(list1,&num1[0]);
|
sl@0
|
116 |
|
sl@0
|
117 |
i = g_list_length(list1);
|
sl@0
|
118 |
|
sl@0
|
119 |
list1 = g_list_remove_all(list1,&num1[0]);
|
sl@0
|
120 |
|
sl@0
|
121 |
i = g_list_length(list1);
|
sl@0
|
122 |
|
sl@0
|
123 |
g_assert(g_list_length(list1) == 5); // should be this value as we will remove 2 1's from the list
|
sl@0
|
124 |
|
sl@0
|
125 |
for(i==0;i<g_list_length(list1);i++)
|
sl@0
|
126 |
{
|
sl@0
|
127 |
l = g_list_nth(list1,i);
|
sl@0
|
128 |
g_assert(*(gint *)(l->data) != 1);
|
sl@0
|
129 |
}
|
sl@0
|
130 |
|
sl@0
|
131 |
g_allocator_free(allocator);
|
sl@0
|
132 |
|
sl@0
|
133 |
#ifdef SYMBIAN
|
sl@0
|
134 |
testResultXml("list_test");
|
sl@0
|
135 |
#endif /* EMULATOR */
|
sl@0
|
136 |
|
sl@0
|
137 |
return 0;
|
sl@0
|
138 |
} |