messagingapp/msgutils/unidatautils/unidatamodelplugins/unimmsdataplugin/tsrc/testunidatamodelmmsplugin/testunidatamodelmmsplugin.cpp
changeset 56 f42d9a78f435
parent 55 5b3b2fa8c3ec
child 58 5401a102f08b
equal deleted inserted replaced
55:5b3b2fa8c3ec 56:f42d9a78f435
     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 <QtTest/QtTest>
       
    18 #include "serviceinfo.h"
       
    19 #include <QtDebug>
       
    20 #include <QTimer>
       
    21 #include <QSignalSpy>
       
    22 #include "convergedmessage.h"
       
    23 #include <xqconversions.h>
       
    24 #include "unidatamodelplugininterface.h"
       
    25 #include "unidatamodelloader.h"
       
    26 #include <mmsclient.h>
       
    27 #include <mmsheaders.h>
       
    28 #include <mmssettings.h>
       
    29 #include <CMsvMimeHeaders.h>
       
    30 #include "convergedmessageaddress.h"
       
    31 #include "testunidatamodelmmsplugin.h"
       
    32 #include "testunidatamodelmmsplugin.ini"
       
    33 #include <f32file.h>
       
    34 
       
    35 _LIT(KUnixEpoch, "19700000:000000.000000");
       
    36 _LIT( KRootPath, "c:\\" );
       
    37 
       
    38 
       
    39 void TestUniDataModelMMSPlugin::initTestCase()
       
    40     {
       
    41     iObserver = new (ELeave) TestObserverMMS();
       
    42 
       
    43     // Create a new messaging server session..
       
    44     TRAPD(err,iMSession = CMsvSession::OpenSyncL(*iObserver));
       
    45     if(err)
       
    46         {
       
    47         TInt x=err;
       
    48         }
       
    49     // Create the client mtm registry
       
    50     iMtmReg = CClientMtmRegistry::NewL(*iMSession);
       
    51 
       
    52     // Get the MMS clientmtm
       
    53     iMmsClientMtm = (CMmsClientMtm *) iMtmReg->NewMtmL(KUidMsgTypeMultimedia);
       
    54 
       
    55     User::LeaveIfError( iFs.Connect() );
       
    56     iFs.SetSessionPath( KRootPath );
       
    57     iSettings = CMmsSettings::NewL();
       
    58     iMmsHeaders = CMmsHeaders::NewL(iSettings->MmsVersion());
       
    59     iSettings->LoadSettingsL();
       
    60     iServiceId = iSettings->Service();
       
    61     
       
    62     iMessageId = 0;
       
    63     pluginLoader = new UniDataModelLoader();
       
    64     retTimeStamp = QDateTime::currentDateTime();
       
    65     }
       
    66 
       
    67 void TestUniDataModelMMSPlugin::cleanupTestCase()
       
    68     {
       
    69     for(TInt i=0; i<idArr.Count();i++)
       
    70         {
       
    71         iMmsClientMtm->Entry().DeleteL(idArr[i]);
       
    72         }
       
    73 
       
    74     delete iObserver;
       
    75     delete iMmsClientMtm;
       
    76     delete iMtmReg;
       
    77     delete iMSession;
       
    78     delete pluginLoader;
       
    79     }
       
    80 
       
    81 
       
    82 //---------------------------------------------------------------
       
    83 // TestUniDataModelPlugin::init
       
    84 //---------------------------------------------------------------
       
    85 
       
    86 void TestUniDataModelMMSPlugin::init()
       
    87 {
       
    88 /*    iObserver = new (ELeave) TestObserverMMS();
       
    89 
       
    90     // Create a new messaging server session..
       
    91     TRAPD(err,iMSession = CMsvSession::OpenSyncL(*iObserver));
       
    92     if(err)
       
    93         {
       
    94         TInt x=err;
       
    95         }
       
    96     // Create the client mtm registry
       
    97     iMtmReg = CClientMtmRegistry::NewL(*iMSession);
       
    98 
       
    99     // Get the MMS clientmtm
       
   100     iMmsClientMtm = (CMmsClientMtm *) iMtmReg->NewMtmL(KUidMsgTypeMultimedia);
       
   101 
       
   102     User::LeaveIfError( iFs.Connect() );
       
   103     iFs.SetSessionPath( KRootPath );
       
   104     iSettings = CMmsSettings::NewL();
       
   105     iMmsHeaders = CMmsHeaders::NewL(iSettings->MmsVersion());
       
   106     iSettings->LoadSettingsL();
       
   107     iServiceId = iSettings->Service();
       
   108     
       
   109     iMessageId = 0;
       
   110     pluginLoader = new UniDataModelLoader();
       
   111     retTimeStamp = QDateTime::currentDateTime();*/
       
   112 }
       
   113 
       
   114 //---------------------------------------------------------------
       
   115 // TestUniDataModelPlugin::cleanup
       
   116 //---------------------------------------------------------------
       
   117 void TestUniDataModelMMSPlugin::cleanup()
       
   118 {
       
   119 
       
   120  /*  
       
   121     for(TInt i=0; i<idArr.Count();i++)
       
   122         {
       
   123         iMmsClientMtm->Entry().DeleteL(idArr[i]);
       
   124         }
       
   125 
       
   126     delete iObserver;
       
   127     delete iMmsClientMtm;
       
   128     delete iMtmReg;
       
   129     delete iMSession;
       
   130     delete pluginLoader;*/
       
   131 }
       
   132 
       
   133 
       
   134 void TestUniDataModelMMSPlugin::createMMS(TMsvId pId, TBool subjectField)
       
   135     {
       
   136     TMsvEntry indexEntry;
       
   137     indexEntry.iType = KUidMsvMessageEntry;
       
   138     indexEntry.iMtm = KUidMsgTypeMultimedia;
       
   139     indexEntry.iServiceId = iServiceId;
       
   140     indexEntry.iDate.HomeTime();
       
   141     
       
   142     // Convert TTime to QDateTime , this will be used for comparing the time of mesage 
       
   143     // when fetched from datamodel
       
   144     TTime unixEpoch(KUnixEpoch);
       
   145     TTimeIntervalSeconds seconds;
       
   146     TTime timeStamp = indexEntry.iDate;
       
   147     timeStamp.SecondsFrom(unixEpoch, seconds);
       
   148     retTimeStamp.setTime_t(seconds.Int());
       
   149 
       
   150 
       
   151     TMsvId parentId = pId;
       
   152     CMsvEntry* entry = CMsvEntry::NewL(*iMSession,parentId,TMsvSelectionOrdering());
       
   153     CleanupStack::PushL(entry);
       
   154 
       
   155     entry->SetEntryL(parentId);
       
   156     entry->CreateL(indexEntry);
       
   157     entry->SetEntryL(indexEntry.Id());
       
   158     iMmsClientMtm->SwitchCurrentEntryL(entry->EntryId());
       
   159     
       
   160     //iMmsClientMtm->LoadMessageL();
       
   161     
       
   162     CMsvStore* store = iMmsClientMtm->Entry().EditStoreL();
       
   163     CleanupStack::PushL(store);
       
   164       
       
   165     iMessageId = indexEntry.Id();
       
   166     idArr.Append(iMessageId);
       
   167     
       
   168     if(subjectField)
       
   169         {
       
   170         QString subject(TEST_MSG_SUBJECT);
       
   171         HBufC* subj = XQConversions::qStringToS60Desc(subject);
       
   172         iMmsClientMtm->SetSubjectL(*subj);
       
   173         }
       
   174 
       
   175     //Sender
       
   176     QString sender(TEST_MSG_FROM1);
       
   177     HBufC* addr = XQConversions::qStringToS60Desc(sender);
       
   178     
       
   179     
       
   180     if (addr)
       
   181         {
       
   182         CleanupStack::PushL(addr);
       
   183         TBuf<32> name;
       
   184         name.Copy(addr->Left(32));
       
   185         indexEntry.iDetails.Set(name);
       
   186         
       
   187         iMmsClientMtm->SetSenderL(*addr);
       
   188         
       
   189         CleanupStack::PopAndDestroy(addr);
       
   190         }
       
   191     
       
   192     //Recipient
       
   193     QString recipient(TEST_MSG_RECIEPIENT1);
       
   194     HBufC* addr2 = XQConversions::qStringToS60Desc(recipient);
       
   195     if (addr2)
       
   196         {
       
   197         CleanupStack::PushL(addr2);
       
   198         iMmsClientMtm->AddAddresseeL(EMsvRecipientTo,*addr2);
       
   199         CleanupStack::PopAndDestroy(addr2);
       
   200         }
       
   201     
       
   202     QString recipient2(TEST_MSG_RECIEPIENT2);
       
   203     HBufC* addr3 = XQConversions::qStringToS60Desc(recipient2);
       
   204     if (addr3)
       
   205         {
       
   206         CleanupStack::PushL(addr3);
       
   207         iMmsClientMtm->AddAddresseeL(EMsvRecipientCc,*addr3);
       
   208         CleanupStack::PopAndDestroy(addr3);
       
   209         }
       
   210         
       
   211     QString recipient3(TEST_MSG_RECIEPIENT3);
       
   212         HBufC* addr4 = XQConversions::qStringToS60Desc(recipient3);
       
   213         if (addr4)
       
   214             {
       
   215             CleanupStack::PushL(addr4);
       
   216             iMmsClientMtm->AddAddresseeL(EMsvRecipientBcc,*addr4);
       
   217             CleanupStack::PopAndDestroy(addr4);
       
   218             }
       
   219         
       
   220     //Create Text Attachment
       
   221     TMsvAttachmentId attaId = 0;
       
   222     TFileName attachmentFile( _L("story.txt") );
       
   223     TBufC<12> story = _L( "Hello world!" );
       
   224     
       
   225     iMmsClientMtm->CreateTextAttachmentL(*store, attaId, story, attachmentFile, ETrue );
       
   226     msgSize = iMmsClientMtm->MessageSize();
       
   227     
       
   228     store->CommitL();
       
   229     CleanupStack::PopAndDestroy(); // store
       
   230     
       
   231     iMmsClientMtm->SaveMessageL();    
       
   232     }
       
   233 
       
   234 void TestUniDataModelMMSPlugin::testInboxMessage()
       
   235     {
       
   236     createMMS(KMsvGlobalInBoxIndexEntryIdValue,ETrue);
       
   237     
       
   238     // Get the MMS data modelplugin
       
   239     pluginInterface = pluginLoader->getDataModelPlugin(ConvergedMessage::Mms);
       
   240     
       
   241     pluginInterface->setMessageId(iMessageId);
       
   242 
       
   243     int size = pluginInterface->messageSize();
       
   244     QVERIFY(size == msgSize);
       
   245     
       
   246     QVERIFY(pluginInterface->timeStamp() == retTimeStamp);
       
   247     
       
   248    
       
   249     //Fetch the To List
       
   250     ConvergedMessageAddressList recipientList;
       
   251     pluginInterface->toRecipientList(recipientList);
       
   252     QVERIFY(recipientList.count() != 0);
       
   253     
       
   254     ConvergedMessageAddressList recipientList2;
       
   255     pluginInterface->ccRecipientList(recipientList2);
       
   256     QVERIFY(recipientList2.count() != 0);
       
   257     
       
   258     ConvergedMessageAddressList recipientList3;
       
   259     pluginInterface->bccRecipientList(recipientList3);
       
   260     QVERIFY(recipientList3.count() != 0);
       
   261     
       
   262     QString recepient(TEST_MSG_FROM1);
       
   263     QString fromaddress;
       
   264     pluginInterface->fromAddress(fromaddress);
       
   265     QVERIFY(recepient == fromaddress);
       
   266     
       
   267     UniMessageInfoList attList = pluginInterface->attachmentList();
       
   268     QVERIFY(attList.count() != 0);
       
   269     
       
   270     TInt attCount =0;
       
   271     attCount = pluginInterface->attachmentCount();
       
   272     QVERIFY(attCount != 0);
       
   273     
       
   274     MsgPriority priority = pluginInterface->messagePriority();
       
   275     // Normal priority
       
   276     qDebug() << "prority" << priority;
       
   277     QVERIFY(priority == 1);
       
   278 
       
   279     QVERIFY(pluginInterface->objectCount() == 1);
       
   280     
       
   281     UniMessageInfoList objectlist = pluginInterface->objectList();
       
   282     QVERIFY(!objectlist.isEmpty());
       
   283     
       
   284     QVERIFY(pluginInterface->slideCount() == 0);
       
   285     
       
   286     TRAPD(err, iMmsClientMtm->SwitchCurrentEntryL(KMsvGlobalInBoxIndexEntryId));
       
   287     }
       
   288 
       
   289 void TestUniDataModelMMSPlugin::testOutboxMessage()
       
   290     {
       
   291     createMMS(KMsvGlobalOutBoxIndexEntryIdValue,EFalse);
       
   292     
       
   293     // Get the MMS data modelplugin
       
   294     pluginInterface = pluginLoader->getDataModelPlugin(ConvergedMessage::Mms);
       
   295     QVERIFY(pluginInterface->messageType()=="mms");
       
   296     
       
   297     pluginInterface->setMessageId(iMessageId);
       
   298 
       
   299     int size = pluginInterface->messageSize();
       
   300     QVERIFY(size == msgSize);
       
   301     
       
   302     QVERIFY(pluginInterface->timeStamp() == retTimeStamp);
       
   303     
       
   304         
       
   305     //Fetch the To List
       
   306     ConvergedMessageAddressList recipientList;
       
   307     pluginInterface->toRecipientList(recipientList);
       
   308     QVERIFY(recipientList.count() != 0);
       
   309     
       
   310     ConvergedMessageAddressList recipientList2;
       
   311     pluginInterface->ccRecipientList(recipientList2);
       
   312     QVERIFY(recipientList2.count() != 0);
       
   313     
       
   314     ConvergedMessageAddressList recipientList3;
       
   315     pluginInterface->bccRecipientList(recipientList3);
       
   316     QVERIFY(recipientList3.count() != 0);
       
   317     
       
   318     QString recepient(TEST_MSG_FROM1);
       
   319     QString fromaddress;
       
   320     pluginInterface->fromAddress(fromaddress);
       
   321     QVERIFY(recepient == fromaddress);
       
   322     
       
   323     UniMessageInfoList attList = pluginInterface->attachmentList();
       
   324     QVERIFY(attList.count() != 0);
       
   325     
       
   326     TInt attCount =0;
       
   327     attCount = pluginInterface->attachmentCount();
       
   328     QVERIFY(attCount != 0);
       
   329     
       
   330     MsgPriority priority = pluginInterface->messagePriority();
       
   331     // Normal priority
       
   332     qDebug() << "prority" << priority;
       
   333     QVERIFY(priority == 1);
       
   334     
       
   335     QVERIFY(pluginInterface->objectCount() == 1);
       
   336     
       
   337     UniMessageInfoList objectlist = pluginInterface->objectList();
       
   338     QVERIFY(!objectlist.isEmpty());
       
   339 
       
   340     TRAPD(err, iMmsClientMtm->SwitchCurrentEntryL(KMsvGlobalInBoxIndexEntryId));    
       
   341     }
       
   342 
       
   343 
       
   344 void TestUniDataModelMMSPlugin::createInboxImageMMS()
       
   345     {
       
   346     TMsvEntry indexEntry;
       
   347     indexEntry.iType = KUidMsvMessageEntry;
       
   348     indexEntry.iMtm = KUidMsgTypeMultimedia;
       
   349     indexEntry.iServiceId = iServiceId;
       
   350     indexEntry.iDate.HomeTime();
       
   351     
       
   352     // Convert TTime to QDateTime , this will be used for comparing the time of mesage 
       
   353     // when fetched from datamodel
       
   354     TTime unixEpoch(KUnixEpoch);
       
   355     TTimeIntervalSeconds seconds;
       
   356     TTime timeStamp = indexEntry.iDate;
       
   357     timeStamp.SecondsFrom(unixEpoch, seconds);
       
   358     retTimeStamp.setTime_t(seconds.Int());
       
   359 
       
   360 
       
   361     TMsvId parentId = KMsvGlobalInBoxIndexEntryIdValue;
       
   362     CMsvEntry* entry = CMsvEntry::NewL(*iMSession,parentId,TMsvSelectionOrdering());
       
   363     CleanupStack::PushL(entry);
       
   364 
       
   365     entry->SetEntryL(parentId);
       
   366     entry->CreateL(indexEntry);
       
   367     entry->SetEntryL(indexEntry.Id());
       
   368     iMmsClientMtm->SwitchCurrentEntryL(entry->EntryId());
       
   369     
       
   370     //iMmsClientMtm->LoadMessageL();
       
   371     
       
   372     CMsvStore* store = iMmsClientMtm->Entry().EditStoreL();
       
   373     CleanupStack::PushL(store);
       
   374       
       
   375     iMessageId = indexEntry.Id();
       
   376     idArr.Append(iMessageId);
       
   377     
       
   378     //Sender
       
   379     QString sender(TEST_MSG_FROM1);
       
   380     HBufC* addr = XQConversions::qStringToS60Desc(sender);
       
   381     
       
   382     if (addr)
       
   383         {
       
   384         CleanupStack::PushL(addr);
       
   385         TBuf<32> name;
       
   386         name.Copy(addr->Left(32));
       
   387         indexEntry.iDetails.Set(name);
       
   388         
       
   389         iMmsClientMtm->SetSenderL(*addr);
       
   390         
       
   391         CleanupStack::PopAndDestroy(addr);
       
   392         }
       
   393     
       
   394     //Recipient
       
   395     QString recipient(TEST_MSG_RECIEPIENT1);
       
   396     HBufC* addr2 = XQConversions::qStringToS60Desc(recipient);
       
   397     if (addr2)
       
   398         {
       
   399         CleanupStack::PushL(addr2);
       
   400         iMmsClientMtm->AddAddresseeL(EMsvRecipientTo,*addr2);    
       
   401         CleanupStack::PopAndDestroy(addr2);
       
   402         }
       
   403     
       
   404     
       
   405     // Attachments are added to the message entry one by one
       
   406    
       
   407     TMsvAttachmentId attaId = 0;
       
   408    
       
   409     RFile attaFile;
       
   410     // Set filename of attachment
       
   411     TFileName name( _L("C:\\pictures\\photo.jpg") );
       
   412    
       
   413     CMsvMimeHeaders* mimeHeaders = CMsvMimeHeaders::NewL();
       
   414     CleanupStack::PushL( mimeHeaders );
       
   415    
       
   416     // Set values to mime headers
       
   417     mimeHeaders->SetContentTypeL( _L8( "image") );
       
   418     mimeHeaders->SetContentSubTypeL( _L8( "jpeg" ) );
       
   419    
       
   420     _LIT8(KMimeType, "image/jpeg");
       
   421     TBufC8<10> mimeType(KMimeType);
       
   422     // CreateAttachment2L will set the content type to attachment Info
       
   423    
       
   424     // Open the attachment file for reading
       
   425     attaFile.Open( iFs, name, EFileShareReadersOnly | EFileRead );
       
   426     CleanupClosePushL(attaFile);
       
   427    
       
   428     CMsvAttachment* attaInfo = CMsvAttachment::NewL(CMsvAttachment::EMsvFile);
       
   429     // attaInfo ownerhip will be transferred to Attachment Manager.
       
   430     // It must not be pushed onto the cleanupStack before calling 
       
   431     // CreateAttachment2L.
       
   432    
       
   433        
       
   434     iMmsClientMtm->CreateAttachment2L(*store, attaFile,mimeType,*mimeHeaders,attaInfo,attaId);
       
   435     // Now Attachment Manager owns the attaInfo
       
   436     attaInfo = NULL;
       
   437    
       
   438     CleanupStack::PopAndDestroy(); // attaFile.Close()
       
   439     CleanupStack::PopAndDestroy(); // mimeHeaders
       
   440    
       
   441     // Several attachments can be added before committing the store
       
   442    
       
   443     // Store must be committed before it is destroyed
       
   444     store->CommitL();
       
   445     CleanupStack::PopAndDestroy(); // store
       
   446     
       
   447     iMmsClientMtm->SaveMessageL();    
       
   448     }
       
   449 
       
   450 void TestUniDataModelMMSPlugin::testInboxImageMMSMessage()
       
   451     {
       
   452     createInboxImageMMS();
       
   453     
       
   454     // Get the MMS data modelplugin
       
   455     pluginInterface = pluginLoader->getDataModelPlugin(ConvergedMessage::Mms);
       
   456     
       
   457     pluginInterface->setMessageId(iMessageId);
       
   458 
       
   459     int size = pluginInterface->messageSize();
       
   460     
       
   461     QVERIFY(pluginInterface->timeStamp() == retTimeStamp);
       
   462     
       
   463         
       
   464     //Fetch the To List
       
   465     ConvergedMessageAddressList recipientList;
       
   466     pluginInterface->toRecipientList(recipientList);
       
   467     QVERIFY(recipientList.count() != 0);
       
   468     
       
   469     QString recepient(TEST_MSG_FROM1);
       
   470     QString fromaddress;
       
   471     pluginInterface->fromAddress(fromaddress);
       
   472     QVERIFY(recepient == fromaddress);
       
   473     
       
   474     TRAPD(err, iMmsClientMtm->SwitchCurrentEntryL(KMsvGlobalInBoxIndexEntryId));
       
   475     }
       
   476 
       
   477 
       
   478 
       
   479 void TestUniDataModelMMSPlugin::testGetPluginWithoutLoading()
       
   480 {
       
   481     pluginInterface = pluginLoader->getDataModelPlugin(ConvergedMessage::Mms);
       
   482     QVERIFY(pluginInterface == NULL);
       
   483 
       
   484     // Try to geta plugin for a differnt message type
       
   485     pluginInterface = pluginLoader->getDataModelPlugin(ConvergedMessage::BioMsg);
       
   486     QVERIFY(pluginInterface == NULL);
       
   487 }
       
   488 
       
   489 
       
   490 void TestObserverMMS::HandleSessionEventL(TMsvSessionEvent /*aEvent*/,
       
   491                                        TAny* /*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/)
       
   492 {
       
   493 }
       
   494 
       
   495 
       
   496