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