[evolution-data-server/treitter-test-suites] Begin factoring out ebook test functions
- From: Travis Reitter <treitter src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [evolution-data-server/treitter-test-suites] Begin factoring out ebook test functions
- Date: Wed, 30 Dec 2009 00:54:46 +0000 (UTC)
commit 512c7c9fcbc0fda52c10577356dad598f80539af
Author: Travis Reitter <treitter gmail com>
Date: Thu Dec 3 09:03:18 2009 -0800
Begin factoring out ebook test functions
addressbook/tests/ebook/Makefile.am | 50 ++++++++++++++++++++++-----
addressbook/tests/ebook/ebook-test-utils.c | 38 ++++++++++++++++++++
addressbook/tests/ebook/ebook-test-utils.h | 29 +++++++++++++++
addressbook/tests/ebook/test-changes.c | 25 ++------------
addressbook/tests/ebook/test-ebook-remove.c | 38 ++------------------
5 files changed, 115 insertions(+), 65 deletions(-)
---
diff --git a/addressbook/tests/ebook/Makefile.am b/addressbook/tests/ebook/Makefile.am
index edf55df..b0b95dc 100644
--- a/addressbook/tests/ebook/Makefile.am
+++ b/addressbook/tests/ebook/Makefile.am
@@ -1,16 +1,48 @@
-TEST_LIBS= \
+noinst_LTLIBRARIES = libebook-test-utils.la
+libebook_test_utils_la_SOURCES = ebook-test-utils.c ebook-test-utils.h
+
+# FIXME: reduct redundancy
+libebook_test_utils_la_CPPFLAGS = \
+ $(AM_CPPFLAGS) \
+ -I$(top_srcdir) \
+ -I$(top_builddir) \
+ -I$(top_srcdir)/addressbook \
+ -I$(top_builddir)/addressbook \
+ $(EVOLUTION_ADDRESSBOOK_CFLAGS) \
+ $(NULL)
+
+libebook_test_utils_la_LIBADD = \
$(top_builddir)/addressbook/libebook/libebook-1.2.la \
- $(EVOLUTION_ADDRESSBOOK_LIBS)
+ $(EVOLUTION_ADDRESSBOOK_LIBS) \
+ $(NULL)
+
+TEST_LIBS = \
+ $(libebook_test_utils_la_LIBADD) \
+ libebook-test-utils.la \
+ $(NULL)
-noinst_PROGRAMS = test-changes test-categories test-date test-ebook test-ebook-async test-ebook-remove test-ebook-view test-nonexistent-id test-photo test-query test-self test-string test-undefinedfield test-untyped-phones test-search test-stress-bookviews
+noinst_PROGRAMS = \
+ test-changes \
+ test-categories \
+ test-date \
+ test-ebook \
+ test-ebook-async \
+ test-ebook-remove \
+ test-ebook-view \
+ test-nonexistent-id \
+ test-photo \
+ test-query \
+ test-self \
+ test-string \
+ test-undefinedfield \
+ test-untyped-phones \
+ test-search \
+ test-stress-bookviews \
+ $(NULL)
TEST_CPPFLAGS= \
- $(AM_CPPFLAGS) \
- -I$(top_srcdir) \
- -I$(top_builddir) \
- -I$(top_srcdir)/addressbook \
- -I$(top_builddir)/addressbook \
- $(EVOLUTION_ADDRESSBOOK_CFLAGS)
+ $(libebook_test_utils_la_CPPFLAGS) \
+ $(NULL)
test_search_LDADD=$(TEST_LIBS)
test_search_CPPFLAGS=$(TEST_CPPFLAGS)
diff --git a/addressbook/tests/ebook/ebook-test-utils.c b/addressbook/tests/ebook/ebook-test-utils.c
new file mode 100644
index 0000000..d3c10a1
--- /dev/null
+++ b/addressbook/tests/ebook/ebook-test-utils.c
@@ -0,0 +1,38 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+#include <stdlib.h>
+#include <libebook/e-book.h>
+
+#include "ebook-test-utils.h"
+
+EBook*
+ebook_test_utils_create_temp_addressbook (char **uri)
+{
+ EBook *book;
+ GError *error = NULL;
+ gchar *file_template;
+
+ file_template = g_build_filename (g_get_tmp_dir (),
+ "ebook-test-XXXXXX/",
+ NULL);
+ g_mkstemp (file_template);
+
+ *uri = g_filename_to_uri (file_template, NULL, &error);
+ if (!*uri) {
+ printf ("failed to convert %s to an URI: %s\n",
+ file_template, error->message);
+ exit (1);
+ }
+ g_free (file_template);
+
+ /* create a temp addressbook in /tmp */
+ printf ("loading addressbook\n");
+ book = e_book_new_from_uri (*uri, &error);
+ if (!book) {
+ printf ("failed to create addressbook: `%s': %s\n",
+ *uri, error->message);
+ exit(1);
+ }
+
+ return book;
+}
diff --git a/addressbook/tests/ebook/ebook-test-utils.h b/addressbook/tests/ebook/ebook-test-utils.h
new file mode 100644
index 0000000..d1e8daa
--- /dev/null
+++ b/addressbook/tests/ebook/ebook-test-utils.h
@@ -0,0 +1,29 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2009 Intel Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU Lesser General Public
+ * License as published by the Free Software Foundation.
+ *
+ * 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * Author: Travis Reitter (travis reitter collabora co uk)
+ */
+
+#ifndef _EBOOK_TEST_UTILS_H
+#define _EBOOK_TEST_UTILS_H
+
+#include <libebook/e-book.h>
+
+EBook* ebook_test_utils_create_temp_addressbook (char **uri);
+
+#endif /* _EBOOK_TEST_UTILS_H */
diff --git a/addressbook/tests/ebook/test-changes.c b/addressbook/tests/ebook/test-changes.c
index e5a339e..0836e38 100644
--- a/addressbook/tests/ebook/test-changes.c
+++ b/addressbook/tests/ebook/test-changes.c
@@ -3,6 +3,8 @@
#include <stdlib.h>
#include <libebook/e-book.h>
+#include "ebook-test-utils.h"
+
#define NEW_VCARD "BEGIN:VCARD\n\
X-EVOLUTION-FILE-AS:Toshok, Chris\n\
FN:Chris Toshok\n\
@@ -18,32 +20,11 @@ main (gint argc, gchar **argv)
GList *changes;
GError *error = NULL;
EBookChange *change;
- gchar *file_template;
gchar *uri;
g_type_init ();
- file_template = g_build_filename (g_get_tmp_dir (),
- "change-test-XXXXXX",
- NULL);
- g_mkstemp (file_template);
-
- uri = g_filename_to_uri (file_template, NULL, &error);
- if (!uri) {
- printf ("failed to convert %s to an URI: %s\n",
- file_template, error->message);
- exit (0);
- }
- g_free (file_template);
-
- /* create a temp addressbook in /tmp */
- printf ("loading addressbook\n");
- book = e_book_new_from_uri (uri, &error);
- if (!book) {
- printf ("failed to create addressbook: `%s': %s\n",
- uri, error->message);
- exit(0);
- }
+ book = ebook_test_utils_create_temp_addressbook (&uri);
if (!e_book_open (book, FALSE, &error)) {
printf ("failed to open addressbook: `%s': %s\n",
diff --git a/addressbook/tests/ebook/test-ebook-remove.c b/addressbook/tests/ebook/test-ebook-remove.c
index b9fea7a..ebe5120 100644
--- a/addressbook/tests/ebook/test-ebook-remove.c
+++ b/addressbook/tests/ebook/test-ebook-remove.c
@@ -3,39 +3,9 @@
#include <stdlib.h>
#include <libebook/e-book.h>
-static GMainLoop *loop;
+#include "ebook-test-utils.h"
-static EBook*
-create_test_addressbook (char **uri)
-{
- EBook *book;
- GError *error = NULL;
- gchar *file_template;
-
- file_template = g_build_filename (g_get_tmp_dir (),
- "change-test-XXXXXX/",
- NULL);
- g_mkstemp (file_template);
-
- *uri = g_filename_to_uri (file_template, NULL, &error);
- if (!*uri) {
- printf ("failed to convert %s to an URI: %s\n",
- file_template, error->message);
- exit (1);
- }
- g_free (file_template);
-
- /* create a temp addressbook in /tmp */
- printf ("loading addressbook\n");
- book = e_book_new_from_uri (*uri, &error);
- if (!book) {
- printf ("failed to create addressbook: `%s': %s\n",
- *uri, error->message);
- exit(1);
- }
-
- return book;
-}
+static GMainLoop *loop;
static void
remove_cb (EBook *book, EBookStatus status, gpointer closure)
@@ -60,7 +30,7 @@ main (gint argc, gchar **argv)
g_type_init ();
/* Sync version */
- book = create_test_addressbook (&uri);
+ book = ebook_test_utils_create_temp_addressbook (&uri);
if (!e_book_open (book, FALSE, &error)) {
printf ("failed to open addressbook: `%s': %s\n",
@@ -77,7 +47,7 @@ main (gint argc, gchar **argv)
g_object_unref (book);
/* Async version */
- book = create_test_addressbook (&uri);
+ book = ebook_test_utils_create_temp_addressbook (&uri);
if (!e_book_open (book, FALSE, &error)) {
printf ("failed to open addressbook: `%s': %s\n",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]