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