Migrated sqlite cursor test cases to not specify any specific collation rule.
[platform/upstream/evolution-data-server.git] / tests / libedata-book / data-test-utils.h
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 2013, Openismus GmbH
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of version 2 of the GNU Lesser General Public
7  * License as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this program; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  *
19  * Authors: Tristan Van Berkom <tristanvb@openismus.com>
20  */
21
22 #ifndef DATA_TEST_UTILS_H
23 #define DATA_TEST_UTILS_H
24
25 #include <libebook/libebook.h>
26 #include <libedata-book/libedata-book.h>
27 #include "e-test-server-utils.h"
28
29
30 /* This legend shows the add order, and various sort order of the sorted
31  * vcards. The UIDs of these contacts are formed as 'sorted-1', 'sorted-2' etc
32  * and the numbering of the contacts is according to the 'N' column in the
33  * following legend.
34  *
35  * The Email column indicates whether the contact has a .com email address
36  * (in order to test filtered cursor results) and corresponds to the natural
37  * order in the 'N' column.
38  *
39  * +-----------------------------------------------------------------------------------------------+
40  * | N   | Email | Last Name   | en_US_POSIX    | en_US / de_DE  | fr_CA          | de_DE          |
41  * |     |       |             |                |                |                | (phonebook)    |
42  * +-----------------------------------------------------------------------------------------------+
43  * | 1   | Yes   | bad         |             11 |             11 |             11 |             11 |
44  * | 2   | Yes   | Bad         | Bad         2  | bad         1  | bad         1  | bad         1  |
45  * | 3   | Yes   | Bat         | Bäd         6  | Bad         2  | Bad         2  | Bad         2  |
46  * | 4   | No    | bat         | Bat         3  | bäd         5  | bäd         5  | bäd         5  |
47  * | 5   | Yes   | bäd         | Bät         8  | Bäd         6  | Bäd         6  | Bäd         6  |
48  * | 6   | No    | Bäd         | C           10 | bat         4  | bat         4  | bät         7  |
49  * | 7   | No    | bät         | Muffler     19 | Bat         3  | Bat         3  | Bät         8  |
50  * | 8   | Yes   | Bät         | Müller      20 | bät         7  | bät         7  | bat         4  |
51  * | 9   | Yes   | côté        | bad         1  | Bät         8  | Bät         8  | Bat         3  |
52  * | 10  | Yes   | C           | bäd         5  | black-bird  15 | black-bird  15 | black-bird  15 |
53  * | 11  | Yes   |             | bat         4  | black-birds 17 | black-birds 17 | black-birds 17 |
54  * | 12  | Yes   | coté        | bät         7  | blackbird   16 | blackbird   16 | blackbird   16 |
55  * | 13  | No    | côte        | black-bird  15 | blackbirds  18 | blackbirds  18 | blackbirds  18 |
56  * | 14  | Yes   | cote        | black-birds 17 | C           10 | C           10 | C           10 |
57  * | 15  | No    | black-bird  | blackbird   16 | cote        14 | cote        14 | cote        14 |
58  * | 16  | Yes   | blackbird   | blackbirds  18 | coté        12 | côte        13 | coté        12 | 
59  * | 17  | Yes   | black-birds | cote        14 | côte        13 | coté        12 | côte        13 | 
60  * | 18  | Yes   | blackbirds  | coté        12 | côté        9  | côté        9  | côté        9  | 
61  * | 19  | No    | Muffler     | côte        13 | Muffler     19 | Muffler     19 | Müller      20 | 
62  * | 20  | No    | Müller      | côté        9  | Müller      20 | Müller      20 | Muffler     19 |
63  * +-----------------------------------------------------------------------------------------------+
64  *
65  * See this ICU demo to check additional sort ordering by ICU in various locales:
66  *     http://demo.icu-project.org/icu-bin/locexp?_=en_US&d_=en&x=col
67  */
68
69 #define SQLITEDB_FOLDER_ID   "folder_id"
70 #define N_SORTED_CONTACTS    20
71 #define MAX_MOVE_BY_COUNTS   5
72
73 typedef struct {
74         ETestServerFixture parent_fixture;
75
76         EBookBackendSqliteDB *ebsdb;
77 } ESqliteDBFixture;
78
79 typedef struct {
80         ESqliteDBFixture parent_fixture;
81
82         EbSdbCursor     *cursor;
83         EContact        *contacts[N_SORTED_CONTACTS];
84         EBookQuery      *query;
85 } EbSdbCursorFixture;
86
87 typedef struct {
88         ETestServerClosure parent;
89
90 } EbSdbCursorClosure;
91
92 typedef struct {
93         EbSdbCursorClosure parent;
94         gchar *path;
95
96         /* array of counts to move by, terminated with 0 or MAX_COUNTS */
97         gint counts[MAX_MOVE_BY_COUNTS];
98
99         /* For each move_by() command, an array of 'ABS (counts[i])' expected contacts */
100         gint expected[MAX_MOVE_BY_COUNTS][N_SORTED_CONTACTS];
101
102         /* Private detail */
103         gsize struct_size;
104 } MoveByData;
105
106 void     e_sqlitedb_fixture_setup          (ESqliteDBFixture *fixture,
107                                             gconstpointer     user_data);
108 void     e_sqlitedb_fixture_teardown       (ESqliteDBFixture *fixture,
109                                             gconstpointer     user_data);
110
111 void     e_sqlitedb_cursor_fixture_setup_book (ESource            *scratch,
112                                                ETestServerClosure *closure);
113 void     e_sqlitedb_cursor_fixture_setup    (EbSdbCursorFixture *fixture,
114                                              gconstpointer       user_data);
115 void     e_sqlitedb_cursor_fixture_teardown (EbSdbCursorFixture *fixture,
116                                              gconstpointer       user_data);
117
118 /* Filters contacts with E_CONTACT_EMAIL ending with '.com' */
119 void     e_sqlitedb_cursor_fixture_filtered_setup (EbSdbCursorFixture *fixture,
120                                                    gconstpointer  user_data);
121
122
123 gchar    *new_vcard_from_test_case         (const gchar *case_name);
124 EContact *new_contact_from_test_case       (const gchar *case_name);
125
126 gboolean add_contact_from_test_case_verify (EBookClient *book_client,
127                                             const gchar *case_name,
128                                             EContact   **contact);
129
130 void     assert_contacts_order_slist       (GSList      *results,
131                                             GSList      *uids);
132 void     assert_contacts_order             (GSList      *results,
133                                             const gchar *first_uid,
134                                             ...) G_GNUC_NULL_TERMINATED;
135
136 void     print_results                     (GSList      *results);
137
138 /*  MoveBy test helpers */
139 void        move_by_test_add_assertion     (MoveByData  *data,
140                                             gint         count,
141                                             ...);
142 MoveByData *move_by_test_new               (const gchar *test_path);
143 void        move_by_test_add               (MoveByData  *data,
144                                             gboolean     filtered);
145
146 #endif /* DATA_TEST_UTILS_H */