[evolution-data-server/openismus-work-master] An attempt at getting test-ebook-get-book-view test to pass with EClient apis.
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/openismus-work-master] An attempt at getting test-ebook-get-book-view test to pass with EClient apis.
- Date: Fri, 24 Jun 2011 22:29:42 +0000 (UTC)
commit 9a932179c17a3c839a8581b91919e5ec55f4384c
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date: Fri Jun 24 18:28:40 2011 -0400
An attempt at getting test-ebook-get-book-view test to pass with EClient apis.
tests/libebook/Makefile.am | 6 +-
tests/libebook/ebook-test-utils.c | 196 ++++++++++++++++++++++++++++-
tests/libebook/ebook-test-utils.h | 44 ++++++-
tests/libebook/test-ebook-get-book-view.c | 51 ++++----
4 files changed, 264 insertions(+), 33 deletions(-)
---
diff --git a/tests/libebook/Makefile.am b/tests/libebook/Makefile.am
index d425d8e..c70bae6 100644
--- a/tests/libebook/Makefile.am
+++ b/tests/libebook/Makefile.am
@@ -62,6 +62,7 @@ endif
# Should be kept ordered approximately from least to most difficult/complex
TESTS = \
+ test-ebook-get-book-view \
$(NULL)
# These tests are broken at the moment because the test fixture hacks
@@ -77,6 +78,7 @@ TESTS = \
# test-ebook-add-contact
# test-ebook-get-contact
# test-ebook-get-book-view
+# test-ebook-suppress-initial-notifications
# test-ebook-commit-contact
# test-ebook-remove-contact
# test-ebook-remove-contact-by-id
@@ -130,8 +132,10 @@ test_ebook_async_CPPFLAGS=$(TEST_CPPFLAGS)
test_ebook_add_contact_CPPFLAGS=$(TEST_CPPFLAGS)
#test_ebook_commit_contact_LDADD=$(TEST_LIBS)
test_ebook_commit_contact_CPPFLAGS=$(TEST_CPPFLAGS)
-#test_ebook_get_book_view_LDADD=$(TEST_LIBS)
+test_ebook_get_book_view_LDADD=$(TEST_LIBS)
test_ebook_get_book_view_CPPFLAGS=$(TEST_CPPFLAGS)
+#test_ebook_suppress_initial_notifications_LDADD=$(TEST_LIBS)
+test_ebook_suppress_initial_notifications_CPPFLAGS=$(TEST_CPPFLAGS)
#test_ebook_get_contact_LDADD=$(TEST_LIBS)
test_ebook_get_contact_CPPFLAGS=$(TEST_CPPFLAGS)
#test_ebook_get_required_fields_LDADD=$(TEST_LIBS)
diff --git a/tests/libebook/ebook-test-utils.c b/tests/libebook/ebook-test-utils.c
index 5a24e8c..057df2f 100644
--- a/tests/libebook/ebook-test-utils.c
+++ b/tests/libebook/ebook-test-utils.c
@@ -3,6 +3,7 @@
#include <stdlib.h>
#include <gio/gio.h>
#include <libebook/e-book.h>
+#include <libebook/e-book-client.h>
#include "ebook-test-utils.h"
@@ -46,7 +47,7 @@ ebook_test_utils_new_vcard_from_test_case (const gchar *case_name)
gchar *case_filename;
GFile* file;
GError *error = NULL;
- gchar *vcard;
+ gchar *vcard = NULL;
case_filename = g_strdup_printf ("%s.vcf", case_name);
filename = g_build_filename (SRCDIR, EBOOK_TEST_UTILS_DATA_DIR, EBOOK_TEST_UTILS_VCARDS_DIR, case_filename, NULL);
@@ -61,13 +62,15 @@ ebook_test_utils_new_vcard_from_test_case (const gchar *case_name)
g_free (filename);
g_object_unref (file);
+ g_assert (vcard != NULL);
+
return vcard;
}
gchar *
-ebook_test_utils_book_add_contact_from_test_case_verify (EBook *book,
+ebook_test_utils_book_add_contact_from_test_case_verify (EBook *book,
const gchar *case_name,
- EContact **contact)
+ EContact **contact)
{
gchar *vcard;
EContact *contact_orig;
@@ -88,6 +91,7 @@ ebook_test_utils_book_add_contact_from_test_case_verify (EBook *book,
return uid;
}
+
/* This is not a thorough comparison (which is difficult, assuming we give the
* back-ends leniency in implementation) and is best suited for simple tests */
gboolean
@@ -666,6 +670,7 @@ ebook_test_utils_book_new_temp (gchar **uri)
return book;
}
+
void
ebook_test_utils_book_open (EBook *book,
gboolean only_if_exists)
@@ -781,3 +786,188 @@ ebook_test_utils_book_async_get_book_view (EBook *book,
exit (1);
}
}
+
+
+/* EClient versions */
+EBookClient *
+ebook_test_utils_book_client_new_from_uri (const gchar *uri)
+{
+ EBookClient *book;
+ GError *error = NULL;
+
+ test_print ("loading addressbook\n");
+ book = e_book_client_new_from_uri (uri, &error);
+ if (!book) {
+ g_error ("failed to create addressbook: `%s': %s", uri,
+ error->message);
+ }
+
+ return book;
+}
+
+EBookClient *
+ebook_test_utils_book_client_new_temp (gchar **uri)
+{
+ EBookClient *book;
+ gchar *file_template;
+ gchar *uri_result;
+
+ file_template = g_build_filename (g_get_tmp_dir (),
+ "ebook-test-XXXXXX/", NULL);
+ g_mkstemp (file_template);
+
+ uri_result = g_strconcat ("local:", file_template, NULL);
+ if (!uri_result) {
+ g_warning ("failed to convert %s to a 'local:' URI", file_template);
+ exit (1);
+ }
+ g_free (file_template);
+
+ book = ebook_test_utils_book_client_new_from_uri (uri_result);
+
+ if (uri)
+ *uri = g_strdup (uri_result);
+
+ g_free (uri_result);
+
+ return book;
+}
+
+void
+ebook_test_utils_book_client_open (EBookClient *book,
+ gboolean only_if_exists)
+{
+ GError *error = NULL;
+
+ if (!e_client_open_sync (E_CLIENT (book), only_if_exists, NULL, &error)) {
+ g_warning ("failed to open addressbook: %s", error->message);
+ exit (1);
+ }
+}
+
+
+void
+ebook_test_utils_book_client_remove (EBookClient *book)
+{
+ GError *error = NULL;
+
+ if (!e_client_remove_sync (E_CLIENT (book), NULL, &error)) {
+ g_warning ("failed to remove book; %s\n", error->message);
+ exit (1);
+ }
+ test_print ("successfully removed the temporary addressbook\n");
+
+ g_object_unref (book);
+}
+
+
+const gchar *
+ebook_test_utils_book_client_add_contact (EBookClient *book,
+ EContact *contact)
+{
+ GError *error = NULL;
+
+ g_assert (contact != NULL);
+
+ if (!e_book_client_add_contact_sync (book, contact, NULL, NULL, &error)) {
+ g_warning ("failed to add contact to addressbook: %s", error->message);
+ exit (1);
+ }
+
+ g_assert (e_contact_get_const (contact, E_CONTACT_UID) != NULL);
+
+ return e_contact_get_const (contact, E_CONTACT_UID);
+}
+
+EContact*
+ebook_test_utils_book_client_get_contact (EBookClient *book,
+ const gchar *uid)
+{
+ EContact *contact = NULL;
+ GError *error = NULL;
+
+ if (!e_book_client_get_contact_sync (book, uid, &contact, NULL, &error)) {
+ if (error)
+ g_warning ("failed to get contact '%s' in addressbook: %s",
+ uid, error->message);
+ else
+ g_warning ("failed to get contact '%s' in addressbook", uid);
+
+ exit (1);
+ }
+
+ return contact;
+}
+
+
+gchar *
+ebook_test_utils_book_client_add_contact_from_test_case_verify (EBookClient *book,
+ const gchar *case_name,
+ EContact **contact)
+{
+ gchar *vcard;
+ EContact *contact_orig;
+ EContact *contact_final;
+ gchar *uid;
+
+ vcard = ebook_test_utils_new_vcard_from_test_case (case_name);
+ contact_orig = e_contact_new_from_vcard (vcard);
+
+ g_assert (e_contact_get_const (contact_orig, E_CONTACT_UID) != NULL);
+
+ uid = g_strdup (ebook_test_utils_book_client_add_contact (book, contact_orig));
+ contact_final = ebook_test_utils_book_client_get_contact (book, uid);
+
+ /* verify the contact was added "successfully" (not thorough) */
+ g_assert (ebook_test_utils_contacts_are_equal_shallow (contact_orig, contact_final));
+
+ if (contact)
+ *contact = g_object_ref (contact_final);
+
+ return uid;
+}
+
+void
+ebook_test_utils_book_client_get_book_view (EBookClient *book,
+ EBookQuery *query,
+ EBookClientView **view)
+{
+ GError *error = NULL;
+ gchar *sexp = NULL;
+
+ if (query)
+ sexp = e_book_query_to_string (query);
+
+ if (!e_book_client_get_view_sync (book, sexp, view, NULL, &error)) {
+ g_warning ("failed to get view for addressbook: %s", error->message);
+ exit (1);
+ }
+
+ g_free (sexp);
+}
+
+void
+ebook_test_utils_book_client_start (EBookClientView *view)
+{
+ GError *error = NULL;
+
+ e_book_client_view_start (view, &error);
+
+ if (error) {
+ g_warning ("failed to start client book view: %s", error->message);
+ exit (1);
+ }
+}
+
+void
+ebook_test_utils_book_client_stop (EBookClientView *view)
+{
+ GError *error = NULL;
+
+ e_book_client_view_stop (view, &error);
+
+ if (error) {
+ g_warning ("failed to stop client book view: %s", error->message);
+ exit (1);
+ }
+}
diff --git a/tests/libebook/ebook-test-utils.h b/tests/libebook/ebook-test-utils.h
index d9fee50..f49211e 100644
--- a/tests/libebook/ebook-test-utils.h
+++ b/tests/libebook/ebook-test-utils.h
@@ -23,15 +23,17 @@
#define _EBOOK_TEST_UTILS_H
#include <libebook/e-book.h>
+#include <libebook/e-book-client.h>
#define EBOOK_TEST_UTILS_DATA_DIR "data"
#define EBOOK_TEST_UTILS_VCARDS_DIR "vcards"
typedef struct {
- GSourceFunc cb;
- gpointer user_data;
- EBookView *view;
- EList *list;
+ GSourceFunc cb;
+ gpointer user_data;
+ EBookView *view;
+ EBookClientView *client_view;
+ EList *list;
} EBookTestClosure;
void
@@ -154,4 +156,38 @@ ebook_test_utils_book_async_get_book_view (EBook *book,
GSourceFunc callback,
gpointer user_data);
+
+EBookClient *
+ebook_test_utils_book_client_new_from_uri (const gchar *uri);
+
+EBookClient *
+ebook_test_utils_book_client_new_temp (gchar **uri);
+
+void
+ebook_test_utils_book_client_open (EBookClient *book,
+ gboolean only_if_exists);
+
+void
+ebook_test_utils_book_client_remove (EBookClient *book);
+
+const gchar *
+ebook_test_utils_book_client_add_contact (EBookClient *book,
+ EContact *contact);
+EContact*
+ebook_test_utils_book_client_get_contact (EBookClient *book,
+ const gchar *uid);
+
+
+gchar *
+ebook_test_utils_book_client_add_contact_from_test_case_verify (EBookClient *book,
+ const gchar *case_name,
+ EContact **contact);
+
+void ebook_test_utils_book_client_get_book_view (EBookClient *book,
+ EBookQuery *query,
+ EBookClientView **view);
+void ebook_test_utils_book_client_start (EBookClientView *view);
+void ebook_test_utils_book_client_stop (EBookClientView *view);
+
+
#endif /* _EBOOK_TEST_UTILS_H */
diff --git a/tests/libebook/test-ebook-get-book-view.c b/tests/libebook/test-ebook-get-book-view.c
index 9cd4a00..431faec 100644
--- a/tests/libebook/test-ebook-get-book-view.c
+++ b/tests/libebook/test-ebook-get-book-view.c
@@ -1,7 +1,7 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
#include <stdlib.h>
-#include <libebook/e-book.h>
+#include <libebook/e-book-client.h>
#include "ebook-test-utils.h"
@@ -27,7 +27,7 @@ print_contact (EContact *contact)
}
static void
-contacts_added (EBookView *book_view, const GList *contacts)
+contacts_added (EBookClientView *book_view, const GList *contacts)
{
GList *l;
@@ -37,7 +37,7 @@ contacts_added (EBookView *book_view, const GList *contacts)
}
static void
-contacts_removed (EBookView *book_view, const GList *ids)
+contacts_removed (EBookClientView *book_view, const GList *ids)
{
GList *l;
@@ -47,42 +47,42 @@ contacts_removed (EBookView *book_view, const GList *ids)
}
static void
-view_complete (EBookView *book_view, EBookViewStatus status, const gchar *error_msg)
+complete (EBookClientView *view, GError *error)
{
- e_book_view_stop (book_view);
- g_object_unref (book_view);
+ ebook_test_utils_book_client_stop (view);
+ g_object_unref (view);
g_main_loop_quit (loop);
}
static void
-setup_and_start_view (EBookView *view)
+setup_and_start_view (EBookClientView *view)
{
- g_signal_connect (view, "contacts_added", G_CALLBACK (contacts_added), NULL);
- g_signal_connect (view, "contacts_removed", G_CALLBACK (contacts_removed), NULL);
- g_signal_connect (view, "view_complete", G_CALLBACK (view_complete), NULL);
+ g_signal_connect (view, "objects-added", G_CALLBACK (contacts_added), NULL);
+ g_signal_connect (view, "objects-removed", G_CALLBACK (contacts_removed), NULL);
+ g_signal_connect (view, "complete", G_CALLBACK (complete), NULL);
- e_book_view_start (view);
+ ebook_test_utils_book_client_start (view);
}
static void
get_book_view_cb (EBookTestClosure *closure)
{
- g_assert (closure->view);
+ g_assert (closure->client_view);
- setup_and_start_view (closure->view);
+ setup_and_start_view (closure->client_view);
}
static void
-setup_book (EBook **book_out)
+setup_book (EBookClient **book_out)
{
- EBook *book;
+ EBookClient *book;
- book = ebook_test_utils_book_new_temp (NULL);
- ebook_test_utils_book_open (book, FALSE);
+ book = ebook_test_utils_book_client_new_temp (NULL);
+ ebook_test_utils_book_client_open (book, FALSE);
- ebook_test_utils_book_add_contact_from_test_case_verify (book, "simple-1", NULL);
- ebook_test_utils_book_add_contact_from_test_case_verify (book, "simple-2", NULL);
- ebook_test_utils_book_add_contact_from_test_case_verify (book, "name-only", NULL);
+ ebook_test_utils_book_client_add_contact_from_test_case_verify (book, "simple-1", NULL);
+ ebook_test_utils_book_client_add_contact_from_test_case_verify (book, "simple-2", NULL);
+ ebook_test_utils_book_client_add_contact_from_test_case_verify (book, "name-only", NULL);
*book_out = book;
}
@@ -90,9 +90,9 @@ setup_book (EBook **book_out)
gint
main (gint argc, gchar **argv)
{
- EBook *book;
+ EBookClient *book;
+ EBookClientView *view;
EBookQuery *query;
- EBookView *view;
g_type_init ();
@@ -101,7 +101,7 @@ main (gint argc, gchar **argv)
*/
setup_book (&book);
query = e_book_query_any_field_contains ("");
- ebook_test_utils_book_get_book_view (book, query, &view);
+ ebook_test_utils_book_client_get_book_view (book, query, &view);
setup_and_start_view (view);
test_print ("successfully set up the book view\n");
@@ -110,8 +110,8 @@ main (gint argc, gchar **argv)
g_main_loop_run (loop);
e_book_query_unref (query);
- ebook_test_utils_book_remove (book);
-
+ ebook_test_utils_book_client_remove (book);
+#if 0
/*
* Async version
*/
@@ -126,6 +126,7 @@ main (gint argc, gchar **argv)
e_book_query_unref (query);
ebook_test_utils_book_remove (book);
+#endif
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]