|
1 // Copyright (c) 2005-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 // Tests EikFileUtils APIs. |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @test |
|
21 @internalComponent - Internal Symbian test code |
|
22 */ |
|
23 |
|
24 #include <eikfutil.h> |
|
25 #include <ecom/ecom.h> |
|
26 |
|
27 #include "tfileutils.h" |
|
28 #include <tfileutils.rsg> |
|
29 |
|
30 |
|
31 _LIT(KTFileUtilesResourceFilePath, "z:\\system\\test\\fileutils\\tfileutils.rsc"); |
|
32 |
|
33 // globals |
|
34 TBufC<128> KOriginalFileName = _L("c:\\home\\letters\\azxcvmbcdef"); |
|
35 |
|
36 // |
|
37 // class CTFileUtilsAppUi |
|
38 // |
|
39 CTFileUtilsAppUi::CTFileUtilsAppUi(CTmsTestStep* aStep) : |
|
40 CTestAppUi(aStep, KTFileUtilesResourceFilePath) |
|
41 { |
|
42 } |
|
43 |
|
44 void CTFileUtilsAppUi::ConstructL() |
|
45 { |
|
46 CTestAppUi::ConstructL(); |
|
47 |
|
48 AutoTestManager().StartAutoTest(); |
|
49 } |
|
50 |
|
51 CTFileUtilsAppUi::~CTFileUtilsAppUi() |
|
52 { |
|
53 } |
|
54 |
|
55 /** |
|
56 The method is an override from CTestAppUi. The method initiates tests on |
|
57 EikFileUtils APIs. |
|
58 */ |
|
59 void CTFileUtilsAppUi::RunTestStepL(TInt aNumStep) |
|
60 { |
|
61 User::After(TTimeIntervalMicroSeconds32(500000)); |
|
62 switch(aNumStep) |
|
63 { |
|
64 case 1: |
|
65 SetTestStepID(_L("UIF-fileutils-TestFileOperations")); |
|
66 TestFileOperations(); |
|
67 RecordTestResultL(); |
|
68 break; |
|
69 case 2: |
|
70 SetTestStepID(_L("UIF-fileutils-TestFileOperations2")); |
|
71 TestFileOperations2(); |
|
72 RecordTestResultL(); |
|
73 break; |
|
74 case 3: |
|
75 SetTestStepID(_L("UIF-fileutils-TestFileOperations3")); |
|
76 TestFileOperations3(); |
|
77 RecordTestResultL(); |
|
78 break; |
|
79 case 4: |
|
80 SetTestStepID(_L("UIF-fileutils-TestFileOperations4")); |
|
81 TestFileOperations4(); |
|
82 RecordTestResultL(); |
|
83 break; |
|
84 case 5: |
|
85 SetTestStepID(_L("UIF-fileutils-TestAbbreviateFileName")); |
|
86 TestAbbreviateFileName(); |
|
87 RecordTestResultL(); |
|
88 break; |
|
89 case 6: |
|
90 SetTestStepID(_L("UIF-fileutils-TestUidTypeMatches")); |
|
91 TestUidTypeMatches(); |
|
92 RecordTestResultL(); |
|
93 break; |
|
94 case 7: |
|
95 SetTestStepID(_L("UIF-fileutils-TestValidFolderName")); |
|
96 TestValidFolderName(); |
|
97 RecordTestResultL(); |
|
98 break; |
|
99 case 8: |
|
100 { |
|
101 SetTestStepID(_L("UIF-fileutils-TestDiskListL")); |
|
102 TRAPD(err, TestDiskListL()); |
|
103 TEST(err == KErrNone); |
|
104 RecordTestResultL(); |
|
105 break; |
|
106 } |
|
107 case 9: |
|
108 { |
|
109 SetTestStepID(_L("UIF-fileutils-TestSortByTableL")); |
|
110 TRAPD(err, TestSortByTableL()); |
|
111 TEST(err == KErrNone); |
|
112 RecordTestResultL(); |
|
113 CloseTMSGraphicsStep(); |
|
114 break; |
|
115 } |
|
116 case 10: |
|
117 INFO_PRINTF1(_L("Tests completed.\n")); |
|
118 AutoTestManager().FinishAllTestCases(CAutoTestManager::EPass); |
|
119 break; |
|
120 |
|
121 default: |
|
122 break; |
|
123 } |
|
124 } |
|
125 |
|
126 |
|
127 /** |
|
128 This method creates & sets the application's user interface object. |
|
129 */ |
|
130 void CFileUtilsStep::ConstructAppL(CEikonEnv* aEikEnv) |
|
131 { // runs inside a TRAP harness |
|
132 aEikEnv->ConstructL(); |
|
133 CTFileUtilsAppUi* appUi=new(ELeave) CTFileUtilsAppUi(this); |
|
134 |
|
135 CleanupStack::PushL(appUi); |
|
136 aEikEnv->SetAppUi(appUi); |
|
137 appUi->ConstructL(); |
|
138 CleanupStack::Pop(appUi); |
|
139 // goes out of scope when function leaves and private members are destroyed. App Architecture handles |
|
140 // CEikAppUI destruction |
|
141 } |
|
142 |
|
143 |
|
144 CFileUtilsStep::~CFileUtilsStep() |
|
145 { |
|
146 } |
|
147 |
|
148 CFileUtilsStep::CFileUtilsStep() |
|
149 { |
|
150 // Call base class method to set up the human readable name for logging |
|
151 SetTestStepName(KFileUtilsStep); |
|
152 } |
|
153 |
|
154 |
|
155 /** |
|
156 The method creates & sets the test step's user interface object and |
|
157 launches the test step. |
|
158 */ |
|
159 TVerdict CFileUtilsStep::doTestStepL() |
|
160 { |
|
161 INFO_PRINTF1(_L("Test Started")); |
|
162 PreallocateHALBuffer(); |
|
163 |
|
164 __UHEAP_MARK; |
|
165 |
|
166 CEikonEnv* eikEnv=new CEikonEnv; |
|
167 if (eikEnv==NULL) |
|
168 { |
|
169 INFO_PRINTF1(_L("Failed to create Eikon Environment due to lack of Memory")); |
|
170 SetTestStepResult(EFail); |
|
171 return TestStepResult(); |
|
172 } |
|
173 TRAPD(err,ConstructAppL(eikEnv)); |
|
174 if (err!=KErrNone) |
|
175 { |
|
176 SetTestStepResult(EFail); |
|
177 delete eikEnv; |
|
178 INFO_PRINTF2(_L("Failed to construct Eikon Environment, error %d"), err); |
|
179 } |
|
180 else |
|
181 eikEnv->ExecuteD(); |
|
182 |
|
183 REComSession::FinalClose(); |
|
184 |
|
185 __UHEAP_MARKEND; |
|
186 |
|
187 INFO_PRINTF1(_L("Test Finished")); |
|
188 return TestStepResult(); |
|
189 } |
|
190 |
|
191 /** |
|
192 @SYMTestCaseID UIF-fileutils-TestFileOperations |
|
193 |
|
194 @SYMPREQ |
|
195 |
|
196 @SYMTestCaseDesc Test folder information,file copy, renaming & deletion APIs of |
|
197 EikFileUtils. |
|
198 |
|
199 @SYMTestPriority High |
|
200 |
|
201 @SYMTestStatus Implemented |
|
202 |
|
203 @SYMTestActions The method tests the following APIs:\n |
|
204 1.EikFileUtils::IsFolder() : IsFolder() API is tested to verify whether |
|
205 folder path exists by passing invalid & valid folder paths. It also tests the |
|
206 API by passing valid path including filename of a file.\n |
|
207 2.EikFileUtils::PathExists() : PathExists() API is tested to verify whether |
|
208 the specifed path exists by passing valid path including filename.\n |
|
209 3.EikFileUtils::FolderExists() : FolderExists() API is tested to verify |
|
210 whether folder exists by passing a valid folder path.\n |
|
211 4.EikFileUtils::CheckFolder() : CheckFolder() API is tested by passing a |
|
212 non-existent folder path.\n |
|
213 5.EikFileUtils::CheckWhetherFullNameRefersToFolder() : |
|
214 CheckWhetherFullNameRefersToFolder() API is tested to verify whether the |
|
215 fullname passed refers to a folder. This is done by passing a fullname |
|
216 with filename and by passing fullname without a filename.\n |
|
217 6.EikFileUtils::CopyFile() : CopyFile() API is tested to verify copying of |
|
218 an existing & non-existent file.\n |
|
219 7.EikFileUtils::RenameFile() : RenameFile() API is tested to verify renaming |
|
220 of a file.\n |
|
221 8.EikFileUtils::DeleteFile() : DeleteFile() API is tested to verify deletion |
|
222 of a valid and invalid file.\n |
|
223 |
|
224 @SYMTestExpectedResults The test validates results against expected values. |
|
225 |
|
226 */ |
|
227 void CTFileUtilsAppUi::TestFileOperations() |
|
228 { |
|
229 _LIT(KSourceFileName, "z:\\uiktest\\uiktest_t_fileutils.script"); |
|
230 _LIT(KSourceFileNameNotExist, "z:\\system\\test\\uiktest\\notexist.txt"); |
|
231 _LIT(KDestDir, "c:\\uiktest\\"); |
|
232 |
|
233 RFs fs; |
|
234 TInt theRes = fs.Connect(); |
|
235 TEST(theRes == KErrNone); |
|
236 if(theRes != KErrNone) |
|
237 { |
|
238 return; |
|
239 } |
|
240 |
|
241 fs.RmDir(KDestDir); |
|
242 |
|
243 INFO_PRINTF2(_L("Tests whether \"%S\" is a folder"), &KDestDir); |
|
244 TBool theBoolRetVal = EFalse; |
|
245 theRes = EikFileUtils::IsFolder(KDestDir, theBoolRetVal); |
|
246 TEST(theRes == KErrNotFound && (!theBoolRetVal)); |
|
247 |
|
248 fs.MkDirAll(KDestDir); |
|
249 theRes = EikFileUtils::IsFolder(KDestDir, theBoolRetVal); |
|
250 // |
|
251 TEST(theRes == KErrNone); |
|
252 TEST(theBoolRetVal); |
|
253 |
|
254 //should be fail as consists filename |
|
255 INFO_PRINTF2(_L("Test whether path \"%S\" exist"), &KSourceFileName); |
|
256 theBoolRetVal = EikFileUtils::PathExists(KSourceFileName); |
|
257 TEST(!theBoolRetVal); |
|
258 |
|
259 theRes = EikFileUtils::IsFolder(KSourceFileName, theBoolRetVal); |
|
260 TEST(theRes == KErrNone); |
|
261 TEST(!theBoolRetVal); |
|
262 |
|
263 //Tests whether a specified folder exists. |
|
264 INFO_PRINTF2(_L("Tests whether a specified folder \"%S\" exist"), &KDestDir); |
|
265 theBoolRetVal = EikFileUtils::FolderExists(KDestDir); |
|
266 TEST(theBoolRetVal); |
|
267 |
|
268 //exercising CheckFolder |
|
269 //non-existant path |
|
270 theRes = EikFileUtils::CheckFolder(_L("c:\\kkkk\\")); |
|
271 TEST(theRes); |
|
272 |
|
273 theRes = EikFileUtils::CheckFolder(KDestDir); |
|
274 TEST(theRes == KErrNone); |
|
275 |
|
276 INFO_PRINTF2(_L("Passing full path, including filename \"%S\" and check whether full name refers to folder"), &KSourceFileName); |
|
277 theRes = EikFileUtils::CheckWhetherFullNameRefersToFolder(KSourceFileName, theBoolRetVal); |
|
278 TEST(theRes == (TInt)KErrNone); |
|
279 TEST(!theBoolRetVal); |
|
280 |
|
281 INFO_PRINTF2(_L("Passing full path, excluding filename \"%S\" and check whether full name refers to folder"), &KDestDir); |
|
282 theRes = EikFileUtils::CheckWhetherFullNameRefersToFolder(KDestDir, theBoolRetVal); |
|
283 TEST(theRes == (TInt)KErrNone); |
|
284 TEST(theBoolRetVal); |
|
285 |
|
286 _LIT(KDestFileName, "fileutils.txt"); |
|
287 _LIT(KDestNewFileName, "fileutilsnew.txt"); |
|
288 |
|
289 TFileName destFileName(KDestDir); |
|
290 destFileName += KDestFileName; |
|
291 TFileName destFileNameNew(KDestDir); |
|
292 destFileNameNew += KDestNewFileName; |
|
293 |
|
294 // When trying to copy an Non-Existant File , the expected Return code is KErrNotFound |
|
295 INFO_PRINTF1(_L("Try to copy non-existent file")); |
|
296 theRes = EikFileUtils::CopyFile(KSourceFileNameNotExist, KDestFileName, CFileMan::EOverWrite); |
|
297 TEST(theRes == KErrNotFound); |
|
298 |
|
299 INFO_PRINTF3(_L("Try to copy a file from %S to %S "), &KSourceFileName, &destFileName); |
|
300 theRes = EikFileUtils::CopyFile(KSourceFileName, destFileName, CFileMan::EOverWrite); |
|
301 TEST(theRes == KErrNone); |
|
302 |
|
303 // When the Source and Destination Filenames are the same |
|
304 INFO_PRINTF2(_L("Try to copy with src and dest filenames being same (\"%S\") with aSwitch = EOverWrite"), &destFileName); |
|
305 theRes = EikFileUtils::CopyFile(destFileName, destFileName, CFileMan::EOverWrite); |
|
306 TEST(theRes == KErrNone); |
|
307 INFO_PRINTF3(_L("Expected Return Code is KErrNone %d obtained return code is %d"),KErrNone,theRes); |
|
308 |
|
309 INFO_PRINTF2(_L("Try to copy with src and dest filenames being same (\"%S\") with aSwitch = 0"), &destFileName); |
|
310 theRes = EikFileUtils::CopyFile(destFileName, destFileName, 0); |
|
311 TEST(theRes == KErrAlreadyExists); |
|
312 INFO_PRINTF3(_L("Expected Return Code is KErrAlreadyExists %d obtained return code is %d"),KErrAlreadyExists,theRes); |
|
313 |
|
314 INFO_PRINTF3(_L("Rename the file from %S to %S"), &destFileName, &destFileNameNew); |
|
315 theRes = EikFileUtils::RenameFile(destFileName, destFileNameNew, CFileMan::EOverWrite); |
|
316 TEST(theRes == KErrNone); |
|
317 |
|
318 // Copy usually keeps the same attributes on target, so we need to fix them |
|
319 fs.SetAtt(destFileNameNew,0,KEntryAttReadOnly); |
|
320 |
|
321 INFO_PRINTF2(_L("Delete the file : \"%S\""), &destFileNameNew); |
|
322 theRes = EikFileUtils::DeleteFile(destFileNameNew); |
|
323 TEST(theRes == KErrNone); |
|
324 if(theRes != KErrNone) |
|
325 { |
|
326 INFO_PRINTF2(_L("Error during deleting the file %d"), theRes); |
|
327 } |
|
328 |
|
329 //try to delete twice |
|
330 INFO_PRINTF1(_L("Delete the file twice")); |
|
331 theRes = EikFileUtils::DeleteFile(destFileNameNew); |
|
332 TEST(theRes == KErrNotFound); |
|
333 |
|
334 INFO_PRINTF2(_L("Tests whether a specified folder %S exists"), &KDestDir); |
|
335 theBoolRetVal = EikFileUtils::FolderExists(KDestDir); |
|
336 TEST(theBoolRetVal); |
|
337 |
|
338 fs.RmDir(KDestDir); |
|
339 |
|
340 //test has to return false as we have deleted the directory |
|
341 theBoolRetVal = EikFileUtils::FolderExists(KDestDir); |
|
342 TEST(!theBoolRetVal); |
|
343 |
|
344 fs.Close(); |
|
345 } |
|
346 |
|
347 |
|
348 /** |
|
349 @SYMTestCaseID UIF-fileutils-TestAbbreviateFileName |
|
350 |
|
351 @SYMPREQ |
|
352 |
|
353 @SYMTestCaseDesc Tests EikFileUtils::AbbreviatePath() |
|
354 & EikFileUtils::AbbreviateFileName() APIs. |
|
355 |
|
356 @SYMTestPriority High |
|
357 |
|
358 @SYMTestStatus Implemented |
|
359 |
|
360 @SYMTestActions The tests performs the following:\n |
|
361 1.EikFileUtils::AbbreviateFileName() : AbbreviateFileName() API is tested to |
|
362 display the filename when the space to display the entire filename is |
|
363 sufficient and in-sufficient. |
|
364 2.EikFileUtils::AbbreviatePath() : AbbreviatePath() API is tested to display |
|
365 path when the space to display the entire path is sufficient and |
|
366 in-sufficient. |
|
367 |
|
368 @SYMTestExpectedResults The test validates results against expected values. |
|
369 |
|
370 */ |
|
371 void CTFileUtilsAppUi::TestAbbreviateFileName() |
|
372 { |
|
373 //exercising AbbreviateFileName function |
|
374 TBuf<256> buf; |
|
375 TBuf<1> buf1; |
|
376 |
|
377 TFileName fileName(KOriginalFileName); |
|
378 TFileName fileName1(KOriginalFileName); |
|
379 |
|
380 EikFileUtils::AbbreviateFileName(fileName, buf); |
|
381 TEST(buf == KOriginalFileName); |
|
382 |
|
383 const TInt theLenghtBuffer = 8; |
|
384 TBuf<theLenghtBuffer> bufLen8; |
|
385 |
|
386 EikFileUtils::AbbreviateFileName(fileName, bufLen8); |
|
387 |
|
388 TChar ellipsis(0x2026); |
|
389 |
|
390 buf = KOriginalFileName.Right(theLenghtBuffer); |
|
391 buf[0] = (TUint16)ellipsis; |
|
392 TEST(buf == bufLen8); |
|
393 |
|
394 //exercising AbbreviatePath function |
|
395 buf1.Zero(); |
|
396 buf1.Append(ellipsis); |
|
397 |
|
398 const CFont* theFont = CEikonEnv::Static()->LegendFont(); |
|
399 fileName = KOriginalFileName; |
|
400 TInt theMaxWidthInPixels = 0; |
|
401 INFO_PRINTF1(_L("exercising AbbreviatePath function")); |
|
402 buf = EikFileUtils::AbbreviatePath(fileName, *theFont, theMaxWidthInPixels); |
|
403 TEST(buf == buf1); |
|
404 |
|
405 //-------- |
|
406 buf.Zero(); |
|
407 buf.Append(ellipsis); |
|
408 fileName = KOriginalFileName.Right(KOriginalFileName.Length() / 2); |
|
409 fileName.Insert(0, buf); |
|
410 theMaxWidthInPixels = theFont->TextWidthInPixels(fileName); |
|
411 fileName1 = KOriginalFileName; |
|
412 buf = EikFileUtils::AbbreviatePath(fileName1, *theFont, theMaxWidthInPixels); |
|
413 TEST(buf == fileName); |
|
414 |
|
415 //-------- |
|
416 buf = EikFileUtils::AbbreviatePath(fileName1, *theFont, theMaxWidthInPixels + 1); |
|
417 TEST(buf == fileName); |
|
418 } |
|
419 |
|
420 |
|
421 /** |
|
422 @SYMTestCaseID UIF-fileutils-TestFileOperations2 |
|
423 |
|
424 @SYMPREQ |
|
425 |
|
426 @SYMTestCaseDesc Tests drive information APIs and Parse() API. |
|
427 |
|
428 @SYMTestPriority High |
|
429 |
|
430 @SYMTestStatus Implemented |
|
431 |
|
432 @SYMTestActions The method tests the following APIs: |
|
433 1.EikFileUtils::RootFolderPath() : RootFolderPath() API is tested to verify |
|
434 whether the root folder for the specified drive is returned.\n |
|
435 2.EikFileUtils::Parse() : Parse() API is tested to verify whether a specifed |
|
436 filename can be parsed. The test is carried out for valid & invalid file |
|
437 paths.\n |
|
438 3.EikFileUtils::DiskIsReadOnly() : DiskIsReadOnly() API is tested to verify |
|
439 whether the specified disk is read only. This is done by specifying the drive |
|
440 root folder, drive letter & invalid drives. |
|
441 4.EikFileUtils::MostSignificantPartOfFullName() : MostSignificantPartOfFullName() |
|
442 API is tested to verify whether it retreives the most significant part of |
|
443 specified drive, path and file name. |
|
444 5.EikFileUtils::DriveAndPathFromFullName() : DriveAndPathFromFullName() |
|
445 API is tested to verify whether it parses the specified full path to obtain |
|
446 the drive and path. |
|
447 |
|
448 @SYMTestExpectedResults The test validates results against expected values. |
|
449 |
|
450 */ |
|
451 void CTFileUtilsAppUi::TestFileOperations2() |
|
452 { |
|
453 TBool theBoolRetVal; |
|
454 TBuf<1> buf1 = _L("d"); |
|
455 _LIT(KRootFolderPath, "d:\\"); |
|
456 |
|
457 TBuf<256> buf; |
|
458 |
|
459 buf = EikFileUtils::RootFolderPath(buf1); |
|
460 TEST(buf == KRootFolderPath); |
|
461 |
|
462 //exercising parse function |
|
463 buf.Copy(KOriginalFileName); |
|
464 INFO_PRINTF1(_L("Tests whether a specified file name can be parsed")); |
|
465 TInt theRes = EikFileUtils::Parse(buf); |
|
466 TEST(theRes == KErrNone); |
|
467 |
|
468 buf.Delete(0, 1); |
|
469 theRes = EikFileUtils::Parse(buf); |
|
470 TEST(theRes == KErrBadName); |
|
471 |
|
472 //exercising function TInt DiskIsReadOnly(const TDesC& aFullName, TBool& aIsReadOnly); |
|
473 buf = _L("c:\\"); |
|
474 INFO_PRINTF2(_L("Tests whether the specified drive %S is read-only"), &buf); |
|
475 theRes = EikFileUtils::DiskIsReadOnly(buf, theBoolRetVal); |
|
476 INFO_PRINTF1(_L("Tests whether the specified drive is read-only")); |
|
477 TEST(theRes == KErrNone && (!theBoolRetVal)); |
|
478 |
|
479 buf = _L("z:"); |
|
480 theRes = EikFileUtils::DiskIsReadOnly(buf, theBoolRetVal); |
|
481 TEST(theRes == KErrNone && theBoolRetVal); |
|
482 |
|
483 buf = _L("c~\\"); |
|
484 theRes = EikFileUtils::DiskIsReadOnly(buf, theBoolRetVal); |
|
485 TEST(theRes == KErrBadName && theBoolRetVal); |
|
486 |
|
487 buf = _L("c"); |
|
488 theRes = EikFileUtils::DiskIsReadOnly(buf, theBoolRetVal); |
|
489 TEST(theRes == KErrBadName); |
|
490 |
|
491 //exercising function MostSignificantPartOfFullName |
|
492 TFileName fileName(KOriginalFileName); |
|
493 |
|
494 INFO_PRINTF1(_L("Gets the folder/file name")); |
|
495 theRes = EikFileUtils::MostSignificantPartOfFullName(fileName, buf); |
|
496 TEST(theRes == KErrNone); |
|
497 TEST(buf.Compare(_L("azxcvmbcdef")) == 0); |
|
498 |
|
499 theRes = fileName.LocateReverseF('\\'); |
|
500 fileName = fileName.Mid(theRes + 1); |
|
501 |
|
502 TEST(fileName == buf); |
|
503 |
|
504 //exercising function DriveAndPathFromFullName |
|
505 fileName = KOriginalFileName; |
|
506 INFO_PRINTF1(_L("Parses the specified full path and file name to obtain the drive and path")); |
|
507 fileName = EikFileUtils::DriveAndPathFromFullName(fileName); |
|
508 buf = KOriginalFileName; |
|
509 theRes = buf.LocateReverseF('\\'); |
|
510 buf = buf.Left(theRes + 1); |
|
511 |
|
512 TEST(buf == fileName); |
|
513 } |
|
514 |
|
515 |
|
516 /** |
|
517 @SYMTestCaseID UIF-fileutils-TestFileOperations4 |
|
518 |
|
519 @SYMPREQ |
|
520 |
|
521 @SYMTestCaseDesc Tests EikFileUtils::FolderNameFromFullName() API. |
|
522 |
|
523 @SYMTestPriority High |
|
524 |
|
525 @SYMTestStatus Implemented |
|
526 |
|
527 @SYMTestActions The method tests FolderNameFromFullName() API to verify whether |
|
528 it retreives folder name from a path and file name. The test is carried out |
|
529 against valid & invalid path & filename. |
|
530 |
|
531 @SYMTestExpectedResults The test validates results against expected values. |
|
532 |
|
533 */ |
|
534 void CTFileUtilsAppUi::TestFileOperations4() |
|
535 { |
|
536 TBuf<256> buf; |
|
537 |
|
538 //exercising function FolderNameFromFullName |
|
539 buf = KOriginalFileName; |
|
540 |
|
541 INFO_PRINTF1(_L("Gets a folder name from a path and file name")); |
|
542 TFileName fileName = EikFileUtils::FolderNameFromFullName(buf); |
|
543 buf=FolderNameFromFullName(buf); |
|
544 TEST(buf == fileName); |
|
545 |
|
546 buf = _L("c:"); |
|
547 INFO_PRINTF1(_L("Gets a folder name from an invalid folder name")); |
|
548 fileName = EikFileUtils::FolderNameFromFullName(buf); |
|
549 buf=FolderNameFromFullName(buf); |
|
550 TEST(buf == fileName); |
|
551 } |
|
552 |
|
553 |
|
554 /** |
|
555 Auxiliary function for TestCaseID tfileutils-TestFileOperations4 |
|
556 |
|
557 This method splits folder name from a full path. |
|
558 |
|
559 */ |
|
560 TFileName CTFileUtilsAppUi::FolderNameFromFullName(const TDesC& aFullName) |
|
561 { |
|
562 //remove drive from path |
|
563 TFileName theFileName = aFullName; |
|
564 if(theFileName.Match(_L("?:*")) == 0) |
|
565 { |
|
566 theFileName = theFileName.Mid(2); |
|
567 } |
|
568 |
|
569 TInt theRes = theFileName.LocateReverseF('\\'); |
|
570 if(theRes >= 0)//whether the char in the string |
|
571 { |
|
572 theFileName = theFileName.Left(theRes); |
|
573 theRes = theFileName.LocateReverseF('\\'); |
|
574 if(theRes >= 0) |
|
575 { |
|
576 theFileName = theFileName.Right(theFileName.Length() - theRes - 1); |
|
577 } |
|
578 } |
|
579 |
|
580 if(theFileName.Length() == 0) |
|
581 { |
|
582 if(aFullName.MatchF(_L("?:\\")) == 0) |
|
583 { |
|
584 theFileName.Copy(aFullName.Ptr(), 3); |
|
585 } |
|
586 else if(aFullName.MatchF(_L("?:")) == 0) |
|
587 { |
|
588 theFileName.Copy(aFullName.Ptr(), 2); |
|
589 } |
|
590 } |
|
591 |
|
592 return theFileName; |
|
593 } |
|
594 |
|
595 /** |
|
596 @SYMTestCaseID UIF-fileutils-TestFileOperations3 |
|
597 |
|
598 @SYMPREQ |
|
599 |
|
600 @SYMTestCaseDesc Tests removal of system directory "z:\\system". |
|
601 |
|
602 @SYMTestPriority High |
|
603 |
|
604 @SYMTestStatus Implemented |
|
605 |
|
606 @SYMTestActions The method connects to the file server and sets the attributes |
|
607 of system directory & files. The test then calls RFs::GetDir() to populate |
|
608 the system directory & file list. EikFileUtils::RemoveSystemDirectory() is |
|
609 invoked to remove the system directory "z:\\system". |
|
610 |
|
611 @SYMTestExpectedResults The test validates results by calling CDir::Count() |
|
612 which lists the directory count matching the attributes set. |
|
613 |
|
614 */ |
|
615 void CTFileUtilsAppUi::TestFileOperations3() |
|
616 { |
|
617 RFs theFs; |
|
618 |
|
619 CDir* theDir = NULL; |
|
620 CDir* fileList = NULL; |
|
621 |
|
622 theFs.Connect(); |
|
623 TInt attribs=KEntryAttDir|KEntryAttSystem|KEntryAttMatchExclusive; |
|
624 theFs.GetDir(_L("z:\\system"),attribs,ESortNone, fileList, theDir); |
|
625 |
|
626 TInt theNumber = theDir -> Count(); |
|
627 TEST(theNumber == 1); |
|
628 INFO_PRINTF1(_L("Removes the System directory from a list of directory entries")); |
|
629 EikFileUtils::RemoveSystemDirectory(*theDir); |
|
630 theNumber = theDir -> Count(); |
|
631 TEST(theNumber == 0); |
|
632 |
|
633 delete fileList; |
|
634 delete theDir; |
|
635 |
|
636 theFs.Close(); |
|
637 } |
|
638 |
|
639 |
|
640 /** |
|
641 @SYMTestCaseID UIF-fileutils-TestUidTypeMatches |
|
642 |
|
643 @SYMPREQ |
|
644 |
|
645 @SYMTestCaseDesc Tests EikFileUtils::UidTypeMatches() function which tests |
|
646 whether two UID types match. |
|
647 |
|
648 @SYMTestPriority High |
|
649 |
|
650 @SYMTestStatus Implemented |
|
651 |
|
652 @SYMTestActions The method creates some valid UID types and NULL UID type. It |
|
653 also creates similar UID types which is used to compare.\n |
|
654 The method then performs the following tests:\n |
|
655 1. Invokes UidTypeMatches() with valid UID type & its corresponding match UID |
|
656 type.\n |
|
657 2. Invokes UidTypeMatches() with NULL UID type & its corresponding match UID |
|
658 type ie another NULL UID type.\n |
|
659 3. Invokes UidTypeMatches() with NULL UID type & a valid UID type.\n |
|
660 4. Invokes UidTypeMatches() with 2 UID types that do not match.\n |
|
661 5. Invokes UidTypeMatches() with 2 UID types that contain some NULL UID but |
|
662 are similar matches.\n |
|
663 |
|
664 @SYMTestExpectedResults The test validates results against expected boolean values |
|
665 returned by EikFileUtils::UidTypeMatches(). |
|
666 |
|
667 */ |
|
668 void CTFileUtilsAppUi::TestUidTypeMatches() |
|
669 { |
|
670 TBool bIsMatch; |
|
671 |
|
672 // set up some uid's |
|
673 TUid uid1, uid2, uid3, uid4; |
|
674 uid1.iUid = 11111; |
|
675 uid2.iUid = 22222; |
|
676 uid3.iUid = 33333; |
|
677 uid4.iUid = 0; |
|
678 |
|
679 // set up some uid types |
|
680 TUidType theFileUid1(uid1, uid2, uid3); |
|
681 TUidType theFileUid2; |
|
682 TUidType theFileUid3(uid1, uid2, uid4); |
|
683 TUidType theMatchUid1(uid1, uid2, uid3); |
|
684 TUidType theMatchUid2; |
|
685 TUidType theMatchUid3(uid1, uid2, uid4); |
|
686 |
|
687 // good |
|
688 INFO_PRINTF3(_L("Tests whether two valid UID types match, uid1 = %d, uid2 = %d"), |
|
689 theFileUid1[0], theMatchUid1[0]); |
|
690 bIsMatch = EikFileUtils::UidTypeMatches(theFileUid1, theMatchUid1); |
|
691 TEST(bIsMatch); |
|
692 // both nulls |
|
693 INFO_PRINTF3(_L("Tests whether two null UID types match, uid1 = %d, uid2 = %d"), |
|
694 theFileUid2[0], theMatchUid2[0]); |
|
695 bIsMatch = EikFileUtils::UidTypeMatches(theFileUid2, theMatchUid2); |
|
696 TEST(bIsMatch); |
|
697 // null passed |
|
698 INFO_PRINTF3(_L("Tests whether null and valid UID types match, uid1 = %d, uid2 = %d"), |
|
699 theFileUid1[0], theMatchUid2[0]); |
|
700 bIsMatch = EikFileUtils::UidTypeMatches(theFileUid1, theMatchUid2); |
|
701 TEST(bIsMatch); |
|
702 // bad |
|
703 INFO_PRINTF3(_L("Tests whether two invalid UID types match, uid1 = %d, uid2 = %d"), |
|
704 theFileUid2[0], theMatchUid1[0]); |
|
705 bIsMatch = EikFileUtils::UidTypeMatches(theFileUid2, theMatchUid1); |
|
706 TEST(!bIsMatch); |
|
707 |
|
708 //some of the Uid are null |
|
709 INFO_PRINTF3(_L("Compearing two UId's where some of them are null, uid1 = %d, uid2 = %d"), |
|
710 theFileUid3[0], theMatchUid3[0]); |
|
711 bIsMatch = EikFileUtils::UidTypeMatches(theFileUid3, theMatchUid3); |
|
712 TEST(bIsMatch); |
|
713 |
|
714 bIsMatch = EikFileUtils::UidTypeMatches(theFileUid3, theMatchUid1); |
|
715 TEST(!bIsMatch); |
|
716 } |
|
717 |
|
718 |
|
719 /** |
|
720 @SYMTestCaseID UIF-fileutils-TestValidFolderName |
|
721 |
|
722 @SYMPREQ |
|
723 |
|
724 @SYMTestCaseDesc Tests EikFileUtils::ValidateFolderNameTypedByUserL() API. |
|
725 |
|
726 @SYMTestPriority High |
|
727 |
|
728 @SYMTestStatus Implemented |
|
729 |
|
730 @SYMTestActions The method tests EikFileUtils::ValidateFolderNameTypedByUserL() |
|
731 API which tests the folder name provided by user is valid. \n |
|
732 The following tests are performed:\n |
|
733 1. Verifies whether alphabetical characters provided by user can form a valid |
|
734 folder name.\n |
|
735 2. Verifies whether invalid characters such as "*?/\":<>\\" provided by user |
|
736 can form a valid folder name.\n |
|
737 3. Verifies whether valid characters such as "#@%^$£()[]{}&~-_;,.+" provided |
|
738 by user can form a valid folder name.\n |
|
739 |
|
740 @SYMTestExpectedResults For alphabet charachets & vlid character specified |
|
741 ValidateFolderNameTypedByUserL() API should return KErrNone. |
|
742 |
|
743 */ |
|
744 void CTFileUtilsAppUi::TestValidFolderName() |
|
745 { |
|
746 const TBufC<128> theCurrentPath = _L("c:\\"); |
|
747 const TBufC<128> theFolderNameTypedByUser = _L("abc"); |
|
748 TFileName theNewFolderFullName; |
|
749 |
|
750 TRAPD(theRes, theNewFolderFullName = EikFileUtils::ValidateFolderNameTypedByUserL(theFolderNameTypedByUser, theCurrentPath)); |
|
751 TEST(theRes == KErrNone); |
|
752 TEST(theNewFolderFullName.Compare(_L("c:\\abc\\")) == 0); |
|
753 |
|
754 //check invalid characters |
|
755 const TBufC<32> theInvalidCharacters = _L("*?/\":<>\\"); |
|
756 |
|
757 for(TInt index = 0; index < theInvalidCharacters.Length(); index++) |
|
758 { |
|
759 TBuf<128> buf; |
|
760 |
|
761 buf = theFolderNameTypedByUser; |
|
762 buf.Append(theInvalidCharacters[index]); |
|
763 INFO_PRINTF2(_L("Check whether the folder's name %S is invalid"), &buf); |
|
764 |
|
765 TRAP(theRes, theNewFolderFullName = EikFileUtils::ValidateFolderNameTypedByUserL(buf, theCurrentPath)); |
|
766 TEST(theRes != KErrNone); |
|
767 } |
|
768 |
|
769 //check valid characters |
|
770 TBuf<32> theValidCharacters = _L("#@%^$£()[]{}&~-_;,.+"); |
|
771 TChar ch(0x20ac); |
|
772 theValidCharacters.Append(ch); |
|
773 |
|
774 for(TInt index1 = 0; index1< theValidCharacters.Length(); index1++) |
|
775 { |
|
776 TBuf<128> buf; |
|
777 |
|
778 buf = theFolderNameTypedByUser; |
|
779 buf.Append(theValidCharacters[index1]); |
|
780 INFO_PRINTF2(_L("Check whether the folder's name %S is valid"), &buf); |
|
781 |
|
782 TRAP(theRes, theNewFolderFullName = EikFileUtils::ValidateFolderNameTypedByUserL(buf, theCurrentPath)); |
|
783 TEST(theRes == KErrNone); |
|
784 } |
|
785 } |
|
786 |
|
787 /** |
|
788 @SYMTestCaseID UIF-fileutils-TestDiskListL |
|
789 |
|
790 @SYMPREQ |
|
791 |
|
792 @SYMTestCaseDesc Tests EikFileUtils::UpdateDiskListL() API. |
|
793 |
|
794 @SYMTestPriority High |
|
795 |
|
796 @SYMTestStatus Implemented |
|
797 |
|
798 @SYMTestActions The method tests whether UpdateDiskListL() API updates the list |
|
799 of available drives. The following tests are performed on UpdateDiskListL():\n |
|
800 1. Tests updating drive list so that ROM is not included as a drive.\n |
|
801 2. Tests updating drive list so that ROM is included as a drive.\n |
|
802 3. Tests updating drive list after mounting a file system on drive X.\n |
|
803 |
|
804 @SYMTestExpectedResults The test validates results against expected values. |
|
805 |
|
806 */ |
|
807 void CTFileUtilsAppUi::TestDiskListL() |
|
808 { |
|
809 CCoeEnv* coeEnv = CCoeEnv::Static(); |
|
810 TBool theIncludeRom = EFalse; |
|
811 |
|
812 CDesCArray* drives = new(ELeave) CDesCArrayFlat(1); |
|
813 TDriveNumber theDriveNumber1 = EDriveC; |
|
814 |
|
815 TBuf<2> driveLetter; |
|
816 |
|
817 CleanupStack::PushL(drives); |
|
818 |
|
819 EikFileUtils::UpdateDiskListL(coeEnv->FsSession(), *drives, theIncludeRom, theDriveNumber1); |
|
820 INFO_PRINTF2(_L("The number of the drive : %d"), drives->MdcaCount()); |
|
821 |
|
822 TInt theCurDriveNumber = drives->MdcaCount(); |
|
823 TEST(theCurDriveNumber >= 1); |
|
824 driveLetter = (*drives)[0]; |
|
825 INFO_PRINTF2(_L("The drive letter should be C only : %S"), &driveLetter); |
|
826 TEST(driveLetter[0] == 'C'); |
|
827 |
|
828 EikFileUtils::UpdateDiskListL(coeEnv->FsSession(), *drives, theIncludeRom, theDriveNumber1); |
|
829 INFO_PRINTF3(_L("The number of drives has to be the same %d: %d"), theCurDriveNumber, drives->MdcaCount()); |
|
830 TEST(drives->MdcaCount() == theCurDriveNumber); |
|
831 |
|
832 theIncludeRom = ETrue; |
|
833 EikFileUtils::UpdateDiskListL(coeEnv->FsSession(), *drives, theIncludeRom, theDriveNumber1); |
|
834 INFO_PRINTF2(_L("The number of the drive : %d"), drives->MdcaCount()); |
|
835 theCurDriveNumber++; |
|
836 TEST(drives->MdcaCount() == theCurDriveNumber); |
|
837 driveLetter = (*drives)[theCurDriveNumber-1]; |
|
838 INFO_PRINTF2(_L("The drive letter should be Z : %S"), &driveLetter); |
|
839 TEST(driveLetter[0] == 'Z'); |
|
840 |
|
841 CleanupStack::PopAndDestroy(drives); |
|
842 } |
|
843 |
|
844 |
|
845 /** |
|
846 @SYMTestCaseID UIF-fileutils-TestSortByTableL |
|
847 |
|
848 @SYMPREQ |
|
849 |
|
850 @SYMTestCaseDesc The test exercises EikFileUtils::SortByTable() API. |
|
851 |
|
852 @SYMTestPriority High |
|
853 |
|
854 @SYMTestStatus Implemented |
|
855 |
|
856 @SYMTestActions The test exercises EikFileUtils::SortByTable function. |
|
857 The function must sort list of files in order specified in the second |
|
858 param - table of UIDs. The testing directory has 4 files, two of them have |
|
859 equal UID in the sort table. |
|
860 |
|
861 @SYMTestExpectedResults The test validates results against expected values. |
|
862 |
|
863 */ |
|
864 void CTFileUtilsAppUi::TestSortByTableL() |
|
865 { |
|
866 CDir* theFileList; |
|
867 TInt theAttribs=KEntryAttNormal|KEntryAttSystem|KEntryAttAllowUid; |
|
868 TFileName theCurrentPath = _L("Z:\\uiktest\\Documents\\test\\"); |
|
869 |
|
870 RFs& fs=iEikonEnv->FsSession(); |
|
871 const TInt ret=fs.GetDir(theCurrentPath,theAttribs,ESortByName,theFileList); |
|
872 User::LeaveIfError(ret); |
|
873 |
|
874 CleanupStack::PushL(theFileList); |
|
875 |
|
876 TResourceReader reader; |
|
877 CEikonEnv::Static()->CreateResourceReaderLC(reader,R_EIK_ARRAY_FILE_SORT_TABLE); |
|
878 |
|
879 CBaflFileSortTable*theTable = new (ELeave) CBaflFileSortTable(); |
|
880 CleanupStack::PushL(theTable); |
|
881 theTable->ConstructFromResourceL(reader); |
|
882 |
|
883 INFO_PRINTF1(_L("Get the names of the files sorted by alphabetical order")); |
|
884 for(TInt theIndex1 = 0; theIndex1 < theFileList->Count(); theIndex1++) |
|
885 { |
|
886 TEntry theEntry = (*theFileList)[theIndex1]; |
|
887 TUid theUid1 = theEntry[2]; |
|
888 INFO_PRINTF4(_L("The %d file in list %S, Uid = 0x%x"), theIndex1 + 1, &theEntry.iName, theUid1.iUid); |
|
889 |
|
890 switch(theIndex1) |
|
891 { |
|
892 case 0: |
|
893 TEST(theEntry.iName == _L("tfileutils.agenda")); |
|
894 break; |
|
895 case 1: |
|
896 TEST(theEntry.iName == _L("tfileutils.dummy")); |
|
897 break; |
|
898 case 2: |
|
899 TEST(theEntry.iName == _L("tfileutils.scetch")); |
|
900 break; |
|
901 case 3: |
|
902 TEST(theEntry.iName == _L("tfileutils.word")); |
|
903 break; |
|
904 default: |
|
905 break; |
|
906 } |
|
907 } |
|
908 |
|
909 |
|
910 EikFileUtils::SortByTable(*theFileList, theTable); |
|
911 INFO_PRINTF1(_L("Get the names of the files sorted by the Uid's table")); |
|
912 for(TInt theIndex = 0; theIndex < theFileList->Count(); theIndex++) |
|
913 { |
|
914 TEntry theEntry = (*theFileList)[theIndex]; |
|
915 TUid theUid1 = theEntry[2]; |
|
916 |
|
917 INFO_PRINTF4(_L("The %d file in list %S, Uid = 0x%x"), theIndex + 1, &theEntry.iName, theUid1.iUid); |
|
918 switch(theIndex) |
|
919 { |
|
920 case 0: |
|
921 TEST(theEntry.iName == _L("tfileutils.word")); |
|
922 break; |
|
923 case 1: |
|
924 TEST(theEntry.iName == _L("tfileutils.agenda")); |
|
925 break; |
|
926 case 2: |
|
927 TEST(theEntry.iName == _L("tfileutils.scetch")); |
|
928 break; |
|
929 case 3: |
|
930 TEST(theEntry.iName == _L("tfileutils.dummy")); |
|
931 break; |
|
932 default: |
|
933 break; |
|
934 } |
|
935 } |
|
936 |
|
937 CleanupStack::PopAndDestroy(3); //reader theFileList theTable |
|
938 } |
|
939 |