os/ossrv/lowlevellibsandfws/apputils/initLocale/test/T_LocaleFlexiOldLocaleModel.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/lowlevellibsandfws/apputils/initLocale/test/T_LocaleFlexiOldLocaleModel.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,326 @@
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 Dlls 2. Loaded all from a single Dll
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 +
1.34 +
1.35 +// Name of the exe to be called explicitly
1.36 +_LIT(KInitPersistLocaleExeName, "InitialiseLocale.exe");
1.37 +_LIT(KFrenchLocale, "elocl.02");
1.38 +
1.39 +_LIT(KSpanishLocale, "elocl.04");
1.40 +
1.41 +// Central Repository Data cage file-path
1.42 +_LIT(KPersistLocale, "C:\\private\\10202be9\\persists\\1020E4D3.*");
1.43 +
1.44 +LOCAL_D RTest TheTest(_L("T_LocaleFlexiOldLocaleModel"));
1.45 +
1.46 +RFs TheFs;
1.47 +
1.48 +TExtendedLocale initialExtendedLocale;
1.49 +
1.50 +
1.51 +void GetInitialLocaleSettings()
1.52 + {
1.53 + initialExtendedLocale.LoadSystemSettings() ;
1.54 + }
1.55 +
1.56 +void RestoreInitialLocaleSettings()
1.57 + {
1.58 + initialExtendedLocale.SaveSystemSettings() ;
1.59 + User::After(1000000);
1.60 + }
1.61 +
1.62 +//Test macros and functions
1.63 +
1.64 +LOCAL_C void Check(TInt aValue, TInt aLine)
1.65 + {
1.66 + if(!aValue)
1.67 + {
1.68 + RestoreInitialLocaleSettings();
1.69 + TheTest(EFalse, aLine);
1.70 + }
1.71 + }
1.72 +
1.73 +LOCAL_C void Check(TInt aValue, TInt aExpected, TInt aLine)
1.74 + {
1.75 + if(aValue != aExpected)
1.76 + {
1.77 + RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
1.78 + RestoreInitialLocaleSettings();
1.79 + TheTest(EFalse, aLine);
1.80 + }
1.81 + }
1.82 +
1.83 +
1.84 +#define TEST(arg) ::Check((arg), __LINE__)
1.85 +#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
1.86 +
1.87 +/*
1.88 +This function prepares for next test i.e, tests InitialiseLocale behaves
1.89 +when persisted file is damaged/corrupt.
1.90 +*/
1.91 +void SetUpTestCorruptLocale()
1.92 + {
1.93 + TExtendedLocale myExtendedLocale;
1.94 + myExtendedLocale.LoadSystemSettings() ;
1.95 +
1.96 + TBuf<100> DllName;
1.97 + DllName.Copy(KFrenchLocale);
1.98 +
1.99 + TheTest.Printf(_L("\n Changing Locale to French Locale(02) so that default values are evident"));
1.100 +
1.101 + // Change the locale to Default Locale, all settings from single Dll
1.102 + myExtendedLocale.LoadLocale(DllName);
1.103 +
1.104 + // Save the changes to system settings
1.105 + myExtendedLocale.SaveSystemSettings();
1.106 +
1.107 + // Wait so that it persists to repository
1.108 + User::After(1000000);
1.109 +
1.110 + User::LeaveIfError(TheFs.Connect());
1.111 + // Delete/damage the persisted file so that InitialiseLocale.exe
1.112 + // detects the damage and loads default locale
1.113 + BaflUtils::DeleteFile(TheFs, KPersistLocale);
1.114 + TheFs.Close();
1.115 + TheTest.Printf(_L("\n Deleted persist file from C: \n"));
1.116 + }
1.117 +
1.118 +/**
1.119 +@SYMTestCaseID SYSLIB-BAFL-CIT-0140
1.120 +@SYMTestCaseDesc Check that locale settings can be selected from several DLLs
1.121 +@SYMTestPriority High
1.122 +@SYMTestActions Ensure that locales are selected, system set and persisted
1.123 +@SYMTestExpectedResults The test must not fail.
1.124 +@SYMREQ PREQ1001
1.125 +*/
1.126 +LOCAL_D void ChangeLocaleMultiDll()
1.127 + {
1.128 + TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-BAFL-CIT-0140 \nTest to demonstrate Locale settings by multiple DLLs "));
1.129 +
1.130 + TExtendedLocale myExtendedLocale;
1.131 + myExtendedLocale.LoadSystemSettings();
1.132 +
1.133 + TBuf<100> DllName1 ;
1.134 + DllName1.Copy(KFrenchLocale);
1.135 +
1.136 + TBuf<100> DllName2 ;
1.137 + DllName2.Copy(KSpanishLocale);
1.138 +
1.139 + TheTest.Printf(_L("Changing Language to Spanish "));
1.140 +
1.141 + // Load the language settings of French
1.142 + myExtendedLocale.LoadLocaleAspect(ELocaleLanguageSettings, DllName1);
1.143 +
1.144 +
1.145 + // Load system charset of French
1.146 + myExtendedLocale.LoadLocaleAspect(ELocaleCollateSetting, DllName1);
1.147 +
1.148 + // Load TLocale settings, currency symbols of Spanish
1.149 + myExtendedLocale.LoadLocaleAspect(ELocaleLocaleSettings, DllName2);
1.150 +
1.151 + // Load time and date display formats of Spanish
1.152 + myExtendedLocale.LoadLocaleAspect(ELocaleTimeDateSettings, DllName2);
1.153 +
1.154 + // Save to system settings
1.155 + myExtendedLocale.SaveSystemSettings();
1.156 +
1.157 + // Wait
1.158 + User::After(1000000);
1.159 +
1.160 + TUid LocaleRepositoryUid ;
1.161 + LocaleRepositoryUid.iUid = KLocalePersistRepositoryUid ;
1.162 +
1.163 + CRepository* repository = CRepository::NewLC(LocaleRepositoryUid);
1.164 +
1.165 + // To get names of DLLs to be loaded
1.166 + TBuf<100> aDllName ;
1.167 +
1.168 + // Test the language settings
1.169 + TInt err = repository->Get(KLocaleLanguageDll, aDllName);
1.170 + if (err != KErrNone)
1.171 + {
1.172 + // Oops! I hit it again
1.173 + CleanupStack::PopAndDestroy(repository) ;
1.174 + return ;
1.175 + }
1.176 +
1.177 +
1.178 + TheTest.Printf(_L("\nTested for language French(02): %S "), &aDllName);
1.179 +
1.180 + // in this case we are only interested in the name "eloc.XX"
1.181 +
1.182 + TEST(DllName1.CompareF(aDllName.Right(8)) == 0);
1.183 +
1.184 +
1.185 + // Test system charset changes
1.186 + err = repository->Get(KLocaleCollationDll, aDllName);
1.187 + if (err != KErrNone)
1.188 + {
1.189 + // Oops! I hit it again
1.190 + CleanupStack::PopAndDestroy(repository) ;
1.191 + return ;
1.192 + }
1.193 + TheTest.Printf(_L("\nTested for Char set of French(02): %S"), &aDllName);
1.194 + TEST(DllName1.CompareF(aDllName.Right(8))==0);
1.195 +
1.196 + // Test TLocale settings, currency symbols
1.197 + err = repository->Get(KLocaleLocaleDll, aDllName) ;
1.198 + if (err != KErrNone)
1.199 + {
1.200 + // Oops! I hit it again
1.201 + CleanupStack::PopAndDestroy(repository) ;
1.202 + return ;
1.203 + }
1.204 + TheTest.Printf(_L("\nTested for Locale of Spanish(04): %S"), &aDllName);
1.205 + TEST(DllName2.CompareF(aDllName.Right(8))==0);
1.206 +
1.207 + // Test time and date display formats
1.208 + err = repository->Get(KLocaleTimeDateDll, aDllName) ;
1.209 + if (err != KErrNone)
1.210 + {
1.211 + // Oops! I hit it again
1.212 + CleanupStack::PopAndDestroy(repository) ;
1.213 + return ;
1.214 + }
1.215 + TheTest.Printf(_L("\nTested for Time and date format of Spanish(04): %S\n"), &aDllName);
1.216 + TEST(DllName2.CompareF(aDllName.Right(8))==0);
1.217 +
1.218 + // Free the central repository object
1.219 + CleanupStack::PopAndDestroy (repository);
1.220 + TheTest.End() ;
1.221 +
1.222 + //becasue we check whether locale content can be persisted is the system in this code block , we mark this test case here.
1.223 + TheTest.Start(_L(" @SYMTestCaseID:TI18N-INITLOCALE-CT-4007 persist system locale content"));
1.224 + TheTest.End();
1.225 + }
1.226 +
1.227 +/**
1.228 +@SYMTestCaseID SYSLIB-BAFL-CIT-0141
1.229 +@SYMTestCaseDesc Check that locale settings can be selected from single DLL
1.230 +@SYMTestPriority High
1.231 +@SYMTestActions Ensure that all settings are loaded from a DLL, system set and persisted
1.232 +@SYMTestExpectedResults The test must not fail.
1.233 +@SYMREQ PREQ1001
1.234 +*/
1.235 +LOCAL_D void ChangeLocaleSingleDll()
1.236 + {
1.237 + TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-BAFL-CIT-0141 Test to demonstrate change of Locale from single DLL "));
1.238 +
1.239 + TExtendedLocale myExtendedLocale;
1.240 + myExtendedLocale.LoadSystemSettings() ;
1.241 +
1.242 + TBuf<100> DllName;
1.243 + DllName.Copy(KSpanishLocale);
1.244 +
1.245 + TheTest.Printf(_L("Changing Locale to Spanish"));
1.246 +
1.247 + // Change the locale to French Locale, all settings from single Dll
1.248 + myExtendedLocale.LoadLocale(DllName);
1.249 +
1.250 + // Save the changes to system settings
1.251 + myExtendedLocale.SaveSystemSettings();
1.252 +
1.253 + // Wait
1.254 + User::After(1000000);
1.255 +
1.256 + TUid LocaleRepositoryUid ;
1.257 + LocaleRepositoryUid.iUid = KLocalePersistRepositoryUid;
1.258 + CRepository* repository = CRepository::NewLC(LocaleRepositoryUid) ;
1.259 +
1.260 + // To get names of DLLs to be loaded
1.261 + TBuf<100> aDllName ;
1.262 +
1.263 + // Test for the language settings
1.264 + TInt err = repository->Get(KLocaleLanguageDll, aDllName);
1.265 + if (err != KErrNone)
1.266 + {
1.267 + // Failed to read DLL name, bail out!
1.268 + CleanupStack::PopAndDestroy(repository) ;
1.269 + return ;
1.270 + }
1.271 + TheTest.Printf(_L("\nTested for Locale settings loaded by single Dll: %S"), &aDllName);
1.272 + TEST(DllName.CompareF(aDllName.Right(8))==0);
1.273 +
1.274 + CleanupStack::PopAndDestroy (repository);
1.275 + TheTest.End();
1.276 + }
1.277 +
1.278 +// Call the tests that test flexibility of Locale
1.279 +void TestLocaleFlexibility()
1.280 + {
1.281 + RProcess process;
1.282 +
1.283 + GetInitialLocaleSettings() ;
1.284 +
1.285 + // Kick-in InitialiseLocale.exe, This will be done as part of system start in actual
1.286 + // release code!
1.287 + TInt r = process.Create(KInitPersistLocaleExeName, KNullDesC);
1.288 + if(r == KErrNone)
1.289 + {
1.290 + process.Resume(); // Start the process going
1.291 + User::After(1000000);
1.292 +
1.293 + ChangeLocaleMultiDll();
1.294 + ChangeLocaleSingleDll();
1.295 +
1.296 + User::After(1000000);
1.297 + process.Close();
1.298 + User::After(1000000);
1.299 + }
1.300 +
1.301 + RestoreInitialLocaleSettings() ;
1.302 +
1.303 + User::After(1000000);
1.304 + // Set up for next test
1.305 + SetUpTestCorruptLocale();
1.306 + }
1.307 +
1.308 +
1.309 +TInt E32Main()
1.310 + {
1.311 + CTrapCleanup* cleanup = CTrapCleanup::New();
1.312 + TEST(cleanup != NULL);
1.313 +
1.314 + __UHEAP_MARK;
1.315 + TheTest.Start(_L("Test to demonstrate Locale flexibility in old locale model"));
1.316 + TheTest.Title();
1.317 +
1.318 + TRAPD(err, ::TestLocaleFlexibility());
1.319 +
1.320 + TEST2(err, KErrNone);
1.321 +
1.322 + TheTest.End();
1.323 + TheTest.Close();
1.324 +
1.325 + __UHEAP_MARKEND;
1.326 + delete cleanup;
1.327 +
1.328 + return(KErrNone);
1.329 + }