messagingapp/msgutils/unieditorplugins/unieditormmsplugin/tsrc/testmmsgplugin/testmsg.h
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 #ifndef TEST_MSG_H
       
    18 #define TEST_MSG_H
       
    19 //Headers 
       
    20 #include <e32svr.h>
       
    21 #include <SMUTHDR.H>
       
    22 #include <msvapi.h>
       
    23 #include <smut.h>
       
    24 #include <msvstd.h>
       
    25 #include <rsendas.h>
       
    26 #include <rsendasmessage.h>
       
    27 #include <SMSCLNT.H>
       
    28 #include <csmsaccount.h> 
       
    29 //#include <MTMStore.h>
       
    30 #include <mtclreg.h>
       
    31 #include <mtclbase.h>
       
    32 #include <txtrich.h> 				// CRichText
       
    33 #include <msvids.h>            // for Message type IDs
       
    34 #include <mmsclient.h>       // for CMmsClientMtm
       
    35 #include <CMsvMimeHeaders.h>        //Attachemt mimeheader
       
    36 #include <MMsvAttachmentManager.h>  //Attachment manager
       
    37 #include <MMsvAttachmentManagerSync.h>
       
    38 #include <f32file.h>                //parse
       
    39 #include <utf.h>
       
    40 
       
    41 #include <e32base.h>
       
    42 #include <e32property.h>
       
    43 #include <simtsy.h>
       
    44 #include <etelmm.h>
       
    45 #include <es_ini.h>
       
    46 #include <commsdattypesv1_1.h>
       
    47 #include <commsdat.h>
       
    48 
       
    49 #include <Qtdebug>
       
    50 #include <s60qconversions.h>
       
    51 #include "testmmsplugin.ini"
       
    52 
       
    53 using namespace CommsDat;
       
    54 
       
    55 const TInt KMsvTestUidPhonePwrValue = 0x100052C5;
       
    56 enum TMsvTestPhoneStatus
       
    57     {
       
    58     EMsvTestPhoneOff = 0,
       
    59     EMsvTestPhoneOn
       
    60     };
       
    61 
       
    62 class TestMsg : public MMsvSessionObserver
       
    63 {
       
    64 public:
       
    65 
       
    66     TestMsg();
       
    67     ~TestMsg();
       
    68 
       
    69     void createSCSettings();
       
    70 
       
    71     void createSMS();
       
    72     void createMMS();
       
    73 
       
    74     void deleteMessage(int msgId);
       
    75 
       
    76     void initSimTsyL();
       
    77 
       
    78 public: //MMsvSessionObserver
       
    79 
       
    80     void HandleSessionEventL(TMsvSessionEvent aEvent, TAny* aArg1, TAny* aArg2,
       
    81                              TAny* aArg3);
       
    82 
       
    83 private:
       
    84 
       
    85     void initL();
       
    86     void createSMSL(TMsvId aFolderId, TBool aUnReadFlag);
       
    87     void createMMSL(TMsvId aFolderId, TBool aUnReadFlag);
       
    88     void initializeSimTsyL(TInt aTestNumber, HBufC* aTsyName);
       
    89 
       
    90 private:
       
    91 
       
    92     CMsvSession* iSession;
       
    93     CClientMtmRegistry* iMtmRegistry;
       
    94     CSmsClientMtm *smsClientMtm;
       
    95 };
       
    96 
       
    97 //---------------------------------------------------------------
       
    98 // TestMsg::TestMsg
       
    99 //---------------------------------------------------------------
       
   100 TestMsg::TestMsg()
       
   101 {
       
   102     int err;
       
   103     TRAP(err,initL());
       
   104     #ifdef _DEBUG_TRACES_
       
   105 qDebug() << "Error in initialization:" << err;
       
   106 #endif
       
   107 
       
   108 }
       
   109 
       
   110 //---------------------------------------------------------------
       
   111 // TestMsg::TestMsg
       
   112 //---------------------------------------------------------------
       
   113 TestMsg::~TestMsg()
       
   114 {
       
   115     if(smsClientMtm)
       
   116     {
       
   117         delete smsClientMtm;
       
   118         smsClientMtm = NULL;
       
   119     }
       
   120     
       
   121     if (iMtmRegistry)
       
   122     {
       
   123         delete iMtmRegistry;
       
   124         iMtmRegistry = NULL;
       
   125     }
       
   126 
       
   127     if (iSession)
       
   128     {
       
   129         delete iSession;
       
   130         iSession = NULL;
       
   131     }
       
   132 }
       
   133 
       
   134 //---------------------------------------------------------------
       
   135 // TestMsg::createSCSettings
       
   136 //---------------------------------------------------------------
       
   137 void TestMsg::createSCSettings()
       
   138 {
       
   139     smsClientMtm = static_cast<CSmsClientMtm*> (iMtmRegistry->NewMtmL(KUidMsgTypeSMS));
       
   140 
       
   141     TMsvSelectionOrdering ordering;
       
   142 
       
   143     CMsvEntry* root = CMsvEntry::NewL(smsClientMtm->Session(),
       
   144                                       KMsvRootIndexEntryId,
       
   145                                       ordering);
       
   146 
       
   147     CSmsAccount* smsAccount = CSmsAccount::NewLC();
       
   148 
       
   149     CSmsSettings* settings = CSmsSettings::NewL();
       
   150     CleanupStack::PushL(settings);
       
   151     smsAccount->LoadSettingsL(*settings);
       
   152 
       
   153     TMsvEntry entry;
       
   154     entry.iMtm = KUidMsgTypeSMS;
       
   155     entry.iType = KUidMsvServiceEntry;
       
   156     entry.SetReadOnly(EFalse);
       
   157     entry.SetVisible(EFalse);
       
   158     entry.iDate.UniversalTime();
       
   159     entry.iDetails.Set(_L("Nokiatest"));
       
   160 
       
   161     root->SetEntryL(KMsvRootIndexEntryId);
       
   162     root->CreateL(entry);
       
   163 
       
   164     QString serviceCenter01(SERVICE_CENTER_01);
       
   165     QString serviceCenter02(SERVICE_CENTER_02);
       
   166     HBufC* sC01 = S60QConversions::qStringToS60Desc(serviceCenter01);
       
   167     HBufC* sC02 = S60QConversions::qStringToS60Desc(serviceCenter02);
       
   168     CleanupStack::PushL(sC01);
       
   169     CleanupStack::PushL(sC02);
       
   170     settings->AddServiceCenterL(_L("Nokia"), *sC01);
       
   171     settings->AddServiceCenterL(_L("Nokia"), *sC02);
       
   172     CleanupStack::PopAndDestroy(sC02);
       
   173     CleanupStack::PopAndDestroy(sC01);
       
   174     settings->SetDefaultServiceCenter(1);
       
   175     settings->SetValidityPeriod(ESmsVPWeek);
       
   176     settings->SetReplyQuoted(ETrue);
       
   177     settings->SetRejectDuplicate(ETrue);
       
   178     settings->SetDelivery(ESmsDeliveryImmediately);
       
   179     settings->SetDeliveryReport(EFalse);
       
   180     settings->SetReplyPath(EFalse);
       
   181     settings->SetMessageConversion(ESmsConvPIDNone);
       
   182     settings->SetCanConcatenate(ETrue);
       
   183     settings->SetCharacterSet(TSmsDataCodingScheme::ESmsAlphabet7Bit);
       
   184     settings->SetValidityPeriodFormat(TSmsFirstOctet::ESmsVPFInteger);
       
   185     settings->SetStatusReportHandling(CSmsSettings::EMoveReportToInboxVisible);
       
   186     settings->SetSpecialMessageHandling(CSmsSettings::EMoveReportToInboxVisible);
       
   187     settings->SetSmsBearer(CSmsSettings::ESmsBearerCircuitPreferred);
       
   188     settings->SetCommDbAction(CSmsSettings::ENone);
       
   189     settings->SetSmsBearerAction(CSmsSettings::ENone);
       
   190     smsAccount->SaveSettingsL(*settings);
       
   191 
       
   192     CleanupStack::PopAndDestroy(settings);
       
   193     CleanupStack::PopAndDestroy(smsAccount);
       
   194 }
       
   195 
       
   196 //---------------------------------------------------------------
       
   197 // TestMsg::createSMS
       
   198 //---------------------------------------------------------------
       
   199 void TestMsg::createSMS()
       
   200 {
       
   201     int err;
       
   202     TRAP(err,createSMSL(KMsvGlobalInBoxIndexEntryId,ETrue));
       
   203     #ifdef _DEBUG_TRACES_
       
   204 qDebug() << "Error in creating SMS:" << err;
       
   205 #endif
       
   206 
       
   207 }
       
   208 
       
   209 //---------------------------------------------------------------
       
   210 // TestMsg::createMMS
       
   211 //---------------------------------------------------------------
       
   212 void TestMsg::createMMS()
       
   213 {
       
   214     int err;
       
   215     TRAP(err,createMMSL(KMsvGlobalInBoxIndexEntryId,ETrue));
       
   216     #ifdef _DEBUG_TRACES_
       
   217 qDebug() << "Error in creating MMS:" << err;
       
   218 #endif
       
   219 
       
   220 }
       
   221 
       
   222 //---------------------------------------------------------------
       
   223 // TestMsg::initL
       
   224 //---------------------------------------------------------------
       
   225 void TestMsg::initL()
       
   226 {
       
   227     iSession = CMsvSession::OpenSyncL(*this);
       
   228     iMtmRegistry = CClientMtmRegistry::NewL(*iSession);
       
   229 }
       
   230 
       
   231 //---------------------------------------------------------------
       
   232 // TestMsg::createSMSL
       
   233 //---------------------------------------------------------------
       
   234 void TestMsg::createSMSL(TMsvId aFolderId, TBool aUnReadFlag)
       
   235 {
       
   236     CSmsClientMtm *smsClientMtm =
       
   237             static_cast<CSmsClientMtm*> (iMtmRegistry->NewMtmL(KUidMsgTypeSMS));
       
   238     CleanupStack::PushL(smsClientMtm);
       
   239     //Create entry from this index entry
       
   240 
       
   241     smsClientMtm->SwitchCurrentEntryL(aFolderId);
       
   242     smsClientMtm->CreateMessageL(KUidMsgTypeSMS.iUid);
       
   243     TMsvEntry indexEntry = smsClientMtm->Entry().Entry();
       
   244     indexEntry.SetInPreparation(ETrue);
       
   245     indexEntry.iMtm = KUidMsgTypeSMS;
       
   246     indexEntry.iType = KUidMsvMessageEntry;
       
   247     indexEntry.iServiceId = smsClientMtm->ServiceId();
       
   248     indexEntry.iDate.HomeTime();
       
   249     //AddBody
       
   250     QString body(TEST_MSG_BODY);
       
   251 
       
   252     HBufC* bodyText = S60QConversions::qStringToS60Desc(body);
       
   253     if (bodyText)
       
   254     {
       
   255         CleanupStack::PushL(bodyText);
       
   256         CRichText & body = smsClientMtm->Body();
       
   257         body.Reset();
       
   258         body.InsertL(0, *bodyText);
       
   259 
       
   260         TBuf<32> buf;
       
   261         buf.Copy(bodyText->Left(32));
       
   262         indexEntry.iDescription.Set(buf);
       
   263 
       
   264         CleanupStack::PopAndDestroy(bodyText);
       
   265     }
       
   266 
       
   267     // Add addressee
       
   268     //Add Address
       
   269     QString recipient(TEST_MSG_FROM1);
       
   270     // convert from QString to HBufC 
       
   271     HBufC* addr = S60QConversions::qStringToS60Desc(recipient);
       
   272     if (addr)
       
   273     {
       
   274         CleanupStack::PushL(addr);
       
   275         TBuf<32> name;
       
   276         name.Copy(addr->Left(32));
       
   277         indexEntry.iDetails.Set(name);
       
   278 
       
   279         if (aFolderId == KMsvDraftEntryId || aFolderId
       
   280                 == KMsvGlobalOutBoxIndexEntryId)
       
   281         {
       
   282             smsClientMtm->AddAddresseeL(*addr, TPtrC());
       
   283             indexEntry.SetSendingState(KMsvSendStateWaiting);
       
   284         }
       
   285         else if (aFolderId == KMsvSentEntryId || aFolderId
       
   286                 == KMsvGlobalInBoxIndexEntryId)
       
   287         {
       
   288             CSmsHeader& smsHeader = smsClientMtm->SmsHeader();
       
   289             smsHeader.SetFromAddressL(*addr);
       
   290         }
       
   291         CleanupStack::PopAndDestroy(addr);
       
   292     }
       
   293 
       
   294     // final fine tuning
       
   295     indexEntry.SetAttachment(EFalse);
       
   296     indexEntry.SetVisible(ETrue);
       
   297     indexEntry.SetInPreparation(EFalse);
       
   298 
       
   299     if (aFolderId == KMsvGlobalInBoxIndexEntryId)
       
   300     {
       
   301         if (aUnReadFlag)
       
   302         {
       
   303             indexEntry.SetUnread(ETrue);
       
   304         }
       
   305         indexEntry.SetNew(ETrue);
       
   306     }
       
   307     indexEntry.SetComplete(ETrue);
       
   308     smsClientMtm->Entry().ChangeL(indexEntry);
       
   309     smsClientMtm->SaveMessageL();
       
   310 
       
   311     CleanupStack::PopAndDestroy(smsClientMtm);
       
   312 }
       
   313 
       
   314 //---------------------------------------------------------------
       
   315 // TestMsg::createMMSL
       
   316 //---------------------------------------------------------------
       
   317 void TestMsg::createMMSL(TMsvId aFolderId, TBool aUnReadFlag)
       
   318 {
       
   319     CMmsClientMtm
       
   320             *mmsClientMtm =
       
   321                     static_cast<CMmsClientMtm*>
       
   322     (iMtmRegistry->NewMtmL(KUidMsgTypeMultimedia));
       
   323     CleanupStack::PushL(mmsClientMtm);
       
   324     //Create entry from this index entry
       
   325 
       
   326     mmsClientMtm->SwitchCurrentEntryL(aFolderId);
       
   327     mmsClientMtm->CreateMessageL(mmsClientMtm->DefaultServiceL());
       
   328 
       
   329     TMsvEntry indexEntry = mmsClientMtm->Entry().Entry();
       
   330     indexEntry.SetInPreparation(ETrue);
       
   331     indexEntry.iMtm = KUidMsgTypeMultimedia;
       
   332     indexEntry.iType = KUidMsvMessageEntry;
       
   333     indexEntry.iServiceId = mmsClientMtm->DefaultServiceL();
       
   334     indexEntry.iDate.HomeTime();
       
   335 
       
   336     //Subject
       
   337     QString subject(TEST_MSG_SUBJECT);
       
   338 
       
   339     HBufC* sub = S60QConversions::qStringToS60Desc(subject);
       
   340     if (sub)
       
   341     {
       
   342         CleanupStack::PushL(sub);
       
   343 
       
   344         TBuf<32> buf;
       
   345         buf.Copy(sub->Left(32));
       
   346         indexEntry.iDescription.Set(buf);
       
   347 
       
   348         mmsClientMtm->SetSubjectL(*sub);
       
   349         CleanupStack::PopAndDestroy(sub);
       
   350     }
       
   351 
       
   352     // Add addressee
       
   353     //Add Address
       
   354     QString recipient(TEST_MSG_FROM1);
       
   355     // convert from QString to HBufC 
       
   356     HBufC* addr = S60QConversions::qStringToS60Desc(recipient);
       
   357     if (addr)
       
   358     {
       
   359         CleanupStack::PushL(addr);
       
   360         TBuf<32> name;
       
   361         name.Copy(addr->Left(32));
       
   362         indexEntry.iDetails.Set(name);
       
   363 
       
   364         if (aFolderId == KMsvDraftEntryId || aFolderId
       
   365                 == KMsvGlobalOutBoxIndexEntryId)
       
   366         {
       
   367             mmsClientMtm->AddAddresseeL(*addr);
       
   368             indexEntry.SetSendingState(KMsvSendStateWaiting);
       
   369         }
       
   370         else if (aFolderId == KMsvSentEntryId || aFolderId
       
   371                 == KMsvGlobalInBoxIndexEntryId)
       
   372         {
       
   373             mmsClientMtm->SetSenderL(*addr);
       
   374             mmsClientMtm->AddAddresseeL(*addr);
       
   375         }
       
   376         CleanupStack::PopAndDestroy(addr);
       
   377     }
       
   378 
       
   379     // final fine tuning
       
   380     indexEntry.SetVisible(ETrue);
       
   381     indexEntry.SetInPreparation(EFalse);
       
   382 
       
   383     if (aFolderId == KMsvGlobalInBoxIndexEntryId)
       
   384     {
       
   385         if (aUnReadFlag)
       
   386         {
       
   387             indexEntry.SetUnread(ETrue);
       
   388         }
       
   389         indexEntry.SetNew(ETrue);
       
   390     }
       
   391 
       
   392     //body text
       
   393     QString bodyText(TEST_MSG_BODY);
       
   394     HBufC* text = S60QConversions::qStringToS60Desc(bodyText);
       
   395     if (text)
       
   396     {
       
   397         CleanupStack::PushL(text);
       
   398 
       
   399         //we may need some conversion of text here
       
   400         const TInt KMmsMaxBytesPerCharacter = 4;
       
   401         HBufC8* buffer = HBufC8::NewL( text->Length() * KMmsMaxBytesPerCharacter );
       
   402         CleanupStack::PushL( buffer );
       
   403         TPtr8 buf8 = buffer->Des();
       
   404 
       
   405         // get an access to the message store
       
   406         CMsvStore* store = mmsClientMtm->Entry().EditStoreL();
       
   407         CleanupStack::PushL(store);
       
   408 
       
   409         CMsvMimeHeaders* mimeHeaders = CMsvMimeHeaders::NewL();
       
   410         CleanupStack::PushL( mimeHeaders );
       
   411 
       
   412         CMsvAttachment* attaInfo = CMsvAttachment::NewL(CMsvAttachment::EMsvFile);
       
   413         CleanupStack::PushL( attaInfo );
       
   414 
       
   415         TPtrC8 contentType;
       
   416         contentType.Set( KMmsTextPlain );
       
   417 
       
   418         TInt position = contentType.Find( KMmsSlash8 );
       
   419         mimeHeaders->SetContentTypeL( contentType.Left( position ) );
       
   420         mimeHeaders->SetContentSubTypeL( contentType.Mid( position + 1 ) );
       
   421         attaInfo->SetMimeTypeL( contentType );
       
   422         attaInfo->SetAttachmentNameL( _L("body.txt") );
       
   423 
       
   424         mimeHeaders->SetMimeCharset( KMmsUtf8 );
       
   425         mimeHeaders->SetSuggestedFilenameL( _L("body.txt") );
       
   426 
       
   427         // if conversion fails, something is really seriously wrong
       
   428         TInt error = CnvUtfConverter::ConvertFromUnicodeToUtf8( buf8, *text );
       
   429 
       
   430         attaInfo->SetSize( buf8.Length() );
       
   431         mimeHeaders->StoreL( *attaInfo ); // Mime headers are streamed into atta info
       
   432 
       
   433         MMsvAttachmentManagerSync& attaManSync = store->AttachmentManagerExtensionsL();
       
   434         RFile textFile;
       
   435 
       
   436         attaManSync.CreateAttachmentL( _L("body.txt"), textFile, attaInfo );
       
   437         CleanupStack::Pop( attaInfo ); //ownership was transferred.
       
   438 
       
   439         CleanupClosePushL( textFile );
       
   440 
       
   441         //get attachement id, we need it incase of failure
       
   442         TMsvAttachmentId attachmentId = attaInfo->Id();
       
   443         // Now our file handle is open for writing
       
   444         if ( buf8.Length()> 0 )
       
   445         {
       
   446             textFile.Write( buf8 );
       
   447             error = textFile.Flush();
       
   448         }
       
   449         // we must always close
       
   450         CleanupStack::PopAndDestroy( &textFile ); // close textFile
       
   451         CleanupStack::PopAndDestroy( mimeHeaders );
       
   452 
       
   453         store->CommitL();
       
   454         CleanupStack::PopAndDestroy(store);
       
   455         CleanupStack::PopAndDestroy( buffer );
       
   456         CleanupStack::PopAndDestroy(text);
       
   457     }
       
   458 
       
   459     indexEntry.SetComplete(ETrue);
       
   460     mmsClientMtm->Entry().ChangeL(indexEntry);
       
   461     mmsClientMtm->SaveMessageL();
       
   462 
       
   463     // cleanup    
       
   464     CleanupStack::PopAndDestroy(mmsClientMtm);
       
   465 }
       
   466 
       
   467 void TestMsg::HandleSessionEventL(TMsvSessionEvent /*aEvent*/, TAny* /*aArg1*/,
       
   468                                   TAny* /*aArg2*/, TAny* /*aArg3*/)
       
   469 {
       
   470 }
       
   471 
       
   472 void TestMsg::deleteMessage(int msgId)
       
   473 {
       
   474     CMsvEntry* cEntry = iSession->GetEntryL(KMsvGlobalInBoxIndexEntryId);
       
   475     CleanupStack::PushL(cEntry);
       
   476 
       
   477     CMsvEntry* entry = iSession->GetEntryL(msgId);
       
   478     CleanupStack::PushL(entry);
       
   479 
       
   480     TMsvEntry tEntry = entry->Entry();
       
   481     tEntry.SetReadOnly(EFalse);
       
   482     entry->ChangeL(tEntry);
       
   483 
       
   484     cEntry->DeleteL(msgId);
       
   485     CleanupStack::PopAndDestroy(entry);
       
   486     CleanupStack::PopAndDestroy(cEntry);
       
   487 
       
   488 }
       
   489 
       
   490 void TestMsg::initSimTsyL()
       
   491 {
       
   492     _LIT(KDefaultTsyName, "SIM");
       
   493     TPtrC defaultTsyName(KDefaultTsyName);
       
   494     HBufC* defaultTsyNameBuf = defaultTsyName.AllocLC();
       
   495     TInt testNumber = 0;
       
   496 
       
   497     initializeSimTsyL(testNumber, defaultTsyNameBuf);
       
   498 
       
   499     CMDBSession* dbSession = CMDBSession::NewL(CMDBSession::LatestVersion());
       
   500     CleanupStack::PushL(dbSession);
       
   501 
       
   502     CMDBRecordLink<CCDModemBearerRecord>
       
   503             *modemBearerRecordSet = new (ELeave) CMDBRecordLink<
       
   504                     CCDModemBearerRecord> (KCDTIdGlobalSettingsRecord
       
   505                     | KCDTIdModemPhoneServicesSMS);
       
   506     CleanupStack::PushL(modemBearerRecordSet);
       
   507 
       
   508     modemBearerRecordSet->SetRecordId(1);
       
   509     //Load field container with data from database
       
   510     TRAPD(err, modemBearerRecordSet->LoadL(*dbSession));
       
   511     CCDModemBearerRecord
       
   512             *modemRecord =
       
   513                     static_cast<CCDModemBearerRecord*>
       
   514     (CCDRecordBase::RecordFactoryL(KCDTIdModemBearerRecord));
       
   515     CleanupStack::PushL(modemRecord);
       
   516 
       
   517     /*!
       
   518      * Set the record ID to that previously read from
       
   519      * CCDGlobalSettingsRecord.iModemForPhoneServicesAndSMS
       
   520      */
       
   521     modemRecord->SetRecordId(*modemBearerRecordSet);
       
   522 
       
   523     //Load record container with data from database
       
   524     modemRecord->LoadL(*dbSession);
       
   525 
       
   526     modemRecord->iTsyName.SetMaxLengthL(defaultTsyNameBuf->Des().Length());
       
   527     modemRecord->iTsyName = defaultTsyNameBuf->Des();
       
   528     modemRecord->ModifyL(*dbSession);
       
   529 
       
   530     CleanupStack::PopAndDestroy(4);
       
   531 }
       
   532 
       
   533 void TestMsg::initializeSimTsyL(TInt aTestNumber, HBufC* aTsyName)
       
   534 {
       
   535     //Initialize TSY using the System Agent
       
   536     TInt testState;
       
   537     if (KErrNone != RProperty::Get(KUidPSSimTsyCategory,
       
   538                                    KPSSimTsyTestNumber,
       
   539                                    testState))
       
   540     {
       
   541         User::LeaveIfError(RProperty::Define(KUidPSSimTsyCategory,
       
   542                                              KPSSimTsyTestNumber,
       
   543                                              RProperty::EInt));
       
   544     }
       
   545 
       
   546     User::LeaveIfError(RProperty::Set(KUidPSSimTsyCategory,
       
   547                                       KPSSimTsyTestNumber,
       
   548                                       aTestNumber));
       
   549     if (KErrNone != RProperty::Get(KUidSystemCategory,
       
   550                                    KMsvTestUidPhonePwrValue,
       
   551                                    testState))
       
   552     {
       
   553         User::LeaveIfError(RProperty::Define(KUidSystemCategory,
       
   554                                              KMsvTestUidPhonePwrValue,
       
   555                                              RProperty::EInt));
       
   556     }
       
   557     User::LeaveIfError(RProperty::Set(KUidSystemCategory,
       
   558                                       KMsvTestUidPhonePwrValue,
       
   559                                       EMsvTestPhoneOn));
       
   560 
       
   561     User::LeaveIfError(RProperty::Get(KUidPSSimTsyCategory,
       
   562                                       KPSSimTsyTestNumber,
       
   563                                       aTestNumber));
       
   564 
       
   565     RTelServer etelServer;
       
   566     TInt err = etelServer.Connect();
       
   567 
       
   568     if (err != KErrNone)
       
   569     {
       
   570         return;
       
   571     }
       
   572     User::LeaveIfError(etelServer.LoadPhoneModule(aTsyName->Des()));
       
   573 
       
   574     /*!
       
   575      * Find the phone corresponding to this TSY and open a number of
       
   576      * handles on it
       
   577      */
       
   578     TInt numPhones;
       
   579     User::LeaveIfError(etelServer.EnumeratePhones(numPhones));
       
   580     TBool found = EFalse;
       
   581 
       
   582     RMobilePhone iPhone;
       
   583     while (!found && numPhones--)
       
   584     {
       
   585         TName phoneTsy;
       
   586         User::LeaveIfError(etelServer.GetTsyName(numPhones, phoneTsy));
       
   587         if (phoneTsy.CompareF(aTsyName->Des()) == KErrNone)
       
   588         {
       
   589             found = ETrue;
       
   590             RTelServer::TPhoneInfo info;
       
   591             User::LeaveIfError(etelServer.GetPhoneInfo(numPhones, info));
       
   592             CleanupClosePushL(iPhone);
       
   593             User::LeaveIfError(iPhone.Open(etelServer, info.iName));
       
   594             User::LeaveIfError(iPhone.Initialise());
       
   595             CleanupStack::PopAndDestroy(&iPhone);
       
   596         }
       
   597     }
       
   598 }
       
   599 
       
   600 #endif //TEST_MSG_H