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 |
// Epoc Includes
|
sl@0
|
22 |
// For File URI handler API
|
sl@0
|
23 |
#include <uri16.h>
|
sl@0
|
24 |
#include <uri8.h>
|
sl@0
|
25 |
|
sl@0
|
26 |
// User Include
|
sl@0
|
27 |
#include "TestGetFileNameFromUriStep.h"
|
sl@0
|
28 |
|
sl@0
|
29 |
/**
|
sl@0
|
30 |
Constructor. Sets the test step name
|
sl@0
|
31 |
*/
|
sl@0
|
32 |
CTestGetFileNameFromUriStep::CTestGetFileNameFromUriStep()
|
sl@0
|
33 |
{
|
sl@0
|
34 |
//Call base class method to set human readable name for test step
|
sl@0
|
35 |
SetTestStepName(KTestGetFileNameFromUriStep);
|
sl@0
|
36 |
}
|
sl@0
|
37 |
|
sl@0
|
38 |
/**
|
sl@0
|
39 |
Does the main functionality of a test step.
|
sl@0
|
40 |
Here, reads values from INI file and calls DoTestL
|
sl@0
|
41 |
@internalTechnology
|
sl@0
|
42 |
@see ExtractFileNameAndCompareL
|
sl@0
|
43 |
@param None
|
sl@0
|
44 |
@return EPass or EFail indicating the success or failure of the test step
|
sl@0
|
45 |
*/
|
sl@0
|
46 |
TVerdict CTestGetFileNameFromUriStep::doTestStepL()
|
sl@0
|
47 |
{
|
sl@0
|
48 |
__UHEAP_MARK;
|
sl@0
|
49 |
INFO_PRINTF1(_L("\n"));
|
sl@0
|
50 |
// Get necessary information from INI file
|
sl@0
|
51 |
TPtrC fileUri;
|
sl@0
|
52 |
TPtrC expectedFileName;
|
sl@0
|
53 |
TPtrC fileType;
|
sl@0
|
54 |
TPtrC drive;
|
sl@0
|
55 |
TInt characterSet;
|
sl@0
|
56 |
|
sl@0
|
57 |
if(!GetStringFromConfig(ConfigSection(), KIniFileUri, fileUri ) ||
|
sl@0
|
58 |
!GetStringFromConfig(ConfigSection(), KIniExpectedFileName, expectedFileName) ||
|
sl@0
|
59 |
!GetStringFromConfig(ConfigSection(), KIniFileType, fileType ) ||
|
sl@0
|
60 |
!GetIntFromConfig (ConfigSection(), KIniCharacterSet, characterSet ) ||
|
sl@0
|
61 |
!GetStringFromConfig(ConfigSection(), KIniDrive, drive )
|
sl@0
|
62 |
)
|
sl@0
|
63 |
{
|
sl@0
|
64 |
ERR_PRINTF6(_L("Problem in reading values from ini. \
|
sl@0
|
65 |
\nExpected fields are: \n%S\n%S\n%S\n%S\n%S\n"
|
sl@0
|
66 |
),&KIniFileUri, &KIniExpectedFileName, &KIniFileType, &KIniCharacterSet, &KIniDrive
|
sl@0
|
67 |
);
|
sl@0
|
68 |
SetTestStepResult(EFail);
|
sl@0
|
69 |
}
|
sl@0
|
70 |
else
|
sl@0
|
71 |
{
|
sl@0
|
72 |
TRAPD(err, DoTestL(fileUri, expectedFileName, fileType, drive, characterSet));
|
sl@0
|
73 |
if(err != KErrNone)
|
sl@0
|
74 |
{
|
sl@0
|
75 |
ERR_PRINTF2(_L("Leave occured in CTestGetFileNameFromUriStep::DoTestL: %D"), err);
|
sl@0
|
76 |
SetTestStepResult(EFail);
|
sl@0
|
77 |
}
|
sl@0
|
78 |
}
|
sl@0
|
79 |
INFO_PRINTF1(_L("\n"));
|
sl@0
|
80 |
__UHEAP_MARKEND;
|
sl@0
|
81 |
return TestStepResult();
|
sl@0
|
82 |
} // doTestStepL()
|
sl@0
|
83 |
|
sl@0
|
84 |
/**
|
sl@0
|
85 |
Constructs fully-qualified filename in case of a private file, checks whether the
|
sl@0
|
86 |
drive is a removable drive. Populates the <drive> placeholder and calls
|
sl@0
|
87 |
ExtractFileNameAndCompareL.
|
sl@0
|
88 |
*/
|
sl@0
|
89 |
void CTestGetFileNameFromUriStep::DoTestL(const TPtrC& aFileUri, const TPtrC& aExpectedFileName, const TPtrC& aFileType, TPtrC& aDrive, const TInt& aCharacterSet)
|
sl@0
|
90 |
{
|
sl@0
|
91 |
TInt err = KErrNone;
|
sl@0
|
92 |
TFileName fullyQualifiedName(aExpectedFileName);
|
sl@0
|
93 |
TBool fileNotFound = EFalse;
|
sl@0
|
94 |
|
sl@0
|
95 |
if(aFileType == KFileTypePrivate)
|
sl@0
|
96 |
{// The file is a private file
|
sl@0
|
97 |
// In the case of a secure vesrion of the OS
|
sl@0
|
98 |
// As the INI file contains relative file-name for private files
|
sl@0
|
99 |
// under the ExpectedFileName field, construct the fully-qualified
|
sl@0
|
100 |
// expected file-name
|
sl@0
|
101 |
if((err = CTestFileUriServer::CreateFullyQualifiedName(aExpectedFileName, aDrive, fullyQualifiedName)) != KErrNone)
|
sl@0
|
102 |
{
|
sl@0
|
103 |
ERR_PRINTF2(_L("Error returned by CTestFileUriServer::CreateFullyQualifiedName: %D"), err);
|
sl@0
|
104 |
SetTestStepResult(EFail);
|
sl@0
|
105 |
return;
|
sl@0
|
106 |
}
|
sl@0
|
107 |
}
|
sl@0
|
108 |
|
sl@0
|
109 |
// Check whether drive is removable drive
|
sl@0
|
110 |
TDriveNumber driveNum;
|
sl@0
|
111 |
CTestFileUriServer::GetDriveNumber(aDrive, driveNum);
|
sl@0
|
112 |
TBool aResult;
|
sl@0
|
113 |
err = CTestFileUriServer::IsRemovableDrive(driveNum, aResult);
|
sl@0
|
114 |
if(err != KErrNone)
|
sl@0
|
115 |
{
|
sl@0
|
116 |
ERR_PRINTF2(_L("Error occured while checking whether drive is removable: %D"), err);
|
sl@0
|
117 |
SetTestStepResult(EFail);
|
sl@0
|
118 |
}
|
sl@0
|
119 |
else
|
sl@0
|
120 |
{
|
sl@0
|
121 |
if(aResult)
|
sl@0
|
122 |
{// The drive is a removable drive
|
sl@0
|
123 |
INFO_PRINTF1(_L("The drive is a removable drive"));
|
sl@0
|
124 |
|
sl@0
|
125 |
// Check if any other drive contains a file of the same path and name
|
sl@0
|
126 |
// but comes ahead in the alphabetical order. If yes, that is the correct
|
sl@0
|
127 |
// expected file name
|
sl@0
|
128 |
TBuf<1> correctDrive;
|
sl@0
|
129 |
err = CTestFileUriServer::FirstRemovableDriveWithSameFileName(fullyQualifiedName, correctDrive);
|
sl@0
|
130 |
if(err != KErrNone)
|
sl@0
|
131 |
{
|
sl@0
|
132 |
ERR_PRINTF2(_L("Error occured in FirstRemovableDriveWithSameFileName: %D"), err);
|
sl@0
|
133 |
SetTestStepResult(EFail);
|
sl@0
|
134 |
}
|
sl@0
|
135 |
else if(correctDrive == KNullDesC)
|
sl@0
|
136 |
{
|
sl@0
|
137 |
INFO_PRINTF1(_L("File not found on removable drive"));
|
sl@0
|
138 |
fileNotFound = ETrue;
|
sl@0
|
139 |
}
|
sl@0
|
140 |
else
|
sl@0
|
141 |
{
|
sl@0
|
142 |
correctDrive.LowerCase();
|
sl@0
|
143 |
TBuf<1> drive = aDrive;
|
sl@0
|
144 |
drive.LowerCase();
|
sl@0
|
145 |
if(correctDrive != drive)
|
sl@0
|
146 |
{
|
sl@0
|
147 |
fullyQualifiedName.Replace(0, 1, correctDrive);
|
sl@0
|
148 |
INFO_PRINTF1(_L("One more removable drive found with the same file name, but is ahead in alphabetical order"));
|
sl@0
|
149 |
INFO_PRINTF2(_L("Hence the correct expected file name is %S"), fullyQualifiedName);
|
sl@0
|
150 |
}
|
sl@0
|
151 |
}
|
sl@0
|
152 |
aDrive.Set(KExtMedia());
|
sl@0
|
153 |
}
|
sl@0
|
154 |
HBufC16* uriWithDrive = NULL;
|
sl@0
|
155 |
|
sl@0
|
156 |
// Fill the <drive> place holder if it exists
|
sl@0
|
157 |
TRAPD(err, uriWithDrive = CTestFileUriServer::CheckAndFillDriveNameL(aFileUri, aDrive));
|
sl@0
|
158 |
|
sl@0
|
159 |
if(err != KErrNone)
|
sl@0
|
160 |
{
|
sl@0
|
161 |
ERR_PRINTF2(_L("Error occured while filling the drive-placeholder: %D"), err);
|
sl@0
|
162 |
SetTestStepResult(EFail);
|
sl@0
|
163 |
}
|
sl@0
|
164 |
else
|
sl@0
|
165 |
{
|
sl@0
|
166 |
CleanupStack::PushL(uriWithDrive);
|
sl@0
|
167 |
INFO_PRINTF2(_L("Character Set = %D"), aCharacterSet);
|
sl@0
|
168 |
INFO_PRINTF2(_L("File URI = %S"), uriWithDrive);
|
sl@0
|
169 |
INFO_PRINTF2(_L("Expected Filename = %S"), &fullyQualifiedName);
|
sl@0
|
170 |
fullyQualifiedName.LowerCase();
|
sl@0
|
171 |
|
sl@0
|
172 |
// Call template function based on the characterset.
|
sl@0
|
173 |
if(aCharacterSet == KCharSet8)
|
sl@0
|
174 |
{
|
sl@0
|
175 |
TUriParser16 uriParser8;
|
sl@0
|
176 |
HBufC16* hBufC8 = NULL;
|
sl@0
|
177 |
ExtractFileNameAndCompareL(uriParser8, hBufC8, uriWithDrive->Des(), fullyQualifiedName, aFileType, fileNotFound);
|
sl@0
|
178 |
}
|
sl@0
|
179 |
else if(aCharacterSet == KCharSet16)
|
sl@0
|
180 |
{
|
sl@0
|
181 |
TUriParser16 uriParser16;
|
sl@0
|
182 |
HBufC16* hBufC16 = NULL;
|
sl@0
|
183 |
ExtractFileNameAndCompareL(uriParser16, hBufC16, uriWithDrive->Des(), fullyQualifiedName, aFileType, fileNotFound);
|
sl@0
|
184 |
}
|
sl@0
|
185 |
else
|
sl@0
|
186 |
{
|
sl@0
|
187 |
ERR_PRINTF1(_L("Invalid CharacterSet"));
|
sl@0
|
188 |
SetTestStepResult(EFail);
|
sl@0
|
189 |
}
|
sl@0
|
190 |
CleanupStack::PopAndDestroy(uriWithDrive);
|
sl@0
|
191 |
}
|
sl@0
|
192 |
}
|
sl@0
|
193 |
} // DoTestL
|
sl@0
|
194 |
|
sl@0
|
195 |
/**
|
sl@0
|
196 |
Template function that calls TUriC::GetFileNameL() after processing
|
sl@0
|
197 |
an 8-bit or 16-bit version of a URI, verifies the expected and
|
sl@0
|
198 |
actual results and sets the test step result accordingly.
|
sl@0
|
199 |
*/
|
sl@0
|
200 |
template <class TUriParserType, class HBufCType>
|
sl@0
|
201 |
void CTestGetFileNameFromUriStep::ExtractFileNameAndCompareL(TUriParserType& uriParser8Or16, HBufCType*& fileUri8Or16, const TPtrC& aFileUri, const TFileName& aFullyQualifiedName, const TPtrC& aFileType, const TBool& aFileNotFound)
|
sl@0
|
202 |
{
|
sl@0
|
203 |
fileUri8Or16 = HBufCType::NewLC(aFileUri.Length());
|
sl@0
|
204 |
fileUri8Or16->Des().Copy(aFileUri);
|
sl@0
|
205 |
uriParser8Or16.Parse(*fileUri8Or16);
|
sl@0
|
206 |
|
sl@0
|
207 |
// The actual API being tested
|
sl@0
|
208 |
HBufC16* fileName16 = NULL;
|
sl@0
|
209 |
TRAPD(err, fileName16 = uriParser8Or16.GetFileNameL());
|
sl@0
|
210 |
CleanupStack::PopAndDestroy(fileUri8Or16);
|
sl@0
|
211 |
|
sl@0
|
212 |
if(aFileType == KFileTypePrivate)
|
sl@0
|
213 |
{
|
sl@0
|
214 |
}
|
sl@0
|
215 |
|
sl@0
|
216 |
if(aFileNotFound)
|
sl@0
|
217 |
{// aFileNotFound is true when the file is not found on removable drive
|
sl@0
|
218 |
if(err == KErrNotFound || err == KErrPathNotFound)
|
sl@0
|
219 |
{
|
sl@0
|
220 |
INFO_PRINTF2(_L("Leave occured = %D. This is expected if file is not found on removable drive"), err);
|
sl@0
|
221 |
}
|
sl@0
|
222 |
else
|
sl@0
|
223 |
{
|
sl@0
|
224 |
ERR_PRINTF2(_L("Unexpected result = %D when file is not found on removable drive"), err);
|
sl@0
|
225 |
SetTestStepResult(EFail);
|
sl@0
|
226 |
if(fileName16 != NULL)
|
sl@0
|
227 |
{
|
sl@0
|
228 |
INFO_PRINTF2(_L("File name returned = %S"), fileName16);
|
sl@0
|
229 |
delete fileName16;
|
sl@0
|
230 |
}
|
sl@0
|
231 |
}
|
sl@0
|
232 |
}
|
sl@0
|
233 |
else if(err != KErrNone)
|
sl@0
|
234 |
{// If it comes here, it means there's some problem. But some tests
|
sl@0
|
235 |
// expect an error. So just set the error, and leave the decision
|
sl@0
|
236 |
// to TEF
|
sl@0
|
237 |
ERR_PRINTF2(_L("Leave occured: %D"), err);
|
sl@0
|
238 |
SetTestStepError(err);
|
sl@0
|
239 |
}
|
sl@0
|
240 |
else
|
sl@0
|
241 |
{// Things seem to be OK and a file-name has been returned.
|
sl@0
|
242 |
// Do the checking
|
sl@0
|
243 |
|
sl@0
|
244 |
INFO_PRINTF2(_L("Returned Filename = %S"), fileName16);
|
sl@0
|
245 |
|
sl@0
|
246 |
fileName16->Des().LowerCase();
|
sl@0
|
247 |
|
sl@0
|
248 |
// Compare and set the verdict
|
sl@0
|
249 |
if((fileName16->Des() != aFullyQualifiedName))
|
sl@0
|
250 |
{
|
sl@0
|
251 |
INFO_PRINTF1(_L("The returned filename did not match the expected filename. Result = INCORRECT"));
|
sl@0
|
252 |
SetTestStepResult(EFail);
|
sl@0
|
253 |
}
|
sl@0
|
254 |
else
|
sl@0
|
255 |
{
|
sl@0
|
256 |
INFO_PRINTF1(_L("The returned filename is the same as the expected filename. Result = CORRECT"));
|
sl@0
|
257 |
}
|
sl@0
|
258 |
|
sl@0
|
259 |
delete fileName16;
|
sl@0
|
260 |
}
|
sl@0
|
261 |
} // ExtractFileNameAndCompareL()
|
sl@0
|
262 |
|
sl@0
|
263 |
|