messagingapp/msgutils/unidatamodel/unimmsdataplugin/tsrc/testunidatamodelmmsplugin/testunidatamodelmmsplugin.cpp
changeset 25 84d9eb65b26f
parent 23 238255e8b033
child 27 e4592d119491
child 37 518b245aa84c
child 79 2981cb3aa489
equal deleted inserted replaced
23:238255e8b033 25:84d9eb65b26f
     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 "s60qconversions.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 = S60QConversions::qStringToS60Desc(subject);
       
   172         iMmsClientMtm->SetSubjectL(*subj);
       
   173         }
       
   174 
       
   175     //Sender
       
   176     QString sender(TEST_MSG_FROM1);
       
   177     HBufC* addr = S60QConversions::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 = S60QConversions::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 = S60QConversions::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 = S60QConversions::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     pluginLoader->loadPlugins();
       
   239     // Get the MMS data modelplugin
       
   240     pluginInterface = pluginLoader->getDataModelPlugin("mms");
       
   241     
       
   242     pluginInterface->setMessageId(iMessageId);
       
   243 
       
   244     int size = pluginInterface->messageSize();
       
   245     QVERIFY(size == msgSize);
       
   246     
       
   247     QVERIFY(pluginInterface->timeStamp() == retTimeStamp);
       
   248     
       
   249    
       
   250     //Fetch the To List
       
   251     ConvergedMessageAddressList recipientList;
       
   252     pluginInterface->toRecipientList(recipientList);
       
   253     QVERIFY(recipientList.count() != 0);
       
   254     
       
   255     ConvergedMessageAddressList recipientList2;
       
   256     pluginInterface->ccRecipientList(recipientList2);
       
   257     QVERIFY(recipientList2.count() != 0);
       
   258     
       
   259     ConvergedMessageAddressList recipientList3;
       
   260     pluginInterface->bccRecipientList(recipientList3);
       
   261     QVERIFY(recipientList3.count() != 0);
       
   262     
       
   263     QString recepient(TEST_MSG_FROM1);
       
   264     QString fromaddress;
       
   265     pluginInterface->fromAddress(fromaddress);
       
   266     QVERIFY(recepient == fromaddress);
       
   267     
       
   268     UniMessageInfoList attList = pluginInterface->attachmentList();
       
   269     QVERIFY(attList.count() != 0);
       
   270     
       
   271     TInt attCount =0;
       
   272     attCount = pluginInterface->attachmentCount();
       
   273     QVERIFY(attCount != 0);
       
   274     
       
   275     MsgPriority priority = pluginInterface->messagePriority();
       
   276     // Normal priority
       
   277     qDebug() << "prority" << priority;
       
   278     QVERIFY(priority == 1);
       
   279 
       
   280     QVERIFY(pluginInterface->objectCount() == 1);
       
   281     
       
   282     UniMessageInfoList objectlist = pluginInterface->objectList();
       
   283     QVERIFY(!objectlist.isEmpty());
       
   284     
       
   285     QVERIFY(pluginInterface->slideCount() == 0);
       
   286     
       
   287     TRAPD(err, iMmsClientMtm->SwitchCurrentEntryL(KMsvGlobalInBoxIndexEntryId));
       
   288     }
       
   289 
       
   290 void TestUniDataModelMMSPlugin::testOutboxMessage()
       
   291     {
       
   292     createMMS(KMsvGlobalOutBoxIndexEntryIdValue,EFalse);
       
   293     
       
   294     pluginLoader->loadPlugins();
       
   295     // Get the MMS data modelplugin
       
   296     pluginInterface = pluginLoader->getDataModelPlugin("mms");
       
   297     QVERIFY(pluginInterface->messageType()=="mms");
       
   298     
       
   299     pluginInterface->setMessageId(iMessageId);
       
   300 
       
   301     int size = pluginInterface->messageSize();
       
   302     QVERIFY(size == msgSize);
       
   303     
       
   304     QVERIFY(pluginInterface->timeStamp() == retTimeStamp);
       
   305     
       
   306         
       
   307     //Fetch the To List
       
   308     ConvergedMessageAddressList recipientList;
       
   309     pluginInterface->toRecipientList(recipientList);
       
   310     QVERIFY(recipientList.count() != 0);
       
   311     
       
   312     ConvergedMessageAddressList recipientList2;
       
   313     pluginInterface->ccRecipientList(recipientList2);
       
   314     QVERIFY(recipientList2.count() != 0);
       
   315     
       
   316     ConvergedMessageAddressList recipientList3;
       
   317     pluginInterface->bccRecipientList(recipientList3);
       
   318     QVERIFY(recipientList3.count() != 0);
       
   319     
       
   320     QString recepient(TEST_MSG_FROM1);
       
   321     QString fromaddress;
       
   322     pluginInterface->fromAddress(fromaddress);
       
   323     QVERIFY(recepient == fromaddress);
       
   324     
       
   325     UniMessageInfoList attList = pluginInterface->attachmentList();
       
   326     QVERIFY(attList.count() != 0);
       
   327     
       
   328     TInt attCount =0;
       
   329     attCount = pluginInterface->attachmentCount();
       
   330     QVERIFY(attCount != 0);
       
   331     
       
   332     MsgPriority priority = pluginInterface->messagePriority();
       
   333     // Normal priority
       
   334     qDebug() << "prority" << priority;
       
   335     QVERIFY(priority == 1);
       
   336     
       
   337     QVERIFY(pluginInterface->objectCount() == 1);
       
   338     
       
   339     UniMessageInfoList objectlist = pluginInterface->objectList();
       
   340     QVERIFY(!objectlist.isEmpty());
       
   341 
       
   342     TRAPD(err, iMmsClientMtm->SwitchCurrentEntryL(KMsvGlobalInBoxIndexEntryId));    
       
   343     }
       
   344 
       
   345 
       
   346 void TestUniDataModelMMSPlugin::createInboxImageMMS()
       
   347     {
       
   348     TMsvEntry indexEntry;
       
   349     indexEntry.iType = KUidMsvMessageEntry;
       
   350     indexEntry.iMtm = KUidMsgTypeMultimedia;
       
   351     indexEntry.iServiceId = iServiceId;
       
   352     indexEntry.iDate.HomeTime();
       
   353     
       
   354     // Convert TTime to QDateTime , this will be used for comparing the time of mesage 
       
   355     // when fetched from datamodel
       
   356     TTime unixEpoch(KUnixEpoch);
       
   357     TTimeIntervalSeconds seconds;
       
   358     TTime timeStamp = indexEntry.iDate;
       
   359     timeStamp.SecondsFrom(unixEpoch, seconds);
       
   360     retTimeStamp.setTime_t(seconds.Int());
       
   361 
       
   362 
       
   363     TMsvId parentId = KMsvGlobalInBoxIndexEntryIdValue;
       
   364     CMsvEntry* entry = CMsvEntry::NewL(*iMSession,parentId,TMsvSelectionOrdering());
       
   365     CleanupStack::PushL(entry);
       
   366 
       
   367     entry->SetEntryL(parentId);
       
   368     entry->CreateL(indexEntry);
       
   369     entry->SetEntryL(indexEntry.Id());
       
   370     iMmsClientMtm->SwitchCurrentEntryL(entry->EntryId());
       
   371     
       
   372     //iMmsClientMtm->LoadMessageL();
       
   373     
       
   374     CMsvStore* store = iMmsClientMtm->Entry().EditStoreL();
       
   375     CleanupStack::PushL(store);
       
   376       
       
   377     iMessageId = indexEntry.Id();
       
   378     idArr.Append(iMessageId);
       
   379     
       
   380     //Sender
       
   381     QString sender(TEST_MSG_FROM1);
       
   382     HBufC* addr = S60QConversions::qStringToS60Desc(sender);
       
   383     
       
   384     if (addr)
       
   385         {
       
   386         CleanupStack::PushL(addr);
       
   387         TBuf<32> name;
       
   388         name.Copy(addr->Left(32));
       
   389         indexEntry.iDetails.Set(name);
       
   390         
       
   391         iMmsClientMtm->SetSenderL(*addr);
       
   392         
       
   393         CleanupStack::PopAndDestroy(addr);
       
   394         }
       
   395     
       
   396     //Recipient
       
   397     QString recipient(TEST_MSG_RECIEPIENT1);
       
   398     HBufC* addr2 = S60QConversions::qStringToS60Desc(recipient);
       
   399     if (addr2)
       
   400         {
       
   401         CleanupStack::PushL(addr2);
       
   402         iMmsClientMtm->AddAddresseeL(EMsvRecipientTo,*addr2);    
       
   403         CleanupStack::PopAndDestroy(addr2);
       
   404         }
       
   405     
       
   406     
       
   407     // Attachments are added to the message entry one by one
       
   408    
       
   409     TMsvAttachmentId attaId = 0;
       
   410    
       
   411     RFile attaFile;
       
   412     // Set filename of attachment
       
   413     TFileName name( _L("C:\\pictures\\photo.jpg") );
       
   414    
       
   415     CMsvMimeHeaders* mimeHeaders = CMsvMimeHeaders::NewL();
       
   416     CleanupStack::PushL( mimeHeaders );
       
   417    
       
   418     // Set values to mime headers
       
   419     mimeHeaders->SetContentTypeL( _L8( "image") );
       
   420     mimeHeaders->SetContentSubTypeL( _L8( "jpeg" ) );
       
   421    
       
   422     _LIT8(KMimeType, "image/jpeg");
       
   423     TBufC8<10> mimeType(KMimeType);
       
   424     // CreateAttachment2L will set the content type to attachment Info
       
   425    
       
   426     // Open the attachment file for reading
       
   427     attaFile.Open( iFs, name, EFileShareReadersOnly | EFileRead );
       
   428     CleanupClosePushL(attaFile);
       
   429    
       
   430     CMsvAttachment* attaInfo = CMsvAttachment::NewL(CMsvAttachment::EMsvFile);
       
   431     // attaInfo ownerhip will be transferred to Attachment Manager.
       
   432     // It must not be pushed onto the cleanupStack before calling 
       
   433     // CreateAttachment2L.
       
   434    
       
   435        
       
   436     iMmsClientMtm->CreateAttachment2L(*store, attaFile,mimeType,*mimeHeaders,attaInfo,attaId);
       
   437     // Now Attachment Manager owns the attaInfo
       
   438     attaInfo = NULL;
       
   439    
       
   440     CleanupStack::PopAndDestroy(); // attaFile.Close()
       
   441     CleanupStack::PopAndDestroy(); // mimeHeaders
       
   442    
       
   443     // Several attachments can be added before committing the store
       
   444    
       
   445     // Store must be committed before it is destroyed
       
   446     store->CommitL();
       
   447     CleanupStack::PopAndDestroy(); // store
       
   448     
       
   449     iMmsClientMtm->SaveMessageL();    
       
   450     }
       
   451 
       
   452 void TestUniDataModelMMSPlugin::testInboxImageMMSMessage()
       
   453     {
       
   454     createInboxImageMMS();
       
   455     
       
   456     pluginLoader->loadPlugins();
       
   457     // Get the MMS data modelplugin
       
   458     pluginInterface = pluginLoader->getDataModelPlugin("mms");
       
   459     
       
   460     pluginInterface->setMessageId(iMessageId);
       
   461 
       
   462     int size = pluginInterface->messageSize();
       
   463     
       
   464     QVERIFY(pluginInterface->timeStamp() == retTimeStamp);
       
   465     
       
   466         
       
   467     //Fetch the To List
       
   468     ConvergedMessageAddressList recipientList;
       
   469     pluginInterface->toRecipientList(recipientList);
       
   470     QVERIFY(recipientList.count() != 0);
       
   471     
       
   472     QString recepient(TEST_MSG_FROM1);
       
   473     QString fromaddress;
       
   474     pluginInterface->fromAddress(fromaddress);
       
   475     QVERIFY(recepient == fromaddress);
       
   476     
       
   477     TRAPD(err, iMmsClientMtm->SwitchCurrentEntryL(KMsvGlobalInBoxIndexEntryId));
       
   478     }
       
   479 
       
   480 
       
   481 void TestUniDataModelMMSPlugin::testPluginLoading()
       
   482 {
       
   483     pluginLoader->loadPlugins();
       
   484 
       
   485 }
       
   486 
       
   487 
       
   488 void TestUniDataModelMMSPlugin::testGetPluginWithoutLoading()
       
   489 {
       
   490     pluginInterface = pluginLoader->getDataModelPlugin("mms");
       
   491     QVERIFY(pluginInterface == NULL);
       
   492 
       
   493     // Try to geta plugin for a differnt message type
       
   494     pluginInterface = pluginLoader->getDataModelPlugin("vcal");
       
   495     QVERIFY(pluginInterface == NULL);
       
   496 }
       
   497 
       
   498 void TestUniDataModelMMSPlugin::testPluginLoadingMultipleTimes()
       
   499 {
       
   500     pluginLoader->loadPlugins();
       
   501     pluginLoader->loadPlugins();
       
   502     pluginLoader->loadPlugins();
       
   503     pluginLoader->loadPlugins();
       
   504 }
       
   505 
       
   506 
       
   507 void TestObserverMMS::HandleSessionEventL(TMsvSessionEvent /*aEvent*/,
       
   508                                        TAny* /*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/)
       
   509 {
       
   510 }
       
   511 
       
   512 
       
   513