test-client-custom-summary.c: Adding more tests regarding phone numbers.
authorTristan Van Berkom <tristanvb@openismus.com>
Fri, 22 Feb 2013 12:55:54 +0000 (21:55 +0900)
committerTristan Van Berkom <tristanvb@openismus.com>
Fri, 22 Feb 2013 13:45:29 +0000 (22:45 +0900)
The nature of phone number matching is complex, some additional
tests are required to ensure that this works to spec (perhaps more
tests will be added here as well).

tests/libebook/client/test-client-custom-summary.c
tests/libebook/data/vcards/custom-8.vcf [new file with mode: 0644]
tests/libebook/data/vcards/custom-9.vcf [new file with mode: 0644]

index 49fe9b4..5750b2f 100644 (file)
@@ -36,7 +36,7 @@ typedef struct {
 
 typedef struct {
        ETestServerFixture parent;
-       EContact *contacts[7];
+       EContact *contacts[9];
 } ClientTestFixture;
 
 static void
@@ -142,7 +142,9 @@ setup_book (ClientTestFixture *fixture)
            !add_contact_from_test_case_verify (book_client, "custom-4", it++) ||
            !add_contact_from_test_case_verify (book_client, "custom-5", it++) ||
            !add_contact_from_test_case_verify (book_client, "custom-6", it++) ||
-           !add_contact_from_test_case_verify (book_client, "custom-7", it++)) {
+           !add_contact_from_test_case_verify (book_client, "custom-7", it++) ||
+           !add_contact_from_test_case_verify (book_client, "custom-8", it++) ||
+           !add_contact_from_test_case_verify (book_client, "custom-9", it++)) {
                g_error ("Failed to add contacts");
        }
 
@@ -307,29 +309,71 @@ main (gint argc,
 
 #ifdef ENABLE_PHONENUMBER
 
-               /* field based phone number queries do an index lookup */
-               add_client_test (suites[i].prefix, "/EqPhone/Exact/Phone", suites[i].func,
+               /* 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", 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);
 
-               add_client_test (suites[i].prefix, "/EqPhone/National/Phone", suites[i].func,
+               /*********************************************
+                * E_BOOK_QUERY_EQUALS_NATIONAL_PHONE_NUMBER *
+                *********************************************/
+
+               /* Test that a query term with no specified country returns only vCards that 
+                * are specifically in the active country code.
+                *
+                * | 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: +3-221-5423789 | Matches: no  |
+                */
+               add_client_test (suites[i].prefix, "/EqPhone/National", suites[i].func,
                                 e_book_query_field_test (E_CONTACT_TEL, E_BOOK_QUERY_EQUALS_NATIONAL_PHONE_NUMBER, "221.542.3789"),
                                 1, suites[i].direct, suites[i].custom);
 
-               add_client_test (suites[i].prefix, "/EqPhone/Short/Phone", suites[i].func,
-                                e_book_query_field_test (E_CONTACT_TEL, E_BOOK_QUERY_EQUALS_SHORT_PHONE_NUMBER, "5423789"),
-                                1, suites[i].direct, suites[i].custom);
+               /* 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: +3-221-5423789 | Matches: no |
+                */
+               add_client_test (suites[i].prefix, "/EqPhone/National/CountryMismatch", suites[i].func,
+                                e_book_query_field_test (E_CONTACT_TEL,
+                                                         E_BOOK_QUERY_EQUALS_NATIONAL_PHONE_NUMBER, "+49 221.542.3789"),
+                                0, suites[i].direct, suites[i].custom);
 
-               /* vCard based phone number queries do a table scan */
-               add_client_test (suites[i].prefix, "/EqPhone/Exact/Tel", suites[i].func,
-                                e_book_query_vcard_field_test (EVC_TEL, E_BOOK_QUERY_EQUALS_PHONE_NUMBER, "+1 221.542.3789"),
-                                1, suites[i].direct, suites[i].custom);
-               add_client_test (suites[i].prefix, "/EqPhone/National/Tel", suites[i].func,
-                                e_book_query_vcard_field_test (EVC_TEL, E_BOOK_QUERY_EQUALS_NATIONAL_PHONE_NUMBER, "221.542.3789"),
+
+               /* Test that a query term with the active 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 |
+                */
+               add_client_test (suites[i].prefix, "/EqPhone/National/CountryAbsent/QueryWithCountry", suites[i].func,
+                                e_book_query_field_test (E_CONTACT_TEL,
+                                                         E_BOOK_QUERY_EQUALS_NATIONAL_PHONE_NUMBER, "+1 514-845-8436"),
                                 1, suites[i].direct, suites[i].custom);
-               add_client_test (suites[i].prefix, "/EqPhone/Short/Tel", suites[i].func,
-                                e_book_query_vcard_field_test(EVC_TEL, E_BOOK_QUERY_EQUALS_SHORT_PHONE_NUMBER, "5423789"),
+
+#if 0
+               /* FIXME: This test passes with the default summary, but fails in the custom summary.
+                *
+                * Because EBookBackendSexp uses a straiht-forward e_phone_number_compare_strings() method
+                * of comparison, it's my feeling that the method used in EBookBackendSqliteDB needs to be
+                * fixed (possibly by just using e_phone_number_compare_strings() directly in it's collation rule).
+                */
+
+               /* Test that a query term with an arbitrary country code specified returns a vCard with an unspecified
+                * country code.
+                *
+                * | Active Country Code: +1 | Query: +49 514-845-8436 | vCard Data: 514-845-8436 | Matches: yes |
+                */
+               add_client_test (suites[i].prefix, "/EqPhone/National/CountryAbsent/QueryOtherCountry", suites[i].func,
+                                e_book_query_field_test (E_CONTACT_TEL,
+                                                         E_BOOK_QUERY_EQUALS_NATIONAL_PHONE_NUMBER, "+49 514-845-8436"),
                                 1, suites[i].direct, suites[i].custom);
+#endif
+
+               add_client_test (suites[i].prefix, "/EqPhone/Short", suites[i].func,
+                                e_book_query_field_test (E_CONTACT_TEL, E_BOOK_QUERY_EQUALS_SHORT_PHONE_NUMBER, "5423789"),
+                                2, suites[i].direct, suites[i].custom);
 
 #endif /* ENABLE_PHONENUMBER */
 
diff --git a/tests/libebook/data/vcards/custom-8.vcf b/tests/libebook/data/vcards/custom-8.vcf
new file mode 100644 (file)
index 0000000..50d3f67
--- /dev/null
@@ -0,0 +1,5 @@
+BEGIN:VCARD
+FN:Purple Pony
+TEL;HOME:+3-221-5423789
+EMAIL;TYPE=home,work:purple@pony.com
+END:VCARD
diff --git a/tests/libebook/data/vcards/custom-9.vcf b/tests/libebook/data/vcards/custom-9.vcf
new file mode 100644 (file)
index 0000000..88f9623
--- /dev/null
@@ -0,0 +1,5 @@
+BEGIN:VCARD
+FN:Pink Pony
+TEL;HOME:514-845-8436
+EMAIL;TYPE=home,work:pink@pony.com
+END:VCARD