[evolution-data-server/openismus-work] Added simple test to show that the local backend sends uris for photo contacts.



commit 3bab5aee43a22538522470c053eb2be5594e0c35
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date:   Fri Jul 1 15:58:41 2011 -0400

    Added simple test to show that the local backend sends uris for photo contacts.

 addressbook/tests/ebook/Makefile.am               |    3 +
 addressbook/tests/ebook/test-ebook-photo-is-uri.c |  144 +++++++++++++++++++++
 2 files changed, 147 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..dde4e1a
--- /dev/null
+++ b/addressbook/tests/ebook/test-ebook-photo-is-uri.c
@@ -0,0 +1,144 @@
+/* -*- 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;
+
+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_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 void
+view_complete (EBookView *book_view, EBookViewStatus status, const gchar *error_msg)
+{
+	e_book_view_stop (book_view);
+	g_object_unref (book_view);
+	g_main_loop_quit (loop);
+}
+
+static void
+setup_and_start_view (EBookView *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);
+
+	e_book_view_start (view);
+}
+
+static void
+add_contact (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));
+}
+
+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 (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]