[evolution-data-server/openismus-work] test-client-custom-summary enhancements.
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/openismus-work] test-client-custom-summary enhancements.
- Date: Wed, 27 Feb 2013 15:44:15 +0000 (UTC)
commit 6309a143a3fc04ae357b40233f3f922226c1be8f
Author: Tristan Van Berkom <tristanvb openismus com>
Date: Wed Feb 27 20:09:41 2013 +0900
test-client-custom-summary enhancements.
o Added an invalid phone number to custom-6.vcf
o Added a query test ensuring that E_CLIENT_ERROR_INVALID_QUERY is
reported for a completely bogus query 'sexp' string.
o Added a query test ensuring that E_CLIENT_ERROR_INVALID_QUERY is
reported for a phone number query where an invalid phone number term
is provided.
o Added a query test ensuring that an invalid phone number string
can still be matched using a normal E_BOOK_QUERY_BEGINS_WITH query
on the E_CONTACT_TEL field (matching the invalid number in custom-6.vcf).
Conflicts:
tests/libebook/client/test-client-custom-summary.c
tests/libebook/client/test-client-custom-summary.c | 163 ++++++++++++--------
tests/libebook/data/vcards/custom-6.vcf | 1 +
2 files changed, 98 insertions(+), 66 deletions(-)
---
diff --git a/tests/libebook/client/test-client-custom-summary.c
b/tests/libebook/client/test-client-custom-summary.c
index b33bae4..f56eb64 100644
--- a/tests/libebook/client/test-client-custom-summary.c
+++ b/tests/libebook/client/test-client-custom-summary.c
@@ -27,10 +27,19 @@
#include "client-test-utils.h"
#include "e-test-server-utils.h"
+/* Define this macro to expect E_CLIENT_ERROR_NOT_SUPPORTED
+ * only on phone number queries when EDS is built with no
+ * phone number support.
+ */
+#ifdef ENABLE_PHONENUMBER
+# define CHECK_UNSUPPORTED_ERROR(data) (FALSE)
+#else
+# define CHECK_UNSUPPORTED_ERROR(data) (((ClientTestData *)(data))->phone_number_query != FALSE)
+#endif
typedef struct {
ETestServerClosure closure;
- EBookQuery *query;
+ gchar *sexp;
gint num_contacts;
gboolean phone_number_query;
} ClientTestData;
@@ -45,8 +54,7 @@ client_test_data_free (gpointer p)
{
ClientTestData *data = (ClientTestData *)p;
- if (data->query)
- e_book_query_unref (data->query);
+ g_free (data->sexp);
g_slice_free (ClientTestData, data);
}
@@ -97,14 +105,14 @@ client_test_teardown (ClientTestFixture *fixture,
}
static void
-add_client_test (const gchar *prefix,
- const gchar *test_case_name,
- gpointer func,
- EBookQuery *query,
- gint num_contacts,
- gboolean direct,
- gboolean custom,
- gboolean phone_number_query)
+add_client_test_sexp (const gchar *prefix,
+ const gchar *test_case_name,
+ gpointer func,
+ gchar *sexp, /* sexp is 'given' */
+ gint num_contacts,
+ gboolean direct,
+ gboolean custom,
+ gboolean phone_number_query)
{
ClientTestData *data = g_slice_new0 (ClientTestData);
gchar *path = g_strconcat (prefix, test_case_name, NULL);
@@ -115,7 +123,7 @@ add_client_test (const gchar *prefix,
data->closure.customize = setup_custom_book;
data->closure.destroy_closure_func = client_test_data_free;
- data->query = query;
+ data->sexp = sexp;
data->num_contacts = num_contacts;
data->phone_number_query = phone_number_query;
@@ -126,6 +134,22 @@ add_client_test (const gchar *prefix,
}
static void
+add_client_test (const gchar *prefix,
+ const gchar *test_case_name,
+ gpointer func,
+ EBookQuery *query,
+ gint num_contacts,
+ gboolean direct,
+ gboolean custom,
+ gboolean phone_number_query)
+{
+ add_client_test_sexp (prefix, test_case_name, func,
+ e_book_query_to_string (query),
+ num_contacts, direct, custom, phone_number_query);
+ e_book_query_unref (query);
+}
+
+static void
setup_book (ClientTestFixture *fixture)
{
EContact **it = fixture->contacts;
@@ -156,47 +180,40 @@ search_test (ETestServerFixture *fixture,
EBookClient *book_client;
GSList *results = NULL;
GError *error = NULL;
- gchar *sexp;
const ClientTestData *const data = user_data;
book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
setup_book ((ClientTestFixture *)fixture);
- sexp = e_book_query_to_string (data->query);
-
-#ifdef ENABLE_PHONENUMBER
-
- if (!e_book_client_get_contacts_sync (book_client, sexp, &results, NULL, &error)) {
- g_error ("get contacts: %s", error->message);
- }
-
- g_assert_cmpint (g_slist_length (results), ==, data->num_contacts);
-
-#else /* if (!ENABLE_PHONENUMBER) */
-
- if (data->phone_number_query == FALSE) {
-
- if (!e_book_client_get_contacts_sync (book_client, sexp, &results, NULL, &error)) {
- g_error ("get contacts: %s", error->message);
- }
-
- g_assert_cmpint (g_slist_length (results), ==, data->num_contacts);
-
- } else {
-
- if (e_book_client_get_contacts_sync (book_client, sexp, &results, NULL, &error))
+ if (CHECK_UNSUPPORTED_ERROR (data)) {
+ /* Expect unsupported query (no phone number support in a phone number query) */
+ if (e_book_client_get_contacts_sync (book_client, data->sexp, &results, NULL, &error))
g_error ("Succeeded to query contacts when phone numbers are not supported");
else if (!g_error_matches (error, E_CLIENT_ERROR, E_CLIENT_ERROR_NOT_SUPPORTED))
g_error ("Wrong error when querying with unsupported query: %s (domain: %s, code:
%d)",
error->message, g_quark_to_string (error->domain), error->code);
else
g_clear_error (&error);
- }
-#endif /* ENABLE_PHONENUMBER */
+ } else if (data->num_contacts < 0) {
+ /* Expect E_CLIENT_ERROR_INVALID_QUERY */
+ if (e_book_client_get_contacts_sync (book_client, data->sexp, &results, NULL, &error))
+ g_error ("Succeeded to query contacts with an invalid query type");
+ else if (!g_error_matches (error, E_CLIENT_ERROR, E_CLIENT_ERROR_INVALID_QUERY))
+ g_error ("Wrong error when querying with an invalid query: %s (domain: %s, code: %d)",
+ error->message, g_quark_to_string (error->domain), error->code);
+ else
+ g_clear_error (&error);
+ } else {
+ /* Expect successful query */
+ if (!e_book_client_get_contacts_sync (book_client, data->sexp, &results, NULL, &error)) {
+ g_error ("get contacts: %s", error->message);
+ }
+
+ g_assert_cmpint (g_slist_length (results), ==, data->num_contacts);
+ }
e_util_free_object_slist (results);
- g_free (sexp);
}
static void
@@ -206,48 +223,40 @@ uid_test (ETestServerFixture *fixture,
EBookClient *book_client;
GSList *results = NULL;
GError *error = NULL;
- gchar *sexp;
const ClientTestData *const data = user_data;
book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
setup_book ((ClientTestFixture *)fixture);
- sexp = e_book_query_to_string (data->query);
-
-#ifdef ENABLE_PHONENUMBER
-
- if (!e_book_client_get_contacts_uids_sync (book_client, sexp, &results, NULL, &error)) {
- g_error ("get contact uids: %s", error->message);
- }
-
- g_assert_cmpint (g_slist_length (results), ==, data->num_contacts);
-
-#else /* if (!ENABLE_PHONENUMBER) */
-
- if (data->phone_number_query == FALSE) {
-
- if (!e_book_client_get_contacts_uids_sync (book_client, sexp, &results, NULL, &error)) {
- g_error ("get contact uids: %s", error->message);
- }
-
- g_assert_cmpint (g_slist_length (results), ==, data->num_contacts);
-
- } else {
-
- if (e_book_client_get_contacts_uids_sync (book_client, sexp, &results, NULL, &error))
+ if (CHECK_UNSUPPORTED_ERROR (data)) {
+ /* Expect unsupported query (no phone number support in a phone number query) */
+ if (e_book_client_get_contacts_uids_sync (book_client, data->sexp, &results, NULL, &error))
g_error ("Succeeded to query contact uids when phone numbers are not supported");
else if (!g_error_matches (error, E_CLIENT_ERROR, E_CLIENT_ERROR_NOT_SUPPORTED))
g_error ("Wrong error when querying uids with unsupported query: %s (domain: %s,
code: %d)",
error->message, g_quark_to_string (error->domain), error->code);
else
g_clear_error (&error);
- }
-#endif /* ENABLE_PHONENUMBER */
+ } else if (data->num_contacts < 0) {
+ /* Expect E_CLIENT_ERROR_INVALID_QUERY */
+ if (e_book_client_get_contacts_uids_sync (book_client, data->sexp, &results, NULL, &error))
+ g_error ("Succeeded to query contacts with an invalid query type");
+ else if (!g_error_matches (error, E_CLIENT_ERROR, E_CLIENT_ERROR_INVALID_QUERY))
+ g_error ("Wrong error when querying with an invalid query: %s (domain: %s, code: %d)",
+ error->message, g_quark_to_string (error->domain), error->code);
+ else
+ g_clear_error (&error);
+ } else {
+ /* Expect successful query */
+ if (!e_book_client_get_contacts_uids_sync (book_client, data->sexp, &results, NULL, &error)) {
+ g_error ("get contact uids: %s", error->message);
+ }
+ g_assert_cmpint (g_slist_length (results), ==, data->num_contacts);
+ }
e_util_free_string_slist (results);
- g_free (sexp);
}
#ifdef ENABLE_PHONENUMBER
@@ -325,6 +334,11 @@ main (gint argc,
*/
for (i = 0; i < G_N_ELEMENTS (suites); i++) {
+ /* A query that will cause e_sexp_parse() to report an error */
+ add_client_test_sexp (suites[i].prefix, "/InvalidQuery", suites[i].func,
+ g_strdup ("(invalid \"query\" \"term\")"),
+ -1, suites[i].direct, suites[i].custom, FALSE);
+
/* Add search tests that fetch contacts */
add_client_test (suites[i].prefix, "/Exact/FullName", suites[i].func,
e_book_query_field_test (E_CONTACT_FULL_NAME, E_BOOK_QUERY_IS, "James
Brown"),
@@ -342,6 +356,13 @@ main (gint argc,
e_book_query_field_test (E_CONTACT_FULL_NAME, E_BOOK_QUERY_BEGINS_WITH, "%"),
1, suites[i].direct, suites[i].custom, FALSE);
+ /* Query the E_CONTACT_TEL field for something that is not a phone number, user is
+ * searching for all the contacts when they noted they must ask Jenny for the phone number
+ */
+ add_client_test (suites[i].prefix, "/Prefix/Phone/NotAPhoneNumber", suites[i].func,
+ e_book_query_field_test (E_CONTACT_TEL, E_BOOK_QUERY_BEGINS_WITH, "ask
Jenny"),
+ 1, suites[i].direct, suites[i].custom, FALSE);
+
add_client_test (suites[i].prefix, "/Suffix/Phone", suites[i].func,
e_book_query_field_test (E_CONTACT_TEL, E_BOOK_QUERY_ENDS_WITH, "999"),
2, suites[i].direct, suites[i].custom, FALSE);
@@ -362,6 +383,16 @@ main (gint argc,
* PHONE NUMBER QUERIES FOLLOW *
*********************************************/
+ /* Expect E_CLIENT_ERROR_INVALID_QUERY, "ask Jenny for Lisa's number" was entered
+ * for contact-6.vcf, it can be searched using normal E_BOOK_QUERY_* queries but
+ * treating it as a phone number is an invalid query.
+ */
+ add_client_test (suites[i].prefix, "/EqPhone/InvalidPhoneNumber", suites[i].func,
+ e_book_query_field_test (E_CONTACT_TEL,
+ E_BOOK_QUERY_EQUALS_PHONE_NUMBER,
+ "ask Jenny for Lisa's number"),
+ -1, suites[i].direct, suites[i].custom, TRUE);
+
/* These queries will do an index lookup with a custom summary, and a full table scan
* matching with EBookBackendSexp when the default summary is used
*/
diff --git a/tests/libebook/data/vcards/custom-6.vcf b/tests/libebook/data/vcards/custom-6.vcf
index d64650e..8c26296 100644
--- a/tests/libebook/data/vcards/custom-6.vcf
+++ b/tests/libebook/data/vcards/custom-6.vcf
@@ -1,3 +1,4 @@
BEGIN:VCARD
+TEL;HOME:ask Jenny for Lisa's number
FN:%Strange Name
END:VCARD
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]