buildverification/smoketest/messaging/Src/TestMessCleanMessageFolder.cpp
changeset 15 5b5908ec640f
parent 13 3a35f7917fa6
child 17 03d9ade4748d
equal deleted inserted replaced
13:3a35f7917fa6 15:5b5908ec640f
     1 // Copyright (c) 2002-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 // This contains CTestMessCleanMessageFolder which cleans out all the
       
    15 // message folders
       
    16 // 
       
    17 //
       
    18 
       
    19 #include "TestMessCleanMessageFolder.h"
       
    20 
       
    21 // EPOC includes
       
    22 #include <msvids.h>
       
    23 #include <test/testexecuteclient.h>
       
    24 
       
    25 #ifdef __MESSAGING_API_V2__
       
    26 #include <cemailaccounts.h>
       
    27 #endif
       
    28 
       
    29 _LIT(KMessageCount, "messagecount");
       
    30 
       
    31 CTestMessCleanMessageFolder::CTestMessCleanMessageFolder()
       
    32 :	CTestMessBase(ETrue)
       
    33 ,	iNumberOfMessagesToDelete(-1)		//	Negative value implies delete all
       
    34 	{
       
    35 	SetTestStepName(_L("CleanMessageFolder"));
       
    36 	}
       
    37 
       
    38 TVerdict CTestMessCleanMessageFolder::doTestStepL()
       
    39 	{
       
    40 	INFO_PRINTF1(_L("Clean message folder"));
       
    41 
       
    42 	if ( GetIntFromConfig(ConfigSection(), KMessageCount, iNumberOfMessagesToDelete) )
       
    43 		{
       
    44 		INFO_PRINTF2(_L("Message count read from the ini file is  %D"), iNumberOfMessagesToDelete);
       
    45 		}
       
    46 	else
       
    47 		{
       
    48 		WARN_PRINTF1(_L("No Count specified in the ini file"));
       
    49 		WARN_PRINTF1(_L("All the messages will be deleted"));
       
    50 		}
       
    51 
       
    52 	if ( TestStepResult() == EPass )
       
    53 		{
       
    54 		//delete the contents of the folder
       
    55 		CleanFolders(EntryL().EntryId());
       
    56 
       
    57 		if ( iNumberOfMessagesToDelete<=0 )
       
    58 			{
       
    59 			INFO_PRINTF1(_L("Messages deleted"));
       
    60 			}
       
    61 		else
       
    62 			{
       
    63 			ERR_PRINTF2(_L("%d Outstanding entries not deleted."), iNumberOfMessagesToDelete);
       
    64 			SetTestStepResult(EFail);
       
    65 			}
       
    66 		}
       
    67 
       
    68 	return TestStepResult();
       
    69 	}
       
    70 
       
    71 void CTestMessCleanMessageFolder::CleanFolders(const TMsvId aEntryId)
       
    72 	{
       
    73 #ifdef __MESSAGING_API_V2__
       
    74 	if ( aEntryId == KMsvRootIndexEntryId )
       
    75 		{
       
    76 		CEmailAccounts*	accounts = CEmailAccounts::NewLC();
       
    77 
       
    78 		RArray<TPopAccount>	pop3Accounts;
       
    79 		CleanupClosePushL(pop3Accounts);
       
    80 		accounts->GetPopAccountsL(pop3Accounts);
       
    81 		TInt	count = pop3Accounts.Count();
       
    82 		TInt	index=0;
       
    83 		for( index = 0; index < count; index++ )
       
    84 			{
       
    85 			TPopAccount	id = pop3Accounts[index];
       
    86 			accounts->DeletePopAccountL( id );
       
    87 			}
       
    88 
       
    89 		RArray<TImapAccount>	imap4Accounts;
       
    90 		CleanupClosePushL(imap4Accounts);
       
    91 		accounts->GetImapAccountsL(imap4Accounts);
       
    92 		count = imap4Accounts.Count();
       
    93 		for( TInt index = 0; index < count; index++ )
       
    94 			{
       
    95 			TImapAccount	id = imap4Accounts[index];
       
    96 			accounts->DeleteImapAccountL( id );
       
    97 			}
       
    98 
       
    99 		CleanupStack::PopAndDestroy(3, accounts);
       
   100 		}
       
   101 #endif
       
   102 
       
   103 	SetEntryL(aEntryId);
       
   104 	EntryL().SetSortTypeL(SelectionOrdering());
       
   105 	CMsvEntrySelection*	selection=EntryL().ChildrenL();
       
   106 	CleanupStack::PushL(selection);
       
   107 	TInt				count=selection->Count();
       
   108 	TInt				i;
       
   109 	for (i=count; i>0; )
       
   110 		{
       
   111 		TMsvId	childId=selection->At(--i);
       
   112 
       
   113 		SetEntryL(aEntryId);
       
   114 		if( iNumberOfMessagesToDelete!=0 )
       
   115 			{
       
   116 			TRAPD(err, EntryL().DeleteL(childId));
       
   117 			switch ( err )
       
   118 				{
       
   119 			case KErrNone:
       
   120 				INFO_PRINTF2(_L("DeletedId      : %x"), childId);
       
   121 				if ( iNumberOfMessagesToDelete > 0 )
       
   122 					{
       
   123 					--iNumberOfMessagesToDelete;
       
   124 					}
       
   125 				break;
       
   126 			case KErrAccessDenied:
       
   127 				INFO_PRINTF2(_L("Access Denied  : %x"), childId);
       
   128 				break;
       
   129 			default:
       
   130 				ERR_PRINTF3(_L("Deletion Error : %d , Id : %x "), err, childId);
       
   131 				SetTestStepResult(EFail);
       
   132 				break;
       
   133 				}
       
   134 			}
       
   135 		}
       
   136 	CleanupStack::PopAndDestroy(selection);
       
   137 
       
   138 	EntryL().SetSortTypeL(SelectionOrdering());
       
   139 	selection=EntryL().ChildrenL();
       
   140 	CleanupStack::PushL(selection);
       
   141 	count=selection->Count();
       
   142 	for (i=count; i>0; )
       
   143 		{
       
   144 		TMsvId	childId=selection->At(--i);
       
   145 
       
   146 		//	Log child
       
   147 		CleanFolders(childId);
       
   148 
       
   149 		SetEntryL(aEntryId);
       
   150 
       
   151 		TRAPD(err, EntryL().DeleteL(childId));
       
   152 		switch ( err )
       
   153 			{
       
   154 		case KErrNone:
       
   155 			INFO_PRINTF2(_L("DeletedId      : %x"), childId);
       
   156 			if ( iNumberOfMessagesToDelete > 0 )
       
   157 				{
       
   158 				--iNumberOfMessagesToDelete;
       
   159 				}
       
   160 			break;
       
   161 		case KErrAccessDenied:
       
   162 			INFO_PRINTF2(_L("Access Denied  : %x"), childId);
       
   163 			break;
       
   164 		default:
       
   165 			ERR_PRINTF3(_L("Deletion Error : %d , Id : %x "), err, childId);
       
   166 			SetTestStepResult(EFail);
       
   167 			break;
       
   168 			}
       
   169 		}
       
   170 	CleanupStack::PopAndDestroy(selection);
       
   171 	}
       
   172