messagingfw/msgtestfw/TestActions/Base/src/CMtfTestActionCheckChildrenCountWithFlagBase.cpp
changeset 62 db3f5fa34ec7
parent 0 8e480a14352b
equal deleted inserted replaced
60:9f5ae1728557 62:db3f5fa34ec7
       
     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 // Abstrast base class for Test Actions that check the number of Message Entries with a 
       
    15 // particular flag set.
       
    16 // Derived classes need to override FlagIsSetL() which tests the specific TMsvEntry flag. 
       
    17 // [Action Parameters]
       
    18 // Session  <input>: Reference to the session.
       
    19 // ParentId <input>: Value of the parent id.
       
    20 // Count    <input>: Value of expected count with particular flag set.
       
    21 // [Action Description]
       
    22 // Checks if children count with particular flag set is as expected.
       
    23 // [APIs Used]
       
    24 // CMsvEntry::SetEntryL
       
    25 // CMsvEntry::ChildrenL
       
    26 // CMsvEntry::SetSortTypeL
       
    27 // TMsvSelectionOrdering::SetShowInvisibleEntries
       
    28 // 
       
    29 //
       
    30 
       
    31 /**
       
    32  @file
       
    33  @internalTechnology
       
    34 */
       
    35 
       
    36 
       
    37 #include "CMtfTestActionCheckChildrenCountWithFlagBase.h"
       
    38 #include "CMtfTestCase.h"
       
    39 #include "CMtfTestActionParameters.h"
       
    40 
       
    41 #include <msvapi.h>
       
    42 
       
    43 _LIT(KFlagNameUnknown, "Unknown Flag");
       
    44 
       
    45 TInt CMtfTestActionCheckChildrenCountWithFlagBase::CountChildrenL(TMsvId aParent, CMsvSession& aSession)
       
    46 	{
       
    47 	TInt children = 0;
       
    48 	// Get children at this level
       
    49 
       
    50 	CMsvEntry* entryContext = CMsvEntry::NewL(aSession, aParent, 
       
    51 	    	TMsvSelectionOrdering(KMsvNoGrouping, EMsvSortByNone, ETrue));
       
    52 	CleanupStack::PushL(entryContext);
       
    53 	
       
    54 	entryContext->SetEntryL(aParent);
       
    55 	TMsvSelectionOrdering order;
       
    56 	order.SetShowInvisibleEntries(ETrue);
       
    57 	entryContext->SetSortTypeL(order);
       
    58 	
       
    59 	CMsvEntrySelection* selection = entryContext->ChildrenL();
       
    60 	CleanupStack::PushL(selection);
       
    61 	
       
    62 	// for each child
       
    63 	TInt count=selection->Count();
       
    64 	for(TInt child=0;child<count;child++)
       
    65 		{
       
    66 		entryContext->SetEntryL((*selection)[child]);
       
    67 		TMsvEntry entry=entryContext->Entry();
       
    68 		if (entry.iType==KUidMsvMessageEntry && FlagIsSet(entry) )
       
    69 			{
       
    70 			++children;
       
    71 			}
       
    72 		// if this is a folder then recurse
       
    73 		if (entry.iType==KUidMsvFolderEntry)
       
    74 			children +=CountChildrenL((*selection)[child], aSession);
       
    75 		}
       
    76 	CleanupStack::PopAndDestroy(2); // selection,entryContext
       
    77 	return children;
       
    78 	}
       
    79 
       
    80 
       
    81 CMtfTestActionCheckChildrenCountWithFlagBase::CMtfTestActionCheckChildrenCountWithFlagBase(CMtfTestCase& aTestCase)
       
    82 	: CMtfSynchronousTestAction(aTestCase)
       
    83 	{
       
    84 	}
       
    85 
       
    86 
       
    87 CMtfTestActionCheckChildrenCountWithFlagBase::~CMtfTestActionCheckChildrenCountWithFlagBase()
       
    88 	{
       
    89 	}
       
    90 
       
    91 TBool CMtfTestActionCheckChildrenCountWithFlagBase::FlagIsSet(TMsvEntry& /*entry */) 
       
    92     {
       
    93 	return EFalse;
       
    94 	}
       
    95 
       
    96 void CMtfTestActionCheckChildrenCountWithFlagBase::ExecuteActionL()
       
    97 	{
       
    98 	TestCase().INFO_PRINTF1(_L("Test Action CMtfTestActionCheckChildrenCountWithFlagBase start..."));
       
    99 	CMsvSession* paramSession = ObtainParameterReferenceL<CMsvSession>(TestCase(),ActionParameters().Parameter(0));
       
   100 	TMsvId paramParentId = ObtainValueParameterL<TMsvId>(TestCase(),ActionParameters().Parameter(1));
       
   101 	TInt paramCount = ObtainValueParameterL<TInt>(TestCase(),ActionParameters().Parameter(2));
       
   102 
       
   103 	TInt count = CountChildrenL(paramParentId, *paramSession);
       
   104 	
       
   105 	if (paramCount != count)
       
   106 	    {
       
   107 	    TestCase().INFO_PRINTF4(_L("ChildrenCount with Flag %S was %d, expected %d"), FlagName(), count, paramCount );
       
   108 		TestCase().SetTestStepResult(EFail);
       
   109 		User::Leave(KErrArgument);
       
   110 		}
       
   111 	else
       
   112 	    {
       
   113 		TestCase().INFO_PRINTF2(_L("Test Action CheckChildrenCountWithFlag %S completed."), FlagName() );
       
   114 		}
       
   115 	TestCase().ActionCompletedL(*this);
       
   116 	}
       
   117