summaryrefslogtreecommitdiff
path: root/tools/tests/test-pem.c
diff options
context:
space:
mode:
authorStef Walter <stefw@gnome.org>2013-04-05 23:52:39 +0200
committerStef Walter <stefw@gnome.org>2013-05-21 11:31:09 +0200
commitdcabaf1d56d410ba7ddb3dfbab9011bbbea5e6bc (patch)
treec49effa4a0696dc00fb591d95dc59e8579a8d030 /tools/tests/test-pem.c
parent7fd6d89d92b6f1b543bf2aa4b2e578201dad7147 (diff)
Our own unit testing framework
* Support the TAP protocol * Much cleaner without having to carry around state * First class support for setup/teardown * Port the common tests * Wait on porting other tests until we've merged outstanding code
Diffstat (limited to 'tools/tests/test-pem.c')
-rw-r--r--tools/tests/test-pem.c96
1 files changed, 33 insertions, 63 deletions
diff --git a/tools/tests/test-pem.c b/tools/tests/test-pem.c
index 4024bac..c74d0df 100644
--- a/tools/tests/test-pem.c
+++ b/tools/tests/test-pem.c
@@ -35,7 +35,8 @@
#define P11_KIT_DISABLE_DEPRECATED
#include "config.h"
-#include "CuTest.h"
+#include "test.h"
+#include "test-tools.h"
#include "attrs.h"
#include "compat.h"
@@ -48,7 +49,6 @@
#include "pkcs11.h"
#include "pkcs11x.h"
#include "oid.h"
-#include "test.h"
#include <assert.h>
#include <stdio.h>
@@ -64,14 +64,14 @@ struct {
} test;
static void
-setup (CuTest *tc)
+setup (void *unused)
{
CK_RV rv;
mock_module_reset ();
memcpy (&test.module, &mock_module, sizeof (CK_FUNCTION_LIST));
rv = test.module.C_Initialize (NULL);
- CuAssertIntEquals (tc, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
test.iter = p11_kit_iter_new (NULL);
@@ -83,7 +83,7 @@ setup (CuTest *tc)
}
static void
-teardown (CuTest *tc)
+teardown (void *unused)
{
CK_RV rv;
@@ -95,7 +95,7 @@ teardown (CuTest *tc)
p11_kit_iter_free (test.iter);
rv = test.module.C_Finalize (NULL);
- CuAssertIntEquals (tc, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
}
static CK_OBJECT_CLASS certificate_class = CKO_CERTIFICATE;
@@ -117,12 +117,10 @@ static CK_ATTRIBUTE certificate_filter[] = {
};
static void
-test_file (CuTest *tc)
+test_file (void)
{
bool ret;
- setup (tc);
-
mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_authority_attrs);
p11_kit_iter_add_callback (test.iter, p11_extract_info_load_filter, &test.ex, NULL);
@@ -133,21 +131,18 @@ test_file (CuTest *tc)
assert_not_reached ();
ret = p11_extract_pem_bundle (test.iter, &test.ex);
- CuAssertIntEquals (tc, true, ret);
+ assert_num_eq (true, ret);
- test_check_file (tc, test.directory, "extract.pem", SRCDIR "/files/cacert3.pem");
+ test_check_file (test.directory, "extract.pem", SRCDIR "/files/cacert3.pem");
free (test.ex.destination);
- teardown (tc);
}
static void
-test_file_multiple (CuTest *tc)
+test_file_multiple (void)
{
bool ret;
- setup (tc);
-
mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_authority_attrs);
mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_authority_attrs);
@@ -159,21 +154,18 @@ test_file_multiple (CuTest *tc)
assert_not_reached ();
ret = p11_extract_pem_bundle (test.iter, &test.ex);
- CuAssertIntEquals (tc, true, ret);
+ assert_num_eq (true, ret);
- test_check_file (tc, test.directory, "extract.pem", SRCDIR "/files/cacert3-twice.pem");
+ test_check_file (test.directory, "extract.pem", SRCDIR "/files/cacert3-twice.pem");
free (test.ex.destination);
- teardown (tc);
}
static void
-test_file_without (CuTest *tc)
+test_file_without (void)
{
bool ret;
- setup (tc);
-
p11_kit_iter_add_callback (test.iter, p11_extract_info_load_filter, &test.ex, NULL);
p11_kit_iter_add_filter (test.iter, certificate_filter, 1);
p11_kit_iter_begin_with (test.iter, &test.module, 0, 0);
@@ -182,21 +174,18 @@ test_file_without (CuTest *tc)
assert_not_reached ();
ret = p11_extract_pem_bundle (test.iter, &test.ex);
- CuAssertIntEquals (tc, true, ret);
+ assert_num_eq (true, ret);
- test_check_data (tc, test.directory, "extract.pem", "", 0);
+ test_check_data (test.directory, "extract.pem", "", 0);
free (test.ex.destination);
- teardown (tc);
}
static void
-test_directory (CuTest *tc)
+test_directory (void)
{
bool ret;
- setup (tc);
-
mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_authority_attrs);
mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_authority_attrs);
@@ -210,22 +199,18 @@ test_directory (CuTest *tc)
test.ex.destination = test.directory;
ret = p11_extract_pem_directory (test.iter, &test.ex);
- CuAssertIntEquals (tc, true, ret);
+ assert_num_eq (true, ret);
- test_check_directory (tc, test.directory, ("Cacert3_Here.pem", "Cacert3_Here.1.pem", NULL));
- test_check_file (tc, test.directory, "Cacert3_Here.pem", SRCDIR "/files/cacert3.pem");
- test_check_file (tc, test.directory, "Cacert3_Here.1.pem", SRCDIR "/files/cacert3.pem");
-
- teardown (tc);
+ test_check_directory (test.directory, ("Cacert3_Here.pem", "Cacert3_Here.1.pem", NULL));
+ test_check_file (test.directory, "Cacert3_Here.pem", SRCDIR "/files/cacert3.pem");
+ test_check_file (test.directory, "Cacert3_Here.1.pem", SRCDIR "/files/cacert3.pem");
}
static void
-test_directory_empty (CuTest *tc)
+test_directory_empty (void)
{
bool ret;
- setup (tc);
-
p11_kit_iter_add_callback (test.iter, p11_extract_info_load_filter, &test.ex, NULL);
p11_kit_iter_add_filter (test.iter, certificate_filter, 1);
p11_kit_iter_begin_with (test.iter, &test.module, 0, 0);
@@ -236,37 +221,22 @@ test_directory_empty (CuTest *tc)
test.ex.destination = test.directory;
ret = p11_extract_pem_directory (test.iter, &test.ex);
- CuAssertIntEquals (tc, true, ret);
-
- test_check_directory (tc, test.directory, (NULL, NULL));
+ assert_num_eq (true, ret);
- teardown (tc);
+ test_check_directory (test.directory, (NULL, NULL));
}
int
-main (void)
+main (int argc,
+ char *argv[])
{
- CuString *output = CuStringNew ();
- CuSuite* suite = CuSuiteNew ();
- int ret;
-
- putenv ("P11_KIT_STRICT=1");
mock_module_init ();
- p11_debug_init ();
-
- SUITE_ADD_TEST (suite, test_file);
- SUITE_ADD_TEST (suite, test_file_multiple);
- SUITE_ADD_TEST (suite, test_file_without);
- SUITE_ADD_TEST (suite, test_directory);
- SUITE_ADD_TEST (suite, test_directory_empty);
-
- 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_file, "/pem/test_file");
+ p11_test (test_file_multiple, "/pem/test_file_multiple");
+ p11_test (test_file_without, "/pem/test_file_without");
+ p11_test (test_directory, "/pem/test_directory");
+ p11_test (test_directory_empty, "/pem/test_directory_empty");
+ return p11_test_run (argc, argv);
}