os/kernelhwsrv/kerneltest/f32test/locl/t_locChange.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2005-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 the License "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 
    16 #include <e32test.h>
    17 #include <f32file.h>
    18 #include <e32svr.h>
    19 
    20 _LIT(KGerLocale, "T_LOCLGE.DLL");
    21 _LIT(KEngLocale, "T_LOCLUS.DLL");
    22 
    23 #ifndef __WINS__  
    24 _LIT(KEngLocaleRAM, "T_LOCLUS_RAM.DLL"); //this should be RAM-loaded library.. 
    25 #else 
    26 _LIT(KEngLocaleRAM, "T_LOCLUS.DLL"); 
    27 #endif
    28     
    29 // 
    30 class RTestSafeLocale : public RTest
    31     {
    32     public:
    33     RTestSafeLocale(const TDesC &aTitle):  RTest(aTitle),  iFailHdnFunc(NULL) {}
    34     RTestSafeLocale(const TDesC &aTitle, void(*func)(RTest &aTest)) : RTest(aTitle), iFailHdnFunc(func) {}
    35     
    36     //new wersion of operator, which calls handler if check failed
    37     void operator()(TInt aResult)
    38         {
    39         if (!aResult && iFailHdnFunc) iFailHdnFunc(*this);
    40         RTest::operator ()(aResult);
    41         }
    42     
    43     //new version of End, which calls handler before exit..
    44     IMPORT_C void End() 
    45         { 
    46         if (iFailHdnFunc) iFailHdnFunc(*this);
    47         RTest::End();
    48         }
    49     
    50     //pointer to handler..
    51     void (*iFailHdnFunc)(RTest &aTest);
    52     };
    53     
    54 // cleanup handler, which restores default locale on test end or failure..
    55 void TestCleanup(RTest &aTest)
    56     {
    57     aTest.Printf(_L("\nTest cleanup: changing locale to default..\n"));
    58     UserSvr::ChangeLocale(_L(""));
    59     aTest.Printf(_L("Default language: %d\n"), User::Language());
    60     }
    61 
    62 // global gTest object..
    63 RTestSafeLocale gTest(_L("T_LOCCHANGE"), &TestCleanup);
    64 
    65 // try to load locale dll prior to changing it..
    66 TInt LoadLocaleCrash(const TDesC& aName)
    67     {
    68     //First - load the library.. 
    69     RLibrary lib;
    70     TInt err = lib.Load(aName);
    71     if (err)
    72         {
    73         gTest.Printf(_L("\nRLibrary::Load() failed, err %d"), err);
    74         return err;
    75         }
    76     // try to change locale.. (it should ignore the previously loaded library.. 
    77     // and load locale library again in the global area.
    78     err = UserSvr::ChangeLocale(aName);
    79     if (err)
    80         {
    81         gTest.Printf(_L("\nUserSvr::ChangeLocale() failed, err %d"), err);
    82         return err;
    83         }
    84 
    85     lib.Close();
    86     return KErrNone;
    87     }
    88 
    89 // change locale normally..
    90 TInt LoadLocale(const TDesC& aName)
    91     {
    92     TInt r = UserSvr::ChangeLocale(aName);
    93     if (r != KErrNone)
    94         return r;
    95     return KErrNone;
    96     }
    97 
    98 // main..
    99 TInt E32Main()
   100     {
   101     gTest.Start(_L("Test Locale Change\n"));
   102 
   103     TInt r;
   104     RChangeNotifier notifier;
   105     TRequestStatus status;
   106     gTest(notifier.Create() == KErrNone);
   107     gTest(notifier.Logon(status) == KErrNone);
   108     User::WaitForRequest(status);
   109 
   110     // Monitor locale change event
   111     gTest(notifier.Logon(status) == KErrNone);
   112     
   113     r = LoadLocale(KGerLocale);
   114     gTest(r == KErrNone);
   115     User::WaitForRequest(status);
   116     gTest(status.Int() & EChangesLocale);
   117     gTest.Printf(_L("New Language: %d\n"), User::Language());
   118     gTest(notifier.Logon(status) == KErrNone);
   119 
   120     r = LoadLocale(KEngLocale);
   121     gTest(r == KErrNone);
   122     User::WaitForRequest(status);
   123     gTest(status.Int() & EChangesLocale);
   124     gTest.Printf(_L("New Language: %d\n"), User::Language());
   125     gTest(notifier.Logon(status) == KErrNone);
   126 
   127     r = LoadLocaleCrash(KEngLocaleRAM);
   128     gTest(r == KErrNone);
   129     User::WaitForRequest(status);
   130     gTest(status.Int() & EChangesLocale);
   131     gTest.Printf(_L("New Language: %d\n"), User::Language());
   132     
   133     notifier.Close();
   134     gTest.End();
   135     return 0;
   136     }