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 {
47
name: "ContactsIntersectionFilterTests"
51
manager: getManagerUnderTest()
56
id: intersectionFilter
61
detail: ContactDetail.Name
64
matchFlags: Filter.MatchExactly
69
detail: ContactDetail.Name
72
matchFlags: Filter.MatchExactly
75
IdFilter { // contact id:s are set in initTestCase()
79
IdFilter { // contact id:s are set in initTestCase()
80
id: idFilter_2A_3A_1B_2B
131
function initTestCase() {
132
initTestForModel(model);
133
waitForContactsChanged();
134
// The wait is needed so the model is populated
135
// (e.g. with garbage left from previous test runs)
136
// before cleanup() is called.
137
emptyContacts(model);
138
saveContactsToModel();
142
function saveContactsToModel() {
143
model.saveContact(contact1A);
144
waitForContactsChanged();
145
model.saveContact(contact2A);
146
waitForContactsChanged();
147
model.saveContact(contact3A);
148
waitForContactsChanged();
149
model.saveContact(contact1B);
150
waitForContactsChanged();
151
model.saveContact(contact2B);
152
waitForContactsChanged();
153
model.saveContact(contact3B);
154
waitForContactsChanged();
155
compare(model.contacts.length, 6);
158
function setupIdFilter() {
159
idFilter_1B_2B_3B.ids = [findId("1", "B"), // contacts in model aren't guaranteed to be in the saving order, so find is needed
162
idFilter_2A_3A_1B_2B.ids = [findId("2", "A"),
168
function findId(firstName, lastName) {
169
for (var i = 0; i < model.contacts.length; i++) {
170
if (model.contacts[i].name.firstName == firstName &&
171
model.contacts[i].name.lastName == lastName)
172
return model.contacts[i].contactId;
176
function test_intersectionFilter_data() {
178
tag: "Intersection of two detail filters",
179
filters: [detailFilter1, detailFilterB],
180
intersection: [contact1B]
183
tag: "Intersection of detail filter and id filter",
184
filters: [detailFilterB, idFilter_2A_3A_1B_2B],
185
intersection: [contact1B, contact2B]
188
tag: "Intersection of two id filters",
189
filters: [idFilter_1B_2B_3B, idFilter_2A_3A_1B_2B],
190
intersection: [contact1B, contact2B]
193
tag: "Intersection of two id filters and detail filter",
194
filters: [detailFilter1, idFilter_1B_2B_3B, idFilter_2A_3A_1B_2B],
195
intersection: [contact1B]
198
tag: "Intersection filter with empty filter set (manager: jsondb)",
201
intersection: [contact1A, contact2A, contact3A, contact1B, contact2B, contact3B]
204
tag: "Intersection filter with empty filter set (manager: memory)",
210
tag: "Intersection filter with a single detail filter",
211
filters: [detailFilter1],
212
intersection: [contact1A, contact1B]
217
function test_intersectionFilter(data) {
218
if (data.manager && data.manager !== model.manager)
219
skip("Test not applicable to this manager");
220
intersectionFilter.filters = data.filters;
221
model.filter = intersectionFilter;
222
waitForContactsChanged();
223
compareContacts(model.contacts, data.intersection)
226
function compareContacts(set1, set2) {
227
// Compare filtered set to expected set.
228
// All contacts in sets are assumed to have unique firstName and lastName detail pairs.
229
compare(set1.length, set2.length);
230
for (var i = 0; i < set1.length; i++) {
232
for (var j = 0; j < set2.length; j++) {
233
if (set1[i].name.firstName == set2[j].name.firstName &&
234
set1[i].name.lastName == set2[j].name.lastName)
237
compare(match, true);
244
waitForContactsChanged();
248
function cleanupTestCase() {
249
emptyContacts(model);
250
finishTestForModel(model);