Update contrib.
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.
19 #include "LangUtilImpl.h"
20 #include "T_LangUtilsTestShareFunc.h"
21 #include "t_langutilslang.h"
25 TBool __bb = (cond); \
29 ERR_PRINTF1(_L("ERROR: Test Failed")); \
37 // Our test diectory and files...
39 _LIT (KNullFilename, "");
40 _LIT (KRscFilename, "C:\\abc.rsc");
41 _LIT (KRscFilenameNoSuffix, "C:\\abc.");
43 _LIT (KAmericanLang, "C:\\abc.r10");
44 _LIT (KFrenchLang, "C:\\abc.r02");
45 _LIT (KJapanEnglishLang, "C:\\abc.r160");
46 _LIT (KEnglishLang, "C:\\abc.r01");
48 LOCAL_C void DeleteTestFiles()
50 User::LeaveIfError (TheFs.Connect ());
51 ::CleanupClosePushL (TheFs);
53 LangUtilsTest::DeleteFile (TheFs, KRscFilename);
54 LangUtilsTest::DeleteFile (TheFs, KAmericanLang);
55 LangUtilsTest::DeleteFile (TheFs, KFrenchLang);
56 LangUtilsTest::DeleteFile (TheFs, KJapanEnglishLang);
57 LangUtilsTest::DeleteFile (TheFs, KEnglishLang);
59 CleanupStack::PopAndDestroy (&::TheFs);
64 void CT_LANGUTILSLANG::CreateTestFiles()
66 User::LeaveIfError (TheFs.Connect ());
67 ::CleanupClosePushL (TheFs);
68 test (LangUtilsTest::FileExists (TheFs, KRscFilename) == EFalse);
69 test (LangUtilsTest::FileExists (TheFs, KAmericanLang) == EFalse);
70 test (LangUtilsTest::FileExists (TheFs, KFrenchLang) == EFalse);
71 test (LangUtilsTest::FileExists (TheFs, KJapanEnglishLang) == EFalse);
72 test (LangUtilsTest::FileExists (TheFs, KEnglishLang) == EFalse);
74 // Create the files...
76 // KFilename1 can't be created
77 rFile.Create (TheFs, KRscFilename, EFileRead);
79 rFile.Create (TheFs, KAmericanLang, EFileRead);
81 rFile.Create (TheFs, KFrenchLang, EFileRead);
84 CleanupStack::PopAndDestroy (&::TheFs);
89 @SYMTestCaseID SYSLIB-BAFL-CT-0070
90 @SYMTestCaseDesc Tests the configuration of the ideal language.
92 @SYMTestActions Set the ideal language and look for nearest language files.
93 @SYMTestExpectedResults The test must not fail.
94 @SYMREQ 3770: Configurable "ideal language" in LangUtil::NearestLanguageFile.
96 void CT_LANGUTILSLANG::TestIdeaLang()
98 INFO_PRINTF1 (_L (" @SYMTestCaseID SYSLIB-BAFL-CT-0070 TestIdeaLang "));
102 User::LeaveIfError (TheFs.Connect ());
103 ::CleanupClosePushL (TheFs);
108 // Test ideal language code
110 // Check initial value of ideal language
112 language=LangUtil::IdealLanguage();
113 test(language == ELangNone);
115 // Set and read back the ideal language
117 LangUtil::SetIdealLanguage( ELangGerman);
118 language=LangUtil::IdealLanguage();
119 test(language == ELangGerman);
121 LangUtil::SetIdealLanguage( ELangAmerican);
122 language=LangUtil::IdealLanguage();
123 test(language == ELangAmerican);
125 // Test NearestLanguageFile with empty name
127 LangUtil::NearestLanguageFile (TheFs, resPath);
128 test(resPath.Length()==0);
129 INFO_PRINTF3 (_L ("The NearestLanguageFile for the null file - %S - is - %S -\n"), &KNullFilename, &filename);
131 // Test NearestLanguageFile with no suffix
132 filename.Copy (KRscFilenameNoSuffix);
133 LangUtil::NearestLanguageFile (TheFs, filename);
134 test(filename==KRscFilenameNoSuffix);
135 INFO_PRINTF3 (_L ("The NearestLanguageFile for %S is %S\n"), &KRscFilenameNoSuffix, &filename);
137 // Test NearestLanguageFile
138 filename.Copy (KRscFilename);
139 LangUtil::NearestLanguageFile (TheFs, filename);
140 INFO_PRINTF3 (_L ("The NearestLanguageFile for %S is %S\n"), &KRscFilename, &filename);
141 test(filename == KAmericanLang);
143 // Set ideal language to one we don't have
144 LangUtil::SetIdealLanguage( ELangGerman);
145 language=LangUtil::IdealLanguage();
146 test(language == ELangGerman);
148 // Test NearestLanguageFile
149 filename.Copy (KRscFilename);
150 LangUtil::NearestLanguageFile (TheFs, filename);
151 INFO_PRINTF3 (_L ("The NearestLanguageFile for %S is %S\n"), &KRscFilename, &filename);
152 test(filename == KRscFilename);
154 // Restore ideal language to default
155 LangUtil::SetIdealLanguage( ELangNone);
156 language=LangUtil::IdealLanguage();
157 test(language == ELangNone);
159 // Test NearestLanguageFile
160 filename.Copy (KRscFilename);
161 LangUtil::NearestLanguageFile (TheFs, filename);
162 INFO_PRINTF3 (_L ("The NearestLanguageFile for %S is %S\n"), &KRscFilename, &filename);
163 test(filename == KRscFilename);
165 // Set ideal language to French
167 LangUtil::SetIdealLanguage( ELangFrench);
168 language=LangUtil::IdealLanguage();
169 test(language == ELangFrench);
171 // Test NearestLanguageFile
172 filename.Copy (KRscFilename);
173 LangUtil::NearestLanguageFile (TheFs, filename);
174 INFO_PRINTF3 (_L ("The NearestLanguageFile for %S is %S\n"), &KRscFilename, &filename);
175 test(filename == KFrenchLang);
177 // Restore ideal language to default
178 LangUtil::SetIdealLanguage( ELangNone);
179 language=LangUtil::IdealLanguage();
180 test(language == ELangNone);
182 // Release ideal language - free's TLS
184 LangUtil::ReleaseIdealLanguage();
186 CleanupStack::PopAndDestroy (&::TheFs);
192 @SYMTestCaseID SYSLIB-BAFL-CT-0071
193 @SYMTestCaseDesc Tests the overload of LangUtil::NearestLanguageFile.
194 @SYMTestPriority High
195 @SYMTestActions Calls the overload of LangUtil::NearestLanguageFile and checks the returned language.
196 @SYMTestExpectedResults The test must not fail.
197 @SYMREQ 3785: Overload of LangUtil::NearestLanguageFile.
199 void CT_LANGUTILSLANG::TestNearestLang()
201 INFO_PRINTF1 (_L (" @SYMTestCaseID SYSLIB-BAFL-CT-0071 TestNearestLang "));
205 User::LeaveIfError (TheFs.Connect ());
206 ::CleanupClosePushL (TheFs);
211 // Ensure that ideal language is default
212 LangUtil::SetIdealLanguage( ELangNone);
213 language=LangUtil::IdealLanguage();
214 test(language == ELangNone);
216 // Test NearestLanguageFile overload with language returned
217 language=ELangAmerican;
218 filename.Copy (KRscFilename);
219 LangUtil::NearestLanguageFile (TheFs, filename, language);
220 INFO_PRINTF4(_L ("The NearestLanguageFile for %S is %S, language = %d\n"), &KRscFilename, &filename, language);
221 test(language == ELangNone);
222 test(filename == KRscFilename);
224 // Set ideal language to American
226 LangUtil::SetIdealLanguage( ELangAmerican);
227 language=LangUtil::IdealLanguage();
228 test(language == ELangAmerican);
230 // Test NearestLanguageFile overload with language returned
232 filename.Copy (KRscFilename);
233 LangUtil::NearestLanguageFile (TheFs, filename, language);
234 INFO_PRINTF4 (_L ("The NearestLanguageFile for %S is %S, language = %d\n"), &KRscFilename, &filename, language);
235 test(language == ELangAmerican);
236 test(filename == KAmericanLang);
238 // Set ideal language to French
240 LangUtil::SetIdealLanguage( ELangFrench);
241 language=LangUtil::IdealLanguage();
242 test(language == ELangFrench);
244 // Test NearestLanguageFile overload with language returned
246 filename.Copy (KRscFilename);
247 LangUtil::NearestLanguageFile (TheFs, filename, language);
248 INFO_PRINTF4 (_L ("The NearestLanguageFile for %S is %S, language = %d\n"), &KRscFilename, &filename, language);
249 test(language == ELangFrench);
250 test(filename == KFrenchLang);
252 // Set ideal language to one we don't have
253 LangUtil::SetIdealLanguage( ELangGerman);
254 language=LangUtil::IdealLanguage();
255 test(language == ELangGerman);
257 // Test NearestLanguageFile overload with language returned
258 language=ELangAmerican;
259 filename.Copy (KRscFilename);
260 LangUtil::NearestLanguageFile (TheFs, filename, language);
261 INFO_PRINTF4 (_L ("The NearestLanguageFile for %S is %S, language = %d\n"), &KRscFilename, &filename, language);
262 test(language == ELangNone);
263 test(filename == KRscFilename);
265 // Restore ideal language to default
266 LangUtil::SetIdealLanguage( ELangNone);
267 language=LangUtil::IdealLanguage();
268 test(language == ELangNone);
270 // Release ideal language - free's TLS
272 LangUtil::ReleaseIdealLanguage();
274 CleanupStack::PopAndDestroy (&::TheFs);
280 void CT_LANGUTILSLANG::TestLANGUTILSLANG ()
288 CT_LANGUTILSLANG::CT_LANGUTILSLANG()
290 SetTestStepName(KTestStep_T_LANGUTILSLANG);
293 TVerdict CT_LANGUTILSLANG::doTestStepL()
295 SetTestStepResult(EFail);
299 TRAPD(error1, TestLANGUTILSLANG());
303 if(error1 == KErrNone )
305 SetTestStepResult(EPass);
308 return TestStepResult();