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;
|
2021-07-28 17:20:32 +03:00
|
|
|
WINPR_UNUSED(argc);
|
|
|
|
WINPR_UNUSED(argv);
|
|
|
|
|
2013-08-06 01:29:14 +04:00
|
|
|
list = LinkedList_New();
|
2021-07-28 17:20:32 +03:00
|
|
|
if (!list)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (!LinkedList_AddFirst(list, (void*)(size_t)1))
|
|
|
|
return -1;
|
|
|
|
if (!LinkedList_AddLast(list, (void*)(size_t)2))
|
|
|
|
return -1;
|
|
|
|
if (!LinkedList_AddLast(list, (void*)(size_t)3))
|
|
|
|
return -1;
|
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))
|
|
|
|
{
|
2021-07-28 17:20:32 +03:00
|
|
|
printf("\t%p\n", LinkedList_Enumerator_Current(list));
|
2013-08-06 01:29:14 +04:00
|
|
|
}
|
|
|
|
|
2017-02-16 15:17:49 +03:00
|
|
|
printf("\n");
|
2021-07-28 17:20:32 +03:00
|
|
|
printf("LinkedList First: %p Last: %p\n", LinkedList_First(list), 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))
|
|
|
|
{
|
2021-07-28 17:20:32 +03:00
|
|
|
printf("\t%p\n", LinkedList_Enumerator_Current(list));
|
2013-08-06 01:29:14 +04:00
|
|
|
}
|
|
|
|
|
2017-02-16 15:17:49 +03:00
|
|
|
printf("\n");
|
2021-07-28 17:20:32 +03:00
|
|
|
printf("LinkedList First: %p Last: %p\n", LinkedList_First(list), 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;
|
|
|
|
}
|
|
|
|
|
2021-07-28 17:20:32 +03:00
|
|
|
if (!LinkedList_AddFirst(list, (void*)(size_t)4))
|
|
|
|
return -1;
|
|
|
|
if (!LinkedList_AddLast(list, (void*)(size_t)5))
|
|
|
|
return -1;
|
|
|
|
if (!LinkedList_AddLast(list, (void*)(size_t)6))
|
|
|
|
return -1;
|
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))
|
|
|
|
{
|
2021-07-28 17:20:32 +03:00
|
|
|
printf("\t%p\n", LinkedList_Enumerator_Current(list));
|
2013-08-06 01:29:14 +04:00
|
|
|
}
|
|
|
|
|
2017-02-16 15:17:49 +03:00
|
|
|
printf("\n");
|
2021-07-28 17:20:32 +03:00
|
|
|
printf("LinkedList First: %p Last: %p\n", LinkedList_First(list), LinkedList_Last(list));
|
|
|
|
if (!LinkedList_Remove(list, (void*)(size_t)5))
|
|
|
|
return -1;
|
2013-08-06 01:29:14 +04:00
|
|
|
LinkedList_Enumerator_Reset(list);
|
|
|
|
|
|
|
|
while (LinkedList_Enumerator_MoveNext(list))
|
|
|
|
{
|
2021-07-28 17:20:32 +03:00
|
|
|
printf("\t%p\n", LinkedList_Enumerator_Current(list));
|
2013-08-06 01:29:14 +04:00
|
|
|
}
|
|
|
|
|
2017-02-16 15:17:49 +03:00
|
|
|
printf("\n");
|
2021-07-28 17:20:32 +03:00
|
|
|
printf("LinkedList First: %p Last: %p\n", LinkedList_First(list), 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();
|
2021-07-28 17:20:32 +03:00
|
|
|
if (!list)
|
|
|
|
return -1;
|
2014-09-24 15:03:46 +04:00
|
|
|
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))
|
|
|
|
{
|
2021-07-28 17:20:32 +03:00
|
|
|
printf("\terror: %p\n", 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();
|
2021-07-28 17:20:32 +03:00
|
|
|
if (!list)
|
|
|
|
return -1;
|
|
|
|
if (!LinkedList_AddFirst(list, (void*)(size_t)4))
|
|
|
|
return -1;
|
|
|
|
if (!LinkedList_AddLast(list, (void*)(size_t)5))
|
|
|
|
return -1;
|
|
|
|
if (!LinkedList_AddLast(list, (void*)(size_t)6))
|
|
|
|
return -1;
|
2017-02-16 15:17:49 +03:00
|
|
|
|
2014-09-24 15:03:46 +04:00
|
|
|
while (LinkedList_Enumerator_MoveNext(list))
|
|
|
|
{
|
2021-07-28 17:20:32 +03:00
|
|
|
printf("\t%p\n", 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;
|
|
|
|
}
|