First public contribution.
1 // Copyright (c) 1997-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.
16 #include "t_langutilsimp.h"
21 TBool __bb = (cond); \
25 ERR_PRINTF1(_L("ERROR: Test Failed")); \
32 void CT_LANGUTILSIMP::TestPath(const TLanguagePath& aPath, const TLanguage* aExpected, TInt aExpectedCount)
34 for (int i = 0; i != aExpectedCount; ++i)
35 test(aPath[i] == *aExpected++);
36 test(aPath[aExpectedCount] == ELangNone);
39 const TLanguage ExpectedPath[] = { ELangFrench, ELangJapanese, ELangGerman, ELangGreek,
40 ELangArabic, ELangEnglish, ELangItalian, ELangHebrew };
43 @SYMTestCaseID SYSLIB-BAFL-CT-0443
44 @SYMTestCaseDesc Tests TLanguagePath class
46 @SYMTestActions Test for adding different language paths
47 @SYMTestExpectedResults Test must not fail
50 void CT_LANGUTILSIMP::TestAddLanguage()
52 INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0443 "));
55 AddLanguage(path, ELangNone);
56 TestPath(path, ExpectedPath, 0);
57 AddLanguage(path, ELangFrench);
58 TestPath(path, ExpectedPath, 1);
59 AddLanguage(path, ELangFrench);
60 TestPath(path, ExpectedPath, 1);
61 AddLanguage(path, ELangNone);
62 TestPath(path, ExpectedPath, 1);
63 AddLanguage(path, ELangFrench);
64 TestPath(path, ExpectedPath, 1);
65 AddLanguage(path, ELangJapanese);
66 TestPath(path, ExpectedPath, 2);
67 AddLanguage(path, ELangFrench);
68 TestPath(path, ExpectedPath, 2);
69 AddLanguage(path, ELangNone);
70 TestPath(path, ExpectedPath, 2);
71 AddLanguage(path, ELangGerman);
72 TestPath(path, ExpectedPath, 3);
73 AddLanguage(path, ELangGreek);
74 TestPath(path, ExpectedPath, 4);
75 AddLanguage(path, ELangArabic);
76 TestPath(path, ExpectedPath, 5);
77 AddLanguage(path, ELangNone);
78 TestPath(path, ExpectedPath, 5);
79 AddLanguage(path, ELangEnglish);
80 TestPath(path, ExpectedPath, 6);
81 AddLanguage(path, ELangItalian);
82 TestPath(path, ExpectedPath, 7);
83 AddLanguage(path, ELangNone);
84 TestPath(path, ExpectedPath, 7);
85 AddLanguage(path, ELangHebrew);
86 TestPath(path, ExpectedPath, 8);
87 AddLanguage(path, ELangHebrew);
88 TestPath(path, ExpectedPath, 8);
89 AddLanguage(path, ELangEnglish);
90 TestPath(path, ExpectedPath, 8);
91 AddLanguage(path, ELangItalian);
92 TestPath(path, ExpectedPath, 8);
93 AddLanguage(path, ELangNone);
94 TestPath(path, ExpectedPath, 8);
95 AddLanguage(path, ELangFrench);
96 TestPath(path, ExpectedPath, 8);
97 AddLanguage(path, ELangNone);
98 TestPath(path, ExpectedPath, 8);
99 AddLanguage(path, ELangGerman);
100 TestPath(path, ExpectedPath, 8);
106 @SYMTestCaseID SYSLIB-BAFL-CT-0444
107 @SYMTestCaseDesc Tests for the functionality of TLocale class
108 @SYMTestPriority High
109 @SYMTestActions Test for language downgrades
110 @SYMTestExpectedResults Test must not fail
113 void CT_LANGUTILSIMP::TestDowngrade(SDowngradeTest& aTest)
115 INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0444 "));
117 loc.SetLanguageDowngrade(0, aTest.iIn[1]);
118 loc.SetLanguageDowngrade(1, aTest.iIn[2]);
119 loc.SetLanguageDowngrade(2, aTest.iIn[3]);
121 MakeLanguageDowngradePath(path, aTest.iIn[0], ELangNone, loc);
122 for (int i = 0; ; ++i)
125 test(aTest.iOut[i] == path[i]);
126 if (path[i] == ELangNone)
130 MakeLanguageDowngradePath(path, ELangAustralian, ELangNone, loc);
131 MakeLanguageDowngradePath(path, ELangNewZealand, ELangNone, loc);
132 MakeLanguageDowngradePath(path, ELangSouthAfricanEnglish, ELangNone, loc);
133 MakeLanguageDowngradePath(path, ELangInternationalEnglish, ELangNone, loc);
134 MakeLanguageDowngradePath(path, ELangAmerican, ELangNone, loc);
135 MakeLanguageDowngradePath(path, ELangEnglish_Apac, ELangNone, loc);
136 MakeLanguageDowngradePath(path, ELangEnglish_Taiwan, ELangNone, loc);
137 MakeLanguageDowngradePath(path, ELangEnglish_HongKong, ELangNone, loc);
138 MakeLanguageDowngradePath(path, ELangEnglish_Prc, ELangNone, loc);
139 MakeLanguageDowngradePath(path, ELangEnglish_Japan, ELangNone, loc);
140 MakeLanguageDowngradePath(path, ELangEnglish_Thailand, ELangNone, loc);
141 MakeLanguageDowngradePath(path, ELangSwissFrench, ELangNone, loc);
142 MakeLanguageDowngradePath(path, ELangBelgianFrench, ELangNone, loc);
143 MakeLanguageDowngradePath(path, ELangInternationalFrench, ELangNone, loc);
144 MakeLanguageDowngradePath(path, ELangCanadianFrench, ELangNone, loc);
145 MakeLanguageDowngradePath(path, ELangSwissGerman, ELangNone, loc);
146 MakeLanguageDowngradePath(path, ELangAustrian, ELangNone, loc);
147 MakeLanguageDowngradePath(path, ELangInternationalSpanish, ELangNone, loc);
148 MakeLanguageDowngradePath(path, ELangLatinAmericanSpanish, ELangNone, loc);
149 MakeLanguageDowngradePath(path, ELangSwissItalian, ELangNone, loc);
150 MakeLanguageDowngradePath(path, ELangFinlandSwedish, ELangNone, loc);
151 MakeLanguageDowngradePath(path, ELangCyprusTurkish, ELangNone, loc);
152 MakeLanguageDowngradePath(path, ELangBelgianFlemish, ELangNone, loc);
153 MakeLanguageDowngradePath(path, ELangHongKongChinese, ELangNone, loc);
154 MakeLanguageDowngradePath(path, ELangCyprusGreek, ELangNone, loc);
155 MakeLanguageDowngradePath(path, ELangMalay_Apac, ELangNone, loc);
156 MakeLanguageDowngradePath(path, ELangBrazilianPortuguese, ELangNone, loc);
161 // Test Dialect enumeration.
162 // Each value represents a dialect (variant) of a TLanguage language.
163 // E.g. AmericanSprint is represented by ELangAmerican | EDialectSprint
165 // The dialect location -- top six bits
166 const TUint KDialectFactor=0x0400;
169 // The following are example dialects for testing only
170 EDialectSprint = (1*KDialectFactor),
171 EDialectOrange = (2*KDialectFactor),
172 EDialectMaximum = EDialectOrange // This must always be equal to the last TDialect enum.
173 // Up to 63 dialects.
176 const TLanguage ELangEnglishOrange = static_cast<TLanguage>(ELangEnglish|EDialectOrange);
177 const TLanguage ELangAmericanSprint = static_cast<TLanguage>(ELangAmerican|EDialectSprint);
179 SDowngradeTest DowngradeData[] =
182 // 1-3 = language downgrade for locale
183 // 4- = calculated language downgrade path, terminated with ELangNone.
184 {{ELangEnglishOrange, ELangNone, ELangNone, ELangNone},
185 {ELangEnglishOrange, ELangEnglish, ELangNone}},
186 {{ELangAmericanSprint, ELangNone, ELangNone, ELangNone},
187 {ELangAmericanSprint, ELangAmerican, ELangEnglish, ELangNone}},
188 {{ELangFrench, ELangNone, ELangNone, ELangNone},
189 {ELangFrench, ELangNone}},
190 {{ELangSwissFrench, ELangNone, ELangNone, ELangNone},
191 {ELangSwissFrench, ELangFrench, ELangNone}},
192 {{ELangCanadianEnglish, ELangNone, ELangNone, ELangNone},
193 {ELangCanadianEnglish, ELangAmerican, ELangEnglish, ELangNone}},
194 {{ELangSwissFrench, ELangNone, ELangFrench, ELangNone},
195 {ELangSwissFrench, ELangFrench, ELangNone}},
196 {{ELangCanadianEnglish, ELangEnglish, ELangNone, ELangAmerican},
197 {ELangCanadianEnglish, ELangEnglish, ELangAmerican, ELangNone}},
198 {{ELangCanadianEnglish, ELangNone, ELangNone, ELangSwissFrench},
199 {ELangCanadianEnglish, ELangSwissFrench, ELangAmerican, ELangEnglish, ELangNone}},
200 {{ELangCanadianEnglish, ELangFrench, ELangAmerican, ELangSwissFrench},
201 {ELangCanadianEnglish, ELangFrench, ELangAmerican, ELangSwissFrench, ELangEnglish, ELangNone}},
202 {{ELangCanadianEnglish, ELangNone, ELangGerman, ELangSwissFrench},
203 {ELangCanadianEnglish, ELangGerman, ELangSwissFrench, ELangAmerican, ELangEnglish, ELangNone}},
204 {{ELangCanadianEnglish, ELangFinlandSwedish, ELangGerman, ELangSwissFrench},
205 {ELangCanadianEnglish, ELangFinlandSwedish, ELangGerman, ELangSwissFrench, ELangAmerican, ELangEnglish, ELangNone}},
206 {{ELangFinlandSwedish, ELangFinlandSwedish, ELangFinlandSwedish, ELangFinlandSwedish},
207 {ELangFinlandSwedish, ELangSwedish, ELangNone}},
211 @SYMTestCaseID SYSLIB-BAFL-CT-0445
212 @SYMTestCaseDesc Tests for language downgrades
213 @SYMTestPriority High
214 @SYMTestActions Call up downgrade path test function
215 @SYMTestExpectedResults Test must not fail
218 void CT_LANGUTILSIMP::TestMakeLanguageDowngradePath()
220 INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0445 "));
221 for (int i = 0; i != sizeof(DowngradeData)/sizeof(DowngradeData[0]); ++i)
222 TestDowngrade(DowngradeData[i]);
225 void CT_LANGUTILSIMP::SetUpFinderForLanguageAndDriveSearchL(
226 TTestNearestLanguageFileFinder& aFinder)
228 aFinder.iDrives = _L("ZAG");
229 aFinder.iFilesSearchedFor = new(ELeave) CDesCArraySeg(10);
230 aFinder.iFilesSearchedFor->AppendL(_L("z:\\dir\\name.e02"));
231 aFinder.iFilesSearchedFor->AppendL(_L("a:\\dir\\name.e02"));
232 aFinder.iFilesSearchedFor->AppendL(_L("g:\\dir\\name.e02"));
233 aFinder.iFilesSearchedFor->AppendL(_L("z:\\dir\\name.e15702")); //Extended lang
234 aFinder.iFilesSearchedFor->AppendL(_L("a:\\dir\\name.e15702"));
235 aFinder.iFilesSearchedFor->AppendL(_L("g:\\dir\\name.e15702"));
236 aFinder.iFilesSearchedFor->AppendL(_L("z:\\dir\\name.e01"));
237 aFinder.iFilesSearchedFor->AppendL(_L("a:\\dir\\name.e01"));
238 aFinder.iFilesSearchedFor->AppendL(_L("g:\\dir\\name.e01"));
239 aFinder.iFilesSearchedFor->AppendL(_L("z:\\dir\\name.ext"));
240 aFinder.iFilesSearchedFor->AppendL(_L("a:\\dir\\name.ext"));
241 aFinder.iFilesSearchedFor->AppendL(_L("g:\\dir\\name.ext"));
242 aFinder.iDrivesChecked = _L("zagzagzagzagzag");
245 _LIT(KTestFileName1, "z:\\dir\\name.ext");
246 //_LIT(KTestFileName2, "z:\\dir\\náme.ext");
247 _LIT(KTestFileName2, "z:\\dir\\n\u00c1me.ext");
248 _LIT(KTestFileName3, "a:\\dir\\name.ext");
249 _LIT(KTestFileName4, "c:\\dir\\name.ext");
250 _LIT(KTestFileName5, "d:\\dir\\name.ext");
251 _LIT(KTestFileName6, "y:\\dir\\name.ext");
252 _LIT(KTestFileName7, "A:\\dir\\name.ext");
253 _LIT(KTestFileName8, "C:\\dir\\name.ext");
254 _LIT(KTestFileName9, "Y:\\dir\\name.ext");
255 _LIT(KTestFileName11, "\\abc\\defg.hijkl");
256 _LIT(KTestFileName256Chars, "\
257 \\abcdefghijklmnopqrstuvwxyz01234\\abcdefghijklmnopqrstuvwxyz01234\
258 \\abcdefghijklmnopqrstuvwxyz01234\\abcdefghijklmnopqrstuvwxyz01234\
259 \\abcdefghijklmnopqrstuvwxyz01234\\abcdefghijklmnopqrstuvwxyz01234\
260 \\abcdefghijklmnopqrstuvwxyz01234\\abcdefghijklmnopqrstuvwxyz0.ext");
262 _LIT(KExpectedFileName256Chars, "?:\
263 \\abcdefghijklmnopqrstuvwxyz01234\\abcdefghijklmnopqrstuvwxyz01234\
264 \\abcdefghijklmnopqrstuvwxyz01234\\abcdefghijklmnopqrstuvwxyz01234\
265 \\abcdefghijklmnopqrstuvwxyz01234\\abcdefghijklmnopqrstuvwxyz01234\
266 \\abcdefghijklmnopqrstuvwxyz01234\\abcdefghijklmnopqrstuvwxyz0.e");
267 _LIT(KExpectedFileName1, "?:\\dir\\name.e");
268 _LIT(KExpectedSuffix1, "xt");
269 _LIT(KExpectedFileName2, "?:\\abc\\defg.hij");
270 _LIT(KExpectedSuffix2, "kl");
271 _LIT(KTestFileName1French, "z:\\dir\\name.e02");
272 _LIT(KTestFileName1Japanese, "z:\\dir\\name.e32");
273 _LIT(KTestFileName1Mongolian, "z:\\dir\\name.e54321");
274 _LIT(KTestFileName1AmericanSprint, "z:\\dir\\name.e1034"); //American=0x0A, Sprint=0x0400. 0x040A=1034.
275 _LIT(KCheckedForFrench, "?:\\dir\\name.e02");
278 @SYMTestCaseID SYSLIB-BAFL-CT-0446
279 @SYMTestCaseDesc Nearest language finder test
280 @SYMTestPriority High
281 @SYMTestActions Test drive sequence construction
282 Test addition of language number
283 Test searching each drive for the specified file
284 Test searching language and drive down the language path
285 Test filename matching
286 Test searching for any language file within a drive
287 Test searching all drives for any language
288 @SYMTestExpectedResults Test must not fail
291 void CT_LANGUTILSIMP::TestNearestLanguageFinder()
293 INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0446 "));
295 TTestNearestLanguageFileFinder finder(dummy);
297 // Test file name setting and disecting
300 TFileName fileName(KTestFileName1);
301 finder.SetFileName(fileName);
302 test(0 <= finder.iFileName->MatchF(KExpectedFileName1));
303 test(0 == finder.iSuffix.Compare(KExpectedSuffix1));
304 test('z' == finder.iInitialDriveLetter);
305 finder.RepairFileName();
306 test(0 == finder.iFileName->Compare(KTestFileName1));
307 fileName = KTestFileName11;
308 finder.SetFileName(fileName);
309 test(0 <= finder.iFileName->MatchF(KExpectedFileName2));
310 test(0 == finder.iSuffix.Compare(KExpectedSuffix2));
311 test(-1 == finder.iInitialDriveLetter);
312 finder.RepairFileName();
313 test(0 == finder.iFileName->Compare(KTestFileName11));
314 fileName = KTestFileName256Chars;
315 finder.SetFileName(fileName);
316 test(0 <= finder.iFileName->MatchF(KExpectedFileName256Chars));
317 test(0 == finder.iSuffix.Compare(KExpectedSuffix1));
318 test(-1 == finder.iInitialDriveLetter);
319 finder.RepairFileName();
320 test(0 == finder.iFileName->Compare(KTestFileName256Chars));
322 // Test drive sequence construction
323 // AddCustomResourceDrive
324 finder.iCustomRscDrive = static_cast<TInt>(EDriveC); // drive c:
325 fileName = KTestFileName1;
326 finder.SetFileName(fileName);
327 test(finder.AddCustomResourceDrive() == KErrNone);
328 test(0 == finder.iDrives.CompareF(_L("CZ")));
329 fileName = KTestFileName3;
330 finder.SetFileName(fileName);
331 test(finder.AddCustomResourceDrive() == KErrNone);
332 test(0 == finder.iDrives.CompareF(_L("CA")));
333 fileName = KTestFileName4;
334 finder.SetFileName(fileName);
335 test(finder.AddCustomResourceDrive() == KErrAlreadyExists);
336 test(0 == finder.iDrives.CompareF(_L("C")));
337 fileName = KTestFileName5;
338 finder.SetFileName(fileName);
339 test(finder.AddCustomResourceDrive() == KErrNone);
340 test(0 == finder.iDrives.CompareF(_L("CD")));
341 fileName = KTestFileName6;
342 finder.SetFileName(fileName);
343 test(finder.AddCustomResourceDrive() == KErrNone);
344 test(0 == finder.iDrives.CompareF(_L("CY")));
345 fileName = KTestFileName7;
346 finder.SetFileName(fileName);
347 test(finder.AddCustomResourceDrive() == KErrNone);
348 test(0 == finder.iDrives.CompareF(_L("CA")));
349 fileName = KTestFileName8;
350 finder.SetFileName(fileName);
351 test(finder.AddCustomResourceDrive() == KErrAlreadyExists);
352 test(0 == finder.iDrives.CompareF(_L("C")));
353 fileName = KTestFileName9;
354 finder.SetFileName(fileName);
355 test(finder.AddCustomResourceDrive() == KErrNone);
356 test(0 == finder.iDrives.CompareF(_L("CY")));
358 fileName = KTestFileName1;
359 finder.SetFileName(fileName);
360 finder.AddAllDrives();
361 test(0 == finder.iDrives.CompareF(_L("ZYXWVUTSRQPONMLKJIHGFEDCBA")));
362 fileName = KTestFileName3;
363 finder.SetFileName(fileName);
364 finder.AddAllDrives();
365 test(0 == finder.iDrives.CompareF(_L("AYXWVUTSRQPONMLKJIHGFEDCBZ")));
366 fileName = KTestFileName4;
367 finder.SetFileName(fileName);
368 finder.AddAllDrives();
369 test(0 == finder.iDrives.CompareF(_L("CYXWVUTSRQPONMLKJIHGFEDBAZ")));
370 fileName = KTestFileName5;
371 finder.SetFileName(fileName);
372 finder.AddAllDrives();
373 test(0 == finder.iDrives.CompareF(_L("DYXWVUTSRQPONMLKJIHGFECBAZ")));
374 fileName = KTestFileName6;
375 finder.SetFileName(fileName);
376 finder.AddAllDrives();
377 test(0 == finder.iDrives.CompareF(_L("YXWVUTSRQPONMLKJIHGFEDCBAZ")));
378 fileName = KTestFileName7;
379 finder.SetFileName(fileName);
380 finder.AddAllDrives();
381 test(0 == finder.iDrives.CompareF(_L("AYXWVUTSRQPONMLKJIHGFEDCBZ")));
382 fileName = KTestFileName8;
383 finder.SetFileName(fileName);
384 finder.AddAllDrives();
385 test(0 == finder.iDrives.CompareF(_L("CYXWVUTSRQPONMLKJIHGFEDBAZ")));
386 fileName = KTestFileName9;
387 finder.SetFileName(fileName);
388 finder.AddAllDrives();
389 test(0 == finder.iDrives.CompareF(_L("YXWVUTSRQPONMLKJIHGFEDCBAZ")));
391 // Test addition of language number
392 // AppendLanguageCode
393 fileName = KTestFileName1;
394 finder.SetFileName(fileName);
395 finder.AppendLanguageCode(ELangFrench);
396 test(0 == finder.iFileName->CompareF(KTestFileName1French));
397 finder.SetFileName(fileName);
398 finder.AppendLanguageCode(ELangJapanese);
399 test(0 == finder.iFileName->CompareF(KTestFileName1Japanese));
400 finder.SetFileName(fileName);
401 finder.AppendLanguageCode(ELangAmericanSprint);
402 test(0 == finder.iFileName->CompareF(KTestFileName1AmericanSprint));
404 fileName = KTestFileName1;
405 finder.SetFileName(fileName);
406 finder.AppendLanguageCode(static_cast<TLanguage>(54321));
407 test(0 == finder.iFileName->CompareF(KTestFileName1Mongolian));
408 fileName = KTestFileName256Chars;
409 finder.SetFileName(fileName);
410 test(!finder.AppendLanguageCode(ELangFrench));
412 // Test searching each drive for the specified file
414 finder.iFileCheckedFor = KCheckedForFrench;
415 finder.iDrivesChecked = _L("D");
416 fileName = KTestFileName5;
417 finder.SetFileName(fileName);
418 finder.AppendLanguageCode(ELangFrench);
420 test(finder.iDrivesChecked.Length() == 0);
421 finder.SetFileName(fileName);
422 finder.AddAllDrives();
423 finder.iDrivesChecked = _L("dyxwvutsrqponmlkjihgfecbaz");
424 finder.AppendLanguageCode(ELangFrench);
426 test(finder.iDrivesChecked.Length() == 0);
427 fileName = KTestFileName5;
428 finder.SetFileName(fileName);
429 finder.AddAllDrives();
430 finder.iDrivesChecked = _L("dyxwvutsrqponmlkjihgfecbaz");
431 finder.AppendLanguageCode(ELangFrench);
432 finder.iFilesThatExist = new (ELeave) CDesCArraySeg(10);
433 finder.iFilesThatExist->AppendL(_L("o:\\dIR\\NAmE.E02"));
434 test(finder.FindDrive());
435 test(0 == finder.iFileName->CompareF(_L("O:\\dir\\name.e02")));
436 fileName = KTestFileName2;
437 finder.SetFileName(fileName);
438 finder.AppendLanguageCode(ELangFrench);
439 finder.AddAllDrives();
440 finder.iDrivesChecked = _L("zyxwvutsrqponmlkjihgfedcba");
441 finder.iFilesThatExist->AppendL(_L("v:\\dIR\\NA\x301mE.E02"));
442 //finder.iFileCheckedFor = _L("?:\\dir\\nÁme.e02");
443 finder.iFileCheckedFor = _L("?:\\dir\\n\u00c1me.e02");
444 test(finder.FindDrive());
445 //test(0 == finder.iFileName->CompareF(_L("v:\\dir\\nÁme.e02")));
446 test(0 == finder.iFileName->CompareF(_L("v:\\dir\\n\u00c1me.e02")));
447 delete finder.iFilesThatExist;
448 finder.iFilesThatExist = 0;
450 // Test searching language and drive down the language path
451 // FindLanguageAndDrive
452 finder.iPath[0] = static_cast<TLanguage>(2);
453 finder.iPath[1] = static_cast<TLanguage>(15702);
454 finder.iPath[2] = static_cast<TLanguage>(1);
455 finder.iPath[3] = ELangNone;
456 fileName = KTestFileName1;
457 finder.SetFileName(fileName);
458 SetUpFinderForLanguageAndDriveSearchL(finder);
459 finder.iFileCheckedFor = _L("?:\\dir\\name.e*");
460 test(!finder.FindLanguageAndDrive());
461 // check that iFileName is undamaged
462 finder.RepairFileName();
463 test(0 == finder.iFileName->CompareF(KTestFileName1));
464 delete finder.iFilesSearchedFor;
465 finder.iFilesThatExist = new (ELeave) CDesCArraySeg(10);
466 finder.iFilesThatExist->AppendL(_L("a:\\dir\\name.e15702"));
467 fileName = KTestFileName1;
468 finder.SetFileName(fileName);
469 SetUpFinderForLanguageAndDriveSearchL(finder);
470 test(finder.FindLanguageAndDrive());
471 test(0 == finder.iFileName->CompareF(_L("a:\\dir\\name.e15702")));
472 delete finder.iFilesSearchedFor;
473 finder.iFilesSearchedFor = 0;
475 finder.iPath[0] = static_cast<TLanguage>(7);
476 finder.iPath[1] = ELangNone;
477 finder.iFilesThatExist->AppendL(_L("g:\\dir\\name.ext"));
478 fileName = KTestFileName1;
479 finder.SetFileName(fileName);
480 finder.iDrives = _L("ZAG");
481 finder.iDrivesChecked = _L("ZAGZAG");
482 test(finder.FindLanguageAndDrive());
483 test(0 == finder.iFileName->CompareF(_L("g:\\dir\\name.ext")));
484 delete finder.iFilesThatExist;
485 finder.iFilesThatExist = 0;
487 // Test filename matching
488 // LanguageNumberFromFile
489 test(4 == TNearestLanguageFileFinder::LanguageNumberFromFile(_L("avb04"), _L("AVB")));
490 //test(4 == TNearestLanguageFileFinder::LanguageNumberFromFile(_L("ávb04"), _L("A\x301VB")));
491 //test(4 == TNearestLanguageFileFinder::LanguageNumberFromFile(_L("a\x301vb04"), _L("ÁVB")));
492 test(4 == TNearestLanguageFileFinder::LanguageNumberFromFile(_L("\u00e1vb04"), _L("A\x301VB")));
493 test(4 == TNearestLanguageFileFinder::LanguageNumberFromFile(_L("a\x301vb04"), _L("\u00c1VB")));
494 test(5254 == TNearestLanguageFileFinder::LanguageNumberFromFile(_L("avb5254"), _L("aVb")));
495 test(KErrNotFound == TNearestLanguageFileFinder::LanguageNumberFromFile(_L("avb04"), _L("avb04")));
496 test(KErrNotFound == TNearestLanguageFileFinder::LanguageNumberFromFile(_L("avb04"), _L("av")));
497 test(KErrNotFound == TNearestLanguageFileFinder::LanguageNumberFromFile(_L("avb04"), _L("")));
498 test(0 == TNearestLanguageFileFinder::LanguageNumberFromFile(_L("avb0000000"), _L("AVB00000")));
499 test(4 == TNearestLanguageFileFinder::LanguageNumberFromFile(_L("avb000000004"), _L("AVB0000000")));
500 test(100004 == TNearestLanguageFileFinder::LanguageNumberFromFile(_L("avb000100004"), _L("AVB000")));
501 test(111114 == TNearestLanguageFileFinder::LanguageNumberFromFile(_L("avb0111114"), _L("AVB0")));
503 // Test searching for any language file within a drive
504 // FindFirstLanguageFile
505 fileName = KTestFileName3;
506 finder.SetFileName(fileName);
507 finder.iFilesThatExist = new (ELeave) CDesCArraySeg(10);
508 finder.iFilesThatExist->AppendL(_L("a:\\dir\\name.e107"));
509 finder.iFilesThatExist->AppendL(_L("a:\\dir\\name.e07"));
510 finder.iFilesThatExist->AppendL(_L("a:\\dir\\name.e02"));
511 finder.iFilesThatExist->AppendL(_L("a:\\dir\\name.ee01"));
512 finder.iFilesThatExist->AppendL(_L("a:\\dir\\name.01"));
513 finder.iFilesThatExist->AppendL(_L("a:\\dir\\name01"));
514 finder.iFilesThatExist->AppendL(_L("a:\\dir\\name01.e01"));
515 finder.iFilesThatExist->AppendL(_L("a:\\dir\\name.e15108"));
516 finder.iFilesThatExist->AppendL(_L("a:\\dir\\name.e03"));
517 finder.iTestScanner.iDriveError[0] = KErrNoMemory;
518 fileName = KTestFileName3;
519 finder.SetFileName(fileName);
520 test(KErrNotFound == finder.FindFirstLanguageFile(dummy));
521 finder.iTestScanner.iDriveError[0] = KErrAbort;
522 fileName = KTestFileName3;
523 finder.SetFileName(fileName);
524 test(KErrNotFound == finder.FindFirstLanguageFile(dummy));
525 finder.iTestScanner.iDriveError[0] = KErrNone;
526 fileName = KTestFileName3;
527 finder.SetFileName(fileName);
528 test(0 <= finder.FindFirstLanguageFile(dummy));
529 test(0 == finder.iFileName->CompareF(_L("a:\\dir\\name.e02")));
531 finder.iFilesThatExist->AppendL(_L("a:\\abaffafg.100"));
532 finder.iFilesThatExist->AppendL(_L("a:\\abcdefg.9539"));
533 finder.iFilesThatExist->AppendL(_L("a:\\abcdefg.19539"));
534 finder.iFilesThatExist->AppendL(_L("a:\\abcdefg.1000"));
535 finder.iFilesThatExist->AppendL(_L("a:\\abaffafg.102"));
536 fileName = _L("a:\\abcdefg.xx");
537 finder.SetFileName(fileName);
538 test(0 <= finder.FindFirstLanguageFile(dummy));
539 test(0 == finder.iFileName->CompareF(_L("a:\\abcdefg.1000")));
540 finder.iFilesThatExist->AppendL(_L("a:\\abaffafg.aaa100"));
541 finder.iFilesThatExist->AppendL(_L("a:\\abcdefg.0523")); // not well-formed. Will not count.
542 finder.iFilesThatExist->AppendL(_L("a:\\abcdefg.1001"));
543 fileName = _L("a:\\abcdefg.xx");
544 finder.SetFileName(fileName);
545 test(0 <= finder.FindFirstLanguageFile(dummy));
546 test(0 == finder.iFileName->CompareF(_L("a:\\abcdefg.1000")));
547 fileName = _L("a:\\abaffafg.xx");
548 finder.SetFileName(fileName);
549 test(0 <= finder.FindFirstLanguageFile(dummy));
550 test(0 == finder.iFileName->CompareF(_L("a:\\abaffafg.100")));
551 finder.iFilesThatExist->AppendL(_L("a:\\abaffafg.09"));
552 fileName = _L("a:\\abaffafg.xx");
553 finder.SetFileName(fileName);
554 test(0 <= finder.FindFirstLanguageFile(dummy));
555 test(0 == finder.iFileName->CompareF(_L("a:\\abaffafg.09")));
557 // Test searching all drives for any language
558 // FindFirstLanguageFileAndDrive
559 finder.iFilesThatExist->AppendL(_L("z:\\abcdefg.05"));
560 fileName = _L("c:\\abcdefg.xx");
561 finder.SetFileName(fileName);
562 finder.iDrives = _L("az");
563 test(0 <= finder.FindFirstLanguageFileAndDrive());
564 test(0 == finder.iFileName->CompareF(_L("a:\\abcdefg.1000")));
565 fileName = _L("c:\\abaffafg.xx");
566 finder.SetFileName(fileName);
567 finder.iDrives = _L("az");
568 test(0 <= finder.FindFirstLanguageFileAndDrive());
569 test(0 == finder.iFileName->CompareF(_L("a:\\abaffafg.09")));
570 fileName = _L("c:\\abcdefg.xx");
571 finder.SetFileName(fileName);
572 finder.iDrives = _L("za");
573 test(0 <= finder.FindFirstLanguageFileAndDrive());
574 test(0 == finder.iFileName->CompareF(_L("z:\\abcdefg.05")));
575 fileName = _L("c:\\xxx.xx");
576 finder.SetFileName(fileName);
577 finder.iDrives = _L("za");
578 test(KErrNotFound == finder.FindFirstLanguageFileAndDrive());
579 finder.iTestScanner.iDriveError[25] = KErrAbort;
580 fileName = _L("c:\\abcdefg.xx");
581 finder.SetFileName(fileName);
582 finder.iDrives = _L("za");
583 test(0 <= finder.FindFirstLanguageFileAndDrive());
584 test(0 == finder.iFileName->CompareF(_L("a:\\abcdefg.1000")));
585 fileName = _L("c:\\abcdefg.xx");
586 finder.SetFileName(fileName);
587 finder.iDrives = _L("za");
588 finder.iTestScanner.iDriveError[0] = KErrNoMemory;
589 test(KErrNotFound == finder.FindFirstLanguageFileAndDrive());
590 fileName = _L("c:\\abcdefg.xx");
591 finder.SetFileName(fileName);
592 finder.iDrives = _L("za");
593 finder.iTestScanner.iDriveError[0] = KErrAbort;
594 test(KErrNotFound == finder.FindFirstLanguageFileAndDrive());
602 void CT_LANGUTILSIMP::TestLANGUTILSIMP()
606 INFO_PRINTF1(_L("LangUtils Internal Tests: "));
609 TestMakeLanguageDowngradePath();
610 TestNearestLanguageFinder();
617 CT_LANGUTILSIMP::CT_LANGUTILSIMP()
619 SetTestStepName(KTestStep_T_LANGUTILSIMP);
622 TVerdict CT_LANGUTILSIMP::doTestStepL()
624 SetTestStepResult(EFail);
628 TRAPD(error1, TestLANGUTILSIMP());
632 if(error1 == KErrNone )
634 SetTestStepResult(EPass);
637 return TestStepResult();