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