os/ossrv/lowlevellibsandfws/apputils/initLocale/test/T_LocaleFlexiNewLocaleModel.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 "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 // This file contains RTest based tests which check flexibility of Locale.
    15 // That are, 1. Selectable from Multiple traditional locale 2. Loaded all from a single traditional locale.
    16 // 
    17 //
    18 
    19 #include <bautils.h>
    20 #include <f32file.h>
    21 #include <e32cmn.h>
    22 #include <e32test.h>
    23 #include <e32std.h>
    24 #include <e32const.h>
    25 #include <babackup.h>
    26 #include <hal.h>
    27 #include <centralrepository.h>
    28 #include "LocaleRepository.h"
    29 #include "InitialiseLocale.h"
    30 #include "T_CheckLocale.h"
    31 
    32 
    33 _LIT(KInitPersistLocaleExeName, "InitialiseLocale.exe");
    34 
    35 LOCAL_D RTest test(_L("T_LocaleFlexiNewLocaleModel"));
    36 
    37 
    38 /**
    39 @SYMTestCaseID		SYSLIB-BAFL-CIT-0140
    40 @SYMTestCaseDesc 	Check that locale settings can be selected from several traditional locale
    41 @SYMTestPriority 	High
    42 @SYMTestActions  	Ensure that locales are selected, system set and persisted
    43 @SYMTestExpectedResults The test must not fail.
    44 @SYMREQ PREQ1001
    45 */
    46 LOCAL_D	void ChangeLocaleNewCombination()
    47 	{
    48 	test.Start(_L(" @SYMTestCaseID:SYSLIB-BAFL-CIT-0140 \nTest to demonstrate Locale settings by multiple traditional locale "));
    49 
    50 	TExtendedLocale myExtendedLocale;
    51 	myExtendedLocale.LoadSystemSettings();
    52 
    53     TBuf<KMaxFullName> languageDllName(KUSLanguage);
    54     TBuf<KMaxFullName> regionDllName(KCNRegion);
    55     TBuf<KMaxFullName> collationDllName(KGECollation);
    56 
    57     test( KErrNone == myExtendedLocale.LoadLocaleAspect(languageDllName));
    58     test( KErrNone == myExtendedLocale.LoadLocaleAspect(regionDllName));
    59     test( KErrNone ==myExtendedLocale.LoadLocaleAspect(collationDllName));
    60 	
    61     test( KErrNone ==myExtendedLocale.SaveSystemSettings());
    62 
    63 	// Wait
    64 	User::After(10000000);
    65 
    66 	TUid LocaleRepositoryUid ;
    67 	LocaleRepositoryUid.iUid = KLocalePersistRepositoryUid ;
    68 
    69 	CRepository* repository = CRepository::NewLC(LocaleRepositoryUid);
    70 
    71     // To get names of DLLs to be loaded
    72     TBuf<KMaxFullName> aDllName ;
    73 
    74     // Test for the language settings
    75     TInt err = repository->Get(KLocaleLanguageDll, aDllName);
    76     if (err != KErrNone)
    77         {
    78         // Failed to read DLL name, bail out!
    79         CleanupStack::PopAndDestroy(repository) ;
    80         return ;
    81         }
    82     
    83     test.Printf(_L("\nThe lagnuage DLL names in CRepository is: %S"), &aDllName);
    84     test( KErrNotFound != aDllName.Find(languageDllName));
    85 
    86     err = repository->Get(KLocaleCollationDll, aDllName);
    87     if (err != KErrNone)
    88         {
    89         // Failed to read DLL name, bail out!
    90         CleanupStack::PopAndDestroy(repository) ;
    91         return ;
    92         }
    93     
    94     test.Printf(_L("\nThe collation DLL names in CRepository is: %S"), &aDllName);
    95     test( KErrNotFound != aDllName.Find(collationDllName));
    96 
    97     
    98    err = repository->Get(KLocaleLocaleDll, aDllName);
    99     if (err != KErrNone)
   100         {
   101         // Failed to read DLL name, bail out!
   102         CleanupStack::PopAndDestroy(repository) ;
   103         return ;
   104         }
   105     
   106     test.Printf(_L("\nThe Region DLL names in CRepository is: %S"), &aDllName);
   107     test( KErrNotFound != aDllName.Find(regionDllName));
   108     
   109 	// Free the central repository object
   110 	CleanupStack::PopAndDestroy (repository);
   111 	test.End() ;
   112 	
   113     //becasue we check whether locale content can be persisted is the system in this code block , we mark this test case here.
   114     test.Start(_L(" @SYMTestCaseID:TI18N-INITLOCALE-CT-4005 persist system locale content"));
   115     test.End();
   116 	}
   117 
   118 /**
   119 @SYMTestCaseID		SYSLIB-BAFL-CIT-0141
   120 @SYMTestCaseDesc 	Check that locale settings can be selected from single traditional locale. Also prepare the data for T_RebootNewLocaleModel
   121 @SYMTestPriority 	High
   122 @SYMTestActions  	Ensure that all settings are loaded from a DLL, system set and persisted
   123 @SYMTestExpectedResults The test must not fail.
   124 @SYMREQ PREQ1001
   125 */
   126 LOCAL_D void ChangeLocaleExistedCombination()
   127 	{
   128 	test.Start(_L(" @SYMTestCaseID:SYSLIB-BAFL-CIT-0141 Test to demonstrate change of Locale from one traditional locale "));
   129 
   130 	TExtendedLocale myExtendedLocale;
   131 	myExtendedLocale.LoadSystemSettings() ;
   132 
   133 	TBuf<KMaxFullName> languageDllName(KCNLanguage);
   134 	TBuf<KMaxFullName> regionDllName(KCNRegion);
   135 	TBuf<KMaxFullName> collationDllName(KCNCollation);
   136 	
   137 	test.Printf(_L("Changing all 3 Locale aspects to Chinese"));
   138 
   139 	// Change the locale to Chinese Locale, all settings from single Dll
   140 	myExtendedLocale.LoadLocale(languageDllName, regionDllName, collationDllName);
   141 
   142 	// Save the changes to system settings
   143 	myExtendedLocale.SaveSystemSettings();
   144 
   145 	// Wait
   146 	User::After(10000000);
   147 
   148 	TUid LocaleRepositoryUid ;
   149 	LocaleRepositoryUid.iUid = KLocalePersistRepositoryUid;
   150 	CRepository* repository = CRepository::NewLC(LocaleRepositoryUid) ;
   151 
   152 	// To get names of DLLs to be loaded
   153 	TBuf<KMaxFullName> aDllName ;
   154 
   155 	// Test for the language settings
   156 	TInt err = repository->Get(KLocaleLanguageDll, aDllName);
   157 	if (err != KErrNone)
   158 		{
   159 		// Failed to read DLL name, bail out!
   160 		CleanupStack::PopAndDestroy(repository) ;
   161 		return ;
   162 		}
   163 	
   164 	test( KErrNotFound != aDllName.Find(languageDllName));
   165 
   166     err = repository->Get(KLocaleCollationDll, aDllName);
   167     if (err != KErrNone)
   168         {
   169         // Failed to read DLL name, bail out!
   170         CleanupStack::PopAndDestroy(repository) ;
   171         return ;
   172         }
   173     
   174     test( KErrNotFound != aDllName.Find(collationDllName));
   175 
   176     
   177     err = repository->Get(KLocaleLocaleDll, aDllName);
   178     if (err != KErrNone)
   179         {
   180         // Failed to read DLL name, bail out!
   181         CleanupStack::PopAndDestroy(repository) ;
   182         return ;
   183         }
   184     
   185     test( KErrNotFound != aDllName.Find(regionDllName));
   186     
   187     
   188     
   189 	CleanupStack::PopAndDestroy (repository);
   190 	test.End();
   191 	}
   192 //prepare for the reboot test
   193 void Prepare4forRebootTest()
   194     {
   195     TExtendedLocale myExtendedLocale;
   196     myExtendedLocale.LoadSystemSettings();
   197     test( KErrNone == myExtendedLocale.LoadLocale(KCNLanguage(), KCNRegion(), KCNCollation() ));
   198     test( KErrNone == myExtendedLocale.SaveSystemSettings());
   199     User::After(10000000);
   200     }
   201 
   202 // Call the tests that test flexibility of Locale
   203 void TestLocaleFlexibility()
   204 	{
   205 	
   206     RProcess process;
   207 
   208     // Kick-in InitialiseLocale.exe, This will be done as part of system start in actual
   209     // release code!
   210     TInt r = process.Create(KInitPersistLocaleExeName, KNullDesC);
   211     if(r == KErrNone)
   212         {
   213         process.Resume(); // Start the process going
   214         User::After(1000000);
   215 
   216         ChangeLocaleNewCombination();
   217         ChangeLocaleExistedCombination();
   218 
   219         User::After(1000000);
   220         Prepare4forRebootTest();
   221         User::After(1000000);
   222         process.Close();
   223         User::After(1000000);
   224         }
   225 
   226 	}
   227 
   228 
   229 
   230 TInt E32Main()
   231 	{
   232 	CTrapCleanup* cleanup = CTrapCleanup::New();
   233 	test(cleanup != NULL);
   234 
   235 	__UHEAP_MARK;
   236 	test.Start(_L("Test to demonstrate Locale flexibility in new locale model"));
   237 	test.Title();
   238 
   239 	TRAPD(err, ::TestLocaleFlexibility());
   240 
   241 	test(err == KErrNone);
   242     
   243 	test.End();
   244 	test.Close();
   245 
   246 	__UHEAP_MARKEND;
   247 	delete cleanup;
   248 
   249 	return(KErrNone);
   250 	}