messagingfw/msgtestfw/TestActions/Email/Imap4/src/CMtfTestActionCreateImap4Service.cpp
changeset 0 8e480a14352b
equal deleted inserted replaced
-1:000000000000 0:8e480a14352b
       
     1 // Copyright (c) 2003-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 // CreateImap4Service
       
    17 // [Action Parameters]
       
    18 // Session        <input>: Reference to the session.
       
    19 // (Priority)     <input>: Value of the entry priority. Default is medium priority.
       
    20 // (ReadOnlyFlag) <input>: Value of the read only flag. Default is false.
       
    21 // (VisibleFlag)  <input>: Value of the visible flag. Default is true.
       
    22 // (Description)  <input>: Name of the description.	Default is blank.
       
    23 // (Details)      <input>: Name of the details. Default is blank.
       
    24 // ServiceId     <output>: Value of the created service id.
       
    25 // [Action Description]
       
    26 // Creates an IMAP4 service.
       
    27 // [APIs Used]
       
    28 // TMsvEntry::iType
       
    29 // TMsvEntry::SetPriority	
       
    30 // TMsvEntry::iMtm	
       
    31 // TMsvEntry::SetReadOnly	
       
    32 // TMsvEntry::SetVisible	
       
    33 // TMsvEntry::iDescription
       
    34 // TMsvEntry::iDetails
       
    35 // TMsvEntry::iDate
       
    36 // TMsvEntry::Id
       
    37 // CMsvEntry::SetEntryL
       
    38 // CMsvEntry::CreateL
       
    39 // __ACTION_INFO_END__
       
    40 // 
       
    41 //
       
    42 
       
    43 /**
       
    44  @file
       
    45 */
       
    46 
       
    47 
       
    48 #include <msvapi.h>
       
    49 #include <miutset.h>
       
    50 
       
    51 #include <cemailaccounts.h>
       
    52 #include <iapprefs.h>
       
    53 
       
    54 #include "CMtfTestActionUtilsImapScripts.h"
       
    55 
       
    56 
       
    57 #include "CMtfTestActionCreateImap4Service.h"
       
    58 #include "CMtfTestCase.h"
       
    59 #include "CMtfTestActionParameters.h"
       
    60 
       
    61 
       
    62 
       
    63 CMtfTestAction* CMtfTestActionCreateImap4Service::NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters)
       
    64 	{
       
    65 	CMtfTestActionCreateImap4Service* self = new (ELeave) CMtfTestActionCreateImap4Service(aTestCase);
       
    66 	CleanupStack::PushL(self);
       
    67 	self->ConstructL(aActionParameters);
       
    68 	CleanupStack::Pop();
       
    69 	return self;
       
    70 	}
       
    71 	
       
    72 
       
    73 CMtfTestActionCreateImap4Service::CMtfTestActionCreateImap4Service(CMtfTestCase& aTestCase)
       
    74 	: CMtfSynchronousTestAction(aTestCase)
       
    75 	{
       
    76 	}
       
    77 
       
    78 
       
    79 CMtfTestActionCreateImap4Service::~CMtfTestActionCreateImap4Service()
       
    80 	{
       
    81 	delete iBlank;
       
    82 	}
       
    83 
       
    84 
       
    85 
       
    86 
       
    87 void CMtfTestActionCreateImap4Service::ExecuteActionL()
       
    88 	{
       
    89 	TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionCreateImap4Service);
       
    90 	// need to create an account in the central repository and make it the default account
       
    91 	HBufC* paramAccountName = ObtainParameterReferenceL<HBufC>( TestCase(),ActionParameters().Parameter(6) );
       
    92 	// settings file contains idle params
       
    93 	HBufC* settingsFile = ObtainParameterReferenceL<HBufC>( TestCase(),ActionParameters().Parameter(7) );
       
    94 
       
    95 	CEmailAccounts* emailAccounts = CEmailAccounts::NewLC();	
       
    96 	CImIAPPreferences* smtpPrefs = CImIAPPreferences::NewLC();
       
    97 	CImSmtpSettings* smtpSettings = new(ELeave) CImSmtpSettings();
       
    98 	CleanupStack::PushL(smtpSettings);
       
    99 	
       
   100 	CImIAPPreferences* imapPrefs = CImIAPPreferences::NewLC();
       
   101 	CImImap4Settings* imapSettings = new(ELeave) CImImap4Settings();
       
   102 	CleanupStack::PushL(imapSettings);
       
   103 
       
   104 	emailAccounts->PopulateDefaultImapSettingsL(*imapSettings, *imapPrefs);
       
   105 	emailAccounts->PopulateDefaultSmtpSettingsL(*smtpSettings, *smtpPrefs);
       
   106 		
       
   107 	if( settingsFile->Compare( _L("none") ) != 0 )
       
   108 		{
       
   109 		CMtfTestActionUtilsImapScripts::ReadImapSettingsFromConfigurationFileL(
       
   110 			TestCase(), settingsFile->Des(), *imapSettings, *imapPrefs, *smtpSettings, *smtpPrefs);
       
   111 		}
       
   112 	
       
   113 	// create the IMAP account and make it the default
       
   114 	TImapAccount imapAccount = emailAccounts->CreateImapAccountL(paramAccountName->Des(), *imapSettings, *imapPrefs, EFalse);
       
   115 	TSmtpAccount smtpAccount = emailAccounts->CreateSmtpAccountL(imapAccount, *smtpSettings, *smtpPrefs, EFalse);
       
   116 	emailAccounts->SetDefaultSmtpAccountL(smtpAccount);
       
   117 	
       
   118 	// need to obtain the service id and save it as a param to maintain compatability
       
   119 	TMsvId serviceId = imapAccount.iImapService;
       
   120 	CleanupStack::PopAndDestroy( 5, emailAccounts );
       
   121 	
       
   122 
       
   123 	StoreParameterL<TMsvId>(TestCase(),serviceId,ActionParameters().Parameter(8));
       
   124 	
       
   125 	TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionCreateImap4Service );
       
   126 	TestCase().ActionCompletedL(*this);
       
   127 	
       
   128 	}