messagingfw/msgtestfw/TestActions/Email/Imap4/src/CMtfTestActionCreateMailSelection.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 // CreateMailSelection
       
    17 // [Action Parameters]
       
    18 // CMsvSession    Session        <input>  : Reference to the session.
       
    19 // TMsvId         ParentId       <input>  : Value of the parent folder ID
       
    20 // CMsvSelection  EvenSelection  <output initiation> : Reference to the created 
       
    21 // even selection.
       
    22 // CMsvSelection  OddSelection   <output initiation> : Reference to the created
       
    23 // odd selection.
       
    24 // [Action Description]
       
    25 // Creates two selections of IMAP4 messages.  The Test Action first creates a 
       
    26 // selection of all IMAP4 messages under the parent folder, then copies the 
       
    27 // Message Ids from the selection into 2 seperate message selections where one
       
    28 // selection has all the message IDs in the odd position in the main selection
       
    29 // and the other has the message Ids in the even position.
       
    30 // These two message selections can be used as inputs to Test Actions related
       
    31 // to IMAP4 commands which require a mail selection is requried as an input.
       
    32 // [APIs Used]
       
    33 // CMsvEntry::SetEntryL
       
    34 // CMsvEntry::SetSortTypeL
       
    35 // CMsvEntry::ChildrenWithMtmL
       
    36 // CMsvEntrySelection::AppendL
       
    37 // __ACTION_INFO_END__
       
    38 // 
       
    39 //
       
    40 
       
    41 /**
       
    42  @file 
       
    43  @internalTechnology 
       
    44 */
       
    45 
       
    46 // EPOC include
       
    47 #include <msvapi.h>
       
    48 #include <miutset.h>
       
    49 
       
    50 
       
    51 // User include
       
    52 #include "CMtfTestActionCreateMailSelection.h"
       
    53 #include "CMtfTestCase.h"
       
    54 #include "CMtfTestActionParameters.h"
       
    55 
       
    56 
       
    57 
       
    58 /**
       
    59   NewL()
       
    60   Constructs a CMtfTestActionCreateMailSelection object. Uses two phase 
       
    61   construction and leaves nothing on the CleanupStack.   
       
    62   @internalTechnology
       
    63   @param  aTestCase         Test Case to which this Test Action belongs
       
    64   @param  aActionParameters Action parameters, must not be NULL
       
    65   @return Created object of type CMtfTestActionCreateMailSelection
       
    66   @pre    None
       
    67   @post   CMtfTestActionCreateMailSelection object is created
       
    68 */
       
    69 CMtfTestAction* CMtfTestActionCreateMailSelection::
       
    70 		NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters)
       
    71 	{
       
    72 	
       
    73 	CMtfTestActionCreateMailSelection* self = 
       
    74 							new (ELeave) CMtfTestActionCreateMailSelection(aTestCase);
       
    75 
       
    76 	CleanupStack::PushL(self);
       
    77 	self->ConstructL(aActionParameters);
       
    78 	CleanupStack::Pop(self);
       
    79 	return self;
       
    80 	}
       
    81 	
       
    82 
       
    83 /**
       
    84 	CMtfTestActionCreateMailSelection constructor
       
    85 	Calls the base class' constructor
       
    86     @internalTechnology  
       
    87  	@param  aTestCase  Test Case to which this Test Action belongs
       
    88     @pre    None
       
    89     @post   None
       
    90 */ 
       
    91 CMtfTestActionCreateMailSelection::CMtfTestActionCreateMailSelection(CMtfTestCase& aTestCase)
       
    92 	: CMtfSynchronousTestAction(aTestCase)
       
    93 	{
       
    94 	}
       
    95 
       
    96 
       
    97 /**
       
    98   Function : ExecuteActionL
       
    99   Creates a selection of all IMAP4 mails present in the parent folder, then copies the 
       
   100   Message Ids from the selection into 2 seperate message selections where one
       
   101   selection has all the message IDs in the odd position in the main selection
       
   102   and the other has the message Ids in the even position.  The two message selections
       
   103   created are stored as output parameters of this Test Action.
       
   104   @internalTechnology 
       
   105   @pre    None
       
   106   @post   The third and the fourth parameters of the section in the .ini file corresponding 
       
   107 		  to the instance of this test action should get associated with the even and the 
       
   108 		  odd message selections objects respectively. These two message selections can be
       
   109 		  used as inputs to Test Actions related to IMAP4 commands which require a 
       
   110 		  mail selection is requried as an input.
       
   111 */	
       
   112 void CMtfTestActionCreateMailSelection::ExecuteActionL()
       
   113 	{
       
   114 	TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionCreateMailSelection);
       
   115 	CMsvSession* paramSession = ObtainParameterReferenceL<CMsvSession>(TestCase(),
       
   116 									ActionParameters().Parameter(0));
       
   117 
       
   118 	TMsvId paramParentId = ObtainValueParameterL<TMsvId>(TestCase(),
       
   119 									ActionParameters().Parameter(1));
       
   120 
       
   121 
       
   122 	/***********************************************************************************
       
   123 	Create a selection of all IMAP4 messages in the parent folder. Create two new message
       
   124 	selection objects.  Loop thru all the messages in the IMAP4 message selection, append  
       
   125 	the Ids of messages present at odd index into one selection and those present at even 
       
   126 	index into another selection.  The two message selections are stored as ouput paramters
       
   127 	of this test action.
       
   128 	***********************************************************************************/
       
   129 
       
   130 
       
   131 	// Set the context to the parent folder 
       
   132 	CMsvEntry* entry = CMsvEntry::NewL(*paramSession,paramParentId,
       
   133 										TMsvSelectionOrdering(KMsvNoGrouping,
       
   134 															  EMsvSortByNone,ETrue
       
   135 															  )
       
   136 									  );
       
   137 	
       
   138 	CleanupStack::PushL(entry);
       
   139 	entry->SetEntryL(paramParentId);
       
   140 
       
   141 	// Create a selection of all IMAP4 messages in the parent folder 
       
   142 	TMsvSelectionOrdering order;
       
   143 	order.SetShowInvisibleEntries(ETrue);
       
   144 	entry->SetSortTypeL(order);
       
   145 	CMsvEntrySelection* selection = entry->ChildrenWithMtmL(KUidMsgTypeIMAP4);
       
   146 	CleanupStack::PushL(selection);
       
   147 
       
   148 	// Create a message selection to store message Ids at even index in the main selection
       
   149 	CMsvEntrySelection* evenSelection = new (ELeave) CMsvEntrySelection;
       
   150 	CleanupStack::PushL(evenSelection);
       
   151 
       
   152 	// Create a message selection to store message Ids at odd index in the main selection
       
   153 	CMsvEntrySelection* oddSelection = new (ELeave) CMsvEntrySelection;
       
   154 	CleanupStack::PushL(oddSelection);
       
   155 	
       
   156 	// Copy Message Ids into seperate selections based on their position (even / odd) 
       
   157 	for(TInt i=0 ; i<selection->Count(); i++)
       
   158 		{
       
   159 		 if((i%2)== 0)
       
   160 			{
       
   161 			evenSelection->AppendL(selection->At(i));
       
   162 			}
       
   163 		 else
       
   164 			{
       
   165 			oddSelection->AppendL(selection->At(i));
       
   166 			}
       
   167 		}
       
   168 
       
   169 	// Pop the mail selection objects before storing them as ouput parameters
       
   170 	CleanupStack::Pop(oddSelection);
       
   171 	CleanupStack::Pop(evenSelection);
       
   172 
       
   173 	// Store the two message selections as output parameters of the Test Action 
       
   174 	StoreParameterL<CMsvEntrySelection>(TestCase(),*evenSelection,
       
   175 													ActionParameters().Parameter(2));
       
   176 
       
   177 	StoreParameterL<CMsvEntrySelection>(TestCase(),*oddSelection,
       
   178 													ActionParameters().Parameter(3));
       
   179 	CleanupStack::PopAndDestroy(selection);
       
   180 	CleanupStack::PopAndDestroy(entry);
       
   181 
       
   182 	TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionCreateMailSelection);
       
   183 	TestCase().ActionCompletedL(*this);
       
   184 	}