messagingfw/msgtestfw/TestActions/Email/Imap4/src/CMtfTestActionLoadImapSettings.cpp
changeset 0 8e480a14352b
equal deleted inserted replaced
-1:000000000000 0:8e480a14352b
       
     1 // Copyright (c) 2004-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 // __ACTION_INFO_BEGIN__ 
       
    15 // [Action Name]
       
    16 // LoadImapSettings
       
    17 // [Action Parameters]
       
    18 // accountId			input		TIMAP4Account
       
    19 // ImapSettings			output		CImImap4Settings
       
    20 // ImapIAP				output		CImIAPPreferences	
       
    21 // SMTPSettings			output		CImSMTPSettings	
       
    22 // SmtpIAP				output		CImIAPPreferences	
       
    23 // [Action Description]
       
    24 // LoadImapSettings Test Action is intended to retrieve IMAP settings 
       
    25 // from CenRep for the specified account Id.
       
    26 // [APIs Used]	
       
    27 // CEmailAccounts::LoadImapSettingsL
       
    28 // CImImap4Settings::SetServerAddressL
       
    29 // CImImap4Settings::SetLoginNameL
       
    30 // CImImap4Settings::SetPasswordL
       
    31 // CImSmtpSettings::SetServerAddressL
       
    32 // CImSmtpSettings::SetEmailAddressL
       
    33 // CImIAPPreferences::Version
       
    34 // CImIAPPreferences::AddIAPL
       
    35 // __ACTION_INFO_END__
       
    36 // 
       
    37 //
       
    38 
       
    39 
       
    40 #include <cemailaccounts.h>
       
    41 
       
    42 #include <imapset.h>
       
    43 #include <smtpset.h>
       
    44 #include <iapprefs.h>
       
    45 
       
    46 #include "CMtfTestCase.h"
       
    47 #include "CMtfTestActionParameters.h"
       
    48 #include "CMtfTestActionLoadImapSettings.h"
       
    49 
       
    50 /**
       
    51   Function : NewL
       
    52   Description : 
       
    53   @internalTechnology
       
    54   @param : aTestCase - CMtfTestCase for the CMtfTestAction base class
       
    55   @param : aActionParams - CMtfTestActionParameters 
       
    56   @return : CMtfTestAction* - a base class pointer to the newly created CMtfTestActionLoadImapSettings object
       
    57   @pre none
       
    58   @post none
       
    59 */
       
    60 CMtfTestAction* CMtfTestActionLoadImapSettings::NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters)
       
    61 	{
       
    62 	CMtfTestActionLoadImapSettings* self = new (ELeave) CMtfTestActionLoadImapSettings(aTestCase);
       
    63 	CleanupStack::PushL(self);
       
    64 	self->ConstructL(aActionParameters);
       
    65 	CleanupStack::Pop(self);
       
    66 	return self;
       
    67 	}
       
    68 	
       
    69 /**
       
    70   Function : CMtfTestActionLoadImapSettings
       
    71   Description : Constructor
       
    72   @internalTechnology
       
    73   @param : aTestCase - CMtfTestCase for the CMtfTestAction base class
       
    74   @return : N/A
       
    75   @pre none
       
    76   @post none
       
    77 */
       
    78 CMtfTestActionLoadImapSettings::CMtfTestActionLoadImapSettings(CMtfTestCase& aTestCase) : CMtfSynchronousTestAction(aTestCase)
       
    79 	{
       
    80 	}
       
    81 
       
    82 /**
       
    83   Function : ~CMtfTestActionLoadImapSettings
       
    84   Description : Destructor
       
    85   @internalTechnology
       
    86   @param :
       
    87   @return : 
       
    88   @pre 
       
    89   @post 
       
    90 */
       
    91 CMtfTestActionLoadImapSettings::~CMtfTestActionLoadImapSettings()
       
    92 	{
       
    93 	}
       
    94 
       
    95 void CMtfTestActionLoadImapSettings::LoadAccountSettingsL(CEmailAccounts& aEmailAccount, const TImapAccount& aAccount, CImImap4Settings& aImapSettings, CImIAPPreferences& aImapIapSettings, CImSmtpSettings& aSmtpSettings, CImIAPPreferences& aSmtpIapSettings)
       
    96 	{
       
    97 	aEmailAccount.LoadImapSettingsL(aAccount, aImapSettings);
       
    98 	aEmailAccount.LoadImapIapSettingsL(aAccount, aImapIapSettings);
       
    99 	
       
   100 	TSmtpAccount smtpAccount;
       
   101 	aEmailAccount.GetSmtpAccountL(aAccount.iSmtpService, smtpAccount);
       
   102 	aEmailAccount.LoadSmtpSettingsL(smtpAccount, aSmtpSettings);
       
   103 	aEmailAccount.LoadSmtpIapSettingsL(smtpAccount, aSmtpIapSettings);
       
   104 	}
       
   105 
       
   106 /**
       
   107   Function : ExecuteActionL
       
   108   Description : Entry point for the this test action in the test framework
       
   109   @internalTechnology
       
   110   @param : none
       
   111   @return : void
       
   112   @pre none 
       
   113   @post none
       
   114 */
       
   115 void CMtfTestActionLoadImapSettings::ExecuteActionL()
       
   116 	{
       
   117 	TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionLoadImapSettings);
       
   118 	// load the previously stored account id
       
   119 	TImapAccount accountId = ObtainValueParameterL<TImapAccount>( TestCase(),ActionParameters().Parameter(0) );
       
   120 	TInt shouldFail = ObtainValueParameterL<TInt>( TestCase(),ActionParameters().Parameter(1) );
       
   121 
       
   122 	// create the objects neccessary for loading the settings
       
   123 	CEmailAccounts* emailAccounts = CEmailAccounts::NewLC();
       
   124 	CImImap4Settings* imapSet = new(ELeave) CImImap4Settings();
       
   125 	CleanupStack::PushL(imapSet);
       
   126 	CImIAPPreferences* imapIapPref = CImIAPPreferences::NewLC();
       
   127 	CImSmtpSettings* smtpSet = new(ELeave) CImSmtpSettings();
       
   128 	CleanupStack::PushL(smtpSet);
       
   129 	CImIAPPreferences* smtpIapPref = CImIAPPreferences::NewLC();
       
   130 
       
   131 	
       
   132 	// load the settings
       
   133 	// this will leave if an attempt is made to access non existent settings
       
   134 	TRAPD( error, LoadAccountSettingsL(*emailAccounts, accountId, *imapSet, *imapIapPref, *smtpSet, *smtpIapPref) );
       
   135 	
       
   136 	if( error != KErrNone )
       
   137 		{
       
   138 		
       
   139 		if( shouldFail == 1 && error == KErrNotFound )
       
   140 			{
       
   141 			TestCase().INFO_PRINTF1(_L("LoadIMAPSettingsL Failed as expected ") );			
       
   142 			}
       
   143 		else
       
   144 			{			
       
   145 			TestCase().ERR_PRINTF2(_L("LoadIMAPSettingsL Failed leave with code %d"), error );
       
   146 			TestCase().SetTestStepResult(EFail);		
       
   147 			}
       
   148 			
       
   149 		CleanupStack::PopAndDestroy( 5, emailAccounts );
       
   150 		}
       
   151 	else
       
   152 		{
       
   153 
       
   154 		// params loaded ok so we can store them	
       
   155 		StoreParameterL<CImIAPPreferences>(TestCase(), *smtpIapPref , ActionParameters().Parameter(5) );
       
   156 		CleanupStack::Pop(smtpIapPref);
       
   157 	
       
   158 		StoreParameterL<CImSmtpSettings>(TestCase(), *smtpSet , ActionParameters().Parameter(4) );
       
   159 		CleanupStack::Pop(smtpSet);
       
   160 
       
   161 		StoreParameterL<CImIAPPreferences>(TestCase(), *imapIapPref , ActionParameters().Parameter(3) );
       
   162 		CleanupStack::Pop(imapIapPref);
       
   163 	
       
   164 		StoreParameterL<CImImap4Settings>(TestCase(), *imapSet , ActionParameters().Parameter(2) );
       
   165 		CleanupStack::Pop(imapSet);
       
   166 		
       
   167 		CleanupStack::PopAndDestroy(emailAccounts);
       
   168 		
       
   169 		if( shouldFail == 1 )
       
   170 			{
       
   171 			// have managed to load settings ok when we should not have
       
   172 			TestCase().ERR_PRINTF1(_L("CMtfTestActionLoadImapSettings loaded settings ok when we should not have") );
       
   173 			TestCase().SetTestStepResult(EFail);					
       
   174 			}
       
   175 		
       
   176 		}	
       
   177 	
       
   178 	TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionLoadImapSettings);
       
   179 	TestCase().ActionCompletedL(*this);
       
   180 	}
       
   181 
       
   182