From 5e4a3ea9b8f254d99544490eed8e17e88c81f975 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Fri, 18 Jan 2013 16:11:06 +0100 Subject: Add p11_array_clear() function * Clears an array without freeing the array itself --- common/tests/test-array.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'common/tests') diff --git a/common/tests/test-array.c b/common/tests/test-array.c index a52f3b5..a796365 100644 --- a/common/tests/test-array.c +++ b/common/tests/test-array.c @@ -167,6 +167,32 @@ test_p11_array_remove_and_count (CuTest *tc) p11_array_free (array); } +static void +test_p11_array_clear_destroys (CuTest *tc) +{ + p11_array *array; + int value = 0; + + array = p11_array_new (destroy_value); + if (!p11_array_push (array, &value)) + CuFail (tc, "should not be reached"); + + CuAssertIntEquals (tc, 1, array->num); + + p11_array_clear (array); + + CuAssertIntEquals (tc, 2, value); + CuAssertIntEquals (tc, 0, array->num); + + /* should not be destroyed again */ + value = 0; + + p11_array_free (array); + + CuAssertIntEquals (tc, 0, value); +} + + int main (void) { @@ -181,6 +207,7 @@ main (void) SUITE_ADD_TEST (suite, test_p11_array_remove_and_count); SUITE_ADD_TEST (suite, test_p11_array_free_null); SUITE_ADD_TEST (suite, test_p11_array_free_destroys); + SUITE_ADD_TEST (suite, test_p11_array_clear_destroys); CuSuiteRun (suite); CuSuiteSummary (suite, output); -- cgit v1.1