[evolution-data-server/openismus-work-master: 120/137] Low Level Cursor API tests: Cursor move API changed to return number of contacts traversed.



commit 4d4ff6c144e81df3c58bba2568130a697fcd1c82
Author: Tristan Van Berkom <tristanvb openismus com>
Date:   Sun Oct 13 04:11:51 2013 +0200

    Low Level Cursor API tests: Cursor move API changed to return number of contacts traversed.

 tests/libedata-book/data-test-utils.c              |   47 +++++----
 tests/libedata-book/test-sqlite-cursor-calculate.c |  110 ++++++++++----------
 .../libedata-book/test-sqlite-cursor-set-target.c  |   32 +++---
 3 files changed, 98 insertions(+), 91 deletions(-)
---
diff --git a/tests/libedata-book/data-test-utils.c b/tests/libedata-book/data-test-utils.c
index b5f3ffc..827f17c 100644
--- a/tests/libedata-book/data-test-utils.c
+++ b/tests/libedata-book/data-test-utils.c
@@ -158,7 +158,7 @@ open_sqlitedb (ESourceRegistry *registry,
               ESource         *source)
 {
        EBookBackendSqliteDB *ebsdb;
-       GError *error;
+       GError *error = NULL;
        gchar *dirname;
 
        dirname = get_addressbook_directory (registry, source);
@@ -549,11 +549,14 @@ static void
 assert_move_by (EbSdbCursorFixture *fixture,
                MoveByData *data,
                gint i,
-               GSList *results)
+               GSList *results,
+               gint n_results)
 {
        GSList *uids = NULL;
        gint j, expected = 0;
 
+       g_assert_cmpint (g_slist_length (results), ==, n_results);
+
        /* Count the number of really expected results */
        for (j = 0; j < ABS (data->counts[i]); j++) {
                gint index = data->expected[i][j];
@@ -604,6 +607,7 @@ test_move_by (EbSdbCursorFixture *fixture,
        gint i;
        gint expected_position = 0, position;
        gint total;
+       gint n_results;
 
        total = data->filtered ? N_FILTERED_CONTACTS : N_SORTED_CONTACTS;
 
@@ -619,15 +623,16 @@ test_move_by (EbSdbCursorFixture *fixture,
                        expected_position = 0;
 
                /* Try normal order */
-               if (!e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
-                                                            fixture->cursor,
-                                                            EBSDB_CURSOR_ORIGIN_CURRENT,
-                                                            data->counts[i],
-                                                            &results, &error))
+               n_results = e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
+                                                                   fixture->cursor,
+                                                                   EBSDB_CURSOR_ORIGIN_CURRENT,
+                                                                   data->counts[i],
+                                                                   &results, &error);
+               if (n_results < 0)
                        g_error ("Error fetching cursor results: %s", error->message);
 
                print_results (results);
-               assert_move_by (fixture, data, i, results);
+               assert_move_by (fixture, data, i, results, n_results);
                g_slist_foreach (results, (GFunc)e_book_backend_sqlitedb_search_data_free, NULL);
                g_slist_free (results);
                results = NULL;
@@ -638,15 +643,16 @@ test_move_by (EbSdbCursorFixture *fixture,
                g_assert_cmpint (expected_position, ==, position);
 
                /* Try repeat last query */
-               if (!e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
-                                                            fixture->cursor,
-                                                            EBSDB_CURSOR_ORIGIN_PREVIOUS,
-                                                            data->counts[i],
-                                                            &results, &error))
+               n_results = e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
+                                                                   fixture->cursor,
+                                                                   EBSDB_CURSOR_ORIGIN_PREVIOUS,
+                                                                   data->counts[i],
+                                                                   &results, &error);
+               if (n_results < 0)
                        g_error ("Error fetching cursor results: %s", error->message);
 
                print_results (results);
-               assert_move_by (fixture, data, i, results);
+               assert_move_by (fixture, data, i, results, n_results);
                g_slist_foreach (results, (GFunc)e_book_backend_sqlitedb_search_data_free, NULL);
                g_slist_free (results);
                results = NULL;
@@ -658,15 +664,16 @@ test_move_by (EbSdbCursorFixture *fixture,
        }
 
        /* One more, test reset API, the first batch from the beginning */
-       if (!e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
-                                                    fixture->cursor,
-                                                    EBSDB_CURSOR_ORIGIN_RESET,
-                                                    data->counts[0],
-                                                    &results, &error))
+       n_results = e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
+                                                           fixture->cursor,
+                                                           EBSDB_CURSOR_ORIGIN_RESET,
+                                                           data->counts[0],
+                                                           &results, &error);
+       if (n_results < 0)
                g_error ("Error fetching cursor results: %s", error->message);
 
        print_results (results);
-       assert_move_by (fixture, data, 0, results);
+       assert_move_by (fixture, data, 0, results, n_results);
        g_slist_foreach (results, (GFunc)e_book_backend_sqlitedb_search_data_free, NULL);
        g_slist_free (results);
        results = NULL;
diff --git a/tests/libedata-book/test-sqlite-cursor-calculate.c 
b/tests/libedata-book/test-sqlite-cursor-calculate.c
index 2d1621f..2ecdb4b 100644
--- a/tests/libedata-book/test-sqlite-cursor-calculate.c
+++ b/tests/libedata-book/test-sqlite-cursor-calculate.c
@@ -42,11 +42,11 @@ test_cursor_calculate_move_forward (EbSdbCursorFixture *fixture,
        gint    position = 0, total = 0;
 
        /* Move cursor */
-       if (!e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
-                                                    fixture->cursor,
-                                                    EBSDB_CURSOR_ORIGIN_CURRENT,
-                                                    5,
-                                                    &results, &error))
+       if (e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
+                                                   fixture->cursor,
+                                                   EBSDB_CURSOR_ORIGIN_CURRENT,
+                                                   5,
+                                                   &results, &error) < 0)
                g_error ("Error fetching cursor results: %s", error->message);
 
        /* Assert the first 5 contacts in en_US order */
@@ -80,11 +80,11 @@ test_cursor_calculate_move_backwards (EbSdbCursorFixture *fixture,
        gint    position = 0, total = 0;
 
        /* Move cursor */
-       if (!e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
-                                                    fixture->cursor,
-                                                    EBSDB_CURSOR_ORIGIN_CURRENT,
-                                                    -5,
-                                                    &results, &error))
+       if (e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
+                                                   fixture->cursor,
+                                                   EBSDB_CURSOR_ORIGIN_CURRENT,
+                                                   -5,
+                                                   &results, &error) < 0)
                g_error ("Error fetching cursor results: %s", error->message);
 
        /* Assert the last 5 contacts in en_US order */
@@ -118,11 +118,11 @@ test_cursor_calculate_back_and_forth (EbSdbCursorFixture *fixture,
        gint    position = 0, total = 0;
 
        /* Move cursor */
-       if (!e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
-                                                    fixture->cursor, 
-                                                    EBSDB_CURSOR_ORIGIN_CURRENT,
-                                                    7,
-                                                    &results, &error))
+       if (e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
+                                                   fixture->cursor, 
+                                                   EBSDB_CURSOR_ORIGIN_CURRENT,
+                                                   7,
+                                                   &results, &error) < 0)
                g_error ("Error fetching cursor results: %s", error->message);
 
        g_assert_cmpint (g_slist_length (results), ==, 7);
@@ -140,11 +140,11 @@ test_cursor_calculate_back_and_forth (EbSdbCursorFixture *fixture,
        g_assert_cmpint (total, ==, 20);
 
        /* Move cursor */
-       if (!e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
-                                                    fixture->cursor,
-                                                    EBSDB_CURSOR_ORIGIN_CURRENT,
-                                                    -4,
-                                                    &results, &error))
+       if (e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
+                                                   fixture->cursor,
+                                                   EBSDB_CURSOR_ORIGIN_CURRENT,
+                                                   -4,
+                                                   &results, &error) < 0)
                g_error ("Error fetching cursor results: %s", error->message);
 
        g_assert_cmpint (g_slist_length (results), ==, 4);
@@ -162,11 +162,11 @@ test_cursor_calculate_back_and_forth (EbSdbCursorFixture *fixture,
        g_assert_cmpint (total, ==, 20);
 
        /* Move cursor */
-       if (!e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
-                                                    fixture->cursor,
-                                                    EBSDB_CURSOR_ORIGIN_CURRENT,
-                                                    5,
-                                                    &results, &error))
+       if (e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
+                                                   fixture->cursor,
+                                                   EBSDB_CURSOR_ORIGIN_CURRENT,
+                                                   5,
+                                                   &results, &error) < 0)
                g_error ("Error fetching cursor results: %s", error->message);
 
        g_assert_cmpint (g_slist_length (results), ==, 5);
@@ -225,10 +225,10 @@ test_cursor_calculate_after_modification (EbSdbCursorFixture *fixture,
        book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
 
        /* Set the cursor to point exactly 'blackbird' (which is the 12th contact) */
-       if (!e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
-                                                    fixture->cursor,
-                                                    EBSDB_CURSOR_ORIGIN_CURRENT,
-                                                    12, NULL, &error))
+       if (e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
+                                                   fixture->cursor,
+                                                   EBSDB_CURSOR_ORIGIN_CURRENT,
+                                                   12, NULL, &error) < 0)
                g_error ("Error fetching cursor results: %s", error->message);
 
        /* Check new position */
@@ -286,10 +286,10 @@ test_cursor_calculate_filtered_move_forward (EbSdbCursorFixture *fixture,
        gint    position = 0, total = 0;
 
        /* Move cursor */
-       if (!e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
-                                                    fixture->cursor,
-                                                    EBSDB_CURSOR_ORIGIN_CURRENT,
-                                                    5, &results, &error))
+       if (e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
+                                                   fixture->cursor,
+                                                   EBSDB_CURSOR_ORIGIN_CURRENT,
+                                                   5, &results, &error) < 0)
                g_error ("Error fetching cursor results: %s", error->message);
 
        g_assert_cmpint (g_slist_length (results), ==, 5);
@@ -316,11 +316,11 @@ test_cursor_calculate_filtered_move_backwards (EbSdbCursorFixture *fixture,
        gint    position = 0, total = 0;
 
        /* Move cursor */
-       if (!e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
-                                                    fixture->cursor,
-                                                    EBSDB_CURSOR_ORIGIN_CURRENT,
-                                                    -5,
-                                                    &results, &error))
+       if (e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
+                                                   fixture->cursor,
+                                                   EBSDB_CURSOR_ORIGIN_CURRENT,
+                                                   -5,
+                                                   &results, &error) < 0)
                g_error ("Error fetching cursor results: %s", error->message);
 
        g_assert_cmpint (g_slist_length (results), ==, 5);
@@ -379,10 +379,10 @@ test_cursor_calculate_filtered_after_modification (EbSdbCursorFixture *fixture,
        book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
 
        /* Set the cursor to point exactly 'blackbird' (which is the 8th contact when filtered) */
-       if (!e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
-                                                    fixture->cursor,
-                                                    EBSDB_CURSOR_ORIGIN_CURRENT,
-                                                    8, NULL, &error))
+       if (e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
+                                                   fixture->cursor,
+                                                   EBSDB_CURSOR_ORIGIN_CURRENT,
+                                                   8, NULL, &error) < 0)
                g_error ("Error fetching cursor results: %s", error->message);
 
        /* 'blackbirds' -> Jacob Appelbaum */
@@ -416,11 +416,11 @@ test_cursor_calculate_descending_move_forward (EbSdbCursorFixture *fixture,
        gint    position = 0, total = 0;
 
        /* Move cursor */
-       if (!e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
-                                                    fixture->cursor,
-                                                    EBSDB_CURSOR_ORIGIN_CURRENT,
-                                                    5,
-                                                    &results, &error))
+       if (e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
+                                                   fixture->cursor,
+                                                   EBSDB_CURSOR_ORIGIN_CURRENT,
+                                                   5,
+                                                   &results, &error) < 0)
                g_error ("Error fetching cursor results: %s", error->message);
 
        /* Assert the first 5 contacts in en_US order */
@@ -455,10 +455,10 @@ test_cursor_calculate_descending_move_backwards (EbSdbCursorFixture *fixture,
        gint    position = 0, total = 0;
 
        /* Move cursor */
-       if (!e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
-                                                    fixture->cursor,
-                                                    EBSDB_CURSOR_ORIGIN_CURRENT,
-                                                    -5, &results, &error))
+       if (e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
+                                                   fixture->cursor,
+                                                   EBSDB_CURSOR_ORIGIN_CURRENT,
+                                                   -5, &results, &error) < 0)
                g_error ("Error fetching cursor results: %s", error->message);
 
        /* Assert the last 5 contacts in en_US order */
@@ -526,10 +526,10 @@ test_cursor_calculate_descending_after_modification (EbSdbCursorFixture *fixture
        book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
 
        /* Set the cursor to point exactly 'Bät' (which is the 12th contact in descending order) */
-       if (!e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
-                                                    fixture->cursor,
-                                                    EBSDB_CURSOR_ORIGIN_CURRENT,
-                                                    12, NULL, &error))
+       if (e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
+                                                   fixture->cursor,
+                                                   EBSDB_CURSOR_ORIGIN_CURRENT,
+                                                   12, NULL, &error) < 0)
                g_error ("Error fetching cursor results: %s", error->message);
 
        /* Check new position */
diff --git a/tests/libedata-book/test-sqlite-cursor-set-target.c 
b/tests/libedata-book/test-sqlite-cursor-set-target.c
index 69bc986..19b4ae8 100644
--- a/tests/libedata-book/test-sqlite-cursor-set-target.c
+++ b/tests/libedata-book/test-sqlite-cursor-set-target.c
@@ -19,10 +19,10 @@ test_cursor_set_target_reset_cursor (EbSdbCursorFixture *fixture,
        GError *error = NULL;
 
        /* First batch */
-       if (!e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
-                                                    fixture->cursor,
-                                                    EBSDB_CURSOR_ORIGIN_CURRENT,
-                                                    5, &results, &error))
+       if (e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
+                                                   fixture->cursor,
+                                                   EBSDB_CURSOR_ORIGIN_CURRENT,
+                                                   5, &results, &error) < 0)
                g_error ("Error fetching cursor results: %s", error->message);
 
        print_results (results);
@@ -42,10 +42,10 @@ test_cursor_set_target_reset_cursor (EbSdbCursorFixture *fixture,
        results = NULL;
 
        /* Second batch reset (same results) */
-       if (!e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
-                                                    fixture->cursor,
-                                                    EBSDB_CURSOR_ORIGIN_RESET,
-                                                    5, &results, &error))
+       if (e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
+                                                   fixture->cursor,
+                                                   EBSDB_CURSOR_ORIGIN_RESET,
+                                                   5, &results, &error) < 0)
                g_error ("Error fetching cursor results: %s", error->message);
 
        print_results (results);
@@ -87,10 +87,10 @@ test_cursor_set_target_c_next_results (EbSdbCursorFixture *fixture,
        e_book_backend_sqlitedb_cursor_set_target_alphabetic_index (((ESqliteDBFixture *) fixture)->ebsdb,
                                                                    fixture->cursor, 3);
 
-       if (!e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
-                                                    fixture->cursor,
-                                                    EBSDB_CURSOR_ORIGIN_CURRENT,
-                                                    5, &results, &error))
+       if (e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
+                                                   fixture->cursor,
+                                                   EBSDB_CURSOR_ORIGIN_CURRENT,
+                                                   5, &results, &error) < 0)
                g_error ("Error fetching cursor results: %s", error->message);
 
        print_results (results);
@@ -132,10 +132,10 @@ test_cursor_set_target_c_prev_results (EbSdbCursorFixture *fixture,
        e_book_backend_sqlitedb_cursor_set_target_alphabetic_index (((ESqliteDBFixture *) fixture)->ebsdb,
                                                                    fixture->cursor, 3);
 
-       if (!e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
-                                                    fixture->cursor, 
-                                                    EBSDB_CURSOR_ORIGIN_CURRENT,
-                                                    -5, &results, &error))
+       if (e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
+                                                   fixture->cursor, 
+                                                   EBSDB_CURSOR_ORIGIN_CURRENT,
+                                                   -5, &results, &error) < 0)
                g_error ("Error fetching cursor results: %s", error->message);
 
        print_results (results);


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