os/ossrv/genericservices/httputils/Test/Integration/TestFileUriSuite/TestDeleteFileStep.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericservices/httputils/Test/Integration/TestFileUriSuite/TestDeleteFileStep.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,117 @@
1.4 +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +/**
1.20 + @file
1.21 + @internalTechnology
1.22 +*/
1.23 +
1.24 +// User Include
1.25 +#include "TestDeleteFileStep.h"
1.26 +
1.27 +/**
1.28 +Constructor. Sets the test step name
1.29 +*/
1.30 +CTestDeleteFileStep::CTestDeleteFileStep()
1.31 + {
1.32 + //Call base class method to set human readable name for test step
1.33 + SetTestStepName(KTestDeleteFileStep);
1.34 + }
1.35 +
1.36 +/**
1.37 +Tries to delete a file mentioned in the ini file.
1.38 +@internalTechnology
1.39 +@param None
1.40 +@return EPass or EFail indicating the success or failure of file deletion.
1.41 +*/
1.42 +TVerdict CTestDeleteFileStep::doTestStepL()
1.43 + {
1.44 + // Get file path and name from ini file
1.45 + TPtrC fileName;
1.46 + TPtrC fileType;
1.47 + TPtrC drive;
1.48 + TInt err = KErrNone;
1.49 + RFs fs;
1.50 +
1.51 + if (!GetStringFromConfig(ConfigSection(), KIniFileName, fileName))
1.52 + {
1.53 + ERR_PRINTF1(_L("Unable to read filename from ini file"));
1.54 + SetTestStepResult(EFail);
1.55 + }
1.56 + else
1.57 + {
1.58 + INFO_PRINTF2(_L("File name = %S"), &fileName);
1.59 +
1.60 + // check whether the filetype field exists in INI
1.61 + if(GetStringFromConfig(ConfigSection(), KIniFileType, fileType))
1.62 + {
1.63 + INFO_PRINTF2(_L("File type = %S"), &fileType);
1.64 + }
1.65 +
1.66 + if(fileType == KFileTypePrivate)
1.67 + {// The file is a private file. We require the drive too, as the path is relative
1.68 + if (!GetStringFromConfig(ConfigSection(), KIniDrive, drive))
1.69 + {
1.70 + ERR_PRINTF1(_L("If file type is private, drive should be provided. Unable to read drive"));
1.71 + SetTestStepResult(EFail);
1.72 + return TestStepResult();
1.73 + }
1.74 + TFileName fullyQualifiedName(fileName);
1.75 + // In the case of a secure vesrion of the OS
1.76 + // As the INI file contains relative file-name for private files
1.77 + // under the ExpectedFileName field, construct the fully-qualified
1.78 + // expected file-name
1.79 + if((err = CTestFileUriServer::CreateFullyQualifiedName(fileName, drive, fullyQualifiedName)) != KErrNone)
1.80 + {
1.81 + ERR_PRINTF2(_L("Error returned by CTestFileUriServer::CreateFullyQualifiedName: %D"), err);
1.82 + SetTestStepResult(EFail);
1.83 + return TestStepResult();
1.84 + }
1.85 + fileName.Set(fullyQualifiedName);
1.86 + INFO_PRINTF2(_L("Fully qualified name = %S"), &fileName);
1.87 + }
1.88 +
1.89 + err = fs.Connect();
1.90 + if(err != KErrNone)
1.91 + {
1.92 + ERR_PRINTF2(_L("Error occured while connecting to file server: %D"), err);
1.93 + SetTestStepResult(EFail);
1.94 + }
1.95 +
1.96 + if(TestStepResult() == EPass)
1.97 + {
1.98 + err = fs.Delete(fileName);
1.99 + if(err == KErrNone)
1.100 + {
1.101 + INFO_PRINTF1(_L("File deleted successfully"));
1.102 + }
1.103 + else if(err == KErrNotFound || err == KErrPathNotFound)
1.104 + {// File or path not found, this is NOT considered as fail
1.105 + INFO_PRINTF1(_L("File and/or path does not exist"));
1.106 + }
1.107 + else if(err == KErrNotReady)
1.108 + {// Drive is not ready, this is NOT considered as fail
1.109 + INFO_PRINTF1(_L("Drive not ready"));
1.110 + }
1.111 + else
1.112 + {
1.113 + ERR_PRINTF2(_L("Error occured while deleting file: %D"), err);
1.114 + SetTestStepResult(EFail);
1.115 + }
1.116 + fs.Close();
1.117 + }
1.118 + }
1.119 + return TestStepResult();
1.120 + } // doTestStepL