[evolution-data-server/openismus-work: 2/7] 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: 2/7] Added test case showing photo data stored as uris.
- Date: Sat, 30 Jul 2011 01:48:31 +0000 (UTC)
commit b81988c56018c4cceaa63b1d1e490076b859ddf2
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date: Fri Jul 15 19:01:25 2011 -0400
Added test case showing photo data stored as uris.
The test asserts:
o binary inlined photos added to the EBook come out
as uris in the EBookView signals
o that it is still 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 (the test does this, however it only asserts
that a uri is indeed returned).
o When sharing an addressbook owned uri fetched from one contact
and assigning it to the next contact, the second contact's uri
is still accessible on disk after deleting the first contact.
addressbook/tests/ebook/Makefile.am | 3 +
addressbook/tests/ebook/test-ebook-photo-is-uri.c | 324 +++++++++++++++++++++
2 files changed, 327 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..3809618
--- /dev/null
+++ b/addressbook/tests/ebook/test-ebook-photo-is-uri.c
@@ -0,0 +1,324 @@
+/* -*- 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;
+
+
+/* Decide what to do with every "view-completed" signal */
+enum {
+ ITERATION_SWAP_FACE = 0,
+ ITERATION_DELETE_JAMES,
+ ITERATION_UPDATE_MICHEAL,
+ ITERATION_DELETE_MICHEAL,
+ ITERATION_FINISH
+};
+static gint iteration = ITERATION_SWAP_FACE;
+
+
+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);
+ }
+}
+
+
+/* This provokes the backend to handle a cross-referenced photo
+ * between contacts, how the backend handles this is it's choice,
+ * we should test that when deleting one of the contacts, the other
+ * contact does not lose it's photo on disk as a result.
+ */
+static void
+give_james_brown_micheal_jacksons_face (EBook *book)
+{
+ EContact *micheal, *james;
+ EContactPhoto *micheal_face;
+ EContactPhoto *james_face;
+ GError *error = NULL;
+
+ micheal = ebook_test_utils_book_get_contact (book, micheal_jackson_uid);
+ james = ebook_test_utils_book_get_contact (book, james_brown_uid);
+
+ micheal_face = e_contact_get (micheal, E_CONTACT_PHOTO);
+ g_assert (micheal_face->type == E_CONTACT_PHOTO_TYPE_URI);
+
+ james_face = g_new (EContactPhoto, 1);
+ james_face->type = E_CONTACT_PHOTO_TYPE_URI;
+ james_face->data.uri = g_strdup (micheal_face->data.uri);
+
+ e_contact_set (james, E_CONTACT_PHOTO, james_face);
+
+ if (!e_book_commit_contact (book, james, &error))
+ g_error ("Failed to modify contact with cross referenced photo: %s", error->message);
+
+ g_print ("Giving james brown micheal jacksons face: %s\n", micheal_face->data.uri);
+
+}
+
+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);
+}
+
+/* This assertion is made a couple of times in the view-complete
+ * handler, we run it to ensure that binary blobs and cross-referenced
+ * photo uris exist on disk while they should */
+static void
+assert_uri_exists (EBook *book,
+ const gchar *uid)
+{
+ EContact *contact;
+ EContactPhoto *photo;
+ const gchar *filename;
+
+ contact = ebook_test_utils_book_get_contact (book, uid);
+ g_assert (contact);
+
+ photo = e_contact_get (contact, E_CONTACT_PHOTO);
+ g_assert (photo);
+ g_assert (photo->type == E_CONTACT_PHOTO_TYPE_URI);
+
+ filename = g_filename_from_uri (photo->data.uri, NULL, NULL);
+ g_assert (filename);
+
+ /* The file should absolutely exist at this point */
+ g_assert (g_file_test (filename, G_FILE_TEST_EXISTS));
+}
+
+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;
+
+ g_print ("View complete, iteration %d\n", iteration);
+
+ /* We get another "complete" notification after removing or modifying a contact */
+ switch (iteration) {
+ case ITERATION_SWAP_FACE:
+ give_james_brown_micheal_jacksons_face (book);
+ break;
+ case ITERATION_DELETE_JAMES:
+ assert_uri_exists (book, 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;
+ break;
+ case ITERATION_UPDATE_MICHEAL:
+ assert_uri_exists (book, micheal_jackson_uid);
+
+ update_contact_inline (book, micheal_jackson_uid);
+ break;
+ case ITERATION_DELETE_MICHEAL:
+ assert_uri_exists (book, 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;
+ break;
+ case ITERATION_FINISH:
+ e_book_view_stop (book_view);
+ g_object_unref (book_view);
+ g_main_loop_quit (loop);
+ break;
+ default:
+ g_assert_not_reached ();
+ break;
+ }
+
+ iteration++;
+}
+
+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]