diff options
author | Stef Walter <stefw@gnome.org> | 2013-01-18 16:11:06 +0100 |
---|---|---|
committer | Stef Walter <stefw@gnome.org> | 2013-02-05 14:54:53 +0100 |
commit | 5e4a3ea9b8f254d99544490eed8e17e88c81f975 (patch) | |
tree | 91043d4d317195cf2d80aa572cab75d22dbd8f5e /common/tests | |
parent | 4400d8ecc4525cfc848937dc562c542fc58a533a (diff) |
Add p11_array_clear() function
* Clears an array without freeing the array itself
Diffstat (limited to 'common/tests')
-rw-r--r-- | common/tests/test-array.c | 27 |
1 files changed, 27 insertions, 0 deletions
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); |