email/pop3andsmtpmtm/imapservermtm/test/src/T_DUMP.cpp
changeset 25 84d9eb65b26f
equal deleted inserted replaced
23:238255e8b033 25:84d9eb65b26f
       
     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 // Testing Recieving of messages
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <e32test.h>
       
    19 #include <f32fsys.h>
       
    20 #include <s32file.h>
       
    21 #include <e32base.h>
       
    22 #include <txtetext.h>
       
    23 #include <txtrich.h>
       
    24 #include <bautils.h>
       
    25 #include <miuthdr.h>
       
    26 #include <miutmsg.h>
       
    27 #include <miutset.h>  //KUidMsgTypePOP3
       
    28 #include <imutdll.h>	
       
    29 #include <imcvtext.h>
       
    30 #include <imcvrecv.h>
       
    31 #include <imcvsend.h>
       
    32 
       
    33 #include <imapset.h>
       
    34 
       
    35 //Oyster includes
       
    36 #include <msvstd.h>
       
    37 #include <msvids.h>
       
    38 #include <msvuids.h>
       
    39 #include <msvruids.h>
       
    40 #include <msvreg.h>
       
    41 
       
    42 #include "msvindexadapter.h"
       
    43 
       
    44 #include "msvserv.h"
       
    45 #include <msventry.h> 
       
    46 #include <msvapi.h>
       
    47 #include <mtclbase.h>
       
    48 #include <offop.h>
       
    49 
       
    50 #include "t_log.h"
       
    51 
       
    52 //----------------------------------------------------------------------------------------
       
    53 
       
    54 _LIT(KFilePathMailTest, "c:\\mailtest\\");
       
    55 
       
    56 //----------------------------------------------------------------------------------------
       
    57 
       
    58 LOCAL_D RTest test(_L("T_DUMP test harness"));
       
    59 
       
    60 LOCAL_D CTrapCleanup* theCleanup;
       
    61 LOCAL_D RFs theFs;	
       
    62 LOCAL_C CActiveScheduler* theScheduler;
       
    63 
       
    64 class CTestTimer;
       
    65 LOCAL_D	CTestTimer* timer;
       
    66 
       
    67 class CDummyMsvSessionObserver;
       
    68 
       
    69 LOCAL_C CMsvServer* theServer;
       
    70 
       
    71 //----------------------------------------------------------------------------------------
       
    72 
       
    73 class CDummyMsvSessionObserver : public CBase, public MMsvSessionObserver
       
    74 	{
       
    75 public:
       
    76 	void HandleSessionEvent(TMsvSessionEvent /*aEvent*/, TAny* /*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/)
       
    77 		{};
       
    78 	};
       
    79 class CTestTimer : public CTimer
       
    80 	{
       
    81 public:
       
    82 	static CTestTimer* NewL();
       
    83 private:
       
    84 	CTestTimer();
       
    85 	void RunL();	
       
    86 	};
       
    87 
       
    88 CTestTimer::CTestTimer() : CTimer(EPriorityLow) {}
       
    89 
       
    90 void CTestTimer::RunL()
       
    91 	{
       
    92 	CActiveScheduler::Stop();
       
    93 	}
       
    94 
       
    95 CTestTimer* CTestTimer::NewL()
       
    96 	{
       
    97 	CTestTimer* self = new(ELeave) CTestTimer();
       
    98 	CleanupStack::PushL(self);
       
    99 	self->ConstructL(); // CTimer
       
   100 	CActiveScheduler::Add(self);
       
   101 	CleanupStack::Pop();
       
   102 	return self;
       
   103 	}
       
   104 
       
   105 class CTestActive : public CActive
       
   106 	{
       
   107 public:
       
   108 	CTestActive();
       
   109 	void ConstructL();
       
   110 //	void ChangeEntryL(TMsvId aId);
       
   111 	~CTestActive();
       
   112 private:
       
   113 	void RunL();
       
   114 	void DoCancel();
       
   115 private:
       
   116 //	CImCalculateMsgSize* iMsgSize;
       
   117 	};
       
   118 
       
   119 LOCAL_C CTestActive* active;
       
   120 
       
   121 //ctestactive
       
   122 CTestActive::CTestActive()
       
   123 : CActive(EPriorityStandard)
       
   124 	
       
   125 	{
       
   126 	__DECLARE_NAME(_S("CTestActive"));
       
   127 	}
       
   128 
       
   129 CTestActive::~CTestActive()
       
   130 	{
       
   131 	Cancel();
       
   132 //	delete iMsgSize;
       
   133 	}
       
   134 
       
   135 void CTestActive::ConstructL()
       
   136 	{
       
   137 	CActiveScheduler::Add(this);	
       
   138 //	iMsgSize = CImCalculateMsgSize::NewL(theFs, *sEntry);
       
   139 	}
       
   140 
       
   141 #if 0
       
   142 void CTestActive::ChangeEntryL(TMsvId /*aId*/)
       
   143 	{
       
   144 //	TTime time;
       
   145 //	iMsgSize->StartL(iStatus, aId, ENoAlgorithm, time, domainName);
       
   146 	SetActive();
       
   147 	}
       
   148 #endif
       
   149 
       
   150 void CTestActive::RunL()
       
   151 	{
       
   152 //	TInt32 size=iMsgSize->MessageSize();
       
   153 //	test.Printf(TRefByValue<const TDesC>_L("message size is %d\n\n"), size);
       
   154 	CActiveScheduler::Stop();
       
   155 	}
       
   156 
       
   157 void CTestActive::DoCancel()
       
   158 	{
       
   159 //	iMsgSize->Cancel();
       
   160 	}
       
   161 
       
   162 //----------------------------------------------------------------------------------------
       
   163 LOCAL_C void CreateAllTestDirectories()
       
   164 //----------------------------------------------------------------------------------------	
       
   165 	{
       
   166 	// create c:\mailtest, c:\mailtest\imcv c:\mailtest\attach\ directories used by this test harness
       
   167 	RFs s;
       
   168 	TFileName buffer;
       
   169 	if(!s.Connect())
       
   170 		{
       
   171 		TBool stop=EFalse;
       
   172 		s.SetSessionPath(_L("c:\\"));
       
   173 		if(!s.MkDir(KFilePathMailTest))
       
   174 			{
       
   175 			buffer=KFilePathMailTest;
       
   176 			test.Printf(TRefByValue<const TDesC>_L("Created %S directory\n"),&buffer);
       
   177 			stop=ETrue;
       
   178 			}
       
   179 #if 0
       
   180 		if(!s.MkDirAll(KTestMessageDir))
       
   181 			{
       
   182 			buffer=KTestMessageDir;
       
   183 			test.Printf(TRefByValue<const TDesC>_L("Created %S directory\n"),&buffer);
       
   184 			stop=ETrue;
       
   185 			}
       
   186 		if(!s.MkDirAll(KLogsDir))
       
   187 			{
       
   188 			buffer=KLogsDir;
       
   189 			test.Printf(TRefByValue<const TDesC>_L("Created %S directory\n"),&buffer);
       
   190 			stop=ETrue;
       
   191 			}
       
   192 #endif
       
   193 		if(stop)
       
   194 			{
       
   195 			test.Printf(_L("[Press any key to continue...]\n\n"));
       
   196 			test.Getch();
       
   197 			}
       
   198 		s.Close();
       
   199 		}
       
   200 	}
       
   201 
       
   202 //----------------------------------------------------------------------------------------
       
   203 LOCAL_C void Up()
       
   204 //----------------------------------------------------------------------------------------
       
   205 	{
       
   206 	theScheduler = new (ELeave)CActiveScheduler;
       
   207 	CActiveScheduler::Install( theScheduler );
       
   208 	CleanupStack::PushL(theScheduler);
       
   209 
       
   210 	User::LeaveIfError(theFs.Connect());
       
   211 	theFs.SetSessionPath(_L("C:\\"));
       
   212 
       
   213 #if 0
       
   214 	theFs.SetSessionPath( KFilePathMailTest );
       
   215 
       
   216 	// Delete out the logs
       
   217 	CFileMan* fileMan=CFileMan::NewL(theFs);
       
   218 	fileMan->Delete(KLogsDir, CFileMan::ERecurse);
       
   219 	delete fileMan;
       
   220 #endif
       
   221 	
       
   222 	// create a CMsvServer
       
   223 	timer = CTestTimer::NewL();
       
   224 	theServer = CMsvServer::NewL();
       
   225 	CleanupStack::PushL(theServer);
       
   226 
       
   227 	timer->After(100000);
       
   228 	CActiveScheduler::Start();
       
   229 	delete timer;
       
   230 
       
   231 	active = new (ELeave) CTestActive();
       
   232 	CleanupStack::PushL(active);
       
   233 	active->ConstructL();	
       
   234 	}
       
   235 
       
   236 //----------------------------------------------------------------------------------------
       
   237 LOCAL_C void Down()
       
   238 //----------------------------------------------------------------------------------------
       
   239 	{
       
   240 	test.Printf(_L("---------------------\n"));
       
   241 	test.Printf(_L("      Going down     \n"));
       
   242 	test.Printf(_L("---------------------\n"));
       
   243 	CleanupStack::PopAndDestroy(3);  //active, msvserver, theScheduler
       
   244 	theFs.Close();
       
   245 	}
       
   246 
       
   247 //----------------------------------------------------------------------------------------
       
   248 LOCAL_C void doMainL()
       
   249 //----------------------------------------------------------------------------------------
       
   250 	{
       
   251 	CreateAllTestDirectories();
       
   252 	Up();
       
   253 
       
   254 	test.Console()->ClearScreen();
       
   255 	test.Console()->SetPos(0, 0);
       
   256 	test.Printf(_L("---------------------\n"));
       
   257 	test.Printf(_L("    Message dumper   \n"));
       
   258 	test.Printf(_L("---------------------\n"));
       
   259 		
       
   260 	__UHEAP_MARK;
       
   261 	COutputter* putter = COutputter::NewL( &test );
       
   262 	CleanupStack::PushL(putter);
       
   263 
       
   264 	putter->SetRFs( &theFs );
       
   265 	theFs.SetSessionPath( KFilePathMailTest );
       
   266 
       
   267 	CMsvServerEntry* entry = CMsvServerEntry::NewL( *theServer, KMsvNullIndexEntryId );
       
   268 	CleanupStack::PushL(entry);
       
   269 
       
   270 	// enable invisible entries
       
   271 	TMsvSelectionOrdering sort = entry->Sort();
       
   272 	sort.SetShowInvisibleEntries(ETrue);
       
   273 	entry->SetSort(sort);
       
   274 	
       
   275 	CMsgOutputter* dumper = CMsgOutputter::NewL( putter, entry );
       
   276 	CleanupStack::PushL(dumper);
       
   277 
       
   278 	dumper->DumpL( KMsvRootIndexEntryId, CMsgOutputter::EToOneFile,
       
   279 				   CMsgOutputter::EToOneFile, ETrue, ETrue);
       
   280 
       
   281 	CleanupStack::PopAndDestroy(3); // dumper, putter, entry
       
   282 	__UHEAP_MARKEND;
       
   283 
       
   284 	Down();
       
   285 	}
       
   286 
       
   287 //----------------------------------------------------------------------------------------
       
   288 GLDEF_C TInt E32Main()
       
   289 //----------------------------------------------------------------------------------------
       
   290 	{	
       
   291 	__UHEAP_MARK;
       
   292 	test.Start(_L("T_DUMP Test harness"));
       
   293 	theCleanup=CTrapCleanup::New();
       
   294 
       
   295 	TRAPD(ret,doMainL());
       
   296 
       
   297 	test(ret==KErrNone);
       
   298 	delete theCleanup;
       
   299 	test.End();
       
   300 	test.Close();
       
   301 	__UHEAP_MARKEND;
       
   302 	return(KErrNone);
       
   303 	}