[evolution-data-server] google: Add some tests to Google address book backend



commit 5eed3f9f327cd2d057a0459f4e2bbccaeac95d17
Author: Philip Withnall <philip tecnocode co uk>
Date:   Sat Jun 16 11:34:41 2012 +0100

    google: Add some tests to Google address book backend
    
    This is necessary to try and prevent regressions on the tangle of GDataâvCard
    conversion code which the backend is built around.
    
    These few tests check the behaviour of phone numbers.
    
    Helps: https://bugzilla.gnome.org/show_bug.cgi?id=675712.

 addressbook/backends/google/Makefile.am           |    2 +
 addressbook/backends/google/tests/Makefile.am     |   28 +++++
 addressbook/backends/google/tests/phone-numbers.c |  124 +++++++++++++++++++++
 configure.ac                                      |    1 +
 4 files changed, 155 insertions(+), 0 deletions(-)
---
diff --git a/addressbook/backends/google/Makefile.am b/addressbook/backends/google/Makefile.am
index a4275fb..f419927 100644
--- a/addressbook/backends/google/Makefile.am
+++ b/addressbook/backends/google/Makefile.am
@@ -1,3 +1,5 @@
+SUBDIRS = . tests
+
 ebook_backend_LTLIBRARIES = libebookbackendgoogle.la
 
 if HAVE_GOA
diff --git a/addressbook/backends/google/tests/Makefile.am b/addressbook/backends/google/tests/Makefile.am
new file mode 100644
index 0000000..3d2bb8e
--- /dev/null
+++ b/addressbook/backends/google/tests/Makefile.am
@@ -0,0 +1,28 @@
+CPPFLAGS = \
+	$(AM_CPPFLAGS) \
+	-I$(top_srcdir)/addressbook \
+	-I$(top_builddir)/addressbook \
+	-I$(top_srcdir)/addressbook/backends/google \
+	-DG_LOG_DOMAIN=\"evolution-tests\" \
+	$(NULL)
+CFLAGS = \
+	$(AM_CFLAGS) \
+	$(EVOLUTION_ADDRESSBOOK_CFLAGS) \
+	$(GDATA_CFLAGS) \
+	$(CAMEL_CFLAGS) \
+	$(NULL)
+LDADD = \
+	$(AM_LDADD) \
+	$(top_builddir)/addressbook/backends/google/libebook-google-utils.la \
+	$(EVOLUTION_ADDRESSBOOK_LIBS) \
+	$(GDATA_LIBS) \
+	$(NULL)
+
+noinst_PROGRAMS = \
+	phone-numbers \
+	$(NULL)
+TESTS = $(noinst_PROGRAMS)
+
+phone_numbers_SOURCES = phone-numbers.c
+
+-include $(top_srcdir)/git.mk
diff --git a/addressbook/backends/google/tests/phone-numbers.c b/addressbook/backends/google/tests/phone-numbers.c
new file mode 100644
index 0000000..ddc6b8b
--- /dev/null
+++ b/addressbook/backends/google/tests/phone-numbers.c
@@ -0,0 +1,124 @@
+/* phone-numbers.c - Phone number tests
+ *
+ * Copyright (C) 2012 Philip Withnall
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation; either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Author: Philip Withnall <philip tecnocode co uk>
+ */
+
+#include <libebook/libebook.h>
+#include <gdata/gdata.h>
+
+#include "e-book-google-utils.h"
+
+static GHashTable/*<string, string>*/ *
+build_groups_by_name (void)
+{
+	return g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+}
+
+static GHashTable/*<string, string>*/ *
+build_system_groups_by_id (void)
+{
+	GHashTable *table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+	g_hash_table_insert (table, g_strdup (GDATA_CONTACTS_GROUP_CONTACTS), g_strdup ("contacts-group-id"));
+	return table;
+}
+
+static gchar *
+create_group_null (const gchar *category_name, gpointer user_data, GError **error)
+{
+	/* Must never be reached. */
+	g_assert_not_reached ();
+}
+
+#define ENTRY_FROM_VCARD(entry, VCARD_PROPS) G_STMT_START { \
+	EContact *contact; \
+	GHashTable *groups_by_name, *system_groups_by_id; \
+\
+	groups_by_name = build_groups_by_name (); \
+	system_groups_by_id = build_system_groups_by_id (); \
+\
+	contact = e_contact_new_from_vcard ( \
+		"BEGIN:VCARD" "\n" \
+		"VERSION:3.0" "\n" \
+		"UID:foobar-baz" "\n" \
+		"FN:Foobar Baz" "\n" \
+		VCARD_PROPS \
+		"END:VCARD" \
+	); \
+\
+	entry = gdata_entry_new_from_e_contact (contact, groups_by_name, system_groups_by_id, create_group_null, NULL); \
+	g_assert (entry != NULL); \
+\
+	g_hash_table_unref (system_groups_by_id); \
+	g_hash_table_unref (groups_by_name); \
+\
+	g_object_unref (contact); \
+} G_STMT_END
+
+/* Include both an X-GOOGLE_LABEL and a TYPE attribute in the vCard and test that exactly one of them is copied to the entry. */
+static void
+test_label_and_type (void)
+{
+	GDataEntry *entry;
+	GDataGDPhoneNumber *phone_number;
+
+	g_test_bug ("675712");
+
+	ENTRY_FROM_VCARD (entry, "TEL;X-GOOGLE-LABEL=VOICE;TYPE=PREF;X-EVOLUTION-UI-SLOT=1:+0123456789" "\n");
+
+	/* Check that the entry has exactly one phone number, and that it contains exactly one of the rel and label properties. */
+	phone_number = gdata_contacts_contact_get_primary_phone_number (GDATA_CONTACTS_CONTACT (entry));
+
+	g_assert_cmpstr (gdata_gd_phone_number_get_relation_type (phone_number), ==, NULL);
+	g_assert_cmpstr (gdata_gd_phone_number_get_label (phone_number), ==, "VOICE");
+
+	g_object_unref (entry);
+}
+
+/* Include neither an X-GOOGLE_LABEL nor a TYPE attribute in the vCard and test that a suitable default appears in the entry. */
+static void
+test_label_nor_type (void)
+{
+	GDataEntry *entry;
+	GDataGDPhoneNumber *phone_number;
+
+	g_test_bug ("675712");
+
+	ENTRY_FROM_VCARD (entry, "TEL;X-EVOLUTION-UI-SLOT=1:+0123456789" "\n");
+
+	/* Check that the entry has exactly one phone number, and that it contains exactly one of the rel and label properties. */
+	phone_number = gdata_contacts_contact_get_primary_phone_number (GDATA_CONTACTS_CONTACT (entry));
+
+	g_assert_cmpstr (gdata_gd_phone_number_get_relation_type (phone_number), ==, GDATA_GD_PHONE_NUMBER_OTHER);
+	g_assert_cmpstr (gdata_gd_phone_number_get_label (phone_number), ==, NULL);
+
+	g_object_unref (entry);
+}
+
+int
+main (int argc, char **argv)
+{
+	g_type_init ();
+	g_test_init (&argc, &argv, NULL);
+	g_test_bug_base ("https://bugzilla.gnome.org/show_bug.cgi?id=";);
+
+	g_test_add_func ("/phone-numbers/label-and-type", test_label_and_type);
+	g_test_add_func ("/phone-numbers/label-nor-type", test_label_nor_type);
+
+	return g_test_run ();
+}
diff --git a/configure.ac b/configure.ac
index dff9bda..795e8c7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1593,6 +1593,7 @@ addressbook/backends/file/Makefile
 addressbook/backends/vcf/Makefile
 addressbook/backends/ldap/Makefile
 addressbook/backends/google/Makefile
+addressbook/backends/google/tests/Makefile
 addressbook/backends/webdav/Makefile
 art/Makefile
 calendar/Makefile



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