1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
5 #include <libebook/libebook.h>
7 #include "data-test-utils.h"
9 /*****************************************************
10 * Expect the same results twice *
11 *****************************************************/
13 test_cursor_set_target_reset_cursor (EbSqlCursorFixture *fixture,
14 gconstpointer user_data)
16 GSList *results = NULL;
20 if (e_book_sqlite_cursor_step (((EbSqlFixture *) fixture)->ebsql,
22 EBSQL_CURSOR_STEP_MOVE | EBSQL_CURSOR_STEP_FETCH,
23 EBSQL_CURSOR_ORIGIN_BEGIN,
24 5, &results, NULL, &error) < 0)
25 g_error ("Error fetching cursor results: %s", error->message);
27 print_results (results);
29 /* Assert the first 5 contacts in en_US order */
30 g_assert_cmpint (g_slist_length (results), ==, 5);
31 assert_contacts_order (
40 g_slist_foreach (results, (GFunc) e_book_sqlite_search_data_free, NULL);
41 g_slist_free (results);
44 /* Second batch reset (same results) */
45 if (e_book_sqlite_cursor_step (((EbSqlFixture *) fixture)->ebsql,
47 EBSQL_CURSOR_STEP_MOVE | EBSQL_CURSOR_STEP_FETCH,
48 EBSQL_CURSOR_ORIGIN_BEGIN,
49 5, &results, NULL, &error) < 0)
50 g_error ("Error fetching cursor results: %s", error->message);
52 print_results (results);
54 /* Assert the first 5 contacts in en_US order again */
55 g_assert_cmpint (g_slist_length (results), ==, 5);
56 assert_contacts_order (
65 g_slist_foreach (results, (GFunc) e_book_sqlite_search_data_free, NULL);
66 g_slist_free (results);
69 /*****************************************************
70 * Expect results with family name starting with 'C' *
71 *****************************************************/
73 test_cursor_set_target_c_next_results (EbSqlCursorFixture *fixture,
74 gconstpointer user_data)
76 GSList *results = NULL;
80 const gchar *const *labels;
82 /* First verify our test... in en_US locale the label 'C' should exist with the index 3 */
83 collator = e_book_sqlite_ref_collator (((EbSqlFixture *) fixture)->ebsql);
84 labels = e_collator_get_index_labels (collator, &n_labels, NULL, NULL, NULL);
85 g_assert_cmpstr (labels[3], ==, "C");
86 e_collator_unref (collator);
88 /* Set the cursor at the start of family names beginning with 'C' */
89 e_book_sqlite_cursor_set_target_alphabetic_index (
90 ((EbSqlFixture *) fixture)->ebsql,
93 if (e_book_sqlite_cursor_step (((EbSqlFixture *) fixture)->ebsql,
95 EBSQL_CURSOR_STEP_MOVE | EBSQL_CURSOR_STEP_FETCH,
96 EBSQL_CURSOR_ORIGIN_CURRENT,
97 5, &results, NULL, &error) < 0)
98 g_error ("Error fetching cursor results: %s", error->message);
100 print_results (results);
102 /* Assert that we got the results starting at C */
103 g_assert_cmpint (g_slist_length (results), ==, 5);
104 assert_contacts_order (
113 g_slist_foreach (results, (GFunc) e_book_sqlite_search_data_free, NULL);
114 g_slist_free (results);
117 /*****************************************************
118 * Expect results before the letter 'C' *
119 *****************************************************/
121 test_cursor_set_target_c_prev_results (EbSqlCursorFixture *fixture,
122 gconstpointer user_data)
124 GSList *results = NULL;
125 GError *error = NULL;
128 const gchar *const *labels;
130 /* First verify our test... in en_US locale the label 'C' should exist with the index 3 */
131 collator = e_book_sqlite_ref_collator (((EbSqlFixture *) fixture)->ebsql);
132 labels = e_collator_get_index_labels (collator, &n_labels, NULL, NULL, NULL);
133 g_assert_cmpstr (labels[3], ==, "C");
134 e_collator_unref (collator);
136 /* Set the cursor at the start of family names beginning with 'C' */
137 e_book_sqlite_cursor_set_target_alphabetic_index (
138 ((EbSqlFixture *) fixture)->ebsql,
141 if (e_book_sqlite_cursor_step (((EbSqlFixture *) fixture)->ebsql,
143 EBSQL_CURSOR_STEP_MOVE | EBSQL_CURSOR_STEP_FETCH,
144 EBSQL_CURSOR_ORIGIN_CURRENT,
145 -5, &results, NULL, &error) < 0)
146 g_error ("Error fetching cursor results: %s", error->message);
148 print_results (results);
150 /* Assert that we got the results before C */
151 g_assert_cmpint (g_slist_length (results), ==, 5);
152 assert_contacts_order (
161 g_slist_foreach (results, (GFunc) e_book_sqlite_search_data_free, NULL);
162 g_slist_free (results);
165 static EbSqlCursorClosure closures[] = {
166 { { FALSE, NULL }, NULL, E_BOOK_CURSOR_SORT_ASCENDING },
167 { { TRUE, NULL }, NULL, E_BOOK_CURSOR_SORT_ASCENDING },
168 { { FALSE, setup_empty_book }, NULL, E_BOOK_CURSOR_SORT_ASCENDING },
169 { { TRUE, setup_empty_book }, NULL, E_BOOK_CURSOR_SORT_ASCENDING }
172 static const gchar *prefixes[] = {
173 "/EBookSqlite/DefaultSummary/StoreVCards",
174 "/EBookSqlite/DefaultSummary/NoVCards",
175 "/EBookSqlite/EmptySummary/StoreVCards",
176 "/EBookSqlite/EmptrySummary/NoVCards"
185 #if !GLIB_CHECK_VERSION (2, 35, 1)
188 g_test_init (&argc, &argv, NULL);
190 for (i = 0; i < G_N_ELEMENTS (closures); i++) {
193 path = g_strconcat (prefixes[i], "/SetTarget/ResetCursor", NULL);
195 path, EbSqlCursorFixture, &closures[i],
196 e_sqlite_cursor_fixture_setup,
197 test_cursor_set_target_reset_cursor,
198 e_sqlite_cursor_fixture_teardown);
201 path = g_strconcat (prefixes[i], "/SetTarget/Alphabetic/C/NextResults", NULL);
203 path, EbSqlCursorFixture, &closures[i],
204 e_sqlite_cursor_fixture_setup,
205 test_cursor_set_target_c_next_results,
206 e_sqlite_cursor_fixture_teardown);
209 path = g_strconcat (prefixes[i], "/SetTarget/Alphabetic/C/PreviousResults", NULL);
211 path, EbSqlCursorFixture, &closures[i],
212 e_sqlite_cursor_fixture_setup,
213 test_cursor_set_target_c_prev_results,
214 e_sqlite_cursor_fixture_teardown);
218 return g_test_run ();