os/ossrv/lowlevellibsandfws/pluginfw/Framework/MultipleImageTest/t_multipleImageTest.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2006-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 //
    15 
    16 #include "..\EcomTestUtils\EcomTestUtils.h"
    17 #include <e32test.h>
    18 #include <Ecom\ECom.h>
    19 #include <Ecom\ImplementationInformation.h>
    20 #include <hal.h>
    21 #include <bautils.h>
    22 
    23 TUid KUidMultipeImageInterface = { 0x10282307 };
    24 static RFs TheFs;
    25 static RTest TheTest(_L("t_multipleImageTest.exe"));
    26 
    27 #ifndef SYMBIAN_DISTINCT_LOCALE_MODEL
    28     _LIT(KEnglishLocale, "elocl.01");
    29     _LIT(KFrenchLocale, "elocl.02");
    30     _LIT(KGermanLocale, "elocl.03");
    31 #else
    32     // refer base/os/kernelhwsrv/kernel/eka/euser/locmapping.cpp
    33     // Language
    34     _LIT(KEComEnglishLang,"elocl_lan.001");
    35     _LIT(KEComFrenchLang,"elocl_lan.002");
    36     _LIT(KEComGermanLang,"elocl_lan.003");
    37     // Region
    38     _LIT(KEComEnglishReg,"elocl_reg.826");
    39     _LIT(KEComFrenchReg,"elocl_reg.250");
    40     _LIT(KEComGermanReg,"elocl_reg.276");
    41     // Collation
    42     _LIT(KEComEnglishColl,"elocl_col.001");
    43     _LIT(KEComFrenchColl,"elocl_col.002");
    44     _LIT(KEComGermanColl,"elocl_col.003");
    45 #endif
    46 
    47 // Test Macroes and Functions
    48 static void Check(TInt aValue, TInt aLine)
    49 	{
    50 	if(!aValue)
    51 		{
    52 		TheTest(EFalse, aLine);
    53 		}
    54 	}
    55 
    56 static  void Check(TInt aValue, TInt aExpected, TInt aLine)
    57 	{
    58 	if(aValue != aExpected)
    59 		{
    60 		RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
    61 		TheTest(EFalse, aLine);
    62 		}
    63 	}
    64 #define TEST(arg) ::Check((arg), __LINE__)
    65 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
    66 
    67 // Type definition for test functions.
    68 // Used in calling t_multipleImageTest functions.
    69 typedef void (*FuncPtrL) (TLanguage* , TPtrC* );
    70 
    71 void KillEComServerL()
    72 	{
    73 	//Need to ensure that the EComServer process is killed before even starting this test by using
    74    	//the EComTestUtils library
    75    	_LIT(KEComServerProcessName,"ecomserver");
    76    	TRAPD(error, EComTestUtils::KillProcessL(KEComServerProcessName));
    77    	TEST2(error, KErrNone);
    78 	}
    79 
    80 void SetLanguageDowngradeL(TLanguage* aLanguages)
    81 	{
    82 	TLocale locale;
    83 
    84 	TInt i=0;
    85 	RArray<TLanguage> languageArray;
    86 
    87 	TLanguage lang = User::Language();
    88 
    89 	if(lang != aLanguages[0])
    90 		{
    91 	    TExtendedLocale extendedLocale;
    92 	    extendedLocale.LoadSystemSettings();
    93 		
    94 	    if(aLanguages[0] == ELangEnglish)
    95 			{
    96             #ifndef SYMBIAN_DISTINCT_LOCALE_MODEL
    97                 extendedLocale.LoadLocale(KEnglishLocale);
    98 			#else
    99                 extendedLocale.LoadLocale(KEComEnglishLang,KEComEnglishReg,KEComEnglishColl);
   100 			#endif
   101 			}
   102 		else if(aLanguages[0] == ELangFrench)
   103 			{
   104             #ifndef SYMBIAN_DISTINCT_LOCALE_MODEL			
   105                 extendedLocale.LoadLocale(KFrenchLocale);
   106             #else
   107                 extendedLocale.LoadLocale(KEComFrenchLang,KEComFrenchReg,KEComFrenchColl);
   108 			#endif			
   109 			}
   110 		else if(aLanguages[0] == ELangGerman)
   111 			{
   112             #ifndef SYMBIAN_DISTINCT_LOCALE_MODEL			
   113                 extendedLocale.LoadLocale(KGermanLocale);
   114 			#else
   115                 extendedLocale.LoadLocale(KEComGermanLang,KEComGermanReg,KEComGermanColl);
   116 			#endif          
   117 			}
   118 		else 
   119 			{
   120 			__ASSERT_ALWAYS(EFalse, User::Leave(KErrNotSupported)); //Unexpected test language
   121 			}
   122 
   123 	    // Save the changes to system settings
   124 		extendedLocale.SaveSystemSettings();
   125 
   126 		TEST(User::Language() == aLanguages[0]);
   127 		}
   128 
   129 	for(i=1; aLanguages[i] != ELangNone && i < KMaxDowngradeLanguages; i++)
   130 		{
   131 		locale.SetLanguageDowngrade(i, aLanguages[i]);
   132 		}
   133 
   134 	locale.Set();
   135 
   136 	BaflUtils::GetDowngradePathL(TheFs,  aLanguages[0], languageArray);
   137 
   138 	for(i = languageArray.Count() - 1; i >= 0; i--)
   139 		{
   140 		TLanguage language = languageArray[i];
   141 		TheTest.Printf(_L("Updated language downgrade[%d]: %d\n"), i, language);
   142 		TEST2(languageArray[i], aLanguages[i]);
   143 		}
   144 
   145 	languageArray.Close();
   146 	}
   147 
   148 /**
   149 @SYMTestCaseID SYSLIB-ECOM-CT-1694
   150 @SYMTestCaseDesc Test that ECOM lists the expected plugins under different language downgrade path settings
   151 @SYMTestPriority High
   152 @SYMTestActions  Set the language downgrade path.Kill ECOM server to ensure ECOM uses the new downgrade path
   153 next time it starts. List implementations. Check that the list contains the expected plugins.
   154 @SYMTestExpectedResults The test must not fail.
   155 @SYMREQ CR0759
   156 */
   157 void ListImplementationsL(TLanguage* aLanguageDowngradePath, TPtrC* aExpectedImplementations)
   158 	{
   159 	//set the language downgrade path
   160 	SetLanguageDowngradeL(aLanguageDowngradePath);
   161 	//kill ecom server to ensure the use of updated language downgrade path
   162 	KillEComServerL();
   163 
   164 	RImplInfoPtrArray implementations;
   165 	TRAPD(err, REComSession::ListImplementationsL(KUidMultipeImageInterface, implementations));
   166 	TEST2(err, KErrNone);
   167 
   168 	const TInt implementationCount = implementations.Count();
   169 	TheTest.Printf(_L("Found %d implementations.\n"), implementationCount);
   170 
   171 	for (TInt i=0; i<implementationCount; i++)
   172 		{
   173 		const CImplementationInformation* info = implementations[i];
   174 		TheTest.Printf(_L("Implementation[%d]: UID=0x%x DisplayName=\"%S\"\n"), i, (info->ImplementationUid()).iUid, &(info->DisplayName())) ;
   175 		TEST(info->DisplayName() == aExpectedImplementations[i]);
   176 		}
   177 
   178 	// Empty the array of implementations to avoid leaks
   179 	implementations.ResetAndDestroy();
   180 	//close the ecom session to avoid leaks
   181 	REComSession::FinalClose();
   182 	}
   183 
   184 
   185 LOCAL_C void DoBasicTestL(FuncPtrL testFuncL, TLanguage* aLanguageDowngradePath, TPtrC* aExpectedImplementations, const TDesC& aTestDesc)
   186 	{
   187 	TheTest.Next(aTestDesc);
   188 
   189 	__UHEAP_MARK;
   190   	// find out the number of open handles
   191 	TInt startProcessHandleCount;
   192 	TInt startThreadHandleCount;
   193 	RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
   194 
   195 	testFuncL(aLanguageDowngradePath, aExpectedImplementations);
   196 
   197 	// check that no handles have leaked
   198 	TInt endProcessHandleCount;
   199 	TInt endThreadHandleCount;
   200 	RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
   201 
   202 	TEST(startProcessHandleCount == endProcessHandleCount);
   203 	TEST(startThreadHandleCount  == endThreadHandleCount);
   204 
   205 	__UHEAP_MARKEND;
   206 	}
   207 
   208 
   209 LOCAL_C void DoTestsL()
   210 	{
   211 	const TLanguage languageDowngradePath[][7] =
   212 		{
   213 			{ELangEnglish, ELangFrench, ELangGerman, ELangNone},
   214 			{ELangFrench, ELangGerman, ELangEnglish, ELangNone},
   215 			{ELangGerman, ELangFrench, ELangEnglish, ELangNone},
   216 			{ELangFrench, ELangGerman, ELangNone, ELangNone},
   217 			{ELangGerman, ELangFrench, ELangNone, ELangNone},
   218 			{ELangFrench, ELangNone, ELangNone, ELangNone},
   219 			{ELangGerman, ELangNone, ELangNone, ELangNone}
   220 		};
   221 
   222 	const TPtrC pluginResolution[][16] =
   223 		{
   224 			{
   225 			_L("Example B Image 2 Language 01 UK English"),
   226 			_L("Example C Image 2 Language 01 UK English"),
   227 			_L("Example E Image 2 Language 02 French"),
   228 			_L("Example F Image 2 Language 02 French"),
   229 			_L("Example G Image 1 Language 02 French"),
   230 			_L("Example H Image 1 Language 03 German"),
   231 			_L("Example I Image 1 Language 02 French"),
   232 			_L("Example J Image 1 Language 03 German"),
   233 			_L("Example K Image 2 Language 02 French"),
   234 			_L("Example L Image 2 Language 03 German"),
   235 			_L("Example M Image 2 Language 02 French"),
   236 			_L("Example N Image 2 Language 03 German"),
   237 			_L("Example O Image 2 Language 02 French"),
   238 			_L("Example P Image 2 Language 03 German"),
   239 			_L("Example Q Image 2 Language 02 French"),
   240 			_L("Example S Image 1 Language 02 French")
   241 			},
   242 			{
   243 			_L("Example B Image 2 Language 01 UK English"),
   244 			_L("Example C Image 2 Language 01 UK English"),
   245 			_L("Example E Image 2 Language 02 French"),
   246 			_L("Example F Image 2 Language 02 French"),
   247 			_L("Example G Image 1 Language 02 French"),
   248 			_L("Example H Image 1 Language 03 German"),
   249 			_L("Example I Image 1 Language 02 French"),
   250 			_L("Example J Image 1 Language 03 German"),
   251 			_L("Example K Image 2 Language 02 French"),
   252 			_L("Example L Image 2 Language 03 German"),
   253 			_L("Example M Image 2 Language 02 French"),
   254 			_L("Example N Image 2 Language 03 German"),
   255 			_L("Example O Image 2 Language 02 French"),
   256 			_L("Example P Image 2 Language 03 German"),
   257 			_L("Example Q Image 2 Language 02 French"),
   258 			_L("Example S Image 1 Language 02 French")
   259 			},
   260 			{
   261 			_L("Example B Image 2 Language 01 UK English"),
   262 			_L("Example C Image 2 Language 01 UK English"),
   263 			_L("Example E Image 2 Language 02 French"),
   264 			_L("Example F Image 2 Language 02 French"),
   265 			_L("Example G Image 1 Language 03 German"),
   266 			_L("Example H Image 1 Language 03 German"),
   267 			_L("Example I Image 1 Language 03 German"),
   268 			_L("Example J Image 1 Language 03 German"),
   269 			_L("Example K Image 2 Language 03 German"),
   270 			_L("Example L Image 2 Language 03 German"),
   271 			_L("Example M Image 2 Language 03 German"),
   272 			_L("Example N Image 2 Language 03 German"),
   273 			_L("Example O Image 2 Language 03 German"),
   274 			_L("Example P Image 2 Language 03 German"),
   275 			_L("Example Q Image 2 Language 03 German"),
   276 			_L("Example S Image 2 Language 03 German")
   277 			},
   278 			{
   279 			_L("Example B Image 2 Language 01 UK English"),
   280 			_L("Example C Image 2 Language 01 UK English"),
   281 			_L("Example E Image 2 Language 02 French"),
   282 			_L("Example F Image 2 Language 02 French"),
   283 			_L("Example G Image 1 Language 02 French"),
   284 			_L("Example H Image 1 Language 03 German"),
   285 			_L("Example I Image 1 Language 02 French"),
   286 			_L("Example J Image 1 Language 03 German"),
   287 			_L("Example K Image 2 Language 02 French"),
   288 			_L("Example L Image 2 Language 03 German"),
   289 			_L("Example M Image 2 Language 02 French"),
   290 			_L("Example N Image 2 Language 03 German"),
   291 			_L("Example O Image 2 Language 02 French"),
   292 			_L("Example P Image 2 Language 03 German"),
   293 			_L("Example Q Image 2 Language 02 French"),
   294 			_L("Example S Image 1 Language 02 French")
   295 			},
   296 			{
   297 			_L("Example B Image 2 Language 01 UK English"),
   298 			_L("Example C Image 2 Language 01 UK English"),
   299 			_L("Example E Image 2 Language 02 French"),
   300 			_L("Example F Image 2 Language 02 French"),
   301 			_L("Example G Image 1 Language 03 German"),
   302 			_L("Example H Image 1 Language 03 German"),
   303 			_L("Example I Image 1 Language 03 German"),
   304 			_L("Example J Image 1 Language 03 German"),
   305 			_L("Example K Image 2 Language 03 German"),
   306 			_L("Example L Image 2 Language 03 German"),
   307 			_L("Example M Image 2 Language 03 German"),
   308 			_L("Example N Image 2 Language 03 German"),
   309 			_L("Example O Image 2 Language 03 German"),
   310 			_L("Example P Image 2 Language 03 German"),
   311 			_L("Example Q Image 2 Language 03 German"),
   312 			_L("Example S Image 2 Language 03 German")
   313 			},
   314 			{
   315 			_L("Example B Image 2 Language 01 UK English"),
   316 			_L("Example C Image 2 Language 01 UK English"),
   317 			_L("Example E Image 2 Language 02 French"),
   318 			_L("Example F Image 2 Language 02 French"),
   319 			_L("Example G Image 1 Language 02 French"),
   320 			_L("Example H Image 1 Language 01 UK English"),
   321 			_L("Example I Image 1 Language 02 French"),
   322 			_L("Example K Image 2 Language 02 French"),
   323 			_L("Example L Image 2 Language 01 UK English"),
   324 			_L("Example M Image 2 Language 02 French"),
   325 			_L("Example O Image 2 Language 02 French"),
   326 			_L("Example P Image 2 Language 01 UK English"),
   327 			_L("Example Q Image 2 Language 02 French"),
   328 			_L("Example S Image 1 Language 02 French"),
   329 			_L("Dummy"),
   330 			_L("Dummy")
   331 			},
   332 			{
   333 			_L("Example B Image 2 Language 01 UK English"),
   334 			_L("Example C Image 2 Language 01 UK English"),
   335 			_L("Example G Image 1 Language 03 German"),
   336 			_L("Example H Image 1 Language 03 German"),
   337 			_L("Example I Image 1 Language 03 German"),
   338 			_L("Example J Image 1 Language 03 German"),
   339 			_L("Example K Image 2 Language 03 German"),
   340 			_L("Example L Image 2 Language 03 German"),
   341 			_L("Example M Image 2 Language 03 German"),
   342 			_L("Example N Image 2 Language 03 German"),
   343 			_L("Example O Image 2 Language 03 German"),
   344 			_L("Example P Image 2 Language 03 German"),
   345 			_L("Example Q Image 2 Language 03 German"),
   346 			_L("Example S Image 2 Language 03 German"),
   347 			_L("Dummy"),
   348 			_L("Dummy")
   349 			}
   350 		};
   351 
   352 	//make a copy of the current locale
   353 	TLocale oldLocale;
   354 
   355 	TRAPD(err,
   356 		{
   357 		DoBasicTestL(&ListImplementationsL,
   358 					(TLanguage*)languageDowngradePath[0],
   359 					(TPtrC*)pluginResolution[0],
   360 					_L("Check Installed Plugins for Downgrade Path English-French-German"));
   361 
   362 		oldLocale.Set();
   363 
   364 		DoBasicTestL(&ListImplementationsL,
   365 					(TLanguage*)languageDowngradePath[1],
   366 					(TPtrC*)pluginResolution[1],
   367 					_L("Check Installed Plugins for Downgrade Path French-German-English"));
   368 
   369 		oldLocale.Set();
   370 
   371 		DoBasicTestL(&ListImplementationsL,
   372 					(TLanguage*)languageDowngradePath[2],
   373 					(TPtrC*)pluginResolution[2],
   374 					_L("Check Installed Plugins for Downgrade Path German-French-English"));
   375 
   376 		oldLocale.Set();
   377 
   378 		DoBasicTestL(&ListImplementationsL,
   379 					(TLanguage*)languageDowngradePath[3],
   380 					(TPtrC*)pluginResolution[3],
   381 					_L("Check Installed Plugins for Downgrade Path French-German"));
   382 
   383 		oldLocale.Set();
   384 
   385 		DoBasicTestL(&ListImplementationsL,
   386 					(TLanguage*)languageDowngradePath[4],
   387 					(TPtrC*)pluginResolution[4],
   388 					_L("Check Installed Plugins for Downgrade Path German-French"));
   389 
   390 		oldLocale.Set();
   391 
   392 		DoBasicTestL(&ListImplementationsL,
   393 					(TLanguage*)languageDowngradePath[5],
   394 					(TPtrC*)pluginResolution[5],
   395 					_L("Check Installed Plugins for Downgrade Path French"));
   396 
   397 		oldLocale.Set();
   398 
   399 		DoBasicTestL(&ListImplementationsL,
   400 					(TLanguage*)languageDowngradePath[6],
   401 					(TPtrC*)pluginResolution[6],
   402 					_L("Check Installed Plugins for Downgrade Path German"));
   403 		}
   404 		);
   405 	TExtendedLocale extendedLocale;
   406 	extendedLocale.LoadSystemSettings();
   407 #ifndef SYMBIAN_DISTINCT_LOCALE_MODEL
   408 	// Change the locale to Default Locale, all settings from single Dll
   409 	extendedLocale.LoadLocale(KEnglishLocale);
   410 #else
   411     extendedLocale.LoadLocale(KEComEnglishLang,KEComEnglishReg,KEComEnglishColl);
   412 #endif
   413 	
   414 	// Save the changes to system settings
   415 	extendedLocale.SaveSystemSettings();
   416 
   417 	//reset locale
   418 	oldLocale.Set();
   419 
   420 	if(err != KErrNone)
   421 		{
   422 		User::Leave(err);
   423 		}
   424 	}
   425 
   426 
   427 GLDEF_C TInt E32Main()
   428 	{
   429 	__UHEAP_MARK;
   430 	TheTest.Printf(_L("\n"));
   431 	TheTest.Title();
   432 	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-1694 MultipleImageTests "));
   433 
   434 	TEST2(TheFs.Connect(), KErrNone);
   435 
   436 	// get clean-up stack
   437 	CTrapCleanup* cleanup = CTrapCleanup::New();
   438 	// Construct and install the Active Scheduler. The Active Scheduler is needed
   439 	// by components used by this test as they are ActiveObjects.
   440 	CActiveScheduler* activeScheduler = new(ELeave)CActiveScheduler;
   441 	CActiveScheduler::Install(activeScheduler);
   442 
   443 	TRAPD(err,DoTestsL());
   444 	TEST2(err, KErrNone);
   445 
   446 	//delete scheduler;
   447 	delete activeScheduler;
   448 	delete cleanup;
   449 
   450 	TheFs.Close();
   451 
   452 	TheTest.End();
   453 	TheTest.Close();
   454 
   455 	__UHEAP_MARKEND;
   456 
   457 	User::Heap().Check();
   458 
   459 	return KErrNone;
   460 	}
   461 
   462