messagingapp/msgui/appengine/tsrc/testconversationengine/src/testconversationupdatehandler.cpp
changeset 27 e4592d119491
child 43 35b64624a9e7
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 #include "testconversationupdatehandler.h"
       
    19 #include "testconversationenginestub.h"
       
    20 #include "conversationsengine.h"
       
    21 #include <conversationsenginedefines.h>
       
    22 #include <QStandardItemModel>
       
    23 #include <s60qconversions.h>
       
    24 #include <ccsdefs.h>
       
    25 #include <ccsclientconversation.h>
       
    26 
       
    27 
       
    28 TConversationUpdateHandler::TConversationUpdateHandler(QObject* parent)
       
    29 : QObject(parent)
       
    30 {
       
    31     
       
    32 }
       
    33     
       
    34 
       
    35 void TConversationUpdateHandler::SetConversationsViewUpdateHandler()
       
    36 {
       
    37     connect(ConversationsEngine::instance(), 
       
    38                 SIGNAL(conversationModelPopulated()), 
       
    39                 this, 
       
    40                 SLOT(ConversationsViewUpdated()));
       
    41 
       
    42     connect(ConversationsEngine::instance(), 
       
    43                 SIGNAL(conversationModelUpdated()), 
       
    44                 this, 
       
    45                 SLOT(ConversationsViewUpdated()));
       
    46 }
       
    47 
       
    48 void TConversationUpdateHandler::SetConversationsSummaryViewUpdateHandler()
       
    49 {
       
    50     connect(ConversationsEngine::instance(), 
       
    51                 SIGNAL(conversationListModelPopulated()), 
       
    52                 this, 
       
    53                 SLOT(ConversationsSummaryViewUpdated()));
       
    54 }
       
    55 
       
    56 void TConversationUpdateHandler::ConversationsViewUpdated()
       
    57 {
       
    58     int loop, entryCount, unRead = 0;
       
    59     
       
    60     QWARN("List is updated to ..Conversation Model");
       
    61 
       
    62     //Need to compare the Msglist with stub engine
       
    63     QStandardItemModel* convModel = ConversationsEngine::instance()->getConversationsModel();
       
    64     
       
    65     //get the list with conversation address, 
       
    66     //as this is common for all the conversation entries 
       
    67     QModelIndexList indexList = convModel->match(convModel->index(0, 0), 
       
    68                                                 ConversationAddress, 
       
    69                                                 S60QConversions::s60DescToQString(TestConversationEngineStub::Instance()->GetContactID()), 
       
    70                                                 -1, // One match 
       
    71                                                 Qt::MatchExactly);
       
    72     entryCount = indexList.count();
       
    73     
       
    74     qDebug() << "entry count " << entryCount;
       
    75     qDebug() << "row count " << convModel->rowCount();
       
    76     
       
    77     QCOMPARE(entryCount, 
       
    78             TestConversationEngineStub::Instance()->GetConvListSize());
       
    79 
       
    80     //match all the entries with stub conversation list
       
    81     for(loop = 0; loop < entryCount; loop++)
       
    82     {
       
    83         //check for bunch of conversation fields and attributes
       
    84         QCOMPARE(convModel->data(indexList[loop], MessageType).toInt(),
       
    85                 TestConversationEngineStub::Instance()->GetMsgType());
       
    86 
       
    87         //compare the message description
       
    88         QCOMPARE(convModel->data(indexList[loop], BodyText).toString(),
       
    89                 S60QConversions::s60DescToQString(
       
    90                         TestConversationEngineStub::Instance()->
       
    91                          GetDescription()));
       
    92         
       
    93         //check the unread message status 
       
    94         if (convModel->data(indexList[loop], UnReadStatus).toBool())
       
    95         {
       
    96            unRead++;
       
    97         }
       
    98         
       
    99         qDebug() << "Conversation IDs " << convModel->data(indexList[loop], ConvergedMsgId).toInt();
       
   100      }
       
   101     
       
   102     //check the unread messages count
       
   103     QCOMPARE(unRead, TestConversationEngineStub::Instance()->GetUnreadCount());
       
   104 }
       
   105 
       
   106 void TConversationUpdateHandler::ConversationsSummaryViewUpdated()
       
   107 {
       
   108     QWARN("List is updated to ..Conversation Summary Model");
       
   109 
       
   110     //get the conversation client list
       
   111     RPointerArray<CCsClientConversation>&  clientList 
       
   112         = TestConversationEngineStub::Instance()->GetConversationClientList();
       
   113 
       
   114     //get the converation summary model
       
   115     QStandardItemModel* convModel = ConversationsEngine::instance()->getConversationsSummaryModel();
       
   116     
       
   117     //list size and rows in conversation model must be the same
       
   118     QCOMPARE(convModel->rowCount(), clientList.Count());
       
   119     
       
   120 
       
   121     //match all the client entries with stub conversation client list
       
   122     for (int loop = 0; loop < clientList.Count(); loop++)
       
   123     {
       
   124         CCsClientConversation* clientConv = clientList[loop];
       
   125         
       
   126         qint64 msgId = clientConv->GetConversationEntryId();
       
   127         
       
   128         //match convId in model, if not found raise error
       
   129         QModelIndexList indexList = convModel->match(convModel->index(0, 0), 
       
   130                  ConversationId, msgId, 1, Qt::MatchExactly);
       
   131         
       
   132          qDebug() << "msgId " << msgId;
       
   133          qDebug() << "index list " << indexList.count();
       
   134          
       
   135          if (indexList.count() == 0)
       
   136          {
       
   137             QFAIL("Conv client not found");
       
   138          }
       
   139      
       
   140          //check the bunch of converation client details 
       
   141          
       
   142          int msgCnt = clientConv->GetUnreadMessageCount();
       
   143          QCOMPARE(convModel->data(indexList[0], UnreadCount).toInt(), msgCnt);
       
   144          
       
   145          TDesC* dispName = clientConv->GetDisplayName();
       
   146          QCOMPARE(convModel->data(indexList[0], DisplayName).toString(),
       
   147                  S60QConversions::s60DescToQString(*dispName));
       
   148          
       
   149          int contactId = clientConv->GetContactId();
       
   150          QCOMPARE(convModel->data(indexList[0], ContactId).toInt(), contactId);
       
   151 
       
   152          //need to check the conversation entry
       
   153     }
       
   154  }
       
   155