Changes: Consider display name settings in unit tests
[qtcontacts-tracker:hasselmms-qtcontacts-tracker.git] / tests / ut_qtcontacts_trackerplugin / ut_qtcontacts_trackerplugin.h
1 /*********************************************************************************
2  ** This file is part of QtContacts tracker storage plugin
3  **
4  ** Copyright (c) 2009-2011 Nokia Corporation and/or its subsidiary(-ies).
5  **
6  ** Contact:  Nokia Corporation (info@qt.nokia.com)
7  **
8  ** GNU Lesser General Public License Usage
9  ** This file may be used under the terms of the GNU Lesser General Public License
10  ** version 2.1 as published by the Free Software Foundation and appearing in the
11  ** file LICENSE.LGPL included in the packaging of this file.  Please review the
12  ** following information to ensure the GNU Lesser General Public License version
13  ** 2.1 requirements will be met:
14  ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
15  **
16  ** In addition, as a special exception, Nokia gives you certain additional rights.
17  ** These rights are described in the Nokia Qt LGPL Exception version 1.1, included
18  ** in the file LGPL_EXCEPTION.txt in this package.
19  **
20  ** Other Usage
21  ** Alternatively, this file may be used in accordance with the terms and
22  ** conditions contained in a signed written agreement between you and Nokia.
23  *********************************************************************************/
24
25 #ifndef UT_QTCONTACTS_TRACKERPLUGIN_H
26 #define UT_QTCONTACTS_TRACKERPLUGIN_H
27
28 #include "ut_qtcontacts_trackerplugin_common.h"
29
30
31 // FIXME: This type name doesn't fit anything!!!
32 struct editStruct;
33 typedef class QMap<QString, QtMobility::QContactDetailFieldDefinition> QContactDetailFieldDefinitionMap;
34 typedef QPair<QContactDetail, QString> ContactDetailSample;
35
36 /**
37  * QtContacts Tracker plugin unittests
38  */
39 class ut_qtcontacts_trackerplugin : public ut_qtcontacts_trackerplugin_common
40 {
41     Q_OBJECT
42
43 public:
44     ut_qtcontacts_trackerplugin(QObject *parent = 0);
45
46 private slots:
47     void initTestCase();
48     void cleanupTestCase();
49     void cleanup();
50
51     void testFetchAll();
52     void testFetchById_data();
53     void testFetchById();
54
55     void testTorture_data();
56     void testTorture();
57
58     void testSaveNothing();
59     void testSavePhoneNumber_data();
60     void testSavePhoneNumber();
61     void testSimilarPhoneNumber();
62     void testEasternArabicPhoneNumber_data();
63     void testEasternArabicPhoneNumber();
64     void testSamePhoneNumber();
65     void testPhoneNumberContext();
66     void testWritingOnlyWorkMobile();
67     void testContacts();
68     void testContact();
69     void testAvatar();
70     void testOnlineAvatar_data();
71     void testOnlineAvatar();
72     void testDateDetail_data();
73     void testDateDetail();
74
75     void testSaveEmailAddress();
76     void testSaveFullname();
77     void testSaveName();
78     void testSaveNameUnique();
79     void testSaveNonLatin1Name_data();
80     void testSaveNonLatin1Name();
81     void testSaveAddress();
82     void testExtendedAddress();
83     void testSaveOrganization();
84     void testSaveCustomValues();
85
86     void testRemoveContact();
87     void testRemoveSelfContact();
88     void testSaveContacts();
89     void testRemoveContacts();
90     void testUrl_data();
91     void testUrl();
92     void testMultipleUrls();
93     void testOrganization();
94     void testUniqueDetails_data();
95     void testUniqueDetails();
96     void testCustomDetails();
97
98     void testRemoveSubType_data();
99     void testRemoveSubType();
100     void testTags_data();
101     void testTags();
102     void testFavouriteTag();
103
104 //    void testGroups();
105 //    void testGroup();
106 //    void testSaveGroup();
107 //    void testRemoveGroup();
108 //    void testDetailDefinitions();
109 //    void testDetailDefinition();
110 //    void testSaveDetailDefinition();
111 //    void testRemoveDetailDefinition();
112     void testSyncContactManagerContactsAddedSince();
113     void testSyncTrackerEngineContactsIdsAddedSince();
114     void testSyncContactManagerContactIdsAddedSince();
115     void testContactsAddedSince();
116     void testContactsModifiedSince();
117     void testContactsRemovedSince();
118 //    void testGroupsAddedSince();
119 //    void testGroupsModifiedSince();
120 //    void testGroupsRemovedSince();
121     void testMergeOnlineContacts();
122     void testMergingContacts();
123     void testMergeSyncTarget_data();
124     void testMergeSyncTarget();
125     void testAsyncReadContacts();
126
127     void testSortContacts();
128     void testSparqlSorting_data();
129     void testSparqlSorting();
130
131     void testFilterContacts();
132     void testFilterContactsEndsWithAndPhoneNumber();
133     void testFilterDTMFNumber();
134 // NB#208065
135     void testFilterContactsMatchPhoneNumberWithShortNumber_data();
136     void testFilterContactsMatchPhoneNumberWithShortNumber();
137 // end NB#208065
138     void testFilterTwoNameFields();
139     void testFilterContactsWithBirthday_data();
140     void testFilterContactsWithBirthday();
141     void testLocalIdFilterManyIds_data();
142     void testLocalIdFilterManyIds();
143     void testContactFilter_data();
144     void testContactFilter();
145     void testFilterOnContainsSubTypesByClass();
146     void testFilterOnSubTypesByProperty();
147     void testFilterOnContainsSubTypesByNaoProperty();
148     void testFilterOnCustomDetail_data();
149     void testFilterOnCustomDetail();
150     void testFilterOnContactType();
151     void testFilterOnQContactOnlineAccount();
152     void testFilterOnDetailFieldWildcard_data();
153     void testFilterOnDetailFieldWildcard();
154     void testFilterOnDetailExists_data();
155     void testFilterOnDetailExists();
156     void testFilterOnContext_data();
157     void testFilterOnContext();
158
159     void testFilterOnDetailFieldValueWithSingleSpaceOrEmptyString_data();
160     void testFilterOnDetailFieldValueWithSingleSpaceOrEmptyString();
161
162     void testFilterInvalid();
163
164     void testIMContactsAndMetacontactMasterPresence();
165     void testIMContactsFiltering();
166     void testContactsWithoutMeContact();
167     void testDefinitionNames();
168     void testMeContact();
169
170     void testDisplayLabelFetch_data();
171     void testDisplayLabelFetch();
172     void testDisplayLabelSaved_data();
173     void testDisplayLabelSaved();
174     void testDisplayLabelSynthesized_data();
175     void testDisplayLabelSynthesized();
176     void testDisplayLabelSynthesizedWithNameOrders_data();
177     void testDisplayLabelSynthesizedWithNameOrders();
178
179     void testSyncTarget_data();
180     void testSyncTarget();
181
182 // NB#161788 and its dependant bugs
183     void testEditCombinations_email();
184     void testEditCombinations_url();
185     void testEditCombinations_address();
186     void testEditCombinations_phone();
187 // end NB#161788
188
189 // NB#173388
190     void testSaveThumbnail_data();
191     void testSaveThumbnail();
192 // end NB#173388
193
194     void testVCardsAndSync_data();
195     void testVCardsAndSync();
196     void testCreateUuid();
197     void testPreserveUID();
198
199     void testFuzzing_data();
200     void testFuzzing();
201
202     void testUnionFilterUniqueness();
203     void testPartialSave_data();
204     void testPartialSave();
205     void testPartialSaveAndWeakSyncTargets_data();
206     void testPartialSaveAndWeakSyncTargets();
207     void testPartialSaveAndThumbnails_data();
208     void testPartialSaveAndThumbnails();
209     void testPartialSaveFuzz_data();
210     void testPartialSaveFuzz();
211
212     void testFetchingNonQctResourcesAsReadOnlyDetails_data();
213     void testFetchingNonQctResourcesAsReadOnlyDetails();
214     void testNotSavingReadOnlyDetails();
215
216     void testFavorite();
217     void testAnniversary();
218     void testOnlineAccount();
219
220     void testMergeContactsWithGroups();
221
222     void testDeleteFromStateChangedHandler_data();
223     void testDeleteFromStateChangedHandler();
224
225     void testDetailUriEncoding();
226
227 private:
228     // FIXME: Most of the following methods are editStruct methods!!!
229     void setName(editStruct &es, QString first = QString(), QString last = QString());
230     void setEmail(editStruct &es, QString email, QString context = QString());
231     void setUrl(editStruct &es, QString url, QString context = QString(), QString subType = QString());
232     void setPhone(editStruct &es, QString phone, QString context = QString(), QString subType = QString());
233     void setAddress(editStruct &es, QString street, QString postcode = QString(), QString pobox = QString(), QString locality = QString(), QString region = QString(), QString country = QString(), QString context = QString(), QString subType = QString());
234     void saveEditsToContact(editStruct &es, QContact &c);
235
236     void verifyEdits(QContact &verify, editStruct &es);
237     void runEditList(QList<editStruct> &editList);
238
239     void syncContactsAddedSinceHelper(QDateTime& start, QList<QContactLocalId>& addedIds);
240
241     void updateIMContactStatus(const QString &contactIri, const QString &imStatus);
242     QContact contact(QContactLocalId uid, const QStringList &detailsToLoad = QStringList());
243     QContact contact(const QString &iri, const QStringList &detailsToLoad = QStringList());
244     QList<QContact> contacts(const QList<QContactLocalId> &uids, const QStringList &detailsToLoad = QStringList());
245
246     void fuzzContact(QContact &result, const QStringList &skipDetailDefinitions = QStringList()) const;
247     void fuzzDetailType(QList<QContactDetail> &result, const QString &definitionName) const;
248     void mergeContacts(QContact &contactTarget, const QList<QContactLocalId> &sourceContactIds);
249     void unmergeContact(QContact &contact, const QList<QContactOnlineAccount> &unmergeCriteria, /*out*/ QList<QContactLocalId> &newUnmergedContactIds);
250
251     /// creates fuzzed values for the given @p field and for each value a contact of @p contactType with only that detail and only that field set,
252     /// then stores and adds these contacts to @p contacts
253     void makeFuzzedSingleDetailFieldContacts(QContactList &contacts,
254                                              const QString &detailName, const QString &fieldName, const QContactDetailFieldDefinition &field,
255                                              const QString &contactType);
256     /// sets the field definitions of @p detailDefinition to @p fields,
257     /// without any for the fields Context and SubType/SubTypes
258     void fieldsWithoutContextAndSubType(QContactDetailFieldDefinitionMap &fields,
259                                         const QString &contactType, const QString &definitionName);
260
261     const QList<ContactDetailSample> displayLabelDetailSamples(bool preferNickname, bool preferLastname);
262
263 private:
264     QList<QContactLocalId> addedContacts;
265 };
266
267 class EvilRequestKiller : QObject
268 {
269     Q_OBJECT
270
271 public:
272     EvilRequestKiller(QContactAbstractRequest *request,
273                       Qt::ConnectionType connectionType,
274                       QContactAbstractRequest::State deletionState,
275                       QObject *parent = 0);
276
277 private slots:
278     void onStateChanged(QContactAbstractRequest::State state);
279
280 private:
281     QContactAbstractRequest *const m_request;
282     QContactAbstractRequest::State const m_deletionState;
283 };
284
285 #endif