email/pop3andsmtpmtm/imapservermtm/test/src/T_DEF059571_IMAP_MissingOffsetStep.cpp
changeset 25 84d9eb65b26f
equal deleted inserted replaced
23:238255e8b033 25:84d9eb65b26f
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // t_parse_def059571_missingoffsetstep.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <testexecutelog.h>
       
    19 #include "t_def059571_imap_missingoffsetstep.h"
       
    20 
       
    21 RTest test(_L("IMAP Missing Offset and HTML Test"));
       
    22 
       
    23 const TInt KSizeDateTimeBuffer = 45;
       
    24 const TInt KImapPort = 143;
       
    25  
       
    26 LOCAL_C void FormatDateTime(TDes& aBuffer, const TTime& aTime)
       
    27 	{ 
       
    28 	aBuffer.Zero();
       
    29 	_LIT(KFormat4,"%/0%1%/1%2%/2%3%/3 %-B%:0%J%:1%T%:2%S%:3%+B");
       
    30 	aTime.FormatL(aBuffer,KFormat4); 
       
    31 	}
       
    32 		
       
    33 CTestImapMissingOffsetStep::~CTestImapMissingOffsetStep()
       
    34 	{
       
    35 	delete iConsole;
       
    36 	delete iSpoofServer;	
       
    37 	delete iTestUtils;
       
    38 	delete iImapClient;	
       
    39 	delete iScheduler;
       
    40 	if(iSession!=NULL)
       
    41 		iSession->CloseMessageServer();
       
    42 	delete iSession;
       
    43 	delete iSessionObserver;
       
    44 	}
       
    45 
       
    46 CTestImapMissingOffsetStep::CTestImapMissingOffsetStep()
       
    47 	{
       
    48 	// Call base class method to set up the human readable name for logging
       
    49 	SetTestStepName(KTestImapMissingOffset);
       
    50 	}
       
    51 
       
    52 void CTestImapMissingOffsetStep::TestComplete(TInt aEventCode)
       
    53 	{
       
    54 	CActiveScheduler::Stop();	
       
    55 	
       
    56 	if(aEventCode!=KErrNone && aEventCode!=KErrEof)
       
    57 		{
       
    58 		ERR_PRINTF2(_L("Error: %d"),aEventCode);	
       
    59 		}
       
    60 	}
       
    61 
       
    62 void CTestImapMissingOffsetStep::PrintEntryTime(TTime* aTIme)
       
    63 	{
       
    64 	TBuf<KSizeDateTimeBuffer> dateTimeString;
       
    65 	FormatDateTime(dateTimeString,*aTIme); 
       
    66 	INFO_PRINTF2(_L("%S"),&dateTimeString);	
       
    67 	}
       
    68 		
       
    69 void CTestImapMissingOffsetStep::GetDetailsFromIniFileL()
       
    70 	{
       
    71 	// get the script file path
       
    72 	_LIT(KScriptFile,"ScriptFile");	
       
    73 	if(!GetStringFromConfig(ConfigSection(),KScriptFile,iScriptFile))
       
    74 		{
       
    75 		_LIT(KErrorScriptFile, "Error reading script file path from ini file");
       
    76 		ERR_PRINTF1(KErrorScriptFile);
       
    77 		User::Leave(KErrArgument);
       
    78 		}
       
    79 	// get the expected number of mails
       
    80 	_LIT(KExpectedCountString, "ExpectedEntryCount");
       
    81 	if(!GetIntFromConfig(ConfigSection(),KExpectedCountString,iExpectedEntryCount))
       
    82 		{
       
    83 		_LIT(KErrorExpectedCount, "Error reading expected entry count from ini file");
       
    84 		ERR_PRINTF1(KErrorExpectedCount);
       
    85 		User::Leave(KErrArgument);	
       
    86 		}
       
    87 	}
       
    88 
       
    89 TVerdict CTestImapMissingOffsetStep::doTestStepPreambleL()
       
    90 	{
       
    91 	SetTestStepResult(EPass);
       
    92 	iScheduler = new (ELeave) CActiveScheduler;
       
    93 	CActiveScheduler::Install(iScheduler);
       
    94 	
       
    95 	iTestUtils = CEmailTestUtils::NewL(test);
       
    96 	iTestUtils->FileSession().SetSessionPath(_L("C:\\"));
       
    97 	iTestUtils->CleanMessageFolderL();
       
    98 	iTestUtils->ClearEmailAccountsL();
       
    99 	
       
   100 	iTestUtils->GoClientSideL();
       
   101 	
       
   102 	// start the imap server
       
   103 	GetDetailsFromIniFileL();
       
   104 	iConsole=Console::NewL(_L("IMAP Missing Offset Test"),TSize(KConsFullScreen,KConsFullScreen));
       
   105 	iSpoofServer = CSpoofServer::NewL(*this,iScriptFile);
       
   106 	iSpoofServer->StartL(KImapPort);
       
   107 		
       
   108 	// start the imap client
       
   109 	iImapClient = CActiveImapClient::NewL(this);
       
   110 	iImapClient->StartL();
       
   111 	
       
   112 	CActiveScheduler::Start();
       
   113 	return TestStepResult();
       
   114 	}
       
   115 
       
   116 TInt CTestImapMissingOffsetStep::GetEntryCountL()
       
   117 	{
       
   118 	TImapAccount imapAccount=iImapClient->GetImapAccount();
       
   119 	
       
   120 	TMsvSelectionOrdering ordering;	
       
   121 
       
   122 	// open the imap service entry
       
   123 	CMsvEntry* imapService = CMsvEntry::NewL(*iSession,imapAccount.iImapService,ordering);
       
   124 	CleanupStack::PushL(imapService);
       
   125 	// get its children
       
   126 	CMsvEntrySelection* msvEntrySelection;
       
   127 	msvEntrySelection=imapService->ChildrenL();
       
   128 	// open its child inbox entry
       
   129 	CMsvEntry* inboxEntry = CMsvEntry::NewL(*iSession, (*msvEntrySelection)[0],ordering);
       
   130     CleanupStack::PushL(inboxEntry);
       
   131     
       
   132     // get the childeren of the inbox
       
   133     delete msvEntrySelection;
       
   134     msvEntrySelection=NULL;
       
   135     msvEntrySelection=inboxEntry->ChildrenL();
       
   136     // the count should be 1
       
   137     TInt count=msvEntrySelection->Count();
       
   138     
       
   139     delete msvEntrySelection;
       
   140     msvEntrySelection=NULL;	
       
   141 	CleanupStack::PopAndDestroy(2,imapService);
       
   142 	
       
   143 	return count;
       
   144 	}
       
   145 
       
   146 
       
   147 TVerdict CTestImapMissingOffsetStep::doTestStepL()
       
   148 	{
       
   149 	TVerdict result;
       
   150 	// Session observer. Needed to create a session
       
   151 	iSessionObserver = new (ELeave) TDummySessionObserver;
       
   152 	// Session. Needed to create a client registry.
       
   153 	iSession=CMsvSession::OpenSyncL(*iSessionObserver);
       
   154 	// get entry count
       
   155 	TInt entryCount=GetEntryCountL();
       
   156 	result = (entryCount==iExpectedEntryCount? EPass:EFail);
       
   157 	SetTestStepResult(result);
       
   158 	return TestStepResult();
       
   159 	}
       
   160 
       
   161 TVerdict CTestImapMissingOffsetStep::doTestStepPostambleL()
       
   162 	{
       
   163 	return TestStepResult();
       
   164 	}
       
   165 
       
   166