os/textandloc/textandlocutils/nearestlangutils/tsrc/T_LangUtilsLang.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 #include <f32file.h>
    16 #include <hal.h>
    17 #include <e32std.h>
    18 #include <langutil.h>
    19 #include "LangUtilImpl.h"
    20 #include "T_LangUtilsTestShareFunc.h"
    21 #include "t_langutilslang.h"
    22 
    23 #define test(cond)                                          \
    24     {                                                       \
    25     TBool __bb = (cond);                                    \
    26     TEST(__bb);                                             \
    27     if (!__bb)                                              \
    28         {                                                   \
    29         ERR_PRINTF1(_L("ERROR: Test Failed"));              \
    30         User::Leave(1);                                     \
    31         }                                                   \
    32     }
    33 
    34 
    35 LOCAL_D RFs                 TheFs;
    36 
    37 // Our test diectory and files...
    38 
    39 _LIT (KNullFilename, "");
    40 _LIT (KRscFilename,  "C:\\abc.rsc");
    41 _LIT (KRscFilenameNoSuffix,  "C:\\abc.");
    42 
    43 _LIT (KAmericanLang, "C:\\abc.r10");
    44 _LIT (KFrenchLang,   "C:\\abc.r02");
    45 _LIT (KJapanEnglishLang, "C:\\abc.r160");
    46 _LIT (KEnglishLang, "C:\\abc.r01");
    47 
    48 LOCAL_C void DeleteTestFiles()
    49 {
    50     User::LeaveIfError (TheFs.Connect ());
    51     ::CleanupClosePushL (TheFs);
    52 
    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);
    58 
    59     CleanupStack::PopAndDestroy (&::TheFs);
    60 }
    61 
    62 
    63 
    64 void CT_LANGUTILSLANG::CreateTestFiles()
    65 {
    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);
    73 
    74     // Create the files...
    75     RFile rFile;
    76     // KFilename1 can't be created
    77     rFile.Create (TheFs, KRscFilename, EFileRead);
    78     rFile.Close ();
    79     rFile.Create (TheFs, KAmericanLang, EFileRead);
    80     rFile.Close ();
    81     rFile.Create (TheFs, KFrenchLang, EFileRead);
    82     rFile.Close ();
    83 
    84     CleanupStack::PopAndDestroy (&::TheFs);
    85 
    86 }
    87 
    88 /**
    89 @SYMTestCaseID SYSLIB-BAFL-CT-0070
    90 @SYMTestCaseDesc Tests the configuration of the ideal language.
    91 @SYMTestPriority High
    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.
    95 */
    96 void CT_LANGUTILSLANG::TestIdeaLang()
    97     {
    98     INFO_PRINTF1 (_L (" @SYMTestCaseID SYSLIB-BAFL-CT-0070 TestIdeaLang "));
    99 
   100     __UHEAP_MARK;
   101 
   102     User::LeaveIfError (TheFs.Connect ());
   103     ::CleanupClosePushL (TheFs);
   104 
   105     TBuf <256> filename;
   106     TLanguage language;
   107 
   108     // Test ideal language code
   109 
   110     // Check initial value of ideal language
   111 
   112     language=LangUtil::IdealLanguage();
   113     test(language == ELangNone);
   114 
   115     // Set and read back the ideal language
   116 
   117     LangUtil::SetIdealLanguage( ELangGerman);
   118     language=LangUtil::IdealLanguage();
   119     test(language == ELangGerman);
   120 
   121     LangUtil::SetIdealLanguage( ELangAmerican);
   122     language=LangUtil::IdealLanguage();
   123     test(language == ELangAmerican);
   124 
   125     // Test NearestLanguageFile with empty name
   126     TFileName resPath;
   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);
   130 
   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);
   136 
   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);
   142 
   143     // Set ideal language to one we don't have
   144     LangUtil::SetIdealLanguage( ELangGerman);
   145     language=LangUtil::IdealLanguage();
   146     test(language == ELangGerman);
   147 
   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);
   153 
   154     // Restore ideal language to default
   155     LangUtil::SetIdealLanguage( ELangNone);
   156     language=LangUtil::IdealLanguage();
   157     test(language == ELangNone);
   158 
   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);
   164 
   165     // Set ideal language to French
   166 
   167     LangUtil::SetIdealLanguage( ELangFrench);
   168     language=LangUtil::IdealLanguage();
   169     test(language == ELangFrench);
   170 
   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);
   176 
   177     // Restore ideal language to default
   178     LangUtil::SetIdealLanguage( ELangNone);
   179     language=LangUtil::IdealLanguage();
   180     test(language == ELangNone);
   181 
   182     // Release ideal language - free's TLS
   183 
   184     LangUtil::ReleaseIdealLanguage();
   185 
   186     CleanupStack::PopAndDestroy (&::TheFs);
   187 
   188     __UHEAP_MARKEND;
   189     }
   190 
   191 /**
   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.
   198 */
   199 void CT_LANGUTILSLANG::TestNearestLang()
   200     {
   201     INFO_PRINTF1 (_L (" @SYMTestCaseID SYSLIB-BAFL-CT-0071 TestNearestLang "));
   202 
   203     __UHEAP_MARK;
   204 
   205     User::LeaveIfError (TheFs.Connect ());
   206     ::CleanupClosePushL (TheFs);
   207 
   208     TBuf <256> filename;
   209     TLanguage language;
   210 
   211     // Ensure that ideal language is default
   212     LangUtil::SetIdealLanguage( ELangNone);
   213     language=LangUtil::IdealLanguage();
   214     test(language == ELangNone);
   215 
   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);
   223 
   224     // Set ideal language to American
   225 
   226     LangUtil::SetIdealLanguage( ELangAmerican);
   227     language=LangUtil::IdealLanguage();
   228     test(language == ELangAmerican);
   229 
   230     // Test NearestLanguageFile overload with language returned
   231     language=ELangNone;
   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);
   237 
   238     // Set ideal language to French
   239 
   240     LangUtil::SetIdealLanguage( ELangFrench);
   241     language=LangUtil::IdealLanguage();
   242     test(language == ELangFrench);
   243 
   244     // Test NearestLanguageFile overload with language returned
   245     language=ELangNone;
   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);
   251 
   252     // Set ideal language to one we don't have
   253     LangUtil::SetIdealLanguage( ELangGerman);
   254     language=LangUtil::IdealLanguage();
   255     test(language == ELangGerman);
   256 
   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);
   264 
   265     // Restore ideal language to default
   266     LangUtil::SetIdealLanguage( ELangNone);
   267     language=LangUtil::IdealLanguage();
   268     test(language == ELangNone);
   269 
   270     // Release ideal language - free's TLS
   271 
   272     LangUtil::ReleaseIdealLanguage();
   273 
   274     CleanupStack::PopAndDestroy (&::TheFs);
   275 
   276     __UHEAP_MARKEND;
   277     }
   278 
   279 
   280 void CT_LANGUTILSLANG::TestLANGUTILSLANG ()
   281     {
   282     CreateTestFiles();
   283     TestIdeaLang ();
   284     TestNearestLang ();
   285     DeleteTestFiles();
   286     }
   287 
   288 CT_LANGUTILSLANG::CT_LANGUTILSLANG()
   289     {
   290     SetTestStepName(KTestStep_T_LANGUTILSLANG);
   291     }
   292 
   293 TVerdict CT_LANGUTILSLANG::doTestStepL()
   294     {
   295     SetTestStepResult(EFail);
   296 
   297     __UHEAP_MARK;
   298 
   299     TRAPD(error1, TestLANGUTILSLANG());
   300 
   301     __UHEAP_MARKEND;
   302 
   303     if(error1 == KErrNone )
   304         {
   305         SetTestStepResult(EPass);
   306         }
   307 
   308     return TestStepResult();
   309     }
   310