FreeRDP
TestListDictionary.c
1 
2 #include <winpr/crt.h>
3 #include <winpr/tchar.h>
4 #include <winpr/collections.h>
5 
6 static char* key1 = "key1";
7 static char* key2 = "key2";
8 static char* key3 = "key3";
9 
10 static char* val1 = "val1";
11 static char* val2 = "val2";
12 static char* val3 = "val3";
13 
14 int TestListDictionary(int argc, char* argv[])
15 {
16  size_t count = 0;
17  char* value = NULL;
18  wListDictionary* list = NULL;
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  ListDictionary_SetItemValue(list, key2, "apple");
109 
110  value = (char*)ListDictionary_GetItemValue(list, key2);
111 
112  if (strcmp(value, "apple") != 0)
113  {
114  printf("ListDictionary_GetItemValue: Expected : %s, Actual: %s\n", "apple", value);
115  return -1;
116  }
117 
118  if (!ListDictionary_Contains(list, key2))
119  {
120  printf("ListDictionary_Contains: Expected : TRUE, Actual: FALSE\n");
121  return -1;
122  }
123 
124  if (!ListDictionary_Take(list, key2))
125  {
126  printf("ListDictionary_Remove: Expected : TRUE, Actual: FALSE\n");
127  return -1;
128  }
129 
130  if (ListDictionary_Take(list, key2))
131  {
132  printf("ListDictionary_Remove: Expected : FALSE, Actual: TRUE\n");
133  return -1;
134  }
135 
136  value = ListDictionary_Take_Head(list);
137  count = ListDictionary_Count(list);
138  if ((strncmp(value, val1, 4) != 0) || (count != 1))
139  {
140  printf("ListDictionary_Remove_Head: Expected : %s, Actual: %s Count: %" PRIuz "\n", val1,
141  value, count);
142  return -1;
143  }
144 
145  value = ListDictionary_Take_Head(list);
146  count = ListDictionary_Count(list);
147  if ((strncmp(value, val3, 4) != 0) || (count != 0))
148  {
149  printf("ListDictionary_Remove_Head: Expected : %s, Actual: %s Count: %" PRIuz "\n", val3,
150  value, count);
151  return -1;
152  }
153 
154  value = ListDictionary_Take_Head(list);
155  if (value)
156  {
157  printf("ListDictionary_Remove_Head: Expected : (null), Actual: %s\n", value);
158  return -1;
159  }
160 
161  if (!ListDictionary_Add(list, key1, val1) || !ListDictionary_Add(list, key2, val2) ||
162  !ListDictionary_Add(list, key3, val3))
163  return -1;
164 
165  ListDictionary_Clear(list);
166 
167  count = ListDictionary_Count(list);
168 
169  if (count != 0)
170  {
171  printf("ListDictionary_Count: Expected : 0, Actual: %" PRIuz "\n", count);
172  return -1;
173  }
174 
175  ListDictionary_Free(list);
176 
177  return 0;
178 }