2012-12-08 04:40:44 +04:00
|
|
|
|
|
|
|
#include <winpr/crt.h>
|
|
|
|
#include <winpr/tchar.h>
|
|
|
|
#include <winpr/collections.h>
|
|
|
|
|
|
|
|
int TestArrayList(int argc, char* argv[])
|
|
|
|
{
|
2019-02-07 16:37:23 +03:00
|
|
|
size_t index;
|
2012-12-08 04:40:44 +04:00
|
|
|
int count;
|
2019-02-07 16:37:23 +03:00
|
|
|
int rc;
|
2013-03-07 15:43:10 +04:00
|
|
|
size_t val;
|
2012-12-08 04:40:44 +04:00
|
|
|
wArrayList* arrayList;
|
2019-02-07 16:37:23 +03:00
|
|
|
const size_t elemsToInsert = 10;
|
2012-12-08 04:40:44 +04:00
|
|
|
|
2021-07-29 11:18:52 +03:00
|
|
|
WINPR_UNUSED(argc);
|
|
|
|
WINPR_UNUSED(argv);
|
|
|
|
|
2012-12-08 04:40:44 +04:00
|
|
|
arrayList = ArrayList_New(TRUE);
|
2015-05-18 12:28:00 +03:00
|
|
|
if (!arrayList)
|
|
|
|
return -1;
|
2012-12-08 04:40:44 +04:00
|
|
|
|
2013-03-07 15:43:10 +04:00
|
|
|
for (index = 0; index < elemsToInsert; index++)
|
2012-12-08 04:40:44 +04:00
|
|
|
{
|
2021-05-17 13:30:18 +03:00
|
|
|
if (!ArrayList_Append(arrayList, (void*)index))
|
2015-05-18 12:28:00 +03:00
|
|
|
return -1;
|
2012-12-08 04:40:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
count = ArrayList_Count(arrayList);
|
|
|
|
|
|
|
|
printf("ArrayList count: %d\n", count);
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
index = ArrayList_IndexOf(arrayList, (void*)(size_t)6, -1, -1);
|
2012-12-08 04:40:44 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
printf("ArrayList index: %" PRIdz "\n", index);
|
2012-12-08 04:40:44 +04:00
|
|
|
|
|
|
|
if (index != 6)
|
|
|
|
return -1;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
ArrayList_Insert(arrayList, 5, (void*)(size_t)100);
|
2012-12-08 04:40:44 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
index = ArrayList_IndexOf(arrayList, (void*)(size_t)6, -1, -1);
|
|
|
|
printf("ArrayList index: %" PRIdz "\n", index);
|
2012-12-08 04:40:44 +04:00
|
|
|
|
|
|
|
if (index != 7)
|
|
|
|
return -1;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
ArrayList_Remove(arrayList, (void*)(size_t)100);
|
2012-12-08 04:40:44 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
rc = ArrayList_IndexOf(arrayList, (void*)(size_t)6, -1, -1);
|
2019-02-07 16:37:23 +03:00
|
|
|
printf("ArrayList index: %d\n", rc);
|
2012-12-08 04:40:44 +04:00
|
|
|
|
2019-02-07 16:37:23 +03:00
|
|
|
if (rc != 6)
|
2012-12-08 04:40:44 +04:00
|
|
|
return -1;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
for (index = 0; index < elemsToInsert; index++)
|
|
|
|
{
|
2013-03-07 15:43:10 +04:00
|
|
|
val = (size_t)ArrayList_GetItem(arrayList, 0);
|
2019-02-07 16:37:23 +03:00
|
|
|
if (!ArrayList_RemoveAt(arrayList, 0))
|
|
|
|
return -1;
|
2013-03-07 15:43:10 +04:00
|
|
|
if (val != index)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
printf("ArrayList: shifted %" PRIdz " entries, expected value %" PRIdz ", got %" PRIdz
|
|
|
|
"\n",
|
|
|
|
index, index, val);
|
2013-03-07 15:43:10 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
rc = ArrayList_IndexOf(arrayList, (void*)(size_t)elemsToInsert, -1, -1);
|
2019-02-07 16:37:23 +03:00
|
|
|
printf("ArrayList index: %d\n", rc);
|
|
|
|
if (rc != -1)
|
2013-03-07 15:43:10 +04:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
count = ArrayList_Count(arrayList);
|
|
|
|
printf("ArrayList count: %d\n", count);
|
|
|
|
if (count != 0)
|
|
|
|
return -1;
|
|
|
|
|
2012-12-08 04:40:44 +04:00
|
|
|
ArrayList_Clear(arrayList);
|
|
|
|
ArrayList_Free(arrayList);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|