messagingapp/msgutils/convergedmessageutils/tsrc/testconvergedmessageutils/src/testconvergedmessageutils.cpp
changeset 52 12db4185673b
parent 44 36f374c67aa8
child 61 8ba0afbb4637
equal deleted inserted replaced
44:36f374c67aa8 52:12db4185673b
     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 ConvergedMessageUtils
       
    15  */
       
    16 
       
    17 #include <QtTest/QtTest>
       
    18 #include <QTimer>
       
    19 #include <QSignalSpy>
       
    20 #include "debugtraces.h"
       
    21 #include "testconvergedmessageutils.h"
       
    22 #include "convergedmessage.h"
       
    23 #include "convergedmessageid.h"
       
    24 #include "unieditormmsplugin.h"
       
    25 #include "mmstestbed.h"
       
    26 #include "testconvergedmessageutils.ini"
       
    27 
       
    28 //---------------------------------------------------------------
       
    29 // TestConvergedMessageUtils::initTestCase
       
    30 //---------------------------------------------------------------
       
    31 void TestConvergedMessageUtils::initTestCase()
       
    32 {
       
    33 	//register user defined object to meta system.
       
    34 	qRegisterMetaType<long int> ("long int");
       
    35 		
       
    36 	//Verify MmsTestBed Instance. 
       
    37 	mmstestbed = new MmsTestBed;
       
    38 	QVERIFY(mmstestbed != NULL);
       
    39 	
       
    40 	//Instantiate UniEditorMmsPlugin and verify if it is correctly Instantited. 
       
    41 	msgPlugin = new UniEditorMmsPlugin();
       
    42 	QVERIFY(msgPlugin != NULL);
       
    43 	
       
    44 	//set up signalspy to listen to signals emitted by mmstestbed
       
    45 	spy_draft = new QSignalSpy(mmstestbed, SIGNAL(entryCreatedInDraft(long int)));
       
    46 }
       
    47 
       
    48 //---------------------------------------------------------------
       
    49 // TestConvergedMessageUtils::init
       
    50 //---------------------------------------------------------------
       
    51 void TestConvergedMessageUtils::init()
       
    52 {
       
    53 }
       
    54 
       
    55 //---------------------------------------------------------------
       
    56 // TestConvergedMessageUtils::createMMS
       
    57 //---------------------------------------------------------------
       
    58 void TestConvergedMessageUtils::createMMS()
       
    59 {
       
    60     //Create a Converged Message instance. 
       
    61     QString subject  = TEST_MSG_SUBJECT;
       
    62     
       
    63     qint64 timeStamp = QDateTime::currentDateTime().toTime_t();
       
    64 	
       
    65 	QString sender(TEST_SENDER);
       
    66 	ConvergedMessageAddress address(sender);
       
    67 	ConvergedMessageAttachmentList attachmentList;    
       
    68 
       
    69 	//Add a text attachment to attachment list. 
       
    70 	QString attachmentPath = TEST_ATTACHMENT;
       
    71 	ConvergedMessageAttachment* attachment = 
       
    72 		new ConvergedMessageAttachment(attachmentPath, ConvergedMessageAttachment::EAttachment);
       
    73 	
       
    74 	attachmentList.append(attachment);
       
    75 	
       
    76 	//Instantiate a Converged Message object and set service a MMS
       
    77 	ConvergedMessage msg;
       
    78 	
       
    79 	msg.setMessageType(ConvergedMessage::Mms);
       
    80 	
       
    81 	//Set Subject
       
    82 	msg.setSubject(subject);
       
    83 	
       
    84 	//Set Timestamp and verify
       
    85 	msg.setTimeStamp(timeStamp);
       
    86 	QVERIFY(timeStamp == msg.timeStamp());
       
    87 	
       
    88 	//Set Alias to an address
       
    89 	address.setAlias(QString (TEST_ALIAS));
       
    90 	
       
    91 	//Set recipient. 
       
    92 	msg.addToRecipient(address);
       
    93 	
       
    94 	//Add attachments' list
       
    95 	msg.addAttachments(attachmentList);
       
    96 	msg.setPriority(ConvergedMessage::Normal);
       
    97 	
       
    98 	//Adding CC Address
       
    99 	QString ccAddress(TEST_CC);
       
   100 	ConvergedMessageAddress ccAdd(ccAddress);
       
   101 	msg.addCcRecipient(ccAdd);
       
   102 	
       
   103 	//Adding BCC Address
       
   104 	QString bccAddress(TEST_BCC);
       
   105 	ConvergedMessageAddress bccAdd(bccAddress);
       
   106 	msg.addBccRecipient(bccAdd);
       
   107 	
       
   108 	//Adding From Address
       
   109 	QString recipientAddress(TEST_SENDER);
       
   110 	ConvergedMessageAddress recipientAdd(recipientAddress);
       
   111 	msg.addFromRecipient(recipientAdd);
       
   112 	
       
   113 	//Set Body Text and verify
       
   114 	msg.setBodyText(QString(TEST_MSG_BODY));
       
   115 	QVERIFY(msg.bodyText().compare(QString(TEST_MSG_BODY)) == 0);
       
   116 	
       
   117 	//Removing Body Text as MMS messages do not contain Body Text
       
   118 	msg.setBodyText(QString(NULL));
       
   119 	
       
   120 	//Set Property and Verify
       
   121 	msg.setProperty(ConvergedMessage::Attachment);
       
   122 	msg.setProperty(ConvergedMessage::Unread);
       
   123 	QVERIFY(msg.properties() == ConvergedMessage::Attachment | ConvergedMessage::Unread);
       
   124 	QVERIFY(msg.hasAttachment() == true);
       
   125 	QVERIFY(msg.isUnread() == true);
       
   126 			
       
   127 	//Set Location
       
   128 	msg.setLocation(ConvergedMessage::Draft);
       
   129 	
       
   130 	//Set Sending State and Verify
       
   131 	msg.setSendingState(ConvergedMessage::Waiting);
       
   132 	QVERIFY(msg.sendingState() == ConvergedMessage::Waiting);
       
   133 	
       
   134 	//Set Direction
       
   135 	msg.setDirection(ConvergedMessage::Outgoing);
       
   136 	
       
   137 	//Set Priority
       
   138 	msg.setPriority(ConvergedMessage::Normal);
       
   139 	
       
   140 	//Set Sub Type and verify
       
   141 	msg.setMessageSubType(ConvergedMessage::NokiaService);
       
   142 	QVERIFY(msg.messageSubType() == ConvergedMessage::NokiaService);
       
   143 	
       
   144 	//Create another Converged Message
       
   145 	ConvergedMessage msgCopyFirst(msg);
       
   146 	ConvergedMessage msgCopySecond(*(msg.id()));//by Id
       
   147 	QCOMPARE(msgCopySecond.id()->getId(), msg.id()->getId());//Verify if the copy was as expected
       
   148 	
       
   149 	//Create a Converged Message with serializing and deserializing and verify
       
   150 	QFile file("c:\\test.txt");
       
   151 	file.open(QIODevice::WriteOnly);
       
   152 	QDataStream out(&file);   // Serialize the data into the file
       
   153 	msg.serialize(out);   // Serialize a string
       
   154 	file.close();
       
   155  
       
   156 	file.open(QIODevice::ReadOnly);
       
   157 	QDataStream in(&file);    // read the data serialized from the file
       
   158 	
       
   159 	ConvergedMessage msgCopyThird;//Third Copy of the Actual Message
       
   160 	msgCopyThird.deserialize(in);
       
   161 	file.close();
       
   162 	
       
   163 	//Verify the 3rd Copy with the Original Copy
       
   164 	QVERIFY(msgCopyThird.id()->getId() == msg.id()->getId());
       
   165 	QCOMPARE(msgCopyThird.subject(), msg.subject());
       
   166 	QVERIFY(msgCopyThird.messageType() == msg.messageType());
       
   167 	
       
   168 	//Get a valid MMS message ID and verify that it is valid.
       
   169 	mmsMsgId = msgPlugin->convertTo(&msgCopyFirst);
       
   170 	QVERIFY(mmsMsgId != -1);
       
   171 	QDEBUG_WRITE("MMS Successfully Sent to Dratfs Folder");
       
   172 }
       
   173 
       
   174 //---------------------------------------------------------------
       
   175 // TestConvergedMessageUtils::testMMS
       
   176 //---------------------------------------------------------------
       
   177 void TestConvergedMessageUtils::testMMS()
       
   178 {
       
   179 	long int mmsDraftMsgId;
       
   180 	
       
   181 	//check if draft-folder signal was received...this means message was created in draft 
       
   182 	if( 1 <= spy_draft->count())
       
   183 	{
       
   184 		//compare the msgid and verify with the ID given by MMS plugin 
       
   185 		void * temp = const_cast<void*>(spy_draft->at(0).at(0).data());
       
   186 		mmsDraftMsgId = *reinterpret_cast< long int(*)>(temp);
       
   187 		QVERIFY(mmsDraftMsgId == mmsMsgId);
       
   188 		
       
   189 		//Validate the MMS message with all the values set before. 
       
   190 		ConvergedMessage* draftMsg = msgPlugin->convertFrom(mmsDraftMsgId);
       
   191 		QVERIFY(draftMsg->subject().compare(QString(TEST_MSG_SUBJECT)) == 0);
       
   192 		QVERIFY(draftMsg->messageType() == ConvergedMessage::Mms);
       
   193 		QVERIFY(QString(TEST_SENDER).contains(draftMsg->toAddressList()[0]->address(), Qt::CaseInsensitive) == true);
       
   194 		QVERIFY(QString(TEST_ALIAS).contains(draftMsg->toAddressList()[0]->alias(), Qt::CaseInsensitive) == true);
       
   195 		QVERIFY(QString(TEST_CC).contains(draftMsg->ccAddressList()[0]->address(), Qt::CaseInsensitive) == true);
       
   196 		QVERIFY(QString(TEST_BCC).contains(draftMsg->bccAddressList()[0]->address(), Qt::CaseInsensitive) == true);
       
   197 		QVERIFY(QString(TEST_SENDER).contains(draftMsg->fromAddress()->address(), Qt::CaseInsensitive) == true);
       
   198 		QVERIFY(draftMsg->attachments().count() == 1);
       
   199 		QVERIFY(draftMsg->attachments()[0]->attachmentType() == ConvergedMessageAttachment::EAttachment);
       
   200 		QVERIFY(draftMsg->attachments()[0]->filePath().contains(QString(TEST_ATTACHMENT).mid(QString(TEST_ATTACHMENT).indexOf(QString("Sample.txt"), 0, Qt::CaseInsensitive)), Qt::CaseInsensitive) == true);
       
   201 		QVERIFY(draftMsg->location() == ConvergedMessage::Draft);
       
   202 		QVERIFY(draftMsg->priority() == ConvergedMessage::Normal);
       
   203 		QVERIFY(draftMsg->direction() == ConvergedMessage::Outgoing);
       
   204 		QDEBUG_WRITE("MMS Successfully Verified at Drafts Folder");
       
   205 	}
       
   206 	else
       
   207 	{
       
   208 		QFAIL("testSendReceiveMMS: Failed to create message in Draft");
       
   209 	}
       
   210 }
       
   211 
       
   212 //---------------------------------------------------------------
       
   213 // TestConvergedMessageUtils::testConvergedMessageIdUnusedMethods
       
   214 //---------------------------------------------------------------
       
   215 void TestConvergedMessageUtils::testConvergedMessageIdUnusedMethods()
       
   216 {
       
   217 	//Create a copy of ConvergedMessageId object from another object
       
   218 	ConvergedMessageId msgId1;
       
   219 	msgId1.setId(0x646);
       
   220 	
       
   221 	//Verify if the two objects match
       
   222 	ConvergedMessageId msgId3;
       
   223 	msgId3 = msgId1;
       
   224 	QVERIFY(msgId3 == msgId1);
       
   225 }
       
   226 
       
   227 //---------------------------------------------------------------
       
   228 // TestConvergedMessageUtils::testConvergedMessageAttachmentUnusedMethods
       
   229 //---------------------------------------------------------------
       
   230 void TestConvergedMessageUtils::testConvergedMessageAttachmentUnusedMethods()
       
   231 {
       
   232 	//Set Attachment File Path and Type and Verify
       
   233 	ConvergedMessageAttachment msgAttachment;
       
   234 	msgAttachment.setFilePath(QString(TEST_ATTACHMENT));
       
   235 	QCOMPARE(msgAttachment.filePath(), QString(TEST_ATTACHMENT));
       
   236 	msgAttachment.setAttachmentType(ConvergedMessageAttachment::EAttachment);
       
   237 	QVERIFY(msgAttachment.attachmentType() == ConvergedMessageAttachment::EAttachment);
       
   238 	
       
   239 	//Second Copy with same Contents
       
   240 	ConvergedMessageAttachment msgAttachmentCopy;
       
   241 	msgAttachmentCopy.setFilePath(QString(TEST_ATTACHMENT));
       
   242 	msgAttachmentCopy.setAttachmentType(ConvergedMessageAttachment::EAttachment);
       
   243 	
       
   244 	//Verify if they are same
       
   245 	QVERIFY(msgAttachmentCopy == msgAttachment);
       
   246 }
       
   247 
       
   248 //---------------------------------------------------------------
       
   249 // TestConvergedMessageUtils::cleanup
       
   250 //---------------------------------------------------------------
       
   251 void TestConvergedMessageUtils::cleanup()
       
   252 {
       
   253 }
       
   254 
       
   255 //---------------------------------------------------------------
       
   256 // TestConvergedMessageUtils::cleanupTestCase
       
   257 //---------------------------------------------------------------
       
   258 void TestConvergedMessageUtils::cleanupTestCase()
       
   259 {
       
   260 	//Cleanup
       
   261 	mmstestbed->cleanAll();//Clean All messages from varios Folders
       
   262 	delete spy_draft;//Signal for Draft Folder
       
   263 	delete msgPlugin;//MMS Plugin
       
   264 	delete mmstestbed;//MMS Testbed
       
   265 }
       
   266 
       
   267 //---------------------------------------------------------------
       
   268 // getObject
       
   269 // factory method to create objects.
       
   270 //---------------------------------------------------------------
       
   271 QObject* getObject(QString className)
       
   272 {
       
   273     if(className == "TestConvergedMessageUtils" )
       
   274     {
       
   275         return new TestConvergedMessageUtils;
       
   276     }
       
   277  	else
       
   278 	{
       
   279 		return 0;
       
   280 	}
       
   281 }
       
   282 
       
   283 //---------------------------------------------------------------
       
   284 // createOutPutDirectory
       
   285 // creating o/p directory.
       
   286 //---------------------------------------------------------------
       
   287 void createOutPutDirectory()
       
   288     {
       
   289     QDir dir;
       
   290     //o/p dir
       
   291     dir.mkdir(OUTPUTDIRECTORY);
       
   292     //tmp dir
       
   293     dir.mkdir(TEMPDIR);
       
   294     // dir inside private folder.
       
   295     dir.mkdir(PRIVATE_DIR);
       
   296     }
       
   297 
       
   298 //---------------------------------------------------------------
       
   299 // main
       
   300 // main entry point
       
   301 //---------------------------------------------------------------
       
   302 int main(int argc, char *argv[])
       
   303     { 
       
   304     int ret = -1;
       
   305     QCoreApplication app(argc, argv);    
       
   306     
       
   307     //creating output directory.
       
   308     createOutPutDirectory();
       
   309     
       
   310     //the configuration file.
       
   311     QFile data("c:/testconvergedmessageutils.cfg");
       
   312 
       
   313     if (data.open(QFile::ReadOnly)) 
       
   314         {
       
   315         QTextStream in(&data);
       
   316         while(!in.atEnd())
       
   317             {
       
   318             QStringList args;
       
   319             QString appName = argv[0];
       
   320             args << appName;
       
   321 
       
   322             QString option  = "-o";
       
   323             args << option;
       
   324 
       
   325             QString outFile = RESULTFILE;
       
   326             QString name = in.readLine();
       
   327             outFile = outFile.arg(name);
       
   328             args << outFile;
       
   329 
       
   330             QObject* tc = getObject(name);
       
   331 
       
   332             if(tc)
       
   333                 {
       
   334                 ret =  QTest::qExec(tc, args); 
       
   335                 delete tc;
       
   336                 }
       
   337             }
       
   338         }    
       
   339     data.close();
       
   340     return ret;
       
   341     }
       
   342 
       
   343 //End of File