messagingapp/msgutils/unieditorplugins/unieditorsmsplugin/tsrc/testsmsgplugin/testsmsplugin.cpp
changeset 25 84d9eb65b26f
parent 23 238255e8b033
child 27 e4592d119491
child 37 518b245aa84c
child 79 2981cb3aa489
equal deleted inserted replaced
23:238255e8b033 25:84d9eb65b26f
     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:
       
    15  */
       
    16 
       
    17 #include "testsmsplugin.h"
       
    18 #include <QtTest/QtTest>
       
    19 #include "debugtraces.h"
       
    20 
       
    21 #include <QTimer>
       
    22 #include <QSignalSpy>
       
    23 
       
    24 #include "convergedmessage.h"
       
    25 #include "TestMsg.h"
       
    26 #include "convergedmessageid.h"
       
    27 #include "unieditorsmsplugin.h"
       
    28 #include "messageserviceaction.h"
       
    29 //---------------------------------------------------------------
       
    30 // TestSmsPlugin::initTestCase
       
    31 //---------------------------------------------------------------
       
    32 void TestSmsPlugin::initTestCase()
       
    33 {
       
    34     msgPlugin = new UniEditorSmsPlugin();
       
    35     testMsg = new TestMsg();
       
    36   //  QVERIFY(msgPlugin != 0);
       
    37     smsId = -1;
       
    38     mmsId = -1;
       
    39 }
       
    40 
       
    41 //---------------------------------------------------------------
       
    42 // TestSmsPlugin::cleanupTestCase
       
    43 //---------------------------------------------------------------
       
    44 void TestSmsPlugin::cleanupTestCase()
       
    45 {
       
    46     delete msgPlugin;
       
    47     delete testMsg;
       
    48 }
       
    49 
       
    50 //---------------------------------------------------------------
       
    51 // TestSmsPlugin::init
       
    52 //---------------------------------------------------------------
       
    53 
       
    54 void TestSmsPlugin::init()
       
    55 {
       
    56 }
       
    57 
       
    58 //---------------------------------------------------------------
       
    59 // TestSmsPlugin::cleanup
       
    60 //---------------------------------------------------------------
       
    61 void TestSmsPlugin::cleanup()
       
    62 {
       
    63 }
       
    64 
       
    65 //---------------------------------------------------------------
       
    66 // TestSmsPlugin::testSendSMS
       
    67 //---------------------------------------------------------------
       
    68 void TestSmsPlugin::testSendReceiveSMS()
       
    69 { 
       
    70     testMsg->createSCSettings();
       
    71     
       
    72     testMsg->initSimTsyL();
       
    73     //TODO: Should uncomment the watcher code below while executing the test case in text shell mode. 
       
    74     //Also the watcher code should be commented while executing in UI mode.
       
    75   /*  RProcess watcherProcess;
       
    76     _LIT(KWatcherExe, "z:\\system\\libs\\watcher.exe");
       
    77     User::LeaveIfError(watcherProcess.Create(KWatcherExe, KNullDesC));
       
    78     watcherProcess.Resume();
       
    79     QTest::qWait(5000);*/
       
    80     TBool result = msgPlugin->validateService(ETrue);
       
    81     result = msgPlugin->validateService(EFalse);
       
    82     result = msgPlugin->isServiceValid();
       
    83     createAndSend(msgPlugin->messageType());
       
    84     testReceived(msgPlugin->messageType());
       
    85 }
       
    86 
       
    87 //---------------------------------------------------------------
       
    88 // TestSmsPlugin::createAndSend
       
    89 //---------------------------------------------------------------
       
    90 void TestSmsPlugin::createAndSend(int type)
       
    91 {
       
    92 
       
    93     ConvergedMessage message;
       
    94     message.setMessageType((ConvergedMessage::MessageType) type);
       
    95     message.setBodyText(QString(TEST_MSG_BODY));
       
    96     ConvergedMessageAddress address1;
       
    97     address1.setAddress(QString(TEST_MSG_TO3));
       
    98     
       
    99     message.addToRecipient(address1);
       
   100     message.setPriority(ConvergedMessage::Normal);
       
   101     if (type == ConvergedMessage::Mms)
       
   102     {
       
   103         ConvergedMessageAddress address2;
       
   104         address2.setAddress(QString(TEST_MSG_FROM2));
       
   105         address2.setAlias(QString(TEST_MSG_ALIAS2));
       
   106         message.addCcRecipient(address2);
       
   107         message.addBccRecipient(address2);
       
   108 
       
   109         message.setSubject(QString(TEST_MSG_SUBJECT));
       
   110         message.setPriority(ConvergedMessage::Normal);
       
   111     }
       
   112 
       
   113     int ret = -1;
       
   114     QBENCHMARK 
       
   115     {
       
   116     long int id = msgPlugin->convertTo(&message);
       
   117     msgPlugin->send(id);
       
   118     }
       
   119 }
       
   120 	
       
   121 //---------------------------------------------------------------
       
   122 // TestSmsPlugin::testReceived
       
   123 //---------------------------------------------------------------
       
   124 void TestSmsPlugin::testReceived(int type)
       
   125 {
       
   126 MessageServiceAction* messageAction = new MessageServiceAction(this);    
       
   127     QVERIFY(messageAction != 0);
       
   128 
       
   129     //register user defined object to meta system.
       
   130     qRegisterMetaType<ConvergedMessage*>("ConvergedMessage*");
       
   131 
       
   132     //signal spy.
       
   133     //listen to added event
       
   134     QSignalSpy spyAdd( messageAction,
       
   135             SIGNAL(messageAdded(ConvergedMessage*, QString)));
       
   136     //signal spy.
       
   137     //listen to updated event
       
   138         QSignalSpy spyUpdate( messageAction,
       
   139                 SIGNAL(messageUpdated(ConvergedMessage*, QString)));
       
   140     //will force stub_clientmanager to emit messageUpdated.
       
   141     messageAction->registerForNotification();
       
   142     //register user defined object to meta system.
       
   143 
       
   144     // wait for the response to come
       
   145     QTest::qWait(5000);
       
   146 
       
   147     //check signals
       
   148     int countAdd = -1;
       
   149     countAdd = spyAdd.count();
       
   150 
       
   151     ConvergedMessage* message = 0;
       
   152     QString serviceId("");
       
   153     
       
   154     if (countAdd)
       
   155     {
       
   156         //verify added event
       
   157         void * temp = const_cast<void*> (spyAdd.at(0).at(0).data());
       
   158         message = *reinterpret_cast<ConvergedMessage*(*)> (temp);
       
   159         serviceId = spyAdd.at(0).at(1).toString();
       
   160         QVERIFY(message != 0);
       
   161         validateMsg(*message, serviceId);
       
   162     }
       
   163 
       
   164     int countUpdate = -1;
       
   165     countUpdate = spyUpdate.count();
       
   166     message = 0;
       
   167 
       
   168     for (int i = countUpdate; i > 0; --i)
       
   169     {
       
   170         //verify updated event
       
   171         void * temp = const_cast<void*> (spyUpdate.at(i-1).at(0).data());
       
   172         message = *reinterpret_cast<ConvergedMessage*(*)> (temp);
       
   173         if (ConvergedMessage::Inbox == message->location())
       
   174         {
       
   175             serviceId = spyUpdate.at(i-1).at(1).toString();
       
   176             break;
       
   177         }
       
   178     }
       
   179     if (message)
       
   180     {
       
   181         validateMsg(*message, serviceId);
       
   182     }
       
   183     delete message;
       
   184 }
       
   185 
       
   186 //---------------------------------------------------------------
       
   187 // TestSmsPlugin::validateMsg
       
   188 //---------------------------------------------------------------
       
   189 void TestSmsPlugin::validateMsg(const ConvergedMessage& message,
       
   190                                 const QString& serviceId)
       
   191 {
       
   192 #ifdef _DEBUG_TRACES_
       
   193 		qDebug() << "....message received.....";
       
   194 #endif
       
   195 
       
   196     //process incoming messages
       
   197     if (message.location() == ConvergedMessage::Inbox)
       
   198     {
       
   199         int msgId;
       
   200         if (message.id())
       
   201         {
       
   202             msgId = message.id()->getId();
       
   203         }
       
   204         ConvergedMessageAddressList array = message.toAddressList();
       
   205         if (array.count() > 0)
       
   206         {
       
   207             if (array[0])
       
   208                 QCOMPARE(array[0]->address(),QString(TEST_MSG_FROM1));
       
   209         }
       
   210         ConvergedMessageAddress *fromAddr = message.fromAddress();
       
   211         if (fromAddr)
       
   212         {
       
   213             QCOMPARE(fromAddr->address(),QString(TEST_MSG_FROM1));
       
   214         }
       
   215 
       
   216         QCOMPARE(serviceId,QString(TEST_SERVICE_ID));
       
   217 
       
   218         if (message.messageType() == ConvergedMessage::Mms)
       
   219         {
       
   220             mmsId = msgId;
       
   221             QCOMPARE(message.subject(), QString(TEST_MSG_SUBJECT));
       
   222         }
       
   223         else if (message.messageType() == ConvergedMessage::Sms)
       
   224         {
       
   225             smsId = msgId;
       
   226             QCOMPARE(message.bodyText(), QString(TEST_MSG_BODY));
       
   227         }
       
   228     }
       
   229     else if (message.location() == ConvergedMessage::Sent)
       
   230     {
       
   231         ConvergedMessageAddressList array = message.toAddressList();
       
   232         if (array.count() > 0)
       
   233         {
       
   234             if (array[0])
       
   235                 QCOMPARE(array[0]->address(),QString(TEST_MSG_FROM1));
       
   236         }
       
   237 
       
   238         QCOMPARE(serviceId,QString(TEST_SERVICE_ID));
       
   239 
       
   240         if (message.messageType() == ConvergedMessage::Mms)
       
   241         {
       
   242             QCOMPARE(message.subject(), QString(TEST_MSG_SUBJECT));
       
   243         }
       
   244         else if (message.messageType() == ConvergedMessage::Sms)
       
   245         {
       
   246             QCOMPARE(message.bodyText(), QString(TEST_MSG_BODY));
       
   247         }
       
   248     }
       
   249 }