messagingapp/msgutils/unidatautils/unidatamodelloader/tsrc/unittest_unidatamodelloader/src/testunidatamodelloader.cpp
changeset 56 f42d9a78f435
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 #include <QtTest/QtTest>
       
    17 #include <QtDebug>
       
    18 #include <QTimer>
       
    19 #include <QSignalSpy>
       
    20 #include <xqconversions.h>
       
    21 #include <bsp.h>
       
    22 #include <biodb.h> 
       
    23 #include <biouids.h>
       
    24 #include <biocmtm.h>
       
    25 #include "convergedmessageaddress.h"
       
    26 
       
    27 #include "testunidatamodelloader.h"
       
    28 #include <unidatamodelloader.h>
       
    29 #include "testunidatamodelloader.ini"
       
    30 #include "unidatamodelplugininterface.h"
       
    31 #include <convergedmessage.h>
       
    32 #include <unieditorplugininterface.h>
       
    33 
       
    34 const TInt KTelephoneNumberMaxLength = 32;
       
    35 
       
    36 // vCalender
       
    37 _LIT(KUnixEpoch, "19700000:000000.000000");
       
    38 #define KBioUidValue  0x10001262
       
    39 
       
    40 const TUid KBioUidValueUid = {KBioUidValue};
       
    41 
       
    42 
       
    43 //---------------------------------------------------------------
       
    44 //Main entry point
       
    45 //---------------------------------------------------------------
       
    46 int main(int argc, char *argv[])
       
    47     { 
       
    48     int ret = -1;
       
    49     QCoreApplication app(argc, argv);
       
    50     QObject* tc = new TestUniDataModelLoader();
       
    51     
       
    52 #ifdef __WINSCW__	
       
    53 		char *new_argv[3]; 
       
    54 		QString str = "C:\\data\\" + QFileInfo(QCoreApplication::applicationFilePath()).baseName() + ".log";	
       
    55 		QByteArray bytes = str.toAscii();	
       
    56 		char arg1[] = "-o";	
       
    57 		new_argv[0] = argv[0];	
       
    58 		new_argv[1] = arg1;	
       
    59 		new_argv[2] = bytes.data();	
       
    60 		ret = QTest::qExec(tc, 3, new_argv);	
       
    61 #else	
       
    62 		ret = QTest::qExec(tc, argc, argv);	
       
    63 #endif
       
    64 	delete tc;
       
    65     return ret;
       
    66 
       
    67     }
       
    68 //---------------------------------------------------------------
       
    69 // TestUniDataModelLoader::init
       
    70 //---------------------------------------------------------------
       
    71 
       
    72 
       
    73 void TestUniDataModelLoader::initTestCase()
       
    74 {
       
    75 		iObserver = new (ELeave) MsgObserver();
       
    76 
       
    77 	    // Create a new messaging server session..
       
    78 	    iMSession = CMsvSession::OpenSyncL(*iObserver);
       
    79 
       
    80 	    iMsvEntry = iMSession->GetEntryL(KMsvRootIndexEntryId);
       
    81 	    newEntryId = 0;
       
    82 	    pluginLoader = new UniDataModelLoader();
       
    83 
       
    84 	    retTimeStamp = QDateTime::currentDateTime();
       
    85 	    int err = iFs.Connect();
       
    86 	    QVERIFY(err == 0);
       
    87 	    iBioDb = CBIODatabase::NewL(iFs);
       
    88 	    iFs.SetSessionPath(_L("c:\\"));
       
    89 	    inbox = EFalse;
       
    90 }
       
    91 
       
    92 //---------------------------------------------------------------
       
    93 // TestUniDataModelLoader::cleanupTestCase
       
    94 //---------------------------------------------------------------
       
    95 
       
    96 void TestUniDataModelLoader::cleanupTestCase()
       
    97 {
       
    98 	    delete iMsvEntry;
       
    99 	    iMsvEntry = NULL;
       
   100 	    delete iObserver;
       
   101 	    iObserver = NULL;
       
   102 	    delete iMSession;
       
   103 	    iMSession = NULL;
       
   104 	    delete pluginLoader;
       
   105 }
       
   106 
       
   107 
       
   108 //---------------------------------------------------------------
       
   109 // TestUniDataModelLoader::init
       
   110 //---------------------------------------------------------------
       
   111 
       
   112 void TestUniDataModelLoader::init()
       
   113 {
       
   114     
       
   115 }
       
   116 
       
   117 //---------------------------------------------------------------
       
   118 // TestUniDataModelLoader::cleanup
       
   119 //---------------------------------------------------------------
       
   120 void TestUniDataModelLoader::cleanup()
       
   121 {
       
   122   
       
   123 
       
   124 }
       
   125 
       
   126 //---------------------------------------------------------------
       
   127 // TestUniDataModelLoader::testSMSMessage
       
   128 //---------------------------------------------------------------
       
   129 
       
   130 void TestUniDataModelLoader::testSMSMessage()
       
   131 {
       
   132 		QString subject  = TEST_MSG_SUBJECT;
       
   133 	    qint64 timeStamp = QDateTime::currentDateTime().toTime_t();
       
   134 	    QString sender(TEST_SENDER);
       
   135 	    ConvergedMessageAddress address(sender);
       
   136 	    ConvergedMessage msg;
       
   137 	    msg.setMessageType(ConvergedMessage::Sms);
       
   138 	    msg.setSubject(subject);
       
   139 	    msg.setTimeStamp(timeStamp);
       
   140 	    msg.addToRecipient(address);
       
   141 	    msg.setBodyText( TEST_MSG_BODY);
       
   142 	    msg.setPriority(ConvergedMessage::Normal);
       
   143 	    //Adding alias
       
   144 	    ConvergedMessageAddress address1;
       
   145 	    address1.setAlias(QString(TEST_MSG_RECIEPIENT));
       
   146 	    msg.addToRecipient(address1);
       
   147 	            
       
   148 	    pluginInterface = pluginLoader->getDataModelPlugin(ConvergedMessage::Sms);
       
   149 	    
       
   150 	    QVERIFY( pluginInterface != NULL );
       
   151 	    
       
   152 	    QString msgType = pluginInterface->messageType();
       
   153 	   
       
   154 	    qDebug() <<"msgType" << msgType;
       
   155 	    QCOMPARE(msgType, QString("sms"));
       
   156 	    
       
   157 	    qDebug() <<"UnidataModel Loader for SMS Created Successfully";
       
   158 	  	    
       
   159 }
       
   160 
       
   161 
       
   162 //---------------------------------------------------------------
       
   163 // TestUniDataModelLoader::testMMSMessage
       
   164 //---------------------------------------------------------------
       
   165 
       
   166 void TestUniDataModelLoader::testMMSMessage()
       
   167 {
       
   168         qRegisterMetaType<long int> ("long int");
       
   169         QString service = TEST_SERVICE_NAME_MMS;
       
   170         QString subject  = TEST_MSG_SUBJECT;
       
   171         qint64 timeStamp = QDateTime::currentDateTime().toTime_t();
       
   172         	
       
   173         QString sender(TEST_SENDER);
       
   174         ConvergedMessageAddress address(sender);
       
   175         ConvergedMessageAttachmentList attachmentList;  
       
   176         
       
   177         QString attachment2Path = TEST_ATTACHMENT4;
       
   178         	ConvergedMessageAttachment* attachment2 = 
       
   179         			new ConvergedMessageAttachment(attachment2Path, ConvergedMessageAttachment::EAttachment);
       
   180         	
       
   181         QString attachmentPath = TEST_ATTACHMENT5;
       
   182         ConvergedMessageAttachment* attachment = 
       
   183         		new ConvergedMessageAttachment(attachmentPath, ConvergedMessageAttachment::EAttachment);
       
   184         		
       
   185         attachmentList.append(attachment);
       
   186         attachmentList.append(attachment2);
       
   187         ConvergedMessage msg;
       
   188         msg.setMessageType(ConvergedMessage::Mms);
       
   189         msg.setSubject(subject);
       
   190         msg.setTimeStamp(timeStamp);
       
   191         msg.addToRecipient(address);
       
   192         msg.addAttachments(attachmentList);
       
   193         msg.setPriority(ConvergedMessage::Normal);
       
   194         	//Adding alias
       
   195         ConvergedMessageAddress address1;
       
   196         address1.setAlias(QString(TEST_MSG_RECIEPIENT));
       
   197         msg.addToRecipient(address1);
       
   198       
       
   199         pluginInterface = pluginLoader->getDataModelPlugin(ConvergedMessage::Mms);
       
   200         pluginInterface->setMessageId(newEntryId);
       
   201 
       
   202         QVERIFY( pluginInterface != NULL ); 
       
   203         
       
   204         QString msgType = pluginInterface->messageType();
       
   205         	   
       
   206         qDebug() <<"msgType" << msgType;
       
   207         QCOMPARE(msgType, QString("mms"));
       
   208         
       
   209         qDebug() <<"UnidataModel Loader for MMS Created Successfully";
       
   210      	int count = pluginInterface->attachmentCount();
       
   211         QVERIFY(count == 1);        
       
   212         
       
   213 } 
       
   214 
       
   215 //---------------------------------------------------------------
       
   216 // TestUniDataModelLoader::testBioMessage
       
   217 //---------------------------------------------------------------
       
   218 
       
   219 void TestUniDataModelLoader::testBioMessage()
       
   220 {
       
   221 		inbox = ETrue;
       
   222 		pluginInterface = pluginLoader->getDataModelPlugin(ConvergedMessage::BioMsg);
       
   223 		
       
   224 		QVERIFY( pluginInterface != NULL );
       
   225 		
       
   226 		QString msgType = pluginInterface->messageType();
       
   227 				
       
   228 		qDebug() <<"msgType" << msgType;
       
   229 		QCOMPARE(msgType, QString("biomessage"));
       
   230 		
       
   231 		qDebug() <<"UnidataModel Loader for Biomessage Created Successfully";
       
   232 		
       
   233 		    
       
   234 }
       
   235 
       
   236 
       
   237 //---------------------------------------------------------------
       
   238 // TestUniDataModelLoader::HandleSessionEventL
       
   239 //---------------------------------------------------------------
       
   240 
       
   241 void MsgObserver::HandleSessionEventL(TMsvSessionEvent /*aEvent*/,
       
   242                                       TAny* /*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/)
       
   243 {
       
   244 }