summaryrefslogtreecommitdiff
path: root/trust/tests/test-persist.c
diff options
context:
space:
mode:
Diffstat (limited to 'trust/tests/test-persist.c')
-rw-r--r--trust/tests/test-persist.c155
1 files changed, 72 insertions, 83 deletions
diff --git a/trust/tests/test-persist.c b/trust/tests/test-persist.c
index ee73331..defeecf 100644
--- a/trust/tests/test-persist.c
+++ b/trust/tests/test-persist.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>
@@ -48,10 +50,8 @@
#include "pkcs11.h"
#include "pkcs11x.h"
-#include "test-data.h"
-
static void
-test_magic (CuTest *tc)
+test_magic (void)
{
const char *input = "[p11-kit-object-v1]\n"
"class: data\n"
@@ -64,10 +64,10 @@ test_magic (CuTest *tc)
"value: \"blah\"\n"
"application: \"test-persist\"\n";
- CuAssertTrue (tc, p11_persist_magic ((unsigned char *)input, strlen (input)));
- CuAssertTrue (tc, !p11_persist_magic ((unsigned char *)input, 5));
- CuAssertTrue (tc, p11_persist_magic ((unsigned char *)other, strlen (other)));
- CuAssertTrue (tc, !p11_persist_magic ((unsigned char *)"blah", 4));
+ assert (p11_persist_magic ((unsigned char *)input, strlen (input)));
+ assert (!p11_persist_magic ((unsigned char *)input, 5));
+ assert (p11_persist_magic ((unsigned char *)other, strlen (other)));
+ assert (!p11_persist_magic ((unsigned char *)"blah", 4));
}
static p11_array *
@@ -94,9 +94,9 @@ args_to_array (void *arg,
}
static void
-check_read_msg (CuTest *tc,
- const char *file,
+check_read_msg (const char *file,
int line,
+ const char *function,
const char *input,
p11_array *expected)
{
@@ -108,14 +108,18 @@ check_read_msg (CuTest *tc,
objects = p11_array_new (p11_attrs_free);
if (p11_persist_read (persist, "test", (const unsigned char *)input, strlen (input), objects)) {
- CuAssert_Line (tc, file, line, "decoding should have failed", expected != NULL);
+ if (expected == NULL)
+ p11_test_fail (file, line, function, "decoding should have failed");
for (i = 0; i < expected->num; i++) {
- CuAssert_Line (tc, file, line, "too few objects read", i < objects->num);
- test_check_attrs_msg (tc, file, line, expected->elem[i], objects->elem[i]);
+ if (i >= objects->num)
+ p11_test_fail (file, line, function, "too few objects read");
+ test_check_attrs_msg (file, line, function, expected->elem[i], objects->elem[i]);
}
- CuAssert_Line (tc, file, line, "too many objects read", i == objects->num);
+ if (i != objects->num)
+ p11_test_fail (file, line, function, "too many objects read");
} else {
- CuAssert_Line (tc, file, line, "decoding failed", expected == NULL);
+ if (expected != NULL)
+ p11_test_fail (file, line, function, "decoding failed");
}
p11_array_free (objects);
@@ -123,11 +127,11 @@ check_read_msg (CuTest *tc,
p11_array_free (expected);
}
-#define check_read_success(tc, input, objs) \
- check_read_msg (tc, __FILE__, __LINE__, input, args_to_array objs)
+#define check_read_success(input, objs) \
+ check_read_msg (__FILE__, __LINE__, __FUNCTION__, input, args_to_array objs)
-#define check_read_failure(tc, input) \
- check_read_msg (tc, __FILE__, __LINE__, input, NULL)
+#define check_read_failure(input) \
+ check_read_msg (__FILE__, __LINE__, __FUNCTION__, input, NULL)
static CK_OBJECT_CLASS certificate = CKO_CERTIFICATE;
static CK_CERTIFICATE_TYPE x509 = CKC_X_509;
@@ -137,7 +141,7 @@ static CK_BBOOL truev = CK_TRUE;
static CK_BBOOL falsev = CK_FALSE;
static void
-test_simple (CuTest *tc)
+test_simple (void)
{
const char *input = "[p11-kit-object-v1]\n"
"class: data\n"
@@ -151,11 +155,11 @@ test_simple (CuTest *tc)
{ CKA_INVALID },
};
- check_read_success (tc, input, (expected, NULL));
+ check_read_success (input, (expected, NULL));
}
static void
-test_number (CuTest *tc)
+test_number (void)
{
const char *input = "[p11-kit-object-v1]\n"
"class: data\n"
@@ -171,11 +175,11 @@ test_number (CuTest *tc)
{ CKA_INVALID },
};
- check_read_success (tc, input, (expected, NULL));
+ check_read_success (input, (expected, NULL));
}
static void
-test_bool (CuTest *tc)
+test_bool (void)
{
const char *input = "[p11-kit-object-v1]\n"
"class: data\n"
@@ -191,11 +195,11 @@ test_bool (CuTest *tc)
{ CKA_INVALID },
};
- check_read_success (tc, input, (expected, NULL));
+ check_read_success (input, (expected, NULL));
}
static void
-test_oid (CuTest *tc)
+test_oid (void)
{
const char *input = "[p11-kit-object-v1]\n"
"class: data\n"
@@ -207,11 +211,11 @@ test_oid (CuTest *tc)
{ CKA_INVALID },
};
- check_read_success (tc, input, (expected, NULL));
+ check_read_success (input, (expected, NULL));
}
static void
-test_constant (CuTest *tc)
+test_constant (void)
{
const char *input = "[p11-kit-object-v1]\n"
"class: data\n"
@@ -225,11 +229,11 @@ test_constant (CuTest *tc)
{ CKA_INVALID },
};
- check_read_success (tc, input, (expected, NULL));
+ check_read_success (input, (expected, NULL));
}
static void
-test_multiple (CuTest *tc)
+test_multiple (void)
{
const char *input = "[p11-kit-object-v1]\n"
"class: data\n"
@@ -252,11 +256,11 @@ test_multiple (CuTest *tc)
{ CKA_INVALID },
};
- check_read_success (tc, input, (expected1, expected2, NULL));
+ check_read_success (input, (expected1, expected2, NULL));
}
static void
-test_pem_block (CuTest *tc)
+test_pem_block (void)
{
const char *input = "[p11-kit-object-v1]\n"
"class: certificate\n"
@@ -286,11 +290,11 @@ test_pem_block (CuTest *tc)
{ CKA_INVALID },
};
- check_read_success (tc, input, (expected, NULL));
+ check_read_success (input, (expected, NULL));
}
static void
-test_pem_invalid (CuTest *tc)
+test_pem_invalid (void)
{
const char *input = "[p11-kit-object-v1]\n"
"class: certificate\n"
@@ -311,13 +315,13 @@ test_pem_invalid (CuTest *tc)
p11_message_quiet ();
- check_read_failure (tc, input);
+ check_read_failure (input);
p11_message_loud ();
}
static void
-test_pem_unsupported (CuTest *tc)
+test_pem_unsupported (void)
{
const char *input = "[p11-kit-object-v1]\n"
"class: certificate\n"
@@ -327,13 +331,13 @@ test_pem_unsupported (CuTest *tc)
p11_message_quiet ();
- check_read_failure (tc, input);
+ check_read_failure (input);
p11_message_loud ();
}
static void
-test_pem_first (CuTest *tc)
+test_pem_first (void)
{
const char *input = "-----BEGIN BLOCK1-----\n"
"aYNNXqshlVxCdo8QfKeXh3GUzd/yn4LYIVgQrx4a\n"
@@ -343,13 +347,13 @@ test_pem_first (CuTest *tc)
p11_message_quiet ();
- check_read_failure (tc, input);
+ check_read_failure (input);
p11_message_loud ();
}
static void
-test_skip_unknown (CuTest *tc)
+test_skip_unknown (void)
{
const char *input = "[version-2]\n"
"class: data\n"
@@ -371,13 +375,13 @@ test_skip_unknown (CuTest *tc)
p11_message_quiet ();
- check_read_success (tc, input, (expected2, NULL));
+ check_read_success (input, (expected2, NULL));
p11_message_loud ();
}
static void
-test_bad_value (CuTest *tc)
+test_bad_value (void)
{
const char *input = "[p11-kit-object-v1]\n"
"class: data\n"
@@ -385,13 +389,13 @@ test_bad_value (CuTest *tc)
p11_message_quiet ();
- check_read_failure (tc, input);
+ check_read_failure (input);
p11_message_loud ();
}
static void
-test_bad_oid (CuTest *tc)
+test_bad_oid (void)
{
const char *input = "[p11-kit-object-v1]\n"
"class: data\n"
@@ -399,13 +403,13 @@ test_bad_oid (CuTest *tc)
p11_message_quiet ();
- check_read_failure (tc, input);
+ check_read_failure (input);
p11_message_loud ();
}
static void
-test_bad_field (CuTest *tc)
+test_bad_field (void)
{
const char *input = "[p11-kit-object-v1]\n"
"class: data\n"
@@ -413,13 +417,13 @@ test_bad_field (CuTest *tc)
p11_message_quiet ();
- check_read_failure (tc, input);
+ check_read_failure (input);
p11_message_loud ();
}
static void
-test_attribute_first (CuTest *tc)
+test_attribute_first (void)
{
const char *input = "class: data\n"
"[p11-kit-object-v1]\n"
@@ -427,45 +431,30 @@ test_attribute_first (CuTest *tc)
p11_message_quiet ();
- check_read_failure (tc, input);
+ check_read_failure (input);
p11_message_loud ();
}
int
-main (void)
+main (int argc,
+ char *argv[])
{
- CuString *output = CuStringNew ();
- CuSuite* suite = CuSuiteNew ();
- int ret;
-
- putenv ("P11_KIT_STRICT=1");
- p11_debug_init ();
-
- SUITE_ADD_TEST (suite, test_magic);
- SUITE_ADD_TEST (suite, test_simple);
- SUITE_ADD_TEST (suite, test_number);
- SUITE_ADD_TEST (suite, test_bool);
- SUITE_ADD_TEST (suite, test_oid);
- SUITE_ADD_TEST (suite, test_constant);
- SUITE_ADD_TEST (suite, test_multiple);
- SUITE_ADD_TEST (suite, test_pem_block);
- SUITE_ADD_TEST (suite, test_pem_invalid);
- SUITE_ADD_TEST (suite, test_pem_unsupported);
- SUITE_ADD_TEST (suite, test_pem_first);
- SUITE_ADD_TEST (suite, test_bad_value);
- SUITE_ADD_TEST (suite, test_bad_oid);
- SUITE_ADD_TEST (suite, test_bad_field);
- SUITE_ADD_TEST (suite, test_skip_unknown);
- SUITE_ADD_TEST (suite, test_attribute_first);
-
- CuSuiteRun (suite);
- CuSuiteSummary (suite, output);
- CuSuiteDetails (suite, output);
- printf ("%s\n", output->buffer);
- ret = suite->failCount;
- CuSuiteDelete (suite);
- CuStringDelete (output);
-
- return ret;
+ p11_test (test_magic, "/persist/magic");
+ p11_test (test_simple, "/persist/simple");
+ p11_test (test_number, "/persist/number");
+ p11_test (test_bool, "/persist/bool");
+ p11_test (test_oid, "/persist/oid");
+ p11_test (test_constant, "/persist/constant");
+ p11_test (test_multiple, "/persist/multiple");
+ p11_test (test_pem_block, "/persist/pem_block");
+ p11_test (test_pem_invalid, "/persist/pem_invalid");
+ p11_test (test_pem_unsupported, "/persist/pem_unsupported");
+ p11_test (test_pem_first, "/persist/pem_first");
+ p11_test (test_bad_value, "/persist/bad_value");
+ p11_test (test_bad_oid, "/persist/bad_oid");
+ p11_test (test_bad_field, "/persist/bad_field");
+ p11_test (test_skip_unknown, "/persist/skip_unknown");
+ p11_test (test_attribute_first, "/persist/attribute_first");
+ return p11_test_run (argc, argv);
}