applayerpluginsandutils/bookmarksupport/test/Integration/TestBookmarksSuite/TestDeleteFolderStep.cpp
changeset 0 b16258d2340f
equal deleted inserted replaced
-1:000000000000 0:b16258d2340f
       
     1 // Copyright (c) 2005-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 // Contains implementation of CTestDeleteFolderStep class
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalTechnology 
       
    21 */
       
    22 
       
    23 // System Include
       
    24 #include <bookmarkdatabase.h>
       
    25 
       
    26 // User Include
       
    27 #include "TestDeleteFolderStep.h"
       
    28 
       
    29 /**
       
    30 Constructor. Sets the test step name
       
    31 @internalTechnology
       
    32 @test
       
    33 */
       
    34 CTestDeleteFolderStep::CTestDeleteFolderStep(CTestBookmarksServer& aTestServer) : CTestBookmarksBaseStep(aTestServer)
       
    35 	{
       
    36 	//Call base class method to set human readable name for test step
       
    37 	SetTestStepName(KTestDeleteFolderStep);
       
    38 	}
       
    39 
       
    40 
       
    41 /**
       
    42 Base class pure virtual.
       
    43 @internalTechnology
       
    44 @test
       
    45 @param		None
       
    46 @return		EPass or EFail indicating the result of the test step.
       
    47 */
       
    48 TVerdict CTestDeleteFolderStep::doTestStepL()
       
    49 	{
       
    50 	TPtrC title;
       
    51 	TBool recursive;
       
    52 	if(!GetStringFromConfig(ConfigSection(), KIniTitle, title))
       
    53 		{
       
    54 		ERR_PRINTF2(_L("Problem in reading values from ini.			\
       
    55 						\nExpected field is : \n%S\n"
       
    56 					  ),&KIniTitle
       
    57 				   );
       
    58 		SetTestStepResult(EFail);
       
    59 		}
       
    60 	else
       
    61 		{
       
    62 		if(!GetBoolFromConfig(ConfigSection(), KIniRecursive, recursive))
       
    63 			{
       
    64 			recursive = ETrue;
       
    65 			INFO_PRINTF1(_L("recursive field not found in ini, defaulting to ETrue"));
       
    66 			}
       
    67 		DoTest(title, recursive);
       
    68 		}
       
    69 	return TestStepResult();
       
    70 	}	// doTestStepL
       
    71 
       
    72 /**
       
    73 Deletes the folder with a particular title.
       
    74 @internalTechnology
       
    75 @test
       
    76 @param		Title of the folder to be deleted
       
    77 @param		TBool indicating recursive delete or not
       
    78 @return		None
       
    79 */
       
    80 void CTestDeleteFolderStep::DoTest(const TPtrC& aTitle, const TBool& aRecursive)
       
    81 	{
       
    82 	TInt error = KErrNone;
       
    83 	RBkFolder rFolder;
       
    84 
       
    85 	FOREVER
       
    86 		{// Just in case DB is corrupt and multiple folders with same name exist
       
    87 		TRAP(error, rFolder = iBkDb.OpenFolderL(aTitle));
       
    88 		if(error == KErrNotFound)
       
    89 			{
       
    90 			// Folder not found, but still result is kept as pass as this
       
    91 			// test step is used for cleanup even before starting the tests
       
    92 			INFO_PRINTF2(_L("Folder %S not found"), &aTitle);
       
    93 			break;
       
    94 			}
       
    95 		else if(error == KErrNone)
       
    96 			{
       
    97 			Bookmark::TItemId id = rFolder.Id();
       
    98 			rFolder.Close();
       
    99 			TRAP(error, iBkDb.DeleteItemL(id, aRecursive));
       
   100 			}
       
   101 
       
   102 		if(error == KErrNone)
       
   103 			{
       
   104 			// No error, commit
       
   105 			INFO_PRINTF2(_L("Folder %S deleted"), &aTitle);
       
   106 			CommitDb();
       
   107 			}
       
   108 		else
       
   109 			{
       
   110 			ERR_PRINTF2(_L("Error occured while deleting folder : %D"), error);
       
   111 			SetTestStepError(error);
       
   112 			break;
       
   113 			}
       
   114 		}
       
   115 	}	// DoTest
       
   116 
       
   117