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