[gnome-keyring/gnome-3-0] pkcs11: Fix up gkm tests to more modern gtest style tests.
- From: Stefan Walter <stefw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-keyring/gnome-3-0] pkcs11: Fix up gkm tests to more modern gtest style tests.
- Date: Mon, 18 Apr 2011 11:29:45 +0000 (UTC)
commit 00052136a0fd42b23956dfd76892912f7fb58e00
Author: Stef Walter <stefw collabora co uk>
Date: Mon Apr 18 13:18:31 2011 +0200
pkcs11: Fix up gkm tests to more modern gtest style tests.
.gitignore | 13 +
pkcs11/gkm/tests/Makefile.am | 94 +++-
.../tests/{test-data => files}/ca-certificates.crt | 0
.../{test-data => files}/der-pkcs8-PBE-MD5-DES.key | Bin 677 -> 677 bytes
.../der-pkcs8-PBE-SHA1-3DES.key | Bin 678 -> 678 bytes
.../der-pkcs8-PBE-SHA1-DES.key | Bin 677 -> 677 bytes
.../der-pkcs8-PBE-SHA1-RC2-40.key | Bin 678 -> 678 bytes
.../der-pkcs8-PBE-SHA1-RC4-128.key | Bin 673 -> 673 bytes
.../tests/{test-data => files}/der-pkcs8-dsa.key | Bin 335 -> 335 bytes
.../der-pkcs8-encrypted-pkcs5.key | Bin 677 -> 677 bytes
.../{test-data => files}/der-pkcs8-v2-des.key | Bin 711 -> 711 bytes
.../{test-data => files}/der-pkcs8-v2-des3.key | Bin 714 -> 714 bytes
.../gkm/tests/{test-data => files}/der-pkcs8.key | Bin 635 -> 635 bytes
.../gkm/tests/{test-data => files}/pem-rsa-enc.key | 0
.../{test-data => files}/test-certificate-1.der | Bin 813 -> 813 bytes
.../{test-data => files}/test-certificate-2.der | Bin 1346 -> 1346 bytes
pkcs11/gkm/tests/mock-locked-object.h | 4 +-
pkcs11/gkm/tests/{test-module.c => mock-module.c} | 36 +-
pkcs11/gkm/tests/{test-module.h => mock-module.h} | 22 +-
.../{unit-test-attributes.c => test-attributes.c} | 260 ++++++++---
.../{unit-test-credential.c => test-credential.c} | 123 +++--
.../{unit-test-data-asn1.c => test-data-asn1.c} | 46 ++-
.../{unit-test-data-der.c => test-data-der.c} | 167 +++++---
pkcs11/gkm/tests/test-file-tracker.c | 244 ++++++++++
pkcs11/gkm/tests/test-memory-store.c | 482 ++++++++++++++++++++
.../tests/{unit-test-object.c => test-object.c} | 132 ++++---
.../tests/{unit-test-secret.c => test-secret.c} | 48 ++-
pkcs11/gkm/tests/{unit-test-sexp.c => test-sexp.c} | 64 ++-
.../gkm/tests/{unit-test-store.c => test-store.c} | 59 ++-
pkcs11/gkm/tests/test-timer.c | 175 +++++++
...{unit-test-transaction.c => test-transaction.c} | 117 ++++--
pkcs11/gkm/tests/unit-test-file-tracker.c | 221 ---------
pkcs11/gkm/tests/unit-test-memory-store.c | 438 ------------------
pkcs11/gkm/tests/unit-test-timer.c | 144 ------
34 files changed, 1712 insertions(+), 1177 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 26bff68..bc10dd5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -114,6 +114,19 @@ run-tests
/gcr/tests/test-simple-certificate
/gcr/tests/test-trust
+/pkcs11/gkm/tests/test-attributes
+/pkcs11/gkm/tests/test-credential
+/pkcs11/gkm/tests/test-data-asn1
+/pkcs11/gkm/tests/test-data-der
+/pkcs11/gkm/tests/test-file-tracker
+/pkcs11/gkm/tests/test-memory-store
+/pkcs11/gkm/tests/test-object
+/pkcs11/gkm/tests/test-secret
+/pkcs11/gkm/tests/test-sexp
+/pkcs11/gkm/tests/test-store
+/pkcs11/gkm/tests/test-timer
+/pkcs11/gkm/tests/test-transaction
+
/daemon/dbus/tests/test-secret-util
/ui/gnome-keyring-prompt.desktop
diff --git a/pkcs11/gkm/tests/Makefile.am b/pkcs11/gkm/tests/Makefile.am
index 662fad9..91cff0a 100644
--- a/pkcs11/gkm/tests/Makefile.am
+++ b/pkcs11/gkm/tests/Makefile.am
@@ -1,33 +1,75 @@
-asn1-def-test.h: test.asn
- $(ASN1PARSER) -o asn1-def-test.h $(srcdir)/test.asn
+INCLUDES = \
+ -I$(top_srcdir)/egg \
+ -I$(top_srcdir)/pkcs11 \
+ -DSRCDIR=$(srcdir) \
+ $(GLIB_CFLAGS) \
+ $(LIBGCRYPT_CFLAGS)
+
+LDADD = \
+ $(top_builddir)/pkcs11/gkm/libgkm.la \
+ $(top_builddir)/egg/libegg.la \
+ $(GLIB_LIBS) \
+ $(LIBGCRYPT_LIBS)
+
+noinst_LIBRARIES = libgkm-mock.a
-TESTING_SOURCES = \
- asn1-def-test.h \
- test-module.c test-module.h \
+BUILT_SOURCES = \
+ asn1-def-test.h
+
+libgkm_mock_a_SOURCES = \
+ mock-module.c mock-module.h \
mock-locked-object.c mock-locked-object.h
+ $(BUILT_SOURCES)
-# Test files should be listed in order they need to run
-TESTING_FILES = \
- unit-test-attributes.c \
- unit-test-sexp.c \
- unit-test-data-asn1.c \
- unit-test-data-der.c \
- unit-test-object.c \
- unit-test-credential.c \
- unit-test-timer.c \
- unit-test-transaction.c \
- unit-test-store.c \
- unit-test-memory-store.c \
- unit-test-secret.c \
- unit-test-file-tracker.c
-
-TESTING_LIBS = \
- $(top_builddir)/pkcs11/gkm/libgkm.la \
- $(top_builddir)/egg/libegg.la
+TEST_PROGS = \
+ test-attributes \
+ test-credential \
+ test-data-asn1 \
+ test-data-der \
+ test-file-tracker \
+ test-memory-store \
+ test-object \
+ test-secret \
+ test-sexp \
+ test-store \
+ test-timer \
+ test-transaction
+
+test_credential_LDADD = \
+ libgkm-mock.a \
+ $(LDADD)
+
+test_memory_store_LDADD = \
+ libgkm-mock.a \
+ $(LDADD)
-include $(top_srcdir)/testing/testing.make
+test_object_LDADD = \
+ libgkm-mock.a \
+ $(LDADD)
+
+test_store_LDADD = \
+ libgkm-mock.a \
+ $(LDADD)
+
+test_timer_LDADD = \
+ libgkm-mock.a \
+ $(LDADD)
+
+check_PROGRAMS = $(TEST_PROGS)
+
+test: $(TEST_PROGS)
+ SRCDIR='$(srcdir)' gtester -k --verbose ${TEST_PROGS}
+
+check-local: test
+
+if WITH_TESTS
+all-local: $(check_PROGRAMS)
+endif
+
+asn1-def-test.h: test.asn
+ $(ASN1PARSER) -o asn1-def-test.h $(srcdir)/test.asn
-EXTRA_DIST += \
+EXTRA_DIST = \
test.asn \
- test-data
+ files
diff --git a/pkcs11/gkm/tests/test-data/ca-certificates.crt b/pkcs11/gkm/tests/files/ca-certificates.crt
similarity index 100%
rename from pkcs11/gkm/tests/test-data/ca-certificates.crt
rename to pkcs11/gkm/tests/files/ca-certificates.crt
diff --git a/pkcs11/gkm/tests/test-data/der-pkcs8-PBE-MD5-DES.key b/pkcs11/gkm/tests/files/der-pkcs8-PBE-MD5-DES.key
similarity index 100%
rename from pkcs11/gkm/tests/test-data/der-pkcs8-PBE-MD5-DES.key
rename to pkcs11/gkm/tests/files/der-pkcs8-PBE-MD5-DES.key
diff --git a/pkcs11/gkm/tests/test-data/der-pkcs8-PBE-SHA1-3DES.key b/pkcs11/gkm/tests/files/der-pkcs8-PBE-SHA1-3DES.key
similarity index 100%
rename from pkcs11/gkm/tests/test-data/der-pkcs8-PBE-SHA1-3DES.key
rename to pkcs11/gkm/tests/files/der-pkcs8-PBE-SHA1-3DES.key
diff --git a/pkcs11/gkm/tests/test-data/der-pkcs8-PBE-SHA1-DES.key b/pkcs11/gkm/tests/files/der-pkcs8-PBE-SHA1-DES.key
similarity index 100%
rename from pkcs11/gkm/tests/test-data/der-pkcs8-PBE-SHA1-DES.key
rename to pkcs11/gkm/tests/files/der-pkcs8-PBE-SHA1-DES.key
diff --git a/pkcs11/gkm/tests/test-data/der-pkcs8-PBE-SHA1-RC2-40.key b/pkcs11/gkm/tests/files/der-pkcs8-PBE-SHA1-RC2-40.key
similarity index 100%
rename from pkcs11/gkm/tests/test-data/der-pkcs8-PBE-SHA1-RC2-40.key
rename to pkcs11/gkm/tests/files/der-pkcs8-PBE-SHA1-RC2-40.key
diff --git a/pkcs11/gkm/tests/test-data/der-pkcs8-PBE-SHA1-RC4-128.key b/pkcs11/gkm/tests/files/der-pkcs8-PBE-SHA1-RC4-128.key
similarity index 100%
rename from pkcs11/gkm/tests/test-data/der-pkcs8-PBE-SHA1-RC4-128.key
rename to pkcs11/gkm/tests/files/der-pkcs8-PBE-SHA1-RC4-128.key
diff --git a/pkcs11/gkm/tests/test-data/der-pkcs8-dsa.key b/pkcs11/gkm/tests/files/der-pkcs8-dsa.key
similarity index 100%
rename from pkcs11/gkm/tests/test-data/der-pkcs8-dsa.key
rename to pkcs11/gkm/tests/files/der-pkcs8-dsa.key
diff --git a/pkcs11/gkm/tests/test-data/der-pkcs8-encrypted-pkcs5.key b/pkcs11/gkm/tests/files/der-pkcs8-encrypted-pkcs5.key
similarity index 100%
rename from pkcs11/gkm/tests/test-data/der-pkcs8-encrypted-pkcs5.key
rename to pkcs11/gkm/tests/files/der-pkcs8-encrypted-pkcs5.key
diff --git a/pkcs11/gkm/tests/test-data/der-pkcs8-v2-des.key b/pkcs11/gkm/tests/files/der-pkcs8-v2-des.key
similarity index 100%
rename from pkcs11/gkm/tests/test-data/der-pkcs8-v2-des.key
rename to pkcs11/gkm/tests/files/der-pkcs8-v2-des.key
diff --git a/pkcs11/gkm/tests/test-data/der-pkcs8-v2-des3.key b/pkcs11/gkm/tests/files/der-pkcs8-v2-des3.key
similarity index 100%
rename from pkcs11/gkm/tests/test-data/der-pkcs8-v2-des3.key
rename to pkcs11/gkm/tests/files/der-pkcs8-v2-des3.key
diff --git a/pkcs11/gkm/tests/test-data/der-pkcs8.key b/pkcs11/gkm/tests/files/der-pkcs8.key
similarity index 100%
rename from pkcs11/gkm/tests/test-data/der-pkcs8.key
rename to pkcs11/gkm/tests/files/der-pkcs8.key
diff --git a/pkcs11/gkm/tests/test-data/pem-rsa-enc.key b/pkcs11/gkm/tests/files/pem-rsa-enc.key
similarity index 100%
rename from pkcs11/gkm/tests/test-data/pem-rsa-enc.key
rename to pkcs11/gkm/tests/files/pem-rsa-enc.key
diff --git a/pkcs11/gkm/tests/test-data/test-certificate-1.der b/pkcs11/gkm/tests/files/test-certificate-1.der
similarity index 100%
rename from pkcs11/gkm/tests/test-data/test-certificate-1.der
rename to pkcs11/gkm/tests/files/test-certificate-1.der
diff --git a/pkcs11/gkm/tests/test-data/test-certificate-2.der b/pkcs11/gkm/tests/files/test-certificate-2.der
similarity index 100%
rename from pkcs11/gkm/tests/test-data/test-certificate-2.der
rename to pkcs11/gkm/tests/files/test-certificate-2.der
diff --git a/pkcs11/gkm/tests/mock-locked-object.h b/pkcs11/gkm/tests/mock-locked-object.h
index f68c863..ad1d0dd 100644
--- a/pkcs11/gkm/tests/mock-locked-object.h
+++ b/pkcs11/gkm/tests/mock-locked-object.h
@@ -24,8 +24,8 @@
#include <glib-object.h>
-#include "gkm-object.h"
-#include "gkm-types.h"
+#include "gkm/gkm-object.h"
+#include "gkm/gkm-types.h"
#define MOCK_TYPE_LOCKED_OBJECT (mock_locked_object_get_type ())
#define MOCK_LOCKED_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MOCK_TYPE_LOCKED_OBJECT, MockLockedObject))
diff --git a/pkcs11/gkm/tests/test-module.c b/pkcs11/gkm/tests/mock-module.c
similarity index 82%
rename from pkcs11/gkm/tests/test-module.c
rename to pkcs11/gkm/tests/mock-module.c
index 20acca6..b53544b 100644
--- a/pkcs11/gkm/tests/test-module.c
+++ b/pkcs11/gkm/tests/mock-module.c
@@ -22,8 +22,10 @@
*/
#include "config.h"
-#include "test-module.h"
-#include "test-suite.h"
+
+#include "mock-module.h"
+
+#include "egg/egg-secure-memory.h"
/* Include all the module entry points */
#include "gkm/gkm-module-ep.h"
@@ -31,8 +33,10 @@ GKM_DEFINE_MODULE (test_module, GKM_TYPE_MODULE);
#include "gkm/gkm-certificate.h"
+EGG_SECURE_GLIB_DEFINITIONS ();
+
GkmModule*
-test_module_initialize_and_enter (void)
+mock_module_initialize_and_enter (void)
{
CK_RV rv;
@@ -42,34 +46,34 @@ test_module_initialize_and_enter (void)
g_return_val_if_fail (pkcs11_module, NULL);
- test_module_enter ();
+ mock_module_enter ();
return pkcs11_module;
}
void
-test_module_leave_and_finalize (void)
+mock_module_leave_and_finalize (void)
{
CK_RV rv;
- test_module_leave ();
+ mock_module_leave ();
rv = test_module_function_list->C_Finalize (NULL);
g_return_if_fail (rv == CKR_OK);
}
void
-test_module_leave (void)
+mock_module_leave (void)
{
g_static_mutex_unlock (&pkcs11_module_mutex);
}
void
-test_module_enter (void)
+mock_module_enter (void)
{
g_static_mutex_lock (&pkcs11_module_mutex);
}
GkmSession*
-test_module_open_session (gboolean writable)
+mock_module_open_session (gboolean writable)
{
CK_ULONG flags = CKF_SERIAL_SESSION;
CK_SESSION_HANDLE handle;
@@ -89,7 +93,7 @@ test_module_open_session (gboolean writable)
}
GkmObject*
-test_module_object_new (GkmSession *session)
+mock_module_object_new (GkmSession *session)
{
CK_BBOOL token = CK_FALSE;
CK_OBJECT_CLASS klass = CKO_CERTIFICATE;
@@ -97,18 +101,26 @@ test_module_object_new (GkmSession *session)
GkmObject *object;
gsize n_data;
- guchar *data = testing_data_read ("test-certificate-1.der", &n_data);
+ gchar *data;
CK_ATTRIBUTE attrs[] = {
+ { CKA_VALUE, data, n_data },
{ CKA_TOKEN, &token, sizeof (token) },
{ CKA_CLASS, &klass, sizeof (klass) },
{ CKA_CERTIFICATE_TYPE, &type, sizeof (type) },
- { CKA_VALUE, data, n_data },
};
+ if (!g_file_get_contents ("files/test-certificate-1.der", &data, &n_data, NULL))
+ g_assert_not_reached ();
+
+ attrs[0].pValue = data;
+ attrs[0].ulValueLen = n_data;
+
object = gkm_session_create_object_for_factory (session, GKM_FACTORY_CERTIFICATE, NULL,
attrs, G_N_ELEMENTS (attrs));
if (object) /* Owned by storage */
g_object_unref (object);
+
+ g_free (data);
return object;
}
diff --git a/pkcs11/gkm/tests/test-module.h b/pkcs11/gkm/tests/mock-module.h
similarity index 66%
rename from pkcs11/gkm/tests/test-module.h
rename to pkcs11/gkm/tests/mock-module.h
index f4223b5..eb42c5e 100644
--- a/pkcs11/gkm/tests/test-module.h
+++ b/pkcs11/gkm/tests/mock-module.h
@@ -1,5 +1,5 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* test-module.h: A test PKCS#11 module implementation
+/* mock-module.h: A test PKCS#11 module implementation
Copyright (C) 2009 Stefan Walter
@@ -21,25 +21,25 @@
Author: Stef Walter <stef memberwebs com>
*/
-#ifndef TESTMODULE_H_
-#define TESTMODULE_H_
+#ifndef MOCK_MODULE_H_
+#define MOCK_MODULE_H_
#include <glib.h>
-#include "gkm-types.h"
+#include "gkm/gkm-types.h"
#include "pkcs11.h"
-void test_module_leave (void);
+void mock_module_leave (void);
-void test_module_enter (void);
+void mock_module_enter (void);
-GkmModule* test_module_initialize_and_enter (void);
+GkmModule* mock_module_initialize_and_enter (void);
-void test_module_leave_and_finalize (void);
+void mock_module_leave_and_finalize (void);
-GkmSession* test_module_open_session (gboolean writable);
+GkmSession* mock_module_open_session (gboolean writable);
-GkmObject* test_module_object_new (GkmSession *session);
+GkmObject* mock_module_object_new (GkmSession *session);
-#endif /* TESTMODULE_H_ */
+#endif /* MOCK_MODULE_H_ */
diff --git a/pkcs11/gkm/tests/unit-test-attributes.c b/pkcs11/gkm/tests/test-attributes.c
similarity index 64%
rename from pkcs11/gkm/tests/unit-test-attributes.c
rename to pkcs11/gkm/tests/test-attributes.c
index a7b1540..18e2072 100644
--- a/pkcs11/gkm/tests/unit-test-attributes.c
+++ b/pkcs11/gkm/tests/test-attributes.c
@@ -1,5 +1,5 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* unit-test-attributes.c: Test attributes functionality
+/* test-attributes.c: Test attributes functionality
Copyright (C) 2009 Stefan Walter
@@ -21,10 +21,12 @@
Author: Stef Walter <stef memberwebs com>
*/
-#include "test-suite.h"
+#include "config.h"
#include "gkm/gkm-attributes.h"
+#include <glib-object.h>
+
/* Some test data */
static CK_OBJECT_CLASS attr_template_klass = CKO_DATA;
static CK_BBOOL attr_template_token = CK_TRUE;
@@ -36,14 +38,16 @@ static CK_ATTRIBUTE attr_template[] = {
{ CKA_VALUE, "\a[\315\025", 4 }
};
-TESTING_TEST(attribute_equal_zero_len_null_ptr)
+static void
+test_attribute_equal_zero_len_null_ptr (void)
{
CK_ATTRIBUTE attr1 = { CKA_LABEL, "", 0 };
CK_ATTRIBUTE attr2 = { CKA_LABEL, NULL, 0 };
g_assert (gkm_attribute_equal (&attr1, &attr2));
}
-TESTING_TEST(attribute_consume)
+static void
+test_attribute_consume (void)
{
CK_ATTRIBUTE attr;
attr.type = CKA_LABEL;
@@ -52,7 +56,8 @@ TESTING_TEST(attribute_consume)
g_assert (attr.type == (gulong)-1);
}
-TESTING_TEST(attribute_consumed)
+static void
+test_attribute_consumed (void)
{
CK_ATTRIBUTE attr;
gboolean ret;
@@ -68,7 +73,8 @@ TESTING_TEST(attribute_consumed)
g_assert (ret == TRUE);
}
-TESTING_TEST(attribute_set_data)
+static void
+test_attribute_set_data (void)
{
guchar buffer[32];
CK_ATTRIBUTE attr = { 0, buffer, sizeof (buffer) };
@@ -80,7 +86,8 @@ TESTING_TEST(attribute_set_data)
g_assert (memcmp (buffer, "mytest", 6) == 0);
}
-TESTING_TEST(attribute_set_data_short)
+static void
+test_attribute_set_data_short (void)
{
guchar buffer[32];
CK_ATTRIBUTE attr = { 0, buffer, 4 };
@@ -91,7 +98,8 @@ TESTING_TEST(attribute_set_data_short)
g_assert (attr.ulValueLen == (CK_ULONG)-1);
}
-TESTING_TEST(attribute_set_data_length)
+static void
+test_attribute_set_data_length (void)
{
CK_ATTRIBUTE attr = { 0, NULL, 0 };
CK_RV rv;
@@ -101,7 +109,8 @@ TESTING_TEST(attribute_set_data_length)
g_assert (attr.ulValueLen == 6);
}
-TESTING_TEST(attribute_set_empty)
+static void
+test_attribute_set_empty (void)
{
CK_ATTRIBUTE attr;
gchar buf[30];
@@ -114,7 +123,8 @@ TESTING_TEST(attribute_set_empty)
g_assert (attr.ulValueLen == 0);
}
-TESTING_TEST(attribute_get_bool)
+static void
+test_attribute_get_bool (void)
{
CK_ATTRIBUTE attr;
CK_BBOOL val = CK_TRUE;
@@ -128,7 +138,8 @@ TESTING_TEST(attribute_get_bool)
g_assert (value == TRUE);
}
-TESTING_TEST(attribute_get_bool_invalid)
+static void
+test_attribute_get_bool_invalid (void)
{
CK_ATTRIBUTE attr;
CK_ULONG val = 4;
@@ -141,7 +152,8 @@ TESTING_TEST(attribute_get_bool_invalid)
g_assert (rv == CKR_ATTRIBUTE_VALUE_INVALID);
}
-TESTING_TEST(attribute_set_time)
+static void
+test_attribute_set_time (void)
{
CK_ATTRIBUTE attr;
gchar buf[30];
@@ -155,7 +167,8 @@ TESTING_TEST(attribute_set_time)
g_assert (memcmp (attr.pValue, "2009071815161100", 16) == 0);
}
-TESTING_TEST(attribute_set_time_empty)
+static void
+test_attribute_set_time_empty (void)
{
CK_ATTRIBUTE attr;
gchar buf[30];
@@ -168,7 +181,8 @@ TESTING_TEST(attribute_set_time_empty)
g_assert (attr.ulValueLen == 0);
}
-TESTING_TEST(attribute_set_time_length)
+static void
+test_attribute_set_time_length (void)
{
CK_ATTRIBUTE attr;
CK_RV rv;
@@ -181,7 +195,8 @@ TESTING_TEST(attribute_set_time_length)
g_assert (attr.pValue == NULL);
}
-TESTING_TEST(attribute_get_time)
+static void
+test_attribute_get_time (void)
{
CK_ATTRIBUTE attr;
glong when;
@@ -194,7 +209,8 @@ TESTING_TEST(attribute_get_time)
g_assert (when == 1247930171);
}
-TESTING_TEST(attribute_get_time_empty)
+static void
+test_attribute_get_time_empty (void)
{
CK_ATTRIBUTE attr;
glong when;
@@ -207,7 +223,8 @@ TESTING_TEST(attribute_get_time_empty)
g_assert (when == -1);
}
-TESTING_TEST(attribute_get_time_invalid)
+static void
+test_attribute_get_time_invalid (void)
{
CK_ATTRIBUTE attr;
glong when;
@@ -219,7 +236,8 @@ TESTING_TEST(attribute_get_time_invalid)
g_assert (rv == CKR_ATTRIBUTE_VALUE_INVALID);
}
-TESTING_TEST(attribute_get_time_invalid_length)
+static void
+test_attribute_get_time_invalid_length (void)
{
CK_ATTRIBUTE attr;
glong when;
@@ -231,7 +249,8 @@ TESTING_TEST(attribute_get_time_invalid_length)
g_assert (rv == CKR_ATTRIBUTE_VALUE_INVALID);
}
-TESTING_TEST(attribute_get_string)
+static void
+test_attribute_get_string (void)
{
CK_ATTRIBUTE attr;
gchar *value;
@@ -247,7 +266,8 @@ TESTING_TEST(attribute_get_string)
g_free (value);
}
-TESTING_TEST(attribute_get_string_null)
+static void
+test_attribute_get_string_null (void)
{
CK_ATTRIBUTE attr;
gchar *value;
@@ -261,7 +281,8 @@ TESTING_TEST(attribute_get_string_null)
g_assert (value == NULL);
}
-TESTING_TEST(attribute_get_string_not_utf8)
+static void
+test_attribute_get_string_not_utf8 (void)
{
CK_ATTRIBUTE attr;
gchar *value;
@@ -275,7 +296,8 @@ TESTING_TEST(attribute_get_string_not_utf8)
g_assert (rv == CKR_ATTRIBUTE_VALUE_INVALID);
}
-TESTING_TEST(attribute_get_string_bad_pointer)
+static void
+test_attribute_get_string_bad_pointer (void)
{
CK_ATTRIBUTE attr;
gchar *value;
@@ -289,7 +311,8 @@ TESTING_TEST(attribute_get_string_bad_pointer)
g_assert (rv == CKR_ATTRIBUTE_VALUE_INVALID);
}
-TESTING_TEST(attribute_set_bool)
+static void
+test_attribute_set_bool (void)
{
guchar buffer[32];
CK_ATTRIBUTE attr = { 0, buffer, sizeof (buffer) };
@@ -306,7 +329,8 @@ TESTING_TEST(attribute_set_bool)
g_assert (memcmp (buffer, "\0", 1) == 0);
}
-TESTING_TEST(attribute_set_bool_short)
+static void
+test_attribute_set_bool_short (void)
{
guchar buffer[32];
CK_ATTRIBUTE attr = { 0, buffer, 0 };
@@ -317,7 +341,8 @@ TESTING_TEST(attribute_set_bool_short)
g_assert (attr.ulValueLen == (CK_ULONG)-1);
}
-TESTING_TEST(attribute_set_bool_length)
+static void
+test_attribute_set_bool_length (void)
{
CK_ATTRIBUTE attr = { 0, NULL, 0 };
CK_RV rv;
@@ -327,7 +352,8 @@ TESTING_TEST(attribute_set_bool_length)
g_assert (attr.ulValueLen == 1);
}
-TESTING_TEST(attribute_set_ulong)
+static void
+test_attribute_set_ulong (void)
{
guchar buffer[32];
CK_ATTRIBUTE attr = { 0, buffer, sizeof (buffer) };
@@ -340,7 +366,8 @@ TESTING_TEST(attribute_set_ulong)
g_assert (memcmp (buffer, &value, sizeof (CK_ULONG)) == 0);
}
-TESTING_TEST(attribute_set_ulong_short)
+static void
+test_attribute_set_ulong_short (void)
{
guchar buffer[32];
CK_ATTRIBUTE attr = { 0, buffer, 0 };
@@ -351,7 +378,8 @@ TESTING_TEST(attribute_set_ulong_short)
g_assert (attr.ulValueLen == (CK_ULONG)-1);
}
-TESTING_TEST(attribute_set_ulong_length)
+static void
+test_attribute_set_ulong_length (void)
{
CK_ATTRIBUTE attr = { 0, NULL, 0 };
CK_RV rv;
@@ -361,7 +389,8 @@ TESTING_TEST(attribute_set_ulong_length)
g_assert (attr.ulValueLen == sizeof (CK_ULONG));
}
-TESTING_TEST(attribute_set_string)
+static void
+test_attribute_set_string (void)
{
guchar buffer[32];
CK_ATTRIBUTE attr = { 0, buffer, sizeof (buffer) };
@@ -373,7 +402,8 @@ TESTING_TEST(attribute_set_string)
g_assert (memcmp (buffer, "hello", 5) == 0);
}
-TESTING_TEST(attribute_set_string_null)
+static void
+test_attribute_set_string_null (void)
{
guchar buffer[32];
CK_ATTRIBUTE attr = { 0, buffer, sizeof (buffer) };
@@ -384,7 +414,8 @@ TESTING_TEST(attribute_set_string_null)
g_assert (attr.ulValueLen == 0);
}
-TESTING_TEST(attribute_set_string_short)
+static void
+test_attribute_set_string_short (void)
{
guchar buffer[32];
CK_ATTRIBUTE attr = { 0, buffer, 3 };
@@ -395,7 +426,8 @@ TESTING_TEST(attribute_set_string_short)
g_assert (attr.ulValueLen == (CK_ULONG)-1);
}
-TESTING_TEST(attribute_set_string_length)
+static void
+test_attribute_set_string_length (void)
{
CK_ATTRIBUTE attr = { 0, NULL, 0 };
CK_RV rv;
@@ -405,7 +437,8 @@ TESTING_TEST(attribute_set_string_length)
g_assert (attr.ulValueLen == 5);
}
-TESTING_TEST(attribute_set_date)
+static void
+test_attribute_set_date (void)
{
guchar buffer[32];
CK_ATTRIBUTE attr = { 0, buffer, sizeof (buffer) };
@@ -421,7 +454,8 @@ TESTING_TEST(attribute_set_date)
g_assert (memcmp (date->year, "2009", 4) == 0);
}
-TESTING_TEST(attribute_set_date_none)
+static void
+test_attribute_set_date_none (void)
{
guchar buffer[32];
CK_ATTRIBUTE attr = { 0, buffer, sizeof (buffer) };
@@ -432,7 +466,8 @@ TESTING_TEST(attribute_set_date_none)
g_assert (attr.ulValueLen == 0);
}
-TESTING_TEST(attribute_set_date_short)
+static void
+test_attribute_set_date_short (void)
{
guchar buffer[32];
CK_ATTRIBUTE attr = { 0, buffer, 5 };
@@ -443,7 +478,8 @@ TESTING_TEST(attribute_set_date_short)
g_assert (attr.ulValueLen == (CK_ULONG)-1);
}
-TESTING_TEST(attribute_set_date_length)
+static void
+test_attribute_set_date_length (void)
{
CK_ATTRIBUTE attr = { 0, NULL, 0 };
CK_RV rv;
@@ -453,7 +489,8 @@ TESTING_TEST(attribute_set_date_length)
g_assert (attr.ulValueLen == sizeof (CK_DATE));
}
-TESTING_TEST(attribute_set_mpi)
+static void
+test_attribute_set_mpi (void)
{
guchar buffer[32];
CK_ATTRIBUTE attr = { 0, buffer, sizeof (buffer) };
@@ -471,7 +508,8 @@ TESTING_TEST(attribute_set_mpi)
gcry_mpi_release (mpi);
}
-TESTING_TEST(attribute_set_mpi_short)
+static void
+test_attribute_set_mpi_short (void)
{
guchar buffer[32];
CK_ATTRIBUTE attr = { 0, buffer, 2 };
@@ -488,7 +526,8 @@ TESTING_TEST(attribute_set_mpi_short)
gcry_mpi_release (mpi);
}
-TESTING_TEST(attribute_set_mpi_length)
+static void
+test_attribute_set_mpi_length (void)
{
CK_ATTRIBUTE attr = { 0, NULL, 0 };
gcry_mpi_t mpi;
@@ -504,7 +543,8 @@ TESTING_TEST(attribute_set_mpi_length)
gcry_mpi_release (mpi);
}
-TESTING_TEST(attribute_equal)
+static void
+test_attribute_equal (void)
{
/* Make sure we actually have two different strings */
gchar *val1 = g_strdup ("my-identifier");
@@ -520,7 +560,8 @@ TESTING_TEST(attribute_equal)
g_free (val2);
}
-TESTING_TEST(attribute_equal_same)
+static void
+test_attribute_equal_same (void)
{
CK_ATTRIBUTE attr = { CKA_ID, "my-identifier", 13 };
gboolean ret;
@@ -529,7 +570,8 @@ TESTING_TEST(attribute_equal_same)
g_assert (ret == TRUE);
}
-TESTING_TEST(attribute_equal_same_pointer)
+static void
+test_attribute_equal_same_pointer (void)
{
gchar *val = "my-identifier";
CK_ATTRIBUTE attr1 = { CKA_ID, val, 13 };
@@ -540,7 +582,8 @@ TESTING_TEST(attribute_equal_same_pointer)
g_assert (ret == TRUE);
}
-TESTING_TEST(attribute_equal_diff_types)
+static void
+test_attribute_equal_diff_types (void)
{
gchar *val = "my-identifier";
CK_ATTRIBUTE attr1 = { CKA_ID, val, 13 };
@@ -551,7 +594,8 @@ TESTING_TEST(attribute_equal_diff_types)
g_assert (ret == FALSE);
}
-TESTING_TEST(attribute_equal_diff_length)
+static void
+test_attribute_equal_diff_length (void)
{
CK_ATTRIBUTE attr1 = { CKA_ID, "my-identifier", 13 };
CK_ATTRIBUTE attr2 = { CKA_ID, "my-identifier", 2 };
@@ -561,7 +605,8 @@ TESTING_TEST(attribute_equal_diff_length)
g_assert (ret == FALSE);
}
-TESTING_TEST(attribute_equal_diff_value)
+static void
+test_attribute_equal_diff_value (void)
{
CK_ATTRIBUTE attr1 = { CKA_ID, "my-identifier", 13 };
CK_ATTRIBUTE attr2 = { CKA_ID, "xy-identifier", 13 };
@@ -571,7 +616,8 @@ TESTING_TEST(attribute_equal_diff_value)
g_assert (ret == FALSE);
}
-TESTING_TEST(attribute_hash)
+static void
+test_attribute_hash (void)
{
CK_ATTRIBUTE attr = { CKA_VALUE, "value", 5 };
guint hash;
@@ -581,7 +627,8 @@ TESTING_TEST(attribute_hash)
g_assert_cmpuint (hash, !=, 0U);
}
-TESTING_TEST(attribute_contains)
+static void
+test_attribute_contains (void)
{
CK_ATTRIBUTE attr = { CKA_ID, "my-identifier", 13 };
gboolean ret;
@@ -590,7 +637,8 @@ TESTING_TEST(attribute_contains)
g_assert (ret == TRUE);
}
-TESTING_TEST(attribute_contains_no_value)
+static void
+test_attribute_contains_no_value (void)
{
CK_ATTRIBUTE attr = { CKA_ID, "other-identifier", 16 };
gboolean ret;
@@ -599,7 +647,8 @@ TESTING_TEST(attribute_contains_no_value)
g_assert (ret == FALSE);
}
-TESTING_TEST(attribute_contains_no_type)
+static void
+test_attribute_contains_no_type (void)
{
CK_ATTRIBUTE attr = { CKA_VALUE, "value", 5 };
gboolean ret;
@@ -608,7 +657,8 @@ TESTING_TEST(attribute_contains_no_type)
g_assert (ret == FALSE);
}
-TESTING_TEST(attributes_find)
+static void
+test_attributes_find (void)
{
CK_ATTRIBUTE_PTR attr;
@@ -617,7 +667,8 @@ TESTING_TEST(attributes_find)
g_assert (attr->type == CKA_LABEL);
}
-TESTING_TEST(attributes_find_not_found)
+static void
+test_attributes_find_not_found (void)
{
CK_ATTRIBUTE_PTR attr;
@@ -625,7 +676,8 @@ TESTING_TEST(attributes_find_not_found)
g_assert (attr == NULL);
}
-TESTING_TEST(attribute_find_boolean)
+static void
+test_attribute_find_boolean (void)
{
gboolean value;
gboolean ret;
@@ -635,7 +687,8 @@ TESTING_TEST(attribute_find_boolean)
g_assert (value == TRUE);
}
-TESTING_TEST(attribute_find_boolean_no_type)
+static void
+test_attribute_find_boolean_no_type (void)
{
gboolean value;
gboolean ret;
@@ -644,7 +697,8 @@ TESTING_TEST(attribute_find_boolean_no_type)
g_assert (ret == FALSE);
}
-TESTING_TEST(attribute_find_boolean_not_bbool)
+static void
+test_attribute_find_boolean_not_bbool (void)
{
gboolean value;
gboolean ret;
@@ -653,7 +707,8 @@ TESTING_TEST(attribute_find_boolean_not_bbool)
g_assert (ret == FALSE);
}
-TESTING_TEST(attribute_find_ulong)
+static void
+test_attribute_find_ulong (void)
{
gulong value;
gboolean ret;
@@ -663,7 +718,8 @@ TESTING_TEST(attribute_find_ulong)
g_assert (value == CKO_DATA);
}
-TESTING_TEST(attribute_find_ulong_no_type)
+static void
+test_attribute_find_ulong_no_type (void)
{
gulong value;
gboolean ret;
@@ -672,7 +728,8 @@ TESTING_TEST(attribute_find_ulong_no_type)
g_assert (ret == FALSE);
}
-TESTING_TEST(attribute_find_ulong_not_ulong)
+static void
+test_attribute_find_ulong_not_ulong (void)
{
gulong value;
gboolean ret;
@@ -681,7 +738,8 @@ TESTING_TEST(attribute_find_ulong_not_ulong)
g_assert (ret == FALSE);
}
-TESTING_TEST(attribute_find_mpi)
+static void
+test_attribute_find_mpi (void)
{
gcry_mpi_t mpi = NULL;
gboolean ret;
@@ -694,7 +752,8 @@ TESTING_TEST(attribute_find_mpi)
gcry_mpi_release (mpi);
}
-TESTING_TEST(attribute_find_mpi_no_type)
+static void
+test_attribute_find_mpi_no_type (void)
{
gcry_mpi_t mpi = NULL;
gboolean ret;
@@ -704,7 +763,8 @@ TESTING_TEST(attribute_find_mpi_no_type)
g_assert (mpi == NULL);
}
-TESTING_TEST(attributes_consume)
+static void
+test_attributes_consume (void)
{
CK_ATTRIBUTE_PTR attrs;
CK_ULONG n_attrs;
@@ -729,14 +789,16 @@ TESTING_TEST(attributes_consume)
g_free (attrs);
}
-TESTING_TEST(template_new_free)
+static void
+test_template_new_free (void)
{
GArray *template = gkm_template_new (attr_template, G_N_ELEMENTS (attr_template));
g_assert (template);
gkm_template_free (template);
}
-TESTING_TEST(template_find)
+static void
+test_template_find (void)
{
GArray *template = gkm_template_new (attr_template, G_N_ELEMENTS (attr_template));
gulong uvalue;
@@ -757,7 +819,8 @@ TESTING_TEST(template_find)
gkm_template_free (template);
}
-TESTING_TEST(template_set_replace)
+static void
+test_template_set_replace (void)
{
GArray *template = gkm_template_new (attr_template, G_N_ELEMENTS (attr_template));
CK_OBJECT_CLASS klass = CKO_HW_FEATURE;
@@ -777,3 +840,74 @@ TESTING_TEST(template_set_replace)
gkm_template_free (template);
}
+
+int
+main (int argc, char **argv)
+{
+ g_type_init ();
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add_func ("/gkm/attributes/attribute_equal_zero_len_null_ptr", test_attribute_equal_zero_len_null_ptr);
+ g_test_add_func ("/gkm/attributes/attribute_consume", test_attribute_consume);
+ g_test_add_func ("/gkm/attributes/attribute_consumed", test_attribute_consumed);
+ g_test_add_func ("/gkm/attributes/attribute_set_data", test_attribute_set_data);
+ g_test_add_func ("/gkm/attributes/attribute_set_data_short", test_attribute_set_data_short);
+ g_test_add_func ("/gkm/attributes/attribute_set_data_length", test_attribute_set_data_length);
+ g_test_add_func ("/gkm/attributes/attribute_set_empty", test_attribute_set_empty);
+ g_test_add_func ("/gkm/attributes/attribute_get_bool", test_attribute_get_bool);
+ g_test_add_func ("/gkm/attributes/attribute_get_bool_invalid", test_attribute_get_bool_invalid);
+ g_test_add_func ("/gkm/attributes/attribute_set_time", test_attribute_set_time);
+ g_test_add_func ("/gkm/attributes/attribute_set_time_empty", test_attribute_set_time_empty);
+ g_test_add_func ("/gkm/attributes/attribute_set_time_length", test_attribute_set_time_length);
+ g_test_add_func ("/gkm/attributes/attribute_get_time", test_attribute_get_time);
+ g_test_add_func ("/gkm/attributes/attribute_get_time_empty", test_attribute_get_time_empty);
+ g_test_add_func ("/gkm/attributes/attribute_get_time_invalid", test_attribute_get_time_invalid);
+ g_test_add_func ("/gkm/attributes/attribute_get_time_invalid_length", test_attribute_get_time_invalid_length);
+ g_test_add_func ("/gkm/attributes/attribute_get_string", test_attribute_get_string);
+ g_test_add_func ("/gkm/attributes/attribute_get_string_null", test_attribute_get_string_null);
+ g_test_add_func ("/gkm/attributes/attribute_get_string_not_utf8", test_attribute_get_string_not_utf8);
+ g_test_add_func ("/gkm/attributes/attribute_get_string_bad_pointer", test_attribute_get_string_bad_pointer);
+ g_test_add_func ("/gkm/attributes/attribute_set_bool", test_attribute_set_bool);
+ g_test_add_func ("/gkm/attributes/attribute_set_bool_short", test_attribute_set_bool_short);
+ g_test_add_func ("/gkm/attributes/attribute_set_bool_length", test_attribute_set_bool_length);
+ g_test_add_func ("/gkm/attributes/attribute_set_ulong", test_attribute_set_ulong);
+ g_test_add_func ("/gkm/attributes/attribute_set_ulong_short", test_attribute_set_ulong_short);
+ g_test_add_func ("/gkm/attributes/attribute_set_ulong_length", test_attribute_set_ulong_length);
+ g_test_add_func ("/gkm/attributes/attribute_set_string", test_attribute_set_string);
+ g_test_add_func ("/gkm/attributes/attribute_set_string_null", test_attribute_set_string_null);
+ g_test_add_func ("/gkm/attributes/attribute_set_string_short", test_attribute_set_string_short);
+ g_test_add_func ("/gkm/attributes/attribute_set_string_length", test_attribute_set_string_length);
+ g_test_add_func ("/gkm/attributes/attribute_set_date", test_attribute_set_date);
+ g_test_add_func ("/gkm/attributes/attribute_set_date_none", test_attribute_set_date_none);
+ g_test_add_func ("/gkm/attributes/attribute_set_date_short", test_attribute_set_date_short);
+ g_test_add_func ("/gkm/attributes/attribute_set_date_length", test_attribute_set_date_length);
+ g_test_add_func ("/gkm/attributes/attribute_set_mpi", test_attribute_set_mpi);
+ g_test_add_func ("/gkm/attributes/attribute_set_mpi_short", test_attribute_set_mpi_short);
+ g_test_add_func ("/gkm/attributes/attribute_set_mpi_length", test_attribute_set_mpi_length);
+ g_test_add_func ("/gkm/attributes/attribute_equal", test_attribute_equal);
+ g_test_add_func ("/gkm/attributes/attribute_equal_same", test_attribute_equal_same);
+ g_test_add_func ("/gkm/attributes/attribute_equal_same_pointer", test_attribute_equal_same_pointer);
+ g_test_add_func ("/gkm/attributes/attribute_equal_diff_types", test_attribute_equal_diff_types);
+ g_test_add_func ("/gkm/attributes/attribute_equal_diff_length", test_attribute_equal_diff_length);
+ g_test_add_func ("/gkm/attributes/attribute_equal_diff_value", test_attribute_equal_diff_value);
+ g_test_add_func ("/gkm/attributes/attribute_hash", test_attribute_hash);
+ g_test_add_func ("/gkm/attributes/attribute_contains", test_attribute_contains);
+ g_test_add_func ("/gkm/attributes/attribute_contains_no_value", test_attribute_contains_no_value);
+ g_test_add_func ("/gkm/attributes/attribute_contains_no_type", test_attribute_contains_no_type);
+ g_test_add_func ("/gkm/attributes/attributes_find", test_attributes_find);
+ g_test_add_func ("/gkm/attributes/attributes_find_not_found", test_attributes_find_not_found);
+ g_test_add_func ("/gkm/attributes/attribute_find_boolean", test_attribute_find_boolean);
+ g_test_add_func ("/gkm/attributes/attribute_find_boolean_no_type", test_attribute_find_boolean_no_type);
+ g_test_add_func ("/gkm/attributes/attribute_find_boolean_not_bbool", test_attribute_find_boolean_not_bbool);
+ g_test_add_func ("/gkm/attributes/attribute_find_ulong", test_attribute_find_ulong);
+ g_test_add_func ("/gkm/attributes/attribute_find_ulong_no_type", test_attribute_find_ulong_no_type);
+ g_test_add_func ("/gkm/attributes/attribute_find_ulong_not_ulong", test_attribute_find_ulong_not_ulong);
+ g_test_add_func ("/gkm/attributes/attribute_find_mpi", test_attribute_find_mpi);
+ g_test_add_func ("/gkm/attributes/attribute_find_mpi_no_type", test_attribute_find_mpi_no_type);
+ g_test_add_func ("/gkm/attributes/attributes_consume", test_attributes_consume);
+ g_test_add_func ("/gkm/attributes/template_new_free", test_template_new_free);
+ g_test_add_func ("/gkm/attributes/template_find", test_template_find);
+ g_test_add_func ("/gkm/attributes/template_set_replace", test_template_set_replace);
+
+ return g_test_run ();
+}
diff --git a/pkcs11/gkm/tests/unit-test-credential.c b/pkcs11/gkm/tests/test-credential.c
similarity index 58%
rename from pkcs11/gkm/tests/unit-test-credential.c
rename to pkcs11/gkm/tests/test-credential.c
index 40b605e..5a7b70e 100644
--- a/pkcs11/gkm/tests/unit-test-credential.c
+++ b/pkcs11/gkm/tests/test-credential.c
@@ -1,5 +1,5 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* unit-test-timer.c: Test thread timer functionality
+/* test-credential.c: Test credentials
Copyright (C) 2009 Stefan Walter
@@ -21,8 +21,9 @@
Author: Stef Walter <stef memberwebs com>
*/
-#include "test-suite.h"
-#include "test-module.h"
+#include "config.h"
+
+#include "mock-module.h"
#include "mock-locked-object.h"
#include "gkm/gkm-attributes.h"
@@ -34,37 +35,38 @@
#include "pkcs11i.h"
-static GkmModule *module = NULL;
-static GkmSession *session = NULL;
-static GkmObject *object = NULL;
+typedef struct {
+ GkmModule *module;
+ GkmSession *session;
+ GkmObject *object;
+} Test;
-TESTING_SETUP(credential_setup)
+static void
+setup (Test *test, gconstpointer unused)
{
CK_RV rv;
- module = test_module_initialize_and_enter ();
- session = test_module_open_session (TRUE);
+ test->module = mock_module_initialize_and_enter ();
+ test->session = mock_module_open_session (TRUE);
- rv = gkm_module_C_Login (module, gkm_session_get_handle (session), CKU_USER, NULL, 0);
+ rv = gkm_module_C_Login (test->module, gkm_session_get_handle (test->session), CKU_USER, NULL, 0);
g_assert (rv == CKR_OK);
- object = mock_locked_object_new (module, gkm_module_get_manager (module));
- gkm_object_expose (object, TRUE);
+ test->object = mock_locked_object_new (test->module, gkm_module_get_manager (test->module));
+ gkm_object_expose (test->object, TRUE);
}
-TESTING_TEARDOWN(credential_teardown)
+static void
+teardown (Test *test, gconstpointer unused)
{
- g_object_unref (object);
- object = NULL;
-
- test_module_leave_and_finalize ();
- module = NULL;
- session = NULL;
+ g_object_unref (test->object);
+ mock_module_leave_and_finalize ();
}
-TESTING_TEST(credential_create)
+static void
+test_create (Test *test, gconstpointer unused)
{
CK_OBJECT_CLASS klass = CKO_G_CREDENTIAL;
- CK_OBJECT_HANDLE locked = gkm_object_get_handle (object);
+ CK_OBJECT_HANDLE locked = gkm_object_get_handle (test->object);
CK_ATTRIBUTE attrs[] = {
{ CKA_CLASS, &klass, sizeof (klass) },
@@ -75,18 +77,19 @@ TESTING_TEST(credential_create)
CK_OBJECT_HANDLE handle;
CK_RV rv;
- rv = gkm_session_C_CreateObject (session, attrs, G_N_ELEMENTS (attrs), &handle);
+ rv = gkm_session_C_CreateObject (test->session, attrs, G_N_ELEMENTS (attrs), &handle);
g_assert (rv == CKR_OK);
g_assert (handle != 0);
- rv = gkm_session_C_DestroyObject (session, handle);
+ rv = gkm_session_C_DestroyObject (test->session, handle);
g_assert (rv == CKR_OK);
}
-TESTING_TEST(credential_create_missing_pin)
+static void
+test_create_missing_pin (Test *test, gconstpointer unused)
{
CK_OBJECT_CLASS klass = CKO_G_CREDENTIAL;
- CK_OBJECT_HANDLE locked = gkm_object_get_handle (object);
+ CK_OBJECT_HANDLE locked = gkm_object_get_handle (test->object);
CK_ATTRIBUTE attrs[] = {
{ CKA_CLASS, &klass, sizeof (klass) },
@@ -96,11 +99,12 @@ TESTING_TEST(credential_create_missing_pin)
CK_OBJECT_HANDLE handle;
CK_RV rv;
- rv = gkm_session_C_CreateObject (session, attrs, G_N_ELEMENTS (attrs), &handle);
+ rv = gkm_session_C_CreateObject (test->session, attrs, G_N_ELEMENTS (attrs), &handle);
g_assert (rv == CKR_USER_NOT_LOGGED_IN);
}
-TESTING_TEST(credential_create_no_object)
+static void
+test_create_no_object (Test *test, gconstpointer unused)
{
CK_OBJECT_CLASS klass = CKO_G_CREDENTIAL;
CK_BBOOL token = CK_FALSE;
@@ -115,19 +119,20 @@ TESTING_TEST(credential_create_no_object)
CK_OBJECT_HANDLE handle;
CK_RV rv;
- rv = gkm_session_C_CreateObject (session, attrs, G_N_ELEMENTS (attrs), &handle);
+ rv = gkm_session_C_CreateObject (test->session, attrs, G_N_ELEMENTS (attrs), &handle);
g_assert (rv == CKR_OK);
g_assert (handle != 0);
attr.type = CKA_G_OBJECT;
attr.pValue = &objhand;
attr.ulValueLen = sizeof (objhand);
- rv = gkm_session_C_GetAttributeValue (session, handle, &attr, 1);
+ rv = gkm_session_C_GetAttributeValue (test->session, handle, &attr, 1);
g_assert (rv == CKR_OK);
g_assert (objhand == 0);
}
-TESTING_TEST(credential_create_invalid_object)
+static void
+test_create_invalid_object (Test *test, gconstpointer unused)
{
CK_OBJECT_CLASS klass = CKO_G_CREDENTIAL;
CK_OBJECT_HANDLE locked = 0;
@@ -142,14 +147,15 @@ TESTING_TEST(credential_create_invalid_object)
CK_OBJECT_HANDLE handle;
CK_RV rv;
- rv = gkm_session_C_CreateObject (session, attrs, G_N_ELEMENTS (attrs), &handle);
+ rv = gkm_session_C_CreateObject (test->session, attrs, G_N_ELEMENTS (attrs), &handle);
g_assert (rv == CKR_OBJECT_HANDLE_INVALID);
}
-TESTING_TEST(credential_get_attributes)
+static void
+test_get_attributes (Test *test, gconstpointer unused)
{
CK_OBJECT_CLASS klass = CKO_G_CREDENTIAL;
- CK_OBJECT_HANDLE locked = gkm_object_get_handle (object);
+ CK_OBJECT_HANDLE locked = gkm_object_get_handle (test->object);
CK_ATTRIBUTE attrs[] = {
{ CKA_CLASS, &klass, sizeof (klass) },
@@ -162,7 +168,7 @@ TESTING_TEST(credential_get_attributes)
CK_ULONG value;
CK_RV rv;
- rv = gkm_session_C_CreateObject (session, attrs, G_N_ELEMENTS (attrs), &handle);
+ rv = gkm_session_C_CreateObject (test->session, attrs, G_N_ELEMENTS (attrs), &handle);
g_assert (rv == CKR_OK);
g_assert (handle != 0);
@@ -170,33 +176,35 @@ TESTING_TEST(credential_get_attributes)
check.pValue = &value;
check.ulValueLen = sizeof (value);
- rv = gkm_session_C_GetAttributeValue (session, handle, &check, 1);
+ rv = gkm_session_C_GetAttributeValue (test->session, handle, &check, 1);
g_assert (rv == CKR_OK);
g_assert (check.ulValueLen == sizeof (value));
g_assert (value == locked);
}
-TESTING_TEST(credential_object_property)
+static void
+test_object_property (Test *test, gconstpointer unused)
{
GkmCredential *auth;
GkmObject *check;
CK_RV rv;
- rv = gkm_credential_create (module, NULL, object, (guchar*)"mock", 4, &auth);
+ rv = gkm_credential_create (test->module, NULL, test->object, (guchar*)"mock", 4, &auth);
g_assert (rv == CKR_OK);
g_assert (auth);
g_object_get (auth, "object", &check, NULL);
- g_assert (check == object);
+ g_assert (check == test->object);
g_object_unref (check);
check = gkm_credential_get_object (auth);
- g_assert (check == object);
+ g_assert (check == test->object);
g_object_unref (auth);
}
-TESTING_TEST(credential_login_property)
+static void
+test_login_property (Test *test, gconstpointer unused)
{
GkmCredential *cred;
GkmSecret *check, *secret;
@@ -204,7 +212,7 @@ TESTING_TEST(credential_login_property)
gsize n_password;
CK_RV rv;
- rv = gkm_credential_create (module, NULL, object, (guchar*)"mock", 4, &cred);
+ rv = gkm_credential_create (test->module, NULL, test->object, (guchar*)"mock", 4, &cred);
g_assert (rv == CKR_OK);
g_assert (cred);
@@ -239,14 +247,15 @@ boxed_string (void)
return type;
}
-TESTING_TEST(credential_data)
+static void
+test_data (Test *test, gconstpointer unused)
{
GkmCredential *cred;
GType type = boxed_string ();
gchar *check;
CK_RV rv;
- rv = gkm_credential_create (module, NULL, object, (guchar*)"mock", 4, &cred);
+ rv = gkm_credential_create (test->module, NULL, test->object, (guchar*)"mock", 4, &cred);
g_assert (rv == CKR_OK);
g_assert (cred);
@@ -269,17 +278,37 @@ TESTING_TEST(credential_data)
g_object_unref (cred);
}
-TESTING_TEST(credential_connect_object)
+static void
+test_connect_object (Test *test, gconstpointer unused)
{
GkmCredential *cred;
CK_RV rv;
- rv = gkm_credential_create (module, NULL, NULL, (guchar*)"mock", 4, &cred);
+ rv = gkm_credential_create (test->module, NULL, NULL, (guchar*)"mock", 4, &cred);
g_assert (rv == CKR_OK);
g_assert (cred);
- gkm_credential_connect (cred, object);
- g_assert (gkm_credential_get_object (cred) == object);
+ gkm_credential_connect (cred, test->object);
+ g_assert (gkm_credential_get_object (cred) == test->object);
g_object_unref (cred);
}
+
+int
+main (int argc, char **argv)
+{
+ g_type_init ();
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add ("/gkm/credential/create", Test, NULL, setup, test_create, teardown);
+ g_test_add ("/gkm/credential/create_missing_pin", Test, NULL, setup, test_create_missing_pin, teardown);
+ g_test_add ("/gkm/credential/create_no_object", Test, NULL, setup, test_create_no_object, teardown);
+ g_test_add ("/gkm/credential/create_invalid_object", Test, NULL, setup, test_create_invalid_object, teardown);
+ g_test_add ("/gkm/credential/get_attributes", Test, NULL, setup, test_get_attributes, teardown);
+ g_test_add ("/gkm/credential/object_property", Test, NULL, setup, test_object_property, teardown);
+ g_test_add ("/gkm/credential/login_property", Test, NULL, setup, test_login_property, teardown);
+ g_test_add ("/gkm/credential/data", Test, NULL, setup, test_data, teardown);
+ g_test_add ("/gkm/credential/connect_object", Test, NULL, setup, test_connect_object, teardown);
+
+ return g_test_run ();
+}
diff --git a/pkcs11/gkm/tests/unit-test-data-asn1.c b/pkcs11/gkm/tests/test-data-asn1.c
similarity index 71%
rename from pkcs11/gkm/tests/unit-test-data-asn1.c
rename to pkcs11/gkm/tests/test-data-asn1.c
index dc7ef6d..d6e3dec 100644
--- a/pkcs11/gkm/tests/unit-test-data-asn1.c
+++ b/pkcs11/gkm/tests/test-data-asn1.c
@@ -1,5 +1,5 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* unit-test-data-asn1.c: Test ASN.1 routines
+/* test-data-asn1.c: Test ASN.1 routines
Copyright (C) 2007 Stefan Walter
@@ -23,11 +23,10 @@
#include "config.h"
-#include "test-suite.h"
-
#include "gkm/gkm-data-asn1.h"
#include <glib.h>
+#include <glib-object.h>
#include <gcrypt.h>
#include <stdlib.h>
@@ -39,25 +38,31 @@
#include "asn1-def-test.h"
-static GNode *asn1_cert = NULL;
-static guchar *data_cert = NULL;
-static gsize n_data_cert = 0;
+typedef struct {
+ GNode *asn1_cert;
+ gchar *data_cert;
+ gsize n_data_cert;
+} Test;
-TESTING_SETUP(asn1_tree)
+static void
+setup (Test *test, gconstpointer unused)
{
- data_cert = testing_data_read ("test-certificate-1.der", &n_data_cert);
- asn1_cert = egg_asn1x_create_and_decode (pkix_asn1_tab, "Certificate", data_cert, n_data_cert);
- g_assert (asn1_cert);
+ if (!g_file_get_contents ("files/test-certificate-1.der", &test->data_cert, &test->n_data_cert, NULL))
+ g_assert_not_reached ();
+
+ test->asn1_cert = egg_asn1x_create_and_decode (pkix_asn1_tab, "Certificate", test->data_cert, test->n_data_cert);
+ g_assert (test->asn1_cert);
}
-TESTING_TEARDOWN(asn1_tree)
+static void
+teardown (Test *test, gconstpointer unused)
{
- egg_asn1x_destroy (asn1_cert);
- g_free (data_cert);
- data_cert = NULL;
+ egg_asn1x_destroy (test->asn1_cert);
+ g_free (test->data_cert);
}
-TESTING_TEST(asn1_integers)
+static void
+test_asn1_integers (Test *test, gconstpointer unused)
{
GNode *asn;
gcry_mpi_t mpi, mpt;
@@ -93,3 +98,14 @@ TESTING_TEST(asn1_integers)
g_free (data);
}
+
+int
+main (int argc, char **argv)
+{
+ g_type_init ();
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add ("/gkm/data-asn1/integers", Test, NULL, setup, test_asn1_integers, teardown);
+
+ return g_test_run ();
+}
diff --git a/pkcs11/gkm/tests/unit-test-data-der.c b/pkcs11/gkm/tests/test-data-der.c
similarity index 71%
rename from pkcs11/gkm/tests/unit-test-data-der.c
rename to pkcs11/gkm/tests/test-data-der.c
index a6aba53..f3b7ab1 100644
--- a/pkcs11/gkm/tests/unit-test-data-der.c
+++ b/pkcs11/gkm/tests/test-data-der.c
@@ -23,8 +23,6 @@
#include "config.h"
-#include "test-suite.h"
-
#include "gkm/gkm-crypto.h"
#include "gkm/gkm-data-asn1.h"
#include "gkm/gkm-data-der.h"
@@ -42,13 +40,16 @@
#include <stdio.h>
#include <string.h>
-static GNode *certificate = NULL;
-static guchar *certificate_data = NULL;
-static gsize n_certificate_data = 0;
+EGG_SECURE_GLIB_DEFINITIONS ();
-static GNode *certificate2 = NULL;
-static guchar *certificate2_data = NULL;
-static gsize n_certificate2_data = 0;
+typedef struct {
+ GNode *certificate;
+ gchar *certificate_data;
+ gsize n_certificate_data;
+ GNode *certificate2;
+ gchar *certificate2_data;
+ gsize n_certificate2_data;
+} Test;
const gchar *rsapub = "(public-key (rsa" \
" (n #00AE4B381CF43F7DC24CF90827325E2FB2EB57EDDE29562DF391C8942AA8E6423410E2D3FE26381F9DE0395E74BF2D17621AE46992C72CF895F6FA5FBE98054FBF#)" \
@@ -112,29 +113,30 @@ test_der_public (gcry_sexp_t key)
g_assert ("key parsed differently" && compare_keys (key, sexp));
}
-TESTING_SETUP(preload)
+static void
+setup (Test *test, gconstpointer unused)
{
- certificate_data = testing_data_read ("test-certificate-1.der", &n_certificate_data);
- certificate = egg_asn1x_create_and_decode (pkix_asn1_tab, "Certificate", certificate_data, n_certificate_data);
- g_assert (certificate);
-
- certificate2_data = testing_data_read ("test-certificate-2.der", &n_certificate2_data);
- certificate2 = egg_asn1x_create_and_decode (pkix_asn1_tab, "Certificate", certificate2_data, n_certificate2_data);
- g_assert (certificate2);
+ if (!g_file_get_contents ("files/test-certificate-1.der", &test->certificate_data, &test->n_certificate_data, NULL))
+ g_assert_not_reached ();
+ test->certificate = egg_asn1x_create_and_decode (pkix_asn1_tab, "Certificate", test->certificate_data, test->n_certificate_data);
+ g_assert (test->certificate);
+ if (!g_file_get_contents ("files/test-certificate-2.der", &test->certificate2_data, &test->n_certificate2_data, NULL))
+ g_assert_not_reached ();
+ test->certificate2 = egg_asn1x_create_and_decode (pkix_asn1_tab, "Certificate", test->certificate2_data, test->n_certificate2_data);
+ g_assert (test->certificate2);
}
-TESTING_TEARDOWN(preload)
+static void
+teardown (Test *test, gconstpointer unused)
{
- egg_asn1x_destroy (certificate);
- g_free (certificate_data);
- certificate_data = NULL;
-
- egg_asn1x_destroy (certificate2);
- g_free (certificate2_data);
- certificate2_data = NULL;
+ egg_asn1x_destroy (test->certificate);
+ g_free (test->certificate_data);
+ egg_asn1x_destroy (test->certificate2);
+ g_free (test->certificate2_data);
}
-TESTING_TEST(der_rsa_public)
+static void
+test_der_rsa_public (Test *test, gconstpointer unused)
{
gcry_sexp_t key;
gcry_error_t gcry;
@@ -145,7 +147,8 @@ TESTING_TEST(der_rsa_public)
test_der_public (key);
}
-TESTING_TEST(der_dsa_public)
+static void
+test_der_dsa_public (Test *test, gconstpointer unused)
{
gcry_sexp_t key;
gcry_error_t gcry;
@@ -180,7 +183,8 @@ test_der_private (gcry_sexp_t key)
egg_secure_free (data);
}
-TESTING_TEST(der_rsa_private)
+static void
+test_der_rsa_private (Test *test, gconstpointer unused)
{
gcry_sexp_t key;
gcry_error_t gcry;
@@ -191,7 +195,8 @@ TESTING_TEST(der_rsa_private)
test_der_private (key);
}
-TESTING_TEST(der_dsa_private)
+static void
+test_der_dsa_private (Test *test, gconstpointer unused)
{
gcry_sexp_t key;
gcry_error_t gcry;
@@ -202,7 +207,8 @@ TESTING_TEST(der_dsa_private)
test_der_private (key);
}
-TESTING_TEST(der_dsa_private_parts)
+static void
+test_der_dsa_private_parts (Test *test, gconstpointer unused)
{
guchar *params, *key;
gsize n_params, n_key;
@@ -235,7 +241,8 @@ const gchar *certpub = "(public-key (rsa " \
"(n #00C966D9F80744CFB98C2EF0A1EF13456C05DFDE2716513641116C6C3BEDFE107D129EE59B429AFE6031C366B7733A48AE4ED032379488B50DB6D9F3F244D9D58812DD764DF21AFC6F231E7AF1D898454E0710EF1642D043756D4ADEE2AAC931FF1F00707C66CF102508BAFAEE00E94603662711153BAA5BF298DD3642B2DA8875#) " \
"(e #010001#) ) )";
-TESTING_TEST(read_public_key_info)
+static void
+test_read_public_key_info (Test *test, gconstpointer unused)
{
const guchar *data;
guchar hash[20];
@@ -244,7 +251,7 @@ TESTING_TEST(read_public_key_info)
gcry_sexp_t sexp, match;
gcry_error_t gcry;
- data = egg_asn1x_get_raw_element (egg_asn1x_node (certificate, "tbsCertificate", "subjectPublicKeyInfo", NULL), &n_data);
+ data = egg_asn1x_get_raw_element (egg_asn1x_node (test->certificate, "tbsCertificate", "subjectPublicKeyInfo", NULL), &n_data);
g_assert (data);
res = gkm_data_der_read_public_key_info (data, n_data, &sexp);
@@ -263,27 +270,29 @@ TESTING_TEST(read_public_key_info)
gcry_sexp_release (match);
}
-TESTING_TEST(read_certificate)
+static void
+test_read_certificate (Test *test, gconstpointer unused)
{
GNode *asn = NULL;
GkmDataResult res;
- res = gkm_data_der_read_certificate (certificate_data, n_certificate_data, &asn);
+ res = gkm_data_der_read_certificate (test->certificate_data, test->n_certificate_data, &asn);
g_assert (res == GKM_DATA_SUCCESS);
g_assert (asn != NULL);
egg_asn1x_destroy (asn);
}
-TESTING_TEST(write_certificate)
+static void
+test_write_certificate (Test *test, gconstpointer unused)
{
guchar *data;
gsize n_data;
- data = gkm_data_der_write_certificate (certificate, &n_data);
+ data = gkm_data_der_write_certificate (test->certificate, &n_data);
g_assert (data);
- g_assert (n_data == n_certificate_data);
- g_assert (memcmp (data, certificate_data, n_data) == 0);
+ g_assert (n_data == test->n_certificate_data);
+ g_assert (memcmp (data, test->certificate_data, n_data) == 0);
g_free (data);
}
@@ -303,7 +312,7 @@ on_ca_certificate_public_key_info (GQuark type, const guchar *data, gsize n_data
res = gkm_data_der_read_certificate (data, n_data, &asn1);
g_assert (res == GKM_DATA_SUCCESS);
- /* Generate a raw public key from our certificate */
+ /* Generate a raw public key from our test->certificate */
keydata = egg_asn1x_encode (egg_asn1x_node (asn1, "tbsCertificate", "subjectPublicKeyInfo", NULL), NULL, &n_keydata);
g_assert (keydata);
@@ -316,18 +325,20 @@ on_ca_certificate_public_key_info (GQuark type, const guchar *data, gsize n_data
g_free (keydata);
}
-TESTING_TEST(read_ca_certificates_public_key_info)
+static void
+test_read_ca_certificates_public_key_info (Test *test, gconstpointer unused)
{
- gpointer data;
+ gchar *data;
gsize n_data;
- data = testing_data_read ("ca-certificates.crt", &n_data);
+ if (!g_file_get_contents ("files/ca-certificates.crt", &data, &n_data, NULL))
+ g_assert_not_reached ();
egg_openssl_pem_parse (data, n_data, on_ca_certificate_public_key_info, NULL);
g_free (data);
}
static const guchar*
-find_extension (GNode *asn, const guchar *data, gsize n_data, const gchar *oid, gsize *n_extension)
+find_extension (GNode *asn, gconstpointer data, gsize n_data, const gchar *oid, gsize *n_extension)
{
const guchar *value;
GNode *node = NULL;
@@ -361,7 +372,8 @@ find_extension (GNode *asn, const guchar *data, gsize n_data, const gchar *oid,
g_assert_not_reached ();
}
-TESTING_TEST(read_basic_constraints)
+static void
+test_read_basic_constraints (Test *test, gconstpointer unused)
{
const guchar *extension;
gsize n_extension;
@@ -369,8 +381,8 @@ TESTING_TEST(read_basic_constraints)
gint path_len;
GkmDataResult res;
- extension = egg_asn1x_get_raw_value (egg_asn1x_node (certificate, "tbsCertificate", "extensions", 1, "extnValue", NULL),
- &n_extension);
+ extension = egg_asn1x_get_raw_value (egg_asn1x_node (test->certificate, "tbsCertificate", "extensions", 1, "extnValue", NULL),
+ &n_extension);
g_assert (extension);
res = gkm_data_der_read_basic_constraints (extension, n_extension, &is_ca, &path_len);
@@ -379,14 +391,15 @@ TESTING_TEST(read_basic_constraints)
g_assert (path_len == -1);
}
-TESTING_TEST(read_key_usage)
+static void
+test_read_key_usage (Test *test, gconstpointer unused)
{
const guchar *extension;
gsize n_extension;
gulong key_usage;
GkmDataResult res;
- extension = find_extension (certificate2, certificate2_data, n_certificate2_data, "2.5.29.15", &n_extension);
+ extension = find_extension (test->certificate2, test->certificate2_data, test->n_certificate2_data, "2.5.29.15", &n_extension);
g_assert (extension);
res = gkm_data_der_read_key_usage (extension, n_extension, &key_usage);
@@ -394,14 +407,15 @@ TESTING_TEST(read_key_usage)
g_assert_cmpuint (key_usage, ==, 0x01);
}
-TESTING_TEST(read_enhanced_usage)
+static void
+test_read_enhanced_usage (Test *test, gconstpointer unused)
{
const guchar *extension;
gsize n_extension;
GQuark *usages;
GkmDataResult res;
- extension = find_extension (certificate2, certificate2_data, n_certificate2_data, "2.5.29.37", &n_extension);
+ extension = find_extension (test->certificate2, test->certificate2_data, test->n_certificate2_data, "2.5.29.37", &n_extension);
g_assert (extension);
res = gkm_data_der_read_enhanced_usage (extension, n_extension, &usages);
@@ -410,16 +424,18 @@ TESTING_TEST(read_enhanced_usage)
g_free (usages);
}
-TESTING_TEST(read_all_pkcs8)
+static void
+test_read_all_pkcs8 (Test *test, gconstpointer unused)
{
gcry_sexp_t sexp;
GkmDataResult res;
GDir *dir;
const gchar *name;
- guchar *data;
+ gchar *data;
gsize n_data;
+ gchar *path;
- dir = g_dir_open (testing_data_directory (), 0, NULL);
+ dir = g_dir_open ("files", 0, NULL);
g_assert (dir);
for(;;) {
@@ -430,7 +446,11 @@ TESTING_TEST(read_all_pkcs8)
if (!g_pattern_match_simple ("der-pkcs8-*", name))
continue;
- data = testing_data_read (name, &n_data);
+ path = g_build_filename ("files", name, NULL);
+ if (!g_file_get_contents (path, &data, &n_data, NULL))
+ g_assert_not_reached ();
+ g_free (path);
+
res = gkm_data_der_read_private_pkcs8 (data, n_data, "booo", 4, &sexp);
g_assert (res == GKM_DATA_SUCCESS);
@@ -442,21 +462,25 @@ TESTING_TEST(read_all_pkcs8)
g_dir_close (dir);
}
-TESTING_TEST(read_pkcs8_bad_password)
+static void
+test_read_pkcs8_bad_password (Test *test, gconstpointer unused)
{
gcry_sexp_t sexp;
GkmDataResult res;
- guchar *data;
+ gchar *data;
gsize n_data;
- data = testing_data_read ("der-pkcs8-encrypted-pkcs5.key", &n_data);
+ if (!g_file_get_contents ("files/der-pkcs8-encrypted-pkcs5.key", &data, &n_data, NULL))
+ g_assert_not_reached ();
+
res = gkm_data_der_read_private_pkcs8 (data, n_data, "wrong password", 4, &sexp);
g_assert (res == GKM_DATA_LOCKED);
g_free (data);
}
-TESTING_TEST(write_pkcs8_plain)
+static void
+test_write_pkcs8_plain (Test *test, gconstpointer unused)
{
gcry_sexp_t sexp, check;
gcry_error_t gcry;
@@ -503,7 +527,8 @@ TESTING_TEST(write_pkcs8_plain)
}
-TESTING_TEST(write_pkcs8_encrypted)
+static void
+test_write_pkcs8_encrypted (Test *test, gconstpointer unused)
{
gcry_sexp_t sexp, check;
gcry_error_t gcry;
@@ -548,3 +573,29 @@ TESTING_TEST(write_pkcs8_encrypted)
gcry_sexp_release (sexp);
gcry_sexp_release (check);
}
+
+int
+main (int argc, char **argv)
+{
+ g_type_init ();
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add ("/gkm/data-der/der_rsa_public", Test, NULL, setup, test_der_rsa_public, teardown);
+ g_test_add ("/gkm/data-der/der_dsa_public", Test, NULL, setup, test_der_dsa_public, teardown);
+ g_test_add ("/gkm/data-der/der_rsa_private", Test, NULL, setup, test_der_rsa_private, teardown);
+ g_test_add ("/gkm/data-der/der_dsa_private", Test, NULL, setup, test_der_dsa_private, teardown);
+ g_test_add ("/gkm/data-der/der_dsa_private_parts", Test, NULL, setup, test_der_dsa_private_parts, teardown);
+ g_test_add ("/gkm/data-der/read_public_key_info", Test, NULL, setup, test_read_public_key_info, teardown);
+ g_test_add ("/gkm/data-der/read_certificate", Test, NULL, setup, test_read_certificate, teardown);
+ g_test_add ("/gkm/data-der/write_certificate", Test, NULL, setup, test_write_certificate, teardown);
+ g_test_add ("/gkm/data-der/read_ca_certificates_public_key_info", Test, NULL, setup, test_read_ca_certificates_public_key_info, teardown);
+ g_test_add ("/gkm/data-der/read_basic_constraints", Test, NULL, setup, test_read_basic_constraints, teardown);
+ g_test_add ("/gkm/data-der/read_key_usage", Test, NULL, setup, test_read_key_usage, teardown);
+ g_test_add ("/gkm/data-der/read_enhanced_usage", Test, NULL, setup, test_read_enhanced_usage, teardown);
+ g_test_add ("/gkm/data-der/read_all_pkcs8", Test, NULL, setup, test_read_all_pkcs8, teardown);
+ g_test_add ("/gkm/data-der/read_pkcs8_bad_password", Test, NULL, setup, test_read_pkcs8_bad_password, teardown);
+ g_test_add ("/gkm/data-der/write_pkcs8_plain", Test, NULL, setup, test_write_pkcs8_plain, teardown);
+ g_test_add ("/gkm/data-der/write_pkcs8_encrypted", Test, NULL, setup, test_write_pkcs8_encrypted, teardown);
+
+ return g_test_run ();
+}
diff --git a/pkcs11/gkm/tests/test-file-tracker.c b/pkcs11/gkm/tests/test-file-tracker.c
new file mode 100644
index 0000000..1e606e3
--- /dev/null
+++ b/pkcs11/gkm/tests/test-file-tracker.c
@@ -0,0 +1,244 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* test-file-tracker.c: File tracker tests
+
+ Copyright (C) 2007 Stefan Walter
+
+ The Gnome Keyring Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The Gnome Keyring Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the Gnome Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Author: Stef Walter <stef memberwebs com>
+*/
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "gkm/gkm-file-tracker.h"
+
+#include <glib/gstdio.h>
+
+#define DATA "test-data"
+#define SUBDIR "test-subdir"
+#define WILDCARD "*.woo?"
+
+typedef struct {
+ GkmFileTracker *the_tracker;
+ gchar *test_dir;
+ gchar *test_file;
+ guint n_files_added;
+ gchar* last_file_added;
+ guint n_files_changed;
+ gchar* last_file_changed;
+ guint n_files_removed;
+ gchar* last_file_removed;
+} Test;
+
+static void
+file_added (GkmFileTracker *tracker, const gchar *path, gpointer user_data)
+{
+ Test *test = user_data;
+
+ g_assert ("should be a non-null path" && path != NULL);
+
+ ++test->n_files_added;
+ g_free (test->last_file_added);
+ test->last_file_added = g_strdup (path);
+}
+
+static void
+file_changed (GkmFileTracker *tracker, const gchar *path, gpointer user_data)
+{
+ Test *test = user_data;
+
+ g_assert ("should be a non-null path" && path != NULL);
+
+ ++test->n_files_changed;
+ g_free (test->last_file_changed);
+ test->last_file_changed = g_strdup (path);
+}
+
+static void
+file_removed (GkmFileTracker *tracker, const gchar *path, gpointer user_data)
+{
+ Test *test = user_data;
+
+ g_assert ("should be a non-null path" && path != NULL);
+
+ ++test->n_files_removed;
+ g_free (test->last_file_removed);
+ test->last_file_removed = g_strdup (path);
+}
+
+static void
+file_reset_stats (Test *test)
+{
+ g_free (test->last_file_removed);
+ g_free (test->last_file_added);
+ g_free (test->last_file_changed);
+ test->last_file_removed = test->last_file_added = test->last_file_changed = NULL;
+ test->n_files_added = test->n_files_changed = test->n_files_removed = 0;
+}
+
+static void
+setup (Test *test, gconstpointer unused)
+{
+ /* Make a test directory */
+ test->test_dir = g_build_filename ("/tmp", SUBDIR, NULL);
+
+ test->the_tracker = gkm_file_tracker_new (test->test_dir, WILDCARD, NULL);
+ g_signal_connect (test->the_tracker, "file-added", G_CALLBACK (file_added), test);
+ g_signal_connect (test->the_tracker, "file-removed", G_CALLBACK (file_removed), test);
+ g_signal_connect (test->the_tracker, "file-changed", G_CALLBACK (file_changed), test);
+
+ /* Mtime must change so wait between tests */
+ sleep (1);
+
+ test->test_file = g_build_filename (test->test_dir, "my-file.woof", NULL);
+ g_unlink (test->test_file);
+}
+
+static void
+teardown (Test *test, gconstpointer unused)
+{
+ file_reset_stats (test);
+ g_object_unref (test->the_tracker);
+ g_free (test->test_dir);
+ g_free (test->test_file);
+}
+
+static void
+test_file_watch (Test *test, gconstpointer unused)
+{
+ /* A watch for an non-existant directory, should have no responses */
+ gkm_file_tracker_refresh (test->the_tracker, FALSE);
+
+ g_assert_cmpint (0, ==, test->n_files_added);
+ g_assert_cmpint (0, ==, test->n_files_changed);
+ g_assert_cmpint (0, ==, test->n_files_removed);
+
+ g_mkdir_with_parents (test->test_dir, 0700);
+
+ /* Should still have no responses even though it exists */
+ gkm_file_tracker_refresh (test->the_tracker, FALSE);
+
+ g_assert_cmpint (0, ==, test->n_files_added);
+ g_assert_cmpint (0, ==, test->n_files_changed);
+ g_assert_cmpint (0, ==, test->n_files_removed);
+}
+
+static void
+test_watch_file (Test *test, gconstpointer unused)
+{
+ gboolean ret;
+
+ /* Make sure things are clean */
+ gkm_file_tracker_refresh (test->the_tracker, FALSE);
+
+ test->n_files_added = test->n_files_changed = test->n_files_removed = 0;
+ test->last_file_added = test->last_file_changed = test->last_file_removed = 0;
+
+ ret = g_file_set_contents (test->test_file, DATA, strlen (DATA), NULL);
+ g_assert (ret);
+
+ /* Now make sure that file is located */
+ gkm_file_tracker_refresh (test->the_tracker, FALSE);
+
+ g_assert_cmpint (1, ==, test->n_files_added);
+ g_assert_cmpint (0, ==, test->n_files_changed);
+ g_assert_cmpint (0, ==, test->n_files_removed);
+
+ /* The added one should match our file */
+ g_assert_cmpstr (test->last_file_added, ==, test->test_file);
+
+ file_reset_stats (test);
+ sleep (1);
+
+ /* Shouldn't find the file again */
+ gkm_file_tracker_refresh (test->the_tracker, FALSE);
+ g_assert_cmpint (0, ==, test->n_files_added);
+ g_assert_cmpint (0, ==, test->n_files_changed);
+ g_assert_cmpint (0, ==, test->n_files_removed);
+
+ /* But we should find the file if forced to */
+ gkm_file_tracker_refresh (test->the_tracker, TRUE);
+ g_assert_cmpint (0, ==, test->n_files_added);
+ g_assert_cmpint (1, ==, test->n_files_changed);
+ g_assert_cmpint (0, ==, test->n_files_removed);
+ g_assert_cmpstr (test->last_file_changed, ==, test->test_file);
+
+ file_reset_stats (test);
+
+ ret = g_file_set_contents (test->test_file, DATA, strlen (DATA), NULL);
+ g_assert (ret);
+
+ /* File was updated */
+ gkm_file_tracker_refresh (test->the_tracker, FALSE);
+ g_assert_cmpint (0, ==, test->n_files_added);
+ g_assert_cmpint (1, ==, test->n_files_changed);
+ g_assert_cmpint (0, ==, test->n_files_removed);
+ g_assert_cmpstr (test->last_file_changed, ==, test->test_file);
+
+ file_reset_stats (test);
+ g_unlink (test->test_file);
+
+ /* Now file should be removed */
+ gkm_file_tracker_refresh (test->the_tracker, FALSE);
+
+ g_assert_cmpint (0, ==, test->n_files_added);
+ g_assert_cmpint (0, ==, test->n_files_changed);
+ g_assert_cmpint (1, ==, test->n_files_removed);
+ g_assert_cmpstr (test->last_file_removed, ==, test->test_file);
+}
+
+static void
+test_nomatch (Test *test, gconstpointer unused)
+{
+ gchar *file = g_build_filename (test->test_dir, "my-file.toot", NULL);
+ gboolean ret;
+
+ /* Mtime must change so wait between tests */
+ sleep (1);
+
+ ret = g_file_set_contents (file, DATA, strlen (DATA), NULL);
+ g_assert (ret);
+
+ file_reset_stats (test);
+
+ /* Now make sure that file is not located */
+ gkm_file_tracker_refresh (test->the_tracker, FALSE);
+
+ g_assert_cmpint (0, ==, test->n_files_added);
+ g_assert_cmpint (0, ==, test->n_files_changed);
+ g_assert_cmpint (0, ==, test->n_files_removed);
+
+ g_unlink (file);
+ g_free (file);
+}
+
+int
+main (int argc, char **argv)
+{
+ g_type_init ();
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add ("/gkm/file-tracker/file_watch", Test, NULL, setup, test_file_watch, teardown);
+ g_test_add ("/gkm/file-tracker/watch_file", Test, NULL, setup, test_watch_file, teardown);
+ g_test_add ("/gkm/file-tracker/nomatch", Test, NULL, setup, test_nomatch, teardown);
+
+ return g_test_run ();
+}
diff --git a/pkcs11/gkm/tests/test-memory-store.c b/pkcs11/gkm/tests/test-memory-store.c
new file mode 100644
index 0000000..07c6b0e
--- /dev/null
+++ b/pkcs11/gkm/tests/test-memory-store.c
@@ -0,0 +1,482 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* unit-test-memory-test->store.c: Test memory test->store functionality
+
+ Copyright (C) 2008 Stefan Walter
+
+ The Gnome Keyring Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The Gnome Keyring Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the Gnome Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Author: Stef Walter <stef memberwebs com>
+*/
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "mock-module.h"
+
+#include "egg/egg-secure-memory.h"
+#include "gkm/gkm-object.h"
+#include "gkm/gkm-memory-store.h"
+#include "gkm/gkm-transaction.h"
+
+typedef struct {
+ GkmModule *module;
+ GkmStore *store;
+ GkmObject *object;
+ GkmTransaction *transaction;
+ guchar buffer[1024];
+} Test;
+
+static CK_RV
+check_validator (GkmObject *obj, CK_ATTRIBUTE_PTR attr)
+{
+ const gchar *data;
+ guint i;
+
+ g_assert (attr);
+ g_assert (attr->type == CKA_LABEL);
+
+ /* Test that the whole string is ascii and lower case */
+ data = attr->pValue;
+ for (i = 0; i < attr->ulValueLen; ++i) {
+ if (!g_ascii_isprint(data[i]) || !g_ascii_islower (data[i]))
+ return CKR_ATTRIBUTE_VALUE_INVALID;
+ }
+
+ return CKR_OK;
+}
+
+static void
+setup (Test *test, gconstpointer unused)
+{
+ CK_ATTRIBUTE attr;
+ CK_ULONG twentyfour = 24;
+
+ test->module = mock_module_initialize_and_enter ();
+
+ attr.type = CKA_LABEL;
+ attr.pValue = "label";
+ attr.ulValueLen = 5;
+
+ test->store = GKM_STORE (gkm_memory_store_new ());
+
+ gkm_store_register_schema (test->store, &attr, check_validator, 0);
+ g_assert (gkm_store_lookup_schema (test->store, CKA_LABEL, NULL));
+
+ attr.type = CKA_VALUE;
+ attr.pValue = NULL;
+ attr.ulValueLen = 0;
+
+ gkm_store_register_schema (test->store, &attr, NULL, GKM_STORE_IS_SENSITIVE);
+
+ attr.type = CKA_BITS_PER_PIXEL;
+ attr.pValue = &twentyfour;
+ attr.ulValueLen = sizeof (twentyfour);
+
+ gkm_store_register_schema (test->store, &attr, NULL, GKM_STORE_IS_INTERNAL);
+
+ test->object = g_object_new (GKM_TYPE_OBJECT, "module", test->module, NULL);
+
+ test->transaction = gkm_transaction_new ();
+}
+
+static void
+teardown (Test *test, gconstpointer unused)
+{
+ g_object_unref (test->store);
+ test->store = NULL;
+
+ g_object_unref (test->transaction);
+ test->transaction = NULL;
+
+ if (test->object != NULL)
+ g_object_unref (test->object);
+ test->object = NULL;
+
+ mock_module_leave_and_finalize ();
+ test->module = NULL;
+}
+
+static void
+test_get_attribute_default (Test *test, gconstpointer unused)
+{
+ CK_ATTRIBUTE attr;
+ CK_RV rv;
+
+ attr.type = CKA_LABEL;
+ attr.pValue = NULL;
+ rv = gkm_store_get_attribute (test->store, test->object, &attr);
+ g_assert (rv == CKR_OK);
+ g_assert (attr.ulValueLen == 5);
+ attr.pValue = test->buffer;
+ rv = gkm_store_get_attribute (test->store, test->object, &attr);
+ g_assert (rv == CKR_OK);
+ g_assert (attr.ulValueLen == 5);
+ g_assert (memcmp (attr.pValue, "label", 5) == 0);
+}
+
+static void
+test_read_value_default (Test *test, gconstpointer unused)
+{
+ gconstpointer value;
+ gsize n_value;
+
+ value = gkm_store_read_value (test->store, test->object, CKA_LABEL, &n_value);
+ g_assert (value);
+ g_assert (n_value == 5);
+ g_assert (memcmp (value, "label", 5) == 0);
+
+ value = gkm_store_read_value (test->store, test->object, CKA_BITS_PER_PIXEL, &n_value);
+ g_assert (value);
+ g_assert (n_value == sizeof (CK_ULONG));
+ g_assert (*((CK_ULONG_PTR)value) == 24);
+}
+
+static void
+test_read_string (Test *test, gconstpointer unused)
+{
+ gchar *str;
+
+ str = gkm_store_read_string (test->store, test->object, CKA_LABEL);
+ g_assert_cmpstr (str, ==, "label");
+ g_free (str);
+}
+
+static void
+test_get_invalid (Test *test, gconstpointer unused)
+{
+ CK_ATTRIBUTE attr;
+ CK_RV rv;
+
+ attr.type = CKA_APPLICATION;
+ attr.pValue = NULL;
+ attr.ulValueLen = 0;
+
+ rv = gkm_store_get_attribute (test->store, test->object, &attr);
+ g_assert (rv == CKR_ATTRIBUTE_TYPE_INVALID);
+}
+
+static void
+test_get_sensitive (Test *test, gconstpointer unused)
+{
+ CK_ATTRIBUTE attr;
+ CK_RV rv;
+
+ attr.type = CKA_VALUE;
+ attr.pValue = NULL;
+ attr.ulValueLen = 0;
+
+ rv = gkm_store_get_attribute (test->store, test->object, &attr);
+ g_assert (rv == CKR_ATTRIBUTE_SENSITIVE);
+}
+
+static void
+test_get_internal (Test *test, gconstpointer unused)
+{
+ CK_ATTRIBUTE attr;
+ CK_RV rv;
+
+ attr.type = CKA_BITS_PER_PIXEL;
+ attr.pValue = NULL;
+ attr.ulValueLen = 0;
+
+ rv = gkm_store_get_attribute (test->store, test->object, &attr);
+ g_assert (rv == CKR_ATTRIBUTE_TYPE_INVALID);
+}
+
+static void
+test_set_invalid (Test *test, gconstpointer unused)
+{
+ CK_ATTRIBUTE attr;
+
+ attr.type = CKA_APPLICATION;
+ attr.pValue = "me";
+ attr.ulValueLen = 2;
+
+ gkm_store_set_attribute (test->store, test->transaction, test->object, &attr);
+ g_assert (gkm_transaction_get_result (test->transaction) == CKR_ATTRIBUTE_TYPE_INVALID);
+}
+
+static void
+test_set_internal (Test *test, gconstpointer unused)
+{
+ CK_ATTRIBUTE attr;
+ CK_ULONG five = 5;
+
+ attr.type = CKA_BITS_PER_PIXEL;
+ attr.pValue = &five;
+ attr.ulValueLen = sizeof (five);
+
+ gkm_store_set_attribute (test->store, test->transaction, test->object, &attr);
+ g_assert (gkm_transaction_get_result (test->transaction) == CKR_ATTRIBUTE_TYPE_INVALID);
+}
+
+static void
+test_set_get_attribute (Test *test, gconstpointer unused)
+{
+ CK_ATTRIBUTE attr;
+ CK_RV rv;
+
+ attr.type = CKA_LABEL;
+ attr.pValue = "booyah";
+ attr.ulValueLen = 6;
+
+ gkm_store_set_attribute (test->store, test->transaction, test->object, &attr);
+
+ gkm_transaction_complete (test->transaction);
+ g_assert (gkm_transaction_get_result (test->transaction) == CKR_OK);
+
+ attr.pValue = test->buffer;
+ attr.ulValueLen = 1024;
+ rv = gkm_store_get_attribute (test->store, test->object, &attr);
+ g_assert (rv == CKR_OK);
+ g_assert (attr.ulValueLen == 6);
+ g_assert (memcmp (attr.pValue, "booyah", 6) == 0);
+}
+
+static void
+test_write_read_value (Test *test, gconstpointer unused)
+{
+ CK_ATTRIBUTE attr;
+ CK_ULONG five = 5;
+ gconstpointer value;
+ gsize n_value;
+
+ attr.type = CKA_BITS_PER_PIXEL;
+ attr.pValue = &five;
+ attr.ulValueLen = sizeof (five);
+
+ gkm_store_write_value (test->store, test->transaction, test->object, &attr);
+
+ gkm_transaction_complete (test->transaction);
+ g_assert (gkm_transaction_get_result (test->transaction) == CKR_OK);
+
+ value = gkm_store_read_value (test->store, test->object, CKA_BITS_PER_PIXEL, &n_value);
+ g_assert (value);
+ g_assert (n_value == sizeof (five));
+ g_assert (memcmp (value, &five, sizeof (five)) == 0);
+}
+
+static void
+test_set_no_validate (Test *test, gconstpointer unused)
+{
+ CK_ATTRIBUTE attr;
+
+ attr.type = CKA_LABEL;
+ attr.pValue = "CAPITALS";
+ attr.ulValueLen = 8;
+
+ gkm_store_set_attribute (test->store, test->transaction, test->object, &attr);
+ g_assert (gkm_transaction_get_failed (test->transaction));
+
+ gkm_transaction_complete (test->transaction);
+ g_assert (gkm_transaction_get_result (test->transaction) == CKR_ATTRIBUTE_VALUE_INVALID);
+}
+
+static void
+test_set_transaction_default (Test *test, gconstpointer unused)
+{
+ CK_ATTRIBUTE attr;
+ gconstpointer value;
+ gsize n_value;
+
+
+ attr.type = CKA_LABEL;
+ attr.pValue = "another";
+ attr.ulValueLen = 7;
+
+ /* Change the attribute */
+ gkm_store_set_attribute (test->store, test->transaction, test->object, &attr);
+ g_assert (gkm_transaction_get_failed (test->transaction) == FALSE);
+
+ /* Should get new value */
+ value = gkm_store_read_value (test->store, test->object, CKA_LABEL, &n_value);
+ g_assert (value && n_value == attr.ulValueLen);
+ g_assert (memcmp (attr.pValue, value, n_value) == 0);
+
+ /* Fail for some arbitrary reason */
+ gkm_transaction_fail (test->transaction, CKR_ATTRIBUTE_VALUE_INVALID);
+
+ /* Value should not have changed yet */
+ value = gkm_store_read_value (test->store, test->object, CKA_LABEL, &n_value);
+ g_assert (value && n_value == attr.ulValueLen);
+ g_assert (memcmp (attr.pValue, value, n_value) == 0);
+
+ /* Now complete the test->transaction */
+ gkm_transaction_complete (test->transaction);
+ g_assert (gkm_transaction_get_failed (test->transaction) == TRUE);
+
+ /* Value should now have changed, back to default */
+ value = gkm_store_read_value (test->store, test->object, CKA_LABEL, &n_value);
+ g_assert (value && n_value == 5);
+ g_assert (memcmp (value, "label", 5) == 0);
+}
+
+static void
+test_set_transaction_revert_first (Test *test, gconstpointer unused)
+{
+ CK_ATTRIBUTE attr, prev;
+ gconstpointer value;
+ gsize n_value;
+
+ prev.type = CKA_LABEL;
+ prev.pValue = "numberone";
+ prev.ulValueLen = 9;
+
+ /* Change the attribute */
+ gkm_store_set_attribute (test->store, test->transaction, test->object, &prev);
+ gkm_transaction_complete (test->transaction);
+ g_assert (gkm_transaction_get_failed (test->transaction) == FALSE);
+
+ /* Value should be new value */
+ value = gkm_store_read_value (test->store, test->object, CKA_LABEL, &n_value);
+ g_assert (value && n_value == prev.ulValueLen);
+ g_assert (memcmp (prev.pValue, value, n_value) == 0);
+
+ /* A new test->transaction */
+ g_object_unref (test->transaction);
+ test->transaction = gkm_transaction_new ();
+
+ attr.type = CKA_LABEL;
+ attr.pValue = "second";
+ attr.ulValueLen = 6;
+
+ gkm_store_set_attribute (test->store, test->transaction, test->object, &attr);
+ g_assert (gkm_transaction_get_failed (test->transaction) == FALSE);
+
+ /* Should get new value */
+ value = gkm_store_read_value (test->store, test->object, CKA_LABEL, &n_value);
+ g_assert (value && n_value == attr.ulValueLen);
+ g_assert (memcmp (attr.pValue, value, n_value) == 0);
+
+ attr.type = CKA_LABEL;
+ attr.pValue = "third";
+ attr.ulValueLen = 5;
+
+ gkm_store_set_attribute (test->store, test->transaction, test->object, &attr);
+ g_assert (gkm_transaction_get_failed (test->transaction) == FALSE);
+
+ /* Should get new value */
+ value = gkm_store_read_value (test->store, test->object, CKA_LABEL, &n_value);
+ g_assert (value && n_value == attr.ulValueLen);
+ g_assert (memcmp (attr.pValue, value, n_value) == 0);
+
+ /* Fail for some arbitrary reason */
+ gkm_transaction_fail (test->transaction, CKR_ATTRIBUTE_VALUE_INVALID);
+
+ /* Value should not have changed yet */
+ value = gkm_store_read_value (test->store, test->object, CKA_LABEL, &n_value);
+ g_assert (value && n_value == attr.ulValueLen);
+ g_assert (memcmp (attr.pValue, value, n_value) == 0);
+
+ /* Now complete the test->transaction */
+ gkm_transaction_complete (test->transaction);
+ g_assert (gkm_transaction_get_failed (test->transaction) == TRUE);
+
+ /* Value should now have changed, back to default */
+ value = gkm_store_read_value (test->store, test->object, CKA_LABEL, &n_value);
+ g_assert (value && n_value == prev.ulValueLen);
+ g_assert (memcmp (prev.pValue, value, n_value) == 0);
+}
+
+static void
+notify_attribute (GkmObject *obj, CK_ATTRIBUTE_TYPE type, gpointer data)
+{
+ g_assert (type == CKA_LABEL);
+ g_assert (data);
+
+ *((CK_ATTRIBUTE_TYPE*)data) = type;
+}
+
+static void
+test_set_notifies (Test *test, gconstpointer unused)
+{
+ CK_ATTRIBUTE attr;
+ CK_ATTRIBUTE_TYPE type = 0;
+
+ attr.type = CKA_LABEL;
+ attr.pValue = "valid";
+ attr.ulValueLen = 5;
+
+ g_signal_connect (test->object, "notify-attribute", G_CALLBACK (notify_attribute), &type);
+
+ gkm_store_set_attribute (test->store, test->transaction, test->object, &attr);
+
+ /* We should have been notified that the attribute changed at this point */
+ g_assert (type == CKA_LABEL);
+
+ /* Reset for next notify */
+ type = 0;
+
+ /* Fail for some arbitrary reason */
+ gkm_transaction_fail (test->transaction, CKR_ATTRIBUTE_VALUE_INVALID);
+
+ /* We should not have been notified yet */
+ g_assert (type == 0);
+
+ /* Now complete the test->transaction */
+ gkm_transaction_complete (test->transaction);
+ g_assert (gkm_transaction_get_failed (test->transaction) == TRUE);
+
+ /* Now we should have been notified that this changed back */
+ g_assert (type == CKA_LABEL);
+}
+
+static void
+test_set_object_gone_first (Test *test, gconstpointer unused)
+{
+ CK_ATTRIBUTE attr;
+
+ attr.type = CKA_LABEL;
+ attr.pValue = "valid";
+ attr.ulValueLen = 5;
+
+ gkm_store_set_attribute (test->store, test->transaction, test->object, &attr);
+ gkm_transaction_complete (test->transaction);
+ g_assert (gkm_transaction_get_result (test->transaction) == CKR_OK);
+
+ /* This tests memory test->store internal tracking */
+ g_object_unref (test->object);
+ test->object = NULL;
+}
+
+int
+main (int argc, char **argv)
+{
+ g_type_init ();
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add ("/gkm/memory-test->store/get_attribute_default", Test, NULL, setup, test_get_attribute_default, teardown);
+ g_test_add ("/gkm/memory-test->store/read_value_default", Test, NULL, setup, test_read_value_default, teardown);
+ g_test_add ("/gkm/memory-test->store/read_string", Test, NULL, setup, test_read_string, teardown);
+ g_test_add ("/gkm/memory-test->store/get_invalid", Test, NULL, setup, test_get_invalid, teardown);
+ g_test_add ("/gkm/memory-test->store/get_sensitive", Test, NULL, setup, test_get_sensitive, teardown);
+ g_test_add ("/gkm/memory-test->store/get_internal", Test, NULL, setup, test_get_internal, teardown);
+ g_test_add ("/gkm/memory-test->store/set_invalid", Test, NULL, setup, test_set_invalid, teardown);
+ g_test_add ("/gkm/memory-test->store/set_internal", Test, NULL, setup, test_set_internal, teardown);
+ g_test_add ("/gkm/memory-test->store/set_get_attribute", Test, NULL, setup, test_set_get_attribute, teardown);
+ g_test_add ("/gkm/memory-test->store/write_read_value", Test, NULL, setup, test_write_read_value, teardown);
+ g_test_add ("/gkm/memory-test->store/set_no_validate", Test, NULL, setup, test_set_no_validate, teardown);
+ g_test_add ("/gkm/memory-test->store/set_transaction_default", Test, NULL, setup, test_set_transaction_default, teardown);
+ g_test_add ("/gkm/memory-test->store/set_transaction_revert_first", Test, NULL, setup, test_set_transaction_revert_first, teardown);
+ g_test_add ("/gkm/memory-test->store/set_notifies", Test, NULL, setup, test_set_notifies, teardown);
+ g_test_add ("/gkm/memory-test->store/set_object_gone_first", Test, NULL, setup, test_set_object_gone_first, teardown);
+
+ return g_test_run ();
+}
diff --git a/pkcs11/gkm/tests/unit-test-object.c b/pkcs11/gkm/tests/test-object.c
similarity index 59%
rename from pkcs11/gkm/tests/unit-test-object.c
rename to pkcs11/gkm/tests/test-object.c
index fc2ce4f..0c3c826 100644
--- a/pkcs11/gkm/tests/unit-test-object.c
+++ b/pkcs11/gkm/tests/test-object.c
@@ -1,5 +1,5 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* unit-test-timer.c: Test thread timer functionality
+/* test-object.c: Test GkmObject
Copyright (C) 2009 Stefan Walter
@@ -21,8 +21,9 @@
Author: Stef Walter <stef memberwebs com>
*/
-#include "test-suite.h"
-#include "test-module.h"
+#include "config.h"
+
+#include "mock-module.h"
#include "gkm/gkm-attributes.h"
#include "gkm/gkm-object.h"
@@ -30,39 +31,42 @@
#include "gkm/gkm-module.h"
#include "gkm/gkm-transaction.h"
+#include "egg/egg-testing.h"
+
#include "pkcs11i.h"
-static GkmModule *module = NULL;
-static GkmSession *session = NULL;
-static guchar *certificate_data = NULL;
-static gsize certificate_n_data = 0;
+typedef struct {
+ GkmModule *module;
+ GkmSession *session;
+ gchar *certificate_data;
+ gsize n_certificate_data;
+} Test;
-TESTING_SETUP(object_setup)
+static void
+setup (Test* test, gconstpointer unused)
{
- module = test_module_initialize_and_enter ();
- session = test_module_open_session (TRUE);
- certificate_data = testing_data_read ("test-certificate-1.der", &certificate_n_data);
+ test->module = mock_module_initialize_and_enter ();
+ test->session = mock_module_open_session (TRUE);
+
+ if (!g_file_get_contents ("files/test-certificate-1.der", &test->certificate_data, &test->n_certificate_data, NULL))
+ g_assert_not_reached ();
}
-TESTING_TEARDOWN(object_teardown)
+static void
+teardown (Test* test, gconstpointer unused)
{
- g_free (certificate_data);
- certificate_data = NULL;
- certificate_n_data = 0;
-
- test_module_leave_and_finalize ();
- module = NULL;
- session = NULL;
+ g_free (test->certificate_data);
+ mock_module_leave_and_finalize ();
}
static gboolean
-check_object_exists (CK_OBJECT_HANDLE handle)
+check_object_exists (CK_OBJECT_HANDLE handle, Test *test)
{
CK_BBOOL token;
CK_ATTRIBUTE attr = { CKA_TOKEN, &token, sizeof (token) };
CK_RV rv;
- rv = gkm_session_C_GetAttributeValue (session, handle, &attr, 1);
+ rv = gkm_session_C_GetAttributeValue (test->session, handle, &attr, 1);
if (rv == CKR_OBJECT_HANDLE_INVALID)
return FALSE;
@@ -70,7 +74,8 @@ check_object_exists (CK_OBJECT_HANDLE handle)
return TRUE;
}
-TESTING_TEST(object_create_destroy_transient)
+static void
+test_create_destroy_transient (Test* test, gconstpointer unused)
{
CK_BBOOL transient = CK_TRUE;
CK_BBOOL token = CK_TRUE;
@@ -82,31 +87,32 @@ TESTING_TEST(object_create_destroy_transient)
{ CKA_GNOME_TRANSIENT, &transient, sizeof (transient) },
{ CKA_CLASS, &klass, sizeof (klass) },
{ CKA_CERTIFICATE_TYPE, &type, sizeof (type) },
- { CKA_VALUE, certificate_data, certificate_n_data },
+ { CKA_VALUE, test->certificate_data, test->n_certificate_data },
};
CK_ATTRIBUTE lookup = { CKA_GNOME_TRANSIENT, &transient, sizeof (transient) };
CK_OBJECT_HANDLE handle;
CK_RV rv;
- rv = gkm_session_C_CreateObject (session, attrs, G_N_ELEMENTS (attrs), &handle);
+ rv = gkm_session_C_CreateObject (test->session, attrs, G_N_ELEMENTS (attrs), &handle);
g_assert (rv == CKR_OK);
g_assert (handle != 0);
- g_assert (check_object_exists (handle));
+ g_assert (check_object_exists (handle, test));
transient = CK_FALSE;
- rv = gkm_session_C_GetAttributeValue (session, handle, &lookup, 1);
+ rv = gkm_session_C_GetAttributeValue (test->session, handle, &lookup, 1);
g_assert (rv == CKR_OK);
g_assert (transient == CK_TRUE);
- rv = gkm_session_C_DestroyObject (session, handle);
+ rv = gkm_session_C_DestroyObject (test->session, handle);
g_assert (rv == CKR_OK);
- g_assert (!check_object_exists (handle));
+ g_assert (!check_object_exists (handle, test));
}
-TESTING_TEST(object_transient_transacted_fail)
+static void
+test_transient_transacted_fail (Test* test, gconstpointer unused)
{
CK_BBOOL transient = CK_TRUE;
CK_BBOOL token = CK_TRUE;
@@ -119,7 +125,7 @@ TESTING_TEST(object_transient_transacted_fail)
{ CKA_GNOME_TRANSIENT, &transient, sizeof (transient) },
{ CKA_CLASS, &klass, sizeof (klass) },
{ CKA_CERTIFICATE_TYPE, &type, sizeof (type) },
- { CKA_VALUE, certificate_data, certificate_n_data },
+ { CKA_VALUE, test->certificate_data, test->n_certificate_data },
/* An invalid attribute, should cause transaction to fail */
{ CKA_BITS_PER_PIXEL, &invalid, sizeof (invalid) }
@@ -128,11 +134,12 @@ TESTING_TEST(object_transient_transacted_fail)
CK_OBJECT_HANDLE handle;
CK_RV rv;
- rv = gkm_session_C_CreateObject (session, attrs, G_N_ELEMENTS (attrs), &handle);
+ rv = gkm_session_C_CreateObject (test->session, attrs, G_N_ELEMENTS (attrs), &handle);
g_assert (rv == CKR_ATTRIBUTE_TYPE_INVALID);
}
-TESTING_TEST(object_create_transient_bad_value)
+static void
+test_create_transient_bad_value (Test* test, gconstpointer unused)
{
CK_OBJECT_CLASS klass = CKO_CERTIFICATE;
CK_CERTIFICATE_TYPE type = CKC_X_509;
@@ -141,18 +148,19 @@ TESTING_TEST(object_create_transient_bad_value)
{ CKA_GNOME_TRANSIENT, NULL, 0 },
{ CKA_CLASS, &klass, sizeof (klass) },
{ CKA_CERTIFICATE_TYPE, &type, sizeof (type) },
- { CKA_VALUE, certificate_data, certificate_n_data },
+ { CKA_VALUE, test->certificate_data, test->n_certificate_data },
};
CK_OBJECT_HANDLE handle;
CK_RV rv;
/* Can't have a non-transient object that auto-destructs */
- rv = gkm_session_C_CreateObject (session, attrs, G_N_ELEMENTS (attrs), &handle);
+ rv = gkm_session_C_CreateObject (test->session, attrs, G_N_ELEMENTS (attrs), &handle);
g_assert (rv == CKR_ATTRIBUTE_VALUE_INVALID);
}
-TESTING_TEST(object_create_auto_destruct)
+static void
+test_create_auto_destruct (Test* test, gconstpointer unused)
{
CK_BBOOL token = CK_FALSE;
CK_OBJECT_CLASS klass = CKO_CERTIFICATE;
@@ -165,7 +173,7 @@ TESTING_TEST(object_create_auto_destruct)
{ CKA_TOKEN, &token, sizeof (token) },
{ CKA_CLASS, &klass, sizeof (klass) },
{ CKA_CERTIFICATE_TYPE, &type, sizeof (type) },
- { CKA_VALUE, certificate_data, certificate_n_data },
+ { CKA_VALUE, test->certificate_data, test->n_certificate_data },
};
CK_BBOOL transient;
@@ -178,26 +186,27 @@ TESTING_TEST(object_create_auto_destruct)
CK_OBJECT_HANDLE handle;
CK_RV rv;
- rv = gkm_session_C_CreateObject (session, attrs, G_N_ELEMENTS (attrs), &handle);
+ rv = gkm_session_C_CreateObject (test->session, attrs, G_N_ELEMENTS (attrs), &handle);
g_assert (rv == CKR_OK);
g_assert (handle != 0);
- g_assert (check_object_exists (handle));
+ g_assert (check_object_exists (handle, test));
transient = CK_FALSE;
- rv = gkm_session_C_GetAttributeValue (session, handle, lookups, G_N_ELEMENTS (lookups));
+ rv = gkm_session_C_GetAttributeValue (test->session, handle, lookups, G_N_ELEMENTS (lookups));
g_assert (rv == CKR_OK);
g_assert (transient == TRUE);
g_assert (memcmp (&lifetime, &check, sizeof (lifetime)) == 0);
- test_module_leave ();
- testing_wait_until (2200);
- test_module_enter ();
+ mock_module_leave ();
+ egg_test_wait_until (2200);
+ mock_module_enter ();
- g_assert (!check_object_exists (handle));
+ g_assert (!check_object_exists (handle, test));
}
-TESTING_TEST(object_create_auto_destruct_not_transient)
+static void
+test_create_auto_destruct_not_transient (Test* test, gconstpointer unused)
{
CK_OBJECT_CLASS klass = CKO_CERTIFICATE;
CK_CERTIFICATE_TYPE type = CKC_X_509;
@@ -209,25 +218,26 @@ TESTING_TEST(object_create_auto_destruct_not_transient)
{ CKA_GNOME_TRANSIENT, &transient, sizeof (transient) },
{ CKA_CLASS, &klass, sizeof (klass) },
{ CKA_CERTIFICATE_TYPE, &type, sizeof (type) },
- { CKA_VALUE, certificate_data, certificate_n_data },
+ { CKA_VALUE, test->certificate_data, test->n_certificate_data },
};
CK_OBJECT_HANDLE handle;
CK_RV rv;
/* Can't have a non-transient object that auto-destructs */
- rv = gkm_session_C_CreateObject (session, attrs, G_N_ELEMENTS (attrs), &handle);
+ rv = gkm_session_C_CreateObject (test->session, attrs, G_N_ELEMENTS (attrs), &handle);
g_assert (rv == CKR_TEMPLATE_INCONSISTENT);
}
-TESTING_TEST(object_expose)
+static void
+test_expose (Test* test, gconstpointer unused)
{
CK_OBJECT_HANDLE handle;
GkmManager *manager;
GkmObject *check, *object;
- manager = gkm_session_get_manager (session);
- object = test_module_object_new (session);
+ manager = gkm_session_get_manager (test->session);
+ object = mock_module_object_new (test->session);
handle = gkm_object_get_handle (object);
gkm_object_expose (object, TRUE);
@@ -243,15 +253,16 @@ TESTING_TEST(object_expose)
g_assert (check == NULL);
}
-TESTING_TEST(object_expose_transaction)
+static void
+test_expose_transaction (Test* test, gconstpointer unused)
{
CK_OBJECT_HANDLE handle;
GkmManager *manager;
GkmObject *check, *object;
GkmTransaction *transaction;
- manager = gkm_session_get_manager (session);
- object = test_module_object_new (session);
+ manager = gkm_session_get_manager (test->session);
+ object = mock_module_object_new (test->session);
handle = gkm_object_get_handle (object);
transaction = gkm_transaction_new ();
@@ -275,3 +286,20 @@ TESTING_TEST(object_expose_transaction)
g_object_unref (transaction);
}
+
+int
+main (int argc, char **argv)
+{
+ g_type_init ();
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add ("/gkm/object/create_destroy_transient", Test, NULL, setup, test_create_destroy_transient, teardown);
+ g_test_add ("/gkm/object/transient_transacted_fail", Test, NULL, setup, test_transient_transacted_fail, teardown);
+ g_test_add ("/gkm/object/create_transient_bad_value", Test, NULL, setup, test_create_transient_bad_value, teardown);
+ g_test_add ("/gkm/object/create_auto_destruct", Test, NULL, setup, test_create_auto_destruct, teardown);
+ g_test_add ("/gkm/object/create_auto_destruct_not_transient", Test, NULL, setup, test_create_auto_destruct_not_transient, teardown);
+ g_test_add ("/gkm/object/expose", Test, NULL, setup, test_expose, teardown);
+ g_test_add ("/gkm/object/expose_transaction", Test, NULL, setup, test_expose_transaction, teardown);
+
+ return egg_tests_run_in_thread_with_loop ();
+}
diff --git a/pkcs11/gkm/tests/unit-test-secret.c b/pkcs11/gkm/tests/test-secret.c
similarity index 85%
rename from pkcs11/gkm/tests/unit-test-secret.c
rename to pkcs11/gkm/tests/test-secret.c
index 5dcea3c..67e7a62 100644
--- a/pkcs11/gkm/tests/unit-test-secret.c
+++ b/pkcs11/gkm/tests/test-secret.c
@@ -1,5 +1,5 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* unit-test-secret.c: Test gkm-secret.c
+/* test-secret.c: Test gkm-secret.c
Copyright (C) 2007 Stefan Walter
@@ -21,15 +21,20 @@
Author: Stef Walter <stef memberwebs com>
*/
+#include "config.h"
+
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-#include "test-suite.h"
-
#include "gkm/gkm-secret.h"
-TESTING_TEST(test_secret)
+#include "egg/egg-secure-memory.h"
+
+EGG_SECURE_GLIB_DEFINITIONS ();
+
+static void
+test_secret (void)
{
GkmSecret *secret;
const gchar *password;
@@ -52,7 +57,8 @@ TESTING_TEST(test_secret)
g_object_unref (secret);
}
-TESTING_TEST(test_secret_from_login)
+static void
+test_secret_from_login (void)
{
GkmSecret *secret;
const gchar *password;
@@ -75,7 +81,8 @@ TESTING_TEST(test_secret_from_login)
g_object_unref (secret);
}
-TESTING_TEST(test_null_terminated)
+static void
+test_null_terminated (void)
{
GkmSecret *secret;
const gchar *password;
@@ -98,7 +105,8 @@ TESTING_TEST(test_null_terminated)
g_object_unref (secret);
}
-TESTING_TEST(test_always_has_null)
+static void
+test_always_has_null (void)
{
GkmSecret *secret;
const guchar *memory;
@@ -117,7 +125,8 @@ TESTING_TEST(test_always_has_null)
g_object_unref (secret);
}
-TESTING_TEST(test_null)
+static void
+test_null (void)
{
GkmSecret *secret;
const gchar *password;
@@ -139,7 +148,8 @@ TESTING_TEST(test_null)
g_object_unref (secret);
}
-TESTING_TEST(test_empty)
+static void
+test_empty (void)
{
GkmSecret *secret;
const gchar *password;
@@ -161,7 +171,8 @@ TESTING_TEST(test_empty)
g_object_unref (secret);
}
-TESTING_TEST(test_equal)
+static void
+test_equal (void)
{
GkmSecret *one;
GkmSecret *two;
@@ -176,3 +187,20 @@ TESTING_TEST(test_equal)
one = gkm_secret_new_from_password ("other");
g_assert (!gkm_secret_equal (one, two));
}
+
+int
+main (int argc, char **argv)
+{
+ g_type_init ();
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add_func ("/gkm/secret/secret", test_secret);
+ g_test_add_func ("/gkm/secret/secret_from_login", test_secret_from_login);
+ g_test_add_func ("/gkm/secret/null_terminated", test_null_terminated);
+ g_test_add_func ("/gkm/secret/always_has_null", test_always_has_null);
+ g_test_add_func ("/gkm/secret/null", test_null);
+ g_test_add_func ("/gkm/secret/empty", test_empty);
+ g_test_add_func ("/gkm/secret/equal", test_equal);
+
+ return g_test_run ();
+}
diff --git a/pkcs11/gkm/tests/unit-test-sexp.c b/pkcs11/gkm/tests/test-sexp.c
similarity index 73%
rename from pkcs11/gkm/tests/unit-test-sexp.c
rename to pkcs11/gkm/tests/test-sexp.c
index c4c2524..5f3e062 100644
--- a/pkcs11/gkm/tests/unit-test-sexp.c
+++ b/pkcs11/gkm/tests/test-sexp.c
@@ -1,5 +1,5 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* unit-test-sexp.c: Test sexp stuff
+/* test-sexp.c: Test sexp stuff
Copyright (C) 2007 Stefan Walter
@@ -21,17 +21,21 @@
Author: Stef Walter <stef memberwebs com>
*/
+#include "config.h"
+
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-#include "test-suite.h"
-
#include "gkm/gkm-crypto.h"
#include "gkm/gkm-sexp.h"
+#include "egg/egg-secure-memory.h"
+
#include <gcrypt.h>
+EGG_SECURE_GLIB_DEFINITIONS ();
+
#define TEST_RSA \
"(private-key (rsa " \
"(n #00B78758D55EBFFAB61D07D0DC49B5309A6F1DA2AE51C275DFC2370959BB81AC0C39093B1C618E396161A0DECEB8768D0FFB14F197B96C3DA14190EE0F20D51315#)" \
@@ -50,30 +54,35 @@
" (y #54734451DB79D4EEDF0BBCEBD43BB6CBB7B8584603B957080075DD318EB5B0266D4B20DC5EFF376BDFC4EA2983B1F7F02A39ED4C619ED68712729FFF3B7C696ADD1B6D748F56A4B4BEC5C4385E528423A3B88AE65E6D5500F97839E7A486255982189C3B4FA8D94338C76F0E5CAFC9A30A1ED728BB9F2091D594E3250A09EA00#)" \
" (x #00876F84F709D51108DFB0CBFA1F1C569C09C413EC#)))"
-gcry_sexp_t rsakey = NULL;
-gcry_sexp_t dsakey = NULL;
+typedef struct {
+ gcry_sexp_t rsakey;
+ gcry_sexp_t dsakey;
+} Test;
-TESTING_SETUP(crypto_setup)
+static void
+setup (Test *test, gconstpointer unused)
{
gcry_error_t gcry;
gkm_crypto_initialize ();
- gcry = gcry_sexp_new (&rsakey, TEST_RSA, strlen (TEST_RSA), 1);
+ gcry = gcry_sexp_new (&test->rsakey, TEST_RSA, strlen (TEST_RSA), 1);
g_return_if_fail (gcry == 0);
- gcry = gcry_sexp_new (&dsakey, TEST_DSA, strlen (TEST_DSA), 1);
+ gcry = gcry_sexp_new (&test->dsakey, TEST_DSA, strlen (TEST_DSA), 1);
g_return_if_fail (gcry == 0);
}
-TESTING_TEARDOWN(crypto_setup)
+static void
+teardown (Test *test, gconstpointer unused)
{
- gcry_sexp_release (rsakey);
- rsakey = NULL;
- gcry_sexp_release (dsakey);
- dsakey = NULL;
+ gcry_sexp_release (test->rsakey);
+ test->rsakey = NULL;
+ gcry_sexp_release (test->dsakey);
+ test->dsakey = NULL;
}
-TESTING_TEST(parse_key)
+static void
+test_parse_key (Test *test, gconstpointer unused)
{
gcry_sexp_t sexp = NULL;
gcry_mpi_t mpi = NULL;
@@ -82,18 +91,19 @@ TESTING_TEST(parse_key)
int algorithm = 0;
/* Get the private key out */
- ret = gkm_sexp_parse_key (rsakey, &algorithm, &is_priv, &sexp);
+ ret = gkm_sexp_parse_key (test->rsakey, &algorithm, &is_priv, &sexp);
g_assert (ret);
g_assert (algorithm == GCRY_PK_RSA);
g_assert (is_priv == TRUE);
g_assert (sexp != NULL);
- ret = gkm_sexp_extract_mpi (rsakey, &mpi, "p", NULL);
+ ret = gkm_sexp_extract_mpi (test->rsakey, &mpi, "p", NULL);
g_assert (ret);
g_assert (mpi != NULL);
}
-TESTING_TEST(sexp_key_to_public)
+static void
+test_key_to_public (Test *test, gconstpointer unused)
{
gcry_sexp_t pubkey = NULL;
guchar id1[20], id2[20];
@@ -101,11 +111,11 @@ TESTING_TEST(sexp_key_to_public)
guchar *p;
/* RSA */
- ret = gkm_sexp_key_to_public (rsakey, &pubkey);
+ ret = gkm_sexp_key_to_public (test->rsakey, &pubkey);
g_assert (ret);
g_assert (pubkey != NULL);
- p = gcry_pk_get_keygrip (rsakey, id1);
+ p = gcry_pk_get_keygrip (test->rsakey, id1);
g_return_if_fail (p == id1);
p = gcry_pk_get_keygrip (pubkey, id2);
g_return_if_fail (p == id2);
@@ -116,11 +126,11 @@ TESTING_TEST(sexp_key_to_public)
/* DSA */
- ret = gkm_sexp_key_to_public (dsakey, &pubkey);
+ ret = gkm_sexp_key_to_public (test->dsakey, &pubkey);
g_assert (ret);
g_assert (pubkey != NULL);
- p = gcry_pk_get_keygrip (dsakey, id1);
+ p = gcry_pk_get_keygrip (test->dsakey, id1);
g_return_if_fail (p == id1);
p = gcry_pk_get_keygrip (pubkey, id2);
g_return_if_fail (p == id2);
@@ -130,3 +140,15 @@ TESTING_TEST(sexp_key_to_public)
gcry_sexp_release (pubkey);
}
+
+int
+main (int argc, char **argv)
+{
+ g_type_init ();
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add ("/gkm/sexp/parse_key", Test, NULL, setup, test_parse_key, teardown);
+ g_test_add ("/gkm/sexp/key_to_public", Test, NULL, setup, test_key_to_public, teardown);
+
+ return g_test_run ();
+}
diff --git a/pkcs11/gkm/tests/unit-test-store.c b/pkcs11/gkm/tests/test-store.c
similarity index 56%
rename from pkcs11/gkm/tests/unit-test-store.c
rename to pkcs11/gkm/tests/test-store.c
index 859aa02..4dab4c4 100644
--- a/pkcs11/gkm/tests/unit-test-store.c
+++ b/pkcs11/gkm/tests/test-store.c
@@ -1,5 +1,5 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* unit-test-store.c: Test general store functionality
+/* test-store.c: Test general store functionality
Copyright (C) 2008 Stefan Walter
@@ -21,35 +21,38 @@
Author: Stef Walter <stef memberwebs com>
*/
+#include "config.h"
+
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
-#include "test-suite.h"
-#include "test-module.h"
+#include "mock-module.h"
#include "gkm/gkm-store.h"
-static GkmModule *module = NULL;
-static GkmStore *store = NULL;
+typedef struct {
+ GkmModule *module;
+ GkmStore *store;
+} Test;
-TESTING_SETUP(store)
+static void
+setup (Test *test, gconstpointer unused)
{
- module = test_module_initialize_and_enter ();
- store = g_object_new (GKM_TYPE_STORE, NULL);
+ test->module = mock_module_initialize_and_enter ();
+ test->store = g_object_new (GKM_TYPE_STORE, NULL);
}
-TESTING_TEARDOWN(store)
+static void
+teardown (Test *test, gconstpointer unused)
{
- g_object_unref (store);
- store = NULL;
-
- test_module_leave_and_finalize ();
- module = NULL;
+ g_object_unref (test->store);
+ mock_module_leave_and_finalize ();
}
-TESTING_TEST(store_schema)
+static void
+test_schema (Test *test, gconstpointer unused)
{
CK_ATTRIBUTE attr;
@@ -57,14 +60,15 @@ TESTING_TEST(store_schema)
attr.pValue = "Label";
attr.ulValueLen = 5;
- gkm_store_register_schema (store, &attr, NULL, 0);
- g_assert (gkm_store_lookup_schema (store, CKA_LABEL, NULL));
+ gkm_store_register_schema (test->store, &attr, NULL, 0);
+ g_assert (gkm_store_lookup_schema (test->store, CKA_LABEL, NULL));
/* Not in the schema */
- g_assert (!gkm_store_lookup_schema (store, CKA_VALUE, NULL));
+ g_assert (!gkm_store_lookup_schema (test->store, CKA_VALUE, NULL));
}
-TESTING_TEST(store_schema_flags)
+static void
+test_schema_flags (Test *test, gconstpointer unused)
{
CK_ATTRIBUTE attr;
guint flags;
@@ -73,8 +77,8 @@ TESTING_TEST(store_schema_flags)
attr.pValue = NULL;
attr.ulValueLen = 0;
- gkm_store_register_schema (store, &attr, NULL, GKM_STORE_IS_SENSITIVE);
- g_assert (gkm_store_lookup_schema (store, CKA_VALUE, &flags));
+ gkm_store_register_schema (test->store, &attr, NULL, GKM_STORE_IS_SENSITIVE);
+ g_assert (gkm_store_lookup_schema (test->store, CKA_VALUE, &flags));
g_assert (flags == GKM_STORE_IS_SENSITIVE);
}
@@ -83,3 +87,16 @@ TESTING_TEST(store_schema_flags)
* derived class. For more tests see unit-test-memory-store.c and
* unit-test-file-store.c
*/
+
+
+int
+main (int argc, char **argv)
+{
+ g_type_init ();
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add ("/gkm/store/schema", Test, NULL, setup, test_schema, teardown);
+ g_test_add ("/gkm/store/schema_flags", Test, NULL, setup, test_schema_flags, teardown);
+
+ return g_test_run ();
+}
diff --git a/pkcs11/gkm/tests/test-timer.c b/pkcs11/gkm/tests/test-timer.c
new file mode 100644
index 0000000..dca9971
--- /dev/null
+++ b/pkcs11/gkm/tests/test-timer.c
@@ -0,0 +1,175 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* test-timer.c: Test thread timer functionality
+
+ Copyright (C) 2009 Stefan Walter
+
+ The Gnome Keyring Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The Gnome Keyring Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the Gnome Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Author: Stef Walter <stef memberwebs com>
+*/
+
+#include "config.h"
+
+#include "mock-module.h"
+
+#include "gkm/gkm-timer.h"
+
+#include "egg/egg-testing.h"
+
+#include <glib-object.h>
+
+typedef struct {
+ GkmModule *module;
+} Test;
+
+static void
+setup (Test* test, gconstpointer unused)
+{
+ test->module = mock_module_initialize_and_enter ();
+}
+
+static void
+teardown (Test* test, gconstpointer unused)
+{
+ mock_module_leave_and_finalize ();
+}
+
+static void
+test_extra_initialize (Test* test, gconstpointer unused)
+{
+ gkm_timer_initialize ();
+ gkm_timer_shutdown ();
+}
+
+static void
+timer_callback (GkmTimer *timer, gpointer user_data)
+{
+ GkmTimer **value = user_data;
+ g_assert (timer);
+ g_assert (timer == *value);
+ *value = NULL;
+}
+
+static void
+test_simple (Test* test, gconstpointer unused)
+{
+ GkmTimer *timer;
+
+ timer = gkm_timer_start (test->module, 2, timer_callback, &timer);
+
+ mock_module_leave ();
+ egg_test_wait_until (2200);
+ mock_module_enter ();
+
+ g_assert (timer == NULL);
+}
+
+static void
+test_cancel (Test* test, gconstpointer unused)
+{
+ GkmTimer *timer;
+
+ timer = gkm_timer_start (test->module, 2, timer_callback, &timer);
+
+ mock_module_leave ();
+ egg_test_wait_until (500);
+ mock_module_enter ();
+
+ gkm_timer_cancel (timer);
+
+ mock_module_leave ();
+ egg_test_wait_until (2000);
+ mock_module_enter ();
+
+ /* The callback should not have been called */
+ g_assert (timer != NULL);
+}
+
+static void
+test_immediate (Test* test, gconstpointer unused)
+{
+ GkmTimer *timer;
+
+ /* Setup timer in the past, should execute as soon as possible */
+ timer = gkm_timer_start (test->module, -5, timer_callback, &timer);
+
+ /* Should not be called immediately */
+ g_assert (timer != NULL);
+
+ mock_module_leave ();
+ egg_test_wait_until (50);
+ mock_module_enter ();
+
+ /* Should have been called now */
+ g_assert (timer == NULL);
+}
+
+static GkmTimer *timer_last = NULL;
+static gint timer_check = 0;
+
+static void
+multiple_callback (GkmTimer *timer, gpointer user_data)
+{
+ gint value = GPOINTER_TO_INT (user_data);
+ g_assert (timer);
+ g_assert (timer != timer_last);
+ g_assert (value == timer_check);
+ timer_last = timer;
+ timer_check += 1;
+}
+
+static void
+test_multiple (Test* test, gconstpointer unused)
+{
+ timer_check = 0;
+
+ /* Multiple timers, add out of order, should be called in order */
+ gkm_timer_start (test->module, 1, multiple_callback, GINT_TO_POINTER (1));
+ gkm_timer_start (test->module, 3, multiple_callback, GINT_TO_POINTER (3));
+ gkm_timer_start (test->module, 2, multiple_callback, GINT_TO_POINTER (2));
+ gkm_timer_start (test->module, 0, multiple_callback, GINT_TO_POINTER (0));
+
+ mock_module_leave ();
+ egg_test_wait_until (3500);
+ mock_module_enter ();
+
+ g_assert (timer_check == 4);
+}
+
+static void
+test_outstanding (Test* test, gconstpointer unused)
+{
+ /* A timer that can't be called */
+ gkm_timer_start (test->module, 5, timer_callback, NULL);
+ gkm_timer_start (test->module, 10, timer_callback, NULL);
+ gkm_timer_start (test->module, 1, timer_callback, NULL);
+}
+
+int
+main (int argc, char **argv)
+{
+ g_type_init ();
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add ("/gkm/secret/extra_initialize", Test, NULL, setup, test_extra_initialize, teardown);
+ g_test_add ("/gkm/secret/simple", Test, NULL, setup, test_simple, teardown);
+ g_test_add ("/gkm/secret/cancel", Test, NULL, setup, test_cancel, teardown);
+ g_test_add ("/gkm/secret/immediate", Test, NULL, setup, test_immediate, teardown);
+ g_test_add ("/gkm/secret/multiple", Test, NULL, setup, test_multiple, teardown);
+ g_test_add ("/gkm/secret/outstanding", Test, NULL, setup, test_outstanding, teardown);
+
+ return egg_tests_run_in_thread_with_loop ();
+}
diff --git a/pkcs11/gkm/tests/unit-test-transaction.c b/pkcs11/gkm/tests/test-transaction.c
similarity index 74%
rename from pkcs11/gkm/tests/unit-test-transaction.c
rename to pkcs11/gkm/tests/test-transaction.c
index 78ab2d4..ac6317b 100644
--- a/pkcs11/gkm/tests/unit-test-transaction.c
+++ b/pkcs11/gkm/tests/test-transaction.c
@@ -1,5 +1,5 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* unit-test-store.c: Test general store functionality
+/* test-transaction.c: Test transaction functionality
Copyright (C) 2008 Stefan Walter
@@ -21,18 +21,25 @@
Author: Stef Walter <stef memberwebs com>
*/
-#include "test-suite.h"
+#include "config.h"
#include "gkm/gkm-transaction.h"
-TESTING_SETUP (transaction_setup)
+#include <glib/gstdio.h>
+
+typedef struct {
+ int unused;
+} Test;
+
+static void
+setup (Test* test, gconstpointer unused)
{
GDir *dir;
const gchar *directory;
const gchar *basename;
gchar *filename;
- directory = testing_scratch_directory ();
+ directory = "/tmp";
dir = g_dir_open (directory, 0, NULL);
g_assert (dir);
@@ -50,7 +57,14 @@ TESTING_SETUP (transaction_setup)
g_dir_close (dir);
}
-TESTING_TEST(transaction_empty)
+static void
+teardown (Test *test, gconstpointer unused)
+{
+
+}
+
+static void
+test_transaction_empty (Test* test, gconstpointer unused)
{
GkmTransaction *transaction;
gboolean completed, failed;
@@ -77,7 +91,8 @@ TESTING_TEST(transaction_empty)
g_object_unref (transaction);
}
-TESTING_TEST(transaction_fail)
+static void
+test_transaction_fail (Test* test, gconstpointer unused)
{
GkmTransaction *transaction;
@@ -123,7 +138,8 @@ completed_callback (GkmTransaction *transaction, GObject *object, gpointer data)
return TRUE;
}
-TESTING_TEST(transaction_signals_success)
+static void
+test_transaction_signals_success (Test* test, gconstpointer unused)
{
GkmTransaction *transaction = gkm_transaction_new ();
@@ -146,7 +162,8 @@ TESTING_TEST(transaction_signals_success)
g_object_unref (transaction);
}
-TESTING_TEST(transaction_signals_failure)
+static void
+test_transaction_signals_failure (Test* test, gconstpointer unused)
{
GkmTransaction *transaction = gkm_transaction_new ();
@@ -183,7 +200,8 @@ order_callback (GkmTransaction *transaction, GObject *object, gpointer data)
return TRUE;
}
-TESTING_TEST(transaction_order_is_reverse)
+static void
+test_transaction_order_is_reverse (Test* test, gconstpointer unused)
{
GkmTransaction *transaction = gkm_transaction_new ();
@@ -196,7 +214,8 @@ TESTING_TEST(transaction_order_is_reverse)
g_object_unref (transaction);
}
-TESTING_TEST(transaction_dispose_completes)
+static void
+test_transaction_dispose_completes (Test* test, gconstpointer unused)
{
GkmTransaction *transaction = gkm_transaction_new ();
@@ -212,10 +231,11 @@ TESTING_TEST(transaction_dispose_completes)
g_object_unref (transaction);
}
-TESTING_TEST(remove_file_success)
+static void
+test_remove_file_success (Test* test, gconstpointer unused)
{
GkmTransaction *transaction = gkm_transaction_new ();
- gchar *filename = testing_scratch_filename ("transaction-remove");
+ const gchar *filename = "/tmp/transaction-remove";
g_assert (g_file_set_contents (filename, "xxx", 3, NULL));
g_assert (g_file_test (filename, G_FILE_TEST_IS_REGULAR));
@@ -229,13 +249,13 @@ TESTING_TEST(remove_file_success)
g_assert (!g_file_test (filename, G_FILE_TEST_IS_REGULAR));
g_object_unref (transaction);
- g_free (filename);
}
-TESTING_TEST(remove_file_abort)
+static void
+test_remove_file_abort (Test* test, gconstpointer unused)
{
GkmTransaction *transaction = gkm_transaction_new ();
- gchar *filename = testing_scratch_filename ("transaction-remove");
+ const gchar *filename = "/tmp/transaction-remove";
gchar *data;
gsize n_data;
@@ -261,13 +281,13 @@ TESTING_TEST(remove_file_abort)
g_unlink (filename);
g_object_unref (transaction);
- g_free (filename);
}
-TESTING_TEST(remove_file_non_exist)
+static void
+test_remove_file_non_exist (Test* test, gconstpointer unused)
{
GkmTransaction *transaction = gkm_transaction_new ();
- gchar *filename = testing_scratch_filename ("transaction-non-existant");
+ const gchar *filename = "/tmp/transaction-non-existant";
g_unlink (filename);
@@ -277,13 +297,13 @@ TESTING_TEST(remove_file_non_exist)
gkm_transaction_complete (transaction);
g_object_unref (transaction);
- g_free (filename);
}
-TESTING_TEST(write_file)
+static void
+test_write_file (Test* test, gconstpointer unused)
{
GkmTransaction *transaction = gkm_transaction_new ();
- gchar *filename = testing_scratch_filename ("transaction-test");
+ const gchar *filename = "/tmp/transaction-test";
gchar *data;
gsize n_data;
@@ -303,13 +323,13 @@ TESTING_TEST(write_file)
g_free (data);
g_object_unref (transaction);
- g_free (filename);
}
-TESTING_TEST(write_file_abort_gone)
+static void
+test_write_file_abort_gone (Test* test, gconstpointer unused)
{
GkmTransaction *transaction = gkm_transaction_new ();
- gchar *filename = testing_scratch_filename ("transaction-test");
+ const gchar *filename = "/tmp/transaction-test";
gchar *data;
gsize n_data;
@@ -329,13 +349,13 @@ TESTING_TEST(write_file_abort_gone)
g_assert (!g_file_test (filename, G_FILE_TEST_IS_REGULAR));
g_object_unref (transaction);
- g_free (filename);
}
-TESTING_TEST(write_file_abort_revert)
+static void
+test_write_file_abort_revert (Test* test, gconstpointer unused)
{
GkmTransaction *transaction = gkm_transaction_new ();
- gchar *filename = testing_scratch_filename ("transaction-test");
+ const gchar *filename = "/tmp/transaction-test";
gchar *data;
g_assert (g_file_set_contents (filename, "my original", -1, NULL));
@@ -355,13 +375,13 @@ TESTING_TEST(write_file_abort_revert)
g_free (data);
g_object_unref (transaction);
- g_free (filename);
}
-TESTING_TEST (unique_file_conflict)
+static void
+test_unique_file_conflict (Test* test, gconstpointer unused)
{
GkmTransaction *transaction = gkm_transaction_new ();
- gchar *filename = testing_scratch_filename ("transaction-test");
+ const gchar *filename = "/tmp/transaction-test";
gchar *dirname;
gchar *basename;
gchar *result;
@@ -383,13 +403,13 @@ TESTING_TEST (unique_file_conflict)
g_free (result);
g_object_unref (transaction);
- g_free (filename);
}
-TESTING_TEST (unique_file_conflict_with_ext)
+static void
+test_unique_file_conflict_with_ext (Test* test, gconstpointer unused)
{
GkmTransaction *transaction = gkm_transaction_new ();
- gchar *filename = testing_scratch_filename ("transaction-test.ext");
+ const gchar *filename = "/tmp/transaction-test.ext";
gchar *dirname;
gchar *basename;
gchar *result;
@@ -411,13 +431,13 @@ TESTING_TEST (unique_file_conflict_with_ext)
g_free (result);
g_object_unref (transaction);
- g_free (filename);
}
-TESTING_TEST (unique_file_no_conflict)
+static void
+test_unique_file_no_conflict (Test* test, gconstpointer unused)
{
GkmTransaction *transaction = gkm_transaction_new ();
- const gchar *dirname = testing_scratch_directory ();
+ const gchar *dirname = "/tmp";
gchar *result;
result = gkm_transaction_unique_file (transaction, dirname, "transaction-another");
@@ -430,3 +450,28 @@ TESTING_TEST (unique_file_no_conflict)
g_object_unref (transaction);
}
+
+int
+main (int argc, char **argv)
+{
+ g_type_init ();
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add ("/gkm/transaction/transaction_empty", Test, NULL, setup, test_transaction_empty, teardown);
+ g_test_add ("/gkm/transaction/transaction_fail", Test, NULL, setup, test_transaction_fail, teardown);
+ g_test_add ("/gkm/transaction/transaction_signals_success", Test, NULL, setup, test_transaction_signals_success, teardown);
+ g_test_add ("/gkm/transaction/transaction_signals_failure", Test, NULL, setup, test_transaction_signals_failure, teardown);
+ g_test_add ("/gkm/transaction/transaction_order_is_reverse", Test, NULL, setup, test_transaction_order_is_reverse, teardown);
+ g_test_add ("/gkm/transaction/transaction_dispose_completes", Test, NULL, setup, test_transaction_dispose_completes, teardown);
+ g_test_add ("/gkm/transaction/remove_file_success", Test, NULL, setup, test_remove_file_success, teardown);
+ g_test_add ("/gkm/transaction/remove_file_abort", Test, NULL, setup, test_remove_file_abort, teardown);
+ g_test_add ("/gkm/transaction/remove_file_non_exist", Test, NULL, setup, test_remove_file_non_exist, teardown);
+ g_test_add ("/gkm/transaction/write_file", Test, NULL, setup, test_write_file, teardown);
+ g_test_add ("/gkm/transaction/write_file_abort_gone", Test, NULL, setup, test_write_file_abort_gone, teardown);
+ g_test_add ("/gkm/transaction/write_file_abort_revert", Test, NULL, setup, test_write_file_abort_revert, teardown);
+ g_test_add ("/gkm/transaction/unique_file_conflict", Test, NULL, setup, test_unique_file_conflict, teardown);
+ g_test_add ("/gkm/transaction/unique_file_conflict_with_ext", Test, NULL, setup, test_unique_file_conflict_with_ext, teardown);
+ g_test_add ("/gkm/transaction/unique_file_no_conflict", Test, NULL, setup, test_unique_file_no_conflict, teardown);
+
+ return g_test_run ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]