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