summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am3
-rw-r--r--tests/test-init.c68
-rw-r--r--tests/uri-test.c12
3 files changed, 79 insertions, 4 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 28aa496..1f6083f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -4,7 +4,8 @@ INCLUDES = \
-I$(top_srcdir)/common \
-I$(top_srcdir)/p11-kit \
-I$(srcdir)/cutest \
- -DSRCDIR=\"$(srcdir)\" \
+ -DSRCDIR=\"$(abs_srcdir)\" \
+ -DBUILDDIR=\"$(abs_builddir)\" \
-DP11_KIT_FUTURE_UNSTABLE_API
LDADD = \
diff --git a/tests/test-init.c b/tests/test-init.c
index be970aa..8128db6 100644
--- a/tests/test-init.c
+++ b/tests/test-init.c
@@ -152,7 +152,8 @@ mock_C_Finalize__threaded_race (CK_VOID_PTR reserved)
_p11_mutex_unlock (&race_mutex);
_p11_sleep_ms (100);
- return CKR_OK;}
+ return CKR_OK;
+}
static void *
initialization_thread (void *data)
@@ -223,6 +224,69 @@ test_threaded_initialization (CuTest *tc)
CuAssertIntEquals (tc, 1, finalization_count);
}
+static CK_RV
+mock_C_Initialize__test_mutexes (CK_VOID_PTR args)
+{
+ CK_C_INITIALIZE_ARGS_PTR init_args;
+ void *mutex = NULL;
+ CK_RV rv;
+
+ assert (args != NULL);
+ init_args = args;
+
+ rv = (init_args->CreateMutex) (&mutex);
+ assert (rv == CKR_OK);
+
+ rv = (init_args->LockMutex) (mutex);
+ assert (rv == CKR_OK);
+
+ rv = (init_args->UnlockMutex) (mutex);
+ assert (rv == CKR_OK);
+
+ rv = (init_args->DestroyMutex) (mutex);
+ assert (rv == CKR_OK);
+
+ return CKR_OK;
+}
+
+static void
+test_mutexes (CuTest *tc)
+{
+ CK_RV rv;
+
+ /* 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);
+
+ rv = p11_kit_finalize_module (&module);
+ CuAssertTrue (tc, rv == CKR_OK);
+}
+
+static void
+test_load_and_initialize (CuTest *tc)
+{
+ CK_FUNCTION_LIST_PTR module;
+ CK_INFO info;
+ CK_RV rv;
+ int ret;
+
+ rv = p11_kit_load_initialize_module (BUILDDIR "/.libs/mock-one.so", &module);
+ CuAssertTrue (tc, rv == CKR_OK);
+ CuAssertTrue (tc, module != NULL);
+
+ rv = (module->C_GetInfo) (&info);
+ CuAssertTrue (tc, rv == CKR_OK);
+
+ ret = memcmp (info.manufacturerID, "MOCK MANUFACTURER ", 32);
+ CuAssertTrue (tc, ret == 0);
+
+ rv = p11_kit_finalize_module (module);
+ CuAssertTrue (tc, ret == CKR_OK);
+}
+
int
main (void)
{
@@ -240,6 +304,8 @@ main (void)
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);
CuSuiteRun (suite);
CuSuiteSummary (suite, output);
diff --git a/tests/uri-test.c b/tests/uri-test.c
index 2012c0f..16480f6 100644
--- a/tests/uri-test.c
+++ b/tests/uri-test.c
@@ -1120,7 +1120,15 @@ test_uri_pin_source (CuTest *tc)
uri = p11_kit_uri_new ();
CuAssertPtrNotNull (tc, uri);
- p11_kit_uri_set_pin_source (uri, "|my-pin-file");
+ 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);
+
+ pin_source = p11_kit_uri_get_pinfile (uri);
+ CuAssertStrEquals (tc, "|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);
@@ -1149,7 +1157,7 @@ static void
test_uri_message (CuTest *tc)
{
CuAssertTrue (tc, p11_kit_uri_message (P11_KIT_URI_OK) == NULL);
- CuAssertPtrNotNull (tc, p11_kit_uri_message (P11_KIT_URI_NO_MEMORY));
+ CuAssertPtrNotNull (tc, p11_kit_uri_message (P11_KIT_URI_UNEXPECTED));
CuAssertPtrNotNull (tc, p11_kit_uri_message (-555555));
}