email/pop3andsmtpmtm/popservermtm/test/src/T_popsCancelProgress.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 // Copyright (c) 1998-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 // Name of test harness: T_PopsCancelProgress
       
    15 // Component: POPS
       
    16 // Brief description of test harness:
       
    17 // Tests that a cancelling a CImTextServerSession connect operation leaves the
       
    18 // object in a consistent state, allowing it's progress to be queried safely
       
    19 // after cancelling.
       
    20 // Detailed description of test harness:
       
    21 // See "INC040630 - AV20 Panic while disconnecting a service"
       
    22 // Output files produced by running test harness:
       
    23 // <DRIVE>:\msglogs\T_PopsCancelProgress.<PLATFORM>.<VARIANT>.LOG.txt
       
    24 // 
       
    25 //
       
    26 
       
    27 #include "emailtestutils.h"
       
    28 #include "scripttestutils.h"
       
    29 #include "miutlog.h"
       
    30 #include "miutmsg.h"
       
    31 #include <txtrich.h>
       
    32 #include <popsmtm.h>
       
    33 #include <cemailaccounts.h>
       
    34 
       
    35 //------------------------------------------------------------------------------
       
    36 
       
    37 class CPopsCancelProgressTest : public CBase
       
    38 	{
       
    39 public:
       
    40 	static CPopsCancelProgressTest* NewLC(CEmailTestUtils& aTestUtils);
       
    41 	void StartTestL();
       
    42 	void InitL();
       
    43 	void ResetL();
       
    44 	void SetUpPopServiceL();
       
    45 	void EndTestL();
       
    46 	void EndTestHarnessL();
       
    47 
       
    48 	~CPopsCancelProgressTest();
       
    49 
       
    50 private:
       
    51 	CPopsCancelProgressTest(CEmailTestUtils& aTestUtils);
       
    52 	void ConstructL();
       
    53 	void ResetMtmL();
       
    54 
       
    55 public:
       
    56 	CMsvEntrySelection* iSelection;
       
    57 	CEmailTestUtils&	iTestUtils;
       
    58 
       
    59 private:
       
    60 	TInt				iTestError;
       
    61 	TInt				iTestNumber;
       
    62 	TInt				iGlobalError;
       
    63 	TMsvId				iPop3Service;
       
    64 	};
       
    65 
       
    66 LOCAL_D CTrapCleanup* theCleanup;
       
    67 _LIT(KImcmTest, "T_PopsCancelProgress Test");
       
    68 RTest test(KImcmTest);
       
    69 
       
    70 //------------------------------------------------------------------------------
       
    71 
       
    72 LOCAL_C void doMainL()
       
    73 	{
       
    74 	CActiveScheduler* scheduler;
       
    75 	scheduler = new (ELeave) CActiveScheduler;
       
    76 	CleanupStack::PushL(scheduler);
       
    77 	CActiveScheduler::Install(scheduler);
       
    78 
       
    79 	CEmailTestUtils* testUtils = CEmailTestUtils::NewLC(test);
       
    80 	CPopsCancelProgressTest* popsTestHarness = CPopsCancelProgressTest::NewLC(*testUtils);
       
    81 
       
    82 	popsTestHarness->SetUpPopServiceL();
       
    83 	popsTestHarness->ResetL();
       
    84 	popsTestHarness->StartTestL();
       
    85 	popsTestHarness->EndTestL();
       
    86 	popsTestHarness->EndTestHarnessL();
       
    87 
       
    88 	CleanupStack::PopAndDestroy(3); // popsTestHarness, testUtils, scheduler
       
    89 	}
       
    90 
       
    91 //------------------------------------------------------------------------------
       
    92 
       
    93 GLDEF_C TInt E32Main()
       
    94 	{	
       
    95 	__UHEAP_MARK;
       
    96 	test.Start(_L("T_PopsCancelProgress Test"));
       
    97 
       
    98 	theCleanup = CTrapCleanup::New();
       
    99 
       
   100 	TRAPD(ret,doMainL());		
       
   101 
       
   102 	test(ret == KErrNone);
       
   103 	delete theCleanup;	
       
   104 	test.End();
       
   105 	test.Close();
       
   106 
       
   107 	__UHEAP_MARKEND;
       
   108 	User::Heap().Check();
       
   109 	return(KErrNone);
       
   110 	}
       
   111 
       
   112 //------------------------------------------------------------------------------
       
   113 
       
   114 CPopsCancelProgressTest* CPopsCancelProgressTest::NewLC(CEmailTestUtils& aTestUtils)
       
   115 	{
       
   116 	CPopsCancelProgressTest* self = new (ELeave) CPopsCancelProgressTest(aTestUtils);
       
   117 	CleanupStack::PushL(self);
       
   118 	self->ConstructL();
       
   119 	return self;
       
   120 	}
       
   121 
       
   122 //------------------------------------------------------------------------------
       
   123 
       
   124 void CPopsCancelProgressTest::ResetMtmL()
       
   125 	{
       
   126 	// Get server MTM.
       
   127 	iTestUtils.Reset();
       
   128 	iTestUtils.CleanMessageFolderL();
       
   129 	iTestUtils.GoServerSideL();
       
   130 	SetUpPopServiceL();
       
   131 	iTestUtils.InstantiatePopServerMtmL();
       
   132 	}
       
   133 
       
   134 //------------------------------------------------------------------------------
       
   135 
       
   136 void CPopsCancelProgressTest::ResetL()
       
   137 	{
       
   138 	ResetMtmL();
       
   139 	}
       
   140 
       
   141 //------------------------------------------------------------------------------
       
   142 
       
   143 void CPopsCancelProgressTest::EndTestL()
       
   144 	{
       
   145 	if ((iTestError != KErrNone) && (iGlobalError == KErrNone))
       
   146 		{
       
   147 		iGlobalError = iTestError;
       
   148 		}
       
   149 
       
   150 	iTestUtils.TestFinish(iTestNumber, iTestError);
       
   151 	}
       
   152 
       
   153 //------------------------------------------------------------------------------
       
   154 
       
   155 void CPopsCancelProgressTest::EndTestHarnessL()
       
   156 	{
       
   157 	if (iGlobalError == KErrNone)
       
   158 		{
       
   159 		iTestUtils.TestHarnessCompleted();
       
   160 		}
       
   161 	else
       
   162 		{
       
   163 		iTestUtils.TestHarnessFailed(iGlobalError);
       
   164 		}
       
   165 	}
       
   166 
       
   167 //------------------------------------------------------------------------------
       
   168 
       
   169 void CPopsCancelProgressTest::InitL()
       
   170 	{
       
   171 	iTestUtils.FileSession().SetSessionPath(_L("C:\\"));
       
   172 	iTestUtils.FileSession().Delete(_L("c:\\logs\\email\\imsk110.scr"));
       
   173 	iTestUtils.CleanMessageFolderL();
       
   174 	iTestUtils.GoServerSideL();
       
   175 	}
       
   176 
       
   177 //------------------------------------------------------------------------------
       
   178 
       
   179 void CPopsCancelProgressTest::ConstructL()
       
   180 	{
       
   181 	InitL();
       
   182 	iSelection = new (ELeave) CMsvEntrySelection;
       
   183 	}
       
   184 
       
   185 //------------------------------------------------------------------------------
       
   186 
       
   187 CPopsCancelProgressTest::~CPopsCancelProgressTest()
       
   188 	{
       
   189 	delete iSelection;
       
   190 	}
       
   191 
       
   192 //------------------------------------------------------------------------------
       
   193 
       
   194 CPopsCancelProgressTest::CPopsCancelProgressTest(CEmailTestUtils& aTestUtils) 
       
   195 :	iTestUtils(aTestUtils), 
       
   196 	iGlobalError(KErrNone)
       
   197 {}
       
   198 
       
   199 //------------------------------------------------------------------------------
       
   200 
       
   201 void CPopsCancelProgressTest::StartTestL()
       
   202 	{
       
   203 	TRequestStatus mtmStatus;
       
   204 	TBuf8<128> parameter;
       
   205 
       
   206 	iTestUtils.Printf(_L("Starting POP Server Mtm Cancel/Progress Test.\n"));
       
   207 	iTestUtils.Printf(_L("Putting the POP Server Mtm into the EPopConnecting state.\n"));
       
   208 	iTestUtils.iPopServerMtm->StartCommandL(
       
   209 		*iSelection, KPOP3MTMConnect, parameter, mtmStatus);
       
   210 	iTestUtils.Printf(_L("Cancelling the POP Server Mtm EPopConnecting operation.\n"));
       
   211 	iTestUtils.iPopServerMtm->Cancel();
       
   212 	iTestUtils.Printf(_L("Querying the POP Server Mtm progress...\n"));
       
   213 	iTestUtils.iPopServerMtm->Progress();
       
   214 	}
       
   215 
       
   216 //------------------------------------------------------------------------------
       
   217 
       
   218 void CPopsCancelProgressTest::SetUpPopServiceL()
       
   219 	{
       
   220 	iTestUtils.GoClientSideL();
       
   221 
       
   222 	// Create the POP3 service and set the settings for this test.
       
   223 	iPop3Service = iTestUtils.CreatePopServiceL();
       
   224 	iSelection->AppendL(iPop3Service);
       
   225 
       
   226 	CImPop3Settings* settings = new(ELeave) CImPop3Settings();
       
   227 	CleanupStack::PushL(settings);
       
   228 	settings->Reset();
       
   229 	_LIT(KPopServer, "pop3.demon.co.uk");
       
   230 	settings->SetServerAddressL(KPopServer);
       
   231 	settings->SetLoginNameL(iTestUtils.MachineName());
       
   232 	settings->SetPasswordL(iTestUtils.MachineName());
       
   233 	settings->SetPort(110);
       
   234 	settings->SetDisconnectedUserMode(ETrue);
       
   235 
       
   236 	CEmailAccounts* accounts = CEmailAccounts::NewLC();
       
   237 
       
   238 	TPopAccount id;
       
   239 	accounts->GetPopAccountL(iPop3Service, id);
       
   240 	accounts->SavePopSettingsL(id, *settings);
       
   241 
       
   242 	CleanupStack::PopAndDestroy(2, settings); // accounts/store, settings
       
   243 	iTestUtils.GoServerSideL();
       
   244 	}
       
   245 
       
   246 //------------------------------------------------------------------------------
       
   247