Files
FreeRDP/winpr/libwinpr/utils/test/TestArrayList.c

85 lines
1.7 KiB
C
Raw Permalink Normal View History

2012-12-07 19:40:44 -05:00
#include <winpr/crt.h>
#include <winpr/tchar.h>
#include <winpr/collections.h>
int TestArrayList(int argc, char* argv[])
{
int res = -1;
2024-08-29 11:11:11 +02:00
SSIZE_T rc = 0;
size_t val = 0;
2019-02-07 14:37:23 +01:00
const size_t elemsToInsert = 10;
2012-12-07 19:40:44 -05:00
2021-07-29 10:18:52 +02:00
WINPR_UNUSED(argc);
WINPR_UNUSED(argv);
2024-09-25 02:50:19 +02:00
wArrayList* arrayList = ArrayList_New(TRUE);
if (!arrayList)
return -1;
2012-12-07 19:40:44 -05:00
for (size_t index = 0; index < elemsToInsert; index++)
2012-12-07 19:40:44 -05:00
{
if (!ArrayList_Append(arrayList, (void*)index))
goto fail;
2012-12-07 19:40:44 -05:00
}
2024-09-25 02:50:19 +02:00
size_t count = ArrayList_Count(arrayList);
2012-12-07 19:40:44 -05:00
2024-09-25 02:50:19 +02:00
printf("ArrayList count: %" PRIuz "\n", count);
2012-12-07 19:40:44 -05:00
SSIZE_T index = ArrayList_IndexOf(arrayList, (void*)(size_t)6, -1, -1);
2012-12-07 19:40:44 -05:00
2019-11-06 15:24:51 +01:00
printf("ArrayList index: %" PRIdz "\n", index);
2012-12-07 19:40:44 -05:00
if (index != 6)
goto fail;
2012-12-07 19:40:44 -05:00
2019-11-06 15:24:51 +01:00
ArrayList_Insert(arrayList, 5, (void*)(size_t)100);
2012-12-07 19:40:44 -05:00
2019-11-06 15:24:51 +01:00
index = ArrayList_IndexOf(arrayList, (void*)(size_t)6, -1, -1);
printf("ArrayList index: %" PRIdz "\n", index);
2012-12-07 19:40:44 -05:00
if (index != 7)
goto fail;
2012-12-07 19:40:44 -05:00
2019-11-06 15:24:51 +01:00
ArrayList_Remove(arrayList, (void*)(size_t)100);
2012-12-07 19:40:44 -05:00
2019-11-06 15:24:51 +01:00
rc = ArrayList_IndexOf(arrayList, (void*)(size_t)6, -1, -1);
2025-03-24 21:23:10 +01:00
printf("ArrayList index: %" PRIdz "\n", rc);
2012-12-07 19:40:44 -05:00
2019-02-07 14:37:23 +01:00
if (rc != 6)
goto fail;
2012-12-07 19:40:44 -05:00
for (size_t index = 0; index < elemsToInsert; index++)
2019-11-06 15:24:51 +01:00
{
val = (size_t)ArrayList_GetItem(arrayList, 0);
2019-02-07 14:37:23 +01:00
if (!ArrayList_RemoveAt(arrayList, 0))
goto fail;
if (val != index)
{
2019-11-06 15:24:51 +01:00
printf("ArrayList: shifted %" PRIdz " entries, expected value %" PRIdz ", got %" PRIdz
"\n",
index, index, val);
goto fail;
}
}
2024-08-29 11:11:11 +02:00
rc = ArrayList_IndexOf(arrayList, (void*)elemsToInsert, -1, -1);
2025-03-24 21:23:10 +01:00
printf("ArrayList index: %" PRIdz "\n", rc);
2019-02-07 14:37:23 +01:00
if (rc != -1)
goto fail;
count = ArrayList_Count(arrayList);
2024-09-25 02:50:19 +02:00
printf("ArrayList count: %" PRIuz "\n", count);
if (count != 0)
goto fail;
2012-12-07 19:40:44 -05:00
ArrayList_Clear(arrayList);
res = 0;
fail:
2012-12-07 19:40:44 -05:00
ArrayList_Free(arrayList);
return res;
2012-12-07 19:40:44 -05:00
}