gcr: Modernize tests. Use standard gtest type setup.
authorStef Walter <stefw@collabora.co.uk>
Wed, 6 Apr 2011 18:08:05 +0000 (20:08 +0200)
committerStef Walter <stefw@collabora.co.uk>
Wed, 6 Apr 2011 18:08:05 +0000 (20:08 +0200)
46 files changed:
gcr/gcr-parser.c
gcr/gcr-parser.h
gcr/tests/Makefile.am
gcr/tests/files/RSA_Root_Certificate_1.pem [moved from gcr/tests/test-data/RSA_Root_Certificate_1.pem with 100% similarity]
gcr/tests/files/RSA_Security_1024_v3.pem [moved from gcr/tests/test-data/RSA_Security_1024_v3.pem with 100% similarity]
gcr/tests/files/RSA_Security_2048_v3.pem [moved from gcr/tests/test-data/RSA_Security_2048_v3.pem with 100% similarity]
gcr/tests/files/Thawte_Personal_Basic_CA.pem [moved from gcr/tests/test-data/Thawte_Personal_Basic_CA.pem with 100% similarity]
gcr/tests/files/Thawte_Personal_Freemail_CA.pem [moved from gcr/tests/test-data/Thawte_Personal_Freemail_CA.pem with 100% similarity]
gcr/tests/files/Thawte_Personal_Premium_CA.pem [moved from gcr/tests/test-data/Thawte_Personal_Premium_CA.pem with 100% similarity]
gcr/tests/files/Thawte_Premium_Server_CA.pem [moved from gcr/tests/test-data/Thawte_Premium_Server_CA.pem with 100% similarity]
gcr/tests/files/Thawte_Server_CA.pem [moved from gcr/tests/test-data/Thawte_Server_CA.pem with 100% similarity]
gcr/tests/files/Thawte_Time_Stamping_CA.pem [moved from gcr/tests/test-data/Thawte_Time_Stamping_CA.pem with 100% similarity]
gcr/tests/files/ca-certificates.crt [moved from gcr/tests/test-data/ca-certificates.crt with 100% similarity]
gcr/tests/files/cacert.org.pem [moved from gcr/tests/test-data/cacert.org.pem with 100% similarity]
gcr/tests/files/collabora-ca.cer [moved from gcr/tests/test-data/collabora-ca.cer with 100% similarity]
gcr/tests/files/der-certificate-dsa.cer [moved from gcr/tests/test-data/der-certificate-dsa.cer with 100% similarity]
gcr/tests/files/der-certificate.crt [moved from gcr/tests/test-data/der-certificate.crt with 100% similarity]
gcr/tests/files/der-dsa-1024.key [moved from gcr/tests/test-data/der-dsa-1024.key with 100% similarity]
gcr/tests/files/der-pkcs8-PBE-MD5-DES.key [moved from gcr/tests/test-data/der-pkcs8-PBE-MD5-DES.key with 100% similarity]
gcr/tests/files/der-pkcs8-PBE-SHA1-3DES.key [moved from gcr/tests/test-data/der-pkcs8-PBE-SHA1-3DES.key with 100% similarity]
gcr/tests/files/der-pkcs8-PBE-SHA1-DES.key [moved from gcr/tests/test-data/der-pkcs8-PBE-SHA1-DES.key with 100% similarity]
gcr/tests/files/der-pkcs8-PBE-SHA1-RC2-40.key [moved from gcr/tests/test-data/der-pkcs8-PBE-SHA1-RC2-40.key with 100% similarity]
gcr/tests/files/der-pkcs8-PBE-SHA1-RC4-128.key [moved from gcr/tests/test-data/der-pkcs8-PBE-SHA1-RC4-128.key with 100% similarity]
gcr/tests/files/der-pkcs8-dsa.key [moved from gcr/tests/test-data/der-pkcs8-dsa.key with 100% similarity]
gcr/tests/files/der-pkcs8-encrypted-pkcs5.key [moved from gcr/tests/test-data/der-pkcs8-encrypted-pkcs5.key with 100% similarity]
gcr/tests/files/der-pkcs8-v2-des.key [moved from gcr/tests/test-data/der-pkcs8-v2-des.key with 100% similarity]
gcr/tests/files/der-pkcs8-v2-des3.key [moved from gcr/tests/test-data/der-pkcs8-v2-des3.key with 100% similarity]
gcr/tests/files/der-pkcs8.key [moved from gcr/tests/test-data/der-pkcs8.key with 100% similarity]
gcr/tests/files/der-rsa-1024.key [moved from gcr/tests/test-data/der-rsa-1024.key with 100% similarity]
gcr/tests/files/dhansak-collabora.cer [moved from gcr/tests/test-data/dhansak-collabora.cer with 100% similarity]
gcr/tests/files/email.p12 [moved from gcr/tests/test-data/email.p12 with 100% similarity]
gcr/tests/files/pem-dsa-1024.key [moved from gcr/tests/test-data/pem-dsa-1024.key with 100% similarity]
gcr/tests/files/pem-pkcs8.key [moved from gcr/tests/test-data/pem-pkcs8.key with 100% similarity]
gcr/tests/files/pem-rsa-enc.key [moved from gcr/tests/test-data/pem-rsa-enc.key with 100% similarity]
gcr/tests/files/test-x509-swiss.p7b [moved from gcr/tests/test-data/test-x509-swiss.p7b with 100% similarity]
gcr/tests/files/unclient.p12 [moved from gcr/tests/test-data/unclient.p12 with 100% similarity]
gcr/tests/frob-certificate.c [moved from gcr/tests/ui-test-certificate.c with 100% similarity]
gcr/tests/frob-key.c [moved from gcr/tests/ui-test-key.c with 100% similarity]
gcr/tests/frob-selector.c [moved from gcr/tests/test-ui-selector.c with 100% similarity]
gcr/tests/frob-unlock-options.c [moved from gcr/tests/ui-test-unlock-options.c with 100% similarity]
gcr/tests/test-certificate-chain.c
gcr/tests/test-certificate.c
gcr/tests/test-parser.c [moved from gcr/tests/unit-test-parser.c with 57% similarity]
gcr/tests/test-pkcs11-certificate.c
gcr/tests/test-simple-certificate.c
gcr/tests/test-trust.c

index 86680bc..444ff75 100644 (file)
@@ -1535,7 +1535,7 @@ gcr_parser_add_password (GcrParser *self, const gchar *password)
 }
 
 gboolean
-gcr_parser_parse_data (GcrParser *self, const guchar *data,
+gcr_parser_parse_data (GcrParser *self, gconstpointer data,
                        gsize n_data, GError **err)
 {
        ForeachArgs args = { self, data, n_data, GCR_ERROR_UNRECOGNIZED };
index 60ab399..366a37a 100644 (file)
@@ -75,7 +75,7 @@ gboolean                 gcr_parser_format_supported       (GcrParser *self,
                                                             gint format);
 
 gboolean                 gcr_parser_parse_data             (GcrParser *self,
-                                                            const guchar *data,
+                                                            gconstpointer data,
                                                             gsize n_data,
                                                             GError **err);
 
index 7aa06c3..c8b4cd7 100644 (file)
@@ -1,43 +1,49 @@
 
-# Test files should be listed in order they need to run
-TESTING_FILES = \
-       test-certificate.c \
-       test-certificate-chain.c \
-       test-simple-certificate.c \
-       test-pkcs11-certificate.c \
-       test-trust.c \
-       unit-test-parser.c
-
-TESTING_LIBS =  \
+INCLUDES = \
+       -I$(top_srcdir)/egg \
+       -I$(top_srcdir)/gcr \
+       -DSRCDIR=$(srcdir) \
+       -DGCR_API_SUBJECT_TO_CHANGE \
+       -DGCK_API_SUBJECT_TO_CHANGE \
+       $(GLIB_CFLAGS) \
+       $(GTK_CFLAGS) \
+       $(LIBGCRYPT_CFLAGS)
+
+LDADD = \
        $(top_builddir)/gcr/libgcr@GCR_VERSION_SUFFIX@.la \
        $(top_builddir)/egg/libegg.la \
        $(top_builddir)/egg/libegg-entry-buffer.la \
-       $(top_builddir)/gck/libgck.la
+       $(top_builddir)/gck/libgck.la \
+       $(GTK_LIBS) \
+       $(GLIB_LIBS) \
+       $(LIBGCRYT_LIBS)
 
-TESTING_FLAGS = \
-       -DGCR_API_SUBJECT_TO_CHANGE \
-       -DGCK_API_SUBJECT_TO_CHANGE
+TEST_PROGS = \
+       test-certificate \
+       test-certificate-chain \
+       test-pkcs11-certificate \
+       test-simple-certificate \
+       test-trust \
+       test-parser
 
-include $(top_srcdir)/testing/testing.make
+check_PROGRAMS = $(TEST_PROGS)
 
-EXTRA_DIST += \
-       test-data
+test: $(TEST_PROGS)
+       SRCDIR='$(srcdir)' gtester -k --verbose ${TEST_PROGS}
 
-# ------------------------------------------------------------------
+check-local: test
 
-INCLUDES += \
-       -DGCR_API_SUBJECT_TO_CHANGE \
-       -DGCK_API_SUBJECT_TO_CHANGE \
-       $(GTK_CFLAGS)
+if WITH_TESTS
+all-local: $(check_PROGRAMS)
+endif
 
-LIBS += \
-       $(top_builddir)/gcr/libgcr@GCR_VERSION_SUFFIX@.la \
-       $(top_builddir)/gck/libgck.la \
-       $(GTK_LIBS) \
-       $(LIBGCRYPT_LIBS)
+EXTRA_DIST = \
+       test-data
+
+# ------------------------------------------------------------------
 
-noinst_PROGRAMS += \
-       test-ui-selector \
-       ui-test-certificate \
-       ui-test-key \
-       ui-test-unlock-options
+noinst_PROGRAMS = \
+       frob-selector \
+       frob-certificate \
+       frob-key \
+       frob-unlock-options
similarity index 100%
rename from gcr/tests/ui-test-key.c
rename to gcr/tests/frob-key.c
index 92284ec..701fb6d 100644 (file)
@@ -1,13 +1,34 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/*
+   Copyright (C) 2010 Collabora Ltd
 
-#include "config.h"
-#include "test-suite.h"
+   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.
 
-#include "egg/egg-asn1x.h"
-#include "egg/egg-asn1-defs.h"
+   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 <stefw@collabora.co.uk>
+*/
+
+#include "config.h"
 
 #include "gcr/gcr.h"
 #include "gcr/gcr-internal.h"
 
+#include "egg/egg-asn1x.h"
+#include "egg/egg-asn1-defs.h"
+#include "egg/egg-testing.h"
+
 #include "gck/gck-mock.h"
 #include "gck/gck-test.h"
 
@@ -16,6 +37,7 @@
 
 #include <glib.h>
 
+#include <errno.h>
 #include <string.h>
 
 /* ---------------------------------------------------------------------------
@@ -42,7 +64,9 @@ typedef struct _MockCertificateClass {
 
 static void mock_certificate_iface (GcrCertificateIface *iface);
 G_DEFINE_TYPE_WITH_CODE (MockCertificate, mock_certificate, G_TYPE_OBJECT,
-                         G_IMPLEMENT_INTERFACE (GCR_TYPE_CERTIFICATE, mock_certificate_iface));
+       GCR_CERTIFICATE_MIXIN_IMPLEMENT_COMPARABLE ();
+       G_IMPLEMENT_INTERFACE (GCR_TYPE_CERTIFICATE, mock_certificate_iface);
+);
 
 static void
 mock_certificate_init (MockCertificate *self)
@@ -64,6 +88,8 @@ mock_certificate_class_init (MockCertificateClass *klass)
 {
        GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
        gobject_class->finalize = mock_certificate_finalize;
+       gobject_class->get_property = gcr_certificate_mixin_get_property;
+       gcr_certificate_mixin_class_init (gobject_class);
 }
 
 static gconstpointer
@@ -95,16 +121,19 @@ mock_certificate_new (gconstpointer data, gsize n_data)
  * TESTS
  */
 
-static GcrCertificate *cert_self = NULL;
-static GcrCertificate *cert_ca = NULL;
-static GcrCertificate *cert_signed = NULL;
-static CK_FUNCTION_LIST funcs;
+typedef struct {
+       GcrCertificate *cert_self;
+       GcrCertificate *cert_ca;
+       GcrCertificate *cert_signed;
+       CK_FUNCTION_LIST funcs;
+} Test;
 
-TESTING_SETUP (certificate_chain)
+static void
+setup (Test *test, gconstpointer unused)
 {
        GList *modules = NULL;
        CK_FUNCTION_LIST_PTR f;
-       guchar *contents;
+       gchar *contents;
        gsize n_contents;
        const gchar *uris[2];
        CK_RV rv;
@@ -112,14 +141,14 @@ TESTING_SETUP (certificate_chain)
 
        rv = gck_mock_C_GetFunctionList (&f);
        gck_assert_cmprv (rv, ==, CKR_OK);
-       memcpy (&funcs, f, sizeof (funcs));
+       memcpy (&test->funcs, f, sizeof (test->funcs));
 
        /* Open a session */
-       rv = (funcs.C_Initialize) (NULL);
+       rv = (test->funcs.C_Initialize) (NULL);
        gck_assert_cmprv (rv, ==, CKR_OK);
 
        g_assert (!modules);
-       module = gck_module_new (&funcs, 0);
+       module = gck_module_new (&test->funcs, 0);
        modules = g_list_prepend (modules, module);
        gcr_pkcs11_set_modules (modules);
        uris[0] = GCK_MOCK_SLOT_ONE_URI;
@@ -129,18 +158,21 @@ TESTING_SETUP (certificate_chain)
        gck_list_unref_free (modules);
 
        /* A self-signed certificate */
-       contents = testing_data_read ("der-certificate.crt", &n_contents);
-       cert_self = gcr_simple_certificate_new (contents, n_contents);
+       if (!g_file_get_contents ("files/der-certificate.crt", &contents, &n_contents, NULL))
+               g_assert_not_reached ();
+       test->cert_self = gcr_simple_certificate_new (contents, n_contents);
        g_free (contents);
 
        /* A signed certificate */
-       contents = testing_data_read ("dhansak-collabora.cer", &n_contents);
-       cert_signed = mock_certificate_new (contents, n_contents);
+       if (!g_file_get_contents ("files/dhansak-collabora.cer", &contents, &n_contents, NULL))
+               g_assert_not_reached ();
+       test->cert_signed = mock_certificate_new (contents, n_contents);
        g_free (contents);
 
        /* The signer for the above certificate */
-       contents = testing_data_read ("collabora-ca.cer", &n_contents);
-       cert_ca = mock_certificate_new (contents, n_contents);
+       if (!g_file_get_contents ("files/collabora-ca.cer", &contents, &n_contents, NULL))
+               g_assert_not_reached ();
+       test->cert_ca = mock_certificate_new (contents, n_contents);
        g_free (contents);
 }
 
@@ -208,24 +240,21 @@ add_pinned_to_module (GcrCertificate *certificate, const gchar *purpose, const g
        gck_mock_module_take_object (attrs);
 }
 
-TESTING_TEARDOWN (certificate_chain)
+static void
+teardown (Test *test, gconstpointer unused)
 {
        CK_RV rv;
 
-       g_object_unref (cert_self);
-       cert_self = NULL;
-
-       g_object_unref (cert_signed);
-       cert_signed = NULL;
-
-       g_object_unref (cert_ca);
-       cert_ca = NULL;
+       g_object_unref (test->cert_self);
+       g_object_unref (test->cert_signed);
+       g_object_unref (test->cert_ca);
 
-       rv = (funcs.C_Finalize) (NULL);
+       rv = (test->funcs.C_Finalize) (NULL);
        gck_assert_cmprv (rv, ==, CKR_OK);
 }
 
-TESTING_TEST (certificate_chain_new)
+static void
+test_new (Test *test, gconstpointer unused)
 {
        GcrCertificateChain *chain;
 
@@ -240,15 +269,16 @@ TESTING_TEST (certificate_chain_new)
        g_object_unref (chain);
 }
 
-TESTING_TEST (certificate_chain_new_with_cert)
+static void
+test_new_with_cert (Test *test, gconstpointer unused)
 {
        GcrCertificateChain *chain;
        GcrCertificate *check;
        guint status, length;
 
        chain = gcr_certificate_chain_new ();
-       gcr_certificate_chain_add (chain, cert_signed);
-       gcr_certificate_chain_add (chain, cert_ca);
+       gcr_certificate_chain_add (chain, test->cert_signed);
+       gcr_certificate_chain_add (chain, test->cert_ca);
 
        g_assert_cmpuint (gcr_certificate_chain_get_status (chain), ==,
                          GCR_CERTIFICATE_CHAIN_UNKNOWN);
@@ -261,19 +291,20 @@ TESTING_TEST (certificate_chain_new_with_cert)
        g_assert_cmpuint (length, ==, 2);
 
        check = gcr_certificate_chain_get_certificate (chain, 1);
-       g_assert (check == cert_ca);
+       g_assert (check == test->cert_ca);
 
        /* Not yet completed */
        check = gcr_certificate_chain_get_anchor (chain);
        g_assert (check == NULL);
 
        check = gcr_certificate_chain_get_endpoint (chain);
-       g_assert (check == cert_signed);
+       g_assert (check == test->cert_signed);
 
        g_object_unref (chain);
 }
 
-TESTING_TEST (certificate_chain_selfsigned)
+static void
+test_selfsigned (Test *test, gconstpointer unused)
 {
        GcrCertificateChain *chain;
        GError *error = NULL;
@@ -281,7 +312,7 @@ TESTING_TEST (certificate_chain_selfsigned)
        chain = gcr_certificate_chain_new ();
 
        /* Add a self-signed certificate */
-       gcr_certificate_chain_add (chain, cert_self);
+       gcr_certificate_chain_add (chain, test->cert_self);
 
        if (!gcr_certificate_chain_build (chain, GCR_PURPOSE_CLIENT_AUTH,
                                          NULL, 0, NULL, &error))
@@ -294,7 +325,8 @@ TESTING_TEST (certificate_chain_selfsigned)
        g_object_unref (chain);
 }
 
-TESTING_TEST (certificate_chain_incomplete)
+static void
+test_incomplete (Test *test, gconstpointer unused)
 {
        GcrCertificateChain *chain;
        GError *error = NULL;
@@ -302,7 +334,7 @@ TESTING_TEST (certificate_chain_incomplete)
        chain = gcr_certificate_chain_new ();
 
        /* Add a signed certificate */
-       gcr_certificate_chain_add (chain, cert_signed);
+       gcr_certificate_chain_add (chain, test->cert_signed);
 
        if (!gcr_certificate_chain_build (chain, GCR_PURPOSE_CLIENT_AUTH,
                                          NULL, 0, NULL, &error))
@@ -315,7 +347,8 @@ TESTING_TEST (certificate_chain_incomplete)
        g_object_unref (chain);
 }
 
-TESTING_TEST (certificate_chain_empty)
+static void
+test_empty (Test *test, gconstpointer unused)
 {
        GcrCertificateChain *chain;
        GError *error = NULL;
@@ -335,7 +368,8 @@ TESTING_TEST (certificate_chain_empty)
        g_object_unref (chain);
 }
 
-TESTING_TEST (certificate_chain_trim_extras)
+static void
+test_trim_extras (Test *test, gconstpointer unused)
 {
        GcrCertificateChain *chain;
        GError *error = NULL;
@@ -343,8 +377,8 @@ TESTING_TEST (certificate_chain_trim_extras)
        chain = gcr_certificate_chain_new ();
 
        /* Add two unrelated certificates */
-       gcr_certificate_chain_add (chain, cert_self);
-       gcr_certificate_chain_add (chain, cert_signed);
+       gcr_certificate_chain_add (chain, test->cert_self);
+       gcr_certificate_chain_add (chain, test->cert_signed);
 
        g_assert_cmpuint (gcr_certificate_chain_get_length (chain), ==, 2);
 
@@ -365,10 +399,11 @@ fetch_async_result (GObject *source, GAsyncResult *result, gpointer user_data)
 {
        *((GAsyncResult**)user_data) = result;
        g_object_ref (result);
-       testing_wait_stop ();
+       egg_test_wait_stop ();
 }
 
-TESTING_TEST (certificate_chain_complete_async)
+static void
+test_complete_async (Test *test, gconstpointer unused)
 {
        GcrCertificateChain *chain;
        GError *error = NULL;
@@ -377,13 +412,13 @@ TESTING_TEST (certificate_chain_complete_async)
        chain = gcr_certificate_chain_new ();
 
        /* Add a whole bunch of certificates */
-       gcr_certificate_chain_add (chain, cert_signed);
-       gcr_certificate_chain_add (chain, cert_ca);
-       gcr_certificate_chain_add (chain, cert_self);
+       gcr_certificate_chain_add (chain, test->cert_signed);
+       gcr_certificate_chain_add (chain, test->cert_ca);
+       gcr_certificate_chain_add (chain, test->cert_self);
 
        gcr_certificate_chain_build_async (chain, GCR_PURPOSE_CLIENT_AUTH,
                                           NULL, 0, NULL, fetch_async_result, &result);
-       testing_wait_until (500);
+       egg_test_wait_until (500);
        if (!gcr_certificate_chain_build_finish (chain, result, &error))
                g_assert_not_reached ();
        g_assert_no_error (error);
@@ -396,7 +431,8 @@ TESTING_TEST (certificate_chain_complete_async)
        g_object_unref (chain);
 }
 
-TESTING_TEST (certificate_chain_with_anchor)
+static void
+test_with_anchor (Test *test, gconstpointer unused)
 {
        GcrCertificateChain *chain;
        GError *error = NULL;
@@ -404,9 +440,9 @@ TESTING_TEST (certificate_chain_with_anchor)
        chain = gcr_certificate_chain_new ();
 
        /* Two certificates in chain with ca trust anchor */
-       gcr_certificate_chain_add (chain, cert_signed);
-       gcr_certificate_chain_add (chain, cert_ca);
-       add_anchor_to_module (cert_ca, GCR_PURPOSE_CLIENT_AUTH);
+       gcr_certificate_chain_add (chain, test->cert_signed);
+       gcr_certificate_chain_add (chain, test->cert_ca);
+       add_anchor_to_module (test->cert_ca, GCR_PURPOSE_CLIENT_AUTH);
 
        g_assert_cmpuint (gcr_certificate_chain_get_length (chain), ==, 2);
 
@@ -418,12 +454,13 @@ TESTING_TEST (certificate_chain_with_anchor)
        g_assert_cmpuint (gcr_certificate_chain_get_status (chain), ==,
                          GCR_CERTIFICATE_CHAIN_ANCHORED);
        g_assert_cmpuint (gcr_certificate_chain_get_length (chain), ==, 2);
-       g_assert (gcr_certificate_chain_get_anchor (chain) == cert_ca);
+       g_assert (gcr_certificate_chain_get_anchor (chain) == test->cert_ca);
 
        g_object_unref (chain);
 }
 
-TESTING_TEST (certificate_chain_with_anchor_and_lookup_ca)
+static void
+test_with_anchor_and_lookup_ca (Test *test, gconstpointer unused)
 {
        GcrCertificateChain *chain;
        GError *error = NULL;
@@ -431,9 +468,9 @@ TESTING_TEST (certificate_chain_with_anchor_and_lookup_ca)
        chain = gcr_certificate_chain_new ();
 
        /* One signed certificate, with CA in pkcs11, and trust anchor */
-       gcr_certificate_chain_add (chain, cert_signed);
-       add_certificate_to_module (cert_ca);
-       add_anchor_to_module (cert_ca, GCR_PURPOSE_CLIENT_AUTH);
+       gcr_certificate_chain_add (chain, test->cert_signed);
+       add_certificate_to_module (test->cert_ca);
+       add_anchor_to_module (test->cert_ca, GCR_PURPOSE_CLIENT_AUTH);
 
        g_assert_cmpuint (gcr_certificate_chain_get_length (chain), ==, 1);
 
@@ -450,7 +487,8 @@ TESTING_TEST (certificate_chain_with_anchor_and_lookup_ca)
        g_object_unref (chain);
 }
 
-TESTING_TEST (certificate_chain_with_pinned)
+static void
+test_with_pinned (Test *test, gconstpointer unused)
 {
        GcrCertificateChain *chain;
        GError *error = NULL;
@@ -458,9 +496,9 @@ TESTING_TEST (certificate_chain_with_pinned)
        chain = gcr_certificate_chain_new ();
 
        /* One certificate, and add CA to pkcs11 */
-       gcr_certificate_chain_add (chain, cert_signed);
-       gcr_certificate_chain_add (chain, cert_ca);
-       add_pinned_to_module (cert_signed, GCR_PURPOSE_CLIENT_AUTH, "pinned.example.com");
+       gcr_certificate_chain_add (chain, test->cert_signed);
+       gcr_certificate_chain_add (chain, test->cert_ca);
+       add_pinned_to_module (test->cert_signed, GCR_PURPOSE_CLIENT_AUTH, "pinned.example.com");
 
        g_assert_cmpuint (gcr_certificate_chain_get_length (chain), ==, 2);
 
@@ -478,7 +516,8 @@ TESTING_TEST (certificate_chain_with_pinned)
        g_object_unref (chain);
 }
 
-TESTING_TEST (certificate_chain_without_lookups)
+static void
+test_without_lookups (Test *test, gconstpointer unused)
 {
        GcrCertificateChain *chain;
        GError *error = NULL;
@@ -486,8 +525,8 @@ TESTING_TEST (certificate_chain_without_lookups)
        chain = gcr_certificate_chain_new ();
 
        /* One certificate, and add CA to pkcs11 */
-       gcr_certificate_chain_add (chain, cert_signed);
-       add_certificate_to_module (cert_ca);
+       gcr_certificate_chain_add (chain, test->cert_signed);
+       add_certificate_to_module (test->cert_ca);
 
        g_assert_cmpuint (gcr_certificate_chain_get_length (chain), ==, 1);
 
@@ -506,19 +545,20 @@ TESTING_TEST (certificate_chain_without_lookups)
        g_object_unref (chain);
 }
 
-TESTING_TEST (certificate_chain_with_lookup_error)
+static void
+test_with_lookup_error (Test *test, gconstpointer unused)
 {
        GcrCertificateChain *chain;
        GError *error = NULL;
 
        /* Make the lookup fail */
-       funcs.C_GetAttributeValue = gck_mock_fail_C_GetAttributeValue;
+       test->funcs.C_GetAttributeValue = gck_mock_fail_C_GetAttributeValue;
 
        chain = gcr_certificate_chain_new ();
 
        /* Two certificates in chain with ca trust anchor */
-       gcr_certificate_chain_add (chain, cert_signed);
-       add_certificate_to_module (cert_ca);
+       gcr_certificate_chain_add (chain, test->cert_signed);
+       add_certificate_to_module (test->cert_ca);
 
        g_assert_cmpuint (gcr_certificate_chain_get_length (chain), ==, 1);
 
@@ -534,19 +574,20 @@ TESTING_TEST (certificate_chain_with_lookup_error)
        g_object_unref (chain);
 }
 
-TESTING_TEST (certificate_chain_with_anchor_error)
+static void
+test_with_anchor_error (Test *test, gconstpointer unused)
 {
        GcrCertificateChain *chain;
        GError *error = NULL;
 
        /* Make the lookup fail */
-       funcs.C_GetAttributeValue = gck_mock_fail_C_GetAttributeValue;
+       test->funcs.C_GetAttributeValue = gck_mock_fail_C_GetAttributeValue;
 
        chain = gcr_certificate_chain_new ();
 
        /* Two certificates in chain with ca trust anchor */
-       gcr_certificate_chain_add (chain, cert_signed);
-       add_certificate_to_module (cert_ca);
+       gcr_certificate_chain_add (chain, test->cert_signed);
+       add_certificate_to_module (test->cert_ca);
 
        if (gcr_certificate_chain_build (chain, GCR_PURPOSE_CLIENT_AUTH,
                                         NULL, 0, NULL, &error))
@@ -560,24 +601,25 @@ TESTING_TEST (certificate_chain_with_anchor_error)
        g_object_unref (chain);
 }
 
-TESTING_TEST (certificate_chain_with_anchor_error_async)
+static void
+test_with_anchor_error_async (Test *test, gconstpointer unused)
 {
        GcrCertificateChain *chain;
        GError *error = NULL;
        GAsyncResult *result;
 
        /* Make the lookup fail */
-       funcs.C_GetAttributeValue = gck_mock_fail_C_GetAttributeValue;
+       test->funcs.C_GetAttributeValue = gck_mock_fail_C_GetAttributeValue;
 
        chain = gcr_certificate_chain_new ();
 
        /* Two certificates in chain with ca trust anchor */
-       gcr_certificate_chain_add (chain, cert_signed);
-       add_certificate_to_module (cert_ca);
+       gcr_certificate_chain_add (chain, test->cert_signed);
+       add_certificate_to_module (test->cert_ca);
 
        gcr_certificate_chain_build_async (chain, GCR_PURPOSE_CLIENT_AUTH,
                                           NULL, 0, NULL, fetch_async_result, &result);
-       testing_wait_until (500);
+       egg_test_wait_until (500);
        if (gcr_certificate_chain_build_finish (chain, result, &error))
                g_assert_not_reached ();
        g_assert_error (error, GCK_ERROR, CKR_FUNCTION_FAILED);
@@ -589,3 +631,33 @@ TESTING_TEST (certificate_chain_with_anchor_error_async)
 
        g_object_unref (chain);
 }
+
+int
+main (int argc, char **argv)
+{
+       const gchar *srcdir;
+
+       g_type_init ();
+       g_test_init (&argc, &argv, NULL);
+
+       srcdir = g_getenv ("SRCDIR");
+       if (srcdir && chdir (srcdir) < 0)
+               g_error ("couldn't change directory to: %s: %s", srcdir, g_strerror (errno));
+
+       g_test_add ("/gcr/certificate-chain/new", Test, NULL, setup, test_new, teardown);
+       g_test_add ("/gcr/certificate-chain/new_with_cert", Test, NULL, setup, test_new_with_cert, teardown);
+       g_test_add ("/gcr/certificate-chain/selfsigned", Test, NULL, setup, test_selfsigned, teardown);
+       g_test_add ("/gcr/certificate-chain/incomplete", Test, NULL, setup, test_incomplete, teardown);
+       g_test_add ("/gcr/certificate-chain/empty", Test, NULL, setup, test_empty, teardown);
+       g_test_add ("/gcr/certificate-chain/trim_extras", Test, NULL, setup, test_trim_extras, teardown);
+       g_test_add ("/gcr/certificate-chain/complete_async", Test, NULL, setup, test_complete_async, teardown);
+       g_test_add ("/gcr/certificate-chain/with_anchor", Test, NULL, setup, test_with_anchor, teardown);
+       g_test_add ("/gcr/certificate-chain/with_anchor_and_lookup_ca", Test, NULL, setup, test_with_anchor_and_lookup_ca, teardown);
+       g_test_add ("/gcr/certificate-chain/with_pinned", Test, NULL, setup, test_with_pinned, teardown);
+       g_test_add ("/gcr/certificate-chain/without_lookups", Test, NULL, setup, test_without_lookups, teardown);
+       g_test_add ("/gcr/certificate-chain/with_lookup_error", Test, NULL, setup, test_with_lookup_error, teardown);
+       g_test_add ("/gcr/certificate-chain/with_anchor_error", Test, NULL, setup, test_with_anchor_error, teardown);
+       g_test_add ("/gcr/certificate-chain/with_anchor_error_async", Test, NULL, setup, test_with_anchor_error_async, teardown);
+
+       return egg_tests_run_in_thread_with_loop ();
+}
index ec84c2f..89d1741 100644 (file)
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/*
+   Copyright (C) 2010 Collabora Ltd
+
+   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 <stefw@collabora.co.uk>
+*/
 
 #include "config.h"
-#include "test-suite.h"
 
 #include "gcr/gcr.h"
 #include "gcr/gcr-internal.h"
 
+#include "egg/egg-testing.h"
+
 #include <glib.h>
 
+#include <errno.h>
 #include <string.h>
 
-static GcrCertificate *certificate = NULL;
-static GcrCertificate *dsa_cert = NULL;
-static GcrCertificate *dhansak_cert = NULL;
+typedef struct {
+       GcrCertificate *certificate;
+       GcrCertificate *dsa_cert;
+       GcrCertificate *dhansak_cert;
+} Test;
 
-TESTING_SETUP(certificate)
+static void
+setup (Test *test, gconstpointer unused)
 {
-       guchar *contents;
+       gchar *contents;
        gsize n_contents;
 
-       contents = testing_data_read ("der-certificate.crt", &n_contents);
-       certificate = gcr_simple_certificate_new (contents, n_contents);
-       g_assert (certificate);
+       if (!g_file_get_contents ("files/der-certificate.crt", &contents, &n_contents, NULL))
+               g_assert_not_reached ();
+       test->certificate = gcr_simple_certificate_new (contents, n_contents);
+       g_assert (test->certificate);
        g_free (contents);
 
-       contents = testing_data_read ("der-certificate-dsa.cer", &n_contents);
-       dsa_cert = gcr_simple_certificate_new (contents, n_contents);
-       g_assert (dsa_cert);
+       if (!g_file_get_contents ("files/der-certificate-dsa.cer", &contents, &n_contents, NULL))
+               g_assert_not_reached ();
+       test->dsa_cert = gcr_simple_certificate_new (contents, n_contents);
+       g_assert (test->dsa_cert);
        g_free (contents);
 
-       contents = testing_data_read ("dhansak-collabora.cer", &n_contents);
-       dhansak_cert = gcr_simple_certificate_new (contents, n_contents);
-       g_assert (certificate);
+       if (!g_file_get_contents ("files/dhansak-collabora.cer", &contents, &n_contents, NULL))
+               g_assert_not_reached ();
+       test->dhansak_cert = gcr_simple_certificate_new (contents, n_contents);
+       g_assert (test->certificate);
        g_free (contents);
 }
 
-TESTING_TEARDOWN(certificate)
+static void
+teardown (Test *test, gconstpointer unused)
 {
-       g_object_unref (certificate);
-       certificate = NULL;
-       g_object_unref (dsa_cert);
-       dsa_cert = NULL;
-       g_object_unref (dhansak_cert);
-       dhansak_cert = NULL;
+       g_object_unref (test->certificate);
+       g_object_unref (test->dsa_cert);
+       g_object_unref (test->dhansak_cert);
 }
 
-TESTING_TEST(issuer_cn)
+static void
+test_issuer_cn (Test *test, gconstpointer unused)
 {
-       gchar *cn = gcr_certificate_get_issuer_cn (certificate);
+       gchar *cn = gcr_certificate_get_issuer_cn (test->certificate);
        g_assert (cn);
        g_assert_cmpstr (cn, ==, "http://www.valicert.com/");
        g_free (cn);
 }
 
-TESTING_TEST(issuer_dn)
+static void
+test_issuer_dn (Test *test, gconstpointer unused)
 {
-       gchar *dn = gcr_certificate_get_issuer_dn (certificate);
+       gchar *dn = gcr_certificate_get_issuer_dn (test->certificate);
        g_assert (dn);
        g_assert_cmpstr (dn, ==, "L=ValiCert Validation Network, O=ValiCert, Inc., OU=ValiCert Class 3 Policy Validation Authority, CN=http://www.valicert.com/, EMAIL=info@valicert.com");
        g_free (dn);
 }
 
-TESTING_TEST(issuer_part)
+static void
+test_issuer_part (Test *test, gconstpointer unused)
 {
-       gchar *part = gcr_certificate_get_issuer_part (certificate, "l");
+       gchar *part = gcr_certificate_get_issuer_part (test->certificate, "l");
        g_assert (part);
        g_assert_cmpstr (part, ==, "ValiCert Validation Network");
        g_free (part);
 }
 
-TESTING_TEST(issuer_raw)
+static void
+test_issuer_raw (Test *test, gconstpointer unused)
 {
        gpointer der;
        gsize n_der;
 
-       der = gcr_certificate_get_issuer_raw (certificate, &n_der);
+       der = gcr_certificate_get_issuer_raw (test->certificate, &n_der);
        g_assert (der);
-       g_assert_cmpsize (n_der, ==, 190);
+       egg_assert_cmpsize (n_der, ==, 190);
        g_free (der);
 }
 
-TESTING_TEST(subject_cn)
+static void
+test_subject_cn (Test *test, gconstpointer unused)
 {
-       gchar *cn = gcr_certificate_get_subject_cn (certificate);
+       gchar *cn = gcr_certificate_get_subject_cn (test->certificate);
        g_assert (cn);
        g_assert_cmpstr (cn, ==, "http://www.valicert.com/");
        g_free (cn);
 
-       cn = gcr_certificate_get_subject_cn (dhansak_cert);
+       cn = gcr_certificate_get_subject_cn (test->dhansak_cert);
        g_assert (cn);
        g_assert_cmpstr (cn, ==, "dhansak.collabora.co.uk");
        g_free (cn);
 }
 
-TESTING_TEST(subject_dn)
+static void
+test_subject_dn (Test *test, gconstpointer unused)
 {
-       gchar *dn = gcr_certificate_get_subject_dn (certificate);
+       gchar *dn = gcr_certificate_get_subject_dn (test->certificate);
        g_assert (dn);
        g_assert_cmpstr (dn, ==, "L=ValiCert Validation Network, O=ValiCert, Inc., OU=ValiCert Class 3 Policy Validation Authority, CN=http://www.valicert.com/, EMAIL=info@valicert.com");
        g_free (dn);
 
-       dn = gcr_certificate_get_subject_dn (dhansak_cert);
+       dn = gcr_certificate_get_subject_dn (test->dhansak_cert);
        g_assert (dn);
        g_assert_cmpstr (dn, ==, "CN=dhansak.collabora.co.uk, EMAIL=sysadmin@collabora.co.uk");
        g_free (dn);
 
 }
 
-TESTING_TEST(subject_part)
+static void
+test_subject_part (Test *test, gconstpointer unused)
 {
-       gchar *part = gcr_certificate_get_subject_part (certificate, "OU");
+       gchar *part = gcr_certificate_get_subject_part (test->certificate, "OU");
        g_assert (part);
        g_assert_cmpstr (part, ==, "ValiCert Class 3 Policy Validation Authority");
        g_free (part);
 
-       part = gcr_certificate_get_subject_part (dhansak_cert, "EMAIL");
+       part = gcr_certificate_get_subject_part (test->dhansak_cert, "EMAIL");
        g_assert (part);
        g_assert_cmpstr (part, ==, "sysadmin@collabora.co.uk");
        g_free (part);
 
 }
 
-TESTING_TEST(subject_raw)
+static void
+test_subject_raw (Test *test, gconstpointer unused)
 {
        gpointer der;
        gsize n_der;
 
-       der = gcr_certificate_get_subject_raw (certificate, &n_der);
+       der = gcr_certificate_get_subject_raw (test->certificate, &n_der);
        g_assert (der);
-       g_assert_cmpsize (n_der, ==, 190);
+       egg_assert_cmpsize (n_der, ==, 190);
        g_free (der);
 
-       der = gcr_certificate_get_subject_raw (dhansak_cert, &n_der);
+       der = gcr_certificate_get_subject_raw (test->dhansak_cert, &n_der);
        g_assert (der);
-       g_assert_cmpsize (n_der, ==, 77);
+       egg_assert_cmpsize (n_der, ==, 77);
        g_free (der);
 }
 
-TESTING_TEST(issued_date)
+static void
+test_issued_date (Test *test, gconstpointer unused)
 {
-       GDate *date = gcr_certificate_get_issued_date (certificate);
+       GDate *date = gcr_certificate_get_issued_date (test->certificate);
        g_assert (date);
        g_assert_cmpuint (g_date_get_year (date), ==, 1999);
        g_assert_cmpuint (g_date_get_month (date), ==, 6);
@@ -146,9 +182,10 @@ TESTING_TEST(issued_date)
        g_date_free (date);
 }
 
-TESTING_TEST(expiry_date)
+static void
+test_expiry_date (Test *test, gconstpointer unused)
 {
-       GDate *date = gcr_certificate_get_expiry_date (certificate);
+       GDate *date = gcr_certificate_get_expiry_date (test->certificate);
        g_assert (date);
        g_assert_cmpuint (g_date_get_year (date), ==, 2019);
        g_assert_cmpuint (g_date_get_month (date), ==, 6);
@@ -156,56 +193,92 @@ TESTING_TEST(expiry_date)
        g_date_free (date);
 }
 
-TESTING_TEST(serial_number)
+static void
+test_serial_number (Test *test, gconstpointer unused)
 {
        gsize n_serial;
        guchar *serial;
        gchar *hex;
 
-       serial = gcr_certificate_get_serial_number (certificate, &n_serial);
+       serial = gcr_certificate_get_serial_number (test->certificate, &n_serial);
        g_assert (serial);
        g_assert_cmpuint (n_serial, ==, 1);
        g_assert (memcmp (serial, "\1", n_serial) == 0);
        g_free (serial);
 
-       hex = gcr_certificate_get_serial_number_hex (certificate);
+       hex = gcr_certificate_get_serial_number_hex (test->certificate);
        g_assert (hex);
        g_assert_cmpstr (hex, ==, "01");
        g_free (hex);
 }
 
-TESTING_TEST(fingerprint)
+static void
+test_fingerprint (Test *test, gconstpointer unused)
 {
        gsize n_print;
-       guchar *print = gcr_certificate_get_fingerprint (certificate, G_CHECKSUM_MD5, &n_print);
+       guchar *print = gcr_certificate_get_fingerprint (test->certificate, G_CHECKSUM_MD5, &n_print);
        g_assert (print);
        g_assert_cmpuint (n_print, ==, g_checksum_type_get_length (G_CHECKSUM_MD5));
        g_assert (memcmp (print, "\xa2\x6f\x53\xb7\xee\x40\xdb\x4a\x68\xe7\xfa\x18\xd9\x10\x4b\x72", n_print) == 0);
        g_free (print);
 }
 
-TESTING_TEST(fingerprint_hex)
+static void
+test_fingerprint_hex (Test *test, gconstpointer unused)
 {
-       gchar *print = gcr_certificate_get_fingerprint_hex (certificate, G_CHECKSUM_MD5);
+       gchar *print = gcr_certificate_get_fingerprint_hex (test->certificate, G_CHECKSUM_MD5);
        g_assert (print);
        g_assert_cmpstr (print, ==, "A2 6F 53 B7 EE 40 DB 4A 68 E7 FA 18 D9 10 4B 72");
        g_free (print);
 }
 
-TESTING_TEST (certificate_key_size)
+static void
+test_certificate_key_size (Test *test, gconstpointer unused)
 {
-       guint key_size = gcr_certificate_get_key_size (certificate);
+       guint key_size = gcr_certificate_get_key_size (test->certificate);
        g_assert_cmpuint (key_size, ==, 1024);
 
-       key_size = gcr_certificate_get_key_size (dsa_cert);
+       key_size = gcr_certificate_get_key_size (test->dsa_cert);
        g_assert_cmpuint (key_size, ==, 1024);
 }
 
-TESTING_TEST (certificate_is_issuer)
+static void
+test_certificate_is_issuer (Test *test, gconstpointer unused)
 {
-       gboolean ret = gcr_certificate_is_issuer (certificate, certificate);
+       gboolean ret = gcr_certificate_is_issuer (test->certificate, test->certificate);
        g_assert (ret == TRUE);
 
-       ret = gcr_certificate_is_issuer (certificate, dsa_cert);
+       ret = gcr_certificate_is_issuer (test->certificate, test->dsa_cert);
        g_assert (ret == FALSE);
 }
+
+int
+main (int argc, char **argv)
+{
+       const gchar *srcdir;
+
+       g_type_init ();
+       g_test_init (&argc, &argv, NULL);
+
+       srcdir = g_getenv ("SRCDIR");
+       if (srcdir && chdir (srcdir) < 0)
+               g_error ("couldn't change directory to: %s: %s", srcdir, g_strerror (errno));
+
+       g_test_add ("/gcr/certificate/issuer_cn", Test, NULL, setup, test_issuer_cn, teardown);
+       g_test_add ("/gcr/certificate/issuer_dn", Test, NULL, setup, test_issuer_dn, teardown);
+       g_test_add ("/gcr/certificate/issuer_part", Test, NULL, setup, test_issuer_part, teardown);
+       g_test_add ("/gcr/certificate/issuer_raw", Test, NULL, setup, test_issuer_raw, teardown);
+       g_test_add ("/gcr/certificate/subject_cn", Test, NULL, setup, test_subject_cn, teardown);
+       g_test_add ("/gcr/certificate/subject_dn", Test, NULL, setup, test_subject_dn, teardown);
+       g_test_add ("/gcr/certificate/subject_part", Test, NULL, setup, test_subject_part, teardown);
+       g_test_add ("/gcr/certificate/subject_raw", Test, NULL, setup, test_subject_raw, teardown);
+       g_test_add ("/gcr/certificate/issued_date", Test, NULL, setup, test_issued_date, teardown);
+       g_test_add ("/gcr/certificate/expiry_date", Test, NULL, setup, test_expiry_date, teardown);
+       g_test_add ("/gcr/certificate/serial_number", Test, NULL, setup, test_serial_number, teardown);
+       g_test_add ("/gcr/certificate/fingerprint", Test, NULL, setup, test_fingerprint, teardown);
+       g_test_add ("/gcr/certificate/fingerprint_hex", Test, NULL, setup, test_fingerprint_hex, teardown);
+       g_test_add ("/gcr/certificate/certificate_key_size", Test, NULL, setup, test_certificate_key_size, teardown);
+       g_test_add ("/gcr/certificate/certificate_is_issuer", Test, NULL, setup, test_certificate_is_issuer, teardown);
+
+       return g_test_run ();
+}
similarity index 57%
rename from gcr/tests/unit-test-parser.c
rename to gcr/tests/test-parser.c
index 5600be7..ae2c466 100644 (file)
@@ -23,8 +23,6 @@
 
 #include "config.h"
 
-#include "test-suite.h"
-
 #include "egg/egg-error.h"
 #include "egg/egg-secure-memory.h"
 
@@ -36,6 +34,7 @@
 #include <glib.h>
 #include <gcrypt.h>
 
+#include <errno.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
  * Tests be run in the order specified here.
  */
 
-static GcrParser *parser = NULL;
-static const gchar* filedesc = NULL;
+typedef struct {
+       GcrParser *parser;
+       gchar* filedesc;
+} Test;
 
 static void
 parsed_item (GcrParser *par, gpointer user_data)
@@ -62,59 +63,62 @@ parsed_item (GcrParser *par, gpointer user_data)
        GckAttributes *attrs;
        const gchar *description;
        const gchar *label;
+       Test *test = user_data;
 
        g_assert (GCR_IS_PARSER (par));
-       g_assert (par == parser);
-       g_assert (par == user_data);
+       g_assert (par == test->parser);
 
-       attrs = gcr_parser_get_parsed_attributes (parser);
-       description = gcr_parser_get_parsed_description (parser);
-       label = gcr_parser_get_parsed_label (parser);
+       attrs = gcr_parser_get_parsed_attributes (test->parser);
+       description = gcr_parser_get_parsed_description (test->parser);
+       label = gcr_parser_get_parsed_label (test->parser);
 
-       g_print ("parsed %s '%s' at: %s\n", description, label, filedesc);
+       g_print ("parsed %s '%s' at: %s\n", description, label, test->filedesc);
 }
 
 static gboolean
 authenticate (GcrParser *par, gint state, gpointer user_data)
 {
+       Test *test = user_data;
+
        g_assert (GCR_IS_PARSER (par));
-       g_assert (par == parser);
-       g_assert (par == user_data);
+       g_assert (par == test->parser);
 
        switch (state) {
        case 0:
-               gcr_parser_add_password (parser, "booo");
+               gcr_parser_add_password (test->parser, "booo");
                return TRUE;
        default:
-               g_printerr ("decryption didn't work for: %s", filedesc);
-               g_assert (FALSE);
+               g_printerr ("decryption didn't work for: %s", test->filedesc);
+               g_assert_not_reached ();
                return FALSE;
        };
 }
 
-TESTING_SETUP(parser)
+static void
+setup (Test *test, gconstpointer unused)
 {
-       parser = gcr_parser_new ();
-       g_signal_connect (parser, "parsed", G_CALLBACK (parsed_item), parser);
-       g_signal_connect (parser, "authenticate", G_CALLBACK (authenticate), parser);
+       test->parser = gcr_parser_new ();
+       g_signal_connect (test->parser, "parsed", G_CALLBACK (parsed_item), test);
+       g_signal_connect (test->parser, "authenticate", G_CALLBACK (authenticate), test);
 }
 
-TESTING_TEARDOWN(parser)
+static void
+teardown (Test *test, gconstpointer unused)
 {
-       g_object_unref (parser);
-       parser = NULL;
+       g_object_unref (test->parser);
 }
 
-TESTING_TEST(parse_all)
+static void
+test_parse_all (Test *test, gconstpointer unused)
 {
-       guchar *contents;
+       gchar *contents;
        GError *err = NULL;
        gboolean result;
        const gchar *filename;
        gsize len;
        GDir *dir;
 
-       dir = g_dir_open (testing_data_directory (), 0, NULL);
+       dir = g_dir_open ("files", 0, NULL);
        g_assert (dir);
 
        for (;;) {
@@ -124,19 +128,40 @@ TESTING_TEST(parse_all)
                if (filename[0] == '.')
                        continue;
 
-               filedesc = filename;
-               contents = testing_data_read (filename, &len);
+               test->filedesc = g_build_filename ("files", filename, NULL);
+               if (!g_file_get_contents (test->filedesc, &contents, &len, NULL))
+                       g_assert_not_reached ();
 
-               result = gcr_parser_parse_data (parser, contents, len, &err);
+               result = gcr_parser_parse_data (test->parser, contents, len, &err);
                g_free (contents);
 
                if (!result) {
                        g_warning ("couldn't parse file data: %s: %s",
                                   filename, egg_error_message (err));
                        g_error_free (err);
-                       g_assert (FALSE);
+                       g_assert_not_reached ();
                }
+
+               g_free (test->filedesc);
+               test->filedesc = NULL;
        }
 
        g_dir_close (dir);
 }
+
+int
+main (int argc, char **argv)
+{
+       const gchar *srcdir;
+
+       g_type_init ();
+       g_test_init (&argc, &argv, NULL);
+
+       srcdir = g_getenv ("SRCDIR");
+       if (srcdir && chdir (srcdir) < 0)
+               g_error ("couldn't change directory to: %s: %s", srcdir, g_strerror (errno));
+
+       g_test_add ("/gcr/parser/parse_all", Test, NULL, setup, test_parse_all, teardown);
+
+       return g_test_run ();
+}
index beb0bd4..52379aa 100644 (file)
 
 #include "config.h"
 
-#include "test-suite.h"
-
 #include "egg/egg-asn1x.h"
 #include "egg/egg-asn1-defs.h"
 
 #include "gcr.h"
 #include "gcr/gcr-internal.h"
 
+#include "egg/egg-testing.h"
+
 #include "gck/gck-mock.h"
 #include "gck/gck-test.h"
 
 
 #include <glib.h>
 
-static gpointer cert_data = NULL;
-static gsize n_cert_data = 0;
-static gpointer cert2_data = NULL;
-static gsize n_cert2_data = 0;
-static CK_FUNCTION_LIST funcs;
+#include <errno.h>
+
+typedef struct {
+       gpointer cert_data;
+       gsize n_cert_data;
+       gpointer cert2_data;
+       gsize n_cert2_data;
+       CK_FUNCTION_LIST funcs;
+} Test;
 
-TESTING_SETUP (pkcs11_certificate)
+static void
+setup (Test *test, gconstpointer unused)
 {
        GList *modules = NULL;
        GckAttributes *attrs;
@@ -54,34 +59,39 @@ TESTING_SETUP (pkcs11_certificate)
        GNode *asn, *node;
        CK_RV rv;
 
-       cert_data = testing_data_read ("der-certificate.crt", &n_cert_data);
-       g_assert (cert_data);
+       if (!g_file_get_contents ("files/der-certificate.crt", (gchar**)&test->cert_data,
+                                 &test->n_cert_data, NULL))
+               g_assert_not_reached ();
+       g_assert (test->cert_data);
 
-       cert2_data = testing_data_read ("der-certificate-dsa.cer", &n_cert2_data);
-       g_assert (cert2_data);
+       if (!g_file_get_contents ("files/der-certificate-dsa.cer", (gchar**)&test->cert2_data,
+                                 &test->n_cert2_data, NULL))
+               g_assert_not_reached ();
+       g_assert (test->cert2_data);
 
        rv = gck_mock_C_GetFunctionList (&f);
        gck_assert_cmprv (rv, ==, CKR_OK);
-       memcpy (&funcs, f, sizeof (funcs));
+       memcpy (&test->funcs, f, sizeof (test->funcs));
 
        /* Open a session */
-       rv = (funcs.C_Initialize) (NULL);
+       rv = (test->funcs.C_Initialize) (NULL);
        gck_assert_cmprv (rv, ==, CKR_OK);
 
        g_assert (!modules);
-       module = gck_module_new (&funcs, 0);
+       module = gck_module_new (&test->funcs, 0);
        modules = g_list_prepend (modules, module);
        gcr_pkcs11_set_modules (modules);
        gck_list_unref_free (modules);
 
-       asn = egg_asn1x_create_and_decode (pkix_asn1_tab, "Certificate", cert_data, n_cert_data);
+       asn = egg_asn1x_create_and_decode (pkix_asn1_tab, "Certificate",
+                                          test->cert_data, test->n_cert_data);
        g_assert (asn);
        node = egg_asn1x_node (asn, "tbsCertificate", "subject", NULL);
        subject = egg_asn1x_get_raw_element (node, &n_subject);
 
        /* Add a certificate to the module */
        attrs = gck_attributes_new ();
-       gck_attributes_add_data (attrs, CKA_VALUE, cert_data, n_cert_data);
+       gck_attributes_add_data (attrs, CKA_VALUE, test->cert_data, test->n_cert_data);
        gck_attributes_add_ulong (attrs, CKA_CLASS, CKO_CERTIFICATE);
        gck_attributes_add_ulong (attrs, CKA_CERTIFICATE_TYPE, CKC_X_509);
        gck_attributes_add_data (attrs, CKA_SUBJECT, subject, n_subject);
@@ -90,23 +100,20 @@ TESTING_SETUP (pkcs11_certificate)
        egg_asn1x_destroy (asn);
 }
 
-TESTING_TEARDOWN (pkcs11_certificate)
+static void
+teardown (Test *test, gconstpointer unused)
 {
        CK_RV rv;
 
-       g_free (cert_data);
-       cert_data = NULL;
-       n_cert_data = 0;
+       g_free (test->cert_data);
+       g_free (test->cert2_data);
 
-       g_free (cert2_data);
-       cert2_data = NULL;
-       n_cert2_data = 0;
-
-       rv = (funcs.C_Finalize) (NULL);
+       rv = (test->funcs.C_Finalize) (NULL);
        gck_assert_cmprv (rv, ==, CKR_OK);
 }
 
-TESTING_TEST (pkcs11_lookup_certificate_issuer)
+static void
+test_lookup_certificate_issuer (Test *test, gconstpointer unused)
 {
        GcrCertificate *cert, *issuer;
        GError *error = NULL;
@@ -115,7 +122,7 @@ TESTING_TEST (pkcs11_lookup_certificate_issuer)
        gconstpointer der;
        gsize n_der;
 
-       cert = gcr_simple_certificate_new_static (cert_data, n_cert_data);
+       cert = gcr_simple_certificate_new_static (test->cert_data, test->n_cert_data);
        g_assert (cert);
 
        /* Should be self-signed, so should find itself (added in setup) */
@@ -125,16 +132,16 @@ TESTING_TEST (pkcs11_lookup_certificate_issuer)
 
        /* Should be the same certificate */
        der = gcr_certificate_get_der_data (issuer, &n_der);
-       g_assert_cmpsize (n_der, ==, n_cert_data);
-       g_assert (memcmp (der, cert_data, n_cert_data) == 0);
+       egg_assert_cmpsize (n_der, ==, test->n_cert_data);
+       g_assert (memcmp (der, test->cert_data, test->n_cert_data) == 0);
 
        /* Should return the same certificate here too */
        attrs = gcr_pkcs11_certificate_get_attributes (GCR_PKCS11_CERTIFICATE (issuer));
        g_assert (attrs);
        attr = gck_attributes_find (attrs, CKA_VALUE);
        g_assert (attr);
-       g_assert_cmpsize (attr->length, ==, n_cert_data);
-       g_assert (memcmp (attr->value, cert_data, n_cert_data) == 0);
+       egg_assert_cmpsize (attr->length, ==, test->n_cert_data);
+       g_assert (memcmp (attr->value, test->cert_data, test->n_cert_data) == 0);
 
        /* Should return the same certificate here too */
        attrs = NULL;
@@ -142,20 +149,21 @@ TESTING_TEST (pkcs11_lookup_certificate_issuer)
        g_assert (attrs);
        attr = gck_attributes_find (attrs, CKA_VALUE);
        g_assert (attr);
-       g_assert_cmpsize (attr->length, ==, n_cert_data);
-       g_assert (memcmp (attr->value, cert_data, n_cert_data) == 0);
+       egg_assert_cmpsize (attr->length, ==, test->n_cert_data);
+       g_assert (memcmp (attr->value, test->cert_data, test->n_cert_data) == 0);
        gck_attributes_unref (attrs);
 
        g_object_unref (cert);
        g_object_unref (issuer);
 }
 
-TESTING_TEST (pkcs11_lookup_certificate_issuer_not_found)
+static void
+test_lookup_certificate_issuer_not_found (Test *test, gconstpointer unused)
 {
        GcrCertificate *cert, *issuer;
        GError *error = NULL;
 
-       cert = gcr_simple_certificate_new_static (cert2_data, n_cert2_data);
+       cert = gcr_simple_certificate_new_static (test->cert2_data, test->n_cert2_data);
        g_assert (cert);
 
        /* Issuer shouldn't be found */
@@ -171,10 +179,11 @@ fetch_async_result (GObject *source, GAsyncResult *result, gpointer user_data)
 {
        *((GAsyncResult**)user_data) = result;
        g_object_ref (result);
-       testing_wait_stop ();
+       egg_test_wait_stop ();
 }
 
-TESTING_TEST (pkcs11_lookup_certificate_issuer_async)
+static void
+test_lookup_certificate_issuer_async (Test *test, gconstpointer unused)
 {
        GAsyncResult *result = NULL;
        GcrCertificate *cert, *issuer;
@@ -182,12 +191,12 @@ TESTING_TEST (pkcs11_lookup_certificate_issuer_async)
        gconstpointer der;
        gsize n_der;
 
-       cert = gcr_simple_certificate_new_static (cert_data, n_cert_data);
+       cert = gcr_simple_certificate_new_static (test->cert_data, test->n_cert_data);
        g_assert (cert);
 
        /* Should be self-signed, so should find itself (added in setup) */
        gcr_pkcs11_certificate_lookup_issuer_async (cert, NULL, fetch_async_result, &result);
-       testing_wait_until (500);
+       egg_test_wait_until (500);
        g_assert (result);
        issuer = gcr_pkcs11_certificate_lookup_issuer_finish (result, &error);
        g_assert (GCR_IS_PKCS11_CERTIFICATE (issuer));
@@ -197,23 +206,24 @@ TESTING_TEST (pkcs11_lookup_certificate_issuer_async)
 
        /* Should be the same certificate */
        der = gcr_certificate_get_der_data (issuer, &n_der);
-       g_assert_cmpsize (n_der, ==, n_cert_data);
-       g_assert (memcmp (der, cert_data, n_cert_data) == 0);
+       egg_assert_cmpsize (n_der, ==, test->n_cert_data);
+       g_assert (memcmp (der, test->cert_data, test->n_cert_data) == 0);
 
        g_object_unref (cert);
        g_object_unref (issuer);
 }
 
-TESTING_TEST (pkcs11_lookup_certificate_issuer_failure)
+static void
+test_lookup_certificate_issuer_failure (Test *test, gconstpointer unused)
 {
        GcrCertificate *cert, *issuer;
        GError *error = NULL;
 
-       cert = gcr_simple_certificate_new_static (cert_data, n_cert_data);
+       cert = gcr_simple_certificate_new_static (test->cert_data, test->n_cert_data);
        g_assert (cert);
 
        /* Make the lookup fail */
-       funcs.C_GetAttributeValue = gck_mock_fail_C_GetAttributeValue;
+       test->funcs.C_GetAttributeValue = gck_mock_fail_C_GetAttributeValue;
 
        issuer = gcr_pkcs11_certificate_lookup_issuer (cert, NULL, &error);
        g_assert (issuer == NULL);
@@ -224,21 +234,22 @@ TESTING_TEST (pkcs11_lookup_certificate_issuer_failure)
        g_object_unref (cert);
 }
 
-TESTING_TEST (pkcs11_lookup_certificate_issuer_fail_async)
+static void
+test_lookup_certificate_issuer_fail_async (Test *test, gconstpointer unused)
 {
        GAsyncResult *result = NULL;
        GcrCertificate *cert, *issuer;
        GError *error = NULL;
 
-       cert = gcr_simple_certificate_new_static (cert_data, n_cert_data);
+       cert = gcr_simple_certificate_new_static (test->cert_data, test->n_cert_data);
        g_assert (cert);
 
        /* Make the lookup fail */
-       funcs.C_GetAttributeValue = gck_mock_fail_C_GetAttributeValue;
+       test->funcs.C_GetAttributeValue = gck_mock_fail_C_GetAttributeValue;
 
        /* Should be self-signed, so should find itself (added in setup) */
        gcr_pkcs11_certificate_lookup_issuer_async (cert, NULL, fetch_async_result, &result);
-       testing_wait_until (500);
+       egg_test_wait_until (500);
        g_assert (result);
        issuer = gcr_pkcs11_certificate_lookup_issuer_finish (result, &error);
        g_assert (issuer == NULL);
@@ -250,3 +261,24 @@ TESTING_TEST (pkcs11_lookup_certificate_issuer_fail_async)
 
        g_object_unref (cert);
 }
+
+int
+main (int argc, char **argv)
+{
+       const gchar *srcdir;
+
+       g_type_init ();
+       g_test_init (&argc, &argv, NULL);
+
+       srcdir = g_getenv ("SRCDIR");
+       if (srcdir && chdir (srcdir) < 0)
+               g_error ("couldn't change directory to: %s: %s", srcdir, g_strerror (errno));
+
+       g_test_add ("/gcr/pkcs11-certificate/lookup_certificate_issuer", Test, NULL, setup, test_lookup_certificate_issuer, teardown);
+       g_test_add ("/gcr/pkcs11-certificate/lookup_certificate_issuer_not_found", Test, NULL, setup, test_lookup_certificate_issuer_not_found, teardown);
+       g_test_add ("/gcr/pkcs11-certificate/lookup_certificate_issuer_async", Test, NULL, setup, test_lookup_certificate_issuer_async, teardown);
+       g_test_add ("/gcr/pkcs11-certificate/lookup_certificate_issuer_failure", Test, NULL, setup, test_lookup_certificate_issuer_failure, teardown);
+       g_test_add ("/gcr/pkcs11-certificate/lookup_certificate_issuer_fail_async", Test, NULL, setup, test_lookup_certificate_issuer_fail_async, teardown);
+
+       return egg_tests_run_in_thread_with_loop ();
+}
index 3bc18dd..8b7d416 100644 (file)
@@ -22,8 +22,6 @@
 
 #include "config.h"
 
-#include "test-suite.h"
-
 #include "gcr.h"
 #include "gcr/gcr-internal.h"
 
 
 #include "pkcs11/pkcs11n.h"
 
+#include "egg/egg-testing.h"
+
 #include <glib.h>
 
-static gpointer cert_data;
-static gsize n_cert_data;
+#include <errno.h>
+
+typedef struct {
+       gpointer cert_data;
+       gsize n_cert_data;
+} Test;
 
-TESTING_SETUP (simple_certificate)
+static void
+setup (Test *test, gconstpointer unused)
 {
-       cert_data = testing_data_read ("der-certificate.crt", &n_cert_data);
-       g_assert (cert_data);
+       if (!g_file_get_contents ("files/der-certificate.crt", (gchar**)&test->cert_data,
+                                 &test->n_cert_data, NULL))
+               g_assert_not_reached ();
+       g_assert (test->cert_data);
 }
 
-TESTING_TEARDOWN (simple_certificate)
+static void
+teardown (Test *test, gconstpointer unused)
 {
-       g_free (cert_data);
-       cert_data = NULL;
-       n_cert_data = 0;
+       g_free (test->cert_data);
 }
 
-TESTING_TEST (simple_certificate_new)
+static void
+test_new (Test *test, gconstpointer unused)
 {
        GcrCertificate *cert;
        gconstpointer der;
        gsize n_der;
 
-       cert = gcr_simple_certificate_new (cert_data, n_cert_data);
+       cert = gcr_simple_certificate_new (test->cert_data, test->n_cert_data);
        g_assert (GCR_IS_SIMPLE_CERTIFICATE (cert));
 
        der = gcr_certificate_get_der_data (cert, &n_der);
        g_assert (der);
-       g_assert_cmpsize (n_der, ==, n_cert_data);
-       g_assert (memcmp (der, cert_data, n_der) == 0);
+       egg_assert_cmpmem (der, n_der, ==, test->cert_data, test->n_cert_data);
 
        g_object_unref (cert);
 }
 
-TESTING_TEST (simple_certificate_new_static)
+static void
+test_new_static (Test *test, gconstpointer unused)
 {
        GcrCertificate *cert;
        gconstpointer der;
        gsize n_der;
 
-       cert = gcr_simple_certificate_new_static (cert_data, n_cert_data);
+       cert = gcr_simple_certificate_new_static (test->cert_data, test->n_cert_data);
        g_assert (GCR_IS_SIMPLE_CERTIFICATE (cert));
 
        der = gcr_certificate_get_der_data (cert, &n_der);
        g_assert (der);
-       g_assert_cmpsize (n_der, ==, n_cert_data);
-       g_assert (der == cert_data); /* Must be same pointer */
+       egg_assert_cmpsize (n_der, ==, test->n_cert_data);
+       g_assert (der == test->cert_data); /* Must be same pointer */
 
        g_object_unref (cert);
 }
+
+int
+main (int argc, char **argv)
+{
+       const gchar *srcdir;
+
+       g_type_init ();
+       g_test_init (&argc, &argv, NULL);
+
+       srcdir = g_getenv ("SRCDIR");
+       if (srcdir && chdir (srcdir) < 0)
+               g_error ("couldn't change directory to: %s: %s", srcdir, g_strerror (errno));
+
+       g_test_add ("/gcr/simple-certificate/new", Test, NULL, setup, test_new, teardown);
+       g_test_add ("/gcr/simple-certificate/new_static", Test, NULL, setup, test_new_static, teardown);
+
+       return g_test_run ();
+}
index 545fce0..f21f80d 100644 (file)
@@ -22,8 +22,6 @@
 
 #include "config.h"
 
-#include "test-suite.h"
-
 #include "gcr.h"
 #include "gcr/gcr-internal.h"
 
 #include "pkcs11/pkcs11n.h"
 #include "pkcs11/pkcs11x.h"
 
+#include "egg/egg-testing.h"
+
 #include <glib.h>
 
-static CK_FUNCTION_LIST funcs;
-static GcrCertificate *certificate = NULL;
+#include <errno.h>
+
+typedef struct {
+       CK_FUNCTION_LIST funcs;
+       GcrCertificate *certificate;
+} Test;
 
-TESTING_SETUP (trust_setup)
+static void
+setup (Test *test, gconstpointer unused)
 {
        GList *modules = NULL;
        CK_FUNCTION_LIST_PTR f;
        GckModule *module;
-       guchar *contents;
+       gchar *contents;
        const gchar *uris[2];
        gsize len;
        CK_RV rv;
 
-       contents = testing_data_read ("der-certificate.crt", &len);
+       if (!g_file_get_contents ("files/der-certificate.crt", &contents, &len, NULL))
+               g_assert_not_reached ();
        g_assert (contents);
 
-       certificate = gcr_simple_certificate_new (contents, len);
+       test->certificate = gcr_simple_certificate_new (contents, len);
        g_free (contents);
 
        rv = gck_mock_C_GetFunctionList (&f);
        gck_assert_cmprv (rv, ==, CKR_OK);
-       memcpy (&funcs, f, sizeof (funcs));
+       memcpy (&test->funcs, f, sizeof (test->funcs));
 
        /* Open a session */
-       rv = (funcs.C_Initialize) (NULL);
+       rv = (test->funcs.C_Initialize) (NULL);
        gck_assert_cmprv (rv, ==, CKR_OK);
 
        g_assert (!modules);
-       module = gck_module_new (&funcs, 0);
+       module = gck_module_new (&test->funcs, 0);
        modules = g_list_prepend (modules, module);
        gcr_pkcs11_set_modules (modules);
        gck_list_unref_free (modules);
@@ -76,79 +82,83 @@ TESTING_SETUP (trust_setup)
        gcr_pkcs11_set_trust_lookup_uris (uris);
 }
 
-TESTING_TEARDOWN (trust_setup)
+static void
+teardown (Test *test, gconstpointer unused)
 {
        CK_RV rv;
 
-       g_object_unref (certificate);
-       certificate = NULL;
+       g_object_unref (test->certificate);
 
-       rv = (funcs.C_Finalize) (NULL);
+       rv = (test->funcs.C_Finalize) (NULL);
        gck_assert_cmprv (rv, ==, CKR_OK);
 }
 
-TESTING_TEST (trust_is_pinned_none)
+static void
+test_is_pinned_none (Test *test, gconstpointer unused)
 {
        GError *error = NULL;
        gboolean trust;
 
-       trust = gcr_trust_is_certificate_pinned (certificate, GCR_PURPOSE_EMAIL, "host", NULL, &error);
+       trust = gcr_trust_is_certificate_pinned (test->certificate, GCR_PURPOSE_EMAIL, "host", NULL, &error);
        g_assert_cmpint (trust, ==, FALSE);
        g_assert (error == NULL);
 }
 
-TESTING_TEST (trust_add_and_is_pinned)
+static void
+test_add_and_is_pinned (Test *test, gconstpointer unused)
 {
        GError *error = NULL;
        gboolean trust;
        gboolean ret;
 
-       trust = gcr_trust_is_certificate_pinned (certificate, GCR_PURPOSE_EMAIL, "host", NULL, &error);
+       trust = gcr_trust_is_certificate_pinned (test->certificate, GCR_PURPOSE_EMAIL, "host", NULL, &error);
        g_assert_cmpint (trust, ==, FALSE);
        g_assert (error == NULL);
 
-       ret = gcr_trust_add_pinned_certificate (certificate, GCR_PURPOSE_EMAIL, "host", NULL, &error);
+       ret = gcr_trust_add_pinned_certificate (test->certificate, GCR_PURPOSE_EMAIL, "host", NULL, &error);
        g_assert (ret == TRUE);
        g_assert (error == NULL);
 
-       trust = gcr_trust_is_certificate_pinned (certificate, GCR_PURPOSE_EMAIL, "host", NULL, &error);
+       trust = gcr_trust_is_certificate_pinned (test->certificate, GCR_PURPOSE_EMAIL, "host", NULL, &error);
        g_assert_cmpint (trust, ==, TRUE);
        g_assert (error == NULL);
 }
 
-TESTING_TEST (trust_add_certificate_pinned_fail)
+static void
+test_add_certificate_pinned_fail (Test *test, gconstpointer unused)
 {
        GError *error = NULL;
        gboolean ret;
 
        /* Make this function fail */
-       funcs.C_CreateObject = gck_mock_fail_C_CreateObject;
+       test->funcs.C_CreateObject = gck_mock_fail_C_CreateObject;
 
-       ret = gcr_trust_add_pinned_certificate (certificate, GCR_PURPOSE_CLIENT_AUTH, "peer", NULL, &error);
+       ret = gcr_trust_add_pinned_certificate (test->certificate, GCR_PURPOSE_CLIENT_AUTH, "peer", NULL, &error);
        g_assert (ret == FALSE);
        g_assert_error (error, GCK_ERROR, CKR_FUNCTION_FAILED);
        g_clear_error (&error);
 }
 
-TESTING_TEST (trust_add_and_remov_pinned)
+static void
+test_add_and_remov_pinned (Test *test, gconstpointer unused)
 {
        GError *error = NULL;
        gboolean trust;
        gboolean ret;
 
-       ret = gcr_trust_add_pinned_certificate (certificate, GCR_PURPOSE_EMAIL, "host", NULL, &error);
+       ret = gcr_trust_add_pinned_certificate (test->certificate, GCR_PURPOSE_EMAIL, "host", NULL, &error);
        g_assert (ret == TRUE);
        g_assert (error == NULL);
 
-       trust = gcr_trust_is_certificate_pinned (certificate, GCR_PURPOSE_EMAIL, "host", NULL, &error);
+       trust = gcr_trust_is_certificate_pinned (test->certificate, GCR_PURPOSE_EMAIL, "host", NULL, &error);
        g_assert_cmpint (trust, ==, TRUE);
        g_assert (error == NULL);
 
-       ret = gcr_trust_remove_pinned_certificate (certificate, GCR_PURPOSE_EMAIL, "host", NULL, &error);
+       ret = gcr_trust_remove_pinned_certificate (test->certificate, GCR_PURPOSE_EMAIL, "host", NULL, &error);
        g_assert (ret == TRUE);
        g_assert (error == NULL);
 
-       trust = gcr_trust_is_certificate_pinned (certificate, GCR_PURPOSE_EMAIL, "host", NULL, &error);
+       trust = gcr_trust_is_certificate_pinned (test->certificate, GCR_PURPOSE_EMAIL, "host", NULL, &error);
        g_assert_cmpint (trust, ==, FALSE);
        g_assert (error == NULL);
 }
@@ -158,18 +168,19 @@ fetch_async_result (GObject *source, GAsyncResult *result, gpointer user_data)
 {
        *((GAsyncResult**)user_data) = result;
        g_object_ref (result);
-       testing_wait_stop ();
+       egg_test_wait_stop ();
 }
 
-TESTING_TEST (trust_add_and_is_pinned_async)
+static void
+test_add_and_is_pinned_async (Test *test, gconstpointer unused)
 {
        GAsyncResult *result = NULL;
        GError *error = NULL;
        gboolean trust;
        gboolean ret;
 
-       gcr_trust_is_certificate_pinned_async (certificate, GCR_PURPOSE_EMAIL, "host", NULL, fetch_async_result, &result);
-       testing_wait_until (500);
+       gcr_trust_is_certificate_pinned_async (test->certificate, GCR_PURPOSE_EMAIL, "host", NULL, fetch_async_result, &result);
+       egg_test_wait_until (500);
        g_assert (result);
        trust = gcr_trust_is_certificate_pinned_finish (result, &error);
        g_assert (trust == FALSE);
@@ -177,9 +188,9 @@ TESTING_TEST (trust_add_and_is_pinned_async)
        g_object_unref (result);
        result = NULL;
 
-       gcr_trust_add_pinned_certificate_async (certificate, GCR_PURPOSE_EMAIL, "host",
-                                                  NULL, fetch_async_result, &result);
-       testing_wait_until (500);
+       gcr_trust_add_pinned_certificate_async (test->certificate, GCR_PURPOSE_EMAIL, "host",
+                                               NULL, fetch_async_result, &result);
+       egg_test_wait_until (500);
        g_assert (result);
        ret = gcr_trust_add_pinned_certificate_finish (result, &error);
        g_assert (ret == TRUE);
@@ -187,8 +198,8 @@ TESTING_TEST (trust_add_and_is_pinned_async)
        g_object_unref (result);
        result = NULL;
 
-       gcr_trust_is_certificate_pinned_async (certificate, GCR_PURPOSE_EMAIL, "host", NULL, fetch_async_result, &result);
-       testing_wait_until (500);
+       gcr_trust_is_certificate_pinned_async (test->certificate, GCR_PURPOSE_EMAIL, "host", NULL, fetch_async_result, &result);
+       egg_test_wait_until (500);
        g_assert (result);
        trust = gcr_trust_is_certificate_pinned_finish (result, &error);
        g_assert (trust == TRUE);
@@ -197,15 +208,16 @@ TESTING_TEST (trust_add_and_is_pinned_async)
        result = NULL;
 }
 
-TESTING_TEST (trust_add_and_remov_pinned_async)
+static void
+test_add_and_remov_pinned_async (Test *test, gconstpointer unused)
 {
        GAsyncResult *result = NULL;
        GError *error = NULL;
        gboolean trust;
        gboolean ret;
 
-       gcr_trust_add_pinned_certificate_async (certificate, GCR_PURPOSE_EMAIL, "host", NULL, fetch_async_result, &result);
-       testing_wait_until (500);
+       gcr_trust_add_pinned_certificate_async (test->certificate, GCR_PURPOSE_EMAIL, "host", NULL, fetch_async_result, &result);
+       egg_test_wait_until (500);
        g_assert (result);
        ret = gcr_trust_add_pinned_certificate_finish (result, &error);
        g_assert (ret == TRUE);
@@ -213,8 +225,8 @@ TESTING_TEST (trust_add_and_remov_pinned_async)
        g_object_unref (result);
        result = NULL;
 
-       gcr_trust_is_certificate_pinned_async (certificate, GCR_PURPOSE_EMAIL, "host", NULL, fetch_async_result, &result);
-       testing_wait_until (500);
+       gcr_trust_is_certificate_pinned_async (test->certificate, GCR_PURPOSE_EMAIL, "host", NULL, fetch_async_result, &result);
+       egg_test_wait_until (500);
        g_assert (result);
        trust = gcr_trust_is_certificate_pinned_finish (result, &error);
        g_assert (trust == TRUE);
@@ -222,8 +234,8 @@ TESTING_TEST (trust_add_and_remov_pinned_async)
        g_object_unref (result);
        result = NULL;
 
-       gcr_trust_remove_pinned_certificate_async (certificate, GCR_PURPOSE_EMAIL, "host", NULL, fetch_async_result, &result);
-       testing_wait_until (500);
+       gcr_trust_remove_pinned_certificate_async (test->certificate, GCR_PURPOSE_EMAIL, "host", NULL, fetch_async_result, &result);
+       egg_test_wait_until (500);
        g_assert (result);
        ret = gcr_trust_remove_pinned_certificate_finish (result, &error);
        g_assert (ret == TRUE);
@@ -231,8 +243,8 @@ TESTING_TEST (trust_add_and_remov_pinned_async)
        g_object_unref (result);
        result = NULL;
 
-       gcr_trust_is_certificate_pinned_async (certificate, GCR_PURPOSE_EMAIL, "host", NULL, fetch_async_result, &result);
-       testing_wait_until (500);
+       gcr_trust_is_certificate_pinned_async (test->certificate, GCR_PURPOSE_EMAIL, "host", NULL, fetch_async_result, &result);
+       egg_test_wait_until (500);
        g_assert (result);
        trust = gcr_trust_is_certificate_pinned_finish (result, &error);
        g_assert (trust == FALSE);
@@ -241,17 +253,19 @@ TESTING_TEST (trust_add_and_remov_pinned_async)
        result = NULL;
 }
 
-TESTING_TEST (trust_is_certificate_anchored_not)
+static void
+test_is_certificate_anchored_not (Test *test, gconstpointer unused)
 {
        GError *error = NULL;
        gboolean ret;
 
-       ret = gcr_trust_is_certificate_anchored (certificate, GCR_PURPOSE_CLIENT_AUTH, NULL, &error);
+       ret = gcr_trust_is_certificate_anchored (test->certificate, GCR_PURPOSE_CLIENT_AUTH, NULL, &error);
        g_assert (ret == FALSE);
        g_assert (error == NULL);
 }
 
-TESTING_TEST (trust_is_certificate_anchored_yes)
+static void
+test_is_certificate_anchored_yes (Test *test, gconstpointer unused)
 {
        GError *error = NULL;
        GckAttributes *attrs;
@@ -261,7 +275,7 @@ TESTING_TEST (trust_is_certificate_anchored_yes)
 
        /* Create a certificate root trust */
        attrs = gck_attributes_new ();
-       der = gcr_certificate_get_der_data (certificate, &n_der);
+       der = gcr_certificate_get_der_data (test->certificate, &n_der);
        gck_attributes_add_data (attrs, CKA_X_CERTIFICATE_VALUE, der, n_der);
        gck_attributes_add_ulong (attrs, CKA_CLASS, CKO_X_TRUST_ASSERTION);
        gck_attributes_add_boolean (attrs, CKA_TOKEN, TRUE);
@@ -269,19 +283,20 @@ TESTING_TEST (trust_is_certificate_anchored_yes)
        gck_attributes_add_ulong (attrs, CKA_X_ASSERTION_TYPE, CKT_X_ANCHORED_CERTIFICATE);
        gck_mock_module_take_object (attrs);
 
-       ret = gcr_trust_is_certificate_anchored (certificate, GCR_PURPOSE_CLIENT_AUTH, NULL, &error);
+       ret = gcr_trust_is_certificate_anchored (test->certificate, GCR_PURPOSE_CLIENT_AUTH, NULL, &error);
        g_assert (ret == TRUE);
        g_assert (error == NULL);
 }
 
-TESTING_TEST (trust_is_certificate_anchored_async)
+static void
+test_is_certificate_anchored_async (Test *test, gconstpointer unused)
 {
        GAsyncResult *result = NULL;
        GError *error = NULL;
        gboolean ret;
 
-       gcr_trust_is_certificate_anchored_async (certificate, GCR_PURPOSE_CLIENT_AUTH, NULL, fetch_async_result, &result);
-       testing_wait_until (500);
+       gcr_trust_is_certificate_anchored_async (test->certificate, GCR_PURPOSE_CLIENT_AUTH, NULL, fetch_async_result, &result);
+       egg_test_wait_until (500);
        g_assert (result);
 
        ret = gcr_trust_is_certificate_anchored_finish (result, &error);
@@ -290,3 +305,28 @@ TESTING_TEST (trust_is_certificate_anchored_async)
 
        g_object_unref (result);
 }
+
+int
+main (int argc, char **argv)
+{
+       const gchar *srcdir;
+
+       g_type_init ();
+       g_test_init (&argc, &argv, NULL);
+
+       srcdir = g_getenv ("SRCDIR");
+       if (srcdir && chdir (srcdir) < 0)
+               g_error ("couldn't change directory to: %s: %s", srcdir, g_strerror (errno));
+
+       g_test_add ("/gcr/trust/is_pinned_none", Test, NULL, setup, test_is_pinned_none, teardown);
+       g_test_add ("/gcr/trust/add_and_is_pinned", Test, NULL, setup, test_add_and_is_pinned, teardown);
+       g_test_add ("/gcr/trust/add_certificate_pinned_fail", Test, NULL, setup, test_add_certificate_pinned_fail, teardown);
+       g_test_add ("/gcr/trust/add_and_remov_pinned", Test, NULL, setup, test_add_and_remov_pinned, teardown);
+       g_test_add ("/gcr/trust/add_and_is_pinned_async", Test, NULL, setup, test_add_and_is_pinned_async, teardown);
+       g_test_add ("/gcr/trust/add_and_remov_pinned_async", Test, NULL, setup, test_add_and_remov_pinned_async, teardown);
+       g_test_add ("/gcr/trust/is_certificate_anchored_not", Test, NULL, setup, test_is_certificate_anchored_not, teardown);
+       g_test_add ("/gcr/trust/is_certificate_anchored_yes", Test, NULL, setup, test_is_certificate_anchored_yes, teardown);
+       g_test_add ("/gcr/trust/is_certificate_anchored_async", Test, NULL, setup, test_is_certificate_anchored_async, teardown);
+
+       return egg_tests_run_in_thread_with_loop ();
+}