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[])
|
|
|
|
{
|
|
|
|
int index;
|
|
|
|
int count;
|
2013-03-07 15:43:10 +04:00
|
|
|
size_t val;
|
2012-12-08 04:40:44 +04:00
|
|
|
wArrayList* arrayList;
|
2013-03-07 15:43:10 +04:00
|
|
|
const int elemsToInsert = 10;
|
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
|
|
|
{
|
2015-05-18 12:28:00 +03:00
|
|
|
if (ArrayList_Add(arrayList, (void*) (size_t) index) < 0)
|
|
|
|
return -1;
|
2012-12-08 04:40:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
count = ArrayList_Count(arrayList);
|
|
|
|
|
|
|
|
printf("ArrayList count: %d\n", count);
|
|
|
|
|
|
|
|
index = ArrayList_IndexOf(arrayList, (void*) (size_t) 6, -1, -1);
|
|
|
|
|
|
|
|
printf("ArrayList index: %d\n", index);
|
|
|
|
|
|
|
|
if (index != 6)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
ArrayList_Insert(arrayList, 5, (void*) (size_t) 100);
|
|
|
|
|
|
|
|
index = ArrayList_IndexOf(arrayList, (void*) (size_t) 6, -1, -1);
|
|
|
|
printf("ArrayList index: %d\n", index);
|
|
|
|
|
|
|
|
if (index != 7)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
ArrayList_Remove(arrayList, (void*) (size_t) 100);
|
|
|
|
|
|
|
|
index = ArrayList_IndexOf(arrayList, (void*) (size_t) 6, -1, -1);
|
|
|
|
printf("ArrayList index: %d\n", index);
|
|
|
|
|
|
|
|
if (index != 6)
|
|
|
|
return -1;
|
|
|
|
|
2013-03-07 15:43:10 +04:00
|
|
|
for (index = 0; index < elemsToInsert; index++) {
|
|
|
|
val = (size_t)ArrayList_GetItem(arrayList, 0);
|
|
|
|
ArrayList_RemoveAt(arrayList, 0);
|
|
|
|
if (val != index)
|
|
|
|
{
|
2019-02-21 19:28:49 +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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
index = ArrayList_IndexOf(arrayList, (void*) (size_t) elemsToInsert, -1, -1);
|
|
|
|
printf("ArrayList index: %d\n", index);
|
|
|
|
if (index != -1)
|
|
|
|
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;
|
|
|
|
}
|