New: ut_qtcontacts_trackerplugin::testNormalizePhoneNumber()
[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 testAvatarTypes_data();
73     void testAvatarTypes();
74     void testDateDetail_data();
75     void testDateDetail();
76
77     void testSaveEmailAddress();
78     void testSaveFullname();
79     void testSaveName();
80     void testSaveNameUnique();
81     void testSaveNonLatin1Name_data();
82     void testSaveNonLatin1Name();
83     void testSaveAddress();
84     void testExtendedAddress();
85     void testSaveOrganization();
86     void testSaveCustomValues();
87
88     void testRemoveContact();
89     void testRemoveSelfContact();
90     void testSaveContacts();
91     void testRemoveContacts();
92     void testUrl_data();
93     void testUrl();
94     void testMultipleUrls();
95     void testOrganization();
96     void testUniqueDetails_data();
97     void testUniqueDetails();
98     void testCustomDetails();
99
100     void testRemoveSubType_data();
101     void testRemoveSubType();
102     void testTags_data();
103     void testTags();
104     void testFavouriteTag();
105
106 //    void testGroups();
107 //    void testGroup();
108 //    void testSaveGroup();
109 //    void testRemoveGroup();
110 //    void testDetailDefinitions();
111 //    void testDetailDefinition();
112 //    void testSaveDetailDefinition();
113 //    void testRemoveDetailDefinition();
114     void testSyncContactManagerContactsAddedSince();
115     void testSyncTrackerEngineContactsIdsAddedSince();
116     void testSyncContactManagerContactIdsAddedSince();
117     void testContactsAddedSince();
118     void testContactsModifiedSince();
119     void testContactsRemovedSince();
120 //    void testGroupsAddedSince();
121 //    void testGroupsModifiedSince();
122 //    void testGroupsRemovedSince();
123     void testMergeOnlineContacts();
124     void testMergingContacts();
125     void testMergingGarbage();
126     void testMergeSyncTarget_data();
127     void testMergeSyncTarget();
128     void testAsyncReadContacts();
129
130     void testSortContacts();
131     void testSparqlSorting_data();
132     void testSparqlSorting();
133
134     void testLimit_data();
135     void testLimit();
136
137     void testFilterContacts();
138     void testFilterContactsEndsWithAndPhoneNumber();
139     void testNormalizePhoneNumber_data();
140     void testNormalizePhoneNumber();
141     void testFilterDTMFNumber();
142
143 // NB#208065
144     void testFilterContactsMatchPhoneNumberWithShortNumber_data();
145     void testFilterContactsMatchPhoneNumberWithShortNumber();
146 // end NB#208065
147     void testFilterTwoNameFields();
148     void testFilterContactsWithBirthday_data();
149     void testFilterContactsWithBirthday();
150     void testLocalIdFilterManyIds_data();
151     void testLocalIdFilterManyIds();
152     void testContactFilter_data();
153     void testContactFilter();
154     void testFilterOnContainsSubTypesByClass();
155     void testFilterOnSubTypesByProperty();
156     void testFilterOnContainsSubTypesByNaoProperty();
157     void testFilterOnCustomDetail_data();
158     void testFilterOnCustomDetail();
159     void testFilterOnContactType();
160     void testFilterOnQContactOnlineAccount();
161     void testFilterOnDetailFieldWildcard_data();
162     void testFilterOnDetailFieldWildcard();
163     void testFilterOnDetailExists_data();
164     void testFilterOnDetailExists();
165     void testFilterOnContext_data();
166     void testFilterOnContext();
167
168     void testFilterOnDetailFieldValueWithSingleSpaceOrEmptyString_data();
169     void testFilterOnDetailFieldValueWithSingleSpaceOrEmptyString();
170
171     void testFilterInvalid();
172
173     void testIMContactsAndMetacontactMasterPresence();
174     void testIMContactsFiltering();
175     void testContactsWithoutMeContact();
176     void testDefinitionNames();
177     void testMeContact();
178
179     void testDisplayLabelFetch_data();
180     void testDisplayLabelFetch();
181     void testDisplayLabelSaved_data();
182     void testDisplayLabelSaved();
183     void testDisplayLabelSynthesized_data();
184     void testDisplayLabelSynthesized();
185     void testDisplayLabelSynthesizedWithNameOrders_data();
186     void testDisplayLabelSynthesizedWithNameOrders();
187
188     void testSyncTarget_data();
189     void testSyncTarget();
190
191 // NB#161788 and its dependant bugs
192     void testEditCombinations_email();
193     void testEditCombinations_url();
194     void testEditCombinations_address();
195     void testEditCombinations_phone();
196 // end NB#161788
197
198 // NB#173388
199     void testSaveThumbnail_data();
200     void testSaveThumbnail();
201 // end NB#173388
202
203     void testVCardsAndSync_data();
204     void testVCardsAndSync();
205     void testCreateUuid();
206     void testPreserveUID();
207
208     void testFuzzing_data();
209     void testFuzzing();
210
211     void testUnionFilterUniqueness();
212     void testPartialSave_data();
213     void testPartialSave();
214     void testPartialSaveAndWeakSyncTargets_data();
215     void testPartialSaveAndWeakSyncTargets();
216     void testPartialSaveAndThumbnails_data();
217     void testPartialSaveAndThumbnails();
218     void testPartialSaveFuzz_data();
219     void testPartialSaveFuzz();
220
221     void testFetchingNonQctResourcesAsReadOnlyDetails_data();
222     void testFetchingNonQctResourcesAsReadOnlyDetails();
223     void testNotSavingReadOnlyDetails();
224
225     void testDetailsFromServicesAreLinked_data();
226     void testDetailsFromServicesAreLinked();
227     void testDetailsFromServicesAreLinkedWithMergedContacts();
228     void testDetailsFromServicesAreLinkedWithMergedContacts_data();
229
230     void testFavorite();
231     void testAnniversary();
232     void testOnlineAccount();
233
234     void testMergeContactsWithGroups();
235
236     void testDeleteFromStateChangedHandler_data();
237     void testDeleteFromStateChangedHandler();
238
239     void testDetailUriEncoding();
240
241 private:
242     // FIXME: Most of the following methods are editStruct methods!!!
243     void setName(editStruct &es, QString first = QString(), QString last = QString());
244     void setEmail(editStruct &es, QString email, QString context = QString());
245     void setUrl(editStruct &es, QString url, QString context = QString(), QString subType = QString());
246     void setPhone(editStruct &es, QString phone, QString context = QString(), QString subType = QString());
247     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());
248     void saveEditsToContact(editStruct &es, QContact &c);
249
250     void verifyEdits(QContact &verify, editStruct &es);
251     void runEditList(QList<editStruct> &editList);
252
253     void syncContactsAddedSinceHelper(QDateTime& start, QList<QContactLocalId>& addedIds);
254
255     void updateIMContactStatus(const QString &contactIri, const QString &imStatus);
256     QContact contact(QContactLocalId uid, const QStringList &detailsToLoad = QStringList());
257     QContact contact(const QString &iri, const QStringList &detailsToLoad = QStringList());
258     QList<QContact> contacts(const QList<QContactLocalId> &uids, const QStringList &detailsToLoad = QStringList());
259
260     void fuzzContact(QContact &result, const QStringList &skipDetailDefinitions = QStringList()) const;
261     void fuzzDetailType(QList<QContactDetail> &result, const QString &definitionName) const;
262     void mergeContacts(QContact &contactTarget, const QList<QContactLocalId> &sourceContactIds);
263     void unmergeContact(QContact &contact, const QList<QContactOnlineAccount> &unmergeCriteria, /*out*/ QList<QContactLocalId> &newUnmergedContactIds);
264
265     /// 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,
266     /// then stores and adds these contacts to @p contacts
267     void makeFuzzedSingleDetailFieldContacts(QContactList &contacts,
268                                              const QString &detailName, const QString &fieldName, const QContactDetailFieldDefinition &field,
269                                              const QString &contactType);
270     /// sets the field definitions of @p detailDefinition to @p fields,
271     /// without any for the fields Context and SubType/SubTypes
272     void fieldsWithoutContextAndSubType(QContactDetailFieldDefinitionMap &fields,
273                                         const QString &contactType, const QString &definitionName);
274
275     const QList<ContactDetailSample> displayLabelDetailSamples(bool preferNickname, bool preferLastname);
276
277 private:
278     QList<QContactLocalId> addedContacts;
279 };
280
281 class EvilRequestKiller : QObject
282 {
283     Q_OBJECT
284
285 public:
286     EvilRequestKiller(QContactAbstractRequest *request,
287                       Qt::ConnectionType connectionType,
288                       QContactAbstractRequest::State deletionState,
289                       QObject *parent = 0);
290
291 private slots:
292     void onStateChanged(QContactAbstractRequest::State state);
293
294 private:
295     QContactAbstractRequest *const m_request;
296     QContactAbstractRequest::State const m_deletionState;
297 };
298
299 #endif