[evolution-data-server/sqlite-refactor: 13/13] test-client-custom-summary: Added various tests



commit d524e98777b07e3b4a517152334a7570392f5c84
Author: Tristan Van Berkom <tristanvb openismus com>
Date:   Sat Nov 23 22:36:18 2013 +0900

    test-client-custom-summary: Added various tests
    
      o Added test for the underscore
    
        Before we used to only escape the '%' character in LIKE statements,
        but SQLite also recognizes the '_' as a single char wildcard and
        needs escaping.
    
        This test ensures that the underscore is properly handled.
    
      o Added query test which ORs the same field
    
        This helps to test the query optimizer in EBookBackendSqlite, which
        will optimize a query which ORs two multi attribute fields (like
        E_CONTACT_EMAIL).
    
      o Added tests for the NOT queries
    
      o Added tests for NOT, AND and OR and as well as some nested AND / OR
        tests which trigger the query optimizer in EBookBackendSqlite
    
      o Fix expectations for phone number matches, now that the phone number
        comparisons are fixed
    
      o Added --filter option.
    
        Pass a regular expression to filter which test cases should run

 tests/libebook/client/test-client-custom-summary.c |  428 ++++++++++++++++++--
 tests/libebook/data/vcards/custom-6.vcf            |    2 +-
 2 files changed, 386 insertions(+), 44 deletions(-)
---
diff --git a/tests/libebook/client/test-client-custom-summary.c 
b/tests/libebook/client/test-client-custom-summary.c
index 7f39e6d..c06ce34 100644
--- a/tests/libebook/client/test-client-custom-summary.c
+++ b/tests/libebook/client/test-client-custom-summary.c
@@ -60,6 +60,18 @@ setup_custom_book (ESource *scratch,
 static ETestServerClosure setup_custom_closure  = { E_TEST_SERVER_ADDRESS_BOOK, setup_custom_book, 0, TRUE, 
NULL };
 static ETestServerClosure setup_default_closure = { E_TEST_SERVER_ADDRESS_BOOK, NULL, 0, TRUE, NULL };
 
+/* Filter which tests we want to try with a regexp */
+static GRegex *test_regex = NULL;
+static gchar  *test_filter = NULL;
+
+static GOptionEntry entries[] = {
+
+       { "filter", 'f', 0, G_OPTION_ARG_STRING, &test_filter,
+         "A regular expression to filter which tests should be added", NULL },
+       { NULL }
+};
+
+
 /* Define this macro to expect E_CLIENT_ERROR_NOT_SUPPORTED
  * only on phone number queries when EDS is built with no
  * phone number support.
@@ -137,6 +149,12 @@ add_client_test_sexp (const gchar *prefix,
        data->num_contacts = num_contacts;
        data->phone_number_query = phone_number_query;
 
+       /* Filter out anything that was not specified in the test filter */
+       if (test_regex && !g_regex_match (test_regex, path, 0, NULL)) {
+               g_free (path);
+               return;
+       }
+
        if (custom)
                g_test_add (
                        path, ClientTestFixture, data,
@@ -302,6 +320,7 @@ gint
 main (gint argc,
       gchar **argv)
 {
+       GOptionContext *context;
        gint ret, i;
        SuiteType suites[] = {
                { search_test, FALSE, FALSE, "/EBookClient/Default/Search" },
@@ -314,6 +333,15 @@ main (gint argc,
                { uid_test,    TRUE,  TRUE,  "/EBookClient/Custom/DirectAccess/SearchUID" }
        };
 
+       /* Parse our regex first */
+       context = g_option_context_new (NULL);
+       g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
+       g_option_context_parse (context, &argc, &argv, NULL);
+       g_option_context_free (context);
+
+       if (test_filter)
+               test_regex = g_regex_new (test_filter, 0, 0, NULL);
+
        g_test_init (&argc, &argv, NULL);
        g_test_bug_base ("http://bugzilla.gnome.org/";);
 
@@ -407,6 +435,19 @@ main (gint argc,
                        suites[i].custom,
                        FALSE);
 
+               add_client_test (
+                       suites[i].prefix,
+                       "/Prefix/FullName/Underscore",
+                       suites[i].func,
+                       e_book_query_field_test (
+                               E_CONTACT_FULL_NAME,
+                               E_BOOK_QUERY_CONTAINS,
+                               "ran_ge"),
+                       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. */
@@ -468,6 +509,25 @@ main (gint argc,
 
                add_client_test (
                        suites[i].prefix,
+                       "/Or/TwoEmails",
+                       suites[i].func,
+                       e_book_query_orv (
+                               e_book_query_field_test (
+                                       E_CONTACT_EMAIL,
+                                       E_BOOK_QUERY_ENDS_WITH,
+                                       "jackson.com"),
+                               e_book_query_field_test (
+                                       E_CONTACT_EMAIL,
+                                       E_BOOK_QUERY_ENDS_WITH,
+                                       ".org"),
+                               NULL),
+                       4,
+                       suites[i].direct,
+                       suites[i].custom,
+                       FALSE);
+
+               add_client_test (
+                       suites[i].prefix,
                        "/Exact/Email",
                        suites[i].func,
                        e_book_query_field_test (
@@ -479,8 +539,157 @@ main (gint argc,
                        suites[i].custom,
                        FALSE);
 
+               add_client_test (
+                       suites[i].prefix,
+                       "/Not/JacksonFamily",
+                       suites[i].func,
+                       e_book_query_not (
+                               e_book_query_field_test (
+                                       E_CONTACT_FULL_NAME,
+                                       E_BOOK_QUERY_ENDS_WITH,
+                                       "jackson"),
+                               TRUE),
+                       /* There are 2 jackson contacts */
+                       N_CONTACTS - 2,
+                       suites[i].direct,
+                       suites[i].custom,
+                       FALSE);
+
+               add_client_test (
+                       suites[i].prefix,
+                       "/Not/DotComEmail",
+                       suites[i].func,
+                       e_book_query_not (
+                               e_book_query_field_test (
+                                       E_CONTACT_EMAIL,
+                                       E_BOOK_QUERY_ENDS_WITH,
+                                       ".com"),
+                               TRUE),
+                       /* There are 9 contacts with emails ending in ".com"  */
+                       N_CONTACTS - 9,
+                       suites[i].direct,
+                       suites[i].custom,
+                       FALSE);
+
+               add_client_test (
+                       suites[i].prefix,
+                       "/And/EmailFullName",
+                       suites[i].func,
+                       e_book_query_andv (
+                               /* There are 9 contacts with emails ending in ".com"  */
+                               e_book_query_field_test (
+                                       E_CONTACT_EMAIL,
+                                       E_BOOK_QUERY_ENDS_WITH,
+                                       ".com"),
+                               /* Contacts custom-1 and custom-2 have Jackson in the full name */
+                               e_book_query_field_test (
+                                       E_CONTACT_FULL_NAME,
+                                       E_BOOK_QUERY_CONTAINS,
+                                       "Jackson"),
+                               NULL),
+                       2,
+                       suites[i].direct,
+                       suites[i].custom,
+                       FALSE);
+
+               add_client_test (
+                       suites[i].prefix,
+                       "/And/EmailEmail",
+                       suites[i].func,
+                       e_book_query_andv (
+                               /* There are 9 contacts with emails ending in ".com"  */
+                               e_book_query_field_test (
+                                       E_CONTACT_EMAIL,
+                                       E_BOOK_QUERY_ENDS_WITH,
+                                       ".com"),
+                               /* Contacts custom-1 and custom-2 have Jackson in the email */
+                               e_book_query_field_test (
+                                       E_CONTACT_EMAIL,
+                                       E_BOOK_QUERY_CONTAINS,
+                                       "jackson"),
+                               NULL),
+                       2,
+                       suites[i].direct,
+                       suites[i].custom,
+                       FALSE);
+
+               add_client_test (
+                       suites[i].prefix,
+                       "/And/EmailPhone",
+                       suites[i].func,
+                       e_book_query_andv (
+                               /* custom-13 begins with eddie */
+                               e_book_query_field_test (
+                                       E_CONTACT_EMAIL,
+                                       E_BOOK_QUERY_BEGINS_WITH,
+                                       "eddie"),
+                               /* custom-13, custom-14 & custom-15 end with 5050 */
+                               e_book_query_field_test (
+                                       E_CONTACT_TEL,
+                                       E_BOOK_QUERY_ENDS_WITH,
+                                       "5050"),
+                               NULL),
+                       1,
+                       suites[i].direct,
+                       suites[i].custom,
+                       FALSE);
+
+               add_client_test (
+                       suites[i].prefix,
+                       "/And/EmailPhoneFamiliy",
+                       suites[i].func,
+                       e_book_query_andv (
+                               /* custom-13 family name is Murphey */
+                               e_book_query_field_test (
+                                       E_CONTACT_FAMILY_NAME,
+                                       E_BOOK_QUERY_IS,
+                                       "Murphey"),
+                               /* custom-13 begins with eddie */
+                               e_book_query_field_test (
+                                       E_CONTACT_EMAIL,
+                                       E_BOOK_QUERY_BEGINS_WITH,
+                                       "eddie"),
+                               /* custom-13, custom-14 & custom-15 end with 5050 */
+                               e_book_query_field_test (
+                                       E_CONTACT_TEL,
+                                       E_BOOK_QUERY_ENDS_WITH,
+                                       "5050"),
+                               NULL),
+                       1,
+                       suites[i].direct,
+                       suites[i].custom,
+                       FALSE);
+
+               add_client_test (
+                       suites[i].prefix,
+                       "/And/Familiy/Or/EmailEmail",
+                       suites[i].func,
+                       e_book_query_andv (
+                               /* Contacts custom-1 and custom-2 have Jackson in the full name */
+                               e_book_query_field_test (
+                                       E_CONTACT_FULL_NAME,
+                                       E_BOOK_QUERY_CONTAINS,
+                                       "Jackson"),
+                               e_book_query_orv (
+                                       /* There are 9 contacts with emails ending in ".com"  */
+                                       e_book_query_field_test (
+                                               E_CONTACT_EMAIL,
+                                               E_BOOK_QUERY_ENDS_WITH,
+                                               ".com"),
+                                       /* Contacts custom-1 and custom-2 have Jackson in the email */
+                                       e_book_query_field_test (
+                                               E_CONTACT_EMAIL,
+                                               E_BOOK_QUERY_CONTAINS,
+                                               "jackson"),
+                                       NULL),
+                               NULL),
+                       2,
+                       suites[i].direct,
+                       suites[i].custom,
+                       FALSE);
+
                /*********************************************
-                *         PHONE NUMBER QUERIES FOLLOW       *
+                *                PHONE NUMBERS              *
                 *********************************************/
 
                /* Expect E_CLIENT_ERROR_INVALID_QUERY, "ask Jenny for
@@ -500,29 +709,13 @@ main (gint argc,
                        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. */
-               add_client_test (
-                       suites[i].prefix,
-                       "/EqPhone/Exact/Common",
-                       suites[i].func,
-                       e_book_query_field_test (
-                               E_CONTACT_TEL,
-                               E_BOOK_QUERY_EQUALS_PHONE_NUMBER,
-                               "+1 221.542.3789"),
-                       1,
-                       suites[i].direct,
-                       suites[i].custom,
-                       TRUE);
-
                /* This test checks that phone number matching works when
                 * deeply nested into a query, when ENABLE_PHONENUMBER is
                 * not defined, then it ensures that the query is refused
                 * while being deeply nested. */
                add_client_test (
                        suites[i].prefix,
-                       "/EqPhone/Exact/Nested",
+                       "/EqPhone/NestedQuery",
                        suites[i].func,
                        e_book_query_orv (
                                e_book_query_field_test (
@@ -550,44 +743,97 @@ main (gint argc,
                        TRUE);
 
                /*********************************************
-                * E_BOOK_QUERY_EQUALS_NATIONAL_PHONE_NUMBER *
+                *      E_BOOK_QUERY_EQUALS_PHONE_NUMBER     *
                 *********************************************/
+               /* Only exact matches are returned.
+                *
+                * Query: +1 221.542.3789
+                * +------------------------------+--------------------+
+                * | vCard Data:   +1-221-5423789 | Matches: Exact     |
+                * | vCard Data:  +31-221-5423789 | Matches: None      |
+                * +------------------------------+--------------------+
+                */
+               add_client_test (
+                       suites[i].prefix,
+                       "/EqPhone/Exact",
+                       suites[i].func,
+                       e_book_query_field_test (
+                               E_CONTACT_TEL,
+                               E_BOOK_QUERY_EQUALS_PHONE_NUMBER,
+                               "+1 221.542.3789"),
+                       1,
+                       suites[i].direct,
+                       suites[i].custom,
+                       TRUE);
+
 
+               /*
+                * Query: +49 408.765.5050 (one exact match)
+                * +------------------------------+--------------------+
+                * | vCard Data:     408 765-5050 | Matches: National  |
+                * | vCard Data:  +1 408 765-5050 | Matches: None      |
+                * | vCard Data: +49 408 765-5050 | Matches: Exact     |
+                * +------------------------------+--------------------+
+                */
                add_client_test (
                        suites[i].prefix,
-                       "/EqPhone/National/WithoutCountry",
+                       "/EqPhone/Exact/Another",
                        suites[i].func,
                        e_book_query_field_test (
                                E_CONTACT_TEL,
-                               E_BOOK_QUERY_EQUALS_NATIONAL_PHONE_NUMBER,
-                               "408 765-5050"),
-                       2,
+                               E_BOOK_QUERY_EQUALS_PHONE_NUMBER,
+                               "+49 408.765.5050"),
+                       1,
                        suites[i].direct,
                        suites[i].custom,
                        TRUE);
 
+               /*
+                * Query: 408.765.5050 (no exact match)
+                * +------------------------------+--------------------+
+                * | vCard Data:     408 765-5050 | Matches: National  |
+                * | vCard Data:  +1 408 765-5050 | Matches: National  |
+                * | vCard Data: +49 408 765-5050 | Matches: National  |
+                * +------------------------------+--------------------+
+                */
                add_client_test (
                        suites[i].prefix,
-                       "/EqPhone/National/en_US",
+                       "/EqPhone/Exact/MissingCountryInput",
                        suites[i].func,
                        e_book_query_field_test (
                                E_CONTACT_TEL,
-                               E_BOOK_QUERY_EQUALS_NATIONAL_PHONE_NUMBER,
-                               "+1 408 765-5050"),
-                       2,
+                               E_BOOK_QUERY_EQUALS_PHONE_NUMBER,
+                               "408.765.5050"),
+                       0,
                        suites[i].direct,
                        suites[i].custom,
                        TRUE);
 
+
+               /*********************************************
+                * E_BOOK_QUERY_EQUALS_NATIONAL_PHONE_NUMBER *
+                *********************************************/
+               /* Test that a query term with no specified country returns
+                * all vCards that have the same national number regardless
+                * of country codes (including contacts which have no
+                * national number specified)
+                *
+                * Query: 408 765-5050
+                * +------------------------------+--------------------+
+                * | vCard Data:     408 765-5050 | Matches: National  |
+                * | vCard Data:  +1 408 765-5050 | Matches: National  |
+                * | vCard Data: +49 408 765-5050 | Matches: National  |
+                * +------------------------------+--------------------+
+                */
                add_client_test (
                        suites[i].prefix,
-                       "/EqPhone/National/de_DE",
+                       "/EqPhone/National/WithoutCountry",
                        suites[i].func,
                        e_book_query_field_test (
                                E_CONTACT_TEL,
                                E_BOOK_QUERY_EQUALS_NATIONAL_PHONE_NUMBER,
-                               "+49 408 765-5050"),
-                       1,
+                               "408 765-5050"),
+                       3,
                        suites[i].direct,
                        suites[i].custom,
                        TRUE);
@@ -596,28 +842,80 @@ main (gint argc,
                 * all vCards that have the same national number regardless
                 * of country codes.
                 *
-                * | Active Country Code: +1 | Query: 221.542.3789 | vCard Data: +1-221-5423789 | Matches: 
yes |
-                * | Active Country Code: +1 | Query: 221.542.3789 | vCard Data: +31-221-5423789 | Matches: 
no  |
+                * Query: 221.542.3789
+                * +------------------------------+--------------------+
+                * | vCard Data:   +1-221-5423789 | Matches: National  |
+                * | vCard Data:  +31-221-5423789 | Matches: National  |
+                * +------------------------------+--------------------+
                 */
                add_client_test (
                        suites[i].prefix,
-                       "/EqPhone/National/Common",
+                       "/EqPhone/National/WithoutCountry2",
                        suites[i].func,
                        e_book_query_field_test (
                                E_CONTACT_TEL,
                                E_BOOK_QUERY_EQUALS_NATIONAL_PHONE_NUMBER,
                                "221.542.3789"),
-                       1,
+                       2,
+                       suites[i].direct,
+                       suites[i].custom,
+                       TRUE);
+
+               /* Test that querying with an explicit country code reports
+                * national number matches for numbers without a country
+                * code, and not for numbers with explicitly different
+                * country codes.
+                *
+                * Query: +1 408 765-5050
+                * +------------------------------+--------------------+
+                * | vCard Data:     408 765-5050 | Matches: National  |
+                * | vCard Data:  +1 408 765-5050 | Matches: Exact     |
+                * | vCard Data: +49 408 765-5050 | Matches: None      |
+                * +------------------------------+--------------------+
+                */
+               add_client_test (
+                       suites[i].prefix,
+                       "/EqPhone/National/en_US",
+                       suites[i].func,
+                       e_book_query_field_test (
+                               E_CONTACT_TEL,
+                               E_BOOK_QUERY_EQUALS_NATIONAL_PHONE_NUMBER,
+                               "+1 408 765-5050"),
+                       2,
                        suites[i].direct,
                        suites[i].custom,
                        TRUE);
 
+               /* Query: +49 408 765-5050
+                * +------------------------------+--------------------+
+                * | vCard Data:     408 765-5050 | Matches: National  |
+                * | vCard Data:  +1 408 765-5050 | Matches: None      |
+                * | vCard Data: +49 408 765-5050 | Matches: Exact     |
+                * +------------------------------+--------------------+
+                */
+               add_client_test (
+                       suites[i].prefix,
+                       "/EqPhone/National/de_DE",
+                       suites[i].func,
+                       e_book_query_field_test (
+                               E_CONTACT_TEL,
+                               E_BOOK_QUERY_EQUALS_NATIONAL_PHONE_NUMBER,
+                               "+49 408 765-5050"),
+                       2,
+                       suites[i].direct,
+                       suites[i].custom,
+                       TRUE);
+
+
                /* Test that a query term with a specified country returns
                 * only vCards that are specifically in the specified country
                 * code.
                 *
-                * | Active Country Code: +1 | Query: +49 221.542.3789 | vCard Data: +1-221-5423789 | 
Matches: no |
-                * | Active Country Code: +1 | Query: +49 221.542.3789 | vCard Data: +31-221-5423789 | 
Matches: no |
+                * Query: +49 221.542.3789
+                * +------------------------------+--------------------+
+                * | vCard Data:   +1-221-5423789 | Matches: None      |
+                * | vCard Data:  +31-221-5423789 | Matches: None      |
+                * +------------------------------+--------------------+
                 */
                add_client_test (
                        suites[i].prefix,
@@ -632,10 +930,13 @@ main (gint argc,
                        suites[i].custom,
                        TRUE);
 
-               /* Test that a query term with the active country code
+               /* Test that a query term with a country code
                 * specified returns a vCard with an unspecified country code.
                 *
-                * | Active Country Code: +1 | Query: +1 514-845-8436 | vCard Data: 514-845-8436 | Matches: 
yes |
+                * Query: +1 514-845-8436
+                * +------------------------------+--------------------+
+                * | vCard Data:     514-845-8436 | Matches: National  |
+                * +------------------------------+--------------------+
                 */
                add_client_test (
                        suites[i].prefix,
@@ -650,10 +951,18 @@ main (gint argc,
                        suites[i].custom,
                        TRUE);
 
-               /* Test that a query term with an arbitrary country code
-                * specified returns a vCard with an unspecified country code.
+               /* Test that a query term with another country code
+                * specified again returns a vCard with an unspecified
+                * country code.
                 *
-                * | Active Country Code: +1 | Query: +49 514-845-8436 | vCard Data: 514-845-8436 | Matches: 
yes |
+                * This test can help make sure that we are properly
+                * ignoring whatever country code is active by default
+                * in our locale.
+                *
+                * Query: +49 514-845-8436
+                * +------------------------------+--------------------+
+                * | vCard Data:     514-845-8436 | Matches: National  |
+                * +------------------------------+--------------------+
                 */
                add_client_test (
                        suites[i].prefix,
@@ -663,11 +972,23 @@ main (gint argc,
                                E_CONTACT_TEL,
                                E_BOOK_QUERY_EQUALS_NATIONAL_PHONE_NUMBER,
                                "+49 514-845-8436"),
-                       0,
+                       1,
                        suites[i].direct,
                        suites[i].custom,
                        TRUE);
 
+
+
+               /********************************************
+                *  E_BOOK_QUERY_EQUALS_SHORT_PHONE_NUMBER  *
+                ********************************************/
+               /*
+                * Query: 5423789
+                * +------------------------------+--------------------+
+                * | vCard Data:   +1-221-5423789 | Matches: Short     |
+                * | vCard Data:  +31-221-5423789 | Matches: Short     |
+                * +------------------------------+--------------------+
+                */
                add_client_test (
                        suites[i].prefix,
                        "/EqPhone/Short",
@@ -676,7 +997,28 @@ main (gint argc,
                                E_CONTACT_TEL,
                                E_BOOK_QUERY_EQUALS_SHORT_PHONE_NUMBER,
                                "5423789"),
-                       1,
+                       2,
+                       suites[i].direct,
+                       suites[i].custom,
+                       TRUE);
+
+               /*
+                * Query: 765-5050
+                * +------------------------------+--------------------+
+                * | vCard Data:     408 765-5050 | Matches: Short     |
+                * | vCard Data:  +1 408 765-5050 | Matches: Short     |
+                * | vCard Data: +49 408 765-5050 | Matches: Short     |
+                * +------------------------------+--------------------+
+                */
+               add_client_test (
+                       suites[i].prefix,
+                       "/EqPhone/Short/Another",
+                       suites[i].func,
+                       e_book_query_field_test (
+                               E_CONTACT_TEL,
+                               E_BOOK_QUERY_EQUALS_SHORT_PHONE_NUMBER,
+                               "765-5050"),
+                       3,
                        suites[i].direct,
                        suites[i].custom,
                        TRUE);
diff --git a/tests/libebook/data/vcards/custom-6.vcf b/tests/libebook/data/vcards/custom-6.vcf
index 03f7767..a43da5e 100644
--- a/tests/libebook/data/vcards/custom-6.vcf
+++ b/tests/libebook/data/vcards/custom-6.vcf
@@ -1,5 +1,5 @@
 BEGIN:VCARD
 UID:custom-6
 TEL;HOME:ask Jenny for Lisa's number
-FN:%Strange Name
+FN:%Stran_ge Name
 END:VCARD


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