messagingapp/msgui/appengine/tsrc/testconversationengine/src/testconversationenginestub.cpp
branchRCL_3
changeset 26 ebe688cedc25
equal deleted inserted replaced
25:fa1df4b99609 26:ebe688cedc25
       
     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 <msgitem.h>
       
    19 #include <ccsdefs.h>
       
    20 #include <ccsconversationentry.h>
       
    21 #include <ccsclientconversation.h>
       
    22 #include <conversationsenginedefines.h>
       
    23 #include "testconversationenginestub.h"
       
    24 #include "testconversationnotifier.h"
       
    25 #include "convergedmessage.h"
       
    26 
       
    27 TestConversationEngineStub* TestConversationEngineStub::Instance()
       
    28 {
       
    29     static TestConversationEngineStub* iStubEngine 
       
    30                                 = new TestConversationEngineStub();
       
    31     return iStubEngine;
       
    32 }
       
    33 
       
    34 void TestConversationEngineStub::InitL()
       
    35 {
       
    36     iNotifier = new TestConversationNotifier();
       
    37     iConversationID = 1234;
       
    38     iTimeStamp = 123456789;
       
    39     iMsgType = ECsSMS;
       
    40     iUnReadCount = 3;
       
    41 
       
    42     _LIT(Kname , "9343434343");
       
    43     _LIT(KDescription , "This is the test msg.");
       
    44 
       
    45     iContactID = Kname;
       
    46     iDescription = KDescription;
       
    47     iDeletedEntry = NULL;
       
    48 }
       
    49 
       
    50 TestConversationEngineStub::TestConversationEngineStub()
       
    51 {
       
    52     TRAP_IGNORE(InitL());
       
    53 }
       
    54 
       
    55 TestConversationEngineStub::~TestConversationEngineStub()
       
    56 {
       
    57     iConversationClientList.ResetAndDestroy();
       
    58     iConversationEntryList.ResetAndDestroy();
       
    59     delete iNotifier;
       
    60 }
       
    61 
       
    62 void TestConversationEngineStub
       
    63 ::SetResultObserver(MCsResultsObserver *aResultObserver)
       
    64 {
       
    65     iNotifier->SetResultNotifier(aResultObserver);
       
    66 }
       
    67 
       
    68 void TestConversationEngineStub::RemoveResultObserver()
       
    69 {
       
    70     iNotifier->RemoveResultNotifier();
       
    71 }
       
    72 
       
    73 void TestConversationEngineStub
       
    74 ::SetConversationChangeObserver(MCsConversationChangeObserver* aObserver,
       
    75             CCsClientConversation* /*aClientConversation*/)
       
    76 {
       
    77     iNotifier->SetConversationChangeNotifier(aObserver);
       
    78 }
       
    79     
       
    80 void TestConversationEngineStub::RemoveConversationChangeObserver()
       
    81 {
       
    82     iNotifier->RemoveConversationChangeNotifier();
       
    83 }
       
    84 
       
    85 void TestConversationEngineStub
       
    86 ::SetConversationListChangeObserver(MCsConversationListChangeObserver* 
       
    87                                         aConversationListChangeObserver)
       
    88 {
       
    89     iNotifier->SetConversationListNotifier(aConversationListChangeObserver);
       
    90 }
       
    91 
       
    92 void TestConversationEngineStub::RemoveConversationListChangeObserver()
       
    93 {
       
    94     iNotifier->RemoveConversationListNotifier();
       
    95 }
       
    96 
       
    97 void TestConversationEngineStub
       
    98 ::MarkConversationRead(const TInt aConversationId)
       
    99 {
       
   100     for (TInt i = 0; i < iConversationEntryList.Count(); ++i)
       
   101          {
       
   102              if (iConversationEntryList[i]->EntryId() == aConversationId)
       
   103                  {
       
   104                      iConversationEntryList[i]->
       
   105                          ChangeAttributes(ECsAttributeNone, ECsAttributeUnread);
       
   106                      break;
       
   107                  }
       
   108           }
       
   109 }
       
   110 
       
   111 void TestConversationEngineStub
       
   112 ::DeleteConversation(const TInt aConversationId)
       
   113 {
       
   114     for (TInt i = 0; i < iConversationEntryList.Count(); ++i)
       
   115          {
       
   116              if (iConversationEntryList[i]->EntryId() == aConversationId)
       
   117                  {
       
   118                      iDeletedEntry  = iConversationEntryList[i];
       
   119                      iConversationEntryList.Remove(i);
       
   120                  }
       
   121           }
       
   122 }
       
   123 
       
   124 TInt TestConversationEngineStub::GetConvListSize()
       
   125 {
       
   126     return iConversationEntryList.Count();
       
   127 }
       
   128 
       
   129 TInt TestConversationEngineStub::GetUnreadCount()
       
   130 {
       
   131     TInt unRead = 0;
       
   132     for (TInt i = 0; i < iConversationEntryList.Count(); ++i)
       
   133      {
       
   134          if (iConversationEntryList[i]->IsAttributeSet(ECsAttributeUnread))
       
   135              {
       
   136                  unRead++;
       
   137              }
       
   138       }
       
   139     return unRead;
       
   140 }
       
   141 
       
   142 TInt TestConversationEngineStub::GetConversationID()
       
   143 {
       
   144     return iConversationID;
       
   145 }
       
   146 
       
   147 TInt TestConversationEngineStub::GetTimeStamp()
       
   148 {
       
   149     return iTimeStamp;
       
   150 }
       
   151 
       
   152 TInt TestConversationEngineStub::GetMsgType()
       
   153 {
       
   154     return iMsgType;
       
   155 }
       
   156 
       
   157 TDesC& TestConversationEngineStub::GetContactID()
       
   158 {
       
   159     return iContactID;
       
   160 }
       
   161 
       
   162 TDesC& TestConversationEngineStub::GetDescription()
       
   163 {
       
   164     return iDescription;
       
   165 }
       
   166 
       
   167 RPointerArray<CCsClientConversation>& 
       
   168 TestConversationEngineStub::GetConversationClientList()
       
   169 {
       
   170     return iConversationClientList;
       
   171 }
       
   172 
       
   173 CCsConversationEntry*
       
   174 TestConversationEngineStub
       
   175 ::CreateConversationEntryL(TInt aConvID, bool aUnread)
       
   176 {
       
   177     CCsConversationEntry* conversationEntry = CCsConversationEntry::NewL();
       
   178     CleanupStack::PushL(conversationEntry);
       
   179 
       
   180     conversationEntry->SetType(iMsgType);
       
   181     conversationEntry->SetEntryId(aConvID);
       
   182 
       
   183     conversationEntry->SetTimeStampL(iTimeStamp);
       
   184 
       
   185     conversationEntry->SetContactL(iContactID);
       
   186 
       
   187     conversationEntry->SetDescriptionL(iDescription);
       
   188     
       
   189     if (aUnread)
       
   190         {
       
   191         conversationEntry->ChangeAttributes(ECsAttributeUnread, 
       
   192                                                 ECsAttributeNone);
       
   193         conversationEntry->SetConversationDir(0/*MsgDirectionIncoming*/);
       
   194         }
       
   195     else
       
   196         {
       
   197         conversationEntry->SetConversationDir(1/*MsgDirectionOutgoing*/);
       
   198         conversationEntry->ChangeAttributes(ECsAttributeSent, 
       
   199                                                 ECsAttributeNone);
       
   200         }
       
   201    
       
   202     CleanupStack::Pop(conversationEntry);
       
   203     
       
   204     return conversationEntry;
       
   205 }
       
   206 
       
   207 void TestConversationEngineStub
       
   208 ::PrepareConversationListL(TInt aConvID, TInt aToatalCnt, TInt aUnreadCnt)
       
   209 {
       
   210     // create conversation entries
       
   211     for ( TInt iloop = 0; iloop < aToatalCnt; iloop++ )
       
   212         {
       
   213         CCsConversationEntry* conversationEntry 
       
   214                 = CreateConversationEntryL(aConvID++, (aUnreadCnt-- > 0));
       
   215         CleanupStack::PushL(conversationEntry);
       
   216     
       
   217         // append conversation entries to list
       
   218         iConversationEntryList.AppendL(conversationEntry);
       
   219 
       
   220         CleanupStack::Pop(conversationEntry);
       
   221         }
       
   222 }
       
   223 
       
   224 //Prerae a list with : conv id, no of unread msgs, 
       
   225 void TestConversationEngineStub::UpdateConversationList()
       
   226 {
       
   227     TInt error;
       
   228     TInt totalCount = 5;
       
   229     TRAP(error, PrepareConversationListL(iConversationID, totalCount, iUnReadCount));    
       
   230     iNotifier->SendListResultUpdate(iConversationEntryList,totalCount);
       
   231 }
       
   232 
       
   233 void TestConversationEngineStub::UpdateConvEntry(TInt aConversationId)
       
   234 {
       
   235     for (TInt i = 0; i < iConversationEntryList.Count(); ++i)
       
   236      {
       
   237          if (iConversationEntryList[i]->EntryId() == aConversationId)
       
   238          {
       
   239              iNotifier->
       
   240              UpdateConversationEntryModify(*iConversationEntryList[i]);
       
   241              break;
       
   242          }
       
   243       }
       
   244 }
       
   245 
       
   246 void TestConversationEngineStub::UpdateDeletedConvEntry()
       
   247 {
       
   248     if (iDeletedEntry)
       
   249     {
       
   250         iNotifier->UpdateConversationEntryDelete(*iDeletedEntry);
       
   251         delete iDeletedEntry;
       
   252         iDeletedEntry = NULL;
       
   253     }
       
   254 }
       
   255 
       
   256 void TestConversationEngineStub::UpdateAddConvEntryL()
       
   257 {
       
   258     CCsConversationEntry*
       
   259     conversationEntry = CreateConversationEntryL(9999/*iConversationID - 1*/, true);
       
   260     CleanupStack::PushL(conversationEntry);
       
   261     iConversationEntryList.AppendL(conversationEntry);
       
   262     CleanupStack::Pop(conversationEntry);
       
   263     iNotifier->UpdateConversationEntryAdd(*conversationEntry);
       
   264 }
       
   265 
       
   266 void TestConversationEngineStub::UpdateAddConvEntry()
       
   267 {
       
   268     TInt error;
       
   269     TRAP(error, UpdateAddConvEntryL());
       
   270 }
       
   271 
       
   272 void TestConversationEngineStub::UpdateAddConvClientL()
       
   273 {
       
   274     _LIT(KFName , "New User");
       
   275     
       
   276     //need to free alloced descriptor
       
   277     TBuf<10>  BufName(KFName);
       
   278     HBufC * fname = BufName.AllocL();
       
   279     CleanupStack::PushL(fname);
       
   280     
       
   281     CCsConversationEntry* 
       
   282     convEntry = CreateConversationEntryL(iConversationID - 1, true);
       
   283     CleanupStack::PushL(convEntry);
       
   284     
       
   285     CCsClientConversation* 
       
   286     convClient = CreateConversationClientL(fname,4000, 2, *convEntry);
       
   287     CleanupStack::PushL(convClient);
       
   288     
       
   289     iConversationClientList.AppendL(convClient);
       
   290     
       
   291     CleanupStack::Pop(convClient);
       
   292     CleanupStack::PopAndDestroy(convEntry);
       
   293     CleanupStack::PopAndDestroy(fname);
       
   294     iNotifier->UpdateConversationClientAdd(*convClient);
       
   295 }
       
   296 
       
   297 void TestConversationEngineStub::UpdateAddConvClient()
       
   298 {
       
   299     TInt error;
       
   300     TRAP(error, UpdateAddConvClientL());
       
   301 }
       
   302 
       
   303 void TestConversationEngineStub::UpdateDeletedConvClient()
       
   304 {
       
   305     CCsClientConversation* convClient = iConversationClientList[0];
       
   306     iConversationClientList.Remove(0);
       
   307 
       
   308     if (convClient)
       
   309     {
       
   310         iNotifier->UpdateConversationClientDelete(*convClient);
       
   311         delete convClient;
       
   312     }
       
   313 }
       
   314 
       
   315 
       
   316 void TestConversationEngineStub::UpdateConvClient(TInt aConversationId)
       
   317 {
       
   318     for (TInt i = 0; i < iConversationClientList.Count(); ++i)
       
   319      {
       
   320          if (iConversationClientList[i]->GetConversationEntryId() 
       
   321                                                  == aConversationId)
       
   322          {
       
   323              iConversationClientList[i]->
       
   324              GetConversationEntry()->
       
   325              ChangeAttributes(ECsAttributeNone, ECsAttributeUnread);
       
   326              
       
   327              iConversationClientList[i]->SetUnreadMessageCount(0);
       
   328              
       
   329              iNotifier->
       
   330              UpdateConversationClientModify(*iConversationClientList[i]);
       
   331              break;
       
   332          }
       
   333       }
       
   334 }
       
   335 
       
   336 CCsClientConversation* 
       
   337 TestConversationEngineStub::
       
   338 CreateConversationClientL(const HBufC* aDispName, TInt aContactID,
       
   339                           TInt aUnreadCnt,
       
   340                           CCsConversationEntry& aConvEntry)
       
   341 {
       
   342     CCsClientConversation* conversationClient = CCsClientConversation::NewL();
       
   343     CleanupStack::PushL(conversationClient);
       
   344     
       
   345     conversationClient->SetContactId(aContactID);
       
   346     conversationClient->SetUnreadMessageCount(aUnreadCnt);
       
   347     
       
   348     conversationClient->SetDisplayNameL(aDispName);
       
   349 
       
   350     conversationClient->SetConversationEntryL(&aConvEntry);
       
   351     
       
   352     conversationClient->SetConversationEntryId(aConvEntry.EntryId());
       
   353     
       
   354     CleanupStack::Pop(conversationClient);
       
   355     
       
   356     return conversationClient;
       
   357 }
       
   358 
       
   359 void TestConversationEngineStub
       
   360 ::PrepareConversationClientListL(TInt aContactID, TInt aListSize, 
       
   361                                 TInt aUnRead, TInt aUnReadCnt)
       
   362 {
       
   363     TInt convID = iConversationID;
       
   364     
       
   365     _LIT(KFName , "abc");
       
   366     
       
   367     //need to free alloced descriptor
       
   368     TBufC<10>  BufName(KFName);
       
   369     HBufC * fname = BufName.AllocL();
       
   370     CleanupStack::PushL(fname);
       
   371     
       
   372     for (TInt loop = 0; loop < aListSize; loop++)
       
   373         {
       
   374             CCsConversationEntry* 
       
   375             convEntry = CreateConversationEntryL(convID++,
       
   376                                   (aUnRead-- > 0 ? true : false));
       
   377             CleanupStack::PushL(convEntry);
       
   378             
       
   379             CCsClientConversation* 
       
   380             convClient = CreateConversationClientL(fname, aContactID++, aUnReadCnt++,
       
   381                                               *convEntry);
       
   382             CleanupStack::PushL(convClient);
       
   383             
       
   384             iConversationClientList.AppendL(convClient);
       
   385             
       
   386             CleanupStack::Pop(convClient);
       
   387             CleanupStack::PopAndDestroy(convEntry);
       
   388         }
       
   389     CleanupStack::Pop(fname);
       
   390 }
       
   391 
       
   392 //conversation client notifications
       
   393 void TestConversationEngineStub::UpdateConversationClientList()
       
   394 {
       
   395     TInt error;
       
   396     TRAP(error, PrepareConversationClientListL(2000, 5, 3, 0));
       
   397     if (error == KErrNone)
       
   398     {
       
   399         iNotifier->SendClientListUpdate(iConversationClientList);
       
   400     }
       
   401 }
       
   402 
       
   403 TInt TestConversationEngineStub
       
   404 ::GetClientConversationID(const TInt aContactId)
       
   405 {
       
   406     for (TInt i = 0; i < iConversationClientList.Count(); ++i)
       
   407      {
       
   408          if (iConversationClientList[i]->GetContactId() ==  aContactId)
       
   409          {
       
   410              return iConversationClientList[i]->GetConversationEntryId();
       
   411          }
       
   412       }
       
   413     return -1;
       
   414 }
       
   415 
       
   416 TInt TestConversationEngineStub
       
   417 ::GetClientConversationID(const TDesC& aContactAddress)
       
   418 {
       
   419     for (TInt i = 0; i < iConversationClientList.Count(); ++i)
       
   420      {
       
   421          if (iConversationClientList[i]->
       
   422                  GetConversationEntry()->
       
   423                  Contact()->Compare(aContactAddress) == 0)
       
   424          {
       
   425              return iConversationClientList[i]->GetConversationEntryId();
       
   426          }
       
   427       }
       
   428     return -1;
       
   429 }