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