gconstpointer user_data)
{
MoveByData *data = (MoveByData *)user_data;
- GSList *results;
+ GSList *results = NULL;
GError *error = NULL;
gint i;
+ gint expected_position = 0, position;
+ gint total;
+
+ total = data->filtered ? N_FILTERED_CONTACTS : N_SORTED_CONTACTS;
for (i = 0; i < MAX_MOVE_BY_COUNTS && data->counts[i] != 0; i++) {
+ /* From the 0 position, a negative move starts from the end */
+ if (expected_position == 0 && data->counts[i] < 0)
+ expected_position = (total + 1) - ABS (data->counts[i]);
+ else
+ expected_position += data->counts[i];
+
+ if (expected_position > total || expected_position < 1)
+ expected_position = 0;
+
/* Try normal order */
- results = e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
- fixture->cursor,
- EBSDB_CURSOR_ORIGIN_CURRENT,
- data->counts[i], &error);
- if (error)
+ if (!e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
+ fixture->cursor,
+ EBSDB_CURSOR_ORIGIN_CURRENT,
+ data->counts[i],
+ &results, &error))
g_error ("Error fetching cursor results: %s", error->message);
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);
+ results = NULL;
+
+ if (!e_book_backend_sqlitedb_cursor_calculate (((ESqliteDBFixture *) fixture)->ebsdb,
+ fixture->cursor, NULL, &position, &error))
+ g_error ("Error calculating cursor: %s", error->message);
+ g_assert_cmpint (expected_position, ==, position);
/* 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)
+ if (!e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
+ fixture->cursor,
+ EBSDB_CURSOR_ORIGIN_PREVIOUS,
+ data->counts[i],
+ &results, &error))
g_error ("Error fetching cursor results: %s", error->message);
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);
+ results = NULL;
+
+ if (!e_book_backend_sqlitedb_cursor_calculate (((ESqliteDBFixture *) fixture)->ebsdb,
+ fixture->cursor, NULL, &position, &error))
+ g_error ("Error calculating cursor: %s", error->message);
+ g_assert_cmpint (expected_position, ==, position);
}
/* 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)
+ if (!e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
+ fixture->cursor,
+ EBSDB_CURSOR_ORIGIN_RESET,
+ data->counts[0],
+ &results, &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);
+ results = NULL;
+
+ /* From the 0 position, a negative move starts from the end */
+ if (data->counts[0] < 0)
+ expected_position = (total + 1) - ABS (data->counts[0]);
+ else
+ expected_position = data->counts[0];
+
+ if (!e_book_backend_sqlitedb_cursor_calculate (((ESqliteDBFixture *) fixture)->ebsdb,
+ fixture->cursor, NULL, &position, &error))
+ g_error ("Error calculating cursor: %s", error->message);
+ g_assert_cmpint (expected_position, ==, position);
}
static void
move_by_test_add (MoveByData *data,
gboolean filtered)
{
+ data->filtered = filtered;
+
g_test_add (data->path, EbSdbCursorFixture, data,
filtered ?
e_sqlitedb_cursor_fixture_filtered_setup :
test_cursor_calculate_move_forward (EbSdbCursorFixture *fixture,
gconstpointer user_data)
{
- GSList *results;
+ GSList *results = NULL;
GError *error = NULL;
gint position = 0, total = 0;
/* Move cursor */
- results = e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
- fixture->cursor,
- EBSDB_CURSOR_ORIGIN_CURRENT,
- 5, &error);
-
- if (error)
+ if (!e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
+ fixture->cursor,
+ EBSDB_CURSOR_ORIGIN_CURRENT,
+ 5,
+ &results, &error))
g_error ("Error fetching cursor results: %s", error->message);
/* Assert the first 5 contacts in en_US order */
test_cursor_calculate_move_backwards (EbSdbCursorFixture *fixture,
gconstpointer user_data)
{
- GSList *results;
+ GSList *results = NULL;
GError *error = NULL;
gint position = 0, total = 0;
/* Move cursor */
- results = e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
- fixture->cursor,
- EBSDB_CURSOR_ORIGIN_CURRENT,
- -5, &error);
-
- if (error)
+ if (!e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
+ fixture->cursor,
+ EBSDB_CURSOR_ORIGIN_CURRENT,
+ -5,
+ &results, &error))
g_error ("Error fetching cursor results: %s", error->message);
/* Assert the last 5 contacts in en_US order */
test_cursor_calculate_back_and_forth (EbSdbCursorFixture *fixture,
gconstpointer user_data)
{
- GSList *results;
+ GSList *results = NULL;
GError *error = NULL;
gint position = 0, total = 0;
/* Move cursor */
- results = e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
- fixture->cursor,
- EBSDB_CURSOR_ORIGIN_CURRENT,
- 7, &error);
-
- if (error)
+ if (!e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
+ fixture->cursor,
+ EBSDB_CURSOR_ORIGIN_CURRENT,
+ 7,
+ &results, &error))
g_error ("Error fetching cursor results: %s", error->message);
g_assert_cmpint (g_slist_length (results), ==, 7);
g_slist_foreach (results, (GFunc)e_book_backend_sqlitedb_search_data_free, NULL);
g_slist_free (results);
+ results = NULL;
/* Check new position */
if (!e_book_backend_sqlitedb_cursor_calculate (((ESqliteDBFixture *) fixture)->ebsdb,
g_assert_cmpint (total, ==, 20);
/* Move cursor */
- results = e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
- fixture->cursor,
- EBSDB_CURSOR_ORIGIN_CURRENT,
- -4, &error);
-
- if (error)
+ if (!e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
+ fixture->cursor,
+ EBSDB_CURSOR_ORIGIN_CURRENT,
+ -4,
+ &results, &error))
g_error ("Error fetching cursor results: %s", error->message);
g_assert_cmpint (g_slist_length (results), ==, 4);
g_slist_foreach (results, (GFunc)e_book_backend_sqlitedb_search_data_free, NULL);
g_slist_free (results);
+ results = NULL;
/* Check new position */
if (!e_book_backend_sqlitedb_cursor_calculate (((ESqliteDBFixture *) fixture)->ebsdb,
g_assert_cmpint (total, ==, 20);
/* Move cursor */
- results = e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
- fixture->cursor,
- EBSDB_CURSOR_ORIGIN_CURRENT,
- 5, &error);
-
- if (error)
+ if (!e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
+ fixture->cursor,
+ EBSDB_CURSOR_ORIGIN_CURRENT,
+ 5,
+ &results, &error))
g_error ("Error fetching cursor results: %s", error->message);
g_assert_cmpint (g_slist_length (results), ==, 5);
g_slist_foreach (results, (GFunc)e_book_backend_sqlitedb_search_data_free, NULL);
g_slist_free (results);
+ results = NULL;
/* Check new position */
if (!e_book_backend_sqlitedb_cursor_calculate (((ESqliteDBFixture *) fixture)->ebsdb,
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 '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)
+ if (!e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
+ fixture->cursor,
+ EBSDB_CURSOR_ORIGIN_CURRENT,
+ 12, NULL, &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,
fixture->cursor, &total, &position, &error))
test_cursor_calculate_filtered_move_forward (EbSdbCursorFixture *fixture,
gconstpointer user_data)
{
- GSList *results;
+ GSList *results = NULL;
GError *error = NULL;
gint position = 0, total = 0;
/* Move cursor */
- results = e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
- fixture->cursor,
- EBSDB_CURSOR_ORIGIN_CURRENT,
- 5, &error);
-
- if (error)
+ if (!e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
+ fixture->cursor,
+ EBSDB_CURSOR_ORIGIN_CURRENT,
+ 5, &results, &error))
g_error ("Error fetching cursor results: %s", error->message);
g_assert_cmpint (g_slist_length (results), ==, 5);
g_slist_foreach (results, (GFunc)e_book_backend_sqlitedb_search_data_free, NULL);
g_slist_free (results);
+ results = NULL;
/* Check new position */
if (!e_book_backend_sqlitedb_cursor_calculate (((ESqliteDBFixture *) fixture)->ebsdb,
test_cursor_calculate_filtered_move_backwards (EbSdbCursorFixture *fixture,
gconstpointer user_data)
{
- GSList *results;
+ GSList *results = NULL;
GError *error = NULL;
gint position = 0, total = 0;
/* Move cursor */
- results = e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
- fixture->cursor,
- EBSDB_CURSOR_ORIGIN_CURRENT,
- -5, &error);
-
- if (error)
+ if (!e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
+ fixture->cursor,
+ EBSDB_CURSOR_ORIGIN_CURRENT,
+ -5,
+ &results, &error))
g_error ("Error fetching cursor results: %s", error->message);
g_assert_cmpint (g_slist_length (results), ==, 5);
g_slist_foreach (results, (GFunc)e_book_backend_sqlitedb_search_data_free, NULL);
g_slist_free (results);
+ results = NULL;
/* Check new position */
if (!e_book_backend_sqlitedb_cursor_calculate (((ESqliteDBFixture *) fixture)->ebsdb,
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 '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)
+ if (!e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
+ fixture->cursor,
+ EBSDB_CURSOR_ORIGIN_CURRENT,
+ 8, NULL, &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");
e_contact_set (fixture->contacts[18 - 1], E_CONTACT_GIVEN_NAME, "Jacob");
test_cursor_calculate_descending_move_forward (EbSdbCursorFixture *fixture,
gconstpointer user_data)
{
- GSList *results;
+ GSList *results = NULL;
GError *error = NULL;
gint position = 0, total = 0;
/* Move cursor */
- results = e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
- fixture->cursor,
- EBSDB_CURSOR_ORIGIN_CURRENT,
- 5, &error);
-
- if (error)
+ if (!e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
+ fixture->cursor,
+ EBSDB_CURSOR_ORIGIN_CURRENT,
+ 5,
+ &results, &error))
g_error ("Error fetching cursor results: %s", error->message);
/* Assert the first 5 contacts in en_US order */
NULL);
g_slist_foreach (results, (GFunc)e_book_backend_sqlitedb_search_data_free, NULL);
g_slist_free (results);
+ results = NULL;
/* Check new position */
if (!e_book_backend_sqlitedb_cursor_calculate (((ESqliteDBFixture *) fixture)->ebsdb,
test_cursor_calculate_descending_move_backwards (EbSdbCursorFixture *fixture,
gconstpointer user_data)
{
- GSList *results;
+ GSList *results = NULL;
GError *error = NULL;
gint position = 0, total = 0;
/* Move cursor */
- results = e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
- fixture->cursor,
- EBSDB_CURSOR_ORIGIN_CURRENT,
- -5, &error);
-
- if (error)
+ if (!e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
+ fixture->cursor,
+ EBSDB_CURSOR_ORIGIN_CURRENT,
+ -5, &results, &error))
g_error ("Error fetching cursor results: %s", error->message);
/* Assert the last 5 contacts in en_US order */
NULL);
g_slist_foreach (results, (GFunc)e_book_backend_sqlitedb_search_data_free, NULL);
g_slist_free (results);
+ results = NULL;
/* Check new position */
if (!e_book_backend_sqlitedb_cursor_calculate (((ESqliteDBFixture *) fixture)->ebsdb,
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 'Bät' (which is the 12th contact in descending order) */
- results = e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
- fixture->cursor,
- EBSDB_CURSOR_ORIGIN_CURRENT,
- 12, &error);
- if (error)
+ if (!e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
+ fixture->cursor,
+ EBSDB_CURSOR_ORIGIN_CURRENT,
+ 12, NULL, &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,
fixture->cursor, &total, &position, &error))
test_cursor_set_target_reset_cursor (EbSdbCursorFixture *fixture,
gconstpointer user_data)
{
- GSList *results;
+ GSList *results = NULL;
GError *error = NULL;
/* First batch */
- results = e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
- fixture->cursor,
- EBSDB_CURSOR_ORIGIN_CURRENT,
- 5, &error);
-
- if (error)
+ if (!e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
+ fixture->cursor,
+ EBSDB_CURSOR_ORIGIN_CURRENT,
+ 5, &results, &error))
g_error ("Error fetching cursor results: %s", error->message);
print_results (results);
g_slist_foreach (results, (GFunc)e_book_backend_sqlitedb_search_data_free, NULL);
g_slist_free (results);
+ results = NULL;
/* Second batch reset (same results) */
- results = e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
- fixture->cursor,
- EBSDB_CURSOR_ORIGIN_RESET,
- 5, &error);
-
- if (error)
+ if (!e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
+ fixture->cursor,
+ EBSDB_CURSOR_ORIGIN_RESET,
+ 5, &results, &error))
g_error ("Error fetching cursor results: %s", error->message);
print_results (results);
test_cursor_set_target_c_next_results (EbSdbCursorFixture *fixture,
gconstpointer user_data)
{
- GSList *results;
+ GSList *results = NULL;
GError *error = NULL;
ECollator *collator;
gint n_labels;
e_book_backend_sqlitedb_cursor_set_target_alphabetic_index (((ESqliteDBFixture *) fixture)->ebsdb,
fixture->cursor, 3);
- results = e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
- fixture->cursor,
- EBSDB_CURSOR_ORIGIN_CURRENT,
- 5, &error);
-
- if (error)
+ if (!e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
+ fixture->cursor,
+ EBSDB_CURSOR_ORIGIN_CURRENT,
+ 5, &results, &error))
g_error ("Error fetching cursor results: %s", error->message);
print_results (results);
test_cursor_set_target_c_prev_results (EbSdbCursorFixture *fixture,
gconstpointer user_data)
{
- GSList *results;
+ GSList *results = NULL;
GError *error = NULL;
ECollator *collator;
gint n_labels;
e_book_backend_sqlitedb_cursor_set_target_alphabetic_index (((ESqliteDBFixture *) fixture)->ebsdb,
fixture->cursor, 3);
- results = e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
- fixture->cursor,
- EBSDB_CURSOR_ORIGIN_CURRENT,
- -5, &error);
-
- if (error)
+ if (!e_book_backend_sqlitedb_cursor_move_by (((ESqliteDBFixture *) fixture)->ebsdb,
+ fixture->cursor,
+ EBSDB_CURSOR_ORIGIN_CURRENT,
+ -5, &results, &error))
g_error ("Error fetching cursor results: %s", error->message);
print_results (results);