messagingapp/msgnotifications/msgnotifier/tsrc/unittest_mmsplugin/testmmsgplugin/src/testmmsplugin.cpp
changeset 52 12db4185673b
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 for Msgnotification -indicator plugin, 
       
    15  *                                                   -notification dialog plugin
       
    16  */
       
    17 
       
    18 #include "testmmsplugin.h"
       
    19 #include <QtTest/QtTest>
       
    20 #include "debugtraces.h"
       
    21 #include <QTimer>
       
    22 #include <QSignalSpy>
       
    23 #include "convergedmessage.h"
       
    24 #include "convergedmessageid.h"
       
    25 #include "unieditormmsplugin.h"
       
    26 #include "mmstestbed.h"
       
    27 #include "testmmsplugin.ini"
       
    28 #include <QSignalSpy>
       
    29 
       
    30 
       
    31 
       
    32 //factory method to create objects.
       
    33 QObject* getObject(QString className)
       
    34 {
       
    35     if(className == "TestMmsPlugin" )
       
    36     {
       
    37         return new TestMmsPlugin;
       
    38     }
       
    39  	else
       
    40 	{
       
    41 		return 0;
       
    42 	}
       
    43 }
       
    44 
       
    45 //main entry point
       
    46 int main(int argc, char *argv[])
       
    47     { 
       
    48     int ret = -1;
       
    49 	QCoreApplication app(argc, argv);
       
    50 	
       
    51 	//the configuration file.
       
    52 	QFile data("c:/testmmsplugin.cfg");
       
    53     if (data.open(QFile::ReadOnly)) 
       
    54         {
       
    55 		QTextStream in(&data);
       
    56 		while(!in.atEnd())
       
    57 			{
       
    58 			QString name = in.readLine();
       
    59 			QObject* tc = getObject(name);
       
    60 			
       
    61 			if(tc)
       
    62 				{
       
    63 				ret =  QTest::qExec(tc, argc, argv);
       
    64 				delete tc;
       
    65 				}
       
    66 			}
       
    67         }
       
    68 	return ret;
       
    69 
       
    70     }
       
    71 
       
    72 
       
    73 
       
    74 
       
    75 
       
    76 
       
    77 //---------------------------------------------------------------
       
    78 // TestMmsPlugin::initTestCase
       
    79 //---------------------------------------------------------------
       
    80 
       
    81 void TestMmsPlugin::initTestCase()
       
    82 {
       
    83     qRegisterMetaType<long int> ("long int"); 
       
    84     msgPlugin = new UniEditorMmsPlugin();
       
    85     QVERIFY(msgPlugin != 0);
       
    86     mmsId = -1;
       
    87     mmstestbed = new MmsTestBed;
       
    88 	QVERIFY(mmstestbed != 0);
       
    89 	if(!mmstestbed)
       
    90 	{
       
    91 		QSKIP("Mmstestbed creation failed", SkipAll); 
       
    92 	}
       
    93 
       
    94     spy_draft  = new QSignalSpy(mmstestbed,SIGNAL(entryCreatedInDraft(long int)));
       
    95     spy_outbox = new QSignalSpy(mmstestbed,SIGNAL(entryMovedToOutbox(long int)));
       
    96     spy_sent   = new QSignalSpy(mmstestbed,SIGNAL(entryMovedToSent(long int)));
       
    97 
       
    98 }
       
    99 
       
   100 //---------------------------------------------------------------
       
   101 // TestMmsPlugin::init
       
   102 //---------------------------------------------------------------
       
   103 
       
   104 void TestMmsPlugin::init()
       
   105 {
       
   106 }
       
   107 
       
   108 //---------------------------------------------------------------
       
   109 // TestMmsPlugin::testSendMMS
       
   110 //---------------------------------------------------------------
       
   111 
       
   112 void TestMmsPlugin::testSendMMS()
       
   113 {
       
   114    
       
   115     qRegisterMetaType<long int> ("long int");
       
   116     QString service = TEST_SERVICE_NAME_MMS;
       
   117 	
       
   118 	QString subject  = TEST_MSG_SUBJECT;
       
   119 	qint64 timeStamp = QDateTime::currentDateTime().toTime_t();
       
   120 	
       
   121 	QString sender(TEST_SENDER);
       
   122 	ConvergedMessageAddress address(sender);
       
   123 	ConvergedMessageAttachmentList attachmentList;    
       
   124 
       
   125 	QString attachment2Path = TEST_ATTACHMENT4;
       
   126 	ConvergedMessageAttachment* attachment2 = 
       
   127 			new ConvergedMessageAttachment(attachment2Path, ConvergedMessageAttachment::EAttachment);
       
   128 	
       
   129 	QString attachmentPath = TEST_ATTACHMENT5;
       
   130 	ConvergedMessageAttachment* attachment = 
       
   131 		new ConvergedMessageAttachment(attachmentPath, ConvergedMessageAttachment::EAttachment);
       
   132 		
       
   133 	attachmentList.append(attachment);
       
   134 	attachmentList.append(attachment2);
       
   135 	ConvergedMessage msg;
       
   136 	msg.setMessageType(ConvergedMessage::Mms);
       
   137 	msg.setSubject(subject);
       
   138 	msg.setTimeStamp(timeStamp);
       
   139 	msg.addToRecipient(address);
       
   140 	msg.addAttachments(attachmentList);
       
   141 	msg.setPriority(ConvergedMessage::Normal);
       
   142 	//Adding alias
       
   143 	ConvergedMessageAddress address1;
       
   144 	address1.setAlias(QString(TEST_MSG_RECIEPIENT));
       
   145 	msg.addToRecipient(address1);
       
   146 	
       
   147 	//Adding CC Address
       
   148 	QString ccAddress(TEST_CC);
       
   149 	ConvergedMessageAddress ccAdd(ccAddress);
       
   150 	msg.addCcRecipient(ccAdd);
       
   151 	
       
   152 	//Adding BCC Address
       
   153 	QString bccAddress(TEST_BCC);
       
   154 	ConvergedMessageAddress bccAdd(bccAddress);
       
   155 	msg.addBccRecipient(bccAdd);
       
   156 	
       
   157 	mmstestbed->cleanAll();
       
   158 	mmstestbed->setConnectionLocal(true);
       
   159 	long int id = msgPlugin->convertTo(&msg);
       
   160 	
       
   161 	QVERIFY(id != 0);
       
   162 	msgPlugin->send(id);
       
   163 	QTest::qWait(5000); 
       
   164 	long int idRec;
       
   165 	
       
   166 	if( 1 == spy_draft->count())
       
   167 		{
       
   168 		void * temp = const_cast<void*>(spy_draft->at(0).at(0).data());
       
   169 		idRec = *reinterpret_cast< long int(*)>(temp);
       
   170 		QDEBUG_WRITE("passed: spy_draft.count");
       
   171 		}
       
   172 	else
       
   173 		{
       
   174 		QFAIL("testSendReceiveMMS: Failed to create message in Draft");
       
   175 		mmstestbed->setConnectionLocal(false);
       
   176 		return;
       
   177 		}
       
   178 	if( 1 == spy_outbox->count())
       
   179 		{
       
   180 		mmstestbed->fromOutboxToMmsc();
       
   181 		QDEBUG_WRITE("passed: spy_outbox.count");
       
   182 		}
       
   183 	else
       
   184 		{
       
   185 		QFAIL("testSendReceiveMMS: Failed to move message to Outbox");
       
   186 		mmstestbed->setConnectionLocal(false);
       
   187 		return;
       
   188 		}
       
   189 
       
   190 	if( 1 == spy_sent->count())
       
   191 		{
       
   192 		void * temp = const_cast<void*>(spy_sent->at(0).at(0).data());
       
   193 		long int sentmsgid = *reinterpret_cast< long int(*)>(temp);
       
   194 		QCOMPARE(sentmsgid, idRec);
       
   195 		mmstestbed->fromMmscToInbox();
       
   196 		QDEBUG_WRITE("passed: spy_sent.count");
       
   197 		}
       
   198 	else
       
   199 		{
       
   200 		QFAIL("testSendReceiveMMS: Failed to move message to Sent folder");
       
   201 		mmstestbed->setConnectionLocal(false);
       
   202 		return;
       
   203 		}
       
   204 }
       
   205 
       
   206 //---------------------------------------------------------------
       
   207 // TestMmsPlugin::testMmsReceived
       
   208 //---------------------------------------------------------------
       
   209 void TestMmsPlugin::testMmsReceived()
       
   210 {
       
   211         QTest::qWait(5000);
       
   212 }
       
   213 
       
   214 //---------------------------------------------------------------
       
   215 // TestMmsPlugin::cleanup
       
   216 //---------------------------------------------------------------
       
   217 void TestMmsPlugin::cleanup()
       
   218 {
       
   219 }
       
   220 
       
   221 //---------------------------------------------------------------
       
   222 // TestMmsPlugin::cleanupTestCase
       
   223 //---------------------------------------------------------------
       
   224 void TestMmsPlugin::cleanupTestCase()
       
   225 {
       
   226     delete msgPlugin;
       
   227     delete mmstestbed;
       
   228 }
       
   229