os/graphics/windowing/windowserver/test/t_integ/src/t_pseudoapputils.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2007-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 /**
    17  @file
    18  @test
    19  @internalComponent
    20 */
    21 
    22 #include <e32debug.h> //RDebug
    23 
    24 #include "t_pseudoapputils.h"
    25 
    26 EXPORT_C void TImportScreenConfig::VerifyFramesPerTraverse(TInt& aFramesPerTraverse, TInt aScreenPixelDimension)
    27 	{
    28 	if(aFramesPerTraverse <= 0 || aFramesPerTraverse > aScreenPixelDimension)
    29 		{
    30 		RDebug::Print(_L("Illegal FramesPerTraverse value of %d Value must be between 1 and %d inclusive\n"), aFramesPerTraverse, aScreenPixelDimension);
    31 		User::Exit(0);
    32 		}
    33 	else
    34 		{
    35 		if(aScreenPixelDimension % aFramesPerTraverse)
    36 			{
    37 			RDebug::Print(_L("Dimension Divisor of %d must be a sub-multiple of the screen pixel dimension %d\n"), aFramesPerTraverse, aScreenPixelDimension);
    38 			User::Exit(0);
    39 			}
    40 		}
    41 	}
    42 
    43 EXPORT_C void TImportScreenConfig::ReadIni(const TPtrC& aIniParam, TPtrC& aMemberVar, CIniData* aUtils)
    44 	{
    45 	TPtrC readInValue;
    46 
    47 	if(!aUtils->FindVar(KSimVideoConfigSectionName, aIniParam, readInValue))
    48 		{
    49 		RDebug::Print(_L("Could not read %s value from config file, aborting\n"), aIniParam.Ptr());
    50 		User::Exit(0);
    51 		}
    52 	else
    53 		{
    54 		aMemberVar.Set(readInValue);
    55 		}
    56 	}
    57 
    58 EXPORT_C void TImportScreenConfig::ReadIni(const TDesC& tempStore, const TPtrC& aIniParam, TPtrC& aMemberVar, CIniData* aUtils)
    59 	{
    60 	TBuf<KMaxUiBitmapNameLength> temp = tempStore;
    61 	temp.Append(aIniParam);
    62 	ReadIni(temp, aMemberVar, aUtils);
    63 	}
    64 
    65 EXPORT_C void TImportScreenConfig::ReadIni(const TPtrC& aIniParam, TInt& aMemberVar, CIniData* aUtils)
    66 	{
    67 	TInt readInValue;
    68 
    69 	if(!aUtils->FindVar(KSimVideoConfigSectionName, aIniParam, readInValue))
    70 		{
    71 		RDebug::Print(_L("Could not read %s value from config file, aborting\n"), aIniParam.Ptr());
    72 		User::Exit(0);
    73 		}
    74 	else
    75 		{
    76 		aMemberVar = readInValue;
    77 		}
    78 	}
    79 
    80 EXPORT_C void TImportScreenConfig::ReadIni(const TDesC& tempStore, const TPtrC& aIniParam, TInt& aMemberVar, CIniData* aUtils)
    81 	{
    82 	TBuf<KMaxUiBitmapNameLength> temp = tempStore;
    83 	temp.Append(aIniParam);
    84 	ReadIni(temp, aMemberVar, aUtils);
    85 	}
    86 
    87 EXPORT_C void TImportScreenConfig::ReadIni(const TPtrC& aIniParam, const TPtrC& aIniValue1, const TPtrC& aIniValue2, TInt& aMemberVar,
    88                                            TInt aValue1, TInt aValue2, CIniData* aUtils)
    89 	{
    90 	TPtrC readInValue;
    91 
    92 	if(!aUtils->FindVar(KSimVideoConfigSectionName, aIniParam, readInValue))
    93 		{
    94 		RDebug::Print(_L("Could not read %s value from config file, aborting\n"), aIniParam.Ptr());
    95 		User::Exit(0);
    96 		}
    97 	else
    98 		{
    99 		if(readInValue == aIniValue1)
   100 			{
   101 			aMemberVar = aValue1;
   102 			}
   103 		else
   104 			{
   105 			if(readInValue == aIniValue2)
   106 				{
   107 				aMemberVar = aValue2;
   108 				}
   109 			else
   110 				{
   111 				RDebug::Print(_L("Invalid %s value from config file\n"), aIniParam.Ptr());
   112 				}
   113 			}
   114 		}
   115 	}
   116 
   117 EXPORT_C void TImportScreenConfig::ReadIni(const TDesC& tempStore, const TPtrC& aIniParam,  const TPtrC& aIniValue1,
   118                                            const TPtrC& aIniValue2, TInt& aMemberVar, TInt aValue1,
   119                                            TInt aValue2, CIniData* aUtils)
   120 	{
   121 	TBuf<KMaxUiBitmapNameLength> temp = tempStore;
   122 	temp.Append(aIniParam);
   123 	ReadIni(temp, aIniValue1, aIniValue2, aMemberVar, aValue1, aValue2, aUtils);
   124 	}
   125 
   126 
   127 EXPORT_C void TImportScreenConfig::ReadIni(const TPtrC& aIniParam,  const TPtrC& aIniValue1, const TPtrC& aIniValue2, const TPtrC& aIniValue3,
   128                                            TInt& aMemberVar, TInt aValue1, TInt aValue2, TInt aValue3, CIniData* aUtils)
   129 	{
   130 	TPtrC readInValue;
   131 
   132 	if(!aUtils->FindVar(KSimVideoConfigSectionName, aIniParam, readInValue))
   133 		{
   134 		RDebug::Print(_L("Could not read %s value from config file, aborting\n"), aIniParam.Ptr());
   135 		User::Exit(0);
   136 		}
   137 	else
   138 		{
   139 		if(readInValue == aIniValue1)
   140 			{
   141 			aMemberVar = aValue1;
   142 			}
   143 		else
   144 			{
   145 			if(readInValue == aIniValue2)
   146 				{
   147 				aMemberVar = aValue2;
   148 				}
   149 			else
   150 				{
   151 				if(readInValue == aIniValue3)
   152 					{
   153 					aMemberVar = aValue3;
   154 					}
   155 				else
   156 					{
   157 					RDebug::Print(_L("Invalid %s value from config file\n"), aIniParam.Ptr());
   158 					}
   159 				}
   160 			}
   161 		}
   162 	}
   163 
   164 EXPORT_C void TImportScreenConfig::ReadIni(const TDesC& tempStore, const TPtrC& aIniParam, const TPtrC& aIniValue1, const TPtrC& aIniValue2,
   165                                            const TPtrC& aIniValue3, TInt& aMemberVar, TInt aValue1, TInt aValue2,
   166                                            TInt aValue3, CIniData* aUtils)
   167 	{
   168 	TBuf<KMaxUiBitmapNameLength> temp = tempStore;
   169 	temp.Append(aIniParam);
   170 	ReadIni(temp, aIniValue1, aIniValue2, aIniValue3, aMemberVar, aValue1, aValue2, aValue3, aUtils);
   171 	}
   172 
   173 EXPORT_C void TImportScreenConfig::ReadIni(const TPtrC& aIniParam, const TPtrC& aIniValue1, const TPtrC& aIniValue2, const TPtrC& aIniValue3,
   174                                            const TPtrC& aIniValue4, TInt& aMemberVar, TInt aValue1, TInt aValue2,
   175                                            TInt aValue3, TInt aValue4, CIniData* aUtils)
   176 	{
   177 	TPtrC readInValue;
   178 
   179 	if(!aUtils->FindVar(KSimVideoConfigSectionName, aIniParam, readInValue))
   180 		{
   181 		RDebug::Print(_L("Could not read %s value from config file, aborting\n"), aIniParam.Ptr());
   182 		User::Exit(0);
   183 		}
   184 	else
   185 		{
   186 		if(readInValue == aIniValue1)
   187 			{
   188 			aMemberVar = aValue1;
   189 			}
   190 		else
   191 			{
   192 			if(readInValue == aIniValue2)
   193 				{
   194 				aMemberVar = aValue2;
   195 				}
   196 			else
   197 				{
   198 				if(readInValue == aIniValue3)
   199 					{
   200 					aMemberVar = aValue3;
   201 					}
   202 				else
   203 					{
   204 					if(readInValue == aIniValue4)
   205 						{
   206 						aMemberVar = aValue4;
   207 						}
   208 					else
   209 						{
   210 						RDebug::Print(_L("Invalid %s value from config file\n"), aIniParam.Ptr());
   211 						}
   212 					}
   213 				}
   214 			}
   215 		}
   216 	}
   217 
   218 EXPORT_C void TImportScreenConfig::ReadIni(const TDesC& tempStore, const TPtrC& aIniParam,  const TPtrC& aIniValue1, const TPtrC& aIniValue2,
   219                                            const TPtrC& aIniValue3, const TPtrC& aIniValue4, TInt& aMemberVar,
   220                                            TInt aValue1, TInt aValue2, TInt aValue3,
   221                                            TInt aValue4, CIniData* aUtils)
   222 	{
   223 	TBuf<KMaxUiBitmapNameLength> temp = tempStore;
   224 	temp.Append(aIniParam);
   225 	ReadIni(temp, aIniValue1, aIniValue2, aIniValue3, aIniValue4, aMemberVar, aValue1, aValue2, aValue3, aValue4, aUtils);
   226 	}
   227 
   228 EXPORT_C void TImportScreenConfig::ReadIni(const TPtrC& aIniParam, const TPtrC& aIniValue1, const TPtrC& aIniValue2, const TPtrC& aIniValue3,
   229                                            const TPtrC& aIniValue4, const TPtrC& aIniValue5, TInt& aMemberVar, TInt aValue1,
   230                                            TInt aValue2, TInt aValue3, TInt aValue4, TInt aValue5, CIniData* aUtils)
   231 	{
   232 	TPtrC readInValue;
   233 
   234 	if(!aUtils->FindVar(KSimVideoConfigSectionName, aIniParam, readInValue))
   235 		{
   236 		RDebug::Print(_L("Could not read %s value from config file, aborting\n"), aIniParam.Ptr());
   237 		User::Exit(0);
   238 		}
   239 	else
   240 		{
   241 		if(readInValue == aIniValue1)
   242 			{
   243 			aMemberVar = aValue1;
   244 			}
   245 		else
   246 			{
   247 			if(readInValue == aIniValue2)
   248 				{
   249 				aMemberVar = aValue2;
   250 				}
   251 			else
   252 				{
   253 				if(readInValue == aIniValue3)
   254 					{
   255 					aMemberVar = aValue3;
   256 					}
   257 				else
   258 					{
   259 					if(readInValue == aIniValue4)
   260 						{
   261 						aMemberVar = aValue4;
   262 						}
   263 					else
   264 						{
   265 						if(readInValue == aIniValue5)
   266 							{
   267 							aMemberVar = aValue5;
   268 							}
   269 						else
   270 							{
   271 							RDebug::Print(_L("Invalid %s value from config file\n"), aIniParam.Ptr());
   272 							}
   273 						}
   274 					}
   275 				}
   276 			}
   277 		}
   278 	}
   279 
   280 EXPORT_C void TImportScreenConfig::ReadIni(const TDesC& tempStore, const TPtrC& aIniParam,  const TPtrC& aIniValue1, const TPtrC& aIniValue2,
   281                                            const TPtrC& aIniValue3, const TPtrC& aIniValue4, const TPtrC& aIniValue5, TInt& aMemberVar,
   282                                            TInt aValue1, TInt aValue2, TInt aValue3, TInt aValue4,
   283                                            TInt aValue5, CIniData* aUtils)
   284 	{
   285 	TBuf<KMaxUiBitmapNameLength> temp = tempStore;
   286 	temp.Append(aIniParam);
   287 	ReadIni(temp, aIniValue1, aIniValue2, aIniValue3, aIniValue4, aIniValue5, aMemberVar, aValue1, aValue2, aValue3, aValue4, aValue5, aUtils);
   288 	}
   289 
   290 EXPORT_C TInt TImportScreenConfig::Numeral(TInt val, TInt& aDigit)
   291 	{
   292 	if( (val > 47) && (val < 58) )
   293 		{
   294 		aDigit = val - 48; //ascii to int conversion trick
   295 		return KErrNone;
   296 		}
   297 	else if(val == 45)
   298 		{
   299 		aDigit = -1;       //ascii code 45 is a minus sign
   300 		return KErrNone;
   301 		}
   302 
   303 	return KErrNotFound;
   304 	}
   305 
   306 EXPORT_C TInt TImportScreenConfig::ExtractNumber(const TPtrC& aRectTextString, TInt& aSearchFrom, TInt& aNumber)
   307 	{
   308 	TInt initFlag = 0;
   309 	TInt digit;
   310 	aNumber = 0;
   311 	TInt sign = 1;
   312 
   313 	for(TInt i=aSearchFrom; i<aRectTextString.Length(); i++)
   314 		{
   315 		if(Numeral(aRectTextString[i], digit) != KErrNotFound)
   316 			{
   317 			if(initFlag == 0)
   318 				{
   319 				initFlag = 1;
   320 				if(digit == -1)
   321 					{
   322 					sign = digit;
   323 					}
   324 				else
   325 					{
   326 					aNumber = digit;
   327 					}
   328 				}
   329 			else
   330 				{
   331 				if(digit == -1)
   332 					{
   333 					RDebug::Print(_L("Error - cannot read value from string, spurious minus sign\n"));
   334 					return KErrNotFound;
   335 					}
   336 				else
   337 					{
   338 					aNumber = aNumber*10 + digit*sign;
   339 					}
   340 				}
   341 			}
   342 		else
   343 			{
   344 			if(initFlag == 1)
   345 				{
   346 				aSearchFrom = i + 1;
   347 				return KErrNone;
   348 				}
   349 			}
   350 		}
   351 
   352 	if(initFlag == 1)
   353 		{
   354 		return KErrNone;
   355 		}
   356 	return KErrNotFound;
   357 	}
   358 
   359 EXPORT_C TInt TImportScreenConfig::ExtractRect(const TPtrC& aRectTextString, TRect& aRect, const TSize& aScreenSize)
   360 	{
   361 	TInt searchFrom = 0;
   362 	TInt number = 0;
   363 	TInt pointvalue[4] = {0};
   364 
   365 	for(TInt i=0; i<4; i++)
   366 		{
   367 		if(ExtractNumber(aRectTextString, searchFrom, number) == KErrNotFound)
   368 			{
   369 			RDebug::Print(_L("Error - cannot read rectangle dimensions from string, setting to zero size\n"));
   370 			aRect = TRect(0,0,0,0);
   371 			return KErrNotFound;
   372 			}
   373 		else
   374 			{
   375 			pointvalue[i] = number;
   376 			}
   377 		}
   378 
   379 	aRect = TRect(TPoint((pointvalue[0]*aScreenSize.iWidth)/100, (pointvalue[2]*aScreenSize.iHeight)/100)
   380 	             ,TPoint((pointvalue[1]*aScreenSize.iWidth)/100, (pointvalue[3]*aScreenSize.iHeight)/100));
   381 
   382 	return KErrNone;
   383 	}
   384 
   385 EXPORT_C TInt TImportScreenConfig::ExtractAspectRatio(const TPtrC& aRatioString, TSize& aAspectRatio)
   386 	{
   387 	TInt searchFrom = 0;
   388 	TInt number = 0;
   389 	TInt pointvalue[2] = {0};
   390 
   391 	for(TInt i=0; i<2; i++)
   392 		{
   393 		if(ExtractNumber(aRatioString, searchFrom, number) == KErrNotFound)
   394 			{
   395 			RDebug::Print(_L("Error - cannot read aspect ratio dimensions from string\n"));
   396 			return KErrNotFound;
   397 			}
   398 		else
   399 			{
   400 			pointvalue[i] = number;
   401 			}
   402 		}
   403 
   404 	aAspectRatio = TSize(pointvalue[0], pointvalue[1]);
   405 	return KErrNone;
   406 	}
   407 
   408 EXPORT_C TInt TImportScreenConfig::ExtractPoint(const TPtrC& aPointString, TPoint& aPoint)
   409 	{
   410 	TInt searchFrom = 0;
   411 	TInt number = 0;
   412 	TInt pointvalue[2] = {0};
   413 
   414 	for(TInt i=0; i<2; i++)
   415 		{
   416 		if(ExtractNumber(aPointString, searchFrom, number) == KErrNotFound)
   417 			{
   418 			RDebug::Print(_L("Error - cannot read point dimensions from string\n"));
   419 			return KErrNotFound;
   420 			}
   421 		else
   422 			{
   423 			pointvalue[i] = number;
   424 			}
   425 		}
   426 
   427 	aPoint = TPoint(pointvalue[0], pointvalue[1]);
   428 	return KErrNone;
   429 	}
   430 
   431 EXPORT_C TInt TImportScreenConfig::ExtractSize(const TPtrC& aSizeString, TSize& aSize)
   432 	{
   433 	TInt searchFrom = 0;
   434 	TInt number = 0;
   435 	TInt pointvalue[2] = {0};
   436 
   437 	for(TInt i=0; i<2; i++)
   438 		{
   439 		if(ExtractNumber(aSizeString, searchFrom, number) == KErrNotFound)
   440 			{
   441 			RDebug::Print(_L("Error - cannot read size dimensions from string\n"));
   442 			return KErrNotFound;
   443 			}
   444 		else
   445 			{
   446 			pointvalue[i] = number;
   447 			}
   448 		}
   449 
   450 	aSize = TSize(pointvalue[0], pointvalue[1]);
   451 	return KErrNone;
   452 	}
   453 
   454 TInt TImportScreenConfig::ReadIniAllowMissing(const TPtrC& aIniParam, TPtrC& aMemberVar, CIniData* aUtils)
   455 	{
   456 	TPtrC readInValue;
   457 
   458 	if(!aUtils->FindVar(KSimVideoConfigSectionName, aIniParam, readInValue))
   459 		{
   460 		RDebug::Print(_L("%s value not found in config file\n"), aIniParam.Ptr());
   461 		return KErrNotFound;
   462 		}
   463 	else
   464 		{
   465 		aMemberVar.Set(readInValue);
   466 		return KErrNone;
   467 		}
   468 	}
   469 
   470 TBool TImportScreenConfig::GetShareSurfaceInfoL(TInt aScreenNo, TInt aWindowNo, TInt& aShareScreenNumber, TInt& aShareWindowNumber, CIniData* aUtils)
   471 	{
   472 	TBuf<KMaxUiBitmapNameLength> tempStore;
   473 	tempStore.Format(KScreenSurface, aScreenNo, aWindowNo);
   474 	tempStore.Append(_L("share_surface"));
   475 	TPtrC shareSurfaceString;
   476 	TInt res = ReadIniAllowMissing(tempStore, shareSurfaceString, aUtils);
   477 
   478 	if(res == KErrNotFound)
   479 		{
   480 		RDebug::Print(_L("%s value not found in config file\n"), tempStore.Ptr());
   481 		return EFalse;
   482 		}
   483 	else if(res != KErrNone)
   484 		{
   485 		RDebug::Print(_L("Could not read %s value correctly from config file, aborting\n"), tempStore.Ptr());
   486 		User::Exit(0);
   487 		}
   488 	
   489 	// Format of aShareSurfaceString should be "screenX_windowY"
   490 	TInt searchFrom = 5;
   491 	TInt ret = ExtractNumber(shareSurfaceString, searchFrom, aShareScreenNumber);
   492 	if(KErrNone != ret)
   493 		{
   494 		RDebug::Print(_L("Error - cannot read screen number from shared_surface string\n"));
   495 		User::Exit(0);
   496 		}
   497 
   498 	ret = ExtractNumber(shareSurfaceString, searchFrom, aShareWindowNumber);
   499 	if(KErrNone != ret)
   500 		{
   501 		RDebug::Print(_L("Error - cannot read window number from shared_surface string\n"));
   502 		User::Exit(0);
   503 		}
   504 
   505 	// Read screen number and window number correctly - surface is shared
   506 	return ETrue;
   507 	}