/**
  Function : ExecuteActionL
  Description : Entry point for the this test action in the test framework
  @internalTechnology
  @param : none
  @return : void
  @pre none 
  @post none
*/
void CMtfTestActionGetPopAccountInArray::ExecuteActionL()
	{
	TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionGetPopAccountInArray);
	TInt indexNumber = ObtainValueParameterL<TInt>(TestCase(), ActionParameters().Parameter(0));
	CEmailAccounts* accounts = CEmailAccounts::NewLC();	
	RArray<TPopAccount> accountArray;
	CleanupClosePushL(accountArray);
	accounts->GetPopAccountsL(accountArray);

	// make sure we're not out of range
	if (indexNumber >= 0 && indexNumber < accountArray.Count())
		{
		TPopAccount id = accountArray[indexNumber];		
		StoreParameterL<TPopAccount>( TestCase(), id, ActionParameters().Parameter(1));
		}
	else
		{
		TestCase().ERR_PRINTF1(_L("Index is out of range!"));
		TestCase().SetTestStepResult(EFail);
		}
	
	CleanupStack::PopAndDestroy( 2, accounts );	
	TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionGetPopAccountInArray);
	
	TestCase().ActionCompletedL(*this);	
	}
/**
doTestStepL()
Reads the POP account name from the ini file. If ALL string is mentioned in the .ini file 
it deletes all the IMAP accounts, Else deletes the IMAP account whose name is 
mentioned in the ini file

@return
Returns the test step result
*/
TVerdict CT_MsgDeletePopAccount::doTestStepL()
	{
	INFO_PRINTF1(_L("Test Step: Delete Pop Account"));
	TPtrC popAccountName;
	// Read Pop Account Name from ini file
	if(!GetStringFromConfig(ConfigSection(), KPopAccountName, popAccountName))
		{
		ERR_PRINTF1(_L("Account name not specified"));
		SetTestStepResult(EFail);
		}
	else
		{	
		CEmailAccounts* account = CEmailAccounts::NewLC();
		
		RArray<TPopAccount> arrayPop3Accounts;
		CleanupClosePushL(arrayPop3Accounts);
		account->GetPopAccountsL(arrayPop3Accounts);
		TInt count=arrayPop3Accounts.Count();
		
		TBuf<12> temp(popAccountName);
		temp.UpperCase();	// Making case insensitive
		if(temp.CompareC(_L("ALL")) == 0)
			{
			INFO_PRINTF2(_L("Deleting all accounts. Total = %d"), count);
			for(TInt i=0; i<count; i++)
				{
				TPopAccount id = arrayPop3Accounts[i];
				account->DeletePopAccountL(id);
				}
			}			
		else 
			{
			TBool deleteFlag = EFalse;
			for(TInt i = 0; i < count; i++)
				{
				if(popAccountName.CompareC(arrayPop3Accounts[i].iPopAccountName) == 0)
					{
					account->DeletePopAccountL(arrayPop3Accounts[i]);
					// Just ensure that if we try to delete it again we hopefuly get an error
					// or can see that it has been deleted.
					arrayPop3Accounts.Remove(i);
					deleteFlag = ETrue;
					break;					
					}
				}
			if(deleteFlag)
				{
				INFO_PRINTF2(_L("Pop acount \" %S \" deleted"), &popAccountName);	
				}
			else
				{
				ERR_PRINTF2(_L("Pop acount \" %S \" not found"), &popAccountName);
				SetTestStepResult(EFail);
				User::Leave(KErrNotFound);
				}
			}
		CleanupStack::PopAndDestroy(2, account);	//arrayPop3Accounts,account
		}
	return TestStepResult();
	}
/**
doTestStepL()
Reads the expected count from the ini file.
Obtains the count of the POP accounts created and compares against the expected number.

@return
Returns the test step result.
*/
TVerdict CT_MsgVerifyPopAccountsCount::doTestStepL()
	{
	INFO_PRINTF1(_L("Test Step: Verify Pop Accounts Count"));
	TInt expectedCount = -1;
	if(!GetIntFromConfig(ConfigSection(), KExpectedCount, expectedCount) && expectedCount < 0)
		{
		ERR_PRINTF1(_L("ExpectedCount is not Specified or < 0"));
		SetTestStepResult(EFail);
		}
	else
		{
		CEmailAccounts *account = CEmailAccounts::NewLC();	
		RArray<TPopAccount> arrayPopAccounts;
		account->GetPopAccountsL(arrayPopAccounts);
		TInt count = arrayPopAccounts.Count();
		
		CleanupStack::PopAndDestroy(account);
		arrayPopAccounts.Reset();
		
		if (count != expectedCount)
			{
			ERR_PRINTF3(_L("Number of POP accounts do not match ! expected = %d actual = %d"), 
									  expectedCount, count);
			SetTestStepResult(EFail);
			}
		else
			{
			INFO_PRINTF2(_L("Number of POP accounts matched value = %d !"), expectedCount);	
			}			
		}
	return TestStepResult();
	}