messagingapp/msgui/appengine/tsrc/testconversationengine/src/testconversationengine.cpp
changeset 27 e4592d119491
child 34 84197e66a4bd
equal deleted inserted replaced
25:84d9eb65b26f 27:e4592d119491
       
     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 <s60qconversions.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     //conversation engine should have emitted signal
       
   107     QCOMPARE( convModify.count(), 1 );
       
   108 }
       
   109 
       
   110 //delete the conversation and validate updetad conversation view
       
   111 void TConversationEngine::DeleteConversationAndUpdateCV()
       
   112 {
       
   113     // delete the conversation entry
       
   114     ConversationsEngine::instance()->
       
   115             deleteConversations(TestConversationEngineStub::Instance()->
       
   116                                 GetConversationID());
       
   117    
       
   118     //listen for emitted signal
       
   119     QSignalSpy convDelete(ConversationsEngine::instance(), 
       
   120                         SIGNAL(conversationModelUpdated()));
       
   121     
       
   122     // Now we check to make sure we don't have any signals already
       
   123     QCOMPARE( convDelete.count(), 0 );
       
   124     
       
   125     // update the conversation view with deleted entry  
       
   126     TestConversationEngineStub::Instance()->UpdateDeletedConvEntry();
       
   127 
       
   128     //conversation engine should have emitted signal
       
   129     QCOMPARE( convDelete.count(), 1 );
       
   130 }
       
   131 
       
   132 //notify new recieved conversation and validate conversation view
       
   133 void TConversationEngine::NotifyNewConversationEntryAndUpdateCV()
       
   134 {
       
   135     //listen for emitted signal
       
   136     QSignalSpy convAdd(ConversationsEngine::instance(), 
       
   137                         SIGNAL(conversationModelUpdated()));
       
   138     
       
   139     // Now we check to make sure we don't have any signals already
       
   140     QCOMPARE( convAdd.count(), 0 );
       
   141 
       
   142     TestConversationEngineStub::Instance()->UpdateAddConvEntry();
       
   143     
       
   144     //conversation engine should have emitted signal
       
   145     QCOMPARE( convAdd.count(), 1 );
       
   146 }
       
   147 
       
   148 //update conversation client list and validate conversation summary model
       
   149 void TConversationEngine::NotifyConversationClientListAndUpdateCLV()
       
   150 {
       
   151     //should be used once, will work for all the test cases
       
   152     //set the conversation summary view update handler 
       
   153     iConvUpdateHandler->SetConversationsSummaryViewUpdateHandler();
       
   154 
       
   155     //listen for emitted signal
       
   156     QSignalSpy convClientList(ConversationsEngine::instance(), 
       
   157                         SIGNAL(conversationListModelPopulated()));
       
   158     
       
   159     // Now we check to make sure we don't have any signals already
       
   160     QCOMPARE( convClientList.count(), 0 );
       
   161     
       
   162     //update the conversation client list to summary model
       
   163     TestConversationEngineStub::Instance()->UpdateConversationClientList();
       
   164     QTest::qWait(2000);
       
   165     
       
   166     //conversation engine should have emitted signal
       
   167     QCOMPARE( convClientList.count(), 1 );
       
   168 }
       
   169 
       
   170 //get contactt details associated with conversation id
       
   171 void TConversationEngine::GetContactDetailsFromConversationID()
       
   172 {
       
   173     //get the conversation client list
       
   174     RPointerArray<CCsClientConversation>&  clientList 
       
   175             = TestConversationEngineStub::Instance()->GetConversationClientList();
       
   176     
       
   177     //match the client list with summary model list
       
   178     for (int loop = 0; loop < clientList.Count(); loop++)
       
   179     {
       
   180         CCsClientConversation* clientConv = clientList[loop];
       
   181          
       
   182         qint64 msgId = clientConv->GetConversationEntryId();
       
   183          
       
   184         QString fname;
       
   185         QString address;
       
   186          
       
   187         ConversationsEngine::instance()->
       
   188                 getContactDetails(msgId, fname, address);
       
   189          
       
   190         qDebug() << "msgId " << msgId;
       
   191           
       
   192         //check the bunch of converation client details 
       
   193         QCOMPARE(fname,
       
   194                S60QConversions::s60DescToQString(
       
   195                        *(clientConv->GetDisplayName())));
       
   196           
       
   197         QCOMPARE(address,
       
   198                 S60QConversions::s60DescToQString(
       
   199                         *(clientConv->GetConversationEntry()->Contact())));
       
   200     }
       
   201 }
       
   202 
       
   203 // get conversation id associated with contact id
       
   204 void TConversationEngine::GetConversationIDFromContatcID()
       
   205 {
       
   206     //get the conversation client list
       
   207     RPointerArray<CCsClientConversation>&  clientList 
       
   208             = TestConversationEngineStub::Instance()->GetConversationClientList();
       
   209 
       
   210     //match the client list with summary model list
       
   211     for (int loop = 0; loop < clientList.Count(); loop++)
       
   212      {
       
   213          CCsClientConversation* clientConv = clientList[loop];
       
   214          
       
   215          qint64 msgId = clientConv->GetConversationEntryId();
       
   216          
       
   217          qint64 convID = ConversationsEngine::instance()->
       
   218                  getConversationIdFromContactId(clientConv->GetContactId());
       
   219          QCOMPARE(convID, msgId);
       
   220      }
       
   221 }
       
   222 
       
   223 // update the new conversation client to summary view 
       
   224 void TConversationEngine::NotifyNewConversationClientAndUpdateCLV()
       
   225 {
       
   226     //Add and update new conversation client to summary model
       
   227     TestConversationEngineStub::Instance()->UpdateAddConvClient();
       
   228 
       
   229     //emit the signal for validating the summary model
       
   230     ConversationsEngine::instance()->emitConversationListModelPopulated();
       
   231 }
       
   232 
       
   233 //update the modified conversation client
       
   234 void TConversationEngine::NotifyModifyConversationClientAndUpdateCLV()
       
   235 {
       
   236     //update the modified conversation client to summary model
       
   237     TestConversationEngineStub::Instance()->
       
   238             UpdateConvClient(TestConversationEngineStub::Instance()->GetConversationID());
       
   239     
       
   240     //emit the signal for validating the summary model
       
   241     ConversationsEngine::instance()->emitConversationListModelPopulated();
       
   242 }
       
   243 
       
   244 //update the deleted conversation client
       
   245 void TConversationEngine::NotifyDeleteConversationClientAndUpdateCLV()
       
   246 {
       
   247     //update the deleted conversation client to summary model
       
   248     TestConversationEngineStub::Instance()->UpdateDeletedConvClient();
       
   249     
       
   250     //emit the signal for validating the summary model
       
   251     ConversationsEngine::instance()->emitConversationListModelPopulated();
       
   252 }
       
   253 
       
   254 //get the conversation id from address
       
   255 void TConversationEngine::GetConversationIDFromAddress()
       
   256 {
       
   257     //get the conversation client list
       
   258     RPointerArray<CCsClientConversation>&  clientList 
       
   259                 = TestConversationEngineStub::Instance()->GetConversationClientList();
       
   260 
       
   261     //math the conversation id recieved from summary model
       
   262     if (clientList.Count())
       
   263     {
       
   264          qint64 msgId = clientList[0]->GetConversationEntryId();
       
   265          
       
   266          QStandardItemModel* convModel = ConversationsEngine::instance()->
       
   267                                                  getConversationsSummaryModel();
       
   268   
       
   269          //match convid in model, if not found raise error
       
   270          QModelIndexList indexList = convModel->match(convModel->index(0, 0), 
       
   271                   ConversationId, msgId, 1, Qt::MatchExactly);
       
   272 
       
   273          QVERIFY2(indexList.count(), "No item found in summary model");
       
   274          
       
   275          qint64 convID = ConversationsEngine::instance()->
       
   276                          getConversationIdFromAddress(
       
   277                          convModel->data(indexList[0], ConversationAddress).toString());
       
   278          QCOMPARE(convID, msgId);
       
   279     }
       
   280 }
       
   281 
       
   282 //fetch more conversations from server
       
   283 void TConversationEngine::FetchMoreConversations()
       
   284 {
       
   285     ConversationsEngine::instance()->fetchMoreConversations();
       
   286 }
       
   287 
       
   288 //clear conversations from conversation view
       
   289 void TConversationEngine::ClearConversations()
       
   290 {
       
   291     //clear the conversations
       
   292     ConversationsEngine::instance()->clearConversations();
       
   293     
       
   294     //validate the conversation view, and raise the error if entry found
       
   295     QStandardItemModel* convModel 
       
   296                         =  ConversationsEngine::instance()->getConversationsModel();
       
   297     QVERIFY2(convModel->rowCount() == 0, "conversation view not cleared");     
       
   298 }
       
   299 
       
   300 //get the drafts model
       
   301 void TConversationEngine::GetDraftsModelFromConversationEngine()
       
   302 {
       
   303     QStandardItemModel* convModel 
       
   304                 =  ConversationsEngine::instance()->getDraftsModel();
       
   305     QVERIFY2(convModel, "Get Drafts Model Failed");
       
   306 }
       
   307 
       
   308 void TConversationEngine::cleanup()
       
   309 {
       
   310     //clean the resources for the current test case
       
   311 }
       
   312 
       
   313 void TConversationEngine::cleanupTestCase()
       
   314 {
       
   315     //delete the update handler
       
   316     delete iConvUpdateHandler;
       
   317     iConvUpdateHandler = NULL;
       
   318     //delete the conversation engine variable
       
   319     delete ConversationsEngine::instance();
       
   320     //delete the stub data
       
   321     delete TestConversationEngineStub::Instance();
       
   322 }