1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ 2 /* 3 * Copyright (C) 2013, Openismus GmbH 4 * 5 * This library is free software: you can redistribute it and/or modify it 6 * under the terms of the GNU Lesser General Public License as published by 7 * the Free Software Foundation. 8 * 9 * This library is distributed in the hope that it will be useful, but 10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 12 * for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public License 15 * along with this library. If not, see <http://www.gnu.org/licenses/>. 16 * 17 * Authors: Tristan Van Berkom <tristanvb@openismus.com> 18 */ 19 20 #ifndef DATA_TEST_UTILS_H 21 #define DATA_TEST_UTILS_H 22 23 #include <libedata-book/libedata-book.h> 24 25 G_BEGIN_DECLS 26 27 /* This legend shows the add order, and various sort order of the sorted 28 * vcards. The UIDs of these contacts are formed as 'sorted-1', 'sorted-2' etc 29 * and the numbering of the contacts is according to the 'N' column in the 30 * following legend. 31 * 32 * The Email column indicates whether the contact has a .com email address 33 * (in order to test filtered cursor results) and corresponds to the natural 34 * order in the 'N' column. 35 * 36 * +-----------------------------------------------------------------------------------------------+ 37 * | N | Email | Last Name | en_US_POSIX | en_US / de_DE | fr_CA | de_DE | 38 * | | | | | | | (phonebook) | 39 * +-----------------------------------------------------------------------------------------------+ 40 * | 1 | Yes | bad | 11 | 11 | 11 | 11 | 41 * | 2 | Yes | Bad | Bad 2 | bad 1 | bad 1 | bad 1 | 42 * | 3 | Yes | Bat | Bäd 6 | Bad 2 | Bad 2 | Bad 2 | 43 * | 4 | No | bat | Bat 3 | bäd 5 | bäd 5 | bäd 5 | 44 * | 5 | Yes | bäd | Bät 8 | Bäd 6 | Bäd 6 | Bäd 6 | 45 * | 6 | No | Bäd | bad 1 | bat 4 | bat 4 | bät 7 | 46 * | 7 | No | bät | bäd 5 | Bat 3 | Bat 3 | Bät 8 | 47 * | 8 | Yes | Bät | bat 4 | bät 7 | bät 7 | bat 4 | 48 * | 9 | Yes | côté | bät 7 | Bät 8 | Bät 8 | Bat 3 | 49 * | 10 | Yes | C | black-bird 15 | black-bird 15 | black-bird 15 | black-bird 15 | 50 * | 11 | Yes | | black-birds 17 | black-birds 17 | black-birds 17 | black-birds 17 | 51 * | 12 | Yes | coté | blackbird 16 | blackbird 16 | blackbird 16 | blackbird 16 | 52 * | 13 | No | côte | blackbirds 18 | blackbirds 18 | blackbirds 18 | blackbirds 18 | 53 * | 14 | Yes | cote | C 10 | C 10 | C 10 | C 10 | 54 * | 15 | No | black-bird | cote 14 | cote 14 | cote 14 | cote 14 | 55 * | 16 | Yes | blackbird | coté 12 | coté 12 | côte 13 | coté 12 | 56 * | 17 | Yes | black-birds | côte 13 | côte 13 | coté 12 | côte 13 | 57 * | 18 | Yes | blackbirds | côté 9 | côté 9 | côté 9 | côté 9 | 58 * | 19 | No | Muffler | Muffler 19 | Muffler 19 | Muffler 19 | Müller 20 | 59 * | 20 | No | Müller | Müller 20 | Müller 20 | Müller 20 | Muffler 19 | 60 * +-----------------------------------------------------------------------------------------------+ 61 * 62 * See this ICU demo to check additional sort ordering by ICU in various locales: 63 * http://demo.icu-project.org/icu-bin/locexp?_=en_US&d_=en&x=col 64 */ 65 66 void data_test_utils_read_args (gint argc, 67 gchar **argv); 68 69 /* 13 contacts in the test data have an email address ending with ".com" */ 70 #define N_FILTERED_CONTACTS 13 71 #define N_SORTED_CONTACTS 20 72 73 typedef ESourceBackendSummarySetup * (* EbSqlSetupSummary) (void); 74 75 typedef struct { 76 EBookSqlite *ebsql; 77 78 GHashTable *contacts; 79 gint n_add_changes; 80 gint n_locale_changes; 81 } EbSqlFixture; 82 83 typedef struct { 84 gboolean without_vcards; 85 EbSqlSetupSummary setup_summary; 86 } EbSqlClosure; 87 88 typedef struct { 89 EbSqlFixture parent_fixture; 90 91 EbSqlCursor *cursor; 92 EContact *contacts[N_SORTED_CONTACTS]; 93 EBookQuery *query; 94 95 guint own_id; 96 } EbSqlCursorFixture; 97 98 typedef struct { 99 EbSqlClosure parent; 100 101 const gchar *locale; 102 EBookCursorSortType sort_type; 103 } EbSqlCursorClosure; 104 105 typedef struct { 106 /* A locale change */ 107 gchar *locale; 108 109 /* count argument for move */ 110 gint count; 111 112 /* An array of 'ABS (counts[i])' expected contacts */ 113 gint expected[N_SORTED_CONTACTS]; 114 } StepAssertion; 115 116 typedef struct { 117 EbSqlCursorClosure parent; 118 gchar *path; 119 120 GList *assertions; 121 122 /* Whether this is a filtered test */ 123 gboolean filtered; 124 } StepData; 125 126 /* Base fixture */ 127 void e_sqlite_fixture_setup (EbSqlFixture *fixture, 128 gconstpointer user_data); 129 void e_sqlite_fixture_teardown (EbSqlFixture *fixture, 130 gconstpointer user_data); 131 ESourceBackendSummarySetup *setup_empty_book (void); 132 133 /* Cursor fixture */ 134 void e_sqlite_cursor_fixture_setup (EbSqlCursorFixture *fixture, 135 gconstpointer user_data); 136 void e_sqlite_cursor_fixture_teardown (EbSqlCursorFixture *fixture, 137 gconstpointer user_data); 138 void e_sqlite_cursor_fixture_set_locale (EbSqlCursorFixture *fixture, 139 const gchar *locale); 140 141 /* Filters contacts with E_CONTACT_EMAIL ending with '.com' */ 142 void e_sqlite_cursor_fixture_filtered_setup (EbSqlCursorFixture *fixture, 143 gconstpointer user_data); 144 145 gchar *new_vcard_from_test_case (const gchar *case_name); 146 EContact *new_contact_from_test_case (const gchar *case_name); 147 148 void add_contact_from_test_case (EbSqlFixture *fixture, 149 const gchar *case_name, 150 EContact **ret_contact); 151 void assert_contacts_order_slist (GSList *results, 152 GSList *uids); 153 void assert_contacts_order (GSList *results, 154 const gchar *first_uid, 155 ...) G_GNUC_NULL_TERMINATED; 156 157 void print_results (GSList *results); 158 159 /* Step test helpers */ 160 void step_test_add_assertion (StepData *data, 161 gint count, 162 ...); 163 void step_test_change_locale (StepData *data, 164 const gchar *locale, 165 gint expected_changes); 166 167 StepData *step_test_new (const gchar *test_prefix, 168 const gchar *test_path, 169 const gchar *locale, 170 gboolean store_vcards, 171 gboolean empty_book); 172 StepData *step_test_new_full (const gchar *test_prefix, 173 const gchar *test_path, 174 const gchar *locale, 175 gboolean store_vcards, 176 gboolean empty_book, 177 EBookCursorSortType sort_type); 178 179 void step_test_add (StepData *data, 180 gboolean filtered); 181 182 G_END_DECLS 183 184 #endif /* DATA_TEST_UTILS_H */ 185