summaryrefslogtreecommitdiff
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
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
-rw-r--r--build/Makefile.am8
-rw-r--r--build/Makefile.tests5
-rw-r--r--build/cutest/CuTest.c329
-rw-r--r--build/cutest/CuTest.h111
-rw-r--r--build/cutest/README.txt211
-rw-r--r--build/cutest/license.txt38
-rw-r--r--common/Makefile.am5
-rw-r--r--common/debug.h2
-rw-r--r--common/test.c261
-rw-r--r--common/test.h131
-rw-r--r--common/tests/Makefile.am3
-rw-r--r--common/tests/test-array.c101
-rw-r--r--common/tests/test-asn1.c53
-rw-r--r--common/tests/test-attrs.c461
-rw-r--r--common/tests/test-base64.c67
-rw-r--r--common/tests/test-buffer.c113
-rw-r--r--common/tests/test-compat.c28
-rw-r--r--common/tests/test-constants.c45
-rw-r--r--common/tests/test-dict.c250
-rw-r--r--common/tests/test-hash.c74
-rw-r--r--common/tests/test-lexer.c126
-rw-r--r--common/tests/test-oid.c45
-rw-r--r--common/tests/test-path.c68
-rw-r--r--common/tests/test-pem.c76
-rw-r--r--common/tests/test-url.c93
-rw-r--r--common/tests/test-utf8.c60
-rw-r--r--common/tests/test-x509.c106
-rw-r--r--p11-kit/tests/Makefile.am14
-rw-r--r--p11-kit/tests/test-conf.c (renamed from p11-kit/tests/conf-test.c)252
-rw-r--r--p11-kit/tests/test-deprecated.c187
-rw-r--r--p11-kit/tests/test-init.c144
-rw-r--r--p11-kit/tests/test-iter.c481
-rw-r--r--p11-kit/tests/test-log.c41
-rw-r--r--p11-kit/tests/test-managed.c97
-rw-r--r--p11-kit/tests/test-mock.c1012
-rw-r--r--p11-kit/tests/test-modules.c157
-rw-r--r--p11-kit/tests/test-pin.c (renamed from p11-kit/tests/pin-test.c)104
-rw-r--r--p11-kit/tests/test-progname.c (renamed from p11-kit/tests/progname-test.c)34
-rw-r--r--p11-kit/tests/test-proxy.c75
-rw-r--r--p11-kit/tests/test-uri.c (renamed from p11-kit/tests/uri-test.c)633
-rw-r--r--p11-kit/tests/test-virtual.c70
-rw-r--r--tools/tests/Makefile.am6
-rw-r--r--tools/tests/test-extract.c221
-rw-r--r--tools/tests/test-openssl.c186
-rw-r--r--tools/tests/test-pem.c96
-rw-r--r--tools/tests/test-save.c329
-rw-r--r--tools/tests/test-tools.c (renamed from tools/tests/test.c)65
-rw-r--r--tools/tests/test-tools.h (renamed from tools/tests/test.h)34
-rw-r--r--tools/tests/test-x509.c102
-rw-r--r--trust/tests/Makefile.am5
-rw-r--r--trust/tests/test-builder.c446
-rw-r--r--trust/tests/test-index.c395
-rw-r--r--trust/tests/test-module.c470
-rw-r--r--trust/tests/test-parser.c219
-rw-r--r--trust/tests/test-persist.c155
-rw-r--r--trust/tests/test-token.c93
-rw-r--r--trust/tests/test-trust.c (renamed from trust/tests/test-data.c)56
-rw-r--r--trust/tests/test-trust.h (renamed from trust/tests/test-data.h)40
58 files changed, 3901 insertions, 5188 deletions
diff --git a/build/Makefile.am b/build/Makefile.am
index 6f80eab..11337b1 100644
--- a/build/Makefile.am
+++ b/build/Makefile.am
@@ -2,16 +2,8 @@
SUBDIRS = certs
EXTRA_DIST = \
- cutest \
Makefile.tests
-noinst_LTLIBRARIES = \
- libcutest.la
-
-libcutest_la_SOURCES = \
- cutest/CuTest.c \
- cutest/CuTest.h
-
memcheck:
leakcheck:
diff --git a/build/Makefile.tests b/build/Makefile.tests
index 0c5b85c..429f5fe 100644
--- a/build/Makefile.tests
+++ b/build/Makefile.tests
@@ -1,13 +1,10 @@
NULL =
-CUTEST_CFLAGS = \
- -I$(top_srcdir)/build/cutest \
+TEST_CFLAGS = \
-DSRCDIR=\"$(abs_srcdir)\" \
-DBUILDDIR=\"$(abs_builddir)\" \
-DP11_KIT_FUTURE_UNSTABLE_API
-CUTEST_LIBS = $(top_builddir)/build/libcutest.la
-
MEMCHECK_ENV = $(TEST_RUNNER) valgrind --error-exitcode=80 --quiet --trace-children=yes
LEAKCHECK_ENV = $(TEST_RUNNER) valgrind --error-exitcode=81 --quiet --leak-check=yes
diff --git a/build/cutest/CuTest.c b/build/cutest/CuTest.c
deleted file mode 100644
index b033483..0000000
--- a/build/cutest/CuTest.c
+++ /dev/null
@@ -1,329 +0,0 @@
-#include <assert.h>
-#include <setjmp.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <math.h>
-
-#include "CuTest.h"
-
-/*-------------------------------------------------------------------------*
- * CuStr
- *-------------------------------------------------------------------------*/
-
-char* CuStrAlloc(int size)
-{
- char* newStr = (char*) malloc( sizeof(char) * (size) );
- return newStr;
-}
-
-char* CuStrCopy(const char* old)
-{
- int len = strlen(old);
- char* newStr = CuStrAlloc(len + 1);
- strcpy(newStr, old);
- return newStr;
-}
-
-/*-------------------------------------------------------------------------*
- * CuString
- *-------------------------------------------------------------------------*/
-
-void CuStringInit(CuString* str)
-{
- str->length = 0;
- str->size = STRING_MAX;
- str->buffer = (char*) malloc(sizeof(char) * str->size);
- str->buffer[0] = '\0';
-}
-
-CuString* CuStringNew(void)
-{
- CuString* str = (CuString*) malloc(sizeof(CuString));
- str->length = 0;
- str->size = STRING_MAX;
- str->buffer = (char*) malloc(sizeof(char) * str->size);
- str->buffer[0] = '\0';
- return str;
-}
-
-void CuStringDelete(CuString *str)
-{
- if (!str) return;
- free(str->buffer);
- free(str);
-}
-
-void CuStringResize(CuString* str, int newSize)
-{
- str->buffer = (char*) realloc(str->buffer, sizeof(char) * newSize);
- str->size = newSize;
-}
-
-void CuStringAppend(CuString* str, const char* text)
-{
- int length;
-
- if (text == NULL) {
- text = "NULL";
- }
-
- length = strlen(text);
- if (str->length + length + 1 >= str->size)
- CuStringResize(str, str->length + length + 1 + STRING_INC);
- str->length += length;
- strcat(str->buffer, text);
-}
-
-void CuStringAppendChar(CuString* str, char ch)
-{
- char text[2];
- text[0] = ch;
- text[1] = '\0';
- CuStringAppend(str, text);
-}
-
-void CuStringAppendFormat(CuString* str, const char* format, ...)
-{
- va_list argp;
- char buf[HUGE_STRING_LEN];
- va_start(argp, format);
- vsprintf(buf, format, argp);
- va_end(argp);
- CuStringAppend(str, buf);
-}
-
-void CuStringInsert(CuString* str, const char* text, int pos)
-{
- int length = strlen(text);
- if (pos > str->length)
- pos = str->length;
- if (str->length + length + 1 >= str->size)
- CuStringResize(str, str->length + length + 1 + STRING_INC);
- memmove(str->buffer + pos + length, str->buffer + pos, (str->length - pos) + 1);
- str->length += length;
- memcpy(str->buffer + pos, text, length);
-}
-
-/*-------------------------------------------------------------------------*
- * CuTest
- *-------------------------------------------------------------------------*/
-
-void CuTestInit(CuTest* t, const char* name, TestFunction function)
-{
- t->name = CuStrCopy(name);
- t->failed = 0;
- t->ran = 0;
- t->message = NULL;
- t->function = function;
- t->jumpBuf = NULL;
-}
-
-CuTest* CuTestNew(const char* name, TestFunction function)
-{
- CuTest* tc = CU_ALLOC(CuTest);
- CuTestInit(tc, name, function);
- return tc;
-}
-
-void CuTestDelete(CuTest *t)
-{
- if (!t) return;
- free(t->name);
- free(t);
-}
-
-void CuTestRun(CuTest* tc)
-{
- jmp_buf buf;
- tc->jumpBuf = &buf;
- if (setjmp(buf) == 0)
- {
- tc->ran = 1;
- (tc->function)(tc);
- }
- tc->jumpBuf = 0;
-}
-
-static void CuFailInternal(CuTest* tc, const char* file, int line, CuString* string)
-{
- char buf[HUGE_STRING_LEN];
-
- sprintf(buf, "%s:%d: ", file, line);
- CuStringInsert(string, buf, 0);
-
- tc->failed = 1;
- tc->message = string->buffer;
- if (tc->jumpBuf != 0) longjmp(*(tc->jumpBuf), 0);
-}
-
-void CuFail_Line(CuTest* tc, const char* file, int line, const char* message2, const char* message)
-{
- CuString string;
-
- CuStringInit(&string);
- if (message2 != NULL)
- {
- CuStringAppend(&string, message2);
- CuStringAppend(&string, ": ");
- }
- CuStringAppend(&string, message);
- CuFailInternal(tc, file, line, &string);
-}
-
-void CuAssert_Line(CuTest* tc, const char* file, int line, const char* message, int condition)
-{
- if (condition) return;
- CuFail_Line(tc, file, line, NULL, message);
-}
-
-void CuAssertStrEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message,
- const char* expected, const char* actual)
-{
- CuString string;
- if ((expected == NULL && actual == NULL) ||
- (expected != NULL && actual != NULL &&
- strcmp(expected, actual) == 0))
- {
- return;
- }
-
- CuStringInit(&string);
- if (message != NULL)
- {
- CuStringAppend(&string, message);
- CuStringAppend(&string, ": ");
- }
- CuStringAppend(&string, "expected <");
- CuStringAppend(&string, expected);
- CuStringAppend(&string, "> but was <");
- CuStringAppend(&string, actual);
- CuStringAppend(&string, ">");
- CuFailInternal(tc, file, line, &string);
-}
-
-void CuAssertIntEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message,
- int expected, int actual)
-{
- char buf[STRING_MAX];
- if (expected == actual) return;
- sprintf(buf, "expected <%d> but was <%d>", expected, actual);
- CuFail_Line(tc, file, line, message, buf);
-}
-
-void CuAssertPtrEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message,
- void* expected, void* actual)
-{
- char buf[STRING_MAX];
- if (expected == actual) return;
- sprintf(buf, "expected pointer <0x%p> but was <0x%p>", expected, actual);
- CuFail_Line(tc, file, line, message, buf);
-}
-
-
-/*-------------------------------------------------------------------------*
- * CuSuite
- *-------------------------------------------------------------------------*/
-
-void CuSuiteInit(CuSuite* testSuite)
-{
- testSuite->count = 0;
- testSuite->failCount = 0;
- memset(testSuite->list, 0, sizeof(testSuite->list));
-}
-
-CuSuite* CuSuiteNew(void)
-{
- CuSuite* testSuite = CU_ALLOC(CuSuite);
- CuSuiteInit(testSuite);
- return testSuite;
-}
-
-void CuSuiteDelete(CuSuite *testSuite)
-{
- unsigned int n;
- for (n=0; n < MAX_TEST_CASES; n++)
- {
- if (testSuite->list[n])
- {
- CuTestDelete(testSuite->list[n]);
- }
- }
- free(testSuite);
-
-}
-
-void CuSuiteAdd(CuSuite* testSuite, CuTest *testCase)
-{
- assert(testSuite->count < MAX_TEST_CASES);
- testSuite->list[testSuite->count] = testCase;
- testSuite->count++;
-}
-
-void CuSuiteAddSuite(CuSuite* testSuite, CuSuite* testSuite2)
-{
- int i;
- for (i = 0 ; i < testSuite2->count ; ++i)
- {
- CuTest* testCase = testSuite2->list[i];
- CuSuiteAdd(testSuite, testCase);
- }
-}
-
-void CuSuiteRun(CuSuite* testSuite)
-{
- int i;
- for (i = 0 ; i < testSuite->count ; ++i)
- {
- CuTest* testCase = testSuite->list[i];
- CuTestRun(testCase);
- if (testCase->failed) { testSuite->failCount += 1; }
- }
-}
-
-void CuSuiteSummary(CuSuite* testSuite, CuString* summary)
-{
- int i;
- for (i = 0 ; i < testSuite->count ; ++i)
- {
- CuTest* testCase = testSuite->list[i];
- CuStringAppend(summary, testCase->failed ? "F" : ".");
- }
- CuStringAppend(summary, "\n\n");
-}
-
-void CuSuiteDetails(CuSuite* testSuite, CuString* details)
-{
- int i;
- int failCount = 0;
-
- if (testSuite->failCount == 0)
- {
- int passCount = testSuite->count - testSuite->failCount;
- const char* testWord = passCount == 1 ? "test" : "tests";
- CuStringAppendFormat(details, "OK (%d %s)\n", passCount, testWord);
- }
- else
- {
- if (testSuite->failCount == 1)
- CuStringAppend(details, "There was 1 failure:\n");
- else
- CuStringAppendFormat(details, "There were %d failures:\n", testSuite->failCount);
-
- for (i = 0 ; i < testSuite->count ; ++i)
- {
- CuTest* testCase = testSuite->list[i];
- if (testCase->failed)
- {
- failCount++;
- CuStringAppendFormat(details, "%d) %s: %s\n",
- failCount, testCase->name, testCase->message);
- }
- }
- CuStringAppend(details, "\n!!!FAILURES!!!\n");
-
- CuStringAppendFormat(details, "Runs: %d ", testSuite->count);
- CuStringAppendFormat(details, "Passes: %d ", testSuite->count - testSuite->failCount);
- CuStringAppendFormat(details, "Fails: %d\n", testSuite->failCount);
- }
-}
diff --git a/build/cutest/CuTest.h b/build/cutest/CuTest.h
deleted file mode 100644
index b82d05b..0000000
--- a/build/cutest/CuTest.h
+++ /dev/null
@@ -1,111 +0,0 @@
-#ifndef CU_TEST_H
-#define CU_TEST_H
-
-#include <setjmp.h>
-#include <stdarg.h>
-
-#define CUTEST_VERSION "CuTest 1.5"
-
-/* CuString */
-
-char* CuStrAlloc(int size);
-char* CuStrCopy(const char* old);
-
-#define CU_ALLOC(TYPE) ((TYPE*) malloc(sizeof(TYPE)))
-
-#define HUGE_STRING_LEN 8192
-#define STRING_MAX 256
-#define STRING_INC 256
-
-typedef struct
-{
- int length;
- int size;
- char* buffer;
-} CuString;
-
-void CuStringInit(CuString* str);
-CuString* CuStringNew(void);
-void CuStringRead(CuString* str, const char* path);
-void CuStringAppend(CuString* str, const char* text);
-void CuStringAppendChar(CuString* str, char ch);
-void CuStringAppendFormat(CuString* str, const char* format, ...);
-void CuStringInsert(CuString* str, const char* text, int pos);
-void CuStringResize(CuString* str, int newSize);
-void CuStringDelete(CuString* str);
-
-/* CuTest */
-
-typedef struct CuTest CuTest;
-
-typedef void (*TestFunction)(CuTest *);
-
-struct CuTest
-{
- char* name;
- TestFunction function;
- int failed;
- int ran;
- const char* message;
- jmp_buf *jumpBuf;
-};
-
-void CuTestInit(CuTest* t, const char* name, TestFunction function);
-CuTest* CuTestNew(const char* name, TestFunction function);
-void CuTestRun(CuTest* tc);
-void CuTestDelete(CuTest *t);
-
-/* Internal versions of assert functions -- use the public versions */
-void CuFail_Line(CuTest* tc, const char* file, int line, const char* message2, const char* message);
-void CuAssert_Line(CuTest* tc, const char* file, int line, const char* message, int condition);
-void CuAssertStrEquals_LineMsg(CuTest* tc,
- const char* file, int line, const char* message,
- const char* expected, const char* actual);
-void CuAssertIntEquals_LineMsg(CuTest* tc,
- const char* file, int line, const char* message,
- int expected, int actual);
-void CuAssertPtrEquals_LineMsg(CuTest* tc,
- const char* file, int line, const char* message,
- void* expected, void* actual);
-
-/* public assert functions */
-
-#define CuFail(tc, ms) CuFail_Line( (tc), __FILE__, __LINE__, NULL, (ms))
-#define CuAssert(tc, ms, cond) CuAssert_Line((tc), __FILE__, __LINE__, (ms), (cond))
-#define CuAssertTrue(tc, cond) CuAssert_Line((tc), __FILE__, __LINE__, "assert failed", (cond))
-
-#define CuAssertStrEquals(tc,ex,ac) CuAssertStrEquals_LineMsg((tc),__FILE__,__LINE__,NULL,(ex),(ac))
-#define CuAssertStrEquals_Msg(tc,ms,ex,ac) CuAssertStrEquals_LineMsg((tc),__FILE__,__LINE__,(ms),(ex),(ac))
-#define CuAssertIntEquals(tc,ex,ac) CuAssertIntEquals_LineMsg((tc),__FILE__,__LINE__,NULL,(ex),(ac))
-#define CuAssertIntEquals_Msg(tc,ms,ex,ac) CuAssertIntEquals_LineMsg((tc),__FILE__,__LINE__,(ms),(ex),(ac))
-#define CuAssertPtrEquals(tc,ex,ac) CuAssertPtrEquals_LineMsg((tc),__FILE__,__LINE__,NULL,(ex),(ac))
-#define CuAssertPtrEquals_Msg(tc,ms,ex,ac) CuAssertPtrEquals_LineMsg((tc),__FILE__,__LINE__,(ms),(ex),(ac))
-
-#define CuAssertPtrNotNull(tc,p) CuAssert_Line((tc),__FILE__,__LINE__,"null pointer unexpected",(p != NULL))
-#define CuAssertPtrNotNullMsg(tc,msg,p) CuAssert_Line((tc),__FILE__,__LINE__,(msg),(p != NULL))
-
-/* CuSuite */
-
-#define MAX_TEST_CASES 1024
-
-#define SUITE_ADD_TEST(SUITE,TEST) CuSuiteAdd(SUITE, CuTestNew(#TEST, TEST))
-
-typedef struct
-{
- int count;
- CuTest* list[MAX_TEST_CASES];
- int failCount;
-
-} CuSuite;
-
-
-void CuSuiteInit(CuSuite* testSuite);
-CuSuite* CuSuiteNew(void);
-void CuSuiteDelete(CuSuite *testSuite);
-void CuSuiteAdd(CuSuite* testSuite, CuTest *testCase);
-void CuSuiteAddSuite(CuSuite* testSuite, CuSuite* testSuite2);
-void CuSuiteRun(CuSuite* testSuite);
-void CuSuiteSummary(CuSuite* testSuite, CuString* summary);
-void CuSuiteDetails(CuSuite* testSuite, CuString* details);
-
-#endif /* CU_TEST_H */
diff --git a/build/cutest/README.txt b/build/cutest/README.txt
deleted file mode 100644
index 96e8853..0000000
--- a/build/cutest/README.txt
+++ /dev/null
@@ -1,211 +0,0 @@
-HOW TO USE
-
-You can use CuTest to create unit tests to drive your development
-in the style of Extreme Programming. You can also add unit tests to
-existing code to ensure that it works as you suspect.
-
-Your unit tests are an investment. They let you to change your
-code and add new features confidently without worrying about
-accidentally breaking earlier features.
-
-
-LICENSING
-
-For details on licensing see license.txt.
-
-
-GETTING STARTED
-
-To add unit testing to your C code the only files you need are
-CuTest.c and CuTest.h.
-
-CuTestTest.c and AllTests.c have been included to provide an
-example of how to write unit tests and then how to aggregate them
-into suites and into a single AllTests.c file. Suites allow you
-to put group tests into logical sets. AllTests.c combines all the
-suites and runs them.
-
-You should not have to look inside CuTest.c. Looking in
-CuTestTest.c and AllTests.c (for example usage) should be
-sufficient.
-
-After downloading the sources, run your compiler to create an
-executable called AllTests.exe. For example, if you are using
-Windows with the cl.exe compiler you would type:
-
- cl.exe AllTests.c CuTest.c CuTestTest.c
- AllTests.exe
-
-This will run all the unit tests associated with CuTest and print
-the output on the console. You can replace cl.exe with gcc or
-your favorite compiler in the command above.
-
-
-DETAILED EXAMPLE
-
-Here is a more detailed example. We will work through a simple
-test first exercise. The goal is to create a library of string
-utilities. First, lets write a function that converts a
-null-terminated string to all upper case.
-
-Ensure that CuTest.c and CuTest.h are accessible from your C
-project. Next, create a file called StrUtil.c with these
-contents:
-
- #include "CuTest.h"
-
- char* StrToUpper(char* str) {
- return str;
- }
-
- void TestStrToUpper(CuTest *tc) {
- char* input = strdup("hello world");
- char* actual = StrToUpper(input);
- char* expected = "HELLO WORLD";
- CuAssertStrEquals(tc, expected, actual);
- }
-
- CuSuite* StrUtilGetSuite() {
- CuSuite* suite = CuSuiteNew();
- SUITE_ADD_TEST(suite, TestStrToUpper);
- return suite;
- }
-
-Create another file called AllTests.c with these contents:
-
- #include "CuTest.h"
-
- CuSuite* StrUtilGetSuite();
-
- void RunAllTests(void) {
- CuString *output = CuStringNew();
- CuSuite* suite = CuSuiteNew();
-
- CuSuiteAddSuite(suite, StrUtilGetSuite());
-
- CuSuiteRun(suite);
- CuSuiteSummary(suite, output);
- CuSuiteDetails(suite, output);
- printf("%s\n", output->buffer);
- }
-
- int main(void) {
- RunAllTests();
- }
-
-Then type this on the command line:
-
- gcc AllTests.c CuTest.c StrUtil.c
-
-to compile. You can replace gcc with your favorite compiler.
-CuTest should be portable enough to handle all Windows and Unix
-compilers. Then to run the tests type:
-
- a.out
-
-This will print an error because we haven't implemented the
-StrToUpper function correctly. We are just returning the string
-without changing it to upper case.
-
- char* StrToUpper(char* str) {
- return str;
- }
-
-Rewrite this as follows:
-
- char* StrToUpper(char* str) {
- char* p;
- for (p = str ; *p ; ++p) *p = toupper(*p);
- return str;
- }
-
-Recompile and run the tests again. The test should pass this
-time.
-
-
-WHAT TO DO NEXT
-
-At this point you might want to write more tests for the
-StrToUpper function. Here are some ideas:
-
-TestStrToUpper_EmptyString : pass in ""
-TestStrToUpper_UpperCase : pass in "HELLO WORLD"
-TestStrToUpper_MixedCase : pass in "HELLO world"
-TestStrToUpper_Numbers : pass in "1234 hello"
-
-As you write each one of these tests add it to StrUtilGetSuite
-function. If you don't the tests won't be run. Later as you write
-other functions and write tests for them be sure to include those
-in StrUtilGetSuite also. The StrUtilGetSuite function should
-include all the tests in StrUtil.c
-
-Over time you will create another file called FunkyStuff.c
-containing other functions unrelated to StrUtil. Follow the same
-pattern. Create a FunkyStuffGetSuite function in FunkyStuff.c.
-And add FunkyStuffGetSuite to AllTests.c.
-
-The framework is designed in the way it is so that it is easy to
-organize a lot of tests.
-
-THE BIG PICTURE
-
-Each individual test corresponds to a CuTest. These are grouped
-to form a CuSuite. CuSuites can hold CuTests or other CuSuites.
-AllTests.c collects all the CuSuites in the program into a single
-CuSuite which it then runs as a single CuSuite.
-
-The project is open source so feel free to take a peek under the
-hood at the CuTest.c file to see how it works. CuTestTest.c
-contains tests for CuTest.c. So CuTest tests itself.
-
-Since AllTests.c has a main() you will need to exclude this when
-you are building your product. Here is a nicer way to do this if
-you want to avoid messing with multiple builds. Remove the main()
-in AllTests.c. Note that it just calls RunAllTests(). Instead
-we'll call this directly from the main program.
-
-Now in the main() of the actual program check to see if the
-command line option "--test" was passed. If it was then I call
-RunAllTests() from AllTests.c. Otherwise run the real program.
-
-Shipping the tests with the code can be useful. If you customers
-complain about a problem you can ask them to run the unit tests
-and send you the output. This can help you to quickly isolate the
-piece of your system that is malfunctioning in the customer's
-environment.
-
-CuTest offers a rich set of CuAssert functions. Here is a list:
-
-void CuAssert(CuTest* tc, char* message, int condition);
-void CuAssertTrue(CuTest* tc, int condition);
-void CuAssertStrEquals(CuTest* tc, char* expected, char* actual);
-void CuAssertIntEquals(CuTest* tc, int expected, int actual);
-void CuAssertPtrEquals(CuTest* tc, void* expected, void* actual);
-void CuAssertPtrNotNull(CuTest* tc, void* pointer);
-
-The project is open source and so you can add other more powerful
-asserts to make your tests easier to write and more concise.
-Please feel free to send me changes you make so that I can
-incorporate them into future releases.
-
-If you see any errors in this document please contact me at
-asimjalis@peakprogramming.com.
-
-
-AUTOMATING TEST SUITE GENERATION
-
-make-tests.sh will grep through all the .c files in the current
-directory and generate the code to run all the tests contained in
-them. Using this script you don't have to worry about writing
-AllTests.c or dealing with any of the other suite code.
-
-
-CREDITS
-
-These people have contributed useful code changes to the CuTest project.
-Thanks!
-
-- [02.23.2003] Dave Glowacki <dglo@hyde.ssec.wisc.edu>
-- [04.17.2009] Tobias Lippert <herrmarder@googlemail.com>
-- [11.13.2009] Eli Bendersky <eliben@gmail.com>
-- [12.14.2009] Andrew Brown <abrown@datasci.com>
diff --git a/build/cutest/license.txt b/build/cutest/license.txt
deleted file mode 100644
index 3d94167..0000000
--- a/build/cutest/license.txt
+++ /dev/null
@@ -1,38 +0,0 @@
-NOTE
-
-The license is based on the zlib/libpng license. For more details see
-http://www.opensource.org/licenses/zlib-license.html. The intent of the
-license is to:
-
-- keep the license as simple as possible
-- encourage the use of CuTest in both free and commercial applications
- and libraries
-- keep the source code together
-- give credit to the CuTest contributors for their work
-
-If you ship CuTest in source form with your source distribution, the
-following license document must be included with it in unaltered form.
-If you find CuTest useful we would like to hear about it.
-
-LICENSE
-
-Copyright (c) 2003 Asim Jalis
-
-This software is provided 'as-is', without any express or implied
-warranty. In no event will the authors be held liable for any damages
-arising from the use of this software.
-
-Permission is granted to anyone to use this software for any purpose,
-including commercial applications, and to alter it and redistribute it
-freely, subject to the following restrictions:
-
-1. The origin of this software must not be misrepresented; you must not
-claim that you wrote the original software. If you use this software in
-a product, an acknowledgment in the product documentation would be
-appreciated but is not required.
-
-2. Altered source versions must be plainly marked as such, and must not
-be misrepresented as being the original software.
-
-3. This notice may not be removed or altered from any source
-distribution.
diff --git a/common/Makefile.am b/common/Makefile.am
index d7b4439..b3e4eaf 100644
--- a/common/Makefile.am
+++ b/common/Makefile.am
@@ -12,7 +12,7 @@ inc_HEADERS = \
noinst_LTLIBRARIES = \
libp11-common.la \
libp11-library.la \
- libp11-mock.la \
+ libp11-test.la \
$(NULL)
libp11_common_la_SOURCES = \
@@ -36,8 +36,9 @@ libp11_library_la_SOURCES = \
library.c library.h \
$(NULL)
-libp11_mock_la_SOURCES = \
+libp11_test_la_SOURCES = \
mock.c mock.h \
+ test.c test.h \
$(NULL)
if WITH_ASN1
diff --git a/common/debug.h b/common/debug.h
index f8b2cf4..0dcfeae 100644
--- a/common/debug.h
+++ b/common/debug.h
@@ -59,8 +59,10 @@ void p11_debug_precond (const char *format,
...) GNUC_PRINTF (1, 2)
CLANG_ANALYZER_NORETURN;
+#ifndef assert_not_reached
#define assert_not_reached() \
(assert (false && "this code should not be reached"))
+#endif
#define return_val_if_fail(x, v) \
do { if (!(x)) { \
diff --git a/common/test.c b/common/test.c
new file mode 100644
index 0000000..8866e48
--- /dev/null
+++ b/common/test.c
@@ -0,0 +1,261 @@
+/*
+ * Copyright (c) 2013, Red Hat Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the
+ * following disclaimer.
+ * * Redistributions in binary form must reproduce the
+ * above copyright notice, this list of conditions and
+ * the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ * * The names of contributors to this software may not be
+ * used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ *
+ * Author: Stef Walter <stefw@redhat.com>
+ */
+
+#include "config.h"
+
+#define P11_TEST_SOURCE 1
+
+#include "test.h"
+#include "debug.h"
+
+#include <assert.h>
+#include <setjmp.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+enum {
+ FIXTURE,
+ TEST,
+};
+
+typedef void (*func_with_arg) (void *);
+
+typedef struct _test_item {
+ int type;
+
+ union {
+ struct {
+ char name[1024];
+ func_with_arg func;
+ void *argument;
+ int failed;
+ } test;
+ struct {
+ func_with_arg setup;
+ func_with_arg teardown;
+ } fix;
+ } x;
+
+ struct _test_item *next;
+} test_item;
+
+struct {
+ test_item *suite;
+ test_item *last;
+ int number;
+ jmp_buf jump;
+} gl = { NULL, NULL, 0, };
+
+void
+p11_test_fail (const char *filename,
+ int line,
+ const char *function,
+ const char *message,
+ ...)
+{
+ const char *pos;
+ char *output;
+ char *from;
+ char *next;
+ va_list va;
+
+ assert (gl.last != NULL);
+ assert (gl.last->type == TEST);
+ gl.last->x.test.failed = 1;
+
+ printf ("not ok %d %s\n", gl.number, gl.last->x.test.name);
+
+ va_start (va, message);
+ if (vasprintf (&output, message, va) < 0)
+ assert (0 && "vasprintf() failed");
+ va_end (va);
+
+ for (from = output; from != NULL; ) {
+ next = strchr (from, '\n');
+ if (next) {
+ next[0] = '\0';
+ next += 1;
+ }
+
+ printf ("# %s\n", from);
+ from = next;
+ }
+
+ pos = strrchr (filename, '/');
+ if (pos != NULL && pos[1] != '\0')
+ filename = pos + 1;
+
+ printf ("# in %s() at %s:%d\n", function, filename, line);
+
+ free (output);
+}
+
+static void
+test_push (test_item *it)
+{
+ test_item *item;
+
+ item = calloc (1, sizeof (test_item));
+ assert (item != NULL);
+ memcpy (item, it, sizeof (test_item));
+
+ if (!gl.suite)
+ gl.suite = item;
+ if (gl.last)
+ gl.last->next = item;
+ gl.last = item;
+}
+
+void
+p11_test (void (* function) (void),
+ const char *name,
+ ...)
+{
+ test_item item = { TEST, };
+ va_list va;
+
+ item.x.test.func = (func_with_arg)function;
+
+ va_start (va, name);
+ vsnprintf (item.x.test.name, sizeof (item.x.test.name), name, va);
+ va_end (va);
+
+ test_push (&item);
+}
+
+void
+p11_testx (void (* function) (void *),
+ void *argument,
+ const char *name,
+ ...)
+{
+ test_item item = { TEST, };
+ va_list va;
+
+ item.type = TEST;
+ item.x.test.func = function;
+ item.x.test.argument = argument;
+
+ va_start (va, name);
+ vsnprintf (item.x.test.name, sizeof (item.x.test.name), name, va);
+ va_end (va);
+
+ test_push (&item);
+}
+
+void
+p11_fixture (void (* setup) (void *),
+ void (* teardown) (void *))
+{
+ test_item item;
+
+ item.type = FIXTURE;
+ item.x.fix.setup = setup;
+ item.x.fix.teardown = teardown;
+
+ test_push (&item);
+}
+
+int
+p11_test_run (int argc,
+ char **argv)
+{
+ test_item *fixture = NULL;
+ test_item *item;
+ test_item *next;
+ int count;
+ int ret = 0;
+
+ /* p11-kit specific stuff */
+ putenv ("P11_KIT_STRICT=1");
+ p11_debug_init ();
+
+ assert (gl.number == 0);
+ gl.last = NULL;
+
+ for (item = gl.suite, count = 0; item != NULL; item = item->next) {
+ if (item->type == TEST)
+ count++;
+ }
+
+ if (count == 0) {
+ printf ("1..0 # No tests\n");
+ return 0;
+ }
+
+ printf ("1..%d\n", count);
+
+ for (item = gl.suite, gl.number = 0; item != NULL; item = item->next) {
+ if (item->type == FIXTURE) {
+ fixture = item;
+ continue;
+ }
+
+ assert (item->type == TEST);
+ gl.last = item;
+ gl.number++;
+
+ if (setjmp (gl.jump) == 0) {
+ if (fixture && fixture->x.fix.setup)
+ (fixture->x.fix.setup) (item->x.test.argument);
+
+ assert (item->x.test.func);
+ (item->x.test.func)(item->x.test.argument);
+
+ if (fixture && fixture->x.fix.teardown)
+ (fixture->x.fix.teardown) (item->x.test.argument);
+
+ printf ("ok %d %s\n", gl.number, item->x.test.name);
+ }
+
+ gl.last = NULL;
+ }
+
+ for (item = gl.suite; item != NULL; item = next) {
+ if (item->type == TEST) {
+ if (item->x.test.failed)
+ ret++;
+ }
+
+ next = item->next;
+ free (item);
+ }
+
+ gl.suite = NULL;
+ gl.last = 0;
+ gl.number = 0;
+ return ret;
+}
diff --git a/common/test.h b/common/test.h
new file mode 100644
index 0000000..1da3608
--- /dev/null
+++ b/common/test.h
@@ -0,0 +1,131 @@
+/*
+ * Copyright (c) 2013, Red Hat Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the
+ * following disclaimer.
+ * * Redistributions in binary form must reproduce the
+ * above copyright notice, this list of conditions and
+ * the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ * * The names of contributors to this software may not be
+ * used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ *
+ * Author: Stef Walter <stefw@redhat.com>
+ */
+
+#include "compat.h"
+
+#ifndef P11_TEST_H_
+#define P11_TEST_H_
+
+#ifndef P11_TEST_SOURCE
+
+#include <string.h>
+
+#ifdef assert_not_reached
+#undef assert_not_reached
+#endif
+
+#ifdef assert
+#undef assert
+#endif
+
+#define assert(expr) \
+ assert_true(expr)
+#define assert_true(expr) \
+ do { if (expr) ; else \
+ p11_test_fail (__FILE__, __LINE__, __FUNCTION__, "assertion failed (%s)", #expr); \
+ } while (0)
+#define assert_false(expr) \
+ do { if (expr) \
+ p11_test_fail (__FILE__, __LINE__, __FUNCTION__, "assertion failed (!(%s))", #expr); \
+ } while (0)
+#define assert_fail(msg, detail) \
+ do { const char *__s = (detail); \
+ p11_test_fail (__FILE__, __LINE__, __FUNCTION__, "%s%s%s", (msg), __s ? ": ": "", __s ? __s : ""); \
+ } while (0)
+#define assert_not_reached(msg) \
+ do { \
+ p11_test_fail (__FILE__, __LINE__, __FUNCTION__, "code should not be reached"); \
+ } while (0)
+#define assert_ptr_not_null(ptr) \
+ do { if ((ptr) != NULL) ; else \
+ p11_test_fail (__FILE__, __LINE__, __FUNCTION__, "assertion failed (%s != NULL)", #ptr); \
+ } while (0)
+#define assert_num_cmp(a1, cmp, a2) \
+ do { unsigned long __n1 = (a1); \
+ unsigned long __n2 = (a2); \
+ if (__n1 cmp __n2) ; else \
+ p11_test_fail (__FILE__, __LINE__, __FUNCTION__, "assertion failed (%s %s %s): (%lu %s %lu)", \
+ #a1, #cmp, #a2, __n1, #cmp, __n2); \
+ } while (0)
+#define assert_num_eq(a1, a2) \
+ assert_num_cmp(a1, ==, a2)
+#define assert_str_cmp(a1, cmp, a2) \
+ do { const char *__s1 = (a1); \
+ const char *__s2 = (a2); \
+ if (__s1 && __s2 && strcmp (__s1, __s2) cmp 0) ; else \
+ p11_test_fail (__FILE__, __LINE__, __FUNCTION__, "assertion failed (%s %s %s): (%s %s %s)", \
+ #a1, #cmp, #a2, __s1 ? __s1 : "(null)", #cmp, __s2 ? __s2 : "(null)"); \
+ } while (0)
+#define assert_str_eq(a1, a2) \
+ assert_str_cmp(a1, ==, a2)
+#define assert_ptr_eq(a1, a2) \
+ do { const void *__p1 = (a1); \
+ const void *__p2 = (a2); \
+ if (__p1 == __p2) ; else \
+ p11_test_fail (__FILE__, __LINE__, __FUNCTION__, "assertion failed (%s == %s): (0x%08lx == 0x%08lx)", \
+ #a1, #a2, (unsigned long)(size_t)__p1, (unsigned long)(size_t)__p2); \
+ } while (0)
+
+#define assert_str_contains(expr, needle) \
+ do { const char *__str = (expr); \
+ if (__str && strstr (__str, needle)) ; else \
+ p1_test_fail (__FILE__, __LINE__, __FUNCTION__, "assertion failed (%s): '%s' does not contain '%s'", \
+ #expr, __str, needle); \
+ } while (0)
+
+#endif /* !P11_TEST_SOURCE */
+
+
+void p11_test_fail (const char *filename,
+ int line,
+ const char *function,
+ const char *message,
+ ...) GNUC_PRINTF(4, 5);
+
+void p11_test (void (* function) (void),
+ const char *name,
+ ...) GNUC_PRINTF(2, 3);
+
+void p11_testx (void (* function) (void *),
+ void *argument,
+ const char *name,
+ ...) GNUC_PRINTF(3, 4);
+
+void p11_fixture (void (* setup) (void *),
+ void (* teardown) (void *));
+
+int p11_test_run (int argc,
+ char **argv);
+
+#endif /* P11_TEST_H_ */
diff --git a/common/tests/Makefile.am b/common/tests/Makefile.am
index 6959c4f..945ed70 100644
--- a/common/tests/Makefile.am
+++ b/common/tests/Makefile.am
@@ -7,7 +7,7 @@ INCLUDES = \
-I$(top_srcdir) \
-I$(srcdir)/.. \
-I$(COMMON) \
- $(CUTEST_CFLAGS)
+ $(TEST_CFLAGS)
LDADD = \
$(NULL)
@@ -61,5 +61,6 @@ endif # WITH_ASN1
TESTS = $(CHECK_PROGS)
LDADD += \
+ $(top_builddir)/common/libp11-test.la \
$(top_builddir)/common/libp11-common.la \
$(CUTEST_LIBS)
diff --git a/common/tests/test-array.c b/common/tests/test-array.c
index a796365..8e8f996 100644
--- a/common/tests/test-array.c
+++ b/common/tests/test-array.c
@@ -33,26 +33,26 @@
*/
#include "config.h"
-#include "CuTest.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "array.h"
+#include "test.h"
static void
-test_p11_array_create (CuTest *tc)
+test_create (void)
{
p11_array *array;
array = p11_array_new (NULL);
- CuAssertPtrNotNull (tc, array);
+ assert_ptr_not_null (array);
p11_array_free (array);
}
static void
-test_p11_array_free_null (CuTest *tc)
+test_free_null (void)
{
p11_array_free (NULL);
}
@@ -65,81 +65,81 @@ destroy_value (void *data)
}
static void
-test_p11_array_free_destroys (CuTest *tc)
+test_free_destroys (void)
{
p11_array *array;
int value = 0;
array = p11_array_new (destroy_value);
- CuAssertPtrNotNull (tc, array);
+ assert_ptr_not_null (array);
if (!p11_array_push (array, &value))
- CuFail (tc, "should not be reached");
+ assert_not_reached ();
p11_array_free (array);
- CuAssertIntEquals (tc, 2, value);
+ assert_num_eq (2, value);
}
static void
-test_p11_array_add (CuTest *tc)
+test_add (void)
{
char *value = "VALUE";
p11_array *array;
array = p11_array_new (NULL);
if (!p11_array_push (array, value))
- CuFail (tc, "should not be reached");
+ assert_not_reached ();
- CuAssertIntEquals (tc, 1, array->num);
- CuAssertPtrEquals (tc, array->elem[0], value);
+ assert_num_eq (1, array->num);
+ assert_ptr_eq (array->elem[0], value);
p11_array_free (array);
}
static void
-test_p11_array_add_remove (CuTest *tc)
+test_add_remove (void)
{
char *value = "VALUE";
p11_array *array;
array = p11_array_new (NULL);
if (!p11_array_push (array, value))
- CuFail (tc, "should not be reached");
+ assert_not_reached ();
- CuAssertIntEquals (tc, 1, array->num);
+ assert_num_eq (1, array->num);
- CuAssertPtrEquals (tc, array->elem[0], value);
+ assert_ptr_eq (array->elem[0], value);
p11_array_remove (array, 0);
- CuAssertIntEquals (tc, 0, array->num);
+ assert_num_eq (0, array->num);
p11_array_free (array);
}
static void
-test_p11_array_remove_destroys (CuTest *tc)
+test_remove_destroys (void)
{
p11_array *array;
int value = 0;
array = p11_array_new (destroy_value);
if (!p11_array_push (array, &value))
- CuFail (tc, "should not be reached");
+ assert_not_reached ();
p11_array_remove (array, 0);
- CuAssertIntEquals (tc, 2, value);
+ assert_num_eq (2, value);
/* should not be destroyed again */
value = 0;
p11_array_free (array);
- CuAssertIntEquals (tc, 0, value);
+ assert_num_eq (0, value);
}
static void
-test_p11_array_remove_and_count (CuTest *tc)
+test_remove_and_count (void)
{
p11_array *array;
int *value;
@@ -147,75 +147,62 @@ test_p11_array_remove_and_count (CuTest *tc)
array = p11_array_new (free);
- CuAssertIntEquals (tc, 0, array->num);
+ assert_num_eq (0, array->num);
for (i = 0; i < 20000; ++i) {
value = malloc (sizeof (int));
*value = i;
if (!p11_array_push (array, value))
- CuFail (tc, "should not be reached");
- CuAssertIntEquals (tc, i + 1, array->num);
+ assert_not_reached ();
+ assert_num_eq (i + 1, array->num);
}
for (i = 10; i < 20000; ++i) {
p11_array_remove (array, 10);
- CuAssertIntEquals (tc, 20010 - (i + 1), array->num);
+ assert_num_eq (20010 - (i + 1), array->num);
}
- CuAssertIntEquals (tc, 10, array->num);
+ assert_num_eq (10, array->num);
p11_array_free (array);
}
static void
-test_p11_array_clear_destroys (CuTest *tc)
+test_clear_destroys (void)
{
p11_array *array;
int value = 0;
array = p11_array_new (destroy_value);
if (!p11_array_push (array, &value))
- CuFail (tc, "should not be reached");
+ assert_not_reached ();
- CuAssertIntEquals (tc, 1, array->num);
+ assert_num_eq (1, array->num);
p11_array_clear (array);
- CuAssertIntEquals (tc, 2, value);
- CuAssertIntEquals (tc, 0, array->num);
+ assert_num_eq (2, value);
+ assert_num_eq (0, array->num);
/* should not be destroyed again */
value = 0;
p11_array_free (array);
- CuAssertIntEquals (tc, 0, value);
+ assert_num_eq (0, value);
}
-
int
-main (void)
+main (int argc,
+ char *argv[])
{
- CuString *output = CuStringNew ();
- CuSuite* suite = CuSuiteNew ();
- int ret;
-
- SUITE_ADD_TEST (suite, test_p11_array_create);
- SUITE_ADD_TEST (suite, test_p11_array_add);
- SUITE_ADD_TEST (suite, test_p11_array_add_remove);
- SUITE_ADD_TEST (suite, test_p11_array_remove_destroys);
- 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);
- CuSuiteDetails (suite, output);
- printf ("%s\n", output->buffer);
- ret = suite->failCount;
- CuSuiteDelete (suite);
- CuStringDelete (output);
-
- return ret;
+ p11_test (test_create, "/array/create");
+ p11_test (test_add, "/array/add");
+ p11_test (test_add_remove, "/array/add-remove");
+ p11_test (test_remove_destroys, "/array/remove-destroys");
+ p11_test (test_remove_and_count, "/array/remove-and-count");
+ p11_test (test_free_null, "/array/free-null");
+ p11_test (test_free_destroys, "/array/free-destroys");
+ p11_test (test_clear_destroys, "/array/clear-destroys");
+ return p11_test_run (argc, argv);
}
diff --git a/common/tests/test-asn1.c b/common/tests/test-asn1.c
index 0335fa6..710928c 100644
--- a/common/tests/test-asn1.c
+++ b/common/tests/test-asn1.c
@@ -33,7 +33,7 @@
*/
#include "config.h"
-#include "CuTest.h"
+#include "test.h"
#include "asn1.h"
#include "debug.h"
@@ -49,21 +49,21 @@ struct {
} test;
static void
-setup (CuTest *cu)
+setup (void *unused)
{
test.asn1_defs = p11_asn1_defs_load ();
- CuAssertPtrNotNull (cu, test.asn1_defs);
+ assert_ptr_not_null (test.asn1_defs);
}
static void
-teardown (CuTest *cu)
+teardown (void *unused)
{
p11_dict_free (test.asn1_defs);
memset (&test, 0, sizeof (test));
}
static void
-test_tlv_length (CuTest *cu)
+test_tlv_length (void)
{
struct {
const char *der;
@@ -79,14 +79,10 @@ test_tlv_length (CuTest *cu)
int length;
int i;
- setup (cu);
-
for (i = 0; tlv_lengths[i].der != NULL; i++) {
length = p11_asn1_tlv_length ((const unsigned char *)tlv_lengths[i].der, tlv_lengths[i].der_len);
- CuAssertIntEquals (cu, tlv_lengths[i].expected, length);
+ assert_num_eq (tlv_lengths[i].expected, length);
}
-
- teardown (cu);
}
static const unsigned char test_eku_server_and_client[] = {
@@ -95,7 +91,7 @@ static const unsigned char test_eku_server_and_client[] = {
};
static void
-test_asn1_cache (CuTest *cu)
+test_asn1_cache (void)
{
p11_asn1_cache *cache;
p11_dict *defs;
@@ -103,15 +99,15 @@ test_asn1_cache (CuTest *cu)
node_asn *check;
cache = p11_asn1_cache_new ();
- CuAssertPtrNotNull (cu, cache);
+ assert_ptr_not_null (cache);
defs = p11_asn1_cache_defs (cache);
- CuAssertPtrNotNull (cu, defs);
+ assert_ptr_not_null (defs);
asn = p11_asn1_decode (defs, "PKIX1.ExtKeyUsageSyntax",
test_eku_server_and_client,
sizeof (test_eku_server_and_client), NULL);
- CuAssertPtrNotNull (cu, defs);
+ assert_ptr_not_null (defs);
/* Place the parsed data in the cache */
p11_asn1_cache_take (cache, asn, "PKIX1.ExtKeyUsageSyntax",
@@ -122,38 +118,27 @@ test_asn1_cache (CuTest *cu)
check = p11_asn1_cache_get (cache, "PKIX1.ExtKeyUsageSyntax",
test_eku_server_and_client,
sizeof (test_eku_server_and_client));
- CuAssertPtrEquals (cu, asn, check);
+ assert_ptr_eq (asn, check);
/* Flush should remove it */
p11_asn1_cache_flush (cache);
check = p11_asn1_cache_get (cache, "PKIX1.ExtKeyUsageSyntax",
test_eku_server_and_client,
sizeof (test_eku_server_and_client));
- CuAssertPtrEquals (cu, NULL, check);
+ assert_ptr_eq (NULL, check);
p11_asn1_cache_free (cache);
}
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_tlv_length);
- SUITE_ADD_TEST (suite, test_asn1_cache);
+ p11_fixture (setup, teardown);
+ p11_test (test_tlv_length, "/asn1/tlv_length");
- CuSuiteRun (suite);
- CuSuiteSummary (suite, output);
- CuSuiteDetails (suite, output);
- printf ("%s\n", output->buffer);
- ret = suite->failCount;
- CuSuiteDelete (suite);
- CuStringDelete (output);
+ p11_fixture (NULL, NULL);
+ p11_test (test_asn1_cache, "/asn1/asn1_cache");
- return ret;
+ return p11_test_run (argc, argv);
}
diff --git a/common/tests/test-attrs.c b/common/tests/test-attrs.c
index 324ed90..6087191 100644
--- a/common/tests/test-attrs.c
+++ b/common/tests/test-attrs.c
@@ -33,7 +33,7 @@
*/
#include "config.h"
-#include "CuTest.h"
+#include "test.h"
#include <stdlib.h>
#include <stdio.h>
@@ -43,7 +43,7 @@
#include "debug.h"
static void
-test_terminator (CuTest *tc)
+test_terminator (void)
{
CK_ATTRIBUTE attrs[] = {
{ CKA_LABEL, "label", 5 },
@@ -51,14 +51,14 @@ test_terminator (CuTest *tc)
{ CKA_INVALID },
};
- CuAssertIntEquals (tc, true, p11_attrs_terminator (attrs + 2));
- CuAssertIntEquals (tc, true, p11_attrs_terminator (NULL));
- CuAssertIntEquals (tc, false, p11_attrs_terminator (attrs));
- CuAssertIntEquals (tc, false, p11_attrs_terminator (attrs + 1));
+ assert_num_eq (true, p11_attrs_terminator (attrs + 2));
+ assert_num_eq (true, p11_attrs_terminator (NULL));
+ assert_num_eq (false, p11_attrs_terminator (attrs));
+ assert_num_eq (false, p11_attrs_terminator (attrs + 1));
}
static void
-test_count (CuTest *tc)
+test_count (void)
{
CK_BBOOL vtrue = CK_TRUE;
@@ -72,13 +72,13 @@ test_count (CuTest *tc)
{ CKA_INVALID },
};
- CuAssertIntEquals (tc, 2, p11_attrs_count (attrs));
- CuAssertIntEquals (tc, 0, p11_attrs_count (NULL));
- CuAssertIntEquals (tc, 0, p11_attrs_count (empty));
+ assert_num_eq (2, p11_attrs_count (attrs));
+ assert_num_eq (0, p11_attrs_count (NULL));
+ assert_num_eq (0, p11_attrs_count (empty));
}
static void
-test_build_one (CuTest *tc)
+test_build_one (void)
{
CK_ATTRIBUTE *attrs;
CK_ATTRIBUTE add = { CKA_LABEL, "yay", 3 };
@@ -86,18 +86,18 @@ test_build_one (CuTest *tc)
attrs = p11_attrs_build (NULL, &add, NULL);
/* Test the first attribute */
- CuAssertPtrNotNull (tc, attrs);
- CuAssertTrue (tc, attrs->type == CKA_LABEL);
- CuAssertIntEquals (tc, 3, attrs->ulValueLen);
- CuAssertTrue (tc, memcmp (attrs->pValue, "yay", 3) == 0);
+ assert_ptr_not_null (attrs);
+ assert (attrs->type == CKA_LABEL);
+ assert_num_eq (3, attrs->ulValueLen);
+ assert (memcmp (attrs->pValue, "yay", 3) == 0);
- CuAssertTrue (tc, attrs[1].type == CKA_INVALID);
+ assert (attrs[1].type == CKA_INVALID);
p11_attrs_free (attrs);
}
static void
-test_build_two (CuTest *tc)
+test_build_two (void)
{
CK_ATTRIBUTE *attrs;
CK_ATTRIBUTE one = { CKA_LABEL, "yay", 3 };
@@ -105,23 +105,23 @@ test_build_two (CuTest *tc)
attrs = p11_attrs_build (NULL, &one, &two, NULL);
- CuAssertPtrNotNull (tc, attrs);
- CuAssertTrue (tc, attrs[0].type == CKA_LABEL);
- CuAssertIntEquals (tc, 3, attrs[0].ulValueLen);
- CuAssertTrue (tc, memcmp (attrs[0].pValue, "yay", 3) == 0);
+ assert_ptr_not_null (attrs);
+ assert (attrs[0].type == CKA_LABEL);
+ assert_num_eq (3, attrs[0].ulValueLen);
+ assert (memcmp (attrs[0].pValue, "yay", 3) == 0);
- CuAssertPtrNotNull (tc, attrs);
- CuAssertTrue (tc, attrs[1].type == CKA_VALUE);
- CuAssertIntEquals (tc, 5, attrs[1].ulValueLen);
- CuAssertTrue (tc, memcmp (attrs[1].pValue, "eight", 5) == 0);
+ assert_ptr_not_null (attrs);
+ assert (attrs[1].type == CKA_VALUE);
+ assert_num_eq (5, attrs[1].ulValueLen);
+ assert (memcmp (attrs[1].pValue, "eight", 5) == 0);
- CuAssertTrue (tc, attrs[2].type == CKA_INVALID);
+ assert (attrs[2].type == CKA_INVALID);
p11_attrs_free (attrs);
}
static void
-test_build_invalid (CuTest *tc)
+test_build_invalid (void)
{
CK_ATTRIBUTE *attrs;
CK_ATTRIBUTE one = { CKA_LABEL, "yay", 3 };
@@ -130,23 +130,23 @@ test_build_invalid (CuTest *tc)
attrs = p11_attrs_build (NULL, &one, &invalid, &two, NULL);
- CuAssertPtrNotNull (tc, attrs);
- CuAssertTrue (tc, attrs[0].type == CKA_LABEL);
- CuAssertIntEquals (tc, 3, attrs[0].ulValueLen);
- CuAssertTrue (tc, memcmp (attrs[0].pValue, "yay", 3) == 0);
+ assert_ptr_not_null (attrs);
+ assert (attrs[0].type == CKA_LABEL);
+ assert_num_eq (3, attrs[0].ulValueLen);
+ assert (memcmp (attrs[0].pValue, "yay", 3) == 0);
- CuAssertPtrNotNull (tc, attrs);
- CuAssertTrue (tc, attrs[1].type == CKA_VALUE);
- CuAssertIntEquals (tc, 5, attrs[1].ulValueLen);
- CuAssertTrue (tc, memcmp (attrs[1].pValue, "eight", 5) == 0);
+ assert_ptr_not_null (attrs);
+ assert (attrs[1].type == CKA_VALUE);
+ assert_num_eq (5, attrs[1].ulValueLen);
+ assert (memcmp (attrs[1].pValue, "eight", 5) == 0);
- CuAssertTrue (tc, attrs[2].type == CKA_INVALID);
+ assert (attrs[2].type == CKA_INVALID);
p11_attrs_free (attrs);
}
static void
-test_buildn_two (CuTest *tc)
+test_buildn_two (void)
{
CK_ATTRIBUTE *attrs;
CK_ATTRIBUTE add[] = {
@@ -157,23 +157,23 @@ test_buildn_two (CuTest *tc)
attrs = p11_attrs_buildn (NULL, add, 2);
/* Test the first attribute */
- CuAssertPtrNotNull (tc, attrs);
- CuAssertTrue (tc, attrs->type == CKA_LABEL);
- CuAssertIntEquals (tc, 3, attrs->ulValueLen);
- CuAssertTrue (tc, memcmp (attrs->pValue, "yay", 3) == 0);
+ assert_ptr_not_null (attrs);
+ assert (attrs->type == CKA_LABEL);
+ assert_num_eq (3, attrs->ulValueLen);
+ assert (memcmp (attrs->pValue, "yay", 3) == 0);
- CuAssertPtrNotNull (tc, attrs);
- CuAssertTrue (tc, attrs[1].type == CKA_VALUE);
- CuAssertIntEquals (tc, 5, attrs[1].ulValueLen);
- CuAssertTrue (tc, memcmp (attrs[1].pValue, "eight", 5) == 0);
+ assert_ptr_not_null (attrs);
+ assert (attrs[1].type == CKA_VALUE);
+ assert_num_eq (5, attrs[1].ulValueLen);
+ assert (memcmp (attrs[1].pValue, "eight", 5) == 0);
- CuAssertTrue (tc, attrs[2].type == CKA_INVALID);
+ assert (attrs[2].type == CKA_INVALID);
p11_attrs_free (attrs);
}
static void
-test_buildn_one (CuTest *tc)
+test_buildn_one (void)
{
CK_ATTRIBUTE *attrs;
CK_ATTRIBUTE add = { CKA_LABEL, "yay", 3 };
@@ -181,18 +181,18 @@ test_buildn_one (CuTest *tc)
attrs = p11_attrs_buildn (NULL, &add, 1);
/* Test the first attribute */
- CuAssertPtrNotNull (tc, attrs);
- CuAssertTrue (tc, attrs->type == CKA_LABEL);
- CuAssertIntEquals (tc, 3, attrs->ulValueLen);
- CuAssertTrue (tc, memcmp (attrs->pValue, "yay", 3) == 0);
+ assert_ptr_not_null (attrs);
+ assert (attrs->type == CKA_LABEL);
+ assert_num_eq (3, attrs->ulValueLen);
+ assert (memcmp (attrs->pValue, "yay", 3) == 0);
- CuAssertTrue (tc, attrs[1].type == CKA_INVALID);
+ assert (attrs[1].type == CKA_INVALID);
p11_attrs_free (attrs);
}
static void
-test_build_add (CuTest *tc)
+test_build_add (void)
{
CK_ATTRIBUTE initial[] = {
{ CKA_LABEL, "label", 5 },
@@ -206,28 +206,28 @@ test_build_add (CuTest *tc)
attrs = p11_attrs_buildn (NULL, initial, 2);
attrs = p11_attrs_build (attrs, &one, &two, NULL);
- CuAssertPtrNotNull (tc, attrs);
- CuAssertTrue (tc, attrs[0].type == CKA_LABEL);
- CuAssertIntEquals (tc, 3, attrs[0].ulValueLen);
- CuAssertTrue (tc, memcmp (attrs[0].pValue, "yay", 3) == 0);
+ assert_ptr_not_null (attrs);
+ assert (attrs[0].type == CKA_LABEL);
+ assert_num_eq (3, attrs[0].ulValueLen);
+ assert (memcmp (attrs[0].pValue, "yay", 3) == 0);
- CuAssertPtrNotNull (tc, attrs);
- CuAssertTrue (tc, attrs[1].type == CKA_VALUE);
- CuAssertIntEquals (tc, 4, attrs[1].ulValueLen);
- CuAssertTrue (tc, memcmp (attrs[1].pValue, "nine", 4) == 0);
+ assert_ptr_not_null (attrs);
+ assert (attrs[1].type == CKA_VALUE);
+ assert_num_eq (4, attrs[1].ulValueLen);
+ assert (memcmp (attrs[1].pValue, "nine", 4) == 0);
- CuAssertPtrNotNull (tc, attrs);
- CuAssertTrue (tc, attrs[2].type == CKA_TOKEN);
- CuAssertIntEquals (tc, 1, attrs[2].ulValueLen);
- CuAssertTrue (tc, memcmp (attrs[2].pValue, "\x01", 1) == 0);
+ assert_ptr_not_null (attrs);
+ assert (attrs[2].type == CKA_TOKEN);
+ assert_num_eq (1, attrs[2].ulValueLen);
+ assert (memcmp (attrs[2].pValue, "\x01", 1) == 0);
- CuAssertTrue (tc, attrs[3].type == CKA_INVALID);
+ assert (attrs[3].type == CKA_INVALID);
p11_attrs_free (attrs);
}
static void
-test_build_null (CuTest *tc)
+test_build_null (void)
{
CK_ATTRIBUTE *attrs;
CK_ATTRIBUTE add = { CKA_LABEL, NULL, (CK_ULONG)-1 };
@@ -235,16 +235,16 @@ test_build_null (CuTest *tc)
attrs = p11_attrs_build (NULL, &add, NULL);
/* Test the first attribute */
- CuAssertPtrNotNull (tc, attrs);
- CuAssertTrue (tc, attrs->type == CKA_LABEL);
- CuAssertTrue (tc, attrs->ulValueLen == (CK_ULONG)-1);
- CuAssertPtrEquals (tc, NULL, attrs->pValue);
+ assert_ptr_not_null (attrs);
+ assert (attrs->type == CKA_LABEL);
+ assert (attrs->ulValueLen == (CK_ULONG)-1);
+ assert_ptr_eq (NULL, attrs->pValue);
p11_attrs_free (attrs);
}
static void
-test_dup (CuTest *tc)
+test_dup (void)
{
CK_ATTRIBUTE *attrs;
CK_ATTRIBUTE original[] = {
@@ -256,23 +256,23 @@ test_dup (CuTest *tc)
attrs = p11_attrs_dup (original);
/* Test the first attribute */
- CuAssertPtrNotNull (tc, attrs);
- CuAssertTrue (tc, attrs->type == CKA_LABEL);
- CuAssertIntEquals (tc, 3, attrs->ulValueLen);
- CuAssertTrue (tc, memcmp (attrs->pValue, "yay", 3) == 0);
+ assert_ptr_not_null (attrs);
+ assert (attrs->type == CKA_LABEL);
+ assert_num_eq (3, attrs->ulValueLen);
+ assert (memcmp (attrs->pValue, "yay", 3) == 0);
- CuAssertPtrNotNull (tc, attrs);
- CuAssertTrue (tc, attrs[1].type == CKA_VALUE);
- CuAssertIntEquals (tc, 5, attrs[1].ulValueLen);
- CuAssertTrue (tc, memcmp (attrs[1].pValue, "eight", 5) == 0);
+ assert_ptr_not_null (attrs);
+ assert (attrs[1].type == CKA_VALUE);
+ assert_num_eq (5, attrs[1].ulValueLen);
+ assert (memcmp (attrs[1].pValue, "eight", 5) == 0);
- CuAssertTrue (tc, attrs[2].type == CKA_INVALID);
+ assert (attrs[2].type == CKA_INVALID);
p11_attrs_free (attrs);
}
static void
-test_take (CuTest *tc)
+test_take (void)
{
CK_ATTRIBUTE initial[] = {
{ CKA_LABEL, "label", 5 },
@@ -284,30 +284,30 @@ test_take (CuTest *tc)
attrs = p11_attrs_buildn (NULL, initial, 2);
attrs = p11_attrs_take (attrs, CKA_LABEL, strdup ("boooyah"), 7);
attrs = p11_attrs_take (attrs, CKA_TOKEN, strdup ("\x01"), 1);
- CuAssertPtrNotNull (tc, attrs);
+ assert_ptr_not_null (attrs);
- CuAssertTrue (tc, attrs[0].type == CKA_LABEL);
- CuAssertIntEquals (tc, 7, attrs[0].ulValueLen);
- CuAssertTrue (tc, memcmp (attrs[0].pValue, "boooyah", 7) == 0);
+ assert (attrs[0].type == CKA_LABEL);
+ assert_num_eq (7, attrs[0].ulValueLen);
+ assert (memcmp (attrs[0].pValue, "boooyah", 7) == 0);
- CuAssertPtrNotNull (tc, attrs);
- CuAssertTrue (tc, attrs[1].type == CKA_VALUE);
- CuAssertIntEquals (tc, 4, attrs[1].ulValueLen);
- CuAssertTrue (tc, memcmp (attrs[1].pValue, "nine", 4) == 0);
+ assert_ptr_not_null (attrs);
+ assert (attrs[1].type == CKA_VALUE);
+ assert_num_eq (4, attrs[1].ulValueLen);
+ assert (memcmp (attrs[1].pValue, "nine", 4) == 0);
- CuAssertPtrNotNull (tc, attrs);
- CuAssertTrue (tc, attrs[2].type == CKA_TOKEN);
- CuAssertIntEquals (tc, 1, attrs[2].ulValueLen);
- CuAssertTrue (tc, memcmp (attrs[2].pValue, "\x01", 1) == 0);
+ assert_ptr_not_null (attrs);
+ assert (attrs[2].type == CKA_TOKEN);
+ assert_num_eq (1, attrs[2].ulValueLen);
+ assert (memcmp (attrs[2].pValue, "\x01", 1) == 0);
- CuAssertTrue (tc, attrs[3].type == CKA_INVALID);
+ assert (attrs[3].type == CKA_INVALID);
p11_attrs_free (attrs);
}
static void
-test_merge_replace (CuTest *tc)
+test_merge_replace (void)
{
CK_ATTRIBUTE initial[] = {
{ CKA_LABEL, "label", 5 },
@@ -325,29 +325,29 @@ test_merge_replace (CuTest *tc)
attrs = p11_attrs_buildn (NULL, initial, 2);
merge = p11_attrs_buildn (NULL, extra, 2);
attrs = p11_attrs_merge (attrs, merge, true);
- CuAssertPtrNotNull (tc, attrs);
+ assert_ptr_not_null (attrs);
- CuAssertTrue (tc, attrs[0].type == CKA_LABEL);
- CuAssertIntEquals (tc, 7, attrs[0].ulValueLen);
- CuAssertTrue (tc, memcmp (attrs[0].pValue, "boooyah", 7) == 0);
+ assert (attrs[0].type == CKA_LABEL);
+ assert_num_eq (7, attrs[0].ulValueLen);
+ assert (memcmp (attrs[0].pValue, "boooyah", 7) == 0);
- CuAssertPtrNotNull (tc, attrs);
- CuAssertTrue (tc, attrs[1].type == CKA_VALUE);
- CuAssertIntEquals (tc, 4, attrs[1].ulValueLen);
- CuAssertTrue (tc, memcmp (attrs[1].pValue, "nine", 4) == 0);
+ assert_ptr_not_null (attrs);
+ assert (attrs[1].type == CKA_VALUE);
+ assert_num_eq (4, attrs[1].ulValueLen);
+ assert (memcmp (attrs[1].pValue, "nine", 4) == 0);
- CuAssertPtrNotNull (tc, attrs);
- CuAssertTrue (tc, attrs[2].type == CKA_APPLICATION);
- CuAssertIntEquals (tc, 5, attrs[2].ulValueLen);
- CuAssertTrue (tc, memcmp (attrs[2].pValue, "disco", 5) == 0);
+ assert_ptr_not_null (attrs);
+ assert (attrs[2].type == CKA_APPLICATION);
+ assert_num_eq (5, attrs[2].ulValueLen);
+ assert (memcmp (attrs[2].pValue, "disco", 5) == 0);
- CuAssertTrue (tc, attrs[3].type == CKA_INVALID);
+ assert (attrs[3].type == CKA_INVALID);
p11_attrs_free (attrs);
}
static void
-test_merge_empty (CuTest *tc)
+test_merge_empty (void)
{
CK_ATTRIBUTE extra[] = {
{ CKA_LABEL, "boooyah", 7 },
@@ -359,14 +359,14 @@ test_merge_empty (CuTest *tc)
merge = p11_attrs_buildn (NULL, extra, 2);
attrs = p11_attrs_merge (attrs, merge, true);
- CuAssertPtrNotNull (tc, attrs);
- CuAssertPtrEquals (tc, merge, attrs);
+ assert_ptr_not_null (attrs);
+ assert_ptr_eq (merge, attrs);
p11_attrs_free (attrs);
}
static void
-test_merge_augment (CuTest *tc)
+test_merge_augment (void)
{
CK_ATTRIBUTE initial[] = {
{ CKA_LABEL, "label", 5 },
@@ -384,35 +384,35 @@ test_merge_augment (CuTest *tc)
attrs = p11_attrs_buildn (NULL, initial, 2);
merge = p11_attrs_buildn (NULL, extra, 2);
attrs = p11_attrs_merge (attrs, merge, false);
- CuAssertPtrNotNull (tc, attrs);
+ assert_ptr_not_null (attrs);
- CuAssertTrue (tc, attrs[0].type == CKA_LABEL);
- CuAssertIntEquals (tc, 5, attrs[0].ulValueLen);
- CuAssertTrue (tc, memcmp (attrs[0].pValue, "label", 5) == 0);
+ assert (attrs[0].type == CKA_LABEL);
+ assert_num_eq (5, attrs[0].ulValueLen);
+ assert (memcmp (attrs[0].pValue, "label", 5) == 0);
- CuAssertPtrNotNull (tc, attrs);
- CuAssertTrue (tc, attrs[1].type == CKA_VALUE);
- CuAssertIntEquals (tc, 4, attrs[1].ulValueLen);
- CuAssertTrue (tc, memcmp (attrs[1].pValue, "nine", 4) == 0);
+ assert_ptr_not_null (attrs);
+ assert (attrs[1].type == CKA_VALUE);
+ assert_num_eq (4, attrs[1].ulValueLen);
+ assert (memcmp (attrs[1].pValue, "nine", 4) == 0);
- CuAssertPtrNotNull (tc, attrs);
- CuAssertTrue (tc, attrs[2].type == CKA_APPLICATION);
- CuAssertIntEquals (tc, 5, attrs[2].ulValueLen);
- CuAssertTrue (tc, memcmp (attrs[2].pValue, "disco", 5) == 0);
+ assert_ptr_not_null (attrs);
+ assert (attrs[2].type == CKA_APPLICATION);
+ assert_num_eq (5, attrs[2].ulValueLen);
+ assert (memcmp (attrs[2].pValue, "disco", 5) == 0);
- CuAssertTrue (tc, attrs[3].type == CKA_INVALID);
+ assert (attrs[3].type == CKA_INVALID);
p11_attrs_free (attrs);
}
static void
-test_free_null (CuTest *tc)
+test_free_null (void)
{
p11_attrs_free (NULL);
}
static void
-test_equal (CuTest *tc)
+test_equal (void)
{
char *data = "extra attribute";
CK_ATTRIBUTE one = { CKA_LABEL, "yay", 3 };
@@ -422,19 +422,19 @@ test_equal (CuTest *tc)
CK_ATTRIBUTE overflow = { CKA_VALUE, data, 5 };
CK_ATTRIBUTE content = { CKA_VALUE, "conte", 5 };
- CuAssertTrue (tc, p11_attr_equal (&one, &one));
- CuAssertTrue (tc, !p11_attr_equal (&one, NULL));
- CuAssertTrue (tc, !p11_attr_equal (NULL, &one));
- CuAssertTrue (tc, !p11_attr_equal (&one, &two));
- CuAssertTrue (tc, !p11_attr_equal (&two, &other));
- CuAssertTrue (tc, p11_attr_equal (&other, &overflow));
- CuAssertTrue (tc, !p11_attr_equal (&one, &null));
- CuAssertTrue (tc, !p11_attr_equal (&one, &null));
- CuAssertTrue (tc, !p11_attr_equal (&other, &content));
+ assert (p11_attr_equal (&one, &one));
+ assert (!p11_attr_equal (&one, NULL));
+ assert (!p11_attr_equal (NULL, &one));
+ assert (!p11_attr_equal (&one, &two));
+ assert (!p11_attr_equal (&two, &other));
+ assert (p11_attr_equal (&other, &overflow));
+ assert (!p11_attr_equal (&one, &null));
+ assert (!p11_attr_equal (&one, &null));
+ assert (!p11_attr_equal (&other, &content));
}
static void
-test_hash (CuTest *tc)
+test_hash (void)
{
char *data = "extra attribute";
CK_ATTRIBUTE one = { CKA_LABEL, "yay", 3 };
@@ -446,18 +446,18 @@ test_hash (CuTest *tc)
unsigned int hash;
hash = p11_attr_hash (&one);
- CuAssertTrue (tc, hash != 0);
-
- CuAssertTrue (tc, p11_attr_hash (&one) == hash);
- CuAssertTrue (tc, p11_attr_hash (&two) != hash);
- CuAssertTrue (tc, p11_attr_hash (&other) != hash);
- CuAssertTrue (tc, p11_attr_hash (&overflow) != hash);
- CuAssertTrue (tc, p11_attr_hash (&null) != hash);
- CuAssertTrue (tc, p11_attr_hash (&content) != hash);
+ assert (hash != 0);
+
+ assert (p11_attr_hash (&one) == hash);
+ assert (p11_attr_hash (&two) != hash);
+ assert (p11_attr_hash (&other) != hash);
+ assert (p11_attr_hash (&overflow) != hash);
+ assert (p11_attr_hash (&null) != hash);
+ assert (p11_attr_hash (&content) != hash);
}
static void
-test_to_string (CuTest *tc)
+test_to_string (void)
{
char *data = "extra attribute";
CK_ATTRIBUTE one = { CKA_LABEL, "yay", 3 };
@@ -471,20 +471,20 @@ test_to_string (CuTest *tc)
string = p11_attr_to_string (&one, CKA_INVALID);
- CuAssertStrEquals (tc, "{ CKA_LABEL = (3) \"yay\" }", string);
+ assert_str_eq ("{ CKA_LABEL = (3) \"yay\" }", string);
free (string);
string = p11_attrs_to_string (attrs, -1);
- CuAssertStrEquals (tc, "(2) [ { CKA_LABEL = (3) \"yay\" }, { CKA_VALUE = (5) NOT-PRINTED } ]", string);
+ assert_str_eq ("(2) [ { CKA_LABEL = (3) \"yay\" }, { CKA_VALUE = (5) NOT-PRINTED } ]", string);
free (string);
string = p11_attrs_to_string (attrs, 1);
- CuAssertStrEquals (tc, "(1) [ { CKA_LABEL = (3) \"yay\" } ]", string);
+ assert_str_eq ("(1) [ { CKA_LABEL = (3) \"yay\" } ]", string);
free (string);
}
static void
-test_find (CuTest *tc)
+test_find (void)
{
CK_BBOOL vtrue = CK_TRUE;
CK_ATTRIBUTE *attr;
@@ -496,17 +496,17 @@ test_find (CuTest *tc)
};
attr = p11_attrs_find (attrs, CKA_LABEL);
- CuAssertPtrEquals (tc, attrs + 0, attr);
+ assert_ptr_eq (attrs + 0, attr);
attr = p11_attrs_find (attrs, CKA_TOKEN);
- CuAssertPtrEquals (tc, attrs + 1, attr);
+ assert_ptr_eq (attrs + 1, attr);
attr = p11_attrs_find (attrs, CKA_VALUE);
- CuAssertPtrEquals (tc, NULL, attr);
+ assert_ptr_eq (NULL, attr);
}
static void
-test_findn (CuTest *tc)
+test_findn (void)
{
CK_BBOOL vtrue = CK_TRUE;
CK_ATTRIBUTE *attr;
@@ -517,20 +517,20 @@ test_findn (CuTest *tc)
};
attr = p11_attrs_findn (attrs, 2, CKA_LABEL);
- CuAssertPtrEquals (tc, attrs + 0, attr);
+ assert_ptr_eq (attrs + 0, attr);
attr = p11_attrs_findn (attrs, 2, CKA_TOKEN);
- CuAssertPtrEquals (tc, attrs + 1, attr);
+ assert_ptr_eq (attrs + 1, attr);
attr = p11_attrs_findn (attrs, 2, CKA_VALUE);
- CuAssertPtrEquals (tc, NULL, attr);
+ assert_ptr_eq (NULL, attr);
attr = p11_attrs_findn (attrs, 1, CKA_TOKEN);
- CuAssertPtrEquals (tc, NULL, attr);
+ assert_ptr_eq (NULL, attr);
}
static void
-test_remove (CuTest *tc)
+test_remove (void)
{
CK_BBOOL vtrue = CK_TRUE;
CK_ATTRIBUTE *attr;
@@ -543,25 +543,25 @@ test_remove (CuTest *tc)
};
attrs = p11_attrs_buildn (NULL, initial, 2);
- CuAssertPtrNotNull (tc, attrs);
+ assert_ptr_not_null (attrs);
attr = p11_attrs_find (attrs, CKA_LABEL);
- CuAssertPtrEquals (tc, attrs + 0, attr);
+ assert_ptr_eq (attrs + 0, attr);
ret = p11_attrs_remove (attrs, CKA_LABEL);
- CuAssertIntEquals (tc, CK_TRUE, ret);
+ assert_num_eq (CK_TRUE, ret);
attr = p11_attrs_find (attrs, CKA_LABEL);
- CuAssertPtrEquals (tc, NULL, attr);
+ assert_ptr_eq (NULL, attr);
ret = p11_attrs_remove (attrs, CKA_LABEL);
- CuAssertIntEquals (tc, CK_FALSE, ret);
+ assert_num_eq (CK_FALSE, ret);
p11_attrs_free (attrs);
}
static void
-test_match (CuTest *tc)
+test_match (void)
{
CK_BBOOL vtrue = CK_TRUE;
@@ -588,14 +588,14 @@ test_match (CuTest *tc)
{ CKA_INVALID },
};
- CuAssertTrue (tc, p11_attrs_match (attrs, attrs));
- CuAssertTrue (tc, p11_attrs_match (attrs, subset));
- CuAssertTrue (tc, !p11_attrs_match (attrs, different));
- CuAssertTrue (tc, !p11_attrs_match (attrs, extra));
+ assert (p11_attrs_match (attrs, attrs));
+ assert (p11_attrs_match (attrs, subset));
+ assert (!p11_attrs_match (attrs, different));
+ assert (!p11_attrs_match (attrs, extra));
}
static void
-test_matchn (CuTest *tc)
+test_matchn (void)
{
CK_BBOOL vtrue = CK_TRUE;
@@ -620,13 +620,13 @@ test_matchn (CuTest *tc)
{ CKA_TOKEN, &vtrue, sizeof (vtrue) },
};
- CuAssertTrue (tc, p11_attrs_matchn (attrs, subset, 1));
- CuAssertTrue (tc, !p11_attrs_matchn (attrs, different, 2));
- CuAssertTrue (tc, !p11_attrs_matchn (attrs, extra, 3));
+ assert (p11_attrs_matchn (attrs, subset, 1));
+ assert (!p11_attrs_matchn (attrs, different, 2));
+ assert (!p11_attrs_matchn (attrs, extra, 3));
}
static void
-test_find_bool (CuTest *tc)
+test_find_bool (void)
{
CK_BBOOL vtrue = CK_TRUE;
CK_BBOOL vfalse = CK_FALSE;
@@ -640,13 +640,13 @@ test_find_bool (CuTest *tc)
{ CKA_INVALID },
};
- CuAssertTrue (tc, p11_attrs_find_bool (attrs, CKA_TOKEN, &value) && value == CK_TRUE);
- CuAssertTrue (tc, !p11_attrs_find_bool (attrs, CKA_LABEL, &value));
- CuAssertTrue (tc, !p11_attrs_find_bool (attrs, CKA_VALUE, &value));
+ assert (p11_attrs_find_bool (attrs, CKA_TOKEN, &value) && value == CK_TRUE);
+ assert (!p11_attrs_find_bool (attrs, CKA_LABEL, &value));
+ assert (!p11_attrs_find_bool (attrs, CKA_VALUE, &value));
}
static void
-test_find_ulong (CuTest *tc)
+test_find_ulong (void)
{
CK_ULONG v33 = 33UL;
CK_ULONG v45 = 45UL;
@@ -660,13 +660,13 @@ test_find_ulong (CuTest *tc)
{ CKA_INVALID },
};
- CuAssertTrue (tc, p11_attrs_find_ulong (attrs, CKA_BITS_PER_PIXEL, &value) && value == v33);
- CuAssertTrue (tc, !p11_attrs_find_ulong (attrs, CKA_LABEL, &value));
- CuAssertTrue (tc, !p11_attrs_find_ulong (attrs, CKA_VALUE, &value));
+ assert (p11_attrs_find_ulong (attrs, CKA_BITS_PER_PIXEL, &value) && value == v33);
+ assert (!p11_attrs_find_ulong (attrs, CKA_LABEL, &value));
+ assert (!p11_attrs_find_ulong (attrs, CKA_VALUE, &value));
}
static void
-test_find_value (CuTest *tc)
+test_find_value (void)
{
void *value;
size_t length;
@@ -681,21 +681,21 @@ test_find_value (CuTest *tc)
};
value = p11_attrs_find_value (attrs, CKA_LABEL, &length);
- CuAssertPtrEquals (tc, attrs[3].pValue, value);
- CuAssertIntEquals (tc, 4, length);
+ assert_ptr_eq (attrs[3].pValue, value);
+ assert_num_eq (4, length);
value = p11_attrs_find_value (attrs, CKA_LABEL, NULL);
- CuAssertPtrEquals (tc, attrs[3].pValue, value);
+ assert_ptr_eq (attrs[3].pValue, value);
value = p11_attrs_find_value (attrs, CKA_VALUE, &length);
- CuAssertPtrEquals (tc, NULL, value);
+ assert_ptr_eq (NULL, value);
value = p11_attrs_find_value (attrs, CKA_TOKEN, &length);
- CuAssertPtrEquals (tc, NULL, value);
+ assert_ptr_eq (NULL, value);
}
static void
-test_find_valid (CuTest *tc)
+test_find_valid (void)
{
CK_ATTRIBUTE *attr;
@@ -709,61 +709,46 @@ test_find_valid (CuTest *tc)
};
attr = p11_attrs_find_valid (attrs, CKA_LABEL);
- CuAssertPtrEquals (tc, attrs + 3, attr);
+ assert_ptr_eq (attrs + 3, attr);
attr = p11_attrs_find_valid (attrs, CKA_VALUE);
- CuAssertPtrEquals (tc, attrs + 4, attr);
+ assert_ptr_eq (attrs + 4, attr);
attr = p11_attrs_find_valid (attrs, CKA_TOKEN);
- CuAssertPtrEquals (tc, NULL, attr);
+ assert_ptr_eq (NULL, attr);
}
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_equal);
- SUITE_ADD_TEST (suite, test_hash);
- SUITE_ADD_TEST (suite, test_to_string);
-
- SUITE_ADD_TEST (suite, test_terminator);
- SUITE_ADD_TEST (suite, test_count);
- SUITE_ADD_TEST (suite, test_build_one);
- SUITE_ADD_TEST (suite, test_build_two);
- SUITE_ADD_TEST (suite, test_build_invalid);
- SUITE_ADD_TEST (suite, test_buildn_one);
- SUITE_ADD_TEST (suite, test_buildn_two);
- SUITE_ADD_TEST (suite, test_build_add);
- SUITE_ADD_TEST (suite, test_build_null);
- SUITE_ADD_TEST (suite, test_dup);
- SUITE_ADD_TEST (suite, test_take);
- SUITE_ADD_TEST (suite, test_merge_replace);
- SUITE_ADD_TEST (suite, test_merge_augment);
- SUITE_ADD_TEST (suite, test_merge_empty);
- SUITE_ADD_TEST (suite, test_free_null);
- SUITE_ADD_TEST (suite, test_match);
- SUITE_ADD_TEST (suite, test_matchn);
- SUITE_ADD_TEST (suite, test_find);
- SUITE_ADD_TEST (suite, test_findn);
- SUITE_ADD_TEST (suite, test_find_bool);
- SUITE_ADD_TEST (suite, test_find_ulong);
- SUITE_ADD_TEST (suite, test_find_value);
- SUITE_ADD_TEST (suite, test_find_valid);
- SUITE_ADD_TEST (suite, test_remove);
-
- 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_equal, "/attrs/equal");
+ p11_test (test_hash, "/attrs/hash");
+ p11_test (test_to_string, "/attrs/to-string");
+
+ p11_test (test_terminator, "/attrs/terminator");
+ p11_test (test_count, "/attrs/count");
+ p11_test (test_build_one, "/attrs/build-one");
+ p11_test (test_build_two, "/attrs/build-two");
+ p11_test (test_build_invalid, "/attrs/build-invalid");
+ p11_test (test_buildn_one, "/attrs/buildn-one");
+ p11_test (test_buildn_two, "/attrs/buildn-two");
+ p11_test (test_build_add, "/attrs/build-add");
+ p11_test (test_build_null, "/attrs/build-null");
+ p11_test (test_dup, "/attrs/dup");
+ p11_test (test_take, "/attrs/take");
+ p11_test (test_merge_replace, "/attrs/merge-replace");
+ p11_test (test_merge_augment, "/attrs/merge-augment");
+ p11_test (test_merge_empty, "/attrs/merge-empty");
+ p11_test (test_free_null, "/attrs/free-null");
+ p11_test (test_match, "/attrs/match");
+ p11_test (test_matchn, "/attrs/matchn");
+ p11_test (test_find, "/attrs/find");
+ p11_test (test_findn, "/attrs/findn");
+ p11_test (test_find_bool, "/attrs/find-bool");
+ p11_test (test_find_ulong, "/attrs/find-ulong");
+ p11_test (test_find_value, "/attrs/find-value");
+ p11_test (test_find_valid, "/attrs/find-valid");
+ p11_test (test_remove, "/attrs/remove");
+ return p11_test_run (argc, argv);
}
diff --git a/common/tests/test-base64.c b/common/tests/test-base64.c
index 90c1f49..ce303e8 100644
--- a/common/tests/test-base64.c
+++ b/common/tests/test-base64.c
@@ -33,7 +33,7 @@
*/
#include "config.h"
-#include "CuTest.h"
+#include "test.h"
#include "base64.h"
#include "debug.h"
@@ -45,9 +45,9 @@
#include <stdlib.h>
static void
-check_decode_msg (CuTest *tc,
- const char *file,
+check_decode_msg (const char *file,
int line,
+ const char *function,
const char *input,
ssize_t input_len,
const unsigned char *expected,
@@ -63,33 +63,38 @@ check_decode_msg (CuTest *tc,
length = p11_b64_pton (input, input_len, decoded, sizeof (decoded));
if (expected == NULL) {
- CuAssert_Line (tc, file, line, "decoding should have failed", length < 0);
+ if (length >= 0)
+ p11_test_fail (file, line, function, "decoding should have failed");
} else {
- CuAssert_Line (tc, file, line, "decoding failed", length >= 0);
- CuAssertIntEquals_LineMsg (tc, file, line, "wrong length", expected_len, length);
- CuAssert_Line (tc, file, line, "decoded wrong", memcmp (decoded, expected, length) == 0);
+ if (length < 0)
+ p11_test_fail (file, line, function, "decoding failed");
+ if (expected_len != length)
+ p11_test_fail (file, line, function, "wrong length: (%lu != %lu)",
+ (unsigned long)expected_len, (unsigned long)length);
+ if (memcmp (decoded, expected, length) != 0)
+ p11_test_fail (file, line, function, "decoded wrong");
}
}
-#define check_decode_success(tc, input, input_len, expected, expected_len) \
- check_decode_msg (tc, __FILE__, __LINE__, input, input_len, expected, expected_len)
+#define check_decode_success(input, input_len, expected, expected_len) \
+ check_decode_msg (__FILE__, __LINE__, __FUNCTION__, input, input_len, expected, expected_len)
-#define check_decode_failure(tc, input, input_len) \
- check_decode_msg (tc, __FILE__, __LINE__, input, input_len, NULL, 0)
+#define check_decode_failure(input, input_len) \
+ check_decode_msg (__FILE__, __LINE__, __FUNCTION__, input, input_len, NULL, 0)
static void
-test_decode_simple (CuTest *tc)
+test_decode_simple (void)
{
- check_decode_success (tc, "", 0, (unsigned char *)"", 0);
- check_decode_success (tc, "MQ==", 0, (unsigned char *)"1", 0);
- check_decode_success (tc, "YmxhaAo=", -1, (unsigned char *)"blah\n", -1);
- check_decode_success (tc, "bGVlbGEK", -1, (unsigned char *)"leela\n", -1);
- check_decode_success (tc, "bGVlbG9vCg==", -1, (unsigned char *)"leeloo\n", -1);
+ check_decode_success ("", 0, (unsigned char *)"", 0);
+ check_decode_success ("MQ==", 0, (unsigned char *)"1", 0);
+ check_decode_success ("YmxhaAo=", -1, (unsigned char *)"blah\n", -1);
+ check_decode_success ("bGVlbGEK", -1, (unsigned char *)"leela\n", -1);
+ check_decode_success ("bGVlbG9vCg==", -1, (unsigned char *)"leeloo\n", -1);
}
static void
-test_decode_thawte (CuTest *tc)
+test_decode_thawte (void)
{
const char *input =
"MIIEKjCCAxKgAwIBAgIQYAGXt0an6rS0mtZLL/eQ+zANBgkqhkiG9w0BAQsFADCB"
@@ -186,28 +191,14 @@ test_decode_thawte (CuTest *tc)
0x31, 0xd4, 0x40, 0x1a, 0x62, 0x34, 0x36, 0x3f, 0x35, 0x01, 0xae, 0xac, 0x63, 0xa0,
};
- check_decode_success (tc, input, -1, output, sizeof (output));
+ check_decode_success (input, -1, output, sizeof (output));
}
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_decode_simple);
- SUITE_ADD_TEST (suite, test_decode_thawte);
-
- 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_decode_simple, "/base64/decode-simple");
+ p11_test (test_decode_thawte, "/base64/decode-thawte");
+ return p11_test_run (argc, argv);
}
diff --git a/common/tests/test-buffer.c b/common/tests/test-buffer.c
index baf7b73..4fd060d 100644
--- a/common/tests/test-buffer.c
+++ b/common/tests/test-buffer.c
@@ -33,7 +33,7 @@
*/
#include "config.h"
-#include "CuTest.h"
+#include "test.h"
#include <stdlib.h>
#include <stdio.h>
@@ -43,41 +43,41 @@
#include "buffer.h"
static void
-test_init_uninit (CuTest *tc)
+test_init_uninit (void)
{
p11_buffer buffer;
p11_buffer_init (&buffer, 10);
- CuAssertPtrNotNull (tc, buffer.data);
- CuAssertIntEquals (tc, 0, buffer.len);
- CuAssertIntEquals (tc, 0, buffer.flags);
- CuAssertTrue (tc, buffer.size >= 10);
- CuAssertPtrNotNull (tc, buffer.ffree);
- CuAssertPtrNotNull (tc, buffer.frealloc);
+ assert_ptr_not_null (buffer.data);
+ assert_num_eq (0, buffer.len);
+ assert_num_eq (0, buffer.flags);
+ assert (buffer.size >= 10);
+ assert_ptr_not_null (buffer.ffree);
+ assert_ptr_not_null (buffer.frealloc);
p11_buffer_uninit (&buffer);
}
static void
-test_append (CuTest *tc)
+test_append (void)
{
p11_buffer buffer;
p11_buffer_init (&buffer, 10);
buffer.len = 5;
p11_buffer_append (&buffer, 35);
- CuAssertIntEquals (tc, 5 + 35, buffer.len);
- CuAssertTrue (tc, buffer.size >= 35 + 5);
+ assert_num_eq (5 + 35, buffer.len);
+ assert (buffer.size >= 35 + 5);
p11_buffer_append (&buffer, 15);
- CuAssertIntEquals (tc, 5 + 35 + 15, buffer.len);
- CuAssertTrue (tc, buffer.size >= 5 + 35 + 15);
+ assert_num_eq (5 + 35 + 15, buffer.len);
+ assert (buffer.size >= 5 + 35 + 15);
p11_buffer_uninit (&buffer);
}
static void
-test_null (CuTest *tc)
+test_null (void)
{
p11_buffer buffer;
@@ -85,7 +85,7 @@ test_null (CuTest *tc)
p11_buffer_add (&buffer, "Blah", -1);
p11_buffer_add (&buffer, " blah", -1);
- CuAssertStrEquals (tc, "Blah blah", buffer.data);
+ assert_str_eq ("Blah blah", buffer.data);
p11_buffer_uninit (&buffer);
}
@@ -109,7 +109,7 @@ mock_free (void *data)
}
static void
-test_init_for_data (CuTest *tc)
+test_init_for_data (void)
{
p11_buffer buffer;
unsigned char *ret;
@@ -121,29 +121,29 @@ test_init_for_data (CuTest *tc)
p11_buffer_init_full (&buffer, (unsigned char *)strdup ("blah"), 4, 0,
mock_realloc, mock_free);
- CuAssertPtrNotNull (tc, buffer.data);
- CuAssertStrEquals (tc, "blah", (char *)buffer.data);
- CuAssertIntEquals (tc, 4, buffer.len);
- CuAssertIntEquals (tc, 0, buffer.flags);
- CuAssertIntEquals (tc, 4, buffer.size);
- CuAssertPtrEquals (tc, mock_free, buffer.ffree);
- CuAssertPtrEquals (tc, mock_realloc, buffer.frealloc);
+ assert_ptr_not_null (buffer.data);
+ assert_str_eq ("blah", (char *)buffer.data);
+ assert_num_eq (4, buffer.len);
+ assert_num_eq (0, buffer.flags);
+ assert_num_eq (4, buffer.size);
+ assert_ptr_eq (mock_free, buffer.ffree);
+ assert_ptr_eq (mock_realloc, buffer.frealloc);
- CuAssertIntEquals (tc, 0, mock_realloced);
- CuAssertIntEquals (tc, 0, mock_freed);
+ assert_num_eq (0, mock_realloced);
+ assert_num_eq (0, mock_freed);
len = buffer.len;
ret = p11_buffer_append (&buffer, 1024);
- CuAssertPtrEquals (tc, (char *)buffer.data + len, ret);
- CuAssertIntEquals (tc, 1, mock_realloced);
+ assert_ptr_eq ((char *)buffer.data + len, ret);
+ assert_num_eq (1, mock_realloced);
p11_buffer_uninit (&buffer);
- CuAssertIntEquals (tc, 1, mock_realloced);
- CuAssertIntEquals (tc, 1, mock_freed);
+ assert_num_eq (1, mock_realloced);
+ assert_num_eq (1, mock_freed);
}
static void
-test_steal (CuTest *tc)
+test_steal (void)
{
p11_buffer buffer;
char *string;
@@ -154,61 +154,46 @@ test_steal (CuTest *tc)
p11_buffer_init_full (&buffer, (unsigned char *)strdup ("blah"), 4,
P11_BUFFER_NULL, mock_realloc, mock_free);
- CuAssertPtrNotNull (tc, buffer.data);
- CuAssertStrEquals (tc, "blah", buffer.data);
+ assert_ptr_not_null (buffer.data);
+ assert_str_eq ("blah", buffer.data);
p11_buffer_add (&buffer, " yada", -1);
- CuAssertStrEquals (tc, "blah yada", buffer.data);
+ assert_str_eq ("blah yada", buffer.data);
string = p11_buffer_steal (&buffer, &length);
p11_buffer_uninit (&buffer);
- CuAssertStrEquals (tc, "blah yada", string);
- CuAssertIntEquals (tc, 9, length);
- CuAssertIntEquals (tc, 0, mock_freed);
+ assert_str_eq ("blah yada", string);
+ assert_num_eq (9, length);
+ assert_num_eq (0, mock_freed);
free (string);
}
static void
-test_add (CuTest *tc)
+test_add (void)
{
p11_buffer buffer;
p11_buffer_init (&buffer, 10);
p11_buffer_add (&buffer, (unsigned char *)"Planet Express", 15);
- CuAssertIntEquals (tc, 15, buffer.len);
- CuAssertStrEquals (tc, "Planet Express", (char *)buffer.data);
- CuAssertTrue (tc, p11_buffer_ok (&buffer));
+ assert_num_eq (15, buffer.len);
+ assert_str_eq ("Planet Express", (char *)buffer.data);
+ assert (p11_buffer_ok (&buffer));
p11_buffer_uninit (&buffer);
}
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_init_uninit);
- SUITE_ADD_TEST (suite, test_init_for_data);
- SUITE_ADD_TEST (suite, test_append);
- SUITE_ADD_TEST (suite, test_null);
- SUITE_ADD_TEST (suite, test_add);
- SUITE_ADD_TEST (suite, test_steal);
-
- 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_init_uninit, "/buffer/init-uninit");
+ p11_test (test_init_for_data, "/buffer/init-for-data");
+ p11_test (test_append, "/buffer/append");
+ p11_test (test_null, "/buffer/null");
+ p11_test (test_add, "/buffer/add");
+ p11_test (test_steal, "/buffer/steal");
+ return p11_test_run (argc, argv);
}
diff --git a/common/tests/test-compat.c b/common/tests/test-compat.c
index 066e723..f1960ce 100644
--- a/common/tests/test-compat.c
+++ b/common/tests/test-compat.c
@@ -33,7 +33,7 @@
*/
#include "config.h"
-#include "CuTest.h"
+#include "test.h"
#include <stdlib.h>
#include <stdio.h>
@@ -42,36 +42,24 @@
#include "compat.h"
static void
-test_strndup (CuTest *tc)
+test_strndup (void)
{
char unterminated[] = { 't', 'e', 's', 't', 'e', 'r', 'o', 'n', 'i', 'o' };
char *res;
res = strndup (unterminated, 6);
- CuAssertStrEquals (tc, res, "tester");
+ assert_str_eq (res, "tester");
free (res);
res = strndup ("test", 6);
- CuAssertStrEquals (tc, res, "test");
+ assert_str_eq (res, "test");
free (res);
}
int
-main (void)
+main (int argc,
+ char *argv[])
{
- CuString *output = CuStringNew ();
- CuSuite* suite = CuSuiteNew ();
- int ret;
-
- SUITE_ADD_TEST (suite, test_strndup);
-
- 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_strndup, "/test/strndup");
+ return p11_test_run (argc, argv);
}
diff --git a/common/tests/test-constants.c b/common/tests/test-constants.c
index 4c2f3eb..76c44d2 100644
--- a/common/tests/test-constants.c
+++ b/common/tests/test-constants.c
@@ -33,7 +33,7 @@
*/
#include "config.h"
-#include "CuTest.h"
+#include "test.h"
#include <stdlib.h>
#include <stdio.h>
@@ -44,7 +44,7 @@
#include "debug.h"
static void
-test_constants (CuTest *tc)
+test_constants (void)
{
const p11_constant *constant;
p11_dict *nicks, *names;
@@ -72,29 +72,27 @@ test_constants (CuTest *tc)
for (j = 0; constants[j] != NULL; j++) {
constant = constants[j];
for (i = 1; constant[i].value != CKA_INVALID; i++) {
- if (constant[i].value < constant[i - 1].value) {
- CuFail_Line (tc, __FILE__, __LINE__,
- "attr constant out of order", constant[i].name);
- }
+ if (constant[i].value < constant[i - 1].value)
+ assert_fail ("attr constant out of order", constant[i].name);
}
for (i = 0; constant[i].value != CKA_INVALID; i++) {
- CuAssertPtrNotNull (tc, constant[i].name);
+ assert_ptr_not_null (constant[i].name);
if (constant[i].nick) {
- CuAssertStrEquals (tc, constant[i].nick,
- p11_constant_nick (constant, constant[i].value));
+ assert_str_eq (constant[i].nick,
+ p11_constant_nick (constant, constant[i].value));
}
- CuAssertStrEquals (tc, constant[i].name,
- p11_constant_name (constant, constant[i].value));
+ assert_str_eq (constant[i].name,
+ p11_constant_name (constant, constant[i].value));
if (constant[i].nick) {
check = p11_constant_resolve (nicks, constant[i].nick);
- CuAssertIntEquals (tc, constant[i].value, check);
+ assert_num_eq (constant[i].value, check);
}
check = p11_constant_resolve (names, constant[i].name);
- CuAssertIntEquals (tc, constant[i].value, check);
+ assert_num_eq (constant[i].value, check);
}
}
@@ -103,23 +101,10 @@ test_constants (CuTest *tc)
}
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_constants);
-
- CuSuiteRun (suite);
- CuSuiteSummary (suite, output);
- CuSuiteDetails (suite, output);
- printf ("%s\n", output->buffer);
- ret = suite->failCount;
- CuSuiteDelete (suite);
- CuStringDelete (output);
+ p11_test (test_constants, "/constants/all");
- return ret;
+ return p11_test_run (argc, argv);
}
diff --git a/common/tests/test-dict.c b/common/tests/test-dict.c
index fc40b07..7c6f851 100644
--- a/common/tests/test-dict.c
+++ b/common/tests/test-dict.c
@@ -33,7 +33,7 @@
*/
#include "config.h"
-#include "CuTest.h"
+#include "test.h"
#include <assert.h>
#include <stdlib.h>
@@ -43,17 +43,17 @@
#include "dict.h"
static void
-test_create (CuTest *tc)
+test_create (void)
{
p11_dict *map;
map = p11_dict_new (p11_dict_direct_hash, p11_dict_direct_equal, NULL, NULL);
- CuAssertPtrNotNull (tc, map);
+ assert_ptr_not_null (map);
p11_dict_free (map);
}
static void
-test_free_null (CuTest *tc)
+test_free_null (void)
{
p11_dict_free (NULL);
}
@@ -98,24 +98,24 @@ value_destroy (void *data)
}
static void
-test_free_destroys (CuTest *tc)
+test_free_destroys (void)
{
p11_dict *map;
Key key = { 8, 0 };
int value = 0;
map = p11_dict_new (key_hash, key_equal, key_destroy, value_destroy);
- CuAssertPtrNotNull (tc, map);
+ assert_ptr_not_null (map);
if (!p11_dict_set (map, &key, &value))
- CuFail (tc, "should not be reached");
+ assert_not_reached ();
p11_dict_free (map);
- CuAssertIntEquals (tc, true, key.freed);
- CuAssertIntEquals (tc, 2, value);
+ assert_num_eq (true, key.freed);
+ assert_num_eq (2, value);
}
static void
-test_iterate (CuTest *tc)
+test_iterate (void)
{
p11_dict *map;
p11_dictiter iter;
@@ -126,19 +126,19 @@ test_iterate (CuTest *tc)
int ret;
map = p11_dict_new (p11_dict_direct_hash, p11_dict_direct_equal, NULL, NULL);
- CuAssertPtrNotNull (tc, map);
+ assert_ptr_not_null (map);
if (!p11_dict_set (map, &key, &value))
- CuFail (tc, "should not be reached");
+ assert_not_reached ();
p11_dict_iterate (map, &iter);
ret = p11_dict_next (&iter, &pkey, &pvalue);
- CuAssertIntEquals (tc, 1, ret);
- CuAssertPtrEquals (tc, pkey, &key);
- CuAssertPtrEquals (tc, pvalue, &value);
+ assert_num_eq (1, ret);
+ assert_ptr_eq (pkey, &key);
+ assert_ptr_eq (pvalue, &value);
ret = p11_dict_next (&iter, &pkey, &pvalue);
- CuAssertIntEquals (tc, 0, ret);
+ assert_num_eq (0, ret);
p11_dict_free (map);
}
@@ -153,7 +153,7 @@ compar_strings (const void *one,
}
static void
-test_iterate_remove (CuTest *tc)
+test_iterate_remove (void)
{
p11_dict *map;
p11_dictiter iter;
@@ -165,45 +165,45 @@ test_iterate_remove (CuTest *tc)
int i;
map = p11_dict_new (p11_dict_str_hash, p11_dict_str_equal, NULL, NULL);
- CuAssertPtrNotNull (tc, map);
+ assert_ptr_not_null (map);
for (i = 0; i < 3; i++) {
if (!p11_dict_set (map, keys[i], values[i]))
- CuFail (tc, "should not be reached");
+ assert_not_reached ();
}
p11_dict_iterate (map, &iter);
ret = p11_dict_next (&iter, &okeys[0], &ovalues[0]);
- CuAssertIntEquals (tc, true, ret);
+ assert_num_eq (true, ret);
ret = p11_dict_next (&iter, &okeys[1], &ovalues[1]);
- CuAssertIntEquals (tc, true, ret);
+ assert_num_eq (true, ret);
if (!p11_dict_remove (map, okeys[1]))
- CuFail (tc, "should not be reached");
+ assert_not_reached ();
ret = p11_dict_next (&iter, &okeys[2], &ovalues[2]);
- CuAssertIntEquals (tc, true, ret);
+ assert_num_eq (true, ret);
ret = p11_dict_next (&iter, NULL, NULL);
- CuAssertIntEquals (tc, false, ret);
+ assert_num_eq (false, ret);
- CuAssertIntEquals (tc, 2, p11_dict_size (map));
+ assert_num_eq (2, p11_dict_size (map));
p11_dict_free (map);
qsort (okeys, 3, sizeof (void *), compar_strings);
qsort (ovalues, 3, sizeof (void *), compar_strings);
for (i = 0; i < 3; i++) {
- CuAssertStrEquals (tc, keys[i], okeys[i]);
- CuAssertPtrEquals (tc, keys[i], okeys[i]);
- CuAssertStrEquals (tc, values[i], ovalues[i]);
- CuAssertPtrEquals (tc, values[i], ovalues[i]);
+ assert_str_eq (keys[i], okeys[i]);
+ assert_ptr_eq (keys[i], okeys[i]);
+ assert_str_eq (values[i], ovalues[i]);
+ assert_ptr_eq (values[i], ovalues[i]);
}
}
static void
-test_set_get (CuTest *tc)
+test_set_get (void)
{
char *key = "KEY";
char *value = "VALUE";
@@ -213,13 +213,13 @@ test_set_get (CuTest *tc)
map = p11_dict_new (p11_dict_str_hash, p11_dict_str_equal, NULL, NULL);
p11_dict_set (map, key, value);
check = p11_dict_get (map, key);
- CuAssertPtrEquals (tc, check, value);
+ assert_ptr_eq (check, value);
p11_dict_free (map);
}
static void
-test_set_get_remove (CuTest *tc)
+test_set_get_remove (void)
{
char *key = "KEY";
char *value = "VALUE";
@@ -230,24 +230,24 @@ test_set_get_remove (CuTest *tc)
map = p11_dict_new (p11_dict_str_hash, p11_dict_str_equal, NULL, NULL);
if (!p11_dict_set (map, key, value))
- CuFail (tc, "should not be reached");
+ assert_not_reached ();
check = p11_dict_get (map, key);
- CuAssertPtrEquals (tc, check, value);
+ assert_ptr_eq (check, value);
ret = p11_dict_remove (map, key);
- CuAssertIntEquals (tc, true, ret);
+ assert_num_eq (true, ret);
ret = p11_dict_remove (map, key);
- CuAssertIntEquals (tc, false, ret);
+ assert_num_eq (false, ret);
check = p11_dict_get (map, key);
- CuAssert (tc, "should be null", check == NULL);
+ assert (check == NULL);
p11_dict_free (map);
}
static void
-test_set_clear (CuTest *tc)
+test_set_clear (void)
{
char *key = "KEY";
char *value = "VALUE";
@@ -257,18 +257,18 @@ test_set_clear (CuTest *tc)
map = p11_dict_new (p11_dict_direct_hash, p11_dict_direct_equal, NULL, NULL);
if (!p11_dict_set (map, key, value))
- CuFail (tc, "should not be reached");
+ assert_not_reached ();
p11_dict_clear (map);
check = p11_dict_get (map, key);
- CuAssert (tc, "should be null", check == NULL);
+ assert (check == NULL);
p11_dict_free (map);
}
static void
-test_remove_destroys (CuTest *tc)
+test_remove_destroys (void)
{
p11_dict *map;
Key key = { 8, 0 };
@@ -276,23 +276,23 @@ test_remove_destroys (CuTest *tc)
bool ret;
map = p11_dict_new (key_hash, key_equal, key_destroy, value_destroy);
- CuAssertPtrNotNull (tc, map);
+ assert_ptr_not_null (map);
if (!p11_dict_set (map, &key, &value))
- CuFail (tc, "should not be reached");
+ assert_not_reached ();
ret = p11_dict_remove (map, &key);
- CuAssertIntEquals (tc, true, ret);
- CuAssertIntEquals (tc, true, key.freed);
- CuAssertIntEquals (tc, 2, value);
+ assert_num_eq (true, ret);
+ assert_num_eq (true, key.freed);
+ assert_num_eq (2, value);
/* should not be destroyed again */
key.freed = false;
value = 0;
ret = p11_dict_remove (map, &key);
- CuAssertIntEquals (tc, false, ret);
- CuAssertIntEquals (tc, false, key.freed);
- CuAssertIntEquals (tc, 0, value);
+ assert_num_eq (false, ret);
+ assert_num_eq (false, key.freed);
+ assert_num_eq (0, value);
/* should not be destroyed again */
key.freed = false;
@@ -300,12 +300,12 @@ test_remove_destroys (CuTest *tc)
p11_dict_free (map);
- CuAssertIntEquals (tc, false, key.freed);
- CuAssertIntEquals (tc, 0, value);
+ assert_num_eq (false, key.freed);
+ assert_num_eq (0, value);
}
static void
-test_set_destroys (CuTest *tc)
+test_set_destroys (void)
{
p11_dict *map;
Key key = { 8, 0 };
@@ -314,88 +314,88 @@ test_set_destroys (CuTest *tc)
bool ret;
map = p11_dict_new (key_hash, key_equal, key_destroy, value_destroy);
- CuAssertPtrNotNull (tc, map);
+ assert_ptr_not_null (map);
if (!p11_dict_set (map, &key, &value))
- CuFail (tc, "should not be reached");
+ assert_not_reached ();
key.freed = key2.freed = false;
value = value2 = 0;
/* Setting same key and value, should not be destroyed */
ret = p11_dict_set (map, &key, &value);
- CuAssertIntEquals (tc, true, ret);
- CuAssertIntEquals (tc, false, key.freed);
- CuAssertIntEquals (tc, false, key2.freed);
- CuAssertIntEquals (tc, 0, value);
- CuAssertIntEquals (tc, 0, value2);
+ assert_num_eq (true, ret);
+ assert_num_eq (false, key.freed);
+ assert_num_eq (false, key2.freed);
+ assert_num_eq (0, value);
+ assert_num_eq (0, value2);
key.freed = key2.freed = false;
value = value2 = 0;
/* Setting a new key same value, key should be destroyed */
ret = p11_dict_set (map, &key2, &value);
- CuAssertIntEquals (tc, true, ret);
- CuAssertIntEquals (tc, true, key.freed);
- CuAssertIntEquals (tc, false, key2.freed);
- CuAssertIntEquals (tc, 0, value);
- CuAssertIntEquals (tc, 0, value2);
+ assert_num_eq (true, ret);
+ assert_num_eq (true, key.freed);
+ assert_num_eq (false, key2.freed);
+ assert_num_eq (0, value);
+ assert_num_eq (0, value2);
key.freed = key2.freed = false;
value = value2 = 0;
/* Setting same key, new value, value should be destroyed */
ret = p11_dict_set (map, &key2, &value2);
- CuAssertIntEquals (tc, true, ret);
- CuAssertIntEquals (tc, false, key.freed);
- CuAssertIntEquals (tc, false, key2.freed);
- CuAssertIntEquals (tc, 2, value);
- CuAssertIntEquals (tc, 0, value2);
+ assert_num_eq (true, ret);
+ assert_num_eq (false, key.freed);
+ assert_num_eq (false, key2.freed);
+ assert_num_eq (2, value);
+ assert_num_eq (0, value2);
key.freed = key2.freed = false;
value = value2 = 0;
/* Setting new key new value, both should be destroyed */
ret = p11_dict_set (map, &key, &value);
- CuAssertIntEquals (tc, true, ret);
- CuAssertIntEquals (tc, false, key.freed);
- CuAssertIntEquals (tc, true, key2.freed);
- CuAssertIntEquals (tc, 0, value);
- CuAssertIntEquals (tc, 2, value2);
+ assert_num_eq (true, ret);
+ assert_num_eq (false, key.freed);
+ assert_num_eq (true, key2.freed);
+ assert_num_eq (0, value);
+ assert_num_eq (2, value2);
key.freed = key2.freed = false;
value = value2 = 0;
p11_dict_free (map);
- CuAssertIntEquals (tc, true, key.freed);
- CuAssertIntEquals (tc, 2, value);
- CuAssertIntEquals (tc, false, key2.freed);
- CuAssertIntEquals (tc, 0, value2);
+ assert_num_eq (true, key.freed);
+ assert_num_eq (2, value);
+ assert_num_eq (false, key2.freed);
+ assert_num_eq (0, value2);
}
static void
-test_clear_destroys (CuTest *tc)
+test_clear_destroys (void)
{
p11_dict *map;
Key key = { 18, 0 };
int value = 0;
map = p11_dict_new (key_hash, key_equal, key_destroy, value_destroy);
- CuAssertPtrNotNull (tc, map);
+ assert_ptr_not_null (map);
if (!p11_dict_set (map, &key, &value))
- CuFail (tc, "should not be reached");
+ assert_not_reached ();
p11_dict_clear (map);
- CuAssertIntEquals (tc, true, key.freed);
- CuAssertIntEquals (tc, 2, value);
+ assert_num_eq (true, key.freed);
+ assert_num_eq (2, value);
/* should not be destroyed again */
key.freed = false;
value = 0;
p11_dict_clear (map);
- CuAssertIntEquals (tc, false, key.freed);
- CuAssertIntEquals (tc, 0, value);
+ assert_num_eq (false, key.freed);
+ assert_num_eq (0, value);
/* should not be destroyed again */
key.freed = false;
@@ -403,8 +403,8 @@ test_clear_destroys (CuTest *tc)
p11_dict_free (map);
- CuAssertIntEquals (tc, false, key.freed);
- CuAssertIntEquals (tc, 0, value);
+ assert_num_eq (false, key.freed);
+ assert_num_eq (0, value);
}
static unsigned int
@@ -415,7 +415,7 @@ test_hash_intptr_with_collisions (const void *data)
}
static void
-test_hash_add_check_lots_and_collisions (CuTest *tc)
+test_hash_add_check_lots_and_collisions (void)
{
p11_dict *map;
int *value;
@@ -428,20 +428,20 @@ test_hash_add_check_lots_and_collisions (CuTest *tc)
value = malloc (sizeof (int));
*value = i;
if (!p11_dict_set (map, value, value))
- CuFail (tc, "should not be reached");
+ assert_not_reached ();
}
for (i = 0; i < 20000; ++i) {
value = p11_dict_get (map, &i);
- CuAssertPtrNotNull (tc, value);
- CuAssertIntEquals (tc, i, *value);
+ assert_ptr_not_null (value);
+ assert_num_eq (i, *value);
}
p11_dict_free (map);
}
static void
-test_hash_count (CuTest *tc)
+test_hash_count (void)
{
p11_dict *map;
int *value;
@@ -450,30 +450,30 @@ test_hash_count (CuTest *tc)
map = p11_dict_new (p11_dict_intptr_hash, p11_dict_intptr_equal, NULL, free);
- CuAssertIntEquals (tc, 0, p11_dict_size (map));
+ assert_num_eq (0, p11_dict_size (map));
for (i = 0; i < 20000; ++i) {
value = malloc (sizeof (int));
*value = i;
if (!p11_dict_set (map, value, value))
- CuFail (tc, "should not be reached");
- CuAssertIntEquals (tc, i + 1, p11_dict_size (map));
+ assert_not_reached ();
+ assert_num_eq (i + 1, p11_dict_size (map));
}
for (i = 0; i < 20000; ++i) {
ret = p11_dict_remove (map, &i);
- CuAssertIntEquals (tc, true, ret);
- CuAssertIntEquals (tc, 20000 - (i + 1), p11_dict_size (map));
+ assert_num_eq (true, ret);
+ assert_num_eq (20000 - (i + 1), p11_dict_size (map));
}
p11_dict_clear (map);
- CuAssertIntEquals (tc, 0, p11_dict_size (map));
+ assert_num_eq (0, p11_dict_size (map));
p11_dict_free (map);
}
static void
-test_hash_ulongptr (CuTest *tc)
+test_hash_ulongptr (void)
{
p11_dict *map;
unsigned long *value;
@@ -485,47 +485,35 @@ test_hash_ulongptr (CuTest *tc)
value = malloc (sizeof (unsigned long));
*value = i;
if (!p11_dict_set (map, value, value))
- CuFail (tc, "should not be reached");
+ assert_not_reached ();
}
for (i = 0; i < 20000; ++i) {
value = p11_dict_get (map, &i);
- CuAssertPtrNotNull (tc, value);
- CuAssertIntEquals (tc, i, *value);
+ assert_ptr_not_null (value);
+ assert_num_eq (i, *value);
}
p11_dict_free (map);
}
int
-main (void)
+main (int argc,
+ char *argv[])
{
- CuString *output = CuStringNew ();
- CuSuite* suite = CuSuiteNew ();
- int ret;
-
- SUITE_ADD_TEST (suite, test_create);
- SUITE_ADD_TEST (suite, test_set_get);
- SUITE_ADD_TEST (suite, test_set_get_remove);
- SUITE_ADD_TEST (suite, test_remove_destroys);
- SUITE_ADD_TEST (suite, test_set_clear);
- SUITE_ADD_TEST (suite, test_set_destroys);
- SUITE_ADD_TEST (suite, test_clear_destroys);
- SUITE_ADD_TEST (suite, test_free_null);
- SUITE_ADD_TEST (suite, test_free_destroys);
- SUITE_ADD_TEST (suite, test_iterate);
- SUITE_ADD_TEST (suite, test_iterate_remove);
- SUITE_ADD_TEST (suite, test_hash_add_check_lots_and_collisions);
- SUITE_ADD_TEST (suite, test_hash_count);
- SUITE_ADD_TEST (suite, test_hash_ulongptr);
-
- 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_create, "/dict/create");
+ p11_test (test_set_get, "/dict/set-get");
+ p11_test (test_set_get_remove, "/dict/set-get-remove");
+ p11_test (test_remove_destroys, "/dict/remove-destroys");
+ p11_test (test_set_clear, "/dict/set-clear");
+ p11_test (test_set_destroys, "/dict/set-destroys");
+ p11_test (test_clear_destroys, "/dict/clear-destroys");
+ p11_test (test_free_null, "/dict/free-null");
+ p11_test (test_free_destroys, "/dict/free-destroys");
+ p11_test (test_iterate, "/dict/iterate");
+ p11_test (test_iterate_remove, "/dict/iterate-remove");
+ p11_test (test_hash_add_check_lots_and_collisions, "/dict/add-check-lots-and-collisions");
+ p11_test (test_hash_count, "/dict/count");
+ p11_test (test_hash_ulongptr, "/dict/ulongptr");
+ return p11_test_run (argc, argv);
}
diff --git a/common/tests/test-hash.c b/common/tests/test-hash.c
index eecf09b..c679cad 100644
--- a/common/tests/test-hash.c
+++ b/common/tests/test-hash.c
@@ -33,7 +33,7 @@
*/
#include "config.h"
-#include "CuTest.h"
+#include "test.h"
#include <assert.h>
#include <stdint.h>
@@ -56,7 +56,7 @@ const char *sha1_checksum[] = {
};
static void
-test_sha1 (CuTest *cu)
+test_sha1 (void)
{
unsigned char checksum[P11_HASH_SHA1_LEN];
size_t len;
@@ -67,28 +67,28 @@ test_sha1 (CuTest *cu)
len = strlen (sha1_input[i]);
p11_hash_sha1 (checksum, sha1_input[i], len, NULL);
- CuAssertTrue (cu, memcmp (sha1_checksum[i], checksum, P11_HASH_SHA1_LEN) == 0);
+ assert (memcmp (sha1_checksum[i], checksum, P11_HASH_SHA1_LEN) == 0);
if (len > 6) {
p11_hash_sha1 (checksum, sha1_input[i], 6, sha1_input[i] + 6, len - 6, NULL);
- CuAssertTrue (cu, memcmp (sha1_checksum[i], checksum, P11_HASH_SHA1_LEN) == 0);
+ assert (memcmp (sha1_checksum[i], checksum, P11_HASH_SHA1_LEN) == 0);
}
}
}
static void
-test_sha1_long (CuTest *cu)
+test_sha1_long (void)
{
unsigned char checksum[P11_HASH_SHA1_LEN];
char *expected = "\x34\xAA\x97\x3C\xD4\xC4\xDA\xA4\xF6\x1E\xEB\x2B\xDB\xAD\x27\x31\x65\x34\x01\x6F";
char *input;
input = malloc (1000000);
- CuAssertTrue (cu, input != NULL);
+ assert (input != NULL);
memset (input, 'a', 1000000);
p11_hash_sha1 (checksum, input, 1000000, NULL);
- CuAssertTrue (cu, memcmp (expected, checksum, P11_HASH_SHA1_LEN) == 0);
+ assert (memcmp (expected, checksum, P11_HASH_SHA1_LEN) == 0);
free (input);
}
@@ -112,7 +112,7 @@ const char *md5_checksum[] = {
};
static void
-test_md5 (CuTest *cu)
+test_md5 (void)
{
unsigned char checksum[P11_HASH_MD5_LEN];
size_t len;
@@ -123,17 +123,17 @@ test_md5 (CuTest *cu)
len = strlen (md5_input[i]);
p11_hash_md5 (checksum, md5_input[i], len, NULL);
- CuAssertTrue (cu, memcmp (md5_checksum[i], checksum, P11_HASH_MD5_LEN) == 0);
+ assert (memcmp (md5_checksum[i], checksum, P11_HASH_MD5_LEN) == 0);
if (len > 5) {
p11_hash_md5 (checksum, md5_input[i], 5, md5_input[i] + 5, len - 5, NULL);
- CuAssertTrue (cu, memcmp (md5_checksum[i], checksum, P11_HASH_MD5_LEN) == 0);
+ assert (memcmp (md5_checksum[i], checksum, P11_HASH_MD5_LEN) == 0);
}
}
}
static void
-test_murmur2 (CuTest *cu)
+test_murmur3 (void)
{
uint32_t one, two, four, seven, eleven, split;
@@ -146,23 +146,23 @@ test_murmur2 (CuTest *cu)
p11_hash_murmur3 ((unsigned char *)&eleven, "eleven", 6, NULL);
p11_hash_murmur3 ((unsigned char *)&split, "ele", 3, "ven", 3, NULL);
- CuAssertTrue (cu, one != two);
- CuAssertTrue (cu, one != four);
- CuAssertTrue (cu, one != seven);
- CuAssertTrue (cu, one != eleven);
+ assert (one != two);
+ assert (one != four);
+ assert (one != seven);
+ assert (one != eleven);
- CuAssertTrue (cu, two != four);
- CuAssertTrue (cu, two != seven);
- CuAssertTrue (cu, two != eleven);
+ assert (two != four);
+ assert (two != seven);
+ assert (two != eleven);
- CuAssertTrue (cu, four != seven);
- CuAssertTrue (cu, four != eleven);
+ assert (four != seven);
+ assert (four != eleven);
- CuAssertTrue (cu, split == eleven);
+ assert (split == eleven);
}
static void
-test_murmur2_incr (CuTest *cu)
+test_murmur3_incr (void)
{
uint32_t first, second;
@@ -182,29 +182,17 @@ test_murmur2_incr (CuTest *cu)
"!", (size_t)1,
NULL);
- CuAssertIntEquals (cu, first, second);
+ assert_num_eq (first, second);
}
int
-main (void)
+main (int argc,
+ char *argv[])
{
- CuString *output = CuStringNew ();
- CuSuite* suite = CuSuiteNew ();
- int ret;
-
- SUITE_ADD_TEST (suite, test_sha1);
- SUITE_ADD_TEST (suite, test_sha1_long);
- SUITE_ADD_TEST (suite, test_md5);
- SUITE_ADD_TEST (suite, test_murmur2);
- SUITE_ADD_TEST (suite, test_murmur2_incr);
-
- 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_sha1, "/hash/sha1");
+ p11_test (test_sha1_long, "/hash/sha1-long");
+ p11_test (test_md5, "/hash/md5");
+ p11_test (test_murmur3, "/hash/murmur3");
+ p11_test (test_murmur3_incr, "/hash/murmur3-incr");
+ return p11_test_run (argc, argv);
}
diff --git a/common/tests/test-lexer.c b/common/tests/test-lexer.c
index 58d5d65..ff18a89 100644
--- a/common/tests/test-lexer.c
+++ b/common/tests/test-lexer.c
@@ -33,7 +33,7 @@
*/
#include "config.h"
-#include "CuTest.h"
+#include "test.h"
#include <stdlib.h>
#include <stdio.h>
@@ -62,9 +62,9 @@ on_pem_get_type (const char *type,
}
static void
-check_lex_msg (CuTest *tc,
- const char *file,
+check_lex_msg (const char *file,
int line,
+ const char *function,
const expected_tok *expected,
const char *input,
bool failure)
@@ -77,60 +77,63 @@ check_lex_msg (CuTest *tc,
p11_lexer_init (&lexer, "test", input, strlen (input));
for (i = 0; p11_lexer_next (&lexer, &failed); i++) {
- CuAssertIntEquals_LineMsg (tc, file, line,
- "lexer token type does not match",
- expected[i].tok_type, lexer.tok_type);
+ if (expected[i].tok_type != lexer.tok_type)
+ p11_test_fail (file, line, function,
+ "lexer token type does not match: (%d != %d)",
+ expected[i].tok_type, lexer.tok_type);
switch (lexer.tok_type) {
case TOK_FIELD:
- CuAssertStrEquals_LineMsg (tc, file, line,
- "field name doesn't match",
- expected[i].name, lexer.tok.field.name);
- CuAssertStrEquals_LineMsg (tc, file, line,
- "field value doesn't match",
- expected[i].value, lexer.tok.field.value);
+ if (strcmp (expected[i].name, lexer.tok.field.name) != 0)
+ p11_test_fail (file, line, function,
+ "field name doesn't match: (%s != %s)",
+ expected[i].name, lexer.tok.field.name);
+ if (strcmp (expected[i].value, lexer.tok.field.value) != 0)
+ p11_test_fail (file, line, function,
+ "field value doesn't match: (%s != %s)",
+ expected[i].value, lexer.tok.field.value);
break;
case TOK_SECTION:
- CuAssertStrEquals_LineMsg (tc, file, line,
- "section name doesn't match",
- expected[i].name, lexer.tok.field.name);
+ if (strcmp (expected[i].name, lexer.tok.field.name) != 0)
+ p11_test_fail (file, line, function,
+ "section name doesn't match: (%s != %s)",
+ expected[i].name, lexer.tok.field.name);
break;
case TOK_PEM:
type = NULL;
count = p11_pem_parse (lexer.tok.pem.begin, lexer.tok.pem.length,
on_pem_get_type, &type);
- CuAssertIntEquals_LineMsg (tc, file, line,
- "wrong number of PEM blocks",
- 1, count);
- CuAssertStrEquals_LineMsg (tc, file, line,
- "wrong type of PEM block",
- expected[i].name, type);
+ if (count != 1)
+ p11_test_fail (file, line, function, "more than one PEM block: %d", count);
+ if (strcmp (expected[i].name, type) != 0)
+ p11_test_fail (file, line, function,
+ "wrong type of PEM block: (%s != %s)",
+ expected[i].name, type);
free (type);
break;
case TOK_EOF:
- CuFail_Line (tc, file, line, NULL, "eof should not be recieved");
+ p11_test_fail (file, line, function, "eof should not be recieved");
break;
}
}
- if (failure)
- CuAssert_Line (tc, file, line, "lexing didn't fail", failed);
- else
- CuAssert_Line (tc, file, line, "lexing failed", !failed);
- CuAssertIntEquals_LineMsg (tc, file, line,
- "premature end of lexing",
- TOK_EOF, expected[i].tok_type);
+ if (failure && !failed)
+ p11_test_fail (file, line, function, "lexing didn't fail");
+ else if (!failure && failed)
+ p11_test_fail (file, line, function, "lexing failed");
+ if (TOK_EOF != expected[i].tok_type)
+ p11_test_fail (file, line, function, "premature end of lexing");
p11_lexer_done (&lexer);
}
-#define check_lex_success(tc, expected, input) \
- check_lex_msg (tc, __FILE__, __LINE__, expected, input, false)
+#define check_lex_success(expected, input) \
+ check_lex_msg (__FILE__, __LINE__, __FUNCTION__, expected, input, false)
-#define check_lex_failure(tc, expected, input) \
- check_lex_msg (tc, __FILE__, __LINE__, expected, input, true)
+#define check_lex_failure(expected, input) \
+ check_lex_msg (__FILE__, __LINE__, __FUNCTION__, expected, input, true)
static void
-test_basic (CuTest *tc)
+test_basic (void)
{
const char *input = "[the header]\n"
"field: value\n"
@@ -145,11 +148,11 @@ test_basic (CuTest *tc)
{ TOK_EOF }
};
- check_lex_success (tc, expected, input);
+ check_lex_success (expected, input);
}
static void
-test_corners (CuTest *tc)
+test_corners (void)
{
const char *input = "\r\n" /* blankline */
" [the header]\r\n" /* bad line endings */
@@ -175,11 +178,11 @@ test_corners (CuTest *tc)
{ TOK_EOF }
};
- check_lex_success (tc, expected, input);
+ check_lex_success (expected, input);
}
static void
-test_following (CuTest *tc)
+test_following (void)
{
const char *input = "-----BEGIN BLOCK1-----\n"
"aYNNXqshlVxCdo8QfKeXh3GUzd/yn4LYIVgQrx4a\n"
@@ -192,11 +195,11 @@ test_following (CuTest *tc)
{ TOK_EOF }
};
- check_lex_success (tc, expected, input);
+ check_lex_success (expected, input);
}
static void
-test_bad_pem (CuTest *tc)
+test_bad_pem (void)
{
const char *input = "field: value\n"
"-----BEGIN BLOCK1-----\n"
@@ -209,13 +212,13 @@ test_bad_pem (CuTest *tc)
p11_message_quiet ();
- check_lex_failure (tc, expected, input);
+ check_lex_failure (expected, input);
p11_message_loud ();
}
static void
-test_bad_section (CuTest *tc)
+test_bad_section (void)
{
const char *input = "field: value\n"
"[section\n"
@@ -228,13 +231,13 @@ test_bad_section (CuTest *tc)
p11_message_quiet ();
- check_lex_failure (tc, expected, input);
+ check_lex_failure (expected, input);
p11_message_loud ();
}
static void
-test_bad_value (CuTest *tc)
+test_bad_value (void)
{
const char *input = "field_value\n"
"[section\n"
@@ -246,35 +249,20 @@ test_bad_value (CuTest *tc)
p11_message_quiet ();
- check_lex_failure (tc, expected, input);
+ check_lex_failure (expected, 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_basic);
- SUITE_ADD_TEST (suite, test_corners);
- SUITE_ADD_TEST (suite, test_following);
- SUITE_ADD_TEST (suite, test_bad_pem);
- SUITE_ADD_TEST (suite, test_bad_section);
- SUITE_ADD_TEST (suite, test_bad_value);
-
- 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_basic, "/lexer/basic");
+ p11_test (test_corners, "/lexer/corners");
+ p11_test (test_following, "/lexer/following");
+ p11_test (test_bad_pem, "/lexer/bad-pem");
+ p11_test (test_bad_section, "/lexer/bad-section");
+ p11_test (test_bad_value, "/lexer/bad-value");
+ return p11_test_run (argc, argv);
}
diff --git a/common/tests/test-oid.c b/common/tests/test-oid.c
index 71b8278..05945d9 100644
--- a/common/tests/test-oid.c
+++ b/common/tests/test-oid.c
@@ -33,7 +33,7 @@
*/
#include "config.h"
-#include "CuTest.h"
+#include "test.h"
#include <stdlib.h>
#include <stdio.h>
@@ -47,7 +47,7 @@
#include "pkix.asn.h"
static void
-test_known_oids (CuTest *cu)
+test_known_oids (void)
{
char buffer[128];
node_asn *definitions = NULL;
@@ -79,29 +79,29 @@ test_known_oids (CuTest *cu)
};
ret = asn1_array2tree (pkix_asn1_tab, &definitions, NULL);
- CuAssertTrue (cu, ret == ASN1_SUCCESS);
+ assert (ret == ASN1_SUCCESS);
for (i = 0; known_oids[i].oid != NULL; i++) {
- CuAssertTrue (cu, p11_oid_simple (known_oids[i].oid, known_oids[i].length));
- CuAssertIntEquals (cu, known_oids[i].length, p11_oid_length (known_oids[i].oid));
- CuAssertTrue (cu, p11_oid_equal (known_oids[i].oid, known_oids[i].oid));
+ assert (p11_oid_simple (known_oids[i].oid, known_oids[i].length));
+ assert_num_eq (known_oids[i].length, p11_oid_length (known_oids[i].oid));
+ assert (p11_oid_equal (known_oids[i].oid, known_oids[i].oid));
if (i > 0)
- CuAssertTrue (cu, !p11_oid_equal (known_oids[i].oid, known_oids[i - 1].oid));
+ assert (!p11_oid_equal (known_oids[i].oid, known_oids[i - 1].oid));
/* AttributeType is a OBJECT IDENTIFIER */
ret = asn1_create_element (definitions, "PKIX1.AttributeType", &node);
- CuAssertTrue (cu, ret == ASN1_SUCCESS);
+ assert (ret == ASN1_SUCCESS);
ret = asn1_der_decoding (&node, known_oids[i].oid, known_oids[i].length, NULL);
- CuAssertTrue (cu, ret == ASN1_SUCCESS);
+ assert (ret == ASN1_SUCCESS);
len = sizeof (buffer);
ret = asn1_read_value (node, "", buffer, &len);
- CuAssertTrue (cu, ret == ASN1_SUCCESS);
+ assert (ret == ASN1_SUCCESS);
- CuAssertStrEquals (cu, known_oids[i].string, buffer);
+ assert_str_eq (known_oids[i].string, buffer);
asn1_delete_structure (&node);
}
@@ -110,24 +110,9 @@ test_known_oids (CuTest *cu)
}
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_known_oids);
-
- 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_known_oids, "/oids/known");
+ return p11_test_run (argc, argv);
}
diff --git a/common/tests/test-path.c b/common/tests/test-path.c
index def4199..54d6f29 100644
--- a/common/tests/test-path.c
+++ b/common/tests/test-path.c
@@ -33,7 +33,7 @@
*/
#include "config.h"
-#include "CuTest.h"
+#include "test.h"
#include <stdlib.h>
#include <stdio.h>
@@ -43,7 +43,7 @@
#include "path.h"
static void
-test_base (CuTest *tc)
+test_base (void)
{
struct {
const char *in;
@@ -70,27 +70,16 @@ test_base (CuTest *tc)
for (i = 0; fixtures[i].in != NULL; i++) {
out = p11_path_base (fixtures[i].in);
- CuAssertStrEquals (tc, fixtures[i].out, out);
+ assert_str_eq (fixtures[i].out, out);
free (out);
}
}
-static void
-check_equals_and_free_msg (CuTest *tc,
- const char *file,
- int line,
- const char *ex,
- char *ac)
-{
- CuAssertStrEquals_LineMsg (tc, file, line, NULL, ex, ac);
- free (ac);
-}
-
#define check_equals_and_free(tc, ex, ac) \
- check_equals_and_free_msg ((tc), __FILE__, __LINE__, (ex), (ac))
+ do { assert_str_eq (ex, ac); free (ac); } while (0)
static void
-test_build (CuTest *tc)
+test_build (void)
{
#ifdef OS_UNIX
check_equals_and_free (tc, "/root/second",
@@ -118,7 +107,7 @@ test_build (CuTest *tc)
}
static void
-test_expand (CuTest *tc)
+test_expand (void)
{
char *path;
@@ -151,52 +140,41 @@ test_expand (CuTest *tc)
putenv("HOME=");
path = p11_path_expand ("$HOME/this/is/my/path");
- CuAssertTrue (tc, strstr (path, "this/is/my/path") != NULL);
+ assert (strstr (path, "this/is/my/path") != NULL);
free (path);
putenv("HOME=");
path = p11_path_expand ("~/this/is/my/path");
- CuAssertTrue (tc, strstr (path, "this/is/my/path") != NULL);
+ assert (strstr (path, "this/is/my/path") != NULL);
free (path);
putenv("TEMP=");
path = p11_path_expand ("$TEMP/this/is/my/path");
- CuAssertTrue (tc, strstr (path, "this/is/my/path") != NULL);
+ assert (strstr (path, "this/is/my/path") != NULL);
free (path);
}
static void
-test_absolute (CuTest *tc)
+test_absolute (void)
{
#ifdef OS_UNIX
- CuAssertTrue (tc, p11_path_absolute ("/home"));
- CuAssertTrue (tc, !p11_path_absolute ("home"));
+ assert (p11_path_absolute ("/home"));
+ assert (!p11_path_absolute ("home"));
#else /* OS_WIN32 */
- CuAssertTrue (tc, p11_path_absolute ("C:\\home"));
- CuAssertTrue (tc, !p11_path_absolute ("home"));
- CuAssertTrue (tc, p11_path_absolute ("/home"));
+ assert (p11_path_absolute ("C:\\home"));
+ assert (!p11_path_absolute ("home"));
+ assert (p11_path_absolute ("/home"));
#endif
}
int
-main (void)
+main (int argc,
+ char *argv[])
{
- CuString *output = CuStringNew ();
- CuSuite* suite = CuSuiteNew ();
- int ret;
-
- SUITE_ADD_TEST (suite, test_base);
- SUITE_ADD_TEST (suite, test_build);
- SUITE_ADD_TEST (suite, test_expand);
- SUITE_ADD_TEST (suite, test_absolute);
-
- 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_base, "/path/base");
+ p11_test (test_build, "/path/build");
+ p11_test (test_expand, "/path/expand");
+ p11_test (test_absolute, "/path/absolute");
+
+ return p11_test_run (argc, argv);
}
diff --git a/common/tests/test-pem.c b/common/tests/test-pem.c
index 54a59d6..7dd7fb2 100644
--- a/common/tests/test-pem.c
+++ b/common/tests/test-pem.c
@@ -33,7 +33,7 @@
*/
#include "config.h"
-#include "CuTest.h"
+#include "test.h"
#include <stdlib.h>
#include <stdio.h>
@@ -125,7 +125,6 @@ struct {
};
typedef struct {
- CuTest *cu;
int input_index;
int output_index;
int parsed;
@@ -139,8 +138,8 @@ on_parse_pem_success (const char *type,
{
Closure *cl = user_data;
- CuAssertIntEquals (cl->cu, success_fixtures[cl->input_index].output[cl->output_index].length, length);
- CuAssertTrue (cl->cu, memcmp (success_fixtures[cl->input_index].output[cl->output_index].data, contents,
+ assert_num_eq (success_fixtures[cl->input_index].output[cl->output_index].length, length);
+ assert (memcmp (success_fixtures[cl->input_index].output[cl->output_index].data, contents,
success_fixtures[cl->input_index].output[cl->output_index].length) == 0);
cl->output_index++;
@@ -148,7 +147,7 @@ on_parse_pem_success (const char *type,
}
static void
-test_pem_success (CuTest *cu)
+test_pem_success (void)
{
Closure cl;
int ret;
@@ -156,7 +155,6 @@ test_pem_success (CuTest *cu)
int j;
for (i = 0; success_fixtures[i].input != NULL; i++) {
- cl.cu = cu;
cl.input_index = i;
cl.output_index = 0;
cl.parsed = 0;
@@ -164,12 +162,12 @@ test_pem_success (CuTest *cu)
ret = p11_pem_parse (success_fixtures[i].input, strlen (success_fixtures[i].input),
on_parse_pem_success, &cl);
- CuAssertTrue (cu, success_fixtures[i].output[cl.output_index].type == NULL);
+ assert (success_fixtures[i].output[cl.output_index].type == NULL);
/* Count number of outputs, return from p11_pem_parse() should match */
for (j = 0; success_fixtures[i].output[j].type != NULL; j++);
- CuAssertIntEquals (cu, j, ret);
- CuAssertIntEquals (cu, ret, cl.parsed);
+ assert_num_eq (j, ret);
+ assert_num_eq (ret, cl.parsed);
}
}
@@ -215,20 +213,19 @@ on_parse_pem_failure (const char *type,
size_t length,
void *user_data)
{
- CuTest *cu = user_data;
- CuAssertTrue (cu, false && "not reached");
+ assert (false && "not reached");
}
static void
-test_pem_failure (CuTest *cu)
+test_pem_failure (void)
{
int ret;
int i;
for (i = 0; failure_fixtures[i] != NULL; i++) {
ret = p11_pem_parse (failure_fixtures[i], strlen (failure_fixtures[i]),
- on_parse_pem_failure, cu);
- CuAssertIntEquals (cu, 0, ret);
+ on_parse_pem_failure, NULL);
+ assert_num_eq (0, ret);
}
}
@@ -239,11 +236,6 @@ typedef struct {
const char *output;
} WriteFixture;
-typedef struct {
- CuTest *cu;
- WriteFixture *fixture;
-} WriteClosure;
-
static WriteFixture write_fixtures[] = {
{
"\x69\x83\x4d\x5e\xab\x21\x95\x5c\x42\x76\x8f\x10\x7c\xa7\x97\x87"
@@ -303,18 +295,17 @@ on_parse_written (const char *type,
size_t length,
void *user_data)
{
- WriteClosure *cl = user_data;
+ WriteFixture *fixture = user_data;
- CuAssertStrEquals (cl->cu, cl->fixture->type, type);
- CuAssertIntEquals (cl->cu, cl->fixture->length, length);
- CuAssertTrue (cl->cu, memcmp (contents, cl->fixture->input, length) == 0);
+ assert_str_eq (fixture->type, type);
+ assert_num_eq (fixture->length, length);
+ assert (memcmp (contents, fixture->input, length) == 0);
}
static void
-test_pem_write (CuTest *cu)
+test_pem_write (void)
{
WriteFixture *fixture;
- WriteClosure cl;
size_t length;
char *output;
unsigned int count;
@@ -326,37 +317,22 @@ test_pem_write (CuTest *cu)
output = p11_pem_write ((unsigned char *)fixture->input,
fixture->length,
fixture->type, &length);
- CuAssertStrEquals (cu, fixture->output, output);
- CuAssertIntEquals (cu, strlen (fixture->output), length);
-
- cl.fixture = fixture;
- cl.cu = cu;
+ assert_str_eq (fixture->output, output);
+ assert_num_eq (strlen (fixture->output), length);
- count = p11_pem_parse (output, length, on_parse_written, &cl);
- CuAssertIntEquals (cu, 1, count);
+ count = p11_pem_parse (output, length, on_parse_written, fixture);
+ assert_num_eq (1, count);
free (output);
}
}
int
-main (void)
+main (int argc,
+ char *argv[])
{
- CuString *output = CuStringNew ();
- CuSuite* suite = CuSuiteNew ();
- int ret;
-
- SUITE_ADD_TEST (suite, test_pem_success);
- SUITE_ADD_TEST (suite, test_pem_failure);
- SUITE_ADD_TEST (suite, test_pem_write);
-
- 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_pem_success, "/pem/success");
+ p11_test (test_pem_failure, "/pem/failure");
+ p11_test (test_pem_write, "/pem/write");
+ return p11_test_run (argc, argv);
}
diff --git a/common/tests/test-url.c b/common/tests/test-url.c
index ed84f0c..4c62594 100644
--- a/common/tests/test-url.c
+++ b/common/tests/test-url.c
@@ -33,7 +33,7 @@
*/
#include "config.h"
-#include "CuTest.h"
+#include "test.h"
#include "debug.h"
#include "message.h"
@@ -46,9 +46,9 @@
#include "url.h"
static void
-check_decode_msg (CuTest *tc,
- const char *file,
+check_decode_msg (const char *file,
int line,
+ const char *function,
const char *input,
ssize_t input_len,
const char *expected,
@@ -62,106 +62,97 @@ check_decode_msg (CuTest *tc,
decoded = p11_url_decode (input, input + input_len, "", &length);
if (expected == NULL) {
- CuAssert_Line (tc, file, line, "decoding should have failed", decoded == NULL);
+ if (decoded != NULL)
+ p11_test_fail (file, line, function, "decoding should have failed");
} else {
- CuAssert_Line (tc, file, line, "decoding failed", decoded != NULL);
- CuAssertIntEquals_LineMsg (tc, file, line, "wrong length", expected_len, length);
- CuAssert_Line (tc, file, line, "decoded wrong", memcmp (decoded, expected, length) == 0);
+ if (decoded == NULL)
+ p11_test_fail (file, line, function, "decoding failed");
+ if (expected_len != length)
+ p11_test_fail (file, line, function, "wrong length: (%lu != %lu)",
+ (unsigned long)expected_len, (unsigned long)length);
+ if (memcmp (decoded, expected, length) != 0)
+ p11_test_fail (file, line, function, "decoding wrong");
free (decoded);
}
}
-#define check_decode_success(tc, input, input_len, expected, expected_len) \
- check_decode_msg (tc, __FILE__, __LINE__, input, input_len, expected, expected_len)
+#define check_decode_success(input, input_len, expected, expected_len) \
+ check_decode_msg (__FILE__, __LINE__, __FUNCTION__, input, input_len, expected, expected_len)
-#define check_decode_failure(tc, input, input_len) \
- check_decode_msg (tc, __FILE__, __LINE__, input, input_len, NULL, 0)
+#define check_decode_failure(input, input_len) \
+ check_decode_msg (__FILE__, __LINE__, __FUNCTION__, input, input_len, NULL, 0)
static void
-test_decode_success (CuTest *tc)
+test_decode_success (void)
{
- check_decode_success (tc, "%54%45%53%54%00", -1, "TEST", 5);
- check_decode_success (tc, "%54%45%53%54%00", 6, "TE", 2);
- check_decode_success (tc, "%54est%00", -1, "Test", 5);
+ check_decode_success ("%54%45%53%54%00", -1, "TEST", 5);
+ check_decode_success ("%54%45%53%54%00", 6, "TE", 2);
+ check_decode_success ("%54est%00", -1, "Test", 5);
}
static void
-test_decode_skip (CuTest *tc)
+test_decode_skip (void)
{
const char *input = "%54 %45 %53 %54 %00";
unsigned char *decoded;
size_t length;
decoded = p11_url_decode (input, input + strlen (input), P11_URL_WHITESPACE, &length);
- CuAssertStrEquals (tc, "TEST", (char *)decoded);
- CuAssertIntEquals (tc, 5, length);
+ assert_str_eq ("TEST", (char *)decoded);
+ assert_num_eq (5, length);
free (decoded);
}
static void
-test_decode_failure (CuTest *tc)
+test_decode_failure (void)
{
/* Early termination */
- check_decode_failure (tc, "%54%45%53%5", -1);
- check_decode_failure (tc, "%54%45%53%", -1);
+ check_decode_failure ("%54%45%53%5", -1);
+ check_decode_failure ("%54%45%53%", -1);
/* Not hex characters */
- check_decode_failure (tc, "%54%XX%53%54%00", -1);
+ check_decode_failure ("%54%XX%53%54%00", -1);
}
static void
-test_encode (CuTest *tc)
+test_encode (void)
{
const unsigned char *input = (unsigned char *)"TEST";
char *encoded;
size_t length;
encoded = p11_url_encode (input, input + 5, "", &length);
- CuAssertStrEquals (tc, "%54%45%53%54%00", (char *)encoded);
- CuAssertIntEquals (tc, 15, length);
+ assert_str_eq ("%54%45%53%54%00", (char *)encoded);
+ assert_num_eq (15, length);
free (encoded);
}
static void
-test_encode_verbatim (CuTest *tc)
+test_encode_verbatim (void)
{
const unsigned char *input = (unsigned char *)"TEST";
char *encoded;
size_t length;
encoded = p11_url_encode (input, input + 5, "ES", &length);
- CuAssertStrEquals (tc, "%54ES%54%00", (char *)encoded);
- CuAssertIntEquals (tc, 11, length);
+ assert_str_eq ("%54ES%54%00", (char *)encoded);
+ assert_num_eq (11, length);
free (encoded);
}
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_decode_success);
- SUITE_ADD_TEST (suite, test_decode_skip);
- SUITE_ADD_TEST (suite, test_decode_failure);
-
- SUITE_ADD_TEST (suite, test_encode);
- SUITE_ADD_TEST (suite, test_encode_verbatim);
-
- 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_decode_success, "/url/decode-success");
+ p11_test (test_decode_skip, "/url/decode-skip");
+ p11_test (test_decode_failure, "/url/decode-failure");
+
+ p11_test (test_encode, "/url/encode");
+ p11_test (test_encode_verbatim, "/url/encode-verbatim");
+ return p11_test_run (argc, argv);
}
diff --git a/common/tests/test-utf8.c b/common/tests/test-utf8.c
index ed13fa2..9b2c3d5 100644
--- a/common/tests/test-utf8.c
+++ b/common/tests/test-utf8.c
@@ -33,7 +33,7 @@
*/
#include "config.h"
-#include "CuTest.h"
+#include "test.h"
#include "utf8.h"
@@ -43,7 +43,7 @@
#define ELEMS(x) (sizeof (x) / sizeof (x[0]))
static void
-test_ucs2be (CuTest *cu)
+test_ucs2be (void)
{
char *output;
size_t length;
@@ -73,14 +73,14 @@ test_ucs2be (CuTest *cu)
fixtures[i].input_len,
&length);
- CuAssertIntEquals (cu, fixtures[i].output_len, length);
- CuAssertStrEquals (cu, fixtures[i].output, output);
+ assert_num_eq (fixtures[i].output_len, length);
+ assert_str_eq (fixtures[i].output, output);
free (output);
}
}
static void
-test_ucs2be_fail (CuTest *cu)
+test_ucs2be_fail (void)
{
char *output;
size_t length;
@@ -97,12 +97,12 @@ test_ucs2be_fail (CuTest *cu)
output = p11_utf8_for_ucs2be (fixtures[i].input,
fixtures[i].input_len,
&length);
- CuAssertPtrEquals (cu, NULL, output);
+ assert_ptr_eq (NULL, output);
}
}
static void
-test_ucs4be (CuTest *cu)
+test_ucs4be (void)
{
char *output;
size_t length;
@@ -146,15 +146,15 @@ test_ucs4be (CuTest *cu)
fixtures[i].input_len,
&length);
- CuAssertIntEquals (cu, fixtures[i].output_len, length);
- CuAssertStrEquals (cu, fixtures[i].output, output);
+ assert_num_eq (fixtures[i].output_len, length);
+ assert_str_eq (fixtures[i].output, output);
free (output);
}
}
static void
-test_ucs4be_fail (CuTest *cu)
+test_ucs4be_fail (void)
{
char *output;
size_t length;
@@ -179,12 +179,12 @@ test_ucs4be_fail (CuTest *cu)
output = p11_utf8_for_ucs4be (fixtures[i].input,
fixtures[i].input_len,
&length);
- CuAssertPtrEquals (cu, NULL, output);
+ assert_ptr_eq (NULL, output);
}
}
static void
-test_utf8 (CuTest *cu)
+test_utf8 (void)
{
bool ret;
int i;
@@ -203,12 +203,12 @@ test_utf8 (CuTest *cu)
for (i = 0; i < ELEMS (fixtures); i++) {
ret = p11_utf8_validate (fixtures[i].input,
fixtures[i].input_len);
- CuAssertIntEquals (cu, true, ret);
+ assert_num_eq (true, ret);
}
}
static void
-test_utf8_fail (CuTest *cu)
+test_utf8_fail (void)
{
bool ret;
int i;
@@ -226,31 +226,19 @@ test_utf8_fail (CuTest *cu)
for (i = 0; i < ELEMS (fixtures); i++) {
ret = p11_utf8_validate (fixtures[i].input,
fixtures[i].input_len);
- CuAssertIntEquals (cu, false, ret);
+ assert_num_eq (false, ret);
}
}
int
-main (void)
+main (int argc,
+ char *argv[])
{
- CuString *output = CuStringNew ();
- CuSuite* suite = CuSuiteNew ();
- int ret;
-
- SUITE_ADD_TEST (suite, test_ucs2be);
- SUITE_ADD_TEST (suite, test_ucs2be_fail);
- SUITE_ADD_TEST (suite, test_ucs4be);
- SUITE_ADD_TEST (suite, test_ucs4be_fail);
- SUITE_ADD_TEST (suite, test_utf8);
- SUITE_ADD_TEST (suite, test_utf8_fail);
-
- 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_ucs2be, "/utf8/ucs2be");
+ p11_test (test_ucs2be_fail, "/utf8/ucs2be_fail");
+ p11_test (test_ucs4be, "/utf8/ucs4be");
+ p11_test (test_ucs4be_fail, "/utf8/ucs4be_fail");
+ p11_test (test_utf8, "/utf8/utf8");
+ p11_test (test_utf8_fail, "/utf8/utf8_fail");
+ return p11_test_run (argc, argv);
}
diff --git a/common/tests/test-x509.c b/common/tests/test-x509.c
index 2596c9c..9f7d258 100644
--- a/common/tests/test-x509.c
+++ b/common/tests/test-x509.c
@@ -33,7 +33,7 @@
*/
#include "config.h"
-#include "CuTest.h"
+#include "test.h"
#include "asn1.h"
#include "debug.h"
@@ -51,14 +51,14 @@ struct {
} test;
static void
-setup (CuTest *cu)
+setup (void *unused)
{
test.asn1_defs = p11_asn1_defs_load ();
- CuAssertPtrNotNull (cu, test.asn1_defs);
+ assert_ptr_not_null (test.asn1_defs);
}
static void
-teardown (CuTest *cu)
+teardown (void *unused)
{
p11_dict_free (test.asn1_defs);
memset (&test, 0, sizeof (test));
@@ -226,29 +226,25 @@ struct {
};
static void
-test_parse_extended_key_usage (CuTest *cu)
+test_parse_extended_key_usage (void)
{
p11_array *ekus;
int i, j, count;
- setup (cu);
-
for (i = 0; extended_key_usage_fixtures[i].eku != NULL; i++) {
ekus = p11_x509_parse_extended_key_usage (test.asn1_defs,
(const unsigned char *)extended_key_usage_fixtures[i].eku,
extended_key_usage_fixtures[i].length);
- CuAssertPtrNotNull (cu, ekus);
+ assert_ptr_not_null (ekus);
for (count = 0; extended_key_usage_fixtures[i].expected[count] != NULL; count++);
- CuAssertIntEquals (cu, count, ekus->num);
+ assert_num_eq (count, ekus->num);
for (j = 0; j < count; j++)
- CuAssertStrEquals (cu, ekus->elem[j], extended_key_usage_fixtures[i].expected[j]);
+ assert_str_eq (ekus->elem[j], extended_key_usage_fixtures[i].expected[j]);
p11_array_free (ekus);
}
-
- teardown (cu);
}
struct {
@@ -263,82 +259,70 @@ struct {
};
static void
-test_parse_key_usage (CuTest *cu)
+test_parse_key_usage (void)
{
unsigned int ku;
int i;
bool ret;
- setup (cu);
-
for (i = 0; key_usage_fixtures[i].ku != NULL; i++) {
ku = 0;
ret = p11_x509_parse_key_usage (test.asn1_defs,
(const unsigned char *)key_usage_fixtures[i].ku,
key_usage_fixtures[i].length, &ku);
- CuAssertIntEquals (cu, true, ret);
+ assert_num_eq (true, ret);
- CuAssertIntEquals (cu, key_usage_fixtures[i].expected, ku);
+ assert_num_eq (key_usage_fixtures[i].expected, ku);
}
-
- teardown (cu);
}
static void
-test_parse_extension (CuTest *cu)
+test_parse_extension (void)
{
node_asn *cert;
unsigned char *ext;
size_t length;
bool is_ca;
- setup (cu);
-
cert = p11_asn1_decode (test.asn1_defs, "PKIX1.Certificate",
test_cacert3_ca_der, sizeof (test_cacert3_ca_der), NULL);
- CuAssertPtrNotNull (cu, cert);
+ assert_ptr_not_null (cert);
ext = p11_x509_find_extension (cert, P11_OID_BASIC_CONSTRAINTS,
test_cacert3_ca_der, sizeof (test_cacert3_ca_der),
&length);
- CuAssertPtrNotNull (cu, ext);
- CuAssertTrue (cu, length > 0);
+ assert_ptr_not_null (ext);
+ assert (length > 0);
asn1_delete_structure (&cert);
if (!p11_x509_parse_basic_constraints (test.asn1_defs, ext, length, &is_ca))
- CuFail (cu, "failed to parse message");
+ assert_fail ("failed to parse message", "basic constraints");
free (ext);
-
- teardown (cu);
}
static void
-test_parse_extension_not_found (CuTest *cu)
+test_parse_extension_not_found (void)
{
node_asn *cert;
unsigned char *ext;
size_t length;
- setup (cu);
-
cert = p11_asn1_decode (test.asn1_defs, "PKIX1.Certificate",
test_cacert3_ca_der, sizeof (test_cacert3_ca_der), NULL);
- CuAssertPtrNotNull (cu, cert);
+ assert_ptr_not_null (cert);
ext = p11_x509_find_extension (cert, P11_OID_OPENSSL_REJECT,
test_cacert3_ca_der, sizeof (test_cacert3_ca_der),
&length);
- CuAssertPtrEquals (cu, NULL, ext);
+ assert_ptr_eq (NULL, ext);
asn1_delete_structure (&cert);
-
- teardown (cu);
}
static void
-test_directory_string (CuTest *tc)
+test_directory_string (void)
{
struct {
unsigned char input[100];
@@ -392,17 +376,17 @@ test_directory_string (CuTest *tc)
string = p11_x509_parse_directory_string (fixtures[i].input,
fixtures[i].input_len,
&unknown, &length);
- CuAssertPtrNotNull (tc, string);
- CuAssertIntEquals (tc, false, unknown);
+ assert_ptr_not_null (string);
+ assert_num_eq (false, unknown);
- CuAssertIntEquals (tc, fixtures[i].output_len, length);
- CuAssertStrEquals (tc, fixtures[i].output, string);
+ assert_num_eq (fixtures[i].output_len, length);
+ assert_str_eq (fixtures[i].output, string);
free (string);
}
}
static void
-test_directory_string_unknown (CuTest *tc)
+test_directory_string_unknown (void)
{
/* Not a valid choice in DirectoryString */
unsigned char input[] = { 0x05, 0x07, 'A', ' ', ' ', 'n', 'i', 'c', 'e' };
@@ -411,34 +395,22 @@ test_directory_string_unknown (CuTest *tc)
size_t length;
string = p11_x509_parse_directory_string (input, sizeof (input), &unknown, &length);
- CuAssertPtrEquals (tc, NULL, string);
- CuAssertIntEquals (tc, true, unknown);
+ assert_ptr_eq (NULL, string);
+ assert_num_eq (true, unknown);
}
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_parse_extended_key_usage);
- SUITE_ADD_TEST (suite, test_parse_key_usage);
- SUITE_ADD_TEST (suite, test_parse_extension);
- SUITE_ADD_TEST (suite, test_parse_extension_not_found);
- SUITE_ADD_TEST (suite, test_directory_string);
- SUITE_ADD_TEST (suite, test_directory_string_unknown);
-
- 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_parse_extended_key_usage, "/x509/parse-extended-key-usage");
+ p11_test (test_parse_key_usage, "/x509/parse-key-usage");
+ p11_test (test_parse_extension, "/x509/parse-extension");
+ p11_test (test_parse_extension_not_found, "/x509/parse-extension-not-found");
+
+ p11_fixture (NULL, NULL);
+ p11_test (test_directory_string, "/x509/directory-string");
+ p11_test (test_directory_string_unknown, "/x509/directory-string-unknown");
+ return p11_test_run (argc, argv);
}
diff --git a/p11-kit/tests/Makefile.am b/p11-kit/tests/Makefile.am
index f385d2a..4a3eaee 100644
--- a/p11-kit/tests/Makefile.am
+++ b/p11-kit/tests/Makefile.am
@@ -7,20 +7,20 @@ INCLUDES = \
-I$(top_srcdir) \
-I$(srcdir)/.. \
-I$(COMMON) \
- $(CUTEST_CFLAGS)
+ $(TEST_CFLAGS)
LDADD = \
$(top_builddir)/p11-kit/libp11-kit-testable.la \
- $(top_builddir)/common/libp11-mock.la \
+ $(top_builddir)/common/libp11-test.la \
$(top_builddir)/common/libp11-common.la \
$(CUTEST_LIBS) \
$(LTLIBINTL)
CHECK_PROGS = \
- progname-test \
- conf-test \
- uri-test \
- pin-test \
+ test-progname \
+ test-conf \
+ test-uri \
+ test-pin \
test-init \
test-modules \
test-deprecated \
@@ -57,7 +57,7 @@ mock_one_la_CFLAGS = \
$(AM_CFLAGS)
mock_one_la_LIBADD = \
- $(top_builddir)/common/libp11-mock.la \
+ $(top_builddir)/common/libp11-test.la \
$(top_builddir)/common/libp11-common.la \
$(NULL)
diff --git a/p11-kit/tests/conf-test.c b/p11-kit/tests/test-conf.c
index d259cf8..c214bac 100644
--- a/p11-kit/tests/conf-test.c
+++ b/p11-kit/tests/test-conf.c
@@ -33,7 +33,7 @@
*/
#include "config.h"
-#include "CuTest.h"
+#include "test.h"
#include <errno.h>
#include <stdlib.h>
@@ -47,54 +47,54 @@
#include "private.h"
static void
-test_parse_conf_1 (CuTest *tc)
+test_parse_conf_1 (void)
{
p11_dict *map;
const char *value;
map = _p11_conf_parse_file (SRCDIR "/files/test-1.conf", 0);
- CuAssertPtrNotNull (tc, map);
+ assert_ptr_not_null (map);
value = p11_dict_get (map, "key1");
- CuAssertStrEquals (tc, "value1", value);
+ assert_str_eq ("value1", value);
value = p11_dict_get (map, "with-colon");
- CuAssertStrEquals (tc, "value-of-colon", value);
+ assert_str_eq ("value-of-colon", value);
value = p11_dict_get (map, "with-whitespace");
- CuAssertStrEquals (tc, "value-with-whitespace", value);
+ assert_str_eq ("value-with-whitespace", value);
value = p11_dict_get (map, "embedded-comment");
- CuAssertStrEquals (tc, "this is # not a comment", value);
+ assert_str_eq ("this is # not a comment", value);
p11_dict_free (map);
}
static void
-test_parse_ignore_missing (CuTest *tc)
+test_parse_ignore_missing (void)
{
p11_dict *map;
map = _p11_conf_parse_file (SRCDIR "/files/non-existant.conf", CONF_IGNORE_MISSING);
- CuAssertPtrNotNull (tc, map);
+ assert_ptr_not_null (map);
- CuAssertIntEquals (tc, 0, p11_dict_size (map));
- CuAssertPtrEquals (tc, NULL, (void*)p11_message_last ());
+ assert_num_eq (0, p11_dict_size (map));
+ assert (p11_message_last () == NULL);
p11_dict_free (map);
}
static void
-test_parse_fail_missing (CuTest *tc)
+test_parse_fail_missing (void)
{
p11_dict *map;
map = _p11_conf_parse_file (SRCDIR "/files/non-existant.conf", 0);
- CuAssertPtrEquals (tc, map, NULL);
- CuAssertPtrNotNull (tc, p11_message_last ());
+ assert (map == NULL);
+ assert_ptr_not_null (p11_message_last ());
}
static void
-test_merge_defaults (CuTest *tc)
+test_merge_defaults (void)
{
p11_dict *values;
p11_dict *defaults;
@@ -109,19 +109,19 @@ test_merge_defaults (CuTest *tc)
p11_dict_set (defaults, strdup ("three"), strdup ("default3"));
if (!_p11_conf_merge_defaults (values, defaults))
- CuFail (tc, "should not be reached");
+ assert_not_reached ();
p11_dict_free (defaults);
- CuAssertStrEquals (tc, p11_dict_get (values, "one"), "real1");
- CuAssertStrEquals (tc, p11_dict_get (values, "two"), "real2");
- CuAssertStrEquals (tc, p11_dict_get (values, "three"), "default3");
+ assert_str_eq (p11_dict_get (values, "one"), "real1");
+ assert_str_eq (p11_dict_get (values, "two"), "real2");
+ assert_str_eq (p11_dict_get (values, "three"), "default3");
p11_dict_free (values);
}
static void
-test_load_globals_merge (CuTest *tc)
+test_load_globals_merge (void)
{
int user_mode = -1;
p11_dict *config;
@@ -131,19 +131,19 @@ test_load_globals_merge (CuTest *tc)
config = _p11_conf_load_globals (SRCDIR "/files/test-system-merge.conf",
SRCDIR "/files/test-user.conf",
&user_mode);
- CuAssertPtrNotNull (tc, config);
- CuAssertStrEquals (tc, NULL, p11_message_last ());
- CuAssertIntEquals (tc, CONF_USER_MERGE, user_mode);
+ assert_ptr_not_null (config);
+ assert (NULL == p11_message_last ());
+ assert_num_eq (CONF_USER_MERGE, user_mode);
- CuAssertStrEquals (tc, p11_dict_get (config, "key1"), "system1");
- CuAssertStrEquals (tc, p11_dict_get (config, "key2"), "user2");
- CuAssertStrEquals (tc, p11_dict_get (config, "key3"), "user3");
+ assert_str_eq (p11_dict_get (config, "key1"), "system1");
+ assert_str_eq (p11_dict_get (config, "key2"), "user2");
+ assert_str_eq (p11_dict_get (config, "key3"), "user3");
p11_dict_free (config);
}
static void
-test_load_globals_no_user (CuTest *tc)
+test_load_globals_no_user (void)
{
int user_mode = -1;
p11_dict *config;
@@ -153,19 +153,19 @@ test_load_globals_no_user (CuTest *tc)
config = _p11_conf_load_globals (SRCDIR "/files/test-system-none.conf",
SRCDIR "/files/test-user.conf",
&user_mode);
- CuAssertPtrNotNull (tc, config);
- CuAssertStrEquals (tc, NULL, p11_message_last ());
- CuAssertIntEquals (tc, CONF_USER_NONE, user_mode);
+ assert_ptr_not_null (config);
+ assert (NULL == p11_message_last ());
+ assert_num_eq (CONF_USER_NONE, user_mode);
- CuAssertStrEquals (tc, p11_dict_get (config, "key1"), "system1");
- CuAssertStrEquals (tc, p11_dict_get (config, "key2"), "system2");
- CuAssertStrEquals (tc, p11_dict_get (config, "key3"), "system3");
+ assert_str_eq (p11_dict_get (config, "key1"), "system1");
+ assert_str_eq (p11_dict_get (config, "key2"), "system2");
+ assert_str_eq (p11_dict_get (config, "key3"), "system3");
p11_dict_free (config);
}
static void
-test_load_globals_user_sets_only (CuTest *tc)
+test_load_globals_user_sets_only (void)
{
int user_mode = -1;
p11_dict *config;
@@ -175,19 +175,19 @@ test_load_globals_user_sets_only (CuTest *tc)
config = _p11_conf_load_globals (SRCDIR "/files/test-system-merge.conf",
SRCDIR "/files/test-user-only.conf",
&user_mode);
- CuAssertPtrNotNull (tc, config);
- CuAssertStrEquals (tc, NULL, p11_message_last ());
- CuAssertIntEquals (tc, CONF_USER_ONLY, user_mode);
+ assert_ptr_not_null (config);
+ assert (NULL == p11_message_last ());
+ assert_num_eq (CONF_USER_ONLY, user_mode);
- CuAssertStrEquals (tc, p11_dict_get (config, "key1"), NULL);
- CuAssertStrEquals (tc, p11_dict_get (config, "key2"), "user2");
- CuAssertStrEquals (tc, p11_dict_get (config, "key3"), "user3");
+ assert (p11_dict_get (config, "key1") == NULL);
+ assert_str_eq (p11_dict_get (config, "key2"), "user2");
+ assert_str_eq (p11_dict_get (config, "key3"), "user3");
p11_dict_free (config);
}
static void
-test_load_globals_system_sets_only (CuTest *tc)
+test_load_globals_system_sets_only (void)
{
int user_mode = -1;
p11_dict *config;
@@ -197,19 +197,19 @@ test_load_globals_system_sets_only (CuTest *tc)
config = _p11_conf_load_globals (SRCDIR "/files/test-system-only.conf",
SRCDIR "/files/test-user.conf",
&user_mode);
- CuAssertPtrNotNull (tc, config);
- CuAssertStrEquals (tc, NULL, p11_message_last ());
- CuAssertIntEquals (tc, CONF_USER_ONLY, user_mode);
+ assert_ptr_not_null (config);
+ assert (NULL == p11_message_last ());
+ assert_num_eq (CONF_USER_ONLY, user_mode);
- CuAssertStrEquals (tc, p11_dict_get (config, "key1"), NULL);
- CuAssertStrEquals (tc, p11_dict_get (config, "key2"), "user2");
- CuAssertStrEquals (tc, p11_dict_get (config, "key3"), "user3");
+ assert (p11_dict_get (config, "key1") == NULL);
+ assert_str_eq (p11_dict_get (config, "key2"), "user2");
+ assert_str_eq (p11_dict_get (config, "key3"), "user3");
p11_dict_free (config);
}
static void
-test_load_globals_system_sets_invalid (CuTest *tc)
+test_load_globals_system_sets_invalid (void)
{
int user_mode = -1;
p11_dict *config;
@@ -221,15 +221,15 @@ test_load_globals_system_sets_invalid (CuTest *tc)
SRCDIR "/files/non-existant.conf",
&user_mode);
error = errno;
- CuAssertPtrEquals (tc, NULL, config);
- CuAssertIntEquals (tc, EINVAL, error);
- CuAssertPtrNotNull (tc, p11_message_last ());
+ assert_ptr_eq (NULL, config);
+ assert_num_eq (EINVAL, error);
+ assert_ptr_not_null (p11_message_last ());
p11_dict_free (config);
}
static void
-test_load_globals_user_sets_invalid (CuTest *tc)
+test_load_globals_user_sets_invalid (void)
{
int user_mode = -1;
p11_dict *config;
@@ -241,9 +241,9 @@ test_load_globals_user_sets_invalid (CuTest *tc)
SRCDIR "/files/test-user-invalid.conf",
&user_mode);
error = errno;
- CuAssertPtrEquals (tc, NULL, config);
- CuAssertIntEquals (tc, EINVAL, error);
- CuAssertPtrNotNull (tc, p11_message_last ());
+ assert_ptr_eq (NULL, config);
+ assert_num_eq (EINVAL, error);
+ assert_ptr_not_null (p11_message_last ());
p11_dict_free (config);
}
@@ -256,7 +256,7 @@ assert_msg_contains (const char *msg,
}
static void
-test_load_modules_merge (CuTest *tc)
+test_load_modules_merge (void)
{
p11_dict *configs;
p11_dict *config;
@@ -267,29 +267,29 @@ test_load_modules_merge (CuTest *tc)
SRCDIR "/files/package-modules",
SRCDIR "/files/system-modules",
SRCDIR "/files/user-modules");
- CuAssertPtrNotNull (tc, configs);
- CuAssertTrue (tc, assert_msg_contains (p11_message_last (), "invalid config filename"));
+ assert_ptr_not_null (configs);
+ assert (assert_msg_contains (p11_message_last (), "invalid config filename"));
config = p11_dict_get (configs, "one");
- CuAssertPtrNotNull (tc, config);
- CuAssertStrEquals (tc, "mock-one.so", p11_dict_get (config, "module"));
- CuAssertStrEquals (tc, p11_dict_get (config, "setting"), "user1");
+ assert_ptr_not_null (config);
+ assert_str_eq ("mock-one.so", p11_dict_get (config, "module"));
+ assert_str_eq (p11_dict_get (config, "setting"), "user1");
config = p11_dict_get (configs, "two.badname");
- CuAssertPtrNotNull (tc, config);
- CuAssertStrEquals (tc, "mock-two.so", p11_dict_get (config, "module"));
- CuAssertStrEquals (tc, p11_dict_get (config, "setting"), "system2");
+ assert_ptr_not_null (config);
+ assert_str_eq ("mock-two.so", p11_dict_get (config, "module"));
+ assert_str_eq (p11_dict_get (config, "setting"), "system2");
config = p11_dict_get (configs, "three");
- CuAssertPtrNotNull (tc, config);
- CuAssertStrEquals (tc, "mock-three.so", p11_dict_get (config, "module"));
- CuAssertStrEquals (tc, p11_dict_get (config, "setting"), "user3");
+ assert_ptr_not_null (config);
+ assert_str_eq ("mock-three.so", p11_dict_get (config, "module"));
+ assert_str_eq (p11_dict_get (config, "setting"), "user3");
p11_dict_free (configs);
}
static void
-test_load_modules_user_none (CuTest *tc)
+test_load_modules_user_none (void)
{
p11_dict *configs;
p11_dict *config;
@@ -300,27 +300,27 @@ test_load_modules_user_none (CuTest *tc)
SRCDIR "/files/package-modules",
SRCDIR "/files/system-modules",
SRCDIR "/files/user-modules");
- CuAssertPtrNotNull (tc, configs);
- CuAssertTrue (tc, assert_msg_contains (p11_message_last (), "invalid config filename"));
+ assert_ptr_not_null (configs);
+ assert (assert_msg_contains (p11_message_last (), "invalid config filename"));
config = p11_dict_get (configs, "one");
- CuAssertPtrNotNull (tc, config);
- CuAssertStrEquals (tc, "mock-one.so", p11_dict_get (config, "module"));
- CuAssertStrEquals (tc, p11_dict_get (config, "setting"), "system1");
+ assert_ptr_not_null (config);
+ assert_str_eq ("mock-one.so", p11_dict_get (config, "module"));
+ assert_str_eq (p11_dict_get (config, "setting"), "system1");
config = p11_dict_get (configs, "two.badname");
- CuAssertPtrNotNull (tc, config);
- CuAssertStrEquals (tc, "mock-two.so", p11_dict_get (config, "module"));
- CuAssertStrEquals (tc, p11_dict_get (config, "setting"), "system2");
+ assert_ptr_not_null (config);
+ assert_str_eq ("mock-two.so", p11_dict_get (config, "module"));
+ assert_str_eq (p11_dict_get (config, "setting"), "system2");
config = p11_dict_get (configs, "three");
- CuAssertPtrEquals (tc, NULL, config);
+ assert_ptr_eq (NULL, config);
p11_dict_free (configs);
}
static void
-test_load_modules_user_only (CuTest *tc)
+test_load_modules_user_only (void)
{
p11_dict *configs;
p11_dict *config;
@@ -331,27 +331,27 @@ test_load_modules_user_only (CuTest *tc)
SRCDIR "/files/package-modules",
SRCDIR "/files/system-modules",
SRCDIR "/files/user-modules");
- CuAssertPtrNotNull (tc, configs);
- CuAssertPtrEquals (tc, NULL, (void *)p11_message_last ());
+ assert_ptr_not_null (configs);
+ assert_ptr_eq (NULL, (void *)p11_message_last ());
config = p11_dict_get (configs, "one");
- CuAssertPtrNotNull (tc, config);
- CuAssertStrEquals (tc, p11_dict_get (config, "module"), NULL);
- CuAssertStrEquals (tc, p11_dict_get (config, "setting"), "user1");
+ assert_ptr_not_null (config);
+ assert (p11_dict_get (config, "module") == NULL);
+ assert_str_eq (p11_dict_get (config, "setting"), "user1");
config = p11_dict_get (configs, "two.badname");
- CuAssertPtrEquals (tc, NULL, config);
+ assert_ptr_eq (NULL, config);
config = p11_dict_get (configs, "three");
- CuAssertPtrNotNull (tc, config);
- CuAssertStrEquals (tc, "mock-three.so", p11_dict_get (config, "module"));
- CuAssertStrEquals (tc, p11_dict_get (config, "setting"), "user3");
+ assert_ptr_not_null (config);
+ assert_str_eq ("mock-three.so", p11_dict_get (config, "module"));
+ assert_str_eq (p11_dict_get (config, "setting"), "user3");
p11_dict_free (configs);
}
static void
-test_load_modules_no_user (CuTest *tc)
+test_load_modules_no_user (void)
{
p11_dict *configs;
p11_dict *config;
@@ -362,67 +362,53 @@ test_load_modules_no_user (CuTest *tc)
SRCDIR "/files/package-modules",
SRCDIR "/files/system-modules",
SRCDIR "/files/non-existant");
- CuAssertPtrNotNull (tc, configs);
- CuAssertTrue (tc, assert_msg_contains (p11_message_last (), "invalid config filename"));
+ assert_ptr_not_null (configs);
+ assert (assert_msg_contains (p11_message_last (), "invalid config filename"));
config = p11_dict_get (configs, "one");
- CuAssertPtrNotNull (tc, config);
- CuAssertStrEquals (tc, "mock-one.so", p11_dict_get (config, "module"));
- CuAssertStrEquals (tc, p11_dict_get (config, "setting"), "system1");
+ assert_ptr_not_null (config);
+ assert_str_eq ("mock-one.so", p11_dict_get (config, "module"));
+ assert_str_eq (p11_dict_get (config, "setting"), "system1");
config = p11_dict_get (configs, "two.badname");
- CuAssertPtrNotNull (tc, config);
- CuAssertStrEquals (tc, "mock-two.so", p11_dict_get (config, "module"));
- CuAssertStrEquals (tc, p11_dict_get (config, "setting"), "system2");
+ assert_ptr_not_null (config);
+ assert_str_eq ("mock-two.so", p11_dict_get (config, "module"));
+ assert_str_eq (p11_dict_get (config, "setting"), "system2");
config = p11_dict_get (configs, "three");
- CuAssertPtrEquals (tc, NULL, config);
+ assert_ptr_eq (NULL, config);
p11_dict_free (configs);
}
static void
-test_parse_boolean (CuTest *tc)
+test_parse_boolean (void)
{
p11_message_quiet ();
- CuAssertIntEquals (tc, true, _p11_conf_parse_boolean ("yes", false));
- CuAssertIntEquals (tc, false, _p11_conf_parse_boolean ("no", true));
- CuAssertIntEquals (tc, true, _p11_conf_parse_boolean ("!!!", true));
+ assert_num_eq (true, _p11_conf_parse_boolean ("yes", false));
+ assert_num_eq (false, _p11_conf_parse_boolean ("no", true));
+ assert_num_eq (true, _p11_conf_parse_boolean ("!!!", true));
}
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_parse_conf_1);
- SUITE_ADD_TEST (suite, test_parse_ignore_missing);
- SUITE_ADD_TEST (suite, test_parse_fail_missing);
- SUITE_ADD_TEST (suite, test_merge_defaults);
- SUITE_ADD_TEST (suite, test_load_globals_merge);
- SUITE_ADD_TEST (suite, test_load_globals_no_user);
- SUITE_ADD_TEST (suite, test_load_globals_system_sets_only);
- SUITE_ADD_TEST (suite, test_load_globals_user_sets_only);
- SUITE_ADD_TEST (suite, test_load_globals_system_sets_invalid);
- SUITE_ADD_TEST (suite, test_load_globals_user_sets_invalid);
- SUITE_ADD_TEST (suite, test_load_modules_merge);
- SUITE_ADD_TEST (suite, test_load_modules_no_user);
- SUITE_ADD_TEST (suite, test_load_modules_user_only);
- SUITE_ADD_TEST (suite, test_load_modules_user_none);
- SUITE_ADD_TEST (suite, test_parse_boolean);
-
- 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_parse_conf_1, "/conf/test_parse_conf_1");
+ p11_test (test_parse_ignore_missing, "/conf/test_parse_ignore_missing");
+ p11_test (test_parse_fail_missing, "/conf/test_parse_fail_missing");
+ p11_test (test_merge_defaults, "/conf/test_merge_defaults");
+ p11_test (test_load_globals_merge, "/conf/test_load_globals_merge");
+ p11_test (test_load_globals_no_user, "/conf/test_load_globals_no_user");
+ p11_test (test_load_globals_system_sets_only, "/conf/test_load_globals_system_sets_only");
+ p11_test (test_load_globals_user_sets_only, "/conf/test_load_globals_user_sets_only");
+ p11_test (test_load_globals_system_sets_invalid, "/conf/test_load_globals_system_sets_invalid");
+ p11_test (test_load_globals_user_sets_invalid, "/conf/test_load_globals_user_sets_invalid");
+ p11_test (test_load_modules_merge, "/conf/test_load_modules_merge");
+ p11_test (test_load_modules_no_user, "/conf/test_load_modules_no_user");
+ p11_test (test_load_modules_user_only, "/conf/test_load_modules_user_only");
+ p11_test (test_load_modules_user_none, "/conf/test_load_modules_user_none");
+ p11_test (test_parse_boolean, "/conf/test_parse_boolean");
+ return p11_test_run (argc, argv);
}
diff --git a/p11-kit/tests/test-deprecated.c b/p11-kit/tests/test-deprecated.c
index 4509241..7ea8260 100644
--- a/p11-kit/tests/test-deprecated.c
+++ b/p11-kit/tests/test-deprecated.c
@@ -36,7 +36,7 @@
#define P11_KIT_NO_DEPRECATIONS
#include "config.h"
-#include "CuTest.h"
+#include "test.h"
#include "dict.h"
#include "library.h"
@@ -55,33 +55,32 @@
#include <unistd.h>
static CK_FUNCTION_LIST_PTR_PTR
-initialize_and_get_modules (CuTest *tc)
+initialize_and_get_modules (void)
{
CK_FUNCTION_LIST_PTR_PTR modules;
CK_RV rv;
rv = p11_kit_initialize_registered ();
- CuAssertIntEquals (tc, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
modules = p11_kit_registered_modules ();
- CuAssertTrue (tc, modules != NULL && modules[0] != NULL);
+ assert (modules != NULL && modules[0] != NULL);
return modules;
}
static void
-finalize_and_free_modules (CuTest *tc,
- CK_FUNCTION_LIST_PTR_PTR modules)
+finalize_and_free_modules (CK_FUNCTION_LIST_PTR_PTR modules)
{
CK_RV rv;
free (modules);
rv = p11_kit_finalize_registered ();
- CuAssertIntEquals (tc, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
}
static void
-test_no_duplicates (CuTest *tc)
+test_no_duplicates (void)
{
CK_FUNCTION_LIST_PTR_PTR modules;
p11_dict *paths;
@@ -89,7 +88,7 @@ test_no_duplicates (CuTest *tc)
char *path;
int i;
- modules = initialize_and_get_modules (tc);
+ modules = initialize_and_get_modules ();
paths = p11_dict_new (p11_dict_str_hash, p11_dict_str_equal, NULL, NULL);
funcs = p11_dict_new (p11_dict_direct_hash, p11_dict_direct_equal, NULL, NULL);
@@ -98,26 +97,25 @@ test_no_duplicates (CuTest *tc)
path = p11_kit_registered_option (modules[i], "module");
if (p11_dict_get (funcs, modules[i]))
- CuAssert (tc, "found duplicate function list pointer", 0);
+ assert_fail ("found duplicate function list pointer", NULL);
if (p11_dict_get (paths, path))
- CuAssert (tc, "found duplicate path name", 0);
+ assert_fail ("found duplicate path name", NULL);
if (!p11_dict_set (funcs, modules[i], ""))
- CuAssert (tc, "shouldn't be reached", 0);
+ assert_not_reached ();
if (!p11_dict_set (paths, path, ""))
- CuAssert (tc, "shouldn't be reached", 0);
+ assert_not_reached ();
free (path);
}
p11_dict_free (paths);
p11_dict_free (funcs);
- finalize_and_free_modules (tc, modules);
+ finalize_and_free_modules (modules);
}
static CK_FUNCTION_LIST_PTR
-lookup_module_with_name (CuTest *tc,
- CK_FUNCTION_LIST_PTR_PTR modules,
+lookup_module_with_name (CK_FUNCTION_LIST_PTR_PTR modules,
const char *name)
{
CK_FUNCTION_LIST_PTR match = NULL;
@@ -127,7 +125,7 @@ lookup_module_with_name (CuTest *tc,
for (i = 0; match == NULL && modules[i] != NULL; i++) {
module_name = p11_kit_registered_module_to_name (modules[i]);
- CuAssertPtrNotNull (tc, module_name);
+ assert_ptr_not_null (module_name);
if (strcmp (module_name, name) == 0)
match = modules[i];
free (module_name);
@@ -138,14 +136,14 @@ lookup_module_with_name (CuTest *tc,
* matches the above search.
*/
module = p11_kit_registered_name_to_module (name);
- CuAssert(tc, "different result from p11_kit_registered_name_to_module()",
- module == match);
+ if (module != match)
+ assert_fail ("different result from p11_kit_registered_name_to_module()", NULL);
return match;
}
static void
-test_disable (CuTest *tc)
+test_disable (void)
{
CK_FUNCTION_LIST_PTR_PTR modules;
@@ -154,9 +152,9 @@ test_disable (CuTest *tc)
* that it has disabled.
*/
- modules = initialize_and_get_modules (tc);
- CuAssertTrue (tc, lookup_module_with_name (tc, modules, "four") != NULL);
- finalize_and_free_modules (tc, modules);
+ modules = initialize_and_get_modules ();
+ assert (lookup_module_with_name (modules, "four") != NULL);
+ finalize_and_free_modules (modules);
/*
* The module two shouldn't have been loaded, because in its config
@@ -167,15 +165,15 @@ test_disable (CuTest *tc)
p11_kit_set_progname ("test-disable");
- modules = initialize_and_get_modules (tc);
- CuAssertTrue (tc, lookup_module_with_name (tc, modules, "four") == NULL);
- finalize_and_free_modules (tc, modules);
+ modules = initialize_and_get_modules ();
+ assert (lookup_module_with_name (modules, "four") == NULL);
+ finalize_and_free_modules (modules);
p11_kit_set_progname (NULL);
}
static void
-test_disable_later (CuTest *tc)
+test_disable_later (void)
{
CK_FUNCTION_LIST_PTR_PTR modules;
CK_RV rv;
@@ -188,21 +186,21 @@ test_disable_later (CuTest *tc)
*/
rv = p11_kit_initialize_registered ();
- CuAssertIntEquals (tc, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
p11_kit_set_progname ("test-disable");
modules = p11_kit_registered_modules ();
- CuAssertTrue (tc, modules != NULL && modules[0] != NULL);
+ assert (modules != NULL && modules[0] != NULL);
- CuAssertTrue (tc, lookup_module_with_name (tc, modules, "two") == NULL);
- finalize_and_free_modules (tc, modules);
+ assert (lookup_module_with_name (modules, "two") == NULL);
+ finalize_and_free_modules (modules);
p11_kit_set_progname (NULL);
}
static void
-test_enable (CuTest *tc)
+test_enable (void)
{
CK_FUNCTION_LIST_PTR_PTR modules;
@@ -211,9 +209,9 @@ test_enable (CuTest *tc)
* program.
*/
- modules = initialize_and_get_modules (tc);
- CuAssertTrue (tc, lookup_module_with_name (tc, modules, "three") == NULL);
- finalize_and_free_modules (tc, modules);
+ modules = initialize_and_get_modules ();
+ assert (lookup_module_with_name (modules, "three") == NULL);
+ finalize_and_free_modules (modules);
/*
* The module three should be loaded here , because in its config
@@ -224,9 +222,9 @@ test_enable (CuTest *tc)
p11_kit_set_progname ("test-enable");
- modules = initialize_and_get_modules (tc);
- CuAssertTrue (tc, lookup_module_with_name (tc, modules, "three") != NULL);
- finalize_and_free_modules (tc, modules);
+ modules = initialize_and_get_modules ();
+ assert (lookup_module_with_name (modules, "three") != NULL);
+ finalize_and_free_modules (modules);
p11_kit_set_progname (NULL);
}
@@ -265,23 +263,23 @@ mock_C_Initialize__with_fork (CK_VOID_PTR init_args)
}
static void
-test_fork_initialization (CuTest *tc)
+test_fork_initialization (void)
{
CK_RV rv;
- CuAssertTrue (tc, !mock_module_initialized ());
+ assert (!mock_module_initialized ());
/* Build up our own function list */
memcpy (&module, &mock_module_no_slots, sizeof (CK_FUNCTION_LIST));
module.C_Initialize = mock_C_Initialize__with_fork;
rv = p11_kit_initialize_module (&module);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = p11_kit_finalize_module (&module);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
- CuAssertTrue (tc, !mock_module_initialized ());
+ assert (!mock_module_initialized ());
}
#endif /* OS_UNIX */
@@ -294,20 +292,20 @@ mock_C_Initialize__with_recursive (CK_VOID_PTR init_args)
}
static void
-test_recursive_initialization (CuTest *tc)
+test_recursive_initialization (void)
{
CK_RV rv;
- CuAssertTrue (tc, !mock_module_initialized ());
+ assert (!mock_module_initialized ());
/* Build up our own function list */
memcpy (&module, &mock_module_no_slots, sizeof (CK_FUNCTION_LIST));
module.C_Initialize = mock_C_Initialize__with_recursive;
rv = p11_kit_initialize_module (&module);
- CuAssertTrue (tc, rv == CKR_FUNCTION_FAILED);
+ assert (rv == CKR_FUNCTION_FAILED);
- CuAssertTrue (tc, !mock_module_initialized ());
+ assert (!mock_module_initialized ());
}
static p11_mutex_t race_mutex;
@@ -341,36 +339,36 @@ mock_C_Finalize__threaded_race (CK_VOID_PTR reserved)
static void *
initialization_thread (void *data)
{
- CuTest *tc = data;
CK_RV rv;
+ assert_str_eq (data, "thread-data");
rv = p11_kit_initialize_module (&module);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
- return tc;
+ return "thread-data";
}
static void *
finalization_thread (void *data)
{
- CuTest *tc = data;
CK_RV rv;
+ assert_str_eq (data, "thread-data");
rv = p11_kit_finalize_module (&module);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
- return tc;
+ return "thread-data";
}
static void
-test_threaded_initialization (CuTest *tc)
+test_threaded_initialization (void)
{
static const int num_threads = 2;
p11_thread_t threads[num_threads];
int ret;
int i;
- CuAssertTrue (tc, !mock_module_initialized ());
+ assert (!mock_module_initialized ());
/* Build up our own function list */
memcpy (&module, &mock_module_no_slots, sizeof (CK_FUNCTION_LIST));
@@ -381,34 +379,34 @@ test_threaded_initialization (CuTest *tc)
finalization_count = 0;
for (i = 0; i < num_threads; i++) {
- ret = p11_thread_create (&threads[i], initialization_thread, tc);
- CuAssertIntEquals (tc, 0, ret);
- CuAssertTrue (tc, threads[i] != 0);
+ ret = p11_thread_create (&threads[i], initialization_thread, "thread-data");
+ assert_num_eq (0, ret);
+ assert (threads[i] != 0);
}
for (i = 0; i < num_threads; i++) {
ret = p11_thread_join (threads[i]);
- CuAssertIntEquals (tc, 0, ret);
+ assert_num_eq (0, ret);
threads[i] = 0;
}
for (i = 0; i < num_threads; i++) {
- ret = p11_thread_create (&threads[i], finalization_thread, tc);
- CuAssertIntEquals (tc, 0, ret);
- CuAssertTrue (tc, threads[i] != 0);
+ ret = p11_thread_create (&threads[i], finalization_thread, "thread-data");
+ assert_num_eq (0, ret);
+ assert (threads[i] != 0);
}
for (i = 0; i < num_threads; i++) {
ret = p11_thread_join (threads[i]);
- CuAssertIntEquals (tc, 0, ret);
+ assert_num_eq (0, ret);
threads[i] = 0;
}
/* C_Initialize should have been called exactly once */
- CuAssertIntEquals (tc, 1, initialization_count);
- CuAssertIntEquals (tc, 1, finalization_count);
+ assert_num_eq (1, initialization_count);
+ assert_num_eq (1, finalization_count);
- CuAssertTrue (tc, !mock_module_initialized ());
+ assert (!mock_module_initialized ());
}
static CK_RV
@@ -441,27 +439,27 @@ mock_C_Initialize__test_mutexes (CK_VOID_PTR args)
}
static void
-test_mutexes (CuTest *tc)
+test_mutexes (void)
{
CK_RV rv;
- CuAssertTrue (tc, !mock_module_initialized ());
+ assert (!mock_module_initialized ());
/* Build up our own function list */
memcpy (&module, &mock_module_no_slots, sizeof (CK_FUNCTION_LIST));
module.C_Initialize = mock_C_Initialize__test_mutexes;
rv = p11_kit_initialize_module (&module);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = p11_kit_finalize_module (&module);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
- CuAssertTrue (tc, !mock_module_initialized ());
+ assert (!mock_module_initialized ());
}
static void
-test_load_and_initialize (CuTest *tc)
+test_load_and_initialize (void)
{
CK_FUNCTION_LIST_PTR module;
CK_INFO info;
@@ -469,53 +467,42 @@ test_load_and_initialize (CuTest *tc)
int ret;
rv = p11_kit_load_initialize_module (BUILDDIR "/.libs/mock-one" SHLEXT, &module);
- CuAssertTrue (tc, rv == CKR_OK);
- CuAssertTrue (tc, module != NULL);
+ assert (rv == CKR_OK);
+ assert (module != NULL);
rv = (module->C_GetInfo) (&info);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
ret = memcmp (info.manufacturerID, "MOCK MANUFACTURER ", 32);
- CuAssertTrue (tc, ret == 0);
+ assert (ret == 0);
rv = p11_kit_finalize_module (module);
- CuAssertTrue (tc, ret == CKR_OK);
+ assert (ret == CKR_OK);
}
int
-main (void)
+main (int argc,
+ char *argv[])
{
- CuString *output = CuStringNew ();
- CuSuite* suite = CuSuiteNew ();
- int ret;
-
- putenv ("P11_KIT_STRICT=1");
p11_mutex_init (&race_mutex);
mock_module_init ();
p11_library_init ();
- SUITE_ADD_TEST (suite, test_no_duplicates);
- SUITE_ADD_TEST (suite, test_disable);
- SUITE_ADD_TEST (suite, test_disable_later);
- SUITE_ADD_TEST (suite, test_enable);
+ p11_test (test_no_duplicates, "/deprecated/test_no_duplicates");
+ p11_test (test_disable, "/deprecated/test_disable");
+ p11_test (test_disable_later, "/deprecated/test_disable_later");
+ p11_test (test_enable, "/deprecated/test_enable");
#ifdef OS_UNIX
- SUITE_ADD_TEST (suite, test_fork_initialization);
+ p11_test (test_fork_initialization, "/deprecated/test_fork_initialization");
#endif
- SUITE_ADD_TEST (suite, test_recursive_initialization);
- SUITE_ADD_TEST (suite, test_threaded_initialization);
- SUITE_ADD_TEST (suite, test_mutexes);
- SUITE_ADD_TEST (suite, test_load_and_initialize);
+ p11_test (test_recursive_initialization, "/deprecated/test_recursive_initialization");
+ p11_test (test_threaded_initialization, "/deprecated/test_threaded_initialization");
+ p11_test (test_mutexes, "/deprecated/test_mutexes");
+ p11_test (test_load_and_initialize, "/deprecated/test_load_and_initialize");
p11_kit_be_quiet ();
- CuSuiteRun (suite);
- CuSuiteSummary (suite, output);
- CuSuiteDetails (suite, output);
- printf ("%s\n", output->buffer);
- ret = suite->failCount;
- CuSuiteDelete (suite);
- CuStringDelete (output);
- return ret;
+ return p11_test_run (argc, argv);
}
diff --git a/p11-kit/tests/test-init.c b/p11-kit/tests/test-init.c
index dbeab46..76805ee 100644
--- a/p11-kit/tests/test-init.c
+++ b/p11-kit/tests/test-init.c
@@ -33,7 +33,7 @@
*/
#include "config.h"
-#include "CuTest.h"
+#include "test.h"
#include <sys/types.h>
@@ -86,7 +86,7 @@ mock_C_Initialize__with_fork (CK_VOID_PTR init_args)
}
static void
-test_fork_initialization (CuTest *tc)
+test_fork_initialization (void)
{
CK_FUNCTION_LIST_PTR result;
CK_RV rv;
@@ -100,20 +100,20 @@ test_fork_initialization (CuTest *tc)
p11_lock ();
rv = p11_module_load_inlock_reentrant (&module, 0, &result);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
p11_unlock ();
rv = p11_kit_module_initialize (result);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = p11_kit_module_finalize (result);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
p11_lock ();
rv = p11_module_release_inlock_reentrant (result);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
p11_unlock ();
}
@@ -134,7 +134,7 @@ mock_C_Initialize__with_recursive (CK_VOID_PTR init_args)
}
static void
-test_recursive_initialization (CuTest *tc)
+test_recursive_initialization (void)
{
CK_RV rv;
@@ -147,17 +147,17 @@ test_recursive_initialization (CuTest *tc)
p11_lock ();
rv = p11_module_load_inlock_reentrant (&module, 0, &recursive_managed);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
p11_unlock ();
rv = p11_kit_module_initialize (recursive_managed);
- CuAssertIntEquals (tc, CKR_FUNCTION_FAILED, rv);
+ assert_num_eq (CKR_FUNCTION_FAILED, rv);
p11_lock ();
rv = p11_module_release_inlock_reentrant (recursive_managed);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
p11_unlock ();
@@ -191,42 +191,37 @@ mock_C_Finalize__threaded_race (CK_VOID_PTR reserved)
return CKR_OK;
}
-typedef struct {
- CuTest *cu;
- CK_FUNCTION_LIST_PTR module;
-} ThreadData;
-
static void *
initialization_thread (void *data)
{
- ThreadData *td = data;
+ CK_FUNCTION_LIST *module = data;
CK_RV rv;
- assert (td->module != NULL);
- rv = p11_kit_module_initialize (td->module);
- CuAssertTrue (td->cu, rv == CKR_OK);
+ assert (module != NULL);
+ rv = p11_kit_module_initialize (module);
+ assert_num_eq (rv, CKR_OK);
- return td->cu;
+ return module;
}
static void *
finalization_thread (void *data)
{
- ThreadData *td = data;
+ CK_FUNCTION_LIST *module = data;
CK_RV rv;
- assert (td->module != NULL);
- rv = p11_kit_module_finalize (td->module);
- CuAssertTrue (td->cu, rv == CKR_OK);
+ assert (module != NULL);
+ rv = p11_kit_module_finalize (module);
+ assert_num_eq (rv, CKR_OK);
- return td->cu;
+ return module;
}
static void
-test_threaded_initialization (CuTest *tc)
+test_threaded_initialization (void)
{
static const int num_threads = 1;
- ThreadData data[num_threads];
+ CK_FUNCTION_LIST *data[num_threads];
p11_thread_t threads[num_threads];
CK_RV rv;
int ret;
@@ -244,51 +239,50 @@ test_threaded_initialization (CuTest *tc)
p11_lock ();
for (i = 0; i < num_threads; i++) {
- assert (data[i].module == NULL);
- rv = p11_module_load_inlock_reentrant (&module, 0, &data[i].module);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (data[i] == NULL);
+ rv = p11_module_load_inlock_reentrant (&module, 0, &data[i]);
+ assert (rv == CKR_OK);
}
p11_unlock ();
for (i = 0; i < num_threads; i++) {
- data[i].cu = tc;
- ret = p11_thread_create (&threads[i], initialization_thread, data + i);
- CuAssertIntEquals (tc, 0, ret);
- CuAssertTrue (tc, threads[i] != 0);
+ ret = p11_thread_create (&threads[i], initialization_thread, data[i]);
+ assert_num_eq (0, ret);
+ assert (threads[i] != 0);
}
for (i = 0; i < num_threads; i++) {
ret = p11_thread_join (threads[i]);
- CuAssertIntEquals (tc, 0, ret);
+ assert_num_eq (0, ret);
threads[i] = 0;
}
for (i = 0; i < num_threads; i++) {
- ret = p11_thread_create (&threads[i], finalization_thread, data + i);
- CuAssertIntEquals (tc, 0, ret);
- CuAssertTrue (tc, threads[i] != 0);
+ ret = p11_thread_create (&threads[i], finalization_thread, data[i]);
+ assert_num_eq (0, ret);
+ assert (threads[i] != 0);
}
for (i = 0; i < num_threads; i++) {
ret = p11_thread_join (threads[i]);
- CuAssertIntEquals (tc, 0, ret);
+ assert_num_eq (0, ret);
threads[i] = 0;
}
p11_lock ();
for (i = 0; i < num_threads; i++) {
- assert (data[i].module != NULL);
- rv = p11_module_release_inlock_reentrant (data[i].module);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (data[i] != NULL);
+ rv = p11_module_release_inlock_reentrant (data[i]);
+ assert (rv == CKR_OK);
}
p11_unlock ();
/* C_Initialize should have been called exactly once */
- CuAssertIntEquals (tc, 1, initialization_count);
- CuAssertIntEquals (tc, 1, finalization_count);
+ assert_num_eq (1, initialization_count);
+ assert_num_eq (1, finalization_count);
}
static CK_RV
@@ -317,7 +311,7 @@ mock_C_Initialize__test_mutexes (CK_VOID_PTR args)
}
static void
-test_mutexes (CuTest *tc)
+test_mutexes (void)
{
CK_FUNCTION_LIST_PTR result;
CK_RV rv;
@@ -329,16 +323,16 @@ test_mutexes (CuTest *tc)
p11_lock ();
rv = p11_module_load_inlock_reentrant (&module, 0, &result);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = p11_module_release_inlock_reentrant (result);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
p11_unlock ();
}
static void
-test_load_and_initialize (CuTest *tc)
+test_load_and_initialize (void)
{
CK_FUNCTION_LIST_PTR module;
CK_INFO info;
@@ -346,25 +340,25 @@ test_load_and_initialize (CuTest *tc)
int ret;
module = p11_kit_module_load (BUILDDIR "/.libs/mock-one" SHLEXT, 0);
- CuAssertTrue (tc, module != NULL);
+ assert (module != NULL);
rv = p11_kit_module_initialize (module);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = (module->C_GetInfo) (&info);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
ret = memcmp (info.manufacturerID, "MOCK MANUFACTURER ", 32);
- CuAssertTrue (tc, ret == 0);
+ assert (ret == 0);
rv = p11_kit_module_finalize (module);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
p11_kit_module_release (module);
}
static void
-test_initalize_fail (CuTest *tc)
+test_initalize_fail (void)
{
CK_FUNCTION_LIST failer;
CK_FUNCTION_LIST *modules[3] = { &mock_module_no_slots, &failer, NULL };
@@ -377,58 +371,46 @@ test_initalize_fail (CuTest *tc)
p11_kit_be_quiet ();
rv = p11_kit_modules_initialize (modules, NULL);
- CuAssertIntEquals (tc, CKR_FUNCTION_FAILED, rv);
+ assert_num_eq (CKR_FUNCTION_FAILED, rv);
p11_kit_be_loud ();
/* Failed modules get removed from the list */
- CuAssertPtrEquals (tc, &mock_module_no_slots, modules[0]);
- CuAssertPtrEquals (tc, NULL, modules[1]);
- CuAssertPtrEquals (tc, NULL, modules[2]);
+ assert_ptr_eq (&mock_module_no_slots, modules[0]);
+ assert_ptr_eq (NULL, modules[1]);
+ assert_ptr_eq (NULL, modules[2]);
p11_kit_modules_finalize (modules);
}
static void
-test_finalize_fail (CuTest *tc)
+test_finalize_fail (void)
{
}
int
-main (void)
+main (int argc,
+ char *argv[])
{
- CuString *output = CuStringNew ();
- CuSuite* suite = CuSuiteNew ();
- int ret;
-
- putenv ("P11_KIT_STRICT=1");
p11_mutex_init (&race_mutex);
mock_module_init ();
p11_library_init ();
/* These only work when managed */
if (p11_virtual_can_wrap ()) {
- SUITE_ADD_TEST (suite, test_recursive_initialization);
- SUITE_ADD_TEST (suite, test_threaded_initialization);
- SUITE_ADD_TEST (suite, test_mutexes);
- SUITE_ADD_TEST (suite, test_load_and_initialize);
+ p11_test (test_recursive_initialization, "/init/test_recursive_initialization");
+ p11_test (test_threaded_initialization, "/init/test_threaded_initialization");
+ p11_test (test_mutexes, "/init/test_mutexes");
+ p11_test (test_load_and_initialize, "/init/test_load_and_initialize");
#ifdef OS_UNIX
- SUITE_ADD_TEST (suite, test_fork_initialization);
+ p11_test (test_fork_initialization, "/init/test_fork_initialization");
#endif
}
- SUITE_ADD_TEST (suite, test_initalize_fail);
- SUITE_ADD_TEST (suite, test_finalize_fail);
-
- CuSuiteRun (suite);
- CuSuiteSummary (suite, output);
- CuSuiteDetails (suite, output);
- printf ("%s\n", output->buffer);
- ret = suite->failCount;
- CuSuiteDelete (suite);
- CuStringDelete (output);
+ p11_test (test_initalize_fail, "/init/test_initalize_fail");
+ p11_test (test_finalize_fail, "/init/test_finalize_fail");
- return ret;
+ return p11_test_run (argc, argv);
}
diff --git a/p11-kit/tests/test-iter.c b/p11-kit/tests/test-iter.c
index 451f4be..18b5ed6 100644
--- a/p11-kit/tests/test-iter.c
+++ b/p11-kit/tests/test-iter.c
@@ -33,7 +33,7 @@
*/
#include "config.h"
-#include "CuTest.h"
+#include "test.h"
#define P11_KIT_FUTURE_UNSTABLE_API 1
@@ -49,14 +49,14 @@
#include <stdlib.h>
static CK_FUNCTION_LIST_PTR_PTR
-initialize_and_get_modules (CuTest *tc)
+initialize_and_get_modules (void)
{
CK_FUNCTION_LIST_PTR_PTR modules;
p11_message_quiet ();
modules = p11_kit_modules_load_and_initialize (0);
- CuAssertTrue (tc, modules != NULL && modules[0] != NULL);
+ assert (modules != NULL && modules[0] != NULL);
p11_message_loud ();
@@ -64,8 +64,7 @@ initialize_and_get_modules (CuTest *tc)
}
static void
-finalize_and_free_modules (CuTest *tc,
- CK_FUNCTION_LIST_PTR_PTR modules)
+finalize_and_free_modules (CK_FUNCTION_LIST_PTR_PTR modules)
{
p11_kit_modules_finalize (modules);
p11_kit_modules_release (modules);
@@ -87,7 +86,7 @@ has_handle (CK_ULONG *objects,
static void
-test_all (CuTest *tc)
+test_all (void)
{
CK_OBJECT_HANDLE objects[128];
CK_FUNCTION_LIST_PTR *modules;
@@ -98,59 +97,60 @@ test_all (CuTest *tc)
CK_RV rv;
int at;
- modules = initialize_and_get_modules (tc);
+ modules = initialize_and_get_modules ();
iter = p11_kit_iter_new (NULL);
p11_kit_iter_begin (iter, modules);
at = 0;
while ((rv = p11_kit_iter_next (iter)) == CKR_OK) {
- CuAssertTrue (tc, at < 128);
+ assert (at < 128);
objects[at] = p11_kit_iter_get_object (iter);
module = p11_kit_iter_get_module (iter);
- CuAssertPtrNotNull (tc, module);
+ assert_ptr_not_null (module);
session = p11_kit_iter_get_session (iter);
- CuAssertTrue (tc, session != 0);
+ assert (session != 0);
/* Do something with the object */
size = 0;
rv = (module->C_GetObjectSize) (session, objects[at], &size);
- CuAssertTrue (tc, rv == CKR_OK);
- CuAssertTrue (tc, size > 0);
+ assert (rv == CKR_OK);
+ assert (size > 0);
at++;
}
- CuAssertTrue (tc, rv == CKR_CANCEL);
+ assert (rv == CKR_CANCEL);
/* Three modules, each with 1 slot, and 3 public objects */
- CuAssertIntEquals (tc, 9, at);
+ assert_num_eq (9, at);
- CuAssertTrue (tc, has_handle (objects, at, MOCK_DATA_OBJECT));
- CuAssertTrue (tc, !has_handle (objects, at, MOCK_PRIVATE_KEY_CAPITALIZE));
- CuAssertTrue (tc, has_handle (objects, at, MOCK_PUBLIC_KEY_CAPITALIZE));
- CuAssertTrue (tc, !has_handle (objects, at, MOCK_PRIVATE_KEY_PREFIX));
- CuAssertTrue (tc, has_handle (objects, at, MOCK_PUBLIC_KEY_PREFIX));
+ assert (has_handle (objects, at, MOCK_DATA_OBJECT));
+ assert (!has_handle (objects, at, MOCK_PRIVATE_KEY_CAPITALIZE));
+ assert (has_handle (objects, at, MOCK_PUBLIC_KEY_CAPITALIZE));
+ assert (!has_handle (objects, at, MOCK_PRIVATE_KEY_PREFIX));
+ assert (has_handle (objects, at, MOCK_PUBLIC_KEY_PREFIX));
p11_kit_iter_free (iter);
- finalize_and_free_modules (tc, modules);
+ finalize_and_free_modules (modules);
}
static CK_RV
on_iter_callback (P11KitIter *iter,
- CK_BBOOL *matches,
- void *data)
+ CK_BBOOL *matches,
+ void *data)
{
- CuTest *tc = data;
CK_OBJECT_HANDLE object;
CK_FUNCTION_LIST_PTR module;
CK_SESSION_HANDLE session;
CK_ULONG size;
CK_RV rv;
+ assert_str_eq (data, "callback");
+
object = p11_kit_iter_get_object (iter);
if (object != MOCK_PUBLIC_KEY_CAPITALIZE && object != MOCK_PUBLIC_KEY_PREFIX) {
*matches = CK_FALSE;
@@ -158,22 +158,22 @@ on_iter_callback (P11KitIter *iter,
}
module = p11_kit_iter_get_module (iter);
- CuAssertPtrNotNull (tc, module);
+ assert_ptr_not_null (module);
session = p11_kit_iter_get_session (iter);
- CuAssertTrue (tc, session != 0);
+ assert (session != 0);
/* Do something with the object */
size = 0;
rv = (module->C_GetObjectSize) (session, object, &size);
- CuAssertTrue (tc, rv == CKR_OK);
- CuAssertTrue (tc, size > 0);
+ assert (rv == CKR_OK);
+ assert (size > 0);
return CKR_OK;
}
static void
-test_callback (CuTest *tc)
+test_callback (void)
{
CK_OBJECT_HANDLE objects[128];
CK_FUNCTION_LIST_PTR *modules;
@@ -181,33 +181,33 @@ test_callback (CuTest *tc)
CK_RV rv;
int at;
- modules = initialize_and_get_modules (tc);
+ modules = initialize_and_get_modules ();
iter = p11_kit_iter_new (NULL);
- p11_kit_iter_add_callback (iter, on_iter_callback, tc, NULL);
+ p11_kit_iter_add_callback (iter, on_iter_callback, "callback", NULL);
p11_kit_iter_begin (iter, modules);
at= 0;
while ((rv = p11_kit_iter_next (iter)) == CKR_OK) {
- CuAssertTrue (tc, at < 128);
+ assert (at < 128);
objects[at] = p11_kit_iter_get_object (iter);
at++;
}
- CuAssertTrue (tc, rv == CKR_CANCEL);
+ assert (rv == CKR_CANCEL);
/* Three modules, each with 1 slot, and 2 public keys */
- CuAssertIntEquals (tc, 6, at);
+ assert_num_eq (6, at);
- CuAssertTrue (tc, !has_handle (objects, at, MOCK_DATA_OBJECT));
- CuAssertTrue (tc, !has_handle (objects, at, MOCK_PRIVATE_KEY_CAPITALIZE));
- CuAssertTrue (tc, has_handle (objects, at, MOCK_PUBLIC_KEY_CAPITALIZE));
- CuAssertTrue (tc, !has_handle (objects, at, MOCK_PRIVATE_KEY_PREFIX));
- CuAssertTrue (tc, has_handle (objects, at, MOCK_PUBLIC_KEY_PREFIX));
+ assert (!has_handle (objects, at, MOCK_DATA_OBJECT));
+ assert (!has_handle (objects, at, MOCK_PRIVATE_KEY_CAPITALIZE));
+ assert (has_handle (objects, at, MOCK_PUBLIC_KEY_CAPITALIZE));
+ assert (!has_handle (objects, at, MOCK_PRIVATE_KEY_PREFIX));
+ assert (has_handle (objects, at, MOCK_PUBLIC_KEY_PREFIX));
p11_kit_iter_free (iter);
- finalize_and_free_modules (tc, modules);
+ finalize_and_free_modules (modules);
}
static CK_RV
@@ -219,30 +219,30 @@ on_callback_fail (P11KitIter *iter,
}
static void
-test_callback_fails (CuTest *tc)
+test_callback_fails (void)
{
CK_FUNCTION_LIST_PTR *modules;
P11KitIter *iter;
CK_RV rv;
int at;
- modules = initialize_and_get_modules (tc);
+ modules = initialize_and_get_modules ();
iter = p11_kit_iter_new (NULL);
- p11_kit_iter_add_callback (iter, on_callback_fail, tc, NULL);
+ p11_kit_iter_add_callback (iter, on_callback_fail, "callback", NULL);
p11_kit_iter_begin (iter, modules);
at= 0;
while ((rv = p11_kit_iter_next (iter)) == CKR_OK)
at++;
- CuAssertTrue (tc, rv == CKR_DATA_INVALID);
+ assert (rv == CKR_DATA_INVALID);
/* Shouldn't have succeeded at all */
- CuAssertIntEquals (tc, 0, at);
+ assert_num_eq (0, at);
p11_kit_iter_free (iter);
- finalize_and_free_modules (tc, modules);
+ finalize_and_free_modules (modules);
}
static void
@@ -253,7 +253,7 @@ on_destroy_increment (void *data)
}
static void
-test_callback_destroyer (CuTest *tc)
+test_callback_destroyer (void)
{
P11KitIter *iter;
int value = 1;
@@ -262,11 +262,11 @@ test_callback_destroyer (CuTest *tc)
p11_kit_iter_add_callback (iter, on_callback_fail, &value, on_destroy_increment);
p11_kit_iter_free (iter);
- CuAssertIntEquals (tc, 2, value);
+ assert_num_eq (2, value);
}
static void
-test_with_session (CuTest *tc)
+test_with_session (void)
{
CK_OBJECT_HANDLE objects[128];
CK_SESSION_HANDLE session;
@@ -278,52 +278,52 @@ test_with_session (CuTest *tc)
mock_module_reset ();
rv = mock_module.C_Initialize (NULL);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = mock_C_OpenSession (MOCK_SLOT_ONE_ID, CKF_SERIAL_SESSION, NULL, NULL, &session);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
iter = p11_kit_iter_new (NULL);
p11_kit_iter_begin_with (iter, &mock_module, 0, session);
at= 0;
while ((rv = p11_kit_iter_next (iter)) == CKR_OK) {
- CuAssertTrue (tc, at < 128);
+ assert (at < 128);
objects[at] = p11_kit_iter_get_object (iter);
slot = p11_kit_iter_get_slot (iter);
- CuAssertTrue (tc, slot == MOCK_SLOT_ONE_ID);
+ assert (slot == MOCK_SLOT_ONE_ID);
module = p11_kit_iter_get_module (iter);
- CuAssertPtrEquals (tc, module, &mock_module);
+ assert_ptr_eq (module, &mock_module);
- CuAssertTrue (tc, session == p11_kit_iter_get_session (iter));
+ assert (session == p11_kit_iter_get_session (iter));
at++;
}
- CuAssertTrue (tc, rv == CKR_CANCEL);
+ assert (rv == CKR_CANCEL);
/* 1 modules, each with 1 slot, and 3 public objects */
- CuAssertIntEquals (tc, 3, at);
+ assert_num_eq (3, at);
- CuAssertTrue (tc, has_handle (objects, at, MOCK_DATA_OBJECT));
- CuAssertTrue (tc, !has_handle (objects, at, MOCK_PRIVATE_KEY_CAPITALIZE));
- CuAssertTrue (tc, has_handle (objects, at, MOCK_PUBLIC_KEY_CAPITALIZE));
- CuAssertTrue (tc, !has_handle (objects, at, MOCK_PRIVATE_KEY_PREFIX));
- CuAssertTrue (tc, has_handle (objects, at, MOCK_PUBLIC_KEY_PREFIX));
+ assert (has_handle (objects, at, MOCK_DATA_OBJECT));
+ assert (!has_handle (objects, at, MOCK_PRIVATE_KEY_CAPITALIZE));
+ assert (has_handle (objects, at, MOCK_PUBLIC_KEY_CAPITALIZE));
+ assert (!has_handle (objects, at, MOCK_PRIVATE_KEY_PREFIX));
+ assert (has_handle (objects, at, MOCK_PUBLIC_KEY_PREFIX));
p11_kit_iter_free (iter);
/* The session is still valid ... */
rv = mock_module.C_CloseSession (session);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = mock_module.C_Finalize (NULL);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
}
static void
-test_with_slot (CuTest *tc)
+test_with_slot (void)
{
CK_OBJECT_HANDLE objects[128];
CK_FUNCTION_LIST_PTR module;
@@ -334,43 +334,43 @@ test_with_slot (CuTest *tc)
mock_module_reset ();
rv = mock_module.C_Initialize (NULL);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
iter = p11_kit_iter_new (NULL);
p11_kit_iter_begin_with (iter, &mock_module, MOCK_SLOT_ONE_ID, 0);
at= 0;
while ((rv = p11_kit_iter_next (iter)) == CKR_OK) {
- CuAssertTrue (tc, at < 128);
+ assert (at < 128);
objects[at] = p11_kit_iter_get_object (iter);
slot = p11_kit_iter_get_slot (iter);
- CuAssertTrue (tc, slot == MOCK_SLOT_ONE_ID);
+ assert (slot == MOCK_SLOT_ONE_ID);
module = p11_kit_iter_get_module (iter);
- CuAssertPtrEquals (tc, module, &mock_module);
+ assert_ptr_eq (module, &mock_module);
at++;
}
- CuAssertTrue (tc, rv == CKR_CANCEL);
+ assert (rv == CKR_CANCEL);
/* 1 modules, each with 1 slot, and 3 public objects */
- CuAssertIntEquals (tc, 3, at);
+ assert_num_eq (3, at);
- CuAssertTrue (tc, has_handle (objects, at, MOCK_DATA_OBJECT));
- CuAssertTrue (tc, !has_handle (objects, at, MOCK_PRIVATE_KEY_CAPITALIZE));
- CuAssertTrue (tc, has_handle (objects, at, MOCK_PUBLIC_KEY_CAPITALIZE));
- CuAssertTrue (tc, !has_handle (objects, at, MOCK_PRIVATE_KEY_PREFIX));
- CuAssertTrue (tc, has_handle (objects, at, MOCK_PUBLIC_KEY_PREFIX));
+ assert (has_handle (objects, at, MOCK_DATA_OBJECT));
+ assert (!has_handle (objects, at, MOCK_PRIVATE_KEY_CAPITALIZE));
+ assert (has_handle (objects, at, MOCK_PUBLIC_KEY_CAPITALIZE));
+ assert (!has_handle (objects, at, MOCK_PRIVATE_KEY_PREFIX));
+ assert (has_handle (objects, at, MOCK_PUBLIC_KEY_PREFIX));
p11_kit_iter_free (iter);
rv = (mock_module.C_Finalize) (NULL);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
}
static void
-test_with_module (CuTest *tc)
+test_with_module (void)
{
CK_OBJECT_HANDLE objects[128];
CK_FUNCTION_LIST_PTR module;
@@ -380,40 +380,40 @@ test_with_module (CuTest *tc)
mock_module_reset ();
rv = mock_module.C_Initialize (NULL);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
iter = p11_kit_iter_new (NULL);
p11_kit_iter_begin_with (iter, &mock_module, 0, 0);
at= 0;
while ((rv = p11_kit_iter_next (iter)) == CKR_OK) {
- CuAssertTrue (tc, at < 128);
+ assert (at < 128);
objects[at] = p11_kit_iter_get_object (iter);
module = p11_kit_iter_get_module (iter);
- CuAssertPtrEquals (tc, module, &mock_module);
+ assert_ptr_eq (module, &mock_module);
at++;
}
- CuAssertTrue (tc, rv == CKR_CANCEL);
+ assert (rv == CKR_CANCEL);
/* 1 modules, each with 1 slot, and 3 public objects */
- CuAssertIntEquals (tc, 3, at);
+ assert_num_eq (3, at);
- CuAssertTrue (tc, has_handle (objects, at, MOCK_DATA_OBJECT));
- CuAssertTrue (tc, !has_handle (objects, at, MOCK_PRIVATE_KEY_CAPITALIZE));
- CuAssertTrue (tc, has_handle (objects, at, MOCK_PUBLIC_KEY_CAPITALIZE));
- CuAssertTrue (tc, !has_handle (objects, at, MOCK_PRIVATE_KEY_PREFIX));
- CuAssertTrue (tc, has_handle (objects, at, MOCK_PUBLIC_KEY_PREFIX));
+ assert (has_handle (objects, at, MOCK_DATA_OBJECT));
+ assert (!has_handle (objects, at, MOCK_PRIVATE_KEY_CAPITALIZE));
+ assert (has_handle (objects, at, MOCK_PUBLIC_KEY_CAPITALIZE));
+ assert (!has_handle (objects, at, MOCK_PRIVATE_KEY_PREFIX));
+ assert (has_handle (objects, at, MOCK_PUBLIC_KEY_PREFIX));
p11_kit_iter_free (iter);
rv = mock_module.C_Finalize (NULL);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
}
static void
-test_keep_session (CuTest *tc)
+test_keep_session (void)
{
CK_SESSION_HANDLE session;
P11KitIter *iter;
@@ -421,27 +421,27 @@ test_keep_session (CuTest *tc)
mock_module_reset ();
rv = mock_module.C_Initialize (NULL);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
iter = p11_kit_iter_new (NULL);
p11_kit_iter_begin_with (iter, &mock_module, 0, 0);
rv = p11_kit_iter_next (iter);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
session = p11_kit_iter_keep_session (iter);
p11_kit_iter_free (iter);
/* The session is still valid ... */
rv = mock_module.C_CloseSession (session);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = mock_module.C_Finalize (NULL);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
}
static void
-test_unrecognized (CuTest *tc)
+test_unrecognized (void)
{
CK_FUNCTION_LIST_PTR *modules;
P11KitIter *iter;
@@ -449,7 +449,7 @@ test_unrecognized (CuTest *tc)
CK_RV rv;
int count;
- modules = initialize_and_get_modules (tc);
+ modules = initialize_and_get_modules ();
uri = p11_kit_uri_new ();
p11_kit_uri_set_unrecognized (uri, 1);
@@ -462,18 +462,18 @@ test_unrecognized (CuTest *tc)
while ((rv = p11_kit_iter_next (iter)) == CKR_OK)
count++;
- CuAssertTrue (tc, rv == CKR_CANCEL);
+ assert (rv == CKR_CANCEL);
/* Nothing should have matched */
- CuAssertIntEquals (tc, 0, count);
+ assert_num_eq (0, count);
p11_kit_iter_free (iter);
- finalize_and_free_modules (tc, modules);
+ finalize_and_free_modules (modules);
}
static void
-test_uri_with_type (CuTest *tc)
+test_uri_with_type (void)
{
CK_OBJECT_HANDLE objects[128];
CK_FUNCTION_LIST_PTR *modules;
@@ -483,11 +483,11 @@ test_uri_with_type (CuTest *tc)
int at;
int ret;
- modules = initialize_and_get_modules (tc);
+ modules = initialize_and_get_modules ();
uri = p11_kit_uri_new ();
ret = p11_kit_uri_parse ("pkcs11:object-type=public", P11_KIT_URI_FOR_OBJECT, uri);
- CuAssertIntEquals (tc, ret, P11_KIT_URI_OK);
+ assert_num_eq (ret, P11_KIT_URI_OK);
iter = p11_kit_iter_new (uri);
p11_kit_uri_free (uri);
@@ -496,29 +496,29 @@ test_uri_with_type (CuTest *tc)
at = 0;
while ((rv = p11_kit_iter_next (iter)) == CKR_OK) {
- CuAssertTrue (tc, at < 128);
+ assert (at < 128);
objects[at] = p11_kit_iter_get_object (iter);
at++;
}
- CuAssertTrue (tc, rv == CKR_CANCEL);
+ assert (rv == CKR_CANCEL);
/* Three modules, each with 1 slot, and 2 public keys */
- CuAssertIntEquals (tc, 6, at);
+ assert_num_eq (6, at);
- CuAssertTrue (tc, !has_handle (objects, at, MOCK_DATA_OBJECT));
- CuAssertTrue (tc, !has_handle (objects, at, MOCK_PRIVATE_KEY_CAPITALIZE));
- CuAssertTrue (tc, has_handle (objects, at, MOCK_PUBLIC_KEY_CAPITALIZE));
- CuAssertTrue (tc, !has_handle (objects, at, MOCK_PRIVATE_KEY_PREFIX));
- CuAssertTrue (tc, has_handle (objects, at, MOCK_PUBLIC_KEY_PREFIX));
+ assert (!has_handle (objects, at, MOCK_DATA_OBJECT));
+ assert (!has_handle (objects, at, MOCK_PRIVATE_KEY_CAPITALIZE));
+ assert (has_handle (objects, at, MOCK_PUBLIC_KEY_CAPITALIZE));
+ assert (!has_handle (objects, at, MOCK_PRIVATE_KEY_PREFIX));
+ assert (has_handle (objects, at, MOCK_PUBLIC_KEY_PREFIX));
p11_kit_iter_free (iter);
- finalize_and_free_modules (tc, modules);
+ finalize_and_free_modules (modules);
}
static void
-test_filter (CuTest *tc)
+test_filter (void)
{
CK_OBJECT_HANDLE objects[128];
CK_FUNCTION_LIST_PTR *modules;
@@ -533,7 +533,7 @@ test_filter (CuTest *tc)
{ CKA_CLASS, &public_key, sizeof (public_key) },
};
- modules = initialize_and_get_modules (tc);
+ modules = initialize_and_get_modules ();
iter = p11_kit_iter_new (NULL);
p11_kit_iter_add_filter (iter, attrs, 2);
@@ -542,29 +542,29 @@ test_filter (CuTest *tc)
at = 0;
while ((rv = p11_kit_iter_next (iter)) == CKR_OK) {
- CuAssertTrue (tc, at < 128);
+ assert (at < 128);
objects[at] = p11_kit_iter_get_object (iter);
at++;
}
- CuAssertTrue (tc, rv == CKR_CANCEL);
+ assert (rv == CKR_CANCEL);
/* Three modules, each with 1 slot, and 2 public keys */
- CuAssertIntEquals (tc, 6, at);
+ assert_num_eq (6, at);
- CuAssertTrue (tc, !has_handle (objects, at, MOCK_DATA_OBJECT));
- CuAssertTrue (tc, !has_handle (objects, at, MOCK_PRIVATE_KEY_CAPITALIZE));
- CuAssertTrue (tc, has_handle (objects, at, MOCK_PUBLIC_KEY_CAPITALIZE));
- CuAssertTrue (tc, !has_handle (objects, at, MOCK_PRIVATE_KEY_PREFIX));
- CuAssertTrue (tc, has_handle (objects, at, MOCK_PUBLIC_KEY_PREFIX));
+ assert (!has_handle (objects, at, MOCK_DATA_OBJECT));
+ assert (!has_handle (objects, at, MOCK_PRIVATE_KEY_CAPITALIZE));
+ assert (has_handle (objects, at, MOCK_PUBLIC_KEY_CAPITALIZE));
+ assert (!has_handle (objects, at, MOCK_PRIVATE_KEY_PREFIX));
+ assert (has_handle (objects, at, MOCK_PUBLIC_KEY_PREFIX));
p11_kit_iter_free (iter);
- finalize_and_free_modules (tc, modules);
+ finalize_and_free_modules (modules);
}
static void
-test_session_flags (CuTest *tc)
+test_session_flags (void)
{
CK_FUNCTION_LIST_PTR *modules;
CK_FUNCTION_LIST_PTR module;
@@ -573,7 +573,7 @@ test_session_flags (CuTest *tc)
P11KitIter *iter;
CK_RV rv;
- modules = initialize_and_get_modules (tc);
+ modules = initialize_and_get_modules ();
iter = p11_kit_iter_new (NULL);
p11_kit_iter_set_session_flags (iter, CKF_RW_SESSION);
@@ -582,26 +582,26 @@ test_session_flags (CuTest *tc)
while ((rv = p11_kit_iter_next (iter)) == CKR_OK) {
module = p11_kit_iter_get_module (iter);
- CuAssertPtrNotNull (tc, module);
+ assert_ptr_not_null (module);
session = p11_kit_iter_get_session (iter);
- CuAssertTrue (tc, session != 0);
+ assert (session != 0);
rv = (module->C_GetSessionInfo) (session, &info);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
- CuAssertIntEquals (tc, CKS_RW_PUBLIC_SESSION, info.state);
+ assert_num_eq (CKS_RW_PUBLIC_SESSION, info.state);
}
- CuAssertTrue (tc, rv == CKR_CANCEL);
+ assert (rv == CKR_CANCEL);
p11_kit_iter_free (iter);
- finalize_and_free_modules (tc, modules);
+ finalize_and_free_modules (modules);
}
static void
-test_module_match (CuTest *tc)
+test_module_match (void)
{
CK_FUNCTION_LIST_PTR *modules;
P11KitIter *iter;
@@ -610,11 +610,11 @@ test_module_match (CuTest *tc)
int count;
int ret;
- modules = initialize_and_get_modules (tc);
+ modules = initialize_and_get_modules ();
uri = p11_kit_uri_new ();
ret = p11_kit_uri_parse ("pkcs11:library-description=MOCK%20LIBRARY", P11_KIT_URI_FOR_MODULE, uri);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
+ assert_num_eq (P11_KIT_URI_OK, ret);
iter = p11_kit_iter_new (uri);
p11_kit_uri_free (uri);
@@ -625,18 +625,18 @@ test_module_match (CuTest *tc)
while ((rv = p11_kit_iter_next (iter)) == CKR_OK)
count++;
- CuAssertTrue (tc, rv == CKR_CANCEL);
+ assert (rv == CKR_CANCEL);
/* Three modules, each with 1 slot, and 3 public objects */
- CuAssertIntEquals (tc, 9, count);
+ assert_num_eq (9, count);
p11_kit_iter_free (iter);
- finalize_and_free_modules (tc, modules);
+ finalize_and_free_modules (modules);
}
static void
-test_module_mismatch (CuTest *tc)
+test_module_mismatch (void)
{
CK_FUNCTION_LIST_PTR *modules;
P11KitIter *iter;
@@ -645,11 +645,11 @@ test_module_mismatch (CuTest *tc)
int count;
int ret;
- modules = initialize_and_get_modules (tc);
+ modules = initialize_and_get_modules ();
uri = p11_kit_uri_new ();
ret = p11_kit_uri_parse ("pkcs11:library-description=blah", P11_KIT_URI_FOR_MODULE, uri);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
+ assert_num_eq (P11_KIT_URI_OK, ret);
iter = p11_kit_iter_new (uri);
p11_kit_uri_free (uri);
@@ -660,18 +660,18 @@ test_module_mismatch (CuTest *tc)
while ((rv = p11_kit_iter_next (iter)) == CKR_OK)
count++;
- CuAssertTrue (tc, rv == CKR_CANCEL);
+ assert (rv == CKR_CANCEL);
/* Nothing should have matched */
- CuAssertIntEquals (tc, 0, count);
+ assert_num_eq (0, count);
p11_kit_iter_free (iter);
- finalize_and_free_modules (tc, modules);
+ finalize_and_free_modules (modules);
}
static void
-test_token_match (CuTest *tc)
+test_token_match (void)
{
CK_FUNCTION_LIST_PTR *modules;
P11KitIter *iter;
@@ -680,11 +680,11 @@ test_token_match (CuTest *tc)
int count;
int ret;
- modules = initialize_and_get_modules (tc);
+ modules = initialize_and_get_modules ();
uri = p11_kit_uri_new ();
ret = p11_kit_uri_parse ("pkcs11:manufacturer=TEST%20MANUFACTURER", P11_KIT_URI_FOR_TOKEN, uri);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
+ assert_num_eq (P11_KIT_URI_OK, ret);
iter = p11_kit_iter_new (uri);
p11_kit_uri_free (uri);
@@ -695,18 +695,18 @@ test_token_match (CuTest *tc)
while ((rv = p11_kit_iter_next (iter)) == CKR_OK)
count++;
- CuAssertTrue (tc, rv == CKR_CANCEL);
+ assert (rv == CKR_CANCEL);
/* Three modules, each with 1 slot, and 3 public objects */
- CuAssertIntEquals (tc, 9, count);
+ assert_num_eq (9, count);
p11_kit_iter_free (iter);
- finalize_and_free_modules (tc, modules);
+ finalize_and_free_modules (modules);
}
static void
-test_token_mismatch (CuTest *tc)
+test_token_mismatch (void)
{
CK_FUNCTION_LIST_PTR *modules;
P11KitIter *iter;
@@ -715,11 +715,11 @@ test_token_mismatch (CuTest *tc)
int count;
int ret;
- modules = initialize_and_get_modules (tc);
+ modules = initialize_and_get_modules ();
uri = p11_kit_uri_new ();
ret = p11_kit_uri_parse ("pkcs11:manufacturer=blah", P11_KIT_URI_FOR_TOKEN, uri);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
+ assert_num_eq (P11_KIT_URI_OK, ret);
iter = p11_kit_iter_new (uri);
p11_kit_uri_free (uri);
@@ -730,18 +730,18 @@ test_token_mismatch (CuTest *tc)
while ((rv = p11_kit_iter_next (iter)) == CKR_OK)
count++;
- CuAssertTrue (tc, rv == CKR_CANCEL);
+ assert (rv == CKR_CANCEL);
/* Nothing should have matched */
- CuAssertIntEquals (tc, 0, count);
+ assert_num_eq (0, count);
p11_kit_iter_free (iter);
- finalize_and_free_modules (tc, modules);
+ finalize_and_free_modules (modules);
}
static void
-test_getslotlist_fail_first (CuTest *tc)
+test_getslotlist_fail_first (void)
{
CK_FUNCTION_LIST module;
P11KitIter *iter;
@@ -750,7 +750,7 @@ test_getslotlist_fail_first (CuTest *tc)
mock_module_reset ();
rv = mock_module.C_Initialize (NULL);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
memcpy (&module, &mock_module, sizeof (CK_FUNCTION_LIST));
module.C_GetSlotList = mock_C_GetSlotList__fail_first;
@@ -762,19 +762,19 @@ test_getslotlist_fail_first (CuTest *tc)
while ((rv = p11_kit_iter_next (iter)) == CKR_OK)
at++;
- CuAssertTrue (tc, rv == CKR_VENDOR_DEFINED);
+ assert (rv == CKR_VENDOR_DEFINED);
/* Should fail on the first iteration */
- CuAssertIntEquals (tc, 0, at);
+ assert_num_eq (0, at);
p11_kit_iter_free (iter);
rv = mock_module.C_Finalize (NULL);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
}
static void
-test_getslotlist_fail_late (CuTest *tc)
+test_getslotlist_fail_late (void)
{
CK_FUNCTION_LIST module;
P11KitIter *iter;
@@ -783,7 +783,7 @@ test_getslotlist_fail_late (CuTest *tc)
mock_module_reset ();
rv = mock_module.C_Initialize (NULL);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
memcpy (&module, &mock_module, sizeof (CK_FUNCTION_LIST));
module.C_GetSlotList = mock_C_GetSlotList__fail_late;
@@ -795,19 +795,19 @@ test_getslotlist_fail_late (CuTest *tc)
while ((rv = p11_kit_iter_next (iter)) == CKR_OK)
at++;
- CuAssertTrue (tc, rv == CKR_VENDOR_DEFINED);
+ assert (rv == CKR_VENDOR_DEFINED);
/* Should fail on the first iteration */
- CuAssertIntEquals (tc, 0, at);
+ assert_num_eq (0, at);
p11_kit_iter_free (iter);
rv = mock_module.C_Finalize (NULL);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
}
static void
-test_open_session_fail (CuTest *tc)
+test_open_session_fail (void)
{
CK_FUNCTION_LIST module;
P11KitIter *iter;
@@ -816,7 +816,7 @@ test_open_session_fail (CuTest *tc)
mock_module_reset ();
rv = mock_module.C_Initialize (NULL);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
memcpy (&module, &mock_module, sizeof (CK_FUNCTION_LIST));
module.C_OpenSession = mock_C_OpenSession__fails;
@@ -828,19 +828,19 @@ test_open_session_fail (CuTest *tc)
while ((rv = p11_kit_iter_next (iter)) == CKR_OK)
at++;
- CuAssertTrue (tc, rv == CKR_DEVICE_ERROR);
+ assert (rv == CKR_DEVICE_ERROR);
/* Should fail on the first iteration */
- CuAssertIntEquals (tc, 0, at);
+ assert_num_eq (0, at);
p11_kit_iter_free (iter);
rv = mock_module.C_Finalize (NULL);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
}
static void
-test_find_init_fail (CuTest *tc)
+test_find_init_fail (void)
{
CK_FUNCTION_LIST module;
P11KitIter *iter;
@@ -849,7 +849,7 @@ test_find_init_fail (CuTest *tc)
mock_module_reset ();
rv = mock_module.C_Initialize (NULL);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
memcpy (&module, &mock_module, sizeof (CK_FUNCTION_LIST));
module.C_FindObjectsInit = mock_C_FindObjectsInit__fails;
@@ -861,19 +861,19 @@ test_find_init_fail (CuTest *tc)
while ((rv = p11_kit_iter_next (iter)) == CKR_OK)
at++;
- CuAssertTrue (tc, rv == CKR_DEVICE_MEMORY);
+ assert (rv == CKR_DEVICE_MEMORY);
/* Should fail on the first iteration */
- CuAssertIntEquals (tc, 0, at);
+ assert_num_eq (0, at);
p11_kit_iter_free (iter);
rv = mock_module.C_Finalize (NULL);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
}
static void
-test_find_objects_fail (CuTest *tc)
+test_find_objects_fail (void)
{
CK_FUNCTION_LIST module;
P11KitIter *iter;
@@ -882,7 +882,7 @@ test_find_objects_fail (CuTest *tc)
mock_module_reset ();
rv = mock_module.C_Initialize (NULL);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
memcpy (&module, &mock_module, sizeof (CK_FUNCTION_LIST));
module.C_FindObjects = mock_C_FindObjects__fails;
@@ -894,19 +894,19 @@ test_find_objects_fail (CuTest *tc)
while ((rv = p11_kit_iter_next (iter)) == CKR_OK)
at++;
- CuAssertTrue (tc, rv == CKR_DEVICE_REMOVED);
+ assert (rv == CKR_DEVICE_REMOVED);
/* Should fail on the first iteration */
- CuAssertIntEquals (tc, 0, at);
+ assert_num_eq (0, at);
p11_kit_iter_free (iter);
rv = mock_module.C_Finalize (NULL);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
}
static void
-test_load_attributes (CuTest *tc)
+test_load_attributes (void)
{
CK_FUNCTION_LIST_PTR *modules;
P11KitIter *iter;
@@ -921,7 +921,7 @@ test_load_attributes (CuTest *tc)
{ CKA_LABEL },
};
- modules = initialize_and_get_modules (tc);
+ modules = initialize_and_get_modules ();
iter = p11_kit_iter_new (NULL);
p11_kit_iter_begin (iter, modules);
@@ -931,24 +931,24 @@ test_load_attributes (CuTest *tc)
at = 0;
while ((rv = p11_kit_iter_next (iter)) == CKR_OK) {
rv = p11_kit_iter_load_attributes (iter, attrs, 2);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
object = p11_kit_iter_get_object (iter);
switch (object) {
case MOCK_DATA_OBJECT:
- CuAssertTrue (tc, p11_attrs_find_ulong (attrs, CKA_CLASS, &ulong) && ulong == CKO_DATA);
- CuAssertTrue (tc, p11_attr_match_value (p11_attrs_find (attrs, CKA_LABEL), "TEST LABEL", -1));
+ assert (p11_attrs_find_ulong (attrs, CKA_CLASS, &ulong) && ulong == CKO_DATA);
+ assert (p11_attr_match_value (p11_attrs_find (attrs, CKA_LABEL), "TEST LABEL", -1));
break;
case MOCK_PUBLIC_KEY_CAPITALIZE:
- CuAssertTrue (tc, p11_attrs_find_ulong (attrs, CKA_CLASS, &ulong) && ulong == CKO_PUBLIC_KEY);
- CuAssertTrue (tc, p11_attr_match_value (p11_attrs_find (attrs, CKA_LABEL), "Public Capitalize Key", -1));
+ assert (p11_attrs_find_ulong (attrs, CKA_CLASS, &ulong) && ulong == CKO_PUBLIC_KEY);
+ assert (p11_attr_match_value (p11_attrs_find (attrs, CKA_LABEL), "Public Capitalize Key", -1));
break;
case MOCK_PUBLIC_KEY_PREFIX:
- CuAssertTrue (tc, p11_attrs_find_ulong (attrs, CKA_CLASS, &ulong) && ulong == CKO_PUBLIC_KEY);
- CuAssertTrue (tc, p11_attr_match_value (p11_attrs_find (attrs, CKA_LABEL), "Public prefix key", -1));
+ assert (p11_attrs_find_ulong (attrs, CKA_CLASS, &ulong) && ulong == CKO_PUBLIC_KEY);
+ assert (p11_attr_match_value (p11_attrs_find (attrs, CKA_LABEL), "Public prefix key", -1));
break;
default:
- CuFail (tc, "Unknown object matched");
+ assert_fail ("Unknown object matched", NULL);
break;
}
@@ -957,18 +957,18 @@ test_load_attributes (CuTest *tc)
p11_attrs_free (attrs);
- CuAssertTrue (tc, rv == CKR_CANCEL);
+ assert (rv == CKR_CANCEL);
/* Three modules, each with 1 slot, and 3 public objects */
- CuAssertIntEquals (tc, 9, at);
+ assert_num_eq (9, at);
p11_kit_iter_free (iter);
- finalize_and_free_modules (tc, modules);
+ finalize_and_free_modules (modules);
}
static void
-test_load_attributes_none (CuTest *tc)
+test_load_attributes_none (void)
{
CK_FUNCTION_LIST module;
P11KitIter *iter;
@@ -977,7 +977,7 @@ test_load_attributes_none (CuTest *tc)
mock_module_reset ();
rv = mock_module.C_Initialize (NULL);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
memcpy (&module, &mock_module, sizeof (CK_FUNCTION_LIST));
@@ -987,20 +987,20 @@ test_load_attributes_none (CuTest *tc)
while ((rv = p11_kit_iter_next (iter)) == CKR_OK) {
attrs = p11_attrs_buildn (NULL, NULL, 0);
rv = p11_kit_iter_load_attributes (iter, attrs, 0);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
p11_attrs_free (attrs);
}
- CuAssertTrue (tc, rv == CKR_CANCEL);
+ assert (rv == CKR_CANCEL);
p11_kit_iter_free (iter);
rv = mock_module.C_Finalize (NULL);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
}
static void
-test_load_attributes_fail_first (CuTest *tc)
+test_load_attributes_fail_first (void)
{
CK_ATTRIBUTE label = { CKA_LABEL, };
CK_FUNCTION_LIST module;
@@ -1010,7 +1010,7 @@ test_load_attributes_fail_first (CuTest *tc)
mock_module_reset ();
rv = mock_module.C_Initialize (NULL);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
memcpy (&module, &mock_module, sizeof (CK_FUNCTION_LIST));
module.C_GetAttributeValue = mock_C_GetAttributeValue__fail_first;
@@ -1021,20 +1021,20 @@ test_load_attributes_fail_first (CuTest *tc)
while ((rv = p11_kit_iter_next (iter)) == CKR_OK) {
attrs = p11_attrs_build (NULL, &label, NULL);
rv = p11_kit_iter_load_attributes (iter, attrs, 1);
- CuAssertTrue (tc, rv == CKR_FUNCTION_REJECTED);
+ assert (rv == CKR_FUNCTION_REJECTED);
p11_attrs_free (attrs);
}
- CuAssertTrue (tc, rv == CKR_CANCEL);
+ assert (rv == CKR_CANCEL);
p11_kit_iter_free (iter);
rv = mock_module.C_Finalize (NULL);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
}
static void
-test_load_attributes_fail_late (CuTest *tc)
+test_load_attributes_fail_late (void)
{
CK_ATTRIBUTE label = { CKA_LABEL, };
CK_FUNCTION_LIST module;
@@ -1044,7 +1044,7 @@ test_load_attributes_fail_late (CuTest *tc)
mock_module_reset ();
rv = mock_module.C_Initialize (NULL);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
memcpy (&module, &mock_module, sizeof (CK_FUNCTION_LIST));
module.C_GetAttributeValue = mock_C_GetAttributeValue__fail_late;
@@ -1055,61 +1055,50 @@ test_load_attributes_fail_late (CuTest *tc)
while ((rv = p11_kit_iter_next (iter)) == CKR_OK) {
attrs = p11_attrs_build (NULL, &label, NULL);
rv = p11_kit_iter_load_attributes (iter, attrs, 1);
- CuAssertTrue (tc, rv == CKR_FUNCTION_FAILED);
+ assert (rv == CKR_FUNCTION_FAILED);
p11_attrs_free (attrs);
}
- CuAssertTrue (tc, rv == CKR_CANCEL);
+ assert (rv == CKR_CANCEL);
p11_kit_iter_free (iter);
rv = mock_module.C_Finalize (NULL);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
}
int
-main (void)
+main (int argc,
+ char *argv[])
{
- CuString *output = CuStringNew ();
- CuSuite* suite = CuSuiteNew ();
- int ret;
-
- putenv ("P11_KIT_STRICT=1");
p11_library_init ();
mock_module_init ();
- SUITE_ADD_TEST (suite, test_all);
- SUITE_ADD_TEST (suite, test_unrecognized);
- SUITE_ADD_TEST (suite, test_uri_with_type);
- SUITE_ADD_TEST (suite, test_session_flags);
- SUITE_ADD_TEST (suite, test_callback);
- SUITE_ADD_TEST (suite, test_callback_fails);
- SUITE_ADD_TEST (suite, test_callback_destroyer);
- SUITE_ADD_TEST (suite, test_filter);
- SUITE_ADD_TEST (suite, test_with_session);
- SUITE_ADD_TEST (suite, test_with_slot);
- SUITE_ADD_TEST (suite, test_with_module);
- SUITE_ADD_TEST (suite, test_keep_session);
- SUITE_ADD_TEST (suite, test_token_match);
- SUITE_ADD_TEST (suite, test_token_mismatch);
- SUITE_ADD_TEST (suite, test_module_match);
- SUITE_ADD_TEST (suite, test_module_mismatch);
- SUITE_ADD_TEST (suite, test_getslotlist_fail_first);
- SUITE_ADD_TEST (suite, test_getslotlist_fail_late);
- SUITE_ADD_TEST (suite, test_open_session_fail);
- SUITE_ADD_TEST (suite, test_find_init_fail);
- SUITE_ADD_TEST (suite, test_find_objects_fail);
- SUITE_ADD_TEST (suite, test_load_attributes);
- SUITE_ADD_TEST (suite, test_load_attributes_none);
- SUITE_ADD_TEST (suite, test_load_attributes_fail_first);
- SUITE_ADD_TEST (suite, test_load_attributes_fail_late);
-
- 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_all, "/iter/test_all");
+ p11_test (test_unrecognized, "/iter/test_unrecognized");
+ p11_test (test_uri_with_type, "/iter/test_uri_with_type");
+ p11_test (test_session_flags, "/iter/test_session_flags");
+ p11_test (test_callback, "/iter/test_callback");
+ p11_test (test_callback_fails, "/iter/test_callback_fails");
+ p11_test (test_callback_destroyer, "/iter/test_callback_destroyer");
+ p11_test (test_filter, "/iter/test_filter");
+ p11_test (test_with_session, "/iter/test_with_session");
+ p11_test (test_with_slot, "/iter/test_with_slot");
+ p11_test (test_with_module, "/iter/test_with_module");
+ p11_test (test_keep_session, "/iter/test_keep_session");
+ p11_test (test_token_match, "/iter/test_token_match");
+ p11_test (test_token_mismatch, "/iter/test_token_mismatch");
+ p11_test (test_module_match, "/iter/test_module_match");
+ p11_test (test_module_mismatch, "/iter/test_module_mismatch");
+ p11_test (test_getslotlist_fail_first, "/iter/test_getslotlist_fail_first");
+ p11_test (test_getslotlist_fail_late, "/iter/test_getslotlist_fail_late");
+ p11_test (test_open_session_fail, "/iter/test_open_session_fail");
+ p11_test (test_find_init_fail, "/iter/test_find_init_fail");
+ p11_test (test_find_objects_fail, "/iter/test_find_objects_fail");
+ p11_test (test_load_attributes, "/iter/test_load_attributes");
+ p11_test (test_load_attributes_none, "/iter/test_load_attributes_none");
+ p11_test (test_load_attributes_fail_first, "/iter/test_load_attributes_fail_first");
+ p11_test (test_load_attributes_fail_late, "/iter/test_load_attributes_fail_late");
+
+ return p11_test_run (argc, argv);
}
diff --git a/p11-kit/tests/test-log.c b/p11-kit/tests/test-log.c
index fc8c45c..e7dab70 100644
--- a/p11-kit/tests/test-log.c
+++ b/p11-kit/tests/test-log.c
@@ -33,7 +33,7 @@
*/
#include "config.h"
-#include "CuTest.h"
+#include "test.h"
#include "dict.h"
#include "library.h"
@@ -49,8 +49,7 @@
#include <string.h>
static CK_FUNCTION_LIST_PTR
-setup_mock_module (CuTest *tc,
- CK_SESSION_HANDLE *session)
+setup_mock_module (CK_SESSION_HANDLE *session)
{
CK_FUNCTION_LIST_PTR module;
CK_RV rv;
@@ -59,38 +58,37 @@ setup_mock_module (CuTest *tc,
p11_log_force = true;
rv = p11_module_load_inlock_reentrant (&mock_module, 0, &module);
- CuAssertTrue (tc, rv == CKR_OK);
- CuAssertPtrNotNull (tc, module);
- CuAssertTrue (tc, p11_virtual_is_wrapper (module));
+ assert (rv == CKR_OK);
+ assert_ptr_not_null (module);
+ assert (p11_virtual_is_wrapper (module));
p11_unlock ();
rv = p11_kit_module_initialize (module);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
if (session) {
rv = (module->C_OpenSession) (MOCK_SLOT_ONE_ID,
CKF_RW_SESSION | CKF_SERIAL_SESSION,
NULL, NULL, session);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
}
return module;
}
static void
-teardown_mock_module (CuTest *tc,
- CK_FUNCTION_LIST_PTR module)
+teardown_mock_module (CK_FUNCTION_LIST_PTR module)
{
CK_RV rv;
rv = p11_kit_module_finalize (module);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
p11_lock ();
rv = p11_module_release_inlock_reentrant (module);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
p11_unlock ();
}
@@ -99,27 +97,16 @@ teardown_mock_module (CuTest *tc,
#include "test-mock.c"
int
-main (void)
+main (int argc,
+ char *argv[])
{
- CuString *output = CuStringNew ();
- CuSuite* suite = CuSuiteNew ();
- int ret;
-
- putenv ("P11_KIT_STRICT=1");
p11_library_init ();
mock_module_init ();
- test_mock_add_tests (suite);
+ test_mock_add_tests ("/log");
p11_kit_be_quiet ();
p11_log_output = false;
- CuSuiteRun (suite);
- CuSuiteSummary (suite, output);
- CuSuiteDetails (suite, output);
- printf ("%s\n", output->buffer);
- ret = suite->failCount;
- CuSuiteDelete (suite);
- CuStringDelete (output);
- return ret;
+ return p11_test_run (argc, argv);
}
diff --git a/p11-kit/tests/test-managed.c b/p11-kit/tests/test-managed.c
index 6184c44..9fc9ffb 100644
--- a/p11-kit/tests/test-managed.c
+++ b/p11-kit/tests/test-managed.c
@@ -33,7 +33,7 @@
*/
#include "config.h"
-#include "CuTest.h"
+#include "test.h"
#include "dict.h"
#include "library.h"
@@ -48,8 +48,7 @@
#include <string.h>
static CK_FUNCTION_LIST_PTR
-setup_mock_module (CuTest *tc,
- CK_SESSION_HANDLE *session)
+setup_mock_module (CK_SESSION_HANDLE *session)
{
CK_FUNCTION_LIST_PTR module;
CK_RV rv;
@@ -57,38 +56,37 @@ setup_mock_module (CuTest *tc,
p11_lock ();
rv = p11_module_load_inlock_reentrant (&mock_module, 0, &module);
- CuAssertTrue (tc, rv == CKR_OK);
- CuAssertPtrNotNull (tc, module);
- CuAssertTrue (tc, p11_virtual_is_wrapper (module));
+ assert (rv == CKR_OK);
+ assert_ptr_not_null (module);
+ assert (p11_virtual_is_wrapper (module));
p11_unlock ();
rv = p11_kit_module_initialize (module);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
if (session) {
rv = (module->C_OpenSession) (MOCK_SLOT_ONE_ID,
CKF_RW_SESSION | CKF_SERIAL_SESSION,
NULL, NULL, session);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
}
return module;
}
static void
-teardown_mock_module (CuTest *tc,
- CK_FUNCTION_LIST_PTR module)
+teardown_mock_module (CK_FUNCTION_LIST_PTR module)
{
CK_RV rv;
rv = p11_kit_module_finalize (module);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
p11_lock ();
rv = p11_module_release_inlock_reentrant (module);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
p11_unlock ();
}
@@ -100,7 +98,7 @@ fail_C_Initialize (void *init_reserved)
}
static void
-test_initialize_finalize (CuTest *tc)
+test_initialize_finalize (void)
{
CK_FUNCTION_LIST_PTR module;
CK_RV rv;
@@ -108,34 +106,34 @@ test_initialize_finalize (CuTest *tc)
p11_lock ();
rv = p11_module_load_inlock_reentrant (&mock_module, 0, &module);
- CuAssertTrue (tc, rv == CKR_OK);
- CuAssertPtrNotNull (tc, module);
- CuAssertTrue (tc, p11_virtual_is_wrapper (module));
+ assert (rv == CKR_OK);
+ assert_ptr_not_null (module);
+ assert (p11_virtual_is_wrapper (module));
p11_unlock ();
rv = module->C_Initialize (NULL);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = module->C_Initialize (NULL);
- CuAssertTrue (tc, rv == CKR_CRYPTOKI_ALREADY_INITIALIZED);
+ assert (rv == CKR_CRYPTOKI_ALREADY_INITIALIZED);
rv = module->C_Finalize (NULL);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = module->C_Finalize (NULL);
- CuAssertTrue (tc, rv == CKR_CRYPTOKI_NOT_INITIALIZED);
+ assert (rv == CKR_CRYPTOKI_NOT_INITIALIZED);
p11_lock ();
rv = p11_module_release_inlock_reentrant (module);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
p11_unlock ();
}
static void
-test_initialize_fail (CuTest *tc)
+test_initialize_fail (void)
{
CK_FUNCTION_LIST_PTR module;
CK_FUNCTION_LIST base;
@@ -147,16 +145,16 @@ test_initialize_fail (CuTest *tc)
p11_lock ();
rv = p11_module_load_inlock_reentrant (&base, 0, &module);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
p11_unlock ();
rv = p11_kit_module_initialize (module);
- CuAssertTrue (tc, rv == CKR_FUNCTION_FAILED);
+ assert (rv == CKR_FUNCTION_FAILED);
}
static void
-test_separate_close_all_sessions (CuTest *tc)
+test_separate_close_all_sessions (void)
{
CK_FUNCTION_LIST *first;
CK_FUNCTION_LIST *second;
@@ -165,64 +163,53 @@ test_separate_close_all_sessions (CuTest *tc)
CK_SESSION_INFO info;
CK_RV rv;
- first = setup_mock_module (tc, &s1);
- second = setup_mock_module (tc, &s2);
+ first = setup_mock_module (&s1);
+ second = setup_mock_module (&s2);
rv = first->C_GetSessionInfo (s1, &info);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = second->C_GetSessionInfo (s2, &info);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
first->C_CloseAllSessions (MOCK_SLOT_ONE_ID);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = first->C_GetSessionInfo (s1, &info);
- CuAssertTrue (tc, rv == CKR_SESSION_HANDLE_INVALID);
+ assert (rv == CKR_SESSION_HANDLE_INVALID);
rv = second->C_GetSessionInfo (s2, &info);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
second->C_CloseAllSessions (MOCK_SLOT_ONE_ID);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = first->C_GetSessionInfo (s1, &info);
- CuAssertTrue (tc, rv == CKR_SESSION_HANDLE_INVALID);
+ assert (rv == CKR_SESSION_HANDLE_INVALID);
rv = second->C_GetSessionInfo (s2, &info);
- CuAssertTrue (tc, rv == CKR_SESSION_HANDLE_INVALID);
+ assert (rv == CKR_SESSION_HANDLE_INVALID);
- teardown_mock_module (tc, first);
- teardown_mock_module (tc, second);
+ teardown_mock_module (first);
+ teardown_mock_module (second);
}
/* Bring in all the mock module tests */
#include "test-mock.c"
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_library_init ();
- SUITE_ADD_TEST (suite, test_initialize_finalize);
- SUITE_ADD_TEST (suite, test_initialize_fail);
- SUITE_ADD_TEST (suite, test_separate_close_all_sessions);
- test_mock_add_tests (suite);
+ p11_test (test_initialize_finalize, "/managed/test_initialize_finalize");
+ p11_test (test_initialize_fail, "/managed/test_initialize_fail");
+ p11_test (test_separate_close_all_sessions, "/managed/test_separate_close_all_sessions");
+ test_mock_add_tests ("/managed");
p11_kit_be_quiet ();
- CuSuiteRun (suite);
- CuSuiteSummary (suite, output);
- CuSuiteDetails (suite, output);
- printf ("%s\n", output->buffer);
- ret = suite->failCount;
- CuSuiteDelete (suite);
- CuStringDelete (output);
- return ret;
+ return p11_test_run (argc, argv);
}
diff --git a/p11-kit/tests/test-mock.c b/p11-kit/tests/test-mock.c
index 3bc5406..5fba7ec 100644
--- a/p11-kit/tests/test-mock.c
+++ b/p11-kit/tests/test-mock.c
@@ -33,7 +33,7 @@
* Author: Stef Walter <stef@thewalter.net>
*/
-#include "CuTest.h"
+#include "test.h"
#include "library.h"
#include "mock.h"
@@ -46,222 +46,222 @@
#include <stdlib.h>
static void
-test_get_info (CuTest *tc)
+test_get_info (void)
{
CK_FUNCTION_LIST_PTR module;
CK_INFO info;
CK_RV rv;
- module = setup_mock_module (tc, NULL);
+ module = setup_mock_module (NULL);
rv = (module->C_GetInfo) (&info);
- CuAssertTrue (tc, rv == CKR_OK);
- CuAssertTrue (tc, memcmp (&info, &MOCK_INFO, sizeof (CK_INFO)) == 0);
+ assert (rv == CKR_OK);
+ assert (memcmp (&info, &MOCK_INFO, sizeof (CK_INFO)) == 0);
- teardown_mock_module (tc, module);
+ teardown_mock_module (module);
}
static void
-test_get_slot_list (CuTest *tc)
+test_get_slot_list (void)
{
CK_FUNCTION_LIST_PTR module;
CK_SLOT_ID slot_list[8];
CK_ULONG count = 0;
CK_RV rv;
- module = setup_mock_module (tc, NULL);
+ module = setup_mock_module (NULL);
/* Normal module has 2 slots, one with token present */
rv = (module->C_GetSlotList) (CK_TRUE, NULL, &count);
- CuAssertTrue (tc, rv == CKR_OK);
- CuAssertIntEquals (tc, MOCK_SLOTS_PRESENT, count);
+ assert (rv == CKR_OK);
+ assert_num_eq (MOCK_SLOTS_PRESENT, count);
rv = (module->C_GetSlotList) (CK_FALSE, NULL, &count);
- CuAssertTrue (tc, rv == CKR_OK);
- CuAssertIntEquals (tc, MOCK_SLOTS_ALL, count);
+ assert (rv == CKR_OK);
+ assert_num_eq (MOCK_SLOTS_ALL, count);
count = 8;
rv = (module->C_GetSlotList) (CK_TRUE, slot_list, &count);
- CuAssertTrue (tc, rv == CKR_OK);
- CuAssertIntEquals (tc, MOCK_SLOTS_PRESENT, count);
- CuAssertIntEquals (tc, MOCK_SLOT_ONE_ID, slot_list[0]);
+ assert (rv == CKR_OK);
+ assert_num_eq (MOCK_SLOTS_PRESENT, count);
+ assert_num_eq (MOCK_SLOT_ONE_ID, slot_list[0]);
count = 8;
rv = (module->C_GetSlotList) (CK_FALSE, slot_list, &count);
- CuAssertTrue (tc, rv == CKR_OK);
- CuAssertIntEquals (tc, MOCK_SLOTS_ALL, count);
- CuAssertIntEquals (tc, MOCK_SLOT_ONE_ID, slot_list[0]);
- CuAssertIntEquals (tc, MOCK_SLOT_TWO_ID, slot_list[1]);
+ assert (rv == CKR_OK);
+ assert_num_eq (MOCK_SLOTS_ALL, count);
+ assert_num_eq (MOCK_SLOT_ONE_ID, slot_list[0]);
+ assert_num_eq (MOCK_SLOT_TWO_ID, slot_list[1]);
- teardown_mock_module (tc, module);
+ teardown_mock_module (module);
}
static void
-test_get_slot_info (CuTest *tc)
+test_get_slot_info (void)
{
CK_FUNCTION_LIST_PTR module;
CK_SLOT_INFO info;
char *string;
CK_RV rv;
- module = setup_mock_module (tc, NULL);
+ module = setup_mock_module (NULL);
rv = (module->C_GetSlotInfo) (MOCK_SLOT_ONE_ID, &info);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
string = p11_kit_space_strdup (info.slotDescription, sizeof (info.slotDescription));
- CuAssertStrEquals (tc, "TEST SLOT", string);
+ assert_str_eq ("TEST SLOT", string);
free (string);
string = p11_kit_space_strdup (info.manufacturerID, sizeof (info.manufacturerID));
- CuAssertStrEquals (tc, "TEST MANUFACTURER", string);
+ assert_str_eq ("TEST MANUFACTURER", string);
free (string);
- CuAssertIntEquals (tc, CKF_TOKEN_PRESENT | CKF_REMOVABLE_DEVICE, info.flags);
- CuAssertIntEquals (tc, 55, info.hardwareVersion.major);
- CuAssertIntEquals (tc, 155, info.hardwareVersion.minor);
- CuAssertIntEquals (tc, 65, info.firmwareVersion.major);
- CuAssertIntEquals (tc, 165, info.firmwareVersion.minor);
+ assert_num_eq (CKF_TOKEN_PRESENT | CKF_REMOVABLE_DEVICE, info.flags);
+ assert_num_eq (55, info.hardwareVersion.major);
+ assert_num_eq (155, info.hardwareVersion.minor);
+ assert_num_eq (65, info.firmwareVersion.major);
+ assert_num_eq (165, info.firmwareVersion.minor);
rv = (module->C_GetSlotInfo) (MOCK_SLOT_TWO_ID, &info);
- CuAssertTrue (tc, rv == CKR_OK);
- CuAssertIntEquals (tc, CKF_REMOVABLE_DEVICE, info.flags);
+ assert (rv == CKR_OK);
+ assert_num_eq (CKF_REMOVABLE_DEVICE, info.flags);
rv = (module->C_GetSlotInfo) (0, &info);
- CuAssertTrue (tc, rv == CKR_SLOT_ID_INVALID);
+ assert (rv == CKR_SLOT_ID_INVALID);
- teardown_mock_module (tc, module);
+ teardown_mock_module (module);
}
static void
-test_get_token_info (CuTest *tc)
+test_get_token_info (void)
{
CK_FUNCTION_LIST_PTR module;
CK_TOKEN_INFO info;
char *string;
CK_RV rv;
- module = setup_mock_module (tc, NULL);
+ module = setup_mock_module (NULL);
rv = (module->C_GetTokenInfo) (MOCK_SLOT_ONE_ID, &info);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
string = p11_kit_space_strdup (info.label, sizeof (info.label));
- CuAssertStrEquals (tc, "TEST LABEL", string);
+ assert_str_eq ("TEST LABEL", string);
free (string);
string = p11_kit_space_strdup (info.manufacturerID, sizeof (info.manufacturerID));
- CuAssertStrEquals (tc, "TEST MANUFACTURER", string);
+ assert_str_eq ("TEST MANUFACTURER", string);
free (string);
string = p11_kit_space_strdup (info.model, sizeof (info.model));
- CuAssertStrEquals (tc, "TEST MODEL", string);
+ assert_str_eq ("TEST MODEL", string);
free (string);
string = p11_kit_space_strdup (info.serialNumber, sizeof (info.serialNumber));
- CuAssertStrEquals (tc, "TEST SERIAL", string);
+ assert_str_eq ("TEST SERIAL", string);
free (string);
- CuAssertIntEquals (tc, CKF_LOGIN_REQUIRED | CKF_USER_PIN_INITIALIZED | CKF_CLOCK_ON_TOKEN | CKF_TOKEN_INITIALIZED, info.flags);
- CuAssertIntEquals (tc, 1, info.ulMaxSessionCount);
- CuAssertIntEquals (tc, 2, info.ulSessionCount);
- CuAssertIntEquals (tc, 3, info.ulMaxRwSessionCount);
- CuAssertIntEquals (tc, 4, info.ulRwSessionCount);
- CuAssertIntEquals (tc, 5, info.ulMaxPinLen);
- CuAssertIntEquals (tc, 6, info.ulMinPinLen);
- CuAssertIntEquals (tc, 7, info.ulTotalPublicMemory);
- CuAssertIntEquals (tc, 8, info.ulFreePublicMemory);
- CuAssertIntEquals (tc, 9, info.ulTotalPrivateMemory);
- CuAssertIntEquals (tc, 10, info.ulFreePrivateMemory);
- CuAssertIntEquals (tc, 75, info.hardwareVersion.major);
- CuAssertIntEquals (tc, 175, info.hardwareVersion.minor);
- CuAssertIntEquals (tc, 85, info.firmwareVersion.major);
- CuAssertIntEquals (tc, 185, info.firmwareVersion.minor);
- CuAssertTrue (tc, memcmp (info.utcTime, "1999052509195900", sizeof (info.utcTime)) == 0);
+ assert_num_eq (CKF_LOGIN_REQUIRED | CKF_USER_PIN_INITIALIZED | CKF_CLOCK_ON_TOKEN | CKF_TOKEN_INITIALIZED, info.flags);
+ assert_num_eq (1, info.ulMaxSessionCount);
+ assert_num_eq (2, info.ulSessionCount);
+ assert_num_eq (3, info.ulMaxRwSessionCount);
+ assert_num_eq (4, info.ulRwSessionCount);
+ assert_num_eq (5, info.ulMaxPinLen);
+ assert_num_eq (6, info.ulMinPinLen);
+ assert_num_eq (7, info.ulTotalPublicMemory);
+ assert_num_eq (8, info.ulFreePublicMemory);
+ assert_num_eq (9, info.ulTotalPrivateMemory);
+ assert_num_eq (10, info.ulFreePrivateMemory);
+ assert_num_eq (75, info.hardwareVersion.major);
+ assert_num_eq (175, info.hardwareVersion.minor);
+ assert_num_eq (85, info.firmwareVersion.major);
+ assert_num_eq (185, info.firmwareVersion.minor);
+ assert (memcmp (info.utcTime, "1999052509195900", sizeof (info.utcTime)) == 0);
rv = (module->C_GetTokenInfo) (MOCK_SLOT_TWO_ID, &info);
- CuAssertTrue (tc, rv == CKR_TOKEN_NOT_PRESENT);
+ assert (rv == CKR_TOKEN_NOT_PRESENT);
rv = (module->C_GetTokenInfo) (0, &info);
- CuAssertTrue (tc, rv == CKR_SLOT_ID_INVALID);
+ assert (rv == CKR_SLOT_ID_INVALID);
- teardown_mock_module (tc, module);
+ teardown_mock_module (module);
}
static void
-test_get_mechanism_list (CuTest *tc)
+test_get_mechanism_list (void)
{
CK_FUNCTION_LIST_PTR module;
CK_MECHANISM_TYPE mechs[8];
CK_ULONG count = 0;
CK_RV rv;
- module = setup_mock_module (tc, NULL);
+ module = setup_mock_module (NULL);
rv = (module->C_GetMechanismList) (MOCK_SLOT_ONE_ID, NULL, &count);
- CuAssertTrue (tc, rv == CKR_OK);
- CuAssertIntEquals (tc, 2, count);
+ assert (rv == CKR_OK);
+ assert_num_eq (2, count);
rv = (module->C_GetMechanismList) (MOCK_SLOT_TWO_ID, NULL, &count);
- CuAssertTrue (tc, rv == CKR_TOKEN_NOT_PRESENT);
+ assert (rv == CKR_TOKEN_NOT_PRESENT);
rv = (module->C_GetMechanismList) (0, NULL, &count);
- CuAssertTrue (tc, rv == CKR_SLOT_ID_INVALID);
+ assert (rv == CKR_SLOT_ID_INVALID);
count = 8;
rv = (module->C_GetMechanismList) (MOCK_SLOT_ONE_ID, mechs, &count);
- CuAssertTrue (tc, rv == CKR_OK);
- CuAssertIntEquals (tc, 2, count);
- CuAssertIntEquals (tc, mechs[0], CKM_MOCK_CAPITALIZE);
- CuAssertIntEquals (tc, mechs[1], CKM_MOCK_PREFIX);
+ assert (rv == CKR_OK);
+ assert_num_eq (2, count);
+ assert_num_eq (mechs[0], CKM_MOCK_CAPITALIZE);
+ assert_num_eq (mechs[1], CKM_MOCK_PREFIX);
- teardown_mock_module (tc, module);
+ teardown_mock_module (module);
}
static void
-test_get_mechanism_info (CuTest *tc)
+test_get_mechanism_info (void)
{
CK_FUNCTION_LIST_PTR module;
CK_MECHANISM_INFO info;
CK_RV rv;
- module = setup_mock_module (tc, NULL);
+ module = setup_mock_module (NULL);
rv = (module->C_GetMechanismInfo) (MOCK_SLOT_ONE_ID, CKM_MOCK_CAPITALIZE, &info);
- CuAssertTrue (tc, rv == CKR_OK);
- CuAssertIntEquals (tc, 512, info.ulMinKeySize);
- CuAssertIntEquals (tc, 4096, info.ulMaxKeySize);
- CuAssertIntEquals (tc, CKF_ENCRYPT | CKF_DECRYPT, info.flags);
+ assert (rv == CKR_OK);
+ assert_num_eq (512, info.ulMinKeySize);
+ assert_num_eq (4096, info.ulMaxKeySize);
+ assert_num_eq (CKF_ENCRYPT | CKF_DECRYPT, info.flags);
rv = (module->C_GetMechanismInfo) (MOCK_SLOT_ONE_ID, CKM_MOCK_PREFIX, &info);
- CuAssertTrue (tc, rv == CKR_OK);
- CuAssertIntEquals (tc, 2048, info.ulMinKeySize);
- CuAssertIntEquals (tc, 2048, info.ulMaxKeySize);
- CuAssertIntEquals (tc, CKF_SIGN | CKF_VERIFY, info.flags);
+ assert (rv == CKR_OK);
+ assert_num_eq (2048, info.ulMinKeySize);
+ assert_num_eq (2048, info.ulMaxKeySize);
+ assert_num_eq (CKF_SIGN | CKF_VERIFY, info.flags);
rv = (module->C_GetMechanismInfo) (MOCK_SLOT_TWO_ID, CKM_MOCK_PREFIX, &info);
- CuAssertTrue (tc, rv == CKR_TOKEN_NOT_PRESENT);
+ assert (rv == CKR_TOKEN_NOT_PRESENT);
rv = (module->C_GetMechanismInfo) (MOCK_SLOT_ONE_ID, 0, &info);
- CuAssertTrue (tc, rv == CKR_MECHANISM_INVALID);
+ assert (rv == CKR_MECHANISM_INVALID);
rv = (module->C_GetMechanismInfo) (0, CKM_MOCK_PREFIX, &info);
- CuAssertTrue (tc, rv == CKR_SLOT_ID_INVALID);
+ assert (rv == CKR_SLOT_ID_INVALID);
- teardown_mock_module (tc, module);
+ teardown_mock_module (module);
}
static void
-test_init_token (CuTest *tc)
+test_init_token (void)
{
CK_FUNCTION_LIST_PTR module;
CK_RV rv;
- module = setup_mock_module (tc, NULL);
+ module = setup_mock_module (NULL);
rv = (module->C_InitToken) (MOCK_SLOT_ONE_ID, (CK_UTF8CHAR_PTR)"TEST PIN", 8, (CK_UTF8CHAR_PTR)"TEST LABEL");
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = (module->C_InitToken) (MOCK_SLOT_ONE_ID, (CK_UTF8CHAR_PTR)"OTHER", 5, (CK_UTF8CHAR_PTR)"TEST LABEL");
- CuAssertTrue (tc, rv == CKR_PIN_INVALID);
+ assert (rv == CKR_PIN_INVALID);
rv = (module->C_InitToken) (MOCK_SLOT_TWO_ID, (CK_UTF8CHAR_PTR)"TEST PIN", 8, (CK_UTF8CHAR_PTR)"TEST LABEL");
- CuAssertTrue (tc, rv == CKR_TOKEN_NOT_PRESENT);
+ assert (rv == CKR_TOKEN_NOT_PRESENT);
rv = (module->C_InitToken) (0, (CK_UTF8CHAR_PTR)"TEST PIN", 8, (CK_UTF8CHAR_PTR)"TEST LABEL");
- CuAssertTrue (tc, rv == CKR_SLOT_ID_INVALID);
+ assert (rv == CKR_SLOT_ID_INVALID);
- teardown_mock_module (tc, module);
+ teardown_mock_module (module);
}
static void
-test_wait_for_slot_event (CuTest *tc)
+test_wait_for_slot_event (void)
{
CK_FUNCTION_LIST_PTR module;
CK_SLOT_ID slot;
@@ -271,179 +271,179 @@ test_wait_for_slot_event (CuTest *tc)
return;
#endif
- module = setup_mock_module (tc, NULL);
+ module = setup_mock_module (NULL);
rv = (module->C_WaitForSlotEvent) (0, &slot, NULL);
- CuAssertTrue (tc, rv == CKR_OK);
- CuAssertIntEquals (tc, slot, MOCK_SLOT_TWO_ID);
+ assert (rv == CKR_OK);
+ assert_num_eq (slot, MOCK_SLOT_TWO_ID);
rv = (module->C_WaitForSlotEvent) (CKF_DONT_BLOCK, &slot, NULL);
- CuAssertTrue (tc, rv == CKR_NO_EVENT);
+ assert (rv == CKR_NO_EVENT);
- teardown_mock_module (tc, module);
+ teardown_mock_module (module);
}
static void
-test_open_close_session (CuTest *tc)
+test_open_close_session (void)
{
CK_FUNCTION_LIST_PTR module;
CK_SESSION_HANDLE session = 0;
CK_RV rv;
- module = setup_mock_module (tc, NULL);
+ module = setup_mock_module (NULL);
rv = (module->C_OpenSession) (MOCK_SLOT_TWO_ID, CKF_SERIAL_SESSION, NULL, NULL, &session);
- CuAssertTrue (tc, rv == CKR_TOKEN_NOT_PRESENT);
+ assert (rv == CKR_TOKEN_NOT_PRESENT);
rv = (module->C_OpenSession) (0, CKF_SERIAL_SESSION, NULL, NULL, &session);
- CuAssertTrue (tc, rv == CKR_SLOT_ID_INVALID);
+ assert (rv == CKR_SLOT_ID_INVALID);
rv = (module->C_OpenSession) (MOCK_SLOT_ONE_ID, CKF_SERIAL_SESSION, NULL, NULL, &session);
- CuAssertTrue (tc, rv == CKR_OK);
- CuAssertTrue (tc, session != 0);
+ assert (rv == CKR_OK);
+ assert (session != 0);
rv = (module->C_CloseSession) (session);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = (module->C_CloseSession) (session);
- CuAssertTrue (tc, rv == CKR_SESSION_HANDLE_INVALID);
+ assert (rv == CKR_SESSION_HANDLE_INVALID);
- teardown_mock_module (tc, module);
+ teardown_mock_module (module);
}
static void
-test_close_all_sessions (CuTest *tc)
+test_close_all_sessions (void)
{
CK_FUNCTION_LIST_PTR module;
CK_SESSION_HANDLE session = 0;
CK_RV rv;
- module = setup_mock_module (tc, NULL);
+ module = setup_mock_module (NULL);
rv = (module->C_OpenSession) (MOCK_SLOT_ONE_ID, CKF_SERIAL_SESSION, NULL, NULL, &session);
- CuAssertTrue (tc, rv == CKR_OK);
- CuAssertTrue (tc, session != 0);
+ assert (rv == CKR_OK);
+ assert (session != 0);
rv = (module->C_CloseAllSessions) (MOCK_SLOT_ONE_ID);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = (module->C_CloseSession) (session);
- CuAssertTrue (tc, rv == CKR_SESSION_HANDLE_INVALID);
+ assert (rv == CKR_SESSION_HANDLE_INVALID);
- teardown_mock_module (tc, module);
+ teardown_mock_module (module);
}
static void
-test_get_function_status (CuTest *tc)
+test_get_function_status (void)
{
CK_FUNCTION_LIST_PTR module;
CK_SESSION_HANDLE session = 0;
CK_RV rv;
- module = setup_mock_module (tc, &session);
+ module = setup_mock_module (&session);
rv = (module->C_GetFunctionStatus) (session);
- CuAssertTrue (tc, rv == CKR_FUNCTION_NOT_PARALLEL);
+ assert (rv == CKR_FUNCTION_NOT_PARALLEL);
- teardown_mock_module (tc, module);
+ teardown_mock_module (module);
}
static void
-test_cancel_function (CuTest *tc)
+test_cancel_function (void)
{
CK_FUNCTION_LIST_PTR module;
CK_SESSION_HANDLE session = 0;
CK_RV rv;
- module = setup_mock_module (tc, &session);
+ module = setup_mock_module (&session);
rv = (module->C_CancelFunction) (session);
- CuAssertTrue (tc, rv == CKR_FUNCTION_NOT_PARALLEL);
+ assert (rv == CKR_FUNCTION_NOT_PARALLEL);
- teardown_mock_module (tc, module);
+ teardown_mock_module (module);
}
static void
-test_get_session_info (CuTest *tc)
+test_get_session_info (void)
{
CK_FUNCTION_LIST_PTR module;
CK_SESSION_HANDLE session = 0;
CK_SESSION_INFO info;
CK_RV rv;
- module = setup_mock_module (tc, NULL);
+ module = setup_mock_module (NULL);
rv = (module->C_GetSessionInfo) (0, &info);
- CuAssertTrue (tc, rv == CKR_SESSION_HANDLE_INVALID);
+ assert (rv == CKR_SESSION_HANDLE_INVALID);
rv = (module->C_OpenSession) (MOCK_SLOT_ONE_ID, CKF_SERIAL_SESSION, NULL, NULL, &session);
- CuAssertTrue (tc, rv == CKR_OK);
- CuAssertTrue (tc, session != 0);
+ assert (rv == CKR_OK);
+ assert (session != 0);
rv = (module->C_GetSessionInfo) (session, &info);
- CuAssertTrue (tc, rv == CKR_OK);
- CuAssertIntEquals (tc, MOCK_SLOT_ONE_ID, info.slotID);
- CuAssertIntEquals (tc, CKS_RO_PUBLIC_SESSION, info.state);
- CuAssertIntEquals (tc, CKF_SERIAL_SESSION, info.flags);
- CuAssertIntEquals (tc, 1414, info.ulDeviceError);
+ assert (rv == CKR_OK);
+ assert_num_eq (MOCK_SLOT_ONE_ID, info.slotID);
+ assert_num_eq (CKS_RO_PUBLIC_SESSION, info.state);
+ assert_num_eq (CKF_SERIAL_SESSION, info.flags);
+ assert_num_eq (1414, info.ulDeviceError);
rv = (module->C_OpenSession) (MOCK_SLOT_ONE_ID, CKF_RW_SESSION | CKF_SERIAL_SESSION, NULL, NULL, &session);
- CuAssertTrue (tc, rv == CKR_OK);
- CuAssertTrue (tc, session != 0);
+ assert (rv == CKR_OK);
+ assert (session != 0);
rv = (module->C_GetSessionInfo) (session, &info);
- CuAssertTrue (tc, rv == CKR_OK);
- CuAssertIntEquals (tc, MOCK_SLOT_ONE_ID, info.slotID);
- CuAssertIntEquals (tc, CKS_RW_PUBLIC_SESSION, info.state);
- CuAssertIntEquals (tc, CKF_SERIAL_SESSION | CKF_RW_SESSION, info.flags);
- CuAssertIntEquals (tc, 1414, info.ulDeviceError);
+ assert (rv == CKR_OK);
+ assert_num_eq (MOCK_SLOT_ONE_ID, info.slotID);
+ assert_num_eq (CKS_RW_PUBLIC_SESSION, info.state);
+ assert_num_eq (CKF_SERIAL_SESSION | CKF_RW_SESSION, info.flags);
+ assert_num_eq (1414, info.ulDeviceError);
- teardown_mock_module (tc, module);
+ teardown_mock_module (module);
}
static void
-test_init_pin (CuTest *tc)
+test_init_pin (void)
{
CK_FUNCTION_LIST_PTR module;
CK_SESSION_HANDLE session = 0;
CK_RV rv;
- module = setup_mock_module (tc, &session);
+ module = setup_mock_module (&session);
rv = (module->C_InitPIN) (0, (CK_UTF8CHAR_PTR)"TEST PIN", 8);
- CuAssertTrue (tc, rv == CKR_SESSION_HANDLE_INVALID);
+ assert (rv == CKR_SESSION_HANDLE_INVALID);
rv = (module->C_InitPIN) (session, (CK_UTF8CHAR_PTR)"TEST PIN", 8);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = (module->C_InitPIN) (session, (CK_UTF8CHAR_PTR)"OTHER", 5);
- CuAssertTrue (tc, rv == CKR_PIN_INVALID);
+ assert (rv == CKR_PIN_INVALID);
- teardown_mock_module (tc, module);
+ teardown_mock_module (module);
}
static void
-test_set_pin (CuTest *tc)
+test_set_pin (void)
{
CK_FUNCTION_LIST_PTR module;
CK_SESSION_HANDLE session = 0;
CK_RV rv;
- module = setup_mock_module (tc, &session);
+ module = setup_mock_module (&session);
rv = (module->C_SetPIN) (0, (CK_UTF8CHAR_PTR)"booo", 4, (CK_UTF8CHAR_PTR)"TEST PIN", 8);
- CuAssertTrue (tc, rv == CKR_SESSION_HANDLE_INVALID);
+ assert (rv == CKR_SESSION_HANDLE_INVALID);
rv = (module->C_SetPIN) (session, (CK_UTF8CHAR_PTR)"booo", 4, (CK_UTF8CHAR_PTR)"TEST PIN", 8);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = (module->C_SetPIN) (session, (CK_UTF8CHAR_PTR)"other", 5, (CK_UTF8CHAR_PTR)"OTHER", 5);
- CuAssertTrue (tc, rv == CKR_PIN_INCORRECT);
+ assert (rv == CKR_PIN_INCORRECT);
- teardown_mock_module (tc, module);
+ teardown_mock_module (module);
}
static void
-test_operation_state (CuTest *tc)
+test_operation_state (void)
{
CK_FUNCTION_LIST_PTR module;
CK_BYTE state[128];
@@ -451,54 +451,54 @@ test_operation_state (CuTest *tc)
CK_SESSION_HANDLE session = 0;
CK_RV rv;
- module = setup_mock_module (tc, &session);
+ module = setup_mock_module (&session);
state_len = sizeof (state);
rv = (module->C_GetOperationState) (0, state, &state_len);
- CuAssertTrue (tc, rv == CKR_SESSION_HANDLE_INVALID);
+ assert (rv == CKR_SESSION_HANDLE_INVALID);
state_len = sizeof (state);
rv = (module->C_GetOperationState) (session, state, &state_len);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = (module->C_SetOperationState) (session, state, state_len, 355, 455);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = (module->C_SetOperationState) (0, state, state_len, 355, 455);
- CuAssertTrue (tc, rv == CKR_SESSION_HANDLE_INVALID);
+ assert (rv == CKR_SESSION_HANDLE_INVALID);
- teardown_mock_module (tc, module);
+ teardown_mock_module (module);
}
static void
-test_login_logout (CuTest *tc)
+test_login_logout (void)
{
CK_FUNCTION_LIST_PTR module;
CK_SESSION_HANDLE session = 0;
CK_RV rv;
- module = setup_mock_module (tc, &session);
+ module = setup_mock_module (&session);
rv = (module->C_Login) (0, CKU_USER, (CK_UTF8CHAR_PTR)"booo", 4);
- CuAssertTrue (tc, rv == CKR_SESSION_HANDLE_INVALID);
+ assert (rv == CKR_SESSION_HANDLE_INVALID);
rv = (module->C_Login) (session, CKU_USER, (CK_UTF8CHAR_PTR)"bo", 2);
- CuAssertTrue (tc, rv == CKR_PIN_INCORRECT);
+ assert (rv == CKR_PIN_INCORRECT);
rv = (module->C_Login) (session, CKU_USER, (CK_UTF8CHAR_PTR)"booo", 4);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = (module->C_Logout) (session);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = (module->C_Logout) (session);
- CuAssertTrue (tc, rv == CKR_USER_NOT_LOGGED_IN);
+ assert (rv == CKR_USER_NOT_LOGGED_IN);
- teardown_mock_module (tc, module);
+ teardown_mock_module (module);
}
static void
-test_get_attribute_value (CuTest *tc)
+test_get_attribute_value (void)
{
CK_FUNCTION_LIST_PTR module;
CK_SESSION_HANDLE session = 0;
@@ -507,7 +507,7 @@ test_get_attribute_value (CuTest *tc)
CK_OBJECT_CLASS klass;
CK_RV rv;
- module = setup_mock_module (tc, &session);
+ module = setup_mock_module (&session);
attrs[0].type = CKA_CLASS;
attrs[0].pValue = &klass;
@@ -520,44 +520,44 @@ test_get_attribute_value (CuTest *tc)
attrs[2].ulValueLen = 0;
rv = (module->C_GetAttributeValue) (session, MOCK_PRIVATE_KEY_CAPITALIZE, attrs, 3);
- CuAssertTrue (tc, rv == CKR_USER_NOT_LOGGED_IN);
+ assert (rv == CKR_USER_NOT_LOGGED_IN);
rv = (module->C_GetAttributeValue) (session, MOCK_PUBLIC_KEY_CAPITALIZE, attrs, 2);
- CuAssertTrue (tc, rv == CKR_BUFFER_TOO_SMALL);
+ assert (rv == CKR_BUFFER_TOO_SMALL);
/* Get right size */
attrs[1].pValue = NULL;
attrs[1].ulValueLen = 0;
rv = (module->C_GetAttributeValue) (session, MOCK_PUBLIC_KEY_CAPITALIZE, attrs, 2);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = (module->C_GetAttributeValue) (session, MOCK_PUBLIC_KEY_CAPITALIZE, attrs, 3);
- CuAssertTrue (tc, rv == CKR_ATTRIBUTE_TYPE_INVALID);
+ assert (rv == CKR_ATTRIBUTE_TYPE_INVALID);
- CuAssertIntEquals (tc, CKO_PUBLIC_KEY, klass);
- CuAssertIntEquals (tc, 21, attrs[1].ulValueLen);
- CuAssertPtrEquals (tc, NULL, attrs[1].pValue);
+ assert_num_eq (CKO_PUBLIC_KEY, klass);
+ assert_num_eq (21, attrs[1].ulValueLen);
+ assert_ptr_eq (NULL, attrs[1].pValue);
attrs[1].pValue = label;
attrs[1].ulValueLen = sizeof (label);
- CuAssertTrue (tc, (CK_ULONG)-1 == attrs[2].ulValueLen);
- CuAssertPtrEquals (tc, NULL, attrs[2].pValue);
+ assert ((CK_ULONG)-1 == attrs[2].ulValueLen);
+ assert_ptr_eq (NULL, attrs[2].pValue);
rv = (module->C_GetAttributeValue) (session, MOCK_PUBLIC_KEY_CAPITALIZE, attrs, 3);
- CuAssertTrue (tc, rv == CKR_ATTRIBUTE_TYPE_INVALID);
+ assert (rv == CKR_ATTRIBUTE_TYPE_INVALID);
- CuAssertIntEquals (tc, CKO_PUBLIC_KEY, klass);
- CuAssertIntEquals (tc, 21, attrs[1].ulValueLen);
- CuAssertPtrEquals (tc, label, attrs[1].pValue);
- CuAssertTrue (tc, memcmp (label, "Public Capitalize Key", attrs[1].ulValueLen) == 0);
- CuAssertTrue (tc, (CK_ULONG)-1 == attrs[2].ulValueLen);
- CuAssertPtrEquals (tc, NULL, attrs[2].pValue);
+ assert_num_eq (CKO_PUBLIC_KEY, klass);
+ assert_num_eq (21, attrs[1].ulValueLen);
+ assert_ptr_eq (label, attrs[1].pValue);
+ assert (memcmp (label, "Public Capitalize Key", attrs[1].ulValueLen) == 0);
+ assert ((CK_ULONG)-1 == attrs[2].ulValueLen);
+ assert_ptr_eq (NULL, attrs[2].pValue);
- teardown_mock_module (tc, module);
+ teardown_mock_module (module);
}
static void
-test_set_attribute_value (CuTest *tc)
+test_set_attribute_value (void)
{
CK_FUNCTION_LIST_PTR module;
CK_SESSION_HANDLE session = 0;
@@ -566,7 +566,7 @@ test_set_attribute_value (CuTest *tc)
CK_ULONG bits;
CK_RV rv;
- module = setup_mock_module (tc, &session);
+ module = setup_mock_module (&session);
strcpy (label, "Blahooo");
bits = 1555;
@@ -579,26 +579,26 @@ test_set_attribute_value (CuTest *tc)
attrs[1].ulValueLen = sizeof (bits);
rv = (module->C_SetAttributeValue) (session, MOCK_PRIVATE_KEY_CAPITALIZE, attrs, 2);
- CuAssertTrue (tc, rv == CKR_USER_NOT_LOGGED_IN);
+ assert (rv == CKR_USER_NOT_LOGGED_IN);
rv = (module->C_SetAttributeValue) (session, MOCK_PUBLIC_KEY_CAPITALIZE, attrs, 2);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
memset (label, 0, sizeof (label));
bits = 0;
rv = (module->C_GetAttributeValue) (session, MOCK_PUBLIC_KEY_CAPITALIZE, attrs, 2);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
- CuAssertIntEquals (tc, bits, 1555);
- CuAssertIntEquals (tc, 7, attrs[0].ulValueLen);
- CuAssertTrue (tc, memcmp (label, "Blahooo", attrs[0].ulValueLen) == 0);
+ assert_num_eq (bits, 1555);
+ assert_num_eq (7, attrs[0].ulValueLen);
+ assert (memcmp (label, "Blahooo", attrs[0].ulValueLen) == 0);
- teardown_mock_module (tc, module);
+ teardown_mock_module (module);
}
static void
-test_create_object (CuTest *tc)
+test_create_object (void)
{
CK_FUNCTION_LIST_PTR module;
CK_SESSION_HANDLE session = 0;
@@ -608,7 +608,7 @@ test_create_object (CuTest *tc)
CK_ULONG bits;
CK_RV rv;
- module = setup_mock_module (tc, &session);
+ module = setup_mock_module (&session);
strcpy (label, "Blahooo");
bits = 1555;
@@ -621,27 +621,27 @@ test_create_object (CuTest *tc)
attrs[1].ulValueLen = sizeof (bits);
rv = (module->C_CreateObject) (0, attrs, 2, &object);
- CuAssertTrue (tc, rv == CKR_SESSION_HANDLE_INVALID);
+ assert (rv == CKR_SESSION_HANDLE_INVALID);
rv = (module->C_CreateObject) (session, attrs, 2, &object);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
attrs[0].ulValueLen = sizeof (label);
memset (label, 0, sizeof (label));
bits = 0;
rv = (module->C_GetAttributeValue) (session, object, attrs, 2);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
- CuAssertIntEquals (tc, bits, 1555);
- CuAssertIntEquals (tc, 7, attrs[0].ulValueLen);
- CuAssertTrue (tc, memcmp (label, "Blahooo", attrs[0].ulValueLen) == 0);
+ assert_num_eq (bits, 1555);
+ assert_num_eq (7, attrs[0].ulValueLen);
+ assert (memcmp (label, "Blahooo", attrs[0].ulValueLen) == 0);
- teardown_mock_module (tc, module);
+ teardown_mock_module (module);
}
static void
-test_copy_object (CuTest *tc)
+test_copy_object (void)
{
CK_FUNCTION_LIST_PTR module;
CK_SESSION_HANDLE session = 0;
@@ -651,7 +651,7 @@ test_copy_object (CuTest *tc)
CK_ULONG bits;
CK_RV rv;
- module = setup_mock_module (tc, &session);
+ module = setup_mock_module (&session);
bits = 1555;
@@ -660,10 +660,10 @@ test_copy_object (CuTest *tc)
attrs[0].ulValueLen = sizeof (bits);
rv = (module->C_CopyObject) (session, 1333, attrs, 1, &object);
- CuAssertTrue (tc, rv == CKR_OBJECT_HANDLE_INVALID);
+ assert (rv == CKR_OBJECT_HANDLE_INVALID);
rv = (module->C_CopyObject) (session, MOCK_PUBLIC_KEY_CAPITALIZE, attrs, 1, &object);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
attrs[1].type = CKA_LABEL;
attrs[1].pValue = label;
@@ -671,17 +671,17 @@ test_copy_object (CuTest *tc)
bits = 0;
rv = (module->C_GetAttributeValue) (session, object, attrs, 2);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
- CuAssertIntEquals (tc, bits, 1555);
- CuAssertIntEquals (tc, 21, attrs[1].ulValueLen);
- CuAssertTrue (tc, memcmp (label, "Public Capitalize Key", attrs[1].ulValueLen) == 0);
+ assert_num_eq (bits, 1555);
+ assert_num_eq (21, attrs[1].ulValueLen);
+ assert (memcmp (label, "Public Capitalize Key", attrs[1].ulValueLen) == 0);
- teardown_mock_module (tc, module);
+ teardown_mock_module (module);
}
static void
-test_destroy_object (CuTest *tc)
+test_destroy_object (void)
{
CK_FUNCTION_LIST_PTR module;
CK_SESSION_HANDLE session = 0;
@@ -689,51 +689,51 @@ test_destroy_object (CuTest *tc)
char label[32];
CK_RV rv;
- module = setup_mock_module (tc, &session);
+ module = setup_mock_module (&session);
attrs[0].type = CKA_LABEL;
attrs[0].pValue = label;
attrs[0].ulValueLen = sizeof (label);
rv = (module->C_GetAttributeValue) (session, MOCK_PUBLIC_KEY_CAPITALIZE, attrs, 1);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = (module->C_DestroyObject) (0, MOCK_PUBLIC_KEY_CAPITALIZE);
- CuAssertTrue (tc, rv == CKR_SESSION_HANDLE_INVALID);
+ assert (rv == CKR_SESSION_HANDLE_INVALID);
rv = (module->C_DestroyObject) (session, MOCK_PUBLIC_KEY_CAPITALIZE);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = (module->C_GetAttributeValue) (session, MOCK_PUBLIC_KEY_CAPITALIZE, attrs, 1);
- CuAssertTrue (tc, rv == CKR_OBJECT_HANDLE_INVALID);
+ assert (rv == CKR_OBJECT_HANDLE_INVALID);
- teardown_mock_module (tc, module);
+ teardown_mock_module (module);
}
static void
-test_get_object_size (CuTest *tc)
+test_get_object_size (void)
{
CK_FUNCTION_LIST_PTR module;
CK_SESSION_HANDLE session = 0;
CK_ULONG size;
CK_RV rv;
- module = setup_mock_module (tc, &session);
+ module = setup_mock_module (&session);
rv = (module->C_GetObjectSize) (session, 1333, &size);
- CuAssertTrue (tc, rv == CKR_OBJECT_HANDLE_INVALID);
+ assert (rv == CKR_OBJECT_HANDLE_INVALID);
rv = (module->C_GetObjectSize) (session, MOCK_PUBLIC_KEY_CAPITALIZE, &size);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
/* The number here is the length of all attributes added up */
- CuAssertIntEquals (tc, sizeof (CK_ULONG) == 8 ? 44 : 36, size);
+ assert_num_eq (sizeof (CK_ULONG) == 8 ? 44 : 36, size);
- teardown_mock_module (tc, module);
+ teardown_mock_module (module);
}
static void
-test_find_objects (CuTest *tc)
+test_find_objects (void)
{
CK_FUNCTION_LIST_PTR module;
CK_SESSION_HANDLE session = 0;
@@ -744,55 +744,55 @@ test_find_objects (CuTest *tc)
CK_ULONG i;
CK_RV rv;
- module = setup_mock_module (tc, &session);
+ module = setup_mock_module (&session);
rv = (module->C_FindObjectsInit) (0, &attr, 1);
- CuAssertTrue (tc, rv == CKR_SESSION_HANDLE_INVALID);
+ assert (rv == CKR_SESSION_HANDLE_INVALID);
rv = (module->C_FindObjectsInit) (session, &attr, 1);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = (module->C_FindObjects) (0, objects, 16, &count);
- CuAssertTrue (tc, rv == CKR_SESSION_HANDLE_INVALID);
+ assert (rv == CKR_SESSION_HANDLE_INVALID);
rv = (module->C_FindObjects) (session, objects, 16, &count);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
- CuAssertTrue (tc, count < 16);
+ assert (count < 16);
/* Make sure we get the capitalize public key */
for (i = 0; i < count; i++) {
if (objects[i] == MOCK_PUBLIC_KEY_CAPITALIZE)
break;
}
- CuAssertTrue (tc, i != count);
+ assert (i != count);
/* Make sure we get the prefix public key */
for (i = 0; i < count; i++) {
if (objects[i] == MOCK_PUBLIC_KEY_PREFIX)
break;
}
- CuAssertTrue (tc, i != count);
+ assert (i != count);
/* Make sure all public keys */
for (i = 0; i < count; i++) {
klass = (CK_ULONG)-1;
rv = (module->C_GetAttributeValue) (session, objects[i], &attr, 1);
- CuAssertTrue (tc, rv == CKR_OK);
- CuAssertIntEquals (tc, CKO_PUBLIC_KEY, klass);
+ assert (rv == CKR_OK);
+ assert_num_eq (CKO_PUBLIC_KEY, klass);
}
rv = (module->C_FindObjectsFinal) (session);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = (module->C_FindObjectsFinal) (session);
- CuAssertTrue (tc, rv == CKR_OPERATION_NOT_INITIALIZED);
+ assert (rv == CKR_OPERATION_NOT_INITIALIZED);
- teardown_mock_module (tc, module);
+ teardown_mock_module (module);
}
static void
-test_encrypt (CuTest *tc)
+test_encrypt (void)
{
CK_FUNCTION_LIST_PTR module;
CK_SESSION_HANDLE session = 0;
@@ -801,52 +801,52 @@ test_encrypt (CuTest *tc)
CK_ULONG length;
CK_RV rv;
- module = setup_mock_module (tc, &session);
+ module = setup_mock_module (&session);
rv = (module->C_EncryptInit) (session, &mech, MOCK_PUBLIC_KEY_PREFIX);
- CuAssertTrue (tc, rv == CKR_KEY_HANDLE_INVALID);
+ assert (rv == CKR_KEY_HANDLE_INVALID);
rv = (module->C_EncryptInit) (session, &mech, MOCK_PUBLIC_KEY_CAPITALIZE);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
length = sizeof (data);
rv = (module->C_Encrypt) (0, (CK_BYTE_PTR)"blah", 4, data, &length);
- CuAssertTrue (tc, rv == CKR_SESSION_HANDLE_INVALID);
+ assert (rv == CKR_SESSION_HANDLE_INVALID);
length = sizeof (data);
rv = (module->C_Encrypt) (session, (CK_BYTE_PTR)"blah", 4, data, &length);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
- CuAssertIntEquals (tc, 4, length);
- CuAssertTrue (tc, memcmp (data, "BLAH", 4) == 0);
+ assert_num_eq (4, length);
+ assert (memcmp (data, "BLAH", 4) == 0);
rv = (module->C_EncryptInit) (session, &mech, MOCK_PUBLIC_KEY_CAPITALIZE);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
length = sizeof (data);
rv = (module->C_EncryptUpdate) (0, (CK_BYTE_PTR)"blah", 4, data, &length);
- CuAssertTrue (tc, rv == CKR_SESSION_HANDLE_INVALID);
+ assert (rv == CKR_SESSION_HANDLE_INVALID);
length = sizeof (data);
rv = (module->C_EncryptUpdate) (session, (CK_BYTE_PTR)"sLurm", 5, data, &length);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
- CuAssertIntEquals (tc, 5, length);
- CuAssertTrue (tc, memcmp (data, "SLURM", 5) == 0);
+ assert_num_eq (5, length);
+ assert (memcmp (data, "SLURM", 5) == 0);
length = sizeof (data);
rv = (module->C_EncryptFinal) (0, data, &length);
- CuAssertTrue (tc, rv == CKR_SESSION_HANDLE_INVALID);
+ assert (rv == CKR_SESSION_HANDLE_INVALID);
length = sizeof (data);
rv = (module->C_EncryptFinal) (session, data, &length);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
- teardown_mock_module (tc, module);
+ teardown_mock_module (module);
}
static void
-test_decrypt (CuTest *tc)
+test_decrypt (void)
{
CK_FUNCTION_LIST_PTR module;
CK_SESSION_HANDLE session = 0;
@@ -855,55 +855,55 @@ test_decrypt (CuTest *tc)
CK_ULONG length;
CK_RV rv;
- module = setup_mock_module (tc, &session);
+ module = setup_mock_module (&session);
rv = (module->C_Login) (session, CKU_USER, (CK_BYTE_PTR)"booo", 4);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = (module->C_DecryptInit) (session, &mech, MOCK_PRIVATE_KEY_PREFIX);
- CuAssertTrue (tc, rv == CKR_KEY_HANDLE_INVALID);
+ assert (rv == CKR_KEY_HANDLE_INVALID);
rv = (module->C_DecryptInit) (session, &mech, MOCK_PRIVATE_KEY_CAPITALIZE);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
length = sizeof (data);
rv = (module->C_Decrypt) (0, (CK_BYTE_PTR)"bLAH", 4, data, &length);
- CuAssertTrue (tc, rv == CKR_SESSION_HANDLE_INVALID);
+ assert (rv == CKR_SESSION_HANDLE_INVALID);
length = sizeof (data);
rv = (module->C_Decrypt) (session, (CK_BYTE_PTR)"BLAh", 4, data, &length);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
- CuAssertIntEquals (tc, 4, length);
- CuAssertTrue (tc, memcmp (data, "blah", 4) == 0);
+ assert_num_eq (4, length);
+ assert (memcmp (data, "blah", 4) == 0);
rv = (module->C_DecryptInit) (session, &mech, MOCK_PRIVATE_KEY_CAPITALIZE);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
length = sizeof (data);
rv = (module->C_DecryptUpdate) (0, (CK_BYTE_PTR)"blah", 4, data, &length);
- CuAssertTrue (tc, rv == CKR_SESSION_HANDLE_INVALID);
+ assert (rv == CKR_SESSION_HANDLE_INVALID);
length = sizeof (data);
rv = (module->C_DecryptUpdate) (session, (CK_BYTE_PTR)"sLuRM", 5, data, &length);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
- CuAssertIntEquals (tc, 5, length);
- CuAssertTrue (tc, memcmp (data, "slurm", 5) == 0);
+ assert_num_eq (5, length);
+ assert (memcmp (data, "slurm", 5) == 0);
length = sizeof (data);
rv = (module->C_DecryptFinal) (0, data, &length);
- CuAssertTrue (tc, rv == CKR_SESSION_HANDLE_INVALID);
+ assert (rv == CKR_SESSION_HANDLE_INVALID);
length = sizeof (data);
rv = (module->C_DecryptFinal) (session, data, &length);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
- teardown_mock_module (tc, module);
+ teardown_mock_module (module);
}
static void
-test_digest (CuTest *tc)
+test_digest (void)
{
CK_FUNCTION_LIST_PTR module;
CK_SESSION_HANDLE session = 0;
@@ -912,58 +912,58 @@ test_digest (CuTest *tc)
CK_ULONG length;
CK_RV rv;
- module = setup_mock_module (tc, &session);
+ module = setup_mock_module (&session);
rv = (module->C_DigestInit) (0, &mech);
- CuAssertTrue (tc, rv == CKR_SESSION_HANDLE_INVALID);
+ assert (rv == CKR_SESSION_HANDLE_INVALID);
rv = (module->C_DigestInit) (session, &mech);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
length = sizeof (digest);
rv = (module->C_Digest) (0, (CK_BYTE_PTR)"bLAH", 4, digest, &length);
- CuAssertTrue (tc, rv == CKR_SESSION_HANDLE_INVALID);
+ assert (rv == CKR_SESSION_HANDLE_INVALID);
length = sizeof (digest);
rv = (module->C_Digest) (session, (CK_BYTE_PTR)"BLAh", 4, digest, &length);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
- CuAssertIntEquals (tc, 1, length);
- CuAssertTrue (tc, memcmp (digest, "4", 1) == 0);
+ assert_num_eq (1, length);
+ assert (memcmp (digest, "4", 1) == 0);
rv = (module->C_DigestInit) (session, &mech);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = (module->C_DigestUpdate) (0, (CK_BYTE_PTR)"blah", 4);
- CuAssertTrue (tc, rv == CKR_SESSION_HANDLE_INVALID);
+ assert (rv == CKR_SESSION_HANDLE_INVALID);
rv = (module->C_DigestUpdate) (session, (CK_BYTE_PTR)"sLuRM", 5);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
/* Adds the the value of object handle to hash: 6 */
- CuAssertIntEquals (tc, 6, MOCK_PUBLIC_KEY_PREFIX);
+ assert_num_eq (6, MOCK_PUBLIC_KEY_PREFIX);
rv = (module->C_DigestKey) (session, MOCK_PUBLIC_KEY_PREFIX);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = (module->C_DigestUpdate) (session, (CK_BYTE_PTR)"Other", 5);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
length = sizeof (digest);
rv = (module->C_DigestFinal) (0, digest, &length);
- CuAssertTrue (tc, rv == CKR_SESSION_HANDLE_INVALID);
+ assert (rv == CKR_SESSION_HANDLE_INVALID);
length = sizeof (digest);
rv = (module->C_DigestFinal) (session, digest, &length);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
- CuAssertIntEquals (tc, 2, length);
- CuAssertTrue (tc, memcmp (digest, "16", 2) == 0);
+ assert_num_eq (2, length);
+ assert (memcmp (digest, "16", 2) == 0);
- teardown_mock_module (tc, module);
+ teardown_mock_module (module);
}
static void
-test_sign (CuTest *tc)
+test_sign (void)
{
CK_FUNCTION_LIST_PTR module;
CK_SESSION_HANDLE session = 0;
@@ -972,62 +972,62 @@ test_sign (CuTest *tc)
CK_ULONG length;
CK_RV rv;
- module = setup_mock_module (tc, &session);
+ module = setup_mock_module (&session);
rv = (module->C_Login) (session, CKU_USER, (CK_BYTE_PTR)"booo", 4);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = (module->C_SignInit) (0, &mech, MOCK_PRIVATE_KEY_PREFIX);
- CuAssertTrue (tc, rv == CKR_SESSION_HANDLE_INVALID);
+ assert (rv == CKR_SESSION_HANDLE_INVALID);
rv = (module->C_SignInit) (session, &mech, MOCK_PRIVATE_KEY_PREFIX);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = (module->C_Login) (session, CKU_CONTEXT_SPECIFIC, (CK_BYTE_PTR)"booo", 4);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
length = sizeof (signature);
rv = (module->C_Sign) (0, (CK_BYTE_PTR)"bLAH", 4, signature, &length);
- CuAssertTrue (tc, rv == CKR_SESSION_HANDLE_INVALID);
+ assert (rv == CKR_SESSION_HANDLE_INVALID);
length = sizeof (signature);
rv = (module->C_Sign) (session, (CK_BYTE_PTR)"BLAh", 4, signature, &length);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
- CuAssertIntEquals (tc, 13, length);
- CuAssertTrue (tc, memcmp (signature, "prefix:value4", 13) == 0);
+ assert_num_eq (13, length);
+ assert (memcmp (signature, "prefix:value4", 13) == 0);
rv = (module->C_SignInit) (session, &mech, MOCK_PRIVATE_KEY_PREFIX);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = (module->C_Login) (session, CKU_CONTEXT_SPECIFIC, (CK_BYTE_PTR)"booo", 4);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = (module->C_SignUpdate) (0, (CK_BYTE_PTR)"blah", 4);
- CuAssertTrue (tc, rv == CKR_SESSION_HANDLE_INVALID);
+ assert (rv == CKR_SESSION_HANDLE_INVALID);
rv = (module->C_SignUpdate) (session, (CK_BYTE_PTR)"sLuRM", 5);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = (module->C_SignUpdate) (session, (CK_BYTE_PTR)"Other", 5);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
length = sizeof (signature);
rv = (module->C_SignFinal) (0, signature, &length);
- CuAssertTrue (tc, rv == CKR_SESSION_HANDLE_INVALID);
+ assert (rv == CKR_SESSION_HANDLE_INVALID);
length = sizeof (signature);
rv = (module->C_SignFinal) (session, signature, &length);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
- CuAssertIntEquals (tc, 14, length);
- CuAssertTrue (tc, memcmp (signature, "prefix:value10", 2) == 0);
+ assert_num_eq (14, length);
+ assert (memcmp (signature, "prefix:value10", 2) == 0);
- teardown_mock_module (tc, module);
+ teardown_mock_module (module);
}
static void
-test_sign_recover (CuTest *tc)
+test_sign_recover (void)
{
CK_FUNCTION_LIST_PTR module;
CK_SESSION_HANDLE session = 0;
@@ -1036,36 +1036,36 @@ test_sign_recover (CuTest *tc)
CK_ULONG length;
CK_RV rv;
- module = setup_mock_module (tc, &session);
+ module = setup_mock_module (&session);
rv = (module->C_Login) (session, CKU_USER, (CK_BYTE_PTR)"booo", 4);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = (module->C_SignRecoverInit) (0, &mech, MOCK_PRIVATE_KEY_PREFIX);
- CuAssertTrue (tc, rv == CKR_SESSION_HANDLE_INVALID);
+ assert (rv == CKR_SESSION_HANDLE_INVALID);
rv = (module->C_SignRecoverInit) (session, &mech, MOCK_PRIVATE_KEY_PREFIX);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = (module->C_Login) (session, CKU_CONTEXT_SPECIFIC, (CK_BYTE_PTR)"booo", 4);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
length = sizeof (signature);
rv = (module->C_SignRecover) (0, (CK_BYTE_PTR)"bLAH", 4, signature, &length);
- CuAssertTrue (tc, rv == CKR_SESSION_HANDLE_INVALID);
+ assert (rv == CKR_SESSION_HANDLE_INVALID);
length = sizeof (signature);
rv = (module->C_SignRecover) (session, (CK_BYTE_PTR)"BLAh", 4, signature, &length);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
- CuAssertIntEquals (tc, 16, length);
- CuAssertTrue (tc, memcmp (signature, "prefix:valueBLAh", 16) == 0);
+ assert_num_eq (16, length);
+ assert (memcmp (signature, "prefix:valueBLAh", 16) == 0);
- teardown_mock_module (tc, module);
+ teardown_mock_module (module);
}
static void
-test_verify (CuTest *tc)
+test_verify (void)
{
CK_FUNCTION_LIST_PTR module;
CK_SESSION_HANDLE session = 0;
@@ -1074,48 +1074,48 @@ test_verify (CuTest *tc)
CK_ULONG length;
CK_RV rv;
- module = setup_mock_module (tc, &session);
+ module = setup_mock_module (&session);
rv = (module->C_VerifyInit) (0, &mech, MOCK_PUBLIC_KEY_PREFIX);
- CuAssertTrue (tc, rv == CKR_SESSION_HANDLE_INVALID);
+ assert (rv == CKR_SESSION_HANDLE_INVALID);
rv = (module->C_VerifyInit) (session, &mech, MOCK_PUBLIC_KEY_PREFIX);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
length = 13;
memcpy (signature, "prefix:value4", length);
rv = (module->C_Verify) (0, (CK_BYTE_PTR)"bLAH", 4, signature, 5);
- CuAssertTrue (tc, rv == CKR_SESSION_HANDLE_INVALID);
+ assert (rv == CKR_SESSION_HANDLE_INVALID);
rv = (module->C_Verify) (session, (CK_BYTE_PTR)"BLAh", 4, signature, length);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = (module->C_VerifyInit) (session, &mech, MOCK_PUBLIC_KEY_PREFIX);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = (module->C_VerifyUpdate) (0, (CK_BYTE_PTR)"blah", 4);
- CuAssertTrue (tc, rv == CKR_SESSION_HANDLE_INVALID);
+ assert (rv == CKR_SESSION_HANDLE_INVALID);
rv = (module->C_VerifyUpdate) (session, (CK_BYTE_PTR)"sLuRM", 5);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = (module->C_VerifyUpdate) (session, (CK_BYTE_PTR)"Other", 5);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
length = 14;
memcpy (signature, "prefix:value10", length);
rv = (module->C_VerifyFinal) (session, signature, 5);
- CuAssertTrue (tc, rv == CKR_SIGNATURE_LEN_RANGE);
+ assert (rv == CKR_SIGNATURE_LEN_RANGE);
rv = (module->C_VerifyFinal) (session, signature, length);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
- teardown_mock_module (tc, module);
+ teardown_mock_module (module);
}
static void
-test_verify_recover (CuTest *tc)
+test_verify_recover (void)
{
CK_FUNCTION_LIST_PTR module;
CK_SESSION_HANDLE session = 0;
@@ -1124,30 +1124,30 @@ test_verify_recover (CuTest *tc)
CK_ULONG length;
CK_RV rv;
- module = setup_mock_module (tc, &session);
+ module = setup_mock_module (&session);
rv = (module->C_VerifyRecoverInit) (0, &mech, MOCK_PUBLIC_KEY_PREFIX);
- CuAssertTrue (tc, rv == CKR_SESSION_HANDLE_INVALID);
+ assert (rv == CKR_SESSION_HANDLE_INVALID);
rv = (module->C_VerifyRecoverInit) (session, &mech, MOCK_PUBLIC_KEY_PREFIX);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
length = sizeof (data);
rv = (module->C_VerifyRecover) (0, (CK_BYTE_PTR)"prefix:valueBLah", 16, data, &length);
- CuAssertTrue (tc, rv == CKR_SESSION_HANDLE_INVALID);
+ assert (rv == CKR_SESSION_HANDLE_INVALID);
length = sizeof (data);
rv = (module->C_VerifyRecover) (session, (CK_BYTE_PTR)"prefix:valueBLah", 16, data, &length);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
- CuAssertIntEquals (tc, 4, length);
- CuAssertTrue (tc, memcmp (data, "BLah", 4) == 0);
+ assert_num_eq (4, length);
+ assert (memcmp (data, "BLah", 4) == 0);
- teardown_mock_module (tc, module);
+ teardown_mock_module (module);
}
static void
-test_digest_encrypt (CuTest *tc)
+test_digest_encrypt (void)
{
CK_FUNCTION_LIST_PTR module;
CK_SESSION_HANDLE session = 0;
@@ -1157,41 +1157,41 @@ test_digest_encrypt (CuTest *tc)
CK_ULONG length;
CK_RV rv;
- module = setup_mock_module (tc, &session);
+ module = setup_mock_module (&session);
rv = (module->C_EncryptInit) (session, &mech, MOCK_PUBLIC_KEY_CAPITALIZE);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = (module->C_DigestInit) (session, &dmech);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
length = sizeof (data);
rv = (module->C_DigestEncryptUpdate) (0, (CK_BYTE_PTR)"blah", 4, data, &length);
- CuAssertTrue (tc, rv == CKR_SESSION_HANDLE_INVALID);
+ assert (rv == CKR_SESSION_HANDLE_INVALID);
length = sizeof (data);
rv = (module->C_DigestEncryptUpdate) (session, (CK_BYTE_PTR)"blah", 4, data, &length);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
- CuAssertIntEquals (tc, 4, length);
- CuAssertTrue (tc, memcmp (data, "BLAH", 4) == 0);
+ assert_num_eq (4, length);
+ assert (memcmp (data, "BLAH", 4) == 0);
length = sizeof (data);
rv = (module->C_EncryptFinal) (session, data, &length);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
length = sizeof (data);
rv = (module->C_DigestFinal) (session, data, &length);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
- CuAssertIntEquals (tc, 1, length);
- CuAssertTrue (tc, memcmp (data, "4", 1) == 0);
+ assert_num_eq (1, length);
+ assert (memcmp (data, "4", 1) == 0);
- teardown_mock_module (tc, module);
+ teardown_mock_module (module);
}
static void
-test_decrypt_digest (CuTest *tc)
+test_decrypt_digest (void)
{
CK_FUNCTION_LIST_PTR module;
CK_SESSION_HANDLE session = 0;
@@ -1201,44 +1201,44 @@ test_decrypt_digest (CuTest *tc)
CK_ULONG length;
CK_RV rv;
- module = setup_mock_module (tc, &session);
+ module = setup_mock_module (&session);
rv = (module->C_Login) (session, CKU_USER, (CK_BYTE_PTR)"booo", 4);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = (module->C_DecryptInit) (session, &mech, MOCK_PRIVATE_KEY_CAPITALIZE);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = (module->C_DigestInit) (session, &dmech);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
length = sizeof (data);
rv = (module->C_DecryptDigestUpdate) (0, (CK_BYTE_PTR)"BLAH", 4, data, &length);
- CuAssertTrue (tc, rv == CKR_SESSION_HANDLE_INVALID);
+ assert (rv == CKR_SESSION_HANDLE_INVALID);
length = sizeof (data);
rv = (module->C_DecryptDigestUpdate) (session, (CK_BYTE_PTR)"BLAH", 4, data, &length);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
- CuAssertIntEquals (tc, 4, length);
- CuAssertTrue (tc, memcmp (data, "blah", 4) == 0);
+ assert_num_eq (4, length);
+ assert (memcmp (data, "blah", 4) == 0);
length = sizeof (data);
rv = (module->C_DecryptFinal) (session, data, &length);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
length = sizeof (data);
rv = (module->C_DigestFinal) (session, data, &length);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
- CuAssertIntEquals (tc, 1, length);
- CuAssertTrue (tc, memcmp (data, "4", 1) == 0);
+ assert_num_eq (1, length);
+ assert (memcmp (data, "4", 1) == 0);
- teardown_mock_module (tc, module);
+ teardown_mock_module (module);
}
static void
-test_sign_encrypt (CuTest *tc)
+test_sign_encrypt (void)
{
CK_FUNCTION_LIST_PTR module;
CK_SESSION_HANDLE session = 0;
@@ -1248,47 +1248,47 @@ test_sign_encrypt (CuTest *tc)
CK_ULONG length;
CK_RV rv;
- module = setup_mock_module (tc, &session);
+ module = setup_mock_module (&session);
rv = (module->C_Login) (session, CKU_USER, (CK_BYTE_PTR)"booo", 4);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = (module->C_EncryptInit) (session, &mech, MOCK_PUBLIC_KEY_CAPITALIZE);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = (module->C_SignInit) (session, &smech, MOCK_PRIVATE_KEY_PREFIX);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = (module->C_Login) (session, CKU_CONTEXT_SPECIFIC, (CK_BYTE_PTR)"booo", 4);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
length = sizeof (data);
rv = (module->C_SignEncryptUpdate) (0, (CK_BYTE_PTR)"blah", 4, data, &length);
- CuAssertTrue (tc, rv == CKR_SESSION_HANDLE_INVALID);
+ assert (rv == CKR_SESSION_HANDLE_INVALID);
length = sizeof (data);
rv = (module->C_SignEncryptUpdate) (session, (CK_BYTE_PTR)"blah", 4, data, &length);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
- CuAssertIntEquals (tc, 4, length);
- CuAssertTrue (tc, memcmp (data, "BLAH", 4) == 0);
+ assert_num_eq (4, length);
+ assert (memcmp (data, "BLAH", 4) == 0);
length = sizeof (data);
rv = (module->C_EncryptFinal) (session, data, &length);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
length = sizeof (data);
rv = (module->C_SignFinal) (session, data, &length);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
- CuAssertIntEquals (tc, 8, length);
- CuAssertTrue (tc, memcmp (data, "p:value4", 1) == 0);
+ assert_num_eq (8, length);
+ assert (memcmp (data, "p:value4", 1) == 0);
- teardown_mock_module (tc, module);
+ teardown_mock_module (module);
}
static void
-test_decrypt_verify (CuTest *tc)
+test_decrypt_verify (void)
{
CK_FUNCTION_LIST_PTR module;
CK_SESSION_HANDLE session = 0;
@@ -1298,40 +1298,40 @@ test_decrypt_verify (CuTest *tc)
CK_ULONG length;
CK_RV rv;
- module = setup_mock_module (tc, &session);
+ module = setup_mock_module (&session);
rv = (module->C_Login) (session, CKU_USER, (CK_BYTE_PTR)"booo", 4);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = (module->C_DecryptInit) (session, &mech, MOCK_PRIVATE_KEY_CAPITALIZE);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = (module->C_VerifyInit) (session, &vmech, MOCK_PUBLIC_KEY_PREFIX);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
length = sizeof (data);
rv = (module->C_DecryptVerifyUpdate) (0, (CK_BYTE_PTR)"BLAH", 4, data, &length);
- CuAssertTrue (tc, rv == CKR_SESSION_HANDLE_INVALID);
+ assert (rv == CKR_SESSION_HANDLE_INVALID);
length = sizeof (data);
rv = (module->C_DecryptVerifyUpdate) (session, (CK_BYTE_PTR)"BLAH", 4, data, &length);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
- CuAssertIntEquals (tc, 4, length);
- CuAssertTrue (tc, memcmp (data, "blah", 4) == 0);
+ assert_num_eq (4, length);
+ assert (memcmp (data, "blah", 4) == 0);
length = sizeof (data);
rv = (module->C_DecryptFinal) (session, data, &length);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = (module->C_VerifyFinal) (session, (CK_BYTE_PTR)"p:value4", 8);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
- teardown_mock_module (tc, module);
+ teardown_mock_module (module);
}
static void
-test_generate_key (CuTest *tc)
+test_generate_key (void)
{
CK_FUNCTION_LIST_PTR module;
CK_SESSION_HANDLE session = 0;
@@ -1343,7 +1343,7 @@ test_generate_key (CuTest *tc)
CK_ULONG bits;
CK_RV rv;
- module = setup_mock_module (tc, &session);
+ module = setup_mock_module (&session);
strcpy (label, "Blahooo");
bits = 1555;
@@ -1356,13 +1356,13 @@ test_generate_key (CuTest *tc)
attrs[1].ulValueLen = sizeof (bits);
rv = (module->C_GenerateKey) (session, &mech, attrs, 2, &object);
- CuAssertTrue (tc, rv == CKR_MECHANISM_PARAM_INVALID);
+ assert (rv == CKR_MECHANISM_PARAM_INVALID);
mech.pParameter = "generate";
mech.ulParameterLen = 9;
rv = (module->C_GenerateKey) (session, &mech, attrs, 2, &object);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
attrs[0].ulValueLen = sizeof (label);
memset (label, 0, sizeof (label));
@@ -1372,19 +1372,19 @@ test_generate_key (CuTest *tc)
attrs[2].ulValueLen = sizeof (value);
rv = (module->C_GetAttributeValue) (session, object, attrs, 3);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
- CuAssertIntEquals (tc, bits, 1555);
- CuAssertIntEquals (tc, 7, attrs[0].ulValueLen);
- CuAssertTrue (tc, memcmp (label, "Blahooo", attrs[0].ulValueLen) == 0);
- CuAssertIntEquals (tc, 9, attrs[2].ulValueLen);
- CuAssertTrue (tc, memcmp (value, "generated", attrs[2].ulValueLen) == 0);
+ assert_num_eq (bits, 1555);
+ assert_num_eq (7, attrs[0].ulValueLen);
+ assert (memcmp (label, "Blahooo", attrs[0].ulValueLen) == 0);
+ assert_num_eq (9, attrs[2].ulValueLen);
+ assert (memcmp (value, "generated", attrs[2].ulValueLen) == 0);
- teardown_mock_module (tc, module);
+ teardown_mock_module (module);
}
static void
-test_generate_key_pair (CuTest *tc)
+test_generate_key_pair (void)
{
CK_FUNCTION_LIST_PTR module;
CK_SESSION_HANDLE session = 0;
@@ -1401,7 +1401,7 @@ test_generate_key_pair (CuTest *tc)
CK_ULONG priv_bits;
CK_RV rv;
- module = setup_mock_module (tc, &session);
+ module = setup_mock_module (&session);
strcpy (pub_label, "Blahooo");
pub_bits = 1555;
@@ -1423,14 +1423,14 @@ test_generate_key_pair (CuTest *tc)
rv = (module->C_GenerateKeyPair) (0, &mech, pub_attrs, 2, priv_attrs, 2,
&pub_object, &priv_object);
- CuAssertTrue (tc, rv == CKR_SESSION_HANDLE_INVALID);
+ assert (rv == CKR_SESSION_HANDLE_INVALID);
mech.pParameter = "generate";
mech.ulParameterLen = 9;
rv = (module->C_GenerateKeyPair) (session, &mech, pub_attrs, 2, priv_attrs, 2,
&pub_object, &priv_object);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
pub_bits = 0;
pub_attrs[0].ulValueLen = sizeof (pub_label);
@@ -1440,13 +1440,13 @@ test_generate_key_pair (CuTest *tc)
pub_attrs[2].ulValueLen = sizeof (pub_value);
rv = (module->C_GetAttributeValue) (session, pub_object, pub_attrs, 3);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
- CuAssertIntEquals (tc, 1555, pub_bits);
- CuAssertIntEquals (tc, 7, pub_attrs[0].ulValueLen);
- CuAssertTrue (tc, memcmp (pub_label, "Blahooo", pub_attrs[0].ulValueLen) == 0);
- CuAssertIntEquals (tc, 9, pub_attrs[2].ulValueLen);
- CuAssertTrue (tc, memcmp (pub_value, "generated", pub_attrs[2].ulValueLen) == 0);
+ assert_num_eq (1555, pub_bits);
+ assert_num_eq (7, pub_attrs[0].ulValueLen);
+ assert (memcmp (pub_label, "Blahooo", pub_attrs[0].ulValueLen) == 0);
+ assert_num_eq (9, pub_attrs[2].ulValueLen);
+ assert (memcmp (pub_value, "generated", pub_attrs[2].ulValueLen) == 0);
priv_bits = 0;
priv_attrs[0].ulValueLen = sizeof (priv_label);
@@ -1456,19 +1456,19 @@ test_generate_key_pair (CuTest *tc)
priv_attrs[2].ulValueLen = sizeof (priv_value);
rv = (module->C_GetAttributeValue) (session, priv_object, priv_attrs, 3);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
- CuAssertIntEquals (tc, 1666, priv_bits);
- CuAssertIntEquals (tc, 7, priv_attrs[0].ulValueLen);
- CuAssertTrue (tc, memcmp (priv_label, "Private", priv_attrs[0].ulValueLen) == 0);
- CuAssertIntEquals (tc, 9, priv_attrs[2].ulValueLen);
- CuAssertTrue (tc, memcmp (priv_value, "generated", priv_attrs[2].ulValueLen) == 0);
+ assert_num_eq (1666, priv_bits);
+ assert_num_eq (7, priv_attrs[0].ulValueLen);
+ assert (memcmp (priv_label, "Private", priv_attrs[0].ulValueLen) == 0);
+ assert_num_eq (9, priv_attrs[2].ulValueLen);
+ assert (memcmp (priv_value, "generated", priv_attrs[2].ulValueLen) == 0);
- teardown_mock_module (tc, module);
+ teardown_mock_module (module);
}
static void
-test_wrap_key (CuTest *tc)
+test_wrap_key (void)
{
CK_FUNCTION_LIST_PTR module;
CK_SESSION_HANDLE session = 0;
@@ -1477,26 +1477,26 @@ test_wrap_key (CuTest *tc)
CK_ULONG length;
CK_RV rv;
- module = setup_mock_module (tc, &session);
+ module = setup_mock_module (&session);
length = sizeof (data);
rv = (module->C_WrapKey) (session, &mech, MOCK_PUBLIC_KEY_PREFIX, MOCK_PUBLIC_KEY_PREFIX, data, &length);
- CuAssertTrue (tc, rv == CKR_MECHANISM_PARAM_INVALID);
+ assert (rv == CKR_MECHANISM_PARAM_INVALID);
mech.pParameter = "wrap";
mech.ulParameterLen = 4;
rv = (module->C_WrapKey) (session, &mech, MOCK_PUBLIC_KEY_PREFIX, MOCK_PUBLIC_KEY_PREFIX, data, &length);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
- CuAssertIntEquals (tc, 5, length);
- CuAssertTrue (tc, memcmp (data, "value", 5) == 0);
+ assert_num_eq (5, length);
+ assert (memcmp (data, "value", 5) == 0);
- teardown_mock_module (tc, module);
+ teardown_mock_module (module);
}
static void
-test_unwrap_key (CuTest *tc)
+test_unwrap_key (void)
{
CK_FUNCTION_LIST_PTR module;
CK_SESSION_HANDLE session = 0;
@@ -1508,7 +1508,7 @@ test_unwrap_key (CuTest *tc)
CK_ULONG bits;
CK_RV rv;
- module = setup_mock_module (tc, &session);
+ module = setup_mock_module (&session);
strcpy (label, "Blahooo");
bits = 1555;
@@ -1522,14 +1522,14 @@ test_unwrap_key (CuTest *tc)
rv = (module->C_UnwrapKey) (session, &mech, MOCK_PUBLIC_KEY_PREFIX,
(CK_BYTE_PTR)"wheee", 5, attrs, 2, &object);
- CuAssertTrue (tc, rv == CKR_MECHANISM_PARAM_INVALID);
+ assert (rv == CKR_MECHANISM_PARAM_INVALID);
mech.pParameter = "wrap";
mech.ulParameterLen = 4;
rv = (module->C_UnwrapKey) (session, &mech, MOCK_PUBLIC_KEY_PREFIX,
(CK_BYTE_PTR)"wheee", 5, attrs, 2, &object);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
attrs[0].ulValueLen = sizeof (label);
memset (label, 0, sizeof (label));
@@ -1539,19 +1539,19 @@ test_unwrap_key (CuTest *tc)
attrs[2].ulValueLen = sizeof (value);
rv = (module->C_GetAttributeValue) (session, object, attrs, 3);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
- CuAssertIntEquals (tc, bits, 1555);
- CuAssertIntEquals (tc, 7, attrs[0].ulValueLen);
- CuAssertTrue (tc, memcmp (label, "Blahooo", attrs[0].ulValueLen) == 0);
- CuAssertIntEquals (tc, 5, attrs[2].ulValueLen);
- CuAssertTrue (tc, memcmp (value, "wheee", attrs[2].ulValueLen) == 0);
+ assert_num_eq (bits, 1555);
+ assert_num_eq (7, attrs[0].ulValueLen);
+ assert (memcmp (label, "Blahooo", attrs[0].ulValueLen) == 0);
+ assert_num_eq (5, attrs[2].ulValueLen);
+ assert (memcmp (value, "wheee", attrs[2].ulValueLen) == 0);
- teardown_mock_module (tc, module);
+ teardown_mock_module (module);
}
static void
-test_derive_key (CuTest *tc)
+test_derive_key (void)
{
CK_FUNCTION_LIST_PTR module;
CK_SESSION_HANDLE session = 0;
@@ -1563,7 +1563,7 @@ test_derive_key (CuTest *tc)
CK_ULONG bits;
CK_RV rv;
- module = setup_mock_module (tc, &session);
+ module = setup_mock_module (&session);
strcpy (label, "Blahooo");
bits = 1555;
@@ -1577,14 +1577,14 @@ test_derive_key (CuTest *tc)
rv = (module->C_DeriveKey) (session, &mech, MOCK_PUBLIC_KEY_PREFIX,
attrs, 2, &object);
- CuAssertTrue (tc, rv == CKR_MECHANISM_PARAM_INVALID);
+ assert (rv == CKR_MECHANISM_PARAM_INVALID);
mech.pParameter = "derive";
mech.ulParameterLen = 6;
rv = (module->C_DeriveKey) (session, &mech, MOCK_PUBLIC_KEY_PREFIX,
attrs, 2, &object);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
attrs[0].ulValueLen = sizeof (label);
memset (label, 0, sizeof (label));
@@ -1594,86 +1594,86 @@ test_derive_key (CuTest *tc)
attrs[2].ulValueLen = sizeof (value);
rv = (module->C_GetAttributeValue) (session, object, attrs, 3);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
- CuAssertIntEquals (tc, bits, 1555);
- CuAssertIntEquals (tc, 7, attrs[0].ulValueLen);
- CuAssertTrue (tc, memcmp (label, "Blahooo", attrs[0].ulValueLen) == 0);
- CuAssertIntEquals (tc, 7, attrs[2].ulValueLen);
- CuAssertTrue (tc, memcmp (value, "derived", attrs[2].ulValueLen) == 0);
+ assert_num_eq (bits, 1555);
+ assert_num_eq (7, attrs[0].ulValueLen);
+ assert (memcmp (label, "Blahooo", attrs[0].ulValueLen) == 0);
+ assert_num_eq (7, attrs[2].ulValueLen);
+ assert (memcmp (value, "derived", attrs[2].ulValueLen) == 0);
- teardown_mock_module (tc, module);
+ teardown_mock_module (module);
}
static void
-test_random (CuTest *tc)
+test_random (void)
{
CK_FUNCTION_LIST_PTR module;
CK_SESSION_HANDLE session = 0;
CK_BYTE data[10];
CK_RV rv;
- module = setup_mock_module (tc, &session);
+ module = setup_mock_module (&session);
rv = (module->C_SeedRandom) (0, (CK_BYTE_PTR)"seed", 4);
- CuAssertTrue (tc, rv == CKR_SESSION_HANDLE_INVALID);
+ assert (rv == CKR_SESSION_HANDLE_INVALID);
rv = (module->C_SeedRandom) (session, (CK_BYTE_PTR)"seed", 4);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = (module->C_GenerateRandom) (0, data, sizeof (data));
- CuAssertTrue (tc, rv == CKR_SESSION_HANDLE_INVALID);
+ assert (rv == CKR_SESSION_HANDLE_INVALID);
rv = (module->C_GenerateRandom) (session, data, sizeof (data));
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
- CuAssertTrue (tc, memcmp (data, "seedseedse", sizeof (data)) == 0);
+ assert (memcmp (data, "seedseedse", sizeof (data)) == 0);
- teardown_mock_module (tc, module);
+ teardown_mock_module (module);
}
static void
-test_mock_add_tests (CuSuite *suite)
+test_mock_add_tests (const char *prefix)
{
- SUITE_ADD_TEST (suite, test_get_info);
- SUITE_ADD_TEST (suite, test_get_slot_list);
- SUITE_ADD_TEST (suite, test_get_slot_info);
- SUITE_ADD_TEST (suite, test_get_token_info);
- SUITE_ADD_TEST (suite, test_get_mechanism_list);
- SUITE_ADD_TEST (suite, test_get_mechanism_info);
- SUITE_ADD_TEST (suite, test_init_token);
- SUITE_ADD_TEST (suite, test_wait_for_slot_event);
- SUITE_ADD_TEST (suite, test_open_close_session);
- SUITE_ADD_TEST (suite, test_close_all_sessions);
- SUITE_ADD_TEST (suite, test_get_function_status);
- SUITE_ADD_TEST (suite, test_cancel_function);
- SUITE_ADD_TEST (suite, test_get_session_info);
- SUITE_ADD_TEST (suite, test_init_pin);
- SUITE_ADD_TEST (suite, test_set_pin);
- SUITE_ADD_TEST (suite, test_operation_state);
- SUITE_ADD_TEST (suite, test_login_logout);
- SUITE_ADD_TEST (suite, test_get_attribute_value);
- SUITE_ADD_TEST (suite, test_set_attribute_value);
- SUITE_ADD_TEST (suite, test_create_object);
- SUITE_ADD_TEST (suite, test_copy_object);
- SUITE_ADD_TEST (suite, test_destroy_object);
- SUITE_ADD_TEST (suite, test_get_object_size);
- SUITE_ADD_TEST (suite, test_find_objects);
- SUITE_ADD_TEST (suite, test_encrypt);
- SUITE_ADD_TEST (suite, test_decrypt);
- SUITE_ADD_TEST (suite, test_digest);
- SUITE_ADD_TEST (suite, test_sign);
- SUITE_ADD_TEST (suite, test_sign_recover);
- SUITE_ADD_TEST (suite, test_verify);
- SUITE_ADD_TEST (suite, test_verify_recover);
- SUITE_ADD_TEST (suite, test_digest_encrypt);
- SUITE_ADD_TEST (suite, test_decrypt_digest);
- SUITE_ADD_TEST (suite, test_sign_encrypt);
- SUITE_ADD_TEST (suite, test_decrypt_verify);
- SUITE_ADD_TEST (suite, test_generate_key);
- SUITE_ADD_TEST (suite, test_generate_key_pair);
- SUITE_ADD_TEST (suite, test_wrap_key);
- SUITE_ADD_TEST (suite, test_unwrap_key);
- SUITE_ADD_TEST (suite, test_derive_key);
- SUITE_ADD_TEST (suite, test_random);
+ p11_test (test_get_info, "%s/test_get_info", prefix);
+ p11_test (test_get_slot_list, "%s/test_get_slot_list", prefix);
+ p11_test (test_get_slot_info, "%s/test_get_slot_info", prefix);
+ p11_test (test_get_token_info, "%s/test_get_token_info", prefix);
+ p11_test (test_get_mechanism_list, "%s/test_get_mechanism_list", prefix);
+ p11_test (test_get_mechanism_info, "%s/test_get_mechanism_info", prefix);
+ p11_test (test_init_token, "%s/test_init_token", prefix);
+ p11_test (test_wait_for_slot_event, "%s/test_wait_for_slot_event", prefix);
+ p11_test (test_open_close_session, "%s/test_open_close_session", prefix);
+ p11_test (test_close_all_sessions, "%s/test_close_all_sessions", prefix);
+ p11_test (test_get_function_status, "%s/test_get_function_status", prefix);
+ p11_test (test_cancel_function, "%s/test_cancel_function", prefix);
+ p11_test (test_get_session_info, "%s/test_get_session_info", prefix);
+ p11_test (test_init_pin, "%s/test_init_pin", prefix);
+ p11_test (test_set_pin, "%s/test_set_pin", prefix);
+ p11_test (test_operation_state, "%s/test_operation_state", prefix);
+ p11_test (test_login_logout, "%s/test_login_logout", prefix);
+ p11_test (test_get_attribute_value, "%s/test_get_attribute_value", prefix);
+ p11_test (test_set_attribute_value, "%s/test_set_attribute_value", prefix);
+ p11_test (test_create_object, "%s/test_create_object", prefix);
+ p11_test (test_copy_object, "%s/test_copy_object", prefix);
+ p11_test (test_destroy_object, "%s/test_destroy_object", prefix);
+ p11_test (test_get_object_size, "%s/test_get_object_size", prefix);
+ p11_test (test_find_objects, "%s/test_find_objects", prefix);
+ p11_test (test_encrypt, "%s/test_encrypt", prefix);
+ p11_test (test_decrypt, "%s/test_decrypt", prefix);
+ p11_test (test_digest, "%s/test_digest", prefix);
+ p11_test (test_sign, "%s/test_sign", prefix);
+ p11_test (test_sign_recover, "%s/test_sign_recover", prefix);
+ p11_test (test_verify, "%s/test_verify", prefix);
+ p11_test (test_verify_recover, "%s/test_verify_recover", prefix);
+ p11_test (test_digest_encrypt, "%s/test_digest_encrypt", prefix);
+ p11_test (test_decrypt_digest, "%s/test_decrypt_digest", prefix);
+ p11_test (test_sign_encrypt, "%s/test_sign_encrypt", prefix);
+ p11_test (test_decrypt_verify, "%s/test_decrypt_verify", prefix);
+ p11_test (test_generate_key, "%s/test_generate_key", prefix);
+ p11_test (test_generate_key_pair, "%s/test_generate_key_pair", prefix);
+ p11_test (test_wrap_key, "%s/test_wrap_key", prefix);
+ p11_test (test_unwrap_key, "%s/test_unwrap_key", prefix);
+ p11_test (test_derive_key, "%s/test_derive_key", prefix);
+ p11_test (test_random, "%s/test_random", prefix);
}
diff --git a/p11-kit/tests/test-modules.c b/p11-kit/tests/test-modules.c
index d6b4753..d50b2d5 100644
--- a/p11-kit/tests/test-modules.c
+++ b/p11-kit/tests/test-modules.c
@@ -33,7 +33,7 @@
*/
#include "config.h"
-#include "CuTest.h"
+#include "test.h"
#include <errno.h>
#include <stdlib.h>
@@ -47,25 +47,24 @@
#include "dict.h"
static CK_FUNCTION_LIST_PTR_PTR
-initialize_and_get_modules (CuTest *tc)
+initialize_and_get_modules (void)
{
CK_FUNCTION_LIST_PTR_PTR modules;
modules = p11_kit_modules_load_and_initialize (0);
- CuAssertTrue (tc, modules != NULL && modules[0] != NULL);
+ assert (modules != NULL && modules[0] != NULL);
return modules;
}
static void
-finalize_and_free_modules (CuTest *tc,
- CK_FUNCTION_LIST_PTR_PTR modules)
+finalize_and_free_modules (CK_FUNCTION_LIST_PTR_PTR modules)
{
p11_kit_modules_finalize_and_release (modules);
}
static void
-test_no_duplicates (CuTest *tc)
+test_no_duplicates (void)
{
CK_FUNCTION_LIST_PTR_PTR modules;
p11_dict *paths;
@@ -73,7 +72,7 @@ test_no_duplicates (CuTest *tc)
char *path;
int i;
- modules = initialize_and_get_modules (tc);
+ modules = initialize_and_get_modules ();
paths = p11_dict_new (p11_dict_str_hash, p11_dict_str_equal, NULL, NULL);
funcs = p11_dict_new (p11_dict_direct_hash, p11_dict_direct_equal, NULL, NULL);
@@ -82,26 +81,25 @@ test_no_duplicates (CuTest *tc)
path = p11_kit_config_option (modules[i], "module");
if (p11_dict_get (funcs, modules[i]))
- CuAssert (tc, "found duplicate function list pointer", 0);
+ assert_fail ("found duplicate function list pointer", NULL);
if (p11_dict_get (paths, path))
- CuAssert (tc, "found duplicate path name", 0);
+ assert_fail ("found duplicate path name", NULL);
if (!p11_dict_set (funcs, modules[i], ""))
- CuAssert (tc, "shouldn't be reached", 0);
+ assert_not_reached ();
if (!p11_dict_set (paths, path, ""))
- CuAssert (tc, "shouldn't be reached", 0);
+ assert_not_reached ();
free (path);
}
p11_dict_free (paths);
p11_dict_free (funcs);
- finalize_and_free_modules (tc, modules);
+ finalize_and_free_modules (modules);
}
static CK_FUNCTION_LIST_PTR
-lookup_module_with_name (CuTest *tc,
- CK_FUNCTION_LIST_PTR_PTR modules,
+lookup_module_with_name (CK_FUNCTION_LIST_PTR_PTR modules,
const char *name)
{
CK_FUNCTION_LIST_PTR match = NULL;
@@ -111,7 +109,7 @@ lookup_module_with_name (CuTest *tc,
for (i = 0; match == NULL && modules[i] != NULL; i++) {
module_name = p11_kit_module_get_name (modules[i]);
- CuAssertPtrNotNull (tc, module_name);
+ assert_ptr_not_null (module_name);
if (strcmp (module_name, name) == 0)
match = modules[i];
free (module_name);
@@ -122,14 +120,14 @@ lookup_module_with_name (CuTest *tc,
* matches the above search.
*/
module = p11_kit_module_for_name (modules, name);
- CuAssert(tc, "different result from p11_kit_module_for_name ()",
- module == match);
+ if (module != match)
+ assert_fail ("different result from p11_kit_module_for_name ()", NULL);
return match;
}
static void
-test_disable (CuTest *tc)
+test_disable (void)
{
CK_FUNCTION_LIST_PTR_PTR modules;
@@ -138,9 +136,9 @@ test_disable (CuTest *tc)
* that it has disabled.
*/
- modules = initialize_and_get_modules (tc);
- CuAssertTrue (tc, lookup_module_with_name (tc, modules, "four") != NULL);
- finalize_and_free_modules (tc, modules);
+ modules = initialize_and_get_modules ();
+ assert (lookup_module_with_name (modules, "four") != NULL);
+ finalize_and_free_modules (modules);
/*
* The module two shouldn't have been loaded, because in its config
@@ -151,15 +149,15 @@ test_disable (CuTest *tc)
p11_kit_set_progname ("test-disable");
- modules = initialize_and_get_modules (tc);
- CuAssertTrue (tc, lookup_module_with_name (tc, modules, "four") == NULL);
- finalize_and_free_modules (tc, modules);
+ modules = initialize_and_get_modules ();
+ assert (lookup_module_with_name (modules, "four") == NULL);
+ finalize_and_free_modules (modules);
p11_kit_set_progname (NULL);
}
static void
-test_disable_later (CuTest *tc)
+test_disable_later (void)
{
CK_FUNCTION_LIST_PTR_PTR modules;
@@ -173,16 +171,16 @@ test_disable_later (CuTest *tc)
p11_kit_set_progname ("test-disable");
modules = p11_kit_modules_load_and_initialize (0);
- CuAssertTrue (tc, modules != NULL && modules[0] != NULL);
+ assert (modules != NULL && modules[0] != NULL);
- CuAssertTrue (tc, lookup_module_with_name (tc, modules, "two") == NULL);
- finalize_and_free_modules (tc, modules);
+ assert (lookup_module_with_name (modules, "two") == NULL);
+ finalize_and_free_modules (modules);
p11_kit_set_progname (NULL);
}
static void
-test_enable (CuTest *tc)
+test_enable (void)
{
CK_FUNCTION_LIST_PTR_PTR modules;
@@ -191,9 +189,9 @@ test_enable (CuTest *tc)
* program.
*/
- modules = initialize_and_get_modules (tc);
- CuAssertTrue (tc, lookup_module_with_name (tc, modules, "three") == NULL);
- finalize_and_free_modules (tc, modules);
+ modules = initialize_and_get_modules ();
+ assert (lookup_module_with_name (modules, "three") == NULL);
+ finalize_and_free_modules (modules);
/*
* The module three should be loaded here , because in its config
@@ -204,15 +202,15 @@ test_enable (CuTest *tc)
p11_kit_set_progname ("test-enable");
- modules = initialize_and_get_modules (tc);
- CuAssertTrue (tc, lookup_module_with_name (tc, modules, "three") != NULL);
- finalize_and_free_modules (tc, modules);
+ modules = initialize_and_get_modules ();
+ assert (lookup_module_with_name (modules, "three") != NULL);
+ finalize_and_free_modules (modules);
p11_kit_set_progname (NULL);
}
static void
-test_priority (CuTest *tc)
+test_priority (void)
{
CK_FUNCTION_LIST_PTR_PTR modules;
char *name;
@@ -231,12 +229,12 @@ test_priority (CuTest *tc)
/* This enables module three */
p11_kit_set_progname ("test-enable");
- modules = initialize_and_get_modules (tc);
+ modules = initialize_and_get_modules ();
/* The loaded modules should not contain duplicates */
for (i = 0; modules[i] != NULL; i++) {
name = p11_kit_module_get_name (modules[i]);
- CuAssertPtrNotNull (tc, name);
+ assert_ptr_not_null (name);
/* Either one of these can be loaded, as this is a duplicate module */
if (strcmp (name, "two-duplicate") == 0) {
@@ -244,16 +242,16 @@ test_priority (CuTest *tc)
name = strdup ("two.badname");
}
- CuAssertStrEquals (tc, expected[i], name);
+ assert_str_eq (expected[i], name);
free (name);
}
- CuAssertIntEquals (tc, 4, i);
- finalize_and_free_modules (tc, modules);
+ assert_num_eq (4, i);
+ finalize_and_free_modules (modules);
}
static void
-test_module_name (CuTest *tc)
+test_module_name (void)
{
CK_FUNCTION_LIST_PTR_PTR modules;
CK_FUNCTION_LIST_PTR module;
@@ -264,25 +262,25 @@ test_module_name (CuTest *tc)
* program.
*/
- modules = initialize_and_get_modules (tc);
+ modules = initialize_and_get_modules ();
module = p11_kit_module_for_name (modules, "one");
- CuAssertPtrNotNull (tc, module);
+ assert_ptr_not_null (module);
name = p11_kit_module_get_name (module);
- CuAssertStrEquals (tc, "one", name);
+ assert_str_eq ("one", name);
free (name);
module = p11_kit_module_for_name (modules, "invalid");
- CuAssertPtrEquals (tc, NULL, module);
+ assert_ptr_eq (NULL, module);
module = p11_kit_module_for_name (NULL, "one");
- CuAssertPtrEquals (tc, NULL, module);
+ assert_ptr_eq (NULL, module);
- finalize_and_free_modules (tc, modules);
+ finalize_and_free_modules (modules);
}
static void
-test_module_flags (CuTest *tc)
+test_module_flags (void)
{
CK_FUNCTION_LIST **modules;
CK_FUNCTION_LIST **unmanaged;
@@ -293,23 +291,23 @@ test_module_flags (CuTest *tc)
* program.
*/
- modules = initialize_and_get_modules (tc);
+ modules = initialize_and_get_modules ();
flags = p11_kit_module_get_flags (modules[0]);
- CuAssertIntEquals (tc, 0, flags);
+ assert_num_eq (0, flags);
unmanaged = p11_kit_modules_load (NULL, P11_KIT_MODULE_UNMANAGED);
- CuAssertTrue (tc, unmanaged != NULL && unmanaged[0] != NULL);
+ assert (unmanaged != NULL && unmanaged[0] != NULL);
flags = p11_kit_module_get_flags (unmanaged[0]);
- CuAssertIntEquals (tc, P11_KIT_MODULE_UNMANAGED, flags);
+ assert_num_eq (P11_KIT_MODULE_UNMANAGED, flags);
- finalize_and_free_modules (tc, modules);
+ finalize_and_free_modules (modules);
p11_kit_modules_release (unmanaged);
}
static void
-test_config_option (CuTest *tc)
+test_config_option (void)
{
CK_FUNCTION_LIST_PTR_PTR modules;
CK_FUNCTION_LIST_PTR module;
@@ -320,59 +318,48 @@ test_config_option (CuTest *tc)
* program.
*/
- modules = initialize_and_get_modules (tc);
+ modules = initialize_and_get_modules ();
value = p11_kit_config_option (NULL, "new");
- CuAssertStrEquals (tc, "world", value);
+ assert_str_eq ("world", value);
free (value);
module = p11_kit_module_for_name (modules, "one");
- CuAssertPtrNotNull (tc, module);
+ assert_ptr_not_null (module);
value = p11_kit_config_option (module, "setting");
- CuAssertStrEquals (tc, "user1", value);
+ assert_str_eq ("user1", value);
free (value);
value = p11_kit_config_option (NULL, "invalid");
- CuAssertPtrEquals (tc, NULL, value);
+ assert_ptr_eq (NULL, value);
value = p11_kit_config_option (module, "invalid");
- CuAssertPtrEquals (tc, NULL, value);
+ assert_ptr_eq (NULL, value);
/* Invalid but non-NULL module pointer */
value = p11_kit_config_option (module + 1, "setting");
- CuAssertPtrEquals (tc, NULL, value);
+ assert_ptr_eq (NULL, value);
- finalize_and_free_modules (tc, modules);
+ finalize_and_free_modules (modules);
}
int
-main (void)
+main (int argc,
+ char *argv[])
{
- CuString *output = CuStringNew ();
- CuSuite* suite = CuSuiteNew ();
- int ret;
-
- putenv ("P11_KIT_STRICT=1");
p11_library_init ();
- SUITE_ADD_TEST (suite, test_no_duplicates);
- SUITE_ADD_TEST (suite, test_disable);
- SUITE_ADD_TEST (suite, test_disable_later);
- SUITE_ADD_TEST (suite, test_enable);
- SUITE_ADD_TEST (suite, test_priority);
- SUITE_ADD_TEST (suite, test_module_name);
- SUITE_ADD_TEST (suite, test_module_flags);
- SUITE_ADD_TEST (suite, test_config_option);
+ p11_test (test_no_duplicates, "/modules/test_no_duplicates");
+ p11_test (test_disable, "/modules/test_disable");
+ p11_test (test_disable_later, "/modules/test_disable_later");
+ p11_test (test_enable, "/modules/test_enable");
+ p11_test (test_priority, "/modules/test_priority");
+ p11_test (test_module_name, "/modules/test_module_name");
+ p11_test (test_module_flags, "/modules/test_module_flags");
+ p11_test (test_config_option, "/modules/test_config_option");
p11_kit_be_quiet ();
- CuSuiteRun (suite);
- CuSuiteSummary (suite, output);
- CuSuiteDetails (suite, output);
- printf ("%s\n", output->buffer);
- ret = suite->failCount;
- CuSuiteDelete (suite);
- CuStringDelete (output);
- return ret;
+ return p11_test_run (argc, argv);
}
diff --git a/p11-kit/tests/pin-test.c b/p11-kit/tests/test-pin.c
index dd020bc..ebe3efc 100644
--- a/p11-kit/tests/pin-test.c
+++ b/p11-kit/tests/test-pin.c
@@ -33,7 +33,7 @@
*/
#include "config.h"
-#include "CuTest.h"
+#include "test.h"
#include "library.h"
@@ -71,7 +71,7 @@ destroy_data (void *callback_data)
}
static void
-test_pin_register_unregister (CuTest *tc)
+test_pin_register_unregister (void)
{
int data = 33;
@@ -81,11 +81,11 @@ test_pin_register_unregister (CuTest *tc)
p11_kit_pin_unregister_callback ("/the/pin_source", callback_one,
&data);
- CuAssertIntEquals (tc, 34, data);
+ assert_num_eq (34, data);
}
static void
-test_pin_read (CuTest *tc)
+test_pin_read (void)
{
P11KitUri *uri;
P11KitPin *pin;
@@ -101,10 +101,10 @@ test_pin_read (CuTest *tc)
P11_KIT_PIN_FLAGS_USER_LOGIN);
p11_kit_uri_free (uri);
- CuAssertPtrNotNull (tc, pin);
+ assert_ptr_not_null (pin);
ptr = p11_kit_pin_get_value (pin, &length);
- CuAssertIntEquals (tc, 3, length);
- CuAssertTrue (tc, memcmp (ptr, "one", 3) == 0);
+ assert_num_eq (3, length);
+ assert (memcmp (ptr, "one", 3) == 0);
p11_kit_pin_unregister_callback ("/the/pin_source", callback_one,
&data);
@@ -113,7 +113,7 @@ test_pin_read (CuTest *tc)
}
static void
-test_pin_read_no_match (CuTest *tc)
+test_pin_read_no_match (void)
{
P11KitUri *uri;
P11KitPin *pin;
@@ -123,11 +123,11 @@ test_pin_read_no_match (CuTest *tc)
P11_KIT_PIN_FLAGS_USER_LOGIN);
p11_kit_uri_free (uri);
- CuAssertPtrEquals (tc, NULL, pin);
+ assert_ptr_eq (NULL, pin);
}
static void
-test_pin_register_duplicate (CuTest *tc)
+test_pin_register_duplicate (void)
{
P11KitUri *uri;
P11KitPin *pin;
@@ -147,10 +147,10 @@ test_pin_register_duplicate (CuTest *tc)
pin = p11_kit_pin_request ("/the/pin_source", uri, "The token",
P11_KIT_PIN_FLAGS_USER_LOGIN);
- CuAssertPtrNotNull (tc, pin);
+ assert_ptr_not_null (pin);
ptr = p11_kit_pin_get_value (pin, &length);
- CuAssertIntEquals (tc, 6, length);
- CuAssertTrue (tc, memcmp (ptr, "secret", length) == 0);
+ assert_num_eq (6, length);
+ assert (memcmp (ptr, "secret", length) == 0);
p11_kit_pin_unref (pin);
p11_kit_pin_unregister_callback ("/the/pin_source", callback_other,
@@ -159,10 +159,10 @@ test_pin_register_duplicate (CuTest *tc)
pin = p11_kit_pin_request ("/the/pin_source", uri, "The token",
P11_KIT_PIN_FLAGS_USER_LOGIN);
- CuAssertPtrNotNull (tc, pin);
+ assert_ptr_not_null (pin);
ptr = p11_kit_pin_get_value (pin, &length);
- CuAssertIntEquals (tc, 3, length);
- CuAssertTrue (tc, memcmp (ptr, "one", length) == 0);
+ assert_num_eq (3, length);
+ assert (memcmp (ptr, "one", length) == 0);
p11_kit_pin_unref (pin);
p11_kit_pin_unregister_callback ("/the/pin_source", callback_one,
@@ -171,13 +171,13 @@ test_pin_register_duplicate (CuTest *tc)
pin = p11_kit_pin_request ("/the/pin_source", uri, "The token",
P11_KIT_PIN_FLAGS_USER_LOGIN);
- CuAssertPtrEquals (tc, NULL, pin);
+ assert_ptr_eq (NULL, pin);
p11_kit_uri_free (uri);
}
static void
-test_pin_register_fallback (CuTest *tc)
+test_pin_register_fallback (void)
{
char *value = "secret";
P11KitUri *uri;
@@ -194,10 +194,10 @@ test_pin_register_fallback (CuTest *tc)
pin = p11_kit_pin_request ("/the/pin_source", uri, "The token",
P11_KIT_PIN_FLAGS_USER_LOGIN);
- CuAssertPtrNotNull (tc, pin);
+ assert_ptr_not_null (pin);
ptr = p11_kit_pin_get_value (pin, &length);
- CuAssertIntEquals (tc, 3, length);
- CuAssertTrue (tc, memcmp (ptr, "one", length) == 0);
+ assert_num_eq (3, length);
+ assert (memcmp (ptr, "one", length) == 0);
p11_kit_pin_unref (pin);
p11_kit_pin_register_callback ("/the/pin_source", callback_other,
@@ -206,10 +206,10 @@ test_pin_register_fallback (CuTest *tc)
pin = p11_kit_pin_request ("/the/pin_source", uri, "The token",
P11_KIT_PIN_FLAGS_USER_LOGIN);
- CuAssertPtrNotNull (tc, pin);
+ assert_ptr_not_null (pin);
ptr = p11_kit_pin_get_value (pin, &length);
- CuAssertIntEquals (tc, 6, length);
- CuAssertTrue (tc, memcmp (ptr, "secret", length) == 0);
+ assert_num_eq (6, length);
+ assert (memcmp (ptr, "secret", length) == 0);
p11_kit_pin_unref (pin);
p11_kit_pin_unregister_callback ("/the/pin_source", callback_other,
@@ -222,7 +222,7 @@ test_pin_register_fallback (CuTest *tc)
}
static void
-test_pin_file (CuTest *tc)
+test_pin_file (void)
{
P11KitUri *uri;
P11KitPin *pin;
@@ -237,16 +237,16 @@ test_pin_file (CuTest *tc)
pin = p11_kit_pin_request (SRCDIR "/files/test-pinfile", uri, "The token",
P11_KIT_PIN_FLAGS_USER_LOGIN);
- CuAssertPtrNotNull (tc, pin);
+ assert_ptr_not_null (pin);
ptr = p11_kit_pin_get_value (pin, &length);
- CuAssertIntEquals (tc, 12, length);
- CuAssertTrue (tc, memcmp (ptr, "yogabbagabba", length) == 0);
+ assert_num_eq (12, length);
+ assert (memcmp (ptr, "yogabbagabba", length) == 0);
p11_kit_pin_unref (pin);
pin = p11_kit_pin_request (SRCDIR "/files/nonexistant", uri, "The token",
P11_KIT_PIN_FLAGS_USER_LOGIN);
- CuAssertPtrEquals (tc, NULL, pin);
+ assert_ptr_eq (NULL, pin);
p11_kit_pin_unregister_callback (P11_KIT_PIN_FALLBACK, p11_kit_pin_file_callback,
NULL);
@@ -255,7 +255,7 @@ test_pin_file (CuTest *tc)
}
static void
-test_pin_file_large (CuTest *tc)
+test_pin_file_large (void)
{
P11KitUri *uri;
P11KitPin *pin;
@@ -270,8 +270,8 @@ test_pin_file_large (CuTest *tc)
P11_KIT_PIN_FLAGS_USER_LOGIN);
error = errno;
- CuAssertPtrEquals (tc, NULL, pin);
- CuAssertIntEquals (tc, EFBIG, error);
+ assert_ptr_eq (NULL, pin);
+ assert_num_eq (EFBIG, error);
p11_kit_pin_unregister_callback (P11_KIT_PIN_FALLBACK, p11_kit_pin_file_callback,
NULL);
@@ -280,7 +280,7 @@ test_pin_file_large (CuTest *tc)
}
static void
-test_pin_ref_unref (CuTest *tc)
+test_pin_ref_unref (void)
{
P11KitPin *pin;
P11KitPin *check;
@@ -288,38 +288,26 @@ test_pin_ref_unref (CuTest *tc)
pin = p11_kit_pin_new_for_string ("crack of lies");
check = p11_kit_pin_ref (pin);
- CuAssertPtrEquals (tc, pin, check);
+ assert_ptr_eq (pin, check);
p11_kit_pin_unref (pin);
p11_kit_pin_unref (check);
}
int
-main (void)
+main (int argc,
+ char *argv[])
{
- CuString *output = CuStringNew ();
- CuSuite* suite = CuSuiteNew ();
- int ret;
-
- putenv ("P11_KIT_STRICT=1");
p11_library_init ();
- SUITE_ADD_TEST (suite, test_pin_register_unregister);
- SUITE_ADD_TEST (suite, test_pin_read);
- SUITE_ADD_TEST (suite, test_pin_read_no_match);
- SUITE_ADD_TEST (suite, test_pin_register_duplicate);
- SUITE_ADD_TEST (suite, test_pin_register_fallback);
- SUITE_ADD_TEST (suite, test_pin_file);
- SUITE_ADD_TEST (suite, test_pin_file_large);
- SUITE_ADD_TEST (suite, test_pin_ref_unref);
-
- 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_pin_register_unregister, "/pin/test_pin_register_unregister");
+ p11_test (test_pin_read, "/pin/test_pin_read");
+ p11_test (test_pin_read_no_match, "/pin/test_pin_read_no_match");
+ p11_test (test_pin_register_duplicate, "/pin/test_pin_register_duplicate");
+ p11_test (test_pin_register_fallback, "/pin/test_pin_register_fallback");
+ p11_test (test_pin_file, "/pin/test_pin_file");
+ p11_test (test_pin_file_large, "/pin/test_pin_file_large");
+ p11_test (test_pin_ref_unref, "/pin/test_pin_ref_unref");
+
+ return p11_test_run (argc, argv);
}
diff --git a/p11-kit/tests/progname-test.c b/p11-kit/tests/test-progname.c
index 18a8c55..76b136d 100644
--- a/p11-kit/tests/progname-test.c
+++ b/p11-kit/tests/test-progname.c
@@ -33,7 +33,7 @@
*/
#include "config.h"
-#include "CuTest.h"
+#include "test.h"
#include "library.h"
@@ -47,52 +47,40 @@
#include "p11-kit/private.h"
static void
-test_progname_default (CuTest *tc)
+test_progname_default (void)
{
const char *progname;
progname = _p11_get_progname_unlocked ();
- CuAssertStrEquals (tc, "progname-test", progname);
+ assert_str_eq ("test-progname", progname);
}
static void
-test_progname_set (CuTest *tc)
+test_progname_set (void)
{
const char *progname;
p11_kit_set_progname ("love-generation");
progname = _p11_get_progname_unlocked ();
- CuAssertStrEquals (tc, "love-generation", progname);
+ assert_str_eq ("love-generation", progname);
_p11_set_progname_unlocked (NULL);
progname = _p11_get_progname_unlocked ();
- CuAssertStrEquals (tc, "progname-test", progname);
+ assert_str_eq ("test-progname", progname);
}
/* Defined in util.c */
extern char p11_my_progname[];
int
-main (void)
+main (int argc,
+ char *argv[])
{
- CuString *output = CuStringNew ();
- CuSuite* suite = CuSuiteNew ();
- int ret;
-
- putenv ("P11_KIT_STRICT=1");
p11_library_init ();
- SUITE_ADD_TEST (suite, test_progname_default);
- SUITE_ADD_TEST (suite, test_progname_set);
-
- 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_progname_default, "/progname/test_progname_default");
+ p11_test (test_progname_set, "/progname/test_progname_set");
+ return p11_test_run (argc, argv);
}
diff --git a/p11-kit/tests/test-proxy.c b/p11-kit/tests/test-proxy.c
index 2ebd848..bf5007d 100644
--- a/p11-kit/tests/test-proxy.c
+++ b/p11-kit/tests/test-proxy.c
@@ -35,7 +35,7 @@
#define CRYPTOKI_EXPORTS
#include "config.h"
-#include "CuTest.h"
+#include "test.h"
#include "library.h"
#include "mock.h"
@@ -62,101 +62,99 @@ static CK_ULONG mock_slots_present;
static CK_ULONG mock_slots_all;
static void
-test_initialize_finalize (CuTest *tc)
+test_initialize_finalize (void)
{
CK_FUNCTION_LIST_PTR proxy;
CK_RV rv;
rv = C_GetFunctionList (&proxy);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
- CuAssertTrue (tc, p11_proxy_module_check (proxy));
+ assert (p11_proxy_module_check (proxy));
rv = proxy->C_Initialize (NULL);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = proxy->C_Finalize (NULL);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
p11_proxy_module_cleanup ();
}
static void
-test_initialize_multiple (CuTest *tc)
+test_initialize_multiple (void)
{
CK_FUNCTION_LIST_PTR proxy;
CK_RV rv;
rv = C_GetFunctionList (&proxy);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
- CuAssertTrue (tc, p11_proxy_module_check (proxy));
+ assert (p11_proxy_module_check (proxy));
rv = proxy->C_Initialize (NULL);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = proxy->C_Initialize (NULL);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = proxy->C_Finalize (NULL);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = proxy->C_Finalize (NULL);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = proxy->C_Finalize (NULL);
- CuAssertTrue (tc, rv == CKR_CRYPTOKI_NOT_INITIALIZED);
+ assert (rv == CKR_CRYPTOKI_NOT_INITIALIZED);
p11_proxy_module_cleanup ();
}
static CK_FUNCTION_LIST_PTR
-setup_mock_module (CuTest *tc,
- CK_SESSION_HANDLE *session)
+setup_mock_module (CK_SESSION_HANDLE *session)
{
CK_FUNCTION_LIST_PTR proxy;
CK_SLOT_ID slots[32];
CK_RV rv;
rv = C_GetFunctionList (&proxy);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
- CuAssertTrue (tc, p11_proxy_module_check (proxy));
+ assert (p11_proxy_module_check (proxy));
rv = proxy->C_Initialize (NULL);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
mock_slots_all = 32;
rv = proxy->C_GetSlotList (CK_FALSE, slots, &mock_slots_all);
- CuAssertTrue (tc, rv == CKR_OK);
- CuAssertTrue (tc, mock_slots_all >= 2);
+ assert (rv == CKR_OK);
+ assert (mock_slots_all >= 2);
/* Assume this is the slot we want to deal with */
mock_slot_one_id = slots[0];
mock_slot_two_id = slots[1];
rv = proxy->C_GetSlotList (CK_TRUE, NULL, &mock_slots_present);
- CuAssertTrue (tc, rv == CKR_OK);
- CuAssertTrue (tc, mock_slots_present > 1);
+ assert (rv == CKR_OK);
+ assert (mock_slots_present > 1);
if (session) {
rv = (proxy->C_OpenSession) (mock_slot_one_id,
CKF_RW_SESSION | CKF_SERIAL_SESSION,
NULL, NULL, session);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
}
return proxy;
}
static void
-teardown_mock_module (CuTest *tc,
- CK_FUNCTION_LIST_PTR module)
+teardown_mock_module (CK_FUNCTION_LIST_PTR module)
{
CK_RV rv;
rv = module->C_Finalize (NULL);
- CuAssertTrue (tc, rv == CKR_OK);
+ assert (rv == CKR_OK);
}
/*
@@ -182,27 +180,16 @@ static const CK_INFO mock_info = {
#include "test-mock.c"
int
-main (void)
+main (int argc,
+ char *argv[])
{
- CuString *output = CuStringNew ();
- CuSuite* suite = CuSuiteNew ();
- int ret;
-
- putenv ("P11_KIT_STRICT=1");
p11_library_init ();
p11_kit_be_quiet ();
- SUITE_ADD_TEST (suite, test_initialize_finalize);
- SUITE_ADD_TEST (suite, test_initialize_multiple);
+ p11_test (test_initialize_finalize, "/proxy/initialize-finalize");
+ p11_test (test_initialize_multiple, "/proxy/initialize-multiple");
- test_mock_add_tests (suite);
+ test_mock_add_tests ("/proxy");
- CuSuiteRun (suite);
- CuSuiteSummary (suite, output);
- CuSuiteDetails (suite, output);
- printf ("%s\n", output->buffer);
- ret = suite->failCount;
- CuSuiteDelete (suite);
- CuStringDelete (output);
- return ret;
+ return p11_test_run (argc, argv);
}
diff --git a/p11-kit/tests/uri-test.c b/p11-kit/tests/test-uri.c
index 2bc121c..f514f7a 100644
--- a/p11-kit/tests/uri-test.c
+++ b/p11-kit/tests/test-uri.c
@@ -33,7 +33,7 @@
*/
#include "config.h"
-#include "CuTest.h"
+#include "test.h"
#include "debug.h"
#include "message.h"
@@ -75,138 +75,138 @@ are_attributes_empty (P11KitUri *uri)
}
static void
-test_uri_parse (CuTest *tc)
+test_uri_parse (void)
{
P11KitUri *uri;
int ret;
uri = p11_kit_uri_new ();
- CuAssertPtrNotNull (tc, uri);
+ assert_ptr_not_null (uri);
ret = p11_kit_uri_parse ("pkcs11:", P11_KIT_URI_FOR_MODULE, uri);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
+ assert_num_eq (P11_KIT_URI_OK, ret);
- CuAssertTrue (tc, is_module_empty (uri));
- CuAssertTrue (tc, is_token_empty (uri));
- CuAssertTrue (tc, are_attributes_empty (uri));
+ assert (is_module_empty (uri));
+ assert (is_token_empty (uri));
+ assert (are_attributes_empty (uri));
p11_kit_uri_free (uri);
}
static void
-test_uri_parse_bad_scheme (CuTest *tc)
+test_uri_parse_bad_scheme (void)
{
P11KitUri *uri;
int ret;
uri = p11_kit_uri_new ();
- CuAssertPtrNotNull (tc, uri);
+ assert_ptr_not_null (uri);
ret = p11_kit_uri_parse ("http:\\example.com\test", P11_KIT_URI_FOR_ANY, uri);
- CuAssertIntEquals (tc, P11_KIT_URI_BAD_SCHEME, ret);
+ assert_num_eq (P11_KIT_URI_BAD_SCHEME, ret);
p11_kit_uri_free (uri);
}
static void
-test_uri_parse_with_label (CuTest *tc)
+test_uri_parse_with_label (void)
{
CK_ATTRIBUTE_PTR attr;
P11KitUri *uri;
int ret;
uri = p11_kit_uri_new ();
- CuAssertPtrNotNull (tc, uri);
+ assert_ptr_not_null (uri);
ret = p11_kit_uri_parse ("pkcs11:object=Test%20Label", P11_KIT_URI_FOR_ANY, uri);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
+ assert_num_eq (P11_KIT_URI_OK, ret);
- CuAssertTrue (tc, is_module_empty (uri));
- CuAssertTrue (tc, is_token_empty (uri));
+ assert (is_module_empty (uri));
+ assert (is_token_empty (uri));
attr = p11_kit_uri_get_attribute (uri, CKA_LABEL);
- CuAssertPtrNotNull (tc, attr);
- CuAssertTrue (tc, attr->ulValueLen == strlen ("Test Label"));
- CuAssertTrue (tc, memcmp (attr->pValue, "Test Label", attr->ulValueLen) == 0);
+ assert_ptr_not_null (attr);
+ assert (attr->ulValueLen == strlen ("Test Label"));
+ assert (memcmp (attr->pValue, "Test Label", attr->ulValueLen) == 0);
p11_kit_uri_free (uri);
}
static void
-test_uri_parse_with_label_and_klass (CuTest *tc)
+test_uri_parse_with_label_and_klass (void)
{
CK_ATTRIBUTE_PTR attr;
P11KitUri *uri;
int ret;
uri = p11_kit_uri_new ();
- CuAssertPtrNotNull (tc, uri);
+ assert_ptr_not_null (uri);
ret = p11_kit_uri_parse ("pkcs11:object=Test%20Label;object-type=cert", P11_KIT_URI_FOR_ANY, uri);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
+ assert_num_eq (P11_KIT_URI_OK, ret);
attr = p11_kit_uri_get_attribute (uri, CKA_LABEL);
- CuAssertPtrNotNull (tc, attr);
- CuAssertTrue (tc, attr->ulValueLen == strlen ("Test Label"));
- CuAssertTrue (tc, memcmp (attr->pValue, "Test Label", attr->ulValueLen) == 0);
+ assert_ptr_not_null (attr);
+ assert (attr->ulValueLen == strlen ("Test Label"));
+ assert (memcmp (attr->pValue, "Test Label", attr->ulValueLen) == 0);
attr = p11_kit_uri_get_attribute (uri, CKA_CLASS);
- CuAssertPtrNotNull (tc, attr);
- CuAssertTrue (tc, attr->ulValueLen == sizeof (CK_OBJECT_CLASS));
- CuAssertTrue (tc, *((CK_OBJECT_CLASS_PTR)attr->pValue) == CKO_CERTIFICATE);
+ assert_ptr_not_null (attr);
+ assert (attr->ulValueLen == sizeof (CK_OBJECT_CLASS));
+ assert (*((CK_OBJECT_CLASS_PTR)attr->pValue) == CKO_CERTIFICATE);
p11_kit_uri_free (uri);
}
static void
-test_uri_parse_with_id (CuTest *tc)
+test_uri_parse_with_id (void)
{
CK_ATTRIBUTE_PTR attr;
P11KitUri *uri;
int ret;
uri = p11_kit_uri_new ();
- CuAssertPtrNotNull (tc, uri);
+ assert_ptr_not_null (uri);
ret = p11_kit_uri_parse ("pkcs11:id=%54%45%53%54%00", P11_KIT_URI_FOR_OBJECT, uri);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
+ assert_num_eq (P11_KIT_URI_OK, ret);
/* Note that there's a NULL in the attribute (end) */
attr = p11_kit_uri_get_attribute (uri, CKA_ID);
- CuAssertPtrNotNull (tc, attr);
- CuAssertTrue (tc, attr->ulValueLen == 5);
- CuAssertTrue (tc, memcmp (attr->pValue, "TEST", 5) == 0);
+ assert_ptr_not_null (attr);
+ assert (attr->ulValueLen == 5);
+ assert (memcmp (attr->pValue, "TEST", 5) == 0);
p11_kit_uri_free (uri);
}
static void
-test_uri_parse_with_bad_string_encoding (CuTest *tc)
+test_uri_parse_with_bad_string_encoding (void)
{
P11KitUri *uri;
int ret;
uri = p11_kit_uri_new ();
- CuAssertPtrNotNull (tc, uri);
+ assert_ptr_not_null (uri);
ret = p11_kit_uri_parse ("pkcs11:object=Test%", P11_KIT_URI_FOR_OBJECT, uri);
- CuAssertIntEquals (tc, P11_KIT_URI_BAD_ENCODING, ret);
+ assert_num_eq (P11_KIT_URI_BAD_ENCODING, ret);
p11_kit_uri_free (uri);
}
static void
-test_uri_parse_with_bad_hex_encoding (CuTest *tc)
+test_uri_parse_with_bad_hex_encoding (void)
{
P11KitUri *uri;
int ret;
uri = p11_kit_uri_new ();
- CuAssertPtrNotNull (tc, uri);
+ assert_ptr_not_null (uri);
ret = p11_kit_uri_parse ("pkcs11:object=T%xxest", P11_KIT_URI_FOR_OBJECT, uri);
- CuAssertIntEquals (tc, P11_KIT_URI_BAD_ENCODING, ret);
+ assert_num_eq (P11_KIT_URI_BAD_ENCODING, ret);
p11_kit_uri_free (uri);
}
@@ -226,131 +226,131 @@ is_space_string (CK_UTF8CHAR_PTR string, CK_ULONG size, const char *check)
}
static void
-test_uri_parse_with_token (CuTest *tc)
+test_uri_parse_with_token (void)
{
P11KitUri *uri = NULL;
CK_TOKEN_INFO_PTR token;
int ret;
uri = p11_kit_uri_new ();
- CuAssertPtrNotNull (tc, uri);
+ assert_ptr_not_null (uri);
ret = p11_kit_uri_parse ("pkcs11:token=Token%20Label;serial=3333;model=Deluxe;manufacturer=Me",
P11_KIT_URI_FOR_TOKEN, uri);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
+ assert_num_eq (P11_KIT_URI_OK, ret);
token = p11_kit_uri_get_token_info (uri);
- CuAssertTrue (tc, is_space_string (token->label, sizeof (token->label), "Token Label"));
- CuAssertTrue (tc, is_space_string (token->serialNumber, sizeof (token->serialNumber), "3333"));
- CuAssertTrue (tc, is_space_string (token->model, sizeof (token->model), "Deluxe"));
- CuAssertTrue (tc, is_space_string (token->manufacturerID, sizeof (token->manufacturerID), "Me"));
+ assert (is_space_string (token->label, sizeof (token->label), "Token Label"));
+ assert (is_space_string (token->serialNumber, sizeof (token->serialNumber), "3333"));
+ assert (is_space_string (token->model, sizeof (token->model), "Deluxe"));
+ assert (is_space_string (token->manufacturerID, sizeof (token->manufacturerID), "Me"));
p11_kit_uri_free (uri);
}
static void
-test_uri_parse_with_token_bad_encoding (CuTest *tc)
+test_uri_parse_with_token_bad_encoding (void)
{
P11KitUri *uri;
int ret;
uri = p11_kit_uri_new ();
- CuAssertPtrNotNull (tc, uri);
+ assert_ptr_not_null (uri);
ret = p11_kit_uri_parse ("pkcs11:token=Token%", P11_KIT_URI_FOR_TOKEN, uri);
- CuAssertIntEquals (tc, P11_KIT_URI_BAD_ENCODING, ret);
+ assert_num_eq (P11_KIT_URI_BAD_ENCODING, ret);
p11_kit_uri_free (uri);
}
static void
-test_uri_parse_with_bad_syntax (CuTest *tc)
+test_uri_parse_with_bad_syntax (void)
{
P11KitUri *uri;
int ret;
uri = p11_kit_uri_new ();
- CuAssertPtrNotNull (tc, uri);
+ assert_ptr_not_null (uri);
ret = p11_kit_uri_parse ("pkcs11:token", P11_KIT_URI_FOR_ANY, uri);
- CuAssertIntEquals (tc, P11_KIT_URI_BAD_SYNTAX, ret);
+ assert_num_eq (P11_KIT_URI_BAD_SYNTAX, ret);
p11_kit_uri_free (uri);
}
static void
-test_uri_parse_with_spaces (CuTest *tc)
+test_uri_parse_with_spaces (void)
{
P11KitUri *uri = NULL;
CK_INFO_PTR info;
int ret;
uri = p11_kit_uri_new ();
- CuAssertPtrNotNull (tc, uri);
+ assert_ptr_not_null (uri);
ret = p11_kit_uri_parse ("pkc\ns11: lib rary-desc\rrip \n tion =The%20Library;\n\n\nlibrary-manufacturer=\rMe",
P11_KIT_URI_FOR_MODULE, uri);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
+ assert_num_eq (P11_KIT_URI_OK, ret);
info = p11_kit_uri_get_module_info (uri);
- CuAssertTrue (tc, is_space_string (info->manufacturerID, sizeof (info->manufacturerID), "Me"));
- CuAssertTrue (tc, is_space_string (info->libraryDescription, sizeof (info->libraryDescription), "The Library"));
+ assert (is_space_string (info->manufacturerID, sizeof (info->manufacturerID), "Me"));
+ assert (is_space_string (info->libraryDescription, sizeof (info->libraryDescription), "The Library"));
p11_kit_uri_free (uri);
}
static void
-test_uri_parse_with_library (CuTest *tc)
+test_uri_parse_with_library (void)
{
P11KitUri *uri = NULL;
CK_INFO_PTR info;
int ret;
uri = p11_kit_uri_new ();
- CuAssertPtrNotNull (tc, uri);
+ assert_ptr_not_null (uri);
ret = p11_kit_uri_parse ("pkcs11:library-description=The%20Library;library-manufacturer=Me",
P11_KIT_URI_FOR_MODULE, uri);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
+ assert_num_eq (P11_KIT_URI_OK, ret);
info = p11_kit_uri_get_module_info (uri);
- CuAssertTrue (tc, is_space_string (info->manufacturerID, sizeof (info->manufacturerID), "Me"));
- CuAssertTrue (tc, is_space_string (info->libraryDescription, sizeof (info->libraryDescription), "The Library"));
+ assert (is_space_string (info->manufacturerID, sizeof (info->manufacturerID), "Me"));
+ assert (is_space_string (info->libraryDescription, sizeof (info->libraryDescription), "The Library"));
p11_kit_uri_free (uri);
}
static void
-test_uri_parse_with_library_bad_encoding (CuTest *tc)
+test_uri_parse_with_library_bad_encoding (void)
{
P11KitUri *uri;
int ret;
uri = p11_kit_uri_new ();
- CuAssertPtrNotNull (tc, uri);
+ assert_ptr_not_null (uri);
ret = p11_kit_uri_parse ("pkcs11:library-description=Library%", P11_KIT_URI_FOR_MODULE, uri);
- CuAssertIntEquals (tc, P11_KIT_URI_BAD_ENCODING, ret);
+ assert_num_eq (P11_KIT_URI_BAD_ENCODING, ret);
p11_kit_uri_free (uri);
}
static void
-test_uri_build_empty (CuTest *tc)
+test_uri_build_empty (void)
{
P11KitUri *uri;
char *string;
int ret;
uri = p11_kit_uri_new ();
- CuAssertPtrNotNull (tc, uri);
+ assert_ptr_not_null (uri);
ret = p11_kit_uri_format (uri, P11_KIT_URI_FOR_ANY, &string);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
- CuAssertStrEquals (tc, "pkcs11:", string);
+ assert_num_eq (P11_KIT_URI_OK, ret);
+ assert_str_eq ("pkcs11:", string);
free (string);
p11_kit_uri_free (uri);
@@ -366,7 +366,7 @@ set_space_string (CK_BYTE_PTR buffer, CK_ULONG length, const char *string)
}
static void
-test_uri_build_with_token_info (CuTest *tc)
+test_uri_build_with_token_info (void)
{
char *string = NULL;
P11KitUri *uri;
@@ -375,7 +375,7 @@ test_uri_build_with_token_info (CuTest *tc)
int ret;
uri = p11_kit_uri_new ();
- CuAssertPtrNotNull (tc, uri);
+ assert_ptr_not_null (uri);
token = p11_kit_uri_get_token_info (uri);
set_space_string (token->label, sizeof (token->label), "The Label");
@@ -384,30 +384,30 @@ test_uri_build_with_token_info (CuTest *tc)
set_space_string (token->model, sizeof (token->model), "Deluxe");
ret = p11_kit_uri_format (uri, P11_KIT_URI_FOR_ANY, &string);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
- CuAssertPtrNotNull (tc, string);
+ assert_num_eq (P11_KIT_URI_OK, ret);
+ assert_ptr_not_null (string);
check = p11_kit_uri_new ();
- CuAssertPtrNotNull (tc, check);
+ assert_ptr_not_null (check);
ret = p11_kit_uri_parse (string, P11_KIT_URI_FOR_TOKEN, check);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
+ assert_num_eq (P11_KIT_URI_OK, ret);
p11_kit_uri_match_token_info (check, p11_kit_uri_get_token_info (uri));
p11_kit_uri_free (uri);
p11_kit_uri_free (check);
- CuAssertTrue (tc, strstr (string, "token=The%20Label") != NULL);
- CuAssertTrue (tc, strstr (string, "serial=44444") != NULL);
- CuAssertTrue (tc, strstr (string, "manufacturer=Me") != NULL);
- CuAssertTrue (tc, strstr (string, "model=Deluxe") != NULL);
+ assert (strstr (string, "token=The%20Label") != NULL);
+ assert (strstr (string, "serial=44444") != NULL);
+ assert (strstr (string, "manufacturer=Me") != NULL);
+ assert (strstr (string, "model=Deluxe") != NULL);
free (string);
}
static void
-test_uri_build_with_token_null_info (CuTest *tc)
+test_uri_build_with_token_null_info (void)
{
char *string = NULL;
P11KitUri *uri;
@@ -415,23 +415,23 @@ test_uri_build_with_token_null_info (CuTest *tc)
int ret;
uri = p11_kit_uri_new ();
- CuAssertPtrNotNull (tc, uri);
+ assert_ptr_not_null (uri);
token = p11_kit_uri_get_token_info (uri);
set_space_string (token->label, sizeof (token->label), "The Label");
ret = p11_kit_uri_format (uri, P11_KIT_URI_FOR_ANY, &string);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
+ assert_num_eq (P11_KIT_URI_OK, ret);
- CuAssertTrue (tc, strstr (string, "token=The%20Label") != NULL);
- CuAssertTrue (tc, strstr (string, "serial=") == NULL);
+ assert (strstr (string, "token=The%20Label") != NULL);
+ assert (strstr (string, "serial=") == NULL);
free (string);
p11_kit_uri_free (uri);
}
static void
-test_uri_build_with_token_empty_info (CuTest *tc)
+test_uri_build_with_token_empty_info (void)
{
char *string = NULL;
P11KitUri *uri;
@@ -439,24 +439,24 @@ test_uri_build_with_token_empty_info (CuTest *tc)
int ret;
uri = p11_kit_uri_new ();
- CuAssertPtrNotNull (tc, uri);
+ assert_ptr_not_null (uri);
token = p11_kit_uri_get_token_info (uri);
set_space_string (token->label, sizeof (token->label), "");
set_space_string (token->serialNumber, sizeof (token->serialNumber), "");
ret = p11_kit_uri_format (uri, P11_KIT_URI_FOR_ANY, &string);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
+ assert_num_eq (P11_KIT_URI_OK, ret);
- CuAssertTrue (tc, strstr (string, "token=") != NULL);
- CuAssertTrue (tc, strstr (string, "serial=") != NULL);
+ assert (strstr (string, "token=") != NULL);
+ assert (strstr (string, "serial=") != NULL);
free (string);
p11_kit_uri_free (uri);
}
static void
-test_uri_build_with_attributes (CuTest *tc)
+test_uri_build_with_attributes (void)
{
char *string = NULL;
P11KitUri *uri;
@@ -467,7 +467,7 @@ test_uri_build_with_attributes (CuTest *tc)
int ret;
uri = p11_kit_uri_new ();
- CuAssertPtrNotNull (tc, uri);
+ assert_ptr_not_null (uri);
at.type = CKA_LABEL;
at.pValue = "The Label";
@@ -486,175 +486,175 @@ test_uri_build_with_attributes (CuTest *tc)
ret = p11_kit_uri_set_attribute (uri, &at);
ret = p11_kit_uri_format (uri, P11_KIT_URI_FOR_ANY, &string);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
+ assert_num_eq (P11_KIT_URI_OK, ret);
check = p11_kit_uri_new ();
- CuAssertPtrNotNull (tc, check);
+ assert_ptr_not_null (check);
ret = p11_kit_uri_parse (string, P11_KIT_URI_FOR_ANY, check);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
+ assert_num_eq (P11_KIT_URI_OK, ret);
attr = p11_kit_uri_get_attribute (check, CKA_LABEL);
- CuAssertPtrNotNull (tc, attr);
- CuAssertTrue (tc, attr->ulValueLen == 9);
- CuAssertTrue (tc, memcmp (attr->pValue, "The Label", attr->ulValueLen) == 0);
+ assert_ptr_not_null (attr);
+ assert (attr->ulValueLen == 9);
+ assert (memcmp (attr->pValue, "The Label", attr->ulValueLen) == 0);
attr = p11_kit_uri_get_attribute (check, CKA_CLASS);
- CuAssertPtrNotNull (tc, attr);
- CuAssertTrue (tc, attr->ulValueLen == sizeof (klass));
- CuAssertTrue (tc, *((CK_OBJECT_CLASS_PTR)attr->pValue) == klass);
+ assert_ptr_not_null (attr);
+ assert (attr->ulValueLen == sizeof (klass));
+ assert (*((CK_OBJECT_CLASS_PTR)attr->pValue) == klass);
attr = p11_kit_uri_get_attribute (check, CKA_ID);
- CuAssertPtrNotNull (tc, attr);
- CuAssertTrue (tc, attr->ulValueLen == 5);
- CuAssertTrue (tc, memcmp (attr->pValue, "HELLO", attr->ulValueLen) == 0);
+ assert_ptr_not_null (attr);
+ assert (attr->ulValueLen == 5);
+ assert (memcmp (attr->pValue, "HELLO", attr->ulValueLen) == 0);
p11_kit_uri_free (check);
- CuAssertTrue (tc, strstr (string, "object=The%20Label") != NULL);
- CuAssertTrue (tc, strstr (string, "object-type=data") != NULL);
- CuAssertTrue (tc, strstr (string, "id=%48%45%4c%4c%4f") != NULL);
+ assert (strstr (string, "object=The%20Label") != NULL);
+ assert (strstr (string, "object-type=data") != NULL);
+ assert (strstr (string, "id=%48%45%4c%4c%4f") != NULL);
free (string);
p11_kit_uri_free (uri);
}
static void
-test_uri_parse_private_key (CuTest *tc)
+test_uri_parse_private_key (void)
{
P11KitUri *uri;
CK_ATTRIBUTE_PTR attr;
int ret;
uri = p11_kit_uri_new ();
- CuAssertPtrNotNull (tc, uri);
+ assert_ptr_not_null (uri);
ret = p11_kit_uri_parse ("pkcs11:object-type=private", P11_KIT_URI_FOR_OBJECT, uri);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
+ assert_num_eq (P11_KIT_URI_OK, ret);
attr = p11_kit_uri_get_attribute (uri, CKA_CLASS);
- CuAssertPtrNotNull (tc, attr);
- CuAssertTrue (tc, attr->ulValueLen == sizeof (CK_OBJECT_CLASS));
- CuAssertTrue (tc, *((CK_OBJECT_CLASS_PTR)attr->pValue) == CKO_PRIVATE_KEY);
+ assert_ptr_not_null (attr);
+ assert (attr->ulValueLen == sizeof (CK_OBJECT_CLASS));
+ assert (*((CK_OBJECT_CLASS_PTR)attr->pValue) == CKO_PRIVATE_KEY);
p11_kit_uri_free (uri);
}
static void
-test_uri_parse_secret_key (CuTest *tc)
+test_uri_parse_secret_key (void)
{
P11KitUri *uri;
CK_ATTRIBUTE_PTR attr;
int ret;
uri = p11_kit_uri_new ();
- CuAssertPtrNotNull (tc, uri);
+ assert_ptr_not_null (uri);
ret = p11_kit_uri_parse ("pkcs11:object-type=secret-key", P11_KIT_URI_FOR_OBJECT, uri);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
+ assert_num_eq (P11_KIT_URI_OK, ret);
attr = p11_kit_uri_get_attribute (uri, CKA_CLASS);
- CuAssertPtrNotNull (tc, attr);
- CuAssertTrue (tc, attr->ulValueLen == sizeof (CK_OBJECT_CLASS));
- CuAssertTrue (tc, *((CK_OBJECT_CLASS_PTR)attr->pValue) == CKO_SECRET_KEY);
+ assert_ptr_not_null (attr);
+ assert (attr->ulValueLen == sizeof (CK_OBJECT_CLASS));
+ assert (*((CK_OBJECT_CLASS_PTR)attr->pValue) == CKO_SECRET_KEY);
p11_kit_uri_free (uri);
}
static void
-test_uri_parse_library_version (CuTest *tc)
+test_uri_parse_library_version (void)
{
P11KitUri *uri;
CK_INFO_PTR info;
int ret;
uri = p11_kit_uri_new ();
- CuAssertPtrNotNull (tc, uri);
+ assert_ptr_not_null (uri);
ret = p11_kit_uri_parse ("pkcs11:library-version=2.101", P11_KIT_URI_FOR_MODULE_WITH_VERSION, uri);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
+ assert_num_eq (P11_KIT_URI_OK, ret);
info = p11_kit_uri_get_module_info (uri);
- CuAssertIntEquals (tc, 2, info->libraryVersion.major);
- CuAssertIntEquals (tc, 101, info->libraryVersion.minor);
+ assert_num_eq (2, info->libraryVersion.major);
+ assert_num_eq (101, info->libraryVersion.minor);
ret = p11_kit_uri_parse ("pkcs11:library-version=23", P11_KIT_URI_FOR_MODULE_WITH_VERSION, uri);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
+ assert_num_eq (P11_KIT_URI_OK, ret);
info = p11_kit_uri_get_module_info (uri);
- CuAssertIntEquals (tc, 23, info->libraryVersion.major);
- CuAssertIntEquals (tc, 0, info->libraryVersion.minor);
+ assert_num_eq (23, info->libraryVersion.major);
+ assert_num_eq (0, info->libraryVersion.minor);
ret = p11_kit_uri_parse ("pkcs11:library-version=23.", P11_KIT_URI_FOR_MODULE_WITH_VERSION, uri);
- CuAssertIntEquals (tc, P11_KIT_URI_BAD_VERSION, ret);
+ assert_num_eq (P11_KIT_URI_BAD_VERSION, ret);
ret = p11_kit_uri_parse ("pkcs11:library-version=a.a", P11_KIT_URI_FOR_MODULE_WITH_VERSION, uri);
- CuAssertIntEquals (tc, P11_KIT_URI_BAD_VERSION, ret);
+ assert_num_eq (P11_KIT_URI_BAD_VERSION, ret);
ret = p11_kit_uri_parse ("pkcs11:library-version=.23", P11_KIT_URI_FOR_MODULE_WITH_VERSION, uri);
- CuAssertIntEquals (tc, P11_KIT_URI_BAD_VERSION, ret);
+ assert_num_eq (P11_KIT_URI_BAD_VERSION, ret);
ret = p11_kit_uri_parse ("pkcs11:library-version=1000", P11_KIT_URI_FOR_MODULE_WITH_VERSION, uri);
- CuAssertIntEquals (tc, P11_KIT_URI_BAD_VERSION, ret);
+ assert_num_eq (P11_KIT_URI_BAD_VERSION, ret);
ret = p11_kit_uri_parse ("pkcs11:library-version=2.1000", P11_KIT_URI_FOR_MODULE_WITH_VERSION, uri);
- CuAssertIntEquals (tc, P11_KIT_URI_BAD_VERSION, ret);
+ assert_num_eq (P11_KIT_URI_BAD_VERSION, ret);
p11_kit_uri_free (uri);
}
static void
-test_uri_parse_parse_unknown_object_type (CuTest *tc)
+test_uri_parse_parse_unknown_object_type (void)
{
P11KitUri *uri;
CK_ATTRIBUTE_PTR attr;
int ret;
uri = p11_kit_uri_new ();
- CuAssertPtrNotNull (tc, uri);
+ assert_ptr_not_null (uri);
ret = p11_kit_uri_parse ("pkcs11:object-type=unknown", P11_KIT_URI_FOR_OBJECT, uri);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
+ assert_num_eq (P11_KIT_URI_OK, ret);
attr = p11_kit_uri_get_attribute (uri, CKA_CLASS);
- CuAssertPtrEquals (tc, NULL, attr);
+ assert_ptr_eq (NULL, attr);
p11_kit_uri_free (uri);
}
static void
-test_uri_parse_unrecognized (CuTest *tc)
+test_uri_parse_unrecognized (void)
{
P11KitUri *uri;
int ret;
uri = p11_kit_uri_new ();
- CuAssertPtrNotNull (tc, uri);
+ assert_ptr_not_null (uri);
ret = p11_kit_uri_parse ("pkcs11:x-blah=some-value", P11_KIT_URI_FOR_ANY, uri);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
+ assert_num_eq (P11_KIT_URI_OK, ret);
ret = p11_kit_uri_any_unrecognized (uri);
- CuAssertIntEquals (tc, 1, ret);
+ assert_num_eq (1, ret);
p11_kit_uri_free (uri);
}
static void
-test_uri_parse_too_long_is_unrecognized (CuTest *tc)
+test_uri_parse_too_long_is_unrecognized (void)
{
P11KitUri *uri;
int ret;
uri = p11_kit_uri_new ();
- CuAssertPtrNotNull (tc, uri);
+ assert_ptr_not_null (uri);
ret = p11_kit_uri_parse ("pkcs11:model=a-value-that-is-too-long-for-the-field-that-it-goes-with",
P11_KIT_URI_FOR_ANY, uri);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
+ assert_num_eq (P11_KIT_URI_OK, ret);
ret = p11_kit_uri_any_unrecognized (uri);
- CuAssertIntEquals (tc, 1, ret);
+ assert_num_eq (1, ret);
p11_kit_uri_free (uri);
}
@@ -662,7 +662,7 @@ test_uri_parse_too_long_is_unrecognized (CuTest *tc)
static void
-test_uri_build_object_type_cert (CuTest *tc)
+test_uri_build_object_type_cert (void)
{
CK_ATTRIBUTE attr;
CK_OBJECT_CLASS klass;
@@ -671,7 +671,7 @@ test_uri_build_object_type_cert (CuTest *tc)
int ret;
uri = p11_kit_uri_new ();
- CuAssertPtrNotNull (tc, uri);
+ assert_ptr_not_null (uri);
klass = CKO_CERTIFICATE;
attr.type = CKA_CLASS;
@@ -680,15 +680,15 @@ test_uri_build_object_type_cert (CuTest *tc)
p11_kit_uri_set_attribute (uri, &attr);
ret = p11_kit_uri_format (uri, P11_KIT_URI_FOR_ANY, &string);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
- CuAssertTrue (tc, strstr (string, "object-type=cert") != NULL);
+ assert_num_eq (P11_KIT_URI_OK, ret);
+ assert (strstr (string, "object-type=cert") != NULL);
p11_kit_uri_free (uri);
free (string);
}
static void
-test_uri_build_object_type_private (CuTest *tc)
+test_uri_build_object_type_private (void)
{
CK_ATTRIBUTE attr;
CK_OBJECT_CLASS klass;
@@ -697,7 +697,7 @@ test_uri_build_object_type_private (CuTest *tc)
int ret;
uri = p11_kit_uri_new ();
- CuAssertPtrNotNull (tc, uri);
+ assert_ptr_not_null (uri);
klass = CKO_PRIVATE_KEY;
attr.type = CKA_CLASS;
@@ -706,15 +706,15 @@ test_uri_build_object_type_private (CuTest *tc)
p11_kit_uri_set_attribute (uri, &attr);
ret = p11_kit_uri_format (uri, P11_KIT_URI_FOR_ANY, &string);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
- CuAssertTrue (tc, strstr (string, "object-type=private") != NULL);
+ assert_num_eq (P11_KIT_URI_OK, ret);
+ assert (strstr (string, "object-type=private") != NULL);
p11_kit_uri_free (uri);
free (string);
}
static void
-test_uri_build_object_type_public (CuTest *tc)
+test_uri_build_object_type_public (void)
{
CK_ATTRIBUTE attr;
CK_OBJECT_CLASS klass;
@@ -723,7 +723,7 @@ test_uri_build_object_type_public (CuTest *tc)
int ret;
uri = p11_kit_uri_new ();
- CuAssertPtrNotNull (tc, uri);
+ assert_ptr_not_null (uri);
klass = CKO_PUBLIC_KEY;
attr.type = CKA_CLASS;
@@ -732,15 +732,15 @@ test_uri_build_object_type_public (CuTest *tc)
p11_kit_uri_set_attribute (uri, &attr);
ret = p11_kit_uri_format (uri, P11_KIT_URI_FOR_ANY, &string);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
- CuAssertTrue (tc, strstr (string, "object-type=public") != NULL);
+ assert_num_eq (P11_KIT_URI_OK, ret);
+ assert (strstr (string, "object-type=public") != NULL);
p11_kit_uri_free (uri);
free (string);
}
static void
-test_uri_build_object_type_secret (CuTest *tc)
+test_uri_build_object_type_secret (void)
{
CK_ATTRIBUTE attr;
CK_OBJECT_CLASS klass;
@@ -749,7 +749,7 @@ test_uri_build_object_type_secret (CuTest *tc)
int ret;
uri = p11_kit_uri_new ();
- CuAssertPtrNotNull (tc, uri);
+ assert_ptr_not_null (uri);
klass = CKO_SECRET_KEY;
attr.type = CKA_CLASS;
@@ -758,15 +758,15 @@ test_uri_build_object_type_secret (CuTest *tc)
p11_kit_uri_set_attribute (uri, &attr);
ret = p11_kit_uri_format (uri, P11_KIT_URI_FOR_ANY, &string);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
- CuAssertTrue (tc, strstr (string, "object-type=secret-key") != NULL);
+ assert_num_eq (P11_KIT_URI_OK, ret);
+ assert (strstr (string, "object-type=secret-key") != NULL);
p11_kit_uri_free (uri);
free (string);
}
static void
-test_uri_build_with_library (CuTest *tc)
+test_uri_build_with_library (void)
{
CK_INFO_PTR info;
P11KitUri *uri;
@@ -774,21 +774,21 @@ test_uri_build_with_library (CuTest *tc)
int ret;
uri = p11_kit_uri_new ();
- CuAssertPtrNotNull (tc, uri);
+ assert_ptr_not_null (uri);
info = p11_kit_uri_get_module_info (uri);
set_space_string (info->libraryDescription, sizeof (info->libraryDescription), "The Description");
ret = p11_kit_uri_format (uri, P11_KIT_URI_FOR_ANY, &string);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
- CuAssertTrue (tc, strstr (string, "library-description=The%20Description") != NULL);
+ assert_num_eq (P11_KIT_URI_OK, ret);
+ assert (strstr (string, "library-description=The%20Description") != NULL);
p11_kit_uri_free (uri);
free (string);
}
static void
-test_uri_build_library_version (CuTest *tc)
+test_uri_build_library_version (void)
{
CK_INFO_PTR info;
P11KitUri *uri;
@@ -796,121 +796,121 @@ test_uri_build_library_version (CuTest *tc)
int ret;
uri = p11_kit_uri_new ();
- CuAssertPtrNotNull (tc, uri);
+ assert_ptr_not_null (uri);
info = p11_kit_uri_get_module_info (uri);
info->libraryVersion.major = 2;
info->libraryVersion.minor = 10;
ret = p11_kit_uri_format (uri, P11_KIT_URI_FOR_ANY, &string);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
- CuAssertTrue (tc, strstr (string, "library-version=2.10") != NULL);
+ assert_num_eq (P11_KIT_URI_OK, ret);
+ assert (strstr (string, "library-version=2.10") != NULL);
p11_kit_uri_free (uri);
free (string);
}
static void
-test_uri_get_set_unrecognized (CuTest *tc)
+test_uri_get_set_unrecognized (void)
{
P11KitUri *uri;
int ret;
uri = p11_kit_uri_new ();
- CuAssertPtrNotNull (tc, uri);
+ assert_ptr_not_null (uri);
ret = p11_kit_uri_any_unrecognized (uri);
- CuAssertIntEquals (tc, 0, ret);
+ assert_num_eq (0, ret);
p11_kit_uri_set_unrecognized (uri, 1);
ret = p11_kit_uri_any_unrecognized (uri);
- CuAssertIntEquals (tc, 1, ret);
+ assert_num_eq (1, ret);
p11_kit_uri_set_unrecognized (uri, 0);
ret = p11_kit_uri_any_unrecognized (uri);
- CuAssertIntEquals (tc, 0, ret);
+ assert_num_eq (0, ret);
p11_kit_uri_free (uri);
}
static void
-test_uri_match_token (CuTest *tc)
+test_uri_match_token (void)
{
CK_TOKEN_INFO token;
P11KitUri *uri;
int ret;
uri = p11_kit_uri_new ();
- CuAssertPtrNotNull (tc, uri);
+ assert_ptr_not_null (uri);
ret = p11_kit_uri_parse ("pkcs11:model=Giselle", P11_KIT_URI_FOR_ANY, uri);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
+ assert_num_eq (P11_KIT_URI_OK, ret);
set_space_string (token.label, sizeof (token.label), "A label");
set_space_string (token.model, sizeof (token.model), "Giselle");
ret = p11_kit_uri_match_token_info (uri, &token);
- CuAssertIntEquals (tc, 1, ret);
+ assert_num_eq (1, ret);
set_space_string (token.label, sizeof (token.label), "Another label");
ret = p11_kit_uri_match_token_info (uri, &token);
- CuAssertIntEquals (tc, 1, ret);
+ assert_num_eq (1, ret);
set_space_string (token.model, sizeof (token.model), "Zoolander");
ret = p11_kit_uri_match_token_info (uri, &token);
- CuAssertIntEquals (tc, 0, ret);
+ assert_num_eq (0, ret);
p11_kit_uri_set_unrecognized (uri, 1);
ret = p11_kit_uri_match_token_info (uri, &token);
- CuAssertIntEquals (tc, 0, ret);
+ assert_num_eq (0, ret);
p11_kit_uri_free (uri);
}
static void
-test_uri_match_module (CuTest *tc)
+test_uri_match_module (void)
{
CK_INFO info;
P11KitUri *uri;
int ret;
uri = p11_kit_uri_new ();
- CuAssertPtrNotNull (tc, uri);
+ assert_ptr_not_null (uri);
ret = p11_kit_uri_parse ("pkcs11:library-description=Quiet", P11_KIT_URI_FOR_ANY, uri);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
+ assert_num_eq (P11_KIT_URI_OK, ret);
set_space_string (info.libraryDescription, sizeof (info.libraryDescription), "Quiet");
set_space_string (info.manufacturerID, sizeof (info.manufacturerID), "Someone");
ret = p11_kit_uri_match_module_info (uri, &info);
- CuAssertIntEquals (tc, 1, ret);
+ assert_num_eq (1, ret);
set_space_string (info.manufacturerID, sizeof (info.manufacturerID), "Someone else");
ret = p11_kit_uri_match_module_info (uri, &info);
- CuAssertIntEquals (tc, 1, ret);
+ assert_num_eq (1, ret);
set_space_string (info.libraryDescription, sizeof (info.libraryDescription), "Leise");
ret = p11_kit_uri_match_module_info (uri, &info);
- CuAssertIntEquals (tc, 0, ret);
+ assert_num_eq (0, ret);
p11_kit_uri_set_unrecognized (uri, 1);
ret = p11_kit_uri_match_module_info (uri, &info);
- CuAssertIntEquals (tc, 0, ret);
+ assert_num_eq (0, ret);
p11_kit_uri_free (uri);
}
static void
-test_uri_match_version (CuTest *tc)
+test_uri_match_version (void)
{
CK_INFO info;
P11KitUri *uri;
@@ -919,28 +919,28 @@ test_uri_match_version (CuTest *tc)
memset (&info, 0, sizeof (info));
uri = p11_kit_uri_new ();
- CuAssertPtrNotNull (tc, uri);
+ assert_ptr_not_null (uri);
ret = p11_kit_uri_parse ("pkcs11:library-version=5.8", P11_KIT_URI_FOR_ANY, uri);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
+ assert_num_eq (P11_KIT_URI_OK, ret);
info.libraryVersion.major = 5;
info.libraryVersion.minor = 8;
ret = p11_kit_uri_match_module_info (uri, &info);
- CuAssertIntEquals (tc, 1, ret);
+ assert_num_eq (1, ret);
info.libraryVersion.major = 2;
info.libraryVersion.minor = 3;
ret = p11_kit_uri_match_module_info (uri, &info);
- CuAssertIntEquals (tc, 0, ret);
+ assert_num_eq (0, ret);
p11_kit_uri_free (uri);
}
static void
-test_uri_match_attributes (CuTest *tc)
+test_uri_match_attributes (void)
{
CK_ATTRIBUTE attrs[4];
CK_OBJECT_CLASS klass;
@@ -965,40 +965,40 @@ test_uri_match_attributes (CuTest *tc)
attrs[3].ulValueLen = sizeof (klass);
uri = p11_kit_uri_new ();
- CuAssertPtrNotNull (tc, uri);
+ assert_ptr_not_null (uri);
ret = p11_kit_uri_parse ("pkcs11:object=Fancy;id=Blah;object-type=data", P11_KIT_URI_FOR_ANY, uri);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
+ assert_num_eq (P11_KIT_URI_OK, ret);
ret = p11_kit_uri_match_attributes (uri, attrs, 4);
- CuAssertIntEquals (tc, 0, ret);
+ assert_num_eq (0, ret);
attrs[1].pValue = "Fancy";
attrs[1].ulValueLen = 5;
ret = p11_kit_uri_match_attributes (uri, attrs, 4);
- CuAssertIntEquals (tc, 1, ret);
+ assert_num_eq (1, ret);
p11_kit_uri_clear_attribute (uri, CKA_CLASS);
ret = p11_kit_uri_match_attributes (uri, attrs, 4);
- CuAssertIntEquals (tc, 1, ret);
+ assert_num_eq (1, ret);
attrs[2].pValue = "pink";
ret = p11_kit_uri_match_attributes (uri, attrs, 4);
- CuAssertIntEquals (tc, 1, ret);
+ assert_num_eq (1, ret);
p11_kit_uri_set_unrecognized (uri, 1);
ret = p11_kit_uri_match_attributes (uri, attrs, 4);
- CuAssertIntEquals (tc, 0, ret);
+ assert_num_eq (0, ret);
p11_kit_uri_free (uri);
}
static void
-test_uri_get_set_attribute (CuTest *tc)
+test_uri_get_set_attribute (void)
{
CK_ATTRIBUTE attr;
CK_ATTRIBUTE_PTR ptr;
@@ -1006,51 +1006,51 @@ test_uri_get_set_attribute (CuTest *tc)
int ret;
uri = p11_kit_uri_new ();
- CuAssertPtrNotNull (tc, uri);
+ assert_ptr_not_null (uri);
ptr = p11_kit_uri_get_attribute (uri, CKA_LABEL);
- CuAssertPtrEquals (tc, NULL, ptr);
+ assert_ptr_eq (NULL, ptr);
ret = p11_kit_uri_clear_attribute (uri, CKA_LABEL);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
+ assert_num_eq (P11_KIT_URI_OK, ret);
ret = p11_kit_uri_clear_attribute (uri, CKA_COLOR);
- CuAssertIntEquals (tc, P11_KIT_URI_NOT_FOUND, ret);
+ assert_num_eq (P11_KIT_URI_NOT_FOUND, ret);
attr.type = CKA_LABEL;
attr.pValue = "Test";
attr.ulValueLen = 4;
ret = p11_kit_uri_set_attribute (uri, &attr);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
+ assert_num_eq (P11_KIT_URI_OK, ret);
/* We can set other attributes */
attr.type = CKA_COLOR;
ret = p11_kit_uri_set_attribute (uri, &attr);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
+ assert_num_eq (P11_KIT_URI_OK, ret);
/* And get them too */
ptr = p11_kit_uri_get_attribute (uri, CKA_COLOR);
- CuAssertPtrNotNull (tc, ptr);
+ assert_ptr_not_null (ptr);
ptr = p11_kit_uri_get_attribute (uri, CKA_LABEL);
- CuAssertPtrNotNull (tc, ptr);
+ assert_ptr_not_null (ptr);
- CuAssertTrue (tc, ptr->type == CKA_LABEL);
- CuAssertTrue (tc, ptr->ulValueLen == 4);
- CuAssertTrue (tc, memcmp (ptr->pValue, "Test", 4) == 0);
+ assert (ptr->type == CKA_LABEL);
+ assert (ptr->ulValueLen == 4);
+ assert (memcmp (ptr->pValue, "Test", 4) == 0);
ret = p11_kit_uri_clear_attribute (uri, CKA_LABEL);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
+ assert_num_eq (P11_KIT_URI_OK, ret);
ptr = p11_kit_uri_get_attribute (uri, CKA_LABEL);
- CuAssertPtrEquals (tc, NULL, ptr);
+ assert_ptr_eq (NULL, ptr);
p11_kit_uri_free (uri);
}
static void
-test_uri_get_set_attributes (CuTest *tc)
+test_uri_get_set_attributes (void)
{
CK_ATTRIBUTE_PTR attrs;
CK_OBJECT_CLASS klass;
@@ -1060,39 +1060,39 @@ test_uri_get_set_attributes (CuTest *tc)
int ret;
uri = p11_kit_uri_new ();
- CuAssertPtrNotNull (tc, uri);
+ assert_ptr_not_null (uri);
attrs = p11_kit_uri_get_attributes (uri, &n_attrs);
- CuAssertPtrNotNull (tc, attrs);
- CuAssertIntEquals (tc, 0, n_attrs);
+ assert_ptr_not_null (attrs);
+ assert_num_eq (0, n_attrs);
attr.type = CKA_LABEL;
attr.pValue = "Test";
attr.ulValueLen = 4;
ret = p11_kit_uri_set_attribute (uri, &attr);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
+ assert_num_eq (P11_KIT_URI_OK, ret);
attrs = p11_kit_uri_get_attributes (uri, &n_attrs);
- CuAssertPtrNotNull (tc, attrs);
- CuAssertIntEquals (tc, 1, n_attrs);
- CuAssertTrue (tc, attrs[0].type == CKA_LABEL);
- CuAssertTrue (tc, attrs[0].ulValueLen == 4);
- CuAssertTrue (tc, memcmp (attrs[0].pValue, "Test", 4) == 0);
+ assert_ptr_not_null (attrs);
+ assert_num_eq (1, n_attrs);
+ assert (attrs[0].type == CKA_LABEL);
+ assert (attrs[0].ulValueLen == 4);
+ assert (memcmp (attrs[0].pValue, "Test", 4) == 0);
attr.type = CKA_LABEL;
attr.pValue = "Kablooey";
attr.ulValueLen = 8;
ret = p11_kit_uri_set_attribute (uri, &attr);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
+ assert_num_eq (P11_KIT_URI_OK, ret);
attrs = p11_kit_uri_get_attributes (uri, &n_attrs);
- CuAssertPtrNotNull (tc, attrs);
- CuAssertIntEquals (tc, 1, n_attrs);
- CuAssertTrue (tc, attrs[0].type == CKA_LABEL);
- CuAssertTrue (tc, attrs[0].ulValueLen == 8);
- CuAssertTrue (tc, memcmp (attrs[0].pValue, "Kablooey", 8) == 0);
+ assert_ptr_not_null (attrs);
+ assert_num_eq (1, n_attrs);
+ assert (attrs[0].type == CKA_LABEL);
+ assert (attrs[0].ulValueLen == 8);
+ assert (memcmp (attrs[0].pValue, "Kablooey", 8) == 0);
klass = CKO_DATA;
attr.type = CKA_CLASS;
@@ -1100,52 +1100,52 @@ test_uri_get_set_attributes (CuTest *tc)
attr.ulValueLen = sizeof (klass);
ret = p11_kit_uri_set_attribute (uri, &attr);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
+ assert_num_eq (P11_KIT_URI_OK, ret);
attrs = p11_kit_uri_get_attributes (uri, &n_attrs);
- CuAssertPtrNotNull (tc, attrs);
- CuAssertIntEquals (tc, 2, n_attrs);
- CuAssertTrue (tc, attrs[0].type == CKA_LABEL);
- CuAssertTrue (tc, attrs[0].ulValueLen == 8);
- CuAssertTrue (tc, memcmp (attrs[0].pValue, "Kablooey", 8) == 0);
- CuAssertTrue (tc, attrs[1].type == CKA_CLASS);
- CuAssertTrue (tc, attrs[1].ulValueLen == sizeof (klass));
- CuAssertTrue (tc, memcmp (attrs[1].pValue, &klass, sizeof (klass)) == 0);
+ assert_ptr_not_null (attrs);
+ assert_num_eq (2, n_attrs);
+ assert (attrs[0].type == CKA_LABEL);
+ assert (attrs[0].ulValueLen == 8);
+ assert (memcmp (attrs[0].pValue, "Kablooey", 8) == 0);
+ assert (attrs[1].type == CKA_CLASS);
+ assert (attrs[1].ulValueLen == sizeof (klass));
+ assert (memcmp (attrs[1].pValue, &klass, sizeof (klass)) == 0);
ret = p11_kit_uri_clear_attribute (uri, CKA_LABEL);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
+ assert_num_eq (P11_KIT_URI_OK, ret);
attrs = p11_kit_uri_get_attributes (uri, &n_attrs);
- CuAssertPtrNotNull (tc, attrs);
- CuAssertIntEquals (tc, 1, n_attrs);
- CuAssertTrue (tc, attrs[0].type == CKA_CLASS);
- CuAssertTrue (tc, attrs[0].ulValueLen == sizeof (klass));
- CuAssertTrue (tc, memcmp (attrs[0].pValue, &klass, sizeof (klass)) == 0);
+ assert_ptr_not_null (attrs);
+ assert_num_eq (1, n_attrs);
+ assert (attrs[0].type == CKA_CLASS);
+ assert (attrs[0].ulValueLen == sizeof (klass));
+ assert (memcmp (attrs[0].pValue, &klass, sizeof (klass)) == 0);
attr.type = CKA_LABEL;
attr.pValue = "Three";
attr.ulValueLen = 5;
ret = p11_kit_uri_set_attributes (uri, &attr, 1);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
+ assert_num_eq (P11_KIT_URI_OK, ret);
attrs = p11_kit_uri_get_attributes (uri, &n_attrs);
- CuAssertPtrNotNull (tc, attrs);
- CuAssertIntEquals (tc, 1, n_attrs);
- CuAssertTrue (tc, attrs[0].type == CKA_LABEL);
- CuAssertTrue (tc, attrs[0].ulValueLen == 5);
- CuAssertTrue (tc, memcmp (attrs[0].pValue, "Three", 5) == 0);
+ assert_ptr_not_null (attrs);
+ assert_num_eq (1, n_attrs);
+ assert (attrs[0].type == CKA_LABEL);
+ assert (attrs[0].ulValueLen == 5);
+ assert (memcmp (attrs[0].pValue, "Three", 5) == 0);
p11_kit_uri_clear_attributes (uri);
attrs = p11_kit_uri_get_attributes (uri, &n_attrs);
- CuAssertPtrNotNull (tc, attrs);
- CuAssertIntEquals (tc, 0, n_attrs);
+ assert_ptr_not_null (attrs);
+ assert_num_eq (0, n_attrs);
p11_kit_uri_free (uri);
}
static void
-test_uri_pin_source (CuTest *tc)
+test_uri_pin_source (void)
{
P11KitUri *uri;
const char *pin_source;
@@ -1153,106 +1153,93 @@ test_uri_pin_source (CuTest *tc)
int ret;
uri = p11_kit_uri_new ();
- CuAssertPtrNotNull (tc, uri);
+ assert_ptr_not_null (uri);
p11_kit_uri_set_pin_source (uri, "|my-pin-source");
pin_source = p11_kit_uri_get_pin_source (uri);
- CuAssertStrEquals (tc, "|my-pin-source", pin_source);
+ assert_str_eq ("|my-pin-source", pin_source);
pin_source = p11_kit_uri_get_pinfile (uri);
- CuAssertStrEquals (tc, "|my-pin-source", pin_source);
+ assert_str_eq ("|my-pin-source", pin_source);
p11_kit_uri_set_pinfile (uri, "|my-pin-file");
pin_source = p11_kit_uri_get_pin_source (uri);
- CuAssertStrEquals (tc, "|my-pin-file", pin_source);
+ assert_str_eq ("|my-pin-file", pin_source);
ret = p11_kit_uri_format (uri, P11_KIT_URI_FOR_ANY, &string);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
- CuAssertTrue (tc, strstr (string, "pin-source=%7cmy-pin-file") != NULL);
+ assert_num_eq (P11_KIT_URI_OK, ret);
+ assert (strstr (string, "pin-source=%7cmy-pin-file") != NULL);
free (string);
ret = p11_kit_uri_parse ("pkcs11:pin-source=blah%2Fblah", P11_KIT_URI_FOR_ANY, uri);
- CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
+ assert_num_eq (P11_KIT_URI_OK, ret);
pin_source = p11_kit_uri_get_pin_source (uri);
- CuAssertStrEquals (tc, "blah/blah", pin_source);
+ assert_str_eq ("blah/blah", pin_source);
p11_kit_uri_free (uri);
}
static void
-test_uri_free_null (CuTest *tc)
+test_uri_free_null (void)
{
p11_kit_uri_free (NULL);
}
static void
-test_uri_message (CuTest *tc)
+test_uri_message (void)
{
- CuAssertTrue (tc, p11_kit_uri_message (P11_KIT_URI_OK) == NULL);
- CuAssertPtrNotNull (tc, p11_kit_uri_message (P11_KIT_URI_UNEXPECTED));
- CuAssertPtrNotNull (tc, p11_kit_uri_message (-555555));
+ assert (p11_kit_uri_message (P11_KIT_URI_OK) == NULL);
+ assert_ptr_not_null (p11_kit_uri_message (P11_KIT_URI_UNEXPECTED));
+ assert_ptr_not_null (p11_kit_uri_message (-555555));
}
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_uri_parse);
- SUITE_ADD_TEST (suite, test_uri_parse_bad_scheme);
- SUITE_ADD_TEST (suite, test_uri_parse_with_label);
- SUITE_ADD_TEST (suite, test_uri_parse_with_label_and_klass);
- SUITE_ADD_TEST (suite, test_uri_parse_with_id);
- SUITE_ADD_TEST (suite, test_uri_parse_with_bad_string_encoding);
- SUITE_ADD_TEST (suite, test_uri_parse_with_bad_hex_encoding);
- SUITE_ADD_TEST (suite, test_uri_parse_with_token);
- SUITE_ADD_TEST (suite, test_uri_parse_with_token_bad_encoding);
- SUITE_ADD_TEST (suite, test_uri_parse_with_bad_syntax);
- SUITE_ADD_TEST (suite, test_uri_parse_with_spaces);
- SUITE_ADD_TEST (suite, test_uri_parse_with_library);
- SUITE_ADD_TEST (suite, test_uri_parse_with_library_bad_encoding);
- SUITE_ADD_TEST (suite, test_uri_build_empty);
- SUITE_ADD_TEST (suite, test_uri_build_with_token_info);
- SUITE_ADD_TEST (suite, test_uri_build_with_token_null_info);
- SUITE_ADD_TEST (suite, test_uri_build_with_token_empty_info);
- SUITE_ADD_TEST (suite, test_uri_build_with_attributes);
- SUITE_ADD_TEST (suite, test_uri_parse_private_key);
- SUITE_ADD_TEST (suite, test_uri_parse_secret_key);
- SUITE_ADD_TEST (suite, test_uri_parse_library_version);
- SUITE_ADD_TEST (suite, test_uri_parse_parse_unknown_object_type);
- SUITE_ADD_TEST (suite, test_uri_parse_unrecognized);
- SUITE_ADD_TEST (suite, test_uri_parse_too_long_is_unrecognized);
- SUITE_ADD_TEST (suite, test_uri_build_object_type_cert);
- SUITE_ADD_TEST (suite, test_uri_build_object_type_private);
- SUITE_ADD_TEST (suite, test_uri_build_object_type_public);
- SUITE_ADD_TEST (suite, test_uri_build_object_type_secret);
- SUITE_ADD_TEST (suite, test_uri_build_with_library);
- SUITE_ADD_TEST (suite, test_uri_build_library_version);
- SUITE_ADD_TEST (suite, test_uri_get_set_unrecognized);
- SUITE_ADD_TEST (suite, test_uri_match_token);
- SUITE_ADD_TEST (suite, test_uri_match_module);
- SUITE_ADD_TEST (suite, test_uri_match_version);
- SUITE_ADD_TEST (suite, test_uri_match_attributes);
- SUITE_ADD_TEST (suite, test_uri_get_set_attribute);
- SUITE_ADD_TEST (suite, test_uri_get_set_attributes);
- SUITE_ADD_TEST (suite, test_uri_pin_source);
- SUITE_ADD_TEST (suite, test_uri_free_null);
- SUITE_ADD_TEST (suite, test_uri_message);
-
- 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_uri_parse, "/uri/test_uri_parse");
+ p11_test (test_uri_parse_bad_scheme, "/uri/test_uri_parse_bad_scheme");
+ p11_test (test_uri_parse_with_label, "/uri/test_uri_parse_with_label");
+ p11_test (test_uri_parse_with_label_and_klass, "/uri/test_uri_parse_with_label_and_klass");
+ p11_test (test_uri_parse_with_id, "/uri/test_uri_parse_with_id");
+ p11_test (test_uri_parse_with_bad_string_encoding, "/uri/test_uri_parse_with_bad_string_encoding");
+ p11_test (test_uri_parse_with_bad_hex_encoding, "/uri/test_uri_parse_with_bad_hex_encoding");
+ p11_test (test_uri_parse_with_token, "/uri/test_uri_parse_with_token");
+ p11_test (test_uri_parse_with_token_bad_encoding, "/uri/test_uri_parse_with_token_bad_encoding");
+ p11_test (test_uri_parse_with_bad_syntax, "/uri/test_uri_parse_with_bad_syntax");
+ p11_test (test_uri_parse_with_spaces, "/uri/test_uri_parse_with_spaces");
+ p11_test (test_uri_parse_with_library, "/uri/test_uri_parse_with_library");
+ p11_test (test_uri_parse_with_library_bad_encoding, "/uri/test_uri_parse_with_library_bad_encoding");
+ p11_test (test_uri_build_empty, "/uri/test_uri_build_empty");
+ p11_test (test_uri_build_with_token_info, "/uri/test_uri_build_with_token_info");
+ p11_test (test_uri_build_with_token_null_info, "/uri/test_uri_build_with_token_null_info");
+ p11_test (test_uri_build_with_token_empty_info, "/uri/test_uri_build_with_token_empty_info");
+ p11_test (test_uri_build_with_attributes, "/uri/test_uri_build_with_attributes");
+ p11_test (test_uri_parse_private_key, "/uri/test_uri_parse_private_key");
+ p11_test (test_uri_parse_secret_key, "/uri/test_uri_parse_secret_key");
+ p11_test (test_uri_parse_library_version, "/uri/test_uri_parse_library_version");
+ p11_test (test_uri_parse_parse_unknown_object_type, "/uri/test_uri_parse_parse_unknown_object_type");
+ p11_test (test_uri_parse_unrecognized, "/uri/test_uri_parse_unrecognized");
+ p11_test (test_uri_parse_too_long_is_unrecognized, "/uri/test_uri_parse_too_long_is_unrecognized");
+ p11_test (test_uri_build_object_type_cert, "/uri/test_uri_build_object_type_cert");
+ p11_test (test_uri_build_object_type_private, "/uri/test_uri_build_object_type_private");
+ p11_test (test_uri_build_object_type_public, "/uri/test_uri_build_object_type_public");
+ p11_test (test_uri_build_object_type_secret, "/uri/test_uri_build_object_type_secret");
+ p11_test (test_uri_build_with_library, "/uri/test_uri_build_with_library");
+ p11_test (test_uri_build_library_version, "/uri/test_uri_build_library_version");
+ p11_test (test_uri_get_set_unrecognized, "/uri/test_uri_get_set_unrecognized");
+ p11_test (test_uri_match_token, "/uri/test_uri_match_token");
+ p11_test (test_uri_match_module, "/uri/test_uri_match_module");
+ p11_test (test_uri_match_version, "/uri/test_uri_match_version");
+ p11_test (test_uri_match_attributes, "/uri/test_uri_match_attributes");
+ p11_test (test_uri_get_set_attribute, "/uri/test_uri_get_set_attribute");
+ p11_test (test_uri_get_set_attributes, "/uri/test_uri_get_set_attributes");
+ p11_test (test_uri_pin_source, "/uri/test_uri_pin_source");
+ p11_test (test_uri_free_null, "/uri/test_uri_free_null");
+ p11_test (test_uri_message, "/uri/test_uri_message");
+
+ return p11_test_run (argc, argv);
}
diff --git a/p11-kit/tests/test-virtual.c b/p11-kit/tests/test-virtual.c
index 1482843..73777d3 100644
--- a/p11-kit/tests/test-virtual.c
+++ b/p11-kit/tests/test-virtual.c
@@ -40,7 +40,7 @@
#include "private.h"
#include "virtual.h"
-#include "CuTest.h"
+#include "test.h"
#include "mock.h"
@@ -57,7 +57,7 @@
typedef struct {
p11_virtual virt;
- CuTest *cu;
+ void *check;
} Override;
static CK_RV
@@ -66,8 +66,8 @@ override_initialize (CK_X_FUNCTION_LIST *self,
{
Override *over = (Override *)self;
- /* We're using CuTest both as closure and as C_Initialize arg */
- CuAssertPtrEquals (over->cu, over->cu, args);
+ assert_str_eq ("initialize-arg", args);
+ assert_str_eq ("overide-arg", over->check);
/* An arbitrary error code to check */
return CKR_NEED_TO_CREATE_THREADS;
@@ -84,7 +84,7 @@ test_destroyer (void *data)
}
static void
-test_initialize (CuTest *tc)
+test_initialize (void)
{
CK_FUNCTION_LIST_PTR module;
Override over = { };
@@ -92,21 +92,21 @@ test_initialize (CuTest *tc)
p11_virtual_init (&over.virt, &p11_virtual_stack, &mock_x_module_no_slots, test_destroyer);
over.virt.funcs.C_Initialize = override_initialize;
- over.cu = tc;
+ over.check = "overide-arg";
test_destroyed = false;
module = p11_virtual_wrap (&over.virt, (p11_destroyer)p11_virtual_uninit);
- CuAssertPtrNotNull (tc, module);
+ assert_ptr_not_null (module);
- rv = (module->C_Initialize) (tc);
- CuAssertIntEquals (tc, CKR_NEED_TO_CREATE_THREADS, rv);
+ rv = (module->C_Initialize) ("initialize-arg");
+ assert_num_eq (CKR_NEED_TO_CREATE_THREADS, rv);
p11_virtual_unwrap (module);
- CuAssertIntEquals (tc, true, test_destroyed);
+ assert_num_eq (true, test_destroyed);
}
static void
-test_fall_through (CuTest *tc)
+test_fall_through (void)
{
CK_FUNCTION_LIST_PTR module;
Override over = { };
@@ -116,22 +116,22 @@ test_fall_through (CuTest *tc)
p11_virtual_init (&base, &p11_virtual_base, &mock_module_no_slots, NULL);
p11_virtual_init (&over.virt, &p11_virtual_stack, &base, NULL);
over.virt.funcs.C_Initialize = override_initialize;
- over.cu = tc;
+ over.check = "overide-arg";
module = p11_virtual_wrap (&over.virt, NULL);
- CuAssertPtrNotNull (tc, module);
+ assert_ptr_not_null (module);
- rv = (module->C_Initialize) (tc);
- CuAssertIntEquals (tc, CKR_NEED_TO_CREATE_THREADS, rv);
+ rv = (module->C_Initialize) ("initialize-arg");
+ assert_num_eq (CKR_NEED_TO_CREATE_THREADS, rv);
/* All other functiosn should have just fallen through */
- CuAssertPtrEquals (tc, mock_module_no_slots.C_Finalize, module->C_Finalize);
+ assert_ptr_eq (mock_module_no_slots.C_Finalize, module->C_Finalize);
p11_virtual_unwrap (module);
}
static void
-test_get_function_list (CuTest *tc)
+test_get_function_list (void)
{
CK_FUNCTION_LIST_PTR module;
CK_FUNCTION_LIST_PTR list;
@@ -140,44 +140,32 @@ test_get_function_list (CuTest *tc)
p11_virtual_init (&virt, &p11_virtual_base, &mock_x_module_no_slots, NULL);
module = p11_virtual_wrap (&virt, NULL);
- CuAssertPtrNotNull (tc, module);
+ assert_ptr_not_null (module);
rv = (module->C_GetFunctionList) (&list);
- CuAssertIntEquals (tc, CKR_OK, rv);
- CuAssertPtrEquals (tc, module, list);
+ assert_num_eq (CKR_OK, rv);
+ assert_ptr_eq (module, list);
rv = (module->C_GetFunctionList) (&list);
- CuAssertIntEquals (tc, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
rv = (module->C_GetFunctionList) (NULL);
- CuAssertIntEquals (tc, CKR_ARGUMENTS_BAD, rv);
+ assert_num_eq (CKR_ARGUMENTS_BAD, rv);
p11_virtual_unwrap (module);
}
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_library_init ();
assert (p11_virtual_can_wrap ());
- SUITE_ADD_TEST (suite, test_initialize);
- SUITE_ADD_TEST (suite, test_fall_through);
- SUITE_ADD_TEST (suite, test_get_function_list);
-
- 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_initialize, "/virtual/test_initialize");
+ p11_test (test_fall_through, "/virtual/test_fall_through");
+ p11_test (test_get_function_list, "/virtual/test_get_function_list");
+
+ return p11_test_run (argc, argv);
}
diff --git a/tools/tests/Makefile.am b/tools/tests/Makefile.am
index f6609ec..667bf12 100644
--- a/tools/tests/Makefile.am
+++ b/tools/tests/Makefile.am
@@ -17,13 +17,13 @@ INCLUDES = \
-I$(COMMON) \
-DP11_KIT_FUTURE_UNSTABLE_API \
$(LIBTASN1_CFLAGS) \
- $(CUTEST_CFLAGS) \
+ $(TEST_CFLAGS) \
$(NULL)
LDADD = \
$(top_builddir)/p11-kit/libp11-kit.la \
$(top_builddir)/common/libp11-data.la \
- $(top_builddir)/common/libp11-mock.la \
+ $(top_builddir)/common/libp11-test.la \
$(top_builddir)/common/libp11-common.la \
$(builddir)/libtestcommon.la \
$(LIBTASN1_LIBS) \
@@ -35,7 +35,7 @@ noinst_LTLIBRARIES = \
libtestcommon.la
libtestcommon_la_SOURCES = \
- test.c test.h
+ test-tools.c test-tools.h
CHECK_PROGS = \
test-save \
diff --git a/tools/tests/test-extract.c b/tools/tests/test-extract.c
index a3db8d8..9712e81 100644
--- a/tools/tests/test-extract.c
+++ b/tools/tests/test-extract.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"
@@ -47,13 +48,12 @@
#include "pkcs11.h"
#include "pkcs11x.h"
#include "oid.h"
-#include "test.h"
#include <stdlib.h>
#include <string.h>
static void
-test_file_name_for_label (CuTest *tc)
+test_file_name_for_label (void)
{
CK_ATTRIBUTE label = { CKA_LABEL, "The Label!", 10 };
p11_extract_info ex;
@@ -64,14 +64,14 @@ test_file_name_for_label (CuTest *tc)
ex.attrs = p11_attrs_build (NULL, &label, NULL);
name = p11_extract_info_filename (&ex);
- CuAssertStrEquals (tc, "The_Label_", name);
+ assert_str_eq ("The_Label_", name);
free (name);
p11_extract_info_cleanup (&ex);
}
static void
-test_file_name_for_class (CuTest *tc)
+test_file_name_for_class (void)
{
p11_extract_info ex;
char *name;
@@ -81,20 +81,20 @@ test_file_name_for_class (CuTest *tc)
ex.klass = CKO_CERTIFICATE;
name = p11_extract_info_filename (&ex);
- CuAssertStrEquals (tc, "certificate", name);
+ assert_str_eq ("certificate", name);
free (name);
ex.klass = CKO_DATA;
name = p11_extract_info_filename (&ex);
- CuAssertStrEquals (tc, "unknown", name);
+ assert_str_eq ("unknown", name);
free (name);
p11_extract_info_cleanup (&ex);
}
static void
-test_comment_for_label (CuTest *tc)
+test_comment_for_label (void)
{
CK_ATTRIBUTE label = { CKA_LABEL, "The Label!", 10 };
p11_extract_info ex;
@@ -106,18 +106,18 @@ test_comment_for_label (CuTest *tc)
ex.attrs = p11_attrs_build (NULL, &label, NULL);
comment = p11_extract_info_comment (&ex, true);
- CuAssertStrEquals (tc, "# The Label!\n", comment);
+ assert_str_eq ("# The Label!\n", comment);
free (comment);
comment = p11_extract_info_comment (&ex, false);
- CuAssertStrEquals (tc, "\n# The Label!\n", comment);
+ assert_str_eq ("\n# The Label!\n", comment);
free (comment);
p11_extract_info_cleanup (&ex);
}
static void
-test_comment_not_enabled (CuTest *tc)
+test_comment_not_enabled (void)
{
CK_ATTRIBUTE label = { CKA_LABEL, "The Label!", 10 };
p11_extract_info ex;
@@ -128,10 +128,10 @@ test_comment_not_enabled (CuTest *tc)
ex.attrs = p11_attrs_build (NULL, &label, NULL);
comment = p11_extract_info_comment (&ex, true);
- CuAssertPtrEquals (tc, NULL, comment);
+ assert_ptr_eq (NULL, comment);
comment = p11_extract_info_comment (&ex, false);
- CuAssertPtrEquals (tc, NULL, comment);
+ assert_ptr_eq (NULL, comment);
p11_extract_info_cleanup (&ex);
}
@@ -143,7 +143,7 @@ struct {
} test;
static void
-setup (CuTest *tc)
+setup (void *unused)
{
CK_RV rv;
@@ -151,7 +151,7 @@ setup (CuTest *tc)
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);
@@ -159,7 +159,7 @@ setup (CuTest *tc)
}
static void
-teardown (CuTest *tc)
+teardown (void *unused)
{
CK_RV rv;
@@ -168,7 +168,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;
@@ -219,15 +219,13 @@ static CK_ATTRIBUTE extension_eku_invalid[] = {
};
static void
-test_info_simple_certificate (CuTest *tc)
+test_info_simple_certificate (void)
{
void *value;
size_t length;
CK_RV rv;
- setup (tc);
-
- CuAssertPtrNotNull (tc, test.ex.asn1_defs);
+ assert_ptr_not_null (test.ex.asn1_defs);
mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_trusted);
mock_module_add_object (MOCK_SLOT_ONE_ID, extension_eku_server_client);
@@ -237,55 +235,47 @@ test_info_simple_certificate (CuTest *tc)
p11_kit_iter_begin_with (test.iter, &test.module, 0, 0);
rv = p11_kit_iter_next (test.iter);
- CuAssertIntEquals (tc, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
- CuAssertIntEquals (tc, CKO_CERTIFICATE, test.ex.klass);
- CuAssertPtrNotNull (tc, test.ex.attrs);
+ assert_num_eq (CKO_CERTIFICATE, test.ex.klass);
+ assert_ptr_not_null (test.ex.attrs);
value = p11_attrs_find_value (test.ex.attrs, CKA_VALUE, &length);
- CuAssertPtrNotNull (tc, value);
- CuAssertTrue (tc, memcmp (value, test_cacert3_ca_der, length) == 0);
- CuAssertPtrNotNull (tc, test.ex.cert_der);
- CuAssertTrue (tc, memcmp (test.ex.cert_der, test_cacert3_ca_der, test.ex.cert_len) == 0);
- CuAssertPtrNotNull (tc, test.ex.cert_asn);
+ assert_ptr_not_null (value);
+ assert (memcmp (value, test_cacert3_ca_der, length) == 0);
+ assert_ptr_not_null (test.ex.cert_der);
+ assert (memcmp (test.ex.cert_der, test_cacert3_ca_der, test.ex.cert_len) == 0);
+ assert_ptr_not_null (test.ex.cert_asn);
rv = p11_kit_iter_next (test.iter);
- CuAssertIntEquals (tc, CKR_CANCEL, rv);
-
- teardown (tc);
+ assert_num_eq (CKR_CANCEL, rv);
}
static void
-test_info_limit_purposes (CuTest *tc)
+test_info_limit_purposes (void)
{
CK_RV rv;
- setup (tc);
-
mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_trusted);
mock_module_add_object (MOCK_SLOT_ONE_ID, extension_eku_server_client);
/* This should not match the above, with the stapled certificat ext */
- CuAssertPtrEquals (tc, NULL, test.ex.limit_to_purposes);
+ assert_ptr_eq (NULL, test.ex.limit_to_purposes);
p11_extract_info_limit_purpose (&test.ex, "1.1.1");
- CuAssertPtrNotNull (tc, test.ex.limit_to_purposes);
+ assert_ptr_not_null (test.ex.limit_to_purposes);
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);
rv = p11_kit_iter_next (test.iter);
- CuAssertIntEquals (tc, CKR_CANCEL, rv);
-
- teardown (tc);
+ assert_num_eq (CKR_CANCEL, rv);
}
static void
-test_info_invalid_purposes (CuTest *tc)
+test_info_invalid_purposes (void)
{
CK_RV rv;
- setup (tc);
-
mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_trusted);
mock_module_add_object (MOCK_SLOT_ONE_ID, extension_eku_invalid);
@@ -297,20 +287,16 @@ test_info_invalid_purposes (CuTest *tc)
/* No results due to invalid purpose on certificate */
rv = p11_kit_iter_next (test.iter);
- CuAssertIntEquals (tc, CKR_CANCEL, rv);
+ assert_num_eq (CKR_CANCEL, rv);
p11_kit_be_loud ();
-
- teardown (tc);
}
static void
-test_info_skip_non_certificate (CuTest *tc)
+test_info_skip_non_certificate (void)
{
CK_RV rv;
- setup (tc);
-
mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_trusted);
p11_kit_iter_add_callback (test.iter, p11_extract_info_load_filter, &test.ex, NULL);
@@ -319,25 +305,21 @@ test_info_skip_non_certificate (CuTest *tc)
p11_message_quiet ();
rv = p11_kit_iter_next (test.iter);
- CuAssertIntEquals (tc, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
- CuAssertIntEquals (tc, CKO_CERTIFICATE, test.ex.klass);
+ assert_num_eq (CKO_CERTIFICATE, test.ex.klass);
rv = p11_kit_iter_next (test.iter);
- CuAssertIntEquals (tc, CKR_CANCEL, rv);
+ assert_num_eq (CKR_CANCEL, rv);
p11_message_loud ();
-
- teardown (tc);
}
static void
-test_limit_to_purpose_match (CuTest *tc)
+test_limit_to_purpose_match (void)
{
CK_RV rv;
- setup (tc);
-
mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_trusted);
mock_module_add_object (MOCK_SLOT_ONE_ID, extension_eku_server_client);
@@ -348,20 +330,16 @@ test_limit_to_purpose_match (CuTest *tc)
p11_message_quiet ();
rv = p11_kit_iter_next (test.iter);
- CuAssertIntEquals (tc, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
p11_message_loud ();
-
- teardown (tc);
}
static void
-test_limit_to_purpose_no_match (CuTest *tc)
+test_limit_to_purpose_no_match (void)
{
CK_RV rv;
- setup (tc);
-
mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_trusted);
mock_module_add_object (MOCK_SLOT_ONE_ID, extension_eku_server_client);
@@ -372,21 +350,17 @@ test_limit_to_purpose_no_match (CuTest *tc)
p11_message_quiet ();
rv = p11_kit_iter_next (test.iter);
- CuAssertIntEquals (tc, CKR_CANCEL, rv);
+ assert_num_eq (CKR_CANCEL, rv);
p11_message_loud ();
-
- teardown (tc);
}
static void
-test_duplicate_extract (CuTest *tc)
+test_duplicate_extract (void)
{
CK_ATTRIBUTE certificate = { CKA_CLASS, &certificate_class, sizeof (certificate_class) };
CK_RV rv;
- setup (tc);
-
mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_trusted);
mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_distrusted);
@@ -395,25 +369,21 @@ test_duplicate_extract (CuTest *tc)
p11_kit_iter_begin_with (test.iter, &test.module, 0, 0);
rv = p11_kit_iter_next (test.iter);
- CuAssertIntEquals (tc, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
rv = p11_kit_iter_next (test.iter);
- CuAssertIntEquals (tc, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
rv = p11_kit_iter_next (test.iter);
- CuAssertIntEquals (tc, CKR_CANCEL, rv);
-
- teardown (tc);
+ assert_num_eq (CKR_CANCEL, rv);
}
static void
-test_duplicate_collapse (CuTest *tc)
+test_duplicate_collapse (void)
{
CK_ATTRIBUTE certificate = { CKA_CLASS, &certificate_class, sizeof (certificate_class) };
CK_RV rv;
- setup (tc);
-
mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_trusted);
mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_distrusted);
@@ -423,23 +393,19 @@ test_duplicate_collapse (CuTest *tc)
p11_kit_iter_begin_with (test.iter, &test.module, 0, 0);
rv = p11_kit_iter_next (test.iter);
- CuAssertIntEquals (tc, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
rv = p11_kit_iter_next (test.iter);
- CuAssertIntEquals (tc, CKR_CANCEL, rv);
-
- teardown (tc);
+ assert_num_eq (CKR_CANCEL, rv);
}
static void
-test_trusted_match (CuTest *tc)
+test_trusted_match (void)
{
CK_ATTRIBUTE certificate = { CKA_CLASS, &certificate_class, sizeof (certificate_class) };
CK_BBOOL boolv;
CK_RV rv;
- setup (tc);
-
mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_trusted);
mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_distrusted);
@@ -449,27 +415,23 @@ test_trusted_match (CuTest *tc)
p11_kit_iter_begin_with (test.iter, &test.module, 0, 0);
rv = p11_kit_iter_next (test.iter);
- CuAssertIntEquals (tc, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
if (!p11_attrs_find_bool (test.ex.attrs, CKA_TRUSTED, &boolv))
boolv = CK_FALSE;
- CuAssertIntEquals (tc, CK_TRUE, boolv);
+ assert_num_eq (CK_TRUE, boolv);
rv = p11_kit_iter_next (test.iter);
- CuAssertIntEquals (tc, CKR_CANCEL, rv);
-
- teardown (tc);
+ assert_num_eq (CKR_CANCEL, rv);
}
static void
-test_distrust_match (CuTest *tc)
+test_distrust_match (void)
{
CK_ATTRIBUTE certificate = { CKA_CLASS, &certificate_class, sizeof (certificate_class) };
CK_BBOOL boolv;
CK_RV rv;
- setup (tc);
-
mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_trusted);
mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_distrusted);
@@ -479,26 +441,22 @@ test_distrust_match (CuTest *tc)
p11_kit_iter_begin_with (test.iter, &test.module, 0, 0);
rv = p11_kit_iter_next (test.iter);
- CuAssertIntEquals (tc, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
if (!p11_attrs_find_bool (test.ex.attrs, CKA_X_DISTRUSTED, &boolv))
boolv = CK_FALSE;
- CuAssertIntEquals (tc, CK_TRUE, boolv);
+ assert_num_eq (CK_TRUE, boolv);
rv = p11_kit_iter_next (test.iter);
- CuAssertIntEquals (tc, CKR_CANCEL, rv);
-
- teardown (tc);
+ assert_num_eq (CKR_CANCEL, rv);
}
static void
-test_anytrust_match (CuTest *tc)
+test_anytrust_match (void)
{
CK_ATTRIBUTE certificate = { CKA_CLASS, &certificate_class, sizeof (certificate_class) };
CK_RV rv;
- setup (tc);
-
mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_trusted);
mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_distrusted);
@@ -508,51 +466,38 @@ test_anytrust_match (CuTest *tc)
p11_kit_iter_begin_with (test.iter, &test.module, 0, 0);
rv = p11_kit_iter_next (test.iter);
- CuAssertIntEquals (tc, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
rv = p11_kit_iter_next (test.iter);
- CuAssertIntEquals (tc, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
rv = p11_kit_iter_next (test.iter);
- CuAssertIntEquals (tc, CKR_CANCEL, rv);
-
- teardown (tc);
+ assert_num_eq (CKR_CANCEL, rv);
}
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_name_for_label);
- SUITE_ADD_TEST (suite, test_file_name_for_class);
- SUITE_ADD_TEST (suite, test_comment_for_label);
- SUITE_ADD_TEST (suite, test_comment_not_enabled);
- SUITE_ADD_TEST (suite, test_info_simple_certificate);
- SUITE_ADD_TEST (suite, test_info_limit_purposes);
- SUITE_ADD_TEST (suite, test_info_invalid_purposes);
- SUITE_ADD_TEST (suite, test_info_skip_non_certificate);
- SUITE_ADD_TEST (suite, test_limit_to_purpose_match);
- SUITE_ADD_TEST (suite, test_limit_to_purpose_no_match);
- SUITE_ADD_TEST (suite, test_duplicate_extract);
- SUITE_ADD_TEST (suite, test_duplicate_collapse);
- SUITE_ADD_TEST (suite, test_trusted_match);
- SUITE_ADD_TEST (suite, test_distrust_match);
- SUITE_ADD_TEST (suite, test_anytrust_match);
-
- 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_file_name_for_label, "/extract/test_file_name_for_label");
+ p11_test (test_file_name_for_class, "/extract/test_file_name_for_class");
+ p11_test (test_comment_for_label, "/extract/test_comment_for_label");
+ p11_test (test_comment_not_enabled, "/extract/test_comment_not_enabled");
+
+ p11_fixture (setup, teardown);
+ p11_test (test_info_simple_certificate, "/extract/test_info_simple_certificate");
+ p11_test (test_info_limit_purposes, "/extract/test_info_limit_purposes");
+ p11_test (test_info_invalid_purposes, "/extract/test_info_invalid_purposes");
+ p11_test (test_info_skip_non_certificate, "/extract/test_info_skip_non_certificate");
+ p11_test (test_limit_to_purpose_match, "/extract/test_limit_to_purpose_match");
+ p11_test (test_limit_to_purpose_no_match, "/extract/test_limit_to_purpose_no_match");
+ p11_test (test_duplicate_extract, "/extract/test_duplicate_extract");
+ p11_test (test_duplicate_collapse, "/extract/test_duplicate_collapse");
+ p11_test (test_trusted_match, "/extract/test_trusted_match");
+ p11_test (test_distrust_match, "/extract/test_distrust_match");
+ p11_test (test_anytrust_match, "/extract/test_anytrust_match");
+
+ return p11_test_run (argc, argv);
}
diff --git a/tools/tests/test-openssl.c b/tools/tests/test-openssl.c
index c778aa7..d393072 100644
--- a/tools/tests/test-openssl.c
+++ b/tools/tests/test-openssl.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 "buffer.h"
@@ -49,9 +50,9 @@
#include "pkcs11.h"
#include "pkcs11x.h"
#include "oid.h"
-#include "test.h"
#include <assert.h>
+#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -67,14 +68,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);
@@ -86,7 +87,7 @@ setup (CuTest *tc)
}
static void
-teardown (CuTest *tc)
+teardown (void *unused)
{
CK_RV rv;
@@ -98,7 +99,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;
@@ -162,12 +163,10 @@ setup_objects (const CK_ATTRIBUTE *attrs,
}
static void
-test_file (CuTest *tc)
+test_file (void)
{
bool ret;
- setup (tc);
-
setup_objects (cacert3_authority_attrs,
extension_eku_server,
extension_reject_email,
@@ -181,21 +180,19 @@ test_file (CuTest *tc)
assert_not_reached ();
ret = p11_extract_openssl_bundle (test.iter, &test.ex);
- CuAssertIntEquals (tc, true, ret);
+ assert_num_eq (true, ret);
- test_check_file (tc, test.directory, "extract.pem",
+ test_check_file (test.directory, "extract.pem",
SRCDIR "/files/cacert3-trusted-server-alias.pem");
free (test.ex.destination);
- teardown (tc);
}
static void
-test_plain (CuTest *tc)
+test_plain (void)
{
bool ret;
- setup (tc);
setup_objects (cacert3_authority_attrs, NULL);
p11_kit_iter_add_callback (test.iter, p11_extract_info_load_filter, &test.ex, NULL);
@@ -206,17 +203,16 @@ test_plain (CuTest *tc)
assert_not_reached ();
ret = p11_extract_openssl_bundle (test.iter, &test.ex);
- CuAssertIntEquals (tc, true, ret);
+ assert_num_eq (true, ret);
- test_check_file (tc, test.directory, "extract.pem",
+ test_check_file (test.directory, "extract.pem",
SRCDIR "/files/cacert3-trusted-alias.pem");
free (test.ex.destination);
- teardown (tc);
}
static void
-test_keyid (CuTest *tc)
+test_keyid (void)
{
bool ret;
@@ -238,7 +234,6 @@ test_keyid (CuTest *tc)
{ CKA_INVALID },
};
- setup (tc);
setup_objects (cacert3_plain, extension_subject_key_identifier, NULL);
p11_kit_iter_add_callback (test.iter, p11_extract_info_load_filter, &test.ex, NULL);
@@ -249,17 +244,16 @@ test_keyid (CuTest *tc)
assert_not_reached ();
ret = p11_extract_openssl_bundle (test.iter, &test.ex);
- CuAssertIntEquals (tc, true, ret);
+ assert_num_eq (true, ret);
- test_check_file (tc, test.directory, "extract.pem",
+ test_check_file (test.directory, "extract.pem",
SRCDIR "/files/cacert3-trusted-keyid.pem");
free (test.ex.destination);
- teardown (tc);
}
static void
-test_not_authority (CuTest *tc)
+test_not_authority (void)
{
bool ret;
@@ -271,7 +265,6 @@ test_not_authority (CuTest *tc)
{ CKA_INVALID },
};
- setup (tc);
setup_objects (cacert3_not_trusted, NULL);
p11_kit_iter_add_callback (test.iter, p11_extract_info_load_filter, &test.ex, NULL);
@@ -282,17 +275,16 @@ test_not_authority (CuTest *tc)
assert_not_reached ();
ret = p11_extract_openssl_bundle (test.iter, &test.ex);
- CuAssertIntEquals (tc, true, ret);
+ assert_num_eq (true, ret);
- test_check_file (tc, test.directory, "extract.pem",
+ test_check_file (test.directory, "extract.pem",
SRCDIR "/files/cacert3-not-trusted.pem");
free (test.ex.destination);
- teardown (tc);
}
static void
-test_distrust_all (CuTest *tc)
+test_distrust_all (void)
{
bool ret;
@@ -305,8 +297,6 @@ test_distrust_all (CuTest *tc)
{ CKA_INVALID },
};
- setup (tc);
-
setup_objects (cacert3_blacklist, NULL);
p11_kit_iter_add_callback (test.iter, p11_extract_info_load_filter, &test.ex, NULL);
@@ -317,22 +307,19 @@ test_distrust_all (CuTest *tc)
assert_not_reached ();
ret = p11_extract_openssl_bundle (test.iter, &test.ex);
- CuAssertIntEquals (tc, true, ret);
+ assert_num_eq (true, ret);
- test_check_file (tc, test.directory, "extract.pem",
+ test_check_file (test.directory, "extract.pem",
SRCDIR "/files/cacert3-distrust-all.pem");
free (test.ex.destination);
- teardown (tc);
}
static void
-test_file_multiple (CuTest *tc)
+test_file_multiple (void)
{
bool ret;
- setup (tc);
-
setup_objects (cacert3_authority_attrs,
extension_eku_server,
extension_reject_email,
@@ -349,22 +336,19 @@ test_file_multiple (CuTest *tc)
assert_not_reached ();
ret = p11_extract_openssl_bundle (test.iter, &test.ex);
- CuAssertIntEquals (tc, true, ret);
+ assert_num_eq (true, ret);
- test_check_file (tc, test.directory, "extract.pem",
+ test_check_file (test.directory, "extract.pem",
SRCDIR "/files/cacert3-trusted-multiple.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);
@@ -373,19 +357,18 @@ test_file_without (CuTest *tc)
assert_not_reached ();
ret = p11_extract_openssl_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);
}
/* From extract-openssl.c */
void p11_openssl_canon_string (char *str, size_t *len);
static void
-test_canon_string (CuTest *tc)
+test_canon_string (void)
{
struct {
char *input;
@@ -418,8 +401,8 @@ test_canon_string (CuTest *tc)
out = strlen (fixtures[i].output);
else
out = fixtures[i].output_len;
- CuAssertIntEquals (tc, out, len);
- CuAssertStrEquals (tc, fixtures[i].output, str);
+ assert_num_eq (out, len);
+ assert_str_eq (fixtures[i].output, str);
free (str);
}
@@ -428,7 +411,7 @@ test_canon_string (CuTest *tc)
bool p11_openssl_canon_string_der (p11_buffer *der);
static void
-test_canon_string_der (CuTest *tc)
+test_canon_string_der (void)
{
struct {
unsigned char input[100];
@@ -487,10 +470,10 @@ test_canon_string_der (CuTest *tc)
fixtures[i].input_len, 0, realloc, free);
ret = p11_openssl_canon_string_der (&buf);
- CuAssertIntEquals (tc, true, ret);
+ assert_num_eq (true, ret);
- CuAssertIntEquals (tc, fixtures[i].output_len, buf.len);
- CuAssertTrue (tc, memcmp (buf.data, fixtures[i].output, buf.len) == 0);
+ assert_num_eq (fixtures[i].output_len, buf.len);
+ assert (memcmp (buf.data, fixtures[i].output, buf.len) == 0);
p11_buffer_uninit (&buf);
}
@@ -500,7 +483,7 @@ bool p11_openssl_canon_name_der (p11_dict *asn1_defs,
p11_buffer *der);
static void
-test_canon_name_der (CuTest *tc)
+test_canon_name_der (void)
{
struct {
unsigned char input[100];
@@ -542,10 +525,10 @@ test_canon_name_der (CuTest *tc)
fixtures[i].input_len, 0, realloc, free);
ret = p11_openssl_canon_name_der (asn1_defs, &buf);
- CuAssertIntEquals (tc, true, ret);
+ assert_num_eq (true, ret);
- CuAssertIntEquals (tc, fixtures[i].output_len, buf.len);
- CuAssertTrue (tc, memcmp (buf.data, fixtures[i].output, buf.len) == 0);
+ assert_num_eq (fixtures[i].output_len, buf.len);
+ assert (memcmp (buf.data, fixtures[i].output, buf.len) == 0);
p11_buffer_uninit (&buf);
}
@@ -554,7 +537,7 @@ test_canon_name_der (CuTest *tc)
}
static void
-test_canon_string_der_fail (CuTest *tc)
+test_canon_string_der_fail (void)
{
struct {
unsigned char input[100];
@@ -574,19 +557,17 @@ test_canon_string_der_fail (CuTest *tc)
fixtures[i].input_len, 0, realloc, free);
ret = p11_openssl_canon_string_der (&buf);
- CuAssertIntEquals (tc, false, ret);
+ assert_num_eq (false, ret);
p11_buffer_uninit (&buf);
}
}
static void
-test_directory (CuTest *tc)
+test_directory (void)
{
bool ret;
- setup (tc);
-
setup_objects (cacert3_authority_attrs,
extension_eku_server,
extension_reject_email,
@@ -605,33 +586,30 @@ test_directory (CuTest *tc)
test.ex.destination = test.directory;
ret = p11_extract_openssl_directory (test.iter, &test.ex);
- CuAssertIntEquals (tc, true, ret);
+ assert_num_eq (true, ret);
- test_check_directory (tc, test.directory, ("Custom_Label.pem", "Custom_Label.1.pem",
+ test_check_directory (test.directory, ("Custom_Label.pem", "Custom_Label.1.pem",
#ifdef OS_UNIX
"e5662767.1", "e5662767.0", "590d426f.1", "590d426f.0",
#endif
NULL));
- test_check_file (tc, test.directory, "Custom_Label.pem",
+ test_check_file (test.directory, "Custom_Label.pem",
SRCDIR "/files/cacert3-trusted-server-alias.pem");
- test_check_file (tc, test.directory, "Custom_Label.1.pem",
+ test_check_file (test.directory, "Custom_Label.1.pem",
SRCDIR "/files/cacert3-trusted-alias.pem");
#ifdef OS_UNIX
- test_check_symlink (tc, test.directory, "e5662767.0", "Custom_Label.pem");
- test_check_symlink (tc, test.directory, "e5662767.1", "Custom_Label.1.pem");
- test_check_symlink (tc, test.directory, "590d426f.0", "Custom_Label.pem");
- test_check_symlink (tc, test.directory, "590d426f.1", "Custom_Label.1.pem");
+ test_check_symlink (test.directory, "e5662767.0", "Custom_Label.pem");
+ test_check_symlink (test.directory, "e5662767.1", "Custom_Label.1.pem");
+ test_check_symlink (test.directory, "590d426f.0", "Custom_Label.pem");
+ test_check_symlink (test.directory, "590d426f.1", "Custom_Label.1.pem");
#endif
- teardown (tc);
}
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);
@@ -642,47 +620,35 @@ test_directory_empty (CuTest *tc)
test.ex.destination = test.directory;
ret = p11_extract_openssl_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_plain);
- SUITE_ADD_TEST (suite, test_keyid);
- SUITE_ADD_TEST (suite, test_not_authority);
- SUITE_ADD_TEST (suite, test_distrust_all);
- SUITE_ADD_TEST (suite, test_file_multiple);
- SUITE_ADD_TEST (suite, test_file_without);
-
- SUITE_ADD_TEST (suite, test_canon_string);
- SUITE_ADD_TEST (suite, test_canon_string_der);
- SUITE_ADD_TEST (suite, test_canon_string_der_fail);
- SUITE_ADD_TEST (suite, test_canon_name_der);
-
- 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, "/openssl/test_file");
+ p11_test (test_plain, "/openssl/test_plain");
+ p11_test (test_keyid, "/openssl/test_keyid");
+ p11_test (test_not_authority, "/openssl/test_not_authority");
+ p11_test (test_distrust_all, "/openssl/test_distrust_all");
+ p11_test (test_file_multiple, "/openssl/test_file_multiple");
+ p11_test (test_file_without, "/openssl/test_file_without");
+
+ p11_fixture (NULL, NULL);
+ p11_test (test_canon_string, "/openssl/test_canon_string");
+ p11_test (test_canon_string_der, "/openssl/test_canon_string_der");
+ p11_test (test_canon_string_der_fail, "/openssl/test_canon_string_der_fail");
+ p11_test (test_canon_name_der, "/openssl/test_canon_name_der");
+
+ p11_fixture (setup, teardown);
+ p11_test (test_directory, "/openssl/test_directory");
+ p11_test (test_directory_empty, "/openssl/test_directory_empty");
+
+ return p11_test_run (argc, argv);
}
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);
}
diff --git a/tools/tests/test-save.c b/tools/tests/test-save.c
index b739c21..93af4f9 100644
--- a/tools/tests/test-save.c
+++ b/tools/tests/test-save.c
@@ -33,7 +33,8 @@
*/
#include "config.h"
-#include "CuTest.h"
+#include "test.h"
+#include "test-tools.h"
#include "attrs.h"
#include "compat.h"
@@ -42,7 +43,6 @@
#include "message.h"
#include "path.h"
#include "save.h"
-#include "test.h"
#include <sys/stat.h>
#include <sys/types.h>
@@ -61,24 +61,23 @@ struct {
} test;
static void
-setup (CuTest *tc)
+setup (void *unused)
{
test.directory = p11_path_expand ("$TEMP/test-extract.XXXXXX");
if (!mkdtemp (test.directory))
- CuFail (tc, "mkdtemp() failed");
+ assert_fail ("mkdtemp() failed", strerror (errno));
}
static void
-teardown (CuTest *tc)
+teardown (void *unused)
{
if (rmdir (test.directory) < 0)
- CuFail (tc, strerror (errno));
+ assert_fail ("rmdir() failed", strerror (errno));
free (test.directory);
}
static void
-write_zero_file (CuTest *tc,
- const char *directory,
+write_zero_file (const char *directory,
const char *name)
{
char *filename;
@@ -86,409 +85,365 @@ write_zero_file (CuTest *tc,
int fd;
if (asprintf (&filename, "%s/%s", directory, name) < 0)
- CuFail (tc, "asprintf() failed");
+ assert_not_reached ();
fd = open (filename, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
- CuAssertTrue (tc, fd != -1);
+ assert (fd != -1);
res = close (fd);
- CuAssertTrue (tc, res >= 0);
+ assert (res >= 0);
free (filename);
}
static void
-test_file_write (CuTest *tc)
+test_file_write (void)
{
p11_save_file *file;
char *filename;
bool ret;
- setup (tc);
-
if (asprintf (&filename, "%s/%s", test.directory, "extract-file") < 0)
- CuFail (tc, "asprintf() failed");
+ assert_not_reached ();
file = p11_save_open_file (filename, 0);
- CuAssertPtrNotNull (tc, file);
+ assert_ptr_not_null (file);
ret = p11_save_write_and_finish (file, test_cacert3_ca_der, sizeof (test_cacert3_ca_der));
- CuAssertIntEquals (tc, true, ret);
+ assert_num_eq (true, ret);
free (filename);
- test_check_file (tc, test.directory, "extract-file", SRCDIR "/files/cacert3.der");
-
- teardown (tc);
+ test_check_file (test.directory, "extract-file", SRCDIR "/files/cacert3.der");
}
static void
-test_file_exists (CuTest *tc)
+test_file_exists (void)
{
p11_save_file *file;
char *filename;
- setup (tc);
-
if (asprintf (&filename, "%s/%s", test.directory, "extract-file") < 0)
- CuFail (tc, "asprintf() failed");
+ assert_not_reached ();
- write_zero_file (tc, test.directory, "extract-file");
+ write_zero_file (test.directory, "extract-file");
p11_message_quiet ();
file = p11_save_open_file (filename, 0);
- CuAssertTrue (tc, file == NULL);
+ assert (file == NULL);
p11_message_loud ();
unlink (filename);
free (filename);
- teardown (tc);
}
static void
-test_file_bad_directory (CuTest *tc)
+test_file_bad_directory (void)
{
p11_save_file *file;
char *filename;
- setup (tc);
-
if (asprintf (&filename, "/non-existent/%s/%s", test.directory, "extract-file") < 0)
- CuFail (tc, "asprintf() failed");
+ assert_not_reached ();
p11_message_quiet ();
file = p11_save_open_file (filename, 0);
- CuAssertTrue (tc, file == NULL);
+ assert (file == NULL);
p11_message_loud ();
free (filename);
- teardown (tc);
}
static void
-test_file_overwrite (CuTest *tc)
+test_file_overwrite (void)
{
p11_save_file *file;
char *filename;
bool ret;
- setup (tc);
-
if (asprintf (&filename, "%s/%s", test.directory, "extract-file") < 0)
- CuFail (tc, "asprintf() failed");
+ assert_not_reached ();
- write_zero_file (tc, test.directory, "extract-file");
+ write_zero_file (test.directory, "extract-file");
file = p11_save_open_file (filename, P11_SAVE_OVERWRITE);
- CuAssertPtrNotNull (tc, file);
+ assert_ptr_not_null (file);
ret = p11_save_write_and_finish (file, test_cacert3_ca_der, sizeof (test_cacert3_ca_der));
- CuAssertIntEquals (tc, true, ret);
+ assert_num_eq (true, ret);
free (filename);
- test_check_file (tc, test.directory, "extract-file", SRCDIR "/files/cacert3.der");
-
- teardown (tc);
+ test_check_file (test.directory, "extract-file", SRCDIR "/files/cacert3.der");
}
static void
-test_file_auto_empty (CuTest *tc)
+test_file_auto_empty (void)
{
p11_save_file *file;
char *filename;
bool ret;
- setup (tc);
-
if (asprintf (&filename, "%s/%s", test.directory, "extract-file") < 0)
- CuFail (tc, "asprintf() failed");
+ assert_not_reached ();
file = p11_save_open_file (filename, 0);
- CuAssertPtrNotNull (tc, file);
+ assert_ptr_not_null (file);
ret = p11_save_write_and_finish (file, NULL, -1);
- CuAssertIntEquals (tc, true, ret);
+ assert_num_eq (true, ret);
free (filename);
- test_check_file (tc, test.directory, "extract-file", SRCDIR "/files/empty-file");
-
- teardown (tc);
+ test_check_file (test.directory, "extract-file", SRCDIR "/files/empty-file");
}
static void
-test_file_auto_length (CuTest *tc)
+test_file_auto_length (void)
{
p11_save_file *file;
char *filename;
bool ret;
- setup (tc);
-
if (asprintf (&filename, "%s/%s", test.directory, "extract-file") < 0)
- CuFail (tc, "asprintf() failed");
+ assert_not_reached ();
file = p11_save_open_file (filename, 0);
- CuAssertPtrNotNull (tc, file);
+ assert_ptr_not_null (file);
ret = p11_save_write_and_finish (file, "The simple string is hairy", -1);
- CuAssertIntEquals (tc, true, ret);
+ assert_num_eq (true, ret);
free (filename);
- test_check_file (tc, test.directory, "extract-file", SRCDIR "/files/simple-string");
-
- teardown (tc);
+ test_check_file (test.directory, "extract-file", SRCDIR "/files/simple-string");
}
static void
-test_write_with_null (CuTest *tc)
+test_write_with_null (void)
{
bool ret;
ret = p11_save_write (NULL, "test", 4);
- CuAssertIntEquals (tc, false, ret);
+ assert_num_eq (false, ret);
}
static void
-test_write_and_finish_with_null (CuTest *tc)
+test_write_and_finish_with_null (void)
{
bool ret;
ret = p11_save_write_and_finish (NULL, "test", 4);
- CuAssertIntEquals (tc, false, ret);
+ assert_num_eq (false, ret);
}
static void
-test_file_abort (CuTest *tc)
+test_file_abort (void)
{
struct stat st;
p11_save_file *file;
char *filename;
bool ret;
- setup (tc);
-
if (asprintf (&filename, "%s/%s", test.directory, "extract-file") < 0)
- CuFail (tc, "asprintf() failed");
+ assert_not_reached ();
file = p11_save_open_file (filename, 0);
- CuAssertPtrNotNull (tc, file);
+ assert_ptr_not_null (file);
ret = p11_save_finish_file (file, false);
- CuAssertIntEquals (tc, true, ret);
+ assert_num_eq (true, ret);
if (stat (filename, &st) >= 0 || errno != ENOENT)
- CuFail (tc, "file should not exist");
+ assert_fail ("file should not exist", filename);
free (filename);
-
- teardown (tc);
}
static void
-test_directory_empty (CuTest *tc)
+test_directory_empty (void)
{
p11_save_dir *dir;
char *subdir;
bool ret;
- setup (tc);
-
if (asprintf (&subdir, "%s/%s", test.directory, "extract-dir") < 0)
- CuFail (tc, "asprintf() failed");
+ assert_not_reached ();
dir = p11_save_open_directory (subdir, 0);
- CuAssertPtrNotNull (tc, dir);
+ assert_ptr_not_null (dir);
ret = p11_save_finish_directory (dir, true);
- CuAssertIntEquals (tc, true, ret);
+ assert_num_eq (true, ret);
- test_check_directory (tc, subdir, (NULL, NULL));
+ test_check_directory (subdir, (NULL, NULL));
- CuAssertTrue (tc, rmdir (subdir) >= 0);
+ assert (rmdir (subdir) >= 0);
free (subdir);
-
- teardown (tc);
}
static void
-test_directory_files (CuTest *tc)
+test_directory_files (void)
{
const char *filename;
p11_save_dir *dir;
char *subdir;
bool ret;
- setup (tc);
-
if (asprintf (&subdir, "%s/%s", test.directory, "extract-dir") < 0)
- CuFail (tc, "asprintf() failed");
+ assert_not_reached ();
dir = p11_save_open_directory (subdir, 0);
- CuAssertPtrNotNull (tc, dir);
+ assert_ptr_not_null (dir);
ret = p11_save_write_and_finish (p11_save_open_file_in (dir, "blah", ".cer", &filename),
test_cacert3_ca_der, sizeof (test_cacert3_ca_der));
- CuAssertIntEquals (tc, true, ret);
- CuAssertStrEquals (tc, "blah.cer", filename);
+ assert_num_eq (true, ret);
+ assert_str_eq ("blah.cer", filename);
ret = p11_save_write_and_finish (p11_save_open_file_in (dir, "file", ".txt", &filename),
test_text, strlen (test_text));
- CuAssertIntEquals (tc, true, ret);
- CuAssertStrEquals (tc, "file.txt", filename);
+ assert_num_eq (true, ret);
+ assert_str_eq ("file.txt", filename);
#ifdef OS_UNIX
ret = p11_save_symlink_in (dir, "link", ".ext", "/the/destination");
- CuAssertIntEquals (tc, true, ret);
+ assert_num_eq (true, ret);
#endif
ret = p11_save_finish_directory (dir, true);
- CuAssertIntEquals (tc, true, ret);
+ assert_num_eq (true, ret);
- test_check_directory (tc, subdir, ("blah.cer", "file.txt",
+ test_check_directory (subdir, ("blah.cer", "file.txt",
#ifdef OS_UNIX
"link.ext",
#endif
NULL));
- test_check_file (tc, subdir, "blah.cer", SRCDIR "/files/cacert3.der");
- test_check_data (tc, subdir, "file.txt", test_text, strlen (test_text));
+ test_check_file (subdir, "blah.cer", SRCDIR "/files/cacert3.der");
+ test_check_data (subdir, "file.txt", test_text, strlen (test_text));
#ifdef OS_UNIX
- test_check_symlink (tc, subdir, "link.ext", "/the/destination");
+ test_check_symlink (subdir, "link.ext", "/the/destination");
#endif
- CuAssertTrue (tc, rmdir (subdir) >= 0);
+ assert (rmdir (subdir) >= 0);
free (subdir);
-
- teardown (tc);
}
static void
-test_directory_dups (CuTest *tc)
+test_directory_dups (void)
{
const char *filename;
p11_save_dir *dir;
char *subdir;
bool ret;
- setup (tc);
-
if (asprintf (&subdir, "%s/%s", test.directory, "extract-dir") < 0)
- CuFail (tc, "asprintf() failed");
+ assert_not_reached ();
dir = p11_save_open_directory (subdir, 0);
- CuAssertPtrNotNull (tc, dir);
+ assert_ptr_not_null (dir);
ret = p11_save_write_and_finish (p11_save_open_file_in (dir, "file", ".txt", &filename),
test_text, 5);
- CuAssertIntEquals (tc, true, ret);
- CuAssertStrEquals (tc, "file.txt", filename);
+ assert_num_eq (true, ret);
+ assert_str_eq ("file.txt", filename);
ret = p11_save_write_and_finish (p11_save_open_file_in (dir, "file", ".txt", &filename),
test_text, 10);
- CuAssertIntEquals (tc, true, ret);
- CuAssertStrEquals (tc, "file.1.txt", filename);
+ assert_num_eq (true, ret);
+ assert_str_eq ("file.1.txt", filename);
ret = p11_save_write_and_finish (p11_save_open_file_in (dir, "file", ".txt", NULL),
test_text, 15);
- CuAssertIntEquals (tc, true, ret);
+ assert_num_eq (true, ret);
ret = p11_save_write_and_finish (p11_save_open_file_in (dir, "no-ext", NULL, NULL),
test_text, 8);
- CuAssertIntEquals (tc, true, ret);
+ assert_num_eq (true, ret);
ret = p11_save_write_and_finish (p11_save_open_file_in (dir, "no-ext", NULL, NULL),
test_text, 16);
- CuAssertIntEquals (tc, true, ret);
+ assert_num_eq (true, ret);
ret = p11_save_write_and_finish (p11_save_open_file_in (dir, "with-num", ".0", NULL),
test_text, 14);
- CuAssertIntEquals (tc, true, ret);
+ assert_num_eq (true, ret);
ret = p11_save_write_and_finish (p11_save_open_file_in (dir, "with-num", ".0", NULL),
test_text, 15);
- CuAssertIntEquals (tc, true, ret);
+ assert_num_eq (true, ret);
#ifdef OS_UNIX
ret = p11_save_symlink_in (dir, "link", ".0", "/destination1");
- CuAssertIntEquals (tc, true, ret);
+ assert_num_eq (true, ret);
ret = p11_save_symlink_in (dir, "link", ".0", "/destination2");
- CuAssertIntEquals (tc, true, ret);
+ assert_num_eq (true, ret);
#endif
ret = p11_save_finish_directory (dir, true);
- CuAssertIntEquals (tc, true, ret);
+ assert_num_eq (true, ret);
- test_check_directory (tc, subdir, ("file.txt", "file.1.txt", "file.2.txt",
+ test_check_directory (subdir, ("file.txt", "file.1.txt", "file.2.txt",
"no-ext", "no-ext.1",
"with-num.0", "with-num.1",
#ifdef OS_UNIX
"link.0", "link.1",
#endif
NULL));
- test_check_data (tc, subdir, "file.txt", test_text, 5);
- test_check_data (tc, subdir, "file.1.txt", test_text, 10);
- test_check_data (tc, subdir, "file.2.txt", test_text, 15);
- test_check_data (tc, subdir, "no-ext", test_text, 8);
- test_check_data (tc, subdir, "no-ext.1", test_text, 16);
- test_check_data (tc, subdir, "with-num.0", test_text, 14);
- test_check_data (tc, subdir, "with-num.1", test_text, 15);
+ test_check_data (subdir, "file.txt", test_text, 5);
+ test_check_data (subdir, "file.1.txt", test_text, 10);
+ test_check_data (subdir, "file.2.txt", test_text, 15);
+ test_check_data (subdir, "no-ext", test_text, 8);
+ test_check_data (subdir, "no-ext.1", test_text, 16);
+ test_check_data (subdir, "with-num.0", test_text, 14);
+ test_check_data (subdir, "with-num.1", test_text, 15);
#ifdef OS_UNIX
- test_check_symlink (tc, subdir, "link.0", "/destination1");
- test_check_symlink (tc, subdir, "link.1", "/destination2");
+ test_check_symlink (subdir, "link.0", "/destination1");
+ test_check_symlink (subdir, "link.1", "/destination2");
#endif
- CuAssertTrue (tc, rmdir (subdir) >= 0);
+ assert (rmdir (subdir) >= 0);
free (subdir);
-
- teardown (tc);
}
static void
-test_directory_exists (CuTest *tc)
+test_directory_exists (void)
{
p11_save_dir *dir;
char *subdir;
- setup (tc);
-
if (asprintf (&subdir, "%s/%s", test.directory, "extract-dir") < 0)
- CuFail (tc, "asprintf() failed");
+ assert_not_reached ();
#ifdef OS_UNIX
if (mkdir (subdir, S_IRWXU) < 0)
#else
if (mkdir (subdir) < 0)
#endif
- CuFail (tc, "mkdir() failed");
+ assert_fail ("mkdir() failed", subdir);
p11_message_quiet ();
dir = p11_save_open_directory (subdir, 0);
- CuAssertPtrEquals (tc, NULL, dir);
+ assert_ptr_eq (NULL, dir);
p11_message_loud ();
rmdir (subdir);
free (subdir);
-
- teardown (tc);
}
static void
-test_directory_overwrite (CuTest *tc)
+test_directory_overwrite (void)
{
const char *filename;
p11_save_dir *dir;
char *subdir;
bool ret;
- setup (tc);
-
if (asprintf (&subdir, "%s/%s", test.directory, "extract-dir") < 0)
- CuFail (tc, "asprintf() failed");
+ assert_not_reached ();
/* Some initial files into this directory, which get overwritten */
dir = p11_save_open_directory (subdir, 0);
@@ -496,74 +451,62 @@ test_directory_overwrite (CuTest *tc)
p11_save_write_and_finish (p11_save_open_file_in (dir, "another-file", NULL, NULL), "", 0) &&
p11_save_write_and_finish (p11_save_open_file_in (dir, "third-file", NULL, NULL), "", 0) &&
p11_save_finish_directory (dir, true);
- CuAssertTrue (tc, ret && dir);
+ assert (ret && dir);
/* Now the actual test, using the same directory */
dir = p11_save_open_directory (subdir, P11_SAVE_OVERWRITE);
- CuAssertPtrNotNull (tc, dir);
+ assert_ptr_not_null (dir);
ret = p11_save_write_and_finish (p11_save_open_file_in (dir, "blah", ".cer", &filename),
test_cacert3_ca_der, sizeof (test_cacert3_ca_der));
- CuAssertIntEquals (tc, true, ret);
- CuAssertStrEquals (tc, "blah.cer", filename);
+ assert_num_eq (true, ret);
+ assert_str_eq ("blah.cer", filename);
ret = p11_save_write_and_finish (p11_save_open_file_in (dir, "file", ".txt", &filename),
test_text, strlen (test_text));
- CuAssertIntEquals (tc, true, ret);
- CuAssertStrEquals (tc, "file.txt", filename);
+ assert_num_eq (true, ret);
+ assert_str_eq ("file.txt", filename);
ret = p11_save_write_and_finish (p11_save_open_file_in (dir, "file", ".txt", &filename),
test_text, 10);
- CuAssertIntEquals (tc, true, ret);
- CuAssertStrEquals (tc, "file.1.txt", filename);
+ assert_num_eq (true, ret);
+ assert_str_eq ("file.1.txt", filename);
ret = p11_save_finish_directory (dir, true);
- CuAssertIntEquals (tc, true, ret);
+ assert_num_eq (true, ret);
- test_check_directory (tc, subdir, ("blah.cer", "file.txt", "file.1.txt", NULL));
- test_check_data (tc, subdir, "blah.cer", test_cacert3_ca_der, sizeof (test_cacert3_ca_der));
- test_check_data (tc, subdir, "file.txt", test_text, strlen (test_text));
- test_check_data (tc, subdir, "file.1.txt", test_text, 10);
+ test_check_directory (subdir, ("blah.cer", "file.txt", "file.1.txt", NULL));
+ test_check_data (subdir, "blah.cer", test_cacert3_ca_der, sizeof (test_cacert3_ca_der));
+ test_check_data (subdir, "file.txt", test_text, strlen (test_text));
+ test_check_data (subdir, "file.1.txt", test_text, 10);
- CuAssertTrue (tc, rmdir (subdir) >= 0);
+ assert (rmdir (subdir) >= 0);
free (subdir);
-
- teardown (tc);
}
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_file_write);
- SUITE_ADD_TEST (suite, test_file_exists);
- SUITE_ADD_TEST (suite, test_file_bad_directory);
- SUITE_ADD_TEST (suite, test_file_overwrite);
- SUITE_ADD_TEST (suite, test_file_auto_empty);
- SUITE_ADD_TEST (suite, test_file_auto_length);
- SUITE_ADD_TEST (suite, test_write_with_null);
- SUITE_ADD_TEST (suite, test_write_and_finish_with_null);
- SUITE_ADD_TEST (suite, test_file_abort);
-
- SUITE_ADD_TEST (suite, test_directory_empty);
- SUITE_ADD_TEST (suite, test_directory_files);
- SUITE_ADD_TEST (suite, test_directory_dups);
- SUITE_ADD_TEST (suite, test_directory_exists);
- SUITE_ADD_TEST (suite, test_directory_overwrite);
-
- 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_write, "/save/test_file_write");
+ p11_test (test_file_exists, "/save/test_file_exists");
+ p11_test (test_file_bad_directory, "/save/test_file_bad_directory");
+ p11_test (test_file_overwrite, "/save/test_file_overwrite");
+ p11_test (test_file_auto_empty, "/save/test_file_auto_empty");
+ p11_test (test_file_auto_length, "/save/test_file_auto_length");
+
+ p11_fixture (NULL, NULL);
+ p11_test (test_write_with_null, "/save/test_write_with_null");
+ p11_test (test_write_and_finish_with_null, "/save/test_write_and_finish_with_null");
+
+ p11_fixture (setup, teardown);
+ p11_test (test_file_abort, "/save/test_file_abort");
+
+ p11_test (test_directory_empty, "/save/test_directory_empty");
+ p11_test (test_directory_files, "/save/test_directory_files");
+ p11_test (test_directory_dups, "/save/test_directory_dups");
+ p11_test (test_directory_exists, "/save/test_directory_exists");
+ p11_test (test_directory_overwrite, "/save/test_directory_overwrite");
+ return p11_test_run (argc, argv);
}
diff --git a/tools/tests/test.c b/tools/tests/test-tools.c
index 4ba2162..0c8b624 100644
--- a/tools/tests/test.c
+++ b/tools/tests/test-tools.c
@@ -33,24 +33,27 @@
*/
#include "config.h"
-#include "CuTest.h"
+#include "test.h"
#include "debug.h"
-#include "test.h"
+#include "test-tools.h"
#include <sys/stat.h>
#include <assert.h>
#include <dirent.h>
+#include <errno.h>
#include <fcntl.h>
+#include <stdarg.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <unistd.h>
static char *
-read_file (CuTest *tc,
- const char *file,
+read_file (const char *file,
int line,
+ const char *function,
const char *filename,
long *len)
{
@@ -60,11 +63,11 @@ read_file (CuTest *tc,
f = fopen (filename, "rb");
if (f == NULL)
- CuFail_Line (tc, file, line, "Couldn't open file", filename);
+ p11_test_fail (file, line, function, "Couldn't open file: %s", filename);
/* Figure out size */
if (stat (filename, &sb) < 0)
- CuFail_Line (tc, file, line, "Couldn't stat file", filename);
+ p11_test_fail (file, line, function, "Couldn't stat file: %s", filename);
*len = sb.st_size;
data = malloc (*len ? *len : 1);
@@ -72,7 +75,7 @@ read_file (CuTest *tc,
/* And read in one block */
if (fread (data, 1, *len, f) != *len)
- CuFail_Line (tc, file, line, "Couldn't read file", filename);
+ p11_test_fail (file, line, function, "Couldn't read file: %s", filename);
fclose (f);
@@ -80,9 +83,9 @@ read_file (CuTest *tc,
}
void
-test_check_file_msg (CuTest *tc,
- const char *file,
+test_check_file_msg (const char *file,
int line,
+ const char *function,
const char *directory,
const char *name,
const char *reference)
@@ -90,15 +93,15 @@ test_check_file_msg (CuTest *tc,
char *refdata;
long reflen;
- refdata = read_file (tc, file, line, reference, &reflen);
- test_check_data_msg (tc, file, line, directory, name, refdata, reflen);
+ refdata = read_file (file, line, function, reference, &reflen);
+ test_check_data_msg (file, line, function, directory, name, refdata, reflen);
free (refdata);
}
void
-test_check_data_msg (CuTest *tc,
- const char *file,
+test_check_data_msg (const char *file,
int line,
+ const char *function,
const char *directory,
const char *name,
const void *refdata,
@@ -109,14 +112,15 @@ test_check_data_msg (CuTest *tc,
long filelen;
if (asprintf (&filename, "%s/%s", directory, name) < 0)
- CuFail_Line (tc, file, line, "asprintf() failed", NULL);
+ assert_not_reached ();
- filedata = read_file (tc, file, line, filename, &filelen);
+ filedata = read_file (file, line, function, filename, &filelen);
if (filelen != reflen || memcmp (filedata, refdata, reflen) != 0)
- CuFail_Line (tc, file, line, "File contents not as expected", filename);
+ p11_test_fail (file, line, function, "File contents not as expected: %s", filename);
- CuAssert_Line (tc, file, line, "couldn't remove file", unlink (filename) >= 0);
+ if (unlink (filename) < 0)
+ p11_test_fail (file, line, function, "Couldn't remove file: %s", filename);
free (filename);
free (filedata);
}
@@ -124,9 +128,9 @@ test_check_data_msg (CuTest *tc,
#ifdef OS_UNIX
void
-test_check_symlink_msg (CuTest *tc,
- const char *file,
+test_check_symlink_msg (const char *file,
int line,
+ const char *function,
const char *directory,
const char *name,
const char *destination)
@@ -135,14 +139,16 @@ test_check_symlink_msg (CuTest *tc,
char *filename;
if (asprintf (&filename, "%s/%s", directory, name) < 0)
- CuFail_Line (tc, file, line, "asprintf() failed", NULL);
+ assert_not_reached ();
if (readlink (filename, buf, sizeof (buf)) < 0)
- CuFail_Line (tc, file, line, "Couldn't read symlink", filename);
+ p11_test_fail (file, line, function, "Couldn't read symlink: %s", filename);
- CuAssertStrEquals_LineMsg (tc, file, line, "symlink contents wrong", destination, buf);
+ if (strcmp (destination, buf) != 0)
+ p11_test_fail (file, line, function, "Symlink contents wrong: %s != %s", destination, buf);
- CuAssert_Line (tc, file, line, "couldn't remove symlink", unlink (filename) >= 0);
+ if (unlink (filename) < 0)
+ p11_test_fail (file, line, function, "Couldn't remove symlink: %s", filename);
free (filename);
}
@@ -171,9 +177,9 @@ test_check_directory_files (const char *file,
}
void
-test_check_directory_msg (CuTest *tc,
- const char *file,
+test_check_directory_msg (const char *file,
int line,
+ const char *function,
const char *directory,
p11_dict *files)
{
@@ -184,7 +190,7 @@ test_check_directory_msg (CuTest *tc,
dir = opendir (directory);
if (dir == NULL)
- CuFail_Line (tc, file ,line, "Couldn't open directory", directory);
+ p11_test_fail (file ,line, function, "Couldn't open directory: %s", directory);
while ((dp = readdir (dir)) != NULL) {
if (strcmp (dp->d_name, ".") == 0 ||
@@ -192,18 +198,19 @@ test_check_directory_msg (CuTest *tc,
continue;
if (!p11_dict_remove (files, dp->d_name))
- CuFail_Line (tc, file, line, "Unexpected file in directory", dp->d_name);
+ p11_test_fail (file, line, function, "Unexpected file in directory: %s", dp->d_name);
}
closedir (dir);
#ifdef OS_UNIX
- CuAssert_Line (tc, file, line, "couldn't chown directory", chmod (directory, S_IRWXU) >= 0);
+ if (chmod (directory, S_IRWXU) < 0)
+ p11_test_fail (file, line, function, "couldn't chown directory: %s: %s", directory, strerror (errno));
#endif
p11_dict_iterate (files, &iter);
while (p11_dict_next (&iter, (void **)&name, NULL))
- CuFail_Line (tc, file, line, "Couldn't find file in directory", name);
+ p11_test_fail (file, line, function, "Couldn't find file in directory: %s", name);
p11_dict_free (files);
}
diff --git a/tools/tests/test.h b/tools/tests/test-tools.h
index de2bdc1..8e66c54 100644
--- a/tools/tests/test.h
+++ b/tools/tests/test-tools.h
@@ -35,7 +35,7 @@
#ifndef TEST_COMMON_H_
#define TEST_COMMON_H_
-#include "CuTest.h"
+#include "test.h"
#include "dict.h"
@@ -205,16 +205,16 @@ static const char test_eku_none[] = {
0x30, 0x00,
};
-void test_check_file_msg (CuTest *tc,
- const char *file,
+void test_check_file_msg (const char *file,
int line,
+ const char *function,
const char *directory,
const char *filename,
const char *reference);
-void test_check_data_msg (CuTest *tc,
- const char *file,
+void test_check_data_msg (const char *file,
int line,
+ const char *function,
const char *directory,
const char *filename,
const void *refdata,
@@ -222,9 +222,9 @@ void test_check_data_msg (CuTest *tc,
#ifdef OS_UNIX
-void test_check_symlink_msg (CuTest *tc,
- const char *file,
+void test_check_symlink_msg (const char *file,
int line,
+ const char *function,
const char *directory,
const char *name,
const char *destination);
@@ -234,27 +234,27 @@ void test_check_symlink_msg (CuTest *tc,
p11_dict * test_check_directory_files (const char *file,
...) GNUC_NULL_TERMINATED;
-void test_check_directory_msg (CuTest *tc,
- const char *file,
+void test_check_directory_msg (const char *file,
int line,
+ const char *function,
const char *directory,
p11_dict *files);
-#define test_check_file(tc, directory, name, reference) \
- (test_check_file_msg (tc, __FILE__, __LINE__, directory, name, reference))
+#define test_check_file(directory, name, reference) \
+ (test_check_file_msg (__FILE__, __LINE__, __FUNCTION__, directory, name, reference))
-#define test_check_data(tc, directory, name, data, length) \
- (test_check_data_msg (tc, __FILE__, __LINE__, directory, name, data, length))
+#define test_check_data(directory, name, data, length) \
+ (test_check_data_msg (__FILE__, __LINE__, __FUNCTION__, directory, name, data, length))
#ifdef OS_UNIX
-#define test_check_symlink(tc, directory, name, destination) \
- (test_check_symlink_msg (tc, __FILE__, __LINE__, directory, name, destination))
+#define test_check_symlink(directory, name, destination) \
+ (test_check_symlink_msg (__FILE__, __LINE__, __FUNCTION__, directory, name, destination))
#endif /* OS_UNIX */
-#define test_check_directory(tc, directory, files) \
- (test_check_directory_msg (tc, __FILE__, __LINE__, directory, \
+#define test_check_directory(directory, files) \
+ (test_check_directory_msg (__FILE__, __LINE__, __FUNCTION__, directory, \
test_check_directory_files files))
#endif /* TEST_COMMON_H_ */
diff --git a/tools/tests/test-x509.c b/tools/tests/test-x509.c
index 5093743..693aaa0 100644
--- a/tools/tests/test-x509.c
+++ b/tools/tests/test-x509.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);
@@ -79,23 +79,23 @@ setup (CuTest *tc)
test.directory = p11_path_expand ("$TEMP/test-extract.XXXXXX");
if (!mkdtemp (test.directory))
- CuFail (tc, "mkdtemp() failed");
+ assert_fail ("mkdtemp() failed", test.directory);
}
static void
-teardown (CuTest *tc)
+teardown (void *unused)
{
CK_RV rv;
if (rmdir (test.directory) < 0)
- CuFail (tc, "rmdir() failed");
+ assert_fail ("rmdir() failed", test.directory);
free (test.directory);
p11_extract_info_cleanup (&test.ex);
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_x509_file (test.iter, &test.ex);
- CuAssertIntEquals (tc, true, ret);
+ assert_num_eq (true, ret);
- test_check_file (tc, test.directory, "extract.cer", SRCDIR "/files/cacert3.der");
+ test_check_file (test.directory, "extract.cer", SRCDIR "/files/cacert3.der");
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);
@@ -161,25 +156,22 @@ test_file_multiple (CuTest *tc)
p11_message_quiet ();
ret = p11_extract_x509_file (test.iter, &test.ex);
- CuAssertIntEquals (tc, true, ret);
+ assert_num_eq (true, ret);
- CuAssertTrue (tc, strstr (p11_message_last (), "multiple certificates") != NULL);
+ assert (strstr (p11_message_last (), "multiple certificates") != NULL);
p11_message_loud ();
- test_check_file (tc, test.directory, "extract.cer", SRCDIR "/files/cacert3.der");
+ test_check_file (test.directory, "extract.cer", SRCDIR "/files/cacert3.der");
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);
@@ -190,23 +182,20 @@ test_file_without (CuTest *tc)
p11_message_quiet ();
ret = p11_extract_x509_file (test.iter, &test.ex);
- CuAssertIntEquals (tc, false, ret);
+ assert_num_eq (false, ret);
- CuAssertTrue (tc, strstr (p11_message_last (), "no certificate") != NULL);
+ assert (strstr (p11_message_last (), "no certificate") != NULL);
p11_message_loud ();
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);
@@ -220,22 +209,18 @@ test_directory (CuTest *tc)
test.ex.destination = test.directory;
ret = p11_extract_x509_directory (test.iter, &test.ex);
- CuAssertIntEquals (tc, true, ret);
+ assert_num_eq (true, ret);
- test_check_directory (tc, test.directory, ("Cacert3_Here.cer", "Cacert3_Here.1.cer", NULL));
- test_check_file (tc, test.directory, "Cacert3_Here.cer", SRCDIR "/files/cacert3.der");
- test_check_file (tc, test.directory, "Cacert3_Here.1.cer", SRCDIR "/files/cacert3.der");
-
- teardown (tc);
+ test_check_directory (test.directory, ("Cacert3_Here.cer", "Cacert3_Here.1.cer", NULL));
+ test_check_file (test.directory, "Cacert3_Here.cer", SRCDIR "/files/cacert3.der");
+ test_check_file (test.directory, "Cacert3_Here.1.cer", SRCDIR "/files/cacert3.der");
}
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);
@@ -246,37 +231,22 @@ test_directory_empty (CuTest *tc)
test.ex.destination = test.directory;
ret = p11_extract_x509_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, "/x509/test_file");
+ p11_test (test_file_multiple, "/x509/test_file_multiple");
+ p11_test (test_file_without, "/x509/test_file_without");
+ p11_test (test_directory, "/x509/test_directory");
+ p11_test (test_directory_empty, "/x509/test_directory_empty");
+ return p11_test_run (argc, argv);
}
diff --git a/trust/tests/Makefile.am b/trust/tests/Makefile.am
index 90b9fb5..240bd7d 100644
--- a/trust/tests/Makefile.am
+++ b/trust/tests/Makefile.am
@@ -7,18 +7,19 @@ INCLUDES = \
-I$(top_srcdir)/common \
-DDATADIR=\"$(datadir)\" \
-DSYSCONFDIR=\"$(sysconfdir)\" \
- $(CUTEST_CFLAGS)
+ $(TEST_CFLAGS)
noinst_LTLIBRARIES = \
libtestdata.la
libtestdata_la_SOURCES = \
- test-data.c test-data.h
+ test-trust.c test-trust.h
LDADD = \
$(top_builddir)/trust/libtrust-testable.la \
$(top_builddir)/common/libp11-data.la \
$(top_builddir)/common/libp11-library.la \
+ $(top_builddir)/common/libp11-test.la \
$(top_builddir)/common/libp11-common.la \
$(builddir)/libtestdata.la \
$(LIBTASN1_LIBS) \
diff --git a/trust/tests/test-builder.c b/trust/tests/test-builder.c
index a875b96..891c722 100644
--- a/trust/tests/test-builder.c
+++ b/trust/tests/test-builder.c
@@ -33,7 +33,8 @@
*/
#include "config.h"
-#include "CuTest.h"
+#include "test.h"
+#include "test-trust.h"
#include <stdlib.h>
#include <stdio.h>
@@ -48,8 +49,6 @@
#include "oid.h"
#include "pkcs11x.h"
-#include "test-data.h"
-
struct {
p11_builder *builder;
p11_index *index;
@@ -73,17 +72,17 @@ static CK_BBOOL truev = CK_TRUE;
static CK_BBOOL falsev = CK_FALSE;
static void
-setup (CuTest *cu)
+setup (void *unused)
{
test.builder = p11_builder_new (P11_BUILDER_FLAG_TOKEN);
- CuAssertPtrNotNull (cu, test.builder);
+ assert_ptr_not_null (test.builder);
test.index = p11_index_new (p11_builder_build, p11_builder_changed, test.builder);
- CuAssertPtrNotNull (cu, test.index);
+ assert_ptr_not_null (test.index);
}
static void
-teardown (CuTest *cu)
+teardown (void *unused)
{
p11_builder_free (test.builder);
p11_index_free (test.index);
@@ -91,20 +90,16 @@ teardown (CuTest *cu)
}
static void
-test_get_cache (CuTest *cu)
+test_get_cache (void)
{
p11_asn1_cache *cache;
- setup (cu);
-
cache = p11_builder_get_cache (test.builder);
- CuAssertPtrEquals (cu, NULL, p11_asn1_cache_get (cache, "blah", (unsigned char *)"blah", 4));
-
- teardown (cu);
+ assert_ptr_eq (NULL, p11_asn1_cache_get (cache, "blah", (unsigned char *)"blah", 4));
}
static void
-test_build_data (CuTest *cu)
+test_build_data (void)
{
CK_ATTRIBUTE input[] = {
{ CKA_CLASS, &data, sizeof (data) },
@@ -128,21 +123,17 @@ test_build_data (CuTest *cu)
CK_ATTRIBUTE *merge;
CK_RV rv;
- setup (cu);
-
attrs = NULL;
merge = p11_attrs_dup (input);
rv = p11_builder_build (test.builder, test.index, &attrs, merge);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
- test_check_attrs (cu, check, attrs);
+ test_check_attrs (check, attrs);
p11_attrs_free (attrs);
-
- teardown (cu);
}
static void
-test_build_certificate (CuTest *cu)
+test_build_certificate (void)
{
CK_ATTRIBUTE input[] = {
{ CKA_CLASS, &certificate, sizeof (certificate) },
@@ -171,21 +162,17 @@ test_build_certificate (CuTest *cu)
CK_ATTRIBUTE *merge;
CK_RV rv;
- setup (cu);
-
attrs = NULL;
merge = p11_attrs_dup (input);
rv = p11_builder_build (test.builder, test.index, &attrs, merge);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
- test_check_attrs (cu, expected, attrs);
+ test_check_attrs (expected, attrs);
p11_attrs_free (attrs);
-
- teardown (cu);
}
static void
-test_build_certificate_empty (CuTest *cu)
+test_build_certificate_empty (void)
{
unsigned char checksum[P11_HASH_SHA1_LEN];
CK_ULONG domain = 0;
@@ -223,19 +210,15 @@ test_build_certificate_empty (CuTest *cu)
CK_ATTRIBUTE *merge;
CK_RV rv;
- setup (cu);
-
p11_hash_sha1 (checksum, test_cacert3_ca_der, sizeof (test_cacert3_ca_der), NULL);
attrs = NULL;
merge = p11_attrs_dup (input);
rv = p11_builder_build (test.builder, test.index, &attrs, merge);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
- test_check_attrs (cu, expected, attrs);
+ test_check_attrs (expected, attrs);
p11_attrs_free (attrs);
-
- teardown (cu);
}
static const unsigned char entrust_pretend_ca[] = {
@@ -312,7 +295,7 @@ static const unsigned char entrust_pretend_ca[] = {
};
static void
-test_build_certificate_non_ca (CuTest *cu)
+test_build_certificate_non_ca (void)
{
CK_ATTRIBUTE input[] = {
{ CKA_CLASS, &certificate, sizeof (certificate) },
@@ -329,20 +312,16 @@ test_build_certificate_non_ca (CuTest *cu)
CK_ATTRIBUTE *attrs;
CK_RV rv;
- setup (cu);
-
attrs = NULL;
rv = p11_builder_build (test.builder, test.index, &attrs, p11_attrs_dup (input));
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
- test_check_attrs (cu, expected, attrs);
+ test_check_attrs (expected, attrs);
p11_attrs_free (attrs);
-
- teardown (cu);
}
static void
-test_build_certificate_v1_ca (CuTest *cu)
+test_build_certificate_v1_ca (void)
{
CK_ATTRIBUTE input[] = {
{ CKA_CLASS, &certificate, sizeof (certificate) },
@@ -359,20 +338,16 @@ test_build_certificate_v1_ca (CuTest *cu)
CK_ATTRIBUTE *attrs;
CK_RV rv;
- setup (cu);
-
attrs = NULL;
rv = p11_builder_build (test.builder, test.index, &attrs, p11_attrs_dup (input));
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
- test_check_attrs (cu, expected, attrs);
+ test_check_attrs (expected, attrs);
p11_attrs_free (attrs);
-
- teardown (cu);
}
static void
-test_build_certificate_staple_ca (CuTest *cu)
+test_build_certificate_staple_ca (void)
{
CK_ULONG category = 2; /* CA */
@@ -400,28 +375,24 @@ test_build_certificate_staple_ca (CuTest *cu)
CK_ATTRIBUTE *attrs;
CK_RV rv;
- setup (cu);
-
/* Add a stapled certificate */
rv = p11_index_add (test.index, stapled, 4, NULL);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
attrs = NULL;
rv = p11_builder_build (test.builder, test.index, &attrs, p11_attrs_dup (input));
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
/*
* Even though the certificate is not a valid CA, the presence of the
* stapled certificate extension transforms it into a CA.
*/
- test_check_attrs (cu, expected, attrs);
+ test_check_attrs (expected, attrs);
p11_attrs_free (attrs);
-
- teardown (cu);
}
static void
-test_build_certificate_no_type (CuTest *cu)
+test_build_certificate_no_type (void)
{
CK_ATTRIBUTE input[] = {
{ CKA_CLASS, &certificate, sizeof (certificate) },
@@ -432,23 +403,19 @@ test_build_certificate_no_type (CuTest *cu)
CK_ATTRIBUTE *merge;
CK_RV rv;
- setup (cu);
-
p11_message_quiet ();
attrs = NULL;
merge = p11_attrs_dup (input);
rv = p11_builder_build (test.builder, test.index, &attrs, merge);
- CuAssertIntEquals (cu, CKR_TEMPLATE_INCOMPLETE, rv);
+ assert_num_eq (CKR_TEMPLATE_INCOMPLETE, rv);
p11_attrs_free (merge);
p11_message_loud ();
-
- teardown (cu);
}
static void
-test_build_certificate_bad_type (CuTest *cu)
+test_build_certificate_bad_type (void)
{
CK_CERTIFICATE_TYPE type = CKC_WTLS;
@@ -462,23 +429,19 @@ test_build_certificate_bad_type (CuTest *cu)
CK_ATTRIBUTE *merge;
CK_RV rv;
- setup (cu);
-
p11_message_quiet ();
attrs = NULL;
merge = p11_attrs_dup (input);
rv = p11_builder_build (test.builder, test.index, &attrs, merge);
- CuAssertIntEquals (cu, CKR_TEMPLATE_INCONSISTENT, rv);
+ assert_num_eq (CKR_TEMPLATE_INCONSISTENT, rv);
p11_attrs_free (merge);
p11_message_loud ();
-
- teardown (cu);
}
static void
-test_build_extension (CuTest *cu)
+test_build_extension (void)
{
CK_ATTRIBUTE input[] = {
{ CKA_CLASS, &certificate_extension, sizeof (certificate_extension) },
@@ -502,16 +465,12 @@ test_build_extension (CuTest *cu)
CK_ATTRIBUTE *attrs;
CK_RV rv;
- setup (cu);
-
attrs = NULL;
rv = p11_builder_build (test.builder, test.index, &attrs, p11_attrs_dup (input));
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
- test_check_attrs (cu, check, attrs);
+ test_check_attrs (check, attrs);
p11_attrs_free (attrs);
-
- teardown (cu);
}
/* This certificate has and end date in 2067 */
@@ -542,7 +501,7 @@ static const unsigned char cert_distant_end_date[] = {
};
static void
-test_build_distant_end_date (CuTest *cu)
+test_build_distant_end_date (void)
{
CK_ATTRIBUTE input[] = {
{ CKA_CLASS, &certificate, sizeof (certificate) },
@@ -560,20 +519,16 @@ test_build_distant_end_date (CuTest *cu)
CK_ATTRIBUTE *attrs;
CK_RV rv;
- setup (cu);
-
attrs = NULL;
rv = p11_builder_build (test.builder, test.index, &attrs, p11_attrs_dup (input));
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
- test_check_attrs (cu, expected, attrs);
+ test_check_attrs (expected, attrs);
p11_attrs_free (attrs);
-
- teardown (cu);
}
static void
-test_create_not_settable (CuTest *cu)
+test_create_not_settable (void)
{
/*
* CKA_TRUSTED cannot be set by the normal user according to spec
@@ -591,25 +546,21 @@ test_create_not_settable (CuTest *cu)
CK_ATTRIBUTE *merge;
CK_RV rv;
- setup (cu);
-
p11_message_quiet ();
attrs = NULL;
merge = p11_attrs_dup (input);
rv = p11_builder_build (test.builder, test.index, &attrs, merge);
- CuAssertIntEquals (cu, CKR_ATTRIBUTE_READ_ONLY, rv);
+ assert_num_eq (CKR_ATTRIBUTE_READ_ONLY, rv);
p11_attrs_free (merge);
p11_message_loud ();
p11_attrs_free (attrs);
-
- teardown (cu);
}
static void
-test_create_but_loadable (CuTest *cu)
+test_create_but_loadable (void)
{
/*
* CKA_TRUSTED cannot be set on creation, but can be set if we're
@@ -627,24 +578,20 @@ test_create_but_loadable (CuTest *cu)
CK_ATTRIBUTE *attrs;
CK_RV rv;
- setup (cu);
-
p11_index_batch (test.index);
attrs = NULL;
rv = p11_builder_build (test.builder, test.index, &attrs, p11_attrs_dup (input));
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
p11_index_finish (test.index);
- test_check_attrs (cu, input, attrs);
+ test_check_attrs (input, attrs);
p11_attrs_free (attrs);
-
- teardown (cu);
}
static void
-test_create_unsupported (CuTest *cu)
+test_create_unsupported (void)
{
CK_OBJECT_CLASS klass = CKO_PRIVATE_KEY;
@@ -657,23 +604,19 @@ test_create_unsupported (CuTest *cu)
CK_ATTRIBUTE *merge;
CK_RV rv;
- setup (cu);
-
p11_message_quiet ();
attrs = NULL;
merge = p11_attrs_dup (input);
rv = p11_builder_build (test.builder, test.index, &attrs, merge);
- CuAssertIntEquals (cu, CKR_TEMPLATE_INCONSISTENT, rv);
+ assert_num_eq (CKR_TEMPLATE_INCONSISTENT, rv);
p11_attrs_free (merge);
p11_message_loud ();
-
- teardown (cu);
}
static void
-test_create_generated (CuTest *cu)
+test_create_generated (void)
{
CK_OBJECT_CLASS klass = CKO_NSS_TRUST;
@@ -686,23 +629,19 @@ test_create_generated (CuTest *cu)
CK_ATTRIBUTE *merge;
CK_RV rv;
- setup (cu);
-
p11_message_quiet ();
attrs = NULL;
merge = p11_attrs_dup (input);
rv = p11_builder_build (test.builder, test.index, &attrs, merge);
- CuAssertIntEquals (cu, CKR_TEMPLATE_INCONSISTENT, rv);
+ assert_num_eq (CKR_TEMPLATE_INCONSISTENT, rv);
p11_attrs_free (merge);
p11_message_loud ();
-
- teardown (cu);
}
static void
-test_create_bad_attribute (CuTest *cu)
+test_create_bad_attribute (void)
{
CK_ATTRIBUTE input[] = {
{ CKA_CLASS, &data, sizeof (data) },
@@ -715,23 +654,19 @@ test_create_bad_attribute (CuTest *cu)
CK_ATTRIBUTE *merge;
CK_RV rv;
- setup (cu);
-
p11_message_quiet ();
attrs = NULL;
merge = p11_attrs_dup (input);
rv = p11_builder_build (test.builder, test.index, &attrs, merge);
- CuAssertIntEquals (cu, CKR_TEMPLATE_INCONSISTENT, rv);
+ assert_num_eq (CKR_TEMPLATE_INCONSISTENT, rv);
p11_attrs_free (merge);
p11_message_loud ();
-
- teardown (cu);
}
static void
-test_create_missing_attribute (CuTest *cu)
+test_create_missing_attribute (void)
{
CK_ATTRIBUTE input[] = {
{ CKA_CLASS, &certificate_extension, sizeof (certificate_extension) },
@@ -742,23 +677,19 @@ test_create_missing_attribute (CuTest *cu)
CK_ATTRIBUTE *merge;
CK_RV rv;
- setup (cu);
-
p11_message_quiet ();
attrs = NULL;
merge = p11_attrs_dup (input);
rv = p11_builder_build (test.builder, test.index, &attrs, merge);
- CuAssertIntEquals (cu, CKR_TEMPLATE_INCOMPLETE, rv);
+ assert_num_eq (CKR_TEMPLATE_INCOMPLETE, rv);
p11_attrs_free (merge);
p11_message_loud ();
-
- teardown (cu);
}
static void
-test_create_no_class (CuTest *cu)
+test_create_no_class (void)
{
CK_ATTRIBUTE input[] = {
{ CKA_VALUE, "the value", 9 },
@@ -769,23 +700,19 @@ test_create_no_class (CuTest *cu)
CK_ATTRIBUTE *merge;
CK_RV rv;
- setup (cu);
-
p11_message_quiet ();
attrs = NULL;
merge = p11_attrs_dup (input);
rv = p11_builder_build (test.builder, test.index, &attrs, merge);
- CuAssertIntEquals (cu, CKR_TEMPLATE_INCOMPLETE, rv);
+ assert_num_eq (CKR_TEMPLATE_INCOMPLETE, rv);
p11_attrs_free (merge);
p11_message_loud ();
-
- teardown (cu);
}
static void
-test_create_token_mismatch (CuTest *cu)
+test_create_token_mismatch (void)
{
CK_ATTRIBUTE input[] = {
{ CKA_CLASS, &data, sizeof (data) },
@@ -797,23 +724,19 @@ test_create_token_mismatch (CuTest *cu)
CK_ATTRIBUTE *merge;
CK_RV rv;
- setup (cu);
-
p11_message_quiet ();
attrs = NULL;
merge = p11_attrs_dup (input);
rv = p11_builder_build (test.builder, test.index, &attrs, merge);
- CuAssertIntEquals (cu, CKR_TEMPLATE_INCONSISTENT, rv);
+ assert_num_eq (CKR_TEMPLATE_INCONSISTENT, rv);
p11_attrs_free (merge);
p11_message_loud ();
-
- teardown (cu);
}
static void
-test_modify_success (CuTest *cu)
+test_modify_success (void)
{
CK_ATTRIBUTE input[] = {
{ CKA_CLASS, &data, sizeof (data) },
@@ -839,23 +762,19 @@ test_modify_success (CuTest *cu)
CK_ATTRIBUTE *attrs;
CK_RV rv;
- setup (cu);
-
attrs = NULL;
rv = p11_builder_build (test.builder, test.index, &attrs, p11_attrs_dup (input));
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
rv = p11_builder_build (test.builder, test.index, &attrs, p11_attrs_dup (modify));
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
- test_check_attrs (cu, expected, attrs);
+ test_check_attrs (expected, attrs);
p11_attrs_free (attrs);
-
- teardown (cu);
}
static void
-test_modify_read_only (CuTest *cu)
+test_modify_read_only (void)
{
CK_ATTRIBUTE input[] = {
{ CKA_CLASS, &data, sizeof (data) },
@@ -873,29 +792,25 @@ test_modify_read_only (CuTest *cu)
CK_ATTRIBUTE *merge;
CK_RV rv;
- setup (cu);
-
attrs = NULL;
merge = p11_attrs_dup (input);
rv = p11_builder_build (test.builder, test.index, &attrs, merge);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
p11_message_quiet ();
merge = p11_attrs_dup (modify);
rv = p11_builder_build (test.builder, test.index, &attrs, merge);
- CuAssertIntEquals (cu, CKR_ATTRIBUTE_READ_ONLY, rv);
+ assert_num_eq (CKR_ATTRIBUTE_READ_ONLY, rv);
p11_attrs_free (merge);
p11_message_loud ();
p11_attrs_free (attrs);
-
- teardown (cu);
}
static void
-test_modify_unchanged (CuTest *cu)
+test_modify_unchanged (void)
{
CK_ATTRIBUTE input[] = {
{ CKA_CLASS, &data, sizeof (data) },
@@ -924,23 +839,19 @@ test_modify_unchanged (CuTest *cu)
CK_ATTRIBUTE *attrs;
CK_RV rv;
- setup (cu);
-
attrs = NULL;
rv = p11_builder_build (test.builder, test.index, &attrs, p11_attrs_dup (input));
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
rv = p11_builder_build (test.builder, test.index, &attrs, p11_attrs_dup (modify));
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
- test_check_attrs (cu, expected, attrs);
+ test_check_attrs (expected, attrs);
p11_attrs_free (attrs);
-
- teardown (cu);
}
static void
-test_modify_not_modifiable (CuTest *cu)
+test_modify_not_modifiable (void)
{
CK_ATTRIBUTE input[] = {
{ CKA_CLASS, &data, sizeof (data) },
@@ -958,24 +869,20 @@ test_modify_not_modifiable (CuTest *cu)
CK_ATTRIBUTE *merge;
CK_RV rv;
- setup (cu);
-
attrs = NULL;
rv = p11_builder_build (test.builder, test.index, &attrs, p11_attrs_dup (input));
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
p11_message_quiet ();
merge = p11_attrs_dup (modify);
rv = p11_builder_build (test.builder, test.index, &attrs, merge);
- CuAssertIntEquals (cu, CKR_ATTRIBUTE_READ_ONLY, rv);
+ assert_num_eq (CKR_ATTRIBUTE_READ_ONLY, rv);
p11_attrs_free (merge);
p11_message_loud ();
p11_attrs_free (attrs);
-
- teardown (cu);
}
static CK_ATTRIBUTE cacert3_assert_distrust_server[] = {
@@ -1059,7 +966,7 @@ static CK_ATTRIBUTE cacert3_assert_distrust_time[] = {
};
static void
-test_changed_trusted_certificate (CuTest *cu)
+test_changed_trusted_certificate (void)
{
static CK_ATTRIBUTE cacert3_trusted_certificate[] = {
{ CKA_CLASS, &certificate, sizeof (certificate) },
@@ -1173,38 +1080,34 @@ test_changed_trusted_certificate (CuTest *cu)
CK_RV rv;
int i;
- setup (cu);
-
/*
* A trusted cetrificate, trusted for server and client purposes,
* and explicitly rejects the email and timestamping purposes.
*/
p11_index_batch (test.index);
rv = p11_index_take (test.index, p11_attrs_dup (cacert3_trusted_certificate), NULL);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
rv = p11_index_take (test.index, p11_attrs_dup (eku_extension_server_and_client), NULL);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
rv = p11_index_take (test.index, p11_attrs_dup (reject_extension_email), NULL);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
p11_index_finish (test.index);
/* The other objects */
for (i = 0; expected[i]; i++) {
handle = p11_index_find (test.index, expected[i], 2);
- CuAssertTrue (cu, handle != 0);
+ assert (handle != 0);
attrs = p11_index_lookup (test.index, handle);
- CuAssertPtrNotNull (cu, attrs);
+ assert_ptr_not_null (attrs);
- test_check_attrs (cu, expected[i], attrs);
+ test_check_attrs (expected[i], attrs);
}
-
- teardown (cu);
}
static void
-test_changed_distrust_value (CuTest *cu)
+test_changed_distrust_value (void)
{
CK_ATTRIBUTE distrust_cert[] = {
{ CKA_CLASS, &certificate, sizeof (certificate), },
@@ -1287,37 +1190,33 @@ test_changed_distrust_value (CuTest *cu)
CK_RV rv;
int i;
- setup (cu);
-
/*
* A distrusted certificate with a value, plus some extra
* extensions (which should be ignored).
*/
p11_index_batch (test.index);
rv = p11_index_take (test.index, p11_attrs_dup (distrust_cert), NULL);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
rv = p11_index_take (test.index, p11_attrs_dup (eku_extension), NULL);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
rv = p11_index_take (test.index, p11_attrs_dup (reject_extension), NULL);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
p11_index_finish (test.index);
/* The other objects */
for (i = 0; expected[i]; i++) {
handle = p11_index_find (test.index, expected[i], 2);
- CuAssertTrue (cu, handle != 0);
+ assert (handle != 0);
attrs = p11_index_lookup (test.index, handle);
- CuAssertPtrNotNull (cu, attrs);
+ assert_ptr_not_null (attrs);
- test_check_attrs (cu, expected[i], attrs);
+ test_check_attrs (expected[i], attrs);
}
-
- teardown (cu);
}
static void
-test_changed_distrust_serial (CuTest *cu)
+test_changed_distrust_serial (void)
{
CK_ATTRIBUTE distrust_cert[] = {
{ CKA_CLASS, &certificate, sizeof (certificate), },
@@ -1377,29 +1276,25 @@ test_changed_distrust_serial (CuTest *cu)
CK_RV rv;
int i;
- setup (cu);
-
/*
* A distrusted certificate without a value.
*/
p11_index_batch (test.index);
rv = p11_index_take (test.index, p11_attrs_dup (distrust_cert), NULL);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
p11_index_finish (test.index);
for (i = 0; expected[i]; i++) {
handle = p11_index_find (test.index, expected[i], 2);
- CuAssertTrue (cu, handle != 0);
+ assert (handle != 0);
attrs = p11_index_lookup (test.index, handle);
- CuAssertPtrNotNull (cu, attrs);
- test_check_attrs (cu, expected[i], attrs);
+ assert_ptr_not_null (attrs);
+ test_check_attrs (expected[i], attrs);
}
-
- teardown (cu);
}
static void
-test_changed_dup_certificates (CuTest *cu)
+test_changed_dup_certificates (void)
{
static CK_ATTRIBUTE trusted_cert[] = {
{ CKA_CLASS, &certificate, sizeof (certificate) },
@@ -1481,68 +1376,64 @@ test_changed_dup_certificates (CuTest *cu)
CK_OBJECT_HANDLE handle;
CK_RV rv;
- setup (cu);
-
/*
* A trusted certificate, should create trutsed nss trust
* and anchor assertions
*/
p11_index_batch (test.index);
rv = p11_index_take (test.index, p11_attrs_dup (trusted_cert), &handle1);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
p11_index_finish (test.index);
handle = p11_index_find (test.index, match_nss, -1);
- CuAssertTrue (cu, handle != 0);
+ assert (handle != 0);
handle = p11_index_find (test.index, match_assertion, -1);
- CuAssertTrue (cu, handle != 0);
+ assert (handle != 0);
handle = p11_index_find (test.index, trusted_nss, -1);
- CuAssertTrue (cu, handle != 0);
+ assert (handle != 0);
handle = p11_index_find (test.index, anchor_assertion, -1);
- CuAssertTrue (cu, handle != 0);
+ assert (handle != 0);
/* Now we add a distrusted certificate, should update the objects */
p11_index_batch (test.index);
rv = p11_index_take (test.index, p11_attrs_dup (distrust_cert), &handle2);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
p11_index_finish (test.index);
handle = p11_index_find (test.index, trusted_nss, -1);
- CuAssertTrue (cu, handle == 0);
+ assert (handle == 0);
handle = p11_index_find (test.index, distrust_nss, -1);
- CuAssertTrue (cu, handle != 0);
+ assert (handle != 0);
handle = p11_index_find (test.index, anchor_assertion, -1);
- CuAssertTrue (cu, handle == 0);
+ assert (handle == 0);
handle = p11_index_find (test.index, distrust_assertion, -1);
- CuAssertTrue (cu, handle != 0);
+ assert (handle != 0);
/* Now remove the trusted cetrificate, should update again */
rv = p11_index_remove (test.index, handle2);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
handle = p11_index_find (test.index, trusted_nss, -1);
- CuAssertTrue (cu, handle != 0);
+ assert (handle != 0);
handle = p11_index_find (test.index, distrust_nss, -1);
- CuAssertTrue (cu, handle == 0);
+ assert (handle == 0);
handle = p11_index_find (test.index, anchor_assertion, -1);
- CuAssertTrue (cu, handle != 0);
+ assert (handle != 0);
handle = p11_index_find (test.index, distrust_assertion, -1);
- CuAssertTrue (cu, handle == 0);
+ assert (handle == 0);
/* Now remove the original certificate, unknown nss and no assertions */
rv = p11_index_remove (test.index, handle1);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
handle = p11_index_find (test.index, unknown_nss, -1);
- CuAssertTrue (cu, handle != 0);
+ assert (handle != 0);
handle = p11_index_find (test.index, match_assertion, -1);
- CuAssertTrue (cu, handle == 0);
-
- teardown (cu);
+ assert (handle == 0);
}
static void
-test_changed_without_id (CuTest *cu)
+test_changed_without_id (void)
{
static CK_ATTRIBUTE trusted_without_id[] = {
{ CKA_CLASS, &certificate, sizeof (certificate) },
@@ -1568,26 +1459,22 @@ test_changed_without_id (CuTest *cu)
CK_OBJECT_HANDLE handle;
CK_RV rv;
- setup (cu);
-
p11_index_batch (test.index);
rv = p11_index_take (test.index, p11_attrs_dup (trusted_without_id), NULL);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
p11_index_finish (test.index);
klass = CKO_NSS_TRUST;
handle = p11_index_find (test.index, match, -1);
- CuAssertTrue (cu, handle != 0);
+ assert (handle != 0);
klass = CKO_X_TRUST_ASSERTION;
handle = p11_index_find (test.index, match, -1);
- CuAssertTrue (cu, handle != 0);
-
- teardown (cu);
+ assert (handle != 0);
}
static void
-test_changed_staple_ca (CuTest *cu)
+test_changed_staple_ca (void)
{
CK_ULONG category = 0;
@@ -1616,31 +1503,27 @@ test_changed_staple_ca (CuTest *cu)
CK_ATTRIBUTE *attrs;
CK_RV rv;
- setup (cu);
-
attrs = NULL;
rv = p11_index_take (test.index, p11_attrs_dup (input), NULL);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
/* Not a CA at this point, until we staple */
category = 0;
- CuAssertTrue (cu, p11_index_find (test.index, match, -1) == 0);
+ assert (p11_index_find (test.index, match, -1) == 0);
/* Add a stapled basic constraint */
rv = p11_index_add (test.index, stapled, 4, NULL);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
/* Now should be a CA */
category = 2;
- CuAssertTrue (cu, p11_index_find (test.index, match, -1) != 0);
+ assert (p11_index_find (test.index, match, -1) != 0);
p11_attrs_free (attrs);
-
- teardown (cu);
}
static void
-test_changed_staple_ku (CuTest *cu)
+test_changed_staple_ku (void)
{
CK_ATTRIBUTE stapled_ds_and_np[] = {
{ CKA_CLASS, &certificate_extension, sizeof (certificate_extension) },
@@ -1684,74 +1567,55 @@ test_changed_staple_ku (CuTest *cu)
CK_ATTRIBUTE *attrs;
CK_RV rv;
- setup (cu);
-
p11_index_batch (test.index);
rv = p11_index_take (test.index, p11_attrs_dup (input), NULL);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
rv = p11_index_take (test.index, p11_attrs_dup (stapled_ds_and_np), NULL);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
p11_index_finish (test.index);
handle = p11_index_find (test.index, nss_trust_ds_and_np, 2);
- CuAssertTrue (cu, handle != 0);
+ assert (handle != 0);
attrs = p11_index_lookup (test.index, handle);
- test_check_attrs (cu, nss_trust_ds_and_np, attrs);
-
- teardown (cu);
+ test_check_attrs (nss_trust_ds_and_np, attrs);
}
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_get_cache);
- SUITE_ADD_TEST (suite, test_build_data);
- SUITE_ADD_TEST (suite, test_build_certificate);
- SUITE_ADD_TEST (suite, test_build_certificate_empty);
- SUITE_ADD_TEST (suite, test_build_certificate_non_ca);
- SUITE_ADD_TEST (suite, test_build_certificate_v1_ca);
- SUITE_ADD_TEST (suite, test_build_certificate_staple_ca);
- SUITE_ADD_TEST (suite, test_build_certificate_no_type);
- SUITE_ADD_TEST (suite, test_build_certificate_bad_type);
- SUITE_ADD_TEST (suite, test_build_extension);
- SUITE_ADD_TEST (suite, test_build_distant_end_date);
- SUITE_ADD_TEST (suite, test_create_not_settable);
- SUITE_ADD_TEST (suite, test_create_but_loadable);
- SUITE_ADD_TEST (suite, test_create_unsupported);
- SUITE_ADD_TEST (suite, test_create_generated);
- SUITE_ADD_TEST (suite, test_create_bad_attribute);
- SUITE_ADD_TEST (suite, test_create_missing_attribute);
- SUITE_ADD_TEST (suite, test_create_no_class);
- SUITE_ADD_TEST (suite, test_create_token_mismatch);
- SUITE_ADD_TEST (suite, test_modify_success);
- SUITE_ADD_TEST (suite, test_modify_read_only);
- SUITE_ADD_TEST (suite, test_modify_unchanged);
- SUITE_ADD_TEST (suite, test_modify_not_modifiable);
-
- SUITE_ADD_TEST (suite, test_changed_trusted_certificate);
- SUITE_ADD_TEST (suite, test_changed_distrust_value);
- SUITE_ADD_TEST (suite, test_changed_distrust_serial);
- SUITE_ADD_TEST (suite, test_changed_without_id);
- SUITE_ADD_TEST (suite, test_changed_staple_ca);
- SUITE_ADD_TEST (suite, test_changed_staple_ku);
- SUITE_ADD_TEST (suite, test_changed_dup_certificates);
-
- 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_get_cache, "/builder/get_cache");
+ p11_test (test_build_data, "/builder/build_data");
+ p11_test (test_build_certificate, "/builder/build_certificate");
+ p11_test (test_build_certificate_empty, "/builder/build_certificate_empty");
+ p11_test (test_build_certificate_non_ca, "/builder/build_certificate_non_ca");
+ p11_test (test_build_certificate_v1_ca, "/builder/build_certificate_v1_ca");
+ p11_test (test_build_certificate_staple_ca, "/builder/build_certificate_staple_ca");
+ p11_test (test_build_certificate_no_type, "/builder/build_certificate_no_type");
+ p11_test (test_build_certificate_bad_type, "/builder/build_certificate_bad_type");
+ p11_test (test_build_extension, "/builder/build_extension");
+ p11_test (test_build_distant_end_date, "/builder/build_distant_end_date");
+ p11_test (test_create_not_settable, "/builder/create_not_settable");
+ p11_test (test_create_but_loadable, "/builder/create_but_loadable");
+ p11_test (test_create_unsupported, "/builder/create_unsupported");
+ p11_test (test_create_generated, "/builder/create_generated");
+ p11_test (test_create_bad_attribute, "/builder/create_bad_attribute");
+ p11_test (test_create_missing_attribute, "/builder/create_missing_attribute");
+ p11_test (test_create_no_class, "/builder/create_no_class");
+ p11_test (test_create_token_mismatch, "/builder/create_token_mismatch");
+ p11_test (test_modify_success, "/builder/modify_success");
+ p11_test (test_modify_read_only, "/builder/modify_read_only");
+ p11_test (test_modify_unchanged, "/builder/modify_unchanged");
+ p11_test (test_modify_not_modifiable, "/builder/modify_not_modifiable");
+
+ p11_test (test_changed_trusted_certificate, "/builder/changed_trusted_certificate");
+ p11_test (test_changed_distrust_value, "/builder/changed_distrust_value");
+ p11_test (test_changed_distrust_serial, "/builder/changed_distrust_serial");
+ p11_test (test_changed_without_id, "/builder/changed_without_id");
+ p11_test (test_changed_staple_ca, "/builder/changed_staple_ca");
+ p11_test (test_changed_staple_ku, "/builder/changed_staple_ku");
+ p11_test (test_changed_dup_certificates, "/builder/changed_dup_certificates");
+ return p11_test_run (argc, argv);
}
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);
}
diff --git a/trust/tests/test-module.c b/trust/tests/test-module.c
index 16d8037..45ec74d 100644
--- a/trust/tests/test-module.c
+++ b/trust/tests/test-module.c
@@ -32,21 +32,21 @@
* Author: Stef Walter <stefw@gnome.org>
*/
+#define CRYPTOKI_EXPORTS
+
#include "config.h"
-#include "CuTest.h"
+#include "test.h"
+#include "test-trust.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-#define CRYPTOKI_EXPORTS
-
#include "attrs.h"
#include "hash.h"
#include "library.h"
#include "path.h"
#include "pkcs11x.h"
-#include "test-data.h"
#include "token.h"
#include <assert.h>
@@ -67,7 +67,7 @@ struct {
} test;
static void
-setup (CuTest *cu)
+setup (void *unused)
{
CK_C_INITIALIZE_ARGS args;
const char *paths;
@@ -79,72 +79,68 @@ setup (CuTest *cu)
/* This is the entry point of the trust module, linked to this test */
rv = C_GetFunctionList (&test.module);
- CuAssertTrue (cu, rv == CKR_OK);
+ assert (rv == CKR_OK);
memset (&args, 0, sizeof (args));
paths = SRCDIR "/input" P11_PATH_SEP \
SRCDIR "/files/self-signed-with-ku.der" P11_PATH_SEP \
SRCDIR "/files/thawte.pem";
if (asprintf (&arguments, "paths='%s'", paths) < 0)
- CuAssertTrue (cu, false && "not reached");
+ assert (false && "not reached");
args.pReserved = arguments;
args.flags = CKF_OS_LOCKING_OK;
rv = test.module->C_Initialize (&args);
- CuAssertTrue (cu, rv == CKR_OK);
+ assert (rv == CKR_OK);
free (arguments);
count = NUM_SLOTS;
rv = test.module->C_GetSlotList (CK_TRUE, test.slots, &count);
- CuAssertTrue (cu, rv == CKR_OK);
- CuAssertTrue (cu, count == NUM_SLOTS);
+ assert (rv == CKR_OK);
+ assert (count == NUM_SLOTS);
}
static void
-teardown (CuTest *cu)
+teardown (void *unused)
{
CK_RV rv;
rv = test.module->C_Finalize (NULL);
- CuAssertTrue (cu, rv == CKR_OK);
+ assert (rv == CKR_OK);
memset (&test, 0, sizeof (test));
}
static void
-test_get_slot_list (CuTest *cu)
+test_get_slot_list (void)
{
CK_SLOT_ID slots[NUM_SLOTS];
CK_ULONG count;
CK_RV rv;
int i;
- setup (cu);
-
rv = test.module->C_GetSlotList (TRUE, NULL, &count);
- CuAssertIntEquals (cu, CKR_OK, rv);
- CuAssertIntEquals (cu, NUM_SLOTS, count);
+ assert_num_eq (CKR_OK, rv);
+ assert_num_eq (NUM_SLOTS, count);
count = 1;
rv = test.module->C_GetSlotList (TRUE, slots, &count);
- CuAssertIntEquals (cu, CKR_BUFFER_TOO_SMALL, rv);
- CuAssertIntEquals (cu, NUM_SLOTS, count);
+ assert_num_eq (CKR_BUFFER_TOO_SMALL, rv);
+ assert_num_eq (NUM_SLOTS, count);
count = NUM_SLOTS;
memset (slots, 0, sizeof (slots));
rv = test.module->C_GetSlotList (TRUE, slots, &count);
- CuAssertIntEquals (cu, CKR_OK, rv);
- CuAssertIntEquals (cu, NUM_SLOTS, count);
+ assert_num_eq (CKR_OK, rv);
+ assert_num_eq (NUM_SLOTS, count);
for (i = 0; i < NUM_SLOTS; i++)
- CuAssertTrue (cu, slots[i] != 0);
-
- teardown (cu);
+ assert (slots[i] != 0);
}
static void
-test_get_slot_info (CuTest *cu)
+test_get_slot_info (void)
{
CK_SLOT_ID slots[NUM_SLOTS];
CK_SLOT_INFO info;
@@ -161,30 +157,26 @@ test_get_slot_info (CuTest *cu)
SRCDIR "/files/thawte.pem"
};
- setup (cu);
-
count = NUM_SLOTS;
rv = test.module->C_GetSlotList (TRUE, slots, &count);
- CuAssertIntEquals (cu, CKR_OK, rv);
- CuAssertIntEquals (cu, NUM_SLOTS, count);
+ assert_num_eq (CKR_OK, rv);
+ assert_num_eq (NUM_SLOTS, count);
for (i = 0; i < NUM_SLOTS; i++) {
rv = test.module->C_GetSlotInfo (slots[i], &info);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
memset (description, ' ', sizeof (description));
length = strlen(paths[i]);
if (length > sizeof (description))
length = sizeof (description);
memcpy (description, paths[i], length);
- CuAssertTrue (cu, memcmp (info.slotDescription, description, sizeof (description)) == 0);
+ assert (memcmp (info.slotDescription, description, sizeof (description)) == 0);
}
-
- teardown (cu);
}
static void
-test_get_token_info (CuTest *cu)
+test_get_token_info (void)
{
CK_C_INITIALIZE_ARGS args;
CK_FUNCTION_LIST *module;
@@ -204,7 +196,7 @@ test_get_token_info (CuTest *cu)
/* This is the entry point of the trust module, linked to this test */
rv = C_GetFunctionList (&module);
- CuAssertTrue (cu, rv == CKR_OK);
+ assert (rv == CKR_OK);
memset (&args, 0, sizeof (args));
args.pReserved = "paths='" \
@@ -214,28 +206,28 @@ test_get_token_info (CuTest *cu)
args.flags = CKF_OS_LOCKING_OK;
rv = module->C_Initialize (&args);
- CuAssertTrue (cu, rv == CKR_OK);
+ assert (rv == CKR_OK);
count = NUM_SLOTS;
rv = module->C_GetSlotList (CK_TRUE, slots, &count);
- CuAssertTrue (cu, rv == CKR_OK);
- CuAssertTrue (cu, count == NUM_SLOTS);
+ assert (rv == CKR_OK);
+ assert (count == NUM_SLOTS);
for (i = 0; i < NUM_SLOTS; i++) {
rv = module->C_GetTokenInfo (slots[i], &info);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
memset (label, ' ', sizeof (label));
memcpy (label, labels[i], strlen (labels[i]));
- CuAssertTrue (cu, memcmp (info.label, label, sizeof (label)) == 0);
+ assert (memcmp (info.label, label, sizeof (label)) == 0);
}
rv = module->C_Finalize (NULL);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
}
static void
-test_get_session_info (CuTest *cu)
+test_get_session_info (void)
{
CK_SLOT_ID slots[NUM_SLOTS];
CK_SESSION_HANDLE sessions[NUM_SLOTS];
@@ -244,30 +236,26 @@ test_get_session_info (CuTest *cu)
CK_RV rv;
int i;
- setup (cu);
-
count = NUM_SLOTS;
rv = test.module->C_GetSlotList (TRUE, slots, &count);
- CuAssertIntEquals (cu, CKR_OK, rv);
- CuAssertIntEquals (cu, NUM_SLOTS, count);
+ assert_num_eq (CKR_OK, rv);
+ assert_num_eq (NUM_SLOTS, count);
/* Open two sessions with each token */
for (i = 0; i < NUM_SLOTS; i++) {
rv = test.module->C_OpenSession (slots[i], CKF_SERIAL_SESSION, NULL, NULL, &sessions[i]);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
rv = test.module->C_GetSessionInfo (sessions[i], &info);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
- CuAssertIntEquals (cu, slots[i], info.slotID);
- CuAssertIntEquals (cu, CKF_SERIAL_SESSION, info.flags);
+ assert_num_eq (slots[i], info.slotID);
+ assert_num_eq (CKF_SERIAL_SESSION, info.flags);
}
-
- teardown (cu);
}
static void
-test_close_all_sessions (CuTest *cu)
+test_close_all_sessions (void)
{
CK_SLOT_ID slots[NUM_SLOTS];
CK_SESSION_HANDLE sessions[NUM_SLOTS][2];
@@ -276,52 +264,47 @@ test_close_all_sessions (CuTest *cu)
CK_RV rv;
int i;
- setup (cu);
-
count = NUM_SLOTS;
rv = test.module->C_GetSlotList (TRUE, slots, &count);
- CuAssertIntEquals (cu, CKR_OK, rv);
- CuAssertIntEquals (cu, NUM_SLOTS, count);
+ assert_num_eq (CKR_OK, rv);
+ assert_num_eq (NUM_SLOTS, count);
/* Open two sessions with each token */
for (i = 0; i < NUM_SLOTS; i++) {
rv = test.module->C_OpenSession (slots[i], CKF_SERIAL_SESSION, NULL, NULL, &sessions[i][0]);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
rv = test.module->C_GetSessionInfo (sessions[i][0], &info);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
rv = test.module->C_OpenSession (slots[i], CKF_SERIAL_SESSION, NULL, NULL, &sessions[i][1]);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
rv = test.module->C_GetSessionInfo (sessions[i][0], &info);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
}
/* Close all the sessions on the first token */
rv = test.module->C_CloseAllSessions (slots[0]);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
/* Those sessions should be closed */
rv = test.module->C_GetSessionInfo (sessions[0][0], &info);
- CuAssertIntEquals (cu, CKR_SESSION_HANDLE_INVALID, rv);
+ assert_num_eq (CKR_SESSION_HANDLE_INVALID, rv);
rv = test.module->C_GetSessionInfo (sessions[0][1], &info);
- CuAssertIntEquals (cu, CKR_SESSION_HANDLE_INVALID, rv);
+ assert_num_eq (CKR_SESSION_HANDLE_INVALID, rv);
/* Other sessions should still be open */
for (i = 1; i < NUM_SLOTS; i++) {
rv = test.module->C_GetSessionInfo (sessions[i][0], &info);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
rv = test.module->C_GetSessionInfo (sessions[i][0], &info);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
}
-
- teardown (cu);
}
static CK_ULONG
-find_objects (CuTest *cu,
- CK_ATTRIBUTE *match,
+find_objects (CK_ATTRIBUTE *match,
CK_OBJECT_HANDLE *sessions,
CK_OBJECT_HANDLE *objects,
CK_ULONG max_objects)
@@ -335,14 +318,14 @@ find_objects (CuTest *cu,
found = 0;
for (i = 0; i < NUM_SLOTS; i++) {
rv = test.module->C_OpenSession (test.slots[i], CKF_SERIAL_SESSION, NULL, NULL, &session);
- CuAssertTrue (cu, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = test.module->C_FindObjectsInit (session, match, p11_attrs_count (match));
- CuAssertTrue (cu, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = test.module->C_FindObjects (session, objects + found, max_objects - found, &count);
- CuAssertTrue (cu, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = test.module->C_FindObjectsFinal (session);
- CuAssertTrue (cu, rv == CKR_OK);
+ assert (rv == CKR_OK);
for (j = found ; j < found + count; j++)
sessions[j] = session;
@@ -354,8 +337,7 @@ find_objects (CuTest *cu,
}
static void
-check_trust_object_equiv (CuTest *cu,
- CK_SESSION_HANDLE session,
+check_trust_object_equiv (CK_SESSION_HANDLE session,
CK_OBJECT_HANDLE trust,
CK_ATTRIBUTE *cert)
{
@@ -379,14 +361,13 @@ check_trust_object_equiv (CuTest *cu,
};
rv = test.module->C_GetAttributeValue (session, trust, equiv, 6);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
- test_check_attrs (cu, equiv, cert);
+ test_check_attrs (equiv, cert);
}
static void
-check_trust_object_hashes (CuTest *cu,
- CK_SESSION_HANDLE session,
+check_trust_object_hashes (CK_SESSION_HANDLE session,
CK_OBJECT_HANDLE trust,
CK_ATTRIBUTE *cert)
{
@@ -403,21 +384,20 @@ check_trust_object_hashes (CuTest *cu,
};
rv = test.module->C_GetAttributeValue (session, trust, hashes, 2);
- CuAssertTrue (cu, rv == CKR_OK);
+ assert (rv == CKR_OK);
value = p11_attrs_find_valid (cert, CKA_VALUE);
- CuAssertPtrNotNull (cu, value);
+ assert_ptr_not_null (value);
p11_hash_md5 (check, value->pValue, value->ulValueLen, NULL);
- CuAssertTrue (cu, memcmp (md5, check, sizeof (md5)) == 0);
+ assert (memcmp (md5, check, sizeof (md5)) == 0);
p11_hash_sha1 (check, value->pValue, value->ulValueLen, NULL);
- CuAssertTrue (cu, memcmp (sha1, check, sizeof (sha1)) == 0);
+ assert (memcmp (sha1, check, sizeof (sha1)) == 0);
}
static void
-check_has_trust_object (CuTest *cu,
- CK_ATTRIBUTE *cert)
+check_has_trust_object (CK_ATTRIBUTE *cert)
{
CK_OBJECT_CLASS trust_object = CKO_NSS_TRUST;
CK_ATTRIBUTE klass = { CKA_CLASS, &trust_object, sizeof (trust_object) };
@@ -428,21 +408,20 @@ check_has_trust_object (CuTest *cu,
CK_ULONG count;
attr = p11_attrs_find_valid (cert, CKA_ID);
- CuAssertPtrNotNull (cu, attr);
+ assert_ptr_not_null (attr);
match = p11_attrs_build (NULL, &klass, attr, NULL);
- count = find_objects (cu, match, sessions, objects, 2);
- CuAssertIntEquals (cu, 1, count);
+ count = find_objects (match, sessions, objects, 2);
+ assert_num_eq (1, count);
- check_trust_object_equiv (cu, sessions[0], objects[0], cert);
- check_trust_object_hashes (cu, sessions[0], objects[0], cert);
+ check_trust_object_equiv (sessions[0], objects[0], cert);
+ check_trust_object_hashes (sessions[0], objects[0], cert);
p11_attrs_free (match);
}
static void
-check_certificate (CuTest *cu,
- CK_SESSION_HANDLE session,
+check_certificate (CK_SESSION_HANDLE session,
CK_OBJECT_HANDLE handle)
{
unsigned char label[4096]= { 0, };
@@ -483,7 +462,7 @@ check_certificate (CuTest *cu,
/* Note that we don't pass the CKA_INVALID attribute in */
rv = test.module->C_GetAttributeValue (session, handle, attrs, 15);
- CuAssertTrue (cu, rv == CKR_OK);
+ assert (rv == CKR_OK);
/* If this is the cacert3 certificate, check its values */
if (memcmp (value, test_cacert3_ca_der, sizeof (test_cacert3_ca_der)) == 0) {
@@ -500,25 +479,25 @@ check_certificate (CuTest *cu,
{ CKA_INVALID, },
};
- test_check_cacert3_ca (cu, attrs, NULL);
+ test_check_cacert3_ca (attrs, NULL);
/* Get anchor specific attributes */
rv = test.module->C_GetAttributeValue (session, handle, anchor, 1);
- CuAssertTrue (cu, rv == CKR_OK);
+ assert (rv == CKR_OK);
/* It lives in the trusted directory */
- test_check_attrs (cu, check, anchor);
+ test_check_attrs (check, anchor);
/* Other certificates, we can't check the values */
} else {
- test_check_object (cu, attrs, CKO_CERTIFICATE, NULL);
+ test_check_object (attrs, CKO_CERTIFICATE, NULL);
}
- check_has_trust_object (cu, attrs);
+ check_has_trust_object (attrs);
}
static void
-test_find_certificates (CuTest *cu)
+test_find_certificates (void)
{
CK_OBJECT_CLASS klass = CKO_CERTIFICATE;
@@ -532,19 +511,15 @@ test_find_certificates (CuTest *cu)
CK_ULONG count;
CK_ULONG i;
- setup (cu);
-
- count = find_objects (cu, match, sessions, objects, 16);
- CuAssertIntEquals (cu, 8, count);
+ count = find_objects (match, sessions, objects, 16);
+ assert_num_eq (8, count);
for (i = 0; i < count; i++)
- check_certificate (cu, sessions[i], objects[i]);
-
- teardown (cu);
+ check_certificate (sessions[i], objects[i]);
}
static void
-test_find_builtin (CuTest *cu)
+test_find_builtin (void)
{
CK_OBJECT_CLASS klass = CKO_NSS_BUILTIN_ROOT_LIST;
CK_BBOOL vtrue = CK_TRUE;
@@ -562,17 +537,13 @@ test_find_builtin (CuTest *cu)
CK_SESSION_HANDLE sessions[16];
CK_ULONG count;
- setup (cu);
-
/* One per token */
- count = find_objects (cu, match, sessions, objects, 16);
- CuAssertIntEquals (cu, NUM_SLOTS, count);
-
- teardown (cu);
+ count = find_objects (match, sessions, objects, 16);
+ assert_num_eq (NUM_SLOTS, count);
}
static void
-test_session_object (CuTest *cu)
+test_session_object (void)
{
CK_ATTRIBUTE original[] = {
{ CKA_CLASS, &data, sizeof (data) },
@@ -586,22 +557,18 @@ test_session_object (CuTest *cu)
CK_ULONG size;
CK_RV rv;
- setup (cu);
-
rv = test.module->C_OpenSession (test.slots[0], CKF_SERIAL_SESSION, NULL, NULL, &session);
- CuAssertTrue (cu, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = test.module->C_CreateObject (session, original, 2, &handle);
- CuAssertTrue (cu, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = test.module->C_GetObjectSize (session, handle, &size);
- CuAssertTrue (cu, rv == CKR_OK);
-
- teardown (cu);
+ assert (rv == CKR_OK);
}
static void
-test_session_find (CuTest *cu)
+test_session_find (void)
{
CK_ATTRIBUTE original[] = {
{ CKA_CLASS, &data, sizeof (data) },
@@ -616,30 +583,26 @@ test_session_find (CuTest *cu)
CK_ULONG count;
CK_RV rv;
- setup (cu);
-
rv = test.module->C_OpenSession (test.slots[0], CKF_SERIAL_SESSION, NULL, NULL, &session);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
rv = test.module->C_CreateObject (session, original, 2, &handle);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
rv = test.module->C_FindObjectsInit (session, original, 2);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
rv = test.module->C_FindObjects (session, &check, 1, &count);
- CuAssertIntEquals (cu, CKR_OK, rv);
- CuAssertIntEquals (cu, 1, count);
- CuAssertIntEquals (cu, handle, check);
+ assert_num_eq (CKR_OK, rv);
+ assert_num_eq (1, count);
+ assert_num_eq (handle, check);
rv = test.module->C_FindObjectsFinal (session);
- CuAssertIntEquals (cu, CKR_OK, rv);
-
- teardown (cu);
+ assert_num_eq (CKR_OK, rv);
}
static void
-test_session_find_no_attr (CuTest *cu)
+test_session_find_no_attr (void)
{
CK_ATTRIBUTE original[] = {
{ CKA_CLASS, &data, sizeof (data) },
@@ -659,71 +622,59 @@ test_session_find_no_attr (CuTest *cu)
CK_ULONG count;
CK_RV rv;
- setup (cu);
-
rv = test.module->C_OpenSession (test.slots[0], CKF_SERIAL_SESSION, NULL, NULL, &session);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
rv = test.module->C_CreateObject (session, original, 3, &handle);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
rv = test.module->C_FindObjectsInit (session, match, 1);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
rv = test.module->C_FindObjects (session, &check, 1, &count);
- CuAssertIntEquals (cu, CKR_OK, rv);
- CuAssertIntEquals (cu, 0, count);
+ assert_num_eq (CKR_OK, rv);
+ assert_num_eq (0, count);
rv = test.module->C_FindObjectsFinal (session);
- CuAssertIntEquals (cu, CKR_OK, rv);
-
- teardown (cu);
+ assert_num_eq (CKR_OK, rv);
}
static void
-test_lookup_invalid (CuTest *cu)
+test_lookup_invalid (void)
{
CK_SESSION_HANDLE session;
CK_ULONG size;
CK_RV rv;
- setup (cu);
-
rv = test.module->C_OpenSession (test.slots[0], CKF_SERIAL_SESSION, NULL, NULL, &session);
- CuAssertTrue (cu, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = test.module->C_GetObjectSize (session, 88888, &size);
- CuAssertTrue (cu, rv == CKR_OBJECT_HANDLE_INVALID);
-
- teardown (cu);
+ assert (rv == CKR_OBJECT_HANDLE_INVALID);
}
static void
-test_remove_token (CuTest *cu)
+test_remove_token (void)
{
CK_SESSION_HANDLE session;
CK_OBJECT_HANDLE handle;
CK_ULONG count;
CK_RV rv;
- setup (cu);
-
rv = test.module->C_OpenSession (test.slots[0], CKF_SERIAL_SESSION, NULL, NULL, &session);
- CuAssertTrue (cu, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = test.module->C_FindObjectsInit (session, NULL, 0);
- CuAssertTrue (cu, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = test.module->C_FindObjects (session, &handle, 1, &count);
- CuAssertTrue (cu, rv == CKR_OK);
- CuAssertIntEquals (cu, 1, count);
+ assert (rv == CKR_OK);
+ assert_num_eq (1, count);
rv = test.module->C_DestroyObject (session, handle);
- CuAssertTrue (cu, rv == CKR_TOKEN_WRITE_PROTECTED);
-
- teardown (cu);
+ assert (rv == CKR_TOKEN_WRITE_PROTECTED);
}
static void
-test_setattr_token (CuTest *cu)
+test_setattr_token (void)
{
CK_ATTRIBUTE original[] = {
{ CKA_CLASS, &data, sizeof (data) },
@@ -737,26 +688,22 @@ test_setattr_token (CuTest *cu)
CK_ULONG count;
CK_RV rv;
- setup (cu);
-
rv = test.module->C_OpenSession (test.slots[0], CKF_SERIAL_SESSION, NULL, NULL, &session);
- CuAssertTrue (cu, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = test.module->C_FindObjectsInit (session, NULL, 0);
- CuAssertTrue (cu, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = test.module->C_FindObjects (session, &handle, 1, &count);
- CuAssertTrue (cu, rv == CKR_OK);
- CuAssertIntEquals (cu, 1, count);
+ assert (rv == CKR_OK);
+ assert_num_eq (1, count);
rv = test.module->C_SetAttributeValue (session, handle, original, 2);
- CuAssertTrue (cu, rv == CKR_TOKEN_WRITE_PROTECTED);
-
- teardown (cu);
+ assert (rv == CKR_TOKEN_WRITE_PROTECTED);
}
static void
-test_session_copy (CuTest *cu)
+test_session_copy (void)
{
CK_ATTRIBUTE original[] = {
{ CKA_CLASS, &data, sizeof (data) },
@@ -771,25 +718,21 @@ test_session_copy (CuTest *cu)
CK_ULONG size;
CK_RV rv;
- setup (cu);
-
rv = test.module->C_OpenSession (test.slots[0], CKF_SERIAL_SESSION, NULL, NULL, &session);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
rv = test.module->C_CreateObject (session, original, 2, &handle);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
rv = test.module->C_CopyObject (session, handle, original, 2, &copy);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
rv = test.module->C_GetObjectSize (session, copy, &size);
- CuAssertIntEquals (cu, CKR_OK, rv);
-
- teardown (cu);
+ assert_num_eq (CKR_OK, rv);
}
static void
-test_session_setattr (CuTest *cu)
+test_session_setattr (void)
{
CK_ATTRIBUTE original[] = {
{ CKA_CLASS, &data, sizeof (data) },
@@ -802,22 +745,18 @@ test_session_setattr (CuTest *cu)
CK_OBJECT_HANDLE handle;
CK_RV rv;
- setup (cu);
-
rv = test.module->C_OpenSession (test.slots[0], CKF_SERIAL_SESSION, NULL, NULL, &session);
- CuAssertTrue (cu, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = test.module->C_CreateObject (session, original, 2, &handle);
- CuAssertTrue (cu, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = test.module->C_SetAttributeValue (session, handle, original, 2);
- CuAssertTrue (cu, rv == CKR_OK);
-
- teardown (cu);
+ assert (rv == CKR_OK);
}
static void
-test_session_remove (CuTest *cu)
+test_session_remove (void)
{
CK_ATTRIBUTE original[] = {
{ CKA_CLASS, &data, sizeof (data) },
@@ -830,25 +769,21 @@ test_session_remove (CuTest *cu)
CK_OBJECT_HANDLE handle;
CK_RV rv;
- setup (cu);
-
rv = test.module->C_OpenSession (test.slots[0], CKF_SERIAL_SESSION, NULL, NULL, &session);
- CuAssertTrue (cu, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = test.module->C_CreateObject (session, original, 2, &handle);
- CuAssertTrue (cu, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = test.module->C_DestroyObject (session, handle);
- CuAssertTrue (cu, rv == CKR_OK);
+ assert (rv == CKR_OK);
rv = test.module->C_DestroyObject (session, handle);
- CuAssertTrue (cu, rv == CKR_OBJECT_HANDLE_INVALID);
-
- teardown (cu);
+ assert (rv == CKR_OBJECT_HANDLE_INVALID);
}
static void
-test_find_serial_der_decoded (CuTest *cu)
+test_find_serial_der_decoded (void)
{
CK_OBJECT_CLASS nss_trust = CKO_NSS_TRUST;
@@ -881,39 +816,35 @@ test_find_serial_der_decoded (CuTest *cu)
* See work_around_broken_nss_serial_number_lookups().
*/
- setup (cu);
-
rv = test.module->C_OpenSession (test.slots[0], CKF_SERIAL_SESSION, NULL, NULL, &session);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
rv = test.module->C_CreateObject (session, object, 2, &handle);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
/* Do a standard find for the same object */
rv = test.module->C_FindObjectsInit (session, object, 2);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
rv = test.module->C_FindObjects (session, &check, 1, &count);
- CuAssertIntEquals (cu, CKR_OK, rv);
- CuAssertIntEquals (cu, 1, count);
- CuAssertIntEquals (cu, handle, check);
+ assert_num_eq (CKR_OK, rv);
+ assert_num_eq (1, count);
+ assert_num_eq (handle, check);
rv = test.module->C_FindObjectsFinal (session);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
/* Do a find for the serial number decoded */
rv = test.module->C_FindObjectsInit (session, match_decoded, 2);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
rv = test.module->C_FindObjects (session, &check, 1, &count);
- CuAssertIntEquals (cu, CKR_OK, rv);
- CuAssertIntEquals (cu, 1, count);
- CuAssertIntEquals (cu, handle, check);
+ assert_num_eq (CKR_OK, rv);
+ assert_num_eq (1, count);
+ assert_num_eq (handle, check);
rv = test.module->C_FindObjectsFinal (session);
- CuAssertIntEquals (cu, CKR_OK, rv);
-
- teardown (cu);
+ assert_num_eq (CKR_OK, rv);
}
static void
-test_find_serial_der_mismatch (CuTest *cu)
+test_find_serial_der_mismatch (void)
{
CK_OBJECT_CLASS nss_trust = CKO_NSS_TRUST;
@@ -935,107 +866,92 @@ test_find_serial_der_mismatch (CuTest *cu)
CK_ULONG count;
CK_RV rv;
- setup (cu);
-
rv = test.module->C_OpenSession (test.slots[0], CKF_SERIAL_SESSION, NULL, NULL, &session);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
rv = test.module->C_CreateObject (session, object, 2, &handle);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
/* Do a find with a null serial number, no match */
rv = test.module->C_FindObjectsInit (session, match, 2);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
rv = test.module->C_FindObjects (session, &check, 1, &count);
- CuAssertIntEquals (cu, CKR_OK, rv);
- CuAssertIntEquals (cu, 0, count);
+ assert_num_eq (CKR_OK, rv);
+ assert_num_eq (0, count);
rv = test.module->C_FindObjectsFinal (session);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
/* Do a find with a wrong length, no match */
match[0].pValue = "at";
match[0].ulValueLen = 2;
rv = test.module->C_FindObjectsInit (session, match, 2);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
rv = test.module->C_FindObjects (session, &check, 1, &count);
- CuAssertIntEquals (cu, CKR_OK, rv);
- CuAssertIntEquals (cu, 0, count);
+ assert_num_eq (CKR_OK, rv);
+ assert_num_eq (0, count);
rv = test.module->C_FindObjectsFinal (session);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
/* Do a find with a right length, wrong value, no match */
match[0].pValue = "one";
match[0].ulValueLen = 3;
rv = test.module->C_FindObjectsInit (session, match, 2);
- CuAssertIntEquals (cu, CKR_OK, rv);
+ assert_num_eq (CKR_OK, rv);
rv = test.module->C_FindObjects (session, &check, 1, &count);
- CuAssertIntEquals (cu, CKR_OK, rv);
- CuAssertIntEquals (cu, 0, count);
+ assert_num_eq (CKR_OK, rv);
+ assert_num_eq (0, count);
rv = test.module->C_FindObjectsFinal (session);
- CuAssertIntEquals (cu, CKR_OK, rv);
-
- teardown (cu);
+ assert_num_eq (CKR_OK, rv);
}
static void
-test_login_logout (CuTest *cu)
+test_login_logout (void)
{
CK_SESSION_HANDLE session;
CK_RV rv;
- setup (cu);
-
rv = test.module->C_OpenSession (test.slots[0], CKF_SERIAL_SESSION, NULL, NULL, &session);
- CuAssertTrue (cu, rv == CKR_OK);
+ assert (rv == CKR_OK);
/* Just testing our stubs for now */
rv = test.module->C_Login (session, CKU_USER, NULL, 0);
- CuAssertTrue (cu, rv == CKR_USER_TYPE_INVALID);
+ assert (rv == CKR_USER_TYPE_INVALID);
rv = test.module->C_Logout (session);
- CuAssertTrue (cu, rv == CKR_USER_NOT_LOGGED_IN);
-
- teardown (cu);
+ assert (rv == CKR_USER_NOT_LOGGED_IN);
}
int
-main (void)
+main (int argc,
+ char *argv[])
{
- CuString *output = CuStringNew ();
- CuSuite* suite = CuSuiteNew ();
- int ret;
-
- putenv ("P11_KIT_STRICT=1");
p11_library_init ();
- SUITE_ADD_TEST (suite, test_get_slot_list);
- SUITE_ADD_TEST (suite, test_get_slot_info);
- SUITE_ADD_TEST (suite, test_get_token_info);
- SUITE_ADD_TEST (suite, test_get_session_info);
- SUITE_ADD_TEST (suite, test_close_all_sessions);
- SUITE_ADD_TEST (suite, test_find_certificates);
- SUITE_ADD_TEST (suite, test_find_builtin);
- SUITE_ADD_TEST (suite, test_lookup_invalid);
- SUITE_ADD_TEST (suite, test_remove_token);
- SUITE_ADD_TEST (suite, test_setattr_token);
- SUITE_ADD_TEST (suite, test_session_object);
- SUITE_ADD_TEST (suite, test_session_find);
- SUITE_ADD_TEST (suite, test_session_find_no_attr);
- SUITE_ADD_TEST (suite, test_session_copy);
- SUITE_ADD_TEST (suite, test_session_remove);
- SUITE_ADD_TEST (suite, test_session_setattr);
- SUITE_ADD_TEST (suite, test_find_serial_der_decoded);
- SUITE_ADD_TEST (suite, test_find_serial_der_mismatch);
- SUITE_ADD_TEST (suite, test_login_logout);
-
- 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_get_slot_list, "/module/get_slot_list");
+ p11_test (test_get_slot_info, "/module/get_slot_info");
+
+ p11_fixture (NULL, NULL);
+ p11_test (test_get_token_info, "/module/get_token_info");
+
+ p11_fixture (setup, teardown);
+ p11_test (test_get_session_info, "/module/get_session_info");
+ p11_test (test_close_all_sessions, "/module/close_all_sessions");
+ p11_test (test_find_certificates, "/module/find_certificates");
+ p11_test (test_find_builtin, "/module/find_builtin");
+ p11_test (test_lookup_invalid, "/module/lookup_invalid");
+ p11_test (test_remove_token, "/module/remove_token");
+ p11_test (test_setattr_token, "/module/setattr_token");
+ p11_test (test_session_object, "/module/session_object");
+ p11_test (test_session_find, "/module/session_find");
+ p11_test (test_session_find_no_attr, "/module/session_find_no_attr");
+ p11_test (test_session_copy, "/module/session_copy");
+ p11_test (test_session_remove, "/module/session_remove");
+ p11_test (test_session_setattr, "/module/session_setattr");
+ p11_test (test_find_serial_der_decoded, "/module/find_serial_der_decoded");
+ p11_test (test_find_serial_der_mismatch, "/module/find_serial_der_mismatch");
+ p11_test (test_login_logout, "/module/login_logout");
+
+ return p11_test_run (argc, argv);
}
diff --git a/trust/tests/test-parser.c b/trust/tests/test-parser.c
index 147823a..2b60254 100644
--- a/trust/tests/test-parser.c
+++ b/trust/tests/test-parser.c
@@ -33,7 +33,8 @@
*/
#include "config.h"
-#include "CuTest.h"
+#include "test.h"
+#include "test-trust.h"
#include <stdlib.h>
#include <stdio.h>
@@ -47,7 +48,6 @@
#include "oid.h"
#include "parser.h"
#include "pkcs11x.h"
-#include "test-data.h"
struct {
p11_parser *parser;
@@ -56,16 +56,16 @@ struct {
} test;
static void
-setup (CuTest *cu)
+setup (void *unused)
{
test.index = p11_index_new (NULL, NULL, NULL);
test.cache = p11_asn1_cache_new ();
test.parser = p11_parser_new (test.index, test.cache);
- CuAssertPtrNotNull (cu, test.parser);
+ assert_ptr_not_null (test.parser);
}
static void
-teardown (CuTest *cu)
+teardown (void *unused)
{
p11_parser_free (test.parser);
p11_index_free (test.index);
@@ -94,7 +94,7 @@ parsed_attrs (CK_ATTRIBUTE *match)
}
static void
-test_parse_der_certificate (CuTest *cu)
+test_parse_der_certificate (void)
{
CK_ATTRIBUTE *cert;
int ret;
@@ -109,23 +109,19 @@ test_parse_der_certificate (CuTest *cu)
{ CKA_INVALID },
};
- setup (cu);
-
ret = p11_parse_file (test.parser, SRCDIR "/files/cacert3.der",
P11_PARSE_FLAG_NONE);
- CuAssertIntEquals (cu, P11_PARSE_SUCCESS, ret);
+ assert_num_eq (P11_PARSE_SUCCESS, ret);
/* Should have gotten certificate */
- CuAssertIntEquals (cu, 1, p11_index_size (test.index));
+ assert_num_eq (1, p11_index_size (test.index));
cert = parsed_attrs (certificate_match);
- test_check_attrs (cu, expected, cert);
-
- teardown (cu);
+ test_check_attrs (expected, cert);
}
static void
-test_parse_pem_certificate (CuTest *cu)
+test_parse_pem_certificate (void)
{
CK_ATTRIBUTE *cert;
int ret;
@@ -140,23 +136,19 @@ test_parse_pem_certificate (CuTest *cu)
{ CKA_INVALID },
};
- setup (cu);
-
ret = p11_parse_file (test.parser, SRCDIR "/files/cacert3.pem",
P11_PARSE_FLAG_NONE);
- CuAssertIntEquals (cu, P11_PARSE_SUCCESS, ret);
+ assert_num_eq (P11_PARSE_SUCCESS, ret);
/* Should have gotten certificate */
- CuAssertIntEquals (cu, 1, p11_index_size (test.index));
+ assert_num_eq (1, p11_index_size (test.index));
cert = parsed_attrs (certificate_match);
- test_check_attrs (cu, expected, cert);
-
- teardown (cu);
+ test_check_attrs (expected, cert);
}
static void
-test_parse_p11_kit_persist (CuTest *cu)
+test_parse_p11_kit_persist (void)
{
CK_ATTRIBUTE *cert;
int ret;
@@ -171,23 +163,19 @@ test_parse_p11_kit_persist (CuTest *cu)
{ CKA_INVALID },
};
- setup (cu);
-
ret = p11_parse_file (test.parser, SRCDIR "/input/verisign-v1.p11-kit",
P11_PARSE_FLAG_NONE);
- CuAssertIntEquals (cu, P11_PARSE_SUCCESS, ret);
+ assert_num_eq (P11_PARSE_SUCCESS, ret);
/* Should have gotten certificate */
- CuAssertIntEquals (cu, 1, p11_index_size (test.index));
+ assert_num_eq (1, p11_index_size (test.index));
cert = parsed_attrs (certificate_match);
- test_check_attrs (cu, expected, cert);
-
- teardown (cu);
+ test_check_attrs (expected, cert);
}
static void
-test_parse_openssl_trusted (CuTest *cu)
+test_parse_openssl_trusted (void)
{
CK_ATTRIBUTE cacert3[] = {
{ CKA_CERTIFICATE_TYPE, &x509, sizeof (x509) },
@@ -228,40 +216,36 @@ test_parse_openssl_trusted (CuTest *cu)
int ret;
int i;
- setup (cu);
-
ret = p11_parse_file (test.parser, SRCDIR "/files/cacert3-trusted.pem",
P11_PARSE_FLAG_ANCHOR);
- CuAssertIntEquals (cu, P11_PARSE_SUCCESS, ret);
+ assert_num_eq (P11_PARSE_SUCCESS, ret);
/*
* Should have gotten:
* - 1 certificate
* - 2 stapled extensions
*/
- CuAssertIntEquals (cu, 3, p11_index_size (test.index));
+ assert_num_eq (3, p11_index_size (test.index));
/* The certificate */
cert = parsed_attrs (certificate_match);
- test_check_attrs (cu, expected[0], cert);
+ test_check_attrs (expected[0], cert);
/* The other objects */
for (i = 1; expected[i]; i++) {
handle = p11_index_find (test.index, expected[i], 2);
- CuAssertTrue (cu, handle != 0);
+ assert (handle != 0);
object = p11_index_lookup (test.index, handle);
- CuAssertPtrNotNull (cu, object);
+ assert_ptr_not_null (object);
- test_check_attrs (cu, expected[i], object);
- test_check_id (cu, cert, object);
+ test_check_attrs (expected[i], object);
+ test_check_id (cert, object);
}
-
- teardown (cu);
}
static void
-test_parse_openssl_distrusted (CuTest *cu)
+test_parse_openssl_distrusted (void)
{
CK_ATTRIBUTE distrust_cert[] = {
{ CKA_CLASS, &certificate, sizeof (certificate), },
@@ -301,42 +285,38 @@ test_parse_openssl_distrusted (CuTest *cu)
int ret;
int i;
- setup (cu);
-
/*
* OpenSSL style is to litter the blacklist in with the anchors,
* so we parse this as an anchor, but expect it to be blacklisted
*/
ret = p11_parse_file (test.parser, SRCDIR "/files/distrusted.pem",
P11_PARSE_FLAG_ANCHOR);
- CuAssertIntEquals (cu, P11_PARSE_SUCCESS, ret);
+ assert_num_eq (P11_PARSE_SUCCESS, ret);
/*
* Should have gotten:
* - 1 certificate
* - 2 stapled extensions
*/
- CuAssertIntEquals (cu, 3, p11_index_size (test.index));
+ assert_num_eq (3, p11_index_size (test.index));
cert = parsed_attrs (certificate_match);
- test_check_attrs (cu, expected[0], cert);
+ test_check_attrs (expected[0], cert);
/* The other objects */
for (i = 1; expected[i]; i++) {
handle = p11_index_find (test.index, expected[i], 2);
- CuAssertTrue (cu, handle != 0);
+ assert (handle != 0);
object = p11_index_lookup (test.index, handle);
- CuAssertPtrNotNull (cu, object);
+ assert_ptr_not_null (object);
- test_check_attrs (cu, expected[i], object);
- test_check_id (cu, cert, object);
+ test_check_attrs (expected[i], object);
+ test_check_id (cert, object);
}
-
- teardown (cu);
}
static void
-test_parse_anchor (CuTest *cu)
+test_parse_anchor (void)
{
CK_ATTRIBUTE cacert3[] = {
{ CKA_CERTIFICATE_TYPE, &x509, sizeof (x509) },
@@ -351,26 +331,22 @@ test_parse_anchor (CuTest *cu)
CK_ATTRIBUTE *cert;
int ret;
- setup (cu);
-
ret = p11_parse_file (test.parser, SRCDIR "/files/cacert3.der",
P11_PARSE_FLAG_ANCHOR);
- CuAssertIntEquals (cu, P11_PARSE_SUCCESS, ret);
+ assert_num_eq (P11_PARSE_SUCCESS, ret);
/*
* Should have gotten:
* - 1 certificate
*/
- CuAssertIntEquals (cu, 1, p11_index_size (test.index));
+ assert_num_eq (1, p11_index_size (test.index));
cert = parsed_attrs (certificate_match);
- test_check_attrs (cu, cacert3, cert);
-
- teardown (cu);
+ test_check_attrs (cacert3, cert);
}
static void
-test_parse_thawte (CuTest *cu)
+test_parse_thawte (void)
{
CK_ATTRIBUTE *cert;
int ret;
@@ -384,61 +360,49 @@ test_parse_thawte (CuTest *cu)
{ CKA_INVALID },
};
- setup (cu);
-
ret = p11_parse_file (test.parser, SRCDIR "/files/thawte.pem",
P11_PARSE_FLAG_NONE);
- CuAssertIntEquals (cu, P11_PARSE_SUCCESS, ret);
+ assert_num_eq (P11_PARSE_SUCCESS, ret);
/* Should have gotten certificate */
- CuAssertIntEquals (cu, 1, p11_index_size (test.index));
+ assert_num_eq (1, p11_index_size (test.index));
cert = parsed_attrs (certificate_match);
- test_check_attrs (cu, expected, cert);
-
- teardown (cu);
+ test_check_attrs (expected, cert);
}
/* TODO: A certificate that uses generalTime needs testing */
static void
-test_parse_invalid_file (CuTest *cu)
+test_parse_invalid_file (void)
{
int ret;
- setup (cu);
-
p11_message_quiet ();
ret = p11_parse_file (test.parser, "/nonexistant",
P11_PARSE_FLAG_NONE);
- CuAssertIntEquals (cu, P11_PARSE_FAILURE, ret);
+ assert_num_eq (P11_PARSE_FAILURE, ret);
p11_message_loud ();
-
- teardown (cu);
}
static void
-test_parse_unrecognized (CuTest *cu)
+test_parse_unrecognized (void)
{
int ret;
- setup (cu);
-
p11_message_quiet ();
ret = p11_parse_file (test.parser, SRCDIR "/files/unrecognized-file.txt",
P11_PARSE_FLAG_NONE);
- CuAssertIntEquals (cu, P11_PARSE_UNRECOGNIZED, ret);
+ assert_num_eq (P11_PARSE_UNRECOGNIZED, ret);
p11_message_loud ();
-
- teardown (cu);
}
static void
-test_duplicate (CuTest *cu)
+test_duplicate (void)
{
CK_ATTRIBUTE cacert3[] = {
{ CKA_CLASS, &certificate, sizeof (certificate) },
@@ -454,36 +418,33 @@ test_duplicate (CuTest *cu)
CK_ATTRIBUTE *cert;
int ret;
- setup (cu);
-
ret = p11_parse_file (test.parser, SRCDIR "/files/cacert3.der", 0);
- CuAssertIntEquals (cu, P11_PARSE_SUCCESS, ret);
+ assert_num_eq (P11_PARSE_SUCCESS, ret);
p11_message_quiet ();
/* This shouldn't be added, should print a message */
ret = p11_parse_file (test.parser, SRCDIR "/files/cacert3.der", 0);
- CuAssertIntEquals (cu, P11_PARSE_SUCCESS, ret);
+ assert_num_eq (P11_PARSE_SUCCESS, ret);
- CuAssertTrue (cu, strstr (p11_message_last (), "duplicate") != NULL);
+ assert (strstr (p11_message_last (), "duplicate") != NULL);
p11_message_loud ();
/* Should only be one certificate since the above two are identical */
handles = p11_index_find_all (test.index, cacert3, 2);
- CuAssertPtrNotNull (cu, handles);
- CuAssertTrue (cu, handles[0] != 0);
- CuAssertTrue (cu, handles[1] == 0);
+ assert_ptr_not_null (handles);
+ assert (handles[0] != 0);
+ assert (handles[1] == 0);
cert = p11_index_lookup (test.index, handles[0]);
- test_check_attrs (cu, cacert3, cert);
+ test_check_attrs (cacert3, cert);
free (handles);
- teardown (cu);
}
static void
-test_duplicate_priority (CuTest *cu)
+test_duplicate_priority (void)
{
CK_ATTRIBUTE cacert3[] = {
{ CKA_CLASS, &certificate, sizeof (certificate) },
@@ -515,29 +476,27 @@ test_duplicate_priority (CuTest *cu)
CK_ATTRIBUTE *cert;
int ret;
- setup (cu);
-
ret = p11_parse_file (test.parser, SRCDIR "/files/cacert3.der", 0);
- CuAssertIntEquals (cu, P11_PARSE_SUCCESS, ret);
+ assert_num_eq (P11_PARSE_SUCCESS, ret);
p11_message_quiet ();
/* This shouldn't be added, should print a message */
ret = p11_parse_file (test.parser, SRCDIR "/files/cacert3.der",
P11_PARSE_FLAG_ANCHOR);
- CuAssertIntEquals (cu, P11_PARSE_SUCCESS, ret);
+ assert_num_eq (P11_PARSE_SUCCESS, ret);
- CuAssertTrue (cu, strstr (p11_message_last (), "duplicate") != NULL);
+ assert (strstr (p11_message_last (), "duplicate") != NULL);
p11_message_loud ();
/* We should now find the trusted certificate */
handles = p11_index_find_all (test.index, cacert3, 2);
- CuAssertPtrNotNull (cu, handles);
- CuAssertTrue (cu, handles[0] != 0);
- CuAssertTrue (cu, handles[1] == 0);
+ assert_ptr_not_null (handles);
+ assert (handles[0] != 0);
+ assert (handles[1] == 0);
cert = p11_index_lookup (test.index, handles[0]);
- test_check_attrs (cu, trusted, cert);
+ test_check_attrs (trusted, cert);
free (handles);
/* Now add a distrutsed one, this should override the trusted */
@@ -546,51 +505,35 @@ test_duplicate_priority (CuTest *cu)
ret = p11_parse_file (test.parser, SRCDIR "/files/cacert3.der",
P11_PARSE_FLAG_BLACKLIST);
- CuAssertIntEquals (cu, P11_PARSE_SUCCESS, ret);
+ assert_num_eq (P11_PARSE_SUCCESS, ret);
p11_message_loud ();
/* We should now find the distrusted certificate */
handles = p11_index_find_all (test.index, cacert3, 2);
- CuAssertPtrNotNull (cu, handles);
- CuAssertTrue (cu, handles[0] != 0);
- CuAssertTrue (cu, handles[1] == 0);
+ assert_ptr_not_null (handles);
+ assert (handles[0] != 0);
+ assert (handles[1] == 0);
cert = p11_index_lookup (test.index, handles[0]);
- test_check_attrs (cu, distrust, cert);
+ test_check_attrs (distrust, cert);
free (handles);
-
- teardown (cu);
}
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_parse_der_certificate);
- SUITE_ADD_TEST (suite, test_parse_pem_certificate);
- SUITE_ADD_TEST (suite, test_parse_p11_kit_persist);
- SUITE_ADD_TEST (suite, test_parse_openssl_trusted);
- SUITE_ADD_TEST (suite, test_parse_openssl_distrusted);
- SUITE_ADD_TEST (suite, test_parse_anchor);
- SUITE_ADD_TEST (suite, test_parse_thawte);
- SUITE_ADD_TEST (suite, test_parse_invalid_file);
- SUITE_ADD_TEST (suite, test_parse_unrecognized);
- SUITE_ADD_TEST (suite, test_duplicate);
- SUITE_ADD_TEST (suite, test_duplicate_priority);
-
- 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_parse_der_certificate, "/parser/parse_der_certificate");
+ p11_test (test_parse_pem_certificate, "/parser/parse_pem_certificate");
+ p11_test (test_parse_p11_kit_persist, "/parser/parse_p11_kit_persist");
+ p11_test (test_parse_openssl_trusted, "/parser/parse_openssl_trusted");
+ p11_test (test_parse_openssl_distrusted, "/parser/parse_openssl_distrusted");
+ p11_test (test_parse_anchor, "/parser/parse_anchor");
+ p11_test (test_parse_thawte, "/parser/parse_thawte");
+ p11_test (test_parse_invalid_file, "/parser/parse_invalid_file");
+ p11_test (test_parse_unrecognized, "/parser/parse_unrecognized");
+ p11_test (test_duplicate, "/parser/duplicate");
+ p11_test (test_duplicate_priority, "/parser/duplicate_priority");
+ return p11_test_run (argc, argv);
}
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);
}
diff --git a/trust/tests/test-token.c b/trust/tests/test-token.c
index ffd733f..6f5ccdb 100644
--- a/trust/tests/test-token.c
+++ b/trust/tests/test-token.c
@@ -33,7 +33,8 @@
*/
#include "config.h"
-#include "CuTest.h"
+#include "test.h"
+#include "test-trust.h"
#include <stdlib.h>
#include <stdio.h>
@@ -43,7 +44,6 @@
#include "debug.h"
#include "pkcs11x.h"
#include "message.h"
-#include "test-data.h"
#include "token.h"
struct {
@@ -51,40 +51,35 @@ struct {
} test;
static void
-setup (CuTest *cu,
- const char *path)
+setup (void *path)
{
test.token = p11_token_new (333, path, "Label");
- CuAssertPtrNotNull (cu, test.token);
+ assert_ptr_not_null (test.token);
}
static void
-teardown (CuTest *cu)
+teardown (void *path)
{
p11_token_free (test.token);
memset (&test, 0, sizeof (test));
}
static void
-test_token_load (CuTest *cu)
+test_token_load (void *path)
{
p11_index *index;
int count;
- setup (cu, SRCDIR "/input");
-
count = p11_token_load (test.token);
- CuAssertIntEquals (cu, 7, count);
+ assert_num_eq (7, count);
/* A certificate and trust object for each parsed object + builtin */
index = p11_token_index (test.token);
- CuAssertTrue (cu, ((count - 1) * 2) + 1 <= p11_index_size (index));
-
- teardown (cu);
+ assert (((count - 1) * 2) + 1 <= p11_index_size (index));
}
static void
-test_token_flags (CuTest *cu)
+test_token_flags (void *path)
{
CK_OBJECT_CLASS certificate = CKO_CERTIFICATE;
CK_BBOOL falsev = CK_FALSE;
@@ -178,78 +173,50 @@ test_token_flags (CuTest *cu)
CK_ATTRIBUTE *object;
int i;
- setup (cu, SRCDIR "/input");
-
if (p11_token_load (test.token) < 0)
- CuFail (cu, "should not be reached");
+ assert_not_reached ();
/* The other objects */
for (i = 0; expected[i]; i++) {
handle = p11_index_find (p11_token_index (test.token), expected[i], 2);
- CuAssertTrue (cu, handle != 0);
+ assert (handle != 0);
object = p11_index_lookup (p11_token_index (test.token), handle);
- CuAssertPtrNotNull (cu, object);
+ assert_ptr_not_null (object);
- test_check_attrs (cu, expected[i], object);
+ test_check_attrs (expected[i], object);
}
-
- teardown (cu);
}
static void
-test_token_path (CuTest *cu)
+test_token_path (void *path)
{
- setup (cu, "/wheee");
-
- CuAssertStrEquals (cu, "/wheee", p11_token_get_path (test.token));
-
- teardown (cu);
+ assert_str_eq (path, p11_token_get_path (test.token));
}
static void
-test_token_label (CuTest *cu)
+test_token_label (void *path)
{
- setup (cu, "/wheee");
-
- CuAssertStrEquals (cu, "Label", p11_token_get_label (test.token));
-
- teardown (cu);
+ assert_str_eq ("Label", p11_token_get_label (test.token));
}
static void
-test_token_slot (CuTest *cu)
+test_token_slot (void *path)
{
- setup (cu, "/unneeded");
-
- CuAssertIntEquals (cu, 333, p11_token_get_slot (test.token));
-
- teardown (cu);
+ assert_num_eq (333, p11_token_get_slot (test.token));
}
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_token_load);
- SUITE_ADD_TEST (suite, test_token_flags);
- SUITE_ADD_TEST (suite, test_token_path);
- SUITE_ADD_TEST (suite, test_token_label);
- SUITE_ADD_TEST (suite, test_token_slot);
-
- 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_testx (test_token_load, SRCDIR "/input", "/token/load");
+ p11_testx (test_token_flags, SRCDIR "/input", "/token/flags");
+
+ p11_fixture (setup, teardown);
+ p11_testx (test_token_path, "/wheee", "/token/path");
+ p11_testx (test_token_label, "/wheee", "/token/label");
+ p11_testx (test_token_slot, "/unneeded", "/token/slot");
+ return p11_test_run (argc, argv);
}
diff --git a/trust/tests/test-data.c b/trust/tests/test-trust.c
index 6c55fd0..6b990dc 100644
--- a/trust/tests/test-data.c
+++ b/trust/tests/test-trust.c
@@ -33,10 +33,10 @@
*/
#include "config.h"
-#include "CuTest.h"
+#include "test.h"
#include "attrs.h"
-#include "test-data.h"
+#include "test-trust.h"
#include <assert.h>
#include <stdlib.h>
@@ -44,9 +44,9 @@
#include <string.h>
void
-test_check_object_msg (CuTest *cu,
- const char *file,
+test_check_object_msg (const char *file,
int line,
+ const char *function,
CK_ATTRIBUTE *attrs,
CK_OBJECT_CLASS klass,
const char *label)
@@ -61,13 +61,13 @@ test_check_object_msg (CuTest *cu,
{ CKA_INVALID },
};
- test_check_attrs_msg (cu, file, line, expected, attrs);
+ test_check_attrs_msg (file, line, function, expected, attrs);
}
void
-test_check_cacert3_ca_msg (CuTest *cu,
- const char *file,
+test_check_cacert3_ca_msg (const char *file,
int line,
+ const char *function,
CK_ATTRIBUTE *attrs,
const char *label)
{
@@ -87,14 +87,14 @@ test_check_cacert3_ca_msg (CuTest *cu,
{ CKA_INVALID },
};
- test_check_object_msg (cu, file, line, attrs, CKO_CERTIFICATE, label);
- test_check_attrs_msg (cu, file, line, expected, attrs);
+ test_check_object_msg (file, line, function, attrs, CKO_CERTIFICATE, label);
+ test_check_attrs_msg (file, line, function, expected, attrs);
}
void
-test_check_id_msg (CuTest *cu,
- const char *file,
+test_check_id_msg (const char *file,
int line,
+ const char *function,
CK_ATTRIBUTE *expected,
CK_ATTRIBUTE *attr)
{
@@ -104,13 +104,13 @@ test_check_id_msg (CuTest *cu,
one = p11_attrs_find (expected, CKA_ID);
two = p11_attrs_find (attr, CKA_ID);
- test_check_attr_msg (cu, file, line, CKA_INVALID, one, two);
+ test_check_attr_msg (file, line, function, CKA_INVALID, one, two);
}
void
-test_check_attrs_msg (CuTest *cu,
- const char *file,
+test_check_attrs_msg (const char *file,
int line,
+ const char *function,
CK_ATTRIBUTE *expected,
CK_ATTRIBUTE *attrs)
{
@@ -122,39 +122,31 @@ test_check_attrs_msg (CuTest *cu,
while (!p11_attrs_terminator (expected)) {
attr = p11_attrs_find (attrs, expected->type);
- test_check_attr_msg (cu, file, line, klass, expected, attr);
+ test_check_attr_msg (file, line, function, klass, expected, attr);
expected++;
}
}
void
-test_check_attr_msg (CuTest *cu,
- const char *file,
+test_check_attr_msg (const char *file,
int line,
+ const char *function,
CK_OBJECT_CLASS klass,
CK_ATTRIBUTE *expected,
CK_ATTRIBUTE *attr)
{
- char *message;
assert (expected != NULL);
if (attr == NULL) {
- asprintf (&message, "expected %s but found NULL",
- p11_attr_to_string (expected, klass));
- CuFail_Line (cu, file, line, "attribute does not match", message);
+ p11_test_fail (file, line, function,
+ "attribute does not match: (expected %s but found NULL)",
+ p11_attr_to_string (expected, klass));
}
if (!p11_attr_equal (attr, expected)) {
- asprintf (&message, "expected %s but found %s",
- p11_attr_to_string (expected, klass),
- p11_attr_to_string (attr, klass));
- CuFail_Line (cu, file, line, "attribute does not match", message);
+ p11_test_fail (file, line, function,
+ "attribute does not match: (expected %s but found %s)",
+ p11_attr_to_string (expected, klass),
+ p11_attr_to_string (attr, klass));
}
}
-
-void
-test_fail_attrs_match (CuTest *cu,
- const char *file,
- const char *line,
- CK_ATTRIBUTE *expect,
- CK_ATTRIBUTE *attrs);
diff --git a/trust/tests/test-data.h b/trust/tests/test-trust.h
index 275dd70..672ae64 100644
--- a/trust/tests/test-data.h
+++ b/trust/tests/test-trust.h
@@ -39,50 +39,50 @@
#ifndef TEST_DATA_H_
#define TEST_DATA_H_
-#define test_check_object(cu, attrs, klass, label) \
- test_check_object_msg (cu, __FILE__, __LINE__, attrs, klass, label)
+#define test_check_object(attrs, klass, label) \
+ test_check_object_msg (__FILE__, __LINE__, __FUNCTION__, attrs, klass, label)
-void test_check_object_msg (CuTest *cu,
- const char *file,
+void test_check_object_msg (const char *file,
int line,
+ const char *function,
CK_ATTRIBUTE *attrs,
CK_OBJECT_CLASS klass,
const char *label);
-#define test_check_cacert3_ca(cu, attrs, label) \
- test_check_cacert3_ca_msg (cu, __FILE__, __LINE__, attrs, label)
+#define test_check_cacert3_ca(attrs, label) \
+ test_check_cacert3_ca_msg (__FILE__, __LINE__, __FUNCTION__, attrs, label)
-void test_check_cacert3_ca_msg (CuTest *cu,
- const char *file,
+void test_check_cacert3_ca_msg (const char *file,
int line,
+ const char *function,
CK_ATTRIBUTE *attrs,
const char *label);
-#define test_check_attrs(cu, expected, attrs) \
- test_check_attrs_msg (cu, __FILE__, __LINE__, expected, attrs)
+#define test_check_attrs(expected, attrs) \
+ test_check_attrs_msg (__FILE__, __LINE__, __FUNCTION__, expected, attrs)
-void test_check_attrs_msg (CuTest *cu,
- const char *file,
+void test_check_attrs_msg (const char *file,
int line,
+ const char *function,
CK_ATTRIBUTE *expected,
CK_ATTRIBUTE *attrs);
-#define test_check_attr(cu, expected, attr) \
- test_check_attr_msg (cu, __FILE__, __LINE__, CKA_INVALID, expected, attr)
+#define test_check_attr(expected, attr) \
+ test_check_attr_msg (__FILE__, __LINE__, __FUNCTION__, CKA_INVALID, expected, attr)
-void test_check_attr_msg (CuTest *cu,
- const char *file,
+void test_check_attr_msg (const char *file,
int line,
+ const char *function,
CK_OBJECT_CLASS klass,
CK_ATTRIBUTE *expected,
CK_ATTRIBUTE *attr);
-#define test_check_id(cu, expected, attrs) \
- test_check_id_msg (cu, __FILE__, __LINE__, expected, attrs)
+#define test_check_id(expected, attrs) \
+ test_check_id_msg (__FILE__, __LINE__, __FUNCTION__, expected, attrs)
-void test_check_id_msg (CuTest *cu,
- const char *file,
+void test_check_id_msg (const char *file,
int line,
+ const char *function,
CK_ATTRIBUTE *expected,
CK_ATTRIBUTE *attr);