Merge pull request #2121 from bmiklautz/fix/linked_list

LinkedList Enumerator fixes
This commit is contained in:
Marc-André Moreau 2014-09-24 16:22:39 -04:00
commit eda6671b06
2 changed files with 28 additions and 1 deletions

View File

@ -306,7 +306,7 @@ BOOL LinkedList_Enumerator_MoveNext(wLinkedList* list)
{
if (list->initial)
list->initial = 0;
else
else if (list->current)
list->current = list->current->next;
if (!list->current)

View File

@ -109,6 +109,33 @@ int TestLinkedList(int argc, char* argv[])
LinkedList_Free(list);
/* Test enumerator robustness */
/* enumerator on an empty list */
list = LinkedList_New();
LinkedList_Enumerator_Reset(list);
while (LinkedList_Enumerator_MoveNext(list))
{
number = (int) (size_t) LinkedList_Enumerator_Current(list);
printf("\t%d\n", number);
}
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))
{
number = (int) (size_t) LinkedList_Enumerator_Current(list);
printf("\t%d\n", number);
}
printf("\n");
LinkedList_Free(list);
return 0;
}