[evolution-data-server/openismus-work: 3/3] Added test case showing photo data stored as uris.
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/openismus-work: 3/3] Added test case showing photo data stored as uris.
- Date: Thu, 7 Jul 2011 23:32:18 +0000 (UTC)
commit 60589806d0c783671679fb1ccedc4a6f8110c432
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date: Thu Jul 7 19:29:23 2011 -0400
Added test case showing photo data stored as uris.
The test so far only really asserts that photo uris ars
sent to an open EBookView for binary blobs sent to the
addressbook. The test asserts this both for added contacts
and modified contacts.
The test also shows that it is possible to use an external
uri that the addressbook does not recognize at which point
the addressbook is simply expected to store the provided URI
string without any extra management.
addressbook/tests/ebook/Makefile.am | 3 +
addressbook/tests/ebook/test-ebook-photo-is-uri.c | 245 +++++++++++++++++++++
2 files changed, 248 insertions(+), 0 deletions(-)
---
diff --git a/addressbook/tests/ebook/Makefile.am b/addressbook/tests/ebook/Makefile.am
index 6859fb6..0e4ddbd 100644
--- a/addressbook/tests/ebook/Makefile.am
+++ b/addressbook/tests/ebook/Makefile.am
@@ -41,6 +41,7 @@ TESTS = \
test-ebook-get-book-view \
test-ebook-get-book-view-uid-only \
test-ebook-suppress-initial-notifications \
+ test-ebook-photo-is-uri \
test-ebook-commit-contact \
test-ebook-remove-contact \
test-ebook-remove-contact-by-id \
@@ -96,6 +97,8 @@ test_ebook_get_book_view_uid_only_LDADD=$(TEST_LIBS)
test_ebook_get_book_view_uid_only_CPPFLAGS=$(TEST_CPPFLAGS)
test_ebook_suppress_initial_notifications_LDADD=$(TEST_LIBS)
test_ebook_suppress_initial_notifications_CPPFLAGS=$(TEST_CPPFLAGS)
+test_ebook_photo_is_uri_LDADD=$(TEST_LIBS)
+test_ebook_photo_is_uri_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/addressbook/tests/ebook/test-ebook-photo-is-uri.c b/addressbook/tests/ebook/test-ebook-photo-is-uri.c
new file mode 100644
index 0000000..b5ae3df
--- /dev/null
+++ b/addressbook/tests/ebook/test-ebook-photo-is-uri.c
@@ -0,0 +1,245 @@
+/* -*- 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"
+
+
+static const gchar *photo_data =
+"/9j/4AAQSkZJRgABAQEARwBHAAD//gAXQ3JlYXRlZCB3aXRoIFRoZSBHSU1Q/9sAQwAIBgYHB\
+gUIBwcHCQkICgwUDQwLCwwZEhMPFB0aHx4dGhwcICQuJyAiLCMcHCg3KSwwMTQ0NB8nOT04Mjw\
+uMzQy/9sAQwEJCQkMCwwYDQ0YMiEcITIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyM\
+jIyMjIyMjIyMjIyMjIyMjIy/8AAEQgAMgAyAwEiAAIRAQMRAf/EABsAAQACAwEBAAAAAAAAAAA\
+AAAAHCAQFBgID/8QAMBAAAgEDAQYEBQQDAAAAAAAAAQIDAAQRBQYSEyExQQdhcYEiI0JRkRQVM\
+qFiguH/xAAaAQADAQEBAQAAAAAAAAAAAAAABAUCBgED/8QAIxEAAgICAQQCAwAAAAAAAAAAAAE\
+CAwQRQRITITEUYQUiUf/aAAwDAQACEQMRAD8An+sHUtWtNKjVrmQ7754cajLvjrgfbzPIdzWdV\
+fds9pJb3XdQkMrcFZGj+HqY0bdVV9Tz/wBia+N9vbjvkaxMb5E9N6SJB1HxLEEjJaWsUjD6QzS\
+MPXdGB7E1zV74t63HINy1s4F7CWCTn77wrA0TY86jY3N1qsUk6wxBxBDvYjLHkoUH4j3JP/a0V\
+3s1CvF/QM9tKpw0THeU+TLkj8VLnmzT8y0n9FujBx5bioba/rZLWx3iPZ7RzLp95GtnqRGVTez\
+HNjruH7/4n+67iqpq7Qi3uYWMMsNynfnE6sM8/Lr6VamFi0KMepUE1Sx7XZHbI+fjxos1H0z3S\
+lKYEjzISI2I64OKqsyu8sck2QYrmPjBvpIYg598Vauoh8VtlY7JW2isoBwpPl6hGByZTyD+o6E\
++h7UtlVOcPHA/+PyI1Wal6Zp7vaC/06wnTTLtEeUDiKwzu4H8vI9AM9Tiuctkng1Nnk1G5cOoY\
+ifB4nI/jB7VjWuoT21qPmwXUCHKlphHKvqG5N6g0/cLi/Rg88FhbkbxlaUSu3kqpnn6kDzqGqb\
+NdPB0XyK4/svZr9RVntL50GePdcKEDqzhVBx7sKtPpayppNosxzKIlDHzxUFeG2zo2n2kivWhK\
+6PpHwwoTnfk65J7kZyT9z5VYADAwKuYtfRA5zPv7tnjgUpSmREV8bq1hvbWW1uY1khlUo6MMhg\
+eor7UoAje18FtmLe9eeQT3EXPcglkJRPbv71EWu7Dajp2o3MGmlRCkjKQ30jPUe1WlrlNW0Rpt\
+TleNB84DnjkD0P9VlxT4Nqck9pmn8JuFp2zo0cgCWFi2e7555/NSHXLadso2m3sU0NxlV65HM+\
+VdTW3rgwvsUpSvAFKUoAUxSlAClKUAKUpQB//2Q==";
+
+
+static GMainLoop *loop = NULL;
+static gchar *micheal_jackson_uid = NULL;
+static gchar *james_brown_uid = NULL;
+
+static void
+print_contact (EContact *contact)
+{
+ EContactPhoto *photo = e_contact_get (contact, E_CONTACT_PHOTO);
+
+ g_assert (photo->type == E_CONTACT_PHOTO_TYPE_URI);
+ g_print ("Test passed with photo uri: %s\n", photo->data.uri);
+}
+
+static void
+contacts_added (EBookView *book_view, const GList *contacts)
+{
+ GList *l;
+
+ for (l = (GList*)contacts; l; l = l->next) {
+ print_contact (l->data);
+ }
+}
+
+static void
+contacts_changed (EBookView *book_view, const GList *contacts)
+{
+ GList *l;
+
+ for (l = (GList*)contacts; l; l = l->next) {
+ print_contact (l->data);
+ }
+}
+
+static void
+contacts_removed (EBookView *book_view, const GList *ids)
+{
+ GList *l;
+
+ for (l = (GList*)ids; l; l = l->next) {
+ test_print ("Removed contact: %s\n", (gchar *)l->data);
+ }
+}
+
+static gboolean
+quit_timeout (EBookView *book_view)
+{
+ e_book_view_stop (book_view);
+ g_object_unref (book_view);
+ g_main_loop_quit (loop);
+
+ return FALSE;
+}
+
+
+static void
+update_contact_inline (EBook *book,
+ const gchar *uid)
+{
+ EContact *contact;
+ EContactPhoto *photo;
+ guchar *data;
+ gsize length = 0;
+ GError *error = NULL;
+
+ contact = ebook_test_utils_book_get_contact (book, uid);
+ g_assert (contact);
+
+ data = g_base64_decode (photo_data, &length);
+
+ photo = g_new (EContactPhoto, 1);
+ photo->type = E_CONTACT_PHOTO_TYPE_INLINED;
+ photo->data.inlined.mime_type = NULL;
+ photo->data.inlined.data = data;
+ photo->data.inlined.length = length;
+
+ /* set the photo */
+ e_contact_set (contact, E_CONTACT_PHOTO, photo);
+
+ if (!e_book_commit_contact (book, contact, &error))
+ g_error ("Failed to modify contact with inline photo data: %s", error->message);
+}
+
+static void
+view_complete (EBookView *book_view, EBookViewStatus status, const gchar *error_msg)
+{
+ EBook *book = e_book_view_get_book (book_view);
+ GError *error = NULL;
+
+ /* We get another "complete" notification after removing or modifying a contact */
+ if (james_brown_uid) {
+
+ if (!e_book_remove_contact (book, james_brown_uid, &error))
+ g_error ("Error removing contact: %s", error->message);
+
+ g_free (james_brown_uid);
+ james_brown_uid = NULL;
+
+ update_contact_inline (book, micheal_jackson_uid);
+
+ } else if (micheal_jackson_uid) {
+
+ if (!e_book_remove_contact (book, micheal_jackson_uid, &error))
+ g_error ("Error removing contact: %s", error->message);
+
+ g_free (micheal_jackson_uid);
+ micheal_jackson_uid = NULL;
+
+ g_timeout_add (500, (GSourceFunc)quit_timeout, book_view);
+ }
+}
+
+static void
+setup_and_start_view (EBookView *view)
+{
+ g_signal_connect (view, "contacts_added", G_CALLBACK (contacts_added), NULL);
+ g_signal_connect (view, "contacts_changed", G_CALLBACK (contacts_changed), NULL);
+ g_signal_connect (view, "contacts_removed", G_CALLBACK (contacts_removed), NULL);
+ g_signal_connect (view, "view_complete", G_CALLBACK (view_complete), NULL);
+
+ e_book_view_start (view);
+}
+
+static void
+add_contact_inline (EBook *book)
+{
+ EContact *contact, *final;
+ EContactPhoto *photo;
+ guchar *data;
+ gsize length = 0;
+ const gchar *uid;
+
+ contact = e_contact_new ();
+
+ data = g_base64_decode (photo_data, &length);
+
+ photo = g_new (EContactPhoto, 1);
+ photo->type = E_CONTACT_PHOTO_TYPE_INLINED;
+ photo->data.inlined.mime_type = NULL;
+ photo->data.inlined.data = data;
+ photo->data.inlined.length = length;
+
+ /* set the photo */
+ e_contact_set (contact, E_CONTACT_PHOTO, photo);
+ e_contact_set (contact, E_CONTACT_FULL_NAME, "Micheal Jackson");
+
+ uid = ebook_test_utils_book_add_contact (book, contact);
+ final = ebook_test_utils_book_get_contact (book, uid);
+
+ /* verify the contact was added "successfully" (not thorough) */
+ g_assert (ebook_test_utils_contacts_are_equal_shallow (contact, final));
+
+ micheal_jackson_uid = g_strdup (uid);
+}
+
+static void
+add_contact_uri (EBook *book)
+{
+ EContact *contact, *final;
+ EContactPhoto *photo;
+ const gchar *uid;
+
+ contact = e_contact_new ();
+
+ photo = g_new (EContactPhoto, 1);
+ photo->type = E_CONTACT_PHOTO_TYPE_URI;
+ photo->data.uri = g_strdup ("http://en.wikipedia.org/wiki/File:Jamesbrown4.jpg");
+
+ /* set the photo */
+ e_contact_set (contact, E_CONTACT_PHOTO, photo);
+ e_contact_set (contact, E_CONTACT_FULL_NAME, "James Brown");
+
+ uid = ebook_test_utils_book_add_contact (book, contact);
+ final = ebook_test_utils_book_get_contact (book, uid);
+
+ /* verify the contact was added "successfully" (not thorough) */
+ g_assert (ebook_test_utils_contacts_are_equal_shallow (contact, final));
+
+ james_brown_uid = g_strdup (uid);
+}
+
+static void
+setup_book (EBook **book_out)
+{
+ EBook *book;
+
+ book = ebook_test_utils_book_new_temp (NULL);
+ ebook_test_utils_book_open (book, FALSE);
+
+ add_contact_inline (book);
+ add_contact_uri (book);
+
+ *book_out = book;
+}
+
+gint
+main (gint argc, gchar **argv)
+{
+ EBook *book;
+ EBookQuery *query;
+ EBookView *view;
+
+ g_type_init ();
+
+ setup_book (&book);
+ query = e_book_query_any_field_contains ("");
+ ebook_test_utils_book_get_book_view (book, query, NULL, &view);
+ setup_and_start_view (view);
+
+ loop = g_main_loop_new (NULL, TRUE);
+ g_main_loop_run (loop);
+
+ e_book_query_unref (query);
+ ebook_test_utils_book_remove (book);
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]