First public contribution.
1 // Copyright (c) 2003-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Tests some code internal to BaflUtils
18 #include "BaUtilsImp.h"
23 #define UNUSED_VAR(a) a = a
25 const TPtrC KValFolderName=_L("ValidFolderName");
26 const TPtrC KCurrentPath=_L("C:\\System\\Data\\");
27 const TPtrC KNoFolderName = _L("");
28 const TPtrC KInValidFolderName=_L("C:\\System\\Data\\InValid3+FollderName");
32 CTrapCleanup* TrapCleanup;
33 RTest test(_L("T_BaflUtilsImp - Internal Bafl function tests"));
36 class RTestDirectoryScanner : public RDirectoryScanner
39 RTestDirectoryScanner(CDesCArray*& aMember)
40 : iOpenError(0), iFilesThatExist(aMember)
42 for (TInt i = 0; i != 26; ++i)
45 virtual TInt Open(RFs&, const TDesC& aMatchPattern)
47 iMatch = aMatchPattern;
51 virtual TInt Next(TEntry& aOut)
55 while (iIndex < iFilesThatExist->Count())
58 if (0 <= (*iFilesThatExist)[i].MatchF(iMatch))
60 TPtrC fullName=(*iFilesThatExist)[i];
61 TParsePtrC name(fullName);
62 aOut.iName=name.NameAndExt();
63 if (1 < fullName.Length() && fullName[1] == ':')
65 TInt drive = fullName[0];
66 if ('a' <= drive && drive <= 'z')
70 ASSERT('A' <= drive && drive <= 'Z');
73 return iDriveError[drive];
80 virtual void Close() {}
84 CDesCArray *&iFilesThatExist;
89 class TTestNearestLanguageFileFinder : public TNearestLanguageFileFinder
92 TTestNearestLanguageFileFinder(const RFs& aFs)
93 : TNearestLanguageFileFinder(aFs), iTestScanner(iFilesThatExist)
96 iFilesSearchedFor = 0;
98 ~TTestNearestLanguageFileFinder()
100 delete iFilesThatExist;
101 delete iFilesSearchedFor;
103 virtual TInt GetCustomResourceDriveNumber() const { return iCustomRscDrive; }
104 virtual TBool FileExists(const TDesC& aFileName) const
106 test(aFileName[1] == ':');
107 test(0 == aFileName.Left(1).CompareF(iDrivesChecked.Left(1)));
108 iDrivesChecked.Delete(0, 1);
109 test(0 <= aFileName.MatchF(iFileCheckedFor));
110 if (iFilesSearchedFor)
112 test(0 == aFileName.CompareF((*iFilesSearchedFor)[0]));
113 iFilesSearchedFor->Delete(0);
115 if (!iFilesThatExist)
118 iFilesThatExist->Find(aFileName, i);
119 return (0 <= i && i < iFilesThatExist->Count())? ETrue : EFalse;
121 virtual RDirectoryScanner& DirectoryScanner() { return iTestScanner; }
123 TInt iCustomRscDrive;
124 CDesCArray* iFilesThatExist;
125 // File that is expected to go into FileExists.
126 // Can contain wildcards.
127 TFileName iFileCheckedFor;
128 // Drives expected in calls to FileExists. The first one is checked then
129 // discarded each time FileExists is called.
130 mutable TBuf<26> iDrivesChecked;
131 CDesCArray* iFilesSearchedFor;
132 RTestDirectoryScanner iTestScanner;
135 void TestPath(const TLanguagePath& aPath, const TLanguage* aExpected, TInt aExpectedCount)
137 for (int i = 0; i != aExpectedCount; ++i)
138 test(aPath[i] == *aExpected++);
139 test(aPath[aExpectedCount] == ELangNone);
142 const TLanguage ExpectedPath[] = { ELangFrench, ELangJapanese, ELangGerman, ELangGreek,
143 ELangArabic, ELangEnglish, ELangItalian, ELangHebrew };
146 @SYMTestCaseID SYSLIB-BAFL-CT-0443
147 @SYMTestCaseDesc Tests TLanguagePath class
148 @SYMTestPriority High
149 @SYMTestActions Test for adding different language paths
150 @SYMTestExpectedResults Test must not fail
153 void TestAddLanguage()
155 test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0443 "));
158 AddLanguage(path, ELangNone);
159 TestPath(path, ExpectedPath, 0);
160 AddLanguage(path, ELangFrench);
161 TestPath(path, ExpectedPath, 1);
162 AddLanguage(path, ELangFrench);
163 TestPath(path, ExpectedPath, 1);
164 AddLanguage(path, ELangNone);
165 TestPath(path, ExpectedPath, 1);
166 AddLanguage(path, ELangFrench);
167 TestPath(path, ExpectedPath, 1);
168 AddLanguage(path, ELangJapanese);
169 TestPath(path, ExpectedPath, 2);
170 AddLanguage(path, ELangFrench);
171 TestPath(path, ExpectedPath, 2);
172 AddLanguage(path, ELangNone);
173 TestPath(path, ExpectedPath, 2);
174 AddLanguage(path, ELangGerman);
175 TestPath(path, ExpectedPath, 3);
176 AddLanguage(path, ELangGreek);
177 TestPath(path, ExpectedPath, 4);
178 AddLanguage(path, ELangArabic);
179 TestPath(path, ExpectedPath, 5);
180 AddLanguage(path, ELangNone);
181 TestPath(path, ExpectedPath, 5);
182 AddLanguage(path, ELangEnglish);
183 TestPath(path, ExpectedPath, 6);
184 AddLanguage(path, ELangItalian);
185 TestPath(path, ExpectedPath, 7);
186 AddLanguage(path, ELangNone);
187 TestPath(path, ExpectedPath, 7);
188 AddLanguage(path, ELangHebrew);
189 TestPath(path, ExpectedPath, 8);
190 AddLanguage(path, ELangHebrew);
191 TestPath(path, ExpectedPath, 8);
192 AddLanguage(path, ELangEnglish);
193 TestPath(path, ExpectedPath, 8);
194 AddLanguage(path, ELangItalian);
195 TestPath(path, ExpectedPath, 8);
196 AddLanguage(path, ELangNone);
197 TestPath(path, ExpectedPath, 8);
198 AddLanguage(path, ELangFrench);
199 TestPath(path, ExpectedPath, 8);
200 AddLanguage(path, ELangNone);
201 TestPath(path, ExpectedPath, 8);
202 AddLanguage(path, ELangGerman);
203 TestPath(path, ExpectedPath, 8);
206 struct SDowngradeTest
213 @SYMTestCaseID SYSLIB-BAFL-CT-0444
214 @SYMTestCaseDesc Tests for the functionality of TLocale class
215 @SYMTestPriority High
216 @SYMTestActions Test for language downgrades
217 @SYMTestExpectedResults Test must not fail
220 void TestDowngrade(SDowngradeTest& aTest)
222 test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0444 "));
224 loc.SetLanguageDowngrade(0, aTest.iIn[1]);
225 loc.SetLanguageDowngrade(1, aTest.iIn[2]);
226 loc.SetLanguageDowngrade(2, aTest.iIn[3]);
228 MakeLanguageDowngradePath(path, aTest.iIn[0], ELangNone, loc);
229 for (int i = 0; ; ++i)
232 test(aTest.iOut[i] == path[i]);
233 if (path[i] == ELangNone)
239 // Test Dialect enumeration.
240 // Each value represents a dialect (variant) of a TLanguage language.
241 // E.g. AmericanSprint is represented by ELangAmerican | EDialectSprint
243 // The dialect location -- top six bits
244 const TUint KDialectFactor=0x0400;
247 // The following are example dialects for testing only
248 EDialectSprint = (1*KDialectFactor),
249 EDialectOrange = (2*KDialectFactor),
250 EDialectMaximum = EDialectOrange // This must always be equal to the last TDialect enum.
251 // Up to 63 dialects.
254 const TLanguage ELangEnglishOrange = static_cast<TLanguage>(ELangEnglish|EDialectOrange);
255 const TLanguage ELangAmericanSprint = static_cast<TLanguage>(ELangAmerican|EDialectSprint);
257 SDowngradeTest DowngradeData[] =
260 // 1-3 = language downgrade for locale
261 // 4- = calculated language downgrade path, terminated with ELangNone.
262 {{ELangEnglishOrange, ELangNone, ELangNone, ELangNone},
263 {ELangEnglishOrange, ELangEnglish, ELangNone}},
264 {{ELangAmericanSprint, ELangNone, ELangNone, ELangNone},
265 {ELangAmericanSprint, ELangAmerican, ELangEnglish, ELangNone}},
266 {{ELangFrench, ELangNone, ELangNone, ELangNone},
267 {ELangFrench, ELangNone}},
268 {{ELangSwissFrench, ELangNone, ELangNone, ELangNone},
269 {ELangSwissFrench, ELangFrench, ELangNone}},
270 {{ELangCanadianEnglish, ELangNone, ELangNone, ELangNone},
271 {ELangCanadianEnglish, ELangAmerican, ELangEnglish, ELangNone}},
272 {{ELangSwissFrench, ELangNone, ELangFrench, ELangNone},
273 {ELangSwissFrench, ELangFrench, ELangNone}},
274 {{ELangCanadianEnglish, ELangEnglish, ELangNone, ELangAmerican},
275 {ELangCanadianEnglish, ELangEnglish, ELangAmerican, ELangNone}},
276 {{ELangCanadianEnglish, ELangNone, ELangNone, ELangSwissFrench},
277 {ELangCanadianEnglish, ELangSwissFrench, ELangAmerican, ELangEnglish, ELangNone}},
278 {{ELangCanadianEnglish, ELangFrench, ELangAmerican, ELangSwissFrench},
279 {ELangCanadianEnglish, ELangFrench, ELangAmerican, ELangSwissFrench, ELangEnglish, ELangNone}},
280 {{ELangCanadianEnglish, ELangNone, ELangGerman, ELangSwissFrench},
281 {ELangCanadianEnglish, ELangGerman, ELangSwissFrench, ELangAmerican, ELangEnglish, ELangNone}},
282 {{ELangCanadianEnglish, ELangFinlandSwedish, ELangGerman, ELangSwissFrench},
283 {ELangCanadianEnglish, ELangFinlandSwedish, ELangGerman, ELangSwissFrench, ELangAmerican, ELangEnglish, ELangNone}},
284 {{ELangFinlandSwedish, ELangFinlandSwedish, ELangFinlandSwedish, ELangFinlandSwedish},
285 {ELangFinlandSwedish, ELangSwedish, ELangNone}},
289 @SYMTestCaseID SYSLIB-BAFL-CT-0445
290 @SYMTestCaseDesc Tests for language downgrades
291 @SYMTestPriority High
292 @SYMTestActions Call up downgrade path test function
293 @SYMTestExpectedResults Test must not fail
296 void TestMakeLanguageDowngradePath()
298 test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0445 "));
299 for (int i = 0; i != sizeof(DowngradeData)/sizeof(DowngradeData[0]); ++i)
300 TestDowngrade(DowngradeData[i]);
303 void SetUpFinderForLanguageAndDriveSearchL(
304 TTestNearestLanguageFileFinder& aFinder)
306 aFinder.iDrives = _L("ZAG");
307 aFinder.iFilesSearchedFor = new(ELeave) CDesCArraySeg(10);
308 aFinder.iFilesSearchedFor->AppendL(_L("z:\\dir\\name.e02"));
309 aFinder.iFilesSearchedFor->AppendL(_L("a:\\dir\\name.e02"));
310 aFinder.iFilesSearchedFor->AppendL(_L("g:\\dir\\name.e02"));
311 aFinder.iFilesSearchedFor->AppendL(_L("z:\\dir\\name.e15702")); //Extended lang
312 aFinder.iFilesSearchedFor->AppendL(_L("a:\\dir\\name.e15702"));
313 aFinder.iFilesSearchedFor->AppendL(_L("g:\\dir\\name.e15702"));
314 aFinder.iFilesSearchedFor->AppendL(_L("z:\\dir\\name.e01"));
315 aFinder.iFilesSearchedFor->AppendL(_L("a:\\dir\\name.e01"));
316 aFinder.iFilesSearchedFor->AppendL(_L("g:\\dir\\name.e01"));
317 aFinder.iFilesSearchedFor->AppendL(_L("z:\\dir\\name.ext"));
318 aFinder.iFilesSearchedFor->AppendL(_L("a:\\dir\\name.ext"));
319 aFinder.iFilesSearchedFor->AppendL(_L("g:\\dir\\name.ext"));
320 aFinder.iDrivesChecked = _L("zagzagzagzagzag");
323 _LIT(KTestFileName1, "z:\\dir\\name.ext");
324 //_LIT(KTestFileName2, "z:\\dir\\náme.ext");
325 _LIT(KTestFileName2, "z:\\dir\\n\u00c1me.ext");
326 _LIT(KTestFileName3, "a:\\dir\\name.ext");
327 _LIT(KTestFileName4, "c:\\dir\\name.ext");
328 _LIT(KTestFileName5, "d:\\dir\\name.ext");
329 _LIT(KTestFileName6, "y:\\dir\\name.ext");
330 _LIT(KTestFileName7, "A:\\dir\\name.ext");
331 _LIT(KTestFileName8, "C:\\dir\\name.ext");
332 _LIT(KTestFileName9, "Y:\\dir\\name.ext");
333 _LIT(KTestFileName11, "\\abc\\defg.hijkl");
334 _LIT(KTestFileName256Chars, "\
335 \\abcdefghijklmnopqrstuvwxyz01234\\abcdefghijklmnopqrstuvwxyz01234\
336 \\abcdefghijklmnopqrstuvwxyz01234\\abcdefghijklmnopqrstuvwxyz01234\
337 \\abcdefghijklmnopqrstuvwxyz01234\\abcdefghijklmnopqrstuvwxyz01234\
338 \\abcdefghijklmnopqrstuvwxyz01234\\abcdefghijklmnopqrstuvwxyz0.ext");
340 _LIT(KExpectedFileName256Chars, "?:\
341 \\abcdefghijklmnopqrstuvwxyz01234\\abcdefghijklmnopqrstuvwxyz01234\
342 \\abcdefghijklmnopqrstuvwxyz01234\\abcdefghijklmnopqrstuvwxyz01234\
343 \\abcdefghijklmnopqrstuvwxyz01234\\abcdefghijklmnopqrstuvwxyz01234\
344 \\abcdefghijklmnopqrstuvwxyz01234\\abcdefghijklmnopqrstuvwxyz0.e");
345 _LIT(KExpectedFileName1, "?:\\dir\\name.e");
346 _LIT(KExpectedSuffix1, "xt");
347 _LIT(KExpectedFileName2, "?:\\abc\\defg.hij");
348 _LIT(KExpectedSuffix2, "kl");
349 _LIT(KTestFileName1French, "z:\\dir\\name.e02");
350 _LIT(KTestFileName1Japanese, "z:\\dir\\name.e32");
351 _LIT(KTestFileName1Mongolian, "z:\\dir\\name.e54321");
352 _LIT(KTestFileName1AmericanSprint, "z:\\dir\\name.e1034"); //American=0x0A, Sprint=0x0400. 0x040A=1034.
353 _LIT(KCheckedForFrench, "?:\\dir\\name.e02");
356 @SYMTestCaseID SYSLIB-BAFL-CT-0446
357 @SYMTestCaseDesc Nearest language finder test
358 @SYMTestPriority High
359 @SYMTestActions Test drive sequence construction
360 Test addition of language number
361 Test searching each drive for the specified file
362 Test searching language and drive down the language path
363 Test filename matching
364 Test searching for any language file within a drive
365 Test searching all drives for any language
366 @SYMTestExpectedResults Test must not fail
369 void TestNearestLanguageFinder()
371 test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0446 "));
373 TTestNearestLanguageFileFinder finder(dummy);
375 // Test file name setting and disecting
378 TFileName fileName(KTestFileName1);
379 finder.SetFileName(fileName);
380 test(0 <= finder.iFileName->MatchF(KExpectedFileName1));
381 test(0 == finder.iSuffix.Compare(KExpectedSuffix1));
382 test('z' == finder.iInitialDriveLetter);
383 finder.RepairFileName();
384 test(0 == finder.iFileName->Compare(KTestFileName1));
385 fileName = KTestFileName11;
386 finder.SetFileName(fileName);
387 test(0 <= finder.iFileName->MatchF(KExpectedFileName2));
388 test(0 == finder.iSuffix.Compare(KExpectedSuffix2));
389 test(-1 == finder.iInitialDriveLetter);
390 finder.RepairFileName();
391 test(0 == finder.iFileName->Compare(KTestFileName11));
392 fileName = KTestFileName256Chars;
393 finder.SetFileName(fileName);
394 test(0 <= finder.iFileName->MatchF(KExpectedFileName256Chars));
395 test(0 == finder.iSuffix.Compare(KExpectedSuffix1));
396 test(-1 == finder.iInitialDriveLetter);
397 finder.RepairFileName();
398 test(0 == finder.iFileName->Compare(KTestFileName256Chars));
400 // Test drive sequence construction
401 // AddCustomResourceDrive
402 finder.iCustomRscDrive = static_cast<TInt>(EDriveC); // drive c:
403 fileName = KTestFileName1;
404 finder.SetFileName(fileName);
405 test(finder.AddCustomResourceDrive() == KErrNone);
406 test(0 == finder.iDrives.CompareF(_L("CZ")));
407 fileName = KTestFileName3;
408 finder.SetFileName(fileName);
409 test(finder.AddCustomResourceDrive() == KErrNone);
410 test(0 == finder.iDrives.CompareF(_L("CA")));
411 fileName = KTestFileName4;
412 finder.SetFileName(fileName);
413 test(finder.AddCustomResourceDrive() == KErrAlreadyExists);
414 test(0 == finder.iDrives.CompareF(_L("C")));
415 fileName = KTestFileName5;
416 finder.SetFileName(fileName);
417 test(finder.AddCustomResourceDrive() == KErrNone);
418 test(0 == finder.iDrives.CompareF(_L("CD")));
419 fileName = KTestFileName6;
420 finder.SetFileName(fileName);
421 test(finder.AddCustomResourceDrive() == KErrNone);
422 test(0 == finder.iDrives.CompareF(_L("CY")));
423 fileName = KTestFileName7;
424 finder.SetFileName(fileName);
425 test(finder.AddCustomResourceDrive() == KErrNone);
426 test(0 == finder.iDrives.CompareF(_L("CA")));
427 fileName = KTestFileName8;
428 finder.SetFileName(fileName);
429 test(finder.AddCustomResourceDrive() == KErrAlreadyExists);
430 test(0 == finder.iDrives.CompareF(_L("C")));
431 fileName = KTestFileName9;
432 finder.SetFileName(fileName);
433 test(finder.AddCustomResourceDrive() == KErrNone);
434 test(0 == finder.iDrives.CompareF(_L("CY")));
436 fileName = KTestFileName1;
437 finder.SetFileName(fileName);
438 finder.AddAllDrives();
439 test(0 == finder.iDrives.CompareF(_L("ZYXWVUTSRQPONMLKJIHGFEDCBA")));
440 fileName = KTestFileName3;
441 finder.SetFileName(fileName);
442 finder.AddAllDrives();
443 test(0 == finder.iDrives.CompareF(_L("AYXWVUTSRQPONMLKJIHGFEDCBZ")));
444 fileName = KTestFileName4;
445 finder.SetFileName(fileName);
446 finder.AddAllDrives();
447 test(0 == finder.iDrives.CompareF(_L("CYXWVUTSRQPONMLKJIHGFEDBAZ")));
448 fileName = KTestFileName5;
449 finder.SetFileName(fileName);
450 finder.AddAllDrives();
451 test(0 == finder.iDrives.CompareF(_L("DYXWVUTSRQPONMLKJIHGFECBAZ")));
452 fileName = KTestFileName6;
453 finder.SetFileName(fileName);
454 finder.AddAllDrives();
455 test(0 == finder.iDrives.CompareF(_L("YXWVUTSRQPONMLKJIHGFEDCBAZ")));
456 fileName = KTestFileName7;
457 finder.SetFileName(fileName);
458 finder.AddAllDrives();
459 test(0 == finder.iDrives.CompareF(_L("AYXWVUTSRQPONMLKJIHGFEDCBZ")));
460 fileName = KTestFileName8;
461 finder.SetFileName(fileName);
462 finder.AddAllDrives();
463 test(0 == finder.iDrives.CompareF(_L("CYXWVUTSRQPONMLKJIHGFEDBAZ")));
464 fileName = KTestFileName9;
465 finder.SetFileName(fileName);
466 finder.AddAllDrives();
467 test(0 == finder.iDrives.CompareF(_L("YXWVUTSRQPONMLKJIHGFEDCBAZ")));
469 // Test addition of language number
470 // AppendLanguageCode
471 fileName = KTestFileName1;
472 finder.SetFileName(fileName);
473 finder.AppendLanguageCode(ELangFrench);
474 test(0 == finder.iFileName->CompareF(KTestFileName1French));
475 finder.SetFileName(fileName);
476 finder.AppendLanguageCode(ELangJapanese);
477 test(0 == finder.iFileName->CompareF(KTestFileName1Japanese));
478 finder.SetFileName(fileName);
479 finder.AppendLanguageCode(ELangAmericanSprint);
480 test(0 == finder.iFileName->CompareF(KTestFileName1AmericanSprint));
482 fileName = KTestFileName1;
483 finder.SetFileName(fileName);
484 finder.AppendLanguageCode(static_cast<TLanguage>(54321));
485 test(0 == finder.iFileName->CompareF(KTestFileName1Mongolian));
486 fileName = KTestFileName256Chars;
487 finder.SetFileName(fileName);
488 test(!finder.AppendLanguageCode(ELangFrench));
490 // Test searching each drive for the specified file
492 finder.iFileCheckedFor = KCheckedForFrench;
493 finder.iDrivesChecked = _L("D");
494 fileName = KTestFileName5;
495 finder.SetFileName(fileName);
496 finder.AppendLanguageCode(ELangFrench);
498 test(finder.iDrivesChecked.Length() == 0);
499 finder.SetFileName(fileName);
500 finder.AddAllDrives();
501 finder.iDrivesChecked = _L("dyxwvutsrqponmlkjihgfecbaz");
502 finder.AppendLanguageCode(ELangFrench);
504 test(finder.iDrivesChecked.Length() == 0);
505 fileName = KTestFileName5;
506 finder.SetFileName(fileName);
507 finder.AddAllDrives();
508 finder.iDrivesChecked = _L("dyxwvutsrqponmlkjihgfecbaz");
509 finder.AppendLanguageCode(ELangFrench);
510 finder.iFilesThatExist = new (ELeave) CDesCArraySeg(10);
511 finder.iFilesThatExist->AppendL(_L("o:\\dIR\\NAmE.E02"));
512 test(finder.FindDrive());
513 test(0 == finder.iFileName->CompareF(_L("O:\\dir\\name.e02")));
514 fileName = KTestFileName2;
515 finder.SetFileName(fileName);
516 finder.AppendLanguageCode(ELangFrench);
517 finder.AddAllDrives();
518 finder.iDrivesChecked = _L("zyxwvutsrqponmlkjihgfedcba");
519 finder.iFilesThatExist->AppendL(_L("v:\\dIR\\NA\x301mE.E02"));
520 //finder.iFileCheckedFor = _L("?:\\dir\\nÁme.e02");
521 finder.iFileCheckedFor = _L("?:\\dir\\n\u00c1me.e02");
522 test(finder.FindDrive());
523 //test(0 == finder.iFileName->CompareF(_L("v:\\dir\\nÁme.e02")));
524 test(0 == finder.iFileName->CompareF(_L("v:\\dir\\n\u00c1me.e02")));
525 delete finder.iFilesThatExist;
526 finder.iFilesThatExist = 0;
528 // Test searching language and drive down the language path
529 // FindLanguageAndDrive
530 finder.iPath[0] = static_cast<TLanguage>(2);
531 finder.iPath[1] = static_cast<TLanguage>(15702);
532 finder.iPath[2] = static_cast<TLanguage>(1);
533 finder.iPath[3] = ELangNone;
534 fileName = KTestFileName1;
535 finder.SetFileName(fileName);
536 SetUpFinderForLanguageAndDriveSearchL(finder);
537 finder.iFileCheckedFor = _L("?:\\dir\\name.e*");
538 test(!finder.FindLanguageAndDrive());
539 // check that iFileName is undamaged
540 finder.RepairFileName();
541 test(0 == finder.iFileName->CompareF(KTestFileName1));
542 delete finder.iFilesSearchedFor;
543 finder.iFilesThatExist = new (ELeave) CDesCArraySeg(10);
544 finder.iFilesThatExist->AppendL(_L("a:\\dir\\name.e15702"));
545 fileName = KTestFileName1;
546 finder.SetFileName(fileName);
547 SetUpFinderForLanguageAndDriveSearchL(finder);
548 test(finder.FindLanguageAndDrive());
549 test(0 == finder.iFileName->CompareF(_L("a:\\dir\\name.e15702")));
550 delete finder.iFilesSearchedFor;
551 finder.iFilesSearchedFor = 0;
553 finder.iPath[0] = static_cast<TLanguage>(7);
554 finder.iPath[1] = ELangNone;
555 finder.iFilesThatExist->AppendL(_L("g:\\dir\\name.ext"));
556 fileName = KTestFileName1;
557 finder.SetFileName(fileName);
558 finder.iDrives = _L("ZAG");
559 finder.iDrivesChecked = _L("ZAGZAG");
560 test(finder.FindLanguageAndDrive());
561 test(0 == finder.iFileName->CompareF(_L("g:\\dir\\name.ext")));
562 delete finder.iFilesThatExist;
563 finder.iFilesThatExist = 0;
565 // Test filename matching
566 // LanguageNumberFromFile
567 test(4 == TNearestLanguageFileFinder::LanguageNumberFromFile(_L("avb04"), _L("AVB")));
568 //test(4 == TNearestLanguageFileFinder::LanguageNumberFromFile(_L("ávb04"), _L("A\x301VB")));
569 //test(4 == TNearestLanguageFileFinder::LanguageNumberFromFile(_L("a\x301vb04"), _L("ÁVB")));
570 test(4 == TNearestLanguageFileFinder::LanguageNumberFromFile(_L("\u00e1vb04"), _L("A\x301VB")));
571 test(4 == TNearestLanguageFileFinder::LanguageNumberFromFile(_L("a\x301vb04"), _L("\u00c1VB")));
572 test(5254 == TNearestLanguageFileFinder::LanguageNumberFromFile(_L("avb5254"), _L("aVb")));
573 test(KErrNotFound == TNearestLanguageFileFinder::LanguageNumberFromFile(_L("avb04"), _L("avb04")));
574 test(KErrNotFound == TNearestLanguageFileFinder::LanguageNumberFromFile(_L("avb04"), _L("av")));
575 test(KErrNotFound == TNearestLanguageFileFinder::LanguageNumberFromFile(_L("avb04"), _L("")));
576 test(0 == TNearestLanguageFileFinder::LanguageNumberFromFile(_L("avb0000000"), _L("AVB00000")));
577 test(4 == TNearestLanguageFileFinder::LanguageNumberFromFile(_L("avb000000004"), _L("AVB0000000")));
578 test(100004 == TNearestLanguageFileFinder::LanguageNumberFromFile(_L("avb000100004"), _L("AVB000")));
579 test(111114 == TNearestLanguageFileFinder::LanguageNumberFromFile(_L("avb0111114"), _L("AVB0")));
581 // Test searching for any language file within a drive
582 // FindFirstLanguageFile
583 fileName = KTestFileName3;
584 finder.SetFileName(fileName);
585 finder.iFilesThatExist = new (ELeave) CDesCArraySeg(10);
586 finder.iFilesThatExist->AppendL(_L("a:\\dir\\name.e107"));
587 finder.iFilesThatExist->AppendL(_L("a:\\dir\\name.e07"));
588 finder.iFilesThatExist->AppendL(_L("a:\\dir\\name.e02"));
589 finder.iFilesThatExist->AppendL(_L("a:\\dir\\name.ee01"));
590 finder.iFilesThatExist->AppendL(_L("a:\\dir\\name.01"));
591 finder.iFilesThatExist->AppendL(_L("a:\\dir\\name01"));
592 finder.iFilesThatExist->AppendL(_L("a:\\dir\\name01.e01"));
593 finder.iFilesThatExist->AppendL(_L("a:\\dir\\name.e15108"));
594 finder.iFilesThatExist->AppendL(_L("a:\\dir\\name.e03"));
595 finder.iTestScanner.iDriveError[0] = KErrNoMemory;
596 fileName = KTestFileName3;
597 finder.SetFileName(fileName);
598 test(KErrNotFound == finder.FindFirstLanguageFile(dummy));
599 finder.iTestScanner.iDriveError[0] = KErrAbort;
600 fileName = KTestFileName3;
601 finder.SetFileName(fileName);
602 test(KErrNotFound == finder.FindFirstLanguageFile(dummy));
603 finder.iTestScanner.iDriveError[0] = KErrNone;
604 fileName = KTestFileName3;
605 finder.SetFileName(fileName);
606 test(0 <= finder.FindFirstLanguageFile(dummy));
607 test(0 == finder.iFileName->CompareF(_L("a:\\dir\\name.e02")));
609 finder.iFilesThatExist->AppendL(_L("a:\\abaffafg.100"));
610 finder.iFilesThatExist->AppendL(_L("a:\\abcdefg.9539"));
611 finder.iFilesThatExist->AppendL(_L("a:\\abcdefg.19539"));
612 finder.iFilesThatExist->AppendL(_L("a:\\abcdefg.1000"));
613 finder.iFilesThatExist->AppendL(_L("a:\\abaffafg.102"));
614 fileName = _L("a:\\abcdefg.xx");
615 finder.SetFileName(fileName);
616 test(0 <= finder.FindFirstLanguageFile(dummy));
617 test(0 == finder.iFileName->CompareF(_L("a:\\abcdefg.1000")));
618 finder.iFilesThatExist->AppendL(_L("a:\\abaffafg.aaa100"));
619 finder.iFilesThatExist->AppendL(_L("a:\\abcdefg.0523")); // not well-formed. Will not count.
620 finder.iFilesThatExist->AppendL(_L("a:\\abcdefg.1001"));
621 fileName = _L("a:\\abcdefg.xx");
622 finder.SetFileName(fileName);
623 test(0 <= finder.FindFirstLanguageFile(dummy));
624 test(0 == finder.iFileName->CompareF(_L("a:\\abcdefg.1000")));
625 fileName = _L("a:\\abaffafg.xx");
626 finder.SetFileName(fileName);
627 test(0 <= finder.FindFirstLanguageFile(dummy));
628 test(0 == finder.iFileName->CompareF(_L("a:\\abaffafg.100")));
629 finder.iFilesThatExist->AppendL(_L("a:\\abaffafg.09"));
630 fileName = _L("a:\\abaffafg.xx");
631 finder.SetFileName(fileName);
632 test(0 <= finder.FindFirstLanguageFile(dummy));
633 test(0 == finder.iFileName->CompareF(_L("a:\\abaffafg.09")));
635 // Test searching all drives for any language
636 // FindFirstLanguageFileAndDrive
637 finder.iFilesThatExist->AppendL(_L("z:\\abcdefg.05"));
638 fileName = _L("c:\\abcdefg.xx");
639 finder.SetFileName(fileName);
640 finder.iDrives = _L("az");
641 test(0 <= finder.FindFirstLanguageFileAndDrive());
642 test(0 == finder.iFileName->CompareF(_L("a:\\abcdefg.1000")));
643 fileName = _L("c:\\abaffafg.xx");
644 finder.SetFileName(fileName);
645 finder.iDrives = _L("az");
646 test(0 <= finder.FindFirstLanguageFileAndDrive());
647 test(0 == finder.iFileName->CompareF(_L("a:\\abaffafg.09")));
648 fileName = _L("c:\\abcdefg.xx");
649 finder.SetFileName(fileName);
650 finder.iDrives = _L("za");
651 test(0 <= finder.FindFirstLanguageFileAndDrive());
652 test(0 == finder.iFileName->CompareF(_L("z:\\abcdefg.05")));
653 fileName = _L("c:\\xxx.xx");
654 finder.SetFileName(fileName);
655 finder.iDrives = _L("za");
656 test(KErrNotFound == finder.FindFirstLanguageFileAndDrive());
657 finder.iTestScanner.iDriveError[25] = KErrAbort;
658 fileName = _L("c:\\abcdefg.xx");
659 finder.SetFileName(fileName);
660 finder.iDrives = _L("za");
661 test(0 <= finder.FindFirstLanguageFileAndDrive());
662 test(0 == finder.iFileName->CompareF(_L("a:\\abcdefg.1000")));
663 fileName = _L("c:\\abcdefg.xx");
664 finder.SetFileName(fileName);
665 finder.iDrives = _L("za");
666 finder.iTestScanner.iDriveError[0] = KErrNoMemory;
667 test(KErrNotFound == finder.FindFirstLanguageFileAndDrive());
668 fileName = _L("c:\\abcdefg.xx");
669 finder.SetFileName(fileName);
670 finder.iDrives = _L("za");
671 finder.iTestScanner.iDriveError[0] = KErrAbort;
672 test(KErrNotFound == finder.FindFirstLanguageFileAndDrive());
677 @SYMTestCaseID SYSLIB-BAFL-CT-0447
678 @SYMTestCaseDesc Tests for defect number DEF039977
679 @SYMTestPriority High
680 @SYMTestActions Test for Panic in BaflUtils::DiskIsReadOnly()
681 when unexpected parameter supplied
682 @SYMTestExpectedResults Test must not fail
685 void TestforDEF039977()
687 test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0447 "));
692 TInt err=fileserver.Connect();
696 theRes=BaflUtils::DiskIsReadOnly(fileserver,filename,readOnly);
697 test(theRes==KErrBadName);
700 theRes=BaflUtils::DiskIsReadOnly(fileserver,filename,readOnly);
701 test(theRes==KErrBadName);
704 theRes=BaflUtils::DiskIsReadOnly(fileserver,filename,readOnly);
705 test(theRes==KErrBadName);
708 theRes=BaflUtils::DiskIsReadOnly(fileserver,filename,readOnly);
709 test(theRes==KErrNotReady);
712 theRes=BaflUtils::DiskIsReadOnly(fileserver,filename,readOnly);
713 test(theRes==KErrNone);
717 theRes=BaflUtils::DiskIsReadOnly(fileserver,filename,readOnly);
718 test(theRes==KErrNone);
722 theRes=BaflUtils::DiskIsReadOnly(fileserver,filename,readOnly);
723 test(theRes==KErrNone);
725 filename=_L("z:\\system\\data\\");
726 theRes=BaflUtils::DiskIsReadOnly(fileserver,filename,readOnly);
727 test(theRes==KErrNone);
733 @SYMTestCaseID SYSLIB-BAFL-CT-1284
734 @SYMTestCaseDesc Tests for invalid character
735 @SYMTestPriority High
736 @SYMTestActions Test for panic when an invalid character when
737 supplied to BaflUtils::RootFolderPath's parameter as drive letter
738 @SYMTestExpectedResults Test must not fail
741 TInt TestforInvalidCharacter(TAny* /*aData*/)
743 This is a root thread function which runs as part of the TestforDEF040198().
744 It tests a panic is produced when an invalid non alphabet character is supplied
745 in the aDriveLetter argument in BaflUtils::RootFolderPath(const TBuf<1> aDriveLetter)
748 TBuf<1> buf1=_L("?");
750 retValue=BaflUtils::RootFolderPath(buf1);
752 // Line above panics if working OK, so should never get here.
758 This method is a test case to demonstrate the fix for DEF040198 by supplying an invalid
759 input aDriveLetter argument (e.g "?") to BaflUtils::RootFolderPath(aDriveLetter).
761 @SYMTestCaseID SYSLIB-BAFL-CT-0448
762 @SYMTestCaseDesc Tests for defect number DEF040198
763 @SYMTestPriority High
764 @SYMTestActions Check by giving an invalid aDriveLetter argument
765 @SYMTestExpectedResults Test must not fail
768 void TestforDEF040198()
770 test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0448 "));
771 //Check invalid aDriveLetter argument panics with panic code EBaflPanicBadOpenArg
773 TRequestStatus threadStatus;
775 _LIT(KThreadName,"ThreadTest");
778 jit=User::JustInTime();
779 User::SetJustInTime(EFalse);
781 test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-1284 "));
782 rc=thread.Create(KThreadName,TestforInvalidCharacter,KDefaultStackSize,KMinHeapSize,KMinHeapSize*4,NULL);
784 thread.Logon(threadStatus);
786 User::WaitForRequest(threadStatus);
787 test (thread.ExitType()==EExitPanic);
788 test (thread.ExitReason()==EBafPanicBadOpenArg);
790 User::SetJustInTime(jit);
795 @SYMTestCaseID SYSLIB-BAFL-CT-1285
796 @SYMTestCaseDesc Tests for invalid path name
797 @SYMTestPriority High
798 @SYMTestActions Test for panic when an invalid character supplied to BaflUtils::RootFolderPath's parameter as drive letter
799 @SYMTestExpectedResults Test must not fail
802 TInt TestforInvalidPathName(TAny* /*aData*/)
804 This is a root thread function which runs as part of the TestforDEF040299().
805 It tests a panic is produced when an invalid name is supplied
806 in the aFullName argument in BaflUtils::FolderNameFromFullName(const TDesC& aFullName)
809 TBuf<1> buf1=_L("?");
811 retValue=BaflUtils::FolderNameFromFullName(buf1);
813 // Line above panics if working OK, so should never get here.
819 @SYMTestCaseID SYSLIB-BAFL-CT-0449
820 @SYMTestCaseDesc Tests for defect number DEF047305
821 @SYMTestPriority High
822 @SYMTestActions Test for correct syntax
823 @SYMTestExpectedResults Test must not fail
826 void TestForDEF047305()
828 test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0449 "));
830 CleanupClosePushL(aFs);
831 User::LeaveIfError(aFs.Connect());
833 TFileName newFolderFullName = KCurrentPath;
835 test(User::LeaveIfError(BaflUtils::ValidateFolderNameTypedByUserL(aFs, KValFolderName, KCurrentPath, newFolderFullName)==KErrNone));
836 test(User::LeaveIfError(BaflUtils::ValidateFolderNameTypedByUserL(aFs, KNoFolderName, KCurrentPath, newFolderFullName)==KErrArgument));
837 test(User::LeaveIfError(BaflUtils::ValidateFolderNameTypedByUserL(aFs, KInValidFolderName, KCurrentPath, newFolderFullName)==KErrBadName));
839 CleanupStack::PopAndDestroy(&aFs);
843 @SYMTestCaseID SYSLIB-BAFL-CT-0450
844 @SYMTestCaseDesc Tests for defect number DEF040299
845 @SYMTestPriority High
846 @SYMTestActions Test by supplying an invalid input aFullName argument to BaflUtils::FolderNameFromFullName(aFullName)
847 @SYMTestExpectedResults Test must not fail
850 void TestforDEF040299()
852 test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0450 "));
858 fileName=BaflUtils::FolderNameFromFullName(buf);
863 fileName=BaflUtils::FolderNameFromFullName(buf);
866 //Path name="c:\\file.txt"
867 buf=_L("c:\\file.txt");
868 fileName=BaflUtils::FolderNameFromFullName(buf);
869 test(fileName==_L("c:\\"));
871 //Path name="c:\\system\\file.txt"
872 buf=_L("c:\\system\\file.txt");
873 fileName=BaflUtils::FolderNameFromFullName(buf);
874 test(fileName==_L("system"));
877 This method is a test case to demonstrate the fix for DEF040299 by supplying an invalid
878 input aFullName argument (e.g "?") to BaflUtils::FolderNameFromFullName(aFullName).
880 //Check invalid aFullName argument panics with panic code EBaflPanicBadOpenArg
882 TRequestStatus threadStatus;
884 //Tread name is changed due to test failing on slow machine
885 //Using "TreadTest" here are causing KErrAlreadyExist at tread creating stage.
886 //This is because the previous tread maybe still being closed when this thread is created.
887 _LIT(KThreadName,"ThreadTest1");
890 jit=User::JustInTime();
891 User::SetJustInTime(EFalse);
892 test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-1285 "));
893 rc=thread.Create(KThreadName,TestforInvalidPathName,KDefaultStackSize,KMinHeapSize,KMinHeapSize*4,NULL);
895 thread.Logon(threadStatus);
897 User::WaitForRequest(threadStatus);
898 test (thread.ExitType()==EExitPanic);
899 test (thread.ExitReason()==EBafPanicBadOpenArg);
901 User::SetJustInTime(jit);
907 @SYMTestCaseID SYSLIB-BAFL-CT-3416
908 @SYMTestCaseDesc Tests for defect number DEF101927
909 @SYMTestPriority High
910 @SYMTestActions Test the simulated Tls functionalities Dll::Tls, Dll::SetTls and Dll::FreeTls
911 which is needed for BAUtils.cpp to be complied as part of an .exe.
912 Dll::Tls - Recalls the value currently referred to by the Tls pointer
913 Dll::SetTls - Sets the the values referred to by the Tls pointer
914 Dll::FreeTls - Sets the Tls pointer to NULL
915 @SYMTestExpectedResults Pass if the TLanguage values is returned as expected after calls to IdealLanguage,
916 SetIdealLanguage and ReleaseIdealLanguage.
919 void TestForDEF101927()
921 test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-3416 "));
922 TLanguage test_language(ELangAmerican);
924 test(BaflUtils::IdealLanguage()==ELangNone);
926 BaflUtils::SetIdealLanguage(ELangAmerican);
927 test(test_language == ELangAmerican);
929 test_language = ELangNone;
930 test_language = BaflUtils::IdealLanguage();
931 test(test_language == ELangAmerican);
933 BaflUtils::ReleaseIdealLanguage();
934 test_language = BaflUtils::IdealLanguage();
935 test(test_language == ELangNone);
939 @SYMTestCaseID SYSLIB-BAFL-UT-3667
940 @SYMTestCaseDesc Tests for defect number DEF109928
941 @SYMTestPriority Normal
942 @SYMTestActions Test for the extended NextLanguage(). Check if the MakeLanguageDowngradePath()
943 can now return the correct default fallback for the languages which are newly
944 added into the NextLanguage().
945 @SYMTestExpectedResults Test must not fail
948 void TestForDEF109928()
950 test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-UT-3667 "));
951 TLanguage testDeviceLangs[8] = {ELangEnglish_Japan, ELangSwissFrench, ELangSwissGerman,
952 ELangLatinAmericanSpanish, ELangSwissItalian, ELangFinlandSwedish,
953 ELangMalay_Apac, ELangBrazilianPortuguese};
954 TLanguagePath testOutputPath[8] = {{ELangEnglish_Japan, ELangEnglish}, {ELangSwissFrench, ELangFrench},
955 {ELangSwissGerman, ELangGerman}, {ELangLatinAmericanSpanish, ELangSpanish},
956 {ELangSwissItalian, ELangItalian}, {ELangFinlandSwedish, ELangSwedish},
957 {ELangMalay_Apac, ELangMalay}, {ELangBrazilianPortuguese, ELangPortuguese}};
959 loc.SetLanguageDowngrade(0, ELangNone);
960 loc.SetLanguageDowngrade(1, ELangNone);
961 loc.SetLanguageDowngrade(2, ELangNone);
965 for(TInt i = 0; i < 8 ; i++)
967 testlang = testDeviceLangs[i];
968 MakeLanguageDowngradePath(path, testlang, ELangNone, loc);
969 test(path[0] == testOutputPath[i][0]);
970 test(path[1] == testOutputPath[i][1]);
971 test(path[2] == ELangNone);
975 /* The following 3 function is defined so that the functions IdealLanguage,
976 SetIdealLanguage, ReleaseIdealLanguage will compile as part as an .exe
977 These functions use a global TAny* to store the data that would have been
978 stored in the TLS under normal compilation (ie If the BaUtils was compilled
989 TInt Dll::SetTls(TAny* aPtr)
1005 test.Start(_L("BaflUtils Internal Tests: "));
1008 TestMakeLanguageDowngradePath();
1009 TestNearestLanguageFinder();
1019 __UHEAP_MARKENDC(0);
1024 TrapCleanup = CTrapCleanup::New();
1025 TRAPD(err, RunTestsL());
1026 test(err == KErrNone);