[evolution-data-server/openismus-work-master: 13/118] Added tests to ensure that localized data is properly migrated.



commit c74af17c4b583a907aae81a0e26d722a706c7103
Author: Tristan Van Berkom <tristanvb openismus com>
Date:   Fri Apr 19 19:49:38 2013 +0900

    Added tests to ensure that localized data is properly migrated.
    
    The added tests must run in the order specified in the Makefile:
      o test-sqlite-cursor-posix-initial
    
        Creates an addressbook sorted in POSIX locale and asserts that
        contacts are sorted in basic POSIX locale
    
      o test-sqlite-cursor-en-US-migrated
    
        Loads the existing address book in en_US-UTF-8 locale and asserts
        that contacts are sorted in the en_US-UTF-8 locale
    
      o test-sqlite-cursor-posix-migrated
    
        Loads the existing address book in POSIX locale again and asserts
        that contacts are sorted in the POSIX locale

 tests/libedata-book/Makefile.am                    |   21 +++-
 tests/libedata-book/data-test-utils.c              |   20 ++-
 tests/libedata-book/data-test-utils.h              |    3 +-
 .../test-sqlite-cursor-en-US-migrated.c            |  149 +++++++++++++++++
 .../test-sqlite-cursor-posix-initial.c             |  176 ++++++++++++++++++++
 .../test-sqlite-cursor-posix-migrated.c            |  149 +++++++++++++++++
 6 files changed, 512 insertions(+), 6 deletions(-)
---
diff --git a/tests/libedata-book/Makefile.am b/tests/libedata-book/Makefile.am
index af42949..c579dd3 100644
--- a/tests/libedata-book/Makefile.am
+++ b/tests/libedata-book/Makefile.am
@@ -35,13 +35,26 @@ libdata_test_utils_la_LIBADD =                              \
        $(NULL)
 
 # Should be kept ordered approximately from least to most difficult/complex
+#
+# Note that these tests must be run in order:
+#   test-sqlite-cursor-posix-initial,
+#   test-sqlite-cursor-en-US-migrated,
+#   test-sqlite-cursor-posix-migrated
+#
+# This is because each migrated test changes the
+# locale and reloads the same addressbook of the previous test. 
 TESTS =                                        \
        test-sqlite-get-contact         \
        test-sqlite-create-cursor       \
        test-sqlite-cursor-move-by      \
        test-sqlite-cursor-set-target   \
        test-sqlite-cursor-calculate    \
-       test-sqlite-cursor-set-sexp
+       test-sqlite-cursor-set-sexp     \
+       test-sqlite-cursor-posix-initial        \
+       test-sqlite-cursor-en-US-migrated       \
+       test-sqlite-cursor-posix-migrated
+
+
 
 noinst_PROGRAMS = $(TESTS)
 
@@ -69,5 +82,11 @@ test_sqlite_cursor_calculate_LDADD=$(TEST_LIBS)
 test_sqlite_cursor_calculate_CPPFLAGS=$(TEST_CPPFLAGS)
 test_sqlite_cursor_set_sexp_LDADD=$(TEST_LIBS)
 test_sqlite_cursor_set_sexp_CPPFLAGS=$(TEST_CPPFLAGS)
+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_posix_migrated_LDADD=$(TEST_LIBS)
+test_sqlite_cursor_posix_migrated_CPPFLAGS=$(TEST_CPPFLAGS)
 
 -include $(top_srcdir)/git.mk
diff --git a/tests/libedata-book/data-test-utils.c b/tests/libedata-book/data-test-utils.c
index 00749a6..ccaee22 100644
--- a/tests/libedata-book/data-test-utils.c
+++ b/tests/libedata-book/data-test-utils.c
@@ -58,6 +58,20 @@ new_vcard_from_test_case (const gchar *case_name)
        return vcard;
 }
 
+EContact *
+new_contact_from_test_case (const gchar *case_name)
+{
+       gchar *vcard;
+       EContact *contact = NULL;
+
+       vcard = new_vcard_from_test_case (case_name);
+       if (vcard)
+               contact = e_contact_new_from_vcard (vcard);
+       g_free (vcard);
+
+       return contact;
+}
+
 static gboolean
 contacts_are_equal_shallow (EContact *a,
                             EContact *b)
@@ -83,15 +97,13 @@ add_contact_from_test_case_verify (EBookClient *book_client,
                                    const gchar *case_name,
                                    EContact **contact)
 {
-       gchar *vcard;
        EContact *contact_orig;
        EContact *contact_final;
        gchar *uid;
        GError *error = NULL;
 
-       vcard = new_vcard_from_test_case (case_name);
-       contact_orig = e_contact_new_from_vcard (vcard);
-       g_free (vcard);
+       contact_orig = new_contact_from_test_case (case_name);
+
        if (!e_book_client_add_contact_sync (book_client, contact_orig, &uid, NULL, &error))
                g_error ("Failed to add contact: %s", error->message);
 
diff --git a/tests/libedata-book/data-test-utils.h b/tests/libedata-book/data-test-utils.h
index a89059a..f1b3d97 100644
--- a/tests/libedata-book/data-test-utils.h
+++ b/tests/libedata-book/data-test-utils.h
@@ -40,7 +40,8 @@ void     e_sqlitedb_fixture_teardown       (ESqliteDBFixture *fixture,
                                            gconstpointer     user_data);
 
 
-gchar   *new_vcard_from_test_case          (const gchar *case_name);
+gchar    *new_vcard_from_test_case         (const gchar *case_name);
+EContact *new_contact_from_test_case       (const gchar *case_name);
 
 gboolean add_contact_from_test_case_verify (EBookClient *book_client,
                                            const gchar *case_name,
diff --git a/tests/libedata-book/test-sqlite-cursor-en-US-migrated.c 
b/tests/libedata-book/test-sqlite-cursor-en-US-migrated.c
new file mode 100644
index 0000000..350e69a
--- /dev/null
+++ b/tests/libedata-book/test-sqlite-cursor-en-US-migrated.c
@@ -0,0 +1,149 @@
+/* -*- 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"
+
+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)
+{
+#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, "");
+
+       g_test_add ("/EbSdbCursor/Locale/en_US/Migrated", CursorFixture, &book_closure,
+                   cursor_fixture_setup, test_cursor_fetch, cursor_fixture_teardown);
+
+       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
new file mode 100644
index 0000000..ded5bf9
--- /dev/null
+++ b/tests/libedata-book/test-sqlite-cursor-posix-initial.c
@@ -0,0 +1,176 @@
+/* -*- 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"
+
+/* 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)
+{
+#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);
+
+       /* 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
new file mode 100644
index 0000000..3e75e65
--- /dev/null
+++ b/tests/libedata-book/test-sqlite-cursor-posix-migrated.c
@@ -0,0 +1,149 @@
+/* -*- 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"
+
+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)
+{
+#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, "");
+
+       g_test_add ("/EbSdbCursor/Locale/POSIX/Migrated", CursorFixture, &book_closure,
+                   cursor_fixture_setup, test_cursor_fetch, cursor_fixture_teardown);
+
+       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]