~chris.gagnon/+junk/qtpim-coverage

« back to all changes in this revision

Viewing changes to tests/auto/contacts/qmlcontacts/testcases/tst_contacts_filtering_by_detail_e2e.qml

  • Committer: chris.gagnon
  • Date: 2013-12-10 23:09:37 UTC
  • Revision ID: chris.gagnon@canonical.com-20131210230937-2akf1ft1edcttk87
first post

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/legal
 
5
**
 
6
** This file is part of the QtPim module of the Qt Toolkit.
 
7
**
 
8
** $QT_BEGIN_LICENSE:LGPL$
 
9
** Commercial License Usage
 
10
** Licensees holding valid commercial Qt licenses may use this file in
 
11
** accordance with the commercial license agreement provided with the
 
12
** Software or, alternatively, in accordance with the terms contained in
 
13
** a written agreement between you and Digia.  For licensing terms and
 
14
** conditions see http://qt.digia.com/licensing.  For further information
 
15
** use the contact form at http://qt.digia.com/contact-us.
 
16
**
 
17
** GNU Lesser General Public License Usage
 
18
** Alternatively, this file may be used under the terms of the GNU Lesser
 
19
** General Public License version 2.1 as published by the Free Software
 
20
** Foundation and appearing in the file LICENSE.LGPL included in the
 
21
** packaging of this file.  Please review the following information to
 
22
** ensure the GNU Lesser General Public License version 2.1 requirements
 
23
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 
24
**
 
25
** In addition, as a special exception, Digia gives you certain additional
 
26
** rights.  These rights are described in the Digia Qt LGPL Exception
 
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
 
28
**
 
29
** GNU General Public License Usage
 
30
** Alternatively, this file may be used under the terms of the GNU
 
31
** General Public License version 3.0 as published by the Free Software
 
32
** Foundation and appearing in the file LICENSE.GPL included in the
 
33
** packaging of this file.  Please review the following information to
 
34
** ensure the GNU General Public License version 3.0 requirements will be
 
35
** met: http://www.gnu.org/copyleft/gpl.html.
 
36
**
 
37
**
 
38
** $QT_END_LICENSE$
 
39
**
 
40
****************************************************************************/
 
41
 
 
42
import QtQuick 2.0
 
43
import QtTest 1.0
 
44
import QtContacts 5.0
 
45
 
 
46
ContactsSavingTestCase {
 
47
 
 
48
    id: testcase
 
49
    name: "ContactsFilteringByDetailE2ETests"
 
50
 
 
51
    ContactModel {
 
52
        id: model
 
53
        manager: getManagerUnderTest()
 
54
        autoUpdate: true
 
55
    }
 
56
 
 
57
    Contact {
 
58
        id: contact1;
 
59
        Name {
 
60
            firstName: "A"
 
61
        }
 
62
        PhoneNumber {
 
63
            number: "1111111111"
 
64
        }
 
65
    }
 
66
 
 
67
    Contact {
 
68
        id: contact2;
 
69
        Name {
 
70
            firstName: "B"
 
71
        }
 
72
        PhoneNumber {
 
73
            number: "2222222222"
 
74
        }
 
75
    }
 
76
 
 
77
    Contact {
 
78
        id: contact3;
 
79
        Name {
 
80
            firstName: "John Joe"
 
81
        }
 
82
        PhoneNumber {
 
83
            number: "3333333333"
 
84
        }
 
85
    }
 
86
 
 
87
    function initTestCase() {
 
88
        initTestForModel(model);
 
89
        waitForContactsChanged();
 
90
        // The wait is needed so the model is populated
 
91
        // (e.g. with garbage left from previous test runs)
 
92
        // before cleanup() is called.
 
93
        emptyContacts(model);
 
94
        model.saveContact(contact1);
 
95
        waitForContactsChanged();
 
96
        model.saveContact(contact2);
 
97
        waitForContactsChanged();
 
98
        model.saveContact(contact3);
 
99
        waitForContactsChanged();
 
100
        compare(model.contacts.length, 3);
 
101
    }
 
102
 
 
103
    function createDetailFilter(detail, field, value, matchFlags) {
 
104
        var filter = Qt.createQmlObject(
 
105
                    "import QtContacts 5.0;" +
 
106
                    "DetailFilter {}",
 
107
                    testcase);
 
108
 
 
109
        filter.detail = detail
 
110
        filter.field = field
 
111
        filter.value = value
 
112
        filter.matchFlags = matchFlags
 
113
        return filter;
 
114
    }
 
115
 
 
116
    function createPhoneNumberFilter(value, matchFlags) {
 
117
        return createDetailFilter(ContactDetail.PhoneNumber, PhoneNumber.Number, value, matchFlags);
 
118
    }
 
119
 
 
120
    function createFirstNameFilter(value, matchFlags) {
 
121
        return createDetailFilter(ContactDetail.Name, Name.FirstName, value, matchFlags);
 
122
    }
 
123
 
 
124
    function test_filterByDetail_data() {
 
125
        return [{
 
126
                    tag: "Phone number, match exactly, identical value",
 
127
                    filter: createPhoneNumberFilter(contact1.phoneNumber.number, Filter.MatchExactly),
 
128
                    matches: [contact1]
 
129
                },
 
130
                {
 
131
                    tag: "Phone number, match exactly, no match",
 
132
                    filter: createPhoneNumberFilter("1111", Filter.MatchExactly),
 
133
                    matches: []
 
134
                },
 
135
                {
 
136
                    tag: "Phone number, match exactly, empty string",
 
137
                    filter: createPhoneNumberFilter("", Filter.MatchExactly),
 
138
                    matches: []
 
139
                },
 
140
                {
 
141
                    tag: "Phone number, match contains, identical value",
 
142
                    filter: createPhoneNumberFilter(contact1.phoneNumber.number, Filter.MatchContains),
 
143
                    matches: [contact1]
 
144
                },
 
145
                {
 
146
                    tag: "Phone number, match contains, no match",
 
147
                    filter: createPhoneNumberFilter(" ", Filter.MatchContains),
 
148
                    matches: []
 
149
                },
 
150
                {
 
151
                    tag: "Phone number, match contains, matching substring",
 
152
                    filter: createPhoneNumberFilter("1111", Filter.MatchContains),
 
153
                    matches: [contact1]
 
154
                },
 
155
                {
 
156
                    tag: "Phone number, match contains, empty string",
 
157
                    filter: createPhoneNumberFilter("", Filter.MatchContains),
 
158
                    matches: [contact1, contact2, contact3]
 
159
                },
 
160
                {
 
161
                    tag: "Phone number, match starts with, identical value",
 
162
                    filter: createPhoneNumberFilter(contact1.phoneNumber.number, Filter.MatchStartsWith),
 
163
                    matches: [contact1]
 
164
                },
 
165
                {
 
166
                    tag: "Phone number, match starts with, no match",
 
167
                    filter: createPhoneNumberFilter(" ", Filter.MatchStartsWith),
 
168
                    matches: []
 
169
                },
 
170
                {
 
171
                    tag: "Phone number, match starts with, matching substring",
 
172
                    filter: createPhoneNumberFilter("1111", Filter.MatchStartsWith),
 
173
                    matches: [contact1]
 
174
                },
 
175
                {
 
176
                    tag: "Phone number, match starts with, empty string",
 
177
                    filter: createPhoneNumberFilter("", Filter.MatchStartsWith),
 
178
                    matches: [contact1, contact2, contact3]
 
179
                },
 
180
                {
 
181
                    tag: "Phone number, match ends with, identical value",
 
182
                    filter: createPhoneNumberFilter(contact1.phoneNumber.number, Filter.MatchEndsWith),
 
183
                    matches: [contact1]
 
184
                },
 
185
                {
 
186
                    tag: "Phone number, match ends with, no match",
 
187
                    filter: createPhoneNumberFilter(" ", Filter.MatchEndsWith),
 
188
                    matches: []
 
189
                },
 
190
                {
 
191
                    tag: "Phone number, match ends with, matching substring",
 
192
                    filter: createPhoneNumberFilter("1111", Filter.MatchEndsWith),
 
193
                    matches: [contact1]
 
194
                },
 
195
                {
 
196
                    tag: "Phone number, match ends with, empty string",
 
197
                    filter: createPhoneNumberFilter("", Filter.MatchEndsWith),
 
198
                    matches: [contact1, contact2, contact3]
 
199
                },
 
200
                {
 
201
                    tag: "First name, match exactly, identical value",
 
202
                    filter: createFirstNameFilter(contact1.name.firstName, Filter.MatchExactly),
 
203
                    matches: [contact1]
 
204
                },
 
205
                {
 
206
                    tag: "First name, match exactly, no match",
 
207
                    filter: createFirstNameFilter("C", Filter.MatchExactly),
 
208
                    matches: []
 
209
                },
 
210
                {
 
211
                    tag: "First name, match contains , matching substring",
 
212
                    filter: createFirstNameFilter("Joe", Filter.MatchContains),
 
213
                    matches: [contact3]
 
214
                },
 
215
                {
 
216
                    tag: "First name, match contains , caseInsensitive by default so matches",
 
217
                    filter: createFirstNameFilter("joe", Filter.MatchContains),
 
218
                    matches: [contact3]
 
219
                },
 
220
                {
 
221
                    tag: "First name, match exactly ,always case sensitive so no matches here",
 
222
                    filter: createFirstNameFilter("john joe", Filter.MatchExactly),
 
223
                    matches: []
 
224
                },
 
225
                {
 
226
                    tag: "First name, match fixed string , identical value",
 
227
                    filter: createFirstNameFilter("John Joe", Filter.MatchFixedString),
 
228
                    matches: [contact3]
 
229
                },
 
230
                {
 
231
                    tag: "First name, match fixed string , no match",
 
232
                    filter: createFirstNameFilter("John", Filter.MatchFixedString),
 
233
                    matches: []
 
234
                },
 
235
                {
 
236
                    tag: "First name, match fixed string, caseInsensitive by default so matches",
 
237
                    filter: createFirstNameFilter("john joe", Filter.MatchFixedString),
 
238
                    matches: [contact3]
 
239
                },
 
240
                {
 
241
                    tag: "First name, match fixed string and case sensitive, no match",
 
242
                    filter: createFirstNameFilter("john joe", Filter.MatchFixedString | Filter.MatchCaseSensitive),
 
243
                    matches: []
 
244
                },
 
245
                {
 
246
                    tag: "First name, match starts with, caseInsensitive by default so matches",
 
247
                    filter: createFirstNameFilter("john", Filter.MatchStartsWith),
 
248
                    matches: [contact3]
 
249
                },
 
250
                {
 
251
                    tag: "First name, match starts with and match caseSensitive, matching substring",
 
252
                    filter: createFirstNameFilter("John", Filter.MatchStartsWith | Filter.MatchCaseSensitive),
 
253
                    matches: [contact3]
 
254
                },
 
255
                {
 
256
                    tag: "First name, match starts with and match caseSensitive, no match",
 
257
                    filter: createFirstNameFilter("john", Filter.MatchStartsWith | Filter.MatchCaseSensitive),
 
258
                    matches: []
 
259
                },
 
260
                {
 
261
                    tag: "First name, match ends with and match caseSensitive, matching substring",
 
262
                    filter: createFirstNameFilter("Joe", Filter.MatchEndsWith | Filter.MatchCaseSensitive),
 
263
                    matches: [contact3]
 
264
                },
 
265
                {
 
266
                    tag: "First name, match ends with and match caseSensitive, no match",
 
267
                    filter: createFirstNameFilter("joe", Filter.MatchEndsWith | Filter.MatchCaseSensitive),
 
268
                    matches: []
 
269
                },
 
270
                {
 
271
                    tag: "First name, match ends with, caseInsensitive by default so matches",
 
272
                    filter: createFirstNameFilter("joe", Filter.MatchEndsWith),
 
273
                    matches: [contact3]
 
274
                },
 
275
                {
 
276
                    tag: "First name, match fixedString and match ends with, matching substring",
 
277
                    filter: createFirstNameFilter("John Joe", Filter.MatchFixedString | Filter.MatchEndsWith),
 
278
                    matches: [contact3]
 
279
                },
 
280
                {
 
281
                    tag: "First name, match fixedString and match startsWith, matching substring",
 
282
                    filter: createFirstNameFilter("John Joe", Filter.MatchFixedString | Filter.MatchStartsWith),
 
283
                    matches: [contact3]
 
284
                },
 
285
                {
 
286
                    tag: "Last name, match exactly, no contact has a value for last name",
 
287
                    filter: createDetailFilter(ContactDetail.Name, Name.LastName, "NoContactHasThisAsLastName", Filter.MatchExactly),
 
288
                    matches: []
 
289
                },
 
290
               ]
 
291
    }
 
292
 
 
293
    function test_filterByDetail(data) {
 
294
        model.filter = data.filter;
 
295
        waitForContactsChanged();
 
296
        compare(model.contacts.length, data.matches.length, data.tag);
 
297
        // Compare filtered set to expected set
 
298
        for (var i = 0; i < model.contacts.length; i++) {
 
299
            var match = false;
 
300
            for (var j = 0; j < data.matches.length; j++) {
 
301
                if (model.contacts[i].name.firstName == data.matches[j].name.firstName &&
 
302
                    model.contacts[i].phoneNumber.number == data.matches[j].phoneNumber.number)
 
303
                    match = true;
 
304
            }
 
305
            compare(match, true);
 
306
        }
 
307
    }
 
308
 
 
309
    function test_settingMatchFlagDoesChangeTheContacts() {
 
310
        var filter = createPhoneNumberFilter("1111", Filter.MatchExactly);
 
311
        model.filter = filter;
 
312
        waitForContactsChanged();
 
313
        compare(model.contacts.length, 0);
 
314
        model.filter.matchFlags = Filter.MatchContains;
 
315
        waitForContactsChanged();
 
316
        compare(model.contacts.length, 1);
 
317
        model.filter.matchFlags = Filter.MatchStartsWith;
 
318
        waitForContactsChanged();
 
319
        compare(model.contacts.length, 1);
 
320
        model.filter.matchFlags = Filter.MatchEndsWith;
 
321
        waitForContactsChanged();
 
322
        compare(model.contacts.length, 1);
 
323
    }
 
324
 
 
325
    // Teardown
 
326
 
 
327
    function cleanup() {
 
328
        if (model.filter) {
 
329
            model.filter = null;
 
330
            waitForContactsChanged();
 
331
        }
 
332
    }
 
333
 
 
334
    function cleanupTestCase() {
 
335
        emptyContacts(model);
 
336
        finishTestForModel(model);
 
337
    }
 
338
 
 
339
}