[evolution-data-server/openismus-work-master: 28/40] Ported test-sqlite-cursor-set-sexp to use the new ICU sorted data.



commit 7bf6b5458dd59fa1781414e565d9f84d70effc1e
Author: Tristan Van Berkom <tristanvb openismus com>
Date:   Tue May 7 21:12:29 2013 +0900

    Ported test-sqlite-cursor-set-sexp to use the new ICU sorted data.

 tests/libedata-book/test-sqlite-cursor-set-sexp.c |  140 +++-----------------
 1 files changed, 21 insertions(+), 119 deletions(-)
---
diff --git a/tests/libedata-book/test-sqlite-cursor-set-sexp.c 
b/tests/libedata-book/test-sqlite-cursor-set-sexp.c
index 50a32e8..473be38 100644
--- a/tests/libedata-book/test-sqlite-cursor-set-sexp.c
+++ b/tests/libedata-book/test-sqlite-cursor-set-sexp.c
@@ -6,103 +6,10 @@
 
 #include "data-test-utils.h"
 
-/* Optimize queries, just so we can run with BOOKSQL_DEBUG=2 and check the
- * indexes are properly leverage for cursor queries
- */
-static void
-setup_custom_book (ESource            *scratch,
-                  ETestServerClosure *closure)
-{
-       ESourceBackendSummarySetup *setup;
-
-       g_type_class_unref (g_type_class_ref (E_TYPE_SOURCE_BACKEND_SUMMARY_SETUP));
-       setup = e_source_get_extension (scratch, E_SOURCE_EXTENSION_BACKEND_SUMMARY_SETUP);
-       e_source_backend_summary_setup_set_summary_fields (setup,
-                                                          E_CONTACT_FAMILY_NAME,
-                                                          E_CONTACT_GIVEN_NAME,
-                                                          E_CONTACT_EMAIL,
-                                                          0);
-       e_source_backend_summary_setup_set_indexed_fields (setup,
-                                                          E_CONTACT_FAMILY_NAME, E_BOOK_INDEX_PREFIX,
-                                                          E_CONTACT_GIVEN_NAME, E_BOOK_INDEX_PREFIX,
-                                                          E_CONTACT_EMAIL, E_BOOK_INDEX_PREFIX,
-                                                          0);
-}
-
-static ETestServerClosure book_closure = { E_TEST_SERVER_ADDRESS_BOOK, setup_custom_book, 0 };
-
-typedef struct {
-       ESqliteDBFixture parent_fixture;
-
-       EbSdbCursor  *cursor;
-
-       EContact *contacts[11];
-} CursorFixture;
-
-static void
-cursor_fixture_setup (CursorFixture *fixture,
-                     gconstpointer  user_data)
-{
-       EContactField sort_fields[] = { E_CONTACT_FAMILY_NAME, E_CONTACT_GIVEN_NAME };
-       EBookSortType sort_types[] = { E_BOOK_SORT_ASCENDING, E_BOOK_SORT_ASCENDING };
-       GError       *error = NULL;
-       EBookClient  *book_client;
-       EContact    **it = fixture->contacts;
-
-       e_sqlitedb_fixture_setup ((ESqliteDBFixture *)fixture, user_data);
-
-       book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
-
-       /* Add contacts... */
-       if (/* N:Jackson;Micheal */
-           !add_contact_from_test_case_verify (book_client, "sorted-1", it++) ||
-           /* N:Jackson;Janet */
-           !add_contact_from_test_case_verify (book_client, "sorted-2", it++) ||
-           /* N:Brown;Bobby */
-           !add_contact_from_test_case_verify (book_client, "sorted-3", it++) ||
-           /* N:Brown;Big Bobby */
-           !add_contact_from_test_case_verify (book_client, "sorted-4", it++) ||
-           /* N:Brown;James */
-           !add_contact_from_test_case_verify (book_client, "sorted-5", it++) ||
-           /* N:%Strange Name;Mister */
-           !add_contact_from_test_case_verify (book_client, "sorted-6", it++) ||
-           /* N:Goose;Purple */
-           !add_contact_from_test_case_verify (book_client, "sorted-7", it++) ||
-           /* N:Pony;Purple */
-           !add_contact_from_test_case_verify (book_client, "sorted-8", it++) ||
-           /* N:Pony;Pink */
-           !add_contact_from_test_case_verify (book_client, "sorted-9", it++) ||
-           /* N:J;Mister */
-           !add_contact_from_test_case_verify (book_client, "sorted-10", it++) ||
-           /* FN:Ye Nameless One */
-           !add_contact_from_test_case_verify (book_client, "sorted-11", it++)) {
-               g_error ("Failed to add contacts");
-       }
-
-       fixture->cursor = e_book_backend_sqlitedb_cursor_new (((ESqliteDBFixture *) fixture)->ebsdb,
-                                                             SQLITEDB_FOLDER_ID,
-                                                             NULL, sort_fields, sort_types, 2, &error);
-
-       g_assert (fixture->cursor != NULL);
-}
+static EbSdbCursorClosure book_closure = { { E_TEST_SERVER_ADDRESS_BOOK, 
e_sqlitedb_cursor_fixture_setup_book, 0 }, FALSE };
 
 static void
-cursor_fixture_teardown (CursorFixture *fixture,
-                        gconstpointer  user_data)
-{
-       gint i;
-
-       for (i = 0; i < G_N_ELEMENTS (fixture->contacts); ++i) {
-               if (fixture->contacts[i])
-                       g_object_unref (fixture->contacts[i]);
-       }
-
-       e_book_backend_sqlitedb_cursor_free (((ESqliteDBFixture *) fixture)->ebsdb, fixture->cursor);
-       e_sqlitedb_fixture_teardown ((ESqliteDBFixture *)fixture, user_data);
-}
-
-static void
-test_cursor_sexp_invalid (CursorFixture *fixture,
+test_cursor_sexp_invalid (EbSdbCursorFixture *fixture,
                          gconstpointer  user_data)
 {
        GError *error = NULL;
@@ -122,7 +29,7 @@ test_cursor_sexp_invalid (CursorFixture *fixture,
 }
 
 static void
-test_cursor_sexp_calculate_position (CursorFixture *fixture,
+test_cursor_sexp_calculate_position (EbSdbCursorFixture *fixture,
                                     gconstpointer  user_data)
 {
        GError *error = NULL;
@@ -130,23 +37,18 @@ test_cursor_sexp_calculate_position (CursorFixture *fixture,
        gint    position = 0, total = 0;
        gchar *sexp = NULL;
 
-       /* Set the cursor to point exactly to Bobby Brown */
+       /* Set the cursor to point exactly to 'blackbirds' */
        e_book_backend_sqlitedb_cursor_set_target_contact (((ESqliteDBFixture *) fixture)->ebsdb,
-                                                          fixture->cursor,
-                                                          fixture->contacts[2]);
+                                                          fixture->cursor, fixture->contacts[16 - 1]);
 
        /* Check position */
        if (!e_book_backend_sqlitedb_cursor_calculate (((ESqliteDBFixture *) fixture)->ebsdb,
                                                       fixture->cursor, &total, &position, &error))
                g_error ("Error calculating cursor: %s", error->message);
 
-       /* Bobby Brown is at position 3, contacts <= Bobby Brown are:
-        *   N:Brown;Bobby
-        *   N:Brown;Big Bobby
-        *   FN:Ye Nameless One
-        */
-       g_assert_cmpint (position, ==, 3);
-       g_assert_cmpint (total, ==, 11);
+       /* blackbird is at position 12 in an unfiltered en_US locale */
+       g_assert_cmpint (position, ==, 12);
+       g_assert_cmpint (total, ==, 20);
 
        /* Set new sexp, only contacts with .com email addresses */
        query = e_book_query_field_test (E_CONTACT_EMAIL, E_BOOK_QUERY_ENDS_WITH, ".com");
@@ -162,12 +64,9 @@ test_cursor_sexp_calculate_position (CursorFixture *fixture,
                                                       fixture->cursor, &total, &position, &error))
                g_error ("Error calculating cursor: %s", error->message);
 
-       /* Bobby Brown is at position 2, filtered contacts <= Bobby Brown are:
-        *   "Bobby Brown"
-        *   "Ye Nameless One"
-        */
-       g_assert_cmpint (position, ==, 2);
-       g_assert_cmpint (total, ==, 8);
+       /* 'blackbird' is now at position 8 out of 13, with a filtered set of contacts in en_US locale */
+       g_assert_cmpint (position, ==, 8);
+       g_assert_cmpint (total, ==, 13);
 }
 
 gint
@@ -180,13 +79,16 @@ main (gint argc,
        g_test_init (&argc, &argv, NULL);
 
        /* Ensure that the client and server get the same locale */
-       g_assert (g_setenv ("LC_ALL", "en_US.UTF-8", TRUE));
-       setlocale (LC_ALL, "");
-
-       g_test_add ("/EbSdbCursor/SetSexp/Invalid", CursorFixture, &book_closure,
-                   cursor_fixture_setup, test_cursor_sexp_invalid, cursor_fixture_teardown);
-       g_test_add ("/EbSdbCursor/SetSexp/CalculatePosition", CursorFixture, &book_closure,
-                   cursor_fixture_setup, test_cursor_sexp_calculate_position, cursor_fixture_teardown);
+       g_assert (g_setenv ("EDS_COLLATE", "en_US.UTF-8", TRUE));
+
+       g_test_add ("/EbSdbCursor/SetSexp/Invalid", EbSdbCursorFixture, &book_closure,
+                   e_sqlitedb_cursor_fixture_setup,
+                   test_cursor_sexp_invalid,
+                   e_sqlitedb_cursor_fixture_teardown);
+       g_test_add ("/EbSdbCursor/SetSexp/CalculatePosition", EbSdbCursorFixture, &book_closure,
+                   e_sqlitedb_cursor_fixture_setup,
+                   test_cursor_sexp_calculate_position,
+                   e_sqlitedb_cursor_fixture_teardown);
 
        return e_test_server_utils_run ();
 }


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