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;
|
|
|
|
int number;
|
|
|
|
wLinkedList* list;
|
|
|
|
|
|
|
|
list = LinkedList_New();
|
|
|
|
|
|
|
|
LinkedList_AddFirst(list, (void*) (size_t) 1);
|
|
|
|
LinkedList_AddLast(list, (void*) (size_t) 2);
|
|
|
|
LinkedList_AddLast(list, (void*) (size_t) 3);
|
|
|
|
|
|
|
|
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))
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
printf("\t%"PRIuz"\n", (size_t) LinkedList_Enumerator_Current(list));
|
2013-08-06 01:29:14 +04:00
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
|
2016-12-14 00:47:08 +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))
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
printf("\t%"PRIuz"\n", (size_t) LinkedList_Enumerator_Current(list));
|
2013-08-06 01:29:14 +04:00
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
|
2016-12-14 00:47:08 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
LinkedList_AddFirst(list, (void*) (size_t) 4);
|
|
|
|
LinkedList_AddLast(list, (void*) (size_t) 5);
|
|
|
|
LinkedList_AddLast(list, (void*) (size_t) 6);
|
|
|
|
|
|
|
|
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))
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
printf("\t%"PRIuz"\n", (size_t) LinkedList_Enumerator_Current(list));
|
2013-08-06 01:29:14 +04:00
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
|
2016-12-14 00:47:08 +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_Remove(list, (void*) (size_t) 5);
|
|
|
|
|
|
|
|
LinkedList_Enumerator_Reset(list);
|
|
|
|
|
|
|
|
while (LinkedList_Enumerator_MoveNext(list))
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
printf("\t%"PRIuz"\n", (size_t) LinkedList_Enumerator_Current(list));
|
2013-08-06 01:29:14 +04:00
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
|
2016-12-14 00:47:08 +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);
|
|
|
|
while (LinkedList_Enumerator_MoveNext(list))
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
printf("\terror: %"PRIuz"\n", (size_t) LinkedList_Enumerator_Current(list));
|
2014-09-24 15:03:46 +04:00
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
LinkedList_Free(list);
|
|
|
|
|
|
|
|
/* Use an enumerator without reset */
|
|
|
|
list = LinkedList_New();
|
|
|
|
LinkedList_AddFirst(list, (void*) (size_t) 4);
|
|
|
|
LinkedList_AddLast(list, (void*) (size_t) 5);
|
|
|
|
LinkedList_AddLast(list, (void*) (size_t) 6);
|
|
|
|
while (LinkedList_Enumerator_MoveNext(list))
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
printf("\t%"PRIuz"\n", (size_t) LinkedList_Enumerator_Current(list));
|
2014-09-24 15:03:46 +04:00
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
LinkedList_Free(list);
|
|
|
|
|
|
|
|
|
2013-08-06 01:29:14 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|