diff options
Diffstat (limited to 'trust/tests/test-index.c')
-rw-r--r-- | trust/tests/test-index.c | 395 |
1 files changed, 168 insertions, 227 deletions
diff --git a/trust/tests/test-index.c b/trust/tests/test-index.c index 8405061..85c44b7 100644 --- a/trust/tests/test-index.c +++ b/trust/tests/test-index.c @@ -33,8 +33,10 @@ */ #include "config.h" -#include "CuTest.h" +#include "test.h" +#include "test-trust.h" +#include <stdarg.h> #include <stdlib.h> #include <stdio.h> #include <string.h> @@ -44,28 +46,26 @@ #include "index.h" #include "message.h" -#include "test-data.h" - struct { p11_index *index; } test; static void -setup (CuTest *cu) +setup (void *unused) { test.index = p11_index_new (NULL, NULL, NULL); - CuAssertPtrNotNull (cu, test.index); + assert_ptr_not_null (test.index); } static void -teardown (CuTest *cu) +teardown (void *unused) { p11_index_free (test.index); memset (&test, 0, sizeof (test)); } static void -test_take_lookup (CuTest *cu) +test_take_lookup (void) { CK_ATTRIBUTE original[] = { { CKA_LABEL, "yay", 3 }, @@ -78,26 +78,22 @@ test_take_lookup (CuTest *cu) CK_OBJECT_HANDLE handle; CK_RV rv; - setup (cu); - attrs = p11_attrs_dup (original); rv = p11_index_take (test.index, attrs, &handle); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); check = p11_index_lookup (test.index, handle); - test_check_attrs (cu, original, check); + test_check_attrs (original, check); check = p11_index_lookup (test.index, 1UL); - CuAssertPtrEquals (cu, NULL, check); + assert_ptr_eq (NULL, check); check = p11_index_lookup (test.index, 0UL); - CuAssertPtrEquals (cu, NULL, check); - - teardown (cu); + assert_ptr_eq (NULL, check); } static void -test_add_lookup (CuTest *cu) +test_add_lookup (void) { CK_ATTRIBUTE original[] = { { CKA_LABEL, "yay", 3 }, @@ -109,19 +105,15 @@ test_add_lookup (CuTest *cu) CK_OBJECT_HANDLE handle; CK_RV rv; - setup (cu); - rv = p11_index_add (test.index, original, 2, &handle); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); check = p11_index_lookup (test.index, handle); - test_check_attrs (cu, original, check); - - teardown (cu); + test_check_attrs (original, check); } static void -test_size (CuTest *cu) +test_size (void) { static CK_ATTRIBUTE original[] = { { CKA_LABEL, "yay", 3 }, @@ -131,20 +123,16 @@ test_size (CuTest *cu) CK_RV rv; - setup (cu); - rv = p11_index_add (test.index, original, 2, NULL); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); rv = p11_index_add (test.index, original, 2, NULL); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); rv = p11_index_add (test.index, original, 2, NULL); - CuAssertTrue (cu, rv == CKR_OK); - - CuAssertIntEquals (cu, 3, p11_index_size (test.index)); + assert (rv == CKR_OK); - teardown (cu); + assert_num_eq (3, p11_index_size (test.index)); } static int @@ -162,7 +150,7 @@ compar_ulong (const void *one, } static void -test_snapshot (CuTest *cu) +test_snapshot (void) { CK_ATTRIBUTE original[] = { { CKA_LABEL, "yay", 3 }, @@ -175,29 +163,26 @@ test_snapshot (CuTest *cu) CK_OBJECT_HANDLE *snapshot; int i; - setup (cu); - for (i = 0; i < NUM; i++) p11_index_add (test.index, original, 2, expected + i); snapshot = p11_index_snapshot (test.index, NULL, NULL, 0); - CuAssertPtrNotNull (cu, snapshot); + assert_ptr_not_null (snapshot); for (i = 0; i < NUM; i++) - CuAssertTrue (cu, snapshot[i] != 0); - CuAssertTrue (cu, snapshot[NUM] == 0); + assert (snapshot[i] != 0); + assert (snapshot[NUM] == 0); qsort (snapshot, NUM, sizeof (CK_OBJECT_HANDLE), compar_ulong); for (i = 0; i < NUM; i++) - CuAssertIntEquals (cu, expected[i], snapshot[i]); + assert_num_eq (expected[i], snapshot[i]); free (snapshot); - teardown (cu); } static void -test_snapshot_base (CuTest *cu) +test_snapshot_base (void) { CK_ATTRIBUTE original[] = { { CKA_LABEL, "yay", 3 }, @@ -211,31 +196,28 @@ test_snapshot_base (CuTest *cu) CK_RV rv; int i; - setup (cu); - for (i = 0; i < NUM; i++) { rv = p11_index_add (test.index, original, 2, expected + i); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); } snapshot = p11_index_snapshot (test.index, test.index, NULL, 0); - CuAssertPtrNotNull (cu, snapshot); + assert_ptr_not_null (snapshot); for (i = 0; i < NUM * 2; i++) - CuAssertTrue (cu, snapshot[i] != 0); - CuAssertTrue (cu, snapshot[NUM * 2] == 0); + assert (snapshot[i] != 0); + assert (snapshot[NUM * 2] == 0); qsort (snapshot, NUM * 2, sizeof (CK_OBJECT_HANDLE), compar_ulong); for (i = 0; i < NUM * 2; i++) - CuAssertIntEquals (cu, expected[i / 2], snapshot[i]); + assert_num_eq (expected[i / 2], snapshot[i]); free (snapshot); - teardown (cu); } static void -test_remove (CuTest *cu) +test_remove (void) { CK_ATTRIBUTE original[] = { { CKA_LABEL, "yay", 3 }, @@ -248,29 +230,25 @@ test_remove (CuTest *cu) CK_OBJECT_HANDLE handle; CK_RV rv; - setup (cu); - attrs = p11_attrs_dup (original); rv = p11_index_take (test.index, attrs, &handle); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); check = p11_index_lookup (test.index, handle); - CuAssertPtrEquals (cu, attrs, check); + assert_ptr_eq (attrs, check); rv = p11_index_remove (test.index, 1UL); - CuAssertTrue (cu, rv == CKR_OBJECT_HANDLE_INVALID); + assert (rv == CKR_OBJECT_HANDLE_INVALID); rv = p11_index_remove (test.index, handle); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); check = p11_index_lookup (test.index, handle); - CuAssertPtrEquals (cu, NULL, check); - - teardown (cu); + assert_ptr_eq (NULL, check); } static void -test_set (CuTest *cu) +test_set (void) { CK_ATTRIBUTE original[] = { { CKA_LABEL, "yay", 3 }, @@ -291,29 +269,25 @@ test_set (CuTest *cu) CK_OBJECT_HANDLE handle; CK_RV rv; - setup (cu); - attrs = p11_attrs_dup (original); rv = p11_index_take (test.index, attrs, &handle); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); check = p11_index_lookup (test.index, handle); - test_check_attrs (cu, original, check); + test_check_attrs (original, check); rv = p11_index_set (test.index, handle, &change, 1); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); check = p11_index_lookup (test.index, handle); - test_check_attrs (cu, changed, check); + test_check_attrs (changed, check); rv = p11_index_set (test.index, 1UL, &change, 1); - CuAssertTrue (cu, rv == CKR_OBJECT_HANDLE_INVALID); - - teardown (cu); + assert (rv == CKR_OBJECT_HANDLE_INVALID); } static void -test_update (CuTest *cu) +test_update (void) { CK_ATTRIBUTE original[] = { { CKA_LABEL, "yay", 3 }, @@ -334,31 +308,27 @@ test_update (CuTest *cu) CK_OBJECT_HANDLE handle; CK_RV rv; - setup (cu); - attrs = p11_attrs_dup (original); rv = p11_index_take (test.index, attrs, &handle); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); check = p11_index_lookup (test.index, handle); - test_check_attrs (cu, original, check); + test_check_attrs (original, check); attrs = p11_attrs_build (NULL, &change, NULL); rv = p11_index_update (test.index, handle, attrs); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); check = p11_index_lookup (test.index, handle); - test_check_attrs (cu, changed, check); + test_check_attrs (changed, check); attrs = p11_attrs_build (NULL, &change, NULL); rv = p11_index_update (test.index, 1L, attrs); - CuAssertTrue (cu, rv == CKR_OBJECT_HANDLE_INVALID); - - teardown (cu); + assert (rv == CKR_OBJECT_HANDLE_INVALID); } static void -test_find (CuTest *tc) +test_find (void) { CK_ATTRIBUTE first[] = { { CKA_LABEL, "yay", 3 }, @@ -399,31 +369,27 @@ test_find (CuTest *tc) CK_OBJECT_HANDLE two; CK_OBJECT_HANDLE three; - setup (tc); - p11_index_add (test.index, first, 2, &one); p11_index_add (test.index, second, 2, &two); p11_index_add (test.index, third, 2, &three); check = p11_index_find (test.index, match3, -1); - CuAssertIntEquals (tc, three, check); + assert_num_eq (three, check); check = p11_index_find (test.index, match3, 1); - CuAssertIntEquals (tc, three, check); + assert_num_eq (three, check); check = p11_index_find (test.index, match_any, -1); - CuAssertTrue (tc, check == one || check == two || check == three); + assert (check == one || check == two || check == three); check = p11_index_find (test.index, match_any, 1); - CuAssertTrue (tc, check == one || check == two || check == three); + assert (check == one || check == two || check == three); check = p11_index_find (test.index, match_none, -1); - CuAssertIntEquals (tc, 0, check); + assert_num_eq (0, check); check = p11_index_find (test.index, match_none, 2); - CuAssertIntEquals (tc, 0, check); - - teardown (tc); + assert_num_eq (0, check); } static bool @@ -464,7 +430,7 @@ handles_are (CK_OBJECT_HANDLE *handles, } static void -test_find_all (CuTest *tc) +test_find_all (void) { CK_ATTRIBUTE first[] = { { CKA_LABEL, "odd", 3 }, @@ -513,44 +479,40 @@ test_find_all (CuTest *tc) CK_OBJECT_HANDLE two; CK_OBJECT_HANDLE three; - setup (tc); - p11_index_add (test.index, first, 3, &one); p11_index_add (test.index, second, 3, &two); p11_index_add (test.index, third, 3, &three); check = p11_index_find_all (test.index, match_3, -1); - CuAssertTrue (tc, handles_are (check, three, 0UL)); + assert (handles_are (check, three, 0UL)); free (check); check = p11_index_find_all (test.index, match_none, -1); - CuAssertTrue (tc, handles_are (check, 0UL)); + assert (handles_are (check, 0UL)); free (check); check = p11_index_find_all (test.index, match_odd, -1); - CuAssertTrue (tc, handles_are (check, one, three, 0UL)); + assert (handles_are (check, one, three, 0UL)); free (check); check = p11_index_find_all (test.index, match_any, -1); - CuAssertTrue (tc, handles_are (check, one, two, three, 0UL)); + assert (handles_are (check, one, two, three, 0UL)); free (check); check = p11_index_find_all (test.index, match_none, -1); - CuAssertPtrNotNull (tc, check); - CuAssertIntEquals (tc, 0, check[0]); + assert_ptr_not_null (check); + assert_num_eq (0, check[0]); free (check); /* A double check of this method */ one = 0UL; check = &one; - CuAssertTrue (tc, !handles_are (check, 29292929, 0UL)); - CuAssertTrue (tc, !handles_are (NULL, 0UL)); - - teardown (tc); + assert (!handles_are (check, 29292929, 0UL)); + assert (!handles_are (NULL, 0UL)); } static void -test_find_realloc (CuTest *tc) +test_find_realloc (void) { CK_ATTRIBUTE attrs[] = { { CKA_LABEL, "odd", 3 }, @@ -566,24 +528,21 @@ test_find_realloc (CuTest *tc) CK_OBJECT_HANDLE *check; int i; - setup (tc); - for (i = 0; i < 1000; i++) p11_index_add (test.index, attrs, 3, NULL); check = p11_index_find_all (test.index, match, -1); - CuAssertPtrNotNull (tc, check); + assert_ptr_not_null (check); for (i = 0; i < 1000; i++) - CuAssertTrue (tc, check[i] != 0); - CuAssertIntEquals (tc, 0, check[1000]); + assert (check[i] != 0); + assert_num_eq (0, check[1000]); free (check); - teardown (tc); } static void -test_replace_all (CuTest *tc) +test_replace_all (void) { CK_ATTRIBUTE first[] = { { CKA_LABEL, "odd", 3 }, @@ -647,16 +606,14 @@ test_replace_all (CuTest *tc) p11_array *array; CK_RV rv; - setup (tc); - p11_index_add (test.index, first, 3, &one); - CuAssertTrue (tc, one != 0); + assert (one != 0); p11_index_add (test.index, second, 3, &two); - CuAssertTrue (tc, two != 0); + assert (two != 0); p11_index_add (test.index, third, 3, &three); - CuAssertTrue (tc, three != 0); + assert (three != 0); p11_index_add (test.index, fifth, 3, &five); - CuAssertTrue (tc, five != 0); + assert (five != 0); array = p11_array_new (p11_attrs_free); p11_array_push (array, p11_attrs_buildn (NULL, eins, 3)); @@ -664,38 +621,36 @@ test_replace_all (CuTest *tc) p11_array_push (array, p11_attrs_buildn (NULL, neun, 3)); rv = p11_index_replace_all (test.index, match, CKA_VALUE, array); - CuAssertTrue (tc, rv == CKR_OK); + assert (rv == CKR_OK); - CuAssertIntEquals (tc, 0, array->num); + assert_num_eq (0, array->num); p11_array_free (array); /* eins should have replaced one */ check = p11_index_find (test.index, eins, -1); - CuAssertIntEquals (tc, one, check); + assert_num_eq (one, check); /* two should still be around */ check = p11_index_find (test.index, second, -1); - CuAssertIntEquals (tc, two, check); + assert_num_eq (two, check); /* three should have been removed */ check = p11_index_find (test.index, third, -1); - CuAssertIntEquals (tc, 0, check); + assert_num_eq (0, check); /* five should have been removed */ check = p11_index_find (test.index, fifth, -1); - CuAssertIntEquals (tc, 0, check); + assert_num_eq (0, check); /* sieben should have been added */ check = p11_index_find (test.index, sieben, -1); - CuAssertTrue (tc, check != one && check != two && check != three && check != five); + assert (check != one && check != two && check != three && check != five); /* neun should have been added */ check = p11_index_find (test.index, neun, -1); - CuAssertTrue (tc, check != one && check != two && check != three && check != five); - - CuAssertIntEquals (tc, 4, p11_index_size (test.index)); + assert (check != one && check != two && check != three && check != five); - teardown (tc); + assert_num_eq (4, p11_index_size (test.index)); } @@ -705,17 +660,16 @@ on_build_populate (void *data, CK_ATTRIBUTE **attrs, CK_ATTRIBUTE *merge) { - CuTest *cu = data; - CK_ATTRIBUTE override[] = { { CKA_APPLICATION, "vigorous", 8 }, { CKA_LABEL, "naay", 4 }, { CKA_INVALID }, }; - CuAssertPtrNotNull (cu, index); - CuAssertPtrNotNull (cu, attrs); - CuAssertPtrNotNull (cu, merge); + assert_str_eq (data, "blah"); + assert_ptr_not_null (index); + assert_ptr_not_null (attrs); + assert_ptr_not_null (merge); *attrs = p11_attrs_merge (*attrs, merge, true); *attrs = p11_attrs_merge (*attrs, p11_attrs_dup (override), true); @@ -723,7 +677,7 @@ on_build_populate (void *data, } static void -test_build_populate (CuTest *cu) +test_build_populate (void) { CK_ATTRIBUTE original[] = { { CKA_LABEL, "yay", 3 }, @@ -744,24 +698,24 @@ test_build_populate (CuTest *cu) p11_index *index; CK_RV rv; - index = p11_index_new (on_build_populate, NULL, cu); - CuAssertPtrNotNull (cu, index); + index = p11_index_new (on_build_populate, NULL, "blah"); + assert_ptr_not_null (index); rv = p11_index_add (index, original, 2, &handle); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); check = p11_index_lookup (index, handle); - CuAssertPtrNotNull (cu, check); + assert_ptr_not_null (check); - test_check_attrs (cu, after, check); + test_check_attrs (after, check); rv = p11_index_set (index, handle, original, 2); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); check = p11_index_lookup (index, handle); - CuAssertPtrNotNull (cu, check); + assert_ptr_not_null (check); - test_check_attrs (cu, after, check); + test_check_attrs (after, check); p11_index_free (index); } @@ -772,14 +726,13 @@ on_build_fail (void *data, CK_ATTRIBUTE **attrs, CK_ATTRIBUTE *merge) { - CuTest *cu = data; - CK_ATTRIBUTE check[] = { { CKA_LABEL, "nay", 3 }, { CKA_INVALID } }; - CuAssertPtrNotNull (cu, merge); + assert_str_eq (data, "testo"); + assert_ptr_not_null (merge); if (p11_attrs_match (merge, check)) return CKR_DEVICE_ERROR; @@ -790,7 +743,7 @@ on_build_fail (void *data, static void -test_build_fail (CuTest *cu) +test_build_fail (void) { CK_ATTRIBUTE okay[] = { { CKA_LABEL, "yay", 3 }, @@ -808,20 +761,20 @@ test_build_fail (CuTest *cu) p11_index *index; CK_RV rv; - index = p11_index_new (on_build_fail, NULL, cu); - CuAssertPtrNotNull (cu, index); + index = p11_index_new (on_build_fail, NULL, "testo"); + assert_ptr_not_null (index); rv = p11_index_add (index, okay, 2, &handle); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); rv = p11_index_add (index, fails, 2, NULL); - CuAssertTrue (cu, rv == CKR_DEVICE_ERROR); + assert (rv == CKR_DEVICE_ERROR); rv = p11_index_set (index, handle, fails, 2); - CuAssertTrue (cu, rv == CKR_DEVICE_ERROR); + assert (rv == CKR_DEVICE_ERROR); rv = p11_index_set (index, handle, okay, 2); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); p11_index_free (index); } @@ -836,8 +789,6 @@ on_change_check (void *data, CK_OBJECT_HANDLE handle, CK_ATTRIBUTE *attrs) { - CuTest *cu = data; - CK_ATTRIBUTE check[] = { { CKA_LABEL, "yay", 3 }, { CKA_VALUE, "eight", 5 }, @@ -845,22 +796,23 @@ on_change_check (void *data, }; - CuAssertPtrNotNull (cu, index); - CuAssertPtrNotNull (cu, attrs); + assert_str_eq (data, "change-check"); + assert_ptr_not_null (index); + assert_ptr_not_null (attrs); if (!on_change_batching) { if (on_change_removing) - CuAssertIntEquals (cu, 0, handle); + assert_num_eq (0, handle); else - CuAssertTrue (cu, handle != 0); + assert (handle != 0); } - test_check_attrs (cu, check, attrs); + test_check_attrs (check, attrs); on_change_called++; } static void -test_change_called (CuTest *cu) +test_change_called (void) { CK_ATTRIBUTE original[] = { { CKA_LABEL, "yay", 3 }, @@ -873,39 +825,39 @@ test_change_called (CuTest *cu) p11_index *index; CK_RV rv; - index = p11_index_new (NULL, on_change_check, cu); - CuAssertPtrNotNull (cu, index); + index = p11_index_new (NULL, on_change_check, "change-check"); + assert_ptr_not_null (index); on_change_removing = false; on_change_called = 0; rv = p11_index_add (index, original, 2, NULL); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); - CuAssertIntEquals (cu, 1, on_change_called); + assert_num_eq (1, on_change_called); rv = p11_index_add (index, original, 2, NULL); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); - CuAssertIntEquals (cu, 2, on_change_called); + assert_num_eq (2, on_change_called); rv = p11_index_add (index, original, 2, &handle); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); - CuAssertIntEquals (cu, 3, on_change_called); + assert_num_eq (3, on_change_called); on_change_removing = true; rv = p11_index_remove (index, handle); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); - CuAssertIntEquals (cu, 4, on_change_called); + assert_num_eq (4, on_change_called); p11_index_free (index); } static void -test_change_batch (CuTest *cu) +test_change_batch (void) { CK_ATTRIBUTE original[] = { { CKA_LABEL, "yay", 3 }, @@ -918,38 +870,38 @@ test_change_batch (CuTest *cu) p11_index *index; CK_RV rv; - index = p11_index_new (NULL, on_change_check, cu); - CuAssertPtrNotNull (cu, index); + index = p11_index_new (NULL, on_change_check, "change-check"); + assert_ptr_not_null (index); on_change_batching = true; on_change_called = 0; p11_index_batch (index); - CuAssertTrue (cu, p11_index_in_batch (index)); + assert (p11_index_in_batch (index)); rv = p11_index_add (index, original, 2, NULL); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); - CuAssertIntEquals (cu, 0, on_change_called); + assert_num_eq (0, on_change_called); rv = p11_index_add (index, original, 2, NULL); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); - CuAssertIntEquals (cu, 0, on_change_called); + assert_num_eq (0, on_change_called); rv = p11_index_add (index, original, 2, &handle); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); - CuAssertIntEquals (cu, 0, on_change_called); + assert_num_eq (0, on_change_called); /* Nested batch is a noop */ p11_index_batch (index); rv = p11_index_remove (index, handle); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); - CuAssertIntEquals (cu, 0, on_change_called); + assert_num_eq (0, on_change_called); /* * Batch finishes when first finish call is called, @@ -957,18 +909,18 @@ test_change_batch (CuTest *cu) */ p11_index_finish (index); - CuAssertTrue (cu, !p11_index_in_batch (index)); + assert (!p11_index_in_batch (index)); /* * Only three calls, because later operations on the * same handle override the earlier one. */ - CuAssertIntEquals (cu, 3, on_change_called); + assert_num_eq (3, on_change_called); /* This is a noop */ p11_index_finish (index); - CuAssertTrue (cu, !p11_index_in_batch (index)); + assert (!p11_index_in_batch (index)); p11_index_free (index); } @@ -979,7 +931,6 @@ on_change_nested (void *data, CK_OBJECT_HANDLE handle, CK_ATTRIBUTE *attrs) { - CuTest *cu = data; CK_RV rv; CK_ATTRIBUTE second[] = { @@ -989,15 +940,16 @@ on_change_nested (void *data, }; + assert_str_eq (data, "change-nested"); on_change_called++; /* A nested call */ rv = p11_index_add (index, second, 2, NULL); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); } static void -test_change_nested (CuTest *cu) +test_change_nested (void) { CK_ATTRIBUTE original[] = { { CKA_LABEL, "yay", 3 }, @@ -1009,61 +961,50 @@ test_change_nested (CuTest *cu) p11_index *index; CK_RV rv; - index = p11_index_new (NULL, on_change_nested, cu); - CuAssertPtrNotNull (cu, index); + index = p11_index_new (NULL, on_change_nested, "change-nested"); + assert_ptr_not_null (index); on_change_called = 0; rv = p11_index_add (index, original, 2, NULL); - CuAssertTrue (cu, rv == CKR_OK); - CuAssertIntEquals (cu, 1, on_change_called); + assert (rv == CKR_OK); + assert_num_eq (1, on_change_called); on_change_called = 0; p11_index_batch (index); rv = p11_index_add (index, original, 2, NULL); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); p11_index_finish (index); - CuAssertIntEquals (cu, 1, on_change_called); + assert_num_eq (1, on_change_called); p11_index_free (index); } int -main (void) +main (int argc, + char *argv[]) { - CuString *output = CuStringNew (); - CuSuite* suite = CuSuiteNew (); - int ret; - - putenv ("P11_KIT_STRICT=1"); - p11_debug_init (); p11_message_quiet (); - SUITE_ADD_TEST (suite, test_add_lookup); - SUITE_ADD_TEST (suite, test_take_lookup); - SUITE_ADD_TEST (suite, test_size); - SUITE_ADD_TEST (suite, test_remove); - SUITE_ADD_TEST (suite, test_snapshot); - SUITE_ADD_TEST (suite, test_snapshot_base); - SUITE_ADD_TEST (suite, test_set); - SUITE_ADD_TEST (suite, test_update); - SUITE_ADD_TEST (suite, test_find); - SUITE_ADD_TEST (suite, test_find_all); - SUITE_ADD_TEST (suite, test_find_realloc); - SUITE_ADD_TEST (suite, test_replace_all); - SUITE_ADD_TEST (suite, test_build_populate); - SUITE_ADD_TEST (suite, test_build_fail); - SUITE_ADD_TEST (suite, test_change_called); - SUITE_ADD_TEST (suite, test_change_batch); - SUITE_ADD_TEST (suite, test_change_nested); - - CuSuiteRun (suite); - CuSuiteSummary (suite, output); - CuSuiteDetails (suite, output); - printf ("%s\n", output->buffer); - ret = suite->failCount; - CuSuiteDelete (suite); - CuStringDelete (output); - - return ret; + p11_fixture (setup, teardown); + p11_test (test_add_lookup, "/index/add_lookup"); + p11_test (test_take_lookup, "/index/take_lookup"); + p11_test (test_size, "/index/size"); + p11_test (test_remove, "/index/remove"); + p11_test (test_snapshot, "/index/snapshot"); + p11_test (test_snapshot_base, "/index/snapshot_base"); + p11_test (test_set, "/index/set"); + p11_test (test_update, "/index/update"); + p11_test (test_find, "/index/find"); + p11_test (test_find_all, "/index/find_all"); + p11_test (test_find_realloc, "/index/find_realloc"); + p11_test (test_replace_all, "/index/replace_all"); + + p11_fixture (NULL, NULL); + p11_test (test_build_populate, "/index/build_populate"); + p11_test (test_build_fail, "/index/build_fail"); + p11_test (test_change_called, "/index/change_called"); + p11_test (test_change_batch, "/index/change_batch"); + p11_test (test_change_nested, "/index/change_nested"); + return p11_test_run (argc, argv); } |