[evolution-data-server] Additional test factoring
- From: Travis Reitter <treitter src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [evolution-data-server] Additional test factoring
- Date: Fri, 15 Jan 2010 21:53:01 +0000 (UTC)
commit 74e42eef820228220e380edc1e0546badf8660a5
Author: Travis Reitter <treitter gmail com>
Date: Tue Dec 29 12:26:54 2009 -0800
Additional test factoring
addressbook/tests/ebook/ebook-test-utils.c | 79 ++++++++++++++++++++++++---
addressbook/tests/ebook/ebook-test-utils.h | 12 ++++-
addressbook/tests/ebook/test-changes.c | 16 +-----
addressbook/tests/ebook/test-ebook-remove.c | 52 +++---------------
addressbook/tests/ebook/test-ebook.c | 9 +--
5 files changed, 96 insertions(+), 72 deletions(-)
---
diff --git a/addressbook/tests/ebook/ebook-test-utils.c b/addressbook/tests/ebook/ebook-test-utils.c
index d3c10a1..7ecba11 100644
--- a/addressbook/tests/ebook/ebook-test-utils.c
+++ b/addressbook/tests/ebook/ebook-test-utils.c
@@ -6,33 +6,94 @@
#include "ebook-test-utils.h"
EBook*
-ebook_test_utils_create_temp_addressbook (char **uri)
+ebook_test_utils_book_new_temp (char **uri)
{
EBook *book;
GError *error = NULL;
gchar *file_template;
- file_template = g_build_filename (g_get_tmp_dir (),
- "ebook-test-XXXXXX/",
- NULL);
+ 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);
+ g_warning ("failed to convert %s to an URI: %s", file_template,
+ error->message);
exit (1);
}
g_free (file_template);
/* create a temp addressbook in /tmp */
- printf ("loading addressbook\n");
+ g_print ("loading addressbook\n");
book = e_book_new_from_uri (*uri, &error);
if (!book) {
- printf ("failed to create addressbook: `%s': %s\n",
- *uri, error->message);
+ g_warning ("failed to create addressbook: `%s': %s", *uri,
+ error->message);
exit(1);
}
return book;
}
+
+void
+ebook_test_utils_book_open (EBook *book,
+ gboolean only_if_exists)
+{
+ GError *error = NULL;
+
+ if (!e_book_open (book, only_if_exists, &error)) {
+ const char *uri;
+
+ uri = e_book_get_uri (book);
+
+ g_warning ("failed to open addressbook: `%s': %s", uri,
+ error->message);
+ exit(1);
+ }
+}
+
+void
+ebook_test_utils_book_remove (EBook *book)
+{
+ GError *error = NULL;
+
+ if (!e_book_remove (book, &error)) {
+ g_warning ("failed to remove book; %s\n", error->message);
+ exit(1);
+ }
+ g_print ("successfully removed the temporary addressbook\n");
+
+ g_object_unref (book);
+}
+
+static void
+remove_cb (EBook *book, EBookStatus status, EBookTestClosure *closure)
+{
+ if (status != E_BOOK_ERROR_OK) {
+ g_warning ("failed to asynchronously remove the book: "
+ "status %d", status);
+ exit (1);
+ }
+
+ g_print ("successfully asynchronously removed the temporary "
+ "addressbook\n");
+ if (closure)
+ (*closure->cb) (closure->user_data);
+}
+
+void
+ebook_test_utils_book_async_remove (EBook *book,
+ GSourceFunc callback,
+ gpointer user_data)
+{
+ EBookTestClosure *closure;
+
+ closure = g_new0 (EBookTestClosure, 1);
+ closure->cb = callback;
+ closure->user_data = user_data;
+ if (e_book_async_remove (book, (EBookCallback) remove_cb, closure)) {
+ g_warning ("failed to set up book removal");
+ exit(1);
+ }
+}
diff --git a/addressbook/tests/ebook/ebook-test-utils.h b/addressbook/tests/ebook/ebook-test-utils.h
index d1e8daa..282c1c9 100644
--- a/addressbook/tests/ebook/ebook-test-utils.h
+++ b/addressbook/tests/ebook/ebook-test-utils.h
@@ -24,6 +24,16 @@
#include <libebook/e-book.h>
-EBook* ebook_test_utils_create_temp_addressbook (char **uri);
+typedef struct {
+ GSourceFunc cb;
+ gpointer user_data;
+} EBookTestClosure;
+
+EBook* ebook_test_utils_book_new_temp (char **uri);
+void ebook_test_utils_book_open (EBook *book, gboolean only_if_exists);
+void ebook_test_utils_book_remove (EBook *book);
+void ebook_test_utils_book_async_remove (EBook *book,
+ GSourceFunc callback,
+ gpointer user_data);
#endif /* _EBOOK_TEST_UTILS_H */
diff --git a/addressbook/tests/ebook/test-changes.c b/addressbook/tests/ebook/test-changes.c
index 0836e38..017f4b8 100644
--- a/addressbook/tests/ebook/test-changes.c
+++ b/addressbook/tests/ebook/test-changes.c
@@ -24,13 +24,8 @@ main (gint argc, gchar **argv)
g_type_init ();
- book = ebook_test_utils_create_temp_addressbook (&uri);
-
- if (!e_book_open (book, FALSE, &error)) {
- printf ("failed to open addressbook: `%s': %s\n",
- uri, error->message);
- exit(0);
- }
+ book = ebook_test_utils_book_new_temp (&uri);
+ ebook_test_utils_book_open (book, FALSE);
/* get an initial change set */
if (!e_book_get_changes (book, "changeidtest", &changes, &error)) {
@@ -67,12 +62,7 @@ main (gint argc, gchar **argv)
e_book_free_change_list (changes);
- if (!e_book_remove (book, &error)) {
- printf ("failed to remove book; %s\n", error->message);
- exit(0);
- }
-
- g_object_unref (book);
+ ebook_test_utils_book_remove (book);
return 0;
}
diff --git a/addressbook/tests/ebook/test-ebook-remove.c b/addressbook/tests/ebook/test-ebook-remove.c
index ebe5120..8d5d5c6 100644
--- a/addressbook/tests/ebook/test-ebook-remove.c
+++ b/addressbook/tests/ebook/test-ebook-remove.c
@@ -5,62 +5,28 @@
#include "ebook-test-utils.h"
-static GMainLoop *loop;
-
-static void
-remove_cb (EBook *book, EBookStatus status, gpointer closure)
-{
- if (status != E_BOOK_ERROR_OK) {
- printf ("failed to asynchronously remove the book: status %d\n",
- status);
- exit (1);
- }
-
- printf ("successfully asynchronously removed the temporary addressbook\n");
- g_main_loop_quit (loop);
-}
-
gint
main (gint argc, gchar **argv)
{
EBook *book;
char *uri = NULL;
- GError *error = NULL;
+ GMainLoop *loop;
g_type_init ();
/* Sync version */
- book = ebook_test_utils_create_temp_addressbook (&uri);
-
- if (!e_book_open (book, FALSE, &error)) {
- printf ("failed to open addressbook: `%s': %s\n",
- uri, error->message);
- exit(1);
- }
-
- if (!e_book_remove (book, &error)) {
- printf ("failed to remove book; %s\n", error->message);
- exit(1);
- }
- printf ("successfully removed the temporary addressbook\n");
-
- g_object_unref (book);
+ book = ebook_test_utils_book_new_temp (&uri);
+ ebook_test_utils_book_open (book, FALSE);
+ ebook_test_utils_book_remove (book);
/* Async version */
- book = ebook_test_utils_create_temp_addressbook (&uri);
-
- if (!e_book_open (book, FALSE, &error)) {
- printf ("failed to open addressbook: `%s': %s\n",
- uri, error->message);
- exit(1);
- }
-
- if (e_book_async_remove (book, remove_cb, NULL)) {
- printf ("failed to set up book removal\n");
- exit(1);
- }
+ book = ebook_test_utils_book_new_temp (&uri);
+ ebook_test_utils_book_open (book, FALSE);
loop = g_main_loop_new (NULL, TRUE);
+ ebook_test_utils_book_async_remove (book,
+ (GSourceFunc) g_main_loop_quit, loop);
+
g_main_loop_run (loop);
return 0;
diff --git a/addressbook/tests/ebook/test-ebook.c b/addressbook/tests/ebook/test-ebook.c
index 532d17c..f8d5998 100644
--- a/addressbook/tests/ebook/test-ebook.c
+++ b/addressbook/tests/ebook/test-ebook.c
@@ -3,6 +3,8 @@
#include <stdlib.h>
#include <libebook/e-book.h>
+#include "ebook-test-utils.h"
+
static void
print_email (EContact *contact)
{
@@ -72,7 +74,6 @@ gint
main (gint argc, gchar **argv)
{
EBook *book;
- gboolean status;
g_type_init ();
@@ -87,11 +88,7 @@ main (gint argc, gchar **argv)
exit(0);
}
- status = e_book_open (book, FALSE, NULL);
- if (status == FALSE) {
- printf ("failed to open local addressbook\n");
- exit(0);
- }
+ ebook_test_utils_book_open (book, FALSE);
printf ("printing one contact\n");
print_one_email (book);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]