2013-08-06 01:29:14 +04:00
|
|
|
|
|
|
|
#include <winpr/crt.h>
|
|
|
|
#include <winpr/tchar.h>
|
|
|
|
#include <winpr/collections.h>
|
|
|
|
|
|
|
|
int TestLinkedList(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
int count;
|
|
|
|
wLinkedList* list;
|
|
|
|
list = LinkedList_New();
|
2019-11-06 17:24:51 +03:00
|
|
|
LinkedList_AddFirst(list, (void*)(size_t)1);
|
|
|
|
LinkedList_AddLast(list, (void*)(size_t)2);
|
|
|
|
LinkedList_AddLast(list, (void*)(size_t)3);
|
2013-08-06 01:29:14 +04:00
|
|
|
count = LinkedList_Count(list);
|
|
|
|
|
|
|
|
if (count != 3)
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
printf("LinkedList_Count: expected 3, actual: %d\n", count);
|
2013-08-06 01:29:14 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
LinkedList_Enumerator_Reset(list);
|
|
|
|
|
|
|
|
while (LinkedList_Enumerator_MoveNext(list))
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
printf("\t%" PRIuz "\n", (size_t)LinkedList_Enumerator_Current(list));
|
2013-08-06 01:29:14 +04:00
|
|
|
}
|
|
|
|
|
2017-02-16 15:17:49 +03:00
|
|
|
printf("\n");
|
2019-11-06 17:24:51 +03:00
|
|
|
printf("LinkedList First: %" PRIuz " Last: %" PRIuz "\n", (size_t)LinkedList_First(list),
|
|
|
|
(size_t)LinkedList_Last(list));
|
2013-08-06 01:29:14 +04:00
|
|
|
LinkedList_RemoveFirst(list);
|
|
|
|
LinkedList_RemoveLast(list);
|
|
|
|
count = LinkedList_Count(list);
|
|
|
|
|
|
|
|
if (count != 1)
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
printf("LinkedList_Count: expected 1, actual: %d\n", count);
|
2013-08-06 01:29:14 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
LinkedList_Enumerator_Reset(list);
|
|
|
|
|
|
|
|
while (LinkedList_Enumerator_MoveNext(list))
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
printf("\t%" PRIuz "\n", (size_t)LinkedList_Enumerator_Current(list));
|
2013-08-06 01:29:14 +04:00
|
|
|
}
|
|
|
|
|
2017-02-16 15:17:49 +03:00
|
|
|
printf("\n");
|
2019-11-06 17:24:51 +03:00
|
|
|
printf("LinkedList First: %" PRIuz " Last: %" PRIuz "\n", (size_t)LinkedList_First(list),
|
|
|
|
(size_t)LinkedList_Last(list));
|
2013-08-06 01:29:14 +04:00
|
|
|
LinkedList_RemoveFirst(list);
|
|
|
|
LinkedList_RemoveLast(list);
|
|
|
|
count = LinkedList_Count(list);
|
|
|
|
|
|
|
|
if (count != 0)
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
printf("LinkedList_Count: expected 0, actual: %d\n", count);
|
2013-08-06 01:29:14 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
LinkedList_AddFirst(list, (void*)(size_t)4);
|
|
|
|
LinkedList_AddLast(list, (void*)(size_t)5);
|
|
|
|
LinkedList_AddLast(list, (void*)(size_t)6);
|
2013-08-06 01:29:14 +04:00
|
|
|
count = LinkedList_Count(list);
|
|
|
|
|
|
|
|
if (count != 3)
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
printf("LinkedList_Count: expected 3, actual: %d\n", count);
|
2013-08-06 01:29:14 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
LinkedList_Enumerator_Reset(list);
|
|
|
|
|
|
|
|
while (LinkedList_Enumerator_MoveNext(list))
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
printf("\t%" PRIuz "\n", (size_t)LinkedList_Enumerator_Current(list));
|
2013-08-06 01:29:14 +04:00
|
|
|
}
|
|
|
|
|
2017-02-16 15:17:49 +03:00
|
|
|
printf("\n");
|
2019-11-06 17:24:51 +03:00
|
|
|
printf("LinkedList First: %" PRIuz " Last: %" PRIuz "\n", (size_t)LinkedList_First(list),
|
|
|
|
(size_t)LinkedList_Last(list));
|
|
|
|
LinkedList_Remove(list, (void*)(size_t)5);
|
2013-08-06 01:29:14 +04:00
|
|
|
LinkedList_Enumerator_Reset(list);
|
|
|
|
|
|
|
|
while (LinkedList_Enumerator_MoveNext(list))
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
printf("\t%" PRIuz "\n", (size_t)LinkedList_Enumerator_Current(list));
|
2013-08-06 01:29:14 +04:00
|
|
|
}
|
|
|
|
|
2017-02-16 15:17:49 +03:00
|
|
|
printf("\n");
|
2019-11-06 17:24:51 +03:00
|
|
|
printf("LinkedList First: %" PRIuz " Last: %" PRIuz "\n", (size_t)LinkedList_First(list),
|
|
|
|
(size_t)LinkedList_Last(list));
|
2013-08-06 01:29:14 +04:00
|
|
|
LinkedList_Free(list);
|
2014-09-24 15:03:46 +04:00
|
|
|
/* Test enumerator robustness */
|
|
|
|
/* enumerator on an empty list */
|
|
|
|
list = LinkedList_New();
|
|
|
|
LinkedList_Enumerator_Reset(list);
|
2017-02-16 15:17:49 +03:00
|
|
|
|
2014-09-24 15:03:46 +04:00
|
|
|
while (LinkedList_Enumerator_MoveNext(list))
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
printf("\terror: %" PRIuz "\n", (size_t)LinkedList_Enumerator_Current(list));
|
2014-09-24 15:03:46 +04:00
|
|
|
}
|
2017-02-16 15:17:49 +03:00
|
|
|
|
2014-09-24 15:03:46 +04:00
|
|
|
printf("\n");
|
|
|
|
LinkedList_Free(list);
|
|
|
|
/* Use an enumerator without reset */
|
|
|
|
list = LinkedList_New();
|
2019-11-06 17:24:51 +03:00
|
|
|
LinkedList_AddFirst(list, (void*)(size_t)4);
|
|
|
|
LinkedList_AddLast(list, (void*)(size_t)5);
|
|
|
|
LinkedList_AddLast(list, (void*)(size_t)6);
|
2017-02-16 15:17:49 +03:00
|
|
|
|
2014-09-24 15:03:46 +04:00
|
|
|
while (LinkedList_Enumerator_MoveNext(list))
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
printf("\t%" PRIuz "\n", (size_t)LinkedList_Enumerator_Current(list));
|
2014-09-24 15:03:46 +04:00
|
|
|
}
|
2017-02-16 15:17:49 +03:00
|
|
|
|
2014-09-24 15:03:46 +04:00
|
|
|
printf("\n");
|
|
|
|
LinkedList_Free(list);
|
2013-08-06 01:29:14 +04:00
|
|
|
return 0;
|
|
|
|
}
|