linked-list: Don't require an argument for the item when enumerating
authorTobias Brunner <tobias@strongswan.org>
Tue, 16 Jul 2013 12:46:43 +0000 (14:46 +0200)
committerTobias Brunner <tobias@strongswan.org>
Wed, 17 Jul 2013 15:42:53 +0000 (17:42 +0200)
src/libstrongswan/collections/linked_list.c
src/libstrongswan/tests/test_linked_list_enumerator.c

index 274ad8e..dbbc2a9 100644 (file)
@@ -138,7 +138,10 @@ METHOD(enumerator_t, enumerate, bool,
                this->finished = TRUE;
                return FALSE;
        }
-       *item = this->current->value;
+       if (item)
+       {
+               *item = this->current->value;
+       }
        return TRUE;
 }
 
index 840e384..93d814b 100644 (file)
@@ -59,6 +59,22 @@ START_TEST(test_enumerate)
 }
 END_TEST
 
+START_TEST(test_enumerate_null)
+{
+       enumerator_t *enumerator;
+       int round;
+
+       round = 1;
+       enumerator = list->create_enumerator(list);
+       while (enumerator->enumerate(enumerator, NULL))
+       {
+               round++;
+       }
+       ck_assert_int_eq(round, 6);
+       enumerator->destroy(enumerator);
+}
+END_TEST
+
 START_TEST(test_reset_enumerator)
 {
        enumerator_t *enumerator;
@@ -364,6 +380,7 @@ Suite *linked_list_enumerator_suite_create()
        tc = tcase_create("enumerate");
        tcase_add_checked_fixture(tc, setup_list, teardown_list);
        tcase_add_test(tc, test_enumerate);
+       tcase_add_test(tc, test_enumerate_null);
        tcase_add_test(tc, test_reset_enumerator);
        tcase_add_test(tc, test_has_more_empty);
        tcase_add_test(tc, test_has_more);