messagingfw/msgtestfw/TestActions/Base/src/CMtfTestActionFindEntryByName.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 // __ACTION_INFO_BEGIN__ 
       
    15 // [Action Name]
       
    16 // FindEntryByName
       
    17 // [Action Parameters]
       
    18 // Session   <input>: Reference to the session.
       
    19 // ParentId  <input>: Value of the parent id.
       
    20 // EntryName <input>: Name of the entry description or details.
       
    21 // EntryId  <output>: Value of the found entry id.
       
    22 // [Action Description]
       
    23 // Finds and returns a specified entry.
       
    24 // [APIs Used]
       
    25 // CMsvEntry::SetEntryL
       
    26 // CMsvEntry::ChildrenL
       
    27 // CMsvEntry::SetSortTypeL
       
    28 // TMsvSelectionOrdering::SetShowInvisibleEntries
       
    29 // __ACTION_INFO_END__
       
    30 // 
       
    31 //
       
    32 
       
    33 /**
       
    34  @file
       
    35 */
       
    36 
       
    37 
       
    38 #include "CMtfTestActionFindEntryByName.h"
       
    39 #include "CMtfTestCase.h"
       
    40 #include "CMtfTestActionParameters.h"
       
    41 
       
    42 #include <msvapi.h>
       
    43 
       
    44 
       
    45 CMtfTestAction* CMtfTestActionFindEntryByName::NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters)
       
    46 	{
       
    47 	CMtfTestActionFindEntryByName* self = new (ELeave) CMtfTestActionFindEntryByName(aTestCase);
       
    48 	CleanupStack::PushL(self);
       
    49 	self->ConstructL(aActionParameters);
       
    50 	CleanupStack::Pop();
       
    51 	return self;
       
    52 	}
       
    53 	
       
    54 
       
    55 CMtfTestActionFindEntryByName::CMtfTestActionFindEntryByName(CMtfTestCase& aTestCase)
       
    56 	: CMtfSynchronousTestAction(aTestCase)
       
    57 	{
       
    58 	}
       
    59 
       
    60 
       
    61 CMtfTestActionFindEntryByName::~CMtfTestActionFindEntryByName()
       
    62 	{
       
    63 	}
       
    64 
       
    65 
       
    66 void CMtfTestActionFindEntryByName::ExecuteActionL()
       
    67 	{
       
    68 	TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionFindEntryByName);
       
    69 	TMsvId paramEntryId;
       
    70 
       
    71 	CMsvSession* paramSession = ObtainParameterReferenceL<CMsvSession>(TestCase(),ActionParameters().Parameter(0));
       
    72 	TMsvId paramParentId      = ObtainValueParameterL<TMsvId>(TestCase(),ActionParameters().Parameter(1));
       
    73 	HBufC* paramEntryName   = ObtainParameterReferenceL<HBufC>(TestCase(),ActionParameters().Parameter(2));
       
    74 	TPtrC entryName = paramEntryName->Des();
       
    75 	
       
    76 	TestCase().INFO_PRINTF2( _L("Searching for Entry %S"), &entryName );	
       
    77 	
       
    78 
       
    79 	CMsvEntry* entry = CMsvEntry::NewL(*paramSession,paramParentId,TMsvSelectionOrdering(KMsvNoGrouping,EMsvSortByNone,ETrue));
       
    80 	CleanupStack::PushL(entry);
       
    81 	entry->SetEntryL(paramParentId);
       
    82 
       
    83 	TMsvSelectionOrdering order;
       
    84 	order.SetShowInvisibleEntries(ETrue);
       
    85 	entry->SetSortTypeL(order);
       
    86 
       
    87 	CMsvEntrySelection* selection = entry->ChildrenL();
       
    88 	CleanupStack::PushL(selection);
       
    89 	
       
    90 	TBool found = EFalse;
       
    91 	TInt count = selection->Count();
       
    92 	for (TInt i=0; i<count; i++) 
       
    93 		{	
       
    94 		entry->SetEntryL((*selection)[i]);
       
    95 		if ( ( entryName.CompareF( entry->Entry().iDescription ) == 0 ) ||
       
    96 		    ( entryName.CompareF( entry->Entry().iDetails ) == 0 ) )
       
    97 			{
       
    98 			found = ETrue;
       
    99 			break;
       
   100 			}
       
   101 		}
       
   102 
       
   103 	if (found)
       
   104 		paramEntryId = entry->Entry().Id();
       
   105 	else
       
   106 		{
       
   107 		TestCase().ERR_PRINTF2( _L("Entry %S not found - leaving"), &entryName );	
       
   108 		User::Leave(KErrNotFound);
       
   109 		}
       
   110 
       
   111 	CleanupStack::PopAndDestroy(selection);
       
   112 	CleanupStack::PopAndDestroy(entry);
       
   113 	StoreParameterL<TMsvId>(TestCase(),paramEntryId,ActionParameters().Parameter(3));
       
   114 	
       
   115 	TestCase().INFO_PRINTF2(_L("CMtfTestActionFindEntryByName search for %S completed ok"), &entryName );
       
   116 
       
   117 	TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionFindEntryByName);
       
   118 	TestCase().ActionCompletedL(*this);
       
   119 	}
       
   120