messagingapp/msgnotifications/msgnotifier/tsrc/testmmsgplugin/src/testmmsplugin.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 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 // TestMmsPlugin::initTestCase
       
    33 //---------------------------------------------------------------
       
    34 
       
    35 void TestMmsPlugin::initTestCase()
       
    36 {
       
    37     qRegisterMetaType<long int> ("long int"); 
       
    38     msgPlugin = new UniEditorMmsPlugin();
       
    39     QVERIFY(msgPlugin != 0);
       
    40     mmsId = -1;
       
    41     mmstestbed = new MmsTestBed;
       
    42 	QVERIFY(mmstestbed != 0);
       
    43 	if(!mmstestbed)
       
    44 	{
       
    45 		QSKIP("Mmstestbed creation failed", SkipAll); 
       
    46 	}
       
    47 
       
    48     spy_draft  = new QSignalSpy(mmstestbed,SIGNAL(entryCreatedInDraft(long int)));
       
    49     spy_outbox = new QSignalSpy(mmstestbed,SIGNAL(entryMovedToOutbox(long int)));
       
    50     spy_sent   = new QSignalSpy(mmstestbed,SIGNAL(entryMovedToSent(long int)));
       
    51 
       
    52 }
       
    53 
       
    54 //---------------------------------------------------------------
       
    55 // TestMmsPlugin::init
       
    56 //---------------------------------------------------------------
       
    57 
       
    58 void TestMmsPlugin::init()
       
    59 {
       
    60 }
       
    61 
       
    62 //---------------------------------------------------------------
       
    63 // TestMmsPlugin::testSendMMS
       
    64 //---------------------------------------------------------------
       
    65 
       
    66 void TestMmsPlugin::testSendMMS()
       
    67 {
       
    68    
       
    69     qRegisterMetaType<long int> ("long int");
       
    70     QString service = TEST_SERVICE_NAME_MMS;
       
    71 	
       
    72 	QString subject  = TEST_MSG_SUBJECT;
       
    73 	qint64 timeStamp = QDateTime::currentDateTime().toTime_t();
       
    74 	
       
    75 	QString sender(TEST_SENDER);
       
    76 	ConvergedMessageAddress address(sender);
       
    77 	ConvergedMessageAttachmentList attachmentList;    
       
    78 
       
    79 	QString attachment2Path = TEST_ATTACHMENT4;
       
    80 	ConvergedMessageAttachment* attachment2 = 
       
    81 			new ConvergedMessageAttachment(attachment2Path, ConvergedMessageAttachment::EAttachment);
       
    82 	
       
    83 	QString attachmentPath = TEST_ATTACHMENT5;
       
    84 	ConvergedMessageAttachment* attachment = 
       
    85 		new ConvergedMessageAttachment(attachmentPath, ConvergedMessageAttachment::EAttachment);
       
    86 		
       
    87 	attachmentList.append(attachment);
       
    88 	attachmentList.append(attachment2);
       
    89 	ConvergedMessage msg;
       
    90 	msg.setMessageType(ConvergedMessage::Mms);
       
    91 	msg.setSubject(subject);
       
    92 	msg.setTimeStamp(timeStamp);
       
    93 	msg.addToRecipient(address);
       
    94 	msg.addAttachments(attachmentList);
       
    95 	msg.setPriority(ConvergedMessage::Normal);
       
    96 	//Adding alias
       
    97 	ConvergedMessageAddress address1;
       
    98 	address1.setAlias(QString(TEST_MSG_RECIEPIENT));
       
    99 	msg.addToRecipient(address1);
       
   100 	
       
   101 	//Adding CC Address
       
   102 	QString ccAddress(TEST_CC);
       
   103 	ConvergedMessageAddress ccAdd(ccAddress);
       
   104 	msg.addCcRecipient(ccAdd);
       
   105 	
       
   106 	//Adding BCC Address
       
   107 	QString bccAddress(TEST_BCC);
       
   108 	ConvergedMessageAddress bccAdd(bccAddress);
       
   109 	msg.addBccRecipient(bccAdd);
       
   110 	
       
   111 	mmstestbed->cleanAll();
       
   112 	mmstestbed->setConnectionLocal(true);
       
   113 	long int id = msgPlugin->convertTo(&msg);
       
   114 	
       
   115 	QVERIFY(id != 0);
       
   116 	msgPlugin->send(id);
       
   117 	QTest::qWait(5000); 
       
   118 	long int idRec;
       
   119 	
       
   120 	if( 1 == spy_draft->count())
       
   121 		{
       
   122 		void * temp = const_cast<void*>(spy_draft->at(0).at(0).data());
       
   123 		idRec = *reinterpret_cast< long int(*)>(temp);
       
   124 		QDEBUG_WRITE("passed: spy_draft.count");
       
   125 		}
       
   126 	else
       
   127 		{
       
   128 		QFAIL("testSendReceiveMMS: Failed to create message in Draft");
       
   129 		mmstestbed->setConnectionLocal(false);
       
   130 		return;
       
   131 		}
       
   132 	if( 1 == spy_outbox->count())
       
   133 		{
       
   134 		mmstestbed->fromOutboxToMmsc();
       
   135 		QDEBUG_WRITE("passed: spy_outbox.count");
       
   136 		}
       
   137 	else
       
   138 		{
       
   139 		QFAIL("testSendReceiveMMS: Failed to move message to Outbox");
       
   140 		mmstestbed->setConnectionLocal(false);
       
   141 		return;
       
   142 		}
       
   143 
       
   144 	if( 1 == spy_sent->count())
       
   145 		{
       
   146 		void * temp = const_cast<void*>(spy_sent->at(0).at(0).data());
       
   147 		long int sentmsgid = *reinterpret_cast< long int(*)>(temp);
       
   148 		QCOMPARE(sentmsgid, idRec);
       
   149 		mmstestbed->fromMmscToInbox();
       
   150 		QDEBUG_WRITE("passed: spy_sent.count");
       
   151 		}
       
   152 	else
       
   153 		{
       
   154 		QFAIL("testSendReceiveMMS: Failed to move message to Sent folder");
       
   155 		mmstestbed->setConnectionLocal(false);
       
   156 		return;
       
   157 		}
       
   158 }
       
   159 
       
   160 //---------------------------------------------------------------
       
   161 // TestMmsPlugin::testMmsReceived
       
   162 //---------------------------------------------------------------
       
   163 void TestMmsPlugin::testMmsReceived()
       
   164 {
       
   165         QTest::qWait(5000);
       
   166 }
       
   167 
       
   168 //---------------------------------------------------------------
       
   169 // TestMmsPlugin::cleanup
       
   170 //---------------------------------------------------------------
       
   171 void TestMmsPlugin::cleanup()
       
   172 {
       
   173 }
       
   174 
       
   175 //---------------------------------------------------------------
       
   176 // TestMmsPlugin::cleanupTestCase
       
   177 //---------------------------------------------------------------
       
   178 void TestMmsPlugin::cleanupTestCase()
       
   179 {
       
   180     delete msgPlugin;
       
   181     delete mmstestbed;
       
   182 }
       
   183