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 ArrayList_Insert(arrayList, 5, (void*)(size_t)100);
38
39 index = ArrayList_IndexOf(arrayList, (void*)(size_t)6, -1, -1);
40 printf("ArrayList index: %" PRIdz "\n", index);
41
42 if (index != 7)
43 goto fail;
44
45 ArrayList_Remove(arrayList, (void*)(size_t)100);
46
47 rc = ArrayList_IndexOf(arrayList, (void*)(size_t)6, -1, -1);
48 printf("ArrayList index: %d\n", rc);
49
50 if (rc != 6)
51 goto fail;
52
53 for (size_t index = 0; index < elemsToInsert; index++)
54 {
55 val = (size_t)ArrayList_GetItem(arrayList, 0);
56 if (!ArrayList_RemoveAt(arrayList, 0))
57 goto fail;
58
59 if (val != index)
60 {
61 printf("ArrayList: shifted %" PRIdz " entries, expected value %" PRIdz ", got %" PRIdz
62 "\n",
63 index, index, val);
64 goto fail;
65 }
66 }
67
68 rc = ArrayList_IndexOf(arrayList, (void*)elemsToInsert, -1, -1);
69 printf("ArrayList index: %d\n", rc);
70 if (rc != -1)
71 goto fail;
72
73 count = ArrayList_Count(arrayList);
74 printf("ArrayList count: %" PRIuz "\n", count);
75 if (count != 0)
76 goto fail;
77
78 ArrayList_Clear(arrayList);
79 res = 0;
80fail:
81 ArrayList_Free(arrayList);
82
83 return res;
84}