Merge pull request #2121 from bmiklautz/fix/linked_list
LinkedList Enumerator fixes
This commit is contained in:
commit
eda6671b06
@ -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)
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user