messagingapp/msgui/appengine/tsrc/testconversationengine/src/testconversationengine.cpp
changeset 37 518b245aa84c
equal deleted inserted replaced
25:84d9eb65b26f 37:518b245aa84c
       
     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 
       
    18 // INCLUDES
       
    19 #include "conversationsengine.h"
       
    20 #include "testconversationengine.h"
       
    21 #include "testconversationenginestub.h"
       
    22 #include "testconversationenginestub.h"
       
    23 #include "testconversationupdatehandler.h"
       
    24 #include <ccsclientconversation.h>
       
    25 #include <ccsconversationentry.h>
       
    26 #include <xqconversions.h>
       
    27 #include <conversationsenginedefines.h>
       
    28 
       
    29 
       
    30 void TConversationEngine::initTestCase()
       
    31 {
       
    32     iConvUpdateHandler = new TConversationUpdateHandler();
       
    33     QVERIFY2(ConversationsEngine::instance() != NULL, "Appengine is not initialized.");
       
    34     QVERIFY2(TestConversationEngineStub::Instance() != NULL, "Appengine Stub is not initialized.");
       
    35     
       
    36 }
       
    37 
       
    38 void TConversationEngine::init()
       
    39 {
       
    40     // allocate, setup the neccessary environment for 
       
    41     // current test case to execute 
       
    42 }
       
    43 
       
    44 // fetch the conversations from server
       
    45 void TConversationEngine::GetConversationsFromServer()
       
    46 {
       
    47     QVERIFY2(ConversationsEngine::instance()->
       
    48             getConversations(TestConversationEngineStub::Instance()->
       
    49                             GetConversationID()), "Get conversations failed");
       
    50 }
       
    51 
       
    52 //fetch the coversation and validate conversation view
       
    53 void TConversationEngine::FetchConversationsAndUpdateCV()
       
    54 {
       
    55     QVERIFY2(ConversationsEngine::instance()->
       
    56             getConversations(TestConversationEngineStub::Instance()->
       
    57                             GetConversationID()), "Get conversations failed");
       
    58     
       
    59     //should be used once, will work for all the test cases
       
    60     iConvUpdateHandler->SetConversationsViewUpdateHandler();
       
    61     
       
    62     //listen for emitted signal
       
    63     QSignalSpy convListUpdate(ConversationsEngine::instance(), 
       
    64                         SIGNAL(conversationModelPopulated()));
       
    65     
       
    66     // Now we check to make sure we don't have any signals already
       
    67     QCOMPARE( convListUpdate.count(), 0 );
       
    68 
       
    69     //update the coversation model and 
       
    70     //wait for active object to execute
       
    71     TestConversationEngineStub::Instance()->UpdateConversationList();
       
    72     QTest::qWait(2000);
       
    73     
       
    74     //conversation engine should have emitted signal
       
    75     QCOMPARE( convListUpdate.count(), 1 );        
       
    76 }
       
    77 
       
    78 //validate the current conversation id
       
    79 void TConversationEngine::CheckCurrentConversationID()
       
    80 {
       
    81     QVERIFY2((ConversationsEngine::instance()->getCurrentConversationId() 
       
    82             == TestConversationEngineStub::Instance()->GetConversationID()), 
       
    83             "Current conversation id mismatch");
       
    84 }
       
    85 
       
    86 //mark the conversation as read and validate the conversation view
       
    87 void TConversationEngine::MarkConversationReadAndUpdateCV()
       
    88 {
       
    89     //mark the conversation as read
       
    90     ConversationsEngine::instance()->
       
    91             markConversationRead(TestConversationEngineStub::Instance()->
       
    92                                 GetConversationID());
       
    93 
       
    94     //listen for emitted signal
       
    95     QSignalSpy convModify(ConversationsEngine::instance(), 
       
    96                         SIGNAL(conversationModelUpdated()));
       
    97     
       
    98     // Now we check to make sure we don't have any signals already
       
    99     QCOMPARE( convModify.count(), 0 );
       
   100 
       
   101     // update the conversation view with modified conversation 
       
   102     TestConversationEngineStub::Instance()->
       
   103             UpdateConvEntry(TestConversationEngineStub::Instance()->
       
   104                                 GetConversationID());
       
   105     
       
   106     ConversationsEngine::instance()->emitConversationModelUpdated();
       
   107     
       
   108     //conversation engine should have emitted signal
       
   109     QCOMPARE( convModify.count(), 1 );
       
   110 }
       
   111 
       
   112 //delete the conversation and validate updetad conversation view
       
   113 void TConversationEngine::DeleteConversationAndUpdateCV()
       
   114 {
       
   115     // delete the conversation entry
       
   116     ConversationsEngine::instance()->
       
   117             deleteConversations(TestConversationEngineStub::Instance()->
       
   118                                 GetConversationID());
       
   119    
       
   120     //listen for emitted signal
       
   121     QSignalSpy convDelete(ConversationsEngine::instance(), 
       
   122                         SIGNAL(conversationModelUpdated()));
       
   123     
       
   124     // Now we check to make sure we don't have any signals already
       
   125     QCOMPARE( convDelete.count(), 0 );
       
   126     
       
   127     // update the conversation view with deleted entry  
       
   128     TestConversationEngineStub::Instance()->UpdateDeletedConvEntry();
       
   129 
       
   130     ConversationsEngine::instance()->emitConversationModelUpdated();
       
   131     
       
   132     //conversation engine should have emitted signal
       
   133     QCOMPARE( convDelete.count(), 1 );
       
   134 }
       
   135 
       
   136 //notify new recieved conversation and validate conversation view
       
   137 void TConversationEngine::NotifyNewConversationEntryAndUpdateCV()
       
   138 {
       
   139     //listen for emitted signal
       
   140     QSignalSpy convAdd(ConversationsEngine::instance(), 
       
   141                         SIGNAL(conversationModelUpdated()));
       
   142     
       
   143     // Now we check to make sure we don't have any signals already
       
   144     QCOMPARE( convAdd.count(), 0 );
       
   145 
       
   146     TestConversationEngineStub::Instance()->UpdateAddConvEntry();
       
   147     
       
   148     //conversation engine should have emitted signal
       
   149     QCOMPARE( convAdd.count(), 1 );
       
   150 }
       
   151 
       
   152 //update conversation client list and validate conversation summary model
       
   153 void TConversationEngine::NotifyConversationClientListAndUpdateCLV()
       
   154 {
       
   155     //should be used once, will work for all the test cases
       
   156     //set the conversation summary view update handler 
       
   157     iConvUpdateHandler->SetConversationsSummaryViewUpdateHandler();
       
   158 
       
   159     //listen for emitted signal
       
   160     QSignalSpy convClientList(ConversationsEngine::instance(), 
       
   161                         SIGNAL(conversationListModelPopulated()));
       
   162     
       
   163     // Now we check to make sure we don't have any signals already
       
   164     QCOMPARE( convClientList.count(), 0 );
       
   165     
       
   166     //update the conversation client list to summary model
       
   167     TestConversationEngineStub::Instance()->UpdateConversationClientList();
       
   168     QTest::qWait(2000);
       
   169     
       
   170     //conversation engine should have emitted signal
       
   171     QCOMPARE( convClientList.count(), 1 );
       
   172 }
       
   173 
       
   174 //get contactt details associated with conversation id
       
   175 void TConversationEngine::GetContactDetailsFromConversationID()
       
   176 {
       
   177     //get the conversation client list
       
   178     RPointerArray<CCsClientConversation>&  clientList 
       
   179             = TestConversationEngineStub::Instance()->GetConversationClientList();
       
   180     
       
   181     //match the client list with summary model list
       
   182     for (int loop = 0; loop < clientList.Count(); loop++)
       
   183     {
       
   184         CCsClientConversation* clientConv = clientList[loop];
       
   185          
       
   186         qint64 msgId = clientConv->GetConversationEntryId();
       
   187          
       
   188         QString fname;
       
   189         QString address;
       
   190          
       
   191         ConversationsEngine::instance()->
       
   192                 getContactDetails(msgId, fname, address);
       
   193          
       
   194         qDebug() << "msgId " << msgId;
       
   195           
       
   196         //check the bunch of converation client details 
       
   197         QCOMPARE(fname,
       
   198                XQConversions::s60DescToQString(
       
   199                        *(clientConv->GetDisplayName())));
       
   200           
       
   201         QCOMPARE(address,
       
   202                 XQConversions::s60DescToQString(
       
   203                         *(clientConv->GetConversationEntry()->Contact())));
       
   204     }
       
   205 }
       
   206 
       
   207 // get conversation id associated with contact id
       
   208 void TConversationEngine::GetConversationIDFromContatcID()
       
   209 {
       
   210     //get the conversation client list
       
   211     RPointerArray<CCsClientConversation>&  clientList 
       
   212             = TestConversationEngineStub::Instance()->GetConversationClientList();
       
   213 
       
   214     //match the client list with summary model list
       
   215     for (int loop = 0; loop < clientList.Count(); loop++)
       
   216      {
       
   217          CCsClientConversation* clientConv = clientList[loop];
       
   218          
       
   219          qint64 msgId = clientConv->GetConversationEntryId();
       
   220          
       
   221          qint64 convID = ConversationsEngine::instance()->
       
   222                  getConversationIdFromContactId(clientConv->GetContactId());
       
   223          QCOMPARE(convID, msgId);
       
   224      }
       
   225 }
       
   226 
       
   227 // update the new conversation client to summary view 
       
   228 void TConversationEngine::NotifyNewConversationClientAndUpdateCLV()
       
   229 {
       
   230     //Add and update new conversation client to summary model
       
   231     TestConversationEngineStub::Instance()->UpdateAddConvClient();
       
   232 
       
   233     //emit the signal for validating the summary model
       
   234     ConversationsEngine::instance()->emitConversationListModelPopulated();
       
   235 }
       
   236 
       
   237 //update the modified conversation client
       
   238 void TConversationEngine::NotifyModifyConversationClientAndUpdateCLV()
       
   239 {
       
   240     //update the modified conversation client to summary model
       
   241     TestConversationEngineStub::Instance()->
       
   242             UpdateConvClient(TestConversationEngineStub::Instance()->GetConversationID());
       
   243     
       
   244     //emit the signal for validating the summary model
       
   245     ConversationsEngine::instance()->emitConversationListModelPopulated();
       
   246 }
       
   247 
       
   248 //update the deleted conversation client
       
   249 void TConversationEngine::NotifyDeleteConversationClientAndUpdateCLV()
       
   250 {
       
   251     //update the deleted conversation client to summary model
       
   252     TestConversationEngineStub::Instance()->UpdateDeletedConvClient();
       
   253     
       
   254     //emit the signal for validating the summary model
       
   255     ConversationsEngine::instance()->emitConversationListModelPopulated();
       
   256 }
       
   257 
       
   258 //get the conversation id from address
       
   259 void TConversationEngine::GetConversationIDFromAddress()
       
   260 {
       
   261     //get the conversation client list
       
   262     RPointerArray<CCsClientConversation>&  clientList 
       
   263                 = TestConversationEngineStub::Instance()->GetConversationClientList();
       
   264 
       
   265     //math the conversation id recieved from summary model
       
   266     if (clientList.Count())
       
   267     {
       
   268          qint64 msgId = clientList[0]->GetConversationEntryId();
       
   269          
       
   270          QStandardItemModel* convModel = ConversationsEngine::instance()->
       
   271                                                  getConversationsSummaryModel();
       
   272   
       
   273          //match convid in model, if not found raise error
       
   274          QModelIndexList indexList = convModel->match(convModel->index(0, 0), 
       
   275                   ConversationId, msgId, 1, Qt::MatchExactly);
       
   276 
       
   277          QVERIFY2(indexList.count(), "No item found in summary model");
       
   278          
       
   279          qint64 convID = ConversationsEngine::instance()->
       
   280                          getConversationIdFromAddress(
       
   281                          convModel->data(indexList[0], ConversationAddress).toString());
       
   282          QCOMPARE(convID, msgId);
       
   283     }
       
   284 }
       
   285 
       
   286 //fetch more conversations from server
       
   287 void TConversationEngine::FetchMoreConversations()
       
   288 {
       
   289     ConversationsEngine::instance()->fetchMoreConversations();
       
   290 }
       
   291 
       
   292 //clear conversations from conversation view
       
   293 void TConversationEngine::ClearConversations()
       
   294 {
       
   295     //clear the conversations
       
   296     ConversationsEngine::instance()->clearConversations();
       
   297     
       
   298     //validate the conversation view, and raise the error if entry found
       
   299     QStandardItemModel* convModel 
       
   300                         =  ConversationsEngine::instance()->getConversationsModel();
       
   301     QVERIFY2(convModel->rowCount() == 0, "conversation view not cleared");     
       
   302 }
       
   303 
       
   304 //get the drafts model
       
   305 void TConversationEngine::GetDraftsModelFromConversationEngine()
       
   306 {
       
   307     QStandardItemModel* convModel 
       
   308                 =  ConversationsEngine::instance()->getDraftsModel();
       
   309     QVERIFY2(convModel, "Get Drafts Model Failed");
       
   310 }
       
   311 
       
   312 void TConversationEngine::cleanup()
       
   313 {
       
   314     //clean the resources for the current test case
       
   315 }
       
   316 
       
   317 void TConversationEngine::cleanupTestCase()
       
   318 {
       
   319     //delete the update handler
       
   320     delete iConvUpdateHandler;
       
   321     iConvUpdateHandler = NULL;
       
   322     //delete the conversation engine variable
       
   323     delete ConversationsEngine::instance();
       
   324     //delete the stub data
       
   325     delete TestConversationEngineStub::Instance();
       
   326 }
       
   327 
       
   328 
       
   329 //main entry point
       
   330 int main(int argc, char *argv[])
       
   331     { 
       
   332     int ret = -1;
       
   333     QCoreApplication app(argc, argv);
       
   334     QObject* tc = new TConversationEngine();
       
   335     ret =  QTest::qExec(tc, argc, argv);
       
   336 	delete tc;
       
   337     return ret;
       
   338     }
       
   339