1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
#include <winpr/crt.h>
#include <winpr/tchar.h>
#include <winpr/collections.h>
static char* key1 = "key1";
static char* key2 = "key2";
static char* key3 = "key3";
static char* val1 = "val1";
static char* val2 = "val2";
static char* val3 = "val3";
int TestListDictionary(int argc, char* argv[])
{
size_t count = 0;
char* value = NULL;
wListDictionary* list = NULL;
WINPR_UNUSED(argc);
WINPR_UNUSED(argv);
list = ListDictionary_New(TRUE);
if (!list)
return -1;
if (!ListDictionary_Add(list, key1, val1) || !ListDictionary_Add(list, key2, val2) ||
!ListDictionary_Add(list, key3, val3))
return -1;
count = ListDictionary_Count(list);
if (count != 3)
{
printf("ListDictionary_Count: Expected : 3, Actual: %" PRIuz "\n", count);
return -1;
}
ListDictionary_Remove(list, key2);
count = ListDictionary_Count(list);
if (count != 2)
{
printf("ListDictionary_Count: Expected : 2, Actual: %" PRIuz "\n", count);
return -1;
}
ListDictionary_Remove(list, key3);
count = ListDictionary_Count(list);
if (count != 1)
{
printf("ListDictionary_Count: Expected : 1, Actual: %" PRIuz "\n", count);
return -1;
}
ListDictionary_Remove(list, key1);
count = ListDictionary_Count(list);
if (count != 0)
{
printf("ListDictionary_Count: Expected : 0, Actual: %" PRIuz "\n", count);
return -1;
}
if (!ListDictionary_Add(list, key1, val1) || !ListDictionary_Add(list, key2, val2) ||
!ListDictionary_Add(list, key3, val3))
return -1;
count = ListDictionary_Count(list);
if (count != 3)
{
printf("ListDictionary_Count: Expected : 3, Actual: %" PRIuz "\n", count);
return -1;
}
value = (char*)ListDictionary_GetItemValue(list, key1);
if (strcmp(value, val1) != 0)
{
printf("ListDictionary_GetItemValue: Expected : %" PRIuz ", Actual: %" PRIuz "\n",
(size_t)val1, (size_t)value);
return -1;
}
value = (char*)ListDictionary_GetItemValue(list, key2);
if (strcmp(value, val2) != 0)
{
printf("ListDictionary_GetItemValue: Expected : %" PRIuz ", Actual: %" PRIuz "\n",
(size_t)val2, (size_t)value);
return -1;
}
value = (char*)ListDictionary_GetItemValue(list, key3);
if (strcmp(value, val3) != 0)
{
printf("ListDictionary_GetItemValue: Expected : %" PRIuz ", Actual: %" PRIuz "\n",
(size_t)val3, (size_t)value);
return -1;
}
ListDictionary_SetItemValue(list, key2, "apple");
value = (char*)ListDictionary_GetItemValue(list, key2);
if (strcmp(value, "apple") != 0)
{
printf("ListDictionary_GetItemValue: Expected : %s, Actual: %s\n", "apple", value);
return -1;
}
if (!ListDictionary_Contains(list, key2))
{
printf("ListDictionary_Contains: Expected : TRUE, Actual: FALSE\n");
return -1;
}
if (!ListDictionary_Take(list, key2))
{
printf("ListDictionary_Remove: Expected : TRUE, Actual: FALSE\n");
return -1;
}
if (ListDictionary_Take(list, key2))
{
printf("ListDictionary_Remove: Expected : FALSE, Actual: TRUE\n");
return -1;
}
value = ListDictionary_Take_Head(list);
count = ListDictionary_Count(list);
if (strncmp(value, val1, 4) || count != 1)
{
printf("ListDictionary_Remove_Head: Expected : %s, Actual: %s Count: %" PRIuz "\n", val1,
value, count);
return -1;
}
value = ListDictionary_Take_Head(list);
count = ListDictionary_Count(list);
if (strncmp(value, val3, 4) || count != 0)
{
printf("ListDictionary_Remove_Head: Expected : %s, Actual: %s Count: %" PRIuz "\n", val3,
value, count);
return -1;
}
value = ListDictionary_Take_Head(list);
if (value)
{
printf("ListDictionary_Remove_Head: Expected : (null), Actual: %s\n", value);
return -1;
}
if (!ListDictionary_Add(list, key1, val1) || !ListDictionary_Add(list, key2, val2) ||
!ListDictionary_Add(list, key3, val3))
return -1;
ListDictionary_Clear(list);
count = ListDictionary_Count(list);
if (count != 0)
{
printf("ListDictionary_Count: Expected : 0, Actual: %" PRIuz "\n", count);
return -1;
}
ListDictionary_Free(list);
return 0;
}
|