[evolution-data-server] Add a test for e_book.*_remove()
- From: Travis Reitter <treitter src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [evolution-data-server] Add a test for e_book.*_remove()
- Date: Fri, 15 Jan 2010 21:52:46 +0000 (UTC)
commit a7d8bba0bc4aaad0e8e6cca1145e5f37f026af17
Author: Travis Reitter <treitter gmail com>
Date: Wed Dec 2 15:25:49 2009 -0800
Add a test for e_book.*_remove()
addressbook/tests/ebook/Makefile.am | 4 +-
addressbook/tests/ebook/test-book-remove.c | 97 ++++++++++++++++++++++++++++
2 files changed, 100 insertions(+), 1 deletions(-)
---
diff --git a/addressbook/tests/ebook/Makefile.am b/addressbook/tests/ebook/Makefile.am
index ff6dcce..76597f2 100644
--- a/addressbook/tests/ebook/Makefile.am
+++ b/addressbook/tests/ebook/Makefile.am
@@ -2,7 +2,7 @@ TEST_LIBS= \
$(top_builddir)/addressbook/libebook/libebook-1.2.la \
$(EVOLUTION_ADDRESSBOOK_LIBS)
-noinst_PROGRAMS= test-changes test-categories test-date test-ebook test-ebook-async 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-book-remove test-changes test-categories test-date test-ebook test-ebook-async test-ebook-view test-nonexistent-id test-photo test-query test-self test-string test-undefinedfield test-untyped-phones test-search test-stress-bookviews
TEST_CPPFLAGS= \
$(AM_CPPFLAGS) \
@@ -12,6 +12,8 @@ TEST_CPPFLAGS= \
-I$(top_builddir)/addressbook \
$(EVOLUTION_ADDRESSBOOK_CFLAGS)
+test_book_remove_LDADD=$(TEST_LIBS)
+test_book_remove_CPPFLAGS=$(TEST_CPPFLAGS)
test_search_LDADD=$(TEST_LIBS)
test_search_CPPFLAGS=$(TEST_CPPFLAGS)
test_date_LDADD=$(TEST_LIBS)
diff --git a/addressbook/tests/ebook/test-book-remove.c b/addressbook/tests/ebook/test-book-remove.c
new file mode 100644
index 0000000..b9fea7a
--- /dev/null
+++ b/addressbook/tests/ebook/test-book-remove.c
@@ -0,0 +1,97 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+#include <stdlib.h>
+#include <libebook/e-book.h>
+
+static GMainLoop *loop;
+
+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 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;
+
+ g_type_init ();
+
+ /* Sync version */
+ book = create_test_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);
+
+ /* Async version */
+ book = create_test_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);
+ }
+
+ loop = g_main_loop_new (NULL, TRUE);
+ g_main_loop_run (loop);
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]