1
/****************************************************************************
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/legal
6
** This file is part of the QtPim module of the Qt Toolkit.
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.
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.
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.
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.
40
****************************************************************************/
46
ContactsSavingTestCase {
49
name: "ContactsFilteringByDetailE2ETests"
53
manager: getManagerUnderTest()
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.
94
model.saveContact(contact1);
95
waitForContactsChanged();
96
model.saveContact(contact2);
97
waitForContactsChanged();
98
model.saveContact(contact3);
99
waitForContactsChanged();
100
compare(model.contacts.length, 3);
103
function createDetailFilter(detail, field, value, matchFlags) {
104
var filter = Qt.createQmlObject(
105
"import QtContacts 5.0;" +
109
filter.detail = detail
112
filter.matchFlags = matchFlags
116
function createPhoneNumberFilter(value, matchFlags) {
117
return createDetailFilter(ContactDetail.PhoneNumber, PhoneNumber.Number, value, matchFlags);
120
function createFirstNameFilter(value, matchFlags) {
121
return createDetailFilter(ContactDetail.Name, Name.FirstName, value, matchFlags);
124
function test_filterByDetail_data() {
126
tag: "Phone number, match exactly, identical value",
127
filter: createPhoneNumberFilter(contact1.phoneNumber.number, Filter.MatchExactly),
131
tag: "Phone number, match exactly, no match",
132
filter: createPhoneNumberFilter("1111", Filter.MatchExactly),
136
tag: "Phone number, match exactly, empty string",
137
filter: createPhoneNumberFilter("", Filter.MatchExactly),
141
tag: "Phone number, match contains, identical value",
142
filter: createPhoneNumberFilter(contact1.phoneNumber.number, Filter.MatchContains),
146
tag: "Phone number, match contains, no match",
147
filter: createPhoneNumberFilter(" ", Filter.MatchContains),
151
tag: "Phone number, match contains, matching substring",
152
filter: createPhoneNumberFilter("1111", Filter.MatchContains),
156
tag: "Phone number, match contains, empty string",
157
filter: createPhoneNumberFilter("", Filter.MatchContains),
158
matches: [contact1, contact2, contact3]
161
tag: "Phone number, match starts with, identical value",
162
filter: createPhoneNumberFilter(contact1.phoneNumber.number, Filter.MatchStartsWith),
166
tag: "Phone number, match starts with, no match",
167
filter: createPhoneNumberFilter(" ", Filter.MatchStartsWith),
171
tag: "Phone number, match starts with, matching substring",
172
filter: createPhoneNumberFilter("1111", Filter.MatchStartsWith),
176
tag: "Phone number, match starts with, empty string",
177
filter: createPhoneNumberFilter("", Filter.MatchStartsWith),
178
matches: [contact1, contact2, contact3]
181
tag: "Phone number, match ends with, identical value",
182
filter: createPhoneNumberFilter(contact1.phoneNumber.number, Filter.MatchEndsWith),
186
tag: "Phone number, match ends with, no match",
187
filter: createPhoneNumberFilter(" ", Filter.MatchEndsWith),
191
tag: "Phone number, match ends with, matching substring",
192
filter: createPhoneNumberFilter("1111", Filter.MatchEndsWith),
196
tag: "Phone number, match ends with, empty string",
197
filter: createPhoneNumberFilter("", Filter.MatchEndsWith),
198
matches: [contact1, contact2, contact3]
201
tag: "First name, match exactly, identical value",
202
filter: createFirstNameFilter(contact1.name.firstName, Filter.MatchExactly),
206
tag: "First name, match exactly, no match",
207
filter: createFirstNameFilter("C", Filter.MatchExactly),
211
tag: "First name, match contains , matching substring",
212
filter: createFirstNameFilter("Joe", Filter.MatchContains),
216
tag: "First name, match contains , caseInsensitive by default so matches",
217
filter: createFirstNameFilter("joe", Filter.MatchContains),
221
tag: "First name, match exactly ,always case sensitive so no matches here",
222
filter: createFirstNameFilter("john joe", Filter.MatchExactly),
226
tag: "First name, match fixed string , identical value",
227
filter: createFirstNameFilter("John Joe", Filter.MatchFixedString),
231
tag: "First name, match fixed string , no match",
232
filter: createFirstNameFilter("John", Filter.MatchFixedString),
236
tag: "First name, match fixed string, caseInsensitive by default so matches",
237
filter: createFirstNameFilter("john joe", Filter.MatchFixedString),
241
tag: "First name, match fixed string and case sensitive, no match",
242
filter: createFirstNameFilter("john joe", Filter.MatchFixedString | Filter.MatchCaseSensitive),
246
tag: "First name, match starts with, caseInsensitive by default so matches",
247
filter: createFirstNameFilter("john", Filter.MatchStartsWith),
251
tag: "First name, match starts with and match caseSensitive, matching substring",
252
filter: createFirstNameFilter("John", Filter.MatchStartsWith | Filter.MatchCaseSensitive),
256
tag: "First name, match starts with and match caseSensitive, no match",
257
filter: createFirstNameFilter("john", Filter.MatchStartsWith | Filter.MatchCaseSensitive),
261
tag: "First name, match ends with and match caseSensitive, matching substring",
262
filter: createFirstNameFilter("Joe", Filter.MatchEndsWith | Filter.MatchCaseSensitive),
266
tag: "First name, match ends with and match caseSensitive, no match",
267
filter: createFirstNameFilter("joe", Filter.MatchEndsWith | Filter.MatchCaseSensitive),
271
tag: "First name, match ends with, caseInsensitive by default so matches",
272
filter: createFirstNameFilter("joe", Filter.MatchEndsWith),
276
tag: "First name, match fixedString and match ends with, matching substring",
277
filter: createFirstNameFilter("John Joe", Filter.MatchFixedString | Filter.MatchEndsWith),
281
tag: "First name, match fixedString and match startsWith, matching substring",
282
filter: createFirstNameFilter("John Joe", Filter.MatchFixedString | Filter.MatchStartsWith),
286
tag: "Last name, match exactly, no contact has a value for last name",
287
filter: createDetailFilter(ContactDetail.Name, Name.LastName, "NoContactHasThisAsLastName", Filter.MatchExactly),
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++) {
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)
305
compare(match, true);
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);
330
waitForContactsChanged();
334
function cleanupTestCase() {
335
emptyContacts(model);
336
finishTestForModel(model);