Use more modern gtest style for egg tests.
authorStef Walter <stefw@collabora.co.uk>
Wed, 23 Feb 2011 17:55:29 +0000 (18:55 +0100)
committerStef Walter <stefw@collabora.co.uk>
Wed, 23 Feb 2011 17:55:29 +0000 (18:55 +0100)
27 files changed:
egg/Makefile.am
egg/egg-hkdf.h [new file with mode: 0644]
egg/egg-testing.c [new file with mode: 0644]
egg/egg-testing.h [new file with mode: 0644]
egg/tests/Makefile.am
egg/tests/files/dh-params.pem [moved from egg/tests/test-data/dh-params.pem with 100% similarity]
egg/tests/files/echo-script.sh [moved from egg/tests/test-data/echo-script.sh with 100% similarity]
egg/tests/files/pem-rsa-enc.key [moved from egg/tests/test-data/pem-rsa-enc.key with 100% similarity]
egg/tests/files/test-certificate-1.der [moved from egg/tests/test-data/test-certificate-1.der with 100% similarity]
egg/tests/files/test-personalname-1.der [moved from egg/tests/test-data/test-personalname-1.der with 100% similarity]
egg/tests/files/test-pkcs12-1.der [moved from egg/tests/test-data/test-pkcs12-1.der with 100% similarity]
egg/tests/files/test-pkcs7-1.der [moved from egg/tests/test-data/test-pkcs7-1.der with 100% similarity]
egg/tests/files/test-pkcs7-2.der [moved from egg/tests/test-data/test-pkcs7-2.der with 100% similarity]
egg/tests/files/test-pkcs8-1.der [moved from egg/tests/test-data/test-pkcs8-1.der with 100% similarity]
egg/tests/files/test-rsakey-1.der [moved from egg/tests/test-data/test-rsakey-1.der with 100% similarity]
egg/tests/test-asn1.c
egg/tests/test-asn1x.c
egg/tests/test-dh.c [moved from egg/tests/unit-test-dh.c with 76% similarity]
egg/tests/test-dn.c
egg/tests/test-hex.c [moved from egg/tests/unit-test-hex.c with 84% similarity]
egg/tests/test-oid.c [moved from egg/tests/unit-test-oid.c with 89% similarity]
egg/tests/test-openssl.c [moved from egg/tests/unit-test-openssl.c with 60% similarity]
egg/tests/test-padding.c
egg/tests/test-secmem.c [moved from egg/tests/unit-test-secmem.c with 86% similarity]
egg/tests/test-symkey.c [moved from egg/tests/unit-test-symkey.c with 71% similarity]
egg/tests/unit-test-asn1.c [deleted file]
egg/tests/unit-test-spawn.c [deleted file]

index 7b30f7f..8485605 100644 (file)
@@ -39,6 +39,7 @@ libegg_la_SOURCES = \
        egg-secure-memory.c egg-secure-memory.h \
        egg-spawn.c egg-spawn.h \
        egg-symkey.c egg-symkey.h \
+       egg-testing.c egg-testing.h \
        egg-asn1-defs.h \
        $(BUILT_SOURCES)
 
diff --git a/egg/egg-hkdf.h b/egg/egg-hkdf.h
new file mode 100644 (file)
index 0000000..430d331
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * gnome-keyring
+ *
+ * Copyright (C) 2011 Collabora Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General  License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General  License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * License along with this program; 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>
+ */
+
+#ifndef EGG_HKDF_H_
+#define EGG_HKDF_H_
+
+#include <glib.h>
+
+gboolean   egg_hkdf_perform                                   (const gchar *hash_algo,
+                                                               gconstpointer input,
+                                                               gsize n_input,
+                                                               gconstpointer salt,
+                                                               gsize n_salt,
+                                                               gconstpointer info,
+                                                               gsize n_info,
+                                                               gpointer output,
+                                                               gsize n_output);
+
+#endif /* EGG_HKDF_H_ */
diff --git a/egg/egg-testing.c b/egg/egg-testing.c
new file mode 100644 (file)
index 0000000..b41ec85
--- /dev/null
@@ -0,0 +1,178 @@
+/*
+ * gnome-keyring
+ *
+ * Copyright (C) 2011 Collabora Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General  License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General  License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Stef Walter <stefw@collabora.co.uk>
+ */
+
+#include "config.h"
+
+#include "egg-testing.h"
+
+#include <errno.h>
+#include <unistd.h>
+
+static GCond *wait_condition = NULL;
+static GCond *wait_start = NULL;
+static GMutex *wait_mutex = NULL;
+static gboolean wait_waiting = FALSE;
+
+static const char HEXC[] = "0123456789ABCDEF";
+
+static gchar*
+hex_dump (const guchar *data, gsize n_data)
+{
+       GString *result;
+       gsize i;
+       guchar j;
+
+       g_assert (data);
+
+       result = g_string_sized_new (n_data * 2 + 1);
+       for (i = 0; i < n_data; ++i) {
+               g_string_append (result, "\\x");
+
+               j = data[i] >> 4 & 0xf;
+               g_string_append_c (result, HEXC[j]);
+               j = data[i] & 0xf;
+               g_string_append_c (result, HEXC[j]);
+       }
+
+       return g_string_free (result, FALSE);
+}
+
+void
+egg_assertion_message_cmpmem (const char     *domain,
+                              const char     *file,
+                              int             line,
+                              const char     *func,
+                              const char     *expr,
+                              gconstpointer   arg1,
+                              gsize           n_arg1,
+                              const char     *cmp,
+                              gconstpointer   arg2,
+                              gsize           n_arg2)
+{
+  char *a1, *a2, *s;
+  a1 = arg1 ? hex_dump (arg1, n_arg1) : g_strdup ("NULL");
+  a2 = arg2 ? hex_dump (arg2, n_arg2) : g_strdup ("NULL");
+  s = g_strdup_printf ("assertion failed (%s): (%s %s %s)", expr, a1, cmp, a2);
+  g_free (a1);
+  g_free (a2);
+  g_assertion_message (domain, file, line, func, s);
+  g_free (s);
+}
+
+void
+egg_tests_chdir_base (gchar* argv0)
+{
+       gchar *dir, *base;
+
+       dir = g_path_get_dirname (argv0);
+       if (chdir (dir) < 0)
+               g_warning ("couldn't change directory to: %s: %s",
+                          dir, g_strerror (errno));
+
+       base = g_path_get_basename (dir);
+       if (strcmp (base, ".libs") == 0) {
+               if (chdir ("..") < 0)
+                       g_warning ("couldn't change directory to ..: %s",
+                                  g_strerror (errno));
+       }
+
+       g_free (base);
+       g_free (dir);
+}
+
+void
+egg_test_wait_stop (void)
+{
+       GTimeVal tv;
+
+       g_get_current_time (&tv);
+       g_time_val_add (&tv, 1000);
+
+       g_assert (wait_mutex);
+       g_assert (wait_condition);
+       g_mutex_lock (wait_mutex);
+               if (!wait_waiting)
+                       g_cond_timed_wait (wait_start, wait_mutex, &tv);
+               g_assert (wait_waiting);
+               g_cond_broadcast (wait_condition);
+       g_mutex_unlock (wait_mutex);
+}
+
+gboolean
+egg_test_wait_until (int timeout)
+{
+       GTimeVal tv;
+       gboolean ret;
+
+       g_get_current_time (&tv);
+       g_time_val_add (&tv, timeout * 1000);
+
+       g_assert (wait_mutex);
+       g_assert (wait_condition);
+       g_mutex_lock (wait_mutex);
+               g_assert (!wait_waiting);
+               wait_waiting = TRUE;
+               g_cond_broadcast (wait_start);
+               ret = g_cond_timed_wait (wait_condition, wait_mutex, &tv);
+               g_assert (wait_waiting);
+               wait_waiting = FALSE;
+       g_mutex_unlock (wait_mutex);
+
+       return ret;
+}
+
+static gpointer
+testing_thread (gpointer loop)
+{
+       /* Must have been defined by the test including this file */
+       gint ret = g_test_run ();
+       g_main_loop_quit (loop);
+       return GINT_TO_POINTER (ret);
+}
+
+gint
+egg_tests_run_in_thread_with_loop (void)
+{
+       GThread *thread;
+       GMainLoop *loop;
+       gpointer ret;
+
+       g_thread_init (NULL);
+
+       loop = g_main_loop_new (NULL, FALSE);
+       wait_condition = g_cond_new ();
+       wait_start = g_cond_new ();
+       wait_mutex = g_mutex_new ();
+
+       thread = g_thread_create (testing_thread, loop, TRUE, NULL);
+       g_assert (thread);
+
+       g_main_loop_run (loop);
+       ret = g_thread_join (thread);
+       g_main_loop_unref (loop);
+
+       g_cond_free (wait_condition);
+       g_mutex_free (wait_mutex);
+
+       return GPOINTER_TO_INT (ret);
+}
diff --git a/egg/egg-testing.h b/egg/egg-testing.h
new file mode 100644 (file)
index 0000000..0d74d81
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * gnome-keyring
+ *
+ * Copyright (C) 2011 Stefan Walter
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General  License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General  License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * License along with this program; 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>
+ */
+
+#ifndef EGG_TESTING_H_
+#define EGG_TESTING_H_
+
+#include <glib.h>
+#include <string.h>
+
+#define egg_assert_cmpsize(a, o, b) \
+       g_assert_cmpuint ((guint)(a), o, (guint)(b))
+
+#define egg_assert_cmpmem(a, na, cmp, b, nb) \
+       do { gconstpointer __p1 = (a), __p2 = (b); gsize __n1 = (na), __n2 = (nb); \
+            if (__n1 cmp __n2 && memcmp (__p1, __p2, __n1) cmp 0) ; else \
+               egg_assertion_message_cmpmem (G_LOG_DOMAIN, __FILE__, __LINE__, \
+                   G_STRFUNC, #a "[" #na"] " #cmp " " #b "[" #nb "]", \
+                    __p1, __n1, #cmp, __p2, __n2); } while (0)
+
+void       egg_assertion_message_cmpmem        (const char *domain, const char *file,
+                                                int line, const char *func,
+                                                const char *expr, gconstpointer arg1,
+                                                gsize n_arg1, const char *cmp,
+                                                gconstpointer arg2, gsize n_arg2);
+
+void       egg_test_wait_stop                  (void);
+
+gboolean   egg_test_wait_until                 (int timeout);
+
+void       egg_tests_chdir_base                (gchar* argv0);
+
+gint       egg_tests_run_in_thread_with_loop   (void);
+
+#endif /* EGG_DH_H_ */
index 4db2975..4f7fa48 100644 (file)
@@ -1,41 +1,53 @@
+
 asn1-def-test.c: test.asn
        $(ASN1PARSER) -o asn1-def-test.c $(srcdir)/test.asn
 
-TESTING_SOURCES = \
-       asn1-def-test.c
-
-# Test files should be listed in order they need to run
-TESTING_FILES = \
+INCLUDES = \
+       -I$(top_srcdir)/egg \
+       -DSRCDIR=$(srcdir) \
+       $(GLIB_CFLAGS)
+
+LDADD =  \
+       $(top_builddir)/egg/libegg.la \
+       $(LIBGCRYPT_LIBS) \
+       $(GTHREAD_LIBS) \
+       $(GLIB_LIBS)
+
+TEST_PROGS = \
+       test-asn1 \
+       test-dn \
+       test-cleanup \
+       test-hex \
+       test-oid \
+       test-secmem \
+       test-padding \
+       test-symkey \
+       test-openssl \
+       test-dh \
+       test-spawn
+
+test_asn1_SOURCES = \
        test-asn1.c \
-       unit-test-asn1.c \
-       test-dn.c \
-       unit-test-cleanup.c \
-       unit-test-hex.c \
-       unit-test-oid.c \
-       test-padding.c \
-       unit-test-secmem.c \
-       unit-test-symkey.c \
-       unit-test-openssl.c \
-       unit-test-dh.c \
-       unit-test-spawn.c
-
-UNIT_PROMPT =
-
-TESTING_LIBS =  \
-       $(top_builddir)/egg/libegg.la
-
-include $(top_srcdir)/testing/testing.make
-
-BUILT_SOURCES += \
        asn1-def-test.c
 
-EXTRA_DIST += \
+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
+
+EXTRA_DIST = \
        test.asn \
-       test-data
+       files
 
 # ------------------------------------------------------------------------------
 
-noinst_PROGRAMS += \
+noinst_PROGRAMS = \
        test-asn1x
 
 test_asn1x_SOURCES = \
@@ -43,4 +55,5 @@ test_asn1x_SOURCES = \
 
 test_asn1x_LDADD = \
        $(top_builddir)/egg/libegg-asn1x.la \
-       $(LIBTASN1_LIBS)
+       $(LIBTASN1_LIBS) \
+       $(LDADD)
index 8e2ac79..39f188d 100644 (file)
@@ -23,9 +23,9 @@
 
 #include "config.h"
 
-#include "test-suite.h"
-
-#include "egg/egg-asn1x.h"
+#include "egg-asn1x.h"
+#include "egg-asn1-defs.h"
+#include "egg-testing.h"
 
 #include <glib.h>
 #include <libtasn1.h>
@@ -55,7 +55,8 @@ const gchar ENUM_THREE[] =           "\x0A\x01\x03";
 
 #define XL(x) G_N_ELEMENTS (x) - 1
 
-TESTING_TEST(asn1_boolean)
+static void
+test_boolean (void)
 {
        GNode *asn;
        gboolean value;
@@ -92,7 +93,8 @@ TESTING_TEST(asn1_boolean)
        egg_asn1x_destroy (asn);
 }
 
-TESTING_TEST(asn1_integer)
+static void
+test_integer (void)
 {
        GNode *asn;
        gulong value;
@@ -120,7 +122,8 @@ TESTING_TEST(asn1_integer)
        egg_asn1x_destroy (asn);
 }
 
-TESTING_TEST(asn1_octet_string)
+static void
+test_octet_string (void)
 {
        GNode *asn;
        gchar *value;
@@ -148,7 +151,8 @@ TESTING_TEST(asn1_octet_string)
        egg_asn1x_destroy (asn);
 }
 
-TESTING_TEST(asn1_generalized_time)
+static void
+test_generalized_time (void)
 {
        GNode *asn;
        glong value;
@@ -175,7 +179,8 @@ TESTING_TEST(asn1_generalized_time)
        egg_asn1x_destroy (asn);
 }
 
-TESTING_TEST(asn1_implicit)
+static void
+test_implicit (void)
 {
        GNode *asn;
        gchar *value;
@@ -193,7 +198,8 @@ TESTING_TEST(asn1_implicit)
        egg_asn1x_destroy (asn);
 }
 
-TESTING_TEST(asn1_explicit)
+static void
+test_explicit (void)
 {
        GNode *asn;
        gchar *value;
@@ -211,7 +217,8 @@ TESTING_TEST(asn1_explicit)
        egg_asn1x_destroy (asn);
 }
 
-TESTING_TEST(asn1_bit_string_decode)
+static void
+test_bit_string_decode (void)
 {
        GNode *asn;
        guchar *bits;
@@ -235,7 +242,8 @@ TESTING_TEST(asn1_bit_string_decode)
        egg_asn1x_destroy (asn);
 }
 
-TESTING_TEST(asn1_bit_string_decode_bad)
+static void
+test_bit_string_decode_bad (void)
 {
        GNode *asn;
 
@@ -249,7 +257,8 @@ TESTING_TEST(asn1_bit_string_decode_bad)
        egg_asn1x_destroy (asn);
 }
 
-TESTING_TEST(asn1_bit_string_decode_ulong)
+static void
+test_bit_string_decode_ulong (void)
 {
        GNode *asn;
        gulong bits;
@@ -271,7 +280,8 @@ TESTING_TEST(asn1_bit_string_decode_ulong)
        egg_asn1x_destroy (asn);
 }
 
-TESTING_TEST(asn1_bit_string_encode_decode)
+static void
+test_bit_string_encode_decode (void)
 {
        GNode *asn;
        guchar bits[] = { 0x5d, 0x6e, 0x83 };
@@ -305,7 +315,8 @@ TESTING_TEST(asn1_bit_string_encode_decode)
        egg_asn1x_destroy (asn);
 }
 
-TESTING_TEST(asn1_bit_string_encode_decode_ulong)
+static void
+test_bit_string_encode_decode_ulong (void)
 {
        GNode *asn;
        gulong check, bits = 0x0101b977;
@@ -335,7 +346,8 @@ TESTING_TEST(asn1_bit_string_encode_decode_ulong)
        egg_asn1x_destroy (asn);
 }
 
-TESTING_TEST(asn1_bit_string_encode_decode_zero)
+static void
+test_bit_string_encode_decode_zero (void)
 {
        GNode *asn;
        gpointer data;
@@ -350,14 +362,15 @@ TESTING_TEST(asn1_bit_string_encode_decode_zero)
        data = egg_asn1x_encode (asn, NULL, &n_data);
        g_assert (data);
 
-       g_assert_cmpsize (n_data, ==, XL (BITS_ZERO));
+       egg_assert_cmpsize (n_data, ==, XL (BITS_ZERO));
        g_assert (memcmp (data, BITS_ZERO, n_data) == 0);
 
        g_free (data);
        egg_asn1x_destroy (asn);
 }
 
-TESTING_TEST(asn1_have)
+static void
+test_have (void)
 {
        GNode *asn;
        guchar *data;
@@ -391,7 +404,8 @@ test_is_freed (gpointer unused)
        is_freed = TRUE;
 }
 
-TESTING_TEST(asn1_any_set_raw)
+static void
+test_any_set_raw (void)
 {
        GNode *asn, *node;
        guchar *data;
@@ -414,13 +428,13 @@ TESTING_TEST(asn1_any_set_raw)
        data = egg_asn1x_encode (asn, NULL, &n_data);
        g_assert (data);
 
-       g_assert_cmpsize (n_data, ==, XL (SEQ_ENCODING));
+       egg_assert_cmpsize (n_data, ==, XL (SEQ_ENCODING));
        g_assert (memcmp (data, SEQ_ENCODING, n_data) == 0);
 
        check = egg_asn1x_get_raw_element (node, &n_check);
        g_assert (check);
 
-       g_assert_cmpsize (n_check, ==, XL (SFARNSWORTH));
+       egg_assert_cmpsize (n_check, ==, XL (SFARNSWORTH));
        g_assert (memcmp (check, SFARNSWORTH, n_check) == 0);
 
        g_free (data);
@@ -428,7 +442,8 @@ TESTING_TEST(asn1_any_set_raw)
        g_assert (is_freed);
 }
 
-TESTING_TEST(asn1_any_set_raw_explicit)
+static void
+test_any_set_raw_explicit (void)
 {
        GNode *asn, *node;
        guchar *data;
@@ -451,7 +466,7 @@ TESTING_TEST(asn1_any_set_raw_explicit)
        data = egg_asn1x_encode (asn, NULL, &n_data);
        g_assert (data);
 
-       g_assert_cmpsize (n_data, ==, XL (SEQ_ENCODING));
+       egg_assert_cmpsize (n_data, ==, XL (SEQ_ENCODING));
        g_assert (memcmp (data, SEQ_ENCODING, n_data) == 0);
 
        check = egg_asn1x_get_raw_element (node, &n_check);
@@ -465,7 +480,8 @@ TESTING_TEST(asn1_any_set_raw_explicit)
        g_assert (is_freed);
 }
 
-TESTING_TEST(asn1_choice_not_chosen)
+static void
+test_choice_not_chosen (void)
 {
        GNode *asn, *node;
        guchar *data;
@@ -517,7 +533,7 @@ perform_asn1_any_choice_set_raw (const gchar *choice, const gchar *encoding, gsi
        }
        g_assert (data);
 
-       g_assert_cmpsize (n_data, ==, n_encoding);
+       egg_assert_cmpsize (n_data, ==, n_encoding);
        g_assert (memcmp (data, encoding, n_data) == 0);
 
        check = egg_asn1x_get_raw_element (node, &n_check);
@@ -531,19 +547,22 @@ perform_asn1_any_choice_set_raw (const gchar *choice, const gchar *encoding, gsi
        g_assert (is_freed);
 }
 
-TESTING_TEST(asn1_any_choice_set_raw_short_tag)
+static void
+test_any_choice_set_raw_short_tag (void)
 {
        const gchar ENCODING[] = "\xBE\x0C\x04\x0A""farnsworth";
        perform_asn1_any_choice_set_raw ("choiceShortTag", ENCODING, XL (ENCODING));
 }
 
-TESTING_TEST(asn1_any_choice_set_raw_long_tag)
+static void
+test_any_choice_set_raw_long_tag (void)
 {
        const gchar ENCODING[] = "\xBF\x1F\x0C\x04\x0A""farnsworth";
        perform_asn1_any_choice_set_raw ("choiceLongTag", ENCODING, XL (ENCODING));
 }
 
-TESTING_TEST(asn1_append)
+static void
+test_append (void)
 {
        GNode *asn;
        GNode *child;
@@ -576,7 +595,8 @@ TESTING_TEST(asn1_append)
        egg_asn1x_destroy (asn);
 }
 
-TESTING_TEST(asn1_append_and_clear)
+static void
+test_append_and_clear (void)
 {
        GNode *asn;
        gpointer data;
@@ -606,7 +626,8 @@ TESTING_TEST(asn1_append_and_clear)
        g_free (data);
 }
 
-TESTING_TEST(asn1_setof)
+static void
+test_setof (void)
 {
        GNode *asn;
        gpointer data;
@@ -642,7 +663,8 @@ TESTING_TEST(asn1_setof)
        egg_asn1x_destroy (asn);
 }
 
-TESTING_TEST(asn1_setof_empty)
+static void
+test_setof_empty (void)
 {
        GNode *asn;
        gpointer data;
@@ -667,7 +689,8 @@ TESTING_TEST(asn1_setof_empty)
        egg_asn1x_destroy (asn);
 }
 
-TESTING_TEST (asn1_enumerated)
+static void
+test_enumerated (void)
 {
        GNode *asn;
        gpointer data;
@@ -693,3 +716,457 @@ TESTING_TEST (asn1_enumerated)
        g_free (data);
        egg_asn1x_destroy (asn);
 }
+
+typedef struct {
+       GNode *asn1;
+       guchar *data;
+       gsize n_data;
+} Test;
+
+static void
+setup (Test *test, gconstpointer unused)
+{
+       if (!g_file_get_contents ("files/test-certificate-1.der", (gchar**)&test->data,
+                                 &test->n_data, NULL))
+               g_assert_not_reached ();
+
+       test->asn1 = egg_asn1x_create (pkix_asn1_tab, "Certificate");
+       g_assert (test->asn1 != NULL);
+
+       if (!egg_asn1x_decode (test->asn1, test->data, test->n_data))
+               g_assert_not_reached ();
+}
+
+static void
+teardown (Test *test, gconstpointer unused)
+{
+       egg_asn1x_destroy (test->asn1);
+       g_free (test->data);
+}
+
+static void
+test_node_name (Test* test, gconstpointer unused)
+{
+       g_assert_cmpstr (egg_asn1x_name (test->asn1), ==, "Certificate");
+}
+
+static void
+test_asn1_integers (Test* test, gconstpointer unused)
+{
+       GNode *asn;
+       guchar *data;
+       gsize n_data;
+       gboolean ret;
+       gulong val;
+
+       asn = egg_asn1x_create (test_asn1_tab, "TestIntegers");
+       g_assert ("asn test structure is null" && asn != NULL);
+
+       ret = egg_asn1x_set_integer_as_ulong (egg_asn1x_node (asn, "uint1", NULL), 35);
+       g_assert ("couldn't write integer" && ret);
+
+       ret = egg_asn1x_set_integer_as_ulong (egg_asn1x_node (asn, "uint2", NULL), 23456);
+       g_assert ("couldn't write integer" && ret);
+
+       ret = egg_asn1x_set_integer_as_ulong (egg_asn1x_node (asn, "uint3", NULL), 209384022);
+       g_assert ("couldn't write integer" && ret);
+
+       /* Now encode the whole caboodle */
+       data = egg_asn1x_encode (asn, NULL, &n_data);
+       g_assert ("encoding asn1 didn't work" && data != NULL);
+
+       egg_asn1x_destroy (asn);
+
+       /* Now decode it all nicely */
+       asn = egg_asn1x_create_and_decode (test_asn1_tab, "TestIntegers", data, n_data);
+       g_return_if_fail (asn != NULL);
+
+       /* And get out the values */
+       ret = egg_asn1x_get_integer_as_ulong (egg_asn1x_node (asn, "uint1", NULL), &val);
+       g_assert ("couldn't read integer from asn1" && ret);
+       g_assert_cmpuint (val, ==, 35);
+
+       ret = egg_asn1x_get_integer_as_ulong (egg_asn1x_node (asn, "uint2", NULL), &val);
+       g_assert ("couldn't read integer from asn1" && ret);
+       g_assert_cmpuint (val, ==, 23456);
+
+       ret = egg_asn1x_get_integer_as_ulong (egg_asn1x_node (asn, "uint3", NULL), &val);
+       g_assert ("couldn't read integer from asn1" && ret);
+       g_assert_cmpuint (val, ==, 209384022);
+
+       g_free (data);
+}
+
+static void
+test_boolean_seq (Test* test, gconstpointer unused)
+{
+       GNode *asn = NULL;
+       gboolean value, ret;
+       gpointer data;
+       gsize n_data;
+
+       asn = egg_asn1x_create (test_asn1_tab, "TestBooleanSeq");
+       g_assert ("asn test structure is null" && asn != NULL);
+
+       /* Get the default value */
+       value = TRUE;
+       ret = egg_asn1x_get_boolean (egg_asn1x_node (asn, "boolean", NULL), &value);
+       g_assert (ret == TRUE);
+       g_assert (value == FALSE);
+
+       ret = egg_asn1x_set_boolean (egg_asn1x_node (asn, "boolean", NULL), TRUE);
+       g_assert (ret == TRUE);
+
+       data = egg_asn1x_encode (asn, NULL, &n_data);
+       g_assert (data);
+
+       ret = egg_asn1x_get_boolean (egg_asn1x_node (asn, "boolean", NULL), &value);
+       g_assert (ret);
+       g_assert (value == TRUE);
+
+       ret = egg_asn1x_set_boolean (egg_asn1x_node (asn, "boolean", NULL), FALSE);
+       g_assert (ret == TRUE);
+
+       g_free (data);
+       data = egg_asn1x_encode (asn, NULL, &n_data);
+       g_assert (data);
+
+       ret = egg_asn1x_get_boolean (egg_asn1x_node (asn, "boolean", NULL), &value);
+       g_assert (ret);
+       g_assert (value == FALSE);
+
+       g_free (data);
+       egg_asn1x_destroy (asn);
+}
+
+static void
+test_write_value (Test* test, gconstpointer unused)
+{
+       GNode *asn = NULL;
+       guchar *data;
+       gsize n_data;
+       guchar *encoded;
+       gsize n_encoded;
+
+       asn = egg_asn1x_create (test_asn1_tab, "TestData");
+       g_assert ("asn test structure is null" && asn != NULL);
+
+       if (!egg_asn1x_set_string_as_raw (egg_asn1x_node (asn, "data", NULL), (guchar*)"SOME DATA", 9, NULL))
+               g_assert_not_reached ();
+
+       encoded = egg_asn1x_encode (asn, NULL, &n_encoded);
+       g_assert (encoded);
+
+       data = egg_asn1x_get_string_as_raw (egg_asn1x_node (asn, "data", NULL), NULL, &n_data);
+       g_assert (data != NULL);
+       g_assert_cmpuint (n_data, ==, 9);
+       g_assert (memcmp (data, "SOME DATA", 9) == 0);
+       g_free (data);
+
+       g_free (encoded);
+       egg_asn1x_destroy (asn);
+}
+
+static void
+test_element_length_content (Test* test, gconstpointer unused)
+{
+       GNode *asn = NULL;
+       gchar *buffer;
+       const guchar *content;
+       gsize n_content;
+       gsize n_buffer;
+       gssize length;
+
+       asn = egg_asn1x_create (test_asn1_tab, "TestData");
+       g_assert ("asn test structure is null" && asn != NULL);
+
+       if (!egg_asn1x_set_string_as_raw (egg_asn1x_node (asn, "data", NULL), (guchar*)"SOME DATA", 9, NULL))
+               g_assert_not_reached ();
+
+       buffer = egg_asn1x_encode (asn, NULL, &n_buffer);
+       g_assert (buffer != NULL);
+
+       /* Now the real test */
+       length = egg_asn1x_element_length (buffer, n_buffer + 1024);
+       g_assert_cmpint (length, ==, 13);
+
+       content = egg_asn1x_element_content (buffer, length, &n_content);
+       g_assert (content);
+       g_assert_cmpuint (n_content, ==, 11);
+
+       content = egg_asn1x_element_content (content, n_content, &n_content);
+       g_assert (content);
+       g_assert_cmpuint (n_content, ==, 9);
+       g_assert (memcmp (content, "SOME DATA", 9) == 0);
+
+       const char *BAD_ASN_TAG = "\x00";
+       content = egg_asn1x_element_content (BAD_ASN_TAG, 1, &n_content);
+       g_assert (content == NULL);
+
+       const char *BAD_ASN_LENGTH = "\x30\x80";
+       content = egg_asn1x_element_content (BAD_ASN_LENGTH, 2, &n_content);
+       g_assert (content == NULL);
+
+       egg_asn1x_destroy (asn);
+       g_free (buffer);
+}
+
+static void
+test_read_element (Test* test, gconstpointer unused)
+{
+       GNode *asn = NULL;
+       guchar *buffer;
+       gconstpointer data;
+       gsize n_data;
+       gsize n_buffer;
+
+       asn = egg_asn1x_create (test_asn1_tab, "TestData");
+       g_assert ("asn test structure is null" && asn != NULL);
+
+       if (!egg_asn1x_set_string_as_raw (egg_asn1x_node (asn, "data", NULL), (guchar*)"SOME DATA", 9, NULL))
+               g_assert_not_reached ();
+
+       buffer = egg_asn1x_encode (asn, NULL, &n_buffer);
+       g_assert (buffer != NULL);
+
+       /* Now the real test */
+       data = egg_asn1x_get_raw_element (egg_asn1x_node (asn, "data", NULL), &n_data);
+       g_assert (data != NULL);
+       g_assert_cmpint (n_data, ==, 11);
+
+       data = egg_asn1x_get_raw_value (egg_asn1x_node (asn, "data", NULL), &n_data);
+       g_assert (data);
+       g_assert_cmpuint (n_data, ==, 9);
+       g_assert (memcmp (data, "SOME DATA", 9) == 0);
+
+       egg_asn1x_destroy (asn);
+       g_free (buffer);
+}
+
+static void
+test_oid (Test* test, gconstpointer unused)
+{
+       GNode *asn = NULL;
+       GQuark oid, check;
+       guchar *buffer;
+       gsize n_buffer;
+
+       asn = egg_asn1x_create (test_asn1_tab, "TestOid");
+       g_assert ("asn test structure is null" && asn != NULL);
+
+       if (!egg_asn1x_set_oid_as_string (egg_asn1x_node (asn, "oid", NULL), "1.2.34567.89"))
+               g_assert_not_reached ();
+
+       buffer = egg_asn1x_encode (asn, NULL, &n_buffer);
+       g_assert (buffer != NULL);
+
+       /* Now a quark has been defined */
+       check = g_quark_from_static_string ("1.2.34567.89");
+       oid = egg_asn1x_get_oid_as_quark (egg_asn1x_node (asn, "oid", NULL));
+       g_assert (oid);
+       g_assert (check == oid);
+       g_assert_cmpstr (g_quark_to_string (oid), ==, "1.2.34567.89");
+
+       /* Write a different OID */
+       if (!egg_asn1x_set_oid_as_quark (egg_asn1x_node (asn, "oid", NULL), g_quark_from_static_string ("5.4.3.2.1678")))
+               g_assert_not_reached ();
+
+       g_free (buffer);
+       buffer = egg_asn1x_encode (asn, NULL, &n_buffer);
+       g_assert (buffer != NULL);
+
+       oid = egg_asn1x_get_oid_as_quark (egg_asn1x_node (asn, "oid", NULL));
+       g_assert (oid);
+       g_assert_cmpstr (g_quark_to_string (oid), ==, "5.4.3.2.1678");
+
+       g_free (buffer);
+       egg_asn1x_destroy (asn);
+}
+
+typedef struct _TimeTestData {
+       gchar *value;
+       time_t ref;
+} TimeTestData;
+
+static const TimeTestData generalized_time_test_data[] = {
+       { "20070725130528Z", 1185368728 },
+       { "20070725130528.2134Z", 1185368728 },
+       { "20070725140528-0100", 1185368728 },
+       { "20070725040528+0900", 1185368728 },
+       { "20070725013528+1130", 1185368728 },
+       { "20070725Z", 1185321600 },
+       { "20070725+0000", 1185321600 },
+
+       /* Bad ones */
+       { "200707", -1 },
+
+       { NULL, 0 }
+};
+
+static const TimeTestData utc_time_test_data[] = {
+       /* Test the Y2K style wrap arounds */
+       { "070725130528Z", 1185368728 },  /* The year 2007 */
+       { "020725130528Z", 1027602328 },  /* The year 2002 */
+       { "970725130528Z", 869835928 },   /* The year 1997 */
+       { "370725130528Z", 2132139928 },  /* The year 2037 */
+
+       /* Test the time zones and other formats */
+       { "070725130528.2134Z", 1185368728 },
+       { "070725140528-0100", 1185368728 },
+       { "070725040528+0900", 1185368728 },
+       { "070725013528+1130", 1185368728 },
+       { "070725Z", 1185321600 },
+       { "070725+0000", 1185321600 },
+
+       /* Bad ones */
+       { "0707", -1 },
+
+       { NULL, 0 }
+};
+
+static void
+test_general_time (Test* test, gconstpointer unused)
+{
+       time_t when;
+       const TimeTestData *data;
+
+       for (data = generalized_time_test_data; data->value; ++data) {
+               when = egg_asn1x_parse_time_general (data->value, -1);
+               if (data->ref != when) {
+                       printf ("%s", data->value);
+                       printf ("%s != ", ctime (&when));
+                       printf ("%s\n", ctime (&data->ref));
+                       fflush (stdout);
+               }
+
+               g_assert ("decoded time doesn't match reference" && data->ref == when);
+       }
+}
+
+static void
+test_utc_time (Test* test, gconstpointer unused)
+{
+       time_t when;
+       const TimeTestData *data;
+
+       for (data = utc_time_test_data; data->value; ++data) {
+               when = egg_asn1x_parse_time_utc (data->value, -1);
+               if (data->ref != when) {
+                       printf ("%s", data->value);
+                       printf ("%s != ", ctime (&when));
+                       printf ("%s\n", ctime (&data->ref));
+                       fflush (stdout);
+               }
+
+               g_assert ("decoded time doesn't match reference" && data->ref == when);
+       }
+}
+
+static void
+test_read_time (Test* test, gconstpointer unused)
+{
+       glong time;
+
+       time = egg_asn1x_get_time_as_long (egg_asn1x_node (test->asn1, "tbsCertificate", "validity", "notBefore", NULL));
+       g_assert_cmpint (time, ==, 820454400);
+}
+
+static void
+test_read_date (Test* test, gconstpointer unused)
+{
+       GDate date;
+       if (!egg_asn1x_get_time_as_date (egg_asn1x_node (test->asn1, "tbsCertificate", "validity", "notAfter", NULL), &date))
+               g_assert_not_reached ();
+       g_assert_cmpint (date.day, ==, 31);
+       g_assert_cmpint (date.month, ==, 12);
+       g_assert_cmpint (date.year, ==, 2020);
+}
+
+static void
+test_create_by_oid (Test* test, gconstpointer unused)
+{
+       /* id-at-initials = X520initials */
+       GNode *node = egg_asn1x_create (pkix_asn1_tab, "2.5.4.43");
+       g_assert (node != NULL);
+       g_assert_cmpstr (egg_asn1x_name (node), ==, "X520initials");
+       egg_asn1x_destroy (node);
+}
+
+static void
+test_create_by_oid_invalid (Test* test, gconstpointer unused)
+{
+       GNode *node = egg_asn1x_create (pkix_asn1_tab, "23.23.23.23");
+       g_assert (node == NULL);
+}
+
+static void
+test_create_by_bad_order (Test* test, gconstpointer unused)
+{
+       /*
+        * In pkix.asn the definition for parts of this oid
+        * come in the wrong order. However this should still work.
+        */
+
+       /* id-pe-authorityInfoAccess = AuthorityInfoAccessSyntax */
+       GNode *node = egg_asn1x_create (pkix_asn1_tab, "1.3.6.1.5.5.7.1.1");
+       g_assert (node != NULL);
+       g_assert_cmpstr (egg_asn1x_name (node), ==, "AuthorityInfoAccessSyntax");
+       egg_asn1x_destroy (node);
+}
+
+static void
+test_count (Test* test, gconstpointer unused)
+{
+       GNode *node;
+
+       node = egg_asn1x_node (test->asn1, "tbsCertificate", "issuer", "rdnSequence", NULL);
+       g_assert (node);
+       g_assert_cmpuint (egg_asn1x_count (node), ==, 7);
+}
+
+int
+main (int argc, char **argv)
+{
+       g_test_init (&argc, &argv, NULL);
+
+       g_test_add_func ("/asn1/boolean", test_boolean);
+       g_test_add_func ("/asn1/integer", test_integer);
+       g_test_add_func ("/asn1/octet_string", test_octet_string);
+       g_test_add_func ("/asn1/generalized_time", test_generalized_time);
+       g_test_add_func ("/asn1/implicit", test_implicit);
+       g_test_add_func ("/asn1/explicit", test_explicit);
+       g_test_add_func ("/asn1/bit_string_decode", test_bit_string_decode);
+       g_test_add_func ("/asn1/bit_string_decode_bad", test_bit_string_decode_bad);
+       g_test_add_func ("/asn1/bit_string_decode_ulong", test_bit_string_decode_ulong);
+       g_test_add_func ("/asn1/bit_string_encode_decode", test_bit_string_encode_decode);
+       g_test_add_func ("/asn1/bit_string_encode_decode_ulong", test_bit_string_encode_decode_ulong);
+       g_test_add_func ("/asn1/bit_string_encode_decode_zero", test_bit_string_encode_decode_zero);
+       g_test_add_func ("/asn1/have", test_have);
+       g_test_add_func ("/asn1/any_set_raw", test_any_set_raw);
+       g_test_add_func ("/asn1/any_set_raw_explicit", test_any_set_raw_explicit);
+       g_test_add_func ("/asn1/choice_not_chosen", test_choice_not_chosen);
+       g_test_add_func ("/asn1/any_choice_set_raw_short_tag", test_any_choice_set_raw_short_tag);
+       g_test_add_func ("/asn1/any_choice_set_raw_long_tag", test_any_choice_set_raw_long_tag);
+       g_test_add_func ("/asn1/append", test_append);
+       g_test_add_func ("/asn1/append_and_clear", test_append_and_clear);
+       g_test_add_func ("/asn1/setof", test_setof);
+       g_test_add_func ("/asn1/setof_empty", test_setof_empty);
+       g_test_add_func ("/asn1/enumerated", test_enumerated);
+       g_test_add ("/asn1/node_name", Test, NULL, setup, test_node_name, teardown);
+       g_test_add ("/asn1/asn1_integers", Test, NULL, setup, test_asn1_integers, teardown);
+       g_test_add ("/asn1/boolean_seq", Test, NULL, setup, test_boolean_seq, teardown);
+       g_test_add ("/asn1/write_value", Test, NULL, setup, test_write_value, teardown);
+       g_test_add ("/asn1/element_length_content", Test, NULL, setup, test_element_length_content, teardown);
+       g_test_add ("/asn1/read_element", Test, NULL, setup, test_read_element, teardown);
+       g_test_add ("/asn1/oid", Test, NULL, setup, test_oid, teardown);
+       g_test_add ("/asn1/general_time", Test, NULL, setup, test_general_time, teardown);
+       g_test_add ("/asn1/utc_time", Test, NULL, setup, test_utc_time, teardown);
+       g_test_add ("/asn1/read_time", Test, NULL, setup, test_read_time, teardown);
+       g_test_add ("/asn1/read_date", Test, NULL, setup, test_read_date, teardown);
+       g_test_add ("/asn1/create_by_oid", Test, NULL, setup, test_create_by_oid, teardown);
+       g_test_add ("/asn1/create_by_oid_invalid", Test, NULL, setup, test_create_by_oid_invalid, teardown);
+       g_test_add ("/asn1/create_by_bad_order", Test, NULL, setup, test_create_by_bad_order, teardown);
+       g_test_add ("/asn1/count", Test, NULL, setup, test_count, teardown);
+
+       return g_test_run ();
+}
index b397754..553ad6f 100644 (file)
@@ -1,12 +1,34 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* test-asn1.c: Test ASN1 stuf
 
-#include "egg/egg-asn1x.h"
-#include "testing/testing.h"
+   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 "egg-asn1x.h"
 
 #include <pwd.h>
 #include <stdlib.h>
 #include <unistd.h>
 
-#include "egg/egg-asn1-defs.h"
+#include "egg-asn1-defs.h"
+#include "egg-testing.h"
 
 #if 0
 static void
@@ -47,7 +69,8 @@ test_some_asn1_stuff (const ASN1_ARRAY_TYPE *defs, const gchar *file, const gcha
        gpointer data, encoded;
        gsize n_data, n_encoded;
 
-       data = testing_data_read (file, &n_data);
+       if (!g_file_get_contents (file, (gchar**)&data, &n_data, NULL))
+               g_assert_not_reached ();
        asn = egg_asn1x_create (defs, identifier);
        egg_asn1x_dump (asn);
 
@@ -68,25 +91,23 @@ test_some_asn1_stuff (const ASN1_ARRAY_TYPE *defs, const gchar *file, const gcha
        g_free (data);
 }
 
-static int
-run (void)
+int
+main (int argc, char **argv)
 {
-
        /* Build up a personal name, which is a set */
 #if 0
        build_personal_name ();
 #endif
 
+       egg_tests_chdir_base (argv[0]);
 
-       test_some_asn1_stuff (pkix_asn1_tab, "test-certificate-1.der", "Certificate");
-       test_some_asn1_stuff (pkix_asn1_tab, "test-pkcs8-1.der", "pkcs-8-PrivateKeyInfo");
-       test_some_asn1_stuff (pk_asn1_tab, "test-rsakey-1.der", "RSAPrivateKey");
-       test_some_asn1_stuff (pkix_asn1_tab, "test-personalname-1.der", "PersonalName");
-       test_some_asn1_stuff (pkix_asn1_tab, "test-pkcs7-1.der", "pkcs-7-ContentInfo");
-       test_some_asn1_stuff (pkix_asn1_tab, "test-pkcs7-2.der", "pkcs-7-ContentInfo");
-       test_some_asn1_stuff (pkix_asn1_tab, "test-pkcs12-1.der", "pkcs-12-PFX");
+       test_some_asn1_stuff (pkix_asn1_tab, "files/test-certificate-1.der", "Certificate");
+       test_some_asn1_stuff (pkix_asn1_tab, "files/test-pkcs8-1.der", "pkcs-8-PrivateKeyInfo");
+       test_some_asn1_stuff (pk_asn1_tab, "files/test-rsakey-1.der", "RSAPrivateKey");
+       test_some_asn1_stuff (pkix_asn1_tab, "files/test-personalname-1.der", "PersonalName");
+       test_some_asn1_stuff (pkix_asn1_tab, "files/test-pkcs7-1.der", "pkcs-7-ContentInfo");
+       test_some_asn1_stuff (pkix_asn1_tab, "files/test-pkcs7-2.der", "pkcs-7-ContentInfo");
+       test_some_asn1_stuff (pkix_asn1_tab, "files/test-pkcs12-1.der", "pkcs-12-PFX");
 
        return 0;
 }
-
-#include "testing/testing.c"
similarity index 76%
rename from egg/tests/unit-test-dh.c
rename to egg/tests/test-dh.c
index 583ffb5..6a2b37f 100644 (file)
    Author: Stef Walter <stef@memberwebs.com>
 */
 
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "test-suite.h"
+#include "config.h"
 
 #include "egg-dh.h"
 #include "egg-secure-memory.h"
+#include "egg-testing.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
 
 #include <gcrypt.h>
 
-TESTING_TEST(dh_perform)
+EGG_SECURE_GLIB_DEFINITIONS ();
+
+static void
+test_perform (void)
 {
        gcry_mpi_t p, g;
        gcry_mpi_t x1, X1;
@@ -69,7 +73,8 @@ TESTING_TEST(dh_perform)
        egg_secure_free (k2);
 }
 
-TESTING_TEST(dh_short_pair)
+static void
+test_short_pair (void)
 {
        gcry_mpi_t p, g;
        gcry_mpi_t x1, X1;
@@ -108,9 +113,9 @@ test_dh_default (const gchar *name, guint bits)
        ret = egg_dh_default_params_raw (name, &prime, &n_prime, &base, &n_base);
        g_assert (ret);
        g_assert (prime != NULL);
-       g_assert_cmpsize (n_prime, >, 0);
+       egg_assert_cmpsize (n_prime, >, 0);
        g_assert (base != NULL);
-       g_assert_cmpsize (n_base, >, 0);
+       egg_assert_cmpsize (n_base, >, 0);
 
        gcry = gcry_mpi_scan (&check, GCRYMPI_FMT_USG, prime, n_prime, NULL);
        g_assert (gcry == 0);
@@ -126,43 +131,51 @@ test_dh_default (const gchar *name, guint bits)
        gcry_mpi_release (g);
 }
 
-TESTING_TEST(dh_default_768)
+static void
+test_default_768 (void)
 {
        test_dh_default ("ietf-ike-grp-modp-768", 768);
 }
 
-TESTING_TEST(dh_default_1024)
+static void
+test_default_1024 (void)
 {
        test_dh_default ("ietf-ike-grp-modp-1024", 1024);
 }
 
-TESTING_TEST(dh_default_1536)
+static void
+test_default_1536 (void)
 {
        test_dh_default ("ietf-ike-grp-modp-1536", 1536);
 }
 
 
-TESTING_TEST(dh_default_2048)
+static void
+test_default_2048 (void)
 {
        test_dh_default ("ietf-ike-grp-modp-2048", 2048);
 }
 
-TESTING_TEST(dh_default_3072)
+static void
+test_default_3072 (void)
 {
        test_dh_default ("ietf-ike-grp-modp-3072", 3072);
 }
 
-TESTING_TEST(dh_default_4096)
+static void
+test_default_4096 (void)
 {
        test_dh_default ("ietf-ike-grp-modp-4096", 4096);
 }
 
-TESTING_TEST(dh_default_8192)
+static void
+test_default_8192 (void)
 {
        test_dh_default ("ietf-ike-grp-modp-8192", 8192);
 }
 
-TESTING_TEST(dh_default_bad)
+static void
+test_default_bad (void)
 {
        gboolean ret;
        gcry_mpi_t p, g;
@@ -170,3 +183,22 @@ TESTING_TEST(dh_default_bad)
        ret = egg_dh_default_params ("bad-name", &p, &g);
        g_assert (!ret);
 }
+
+int
+main (int argc, char **argv)
+{
+       g_test_init (&argc, &argv, NULL);
+
+       g_test_add_func ("/dh/perform", test_perform);
+       g_test_add_func ("/dh/short_pair", test_short_pair);
+       g_test_add_func ("/dh/default_768", test_default_768);
+       g_test_add_func ("/dh/default_1024", test_default_1024);
+       g_test_add_func ("/dh/default_1536", test_default_1536);
+       g_test_add_func ("/dh/default_2048", test_default_2048);
+       g_test_add_func ("/dh/default_3072", test_default_3072);
+       g_test_add_func ("/dh/default_4096", test_default_4096);
+       g_test_add_func ("/dh/default_8192", test_default_8192);
+       g_test_add_func ("/dh/default_bad", test_default_bad);
+
+       return g_test_run ();
+}
index 0ac7a95..eae139f 100644 (file)
 
 #include "config.h"
 
-#include "test-suite.h"
-
-#include "egg/egg-asn1-defs.h"
-#include "egg/egg-asn1x.h"
-#include "egg/egg-dn.h"
-#include "egg/egg-oid.h"
+#include "egg-asn1-defs.h"
+#include "egg-asn1x.h"
+#include "egg-dn.h"
+#include "egg-oid.h"
 
 #include <glib.h>
 #include <gcrypt.h>
 #include <stdio.h>
 #include <string.h>
 
-static GNode* asn1_cert = NULL;
-static guchar *data_cert = NULL;
-static gsize n_data_cert = 0;
+typedef struct {
+       GNode* asn1;
+       guchar *data;
+       gsize n_data;
+} Test;
 
-TESTING_SETUP(dn_cert)
+static void
+setup (Test *test, gconstpointer unused)
 {
-       data_cert = testing_data_read ("test-certificate-1.der", &n_data_cert);
+       if (!g_file_get_contents ("files/test-certificate-1.der", (gchar**)&test->data,
+                                 &test->n_data, NULL))
+               g_assert_not_reached ();
 
-       asn1_cert = egg_asn1x_create (pkix_asn1_tab, "Certificate");
-       g_assert (asn1_cert != NULL);
+       test->asn1 = egg_asn1x_create (pkix_asn1_tab, "Certificate");
+       g_assert (test->asn1 != NULL);
 
-       if (!egg_asn1x_decode (asn1_cert, data_cert, n_data_cert))
+       if (!egg_asn1x_decode (test->asn1, test->data, test->n_data))
                g_assert_not_reached ();
 }
 
-TESTING_TEARDOWN(dn_cert)
+static void
+teardown (Test *test, gconstpointer unused)
 {
-       egg_asn1x_destroy (asn1_cert);
-       g_free (data_cert);
-       data_cert = NULL;
+       egg_asn1x_destroy (test->asn1);
+       g_free (test->data);
 }
 
-TESTING_TEST(read_dn)
+static void
+test_read_dn (Test* test, gconstpointer unused)
 {
        gchar *dn;
 
-       dn = egg_dn_read (egg_asn1x_node (asn1_cert, "tbsCertificate", "issuer", "rdnSequence", NULL));
+       dn = egg_dn_read (egg_asn1x_node (test->asn1, "tbsCertificate", "issuer", "rdnSequence", NULL));
        g_assert (dn != NULL);
        g_assert_cmpstr (dn, ==, "C=ZA, ST=Western Cape, L=Cape Town, O=Thawte Consulting, OU=Certification Services Division, CN=Thawte Personal Premium CA, EMAIL=personal-premium@thawte.com");
 
        g_free (dn);
 }
 
-TESTING_TEST(dn_value)
+static void
+test_dn_value (Test* test, gconstpointer unused)
 {
        const guchar value[] = { 0x13, 0x1a, 0x54, 0x68, 0x61, 0x77, 0x74, 0x65, 0x20, 0x50, 0x65, 0x72, 0x73, 0x6f, 0x6e, 0x61, 0x6c, 0x20, 0x50, 0x72, 0x65, 0x6d, 0x69, 0x75, 0x6d, 0x20, 0x43, 0x41 };
        gsize n_value = 28;
@@ -118,24 +123,26 @@ concatenate_dn (guint index, GQuark oid, const guchar *value, gsize n_value, gpo
        g_free (text);
 }
 
-TESTING_TEST(parse_dn)
+static void
+test_parse_dn (Test* test, gconstpointer unused)
 {
        GString *dn = g_string_new ("");
        last_index = 1;
 
-       if (!egg_dn_parse (egg_asn1x_node (asn1_cert, "tbsCertificate", "issuer", "rdnSequence", NULL), concatenate_dn, dn))
+       if (!egg_dn_parse (egg_asn1x_node (test->asn1, "tbsCertificate", "issuer", "rdnSequence", NULL), concatenate_dn, dn))
                g_assert_not_reached ();
 
        g_assert_cmpstr (dn->str, ==, "C=ZA, ST=Western Cape, L=Cape Town, O=Thawte Consulting, OU=Certification Services Division, CN=Thawte Personal Premium CA, EMAIL=personal-premium@thawte.com");
        g_string_free (dn, TRUE);
 }
 
-TESTING_TEST(read_dn_part)
+static void
+test_read_dn_part (Test* test, gconstpointer unused)
 {
        GNode *node;
        gchar *value;
 
-       node = egg_asn1x_node (asn1_cert, "tbsCertificate", "issuer", "rdnSequence", NULL);
+       node = egg_asn1x_node (test->asn1, "tbsCertificate", "issuer", "rdnSequence", NULL);
 
        value = egg_dn_read_part (node, "CN");
        g_assert (value != NULL);
@@ -156,3 +163,16 @@ TESTING_TEST(read_dn_part)
        value = egg_dn_read_part (node, "2.5.4.9");
        g_assert (value == NULL);
 }
+
+int
+main (int argc, char **argv)
+{
+       g_test_init (&argc, &argv, NULL);
+
+       g_test_add ("/dn/read_dn", Test, NULL, setup, test_read_dn, teardown);
+       g_test_add ("/dn/dn_value", Test, NULL, setup, test_dn_value, teardown);
+       g_test_add ("/dn/parse_dn", Test, NULL, setup, test_parse_dn, teardown);
+       g_test_add ("/dn/read_dn_part", Test, NULL, setup, test_read_dn_part, teardown);
+
+       return g_test_run ();
+}
similarity index 84%
rename from egg/tests/unit-test-hex.c
rename to egg/tests/test-hex.c
index 30e20cd..713bf60 100644 (file)
    Author: Stef Walter <stef@memberwebs.com>
 */
 
+#include "config.h"
+
+#include "egg-hex.h"
+
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 
-#include "test-suite.h"
-
-#include "egg-hex.h"
-
 static const guchar TEST_DATA[] = { 0x05, 0xD6, 0x95, 0x96, 0x10, 0x12, 0xAE, 0x35 };
 static const gchar *TEST_HEX = "05D695961012AE35";
 static const gchar *TEST_HEX_DELIM = "05 D6 95 96 10 12 AE 35";
 
-TESTING_TEST(hex_encode)
+static void
+test_encode (void)
 {
        gchar *hex;
 
@@ -42,7 +43,8 @@ TESTING_TEST(hex_encode)
        g_assert_cmpstr (hex, ==, TEST_HEX);
 }
 
-TESTING_TEST(hex_encode_spaces)
+static void
+test_encode_spaces (void)
 {
        gchar *hex;
 
@@ -57,7 +59,8 @@ TESTING_TEST(hex_encode_spaces)
        g_assert_cmpstr (hex, ==, TEST_HEX_DELIM);
 }
 
-TESTING_TEST(hex_decode)
+static void
+test_decode (void)
 {
        guchar *data;
        gsize n_data;
@@ -82,7 +85,8 @@ TESTING_TEST(hex_decode)
        g_free (data);
 }
 
-TESTING_TEST(hex_decode_fail)
+static void
+test_decode_fail (void)
 {
        guchar *data;
        gsize n_data;
@@ -99,3 +103,16 @@ TESTING_TEST(hex_decode_fail)
        data = egg_hex_decode_full ("ABABAB", -1, ':', 1, &n_data);
        g_assert (!data);
 }
+
+int
+main (int argc, char **argv)
+{
+       g_test_init (&argc, &argv, NULL);
+
+       g_test_add_func ("/hex/encode", test_encode);
+       g_test_add_func ("/hex/encode_spaces", test_encode_spaces);
+       g_test_add_func ("/hex/decode", test_decode);
+       g_test_add_func ("/hex/decode_fail", test_decode_fail);
+
+       return g_test_run ();
+}
similarity index 89%
rename from egg/tests/unit-test-oid.c
rename to egg/tests/test-oid.c
index eb256eb..189a200 100644 (file)
@@ -1,6 +1,5 @@
 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
 /* unit-test-oid.c: Test OID routines
-
    Copyright (C) 2008 Stefan Walter
 
    The Gnome Keyring Library is free software; you can redistribute it and/or
 
 #include "config.h"
 
-#include "test-suite.h"
-
-#include "egg/egg-oid.h"
+#include "egg-oid.h"
 
 #include <glib.h>
 
-TESTING_TEST(oid_tests)
+static void
+test_tests (void)
 {
        GQuark oid;
 
@@ -44,3 +42,13 @@ TESTING_TEST(oid_tests)
        g_assert_cmpstr (egg_oid_get_description (oid), ==, "1.1.1.1.1");
        g_assert_cmpuint (egg_oid_get_flags (oid), ==, 0);
 }
+
+int
+main (int argc, char **argv)
+{
+       g_test_init (&argc, &argv, NULL);
+
+       g_test_add_func ("/oid/tests", test_tests);
+
+       return g_test_run ();
+}
similarity index 60%
rename from egg/tests/unit-test-openssl.c
rename to egg/tests/test-openssl.c
index 8882be2..bf8134a 100644 (file)
 
 #include "config.h"
 
-#include "test-suite.h"
-
 #include "egg-symkey.h"
 #include "egg-openssl.h"
+#include "egg-secure-memory.h"
+#include "egg-testing.h"
 
 #include <glib.h>
 
 #include <stdio.h>
 #include <string.h>
 
-guchar *refenc = NULL;
-guchar *refdata = NULL;
-gsize n_refenc = 0;
-gsize n_refdata = 0;
-GHashTable *refheaders = NULL;
+EGG_SECURE_GLIB_DEFINITIONS ();
+
+typedef struct {
+       guchar *input;
+       gsize n_input;
+       guchar *refenc;
+       guchar *refdata;
+       gsize n_refenc;
+       gsize n_refdata;
+       GHashTable *refheaders;
+} Test;
+
+static void
+setup (Test *test, gconstpointer unused)
+{
+       if (!g_file_get_contents ("files/pem-rsa-enc.key", (gchar**)&test->input, &test->n_input, NULL))
+               g_assert_not_reached ();
+}
+
+static void
+teardown (Test *test, gconstpointer unused)
+{
+       g_free (test->input);
+       g_free (test->refenc);
+       egg_secure_free (test->refdata);
+       g_hash_table_destroy (test->refheaders);
+}
 
 static void
 copy_each_key_value (gpointer key, gpointer value, gpointer user_data)
@@ -50,64 +72,69 @@ static void
 parse_reference (GQuark type, const guchar *data, gsize n_data,
                  GHashTable *headers, gpointer user_data)
 {
+       Test *test = user_data;
        gboolean res;
        const gchar *dekinfo;
 
        g_assert ("no data in PEM callback" && data != NULL);
        g_assert ("no data in PEM callback" && n_data > 0);
-       refenc = g_memdup (data, n_data);
-       n_refenc = n_data;
+       test->refenc = g_memdup (data, n_data);
+       test->n_refenc = n_data;
 
        g_assert ("no headers present in file" && headers != NULL);
-       refheaders = egg_openssl_headers_new ();
-       g_hash_table_foreach (headers, copy_each_key_value, refheaders);
+       g_assert (!test->refheaders);
+       test->refheaders = egg_openssl_headers_new ();
+       g_hash_table_foreach (headers, copy_each_key_value, test->refheaders);
        dekinfo = egg_openssl_get_dekinfo (headers);
        g_assert ("no dekinfo in headers" && dekinfo != NULL);
 
-       res = egg_openssl_decrypt_block (dekinfo, "booo", 4, data, n_data, &refdata, &n_refdata);
+       res = egg_openssl_decrypt_block (dekinfo, "booo", 4, data, n_data, &test->refdata, &test->n_refdata);
        g_assert ("couldn't openssl decrypt block" && res == TRUE);
-       g_assert ("no data returned from openssl decrypt" && refdata != NULL);
-       g_assert ("invalid amount of data returned from openssl decrypt" && n_refdata == n_data);
+       g_assert ("no data returned from openssl decrypt" && test->refdata != NULL);
+       g_assert ("invalid amount of data returned from openssl decrypt" && test->n_refdata == n_data);
 }
 
-TESTING_TEST(parse_reference)
+static void
+test_parse_reference (Test *test, gconstpointer unused)
 {
-       guchar *input;
-       gsize n_input;
        guint num;
 
-       input = testing_data_read ("pem-rsa-enc.key", &n_input);
-
-       num = egg_openssl_pem_parse (input, n_input, parse_reference, NULL);
+       num = egg_openssl_pem_parse (test->input, test->n_input, parse_reference, test);
        g_assert ("couldn't PEM block in reference data" && num == 1);
 
-       g_assert ("parse_reference() wasn't called" && refdata != NULL);
+       g_assert ("parse_reference() wasn't called" && test->refdata != NULL);
 }
 
-TESTING_TEST(write_reference)
+static void
+test_write_reference (Test *test, gconstpointer unused)
 {
        const gchar *dekinfo;
        guchar *encrypted;
        gsize n_encrypted;
        gboolean ret;
+       guint num;
 
-       dekinfo = egg_openssl_get_dekinfo (refheaders);
+       num = egg_openssl_pem_parse (test->input, test->n_input, parse_reference, test);
+       g_assert ("couldn't PEM block in reference data" && num == 1);
+
+       dekinfo = egg_openssl_get_dekinfo (test->refheaders);
        g_assert ("no dekinfo in headers" && dekinfo != NULL);
 
-       ret = egg_openssl_encrypt_block (dekinfo, "booo", 4, refdata, n_refdata, &encrypted, &n_encrypted);
+       ret = egg_openssl_encrypt_block (dekinfo, "booo", 4, test->refdata, test->n_refdata, &encrypted, &n_encrypted);
        g_assert ("couldn't openssl encrypt block" && ret == TRUE);
        g_assert ("no data returned from openssl encrypt" && encrypted != NULL);
-       g_assert ("invalid amount of data returned from openssl encrypt" && n_refdata <= n_encrypted);
+       g_assert ("invalid amount of data returned from openssl encrypt" && test->n_refdata <= n_encrypted);
 
-       g_assert ("data length doesn't match input length" && n_encrypted == n_refenc);
-       g_assert ("data doesn't match input" && memcmp (encrypted, refenc, n_encrypted) == 0);
+       g_assert ("data length doesn't match input length" && n_encrypted == test->n_refenc);
+       g_assert ("data doesn't match input" && memcmp (encrypted, test->refenc, n_encrypted) == 0);
 }
 
 /* 29 bytes (prime number, so block length has bad chance of matching */
 static const guchar *TEST_DATA = (guchar*)"ABCDEFGHIJKLMNOPQRSTUVWXYZ123";
 const gsize TEST_DATA_L = 29;
 
-TESTING_TEST(openssl_roundtrip)
+static void
+test_openssl_roundtrip (Test *test, gconstpointer unused)
 {
        const gchar *dekinfo;
        gboolean res;
@@ -115,8 +142,12 @@ TESTING_TEST(openssl_roundtrip)
        guchar *encrypted, *decrypted;
        gsize n_encrypted, n_decrypted;
        int i;
+       guint num;
 
-       dekinfo = egg_openssl_prep_dekinfo (refheaders);
+       num = egg_openssl_pem_parse (test->input, test->n_input, parse_reference, test);
+       g_assert ("couldn't PEM block in reference data" && num == 1);
+
+       dekinfo = egg_openssl_prep_dekinfo (test->refheaders);
 
        ret = egg_openssl_encrypt_block (dekinfo, "password", -1, TEST_DATA, TEST_DATA_L, &encrypted, &n_encrypted);
        g_assert ("couldn't openssl encrypt block" && ret == TRUE);
@@ -135,3 +166,16 @@ TESTING_TEST(openssl_roundtrip)
        for (i = TEST_DATA_L; i < n_decrypted; ++i)
                g_assert ("non null byte in padding" && decrypted[i] == 0);
 }
+
+int
+main (int argc, char **argv)
+{
+       g_test_init (&argc, &argv, NULL);
+       egg_tests_chdir_base (argv[0]);
+
+       g_test_add ("/openssl/parse_reference", Test, NULL, setup, test_parse_reference, teardown);
+       g_test_add ("/openssl/write_reference", Test, NULL, setup, test_write_reference, teardown);
+       g_test_add ("/openssl/openssl_roundtrip", Test, NULL, setup, test_openssl_roundtrip, teardown);
+
+       return g_test_run ();
+}
index 3a11f46..236d941 100644 (file)
    Author: Stef Walter <stef@memberwebs.com>
 */
 
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
+#include "config.h"
 
-#include "test-suite.h"
-
-#include "egg/egg-padding.h"
+#include "egg-padding.h"
+#include "egg-testing.h"
 
 #include <gcrypt.h>
 
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
 static void
-test_padding (EggPadding padding, gsize block, gconstpointer input,
-              gsize n_input, gconstpointer output, gsize n_output)
+check_padding (EggPadding padding, gsize block, gconstpointer input,
+               gsize n_input, gconstpointer output, gsize n_output)
 {
        gpointer result;
        gsize n_result;
@@ -44,7 +45,7 @@ test_padding (EggPadding padding, gsize block, gconstpointer input,
        }
 
        g_assert (result != NULL);
-       g_assert_cmpsize (n_output, ==, n_result);
+       egg_assert_cmpsize (n_output, ==, n_result);
        g_assert (memcmp (output, result, n_output) == 0);
        g_free (result);
 
@@ -52,40 +53,45 @@ test_padding (EggPadding padding, gsize block, gconstpointer input,
        if (!(padding) (NULL, block, input, n_input, NULL, &n_result))
                g_assert_not_reached ();
 
-       g_assert_cmpsize (n_output, ==, n_result);
+       egg_assert_cmpsize (n_output, ==, n_result);
 }
 
-TESTING_TEST(zero_padding)
+static void
+test_zero_padding (void)
 {
        guchar padded[] = { 0x00, 0x00, 0x00, 0x00, 'T', 'E', 'S', 'T' };
        gchar raw[] = "TEST";
-       test_padding (egg_padding_zero_pad, 8, raw, 4, padded, 8);
+       check_padding (egg_padding_zero_pad, 8, raw, 4, padded, 8);
 }
 
-TESTING_TEST(zero_padding_no_data)
+static void
+test_zero_padding_no_data (void)
 {
        guchar padded[] = { };
        gchar raw[] = "";
-       test_padding (egg_padding_zero_pad, 8, raw, 0, padded, 0);
+       check_padding (egg_padding_zero_pad, 8, raw, 0, padded, 0);
 }
 
-TESTING_TEST(pkcs1_one_padding)
+static void
+test_pkcs1_one_padding (void)
 {
        guchar padded[] = { 0x00, 0x01, 0xFF, 0x00, 'T', 'E', 'S', 'T' };
        gchar raw[] = "TEST";
-       test_padding (egg_padding_pkcs1_pad_01, 8, raw, 4, padded, 8);
-       test_padding (egg_padding_pkcs1_unpad_01, 8, padded, 8, raw, 4);
+       check_padding (egg_padding_pkcs1_pad_01, 8, raw, 4, padded, 8);
+       check_padding (egg_padding_pkcs1_unpad_01, 8, padded, 8, raw, 4);
 }
 
-TESTING_TEST(pkcs1_one_padding_no_data)
+static void
+test_pkcs1_one_padding_no_data (void)
 {
        guchar padded[] = { 0x00, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00 };
        gchar raw[] = "";
-       test_padding (egg_padding_pkcs1_pad_01, 8, raw, 0, padded, 8);
-       test_padding (egg_padding_pkcs1_unpad_01, 8, padded, 8, raw, 0);
+       check_padding (egg_padding_pkcs1_pad_01, 8, raw, 0, padded, 8);
+       check_padding (egg_padding_pkcs1_unpad_01, 8, padded, 8, raw, 0);
 }
 
-TESTING_TEST(pkcs1_two_padding)
+static void
+test_pkcs1_two_padding (void)
 {
        guchar padded[] = { 0x00, 0x02, 0x77, 0x66, 0x55, 0x00, 'T', 'E', };
        gchar raw[] = "TE";
@@ -93,14 +99,14 @@ TESTING_TEST(pkcs1_two_padding)
        gpointer vesult;
        gsize n_result;
 
-       test_padding (egg_padding_pkcs1_unpad_02, 8, padded, 8, raw, 2);
+       check_padding (egg_padding_pkcs1_unpad_02, 8, padded, 8, raw, 2);
 
        /* PKCS#1 02 padding is unpredictable */
        if (!egg_padding_pkcs1_pad_02 (NULL, 8, raw, 2, &vesult, &n_result))
                g_assert_not_reached ();
        result = vesult;
        g_assert (result != NULL);
-       g_assert_cmpsize (n_result, ==, 8);
+       egg_assert_cmpsize (n_result, ==, 8);
        g_assert (result[0] == 0x00);
        g_assert (result[1] == 0x02);
        g_assert (result[2] != 0x00);
@@ -111,72 +117,106 @@ TESTING_TEST(pkcs1_two_padding)
        g_assert (result[7] == 'E');
 }
 
-TESTING_TEST(pkcs1_padding_invalid_prefix)
+static void
+test_pkcs1_padding_invalid_prefix (void)
 {
        guchar padded[] = { 0x01, 0x04, 0x04, 0x04 };
-       test_padding (egg_padding_pkcs1_unpad_01, 4, padded, 4, NULL, 0);
+       check_padding (egg_padding_pkcs1_unpad_01, 4, padded, 4, NULL, 0);
 }
 
-TESTING_TEST(pkcs1_padding_invalid_type)
+static void
+test_pkcs1_padding_invalid_type (void)
 {
        guchar padded[] = { 0x00, 0x03, 0xFF, 0x00, 'T', 'E', 'S', 'T' };
-       test_padding (egg_padding_pkcs1_unpad_01, 8, padded, 8, NULL, 0);
+       check_padding (egg_padding_pkcs1_unpad_01, 8, padded, 8, NULL, 0);
 }
 
-TESTING_TEST(pkcs1_padding_invalid_no_zero)
+static void
+test_pkcs1_padding_invalid_no_zero (void)
 {
        guchar padded[] = { 0x00, 0x01, 0xFF, 0xFF, 'T', 'E', 'S', 'T' };
-       test_padding (egg_padding_pkcs1_unpad_01, 8, padded, 8, NULL, 0);
+       check_padding (egg_padding_pkcs1_unpad_01, 8, padded, 8, NULL, 0);
 }
 
-TESTING_TEST(pkcs1_padding_invalid_length)
+static void
+test_pkcs1_padding_invalid_length (void)
 {
        guchar padded[] = { 0x00, 0x01, 0xFF, 0xFF, 'T', 'E', 'S' };
-       test_padding (egg_padding_pkcs1_unpad_01, 8, padded, 7, NULL, 0);
+       check_padding (egg_padding_pkcs1_unpad_01, 8, padded, 7, NULL, 0);
 }
 
-TESTING_TEST(pkcs7_padding)
+static void
+test_pkcs7_padding (void)
 {
        guchar padded[] = { 'T', 'E', 'S', 'T', 0x04, 0x04, 0x04, 0x04 };
        gchar raw[] = "TEST";
 
-       test_padding (egg_padding_pkcs7_pad, 8, raw, 4, padded, 8);
-       test_padding (egg_padding_pkcs7_unpad, 8, padded, 8, raw, 4);
+       check_padding (egg_padding_pkcs7_pad, 8, raw, 4, padded, 8);
+       check_padding (egg_padding_pkcs7_unpad, 8, padded, 8, raw, 4);
 }
 
-TESTING_TEST(pkcs7_padding_equal_block)
+static void
+test_pkcs7_padding_equal_block (void)
 {
        guchar padded[] = { 'T', 'E', 'S', 'T', 'T', 'E', 'S', 'T', 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08 };
        gchar raw[] = "TESTTEST";
 
-       test_padding (egg_padding_pkcs7_pad, 8, raw, 8, padded, 16);
-       test_padding (egg_padding_pkcs7_unpad, 8, padded, 16, raw, 8);
+       check_padding (egg_padding_pkcs7_pad, 8, raw, 8, padded, 16);
+       check_padding (egg_padding_pkcs7_unpad, 8, padded, 16, raw, 8);
 }
 
-TESTING_TEST(pkcs7_padding_zero)
+static void
+test_pkcs7_padding_zero (void)
 {
        guchar padded[] = { 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08 };
        gchar raw[] = "";
 
-       test_padding (egg_padding_pkcs7_pad, 8, raw, 0, padded, 8);
-       test_padding (egg_padding_pkcs7_unpad, 8, padded, 8, raw, 0);
+       check_padding (egg_padding_pkcs7_pad, 8, raw, 0, padded, 8);
+       check_padding (egg_padding_pkcs7_unpad, 8, padded, 8, raw, 0);
 }
 
-TESTING_TEST(pkcs7_padding_invalid_zero)
+static void
+test_pkcs7_padding_invalid_zero (void)
 {
        guchar padded[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
-       test_padding (egg_padding_pkcs7_unpad, 8, padded, 8, NULL, 0);
+       check_padding (egg_padding_pkcs7_unpad, 8, padded, 8, NULL, 0);
 }
 
-TESTING_TEST(pkcs7_padding_invalid_too_long)
+static void
+test_pkcs7_padding_invalid_too_long (void)
 {
        guchar padded[] = { 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08 };
-       test_padding (egg_padding_pkcs7_unpad, 4, padded, 8, NULL, 0);
-       test_padding (egg_padding_pkcs7_unpad, 4, padded, 4, NULL, 0);
+       check_padding (egg_padding_pkcs7_unpad, 4, padded, 8, NULL, 0);
+       check_padding (egg_padding_pkcs7_unpad, 4, padded, 4, NULL, 0);
 }
 
-TESTING_TEST(pkcs7_padding_invalid_different)
+static void
+test_pkcs7_padding_invalid_different (void)
 {
        guchar padded[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
-       test_padding (egg_padding_pkcs7_unpad, 8, padded, 8, NULL, 0);
+       check_padding (egg_padding_pkcs7_unpad, 8, padded, 8, NULL, 0);
+}
+
+int
+main (int argc, char **argv)
+{
+       g_test_init (&argc, &argv, NULL);
+
+       g_test_add_func ("/padding/zero_padding", test_zero_padding);
+       g_test_add_func ("/padding/zero_padding_no_data", test_zero_padding_no_data);
+       g_test_add_func ("/padding/pkcs1_one_padding", test_pkcs1_one_padding);
+       g_test_add_func ("/padding/pkcs1_one_padding_no_data", test_pkcs1_one_padding_no_data);
+       g_test_add_func ("/padding/pkcs1_two_padding", test_pkcs1_two_padding);
+       g_test_add_func ("/padding/pkcs1_padding_invalid_prefix", test_pkcs1_padding_invalid_prefix);
+       g_test_add_func ("/padding/pkcs1_padding_invalid_type", test_pkcs1_padding_invalid_type);
+       g_test_add_func ("/padding/pkcs1_padding_invalid_no_zero", test_pkcs1_padding_invalid_no_zero);
+       g_test_add_func ("/padding/pkcs1_padding_invalid_length", test_pkcs1_padding_invalid_length);
+       g_test_add_func ("/padding/pkcs7_padding", test_pkcs7_padding);
+       g_test_add_func ("/padding/pkcs7_padding_equal_block", test_pkcs7_padding_equal_block);
+       g_test_add_func ("/padding/pkcs7_padding_zero", test_pkcs7_padding_zero);
+       g_test_add_func ("/padding/pkcs7_padding_invalid_zero", test_pkcs7_padding_invalid_zero);
+       g_test_add_func ("/padding/pkcs7_padding_invalid_too_long", test_pkcs7_padding_invalid_too_long);
+       g_test_add_func ("/padding/pkcs7_padding_invalid_different", test_pkcs7_padding_invalid_different);
+
+       return g_test_run ();
 }
similarity index 86%
rename from egg/tests/unit-test-secmem.c
rename to egg/tests/test-secmem.c
index e1d7961..ddd74a1 100644 (file)
    Author: Stef Walter <stef@memberwebs.com>
 */
 
+#include "config.h"
+
+#include "egg-secure-memory.h"
+
+#include <glib.h>
+
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 
-#include "test-suite.h"
 
-#include "egg/egg-secure-memory.h"
+EGG_SECURE_GLIB_DEFINITIONS ();
 
 /* Declared in egg-secure-memory.c */
 extern int egg_secure_warnings;
@@ -58,7 +63,8 @@ find_non_zero (gpointer mem, gsize len)
        return G_MAXSIZE;
 }
 
-TESTING_TEST(secmem_alloc_free)
+static void
+test_alloc_free (void)
 {
        gpointer p;
        gboolean ret;
@@ -75,7 +81,8 @@ TESTING_TEST(secmem_alloc_free)
        egg_secure_free_full (p, 0);
 }
 
-TESTING_TEST(secmem_realloc_across)
+static void
+test_realloc_across (void)
 {
        gpointer p, p2;
 
@@ -90,7 +97,8 @@ TESTING_TEST(secmem_realloc_across)
        g_assert_cmpint (G_MAXSIZE, ==, find_non_zero (p2, 16200));
 }
 
-TESTING_TEST(secmem_alloc_two)
+static void
+test_alloc_two (void)
 {
        gpointer p, p2;
        gboolean ret;
@@ -114,7 +122,8 @@ TESTING_TEST(secmem_alloc_two)
        egg_secure_free_full (p, 0);
 }
 
-TESTING_TEST(secmem_realloc)
+static void
+test_realloc (void)
 {
        gchar *str = "a test string to see if realloc works properly";
        gpointer p, p2;
@@ -138,7 +147,8 @@ TESTING_TEST(secmem_realloc)
        g_assert (p == NULL);
 }
 
-TESTING_TEST(secmem_multialloc)
+static void
+test_multialloc (void)
 {
        GPtrArray *memory;
        gpointer data;
@@ -205,7 +215,8 @@ TESTING_TEST(secmem_multialloc)
        egg_secure_warnings = 1;
 }
 
-TESTING_TEST(secmem_clear)
+static void
+test_clear (void)
 {
        gpointer p;
 
@@ -220,7 +231,8 @@ TESTING_TEST(secmem_clear)
        egg_secure_free_full (p, 0);
 }
 
-TESTING_TEST(secmem_strclear)
+static void
+test_strclear (void)
 {
        gchar *str;
 
@@ -235,3 +247,19 @@ TESTING_TEST(secmem_strclear)
 
        egg_secure_free_full (str, 0);
 }
+
+int
+main (int argc, char **argv)
+{
+       g_test_init (&argc, &argv, NULL);
+
+       g_test_add_func ("/secmem/alloc_free", test_alloc_free);
+       g_test_add_func ("/secmem/realloc_across", test_realloc_across);
+       g_test_add_func ("/secmem/alloc_two", test_alloc_two);
+       g_test_add_func ("/secmem/realloc", test_realloc);
+       g_test_add_func ("/secmem/multialloc", test_multialloc);
+       g_test_add_func ("/secmem/clear", test_clear);
+       g_test_add_func ("/secmem/strclear", test_strclear);
+
+       return g_test_run ();
+}
similarity index 71%
rename from egg/tests/unit-test-symkey.c
rename to egg/tests/test-symkey.c
index b0ab052..c2c1b78 100644 (file)
    Author: Stef Walter <stef@memberwebs.com>
 */
 
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "test-suite.h"
+#include "config.h"
 
 #include "egg-libgcrypt.h"
 #include "egg-secure-memory.h"
 
 #include <gcrypt.h>
 
-TESTING_SETUP(crypto_setup)
-{
-       egg_libgcrypt_initialize ();
-}
-
-TESTING_TEARDOWN(crypto_setup)
-{
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
 
-}
+EGG_SECURE_GLIB_DEFINITIONS ();
 
 static const struct {
        const gchar *password;
@@ -63,7 +55,7 @@ static const struct {
                NULL,
                NULL,
                NULL
-        },
+       },
 
        { /* 5 byte output */
                "booo", GCRY_CIPHER_RFC2268_40, GCRY_MD_SHA1, 2048,
@@ -122,7 +114,8 @@ static const struct {
 
 #define N_GENERATION_TESTS (sizeof (all_generation_tests) / sizeof (all_generation_tests[0]))
 
-TESTING_TEST(generate_key_simple)
+static void
+test_generate_key_simple (void)
 {
        int i;
        gboolean ret;
@@ -134,11 +127,11 @@ TESTING_TEST(generate_key_simple)
                        continue;
 
                ret = egg_symkey_generate_simple (all_generation_tests[i].cipher_algo,
-                                                         all_generation_tests[i].hash_algo,
-                                                         all_generation_tests[i].password, -1,
-                                                         (guchar*)all_generation_tests[i].salt, 8,
-                                                         all_generation_tests[i].iterations,
-                                                         &key, NULL);
+                                                 all_generation_tests[i].hash_algo,
+                                                 all_generation_tests[i].password, -1,
+                                                 (guchar*)all_generation_tests[i].salt, 8,
+                                                 all_generation_tests[i].iterations,
+                                                 &key, NULL);
                g_assert (ret && "key generation failed");
 
                ret = (memcmp (key, all_generation_tests[i].result_simple,
@@ -148,7 +141,8 @@ TESTING_TEST(generate_key_simple)
        }
 }
 
-TESTING_TEST(generate_key_pkcs12)
+static void
+test_generate_key_pkcs12 (void)
 {
        int i;
        gboolean ret;
@@ -160,11 +154,11 @@ TESTING_TEST(generate_key_pkcs12)
                        continue;
 
                ret = egg_symkey_generate_pkcs12 (all_generation_tests[i].cipher_algo,
-                                                         all_generation_tests[i].hash_algo,
-                                                         all_generation_tests[i].password, -1,
-                                                         (guchar*)all_generation_tests[i].salt, 8,
-                                                         all_generation_tests[i].iterations,
-                                                         &key, NULL);
+                                                 all_generation_tests[i].hash_algo,
+                                                 all_generation_tests[i].password, -1,
+                                                 (guchar*)all_generation_tests[i].salt, 8,
+                                                 all_generation_tests[i].iterations,
+                                                 &key, NULL);
                g_assert ("failed to generate pkcs12 key" && ret);
 
                ret = (memcmp (key, all_generation_tests[i].result_pkcs12,
@@ -174,7 +168,8 @@ TESTING_TEST(generate_key_pkcs12)
        }
 }
 
-TESTING_TEST(generate_key_pbkdf2)
+static void
+test_generate_key_pbkdf2 (void)
 {
        int i;
        gboolean ret;
@@ -186,11 +181,11 @@ TESTING_TEST(generate_key_pbkdf2)
                        continue;
 
                ret = egg_symkey_generate_pbkdf2 (all_generation_tests[i].cipher_algo,
-                                                         all_generation_tests[i].hash_algo,
-                                                         all_generation_tests[i].password, -1,
-                                                         (guchar*)all_generation_tests[i].salt, 8,
-                                                         all_generation_tests[i].iterations,
-                                                         &key, NULL);
+                                                 all_generation_tests[i].hash_algo,
+                                                 all_generation_tests[i].password, -1,
+                                                 (guchar*)all_generation_tests[i].salt, 8,
+                                                 all_generation_tests[i].iterations,
+                                                 &key, NULL);
                g_assert ("failed to generate pbkdf2 key" && ret);
 
                ret = (memcmp (key, all_generation_tests[i].result_pbkdf2,
@@ -200,7 +195,8 @@ TESTING_TEST(generate_key_pbkdf2)
        }
 }
 
-TESTING_TEST(generate_key_pbe)
+static void
+test_generate_key_pbe (void)
 {
        int i;
        gboolean ret;
@@ -212,11 +208,11 @@ TESTING_TEST(generate_key_pbe)
                        continue;
 
                ret = egg_symkey_generate_pbe (all_generation_tests[i].cipher_algo,
-                                                      all_generation_tests[i].hash_algo,
-                                                      all_generation_tests[i].password, -1,
-                                                      (guchar*)all_generation_tests[i].salt, 8,
-                                                      all_generation_tests[i].iterations,
-                                                      &key, NULL);
+                                              all_generation_tests[i].hash_algo,
+                                              all_generation_tests[i].password, -1,
+                                              (guchar*)all_generation_tests[i].salt, 8,
+                                              all_generation_tests[i].iterations,
+                                              &key, NULL);
                g_assert ("failed to generate pbe key" && ret);
 
                ret = (memcmp (key, all_generation_tests[i].result_pbe,
@@ -226,3 +222,17 @@ TESTING_TEST(generate_key_pbe)
 
        }
 }
+
+int
+main (int argc, char **argv)
+{
+       g_test_init (&argc, &argv, NULL);
+       egg_libgcrypt_initialize ();
+
+       g_test_add_func ("/symkey/generate_key_simple", test_generate_key_simple);
+       g_test_add_func ("/symkey/generate_key_pkcs12", test_generate_key_pkcs12);
+       g_test_add_func ("/symkey/generate_key_pbkdf2", test_generate_key_pbkdf2);
+       g_test_add_func ("/symkey/generate_key_pbe", test_generate_key_pbe);
+
+       return g_test_run ();
+}
diff --git a/egg/tests/unit-test-asn1.c b/egg/tests/unit-test-asn1.c
deleted file mode 100644 (file)
index 846b528..0000000
+++ /dev/null
@@ -1,427 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* unit-test-pkix-parser.c: Test PKIX parser
-
-   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 "test-suite.h"
-
-#include "egg/egg-asn1-defs.h"
-#include "egg/egg-asn1x.h"
-#include "egg/egg-oid.h"
-
-#include <glib.h>
-#include <gcrypt.h>
-#include <libtasn1.h>
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-extern const ASN1_ARRAY_TYPE test_asn1_tab[];
-
-static GNode *asn1_cert = NULL;
-static guchar *data_cert = NULL;
-static gsize n_data_cert = 0;
-
-TESTING_SETUP(asn1_tree)
-{
-       data_cert = testing_data_read ("test-certificate-1.der", &n_data_cert);
-
-       asn1_cert = egg_asn1x_create (pkix_asn1_tab, "Certificate");
-       g_assert (asn1_cert != NULL);
-
-       if (!egg_asn1x_decode (asn1_cert, data_cert, n_data_cert))
-               egg_asn1x_assert_not_reached (asn1_cert);
-}
-
-TESTING_TEARDOWN(asn1_tree)
-{
-       egg_asn1x_destroy (asn1_cert);
-       g_free (data_cert);
-       data_cert = NULL;
-}
-
-TESTING_TEST(node_name)
-{
-       g_assert_cmpstr (egg_asn1x_name (asn1_cert), ==, "Certificate");
-}
-
-TESTING_TEST(asn1_integers)
-{
-       GNode *asn;
-       guchar *data;
-       gsize n_data;
-       gboolean ret;
-       gulong val;
-
-       asn = egg_asn1x_create (test_asn1_tab, "TestIntegers");
-       g_assert ("asn test structure is null" && asn != NULL);
-
-       ret = egg_asn1x_set_integer_as_ulong (egg_asn1x_node (asn, "uint1", NULL), 35);
-       g_assert ("couldn't write integer" && ret);
-
-       ret = egg_asn1x_set_integer_as_ulong (egg_asn1x_node (asn, "uint2", NULL), 23456);
-       g_assert ("couldn't write integer" && ret);
-
-       ret = egg_asn1x_set_integer_as_ulong (egg_asn1x_node (asn, "uint3", NULL), 209384022);
-       g_assert ("couldn't write integer" && ret);
-
-       /* Now encode the whole caboodle */
-       data = egg_asn1x_encode (asn, NULL, &n_data);
-       g_assert ("encoding asn1 didn't work" && data != NULL);
-
-       egg_asn1x_destroy (asn);
-
-       /* Now decode it all nicely */
-       asn = egg_asn1x_create_and_decode (test_asn1_tab, "TestIntegers", data, n_data);
-       g_return_if_fail (asn != NULL);
-
-       /* And get out the values */
-       ret = egg_asn1x_get_integer_as_ulong (egg_asn1x_node (asn, "uint1", NULL), &val);
-       g_assert ("couldn't read integer from asn1" && ret);
-       g_assert_cmpuint (val, ==, 35);
-
-       ret = egg_asn1x_get_integer_as_ulong (egg_asn1x_node (asn, "uint2", NULL), &val);
-       g_assert ("couldn't read integer from asn1" && ret);
-       g_assert_cmpuint (val, ==, 23456);
-
-       ret = egg_asn1x_get_integer_as_ulong (egg_asn1x_node (asn, "uint3", NULL), &val);
-       g_assert ("couldn't read integer from asn1" && ret);
-       g_assert_cmpuint (val, ==, 209384022);
-
-       g_free (data);
-}
-
-TESTING_TEST(boolean)
-{
-       GNode *asn = NULL;
-       gboolean value, ret;
-       gpointer data;
-       gsize n_data;
-
-       asn = egg_asn1x_create (test_asn1_tab, "TestBooleanSeq");
-       g_assert ("asn test structure is null" && asn != NULL);
-
-       /* Get the default value */
-       value = TRUE;
-       ret = egg_asn1x_get_boolean (egg_asn1x_node (asn, "boolean", NULL), &value);
-       g_assert (ret == TRUE);
-       g_assert (value == FALSE);
-
-       ret = egg_asn1x_set_boolean (egg_asn1x_node (asn, "boolean", NULL), TRUE);
-       g_assert (ret == TRUE);
-
-       data = egg_asn1x_encode (asn, NULL, &n_data);
-       g_assert (data);
-
-       ret = egg_asn1x_get_boolean (egg_asn1x_node (asn, "boolean", NULL), &value);
-       g_assert (ret);
-       g_assert (value == TRUE);
-
-       ret = egg_asn1x_set_boolean (egg_asn1x_node (asn, "boolean", NULL), FALSE);
-       g_assert (ret == TRUE);
-
-       g_free (data);
-       data = egg_asn1x_encode (asn, NULL, &n_data);
-       g_assert (data);
-
-       ret = egg_asn1x_get_boolean (egg_asn1x_node (asn, "boolean", NULL), &value);
-       g_assert (ret);
-       g_assert (value == FALSE);
-
-       g_free (data);
-       egg_asn1x_destroy (asn);
-}
-
-TESTING_TEST(write_value)
-{
-       GNode *asn = NULL;
-       guchar *data;
-       gsize n_data;
-       guchar *encoded;
-       gsize n_encoded;
-
-       asn = egg_asn1x_create (test_asn1_tab, "TestData");
-       g_assert ("asn test structure is null" && asn != NULL);
-
-       if (!egg_asn1x_set_string_as_raw (egg_asn1x_node (asn, "data", NULL), (guchar*)"SOME DATA", 9, NULL))
-               g_assert_not_reached ();
-
-       encoded = egg_asn1x_encode (asn, NULL, &n_encoded);
-       g_assert (encoded);
-
-       data = egg_asn1x_get_string_as_raw (egg_asn1x_node (asn, "data", NULL), NULL, &n_data);
-       g_assert (data != NULL);
-       g_assert_cmpuint (n_data, ==, 9);
-       g_assert (memcmp (data, "SOME DATA", 9) == 0);
-       g_free (data);
-
-       g_free (encoded);
-       egg_asn1x_destroy (asn);
-}
-
-TESTING_TEST(element_length_content)
-{
-       GNode *asn = NULL;
-       gchar *buffer;
-       const guchar *content;
-       gsize n_content;
-       gsize n_buffer;
-       gssize length;
-
-       asn = egg_asn1x_create (test_asn1_tab, "TestData");
-       g_assert ("asn test structure is null" && asn != NULL);
-
-       if (!egg_asn1x_set_string_as_raw (egg_asn1x_node (asn, "data", NULL), (guchar*)"SOME DATA", 9, NULL))
-               g_assert_not_reached ();
-
-       buffer = egg_asn1x_encode (asn, NULL, &n_buffer);
-       g_assert (buffer != NULL);
-
-       /* Now the real test */
-       length = egg_asn1x_element_length (buffer, n_buffer + 1024);
-       g_assert_cmpint (length, ==, 13);
-
-       content = egg_asn1x_element_content (buffer, length, &n_content);
-       g_assert (content);
-       g_assert_cmpuint (n_content, ==, 11);
-
-       content = egg_asn1x_element_content (content, n_content, &n_content);
-       g_assert (content);
-       g_assert_cmpuint (n_content, ==, 9);
-       g_assert (memcmp (content, "SOME DATA", 9) == 0);
-
-       const char *BAD_ASN_TAG = "\x00";
-       content = egg_asn1x_element_content (BAD_ASN_TAG, 1, &n_content);
-       g_assert (content == NULL);
-
-       const char *BAD_ASN_LENGTH = "\x30\x80";
-       content = egg_asn1x_element_content (BAD_ASN_LENGTH, 2, &n_content);
-       g_assert (content == NULL);
-
-       egg_asn1x_destroy (asn);
-       g_free (buffer);
-}
-
-TESTING_TEST(read_element)
-{
-       GNode *asn = NULL;
-       guchar *buffer;
-       gconstpointer data;
-       gsize n_data;
-       gsize n_buffer;
-
-       asn = egg_asn1x_create (test_asn1_tab, "TestData");
-       g_assert ("asn test structure is null" && asn != NULL);
-
-       if (!egg_asn1x_set_string_as_raw (egg_asn1x_node (asn, "data", NULL), (guchar*)"SOME DATA", 9, NULL))
-               g_assert_not_reached ();
-
-       buffer = egg_asn1x_encode (asn, NULL, &n_buffer);
-       g_assert (buffer != NULL);
-
-       /* Now the real test */
-       data = egg_asn1x_get_raw_element (egg_asn1x_node (asn, "data", NULL), &n_data);
-       g_assert (data != NULL);
-       g_assert_cmpint (n_data, ==, 11);
-
-       data = egg_asn1x_get_raw_value (egg_asn1x_node (asn, "data", NULL), &n_data);
-       g_assert (data);
-       g_assert_cmpuint (n_data, ==, 9);
-       g_assert (memcmp (data, "SOME DATA", 9) == 0);
-
-       egg_asn1x_destroy (asn);
-       g_free (buffer);
-}
-
-TESTING_TEST(oid)
-{
-       GNode *asn = NULL;
-       GQuark oid, check;
-       guchar *buffer;
-       gsize n_buffer;
-
-       asn = egg_asn1x_create (test_asn1_tab, "TestOid");
-       g_assert ("asn test structure is null" && asn != NULL);
-
-       if (!egg_asn1x_set_oid_as_string (egg_asn1x_node (asn, "oid", NULL), "1.2.34567.89"))
-               g_assert_not_reached ();
-
-       buffer = egg_asn1x_encode (asn, NULL, &n_buffer);
-       g_assert (buffer != NULL);
-
-       /* Now a quark has been defined */
-       check = g_quark_from_static_string ("1.2.34567.89");
-       oid = egg_asn1x_get_oid_as_quark (egg_asn1x_node (asn, "oid", NULL));
-       g_assert (oid);
-       g_assert (check == oid);
-       g_assert_cmpstr (g_quark_to_string (oid), ==, "1.2.34567.89");
-
-       /* Write a different OID */
-       if (!egg_asn1x_set_oid_as_quark (egg_asn1x_node (asn, "oid", NULL), g_quark_from_static_string ("5.4.3.2.1678")))
-               g_assert_not_reached ();
-
-       g_free (buffer);
-       buffer = egg_asn1x_encode (asn, NULL, &n_buffer);
-       g_assert (buffer != NULL);
-
-       oid = egg_asn1x_get_oid_as_quark (egg_asn1x_node (asn, "oid", NULL));
-       g_assert (oid);
-       g_assert_cmpstr (g_quark_to_string (oid), ==, "5.4.3.2.1678");
-
-       g_free (buffer);
-       egg_asn1x_destroy (asn);
-}
-
-typedef struct _TimeTestData {
-       gchar *value;
-       time_t ref;
-} TimeTestData;
-
-static const TimeTestData generalized_time_test_data[] = {
-       { "20070725130528Z", 1185368728 },
-       { "20070725130528.2134Z", 1185368728 },
-       { "20070725140528-0100", 1185368728 },
-       { "20070725040528+0900", 1185368728 },
-       { "20070725013528+1130", 1185368728 },
-       { "20070725Z", 1185321600 },
-       { "20070725+0000", 1185321600 },
-
-       /* Bad ones */
-       { "200707", -1 },
-
-       { NULL, 0 }
-};
-
-static const TimeTestData utc_time_test_data[] = {
-       /* Test the Y2K style wrap arounds */
-       { "070725130528Z", 1185368728 },  /* The year 2007 */
-       { "020725130528Z", 1027602328 },  /* The year 2002 */
-       { "970725130528Z", 869835928 },   /* The year 1997 */
-       { "370725130528Z", 2132139928 },  /* The year 2037 */
-
-       /* Test the time zones and other formats */
-       { "070725130528.2134Z", 1185368728 },
-       { "070725140528-0100", 1185368728 },
-       { "070725040528+0900", 1185368728 },
-       { "070725013528+1130", 1185368728 },
-       { "070725Z", 1185321600 },
-       { "070725+0000", 1185321600 },
-
-       /* Bad ones */
-       { "0707", -1 },
-
-       { NULL, 0 }
-};
-
-TESTING_TEST(general_time)
-{
-       time_t when;
-       const TimeTestData *data;
-
-       for (data = generalized_time_test_data; data->value; ++data) {
-               when = egg_asn1x_parse_time_general (data->value, -1);
-               if (data->ref != when) {
-                       printf ("%s", data->value);
-                       printf ("%s != ", ctime (&when));
-                       printf ("%s\n", ctime (&data->ref));
-                       fflush (stdout);
-               }
-
-               g_assert ("decoded time doesn't match reference" && data->ref == when);
-       }
-}
-
-TESTING_TEST(utc_time)
-{
-       time_t when;
-       const TimeTestData *data;
-
-       for (data = utc_time_test_data; data->value; ++data) {
-               when = egg_asn1x_parse_time_utc (data->value, -1);
-               if (data->ref != when) {
-                       printf ("%s", data->value);
-                       printf ("%s != ", ctime (&when));
-                       printf ("%s\n", ctime (&data->ref));
-                       fflush (stdout);
-               }
-
-               g_assert ("decoded time doesn't match reference" && data->ref == when);
-       }
-}
-
-TESTING_TEST(read_time)
-{
-       glong time;
-
-       time = egg_asn1x_get_time_as_long (egg_asn1x_node (asn1_cert, "tbsCertificate", "validity", "notBefore", NULL));
-       g_assert_cmpint (time, ==, 820454400);
-}
-
-TESTING_TEST(read_date)
-{
-       GDate date;
-       if (!egg_asn1x_get_time_as_date (egg_asn1x_node (asn1_cert, "tbsCertificate", "validity", "notAfter", NULL), &date))
-               g_assert_not_reached ();
-       g_assert_cmpint (date.day, ==, 31);
-       g_assert_cmpint (date.month, ==, 12);
-       g_assert_cmpint (date.year, ==, 2020);
-}
-
-TESTING_TEST(create_by_oid)
-{
-       /* id-at-initials = X520initials */
-       GNode *node = egg_asn1x_create (pkix_asn1_tab, "2.5.4.43");
-       g_assert (node != NULL);
-       g_assert_cmpstr (egg_asn1x_name (node), ==, "X520initials");
-       egg_asn1x_destroy (node);
-}
-
-TESTING_TEST(create_by_oid_invalid)
-{
-       GNode *node = egg_asn1x_create (pkix_asn1_tab, "23.23.23.23");
-       g_assert (node == NULL);
-}
-
-TESTING_TEST(create_by_bad_order)
-{
-       /*
-        * In pkix.asn the definition for parts of this oid
-        * come in the wrong order. However this should still work.
-        */
-
-       /* id-pe-authorityInfoAccess = AuthorityInfoAccessSyntax */
-       GNode *node = egg_asn1x_create (pkix_asn1_tab, "1.3.6.1.5.5.7.1.1");
-       g_assert (node != NULL);
-       g_assert_cmpstr (egg_asn1x_name (node), ==, "AuthorityInfoAccessSyntax");
-       egg_asn1x_destroy (node);
-}
-
-TESTING_TEST(count)
-{
-       GNode *node;
-
-       node = egg_asn1x_node (asn1_cert, "tbsCertificate", "issuer", "rdnSequence", NULL);
-       g_assert (node);
-       g_assert_cmpuint (egg_asn1x_count (node), ==, 7);
-}
diff --git a/egg/tests/unit-test-spawn.c b/egg/tests/unit-test-spawn.c
deleted file mode 100644 (file)
index 23be4cf..0000000
+++ /dev/null
@@ -1,270 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* unit-test-dh.c: Test egg-spawn.c
-
-   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 <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "test-suite.h"
-
-#include "egg-spawn.h"
-
-#include <sys/wait.h>
-
-typedef struct _EchoData {
-       gint index;
-       gchar *output;
-       gchar *error;
-       gboolean finalized;
-       gboolean completed;
-       gboolean is_async;
-       pid_t parent_pid;
-} EchoData;
-
-static gboolean
-want_input (gint fd, gpointer user_data)
-{
-       EchoData *data = user_data;
-       gchar *buffer;
-
-       g_assert (data);
-       if (data->index == 85)
-               return FALSE;
-
-       g_assert (data->index >= 80);
-       g_assert (data->index < 85);
-
-       buffer = g_strdup_printf ("%d\n", data->index);
-       if (egg_spawn_write_input (fd, (guchar*)buffer, strlen (buffer)) < 0)
-               g_assert_not_reached ();
-       g_free (buffer);
-       ++data->index;
-       return TRUE;
-}
-
-static gboolean
-have_output (gint fd, gpointer user_data)
-{
-       EchoData *data = user_data;
-       gchar buffer[1024];
-       gssize length;
-       gchar *output;
-
-       g_assert (data);
-
-       length = egg_spawn_read_output (fd, (guchar*)buffer, 1023);
-       g_assert (length >= 0);
-
-       buffer[length] = 0;
-       output = g_strconcat (data->output ? data->output : "", buffer, NULL);
-       g_free (data->output);
-       data->output = output;
-
-       return (length > 0);
-}
-
-static gboolean
-have_error (gint fd, gpointer user_data)
-{
-       EchoData *data = user_data;
-       gchar buffer[1024];
-       gssize length;
-       gchar *error;
-
-       g_assert (data);
-
-       length = egg_spawn_read_output (fd, (guchar*)buffer, 1023);
-       g_assert (length >= 0);
-
-       buffer[length] = 0;
-       error = g_strconcat (data->error ? data->error : "", buffer, NULL);
-       g_free (data->error);
-       data->error = error;
-
-       return (length > 0);
-}
-
-static void
-completed_func (gpointer user_data)
-{
-       EchoData *data = user_data;
-       g_assert (data);
-       g_assert (!data->finalized);
-       g_assert (!data->completed);
-       data->completed = TRUE;
-       if (data->is_async)
-               testing_wait_stop ();
-}
-
-static void
-finalize_func (gpointer user_data)
-{
-       EchoData *data = user_data;
-       g_assert (!data->finalized);
-       data->finalized = 1;
-}
-
-static void
-child_setup (gpointer user_data)
-{
-       EchoData *data = user_data;
-       g_assert (data->parent_pid != getpid ());
-}
-
-static EggSpawnCallbacks echo_callbacks = {
-       want_input,
-       have_output,
-       have_error,
-       completed_func,
-       finalize_func,
-       child_setup,
-};
-
-static char* echo_argv[] = {
-       "/bin/sh",
-       "./echo-script.sh",
-       NULL
-};
-
-static char* error_argv[] = {
-       "/nonexistent",
-       NULL
-};
-
-static EggSpawnCallbacks null_callbacks = {
-       NULL,
-       NULL,
-       NULL,
-       completed_func,
-       finalize_func,
-       child_setup,
-};
-
-TESTING_TEST(test_spawn_sync)
-{
-       GError *error = NULL;
-       gboolean ret;
-       gint exit_status;
-       EchoData data;
-       GPid pid = 0;
-
-       memset (&data, 0, sizeof (data));
-       data.parent_pid = getpid();
-       data.index = 80;
-
-       ret = egg_spawn_sync_with_callbacks (testing_data_directory (),
-                                            echo_argv, NULL, 0, &pid,
-                                            &echo_callbacks, &data,
-                                            &exit_status, &error);
-       g_assert (ret == TRUE);
-       g_assert (pid != 0);
-       g_assert (WIFEXITED (exit_status));
-       g_assert_cmpint (WEXITSTATUS(exit_status), ==, 3);
-       g_assert (error == NULL);
-       g_assert (data.finalized);
-       g_assert (data.completed);
-       g_assert_cmpstr (data.output, ==, "80 81 82 83 84\n");
-       g_assert_cmpstr (data.error, ==, "1\n2\n3\n4\n5\n");
-}
-
-TESTING_TEST(test_spawn_sync_error)
-{
-       GError *error = NULL;
-       gboolean ret;
-
-       ret = egg_spawn_sync_with_callbacks (testing_data_directory (),
-                                            error_argv, NULL, 0, NULL,
-                                            NULL, NULL,
-                                            NULL, &error);
-       g_assert (ret == FALSE);
-       g_assert (error != NULL);
-       g_clear_error (&error);
-}
-
-
-TESTING_TEST(test_spawn_async)
-{
-       GError *error = NULL;
-       EchoData data;
-       guint ret;
-       GPid pid;
-
-       memset (&data, 0, sizeof (data));
-       data.parent_pid = getpid();
-       data.index = 80;
-       data.is_async = TRUE;
-
-       ret = egg_spawn_async_with_callbacks (testing_data_directory (),
-                                            echo_argv, NULL, 0, &pid,
-                                            &echo_callbacks, &data,
-                                            NULL, &error);
-       g_assert (ret != 0);
-       g_assert (error == NULL);
-       g_assert (!data.finalized);
-
-       testing_wait_until (2000);
-
-       g_assert (data.finalized);
-       g_assert (data.completed);
-       g_assert_cmpstr (data.output, ==, "80 81 82 83 84\n");
-       g_assert_cmpstr (data.error, ==, "1\n2\n3\n4\n5\n");
-}
-
-TESTING_TEST(test_spawn_async_none)
-{
-       GError *error = NULL;
-       EchoData data;
-       guint ret;
-
-       memset (&data, 0, sizeof (data));
-       data.parent_pid = getpid();
-       data.is_async = TRUE;
-
-       ret = egg_spawn_async_with_callbacks (testing_data_directory (),
-                                            echo_argv, NULL, 0, NULL,
-                                            &null_callbacks, &data,
-                                            NULL, &error);
-       g_assert (ret != 0);
-       g_assert (error == NULL);
-       g_assert (!data.finalized);
-
-       testing_wait_until (2000);
-
-       g_assert (data.finalized);
-       g_assert (data.completed);
-       g_assert (!data.output);
-}
-
-TESTING_TEST(test_spawn_async_error)
-{
-       GError *error = NULL;
-       guint ret;
-
-       ret = egg_spawn_async_with_callbacks (testing_data_directory (),
-                                            error_argv, NULL, 0, NULL,
-                                            NULL, NULL,
-                                            NULL, &error);
-       g_assert (ret == 0);
-       g_assert (error != NULL);
-       g_clear_error (&error);
-}