common/tools/ats/smoketest/email/email/smtp/src/T_CreateSmtpAccount.cpp
changeset 719 d5603c08781b
child 872 17498133d9ad
equal deleted inserted replaced
718:b18be44be852 719:d5603c08781b
       
     1 // Copyright (c) 2007-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 the License "Symbian Foundation License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // [TestStep Name]
       
    15 // CreateSmtpAccount
       
    16 // [Paramaters]
       
    17 // SmtpAccountName			:Name of the Smtp account.
       
    18 // SmtpConfigFileName		:Config file from which the Smtp account settings are read.
       
    19 // Creates a SMTP account in the Central Repository with the specified name using the 
       
    20 // settings read from the config file.
       
    21 // 
       
    22 //
       
    23 
       
    24 //User includes
       
    25 #include "T_CreateSmtpAccount.h"
       
    26 #include <t_utilsreademailsettingsfromconfigfile.h>
       
    27 
       
    28 //Epoc inlcudes
       
    29 #include <cemailaccounts.h>
       
    30 #include <iapprefs.h>
       
    31 #include <smtpset.h>
       
    32 
       
    33 //Literals used
       
    34 _LIT(KSmtpAccountName,"SmtpAccountName");
       
    35 _LIT(KSmtpConfigFileName,"SmtpConfigFileName");
       
    36 
       
    37 /**
       
    38   Function : CT_MsgCreateSmtpAccount
       
    39   Description : Constructor
       
    40   @param : aSharedDataSMTP Reference to CT_MsgSharedDataSmtp
       
    41   @return : N/A
       
    42 */
       
    43 CT_MsgCreateSmtpAccount::CT_MsgCreateSmtpAccount(CT_MsgSharedDataSmtp& aSharedDataSMTP)
       
    44 :CT_MsgSyncStepSMTP(aSharedDataSMTP)
       
    45 	{
       
    46 	SetTestStepName(KCreateSmtpAccount);
       
    47 	}
       
    48 
       
    49 /**
       
    50   Function : ReadIni
       
    51   Description :Reads the corresponding .ini file and returns EPass or EFail if any of the inputs are missing
       
    52   @return : TBool
       
    53 */
       
    54 TBool CT_MsgCreateSmtpAccount::ReadIni()
       
    55 	{
       
    56 	TBool result = ETrue;
       
    57 	
       
    58 	if(!GetStringFromConfig(ConfigSection(), KSmtpAccountName, iSmtpAccountName))
       
    59 		{
       
    60 		ERR_PRINTF1(_L("Smtp account name is not specified"));
       
    61 		SetTestStepResult(EFail);
       
    62 		result = EFalse;
       
    63 		}
       
    64 		
       
    65 	if(!GetStringFromConfig(ConfigSection(), KSmtpConfigFileName, iConfigFileName))
       
    66 		{
       
    67 		ERR_PRINTF1(_L("Configuration file path is not specified"));
       
    68 		SetTestStepResult(EFail);
       
    69 		}
       
    70 		
       
    71 	return result;
       
    72 	}
       
    73 
       
    74 /**
       
    75   Function : doTestStepL
       
    76   Description : Reads the Smtp account name and the settings file name from the .ini file
       
    77 				and then creates an Smtp account.
       
    78   @return : TVerdict - Test step result
       
    79 */
       
    80 TVerdict CT_MsgCreateSmtpAccount::doTestStepL()
       
    81 	{
       
    82 	
       
    83 	INFO_PRINTF1(_L("Test Step : CreateSmtpAccount"));
       
    84 	if(ReadIni())
       
    85 		{
       
    86 		CEmailAccounts*	emailAccounts = CEmailAccounts::NewLC();
       
    87 		
       
    88 		// Creates objects requried for SMTP account
       
    89 		CImIAPPreferences *smtpIapPreferences = CImIAPPreferences::NewLC();
       
    90 		CImSmtpSettings *smtpSettings = new (ELeave) CImSmtpSettings;
       
    91 		CleanupStack::PushL(smtpSettings);
       
    92 
       
    93 		// Populates the default SMTP settings
       
    94 		emailAccounts->PopulateDefaultSmtpSettingsL(*smtpSettings, *smtpIapPreferences);
       
    95 
       
    96 		//If the config file name is provided as input, then reads the SMTP settings from it
       
    97 		if(iConfigFileName.CompareF( _L("none") ) != 0)
       
    98 			{
       
    99 			TRAPD(err, CT_MsgUtilsReadEmailSettingsFromConfigFile::ReadSmtpSettingsFromConfigurationFileL(iConfigFileName, *smtpSettings, *smtpIapPreferences));
       
   100 			if(err)
       
   101 				{
       
   102 				ERR_PRINTF2(_L("Failure while setting the SMTP settings, failed with error %d"), err);
       
   103 				SetTestStepError(err);
       
   104 				CleanupStack::PopAndDestroy(3,emailAccounts); // smtpSettings, smtpIapPreferences, emailAccounts
       
   105 				return TestStepResult();														  
       
   106 				}
       
   107 			if(TestStepResult() == EPass)
       
   108 				{
       
   109 				// Creates the SMTP account for the name specified and for the settings objects
       
   110 				TSmtpAccount smtpAccount = emailAccounts->CreateSmtpAccountL(iSmtpAccountName, *smtpSettings,*smtpIapPreferences,EFalse);
       
   111 				
       
   112 				// Sets the SMTP account created as the default SMTP account
       
   113 				emailAccounts->SetDefaultSmtpAccountL(smtpAccount);
       
   114 				}
       
   115 			}
       
   116 		CleanupStack::PopAndDestroy(3,emailAccounts); // smtpSettings, smtpIapPreferences, emailAccounts
       
   117 		}
       
   118 	return TestStepResult();
       
   119 	}