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