sl@0
|
1 |
// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
/**
|
sl@0
|
17 |
@file
|
sl@0
|
18 |
@internalTechnology
|
sl@0
|
19 |
*/
|
sl@0
|
20 |
|
sl@0
|
21 |
// User Include
|
sl@0
|
22 |
#include "TestDeleteFileStep.h"
|
sl@0
|
23 |
|
sl@0
|
24 |
/**
|
sl@0
|
25 |
Constructor. Sets the test step name
|
sl@0
|
26 |
*/
|
sl@0
|
27 |
CTestDeleteFileStep::CTestDeleteFileStep()
|
sl@0
|
28 |
{
|
sl@0
|
29 |
//Call base class method to set human readable name for test step
|
sl@0
|
30 |
SetTestStepName(KTestDeleteFileStep);
|
sl@0
|
31 |
}
|
sl@0
|
32 |
|
sl@0
|
33 |
/**
|
sl@0
|
34 |
Tries to delete a file mentioned in the ini file.
|
sl@0
|
35 |
@internalTechnology
|
sl@0
|
36 |
@param None
|
sl@0
|
37 |
@return EPass or EFail indicating the success or failure of file deletion.
|
sl@0
|
38 |
*/
|
sl@0
|
39 |
TVerdict CTestDeleteFileStep::doTestStepL()
|
sl@0
|
40 |
{
|
sl@0
|
41 |
// Get file path and name from ini file
|
sl@0
|
42 |
TPtrC fileName;
|
sl@0
|
43 |
TPtrC fileType;
|
sl@0
|
44 |
TPtrC drive;
|
sl@0
|
45 |
TInt err = KErrNone;
|
sl@0
|
46 |
RFs fs;
|
sl@0
|
47 |
|
sl@0
|
48 |
if (!GetStringFromConfig(ConfigSection(), KIniFileName, fileName))
|
sl@0
|
49 |
{
|
sl@0
|
50 |
ERR_PRINTF1(_L("Unable to read filename from ini file"));
|
sl@0
|
51 |
SetTestStepResult(EFail);
|
sl@0
|
52 |
}
|
sl@0
|
53 |
else
|
sl@0
|
54 |
{
|
sl@0
|
55 |
INFO_PRINTF2(_L("File name = %S"), &fileName);
|
sl@0
|
56 |
|
sl@0
|
57 |
// check whether the filetype field exists in INI
|
sl@0
|
58 |
if(GetStringFromConfig(ConfigSection(), KIniFileType, fileType))
|
sl@0
|
59 |
{
|
sl@0
|
60 |
INFO_PRINTF2(_L("File type = %S"), &fileType);
|
sl@0
|
61 |
}
|
sl@0
|
62 |
|
sl@0
|
63 |
if(fileType == KFileTypePrivate)
|
sl@0
|
64 |
{// The file is a private file. We require the drive too, as the path is relative
|
sl@0
|
65 |
if (!GetStringFromConfig(ConfigSection(), KIniDrive, drive))
|
sl@0
|
66 |
{
|
sl@0
|
67 |
ERR_PRINTF1(_L("If file type is private, drive should be provided. Unable to read drive"));
|
sl@0
|
68 |
SetTestStepResult(EFail);
|
sl@0
|
69 |
return TestStepResult();
|
sl@0
|
70 |
}
|
sl@0
|
71 |
TFileName fullyQualifiedName(fileName);
|
sl@0
|
72 |
// In the case of a secure vesrion of the OS
|
sl@0
|
73 |
// As the INI file contains relative file-name for private files
|
sl@0
|
74 |
// under the ExpectedFileName field, construct the fully-qualified
|
sl@0
|
75 |
// expected file-name
|
sl@0
|
76 |
if((err = CTestFileUriServer::CreateFullyQualifiedName(fileName, drive, fullyQualifiedName)) != KErrNone)
|
sl@0
|
77 |
{
|
sl@0
|
78 |
ERR_PRINTF2(_L("Error returned by CTestFileUriServer::CreateFullyQualifiedName: %D"), err);
|
sl@0
|
79 |
SetTestStepResult(EFail);
|
sl@0
|
80 |
return TestStepResult();
|
sl@0
|
81 |
}
|
sl@0
|
82 |
fileName.Set(fullyQualifiedName);
|
sl@0
|
83 |
INFO_PRINTF2(_L("Fully qualified name = %S"), &fileName);
|
sl@0
|
84 |
}
|
sl@0
|
85 |
|
sl@0
|
86 |
err = fs.Connect();
|
sl@0
|
87 |
if(err != KErrNone)
|
sl@0
|
88 |
{
|
sl@0
|
89 |
ERR_PRINTF2(_L("Error occured while connecting to file server: %D"), err);
|
sl@0
|
90 |
SetTestStepResult(EFail);
|
sl@0
|
91 |
}
|
sl@0
|
92 |
|
sl@0
|
93 |
if(TestStepResult() == EPass)
|
sl@0
|
94 |
{
|
sl@0
|
95 |
err = fs.Delete(fileName);
|
sl@0
|
96 |
if(err == KErrNone)
|
sl@0
|
97 |
{
|
sl@0
|
98 |
INFO_PRINTF1(_L("File deleted successfully"));
|
sl@0
|
99 |
}
|
sl@0
|
100 |
else if(err == KErrNotFound || err == KErrPathNotFound)
|
sl@0
|
101 |
{// File or path not found, this is NOT considered as fail
|
sl@0
|
102 |
INFO_PRINTF1(_L("File and/or path does not exist"));
|
sl@0
|
103 |
}
|
sl@0
|
104 |
else if(err == KErrNotReady)
|
sl@0
|
105 |
{// Drive is not ready, this is NOT considered as fail
|
sl@0
|
106 |
INFO_PRINTF1(_L("Drive not ready"));
|
sl@0
|
107 |
}
|
sl@0
|
108 |
else
|
sl@0
|
109 |
{
|
sl@0
|
110 |
ERR_PRINTF2(_L("Error occured while deleting file: %D"), err);
|
sl@0
|
111 |
SetTestStepResult(EFail);
|
sl@0
|
112 |
}
|
sl@0
|
113 |
fs.Close();
|
sl@0
|
114 |
}
|
sl@0
|
115 |
}
|
sl@0
|
116 |
return TestStepResult();
|
sl@0
|
117 |
} // doTestStepL
|