[evolution-data-server] Factor out test vcard into its own file, so we can add additional ones in a clean way.



commit 25a2a0f5e32a9d761e438910c5d60c33beb10d55
Author: Travis Reitter <treitter gmail com>
Date:   Tue Dec 29 12:37:28 2009 -0800

    Factor out test vcard into its own file, so we can add additional ones in a clean way.

 addressbook/tests/ebook/ebook-test-utils.c       |   26 ++++++++++++++++++++++
 addressbook/tests/ebook/ebook-test-utils.h       |   11 ++++-----
 addressbook/tests/ebook/test-ebook-add-contact.c |    7 ++++-
 addressbook/tests/ebook/test-ebook-get-contact.c |    5 +++-
 4 files changed, 40 insertions(+), 9 deletions(-)
---
diff --git a/addressbook/tests/ebook/ebook-test-utils.c b/addressbook/tests/ebook/ebook-test-utils.c
index a9a5245..649ee11 100644
--- a/addressbook/tests/ebook/ebook-test-utils.c
+++ b/addressbook/tests/ebook/ebook-test-utils.c
@@ -2,10 +2,36 @@
 
 #include <stdlib.h>
 #include <glib.h>
+#include <gio/gio.h>
 #include <libebook/e-book.h>
 
 #include "ebook-test-utils.h"
 
+char*
+ebook_test_utils_new_vcard_from_test_case (const char *case_name)
+{
+        char *filename;
+        char *case_filename;
+        GFile* file;
+        GError *error = NULL;
+        char *vcard;
+
+        case_filename = g_strdup_printf ("%s.vcf", case_name);
+        filename = g_build_filename (EBOOK_TEST_UTILS_DATA_DIR, EBOOK_TEST_UTILS_VCARDS_DIR, case_filename, NULL);
+        file = g_file_new_for_path (filename);
+        if (!g_file_load_contents (file, NULL, &vcard, NULL, NULL, &error)) {
+                g_warning ("failed to read test contact file '%s': %s",
+                                filename, error->message);
+                exit(1);
+        }
+
+        g_free (case_filename);
+        g_free (filename);
+        g_object_unref (file);
+
+        return vcard;
+}
+
 const char*
 ebook_test_utils_book_add_contact (EBook    *book,
                                    EContact *contact)
diff --git a/addressbook/tests/ebook/ebook-test-utils.h b/addressbook/tests/ebook/ebook-test-utils.h
index 3a57535..6a0f58f 100644
--- a/addressbook/tests/ebook/ebook-test-utils.h
+++ b/addressbook/tests/ebook/ebook-test-utils.h
@@ -25,18 +25,17 @@
 #include <glib.h>
 #include <libebook/e-book.h>
 
-/* TODO: build up a library of vcards as separate files; don't hardcode here */
-#define EBOOK_TEST_UTILS_VCARD_SIMPLE \
-"BEGIN:VCARD\n\
-FN:Foo Bar\n\
-EMAIL;INTERNET:foo bar example org\n\
-END:VCARD"
+#define EBOOK_TEST_UTILS_DATA_DIR "data"
+#define EBOOK_TEST_UTILS_VCARDS_DIR "vcards"
 
 typedef struct {
         GSourceFunc    cb;
         gpointer       user_data;
 } EBookTestClosure;
 
+char*
+ebook_test_utils_new_vcard_from_test_case (const char *case_name);
+
 EBook*
 ebook_test_utils_book_new_temp (char **uri);
 
diff --git a/addressbook/tests/ebook/test-ebook-add-contact.c b/addressbook/tests/ebook/test-ebook-add-contact.c
index 1bc289b..4297c93 100644
--- a/addressbook/tests/ebook/test-ebook-add-contact.c
+++ b/addressbook/tests/ebook/test-ebook-add-contact.c
@@ -10,6 +10,7 @@ main (gint argc, gchar **argv)
 {
 	EBook *book;
 	GMainLoop *loop;
+	char *vcard;
 	EContact *contact;
 	EContact *contact_final;
 	char *uid;
@@ -23,7 +24,8 @@ main (gint argc, gchar **argv)
 	book = ebook_test_utils_book_new_temp (NULL);
 	ebook_test_utils_book_open (book, FALSE);
 
-	contact = e_contact_new_from_vcard (EBOOK_TEST_UTILS_VCARD_SIMPLE);
+	vcard = ebook_test_utils_new_vcard_from_test_case ("simple-1");
+	contact = e_contact_new_from_vcard (vcard);
 	uid = g_strdup (ebook_test_utils_book_add_contact (book, contact));
 
 	/*
@@ -56,7 +58,7 @@ main (gint argc, gchar **argv)
 	 */
 	book = ebook_test_utils_book_new_temp (NULL);
 	ebook_test_utils_book_open (book, FALSE);
-	contact = e_contact_new_from_vcard (EBOOK_TEST_UTILS_VCARD_SIMPLE);
+	contact = e_contact_new_from_vcard (vcard);
 
 	loop = g_main_loop_new (NULL, TRUE);
 	ebook_test_utils_book_async_add_contact (book, contact,
@@ -66,6 +68,7 @@ main (gint argc, gchar **argv)
 	g_main_loop_run (loop);
 
 	ebook_test_utils_book_remove (book);
+	g_free (vcard);
 
 	return 0;
 }
diff --git a/addressbook/tests/ebook/test-ebook-get-contact.c b/addressbook/tests/ebook/test-ebook-get-contact.c
index 4ffd1d8..ff3dcda 100644
--- a/addressbook/tests/ebook/test-ebook-get-contact.c
+++ b/addressbook/tests/ebook/test-ebook-get-contact.c
@@ -10,6 +10,7 @@ main (gint argc, gchar **argv)
 {
 	EBook *book;
 	GMainLoop *loop;
+	char *vcard;
 	EContact *contact;
 	EContact *contact_final;
 	const char *uid;
@@ -23,7 +24,8 @@ main (gint argc, gchar **argv)
 	book = ebook_test_utils_book_new_temp (NULL);
 	ebook_test_utils_book_open (book, FALSE);
 
-	contact = e_contact_new_from_vcard (EBOOK_TEST_UTILS_VCARD_SIMPLE);
+	vcard = ebook_test_utils_new_vcard_from_test_case ("simple-1");
+	contact = e_contact_new_from_vcard (vcard);
 	uid = ebook_test_utils_book_add_contact (book, contact);
 
 	/*
@@ -58,6 +60,7 @@ main (gint argc, gchar **argv)
 	g_main_loop_run (loop);
 
 	ebook_test_utils_book_remove (book);
+	g_free (vcard);
 
 	return 0;
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]