email/pop3andsmtpmtm/clientmtms/test/src/T_MIUT10A.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_MIUT10A
       
    15 // Component: IMCM
       
    16 // Owner: 
       
    17 // Brief description of test harness:
       
    18 // Cachemanager tests - Automatic test that proves that the cachemanager 
       
    19 // recursively prunes bodytext and attachment data.
       
    20 // This is identical to T_MIUT10, except that it starts the cachemanager
       
    21 // with a selection of message entries to prune instead of a service entry.
       
    22 // Written as part of the fix for DEF043085, propagated from Hurricane (DEF042552).
       
    23 // Detailed description of test harness:
       
    24 // As above.
       
    25 // Input files required to run test harness:
       
    26 // \MSG\IMCMTSRC\plain_text.txt				<DRIVE>:\msgtest\IMCM\rfc822\plain_text.txt
       
    27 // \MSG\IMCMTSRC\html_with_attachment.txt		<DRIVE>:\msgtest\IMCM\rfc822\html_with_attachment.txt
       
    28 // Intermediate files produced while running test harness:
       
    29 // <DRIVE>:\msglogs\T_MIUT10A\Entry_822Headers.txt
       
    30 // <DRIVE>:\msglogs\T_MIUT10A\Entry_MimeHeaders.txt
       
    31 // <DRIVE>:\msglogs\T_MIUT10A\Entry_RichTextBodies.txt
       
    32 // <DRIVE>:\msglogs\T_MIUT10A\Entry_Structure.txt
       
    33 // Output files produced by running test harness:
       
    34 // <DRIVE>:\msglogs\T_MIUT10A.<PLATFORM>.<VARIANT>.LOG.txt
       
    35 // Description of how to build test harness:
       
    36 // cd \msg\imcm\
       
    37 // bldmake bldfiles
       
    38 // abld test build
       
    39 // Description of how to run test harness:
       
    40 // The following instructions are the same for all platforms:
       
    41 // 1. Build T_DB test harness from COMMDB component:
       
    42 // cd \commdb\group
       
    43 // bldmake bldfiles
       
    44 // abld test build t_db
       
    45 // 2. Build the test utilities:
       
    46 // cd \msg\testutils\group\
       
    47 // bldmake bldfiles
       
    48 // abld build
       
    49 // WINS running instructions:
       
    50 // 1. \epoc32\release\wins\<VARIANT>\T_MIUT10A.exe can be used at the command prompt
       
    51 // or executable can be run from Windows Explorer.
       
    52 // All other platform running instructions:
       
    53 // 1. Copy \epoc32\release\<PLATFORM>\<VARIANT>\T_MIUT10A.exe onto the other platform
       
    54 // 2. Copy \epoc32\release\<PLATFORM>\<VARIANT>\MSVTESTUTILS.DLL into 
       
    55 // <DRIVE>:\system\libs on the other platform
       
    56 // 3. Copy \epoc32\release\<PLATFORM>\<VARIANT>\EMAILTESTUTILS.DLL into 
       
    57 // <DRIVE>:\system\libs on the other platform
       
    58 // 4. Run T_MIUT10A.exe on the other platform
       
    59 // 
       
    60 //
       
    61 
       
    62 #include "emailtestutils.h"
       
    63 #include <miutlog.h>
       
    64 #include <cacheman.h>
       
    65 
       
    66 // local variables etc //
       
    67 
       
    68 // Message file names
       
    69 _LIT(K_T_MIUT10_PLAIN_MSG, "c:\\mailtest\\rfc822\\plain_text.txt");
       
    70 _LIT(K_T_MIUT10_HTML_ATTACHMENT_MSG, "c:\\mailtest\\rfc822\\html_with_attachment.txt" );
       
    71 
       
    72 // Logging strings
       
    73 _LIT(K_T_MIUT10_TEST_INFO, "MIUT10A - Cache Management Tests");
       
    74 _LIT(K_T_MIUT10_TEXT_LEFT, "The text stream on entry was not removed.");
       
    75 _LIT(K_T_MIUT10_ATTACHMENT_LEFT, "The attachment on entry was not removed.");
       
    76 _LIT(K_T_MIUT10_FILTER_FAILED, "The filter didn't work.");
       
    77 _LIT(K_T_MIUT10_DESCRIPTION, "Testing pruning of a remote service containing plain test and MHTML mails.");
       
    78 _LIT(K_T_MIUT10_PROGRESS, "   Messages pruned %d/%d		\n");
       
    79 
       
    80 RTest test(K_T_MIUT10_TEST_INFO);
       
    81 
       
    82 #define DONT_PRUNE_ID 0x100002
       
    83 #define KErrBodyTextNotRemoved 5599
       
    84 #define KErrAttachmentNotRemoved 5600
       
    85 #define KErrFilterNotWorking 5601
       
    86 #define KPeriod 10000	// period of timer
       
    87 LOCAL_D TMsvId pop3Service;
       
    88 
       
    89 LOCAL_D CTrapCleanup* theCleanup;
       
    90 LOCAL_D CEmailTestUtils* testUtils;
       
    91 
       
    92 class CFilteredCacheManager : public CImCacheManager
       
    93 	{
       
    94 public:
       
    95 	CFilteredCacheManager(CMsvSession& aSession, TRequestStatus& aObserverRequestStatus);
       
    96 	static CFilteredCacheManager* NewL(CMsvSession& aSession, TRequestStatus& aObserverRequestStatus);
       
    97 
       
    98 private:
       
    99 	TBool Filter() const;
       
   100 	};
       
   101 
       
   102 CFilteredCacheManager::CFilteredCacheManager(CMsvSession& aSession, TRequestStatus& aObserverRequestStatus) : CImCacheManager(aSession, aObserverRequestStatus)
       
   103 	{
       
   104 	}
       
   105 
       
   106 CFilteredCacheManager* CFilteredCacheManager::NewL(CMsvSession& aSession, TRequestStatus& aObserverRequestStatus)
       
   107 	{
       
   108 	CFilteredCacheManager* self = new (ELeave) CFilteredCacheManager(aSession, aObserverRequestStatus);
       
   109 	CleanupStack::PushL(self);
       
   110 	self->ConstructL();
       
   111 	CleanupStack::Pop(); // self
       
   112 	return self;
       
   113 	}
       
   114 
       
   115 TBool CFilteredCacheManager::Filter() const
       
   116 	{
       
   117 	return (iCurrentEntry->Entry().Id() == DONT_PRUNE_ID) ? EFalse : ETrue;
       
   118 	}
       
   119 
       
   120 
       
   121 //
       
   122 
       
   123 
       
   124 class CImCacheManager;
       
   125 class TestUiTimer : public CTimer
       
   126 	{
       
   127 public:
       
   128 	static TestUiTimer* NewLC(CConsoleBase* aConsole, CImCacheManager* aCacheManager);
       
   129 	void RunL();
       
   130 	void DoCancel();
       
   131 	void ConstructL();
       
   132 	void IssueRequest();
       
   133 	
       
   134 	CConsoleBase*				iConsole;
       
   135 	CImCacheManager*			iCacheManager;
       
   136 	TTimeIntervalMicroSeconds32 period;
       
   137 protected:
       
   138 	TInt iCount;
       
   139 	TBool iClosing;
       
   140 	TestUiTimer(CConsoleBase* aConsole, CImCacheManager* aCacheManager);
       
   141 	};
       
   142 
       
   143 //
       
   144 // Progress timer
       
   145 //	  
       
   146 TestUiTimer* TestUiTimer::NewLC(CConsoleBase* aConsole, CImCacheManager* aCacheManager)
       
   147 	{
       
   148 	TestUiTimer* self = new(ELeave) TestUiTimer(aConsole, aCacheManager);
       
   149 	CleanupStack::PushL(self);
       
   150 	self->iCacheManager = aCacheManager;
       
   151 	self->ConstructL();
       
   152 	return self;
       
   153 	}
       
   154 
       
   155 TestUiTimer::TestUiTimer(CConsoleBase* aConsole, CImCacheManager* aCacheManager)
       
   156 	: CTimer(EPriorityStandard+3), iCacheManager(aCacheManager)
       
   157 	{
       
   158 //	counter =0;
       
   159 	iConsole = aConsole;
       
   160 	period = KPeriod;
       
   161 	iClosing = EFalse;
       
   162 	iCount = 0;
       
   163 	}
       
   164 
       
   165 void TestUiTimer::ConstructL()
       
   166 	{
       
   167 	CTimer::ConstructL();
       
   168 	CActiveScheduler::Add(this);
       
   169 	}
       
   170 
       
   171 void TestUiTimer::IssueRequest()
       
   172 	{
       
   173 	After(period);
       
   174 	}
       
   175 
       
   176 void TestUiTimer::DoCancel()
       
   177 	{
       
   178 	CTimer::DoCancel();
       
   179 	}
       
   180 
       
   181 void TestUiTimer::RunL()
       
   182 	{
       
   183 	// display the current progress
       
   184 	TImCacheManagerProgress temp;	
       
   185 	TPckgC<TImCacheManagerProgress> paramPack(temp);
       
   186 
       
   187 	const TDesC8& progBuf = iCacheManager->ProgressL();	
       
   188 	paramPack.Set(progBuf);
       
   189 	TImCacheManagerProgress progress=paramPack();	
       
   190 
       
   191 
       
   192 	test.Console()->SetPos(0, 10);
       
   193 
       
   194 	TBuf<128> strProgress;
       
   195 	strProgress.Format(K_T_MIUT10_PROGRESS, progress.iMessagesProcessed,
       
   196 				progress.iTotalMessages);
       
   197 	test.Printf(strProgress);
       
   198 	
       
   199 	testUtils->WriteComment(strProgress);
       
   200 
       
   201 	IssueRequest();
       
   202 	};
       
   203 
       
   204 //
       
   205 
       
   206 LOCAL_C void Init()
       
   207 	{
       
   208 	CActiveScheduler* scheduler = new (ELeave) CActiveScheduler;
       
   209 	CActiveScheduler::Install(scheduler);
       
   210 	CleanupStack::PushL(scheduler);
       
   211 
       
   212 	testUtils = CEmailTestUtils::NewLC(test);
       
   213 	testUtils->CreateAllTestDirectories();
       
   214 
       
   215 	testUtils->WriteComment(K_T_MIUT10_TEST_INFO);
       
   216 	
       
   217 	testUtils->FileSession().SetSessionPath(_L("C:\\"));
       
   218 	testUtils->CleanMessageFolderL();
       
   219 	testUtils->GoServerSideL();
       
   220 	}
       
   221 	
       
   222 LOCAL_C void Closedown()
       
   223 	{
       
   224 	CleanupStack::PopAndDestroy(2);  //testUtils, scheduler
       
   225 	}
       
   226 
       
   227 LOCAL_C void doMainL()
       
   228 	{
       
   229 	Init();
       
   230 	TInt globalError = KErrNone;
       
   231 	testUtils->FileSession().SetSessionPath(_L("c:\\"));
       
   232 
       
   233 	testUtils->CreateSmtpServiceL();
       
   234 	pop3Service = testUtils->CreatePopServiceL();
       
   235 
       
   236 	testUtils->CreateMessageL(K_T_MIUT10_PLAIN_MSG, pop3Service, pop3Service);
       
   237 	testUtils->CreateMessageL(K_T_MIUT10_PLAIN_MSG, pop3Service, pop3Service);
       
   238 	testUtils->CreateMessageL(K_T_MIUT10_HTML_ATTACHMENT_MSG, pop3Service, pop3Service);
       
   239 
       
   240 	test.Printf(_L("\nPerforming Cache Management Tests\n"));
       
   241 	
       
   242 	testUtils->GoClientSideL();
       
   243 
       
   244 	testUtils->iMsvEntry->SetEntryL(pop3Service);
       
   245 	TMsvEntry entry = testUtils->iMsvEntry->Entry();
       
   246 	entry.SetVisible(ETrue);
       
   247 	testUtils->iMsvEntry->ChangeL(entry);
       
   248 
       
   249 
       
   250 	// create a selection of message entries to pass to the cache manager
       
   251 	CMsvEntrySelection* mySelection = testUtils->iMsvEntry->ChildrenL();
       
   252 	CleanupStack::PushL(mySelection);
       
   253 	ASSERT(mySelection->Count() == 3);
       
   254 
       
   255 
       
   256 	TRequestStatus observerStatus;
       
   257 	CImCacheManager* cacheManager = CFilteredCacheManager::NewL(*testUtils->iMsvSession, observerStatus);
       
   258 	CleanupStack::PushL(cacheManager);
       
   259 	TestUiTimer* testUiTimer = TestUiTimer::NewLC(test.Console(), cacheManager);
       
   260 	CTestActive* testActive = new (ELeave) CTestActive();
       
   261 	CleanupStack::PushL(testActive);
       
   262 
       
   263 	testActive->StartL();
       
   264 	testUiTimer->IssueRequest();
       
   265 
       
   266 	testUtils->TestStart(0, K_T_MIUT10_DESCRIPTION);
       
   267 
       
   268 	cacheManager->StartL(*mySelection, testActive->iStatus);
       
   269 
       
   270 	CActiveScheduler::Start();
       
   271 
       
   272 	testUtils->FindChildrenL(KMsvRootIndexEntryId);
       
   273 	CMsvStore* store=NULL;
       
   274 	// added HasStore check for: DEF049479 CImCacheManager doesn't remove CMsvStores 
       
   275 	// Check that the items have been removed...
       
   276 	if (testUtils->iMsvEntry->HasStoreL())
       
   277 		{
       
   278 		testUtils->iMsvEntry->SetEntryL(0x100004);
       
   279 		CMsvStore* store = testUtils->iMsvEntry->ReadStoreL();
       
   280 		CleanupStack::PushL(store);
       
   281 
       
   282 		// Check that body text has been removed
       
   283 		if (store->HasBodyTextL())
       
   284 			{
       
   285 			// Body text hasn't been removed.
       
   286 			testUtils->WriteComment(K_T_MIUT10_TEXT_LEFT);
       
   287 			globalError = KErrBodyTextNotRemoved;
       
   288 			// User::Leave(KErrBodyTextNotRemoved);
       
   289 			}
       
   290 		CleanupStack::PopAndDestroy(store); 
       
   291 		store=NULL;
       
   292 		}
       
   293 	test.Printf(_L("\nBody Text Removed\n"));
       
   294 
       
   295 	if (testUtils->iMsvEntry->HasStoreL())
       
   296 		{
       
   297 		store = testUtils->iMsvEntry->ReadStoreL();
       
   298 		CleanupStack::PushL(store);
       
   299 	// Check that empty directory exists (try deleting it)
       
   300 		if (testUtils->FileSession().RmDir(_L("c:\\private\\mail\\1000484b\\mail\\00100001_S\\b\\")) != KErrNone)	
       
   301 			{
       
   302 			// Attachment data hasn't been removed.
       
   303 			testUtils->WriteComment(K_T_MIUT10_ATTACHMENT_LEFT);
       
   304 			globalError = KErrAttachmentNotRemoved;
       
   305 			}
       
   306 			CleanupStack::PopAndDestroy(store); 
       
   307 		}
       
   308 	test.Printf(_L("\nAttachment Removed\n"));
       
   309 	store=NULL;
       
   310 
       
   311 	if (testUtils->iMsvEntry->HasStoreL())
       
   312 		{
       
   313 		testUtils->iMsvEntry->SetEntryL(0x100003);
       
   314 		store=testUtils->iMsvEntry->ReadStoreL();
       
   315 		CleanupStack::PushL(store);
       
   316 		if (!(store->HasBodyTextL()))
       
   317 			{
       
   318 			// The filter hasn't worked
       
   319 			testUtils->WriteComment(K_T_MIUT10_FILTER_FAILED);
       
   320 			globalError = KErrFilterNotWorking;
       
   321 			}
       
   322 		CleanupStack::PopAndDestroy(store);
       
   323 		store=NULL;
       
   324 		}
       
   325 	testUtils->TestFinish(0, globalError);
       
   326 
       
   327 	if (globalError == KErrNone)
       
   328 		{
       
   329 		testUtils->TestHarnessCompleted();
       
   330 		}
       
   331 	else
       
   332 		{
       
   333 		testUtils->TestHarnessFailed(globalError);
       
   334 		}
       
   335 
       
   336 	CleanupStack::PopAndDestroy(4); // mySelection, testActive, testUiTimer, cacheManager
       
   337 
       
   338 	Closedown();
       
   339 	}
       
   340 
       
   341 GLDEF_C TInt E32Main()
       
   342 	{	
       
   343 	__UHEAP_MARK;
       
   344 	test.Start(_L("T_MIUT10A Test CImCacheManager class\n"));
       
   345 	theCleanup=CTrapCleanup::New();
       
   346 	TRAPD(ret,doMainL());		
       
   347 	test(ret==KErrNone);
       
   348 	delete theCleanup;	
       
   349 	test.End();
       
   350 	test.Close();
       
   351 	__UHEAP_MARKEND;
       
   352 	User::Heap().Check();
       
   353 	return(KErrNone);
       
   354 	}
       
   355