Update contrib.
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
22 LOCAL_D CTrapCleanup* TheTrapCleanup=NULL;
24 LOCAL_D RTest TheTest (_L("T_BaflLang"));
27 // Our test diectory and files...
29 _LIT (KNullFilename, "");
30 _LIT (KRscFilename, "C:\\abc.rsc");
31 _LIT (KRscFilenameNoSuffix, "C:\\abc.");
33 _LIT (KAmericanLang, "C:\\abc.r10");
34 _LIT (KFrenchLang, "C:\\abc.r02");
35 _LIT (KJapanEnglishLang, "C:\\abc.r160");
36 _LIT (KEnglishLang, "C:\\abc.r01");
38 LOCAL_C void DeleteTestFiles()
40 User::LeaveIfError (TheFs.Connect ());
41 ::CleanupClosePushL (TheFs);
43 BaflUtils::DeleteFile (TheFs, KRscFilename);
44 BaflUtils::DeleteFile (TheFs, KAmericanLang);
45 BaflUtils::DeleteFile (TheFs, KFrenchLang);
46 BaflUtils::DeleteFile (TheFs, KJapanEnglishLang);
47 BaflUtils::DeleteFile (TheFs, KEnglishLang);
49 CleanupStack::PopAndDestroy (&::TheFs);
53 //Test macroses and functions
54 LOCAL_C void Check(TInt aValue, TInt aLine)
59 TheTest(EFalse, aLine);
63 #define TEST(arg) ::Check((arg), __LINE__)
65 LOCAL_C void CreateTestFiles()
67 User::LeaveIfError (TheFs.Connect ());
68 ::CleanupClosePushL (TheFs);
69 TEST (BaflUtils::FileExists (TheFs, KRscFilename) == EFalse);
70 TEST (BaflUtils::FileExists (TheFs, KAmericanLang) == EFalse);
71 TEST (BaflUtils::FileExists (TheFs, KFrenchLang) == EFalse);
72 TEST (BaflUtils::FileExists (TheFs, KJapanEnglishLang) == EFalse);
73 TEST (BaflUtils::FileExists (TheFs, KEnglishLang) == EFalse);
75 // Create the files...
77 // KFilename1 can't be created
78 rFile.Create (TheFs, KRscFilename, EFileRead);
80 rFile.Create (TheFs, KAmericanLang, EFileRead);
82 rFile.Create (TheFs, KFrenchLang, EFileRead);
85 CleanupStack::PopAndDestroy (&::TheFs);
90 @SYMTestCaseID SYSLIB-BAFL-CT-0070
91 @SYMTestCaseDesc Tests the configuration of the ideal language.
93 @SYMTestActions Set the ideal language and look for nearest language files.
94 @SYMTestExpectedResults The test must not fail.
95 @SYMREQ 3770: Configurable "ideal language" in BaflUtils::NearestLanguageFile.
99 TheTest.Next (_L (" @SYMTestCaseID SYSLIB-BAFL-CT-0070 REQ3770L "));
103 User::LeaveIfError (TheFs.Connect ());
104 ::CleanupClosePushL (TheFs);
109 // Test ideal language code
111 // Check initial value of ideal language
113 language=BaflUtils::IdealLanguage();
114 TEST(language == ELangNone);
116 // Set and read back the ideal language
118 BaflUtils::SetIdealLanguage( ELangGerman);
119 language=BaflUtils::IdealLanguage();
120 TEST(language == ELangGerman);
122 BaflUtils::SetIdealLanguage( ELangAmerican);
123 language=BaflUtils::IdealLanguage();
124 TEST(language == ELangAmerican);
126 // Test NearestLanguageFile with empty name
128 BaflUtils::NearestLanguageFile (TheFs, resPath);
129 TEST(resPath.Length()==0);
130 TheTest.Printf (_L ("The NearestLanguageFile for the null file - %S - is - %S -\n"), &KNullFilename, &filename);
132 // Test NearestLanguageFile with no suffix
133 filename.Copy (KRscFilenameNoSuffix);
134 BaflUtils::NearestLanguageFile (TheFs, filename);
135 TEST(filename==KRscFilenameNoSuffix);
136 TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KRscFilenameNoSuffix, &filename);
138 // Test NearestLanguageFile
139 filename.Copy (KRscFilename);
140 BaflUtils::NearestLanguageFile (TheFs, filename);
141 TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KRscFilename, &filename);
142 TEST(filename == KAmericanLang);
144 // Set ideal language to one we don't have
145 BaflUtils::SetIdealLanguage( ELangGerman);
146 language=BaflUtils::IdealLanguage();
147 TEST(language == ELangGerman);
149 // Test NearestLanguageFile
150 filename.Copy (KRscFilename);
151 BaflUtils::NearestLanguageFile (TheFs, filename);
152 TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KRscFilename, &filename);
153 TEST(filename == KRscFilename);
155 // Restore ideal language to default
156 BaflUtils::SetIdealLanguage( ELangNone);
157 language=BaflUtils::IdealLanguage();
158 TEST(language == ELangNone);
160 // Test NearestLanguageFile
161 filename.Copy (KRscFilename);
162 BaflUtils::NearestLanguageFile (TheFs, filename);
163 TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KRscFilename, &filename);
164 TEST(filename == KRscFilename);
166 // Set ideal language to French
168 BaflUtils::SetIdealLanguage( ELangFrench);
169 language=BaflUtils::IdealLanguage();
170 TEST(language == ELangFrench);
172 // Test NearestLanguageFile
173 filename.Copy (KRscFilename);
174 BaflUtils::NearestLanguageFile (TheFs, filename);
175 TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KRscFilename, &filename);
176 TEST(filename == KFrenchLang);
178 // Restore ideal language to default
179 BaflUtils::SetIdealLanguage( ELangNone);
180 language=BaflUtils::IdealLanguage();
181 TEST(language == ELangNone);
183 // Release ideal language - free's TLS
185 BaflUtils::ReleaseIdealLanguage();
187 CleanupStack::PopAndDestroy (&::TheFs);
193 @SYMTestCaseID SYSLIB-BAFL-CT-0071
194 @SYMTestCaseDesc Tests the overload of BaflUtils::NearestLanguageFile.
195 @SYMTestPriority High
196 @SYMTestActions Calls the overload of BaflUtils::NearestLanguageFile and checks the returned language.
197 @SYMTestExpectedResults The test must not fail.
198 @SYMREQ 3785: Overload of BaflUtils::NearestLanguageFile.
202 TheTest.Next (_L (" @SYMTestCaseID SYSLIB-BAFL-CT-0071 REQ3785L "));
206 User::LeaveIfError (TheFs.Connect ());
207 ::CleanupClosePushL (TheFs);
212 // Ensure that ideal language is default
213 BaflUtils::SetIdealLanguage( ELangNone);
214 language=BaflUtils::IdealLanguage();
215 TEST(language == ELangNone);
217 // Test NearestLanguageFile overload with language returned
218 language=ELangAmerican;
219 filename.Copy (KRscFilename);
220 BaflUtils::NearestLanguageFile (TheFs, filename, language);
221 TheTest.Printf (_L ("The NearestLanguageFile for %S is %S, language = %d\n"), &KRscFilename, &filename, language);
222 TEST(language == ELangNone);
223 TEST(filename == KRscFilename);
225 // Set ideal language to American
227 BaflUtils::SetIdealLanguage( ELangAmerican);
228 language=BaflUtils::IdealLanguage();
229 TEST(language == ELangAmerican);
231 // Test NearestLanguageFile overload with language returned
233 filename.Copy (KRscFilename);
234 BaflUtils::NearestLanguageFile (TheFs, filename, language);
235 TheTest.Printf (_L ("The NearestLanguageFile for %S is %S, language = %d\n"), &KRscFilename, &filename, language);
236 TEST(language == ELangAmerican);
237 TEST(filename == KAmericanLang);
239 // Set ideal language to French
241 BaflUtils::SetIdealLanguage( ELangFrench);
242 language=BaflUtils::IdealLanguage();
243 TEST(language == ELangFrench);
245 // Test NearestLanguageFile overload with language returned
247 filename.Copy (KRscFilename);
248 BaflUtils::NearestLanguageFile (TheFs, filename, language);
249 TheTest.Printf (_L ("The NearestLanguageFile for %S is %S, language = %d\n"), &KRscFilename, &filename, language);
250 TEST(language == ELangFrench);
251 TEST(filename == KFrenchLang);
253 // Set ideal language to one we don't have
254 BaflUtils::SetIdealLanguage( ELangGerman);
255 language=BaflUtils::IdealLanguage();
256 TEST(language == ELangGerman);
258 // Test NearestLanguageFile overload with language returned
259 language=ELangAmerican;
260 filename.Copy (KRscFilename);
261 BaflUtils::NearestLanguageFile (TheFs, filename, language);
262 TheTest.Printf (_L ("The NearestLanguageFile for %S is %S, language = %d\n"), &KRscFilename, &filename, language);
263 TEST(language == ELangNone);
264 TEST(filename == KRscFilename);
266 // Restore ideal language to default
267 BaflUtils::SetIdealLanguage( ELangNone);
268 language=BaflUtils::IdealLanguage();
269 TEST(language == ELangNone);
271 // Release ideal language - free's TLS
273 BaflUtils::ReleaseIdealLanguage();
275 CleanupStack::PopAndDestroy (&::TheFs);
281 @SYMTestCaseID SYSLIB-BAFL-CT-3158
282 @SYMTestCaseDesc Test the downgrade path from ELangMalay_Apac to ELangMalay
283 @SYMTestPriority High
284 @SYMTestActions Calls the BaflUtils::GetDowngradePathL function to check that ELangMalay_Apac downgrades to ELangMalay
285 @SYMTestExpectedResults The test must not fail.
290 TheTest.Next (_L (" @SYMTestCaseID SYSLIB-BAFL-CT-3158 DEF094490L "));
294 User::LeaveIfError (TheFs.Connect ());
295 ::CleanupClosePushL (TheFs);
296 RArray<TLanguage> aLanguageArray;
298 //Test GetDowngradePathL to see if ELangMalay is included in the path
299 BaflUtils::GetDowngradePathL(TheFs,ELangMalay_Apac,aLanguageArray);
300 TEST(aLanguageArray.Find(ELangMalay)!= KErrNotFound);
302 aLanguageArray.Close();
304 CleanupStack::PopAndDestroy (&::TheFs);
310 @SYMTestCaseID SYSLIB-BAFL-CT-3359
311 @SYMTestCaseDesc Test correct and incorrect usage of NearestLanguageFile as documented in the developer library
312 @SYMTestPriority High
313 @SYMTestActions Calls the BaflUtils::NearestLanguageFile function with different contructed
314 language downgrade path cases along with different input paths
315 @SYMTestExpectedResults The test must not fail.
320 TheTest.Next (_L (" @SYMTestCaseID SYSLIB-BAFL-CT-3359 DEF096421 "));
327 //number of characters in the suffix is less than KInvNameAndMinSuffixLength(2)
328 _LIT (KInvalidSuffix1, "C:\\abc.r");
330 //number of digits in the suffix is more than KMaxSuffixLength(5)
331 _LIT (KInvalidSuffix2, "C:\\abc.r123456");
333 //no proceeding alphabetical characters in the suffix
334 _LIT (KInvalidSuffix3, "C:\\abc.10");
336 //no drive letters supplied in the path
337 _LIT (KRscFilenameNoDrive, "\\abc.rsc");
339 _LIT (KRscFileInZDrive, "\\system\\data\\T_CALYPSO_TEST_RESOURCE_FILE_1.RSC");
340 _LIT (KRScFullFile, "Z:\\system\\data\\T_CALYPSO_TEST_RESOURCE_FILE_1.RSC");
342 User::LeaveIfError (TheFs.Connect ());
343 ::CleanupClosePushL (TheFs);
345 rFile.Create (TheFs, KJapanEnglishLang, EFileRead);
347 rFile.Create (TheFs, KEnglishLang, EFileRead);
350 BaflUtils::SetIdealLanguage( ELangAmerican);
351 language=BaflUtils::IdealLanguage();
352 TEST(language == ELangAmerican);
354 //Test match for the ideal language
355 path.Copy(KRscFilename);
356 BaflUtils::NearestLanguageFile (TheFs, path, language);
357 TEST(path == KAmericanLang);
358 TEST(language == ELangAmerican);
359 TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KRscFilename, &path);
361 //Test match when supplied with the language file
362 path.Copy(KAmericanLang);
363 BaflUtils::NearestLanguageFile (TheFs, path, language);
364 TEST(path == KAmericanLang);
365 TEST(language == ELangAmerican);
366 TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KAmericanLang, &path);
368 //Test when the no. of characters in the suffix is less than KInvNameAndMinSuffixLength(2)
369 path.Copy(KInvalidSuffix1);
370 BaflUtils::NearestLanguageFile (TheFs, path, language);
371 TEST(path == KInvalidSuffix1);
372 TEST(language == ELangNone);
373 TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KInvalidSuffix1, &path);
375 //Test when filename ends with a period
376 path.Copy(KRscFilenameNoSuffix);
377 BaflUtils::NearestLanguageFile (TheFs, path, language);
378 TEST(path == KRscFilenameNoSuffix);
379 TEST(language == ELangNone);
380 TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KRscFilenameNoSuffix, &path);
382 //Test when the no. of digits in the suffix is more than KMaxSuffixLength(5)
383 path.Copy(KInvalidSuffix2);
384 BaflUtils::NearestLanguageFile (TheFs, path, language);
385 TEST(path == KInvalidSuffix2);
386 TEST(language == ELangNone);
387 TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KInvalidSuffix2, &path);
389 //Test when theres no proceeding alphabetical characters in the suffix
390 path.Copy(KInvalidSuffix3);
391 BaflUtils::NearestLanguageFile (TheFs, path, language);
392 TEST(path == KInvalidSuffix3);
393 TEST(language == ELangNone);
394 TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KInvalidSuffix3, &path);
396 //Test when no drive letter is supplied in the path and theres no corresponding file in Z:
397 path.Copy(KRscFilenameNoDrive);
398 BaflUtils::NearestLanguageFile (TheFs, path, language);
399 TEST(path == KRscFilenameNoDrive);
400 TEST(language == ELangNone);
401 TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KRscFilenameNoDrive, &path);
403 BaflUtils::SetIdealLanguage(ELangEnglish_Japan);
404 TheTest.Printf(_L("The ideal langauge set to ELangEnglish_Japan\n"));
406 //Test when the matching language file is 3 digits long
407 path.Copy(KRscFilename);
408 BaflUtils::NearestLanguageFile (TheFs, path, language);
409 TEST(path == KJapanEnglishLang);
410 TEST(language == ELangEnglish_Japan);
411 TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KRscFilename, &path);
413 BaflUtils::DeleteFile (TheFs, KJapanEnglishLang);
414 TheTest.Printf(_L("Deleting C:\\abc.r160\n"));
416 //Test match for the current locale (2nd best match)
417 path.Copy(KRscFilename);
418 BaflUtils::NearestLanguageFile (TheFs, path, language);
419 TEST(path == KEnglishLang);
420 TEST(language == ELangEnglish);
421 TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KRscFilename, &path);
423 BaflUtils::DeleteFile (TheFs, KEnglishLang);
424 TheTest.Printf(_L("Deleting C:\\abc.r01\n"));
426 //Test when theres no matching language file
427 path.Copy(KRscFilename);
428 BaflUtils::NearestLanguageFile (TheFs, path, language);
429 TEST(path == KRscFilename);
430 TEST(language == ELangNone);
431 TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KRscFilename, &path);
433 //Test when no drive letter is supplied in the
434 //path but theres a corresponding file in Z:
435 path.Copy(KRscFileInZDrive);
436 BaflUtils::NearestLanguageFile (TheFs, path, language);
437 TEST(path == KRScFullFile);
438 TEST(language == ELangNone);
439 TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KRscFileInZDrive, &path);
441 CleanupStack::PopAndDestroy (&::TheFs);
443 BaflUtils::ReleaseIdealLanguage();
447 //===============================================================================
450 Initialise the cleanup stack
452 LOCAL_C void SetupL ()
454 TheTrapCleanup = CTrapCleanup::New ();
455 User::LeaveIfNull (TheTrapCleanup);
461 LOCAL_C void CleanupL ()
463 delete TheTrapCleanup;
469 LOCAL_C void DoTestsL ()
480 GLDEF_C TInt E32Main ()
484 TheTest.Printf (_L ("\n"));
486 TheTest.Start (_L("Ideal language Tests "));
488 TRAPD (err, SetupL ());
489 TheTest (err == KErrNone);
491 TRAP (err, DoTestsL ());
492 TheTest (err == KErrNone);