[evolution-data-server/openismus-work-master: 46/76] EBookBackendSqliteDB Cursor tests updated.
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/openismus-work-master: 46/76] EBookBackendSqliteDB Cursor tests updated.
- Date: Tue, 30 Jul 2013 21:38:17 +0000 (UTC)
commit 01ff2bce8b3333a1d80ad3fce71eb6d18777386f
Author: Tristan Van Berkom <tristanvb openismus com>
Date: Tue Jun 11 19:05:18 2013 +0900
EBookBackendSqliteDB Cursor tests updated.
Updated cursor tests for the new _move_by() API and removal
of the _set_target_contact() API.
tests/libedata-book/data-test-utils.c | 94 ++++++++++++-----
tests/libedata-book/test-sqlite-cursor-calculate.c | 110 ++++++++------------
tests/libedata-book/test-sqlite-cursor-set-sexp.c | 18 +++-
.../libedata-book/test-sqlite-cursor-set-target.c | 106 +++----------------
4 files changed, 142 insertions(+), 186 deletions(-)
---
diff --git a/tests/libedata-book/data-test-utils.c b/tests/libedata-book/data-test-utils.c
index c95744a..3379934 100644
--- a/tests/libedata-book/data-test-utils.c
+++ b/tests/libedata-book/data-test-utils.c
@@ -532,54 +532,94 @@ test_cursor_move_teardown (EbSdbCursorFixture *fixture,
}
static void
+assert_move_by (EbSdbCursorFixture *fixture,
+ MoveByData *data,
+ gint i,
+ GSList *results)
+{
+ GSList *uids = NULL;
+ gint j;
+
+ /* Assert the exact amount of requested results */
+ g_assert_cmpint (g_slist_length (results), ==, ABS (data->counts[i]));
+
+#if DEBUG_FIXTURE
+ g_print ("%s: Constructing expected result list for a fetch of %d: ",
+ data->path, data->counts[i]);
+#endif
+ for (j = 0; j < ABS (data->counts[i]); j++) {
+ gint index = data->expected[i][j];
+ gchar *uid;
+
+ uid = (gchar *)e_contact_get_const (fixture->contacts[index], E_CONTACT_UID);
+ uids = g_slist_append (uids, uid);
+
+#if DEBUG_FIXTURE
+ g_print ("%s ", uid);
+#endif
+
+ }
+#if DEBUG_FIXTURE
+ g_print ("\n");
+#endif
+
+ assert_contacts_order_slist (results, uids);
+ g_slist_free (uids);
+}
+
+static void
test_move_by (EbSdbCursorFixture *fixture,
gconstpointer user_data)
{
MoveByData *data = (MoveByData *)user_data;
GSList *results;
GError *error = NULL;
- gint i, j;
+ gint i;
for (i = 0; i < MAX_MOVE_BY_COUNTS && data->counts[i] != 0; i++) {
- GSList *uids = NULL;
+ /* Try normal order */
results = e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
- fixture->cursor, data->counts[i], &error);
+ fixture->cursor,
+ EBSDB_CURSOR_ORIGIN_CURRENT,
+ data->counts[i], &error);
if (error)
g_error ("Error fetching cursor results: %s", error->message);
print_results (results);
+ assert_move_by (fixture, data, i, results);
- /* Assert the exact amount of requested results */
- g_assert_cmpint (g_slist_length (results), ==, ABS (data->counts[i]));
-
-#if DEBUG_FIXTURE
- g_print ("%s: Constructing expected result list for a fetch of %d: ",
- data->path, data->counts[i]);
-#endif
-
- for (j = 0; j < ABS (data->counts[i]); j++) {
- gint index = data->expected[i][j];
- gchar *uid;
-
- uid = (gchar *)e_contact_get_const (fixture->contacts[index], E_CONTACT_UID);
- uids = g_slist_append (uids, uid);
-
-#if DEBUG_FIXTURE
- g_print ("%s ", uid);
-#endif
+ g_slist_foreach (results, (GFunc)e_book_backend_sqlitedb_search_data_free, NULL);
+ g_slist_free (results);
- }
-#if DEBUG_FIXTURE
- g_print ("\n");
-#endif
+ /* Try repeat last query */
+ results = e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
+ fixture->cursor,
+ EBSDB_CURSOR_ORIGIN_PREVIOUS,
+ data->counts[i], &error);
+ if (error)
+ g_error ("Error fetching cursor results: %s", error->message);
- assert_contacts_order_slist (results, uids);
- g_slist_free (uids);
+ print_results (results);
+ assert_move_by (fixture, data, i, results);
g_slist_foreach (results, (GFunc)e_book_backend_sqlitedb_search_data_free, NULL);
g_slist_free (results);
}
+
+ /* One more, test reset API, the first batch from the beginning */
+ results = e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
+ fixture->cursor,
+ EBSDB_CURSOR_ORIGIN_RESET,
+ data->counts[0], &error);
+ if (error)
+ g_error ("Error fetching cursor results: %s", error->message);
+
+ print_results (results);
+ assert_move_by (fixture, data, 0, results);
+
+ g_slist_foreach (results, (GFunc)e_book_backend_sqlitedb_search_data_free, NULL);
+ g_slist_free (results);
}
static void
diff --git a/tests/libedata-book/test-sqlite-cursor-calculate.c
b/tests/libedata-book/test-sqlite-cursor-calculate.c
index c71823e..d895e3d 100644
--- a/tests/libedata-book/test-sqlite-cursor-calculate.c
+++ b/tests/libedata-book/test-sqlite-cursor-calculate.c
@@ -33,7 +33,9 @@ test_cursor_calculate_move_forward (EbSdbCursorFixture *fixture,
/* Move cursor */
results = e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
- fixture->cursor, 5, &error);
+ fixture->cursor,
+ EBSDB_CURSOR_ORIGIN_CURRENT,
+ 5, &error);
if (error)
g_error ("Error fetching cursor results: %s", error->message);
@@ -70,7 +72,9 @@ test_cursor_calculate_move_backwards (EbSdbCursorFixture *fixture,
/* Move cursor */
results = e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
- fixture->cursor, -5, &error);
+ fixture->cursor,
+ EBSDB_CURSOR_ORIGIN_CURRENT,
+ -5, &error);
if (error)
g_error ("Error fetching cursor results: %s", error->message);
@@ -107,7 +111,9 @@ test_cursor_calculate_back_and_forth (EbSdbCursorFixture *fixture,
/* Move cursor */
results = e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
- fixture->cursor, 7, &error);
+ fixture->cursor,
+ EBSDB_CURSOR_ORIGIN_CURRENT,
+ 7, &error);
if (error)
g_error ("Error fetching cursor results: %s", error->message);
@@ -127,7 +133,9 @@ test_cursor_calculate_back_and_forth (EbSdbCursorFixture *fixture,
/* Move cursor */
results = e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
- fixture->cursor, -4, &error);
+ fixture->cursor,
+ EBSDB_CURSOR_ORIGIN_CURRENT,
+ -4, &error);
if (error)
g_error ("Error fetching cursor results: %s", error->message);
@@ -147,7 +155,9 @@ test_cursor_calculate_back_and_forth (EbSdbCursorFixture *fixture,
/* Move cursor */
results = e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
- fixture->cursor, 5, &error);
+ fixture->cursor,
+ EBSDB_CURSOR_ORIGIN_CURRENT,
+ 5, &error);
if (error)
g_error ("Error fetching cursor results: %s", error->message);
@@ -167,27 +177,6 @@ test_cursor_calculate_back_and_forth (EbSdbCursorFixture *fixture,
}
static void
-test_cursor_calculate_exact_target (EbSdbCursorFixture *fixture,
- gconstpointer user_data)
-{
- GError *error = NULL;
- gint position = 0, total = 0;
-
- /* Set the cursor to point exactly to blackbird */
- e_book_backend_sqlitedb_cursor_set_target_contact (((ESqliteDBFixture *) fixture)->ebsdb,
- fixture->cursor, fixture->contacts[16 - 1]);
-
- /* Check new position */
- if (!e_book_backend_sqlitedb_cursor_calculate (((ESqliteDBFixture *) fixture)->ebsdb,
- fixture->cursor, &total, &position, &error))
- g_error ("Error calculating cursor: %s", error->message);
-
- /* blackbird is at position 12 in en_US locale */
- g_assert_cmpint (position, ==, 12);
- g_assert_cmpint (total, ==, 20);
-}
-
-static void
test_cursor_calculate_partial_target (EbSdbCursorFixture *fixture,
gconstpointer user_data)
{
@@ -224,12 +213,20 @@ test_cursor_calculate_after_modification (EbSdbCursorFixture *fixture,
EBookClient *book_client;
GError *error = NULL;
gint position = 0, total = 0;
+ GSList *results;
book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
- /* Set the cursor to point exactly to 'blackbird' */
- e_book_backend_sqlitedb_cursor_set_target_contact (((ESqliteDBFixture *) fixture)->ebsdb,
- fixture->cursor, fixture->contacts[16 - 1]);
+ /* Set the cursor to point exactly 'blackbird' (which is the 12th contact) */
+ results = e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
+ fixture->cursor,
+ EBSDB_CURSOR_ORIGIN_CURRENT,
+ 12, &error);
+ if (error)
+ g_error ("Error fetching cursor results: %s", error->message);
+
+ g_slist_foreach (results, (GFunc)e_book_backend_sqlitedb_search_data_free, NULL);
+ g_slist_free (results);
/* Check new position */
if (!e_book_backend_sqlitedb_cursor_calculate (((ESqliteDBFixture *) fixture)->ebsdb,
@@ -287,7 +284,9 @@ test_cursor_calculate_filtered_move_forward (EbSdbCursorFixture *fixture,
/* Move cursor */
results = e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
- fixture->cursor, 5, &error);
+ fixture->cursor,
+ EBSDB_CURSOR_ORIGIN_CURRENT,
+ 5, &error);
if (error)
g_error ("Error fetching cursor results: %s", error->message);
@@ -316,7 +315,9 @@ test_cursor_calculate_filtered_move_backwards (EbSdbCursorFixture *fixture,
/* Move cursor */
results = e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
- fixture->cursor, -5, &error);
+ fixture->cursor,
+ EBSDB_CURSOR_ORIGIN_CURRENT,
+ -5, &error);
if (error)
g_error ("Error fetching cursor results: %s", error->message);
@@ -336,27 +337,6 @@ test_cursor_calculate_filtered_move_backwards (EbSdbCursorFixture *fixture,
}
static void
-test_cursor_calculate_filtered_exact_target (EbSdbCursorFixture *fixture,
- gconstpointer user_data)
-{
- GError *error = NULL;
- gint position = 0, total = 0;
-
- /* Set the cursor to point exactly to 'blackbird' */
- e_book_backend_sqlitedb_cursor_set_target_contact (((ESqliteDBFixture *) fixture)->ebsdb,
- fixture->cursor, fixture->contacts[16 - 1]);
-
- /* Check new position */
- if (!e_book_backend_sqlitedb_cursor_calculate (((ESqliteDBFixture *) fixture)->ebsdb,
- fixture->cursor, &total, &position, &error))
- g_error ("Error calculating cursor: %s", error->message);
-
- /* 'blackbird' is the 8th contact with a .com email address in en_US locale */
- g_assert_cmpint (position, ==, 8);
- g_assert_cmpint (total, ==, 13);
-}
-
-static void
test_cursor_calculate_filtered_partial_target (EbSdbCursorFixture *fixture,
gconstpointer user_data)
{
@@ -393,12 +373,20 @@ test_cursor_calculate_filtered_after_modification (EbSdbCursorFixture *fixture,
EBookClient *book_client;
GError *error = NULL;
gint position = 0, total = 0;
+ GSList *results;
book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
- /* Set the cursor to point exactly to 'blackbird' */
- e_book_backend_sqlitedb_cursor_set_target_contact (((ESqliteDBFixture *) fixture)->ebsdb,
- fixture->cursor, fixture->contacts[16 - 1]);
+ /* Set the cursor to point exactly 'blackbird' (which is the 8th contact when filtered) */
+ results = e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
+ fixture->cursor,
+ EBSDB_CURSOR_ORIGIN_CURRENT,
+ 8, &error);
+ if (error)
+ g_error ("Error fetching cursor results: %s", error->message);
+
+ g_slist_foreach (results, (GFunc)e_book_backend_sqlitedb_search_data_free, NULL);
+ g_slist_free (results);
/* 'blackbirds' -> Jacob Appelbaum */
e_contact_set (fixture->contacts[18 - 1], E_CONTACT_FAMILY_NAME, "Appelbaum");
@@ -447,11 +435,7 @@ main (gint argc,
e_sqlitedb_cursor_fixture_setup,
test_cursor_calculate_back_and_forth,
e_sqlitedb_cursor_fixture_teardown);
- g_test_add ("/EbSdbCursor/Calculate/ExactTarget", EbSdbCursorFixture, &book_closure,
- e_sqlitedb_cursor_fixture_setup,
- test_cursor_calculate_exact_target,
- e_sqlitedb_cursor_fixture_teardown);
- g_test_add ("/EbSdbCursor/Calculate/PartialTarget", EbSdbCursorFixture, &book_closure,
+ g_test_add ("/EbSdbCursor/Calculate/AlphabeticTarget", EbSdbCursorFixture, &book_closure,
e_sqlitedb_cursor_fixture_setup,
test_cursor_calculate_partial_target,
e_sqlitedb_cursor_fixture_teardown);
@@ -472,11 +456,7 @@ main (gint argc,
e_sqlitedb_cursor_fixture_filtered_setup,
test_cursor_calculate_filtered_move_backwards,
e_sqlitedb_cursor_fixture_teardown);
- g_test_add ("/EbSdbCursor/Calculate/Filtered/ExactTarget", EbSdbCursorFixture, &book_closure,
- e_sqlitedb_cursor_fixture_filtered_setup,
- test_cursor_calculate_filtered_exact_target,
- e_sqlitedb_cursor_fixture_teardown);
- g_test_add ("/EbSdbCursor/Calculate/Filtered/PartialTarget", EbSdbCursorFixture, &book_closure,
+ g_test_add ("/EbSdbCursor/Calculate/Filtered/AlphabeticTarget", EbSdbCursorFixture, &book_closure,
e_sqlitedb_cursor_fixture_filtered_setup,
test_cursor_calculate_filtered_partial_target,
e_sqlitedb_cursor_fixture_teardown);
diff --git a/tests/libedata-book/test-sqlite-cursor-set-sexp.c
b/tests/libedata-book/test-sqlite-cursor-set-sexp.c
index f52877f..b5c1071 100644
--- a/tests/libedata-book/test-sqlite-cursor-set-sexp.c
+++ b/tests/libedata-book/test-sqlite-cursor-set-sexp.c
@@ -36,10 +36,22 @@ test_cursor_sexp_calculate_position (EbSdbCursorFixture *fixture,
EBookQuery *query;
gint position = 0, total = 0;
gchar *sexp = NULL;
-
- /* Set the cursor to point exactly to 'blackbirds' */
- e_book_backend_sqlitedb_cursor_set_target_contact (((ESqliteDBFixture *) fixture)->ebsdb,
- fixture->cursor, fixture->contacts[16 - 1]);
+ GSList *results, *node;
+ EbSdbSearchData *data;
+
+ /* Set the cursor to point exactly to 'blackbirds', which is the 12th contact in en_US */
+ results = e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
+ fixture->cursor,
+ EBSDB_CURSOR_ORIGIN_RESET,
+ 12, &error);
+
+ /* Ensure we moved to the right contact */
+ node = g_slist_last (results);
+ g_assert (node);
+ data = node->data;
+ g_assert_cmpstr (data->uid, ==, "sorted-16");
+ g_slist_foreach (results, (GFunc)e_book_backend_sqlitedb_search_data_free, NULL);
+ g_slist_free (results);
/* Check position */
if (!e_book_backend_sqlitedb_cursor_calculate (((ESqliteDBFixture *) fixture)->ebsdb,
diff --git a/tests/libedata-book/test-sqlite-cursor-set-target.c
b/tests/libedata-book/test-sqlite-cursor-set-target.c
index 4f240ef..c2f6fec 100644
--- a/tests/libedata-book/test-sqlite-cursor-set-target.c
+++ b/tests/libedata-book/test-sqlite-cursor-set-target.c
@@ -20,7 +20,9 @@ test_cursor_set_target_reset_cursor (EbSdbCursorFixture *fixture,
/* First batch */
results = e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
- fixture->cursor, 5, &error);
+ fixture->cursor,
+ EBSDB_CURSOR_ORIGIN_CURRENT,
+ 5, &error);
if (error)
g_error ("Error fetching cursor results: %s", error->message);
@@ -40,13 +42,11 @@ test_cursor_set_target_reset_cursor (EbSdbCursorFixture *fixture,
g_slist_foreach (results, (GFunc)e_book_backend_sqlitedb_search_data_free, NULL);
g_slist_free (results);
- /* Reset cursor */
- e_book_backend_sqlitedb_cursor_set_target_contact (((ESqliteDBFixture *) fixture)->ebsdb,
- fixture->cursor, NULL);
-
- /* Second batch */
+ /* Second batch reset (same results) */
results = e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
- fixture->cursor, 5, &error);
+ fixture->cursor,
+ EBSDB_CURSOR_ORIGIN_RESET,
+ 5, &error);
if (error)
g_error ("Error fetching cursor results: %s", error->message);
@@ -91,7 +91,9 @@ test_cursor_set_target_c_next_results (EbSdbCursorFixture *fixture,
fixture->cursor, 3);
results = e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
- fixture->cursor, 5, &error);
+ fixture->cursor,
+ EBSDB_CURSOR_ORIGIN_CURRENT,
+ 5, &error);
if (error)
g_error ("Error fetching cursor results: %s", error->message);
@@ -136,7 +138,9 @@ test_cursor_set_target_c_prev_results (EbSdbCursorFixture *fixture,
fixture->cursor, 3);
results = e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
- fixture->cursor, -5, &error);
+ fixture->cursor,
+ EBSDB_CURSOR_ORIGIN_CURRENT,
+ -5, &error);
if (error)
g_error ("Error fetching cursor results: %s", error->message);
@@ -157,78 +161,6 @@ test_cursor_set_target_c_prev_results (EbSdbCursorFixture *fixture,
g_slist_free (results);
}
-/*****************************************************
- * Expect results after 'blackbird' *
- *****************************************************/
-static void
-test_cursor_set_target_blackbird_next_results (EbSdbCursorFixture *fixture,
- gconstpointer user_data)
-{
- GSList *results;
- GError *error = NULL;
-
- /* Set the cursor to point exactly to Bobby Brown */
- e_book_backend_sqlitedb_cursor_set_target_contact (((ESqliteDBFixture *) fixture)->ebsdb,
- fixture->cursor, fixture->contacts[16 -1]);
-
- results = e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
- fixture->cursor, 5, &error);
-
- if (error)
- g_error ("Error fetching cursor results: %s", error->message);
-
- print_results (results);
-
- /* Assert that we got the results after blackbird */
- g_assert_cmpint (g_slist_length (results), ==, 5);
- assert_contacts_order (results,
- "sorted-18",
- "sorted-10",
- "sorted-14",
- "sorted-12",
- "sorted-13",
- NULL);
-
- g_slist_foreach (results, (GFunc)e_book_backend_sqlitedb_search_data_free, NULL);
- g_slist_free (results);
-}
-
-/*****************************************************
- * Expect results before 'blackbird' *
- *****************************************************/
-static void
-test_cursor_set_target_blackbird_prev_results (EbSdbCursorFixture *fixture,
- gconstpointer user_data)
-{
- GSList *results;
- GError *error = NULL;
-
- /* Set the cursor to point exactly to Bobby Brown */
- e_book_backend_sqlitedb_cursor_set_target_contact (((ESqliteDBFixture *) fixture)->ebsdb,
- fixture->cursor, fixture->contacts[16 -1]);
-
- results = e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
- fixture->cursor, -5, &error);
-
- if (error)
- g_error ("Error fetching cursor results: %s", error->message);
-
- print_results (results);
-
- /* Assert that we got the results before blackbird */
- g_assert_cmpint (g_slist_length (results), ==, 5);
- assert_contacts_order (results,
- "sorted-17",
- "sorted-15",
- "sorted-8",
- "sorted-7",
- "sorted-3",
- NULL);
-
- g_slist_foreach (results, (GFunc)e_book_backend_sqlitedb_search_data_free, NULL);
- g_slist_free (results);
-}
-
gint
main (gint argc,
gchar **argv)
@@ -242,22 +174,14 @@ main (gint argc,
e_sqlitedb_cursor_fixture_setup,
test_cursor_set_target_reset_cursor,
e_sqlitedb_cursor_fixture_teardown);
- g_test_add ("/EbSdbCursor/SetTarget/Partial/C/NextResults", EbSdbCursorFixture, &book_closure,
+ g_test_add ("/EbSdbCursor/SetTarget/Alphabetic/C/NextResults", EbSdbCursorFixture, &book_closure,
e_sqlitedb_cursor_fixture_setup,
test_cursor_set_target_c_next_results,
e_sqlitedb_cursor_fixture_teardown);
- g_test_add ("/EbSdbCursor/SetTarget/Partial/C/PreviousResults", EbSdbCursorFixture, &book_closure,
+ g_test_add ("/EbSdbCursor/SetTarget/Alphabetic/C/PreviousResults", EbSdbCursorFixture, &book_closure,
e_sqlitedb_cursor_fixture_setup,
test_cursor_set_target_c_prev_results,
e_sqlitedb_cursor_fixture_teardown);
- g_test_add ("/EbSdbCursor/SetTarget/Exact/blackbird/NextResults", EbSdbCursorFixture, &book_closure,
- e_sqlitedb_cursor_fixture_setup,
- test_cursor_set_target_blackbird_next_results,
- e_sqlitedb_cursor_fixture_teardown);
- g_test_add ("/EbSdbCursor/SetTarget/Exact/blackbird/PreviousResults", EbSdbCursorFixture,
&book_closure,
- e_sqlitedb_cursor_fixture_setup,
- test_cursor_set_target_blackbird_prev_results,
- 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]