os/kernelhwsrv/kerneltest/f32test/server/t_dlocl.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 the License "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
// f32test\server\t_dlocl.cpp
sl@0
    15
// Tests UserSvr::ChangeLocale() function
sl@0
    16
// 
sl@0
    17
//
sl@0
    18
sl@0
    19
#define __E32TEST_EXTENSION__
sl@0
    20
sl@0
    21
#include <e32std.h>
sl@0
    22
#include <e32std_private.h>
sl@0
    23
#include <e32test.h>
sl@0
    24
#include <f32file.h>
sl@0
    25
#include <e32svr.h>
sl@0
    26
#include <collate.h>
sl@0
    27
sl@0
    28
#include "t_server.h"
sl@0
    29
sl@0
    30
LOCAL_D TFindLibrary fLib;
sl@0
    31
sl@0
    32
typedef TInt (*TLibEntry)(TInt);
sl@0
    33
typedef TInt (*TLibEntry2)();
sl@0
    34
sl@0
    35
const TBool KEY_DOWN=EFalse;
sl@0
    36
const TBool EXPECT_KEY_PRESS=ETrue;
sl@0
    37
sl@0
    38
RTest test(_L("T_DLOCL"));
sl@0
    39
sl@0
    40
_LIT(ELOCL_DEFAULT, "");
sl@0
    41
_LIT(ELOCLGE, "T_LOCLGE");
sl@0
    42
_LIT(ELOCLUS, "T_LOCLUS");
sl@0
    43
_LIT(ELOCLUS1, "T_LOCLUS1");
sl@0
    44
_LIT(ELOCLUS2, "T_LOCLUS2");
sl@0
    45
_LIT(EKDATA, "EKDATA");
sl@0
    46
_LIT(DUMMYDLL, "EDISP");
sl@0
    47
_LIT(KColonColon, "::");
sl@0
    48
_LIT(KDLLExtension, ".DLL");
sl@0
    49
sl@0
    50
GLDEF_D CKeyTranslator *KeyTranslator=CKeyTranslator::New();
sl@0
    51
LOCAL_D CCaptureKeys *CaptureKeys;
sl@0
    52
sl@0
    53
void testConv(const TDesC& aDes,TBool aKeyup,TBool aRet,TUint aScanCode,TUint aKeyCode,TInt aModifiers)
sl@0
    54
    {
sl@0
    55
sl@0
    56
    TKeyData keyData;
sl@0
    57
    TBool ret=KeyTranslator->TranslateKey(aScanCode, aKeyup,*CaptureKeys,keyData);
sl@0
    58
    test.Next(aDes);
sl@0
    59
    test(ret==aRet);
sl@0
    60
    test((keyData.iKeyCode==aKeyCode));
sl@0
    61
    test((keyData.iModifiers==aModifiers));
sl@0
    62
    }
sl@0
    63
sl@0
    64
void testChangeKeyData()
sl@0
    65
    {
sl@0
    66
    TName pn(RProcess().Name());
sl@0
    67
    pn+=KColonColon;
sl@0
    68
    TFullName n;
sl@0
    69
    CaptureKeys=new CCaptureKeys();
sl@0
    70
    CaptureKeys->Construct();
sl@0
    71
    test.Printf(_L("Test default key data\n"));
sl@0
    72
    testConv(_L("\nFirst Special key down"),KEY_DOWN,EXPECT_KEY_PRESS,ESpecialKeyBase,ESpecialKeyBase,0);
sl@0
    73
sl@0
    74
    RLibrary testLib;
sl@0
    75
    TInt res=testLib.Load(EKDATA);
sl@0
    76
    test(res==KErrNone);
sl@0
    77
    THandleInfo handleInfo;
sl@0
    78
    testLib.HandleInfo(&handleInfo);
sl@0
    79
    test(handleInfo.iNumOpenInThread==2);
sl@0
    80
    testLib.Close();
sl@0
    81
sl@0
    82
    test.Printf(_L("Change to unknown dll \n"));                // Test with non keydata type dll
sl@0
    83
    res=KeyTranslator->ChangeKeyData(DUMMYDLL);
sl@0
    84
    test(res==KErrArgument);
sl@0
    85
    
sl@0
    86
    res=testLib.Load(EKDATA);
sl@0
    87
    test(res==KErrNone);
sl@0
    88
    testLib.HandleInfo(&handleInfo);
sl@0
    89
    test(handleInfo.iNumOpenInThread==2);
sl@0
    90
    testLib.Close();
sl@0
    91
sl@0
    92
    res=testLib.Load(DUMMYDLL);
sl@0
    93
    test(res==KErrNone);
sl@0
    94
    testLib.HandleInfo(&handleInfo);
sl@0
    95
    test(handleInfo.iNumOpenInThread==1);
sl@0
    96
    testLib.Close();
sl@0
    97
sl@0
    98
    fLib.Find(_L("*"));
sl@0
    99
    while (fLib.Next(n)==KErrNone)
sl@0
   100
        {
sl@0
   101
        TName findname=pn;
sl@0
   102
        findname+=DUMMYDLL;
sl@0
   103
        test.Printf(_L("  %S\n"),&n);        
sl@0
   104
        test(n.FindF(findname) == KErrNotFound);
sl@0
   105
        }
sl@0
   106
    //
sl@0
   107
    test.Printf(_L("Change to EKDATA.dll\n"));
sl@0
   108
    res=KeyTranslator->ChangeKeyData(EKDATA);
sl@0
   109
    test(res==KErrNone);
sl@0
   110
    
sl@0
   111
    res=testLib.Load(EKDATA);
sl@0
   112
    test(res==KErrNone);
sl@0
   113
    testLib.HandleInfo(&handleInfo);
sl@0
   114
    test(handleInfo.iNumOpenInThread==2);
sl@0
   115
    testLib.Close();
sl@0
   116
    res=testLib.Load(DUMMYDLL);
sl@0
   117
    test(res==KErrNone);
sl@0
   118
    testLib.HandleInfo(&handleInfo);
sl@0
   119
    test(handleInfo.iNumOpenInThread==1);
sl@0
   120
    testLib.Close();
sl@0
   121
sl@0
   122
    fLib.Find(_L("*"));
sl@0
   123
    while (fLib.Next(n)==KErrNone)
sl@0
   124
        {
sl@0
   125
        TName findname=pn;
sl@0
   126
        findname+=EKDATA;
sl@0
   127
        test.Printf(_L("  %S\n"),&n);        
sl@0
   128
        if(n.FindF(findname) != KErrNotFound)
sl@0
   129
            break;
sl@0
   130
        }
sl@0
   131
    //The test below fails if we use Secure APIs
sl@0
   132
    //test(n.FindF(EKDATA) == KErrNotSupported);
sl@0
   133
    testConv(_L("\nFirst Special key down"),KEY_DOWN,EXPECT_KEY_PRESS,ESpecialKeyBase,ESpecialKeyBase,0);
sl@0
   134
sl@0
   135
    test.Printf(_L("Change back to Default KeyData\n"));
sl@0
   136
    res=KeyTranslator->ChangeKeyData(_L(""));
sl@0
   137
    test(res==KErrNone);
sl@0
   138
    
sl@0
   139
    res=testLib.Load(EKDATA);
sl@0
   140
    test(res==KErrNone);
sl@0
   141
    testLib.HandleInfo(&handleInfo);
sl@0
   142
    test(handleInfo.iNumOpenInThread==2);
sl@0
   143
    testLib.Close();
sl@0
   144
sl@0
   145
    res=testLib.Load(DUMMYDLL);
sl@0
   146
    test(res==KErrNone);
sl@0
   147
    testLib.HandleInfo(&handleInfo);
sl@0
   148
    test(handleInfo.iNumOpenInThread==1);
sl@0
   149
    testLib.Close();
sl@0
   150
sl@0
   151
    fLib.Find(_L("*"));
sl@0
   152
    while (fLib.Next(n)==KErrNone)
sl@0
   153
        {
sl@0
   154
        TName findname=pn;
sl@0
   155
        findname+=DUMMYDLL;
sl@0
   156
        test.Printf(_L("  %S\n"),&n);        
sl@0
   157
        test(n.FindF(findname) == KErrNotFound);
sl@0
   158
        }
sl@0
   159
    testConv(_L("\nFirst Special key down"),KEY_DOWN,EXPECT_KEY_PRESS,ESpecialKeyBase,ESpecialKeyBase,0);
sl@0
   160
    delete CaptureKeys;
sl@0
   161
    }
sl@0
   162
sl@0
   163
void testUS(const TLocale& aLocale)
sl@0
   164
    {
sl@0
   165
//#ifdef __WINS__
sl@0
   166
    test(aLocale.CountryCode()==1);
sl@0
   167
    test(aLocale.DateFormat()==EDateAmerican);
sl@0
   168
    test(aLocale.TimeFormat()==ETime12);
sl@0
   169
    test(aLocale.CurrencySymbolPosition()==ELocaleBefore);
sl@0
   170
    test(aLocale.CurrencySpaceBetween()==FALSE);
sl@0
   171
    test(aLocale.CurrencyDecimalPlaces()==2);
sl@0
   172
    test(aLocale.CurrencyNegativeInBrackets()==EFalse);
sl@0
   173
    test(aLocale.CurrencyTriadsAllowed()==TRUE);
sl@0
   174
    test(aLocale.ThousandsSeparator()==',');
sl@0
   175
    test(aLocale.DecimalSeparator()=='.');
sl@0
   176
    test(aLocale.DateSeparator(0)==0);
sl@0
   177
    test(aLocale.DateSeparator(1)=='/');
sl@0
   178
    test(aLocale.DateSeparator(2)=='/');
sl@0
   179
    test(aLocale.DateSeparator(3)==0);
sl@0
   180
    test(aLocale.TimeSeparator(0)==0);
sl@0
   181
    test(aLocale.TimeSeparator(1)==':');
sl@0
   182
    test(aLocale.TimeSeparator(2)==':');
sl@0
   183
    test(aLocale.TimeSeparator(3)==0);
sl@0
   184
    test(aLocale.AmPmSymbolPosition()==TRUE);
sl@0
   185
    test(aLocale.AmPmSpaceBetween()==TRUE);
sl@0
   186
    test(aLocale.HomeDaylightSavingZone()==EDstNorthern);
sl@0
   187
    test(aLocale.WorkDays()==0x1f);
sl@0
   188
    test(aLocale.StartOfWeek()==ESunday);
sl@0
   189
    test(aLocale.ClockFormat()==EClockAnalog);
sl@0
   190
    test(aLocale.UnitsGeneral()==EUnitsImperial);
sl@0
   191
    test(aLocale.UnitsDistanceShort()==EUnitsImperial);
sl@0
   192
    test(aLocale.UnitsDistanceLong()==EUnitsImperial);
sl@0
   193
//#endif
sl@0
   194
    }
sl@0
   195
sl@0
   196
sl@0
   197
void testUK(const TLocale& aLocale)
sl@0
   198
    {
sl@0
   199
//#ifdef __WINS__
sl@0
   200
    test(aLocale.CountryCode()==44);
sl@0
   201
    test(aLocale.DateFormat()==EDateEuropean);
sl@0
   202
    test(aLocale.TimeFormat()==ETime12);
sl@0
   203
    test(aLocale.CurrencySymbolPosition()==ELocaleBefore);
sl@0
   204
    test(aLocale.CurrencySpaceBetween()==FALSE);
sl@0
   205
    test(aLocale.CurrencyDecimalPlaces()==2);
sl@0
   206
    test(aLocale.CurrencyNegativeInBrackets()==EFalse);
sl@0
   207
    test(aLocale.CurrencyTriadsAllowed()==TRUE);
sl@0
   208
    test(aLocale.ThousandsSeparator()==',');
sl@0
   209
    test(aLocale.DecimalSeparator()=='.');
sl@0
   210
    test(aLocale.DateSeparator(0)==0);
sl@0
   211
    test(aLocale.DateSeparator(1)=='/');
sl@0
   212
    test(aLocale.DateSeparator(2)=='/');
sl@0
   213
    test(aLocale.DateSeparator(3)==0);
sl@0
   214
    test(aLocale.TimeSeparator(0)==0);
sl@0
   215
    test(aLocale.TimeSeparator(1)==':');
sl@0
   216
    test(aLocale.TimeSeparator(2)==':');
sl@0
   217
    test(aLocale.TimeSeparator(3)==0);
sl@0
   218
    test(aLocale.AmPmSymbolPosition()==TRUE);
sl@0
   219
    test(aLocale.AmPmSpaceBetween()==TRUE);
sl@0
   220
    test(aLocale.HomeDaylightSavingZone()==EDstEuropean);
sl@0
   221
    test(aLocale.WorkDays()==0x1f);
sl@0
   222
    test(aLocale.StartOfWeek()==EMonday);
sl@0
   223
    test(aLocale.ClockFormat()==EClockAnalog);
sl@0
   224
    test(aLocale.UnitsGeneral()==EUnitsImperial);
sl@0
   225
    test(aLocale.UnitsDistanceShort()==EUnitsImperial);
sl@0
   226
    test(aLocale.UnitsDistanceLong()==EUnitsImperial);
sl@0
   227
//#endif
sl@0
   228
    }
sl@0
   229
sl@0
   230
void testGE(const TLocale& aLocale)
sl@0
   231
    {
sl@0
   232
//#ifdef __WINS__
sl@0
   233
    test(aLocale.CountryCode()==49);
sl@0
   234
    test(aLocale.DateFormat()==EDateEuropean);
sl@0
   235
    test(aLocale.TimeFormat()==ETime24);
sl@0
   236
    test(aLocale.CurrencySymbolPosition()==ELocaleAfter);
sl@0
   237
    test(aLocale.CurrencySpaceBetween()==TRUE);
sl@0
   238
    test(aLocale.CurrencyDecimalPlaces()==2);
sl@0
   239
    test(aLocale.CurrencyNegativeInBrackets()==TRUE);
sl@0
   240
    test(aLocale.CurrencyTriadsAllowed()==TRUE);
sl@0
   241
    test(aLocale.ThousandsSeparator()=='.');
sl@0
   242
    test(aLocale.DecimalSeparator()==',');
sl@0
   243
    test(aLocale.DateSeparator(0)==0);
sl@0
   244
    test(aLocale.DateSeparator(1)=='.');
sl@0
   245
    test(aLocale.DateSeparator(2)=='.');
sl@0
   246
    test(aLocale.DateSeparator(3)==0);
sl@0
   247
sl@0
   248
    test(aLocale.TimeSeparator(0)==0);
sl@0
   249
    test(aLocale.TimeSeparator(1)==':');
sl@0
   250
    test(aLocale.TimeSeparator(2)==':');
sl@0
   251
    test(aLocale.TimeSeparator(3)==0);
sl@0
   252
    test(aLocale.AmPmSymbolPosition()==TRUE);
sl@0
   253
    test(aLocale.AmPmSpaceBetween()==TRUE);
sl@0
   254
    test(aLocale.HomeDaylightSavingZone()==EDstEuropean);
sl@0
   255
    test(aLocale.WorkDays()==0x1f);
sl@0
   256
    test(aLocale.StartOfWeek()==EMonday);
sl@0
   257
    test(aLocale.ClockFormat()==EClockDigital);
sl@0
   258
    test(aLocale.UnitsGeneral()==EUnitsMetric);
sl@0
   259
    test(aLocale.UnitsDistanceShort()==EUnitsMetric);
sl@0
   260
    test(aLocale.UnitsDistanceLong()==EUnitsMetric);
sl@0
   261
//#endif
sl@0
   262
    }
sl@0
   263
sl@0
   264
sl@0
   265
sl@0
   266
/**
sl@0
   267
    Subscribe to a system event.
sl@0
   268
sl@0
   269
    @param  aNotifier   notifier
sl@0
   270
    @param  aStatus     request status that is used with the notifier
sl@0
   271
    @param  aEventMask  Specifies the event. See TChanges
sl@0
   272
*/
sl@0
   273
static void SubscribeToSystemChangeNotification(RChangeNotifier& aNotifier, TRequestStatus& aStatus, TUint32 aEventMask)
sl@0
   274
{
sl@0
   275
    
sl@0
   276
    const TInt KMaxAttempts = 100;
sl@0
   277
    TInt i;
sl@0
   278
    for(i=0; i<KMaxAttempts; ++i)
sl@0
   279
    {
sl@0
   280
        test.Printf(_L("SubscribeToSystemChangeNotification(0x%x), attempt:%d\n"), aEventMask, i);   
sl@0
   281
sl@0
   282
        TInt nRes = aNotifier.Logon(aStatus);
sl@0
   283
        test(nRes==KErrNone);
sl@0
   284
sl@0
   285
        if(aStatus.Int() == KRequestPending)
sl@0
   286
            break;
sl@0
   287
sl@0
   288
        //-- some other system-wide event can just happen; re-subscribe
sl@0
   289
        test( !(aStatus.Int() & aEventMask));
sl@0
   290
    }
sl@0
   291
sl@0
   292
    test(i<KMaxAttempts);
sl@0
   293
}
sl@0
   294
sl@0
   295
/**
sl@0
   296
    Wait for the event(s) specified in aEventMask to happen
sl@0
   297
sl@0
   298
    @param  aNotifier   notifier
sl@0
   299
    @param  aStatus     request status that is used with the notifier
sl@0
   300
    @param  aEventMask  Specifies the event. See TChanges
sl@0
   301
*/
sl@0
   302
static void WaitForSystemChange(RChangeNotifier& aNotifier, TRequestStatus& aStatus, TUint32 aEventMask)
sl@0
   303
{
sl@0
   304
    //-- it would be nice to have here a timeout processing in order not to wait forever.. but later.
sl@0
   305
    for(;;)
sl@0
   306
    {
sl@0
   307
        User::WaitForRequest(aStatus);
sl@0
   308
        if(aStatus.Int() & aEventMask)
sl@0
   309
            return; 
sl@0
   310
sl@0
   311
        //-- some other system-wide unexpected event happened, we need to resubscribe
sl@0
   312
        test.Printf(_L("WaitForSystemChange(0x%x), happened:0x%x, resubscribing...\n"), aEventMask, aStatus.Int());   
sl@0
   313
        SubscribeToSystemChangeNotification(aNotifier, aStatus, aEventMask);
sl@0
   314
    }
sl@0
   315
sl@0
   316
}
sl@0
   317
    
sl@0
   318
sl@0
   319
void testChangeLocale()
sl@0
   320
    {
sl@0
   321
    TLocale locale;
sl@0
   322
    
sl@0
   323
    RChangeNotifier notifier;
sl@0
   324
    TInt res=notifier.Create();
sl@0
   325
    test(res==KErrNone);
sl@0
   326
    TRequestStatus stat;
sl@0
   327
    
sl@0
   328
    res=notifier.Logon(stat);
sl@0
   329
    test(res==KErrNone);
sl@0
   330
	// initial value of stat already tested by t_chnot
sl@0
   331
sl@0
   332
    SubscribeToSystemChangeNotification(notifier, stat, EChangesLocale);
sl@0
   333
sl@0
   334
        test.Printf(_L("Change to US Locale\n"));   
sl@0
   335
        res=UserSvr::ChangeLocale(ELOCLUS);
sl@0
   336
        test.Printf(_L("res=%d\n"),res);
sl@0
   337
        test(res==KErrNone);
sl@0
   338
sl@0
   339
    WaitForSystemChange(notifier, stat, EChangesLocale);
sl@0
   340
    test(stat.Int() & EChangesLocale);
sl@0
   341
    
sl@0
   342
    //-------------------
sl@0
   343
    SubscribeToSystemChangeNotification(notifier, stat, EChangesLocale);
sl@0
   344
        
sl@0
   345
        locale.Refresh();
sl@0
   346
        // let's not test localisation data details now that the internationalisation
sl@0
   347
        // team rather than us release the localisation dlls (changed 9/6/98)
sl@0
   348
        testUS(locale);
sl@0
   349
sl@0
   350
        test.Printf(_L("Change to GE Locale\n"));
sl@0
   351
        res=UserSvr::ChangeLocale(ELOCLGE);
sl@0
   352
        test.Printf(_L("res=%d\n"),res);
sl@0
   353
        test(res==KErrNone);
sl@0
   354
sl@0
   355
    WaitForSystemChange(notifier, stat, EChangesLocale);
sl@0
   356
    test(stat.Int() & EChangesLocale);
sl@0
   357
    
sl@0
   358
    //-------------------
sl@0
   359
    
sl@0
   360
    SubscribeToSystemChangeNotification(notifier, stat, EChangesLocale);
sl@0
   361
        
sl@0
   362
        locale.Refresh();
sl@0
   363
        // let's not test localisation data details now that the internationalisation
sl@0
   364
        // team rather than us release the localisation dlls (changed 9/6/98)
sl@0
   365
        testGE(locale);
sl@0
   366
sl@0
   367
        test.Printf(_L("Load non ELOCL type DLL\n"));    
sl@0
   368
        res=UserSvr::ChangeLocale(DUMMYDLL);
sl@0
   369
        test.Printf(_L("res=%d\n"),res);
sl@0
   370
        test(res == KErrNotSupported);
sl@0
   371
    
sl@0
   372
    //-- ensure that there wasn't locale change
sl@0
   373
    const TInt KMaxAttempts = 100;
sl@0
   374
	TInt i;
sl@0
   375
    for(i=0; i<KMaxAttempts; ++i)
sl@0
   376
    {
sl@0
   377
        if(stat ==KRequestPending)
sl@0
   378
            break;
sl@0
   379
        
sl@0
   380
        //-- check that if something system-wide happened, it wasn't a locale change
sl@0
   381
        test(!(stat.Int() & EChangesLocale));
sl@0
   382
        SubscribeToSystemChangeNotification(notifier, stat, EChangesLocale);
sl@0
   383
    }
sl@0
   384
    test(i<KMaxAttempts);
sl@0
   385
sl@0
   386
sl@0
   387
        locale.Refresh();
sl@0
   388
        // let's not test localisation data details now that the internationalisation
sl@0
   389
        // team rather than us release the localisation dlls (changed 9/6/98)
sl@0
   390
        testGE(locale);
sl@0
   391
sl@0
   392
        //This test using US1 locale is for identifying different collation table
sl@0
   393
        //used for matching and comparing. To specify a table to be used in the
sl@0
   394
        //matching we just need to add the TCollationTable::EMatchingTable flag
sl@0
   395
        //inside the TCollationMethods::iFlags
sl@0
   396
        test.Printf(_L("Change to US1 Locale\n"));  
sl@0
   397
        res=UserSvr::ChangeLocale(ELOCLUS1);
sl@0
   398
        test.Printf(_L("res=%d\n"),res);
sl@0
   399
        test(res==KErrNone);
sl@0
   400
    
sl@0
   401
    WaitForSystemChange(notifier, stat, EChangesLocale);
sl@0
   402
    test(stat.Int() & EChangesLocale);
sl@0
   403
sl@0
   404
    
sl@0
   405
    //-------------------
sl@0
   406
    SubscribeToSystemChangeNotification(notifier, stat, EChangesLocale);
sl@0
   407
sl@0
   408
        locale.Refresh();
sl@0
   409
    
sl@0
   410
    //Testing the different collation table used for Matching and Comparing
sl@0
   411
    //after loading this new locale using T_LOCLUS1.DLL.
sl@0
   412
    //test.Printf(_L("Test for differnt collation table for Matching and Comparing\n"));
sl@0
   413
    //TCollationMethod m=*Mem::GetDefaultMatchingTable();
sl@0
   414
    //test(m.iFlags & TCollationMethod::EMatchingTable);
sl@0
   415
    
sl@0
   416
    //The collation table t_locl.cpp can be found in \locl\t_locl.cpp
sl@0
   417
    //Expected collation override for MatchC A==B and a==b
sl@0
   418
    //Expected collation override for CompareC A>B and a>b
sl@0
   419
    //Collation tables cannot be changed at runtime
sl@0
   420
/*  TBuf16<1> a_cap(_L("A"));
sl@0
   421
    TBuf16<1> a_small(_L("a"));
sl@0
   422
    
sl@0
   423
    //Test using the locale independent matching and comparing
sl@0
   424
    test(a_cap.Match(_L("B"))!=0);
sl@0
   425
    test(a_cap.Compare(_L("B"))<0);
sl@0
   426
    test(a_small.Match(_L("b"))!=0);
sl@0
   427
    test(a_small.Compare(_L("b"))<0);
sl@0
   428
    //Test that the default collation table(1st table) is selected here
sl@0
   429
    test(a_cap.CompareC(_L("B"))!=0);
sl@0
   430
    test(a_small.CompareC(_L("b"))!=0);
sl@0
   431
    test(a_cap.CompareC(_L("B"))>0);
sl@0
   432
    test(a_small.CompareC(_L("b"))>0);
sl@0
   433
    //Test that the Matching collation table(3rd table) is selected here
sl@0
   434
    test(a_cap.MatchC(_L("B"))==0);
sl@0
   435
    test(a_small.MatchC(_L("b"))==0);
sl@0
   436
*/
sl@0
   437
        test.Printf(_L("Back to default UK Locale\n"));
sl@0
   438
        res=UserSvr::ChangeLocale(ELOCL_DEFAULT);
sl@0
   439
        test.Printf(_L("res=%d\n"),res);
sl@0
   440
        test(res==KErrNone);
sl@0
   441
    
sl@0
   442
    WaitForSystemChange(notifier, stat, EChangesLocale);
sl@0
   443
    test(stat.Int() & EChangesLocale);
sl@0
   444
    
sl@0
   445
    //-------------------
sl@0
   446
sl@0
   447
    SubscribeToSystemChangeNotification(notifier, stat, EChangesLocale);
sl@0
   448
sl@0
   449
        locale.Refresh();
sl@0
   450
        testUK(locale); 
sl@0
   451
    
sl@0
   452
        //Test for locale which does not have a matching collation table
sl@0
   453
        TCollationMethod m1=*Mem::GetDefaultMatchingTable();
sl@0
   454
        test((m1.iFlags & TCollationMethod::EMatchingTable)==0);
sl@0
   455
sl@0
   456
        //************************************************
sl@0
   457
        test.Printf(_L("Change to US Locale with file open on drive\n"));   
sl@0
   458
    
sl@0
   459
        _LIT(KTestFile, "TEST.TXT");
sl@0
   460
        RFile file;
sl@0
   461
        res = file.Replace(TheFs, KTestFile, 0);
sl@0
   462
        test(res == KErrNone);
sl@0
   463
sl@0
   464
sl@0
   465
        res=UserSvr::ChangeLocale(ELOCLUS);
sl@0
   466
        test.Printf(_L("res=%d\n"),res);
sl@0
   467
        test(res==KErrNone);
sl@0
   468
sl@0
   469
sl@0
   470
    WaitForSystemChange(notifier, stat, EChangesLocale);
sl@0
   471
    test(stat.Int() & EChangesLocale);
sl@0
   472
sl@0
   473
    
sl@0
   474
    //-------------------
sl@0
   475
    SubscribeToSystemChangeNotification(notifier, stat, EChangesLocale);
sl@0
   476
sl@0
   477
sl@0
   478
        _LIT8(KTestData, "Arsenal");
sl@0
   479
        res = file.Write(KTestData);
sl@0
   480
        test(res==KErrNone);
sl@0
   481
        file.Close();
sl@0
   482
sl@0
   483
        res = file.Open(TheFs, KTestFile, 0);
sl@0
   484
        test(res == KErrNone);
sl@0
   485
        file.Close();
sl@0
   486
        res = TheFs.Delete(KTestFile);
sl@0
   487
        test(res==KErrNone);
sl@0
   488
sl@0
   489
    //************************************************
sl@0
   490
sl@0
   491
    //-- close the notifier
sl@0
   492
    notifier.Close();
sl@0
   493
    User::WaitForRequest(stat);
sl@0
   494
    
sl@0
   495
    //-- n.b. it's actually a bad idea to expect _exact_ event completion from the RChangeNotifier, because
sl@0
   496
    //-- this is a system-wide events observer and any of the TChanges events can happen, not only EChangesLocale.
sl@0
   497
    //-- so this test is a bit flawed.
sl@0
   498
sl@0
   499
    //test(stat==KErrGeneral);
sl@0
   500
    }
sl@0
   501
sl@0
   502
const TText * const DateSuffixTable[KMaxSuffixes] =
sl@0
   503
    {
sl@0
   504
    _S("st"),_S("nd"),_S("rd"),_S("th"),_S("th"),
sl@0
   505
    _S("th"),_S("th"),_S("th"),_S("th"),_S("th"),
sl@0
   506
    _S("th"),_S("th"),_S("th"),_S("th"),_S("th"),
sl@0
   507
    _S("th"),_S("th"),_S("th"),_S("th"),_S("th"),
sl@0
   508
    _S("st"),_S("nd"),_S("rd"),_S("th"),_S("th"),
sl@0
   509
    _S("th"),_S("th"),_S("th"),_S("th"),_S("th"),
sl@0
   510
    _S("st")
sl@0
   511
    };
sl@0
   512
sl@0
   513
const TText * const DayTable[KMaxDays] =
sl@0
   514
    {
sl@0
   515
    _S("Monday"),
sl@0
   516
    _S("Tuesday"),
sl@0
   517
    _S("Wednesday"),
sl@0
   518
    _S("Thursday"),
sl@0
   519
    _S("Friday"),
sl@0
   520
    _S("Saturday"),
sl@0
   521
    _S("Sunday")
sl@0
   522
    };
sl@0
   523
sl@0
   524
const TText * const DayAbbTable[KMaxDays] =
sl@0
   525
    {
sl@0
   526
    _S("Mon"),
sl@0
   527
    _S("Tue"),
sl@0
   528
    _S("Wed"),
sl@0
   529
    _S("Thu"),
sl@0
   530
    _S("Fri"),
sl@0
   531
    _S("Sat"),
sl@0
   532
    _S("Sun")
sl@0
   533
    };
sl@0
   534
sl@0
   535
const TText * const MonthTable[KMaxMonths] =
sl@0
   536
    {
sl@0
   537
    _S("January"),
sl@0
   538
    _S("February"),
sl@0
   539
    _S("March"),
sl@0
   540
    _S("April"),
sl@0
   541
    _S("May"),
sl@0
   542
    _S("June"),
sl@0
   543
    _S("July"),
sl@0
   544
    _S("August"),
sl@0
   545
    _S("September"),
sl@0
   546
    _S("October"),
sl@0
   547
    _S("November"),
sl@0
   548
    _S("December")
sl@0
   549
    };
sl@0
   550
sl@0
   551
const TText * const MonthAbbTable[KMaxMonths] =
sl@0
   552
    {
sl@0
   553
    _S("Jan"),
sl@0
   554
    _S("Feb"),
sl@0
   555
    _S("Mar"),
sl@0
   556
    _S("Apr"),
sl@0
   557
    _S("May"),
sl@0
   558
    _S("Jun"),
sl@0
   559
    _S("Jul"),
sl@0
   560
    _S("Aug"),
sl@0
   561
    _S("Sep"),
sl@0
   562
    _S("Oct"),
sl@0
   563
    _S("Nov"),
sl@0
   564
    _S("Dec")
sl@0
   565
    };
sl@0
   566
sl@0
   567
const TText * const AmPmTable[KMaxAmPms] = {_S("am"),_S("pm")};
sl@0
   568
sl@0
   569
void testExtendedUS(TUint aAspect, TExtendedLocale& aLocale)
sl@0
   570
    {
sl@0
   571
    TLocale* loc = aLocale.GetLocale();
sl@0
   572
    testUS(*loc);
sl@0
   573
    
sl@0
   574
    if(aAspect & ELocaleLanguageSettings)
sl@0
   575
        {
sl@0
   576
        TLanguage tl = User::Language();
sl@0
   577
        test(tl == ELangAmerican);
sl@0
   578
        
sl@0
   579
        TDateSuffix datesuffix;
sl@0
   580
        TInt i;
sl@0
   581
        for(i=0;i<KMaxSuffixes;++i)
sl@0
   582
            {
sl@0
   583
            datesuffix.Set(i);
sl@0
   584
            test(datesuffix.Compare(TPtrC(DateSuffixTable[i])) == 0);
sl@0
   585
            }
sl@0
   586
sl@0
   587
        TDayName dayname;
sl@0
   588
        for(i=0;i<KMaxDays;++i)
sl@0
   589
            {
sl@0
   590
            dayname.Set((TDay)i);
sl@0
   591
            test(dayname.Compare(TPtrC(DayTable[i])) == 0);
sl@0
   592
            }
sl@0
   593
sl@0
   594
        TDayNameAbb daynameabb;
sl@0
   595
        for(i=0;i<KMaxDays;++i)
sl@0
   596
            {
sl@0
   597
            daynameabb.Set((TDay)i);
sl@0
   598
            test(daynameabb.Compare(TPtrC(DayAbbTable[i])) == 0);
sl@0
   599
            }
sl@0
   600
sl@0
   601
        TMonthName monthname;
sl@0
   602
        for(i=0;i<KMaxMonths;++i)
sl@0
   603
            {
sl@0
   604
            monthname.Set((TMonth)i);
sl@0
   605
            test(monthname.Compare(TPtrC(MonthTable[i])) == 0);
sl@0
   606
            }
sl@0
   607
sl@0
   608
        TMonthNameAbb monthnameabb;
sl@0
   609
        for(i=0;i<KMaxMonths;++i)
sl@0
   610
            {
sl@0
   611
            monthnameabb.Set((TMonth)i);
sl@0
   612
            test(monthnameabb.Compare(TPtrC(MonthAbbTable[i])) == 0);
sl@0
   613
            }
sl@0
   614
sl@0
   615
        TAmPmName ampmname;
sl@0
   616
        for(i=0;i<KMaxAmPms;++i)
sl@0
   617
            {
sl@0
   618
            ampmname.Set((TAmPm)i);
sl@0
   619
            test(ampmname.Compare(TPtrC(AmPmTable[i])) == 0);
sl@0
   620
            }
sl@0
   621
        }
sl@0
   622
sl@0
   623
    if(aAspect & ELocaleLocaleSettings)
sl@0
   624
        {
sl@0
   625
        TCurrencySymbol symbol;
sl@0
   626
        symbol.Set();
sl@0
   627
        test(symbol.Compare(TPtrC(_S("$"))) == 0);
sl@0
   628
        }
sl@0
   629
sl@0
   630
    if(aAspect & ELocaleTimeDateSettings)
sl@0
   631
        {
sl@0
   632
        TShortDateFormatSpec shortdate;
sl@0
   633
        shortdate.Set();
sl@0
   634
        test(shortdate.Compare(TPtrC(_S("%F%*M/%*D/%Y"))) == 0);
sl@0
   635
sl@0
   636
        TLongDateFormatSpec longdate;
sl@0
   637
        longdate.Set();
sl@0
   638
        test(longdate.Compare(TPtrC(_S("%F%*D%X %N %Y"))) == 0);
sl@0
   639
sl@0
   640
        TTimeFormatSpec spec;
sl@0
   641
        spec.Set();
sl@0
   642
        test(spec.Compare(TPtrC(_S("%F%*I:%T:%S %*A"))) == 0);
sl@0
   643
        }
sl@0
   644
sl@0
   645
    }
sl@0
   646
sl@0
   647
    
sl@0
   648
void testExtendedLocale()
sl@0
   649
    {
sl@0
   650
    TExtendedLocale locale;
sl@0
   651
    locale.LoadLocale(ELOCLUS);
sl@0
   652
    TInt r = locale.SaveSystemSettings();
sl@0
   653
    test(r == KErrNone);
sl@0
   654
    testExtendedUS(ELocaleLanguageSettings | ELocaleCollateSetting | ELocaleLocaleSettings | ELocaleTimeDateSettings, locale);
sl@0
   655
sl@0
   656
    r = locale.SetCurrencySymbol(TPtrC(_S("Leu")));
sl@0
   657
    test(r == KErrNone);
sl@0
   658
    TCurrencySymbol symbol;
sl@0
   659
    symbol.Set();
sl@0
   660
    test(symbol.Compare(TPtrC(_S("Leu"))) == 0);
sl@0
   661
sl@0
   662
    User::SetCurrencySymbol(TPtrC(_S("Le")));
sl@0
   663
    symbol.Set();
sl@0
   664
    test(symbol.Compare(TPtrC(_S("Le"))) == 0);
sl@0
   665
sl@0
   666
    TFileName dllName;
sl@0
   667
    TFileName eloclus;
sl@0
   668
    eloclus.Copy(ELOCLUS);
sl@0
   669
    eloclus.Append(TPtrC(KDLLExtension));
sl@0
   670
    r = locale.GetLocaleDllName(ELocaleLanguageSettings, dllName);
sl@0
   671
    test(r == KErrNone);
sl@0
   672
    test.Printf(_L("dllName looking for %s (%s)\n"), dllName.Ptr(), eloclus.Ptr());
sl@0
   673
    test(dllName.Find(eloclus) != KErrNotFound);
sl@0
   674
    
sl@0
   675
    dllName.FillZ();
sl@0
   676
sl@0
   677
    r = locale.GetLocaleDllName(ELocaleCollateSetting, dllName);
sl@0
   678
    test(r == KErrNone);
sl@0
   679
    test(dllName.Find(eloclus) != KErrNotFound);
sl@0
   680
    
sl@0
   681
    dllName.FillZ();
sl@0
   682
sl@0
   683
    r = locale.GetLocaleDllName(ELocaleLocaleSettings, dllName);
sl@0
   684
    test(r == KErrNone);
sl@0
   685
    test(dllName.Find(eloclus) != KErrNotFound);
sl@0
   686
    
sl@0
   687
    dllName.FillZ();
sl@0
   688
sl@0
   689
    r = locale.GetLocaleDllName(ELocaleTimeDateSettings, dllName);
sl@0
   690
    test(r == KErrNone);
sl@0
   691
    test(dllName.Find(eloclus) != KErrNotFound);
sl@0
   692
    
sl@0
   693
    dllName.FillZ();
sl@0
   694
sl@0
   695
    r = locale.LoadLocaleAspect(ELocaleLocaleSettings | ELocaleTimeDateSettings, ELOCLGE);
sl@0
   696
    test(r == KErrNone);
sl@0
   697
sl@0
   698
    r = locale.SaveSystemSettings();
sl@0
   699
    test(r == KErrNone);
sl@0
   700
sl@0
   701
    testExtendedUS(ELocaleLanguageSettings | ELocaleCollateSetting, locale);
sl@0
   702
sl@0
   703
    symbol.Set();
sl@0
   704
    test(symbol.Compare(TPtrC(_S("DM"))) == 0);
sl@0
   705
sl@0
   706
    TShortDateFormatSpec shortdate;
sl@0
   707
    shortdate.Set();
sl@0
   708
    test(shortdate.Compare(TPtrC(_S("%F%*D.%*M.%Y"))) == 0);
sl@0
   709
sl@0
   710
    TLongDateFormatSpec longdate;
sl@0
   711
    longdate.Set();
sl@0
   712
    test(longdate.Compare(TPtrC(_S("%F%*D%X %N %Y"))) == 0);
sl@0
   713
sl@0
   714
    TTimeFormatSpec spec;
sl@0
   715
    spec.Set();
sl@0
   716
    test(spec.Compare(TPtrC(_S("%F%H:%T:%S"))) == 0);
sl@0
   717
sl@0
   718
    TFileName eloclge;
sl@0
   719
    eloclge.Copy(ELOCLGE);
sl@0
   720
    eloclge.Append(KDLLExtension);
sl@0
   721
    r = locale.GetLocaleDllName(ELocaleLanguageSettings, dllName);
sl@0
   722
    test(r == KErrNone);
sl@0
   723
    test(dllName.Find(eloclus) != KErrNotFound);
sl@0
   724
    
sl@0
   725
    dllName.FillZ();
sl@0
   726
sl@0
   727
    r = locale.GetLocaleDllName(ELocaleCollateSetting, dllName);
sl@0
   728
    test(r == KErrNone);
sl@0
   729
    test(dllName.Find(eloclus) != KErrNotFound);
sl@0
   730
    
sl@0
   731
    dllName.FillZ();
sl@0
   732
sl@0
   733
    r = locale.GetLocaleDllName(ELocaleLocaleSettings, dllName);
sl@0
   734
    test(r == KErrNone);
sl@0
   735
    test(dllName.Find(eloclge) != KErrNotFound);
sl@0
   736
    
sl@0
   737
    dllName.FillZ();
sl@0
   738
sl@0
   739
    r = locale.GetLocaleDllName(ELocaleTimeDateSettings, dllName);
sl@0
   740
    test(r == KErrNone);
sl@0
   741
    test(dllName.Find(eloclge) != KErrNotFound);
sl@0
   742
    
sl@0
   743
    dllName.FillZ();
sl@0
   744
sl@0
   745
    }
sl@0
   746
sl@0
   747
void testDigitsInMonthsNames()
sl@0
   748
    {
sl@0
   749
    test.Next(_L("Testing date parsing when month names include digits"));
sl@0
   750
sl@0
   751
    TTime time;
sl@0
   752
    _LIT(KMonthJan, "30 Th1 2006 14:31:50");
sl@0
   753
    test_Equal(KErrArgument, time.Parse(KMonthJan));
sl@0
   754
    test_KErrNone(UserSvr::ChangeLocale(ELOCLUS2));
sl@0
   755
    test_Equal(EParseDatePresent | EParseTimePresent, time.Parse(KMonthJan));
sl@0
   756
    test_KErrNone(UserSvr::ChangeLocale(ELOCL_DEFAULT));
sl@0
   757
    }
sl@0
   758
sl@0
   759
GLDEF_C void CallTestsL(void)
sl@0
   760
    {
sl@0
   761
sl@0
   762
    test.Title();
sl@0
   763
    test.Start(_L("Starting T_DLOCL tests"));
sl@0
   764
sl@0
   765
    testChangeLocale();
sl@0
   766
    testChangeKeyData();
sl@0
   767
    testExtendedLocale();
sl@0
   768
    testDigitsInMonthsNames();
sl@0
   769
    test.Next(_L("Close connection to the file server\n"));
sl@0
   770
sl@0
   771
    test.End();
sl@0
   772
    }
sl@0
   773