19 #include "logsevent.h" |
19 #include "logsevent.h" |
20 #include "logseventdata.h" |
20 #include "logseventdata.h" |
21 #include "logsdbconnector.h" |
21 #include "logsdbconnector.h" |
22 #include "logsdbconnector_stub_helper.h" |
22 #include "logsdbconnector_stub_helper.h" |
23 #include "qtcontacts_stubs_helper.h" |
23 #include "qtcontacts_stubs_helper.h" |
|
24 #include "qthighway_stub_helper.h" |
24 |
25 |
25 #include <xqservicerequest.h> |
26 #include <xqservicerequest.h> |
26 #include <QtTest/QtTest> |
27 #include <QtTest/QtTest> |
27 |
28 |
28 const int logsContactsLocalIdTest1 = 1; |
29 const int logsContactsLocalIdTest1 = 1; |
104 QVERIFY( !mLogsContact->open() ); |
105 QVERIFY( !mLogsContact->open() ); |
105 QVERIFY( !mLogsContact->mService ); |
106 QVERIFY( !mLogsContact->mService ); |
106 QVERIFY( mLogsContact->mCurrentRequest == LogsContact::TypeLogsContactSave ); |
107 QVERIFY( mLogsContact->mCurrentRequest == LogsContact::TypeLogsContactSave ); |
107 |
108 |
108 //contact is in phonebook, open is ok |
109 //contact is in phonebook, open is ok |
|
110 QtHighwayStubHelper::reset(); |
109 mLogsEvent->logsEventData()->setContactLocalId(2); |
111 mLogsEvent->logsEventData()->setContactLocalId(2); |
110 QtContactsStubsHelper::setContactId(2); |
112 QtContactsStubsHelper::setContactId(2); |
111 delete mLogsContact; |
113 delete mLogsContact; |
112 mLogsContact = 0; |
114 mLogsContact = 0; |
113 mLogsContact = new LogsContact(*mLogsEvent, *mDbConnector); |
115 mLogsContact = new LogsContact(*mLogsEvent, *mDbConnector); |
114 QVERIFY( mLogsContact->open() ); |
116 QVERIFY( mLogsContact->open() ); |
115 QVERIFY( mLogsContact->mService ); |
117 QVERIFY( mLogsContact->mService ); |
116 QVERIFY( mLogsContact->mCurrentRequest == LogsContact::TypeLogsContactOpen ); |
118 QVERIFY( mLogsContact->mCurrentRequest == LogsContact::TypeLogsContactOpen ); |
117 QVERIFY( mLogsContact->mService->service() == logsFetchService ); |
119 QVERIFY( mLogsContact->mService->service() == logsFetchService ); |
118 QVERIFY( mLogsContact->mService->message() == "open(int)" ); |
120 QVERIFY( mLogsContact->mService->message() == "open(int)" ); |
|
121 QVERIFY( QtHighwayStubHelper::isRequestEmbedded() ); |
119 |
122 |
120 // Same but without using logsevent at construction |
123 // Same but without using logsevent at construction |
|
124 QtHighwayStubHelper::reset(); |
121 LogsContact contactWithoutEvent("2345", *mDbConnector, 2); |
125 LogsContact contactWithoutEvent("2345", *mDbConnector, 2); |
122 QVERIFY( contactWithoutEvent.open() ); |
126 QVERIFY( contactWithoutEvent.open() ); |
123 QVERIFY( contactWithoutEvent.mService ); |
127 QVERIFY( contactWithoutEvent.mService ); |
124 QVERIFY( contactWithoutEvent.mCurrentRequest == LogsContact::TypeLogsContactOpen ); |
128 QVERIFY( contactWithoutEvent.mCurrentRequest == LogsContact::TypeLogsContactOpen ); |
125 QVERIFY( contactWithoutEvent.mService->service() == logsFetchService ); |
129 QVERIFY( contactWithoutEvent.mService->service() == logsFetchService ); |
126 QVERIFY( contactWithoutEvent.mService->message() == "open(int)" ); |
130 QVERIFY( contactWithoutEvent.mService->message() == "open(int)" ); |
127 |
131 QVERIFY( QtHighwayStubHelper::isRequestEmbedded() ); |
128 } |
132 } |
129 |
133 |
130 void UT_LogsContact::testAddNew() |
134 void UT_LogsContact::testAddNew() |
131 { |
135 { |
132 //no caller ID, contact won't be saved |
136 //no caller ID, contact won't be saved |
135 QVERIFY( !mLogsContact->addNew() ); |
139 QVERIFY( !mLogsContact->addNew() ); |
136 QVERIFY( !mLogsContact->mService ); |
140 QVERIFY( !mLogsContact->mService ); |
137 QVERIFY( mLogsContact->mCurrentRequest == LogsContact::TypeLogsContactSave ); |
141 QVERIFY( mLogsContact->mCurrentRequest == LogsContact::TypeLogsContactSave ); |
138 |
142 |
139 //called ID present, contact not in phonebook => save is ok |
143 //called ID present, contact not in phonebook => save is ok |
|
144 QtHighwayStubHelper::reset(); |
140 mLogsEvent->setNumber(QString::number(12345)); |
145 mLogsEvent->setNumber(QString::number(12345)); |
141 mLogsEvent->setEventType(LogsEvent::TypeVoiceCall); |
146 mLogsEvent->setEventType(LogsEvent::TypeVoiceCall); |
142 delete mLogsContact; |
147 delete mLogsContact; |
143 mLogsContact = 0; |
148 mLogsContact = 0; |
144 mLogsContact = new LogsContact(*mLogsEvent, *mDbConnector); |
149 mLogsContact = new LogsContact(*mLogsEvent, *mDbConnector); |
147 QVERIFY( mLogsContact->addNew() ); |
152 QVERIFY( mLogsContact->addNew() ); |
148 QVERIFY( mLogsContact->mService ); |
153 QVERIFY( mLogsContact->mService ); |
149 QVERIFY( mLogsContact->mCurrentRequest == LogsContact::TypeLogsContactSave ); |
154 QVERIFY( mLogsContact->mCurrentRequest == LogsContact::TypeLogsContactSave ); |
150 QVERIFY( mLogsContact->mService->service() == logsFetchService ); |
155 QVERIFY( mLogsContact->mService->service() == logsFetchService ); |
151 QVERIFY( mLogsContact->mService->message() == "editCreateNew(QString,QString)" ); |
156 QVERIFY( mLogsContact->mService->message() == "editCreateNew(QString,QString)" ); |
|
157 QVERIFY( QtHighwayStubHelper::isRequestEmbedded() ); |
152 |
158 |
153 //caller ID present, contact is in phonebook => save is ok |
159 //caller ID present, contact is in phonebook => save is ok |
|
160 QtHighwayStubHelper::reset(); |
154 mLogsEvent->setEventType(LogsEvent::TypeVoIPCall); |
161 mLogsEvent->setEventType(LogsEvent::TypeVoIPCall); |
155 mLogsEvent->setNumber(""); |
162 mLogsEvent->setNumber(""); |
156 mLogsEvent->logsEventData()->mRemoteUrl = "someurl@blah"; |
163 mLogsEvent->logsEventData()->mRemoteUrl = "someurl@blah"; |
157 mLogsEvent->logsEventData()->setContactLocalId(2); |
164 mLogsEvent->logsEventData()->setContactLocalId(2); |
158 QtContactsStubsHelper::setContactId(2); |
165 QtContactsStubsHelper::setContactId(2); |
163 QVERIFY( mLogsContact->addNew() ); |
170 QVERIFY( mLogsContact->addNew() ); |
164 QVERIFY( mLogsContact->mService ); |
171 QVERIFY( mLogsContact->mService ); |
165 QVERIFY( mLogsContact->mCurrentRequest == LogsContact::TypeLogsContactSave ); |
172 QVERIFY( mLogsContact->mCurrentRequest == LogsContact::TypeLogsContactSave ); |
166 QVERIFY( mLogsContact->mService->service() == logsFetchService ); |
173 QVERIFY( mLogsContact->mService->service() == logsFetchService ); |
167 QVERIFY( mLogsContact->mService->message() == "editCreateNew(QString,QString)" ); |
174 QVERIFY( mLogsContact->mService->message() == "editCreateNew(QString,QString)" ); |
|
175 QVERIFY( QtHighwayStubHelper::isRequestEmbedded() ); |
168 } |
176 } |
169 |
177 |
170 void UT_LogsContact::testUpdateExisting() |
178 void UT_LogsContact::testUpdateExisting() |
171 { |
179 { |
172 //caller ID present, contact is in phonebook => update is ok |
180 //caller ID present, contact is in phonebook => update is ok |
|
181 QtHighwayStubHelper::reset(); |
173 mLogsEvent->setNumber(QString::number(12345)); |
182 mLogsEvent->setNumber(QString::number(12345)); |
174 mLogsEvent->setEventType(LogsEvent::TypeVoiceCall); |
183 mLogsEvent->setEventType(LogsEvent::TypeVoiceCall); |
175 mLogsEvent->logsEventData()->setContactLocalId(2); |
184 mLogsEvent->logsEventData()->setContactLocalId(2); |
176 QtContactsStubsHelper::setContactId(2); |
185 QtContactsStubsHelper::setContactId(2); |
177 delete mLogsContact; |
186 delete mLogsContact; |
181 QVERIFY( mLogsContact->updateExisting() ); |
190 QVERIFY( mLogsContact->updateExisting() ); |
182 QVERIFY( mLogsContact->mService ); |
191 QVERIFY( mLogsContact->mService ); |
183 QVERIFY( mLogsContact->mCurrentRequest == LogsContact::TypeLogsContactSave ); |
192 QVERIFY( mLogsContact->mCurrentRequest == LogsContact::TypeLogsContactSave ); |
184 QVERIFY( mLogsContact->mService->service() == logsFetchService ); |
193 QVERIFY( mLogsContact->mService->service() == logsFetchService ); |
185 QVERIFY( mLogsContact->mService->message() == "editUpdateExisting(QString,QString)" ); |
194 QVERIFY( mLogsContact->mService->message() == "editUpdateExisting(QString,QString)" ); |
|
195 QVERIFY( QtHighwayStubHelper::isRequestEmbedded() ); |
186 } |
196 } |
187 |
197 |
188 void UT_LogsContact::testIsContactInPhonebook() |
198 void UT_LogsContact::testIsContactInPhonebook() |
189 { |
199 { |
190 QVERIFY( !mLogsContact->isContactInPhonebook() ); |
200 QVERIFY( !mLogsContact->isContactInPhonebook() ); |
273 mLogsContact->handleRequestCompleted( QVariant(0) ); |
283 mLogsContact->handleRequestCompleted( QVariant(0) ); |
274 QVERIFY( spyOpened.count() == 0 ); |
284 QVERIFY( spyOpened.count() == 0 ); |
275 QVERIFY( spySaved.count() == 1 ); |
285 QVERIFY( spySaved.count() == 1 ); |
276 QVERIFY( LogsDbConnectorStubHelper::lastCalledFunction().isEmpty() ); |
286 QVERIFY( LogsDbConnectorStubHelper::lastCalledFunction().isEmpty() ); |
277 } |
287 } |
|
288 |
|
289 void UT_LogsContact::testCancelServiceRequest() |
|
290 { |
|
291 QVERIFY( !mLogsContact->mService ); |
|
292 mLogsContact->mService = new XQServiceRequest("service", "message", false); |
|
293 mLogsContact->cancelServiceRequest(); |
|
294 QVERIFY( !mLogsContact->mService ); |
|
295 } |