|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Main test class definition for UnieditorPluginLoader |
|
15 */ |
|
16 |
|
17 #include <QtTest/QtTest> |
|
18 #include "debugtraces.h" |
|
19 #include "unieditorpluginloader.h" |
|
20 #include "unieditorplugininterface.h" |
|
21 #include "testunieditorpluginloader.h" |
|
22 #include "testunieditorpluginloader.ini" |
|
23 |
|
24 //--------------------------------------------------------------- |
|
25 // TestUnieditorPluginLoader::initTestCase |
|
26 //--------------------------------------------------------------- |
|
27 void TestUnieditorPluginLoader::initTestCase() |
|
28 { |
|
29 //register user defined object to meta system. |
|
30 qRegisterMetaType<long int> ("long int"); |
|
31 |
|
32 //Instantiate UnieditorPluginLoader and verify if it is correctly Instantited. |
|
33 unieditorPluginLoader = new UniEditorPluginLoader; |
|
34 QVERIFY(unieditorPluginLoader != NULL); |
|
35 } |
|
36 |
|
37 //--------------------------------------------------------------- |
|
38 // TestUnieditorPluginLoader::init |
|
39 //--------------------------------------------------------------- |
|
40 void TestUnieditorPluginLoader::init() |
|
41 { |
|
42 } |
|
43 |
|
44 //--------------------------------------------------------------- |
|
45 // TestUnieditorPluginLoader::createMMS |
|
46 //--------------------------------------------------------------- |
|
47 void TestUnieditorPluginLoader::createMMS() |
|
48 { |
|
49 //Create a Converged Message instance. |
|
50 QString subject = TEST_MSG_SUBJECT; |
|
51 |
|
52 qint64 timeStamp = QDateTime::currentDateTime().toTime_t(); |
|
53 |
|
54 QString sender(TEST_SENDER); |
|
55 ConvergedMessageAddress address(sender); |
|
56 ConvergedMessageAttachmentList attachmentList; |
|
57 |
|
58 //Add a text attachment to attachment list. |
|
59 QString attachmentPath = TEST_ATTACHMENT; |
|
60 ConvergedMessageAttachment* attachment = |
|
61 new ConvergedMessageAttachment(attachmentPath, ConvergedMessageAttachment::EAttachment); |
|
62 |
|
63 attachmentList.append(attachment); |
|
64 |
|
65 //Instantiate a Converged Message object and set service a MMS |
|
66 ConvergedMessage msg; |
|
67 |
|
68 messageType = ConvergedMessage::Mms; |
|
69 msg.setMessageType(messageType); |
|
70 |
|
71 //Set Subject |
|
72 msg.setSubject(subject); |
|
73 |
|
74 //Set Timestamp and verify |
|
75 msg.setTimeStamp(timeStamp); |
|
76 QVERIFY(timeStamp == msg.timeStamp()); |
|
77 |
|
78 //Set Alias to an address |
|
79 address.setAlias(QString (TEST_ALIAS)); |
|
80 |
|
81 //Set recipient. |
|
82 msg.addToRecipient(address); |
|
83 |
|
84 //Add attachments' list |
|
85 msg.addAttachments(attachmentList); |
|
86 msg.setPriority(ConvergedMessage::Normal); |
|
87 |
|
88 //Adding CC Address |
|
89 QString ccAddress(TEST_CC); |
|
90 ConvergedMessageAddress ccAdd(ccAddress); |
|
91 msg.addCcRecipient(ccAdd); |
|
92 |
|
93 //Adding BCC Address |
|
94 QString bccAddress(TEST_BCC); |
|
95 ConvergedMessageAddress bccAdd(bccAddress); |
|
96 msg.addBccRecipient(bccAdd); |
|
97 |
|
98 //Adding From Address |
|
99 QString recipientAddress(TEST_SENDER); |
|
100 ConvergedMessageAddress recipientAdd(recipientAddress); |
|
101 msg.addFromRecipient(recipientAdd); |
|
102 |
|
103 //Set Body Text and verify |
|
104 msg.setBodyText(QString(TEST_MSG_BODY)); |
|
105 QVERIFY(msg.bodyText().compare(QString(TEST_MSG_BODY)) == 0); |
|
106 |
|
107 //Removing Body Text as MMS messages do not contain Body Text |
|
108 msg.setBodyText(QString(NULL)); |
|
109 |
|
110 //Set Property and Verify |
|
111 msg.setProperty(ConvergedMessage::Attachment); |
|
112 msg.setProperty(ConvergedMessage::Unread); |
|
113 QVERIFY(msg.properties() == ConvergedMessage::Attachment | ConvergedMessage::Unread); |
|
114 QVERIFY(msg.hasAttachment() == true); |
|
115 QVERIFY(msg.isUnread() == true); |
|
116 |
|
117 //Set Location |
|
118 msg.setLocation(ConvergedMessage::Draft); |
|
119 |
|
120 //Set Sending State and Verify |
|
121 msg.setSendingState(ConvergedMessage::Waiting); |
|
122 QVERIFY(msg.sendingState() == ConvergedMessage::Waiting); |
|
123 |
|
124 //Set Direction |
|
125 msg.setDirection(ConvergedMessage::Outgoing); |
|
126 |
|
127 //Set Priority |
|
128 msg.setPriority(ConvergedMessage::Normal); |
|
129 |
|
130 //Set Sub Type and verify |
|
131 msg.setMessageSubType(ConvergedMessage::NokiaService); |
|
132 QVERIFY(msg.messageSubType() == ConvergedMessage::NokiaService); |
|
133 |
|
134 UniEditorPluginInterface* pluginInterface = unieditorPluginLoader->getUniEditorPlugin(messageType); |
|
135 |
|
136 //Get a valid MMS message ID and verify that it is valid. |
|
137 msgId = pluginInterface->convertTo(&msg); |
|
138 QVERIFY(msgId != -1); |
|
139 QDEBUG_WRITE("MMS Successfully Created in Drafts Folder"); |
|
140 } |
|
141 |
|
142 //--------------------------------------------------------------- |
|
143 // TestUnieditorPluginLoader::testMMS |
|
144 //--------------------------------------------------------------- |
|
145 void TestUnieditorPluginLoader::testMMS() |
|
146 { |
|
147 //check if draft-folder signal was received...this means message was created in draft |
|
148 |
|
149 UniEditorPluginInterface* pluginInterface = unieditorPluginLoader->getUniEditorPlugin(messageType); |
|
150 |
|
151 //Validate the MMS message with all the values set before. |
|
152 ConvergedMessage draftMsg = *(pluginInterface->convertFrom(msgId)); |
|
153 QVERIFY(draftMsg.subject().compare(QString(TEST_MSG_SUBJECT)) == 0); |
|
154 QVERIFY(draftMsg.messageType() == ConvergedMessage::Mms); |
|
155 QVERIFY(QString(TEST_SENDER).contains(draftMsg.toAddressList()[0]->address(), Qt::CaseInsensitive) == true); |
|
156 QVERIFY(QString(TEST_ALIAS).contains(draftMsg.toAddressList()[0]->alias(), Qt::CaseInsensitive) == true); |
|
157 QVERIFY(QString(TEST_CC).contains(draftMsg.ccAddressList()[0]->address(), Qt::CaseInsensitive) == true); |
|
158 QVERIFY(QString(TEST_BCC).contains(draftMsg.bccAddressList()[0]->address(), Qt::CaseInsensitive) == true); |
|
159 QVERIFY(QString(TEST_SENDER).contains(draftMsg.fromAddress()->address(), Qt::CaseInsensitive) == true); |
|
160 QVERIFY(draftMsg.attachments().count() == 1); |
|
161 QVERIFY(draftMsg.attachments()[0]->attachmentType() == ConvergedMessageAttachment::EAttachment); |
|
162 QVERIFY(draftMsg.attachments()[0]->filePath().contains(QString(TEST_ATTACHMENT).mid(QString(TEST_ATTACHMENT).indexOf(QString("Sample.txt"), 0, Qt::CaseInsensitive)), Qt::CaseInsensitive) == true); |
|
163 QVERIFY(draftMsg.location() == ConvergedMessage::Draft); |
|
164 QVERIFY(draftMsg.priority() == ConvergedMessage::Normal); |
|
165 QVERIFY(draftMsg.direction() == ConvergedMessage::Outgoing); |
|
166 QDEBUG_WRITE("MMS Successfully Verified at Drafts Folder"); |
|
167 } |
|
168 |
|
169 //--------------------------------------------------------------- |
|
170 // TestUnieditorPluginLoader::createSMS |
|
171 //--------------------------------------------------------------- |
|
172 void TestUnieditorPluginLoader::createSMS() |
|
173 { |
|
174 //Create a Converged Message instance. |
|
175 QString subject = TEST_MSG_SUBJECT; |
|
176 |
|
177 qint64 timeStamp = QDateTime::currentDateTime().toTime_t(); |
|
178 |
|
179 QString sender(TEST_SENDER); |
|
180 ConvergedMessageAddress address(sender); |
|
181 |
|
182 //Instantiate a Converged Message object and set service a SMS |
|
183 ConvergedMessage msg; |
|
184 |
|
185 messageType = ConvergedMessage::Sms; |
|
186 msg.setMessageType(messageType); |
|
187 |
|
188 //Set Subject |
|
189 msg.setSubject(subject); |
|
190 |
|
191 //Set Body |
|
192 msg.setBodyText(QString(TEST_MSG_BODY)); |
|
193 |
|
194 //Set Timestamp and verify |
|
195 msg.setTimeStamp(timeStamp); |
|
196 QVERIFY(timeStamp == msg.timeStamp()); |
|
197 |
|
198 //Set recipient. |
|
199 msg.addToRecipient(address); |
|
200 |
|
201 //Set priority. |
|
202 msg.setPriority(ConvergedMessage::Normal); |
|
203 |
|
204 //Adding From Address |
|
205 QString recipientAddress(TEST_SENDER); |
|
206 ConvergedMessageAddress recipientAdd(recipientAddress); |
|
207 msg.addFromRecipient(recipientAdd); |
|
208 |
|
209 //Set Property and Verify |
|
210 msg.setProperty(ConvergedMessage::Unread); |
|
211 QVERIFY(msg.properties() == ConvergedMessage::Unread); |
|
212 QVERIFY(msg.isUnread() == true); |
|
213 |
|
214 //Set Location |
|
215 msg.setLocation(ConvergedMessage::Draft); |
|
216 |
|
217 //Set Sending State and Verify |
|
218 msg.setSendingState(ConvergedMessage::Waiting); |
|
219 QVERIFY(msg.sendingState() == ConvergedMessage::Waiting); |
|
220 |
|
221 //Set Direction |
|
222 msg.setDirection(ConvergedMessage::Outgoing); |
|
223 |
|
224 //Set Priority |
|
225 msg.setPriority(ConvergedMessage::Normal); |
|
226 |
|
227 UniEditorPluginInterface* pluginInterface = unieditorPluginLoader->getUniEditorPlugin(messageType); |
|
228 |
|
229 //Get a valid SMS message ID and verify that it is valid. |
|
230 msgId = pluginInterface->convertTo(&msg); |
|
231 QVERIFY(msgId != -1); |
|
232 QDEBUG_WRITE("SMS Successfully Created in Drafts Folder"); |
|
233 } |
|
234 |
|
235 //--------------------------------------------------------------- |
|
236 // TestUnieditorPluginLoader::testSMS |
|
237 //--------------------------------------------------------------- |
|
238 void TestUnieditorPluginLoader::testSMS() |
|
239 { |
|
240 //check if draft-folder signal was received...this means message was created in draft |
|
241 |
|
242 UniEditorPluginInterface* pluginInterface = unieditorPluginLoader->getUniEditorPlugin(messageType); |
|
243 |
|
244 //Validate the SMS message with all the values set before. |
|
245 ConvergedMessage draftMsg = *(pluginInterface->convertFrom(msgId)); |
|
246 QVERIFY(draftMsg.subject().compare(QString(TEST_MSG_SUBJECT)) == 0); |
|
247 QVERIFY(draftMsg.bodyText().compare(QString(TEST_MSG_BODY)) == 0); |
|
248 QVERIFY(draftMsg.messageType() == ConvergedMessage::Sms); |
|
249 QVERIFY(QString(TEST_SENDER).contains(draftMsg.toAddressList()[0]->address(), Qt::CaseInsensitive) == true); |
|
250 QVERIFY(QString(TEST_SENDER).contains(draftMsg.fromAddress()->address(), Qt::CaseInsensitive) == true); |
|
251 QVERIFY(draftMsg.location() == ConvergedMessage::Draft); |
|
252 QVERIFY(draftMsg.priority() == ConvergedMessage::Normal); |
|
253 QVERIFY(draftMsg.direction() == ConvergedMessage::Outgoing); |
|
254 QDEBUG_WRITE("SMS Successfully Verified at Drafts Folder"); |
|
255 } |
|
256 |
|
257 //--------------------------------------------------------------- |
|
258 // TestUnieditorPluginLoader::cleanup |
|
259 //--------------------------------------------------------------- |
|
260 void TestUnieditorPluginLoader::cleanup() |
|
261 { |
|
262 } |
|
263 |
|
264 //--------------------------------------------------------------- |
|
265 // TestUnieditorPluginLoader::cleanupTestCase |
|
266 //--------------------------------------------------------------- |
|
267 void TestUnieditorPluginLoader::cleanupTestCase() |
|
268 { |
|
269 //Cleanup |
|
270 delete unieditorPluginLoader;//SMS/MMS Plugin Loader |
|
271 } |
|
272 |
|
273 //--------------------------------------------------------------- |
|
274 // main |
|
275 // main entry point |
|
276 //--------------------------------------------------------------- |
|
277 int main(int argc, char *argv[]) |
|
278 { |
|
279 int ret = -1; |
|
280 QCoreApplication app(argc, argv); |
|
281 QObject* tc = new TestUnieditorPluginLoader(); |
|
282 |
|
283 #ifdef __WINSCW__ |
|
284 char *new_argv[3]; |
|
285 QString str = "C:\\data\\" + QFileInfo(QCoreApplication::applicationFilePath()).baseName() + ".log"; |
|
286 QByteArray bytes = str.toAscii(); |
|
287 char arg1[] = "-o"; |
|
288 new_argv[0] = argv[0]; |
|
289 new_argv[1] = arg1; |
|
290 new_argv[2] = bytes.data(); |
|
291 ret = QTest::qExec(tc, 3, new_argv); |
|
292 #else |
|
293 ret = QTest::qExec(tc, argc, argv); |
|
294 #endif |
|
295 |
|
296 delete tc; |
|
297 return ret; |
|
298 } |
|
299 |
|
300 //End of File |