FreeRDP
Loading...
Searching...
No Matches
TestArrayList.c
1
2#include <winpr/crt.h>
3#include <winpr/tchar.h>
4#include <winpr/collections.h>
5
6int TestArrayList(int argc, char* argv[])
7{
8 int res = -1;
9 SSIZE_T rc = 0;
10 size_t val = 0;
11 const size_t elemsToInsert = 10;
12
13 WINPR_UNUSED(argc);
14 WINPR_UNUSED(argv);
15
16 wArrayList* arrayList = ArrayList_New(TRUE);
17 if (!arrayList)
18 return -1;
19
20 for (size_t index = 0; index < elemsToInsert; index++)
21 {
22 if (!ArrayList_Append(arrayList, (void*)index))
23 goto fail;
24 }
25
26 size_t count = ArrayList_Count(arrayList);
27
28 printf("ArrayList count: %" PRIuz "\n", count);
29
30 SSIZE_T index = ArrayList_IndexOf(arrayList, (void*)(size_t)6, -1, -1);
31
32 printf("ArrayList index: %" PRIdz "\n", index);
33
34 if (index != 6)
35 goto fail;
36
37 if (!ArrayList_Insert(arrayList, 5, (void*)(size_t)100))
38 goto fail;
39
40 index = ArrayList_IndexOf(arrayList, (void*)(size_t)6, -1, -1);
41 printf("ArrayList index: %" PRIdz "\n", index);
42
43 if (index != 7)
44 goto fail;
45
46 ArrayList_Remove(arrayList, (void*)(size_t)100);
47
48 rc = ArrayList_IndexOf(arrayList, (void*)(size_t)6, -1, -1);
49 printf("ArrayList index: %" PRIdz "\n", rc);
50
51 if (rc != 6)
52 goto fail;
53
54 for (size_t index = 0; index < elemsToInsert; index++)
55 {
56 val = (size_t)ArrayList_GetItem(arrayList, 0);
57 if (!ArrayList_RemoveAt(arrayList, 0))
58 goto fail;
59
60 if (val != index)
61 {
62 printf("ArrayList: shifted %" PRIdz " entries, expected value %" PRIdz ", got %" PRIdz
63 "\n",
64 index, index, val);
65 goto fail;
66 }
67 }
68
69 rc = ArrayList_IndexOf(arrayList, (void*)elemsToInsert, -1, -1);
70 printf("ArrayList index: %" PRIdz "\n", rc);
71 if (rc != -1)
72 goto fail;
73
74 count = ArrayList_Count(arrayList);
75 printf("ArrayList count: %" PRIuz "\n", count);
76 if (count != 0)
77 goto fail;
78
79 ArrayList_Clear(arrayList);
80 res = 0;
81fail:
82 ArrayList_Free(arrayList);
83
84 return res;
85}