os/ossrv/genericservices/httputils/Test/Integration/TestFileUriSuite/TestDeleteFileStep.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     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 //
    15 
    16 /**
    17  @file
    18  @internalTechnology 
    19 */
    20 
    21 // User Include
    22 #include "TestDeleteFileStep.h"
    23 
    24 /**
    25 Constructor. Sets the test step name
    26 */
    27 CTestDeleteFileStep::CTestDeleteFileStep()
    28 	{
    29 	//Call base class method to set human readable name for test step
    30 	SetTestStepName(KTestDeleteFileStep);
    31 	}
    32 
    33 /**
    34 Tries to delete a file mentioned in the ini file.
    35 @internalTechnology
    36 @param		None
    37 @return		EPass or EFail indicating the success or failure of file deletion.
    38 */
    39 TVerdict CTestDeleteFileStep::doTestStepL()
    40 	{
    41 	// Get file path and name from ini file
    42 	TPtrC fileName;
    43 	TPtrC fileType;
    44 	TPtrC drive;
    45 	TInt err = KErrNone;
    46 	RFs fs;
    47 	
    48 	if (!GetStringFromConfig(ConfigSection(), KIniFileName, fileName))
    49 		{
    50 		ERR_PRINTF1(_L("Unable to read filename from ini file"));
    51 		SetTestStepResult(EFail);
    52 		}
    53 	else
    54 		{
    55 		INFO_PRINTF2(_L("File name = %S"), &fileName);
    56 		
    57 		// check whether the filetype field exists in INI
    58 		if(GetStringFromConfig(ConfigSection(), KIniFileType, fileType))
    59 		{
    60 		INFO_PRINTF2(_L("File type = %S"), &fileType);
    61 		}
    62 		
    63 	if(fileType == KFileTypePrivate)
    64 		{// The file is a private file. We require the drive too, as the path is relative
    65 		if (!GetStringFromConfig(ConfigSection(), KIniDrive, drive))
    66 			{
    67 			ERR_PRINTF1(_L("If file type is private, drive should be provided. Unable to read drive"));
    68 			SetTestStepResult(EFail);
    69 			return TestStepResult();
    70 			}
    71 		TFileName fullyQualifiedName(fileName);
    72 		// In the case of a secure vesrion of the OS
    73 		// As the INI file contains relative file-name for private files
    74 		// under the ExpectedFileName field, construct the fully-qualified
    75 		// expected file-name
    76 		if((err = CTestFileUriServer::CreateFullyQualifiedName(fileName, drive, fullyQualifiedName)) != KErrNone)
    77 			{
    78 			ERR_PRINTF2(_L("Error returned by CTestFileUriServer::CreateFullyQualifiedName: %D"), err);
    79 			SetTestStepResult(EFail);
    80 			return TestStepResult();
    81 			}
    82 		fileName.Set(fullyQualifiedName);
    83 		INFO_PRINTF2(_L("Fully qualified name = %S"), &fileName);
    84 		}
    85 
    86 		err = fs.Connect();
    87 		if(err != KErrNone)
    88 			{
    89 			ERR_PRINTF2(_L("Error occured while connecting to file server: %D"), err);
    90 			SetTestStepResult(EFail);
    91 			}
    92 
    93 		if(TestStepResult() == EPass)
    94 			{
    95 			err = fs.Delete(fileName);
    96 			if(err == KErrNone)
    97 				{
    98 				INFO_PRINTF1(_L("File deleted successfully"));
    99 				}
   100 			else if(err == KErrNotFound || err == KErrPathNotFound)
   101 				{// File or path not found, this is NOT considered as fail
   102 				INFO_PRINTF1(_L("File and/or path does not exist"));
   103 				}
   104 			else if(err == KErrNotReady)
   105 				{// Drive is not ready, this is NOT considered as fail
   106 				INFO_PRINTF1(_L("Drive not ready"));
   107 				}
   108 			else
   109 				{
   110 				ERR_PRINTF2(_L("Error occured while deleting file: %D"), err);
   111 				SetTestStepResult(EFail);
   112 				}
   113 			fs.Close();
   114 			}
   115 		}
   116 	return TestStepResult();
   117 	}	// doTestStepL