email/imap4mtm/imapservermtm/test/src/ctestimapservermtmbase.cpp
changeset 80 8b14b30db193
parent 0 72b543305e3a
equal deleted inserted replaced
79:2981cb3aa489 80:8b14b30db193
       
     1 // Copyright (c) 2008-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 //
       
    15 
       
    16 #include "cactivewaiter.h"
       
    17 #include "ctestimapservermtmbase.h"
       
    18 #include <iapprefs.h>
       
    19 #include <cemailaccounts.h>
       
    20 
       
    21 // For loading the serial comms device drivers 
       
    22 #if defined (__WINS__)
       
    23 	#define PDD_NAME		_L("ECDRV")
       
    24 	#define LDD_NAME		_L("ECOMM")
       
    25 #else
       
    26 	#define PDD_NAME		_L("EUART1")
       
    27 	#define LDD_NAME		_L("ECOMM")
       
    28 #endif
       
    29 
       
    30 _LIT( KLoopbackAddress, "127.0.0.1" );
       
    31 //_LIT( KLoopbackAddress, "10.22.64.6" );	// Used for online testing
       
    32 
       
    33 const TInt KImapPort = 143;
       
    34 
       
    35 //RTest test( _L( "IMPS.dll Unit Test" ) );
       
    36 
       
    37 CTestImapServerMtmBase::CTestImapServerMtmBase( ) :
       
    38 	iTestUtils( NULL ),
       
    39 	iImapServerMtm( NULL ),
       
    40 	iSpoofServer( NULL ),
       
    41 	iAccounts( NULL ),
       
    42 	iActiveWaiter( NULL ),
       
    43 	iSelection( NULL ),
       
    44 	iTest( _L( "IMPS.dll Unit Test" ) )
       
    45 	{
       
    46 	
       
    47 	}
       
    48 	
       
    49 CTestImapServerMtmBase::~CTestImapServerMtmBase( )
       
    50 	{
       
    51 	delete iAccounts;
       
    52 	delete iSpoofServer;
       
    53 	delete iImapSettings;
       
    54 	delete iTestUtils;
       
    55 	delete iActiveWaiter;
       
    56 	delete iSelection;
       
    57 	
       
    58 	}
       
    59 
       
    60 
       
    61 /**
       
    62 Set up environment
       
    63 */	
       
    64 void CTestImapServerMtmBase::SetupL( )
       
    65 	{
       
    66 	DoLoadDriversL( );
       
    67 	
       
    68 	// Load Server MTM (Can this be in the TEFUnit server?)	
       
    69 //	iTestUtils = CEmailTestUtils::NewL( test );
       
    70 	iTestUtils = CEmailTestUtils::NewL( iTest );
       
    71 	iTestUtils->FileSession( ).SetSessionPath( _L( "C:\\" ) );
       
    72 
       
    73 // TODO: How to clean the message folders or close the messaging server without a PANIC ????
       
    74 
       
    75 //	iTestUtils->CleanMessageFolderL( );
       
    76 	iTestUtils->ClearEmailAccountsL( );
       
    77 	
       
    78 	iTestUtils->CreateAllTestDirectories( );
       
    79 	iTestUtils->FileSession( ).SetSessionPath( _L( "C:\\" ) );
       
    80 	
       
    81 	iTestUtils->GoServerSideL( );
       
    82 	iTestUtils->InstantiateImapServerMtmL( );
       
    83 	iImapServerMtm = iTestUtils->iImapServerMtm;
       
    84 	
       
    85 	// Create an account
       
    86 	iTestUtils->GoClientSideL( );
       
    87 	iAccounts = CEmailAccounts::NewL( );	
       
    88 	DoCreateImapAccountL( );
       
    89 	
       
    90 	// Delete iAccounts to make sure that CMsvServer is closed and 
       
    91 	// we can go to the serverSide
       
    92 	delete iAccounts;
       
    93 	iAccounts = NULL;
       
    94 	
       
    95 	iTestUtils->GoServerSideL( );
       
    96 	
       
    97 	iEntry = iTestUtils->iServerEntry;
       
    98 
       
    99 	iServiceId = iImapAccount.iImapService;
       
   100 	iTestUtils->InstantiateImapServerMtmL( );
       
   101 	iImapServerMtm = iTestUtils->iImapServerMtm;
       
   102 
       
   103 	// Creata active waiter
       
   104 	iActiveWaiter = new ( ELeave ) CActiveWaiter( );
       
   105 
       
   106 	iEntry = iTestUtils->iServerEntry;		
       
   107 	
       
   108 	iImapSettings = CImapSettings::NewL(*iEntry);
       
   109 	iImapSettings->LoadSettingsL(iServiceId);
       
   110 	// and CMsvSelection
       
   111 	iSelection = new ( ELeave ) CMsvEntrySelection( );
       
   112 	}
       
   113 	
       
   114 /**
       
   115 Tear down environment
       
   116 */
       
   117 void CTestImapServerMtmBase::TearDownL( )
       
   118 	{
       
   119 	// tear Down
       
   120 	delete iAccounts;
       
   121 	iAccounts = NULL;
       
   122 	
       
   123 	delete iSpoofServer;
       
   124 	iSpoofServer = NULL;
       
   125 
       
   126 // TODO: cleanup
       
   127 //	iTestUtils->GoClientSideL( );
       
   128 //	iTestUtils->iMsvSession->CloseMessageServer( );
       
   129 //	iTestUtils->Reset( );
       
   130 	
       
   131 	_LIT(KMsvServerPattern, "!MsvServer*");
       
   132 	TFindProcess findprocess(KMsvServerPattern);
       
   133 	TFullName name;
       
   134 
       
   135 	// wait for the server to close before continuing
       
   136 //	for(;;)
       
   137 //		{   
       
   138 //		TFindServer find(KMsvServerPattern);
       
   139 //		if (find.Next(name) != KErrNone)
       
   140 //			break;
       
   141 //		User::After(100000);
       
   142 //	}
       
   143 
       
   144 	delete iTestUtils;
       
   145 	iTestUtils = NULL;	
       
   146 	
       
   147 	delete iActiveWaiter;
       
   148 	iActiveWaiter = NULL;
       
   149 
       
   150 	delete iSelection;
       
   151 	iSelection = NULL;
       
   152 	
       
   153 	}
       
   154 
       
   155 void CTestImapServerMtmBase::DoConnectL( )
       
   156 	{
       
   157 	INFO_PRINTF1( _L("Connecting...") );
       
   158 	iSelection->Reset( );
       
   159 	iSelection->AppendL( iImapAccount.iImapService );
       
   160 	
       
   161 	iImapServerMtm->StartCommandL( *iSelection, 
       
   162 					    		   KIMAP4MTMConnect, 
       
   163 								   KNullDesC8, 
       
   164 								   iActiveWaiter->iStatus );
       
   165 
       
   166 	iActiveWaiter->WaitActive( );
       
   167 
       
   168 	}
       
   169 
       
   170 void CTestImapServerMtmBase::DoDisconnectL( )
       
   171 	{
       
   172 	INFO_PRINTF1( _L("Disconnecting...") );
       
   173 	iSelection->Reset( );
       
   174 	iImapServerMtm->StartCommandL( *iSelection,
       
   175 								   KIMAP4MTMDisconnect,
       
   176 								   KNullDesC8,
       
   177 								   iActiveWaiter->iStatus );
       
   178 								   
       
   179 	iActiveWaiter->WaitActive( );
       
   180 	
       
   181 	}
       
   182 
       
   183 void CTestImapServerMtmBase::DoCreateImapAccountL( )
       
   184 	{
       
   185 	INFO_PRINTF1( _L("Create IMAP account") );
       
   186 	//create objects and initialise with the defaults
       
   187 	CImImap4Settings* imap4Settings = new ( ELeave ) CImImap4Settings;
       
   188 	CleanupStack::PushL( imap4Settings );
       
   189 	
       
   190 	CImSmtpSettings* smtpSettings = new ( ELeave ) CImSmtpSettings;
       
   191 	CleanupStack::PushL( smtpSettings );
       
   192 	
       
   193 	CImIAPPreferences* imapIap = CImIAPPreferences::NewLC( );
       
   194 	CImIAPPreferences* smtpIap = CImIAPPreferences::NewLC( );
       
   195 	
       
   196 	iAccounts->PopulateDefaultImapSettingsL( *imap4Settings, *imapIap );
       
   197 	iAccounts->PopulateDefaultSmtpSettingsL( *smtpSettings, *smtpIap );
       
   198 	
       
   199 	//override some of the defaults
       
   200 	imap4Settings->SetPasswordL( _L8( "prakash" ) );
       
   201 	imap4Settings->SetLoginNameL( _L8( "prakash" ) );
       
   202 	imap4Settings->SetServerAddressL( KLoopbackAddress );
       
   203 	imap4Settings->SetFolderPathL( _L8( "" ) );
       
   204 	imap4Settings->SetSynchronise( EUseLocal );
       
   205 		
       
   206 	//create the account
       
   207 	iImapAccount = iAccounts->CreateImapAccountL( _L( "TestAccount" ), *imap4Settings, *imapIap, EFalse );
       
   208 	//clean up
       
   209 	CleanupStack::PopAndDestroy( 4,imap4Settings );
       
   210 	
       
   211 	INFO_PRINTF1( _L("IMAP account created") );
       
   212 	}
       
   213 
       
   214 void CTestImapServerMtmBase::DoLoadDriversL( )
       
   215 	{
       
   216 	// Load the serial comms device drivers.  If this is not done,
       
   217 	// connecting via NT-RAS returns KErrNotFound (-1).
       
   218 	TInt driverErr;
       
   219 	driverErr=User::LoadPhysicalDevice(PDD_NAME);
       
   220 	if (driverErr!=KErrNone && driverErr!=KErrAlreadyExists)
       
   221 		User::Leave(driverErr);
       
   222 	driverErr=User::LoadLogicalDevice(LDD_NAME);
       
   223 	if (driverErr!=KErrNone && driverErr!=KErrAlreadyExists)
       
   224 		User::Leave(driverErr);
       
   225 	}
       
   226 	
       
   227 
       
   228 	
       
   229 void CTestImapServerMtmBase::DoStartSpoofServerL( const TDesC& aScriptSection )
       
   230 	{
       
   231 	// Start Spoof Server
       
   232 	INFO_PRINTF2( _L( "Loading spoofscript: " ), aScriptSection );
       
   233 	TPtrC spoofScript;
       
   234 	User::LeaveIfError( iConfig.GetString( aScriptSection, 
       
   235 								  		   _L( "ScriptFile" ), 
       
   236 								  		   spoofScript ) );
       
   237 	
       
   238 	INFO_PRINTF1( _L( "Starting spoofserver" ) );
       
   239 	iSpoofServer = CSpoofServer::NewL( *this, spoofScript );
       
   240 	iSpoofServer->StartL( KImapPort );
       
   241 	INFO_PRINTF1( _L( "Spoofserver started" ) );
       
   242 	
       
   243 	}
       
   244 	
       
   245 void CTestImapServerMtmBase::TestComplete( TInt /*aErrorCode*/ )
       
   246 	{
       
   247 	// TODO
       
   248 	}