[libgnome-keyring] Convert to simpler gtest usage with one process per suite.
- From: Stefan Walter <stefw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgnome-keyring] Convert to simpler gtest usage with one process per suite.
- Date: Wed, 23 Feb 2011 10:08:16 +0000 (UTC)
commit e9d716e05cb6bd3a0f901c6378eeaa480330052e
Author: Stef Walter <stefw collabora co uk>
Date: Wed Feb 23 10:36:38 2011 +0100
Convert to simpler gtest usage with one process per suite.
.gitignore | 5 +
Makefile.am | 6 -
configure.in | 4 +-
egg/Makefile.am | 3 +-
egg/egg-secure-memory.c | 10 +-
egg/egg-secure-memory.h | 8 +
egg/egg-testing.h | 32 +++
egg/tests/Makefile.am | 22 ++-
egg/tests/test-dh.c | 84 +++++---
egg/tests/{unit-test-secmem.c => test-secmem.c} | 47 +++-
library/Makefile.am | 2 -
library/tests/Makefile.am | 37 ++--
library/tests/test-keyrings.c | 242 ++++++++++++++++++---
library/tests/test-memory.c | 35 +++-
library/tests/test-other.c | 41 ++---
library/tests/test-prompting.c | 3 +-
tests/Makefile.am | 6 -
tests/gtest-helpers.c | 266 -----------------------
tests/gtest-helpers.h | 75 -------
tests/gtest.make | 49 ----
tests/prep-gtest.sh | 119 ----------
21 files changed, 436 insertions(+), 660 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 8ab339b..f193699 100644
--- a/.gitignore
+++ b/.gitignore
@@ -101,6 +101,8 @@ run-auto-test.h
# /egg/tests
/egg/tests/Makefile
/egg/tests/Makefile.in
+/egg/tests/test-dh
+/egg/tests/test-secmem
# /library
/library/*.pc
@@ -111,6 +113,9 @@ run-auto-test.h
/library/tests/Makefile
/library/tests/Makefile.in
/library/tests/test-prompting
+/library/tests/test-keyrings
+/library/tests/test-memory
+/library/tests/test-other
# /po
/po/*.gmo
diff --git a/Makefile.am b/Makefile.am
index cfadba2..710af78 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,14 +1,8 @@
-if WITH_TESTS
-TESTS_DIR = tests
-else
-TESTS_DIR =
-endif
SUBDIRS = \
. \
egg \
library \
- $(TESTS_DIR) \
po \
docs
diff --git a/configure.in b/configure.in
index 1fc6974..bacdf7a 100644
--- a/configure.in
+++ b/configure.in
@@ -37,6 +37,9 @@ PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.16.0)
AC_SUBST(GLIB_CFLAGS)
AC_SUBST(GLIB_LIBS)
+LIBRARY_CFLAGS="$LIBRARY_CFLAGS $GLIB_CFLAGS"
+LIBRARY_LIBS="$LIBRARY_LIBS $GLIB_LIBS"
+
GETTEXT_PACKAGE="libgnome-keyring"
AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE, "$GETTEXT_PACKAGE", [The gettext domain name])
AC_SUBST(GETTEXT_PACKAGE)
@@ -214,7 +217,6 @@ library/tests/Makefile
library/gnome-keyring-1.pc
library/gnome-keyring-1-uninstalled.pc
po/Makefile.in
-tests/Makefile
])
# ------------------------------------------------------------------------------
diff --git a/egg/Makefile.am b/egg/Makefile.am
index a765a14..7fce691 100644
--- a/egg/Makefile.am
+++ b/egg/Makefile.am
@@ -15,7 +15,8 @@ libegg_la_SOURCES = \
egg-dbus.c egg-dbus.h \
egg-dh.c egg-dh.h \
egg-libgcrypt.c egg-libgcrypt.h \
- egg-secure-memory.c egg-secure-memory.h
+ egg-secure-memory.c egg-secure-memory.h \
+ egg-testing.h
# -------------------------------------------------------------------
diff --git a/egg/egg-secure-memory.c b/egg/egg-secure-memory.c
index 2433ce6..27fa874 100644
--- a/egg/egg-secure-memory.c
+++ b/egg/egg-secure-memory.c
@@ -1205,11 +1205,11 @@ egg_secure_clear (void *p, size_t length)
if (p == NULL)
return;
- vp = (volatile char*)p;
- while (length) {
- *vp = 0xAA;
- vp++;
- length--;
+ vp = (volatile char*)p;
+ while (length) {
+ *vp = 0xAA;
+ vp++;
+ length--;
}
}
diff --git a/egg/egg-secure-memory.h b/egg/egg-secure-memory.h
index 6d412cd..fb2e84e 100644
--- a/egg/egg-secure-memory.h
+++ b/egg/egg-secure-memory.h
@@ -55,6 +55,14 @@ extern void egg_memory_unlock (void);
*/
extern void* egg_memory_fallback (void *p, size_t length);
+#define EGG_SECURE_GLIB_DEFINITIONS() \
+ static GStaticMutex memory_mutex = G_STATIC_MUTEX_INIT; \
+ void egg_memory_lock (void) \
+ { g_static_mutex_lock (&memory_mutex); } \
+ void egg_memory_unlock (void) \
+ { g_static_mutex_unlock (&memory_mutex); } \
+ void* egg_memory_fallback (void *p, size_t sz) \
+ { return g_realloc (p, sz); } \
/*
* Main functionality
diff --git a/egg/egg-testing.h b/egg/egg-testing.h
new file mode 100644
index 0000000..ef27cfe
--- /dev/null
+++ b/egg/egg-testing.h
@@ -0,0 +1,32 @@
+/*
+ * 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>
+
+#define egg_assert_cmpsize(a, o, b) \
+ g_assert_cmpuint ((guint)(a), o, (guint)(b))
+
+#endif /* EGG_DH_H_ */
diff --git a/egg/tests/Makefile.am b/egg/tests/Makefile.am
index 0efe754..13fd068 100644
--- a/egg/tests/Makefile.am
+++ b/egg/tests/Makefile.am
@@ -1,11 +1,19 @@
-# Test files should be listed in order they need to run
-TEST_AUTO = \
- test-dh.c \
- unit-test-secmem.c
+INCLUDES = \
+ -I$(top_srcdir)/egg \
+ $(LIBRARY_CFLAGS)
-TEST_LIBS = \
- $(top_builddir)/egg/libegg.la
+LDADD = \
+ $(top_builddir)/egg/libegg.la \
+ $(LIBRARY_LIBS)
-include $(top_srcdir)/tests/gtest.make
+TEST_PROGS = \
+ test-dh \
+ test-secmem
+check_PROGRAMS = $(TEST_PROGS)
+
+test: ${TEST_PROGS}
+ gtester -k --verbose ${TEST_PROGS}
+
+check-local: test
diff --git a/egg/tests/test-dh.c b/egg/tests/test-dh.c
index 1111fd4..81cf0d7 100644
--- a/egg/tests/test-dh.c
+++ b/egg/tests/test-dh.c
@@ -21,18 +21,23 @@
Author: Stef Walter <stef memberwebs com>
*/
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "run-auto-test.h"
+#include "config.h"
#include "egg-dh.h"
#include "egg-secure-memory.h"
+#include "egg-testing.h"
+#include <glib.h>
#include <gcrypt.h>
-DEFINE_TEST(dh_perform)
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+EGG_SECURE_GLIB_DEFINITIONS ();
+
+static void
+test_dh_perform (void)
{
gcry_mpi_t p, g;
gcry_mpi_t x1, X1;
@@ -69,7 +74,8 @@ DEFINE_TEST(dh_perform)
egg_secure_free (k2);
}
-DEFINE_TEST(dh_short_pair)
+static void
+test_dh_short_pair (void)
{
gcry_mpi_t p, g;
gcry_mpi_t x1, X1;
@@ -92,7 +98,7 @@ DEFINE_TEST(dh_short_pair)
}
static void
-test_dh_default (const gchar *name, guint bits)
+check_dh_default (const gchar *name, guint bits)
{
gboolean ret;
gcry_mpi_t p, g, check;
@@ -108,9 +114,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 +132,50 @@ test_dh_default (const gchar *name, guint bits)
gcry_mpi_release (g);
}
-DEFINE_TEST(dh_default_768)
+static void
+test_dh_default_768 (void)
{
- test_dh_default ("ietf-ike-grp-modp-768", 768);
+ check_dh_default ("ietf-ike-grp-modp-768", 768);
}
-DEFINE_TEST(dh_default_1024)
+static void
+test_dh_default_1024 (void)
{
- test_dh_default ("ietf-ike-grp-modp-1024", 1024);
+ check_dh_default ("ietf-ike-grp-modp-1024", 1024);
}
-DEFINE_TEST(dh_default_1536)
+static void
+test_dh_default_1536 (void)
{
- test_dh_default ("ietf-ike-grp-modp-1536", 1536);
+ check_dh_default ("ietf-ike-grp-modp-1536", 1536);
}
-
-DEFINE_TEST(dh_default_2048)
+static void
+test_dh_default_2048 (void)
{
- test_dh_default ("ietf-ike-grp-modp-2048", 2048);
+ check_dh_default ("ietf-ike-grp-modp-2048", 2048);
}
-DEFINE_TEST(dh_default_3072)
+static void
+test_dh_default_3072 (void)
{
- test_dh_default ("ietf-ike-grp-modp-3072", 3072);
+ check_dh_default ("ietf-ike-grp-modp-3072", 3072);
}
-DEFINE_TEST(dh_default_4096)
+static void
+test_dh_default_4096 (void)
{
- test_dh_default ("ietf-ike-grp-modp-4096", 4096);
+ check_dh_default ("ietf-ike-grp-modp-4096", 4096);
}
-DEFINE_TEST(dh_default_8192)
+static void
+test_dh_default_8192 (void)
{
- test_dh_default ("ietf-ike-grp-modp-8192", 8192);
+ check_dh_default ("ietf-ike-grp-modp-8192", 8192);
}
-DEFINE_TEST(dh_default_bad)
+static void
+test_dh_default_bad (void)
{
gboolean ret;
gcry_mpi_t p, g;
@@ -170,3 +183,22 @@ DEFINE_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_dh_perform);
+ g_test_add_func ("/dh/short-pair", test_dh_short_pair);
+ g_test_add_func ("/dh/default-768", test_dh_default_768);
+ g_test_add_func ("/dh/default-1024", test_dh_default_1024);
+ g_test_add_func ("/dh/default-1536", test_dh_default_1536);
+ g_test_add_func ("/dh/default-2048", test_dh_default_2048);
+ g_test_add_func ("/dh/default-3072", test_dh_default_3072);
+ g_test_add_func ("/dh/default-4096", test_dh_default_4096);
+ g_test_add_func ("/dh/default-8192", test_dh_default_8192);
+ g_test_add_func ("/dh/default-bad", test_dh_default_bad);
+
+ return g_test_run ();
+}
diff --git a/egg/tests/unit-test-secmem.c b/egg/tests/test-secmem.c
similarity index 86%
rename from egg/tests/unit-test-secmem.c
rename to egg/tests/test-secmem.c
index 32e6813..f908f19 100644
--- a/egg/tests/unit-test-secmem.c
+++ b/egg/tests/test-secmem.c
@@ -21,13 +21,17 @@
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 "run-auto-test.h"
-
-#include "egg/egg-secure-memory.h"
+EGG_SECURE_GLIB_DEFINITIONS ();
/* Declared in egg-secure-memory.c */
extern int egg_secure_warnings;
@@ -58,7 +62,8 @@ find_non_zero (gpointer mem, gsize len)
return G_MAXSIZE;
}
-DEFINE_TEST(secmem_alloc_free)
+static void
+test_alloc_free (void)
{
gpointer p;
gboolean ret;
@@ -75,7 +80,8 @@ DEFINE_TEST(secmem_alloc_free)
egg_secure_free_full (p, 0);
}
-DEFINE_TEST(secmem_realloc_across)
+static void
+test_realloc_across (void)
{
gpointer p, p2;
@@ -90,7 +96,8 @@ DEFINE_TEST(secmem_realloc_across)
g_assert_cmpint (G_MAXSIZE, ==, find_non_zero (p2, 16200));
}
-DEFINE_TEST(secmem_alloc_two)
+static void
+test_alloc_two (void)
{
gpointer p, p2;
gboolean ret;
@@ -114,7 +121,8 @@ DEFINE_TEST(secmem_alloc_two)
egg_secure_free_full (p, 0);
}
-DEFINE_TEST(secmem_realloc)
+static void
+test_realloc (void)
{
gchar *str = "a test string to see if realloc works properly";
gpointer p, p2;
@@ -138,7 +146,8 @@ DEFINE_TEST(secmem_realloc)
g_assert (p == NULL);
}
-DEFINE_TEST(secmem_multialloc)
+static void
+test_multialloc (void)
{
GPtrArray *memory;
gpointer data;
@@ -205,7 +214,8 @@ DEFINE_TEST(secmem_multialloc)
egg_secure_warnings = 1;
}
-DEFINE_TEST(secmem_clear)
+static void
+test_clear (void)
{
gpointer p;
@@ -220,7 +230,8 @@ DEFINE_TEST(secmem_clear)
egg_secure_free_full (p, 0);
}
-DEFINE_TEST(secmem_strclear)
+static void
+test_strclear (void)
{
gchar *str;
@@ -235,3 +246,19 @@ DEFINE_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 ();
+}
diff --git a/library/Makefile.am b/library/Makefile.am
index 68f53a6..7575601 100644
--- a/library/Makefile.am
+++ b/library/Makefile.am
@@ -10,7 +10,6 @@ INCLUDES= \
-I$(top_srcdir) \
-I$(top_builddir) \
$(LIBRARY_CFLAGS) \
- $(GLIB_CFLAGS) \
$(LIBGCRYPT_CFLAGS)
libgnome_keyring_la_SOURCES = \
@@ -34,7 +33,6 @@ libgnomekeyringinclude_HEADERS = \
libgnome_keyring_la_LIBADD = \
$(top_builddir)/egg/libegg.la \
$(LIBRARY_LIBS) \
- $(GLIB_LIBS) \
$(LIBGCRYPT_LIBS)
libgnome_keyring_la_LDFLAGS = \
diff --git a/library/tests/Makefile.am b/library/tests/Makefile.am
index 0a54cc7..00d3ed5 100644
--- a/library/tests/Makefile.am
+++ b/library/tests/Makefile.am
@@ -1,26 +1,27 @@
-TEST_AUTO = \
- test-memory.c \
- test-keyrings.c \
- test-other.c
+INCLUDES = \
+ -I$(top_srcdir)/library \
+ $(LIBRARY_CFLAGS)
-TEST_LIBS = \
+LDADD = \
$(top_builddir)/egg/libegg.la \
- $(top_builddir)/library/libgnome-keyring.la
-
-include $(top_srcdir)/tests/gtest.make
+ $(top_builddir)/library/libgnome-keyring.la \
+ $(LIBRARY_LIBS)
-# ------------------------------------------------------------------
+TEST_PROGS = \
+ test-memory \
+ test-keyrings \
+ test-other
-noinst_PROGRAMS += \
- test-prompting
+check_PROGRAMS = \
+ test-prompting \
+ $(TEST_PROGS)
-test_prompting_SOURCES = \
- test-prompting.c
+test: $(TEST_PROGS)
+ gtester -k --verbose $(TEST_PROGS)
-test_prompting_CFLAGS = \
- $(GLIB_CFLAGS)
+if WITH_TESTS
+all-local: $(check_PROGRAMS)
+endif
-test_prompting_LDADD = \
- $(top_builddir)/library/libgnome-keyring.la \
- $(GLIB_LIBS)
+check-local: test
diff --git a/library/tests/test-keyrings.c b/library/tests/test-keyrings.c
index 433f929..d5ac7aa 100644
--- a/library/tests/test-keyrings.c
+++ b/library/tests/test-keyrings.c
@@ -21,14 +21,16 @@
Author: Stef Walter <stef memberwebs com>
*/
+#include "config.h"
+
+#include "gnome-keyring.h"
+#include <glib.h>
+
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
-
-#include "run-auto-test.h"
-
-#include "library/gnome-keyring.h"
+#include <unistd.h>
static GList* keyrings = NULL;
@@ -38,7 +40,29 @@ static GList* keyrings = NULL;
#define DISPLAY_NAME "Item Display Name"
#define SECRET "item-secret"
-DEFINE_TEST(remove_incomplete)
+static GMainLoop *mainloop = NULL;
+
+static gboolean
+quit_loop (gpointer data)
+{
+ g_main_loop_quit (data);
+ return TRUE;
+}
+
+static void
+mainloop_run (int timeout)
+{
+ guint id = 0;
+
+ if (timeout)
+ id = g_timeout_add (timeout, quit_loop, mainloop);
+ g_main_loop_run (mainloop);
+ if (timeout)
+ g_source_remove (id);
+}
+
+static void
+test_remove_incomplete (void)
{
GnomeKeyringResult res;
@@ -47,7 +71,8 @@ DEFINE_TEST(remove_incomplete)
g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
}
-DEFINE_TEST(create_keyring)
+static void
+test_create_keyring (void)
{
GnomeKeyringResult res;
@@ -55,7 +80,8 @@ DEFINE_TEST(create_keyring)
g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
}
-DEFINE_TEST(create_keyring_already_exists)
+static void
+test_create_keyring_already_exists (void)
{
GnomeKeyringResult res;
@@ -64,7 +90,8 @@ DEFINE_TEST(create_keyring_already_exists)
g_assert_cmpint (GNOME_KEYRING_RESULT_ALREADY_EXISTS, ==, res);
}
-DEFINE_TEST(set_default_keyring)
+static void
+test_set_default_keyring (void)
{
GnomeKeyringResult res;
gchar* name;
@@ -81,7 +108,8 @@ DEFINE_TEST(set_default_keyring)
g_assert_cmpstr (name, ==, KEYRING_NAME);
}
-DEFINE_TEST(delete_keyring)
+static void
+test_delete_keyring (void)
{
GnomeKeyringResult res;
gchar* name;
@@ -98,7 +126,8 @@ DEFINE_TEST(delete_keyring)
g_assert(name == NULL || strcmp (name, KEYRING_NAME) != 0);
}
-DEFINE_TEST(recreate_keyring)
+static void
+test_recreate_keyring (void)
{
GnomeKeyringResult res;
@@ -117,7 +146,8 @@ compare_ids (gconstpointer a, gconstpointer b)
return a == b ? 0 : 1;
}
-DEFINE_TEST(create_list_items)
+static void
+test_create_list_items (void)
{
GnomeKeyringResult res;
guint id, id2, id3;
@@ -203,7 +233,8 @@ DEFINE_TEST(create_list_items)
g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
}
-DEFINE_TEST(find_keyrings)
+static void
+test_find_keyrings (void)
{
GnomeKeyringResult res;
GnomeKeyringAttributeList* attrs;
@@ -268,7 +299,8 @@ DEFINE_TEST(find_keyrings)
* A find that does not match should return 'Not Found':
* http://bugzilla.gnome.org/show_bug.cgi?id=476682
*/
-DEFINE_TEST(find_invalid)
+static void
+test_find_invalid (void)
{
GnomeKeyringResult res;
GnomeKeyringAttributeList* attrs;
@@ -282,7 +314,8 @@ DEFINE_TEST(find_invalid)
g_assert_cmpint (GNOME_KEYRING_RESULT_NO_MATCH, ==, res);
}
-DEFINE_TEST(lock_keyrings)
+static void
+test_lock_keyrings (void)
{
GnomeKeyringResult res;
@@ -300,7 +333,8 @@ DEFINE_TEST(lock_keyrings)
g_assert_cmpint (GNOME_KEYRING_RESULT_NO_SUCH_KEYRING, ==, res);
}
-DEFINE_TEST(change_password)
+static void
+test_change_password (void)
{
GnomeKeyringResult res;
@@ -308,7 +342,8 @@ DEFINE_TEST(change_password)
g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
}
-DEFINE_TEST(keyring_info)
+static void
+test_keyring_info (void)
{
GnomeKeyringResult res;
GnomeKeyringInfo *info;
@@ -320,7 +355,8 @@ DEFINE_TEST(keyring_info)
g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
}
-DEFINE_TEST(list_keyrings)
+static void
+test_list_keyrings (void)
{
GnomeKeyringResult res;
GList *l;
@@ -339,10 +375,11 @@ static void
done_grant_access (GnomeKeyringResult res, gpointer data)
{
grant_access_result = res;
- test_mainloop_quit ();
+ g_main_loop_quit (mainloop);
}
-DEFINE_TEST(keyring_grant_access)
+static void
+test_keyring_grant_access (void)
{
GList *acl;
GnomeKeyringResult res;
@@ -365,7 +402,7 @@ DEFINE_TEST(keyring_grant_access)
/* "callback already called" */
g_assert_cmpint (grant_access_result, ==, GNOME_KEYRING_RESULT_CANCELLED);
- test_mainloop_run (2000);
+ mainloop_run (2000);
g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, grant_access_result);
@@ -393,10 +430,11 @@ static void
done_store_password (GnomeKeyringResult res, gpointer data)
{
*((GnomeKeyringResult*)data) = res;
- test_mainloop_quit ();
+ g_main_loop_quit (mainloop);
}
-DEFINE_TEST(store_password)
+static void
+test_store_password (void)
{
GnomeKeyringResult res;
gpointer op;
@@ -428,7 +466,7 @@ DEFINE_TEST(store_password)
/* "callback already called" */
g_assert_cmpint (res, ==, GNOME_KEYRING_RESULT_CANCELLED);
- test_mainloop_run (2000);
+ mainloop_run (2000);
g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
}
@@ -447,10 +485,11 @@ done_find_password (GnomeKeyringResult res, const gchar* password, gpointer unus
g_assert_cmpstr (password, ==, "password");
}
- test_mainloop_quit ();
+ g_main_loop_quit (mainloop);
}
-DEFINE_TEST(find_password)
+static void
+test_find_password (void)
{
GnomeKeyringResult res;
gchar *password;
@@ -484,7 +523,7 @@ DEFINE_TEST(find_password)
/* "callback already called" */
g_assert (find_password_result == GNOME_KEYRING_RESULT_CANCELLED);
- test_mainloop_run (2000);
+ mainloop_run (2000);
g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, find_password_result);
}
@@ -496,10 +535,11 @@ done_find_no_password (GnomeKeyringResult res, const gchar* password, gpointer u
{
find_no_password_result = res;
g_assert (password == NULL);
- test_mainloop_quit ();
+ g_main_loop_quit (mainloop);
}
-DEFINE_TEST(find_no_password)
+static void
+test_find_no_password (void)
{
GnomeKeyringResult res;
gchar *password = NULL;
@@ -523,7 +563,7 @@ DEFINE_TEST(find_no_password)
g_assert (op != NULL);
g_assert (find_no_password_result == GNOME_KEYRING_RESULT_CANCELLED);
- test_mainloop_run (2000);
+ mainloop_run (2000);
g_assert_cmpint (GNOME_KEYRING_RESULT_NO_MATCH, ==, find_no_password_result);
}
@@ -532,10 +572,11 @@ static void
done_delete_password (GnomeKeyringResult res, gpointer data)
{
*((GnomeKeyringResult*)data) = res;
- test_mainloop_quit ();
+ g_main_loop_quit (mainloop);
}
-DEFINE_TEST(delete_password)
+static void
+test_delete_password (void)
{
GnomeKeyringResult res;
gpointer op;
@@ -562,16 +603,151 @@ DEFINE_TEST(delete_password)
/* "callback already called" */
g_assert (res == GNOME_KEYRING_RESULT_CANCELLED);
- test_mainloop_run (2000);
+ mainloop_run (2000);
/* Should have already been deleted by the second call above */
g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
}
-DEFINE_TEST(cleanup)
+static void
+test_cleanup (void)
{
GnomeKeyringResult res;
res = gnome_keyring_delete_sync (KEYRING_NAME);
g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
}
+
+static void
+test_set_display (void)
+{
+ GnomeKeyringResult res;
+
+ /* Deprecated method */
+ res = gnome_keyring_daemon_set_display_sync (":0.0");
+ g_assert_cmpint (GNOME_KEYRING_RESULT_DENIED, ==, res);
+}
+
+static void
+test_setup_environment (void)
+{
+ GnomeKeyringResult res;
+
+ res = gnome_keyring_daemon_prepare_environment_sync ();
+ g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
+}
+
+static pid_t daemon_pid = 0;
+
+static gboolean
+daemon_start (void)
+{
+ GError *err = NULL;
+ gchar *args[5];
+ const gchar *path, *service, *address;
+ gchar *output = NULL;
+ gint exit_status = 1;
+ GError *error = NULL;
+
+ /* Need to have DBUS running */
+ address = g_getenv ("DBUS_SESSION_BUS_ADDRESS");
+ if (!address || !address[0]) {
+ g_printerr ("\nNo DBUS session available, skipping tests!\n\n");
+ return FALSE;
+ }
+
+ /* Check if gnome-keyring-daemon has testing enabled */
+ if (!g_spawn_command_line_sync (GNOME_KEYRING_DAEMON_PATH " --version",
+ &output, NULL, &exit_status, &error)) {
+ g_printerr ("Couldn't launch '%s': %s", GNOME_KEYRING_DAEMON_PATH,
+ error->message);
+ return FALSE;
+ }
+
+ /* For some reason --version failed */
+ if (exit_status != 0 || strstr (output, "testing: enabled") == NULL) {
+ g_printerr ("Skipping tests since no testing enabled gnome-keyring-daemin is available\n");
+ g_free (output);
+ return FALSE;
+ }
+
+ g_free (output);
+
+ path = g_getenv ("GNOME_KEYRING_TEST_PATH");
+ if (path && !path[0])
+ path = NULL;
+
+ service = g_getenv ("GNOME_KEYRING_TEST_SERVICE");
+ if (service && !service[0])
+ service = NULL;
+
+ if (!path && !service) {
+ g_mkdir_with_parents ("/tmp/keyring-test/data", 0700);
+ g_setenv ("GNOME_KEYRING_TEST_PATH", "/tmp/keyring-test/data", TRUE);
+ g_setenv ("GNOME_KEYRING_TEST_SERVICE", "org.gnome.keyring.Test", TRUE);
+
+ g_printerr ("Starting gnome-keyring-daemon...\n");
+
+ args[0] = GNOME_KEYRING_DAEMON_PATH;
+ args[1] = "--foreground";
+ args[2] = "--control-directory";
+ args[3] = "/tmp/keyring-test";
+ args[4] = NULL;
+
+ if (!g_spawn_async (NULL, args, NULL, G_SPAWN_LEAVE_DESCRIPTORS_OPEN | G_SPAWN_DO_NOT_REAP_CHILD,
+ NULL, NULL, &daemon_pid, &err)) {
+ g_error ("couldn't start gnome-keyring-daemon for testing: %s",
+ err && err->message ? err->message : "");
+ g_assert_not_reached ();
+ }
+
+ /* Let it startup properly */
+ sleep (2);
+ }
+
+ return TRUE;
+}
+
+static void
+daemon_stop (void)
+{
+ if (daemon_pid)
+ kill (daemon_pid, SIGTERM);
+ daemon_pid = 0;
+}
+
+int
+main (int argc, char **argv)
+{
+ g_test_init (&argc, &argv, NULL);
+
+ mainloop = g_main_loop_new (NULL, FALSE);
+
+ if (daemon_start ()) {
+ g_test_add_func ("/keyrings/remove-incomplete", test_remove_incomplete);
+ g_test_add_func ("/keyrings/create-keyring", test_create_keyring);
+ g_test_add_func ("/keyrings/create-keyring-already-exists", test_create_keyring_already_exists);
+ g_test_add_func ("/keyrings/set-default-keyring", test_set_default_keyring);
+ g_test_add_func ("/keyrings/delete-keyring", test_delete_keyring);
+ g_test_add_func ("/keyrings/recreate-keyring", test_recreate_keyring);
+ g_test_add_func ("/keyrings/create-list-items", test_create_list_items);
+ g_test_add_func ("/keyrings/find-keyrings", test_find_keyrings);
+ g_test_add_func ("/keyrings/find-invalid", test_find_invalid);
+ g_test_add_func ("/keyrings/lock-keyrings", test_lock_keyrings);
+ g_test_add_func ("/keyrings/change-password", test_change_password);
+ g_test_add_func ("/keyrings/keyring-info", test_keyring_info);
+ g_test_add_func ("/keyrings/list-keyrings", test_list_keyrings);
+ g_test_add_func ("/keyrings/keyring-grant-access", test_keyring_grant_access);
+ g_test_add_func ("/keyrings/store-password", test_store_password);
+ g_test_add_func ("/keyrings/find-password", test_find_password);
+ g_test_add_func ("/keyrings/find-no-password", test_find_no_password);
+ g_test_add_func ("/keyrings/delete-password", test_delete_password);
+ g_test_add_func ("/keyrings/cleanup", test_cleanup);
+ g_test_add_func ("/keyrings/set-display", test_set_display);
+ g_test_add_func ("/keyrings/setup-environment", test_setup_environment);
+
+ daemon_stop ();
+ }
+
+ return g_test_run ();
+}
diff --git a/library/tests/test-memory.c b/library/tests/test-memory.c
index 7cc01b7..2b12f41 100644
--- a/library/tests/test-memory.c
+++ b/library/tests/test-memory.c
@@ -21,14 +21,16 @@
Author: Stef Walter <stef memberwebs com>
*/
+#include "config.h"
+
+#include "gnome-keyring-memory.h"
+
+#include <glib.h>
+
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-#include "run-auto-test.h"
-
-#include "library/gnome-keyring-memory.h"
-
#define IS_ZERO -1
static int
@@ -44,7 +46,8 @@ find_non_zero (gpointer mem, gsize len)
return -1;
}
-DEFINE_TEST(alloc_free)
+static void
+test_alloc_free (void)
{
gpointer p;
gboolean ret;
@@ -61,7 +64,8 @@ DEFINE_TEST(alloc_free)
gnome_keyring_memory_free (p);
}
-DEFINE_TEST(alloc_two)
+static void
+test_alloc_two (void)
{
gpointer p, p2;
gboolean ret;
@@ -85,7 +89,8 @@ DEFINE_TEST(alloc_two)
gnome_keyring_memory_free (p);
}
-DEFINE_TEST(realloc)
+static void
+test_realloc (void)
{
gchar *str = "a test string to see if realloc works properly";
gpointer p, p2;
@@ -110,7 +115,8 @@ DEFINE_TEST(realloc)
g_assert (p == NULL);
}
-DEFINE_TEST(realloc_across)
+static void
+test_realloc_across (void)
{
gpointer p, p2;
@@ -126,3 +132,16 @@ DEFINE_TEST(realloc_across)
gnome_keyring_memory_free (p2);
}
+
+int
+main (int argc, char **argv)
+{
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add_func ("/memory/alloc-free", test_alloc_free);
+ g_test_add_func ("/memory/alloc-two", test_alloc_two);
+ g_test_add_func ("/memory/realloc", test_realloc);
+ g_test_add_func ("/memory/realloc-across", test_realloc_across);
+
+ return g_test_run ();
+}
diff --git a/library/tests/test-other.c b/library/tests/test-other.c
index 0324af3..f95bcd3 100644
--- a/library/tests/test-other.c
+++ b/library/tests/test-other.c
@@ -21,32 +21,18 @@
Author: Stef Walter <stef memberwebs com>
*/
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "run-auto-test.h"
-
-#include "library/gnome-keyring.h"
-
-DEFINE_TEST(set_display)
-{
- GnomeKeyringResult res;
+#include "config.h"
- /* Deprecated method */
- res = gnome_keyring_daemon_set_display_sync (":0.0");
- g_assert_cmpint (GNOME_KEYRING_RESULT_DENIED, ==, res);
-}
+#include "gnome-keyring.h"
-DEFINE_TEST(setup_environment)
-{
- GnomeKeyringResult res;
+#include <glib.h>
- res = gnome_keyring_daemon_prepare_environment_sync ();
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-}
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
-DEFINE_TEST(result_string)
+static void
+test_result_string (void)
{
const gchar *msg;
@@ -83,11 +69,12 @@ DEFINE_TEST(result_string)
g_assert (msg && msg[0]);
}
-DEFINE_TEST(is_available)
+int
+main (int argc, char **argv)
{
- gboolean ret;
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add_func ("/other/result-string", test_result_string);
- ret = gnome_keyring_is_available ();
- /* "gnome_keyring_is_available returned false" */
- g_assert (ret == TRUE);
+ return g_test_run ();
}
diff --git a/library/tests/test-prompting.c b/library/tests/test-prompting.c
index bfba694..9ab23e3 100644
--- a/library/tests/test-prompting.c
+++ b/library/tests/test-prompting.c
@@ -1,5 +1,5 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* unit-test-other.c: Test some prompts
+/* test-prompting.c: Test some prompts
Copyright (C) 2010 Stefan Walter
@@ -22,6 +22,7 @@
*/
#include "config.h"
+
#include "gnome-keyring.h"
#include <glib.h>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]