os/ossrv/lowlevellibsandfws/apputils/initLocale/test/T_LocaleFlexiNewLocaleModel.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/lowlevellibsandfws/apputils/initLocale/test/T_LocaleFlexiNewLocaleModel.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,250 @@
1.4 +// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// This file contains RTest based tests which check flexibility of Locale.
1.18 +// That are, 1. Selectable from Multiple traditional locale 2. Loaded all from a single traditional locale.
1.19 +//
1.20 +//
1.21 +
1.22 +#include <bautils.h>
1.23 +#include <f32file.h>
1.24 +#include <e32cmn.h>
1.25 +#include <e32test.h>
1.26 +#include <e32std.h>
1.27 +#include <e32const.h>
1.28 +#include <babackup.h>
1.29 +#include <hal.h>
1.30 +#include <centralrepository.h>
1.31 +#include "LocaleRepository.h"
1.32 +#include "InitialiseLocale.h"
1.33 +#include "T_CheckLocale.h"
1.34 +
1.35 +
1.36 +_LIT(KInitPersistLocaleExeName, "InitialiseLocale.exe");
1.37 +
1.38 +LOCAL_D RTest test(_L("T_LocaleFlexiNewLocaleModel"));
1.39 +
1.40 +
1.41 +/**
1.42 +@SYMTestCaseID SYSLIB-BAFL-CIT-0140
1.43 +@SYMTestCaseDesc Check that locale settings can be selected from several traditional locale
1.44 +@SYMTestPriority High
1.45 +@SYMTestActions Ensure that locales are selected, system set and persisted
1.46 +@SYMTestExpectedResults The test must not fail.
1.47 +@SYMREQ PREQ1001
1.48 +*/
1.49 +LOCAL_D void ChangeLocaleNewCombination()
1.50 + {
1.51 + test.Start(_L(" @SYMTestCaseID:SYSLIB-BAFL-CIT-0140 \nTest to demonstrate Locale settings by multiple traditional locale "));
1.52 +
1.53 + TExtendedLocale myExtendedLocale;
1.54 + myExtendedLocale.LoadSystemSettings();
1.55 +
1.56 + TBuf<KMaxFullName> languageDllName(KUSLanguage);
1.57 + TBuf<KMaxFullName> regionDllName(KCNRegion);
1.58 + TBuf<KMaxFullName> collationDllName(KGECollation);
1.59 +
1.60 + test( KErrNone == myExtendedLocale.LoadLocaleAspect(languageDllName));
1.61 + test( KErrNone == myExtendedLocale.LoadLocaleAspect(regionDllName));
1.62 + test( KErrNone ==myExtendedLocale.LoadLocaleAspect(collationDllName));
1.63 +
1.64 + test( KErrNone ==myExtendedLocale.SaveSystemSettings());
1.65 +
1.66 + // Wait
1.67 + User::After(10000000);
1.68 +
1.69 + TUid LocaleRepositoryUid ;
1.70 + LocaleRepositoryUid.iUid = KLocalePersistRepositoryUid ;
1.71 +
1.72 + CRepository* repository = CRepository::NewLC(LocaleRepositoryUid);
1.73 +
1.74 + // To get names of DLLs to be loaded
1.75 + TBuf<KMaxFullName> aDllName ;
1.76 +
1.77 + // Test for the language settings
1.78 + TInt err = repository->Get(KLocaleLanguageDll, aDllName);
1.79 + if (err != KErrNone)
1.80 + {
1.81 + // Failed to read DLL name, bail out!
1.82 + CleanupStack::PopAndDestroy(repository) ;
1.83 + return ;
1.84 + }
1.85 +
1.86 + test.Printf(_L("\nThe lagnuage DLL names in CRepository is: %S"), &aDllName);
1.87 + test( KErrNotFound != aDllName.Find(languageDllName));
1.88 +
1.89 + err = repository->Get(KLocaleCollationDll, aDllName);
1.90 + if (err != KErrNone)
1.91 + {
1.92 + // Failed to read DLL name, bail out!
1.93 + CleanupStack::PopAndDestroy(repository) ;
1.94 + return ;
1.95 + }
1.96 +
1.97 + test.Printf(_L("\nThe collation DLL names in CRepository is: %S"), &aDllName);
1.98 + test( KErrNotFound != aDllName.Find(collationDllName));
1.99 +
1.100 +
1.101 + err = repository->Get(KLocaleLocaleDll, aDllName);
1.102 + if (err != KErrNone)
1.103 + {
1.104 + // Failed to read DLL name, bail out!
1.105 + CleanupStack::PopAndDestroy(repository) ;
1.106 + return ;
1.107 + }
1.108 +
1.109 + test.Printf(_L("\nThe Region DLL names in CRepository is: %S"), &aDllName);
1.110 + test( KErrNotFound != aDllName.Find(regionDllName));
1.111 +
1.112 + // Free the central repository object
1.113 + CleanupStack::PopAndDestroy (repository);
1.114 + test.End() ;
1.115 +
1.116 + //becasue we check whether locale content can be persisted is the system in this code block , we mark this test case here.
1.117 + test.Start(_L(" @SYMTestCaseID:TI18N-INITLOCALE-CT-4005 persist system locale content"));
1.118 + test.End();
1.119 + }
1.120 +
1.121 +/**
1.122 +@SYMTestCaseID SYSLIB-BAFL-CIT-0141
1.123 +@SYMTestCaseDesc Check that locale settings can be selected from single traditional locale. Also prepare the data for T_RebootNewLocaleModel
1.124 +@SYMTestPriority High
1.125 +@SYMTestActions Ensure that all settings are loaded from a DLL, system set and persisted
1.126 +@SYMTestExpectedResults The test must not fail.
1.127 +@SYMREQ PREQ1001
1.128 +*/
1.129 +LOCAL_D void ChangeLocaleExistedCombination()
1.130 + {
1.131 + test.Start(_L(" @SYMTestCaseID:SYSLIB-BAFL-CIT-0141 Test to demonstrate change of Locale from one traditional locale "));
1.132 +
1.133 + TExtendedLocale myExtendedLocale;
1.134 + myExtendedLocale.LoadSystemSettings() ;
1.135 +
1.136 + TBuf<KMaxFullName> languageDllName(KCNLanguage);
1.137 + TBuf<KMaxFullName> regionDllName(KCNRegion);
1.138 + TBuf<KMaxFullName> collationDllName(KCNCollation);
1.139 +
1.140 + test.Printf(_L("Changing all 3 Locale aspects to Chinese"));
1.141 +
1.142 + // Change the locale to Chinese Locale, all settings from single Dll
1.143 + myExtendedLocale.LoadLocale(languageDllName, regionDllName, collationDllName);
1.144 +
1.145 + // Save the changes to system settings
1.146 + myExtendedLocale.SaveSystemSettings();
1.147 +
1.148 + // Wait
1.149 + User::After(10000000);
1.150 +
1.151 + TUid LocaleRepositoryUid ;
1.152 + LocaleRepositoryUid.iUid = KLocalePersistRepositoryUid;
1.153 + CRepository* repository = CRepository::NewLC(LocaleRepositoryUid) ;
1.154 +
1.155 + // To get names of DLLs to be loaded
1.156 + TBuf<KMaxFullName> aDllName ;
1.157 +
1.158 + // Test for the language settings
1.159 + TInt err = repository->Get(KLocaleLanguageDll, aDllName);
1.160 + if (err != KErrNone)
1.161 + {
1.162 + // Failed to read DLL name, bail out!
1.163 + CleanupStack::PopAndDestroy(repository) ;
1.164 + return ;
1.165 + }
1.166 +
1.167 + test( KErrNotFound != aDllName.Find(languageDllName));
1.168 +
1.169 + err = repository->Get(KLocaleCollationDll, aDllName);
1.170 + if (err != KErrNone)
1.171 + {
1.172 + // Failed to read DLL name, bail out!
1.173 + CleanupStack::PopAndDestroy(repository) ;
1.174 + return ;
1.175 + }
1.176 +
1.177 + test( KErrNotFound != aDllName.Find(collationDllName));
1.178 +
1.179 +
1.180 + err = repository->Get(KLocaleLocaleDll, aDllName);
1.181 + if (err != KErrNone)
1.182 + {
1.183 + // Failed to read DLL name, bail out!
1.184 + CleanupStack::PopAndDestroy(repository) ;
1.185 + return ;
1.186 + }
1.187 +
1.188 + test( KErrNotFound != aDllName.Find(regionDllName));
1.189 +
1.190 +
1.191 +
1.192 + CleanupStack::PopAndDestroy (repository);
1.193 + test.End();
1.194 + }
1.195 +//prepare for the reboot test
1.196 +void Prepare4forRebootTest()
1.197 + {
1.198 + TExtendedLocale myExtendedLocale;
1.199 + myExtendedLocale.LoadSystemSettings();
1.200 + test( KErrNone == myExtendedLocale.LoadLocale(KCNLanguage(), KCNRegion(), KCNCollation() ));
1.201 + test( KErrNone == myExtendedLocale.SaveSystemSettings());
1.202 + User::After(10000000);
1.203 + }
1.204 +
1.205 +// Call the tests that test flexibility of Locale
1.206 +void TestLocaleFlexibility()
1.207 + {
1.208 +
1.209 + RProcess process;
1.210 +
1.211 + // Kick-in InitialiseLocale.exe, This will be done as part of system start in actual
1.212 + // release code!
1.213 + TInt r = process.Create(KInitPersistLocaleExeName, KNullDesC);
1.214 + if(r == KErrNone)
1.215 + {
1.216 + process.Resume(); // Start the process going
1.217 + User::After(1000000);
1.218 +
1.219 + ChangeLocaleNewCombination();
1.220 + ChangeLocaleExistedCombination();
1.221 +
1.222 + User::After(1000000);
1.223 + Prepare4forRebootTest();
1.224 + User::After(1000000);
1.225 + process.Close();
1.226 + User::After(1000000);
1.227 + }
1.228 +
1.229 + }
1.230 +
1.231 +
1.232 +
1.233 +TInt E32Main()
1.234 + {
1.235 + CTrapCleanup* cleanup = CTrapCleanup::New();
1.236 + test(cleanup != NULL);
1.237 +
1.238 + __UHEAP_MARK;
1.239 + test.Start(_L("Test to demonstrate Locale flexibility in new locale model"));
1.240 + test.Title();
1.241 +
1.242 + TRAPD(err, ::TestLocaleFlexibility());
1.243 +
1.244 + test(err == KErrNone);
1.245 +
1.246 + test.End();
1.247 + test.Close();
1.248 +
1.249 + __UHEAP_MARKEND;
1.250 + delete cleanup;
1.251 +
1.252 + return(KErrNone);
1.253 + }