ipsservices/tsrc/profiletester/src/popimapprofiletesterBlocks.cpp
branchRCL_3
changeset 80 726fba06891a
parent 70 968773a0b6ef
equal deleted inserted replaced
73:c8382f7b54ef 80:726fba06891a
     1 /* ============================================================================
     1 /* ============================================================================
     2  *  Name        :  popimapprofiletesterBlocks.cpp
     2  *  Name        :  popimapprofiletesterBlocks.cpp
     3  *  Part of     :  ipsservices / profiletester 
     3  *  Part of     :  ipsservices / profiletester 
     4  *  Description :: STIF test cases
     4  *  Description :: STIF test cases
     5  *  Version     : %version: 1 % << Don't touch! Updated by Synergy at check-out.
     5  *  Version     : %version: 2 % << Don't touch! Updated by Synergy at check-out.
     6  *
     6  *
     7  *  Copyright © 2010-2010 Nokia and/or its subsidiary(-ies).  All rights reserved.
     7  *  Copyright © 2010-2010 Nokia and/or its subsidiary(-ies).  All rights reserved.
     8  *  This material, including documentation and any related computer
     8  *  This material, including documentation and any related computer
     9  *  programs, is protected by copyright controlled by Nokia.  All
     9  *  programs, is protected by copyright controlled by Nokia.  All
    10  *  rights are reserved.  Copying, including reproducing, storing,
    10  *  rights are reserved.  Copying, including reproducing, storing,
    20 #include <StifParser.h>
    20 #include <StifParser.h>
    21 #include <StifTestInterface.h>
    21 #include <StifTestInterface.h>
    22 #include <e32math.h>
    22 #include <e32math.h>
    23 #include <msvids.h>
    23 #include <msvids.h>
    24 #include "popimapprofiletester.h"
    24 #include "popimapprofiletester.h"
       
    25 
       
    26 //const values
       
    27 const TInt KMailboxStatusLen = 10;
       
    28 const TInt KTimeUnits = 3;
       
    29 const TInt KNumOfRec= 2;
       
    30 
    25 _LIT( KPopImapProfileTester, "c:\\TestFramework\\TestFramework_ips.ini" );
    31 _LIT( KPopImapProfileTester, "c:\\TestFramework\\TestFramework_ips.ini" );
    26 _LIT( KStifEmailSubject, "STIF Basic Operations test" );
    32 _LIT( KStifEmailSubject, "STIF Basic Operations test" );
    27 _LIT( KStifEmailSubjectDes,"STIF_");
    33 _LIT( KStifEmailSubjectDes,"STIF_");
    28 _LIT( KStifEmailBodyText, "This is a temporary STIF test message");
    34 _LIT( KStifEmailBodyText, "This is a temporary STIF test message");
    29 _LIT( KStifEmailSubjectAttHandling, "STIF Attachment Handling Test" );
    35 _LIT( KStifEmailSubjectAttHandling, "STIF Attachment Handling Test" );
   114     iLog->Log(_L( "== End a transaction in SetupAccount ==" ));
   120     iLog->Log(_L( "== End a transaction in SetupAccount ==" ));
   115 
   121 
   116     // IV. Create mailbox through WizardDataAvailableL()
   122     // IV. Create mailbox through WizardDataAvailableL()
   117     err = iMailClient->WizardDataAvailableL();
   123     err = iMailClient->WizardDataAvailableL();
   118     if (KErrNone == err)
   124     if (KErrNone == err)
       
   125 	  {
   119         WaitForEvent(TFSEventNewMailbox, NULL, NULL, KTenSecondsTime);
   126         WaitForEvent(TFSEventNewMailbox, NULL, NULL, KTenSecondsTime);
       
   127 	  }
   120     err = InitMailboxL();
   128     err = InitMailboxL();
   121     if ((KErrNone == err) && NULL != iIPSMailbox)
   129     if ((KErrNone == err) && NULL != iIPSMailbox)
       
   130 	  {
   122         err = KErrNone;
   131         err = KErrNone;
       
   132 	  }
   123     else
   133     else
       
   134 	  {
   124         err = KErrGeneral;
   135         err = KErrGeneral;
       
   136 	  }
   125 
   137 
   126     iLog->Log(_L( "== SetupAccount Ends err=%d" ), err);
   138     iLog->Log(_L( "== SetupAccount Ends err=%d" ), err);
   127     return err;
   139     return err;
   128     }
   140     }
   129 // -----------------------------------------------------------------------------
   141 // -----------------------------------------------------------------------------
   141         }
   153         }
   142 
   154 
   143     iLog->Log(_L( "== GoOnline Begins ==" ));
   155     iLog->Log(_L( "== GoOnline Begins ==" ));
   144 
   156 
   145     // check current mailbox status
   157     // check current mailbox status
   146     TBuf<10> statusDes;
   158     TBuf<KMailboxStatusLen> statusDes;
   147     TFSMailBoxStatus status = iIPSMailbox->GetMailBoxStatus();
   159     TFSMailBoxStatus status = iIPSMailbox->GetMailBoxStatus();
   148     if (status == EFSMailBoxOffline)
   160     if (status == EFSMailBoxOffline)
   149         {
   161         {
   150         statusDes.Copy(_L("offline"));
   162         statusDes.Copy(_L("offline"));
   151         }
   163         }
   167     iEventSynchronousCall = ETrue;
   179     iEventSynchronousCall = ETrue;
   168     iIPSMailbox->GoOnlineL();
   180     iIPSMailbox->GoOnlineL();
   169     syncstatus = iIPSMailbox->CurrentSyncState();
   181     syncstatus = iIPSMailbox->CurrentSyncState();
   170     // we should likely base on TFSEventMailboxOnline, but this does not come always (?)
   182     // we should likely base on TFSEventMailboxOnline, but this does not come always (?)
   171     err = WaitForEvent(TFSEventMailboxOnline, NULL, NULL, KOneMinuteTime);
   183     err = WaitForEvent(TFSEventMailboxOnline, NULL, NULL, KOneMinuteTime);
   172 
   184     
   173     syncstatus = iIPSMailbox->CurrentSyncState();
   185 	if( KErrNone == err)
   174 
   186 	{
   175     //check status of current mailbox again
   187      syncstatus = iIPSMailbox->CurrentSyncState();
   176     status = iIPSMailbox->GetMailBoxStatus();
   188 
   177 
   189      //check status of current mailbox again
   178     if (status == EFSMailBoxOnline)
   190      status = iIPSMailbox->GetMailBoxStatus();
       
   191 
       
   192      if (status == EFSMailBoxOnline)
   179         {
   193         {
   180         err = KErrNone;
   194         err = KErrNone;
   181         iLog->Log(_L("Success: mailbox online"));
   195         iLog->Log(_L("Success: mailbox online"));
   182         }
   196         }
   183     else
   197      else
   184         {
   198         {
   185         err = KErrGeneral;
   199         err = KErrGeneral;
   186         iLog->Log(_L("Failed: mailbox status- %S"), &statusDes);
   200         iLog->Log(_L("Failed: mailbox status- %S"), &statusDes);
   187         }
   201         }
   188 
   202 	} //end if 'KErrNone == err'
       
   203 	
   189     iLog->Log(_L( "== GoOnline ends err=%d" ), err);
   204     iLog->Log(_L( "== GoOnline ends err=%d" ), err);
   190     return err;
   205     return err;
   191     }
   206     }
   192 // -----------------------------------------------------------------------------
   207 // -----------------------------------------------------------------------------
   193 // CPopImapProfileTester:: GoOfflineL
   208 // CPopImapProfileTester:: GoOfflineL
   202         iLog->Log(_L("Error: IMAP/POP profile does NOT exist"));
   217         iLog->Log(_L("Error: IMAP/POP profile does NOT exist"));
   203         return KErrGeneral;
   218         return KErrGeneral;
   204         }
   219         }
   205 
   220 
   206     iLog->Log(_L( "== GoOffline Begins ==" ));
   221     iLog->Log(_L( "== GoOffline Begins ==" ));
   207     TBuf<10> statusDes;
   222     TBuf<KMailboxStatusLen> statusDes;
   208     TFSMailBoxStatus status = iIPSMailbox->GetMailBoxStatus();
   223     TFSMailBoxStatus status = iIPSMailbox->GetMailBoxStatus();
   209     if (status == EFSMailBoxOffline)
   224     if (status == EFSMailBoxOffline)
   210         {
   225         {
   211         statusDes.Copy(_L("offline"));
   226         statusDes.Copy(_L("offline"));
   212         iLog->Log(_L("Mailbox has been Offline, go online firstly"));
   227         iLog->Log(_L("Mailbox has been Offline, go online firstly"));
   228     iEventSynchronousCall = ETrue;
   243     iEventSynchronousCall = ETrue;
   229     TSSMailSyncState syncstatus = iIPSMailbox->CurrentSyncState();
   244     TSSMailSyncState syncstatus = iIPSMailbox->CurrentSyncState();
   230     iIPSMailbox->GoOfflineL();
   245     iIPSMailbox->GoOfflineL();
   231     syncstatus = iIPSMailbox->CurrentSyncState();
   246     syncstatus = iIPSMailbox->CurrentSyncState();
   232     err = WaitForEvent(TFSEventMailboxOffline, NULL, NULL, KOneMinuteTime);
   247     err = WaitForEvent(TFSEventMailboxOffline, NULL, NULL, KOneMinuteTime);
   233     syncstatus = iIPSMailbox->CurrentSyncState();
   248 	if( KErrNone == err)
   234     //check status of current mailbox again
   249 	{
   235     status = iIPSMailbox->GetMailBoxStatus();
   250      syncstatus = iIPSMailbox->CurrentSyncState();
   236 
   251      //check status of current mailbox again
   237     if (status == EFSMailBoxOffline)
   252      status = iIPSMailbox->GetMailBoxStatus();
       
   253 
       
   254      if (status == EFSMailBoxOffline)
   238         {
   255         {
   239         iLog->Log(_L("Success: mailbox offline"));
   256         iLog->Log(_L("Success: mailbox offline"));
   240         }
   257         }
   241     else
   258      else
   242         {
   259         {
   243         err = KErrGeneral;
   260         err = KErrGeneral;
   244         iLog->Log(_L("Failed: mailbox status- %S"), &statusDes);
   261         iLog->Log(_L("Failed: mailbox status- %S"), &statusDes);
   245         }
   262         }
   246 
   263     } //end if 'KErrNone == err'
   247     iLog->Log(_L( "GoOffline ends err=%d" ), err);
   264     iLog->Log(_L( "GoOffline ends err=%d" ), err);
   248     return err;
   265     return err;
   249     }
   266     }
   250 // -----------------------------------------------------------------------------
   267 // -----------------------------------------------------------------------------
   251 // CPopImapProfileTester:: RefreshNowL
   268 // CPopImapProfileTester:: RefreshNowL
   263     iLog->Log(_L( "RefreshNow begins" ));
   280     iLog->Log(_L( "RefreshNow begins" ));
   264     TInt reqId = iIPSMailbox->RefreshNowL(*this);
   281     TInt reqId = iIPSMailbox->RefreshNowL(*this);
   265     iLog->Log(_L("Request Id -> %d"), reqId);
   282     iLog->Log(_L("Request Id -> %d"), reqId);
   266     TSSMailSyncState syncstatus = iIPSMailbox->CurrentSyncState();
   283     TSSMailSyncState syncstatus = iIPSMailbox->CurrentSyncState();
   267     if ((StartingSync == syncstatus) || (EmailSyncing == syncstatus))
   284     if ((StartingSync == syncstatus) || (EmailSyncing == syncstatus))
       
   285 	  {
   268         err = WaitForEvent(TFSEventMailboxOnline);
   286         err = WaitForEvent(TFSEventMailboxOnline);
       
   287 	  }
   269     else
   288     else
       
   289 	  {
   270         err = KErrGeneral;
   290         err = KErrGeneral;
       
   291 	  }
   271     if (err == KErrNone)
   292     if (err == KErrNone)
   272         {
   293         {
   273         WaitForResponse(TFSProgress::EFSStatus_RequestComplete, KOneMinuteTime*3);
   294         WaitForResponse(TFSProgress::EFSStatus_RequestComplete, KOneMinuteTime*KTimeUnits);
   274         syncstatus = iIPSMailbox->CurrentSyncState();
   295         syncstatus = iIPSMailbox->CurrentSyncState();
   275         }
   296         }
   276     iLog->Log(_L( "RefreshNow ends err=%d" ), err);
   297     iLog->Log(_L( "RefreshNow ends err=%d" ), err);
   277     return err;
   298     return err;
   278     }
   299     }
   502                     EFSMsgDataSubject, EFSMailSortByDate, msgCount);
   523                     EFSMsgDataSubject, EFSMailSortByDate, msgCount);
   503             if (gotMsgs > 0)
   524             if (gotMsgs > 0)
   504                 {
   525                 {
   505                 iLog->Log(_L("  Listing first %d emails:"), gotMsgs);
   526                 iLog->Log(_L("  Listing first %d emails:"), gotMsgs);
   506                 }
   527                 }
   507             for (TInt i = 0; i < messages.Count(); ++i)
   528 			TInt messagesCount = messages.Count();
       
   529             for (TInt i = 0; i < messagesCount; ++i)
   508                 {
   530                 {
   509                 iLog->Log(_L("    %d. %S"), i + 1, &messages[i]->GetSubject());
   531                 iLog->Log(_L("    %d. %S"), i + 1, &messages[i]->GetSubject());
   510                 }
   532                 }
   511             if (gotMsgs != messages.Count())
   533             if (gotMsgs != messages.Count())
   512                 { // warning, NextL() returned fewer entries than expected
   534                 { // warning, NextL() returned fewer entries than expected
   553     //get folder name  
   575     //get folder name  
   554     if (aItem.GetString(_L("_messageFolder:"), folderS) == KErrNone)
   576     if (aItem.GetString(_L("_messageFolder:"), folderS) == KErrNone)
   555         {
   577         {
   556         RPointerArray<CFSMailFolder>& folders = iIPSMailbox->ListFolders();
   578         RPointerArray<CFSMailFolder>& folders = iIPSMailbox->ListFolders();
   557         // find and get folder id
   579         // find and get folder id
   558         for (TInt i = 0; i < folders.Count(); i++)
   580 		TInt foldersCount = folders.Count();
       
   581         for (TInt i = 0; i < foldersCount; i++)
   559             {
   582             {
   560             if (folders[i]->GetFolderName().Compare(folderS) == 0)
   583             if (folders[i]->GetFolderName().Compare(folderS) == 0)
   561                 {
   584                 {
   562                 msgFolderId = folders[i]->GetFolderId();
   585                 msgFolderId = folders[i]->GetFolderId();
   563                 iLog->Log(_L("Message will be fetched from %S folder"),
   586                 iLog->Log(_L("Message will be fetched from %S folder"),
   655         TFSMailMsgId newMsgId = TFSMailMsgId();
   678         TFSMailMsgId newMsgId = TFSMailMsgId();
   656         iLog->Log(_L("Message is to be sent..."));
   679         iLog->Log(_L("Message is to be sent..."));
   657         err = SendMsgL(*newMsg, subject, newMsgId); //sending message..
   680         err = SendMsgL(*newMsg, subject, newMsgId); //sending message..
   658 
   681 
   659         if (KErrNone == err)
   682         if (KErrNone == err)
       
   683 		  {
   660             iLog->Log(_L("Message was sent successfully"));
   684             iLog->Log(_L("Message was sent successfully"));
       
   685 		  }
   661         else
   686         else
       
   687 		  {
   662             iLog->Log(_L("Failed to send message with error (ID:%d)"), err);
   688             iLog->Log(_L("Failed to send message with error (ID:%d)"), err);
   663 
   689 		  }
   664         CleanupStack::PopAndDestroy(newMsg);
   690         CleanupStack::PopAndDestroy(newMsg);
   665         }
   691         }
   666     else
   692     else
   667         {
   693         {
   668         iLog->Log(_L("Error: Tested message was NOT created"));
   694         iLog->Log(_L("Error: Tested message was NOT created"));
   718     newMsg->SaveMessageL();
   744     newMsg->SaveMessageL();
   719 
   745 
   720     // II. Send test message
   746     // II. Send test message
   721     TFSMailMsgId newMsgId = TFSMailMsgId();
   747     TFSMailMsgId newMsgId = TFSMailMsgId();
   722     err = SendMsgL(*newMsg, KStifEmailSubject, newMsgId);
   748     err = SendMsgL(*newMsg, KStifEmailSubject, newMsgId);
       
   749 	iLog->Log(_L("'SendMsgL' returns value of err=%d"),err);
   723     CleanupStack::PopAndDestroy(newMsg);
   750     CleanupStack::PopAndDestroy(newMsg);
   724     newMsg = NULL;
   751     newMsg = NULL;
   725     TFSMailMsgId msgFolderId = iIPSMailbox->GetStandardFolderId(EFSInbox);
   752     TFSMailMsgId msgFolderId = iIPSMailbox->GetStandardFolderId(EFSInbox);
   726     CFSMailFolder* pFolder = NULL;
   753     CFSMailFolder* pFolder = NULL;
   727     // get message folder
   754     // get message folder
   782 
   809 
   783             // check To recipients
   810             // check To recipients
   784             RPointerArray<CFSMailAddress>& toRecipients =
   811             RPointerArray<CFSMailAddress>& toRecipients =
   785                     newMsg->GetToRecipients();
   812                     newMsg->GetToRecipients();
   786             TInt toRec = toRecipients.Count();
   813             TInt toRec = toRecipients.Count();
   787             if (toRec != 2)
   814             if (toRec != KNumOfRec)
   788                 {
   815                 {
   789                 iLog->Log(_L("   Error: Got %d 'To' recipients, expected 2"),
   816                 iLog->Log(_L("   Error: Got %d 'To' recipients, expected 2"),
   790                         toRec);
   817                         toRec);
   791                 err = KErrGeneral;
   818                 err = KErrGeneral;
   792                 }
   819                 }
   809             toRecipients.ResetAndDestroy();
   836             toRecipients.ResetAndDestroy();
   810             // check Cc recipients
   837             // check Cc recipients
   811             RPointerArray<CFSMailAddress>& ccRecipients =
   838             RPointerArray<CFSMailAddress>& ccRecipients =
   812                     newMsg->GetCCRecipients();
   839                     newMsg->GetCCRecipients();
   813             TInt ccRec = ccRecipients.Count();
   840             TInt ccRec = ccRecipients.Count();
   814             if (ccRec != 2)
   841             if (ccRec != KNumOfRec)
   815                 {
   842                 {
   816                 iLog->Log(_L("   Error: Got %d 'Cc' recipients, expected 2"),
   843                 iLog->Log(_L("   Error: Got %d 'Cc' recipients, expected 2"),
   817                         ccRec);
   844                         ccRec);
   818                 err = KErrGeneral;
   845                 err = KErrGeneral;
   819                 }
   846                 }
   931          */
   958          */
   932         //Moving tested messages from 'Inbox' to 'Sent Items'
   959         //Moving tested messages from 'Inbox' to 'Sent Items'
   933         if (gotMsgs > 0)
   960         if (gotMsgs > 0)
   934             {
   961             {
   935             iLog->Log(_L("  Listing %d messages:"), gotMsgs);
   962             iLog->Log(_L("  Listing %d messages:"), gotMsgs);
   936             for (TInt i = 0; i < messages.Count(); i++)
   963 			TInt messagesCount = messages.Count();
       
   964             for (TInt i = 0; i < messagesCount; i++)
   937                 {
   965                 {
   938                 iLog->Log(_L("%d.ID:,Subject: %S"), i + 1,
   966                 iLog->Log(_L("%d.ID:,Subject: %S"), i + 1,
   939                         &messages[i]->GetSubject());
   967                         &messages[i]->GetSubject());
   940                 originalArray.Append(messages[i]->GetMessageId());
   968                 originalArray.Append(messages[i]->GetMessageId());
   941                 }//end loop: 'for'
   969                 }//end loop: 'for'
   990 
  1018 
   991     TInt err(KErrNone);
  1019     TInt err(KErrNone);
   992     iLog->Log(_L( "Search begins" ));
  1020     iLog->Log(_L( "Search begins" ));
   993 
  1021 
   994     // Step01: to prepare testing msg
  1022     // Step01: to prepare testing msg
   995     HBufC* bufSubject = HBufC::NewL(30);
  1023     HBufC* bufSubject = HBufC::NewL(KMidBufLen);
   996     HBufC* bufBody = HBufC::NewL(128);
  1024     HBufC* bufBody = HBufC::NewL(KMidBufLen);
   997     TPtr subject = bufSubject->Des();
  1025     TPtr subject = bufSubject->Des();
   998     TPtr body = bufBody->Des();
  1026     TPtr body = bufBody->Des();
   999     subject.Append(KStifEmailSubjectDes);
  1027     subject.Append(KStifEmailSubjectDes);
  1000     body.Append(KStifEmailBodyText);
  1028     body.Append(KStifEmailBodyText);
  1001 
  1029