[evolution-data-server/openismus-work-master: 21/134] Ported data migration tests to use the new ICU sorted data.



commit eb2dbf8f3a2c25c62f08c9040d67b462954ac56f
Author: Tristan Van Berkom <tristanvb openismus com>
Date:   Tue May 7 22:00:32 2013 +0900

    Ported data migration tests to use the new ICU sorted data.
    
    Added migration tests also for fr_CA and de_DE locale, the
    de_DE locale expects a @collation=phonebook type of sort order
    but only the test-sqlite-cursor-posix-initial test which creates
    the shared addressbook defines it, so we also test that the
    collation rule is properly stored and introspected in the
    SQLite tables.

 tests/libedata-book/Makefile.am                    |    6 +
 tests/libedata-book/data-test-utils.c              |   25 +++-
 .../test-sqlite-cursor-de-DE-migrated.c            |   44 +++++
 .../test-sqlite-cursor-en-US-migrated.c            |  140 ++--------------
 .../test-sqlite-cursor-fr-CA-migrated.c            |   34 ++++
 .../test-sqlite-cursor-posix-initial.c             |  174 +++-----------------
 .../test-sqlite-cursor-posix-migrated.c            |  141 ++--------------
 7 files changed, 152 insertions(+), 412 deletions(-)
---
diff --git a/tests/libedata-book/Makefile.am b/tests/libedata-book/Makefile.am
index aeeb84f..98726c6 100644
--- a/tests/libedata-book/Makefile.am
+++ b/tests/libedata-book/Makefile.am
@@ -55,6 +55,8 @@ TESTS =                                               \
        test-sqlite-cursor-set-sexp             \
        test-sqlite-cursor-posix-initial        \
        test-sqlite-cursor-en-US-migrated       \
+       test-sqlite-cursor-fr-CA-migrated       \
+       test-sqlite-cursor-de-DE-migrated       \
        test-sqlite-cursor-posix-migrated
 
 
@@ -94,6 +96,10 @@ test_sqlite_cursor_posix_initial_LDADD=$(TEST_LIBS)
 test_sqlite_cursor_posix_initial_CPPFLAGS=$(TEST_CPPFLAGS)
 test_sqlite_cursor_en_US_migrated_LDADD=$(TEST_LIBS)
 test_sqlite_cursor_en_US_migrated_CPPFLAGS=$(TEST_CPPFLAGS)
+test_sqlite_cursor_fr_CA_migrated_LDADD=$(TEST_LIBS)
+test_sqlite_cursor_fr_CA_migrated_CPPFLAGS=$(TEST_CPPFLAGS)
+test_sqlite_cursor_de_DE_migrated_LDADD=$(TEST_LIBS)
+test_sqlite_cursor_de_DE_migrated_CPPFLAGS=$(TEST_CPPFLAGS)
 test_sqlite_cursor_posix_migrated_LDADD=$(TEST_LIBS)
 test_sqlite_cursor_posix_migrated_CPPFLAGS=$(TEST_CPPFLAGS)
 
diff --git a/tests/libedata-book/data-test-utils.c b/tests/libedata-book/data-test-utils.c
index 7267112..7bea05a 100644
--- a/tests/libedata-book/data-test-utils.c
+++ b/tests/libedata-book/data-test-utils.c
@@ -228,6 +228,7 @@ void
 e_sqlitedb_cursor_fixture_setup (EbSdbCursorFixture *fixture,
                                 gconstpointer       user_data)
 {
+       ETestServerFixture *base_fixture = (ETestServerFixture *)fixture;
        EContactField sort_fields[] = { E_CONTACT_FAMILY_NAME, E_CONTACT_GIVEN_NAME };
        EBookSortType sort_types[] = { E_BOOK_SORT_ASCENDING, E_BOOK_SORT_ASCENDING };
        EBookClient *book_client;
@@ -235,6 +236,12 @@ e_sqlitedb_cursor_fixture_setup (EbSdbCursorFixture *fixture,
        GError *error = NULL;
        gint i;
        gchar *sexp = NULL;
+       const gchar *source_name;
+
+       /* Support the migration tests */
+       source_name = g_getenv ("MIGRATION_TEST_SOURCE_NAME");
+       if (source_name != NULL)
+               base_fixture->source_name = g_strdup (source_name);
 
        e_sqlitedb_fixture_setup ((ESqliteDBFixture *)fixture, user_data);
 
@@ -254,8 +261,17 @@ e_sqlitedb_cursor_fixture_setup (EbSdbCursorFixture *fixture,
                fixture->contacts[i] = contact;
        }
 
-       if (!e_book_client_add_contacts_sync (book_client, contacts, NULL, NULL, &error))
-               g_error ("Failed to add test contacts");
+       if (!e_book_client_add_contacts_sync (book_client, contacts, NULL, NULL, &error)) { 
+
+               /* Dont complain here, we re-use the same addressbook for multiple tests
+                * and we can't add the same contacts twice
+                */
+               if (g_error_matches (error, E_BOOK_CLIENT_ERROR,
+                                    E_BOOK_CLIENT_ERROR_CONTACT_ID_ALREADY_EXISTS))
+                       g_clear_error (&error);
+               else
+                       g_error ("Failed to add test contacts: %s", error->message);
+       }
 
        g_slist_free (contacts);
 
@@ -270,7 +286,6 @@ e_sqlitedb_cursor_fixture_setup (EbSdbCursorFixture *fixture,
                                                              SQLITEDB_FOLDER_ID,
                                                              sexp, sort_fields, sort_types, 2, &error);
 
-
        g_free (sexp);
 
        g_assert (fixture->cursor != NULL);
@@ -396,6 +411,10 @@ move_by_test_new_internal (const gchar *test_path,
        data->path = g_strdup (test_path);
        data->struct_size = struct_size;
 
+       /* Keep the work dir for migration tests */
+       if (g_getenv ("MIGRATION_TEST_SOURCE_NAME") != NULL)
+           data->parent.parent.keep_work_directory = TRUE;
+
        return data;
 }
 
diff --git a/tests/libedata-book/test-sqlite-cursor-de-DE-migrated.c 
b/tests/libedata-book/test-sqlite-cursor-de-DE-migrated.c
new file mode 100644
index 0000000..11692d2
--- /dev/null
+++ b/tests/libedata-book/test-sqlite-cursor-de-DE-migrated.c
@@ -0,0 +1,44 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+#include <stdlib.h>
+#include <locale.h>
+#include <libebook/libebook.h>
+
+#include "data-test-utils.h"
+
+gint
+main (gint argc,
+      gchar **argv)
+{
+       MoveByData *data;
+
+#if !GLIB_CHECK_VERSION (2, 35, 1)
+       g_type_init ();
+#endif
+       g_test_init (&argc, &argv, NULL);
+
+       /* Ensure that the client and server get the same locale */
+       g_assert (g_setenv ("EDS_COLLATE", "de_DE.UTF-8", TRUE));
+       g_assert (g_setenv ("MIGRATION_TEST_SOURCE_NAME", "migration-test-source", TRUE));
+
+       /* Here we rely on the initial addressbook book created by
+        * test-sqlite-cursor-posix-initial, which created the addressbook
+        * with the phonebook collation rule.
+        *
+        * Here we assert that the SQLite introspection works properly after
+        * a migration, and the recorded SQLite collation names are used instead of the
+        * parameters when opening the addressbook (since we pass FALSE here
+        * to move_by_test_new(), we create our addressbook with no special collation rule).
+        */
+       data = move_by_test_new ("/EbSdbCursor/Locale/de_DE/Migrated", FALSE);
+
+       /* Assert the whole set of contacts */
+       move_by_test_add_assertion (data, 5, 11, 1,  2,  5,  6);
+       move_by_test_add_assertion (data, 5, 7,  8,  4,  3,  15);
+       move_by_test_add_assertion (data, 5, 17, 16, 18, 10, 14);
+       move_by_test_add_assertion (data, 5, 12, 13, 9,  20, 19);
+       move_by_test_add (data, FALSE);
+
+       /* On this case, we are using the migrated addressbook, don't delete it first */
+       return e_test_server_utils_run_full (E_TEST_SERVER_KEEP_WORK_DIRECTORY);
+}
diff --git a/tests/libedata-book/test-sqlite-cursor-en-US-migrated.c 
b/tests/libedata-book/test-sqlite-cursor-en-US-migrated.c
index 350e69a..dd0a098 100644
--- a/tests/libedata-book/test-sqlite-cursor-en-US-migrated.c
+++ b/tests/libedata-book/test-sqlite-cursor-en-US-migrated.c
@@ -6,144 +6,30 @@
 
 #include "data-test-utils.h"
 
-static ETestServerClosure book_closure = { E_TEST_SERVER_ADDRESS_BOOK, NULL, 0, TRUE, NULL };
-
-typedef struct {
-       ESqliteDBFixture parent_fixture;
-
-       EbSdbCursor  *cursor;
-
-       EContact *contacts[11];
-} CursorFixture;
-
-static void
-cursor_fixture_setup (CursorFixture *fixture,
-                     gconstpointer  user_data)
-{
-       ETestServerFixture *base_fixture = (ETestServerFixture *)fixture;
-       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;
-       gint          i = 0;
-
-       base_fixture->source_name = g_strdup ("locale-test-source");
-
-       e_sqlitedb_fixture_setup ((ESqliteDBFixture *)fixture, user_data);
-
-       /* Load contacts... */
-       if (/* N:Jackson;Micheal */
-           (fixture->contacts[i++] = new_contact_from_test_case ("sorted-1")) == NULL ||
-           /* N:Jackson;Janet */
-           (fixture->contacts[i++] = new_contact_from_test_case ("sorted-2")) == NULL ||
-           /* N:Brown;Bobby */
-           (fixture->contacts[i++] = new_contact_from_test_case ("sorted-3")) == NULL ||
-           /* N:Brown;Big Bobby */
-           (fixture->contacts[i++] = new_contact_from_test_case ("sorted-4")) == NULL ||
-           /* N:Brown;James */
-           (fixture->contacts[i++] = new_contact_from_test_case ("sorted-5")) == NULL ||
-           /* N:%Strange Name;Mister */
-           (fixture->contacts[i++] = new_contact_from_test_case ("sorted-6")) == NULL ||
-           /* N:Goose;Purple */
-           (fixture->contacts[i++] = new_contact_from_test_case ("sorted-7")) == NULL ||
-           /* N:Pony;Purple */
-           (fixture->contacts[i++] = new_contact_from_test_case ("sorted-8")) == NULL ||
-           /* N:Pony;Pink */
-           (fixture->contacts[i++] = new_contact_from_test_case ("sorted-9")) == NULL ||
-           /* N:J;Mister */
-           (fixture->contacts[i++] = new_contact_from_test_case ("sorted-10")) == NULL ||
-           /* FN:Ye Nameless One */
-           (fixture->contacts[i++] = new_contact_from_test_case ("sorted-11")) == NULL)
-               g_error ("Failed to load 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 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);
-}
-
-/********************** FetchResults **********************/
-static void
-test_cursor_fetch (CursorFixture *fixture,
-                  gconstpointer  user_data)
-{
-       GSList *results;
-       GError *error = NULL;
-
-       /* First batch */
-       results = e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
-                                                         fixture->cursor, 11, &error);
-
-       if (error)
-               g_error ("Error fetching cursor results: %s", error->message);
-
-       print_results (results);
-
-       g_assert_cmpint (g_slist_length (results), ==, 11);
-
-       /* Assert that we got the results ordered in POSIX locale:
-        */
-       assert_contacts_order (results,
-                              /* FN:Ye Nameless One */
-                              e_contact_get_const (fixture->contacts[10], E_CONTACT_UID),
-                              /* N:Brown;Big Bobby */
-                              e_contact_get_const (fixture->contacts[3], E_CONTACT_UID),
-                              /* N:Brown;Bobby */
-                              e_contact_get_const (fixture->contacts[2], E_CONTACT_UID),
-                              /* N:Brown;James */
-                              e_contact_get_const (fixture->contacts[4], E_CONTACT_UID),
-                              /* N:Goose;Purple */
-                              e_contact_get_const (fixture->contacts[6], E_CONTACT_UID),
-                              /* N:J;Mister */
-                              e_contact_get_const (fixture->contacts[9], E_CONTACT_UID),
-                              /* N:Jackson;Janet */
-                              e_contact_get_const (fixture->contacts[1], E_CONTACT_UID),
-                              /* N:Jackson;Micheal */
-                              e_contact_get_const (fixture->contacts[0], E_CONTACT_UID),
-                              /* N:Pony;Pink */
-                              e_contact_get_const (fixture->contacts[8], E_CONTACT_UID),
-                              /* N:Pony;Purple */
-                              e_contact_get_const (fixture->contacts[7], E_CONTACT_UID),
-                              /* N:%Strange Name;Mister */
-                              e_contact_get_const (fixture->contacts[5], E_CONTACT_UID),
-                              NULL);
-
-       g_slist_foreach (results, (GFunc)e_book_backend_sqlitedb_search_data_free, NULL);
-       g_slist_free (results);
-}
 
 gint
 main (gint argc,
       gchar **argv)
 {
+       MoveByData *data;
+
 #if !GLIB_CHECK_VERSION (2, 35, 1)
        g_type_init ();
 #endif
        g_test_init (&argc, &argv, NULL);
 
-       /* Run the addressbook in en_US-UTF-8 locale, causing a migration
-        * of collation keys and a changed sort order
-        */
-       g_assert (g_setenv ("LC_ALL", "en_US.UTF-8", TRUE));
-       setlocale (LC_ALL, "");
+       /* Ensure that the client and server get the same locale */
+       g_assert (g_setenv ("EDS_COLLATE", "en_US.UTF-8", TRUE));
+       g_assert (g_setenv ("MIGRATION_TEST_SOURCE_NAME", "migration-test-source", TRUE));
 
-       g_test_add ("/EbSdbCursor/Locale/en_US/Migrated", CursorFixture, &book_closure,
-                   cursor_fixture_setup, test_cursor_fetch, cursor_fixture_teardown);
+       /* Try them all once in the normal base locale */
+       data = move_by_test_new ("/EbSdbCursor/Locale/en_US/Migrated", FALSE);
+       move_by_test_add_assertion (data, 5, 11, 1,  2,  5,  6);
+       move_by_test_add_assertion (data, 5, 4,  3,  7,  8,  15);
+       move_by_test_add_assertion (data, 5, 17, 16, 18, 10, 14);
+       move_by_test_add_assertion (data, 5, 12, 13, 9,  19, 20);
+       move_by_test_add (data, FALSE);
 
+       /* On this case, we are using the migrated addressbook, don't delete it first */
        return e_test_server_utils_run_full (E_TEST_SERVER_KEEP_WORK_DIRECTORY);
 }
diff --git a/tests/libedata-book/test-sqlite-cursor-fr-CA-migrated.c 
b/tests/libedata-book/test-sqlite-cursor-fr-CA-migrated.c
new file mode 100644
index 0000000..932e7c6
--- /dev/null
+++ b/tests/libedata-book/test-sqlite-cursor-fr-CA-migrated.c
@@ -0,0 +1,34 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+#include <stdlib.h>
+#include <locale.h>
+#include <libebook/libebook.h>
+
+#include "data-test-utils.h"
+
+gint
+main (gint argc,
+      gchar **argv)
+{
+       MoveByData *data;
+
+#if !GLIB_CHECK_VERSION (2, 35, 1)
+       g_type_init ();
+#endif
+       g_test_init (&argc, &argv, NULL);
+
+       /* Ensure that the client and server get the same locale */
+       g_assert (g_setenv ("EDS_COLLATE", "fr_CA.UTF-8", TRUE));
+       g_assert (g_setenv ("MIGRATION_TEST_SOURCE_NAME", "migration-test-source", TRUE));
+
+       /* Assert the whole set of contacts */
+       data = move_by_test_new ("/EbSdbCursor/Locale/fr_CA/Migrated", FALSE);
+       move_by_test_add_assertion (data, 5, 11, 1,  2,  5,  6);
+       move_by_test_add_assertion (data, 5, 4,  3,  7,  8,  15);
+       move_by_test_add_assertion (data, 5, 17, 16, 18, 10, 14);
+       move_by_test_add_assertion (data, 5, 13, 12, 9,  19, 20);
+       move_by_test_add (data, FALSE);
+
+       /* On this case, we are using the migrated addressbook, don't delete it first */
+       return e_test_server_utils_run_full (E_TEST_SERVER_KEEP_WORK_DIRECTORY);
+}
diff --git a/tests/libedata-book/test-sqlite-cursor-posix-initial.c 
b/tests/libedata-book/test-sqlite-cursor-posix-initial.c
index ded5bf9..d3ba0a4 100644
--- a/tests/libedata-book/test-sqlite-cursor-posix-initial.c
+++ b/tests/libedata-book/test-sqlite-cursor-posix-initial.c
@@ -6,170 +6,36 @@
 
 #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, TRUE, NULL };
-
-typedef struct {
-       ESqliteDBFixture parent_fixture;
-
-       EbSdbCursor  *cursor;
-
-       EContact *contacts[11];
-} CursorFixture;
-
-static void
-cursor_fixture_setup (CursorFixture *fixture,
-                     gconstpointer  user_data)
-{
-       ETestServerFixture *base_fixture = (ETestServerFixture *)fixture;
-       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;
-
-       base_fixture->source_name = g_strdup ("locale-test-source");
-
-       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 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);
-}
-
-/********************** FetchResults **********************/
-static void
-test_cursor_fetch (CursorFixture *fixture,
-                  gconstpointer  user_data)
-{
-       GSList *results;
-       GError *error = NULL;
-
-       /* First batch */
-       results = e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
-                                                         fixture->cursor, 11, &error);
-
-       if (error)
-               g_error ("Error fetching cursor results: %s", error->message);
-
-       print_results (results);
-
-       g_assert_cmpint (g_slist_length (results), ==, 11);
-
-       /* Assert that we got the results ordered in POSIX locale:
-        */
-       assert_contacts_order (results,
-                              /* FN:Ye Nameless One */
-                              e_contact_get_const (fixture->contacts[10], E_CONTACT_UID),
-                              /* N:%Strange Name;Mister */
-                              e_contact_get_const (fixture->contacts[5], E_CONTACT_UID),
-                              /* N:Brown;Big Bobby */
-                              e_contact_get_const (fixture->contacts[3], E_CONTACT_UID),
-                              /* N:Brown;Bobby */
-                              e_contact_get_const (fixture->contacts[2], E_CONTACT_UID),
-                              /* N:Brown;James */
-                              e_contact_get_const (fixture->contacts[4], E_CONTACT_UID),
-                              /* N:Goose;Purple */
-                              e_contact_get_const (fixture->contacts[6], E_CONTACT_UID),
-                              /* N:J;Mister */
-                              e_contact_get_const (fixture->contacts[9], E_CONTACT_UID),
-                              /* N:Jackson;Janet */
-                              e_contact_get_const (fixture->contacts[1], E_CONTACT_UID),
-                              /* N:Jackson;Micheal */
-                              e_contact_get_const (fixture->contacts[0], E_CONTACT_UID),
-                              /* N:Pony;Pink */
-                              e_contact_get_const (fixture->contacts[8], E_CONTACT_UID),
-                              /* N:Pony;Purple */
-                              e_contact_get_const (fixture->contacts[7], E_CONTACT_UID),
-                              NULL);
-
-       g_slist_foreach (results, (GFunc)e_book_backend_sqlitedb_search_data_free, NULL);
-       g_slist_free (results);
-}
-
 gint
 main (gint argc,
       gchar **argv)
 {
+       MoveByData *data;
+
 #if !GLIB_CHECK_VERSION (2, 35, 1)
        g_type_init ();
 #endif
        g_test_init (&argc, &argv, NULL);
 
        /* Ensure that the client and server get the same locale */
-       g_assert (g_setenv ("LC_ALL", "POSIX", TRUE));
-       setlocale (LC_ALL, "");
-
-       g_test_add ("/EbSdbCursor/Locale/POSIX/Initial", CursorFixture, &book_closure,
-                   cursor_fixture_setup, test_cursor_fetch, cursor_fixture_teardown);
+       g_assert (g_setenv ("EDS_COLLATE", "POSIX", TRUE));
+       g_assert (g_setenv ("MIGRATION_TEST_SOURCE_NAME", "migration-test-source", TRUE));
+
+       /* When creating the addressbook, declare it with collation_type = "phonebook",
+        * note that other tests dont specify this, however the de_DE needs phonebook collation.
+        *
+        * In this way, we also assert that the SQLite introspection works properly after
+        * a migration, and the recorded SQLite collation names are used instead of the
+        * parameters when opening the addressbook.
+        */
+       data = move_by_test_new ("/EbSdbCursor/Locale/POSIX/Initial", TRUE);
+
+       /* Assert the whole set of contacts */
+       move_by_test_add_assertion (data, 5, 11, 2,  6,  3,  8);
+       move_by_test_add_assertion (data, 5, 10, 19, 20, 1,  5);
+       move_by_test_add_assertion (data, 5, 4,  7,  15, 17, 16);
+       move_by_test_add_assertion (data, 5, 18, 14, 12, 13, 9);
+       move_by_test_add (data, FALSE);
 
        /* On this case, we want to delete the work directory and start afresh */
        return e_test_server_utils_run ();
diff --git a/tests/libedata-book/test-sqlite-cursor-posix-migrated.c 
b/tests/libedata-book/test-sqlite-cursor-posix-migrated.c
index 3e75e65..a6f2799 100644
--- a/tests/libedata-book/test-sqlite-cursor-posix-migrated.c
+++ b/tests/libedata-book/test-sqlite-cursor-posix-migrated.c
@@ -6,144 +6,29 @@
 
 #include "data-test-utils.h"
 
-static ETestServerClosure book_closure = { E_TEST_SERVER_ADDRESS_BOOK, NULL, 0, TRUE, NULL };
-
-typedef struct {
-       ESqliteDBFixture parent_fixture;
-
-       EbSdbCursor  *cursor;
-
-       EContact *contacts[11];
-} CursorFixture;
-
-static void
-cursor_fixture_setup (CursorFixture *fixture,
-                     gconstpointer  user_data)
-{
-       ETestServerFixture *base_fixture = (ETestServerFixture *)fixture;
-       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;
-       gint          i = 0;
-
-       base_fixture->source_name = g_strdup ("locale-test-source");
-
-       e_sqlitedb_fixture_setup ((ESqliteDBFixture *)fixture, user_data);
-
-       /* Load contacts... */
-       if (/* N:Jackson;Micheal */
-           (fixture->contacts[i++] = new_contact_from_test_case ("sorted-1")) == NULL ||
-           /* N:Jackson;Janet */
-           (fixture->contacts[i++] = new_contact_from_test_case ("sorted-2")) == NULL ||
-           /* N:Brown;Bobby */
-           (fixture->contacts[i++] = new_contact_from_test_case ("sorted-3")) == NULL ||
-           /* N:Brown;Big Bobby */
-           (fixture->contacts[i++] = new_contact_from_test_case ("sorted-4")) == NULL ||
-           /* N:Brown;James */
-           (fixture->contacts[i++] = new_contact_from_test_case ("sorted-5")) == NULL ||
-           /* N:%Strange Name;Mister */
-           (fixture->contacts[i++] = new_contact_from_test_case ("sorted-6")) == NULL ||
-           /* N:Goose;Purple */
-           (fixture->contacts[i++] = new_contact_from_test_case ("sorted-7")) == NULL ||
-           /* N:Pony;Purple */
-           (fixture->contacts[i++] = new_contact_from_test_case ("sorted-8")) == NULL ||
-           /* N:Pony;Pink */
-           (fixture->contacts[i++] = new_contact_from_test_case ("sorted-9")) == NULL ||
-           /* N:J;Mister */
-           (fixture->contacts[i++] = new_contact_from_test_case ("sorted-10")) == NULL ||
-           /* FN:Ye Nameless One */
-           (fixture->contacts[i++] = new_contact_from_test_case ("sorted-11")) == NULL)
-               g_error ("Failed to load 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 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);
-}
-
-/********************** FetchResults **********************/
-static void
-test_cursor_fetch (CursorFixture *fixture,
-                  gconstpointer  user_data)
-{
-       GSList *results;
-       GError *error = NULL;
-
-       /* First batch */
-       results = e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
-                                                         fixture->cursor, 11, &error);
-
-       if (error)
-               g_error ("Error fetching cursor results: %s", error->message);
-
-       print_results (results);
-
-       g_assert_cmpint (g_slist_length (results), ==, 11);
-
-       /* Assert that we got the results ordered in POSIX locale:
-        */
-       assert_contacts_order (results,
-                              /* FN:Ye Nameless One */
-                              e_contact_get_const (fixture->contacts[10], E_CONTACT_UID),
-                              /* N:%Strange Name;Mister */
-                              e_contact_get_const (fixture->contacts[5], E_CONTACT_UID),
-                              /* N:Brown;Big Bobby */
-                              e_contact_get_const (fixture->contacts[3], E_CONTACT_UID),
-                              /* N:Brown;Bobby */
-                              e_contact_get_const (fixture->contacts[2], E_CONTACT_UID),
-                              /* N:Brown;James */
-                              e_contact_get_const (fixture->contacts[4], E_CONTACT_UID),
-                              /* N:Goose;Purple */
-                              e_contact_get_const (fixture->contacts[6], E_CONTACT_UID),
-                              /* N:J;Mister */
-                              e_contact_get_const (fixture->contacts[9], E_CONTACT_UID),
-                              /* N:Jackson;Janet */
-                              e_contact_get_const (fixture->contacts[1], E_CONTACT_UID),
-                              /* N:Jackson;Micheal */
-                              e_contact_get_const (fixture->contacts[0], E_CONTACT_UID),
-                              /* N:Pony;Pink */
-                              e_contact_get_const (fixture->contacts[8], E_CONTACT_UID),
-                              /* N:Pony;Purple */
-                              e_contact_get_const (fixture->contacts[7], E_CONTACT_UID),
-                              NULL);
-
-       g_slist_foreach (results, (GFunc)e_book_backend_sqlitedb_search_data_free, NULL);
-       g_slist_free (results);
-}
-
 gint
 main (gint argc,
       gchar **argv)
 {
+       MoveByData *data;
+
 #if !GLIB_CHECK_VERSION (2, 35, 1)
        g_type_init ();
 #endif
        g_test_init (&argc, &argv, NULL);
 
-       /* Run the addressbook in POSIX locale, causing a migration
-        * of collation keys back to posix locale
-        */
-       g_assert (g_setenv ("LC_ALL", "POSIX", TRUE));
-       setlocale (LC_ALL, "");
+       /* Ensure that the client and server get the same locale */
+       g_assert (g_setenv ("EDS_COLLATE", "POSIX", TRUE));
+       g_assert (g_setenv ("MIGRATION_TEST_SOURCE_NAME", "migration-test-source", TRUE));
 
-       g_test_add ("/EbSdbCursor/Locale/POSIX/Migrated", CursorFixture, &book_closure,
-                   cursor_fixture_setup, test_cursor_fetch, cursor_fixture_teardown);
+       /* Assert the whole set of contacts */
+       data = move_by_test_new ("/EbSdbCursor/Locale/POSIX/Migrated", FALSE);
+       move_by_test_add_assertion (data, 5, 11, 2,  6,  3,  8);
+       move_by_test_add_assertion (data, 5, 10, 19, 20, 1,  5);
+       move_by_test_add_assertion (data, 5, 4,  7,  15, 17, 16);
+       move_by_test_add_assertion (data, 5, 18, 14, 12, 13, 9);
+       move_by_test_add (data, FALSE);
 
+       /* On this case, we are using the migrated addressbook, don't delete it first */
        return e_test_server_utils_run_full (E_TEST_SERVER_KEEP_WORK_DIRECTORY);
 }


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