kerneltest/e32test/video/t_video.cpp
changeset 43 96e5fb8b040d
child 109 b3a1d9898418
equal deleted inserted replaced
-1:000000000000 43:96e5fb8b040d
       
     1 // Copyright (c) 2001-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 the License "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 // Overview:
       
    15 // Test the video driver kernel extension
       
    16 // API Information:
       
    17 // HAL, UserSvr
       
    18 // Details:
       
    19 // - Get and report the value for brightness & max brightness. Adjust 
       
    20 // the brightness. Verify results are as expected.
       
    21 // - Get and report the value for contrast & max contrast. Adjust the 
       
    22 // contrast. Verify results are as expected.
       
    23 // - Get and set backlight status, verify results.
       
    24 // - Get the number of display modes and the current display mode.
       
    25 // - Get screen information for current display mode.
       
    26 // - Get Bits per pixel for current display mode, for an illegal mode 
       
    27 // and for all modes.
       
    28 // - Switch display modes and verify results are as expected.
       
    29 // - Get and set palette entries, verify the results.
       
    30 // - Turn the display on and off.
       
    31 // - If additional screens are supported, test each screen as above.
       
    32 // - Test more devices than the kernel supports, verify the results.
       
    33 // Platforms/Drives/Compatibility:
       
    34 // All.
       
    35 // Assumptions/Requirement/Pre-requisites:
       
    36 // Failures and causes:
       
    37 // Base Port information:
       
    38 // 
       
    39 //
       
    40 
       
    41 #include <e32test.h>
       
    42 #include <videodriver.h>
       
    43 #include <hal.h>
       
    44 #include <e32svr.h>
       
    45 
       
    46 LOCAL_D RTest test(_L("T_VIDEO"));
       
    47 
       
    48 LOCAL_C void RunTests(void);
       
    49 
       
    50 #ifndef __WINS__
       
    51 #define DUMP(x) test.Printf(_L(#x"= %d =0x%08x\n"), x, x)
       
    52 #endif
       
    53 
       
    54 LOCAL_C void RunTests(void)
       
    55 	{
       
    56 	TInt ret = KErrNone;
       
    57 	TInt HALArg;
       
    58 	TInt saved = 0;
       
    59 
       
    60 /*	BRIGHTNESS	*/
       
    61 	
       
    62 	TBool HALMaxBrightnessSupported = EFalse;
       
    63 	TBool HALGetBrightnessSupported = EFalse;
       
    64 	TBool HALSetBrightnessSupported = EFalse;
       
    65 
       
    66 	test.Next(_L("Max Brightness using HAL"));
       
    67 	TInt maxBrightness=-1;
       
    68 	ret = HAL::Get(HAL::EDisplayBrightnessMax, maxBrightness);
       
    69 	test ((KErrNone == ret) || (KErrNotSupported == ret));
       
    70 
       
    71 	if (KErrNone == ret)
       
    72 		{
       
    73 		HALMaxBrightnessSupported = ETrue;
       
    74 		test.Printf(_L("Maximum brightness = %d\n"), maxBrightness);
       
    75 		}
       
    76 	else
       
    77 		test.Printf(_L("Maximum brightness is NOT SUPPORTED by HAL\n"));
       
    78 
       
    79 
       
    80 	test.Next(_L("Get Brightness using HAL"));
       
    81 	HALArg = -1;
       
    82 	ret = HAL::Get(HAL::EDisplayBrightness, HALArg);
       
    83 	test ((KErrNone == ret) || (KErrNotSupported == ret));
       
    84 	if (KErrNone == ret)
       
    85 		{
       
    86 		test.Printf(_L("Brightness = %d\n"), HALArg);
       
    87 		HALGetBrightnessSupported = ETrue;
       
    88 		saved = HALArg;
       
    89 		}
       
    90 	else
       
    91 		{
       
    92 		test.Printf(_L("Get Brightness is NOT SUPPORTED by HAL\n"));
       
    93 		}
       
    94 
       
    95 	test.Next(_L("Test brightness is <= maxBrightness"));
       
    96 	test(HALArg <= maxBrightness);
       
    97 
       
    98 	test.Next(_L("Set Brightness using HAL"));
       
    99 	ret = HAL::Set(HAL::EDisplayBrightness, 0);
       
   100 	test ((KErrNone == ret) || (KErrNotSupported == ret) || (KErrArgument == ret));
       
   101 	if ((KErrNone == ret) || (KErrArgument == ret))
       
   102 		HALSetBrightnessSupported = ETrue;
       
   103 	else
       
   104 		test.Printf(_L("Set brightness is NOT SUPPORTED by HAL\n"));
       
   105 
       
   106 
       
   107 		
       
   108 	//if any of the brightness funcs are supported, test they all are
       
   109 	//we've already tested Ldd/HAL are giving same support
       
   110 	if (HALSetBrightnessSupported && HALGetBrightnessSupported && HALMaxBrightnessSupported)
       
   111 		{
       
   112 		//all supported
       
   113 		//do more comprehensive set/gets
       
   114 		test.Next(_L("Set Brightness using HAL to saved value"));
       
   115 		ret = HAL::Set(HAL::EDisplayBrightness, saved);
       
   116 		test (KErrNone == ret);
       
   117 
       
   118 		test.Next(_L("Get Brightness using HAL"));
       
   119 		HALArg = -1;
       
   120 		ret = HAL::Get(HAL::EDisplayBrightness, HALArg);
       
   121 		test (KErrNone == ret);
       
   122 		test (saved == HALArg);
       
   123 	
       
   124 		test.Next(_L("Set Brightness to the max using HAL"));
       
   125 		ret = HAL::Set(HAL::EDisplayBrightness, maxBrightness);
       
   126 		test.Printf(_L("ret = %d maxbr = %d"),ret, maxBrightness);
       
   127 		test (KErrNone == ret);
       
   128 
       
   129 		test.Next(_L("Get Brightness using HAL"));
       
   130 		HALArg = 0;
       
   131 		ret = HAL::Get(HAL::EDisplayBrightness, HALArg);
       
   132 		test (KErrNone == ret);
       
   133 		test (maxBrightness == HALArg);
       
   134 
       
   135 		test.Next(_L("Set Brightness using HAL"));
       
   136 		ret = HAL::Set(HAL::EDisplayBrightness, saved);
       
   137 		test (KErrNone == ret);
       
   138 
       
   139 
       
   140 		//test some out of range values
       
   141 		ret = HAL::Get(HAL::EDisplayBrightness, HALArg);
       
   142 		test (KErrNone == ret);
       
   143 		saved = HALArg;
       
   144 
       
   145 		test.Next(_L("Set Brightness too large using HAL"));
       
   146 		ret = HAL::Set(HAL::EDisplayBrightness, maxBrightness+1);
       
   147 		test (KErrArgument == ret);
       
   148 
       
   149 		test.Next(_L("Set Brightness too small using HAL"));
       
   150 		ret = HAL::Set(HAL::EDisplayBrightness, -1);
       
   151 		test (KErrArgument == ret);
       
   152 
       
   153 		}
       
   154 		else	//check none are supported
       
   155 			test(!(HALSetBrightnessSupported || HALGetBrightnessSupported || HALMaxBrightnessSupported));
       
   156 
       
   157 
       
   158 /*	CONTRAST	*/
       
   159 
       
   160 	TBool HALMaxContrastSupported = EFalse;
       
   161 	TBool HALGetContrastSupported = EFalse;
       
   162 	TBool HALSetContrastSupported = EFalse;
       
   163 	
       
   164 
       
   165 	test.Next(_L("Max Contrast using HAL"));
       
   166 	TInt maxContrast=-1;
       
   167 	ret = HAL::Get(HAL::EDisplayContrastMax, maxContrast);
       
   168 	test ((KErrNone == ret) || (KErrNotSupported == ret));
       
   169 
       
   170 	if (KErrNone == ret)
       
   171 		{
       
   172 		HALMaxContrastSupported = ETrue;
       
   173 		test.Printf(_L("Maximum Contrast = %d\n"), maxContrast);
       
   174 		}
       
   175 	else
       
   176 		test.Printf(_L("Maximum Contrast is NOT SUPPORTED by HAL\n"));
       
   177 
       
   178 
       
   179 	test.Next(_L("Get Contrast using HAL"));
       
   180 	HALArg = -1;
       
   181 	ret = HAL::Get(HAL::EDisplayContrast, HALArg);
       
   182 	test ((KErrNone == ret) || (KErrNotSupported == ret));
       
   183 	if (KErrNone == ret)
       
   184 		{
       
   185 		test.Printf(_L("Contrast = %d\n"), HALArg);
       
   186 		HALGetContrastSupported = ETrue;
       
   187 		saved = HALArg;
       
   188 		}
       
   189 	else
       
   190 		{
       
   191 		test.Printf(_L("Get Contrast is NOT SUPPORTED by HAL\n"));
       
   192 		}
       
   193 
       
   194 	test.Next(_L("Test contrast is <= maxcontrast"));
       
   195 	test(HALArg <= maxContrast);
       
   196 
       
   197 	test.Next(_L("Set Contrast using HAL"));
       
   198 	ret = HAL::Set(HAL::EDisplayContrast, 0);
       
   199 	test ((KErrNone == ret) || (KErrNotSupported == ret) || (KErrArgument == ret));
       
   200 	if ((KErrNone == ret) || (KErrArgument == ret))
       
   201 		HALSetContrastSupported = ETrue;
       
   202 	else
       
   203 		test.Printf(_L("Set Contrast is NOT SUPPORTED by HAL\n"));
       
   204 
       
   205 
       
   206 		
       
   207 	//if any of the Contrast funcs are supported, test they all are
       
   208 	//we've already tested Ldd/HAL are giving same support
       
   209 	if (HALSetContrastSupported && HALGetContrastSupported && HALMaxContrastSupported)
       
   210 		{
       
   211 		//all supported
       
   212 		//do more comprehensive set/gets
       
   213 		test.Next(_L("Set Contrast using HAL to saved value"));
       
   214 		ret = HAL::Set(HAL::EDisplayContrast, saved);
       
   215 		test (KErrNone == ret);
       
   216 
       
   217 		test.Next(_L("Get Contrast using HAL"));
       
   218 		HALArg = -1;
       
   219 		ret = HAL::Get(HAL::EDisplayContrast, HALArg);
       
   220 		test (KErrNone == ret);
       
   221 		test (saved == HALArg);
       
   222 	
       
   223 		test.Next(_L("Set Contrast to the max using HAL"));
       
   224 		ret = HAL::Set(HAL::EDisplayContrast, maxContrast);
       
   225 		test (KErrNone == ret);
       
   226 
       
   227 		test.Next(_L("Get Contrast using HAL"));
       
   228 		HALArg = 0;
       
   229 		ret = HAL::Get(HAL::EDisplayContrast, HALArg);
       
   230 		test (KErrNone == ret);
       
   231 		test (maxContrast == HALArg);
       
   232 
       
   233 		test.Next(_L("Set Contrast using HAL"));
       
   234 		ret = HAL::Set(HAL::EDisplayContrast, saved);
       
   235 		test (KErrNone == ret);
       
   236 
       
   237 
       
   238 		//test some out of range values
       
   239 		ret = HAL::Get(HAL::EDisplayContrast, HALArg);
       
   240 		test (KErrNone == ret);
       
   241 		saved = HALArg;
       
   242 
       
   243 		test.Next(_L("Set Contrast too large using HAL"));
       
   244 		ret = HAL::Set(HAL::EDisplayContrast, maxContrast+1);
       
   245 		test (KErrArgument == ret);
       
   246 
       
   247 		test.Next(_L("Set Contrast too small using HAL"));
       
   248 		ret = HAL::Set(HAL::EDisplayContrast, -1);
       
   249 		test (KErrArgument == ret);
       
   250 
       
   251 		}
       
   252 		else	//check none are supported
       
   253 			test(!(HALSetContrastSupported || HALGetContrastSupported || HALMaxContrastSupported));
       
   254 
       
   255 		
       
   256 		
       
   257 /*	BACKLIGHT	*/
       
   258 
       
   259 	TBool HALGetBacklightSupported = EFalse;
       
   260 	TBool HALSetBacklightSupported = EFalse;
       
   261 	TBool lightSupported = EFalse;
       
   262 
       
   263 	test.Next(_L("check if backlight supported using HAL"));
       
   264 	HALArg = -1;
       
   265 	ret = HAL::Get(HAL::EBacklight, lightSupported);
       
   266 	test ((KErrNone == ret) || (KErrNotSupported == ret));
       
   267 	test.Printf(_L("Backlight supported = %d"), lightSupported);
       
   268 
       
   269 
       
   270 
       
   271 	test.Next(_L("Get Backlight state using HAL"));
       
   272 	HALArg = -1;
       
   273 	ret = HAL::Get(HAL::EBacklightState, HALArg);
       
   274 	test ((KErrNone == ret) || (KErrNotSupported == ret));
       
   275 	if (KErrNone == ret)
       
   276 		{
       
   277 		HALGetBacklightSupported = ETrue;
       
   278 		test.Printf(_L("Backlight is = %d from HAL\n"), HALArg);
       
   279 		}
       
   280 	else
       
   281 		test.Printf(_L("Get Light is NOT SUPPORTED by HAL\n"));
       
   282 
       
   283 
       
   284 	test.Next(_L("Set Backlight state using HAL"));
       
   285 	HALArg = 0;
       
   286 	ret = HAL::Set(HAL::EBacklightState, HALArg);
       
   287 	test ((KErrNone == ret) || (KErrNotSupported == ret));
       
   288 	if (KErrNone == ret)
       
   289 		{
       
   290 		HALSetBacklightSupported = ETrue;
       
   291 		test.Printf(_L("Backlight is set to = %d from HAL\n"), HALArg);
       
   292 		}
       
   293 	else
       
   294 		test.Printf(_L("Set Light is NOT SUPPORTED by HAL\n"));
       
   295 
       
   296 
       
   297 
       
   298 
       
   299 	if 	(HALGetBacklightSupported && HALSetBacklightSupported)
       
   300 		{
       
   301 
       
   302 		test.Next(_L("Get Backlight state using HAL (should be off)"));
       
   303 		HALArg = -1;
       
   304 		ret = HAL::Get(HAL::EBacklightState, HALArg);
       
   305 		test (KErrNone == ret);
       
   306 		test (0 == HALArg);
       
   307 
       
   308 		test.Next(_L("Set Backlight state to on using HAL"));
       
   309 		ret = HAL::Set(HAL::EBacklightState, 1);
       
   310 		test (KErrNone == ret);
       
   311 
       
   312 		}
       
   313 	else
       
   314 		test (!HALGetBacklightSupported == !HALSetBacklightSupported);
       
   315 
       
   316 
       
   317 	/* maximum display colors*/
       
   318 	test.Next(_L("Display Colors"));
       
   319 	ret = HAL::Get(HAL::EDisplayColors, HALArg);
       
   320 	test (KErrNone == ret);
       
   321 
       
   322 	
       
   323 	/*  DISPLAY MODE */
       
   324 	test.Next(_L("Display Modes"));
       
   325 	TInt totalModes;
       
   326 	ret = HAL::Get(HAL::EDisplayNumModes, totalModes);
       
   327 	test (KErrNone == ret);
       
   328 
       
   329 	TInt displayMode;
       
   330 	ret = HAL::Get(HAL::EDisplayMode, displayMode);
       
   331 	test (KErrNone == ret);
       
   332 	
       
   333 	
       
   334 
       
   335 	/* SCREEN INFORMATION*/
       
   336 
       
   337 	test.Next(_L("Get Screen Info for current mode using driver"));
       
   338 
       
   339 
       
   340 	test.Next(_L("Get screen info using usersvr"));
       
   341 	TScreenInfoV01 screenInfo;
       
   342 	TPckg<TScreenInfoV01> sI(screenInfo);
       
   343 	UserSvr::ScreenInfo(sI);
       
   344 	test (screenInfo.iScreenAddressValid != screenInfo.iWindowHandleValid);
       
   345 	if (screenInfo.iScreenAddressValid)
       
   346 		test (screenInfo.iScreenAddress != 0);
       
   347 	if (screenInfo.iWindowHandleValid)
       
   348 		test (screenInfo.iWindowHandle != 0);
       
   349 
       
   350 
       
   351 	TInt val;
       
   352 	test.Next(_L("Get DisplayXPixels using HAL"));
       
   353 	ret = HAL::Get(HAL::EDisplayXPixels, val);
       
   354 	test (KErrNone == ret);
       
   355 	test (val == screenInfo.iScreenSize.iWidth);
       
   356 
       
   357 	test.Next(_L("Get DisplayYPixels using HAL"));
       
   358 	ret = HAL::Get(HAL::EDisplayYPixels, val);
       
   359 	test (KErrNone == ret);
       
   360 	test (val == screenInfo.iScreenSize.iHeight);
       
   361 
       
   362 	TInt xtwips;
       
   363 	test.Next(_L("Get DisplayXTwips using HAL"));
       
   364 	ret = HAL::Get(HAL::EDisplayXTwips, xtwips);
       
   365 	test (KErrNone == ret);
       
   366 
       
   367 	TInt ytwips;
       
   368 	test.Next(_L("Get DisplayYTwips using HAL"));
       
   369 	ret = HAL::Get(HAL::EDisplayYTwips, ytwips);
       
   370 	test (KErrNone == ret);
       
   371 
       
   372 	TInt vaddr;
       
   373 	test.Next(_L("Get video address using HAL"));
       
   374 	ret = HAL::Get(HAL::EDisplayMemoryAddress, vaddr);
       
   375 	test (KErrNone == ret);
       
   376 #ifndef __WINS__
       
   377 	test (vaddr == (TInt)screenInfo.iScreenAddress);
       
   378 #else
       
   379 	test (vaddr == (TInt)screenInfo.iWindowHandle);
       
   380 #endif
       
   381 
       
   382 	test.Next(_L("Use machine info"));
       
   383 
       
   384 	TMachineInfoV1 mi;
       
   385 	TMachineInfoV1Buf mib;
       
   386 
       
   387 	UserHal::MachineInfo(mib);
       
   388 	mi = mib();
       
   389 
       
   390 	test.Printf(_L("si.iWidth = %d,  si.iHeight = %d,  mi.iWidth = %d, mi.iHeight = %d\n"),screenInfo.iScreenSize.iWidth, screenInfo.iScreenSize.iHeight, mi.iDisplaySizeInPixels.iWidth, mi.iDisplaySizeInPixels.iHeight);
       
   391 	test.Printf(_L("xtwips = %d,  ytwips = %d,  iWidth = %d, iHeight = %d\n"),xtwips, ytwips, mi.iPhysicalScreenSize.iWidth, mi.iPhysicalScreenSize.iHeight);
       
   392 
       
   393 	test (screenInfo.iScreenSize.iWidth == mi.iDisplaySizeInPixels.iWidth);
       
   394 	test (screenInfo.iScreenSize.iHeight == mi.iDisplaySizeInPixels.iHeight);
       
   395 	test (xtwips == mi.iPhysicalScreenSize.iWidth);
       
   396 	test (ytwips == mi.iPhysicalScreenSize.iHeight);
       
   397 
       
   398 
       
   399 /* BITS PER PIXEL */
       
   400 
       
   401 	test.Next(_L("Get Bits per pixel for current display mode using HAL"));
       
   402 
       
   403 	HALArg = displayMode;
       
   404 	ret = HAL::Get(HAL::EDisplayBitsPerPixel, HALArg);
       
   405 	test (KErrNone == ret);
       
   406 
       
   407 
       
   408 	test.Next(_L("Get Bits per pixel with illegal mode using HAL"));
       
   409 	HALArg = -1;
       
   410 	ret = HAL::Get(HAL::EDisplayBitsPerPixel, HALArg);
       
   411 	test (KErrArgument == ret);
       
   412 
       
   413 	HALArg = totalModes;
       
   414 	ret = HAL::Get(HAL::EDisplayBitsPerPixel, HALArg);
       
   415 	test (KErrArgument == ret);
       
   416 
       
   417 	
       
   418 /*DISPLAY MODES*/
       
   419 	test.Next(_L("loop through the display modes getting the info"));
       
   420 
       
   421 	TInt count;
       
   422 
       
   423 	TInt fourBppMode = -1;
       
   424 
       
   425 	for (count = 0; count < totalModes; count++)
       
   426 		{
       
   427 
       
   428 		test.Next(_L("Offset To first pixel"));
       
   429 		HALArg = count;
       
   430 		ret = HAL::Get(HAL::EDisplayOffsetToFirstPixel, HALArg);
       
   431 		test (KErrNone == ret);
       
   432 		test (HALArg >= 0);
       
   433 
       
   434 		test.Next(_L("Test Offset between lines is > 0"));
       
   435 		HALArg = count;
       
   436 		ret = HAL::Get(HAL::EDisplayOffsetBetweenLines, HALArg);
       
   437 		test (KErrNone == ret);
       
   438 #ifndef __WINS__
       
   439 		test (HALArg > 0);
       
   440 #else		
       
   441 		test.Printf(_L("WINS can return 0 here as it doesn't handle the buffer itself, target hardware must return > 0"));
       
   442 		test (HALArg >= 0);
       
   443 #endif
       
   444 		test.Next(_L("is display mono"));
       
   445 		HALArg = count;
       
   446 		ret = HAL::Get(HAL::EDisplayIsMono, HALArg);
       
   447 		test (KErrNone == ret);
       
   448 		
       
   449 		test.Next(_L("is display palettized"));
       
   450 		HALArg = count;
       
   451 		ret = HAL::Get(HAL::EDisplayIsPalettized, HALArg);
       
   452 		test (KErrNone == ret);
       
   453 
       
   454 		test.Next(_L("bits per pixel"));
       
   455 		HALArg = count;
       
   456 		ret = HAL::Get(HAL::EDisplayBitsPerPixel, HALArg);
       
   457 		test (KErrNone == ret);
       
   458 
       
   459 		if (HALArg == 4)
       
   460 			fourBppMode = count;
       
   461 
       
   462 		}
       
   463 
       
   464 
       
   465 	test.Next(_L("switch display modes must be supported if > 1 display mode"));
       
   466 
       
   467 	TInt oldMode = displayMode;
       
   468 #ifndef __X86__
       
   469 	if (totalModes > 1)
       
   470 		{
       
   471 		HALArg = displayMode;
       
   472 		ret = HAL::Set(HAL::EDisplayMode, HALArg);
       
   473 		test.Printf(_L("ret is %d dmode is %d\n"),ret, HALArg);
       
   474 		test (KErrNone == ret);
       
   475 
       
   476 		ret = HAL::Get(HAL::EDisplayMode, HALArg);
       
   477 		test (KErrNone == ret);
       
   478 		test (HALArg == displayMode);
       
   479 
       
   480 		}
       
   481 #endif
       
   482 	for (count = 0; count < totalModes; count++)
       
   483 		{
       
   484 			
       
   485 #ifndef __X86__
       
   486 		if (totalModes > 1)  //we must support mode change
       
   487 			{
       
   488 			test.Printf(_L("Setting Display Mode to %d\n"), count);
       
   489 
       
   490 			ret = HAL::Set(HAL::EDisplayMode, count);
       
   491 			test (KErrNone == ret);
       
   492 
       
   493 			ret = HAL::Get(HAL::EDisplayMode, HALArg);
       
   494 			test (KErrNone == ret);
       
   495 			test (HALArg == count);
       
   496 			}
       
   497 #endif
       
   498 
       
   499 		/* PALETTE */
       
   500 
       
   501 		//get the palette entries
       
   502 		//set a few to something else
       
   503 		//set them again
       
   504 
       
   505 		TInt palettized = count;
       
   506 		test.Next(_L("Get if we are using a palette using HAL"));
       
   507 		ret = HAL::Get(HAL::EDisplayIsPalettized, palettized);
       
   508 		test (KErrNone == ret);
       
   509 
       
   510 		if (palettized)
       
   511 			{
       
   512 			HALArg = count;
       
   513 			ret = HAL::Get(HAL::EDisplayBitsPerPixel, HALArg);
       
   514 			test (KErrNone == ret);
       
   515 			test.Printf(_L("Bitsperpixel is  %d\n"),HALArg);
       
   516 			test (HALArg <= 8);
       
   517 
       
   518 			TInt max = (1 << HALArg) - 1;
       
   519 			test.Printf(_L("number of palette entries is %d\n"),max);
       
   520 			
       
   521 			test.Next(_L("Get legal Palette entries using HAL and driver in loop"));
       
   522 			for (TInt x = 0; x <= max; x++)
       
   523 				{
       
   524 				HALArg = x;
       
   525 				ret = HAL::Get(HAL::EDisplayPaletteEntry, HALArg);
       
   526 				test.Printf(_L("getting entry %d, ret is %d\n"),x, ret);
       
   527 				test (KErrNone == ret);
       
   528 
       
   529 				}
       
   530 
       
   531 
       
   532 			//try a few sets
       
   533 			TInt saved;
       
   534 
       
   535 			test.Next(_L("Set Palette entry 0 to red using HAL"));
       
   536 
       
   537 			saved = 0;
       
   538 			ret = HAL::Get(HAL::EDisplayPaletteEntry, saved);
       
   539 			test (KErrNone == ret);
       
   540 
       
   541 			HALArg = 0xF80000;
       
   542 			ret = HAL::Set(HAL::EDisplayPaletteEntry, HALArg);
       
   543 			test (KErrNone == ret || KErrNotSupported == ret);
       
   544 			
       
   545 			if (KErrNone == ret)
       
   546 				{
       
   547 				HALArg = 0;
       
   548 				ret = HAL::Get(HAL::EDisplayPaletteEntry, HALArg);
       
   549 				test (KErrNone == ret);
       
   550 				test ((HALArg & 0xF8FFFF)==0xF80000);
       
   551 
       
   552 				ret = HAL::Set(HAL::EDisplayPaletteEntry, saved);
       
   553 				test (KErrNone == ret);
       
   554 
       
   555 
       
   556 				HALArg = 1;
       
   557 				ret = HAL::Get(HAL::EDisplayPaletteEntry, HALArg);
       
   558 				test (KErrNone == ret);
       
   559 
       
   560 
       
   561 				HALArg = (7 << 24) || 0xFFFF00;
       
   562 				ret = HAL::Set(HAL::EDisplayPaletteEntry, HALArg);
       
   563 				test (KErrNone == ret);
       
   564 
       
   565 			
       
   566 				}
       
   567 				
       
   568 
       
   569 			
       
   570 			HALArg = count;
       
   571 			test (KErrNone == HAL::Get(HAL::EDisplayBitsPerPixel, HALArg));
       
   572 
       
   573 			if (4 == HALArg)
       
   574 				{
       
   575 				test.Next(_L("Get Illegal palette entry using HAL"));
       
   576 				HALArg = 18;
       
   577 				ret = HAL::Get(HAL::EDisplayPaletteEntry, HALArg);
       
   578 				test (KErrArgument == ret);
       
   579 
       
   580 
       
   581 				test.Next(_L("Set Illegal palette entry using HAL"));
       
   582 				HALArg = 0x12 << 24 ;
       
   583 				ret = HAL::Set(HAL::EDisplayPaletteEntry, HALArg);
       
   584 				test (KErrArgument == ret);
       
   585 				}
       
   586 		
       
   587 			}
       
   588 		else
       
   589 			{
       
   590 			//not palettized
       
   591 			test.Next(_L("Get palette entry using HAL - should fail"));
       
   592 			HALArg = 0;
       
   593 			ret = HAL::Get(HAL::EDisplayPaletteEntry, HALArg);
       
   594 			test (KErrNotSupported == ret);
       
   595 			}
       
   596 
       
   597 	
       
   598 		}		
       
   599 
       
   600 #ifndef __X86__
       
   601 	if (totalModes > 1)  //we must support mode change
       
   602 		{
       
   603 		ret = HAL::Set(HAL::EDisplayMode, oldMode);
       
   604 		test (KErrNone == ret);
       
   605 		}
       
   606 #endif
       
   607 	
       
   608 	
       
   609 	
       
   610 	
       
   611 	/*	DISPLAY ON/OFF	*/
       
   612 
       
   613 	TInt displayState;
       
   614 
       
   615 	test.Next(_L("Check Display is on using HAL"));
       
   616 	displayState = EFalse;
       
   617 	ret = HAL::Get(HAL::EDisplayState, displayState);
       
   618 	test (KErrNone == ret);
       
   619 	test (displayState!=EFalse);
       
   620 
       
   621 	test.Next(_L("Turn Display Off using HAL"));
       
   622 	ret = HAL::Set(HAL::EDisplayState, 0);
       
   623 	test (KErrNone == ret || KErrNotSupported == ret);
       
   624 
       
   625 	if (KErrNone == ret)
       
   626 		{
       
   627 //		test.Next(_L("Check Display is off using HAL"));
       
   628 		displayState = ETrue;
       
   629 		ret = HAL::Get(HAL::EDisplayState, displayState);
       
   630 		test (KErrNone == ret);
       
   631 		test (displayState==EFalse);
       
   632 
       
   633 	//	test.Next(_L("Display On using HAL"));
       
   634 	//	ret = HAL::Set(HAL::EDisplayState, 1);
       
   635 	//	test (KErrNotSupported == ret);
       
   636 		
       
   637 
       
   638 	//need some way of turning on the display!
       
   639 		RTimer timer;
       
   640 		test(timer.CreateLocal()==KErrNone);
       
   641 		TTime now;
       
   642 		now.HomeTime();
       
   643 		TTime wakeup;
       
   644 		wakeup=now+TTimeIntervalSeconds(10);
       
   645 		TRequestStatus done;
       
   646 		timer.At(done,wakeup);
       
   647 
       
   648 		UserHal::SwitchOff();
       
   649 		User::WaitForRequest(done);
       
   650 
       
   651 		TRawEvent switchon;
       
   652 		switchon.Set(TRawEvent::ESwitchOn);
       
   653 		UserSvr::AddEvent(switchon);
       
   654 		}
       
   655 	else
       
   656 		test.Printf(_L("Display On/Off not supported by HAL on this playform\n"));
       
   657 
       
   658 	
       
   659 	test.Next(_L("Check Display On using HAL"));
       
   660 	displayState = EFalse;
       
   661 	ret = HAL::Get(HAL::EDisplayState, displayState);
       
   662 	test (KErrNone == ret);
       
   663 	test (displayState!=EFalse);
       
   664 
       
   665 
       
   666 // !!! Disable platform security tests until we get the new APIs
       
   667 /*	
       
   668 	test.Next(_L("Check if secure screen supported"));
       
   669 	TInt secure = EFalse;
       
   670 	ret = HAL::Get(HAL::ESecureDisplay, secure);
       
   671 	test (KErrNone == ret || KErrNotSupported == ret);
       
   672 	if (KErrNone == ret)
       
   673 		{
       
   674 		//get the secure address
       
   675 		TInt addr = 0;
       
   676 		ret = HAL::Get(HAL::ESecureDisplayMemoryAddress, addr);
       
   677 		test (KErrNone == ret);
       
   678 
       
   679 		//switch to secure screen
       
   680 		ret = HAL::Set(HAL::ESecureDisplay, ETrue);
       
   681 		test (KErrNone == ret);
       
   682 		User::After(2000000);
       
   683 
       
   684 		//switch to insecure screen
       
   685 		ret = HAL::Set(HAL::ESecureDisplay, EFalse);
       
   686 		test (KErrNone == ret);
       
   687 		User::After(2000000);
       
   688 
       
   689 		//switch to secure screen
       
   690 		ret = HAL::Set(HAL::ESecureDisplay, ETrue);
       
   691 		test (KErrNone == ret);
       
   692 		User::After(2000000);
       
   693 
       
   694 		//switch to insecure screen
       
   695 		ret = HAL::Set(HAL::ESecureDisplay, EFalse);
       
   696 		test (KErrNone == ret);
       
   697 		}
       
   698 	else
       
   699 		test.Printf(_L("secure screen not supported on this platform\n"));
       
   700 */
       
   701 
       
   702 	}
       
   703 
       
   704 
       
   705 //the function above tests HAL APIs where no screen number is specified
       
   706 //and implicitly screen 0 is assumed. This function runs only for additional
       
   707 //screens if any (screen1, screen2 etc.)
       
   708 //this uses the HAL APIs that take a screen number
       
   709 LOCAL_C void RunTestsAdditionalScreens(TInt screen)
       
   710 	{
       
   711 	TInt ret = KErrNone;
       
   712 	TInt HALArg;
       
   713 	TInt saved = 0;
       
   714 
       
   715 /*	BRIGHTNESS	*/
       
   716 	
       
   717 	TBool HALMaxBrightnessSupported = EFalse;
       
   718 	TBool HALGetBrightnessSupported = EFalse;
       
   719 	TBool HALSetBrightnessSupported = EFalse;
       
   720 	
       
   721 
       
   722 	test.Next(_L("Max Brightness using HAL"));
       
   723 	TInt maxBrightness=-1;
       
   724 	ret = HAL::Get(screen, HAL::EDisplayBrightnessMax, maxBrightness);
       
   725 	test ((KErrNone == ret) || (KErrNotSupported == ret));
       
   726 
       
   727 	if (KErrNone == ret)
       
   728 		{
       
   729 		HALMaxBrightnessSupported = ETrue;
       
   730 		test.Printf(_L("Maximum brightness = %d\n"), maxBrightness);
       
   731 		}
       
   732 	else
       
   733 		test.Printf(_L("Maximum brightness is NOT SUPPORTED by HAL\n"));
       
   734 
       
   735 
       
   736 	test.Next(_L("Get Brightness using HAL"));
       
   737 	HALArg = -1;
       
   738 	ret = HAL::Get(screen, HAL::EDisplayBrightness, HALArg);
       
   739 	test ((KErrNone == ret) || (KErrNotSupported == ret));
       
   740 	if (KErrNone == ret)
       
   741 		{
       
   742 		test.Printf(_L("Brightness = %d\n"), HALArg);
       
   743 		HALGetBrightnessSupported = ETrue;
       
   744 		saved = HALArg;
       
   745 		}
       
   746 	else
       
   747 		{
       
   748 		test.Printf(_L("Get Brightness is NOT SUPPORTED by HAL\n"));
       
   749 		}
       
   750 
       
   751 	test.Next(_L("Test brightness is <= maxBrightness"));
       
   752 	test(HALArg <= maxBrightness);
       
   753 
       
   754 	test.Next(_L("Set Brightness using HAL"));
       
   755 	ret = HAL::Set(screen, HAL::EDisplayBrightness, 0);
       
   756 	test ((KErrNone == ret) || (KErrNotSupported == ret) || (KErrArgument == ret));
       
   757 	if ((KErrNone == ret) || (KErrArgument == ret))
       
   758 		HALSetBrightnessSupported = ETrue;
       
   759 	else
       
   760 		test.Printf(_L("Set brightness is NOT SUPPORTED by HAL\n"));
       
   761 
       
   762 
       
   763 		
       
   764 	//if any of the brightness funcs are supported, test they all are
       
   765 	//we've already tested Ldd/HAL are giving same support
       
   766 	if (HALSetBrightnessSupported && HALGetBrightnessSupported && HALMaxBrightnessSupported)
       
   767 		{
       
   768 		//all supported
       
   769 		//do more comprehensive set/gets
       
   770 		test.Next(_L("Set Brightness using HAL to saved value"));
       
   771 		ret = HAL::Set(screen, HAL::EDisplayBrightness, saved);
       
   772 		test (KErrNone == ret);
       
   773 
       
   774 		test.Next(_L("Get Brightness using HAL"));
       
   775 		HALArg = -1;
       
   776 		ret = HAL::Get(screen, HAL::EDisplayBrightness, HALArg);
       
   777 		test (KErrNone == ret);
       
   778 		test (saved == HALArg);
       
   779 	
       
   780 		test.Next(_L("Set Brightness to the max using HAL"));
       
   781 		ret = HAL::Set(screen, HAL::EDisplayBrightness, maxBrightness);
       
   782 		test.Printf(_L("ret = %d maxbr = %d"),ret, maxBrightness);
       
   783 		test (KErrNone == ret);
       
   784 
       
   785 		test.Next(_L("Get Brightness using HAL"));
       
   786 		HALArg = 0;
       
   787 		ret = HAL::Get(screen, HAL::EDisplayBrightness, HALArg);
       
   788 		test (KErrNone == ret);
       
   789 		test (maxBrightness == HALArg);
       
   790 
       
   791 		test.Next(_L("Set Brightness using HAL"));
       
   792 		ret = HAL::Set(screen, HAL::EDisplayBrightness, saved);
       
   793 		test (KErrNone == ret);
       
   794 
       
   795 
       
   796 		//test some out of range values
       
   797 		ret = HAL::Get(screen, HAL::EDisplayBrightness, HALArg);
       
   798 		test (KErrNone == ret);
       
   799 		saved = HALArg;
       
   800 
       
   801 		test.Next(_L("Set Brightness too large using HAL"));
       
   802 		ret = HAL::Set(screen, HAL::EDisplayBrightness, maxBrightness+1);
       
   803 		test (KErrArgument == ret);
       
   804 
       
   805 		test.Next(_L("Set Brightness too small using HAL"));
       
   806 		ret = HAL::Set(screen, HAL::EDisplayBrightness, -1);
       
   807 		test (KErrArgument == ret);
       
   808 
       
   809 		}
       
   810 		else	//check none are supported
       
   811 			test(!(HALSetBrightnessSupported || HALGetBrightnessSupported || HALMaxBrightnessSupported));
       
   812 
       
   813 
       
   814 /*	CONTRAST	*/
       
   815 
       
   816 	TBool HALMaxContrastSupported = EFalse;
       
   817 	TBool HALGetContrastSupported = EFalse;
       
   818 	TBool HALSetContrastSupported = EFalse;
       
   819 	
       
   820 
       
   821 	test.Next(_L("Max Contrast using HAL"));
       
   822 	TInt maxContrast=-1;
       
   823 	ret = HAL::Get(screen, HAL::EDisplayContrastMax, maxContrast);
       
   824 	test ((KErrNone == ret) || (KErrNotSupported == ret));
       
   825 
       
   826 	if (KErrNone == ret)
       
   827 		{
       
   828 		HALMaxContrastSupported = ETrue;
       
   829 		test.Printf(_L("Maximum Contrast = %d\n"), maxContrast);
       
   830 		}
       
   831 	else
       
   832 		test.Printf(_L("Maximum Contrast is NOT SUPPORTED by HAL\n"));
       
   833 
       
   834 
       
   835 	test.Next(_L("Get Contrast using HAL"));
       
   836 	HALArg = -1;
       
   837 	ret = HAL::Get(screen, HAL::EDisplayContrast, HALArg);
       
   838 	test ((KErrNone == ret) || (KErrNotSupported == ret));
       
   839 	if (KErrNone == ret)
       
   840 		{
       
   841 		test.Printf(_L("Contrast = %d\n"), HALArg);
       
   842 		HALGetContrastSupported = ETrue;
       
   843 		saved = HALArg;
       
   844 		}
       
   845 	else
       
   846 		{
       
   847 		test.Printf(_L("Get Contrast is NOT SUPPORTED by HAL\n"));
       
   848 		}
       
   849 
       
   850 	test.Next(_L("Test contrast is <= maxcontrast"));
       
   851 	test(HALArg <= maxContrast);
       
   852 
       
   853 	test.Next(_L("Set Contrast using HAL"));
       
   854 	ret = HAL::Set(screen, HAL::EDisplayContrast, 0);
       
   855 	test ((KErrNone == ret) || (KErrNotSupported == ret) || (KErrArgument == ret));
       
   856 	if ((KErrNone == ret) || (KErrArgument == ret))
       
   857 		HALSetContrastSupported = ETrue;
       
   858 	else
       
   859 		test.Printf(_L("Set Contrast is NOT SUPPORTED by HAL\n"));
       
   860 
       
   861 
       
   862 		
       
   863 	//if any of the Contrast funcs are supported, test they all are
       
   864 	//we've already tested Ldd/HAL are giving same support
       
   865 	if (HALSetContrastSupported && HALGetContrastSupported && HALMaxContrastSupported)
       
   866 		{
       
   867 		//all supported
       
   868 		//do more comprehensive set/gets
       
   869 		test.Next(_L("Set Contrast using HAL to saved value"));
       
   870 		ret = HAL::Set(screen, HAL::EDisplayContrast, saved);
       
   871 		test (KErrNone == ret);
       
   872 
       
   873 		test.Next(_L("Get Contrast using HAL"));
       
   874 		HALArg = -1;
       
   875 		ret = HAL::Get(screen, HAL::EDisplayContrast, HALArg);
       
   876 		test (KErrNone == ret);
       
   877 		test (saved == HALArg);
       
   878 	
       
   879 		test.Next(_L("Set Contrast to the max using HAL"));
       
   880 		ret = HAL::Set(screen, HAL::EDisplayContrast, maxContrast);
       
   881 		test (KErrNone == ret);
       
   882 
       
   883 		test.Next(_L("Get Contrast using HAL"));
       
   884 		HALArg = 0;
       
   885 		ret = HAL::Get(screen, HAL::EDisplayContrast, HALArg);
       
   886 		test (KErrNone == ret);
       
   887 		test (maxContrast == HALArg);
       
   888 
       
   889 		test.Next(_L("Set Contrast using HAL"));
       
   890 		ret = HAL::Set(screen, HAL::EDisplayContrast, saved);
       
   891 		test (KErrNone == ret);
       
   892 
       
   893 
       
   894 		//test some out of range values
       
   895 		ret = HAL::Get(screen, HAL::EDisplayContrast, HALArg);
       
   896 		test (KErrNone == ret);
       
   897 		saved = HALArg;
       
   898 
       
   899 		test.Next(_L("Set Contrast too large using HAL"));
       
   900 		ret = HAL::Set(screen, HAL::EDisplayContrast, maxContrast+1);
       
   901 		test (KErrArgument == ret);
       
   902 
       
   903 		test.Next(_L("Set Contrast too small using HAL"));
       
   904 		ret = HAL::Set(screen, HAL::EDisplayContrast, -1);
       
   905 		test (KErrArgument == ret);
       
   906 
       
   907 		}
       
   908 		else	//check none are supported
       
   909 			test(!(HALSetContrastSupported || HALGetContrastSupported || HALMaxContrastSupported));
       
   910 
       
   911 		
       
   912 		
       
   913 /*	BACKLIGHT	*/
       
   914 
       
   915 	TBool HALGetBacklightSupported = EFalse;
       
   916 	TBool HALSetBacklightSupported = EFalse;
       
   917 	TBool lightSupported = EFalse;
       
   918 
       
   919 	test.Next(_L("check if backlight supported using HAL"));
       
   920 	HALArg = -1;
       
   921 	ret = HAL::Get(screen, HAL::EBacklight, lightSupported);
       
   922 	test ((KErrNone == ret) || (KErrNotSupported == ret));
       
   923 	test.Printf(_L("Backlight supported = %d"), lightSupported);
       
   924 
       
   925 
       
   926 
       
   927 	test.Next(_L("Get Backlight state using HAL"));
       
   928 	HALArg = -1;
       
   929 	ret = HAL::Get(screen, HAL::EBacklightState, HALArg);
       
   930 	test ((KErrNone == ret) || (KErrNotSupported == ret));
       
   931 	if (KErrNone == ret)
       
   932 		{
       
   933 		HALGetBacklightSupported = ETrue;
       
   934 		test.Printf(_L("Backlight is = %d from HAL\n"), HALArg);
       
   935 		}
       
   936 	else
       
   937 		test.Printf(_L("Get Light is NOT SUPPORTED by HAL\n"));
       
   938 
       
   939 
       
   940 	test.Next(_L("Set Backlight state using HAL"));
       
   941 	HALArg = 0;
       
   942 	ret = HAL::Set(screen, HAL::EBacklightState, HALArg);
       
   943 	test ((KErrNone == ret) || (KErrNotSupported == ret));
       
   944 	if (KErrNone == ret)
       
   945 		{
       
   946 		HALSetBacklightSupported = ETrue;
       
   947 		test.Printf(_L("Backlight is set to = %d from HAL\n"), HALArg);
       
   948 		}
       
   949 	else
       
   950 		test.Printf(_L("Set Light is NOT SUPPORTED by HAL\n"));
       
   951 
       
   952 
       
   953 
       
   954 
       
   955 	if 	(HALGetBacklightSupported && HALSetBacklightSupported)
       
   956 		{
       
   957 
       
   958 		test.Next(_L("Get Backlight state using HAL (should be off)"));
       
   959 		HALArg = -1;
       
   960 		ret = HAL::Get(screen, HAL::EBacklightState, HALArg);
       
   961 		test (KErrNone == ret);
       
   962 		test (0 == HALArg);
       
   963 
       
   964 		test.Next(_L("Set Backlight state to on using HAL"));
       
   965 		ret = HAL::Set(screen, HAL::EBacklightState, 1);
       
   966 		test (KErrNone == ret);
       
   967 
       
   968 		}
       
   969 	else
       
   970 		test (!HALGetBacklightSupported == !HALSetBacklightSupported);
       
   971 
       
   972 
       
   973 	/* maximum display colors*/
       
   974 	test.Next(_L("Display Colors"));
       
   975 	ret = HAL::Get(screen, HAL::EDisplayColors, HALArg);
       
   976 	test (KErrNone == ret);
       
   977 
       
   978 	
       
   979 	/*  DISPLAY MODE */
       
   980 	test.Next(_L("Display Modes"));
       
   981 	TInt totalModes;
       
   982 	ret = HAL::Get(screen, HAL::EDisplayNumModes, totalModes);
       
   983 	test (KErrNone == ret);
       
   984 
       
   985 	TInt displayMode;
       
   986 	ret = HAL::Get(screen, HAL::EDisplayMode, displayMode);
       
   987 	test (KErrNone == ret);
       
   988 	
       
   989 	TInt val;
       
   990 	test.Next(_L("Get DisplayXPixels using HAL"));
       
   991 	ret = HAL::Get(screen, HAL::EDisplayXPixels, val);
       
   992 	test (KErrNone == ret);
       
   993 
       
   994 	test.Next(_L("Get DisplayYPixels using HAL"));
       
   995 	ret = HAL::Get(screen, HAL::EDisplayYPixels, val);
       
   996 	test (KErrNone == ret);
       
   997 
       
   998 	TInt xtwips;
       
   999 	test.Next(_L("Get DisplayXTwips using HAL"));
       
  1000 	ret = HAL::Get(screen, HAL::EDisplayXTwips, xtwips);
       
  1001 	test (KErrNone == ret);
       
  1002 
       
  1003 	TInt ytwips;
       
  1004 	test.Next(_L("Get DisplayYTwips using HAL"));
       
  1005 	ret = HAL::Get(screen, HAL::EDisplayYTwips, ytwips);
       
  1006 	test (KErrNone == ret);
       
  1007 
       
  1008 	TInt vaddr;
       
  1009 	test.Next(_L("Get video address using HAL"));
       
  1010 	ret = HAL::Get(screen, HAL::EDisplayMemoryAddress, vaddr);
       
  1011 	test (KErrNone == ret);
       
  1012 
       
  1013 
       
  1014 /* BITS PER PIXEL */
       
  1015 
       
  1016 	test.Next(_L("Get Bits per pixel for current display mode using HAL"));
       
  1017 
       
  1018 	HALArg = displayMode;
       
  1019 	ret = HAL::Get(screen, HAL::EDisplayBitsPerPixel, HALArg);
       
  1020 	test (KErrNone == ret);
       
  1021 
       
  1022 
       
  1023 	test.Next(_L("Get Bits per pixel with illegal mode using HAL"));
       
  1024 	HALArg = -1;
       
  1025 	ret = HAL::Get(screen, HAL::EDisplayBitsPerPixel, HALArg);
       
  1026 	test (KErrArgument == ret);
       
  1027 
       
  1028 	HALArg = totalModes;
       
  1029 	ret = HAL::Get(screen, HAL::EDisplayBitsPerPixel, HALArg);
       
  1030 	test (KErrArgument == ret);
       
  1031 
       
  1032 	
       
  1033 /*DISPLAY MODES*/
       
  1034 	test.Next(_L("loop through the display modes getting the info"));
       
  1035 
       
  1036 	TInt count;
       
  1037 
       
  1038 	TInt fourBppMode = -1;
       
  1039 
       
  1040 	for (count = 0; count < totalModes; count++)
       
  1041 		{
       
  1042 
       
  1043 		test.Next(_L("Offset To first pixel"));
       
  1044 		HALArg = count;
       
  1045 		ret = HAL::Get(screen, HAL::EDisplayOffsetToFirstPixel, HALArg);
       
  1046 		test (KErrNone == ret);
       
  1047 		test (HALArg >= 0);
       
  1048 
       
  1049 		test.Next(_L("Test Offset between lines is > 0"));
       
  1050 		HALArg = count;
       
  1051 		ret = HAL::Get(screen, HAL::EDisplayOffsetBetweenLines, HALArg);
       
  1052 		test (KErrNone == ret);
       
  1053 #ifndef __WINS__
       
  1054 		test (HALArg > 0);
       
  1055 #else		
       
  1056 		test.Printf(_L("WINS can return 0 here as it doesn't handle the buffer itself, target hardware must return > 0"));
       
  1057 		test (HALArg >= 0);
       
  1058 #endif
       
  1059 		test.Next(_L("is display mono"));
       
  1060 		HALArg = count;
       
  1061 		ret = HAL::Get(screen, HAL::EDisplayIsMono, HALArg);
       
  1062 		test (KErrNone == ret);
       
  1063 		
       
  1064 		test.Next(_L("is display palettized"));
       
  1065 		HALArg = count;
       
  1066 		ret = HAL::Get(screen, HAL::EDisplayIsPalettized, HALArg);
       
  1067 		test (KErrNone == ret);
       
  1068 
       
  1069 		test.Next(_L("bits per pixel"));
       
  1070 		HALArg = count;
       
  1071 		ret = HAL::Get(screen, HAL::EDisplayBitsPerPixel, HALArg);
       
  1072 		test (KErrNone == ret);
       
  1073 
       
  1074 		if (HALArg == 4)
       
  1075 			fourBppMode = count;
       
  1076 
       
  1077 		}
       
  1078 
       
  1079 
       
  1080 	test.Next(_L("switch display modes must be supported if > 1 display mode"));
       
  1081 
       
  1082 	TInt oldMode = displayMode;
       
  1083 #ifndef __X86__
       
  1084 	if (totalModes > 1)
       
  1085 		{
       
  1086 		HALArg = displayMode;
       
  1087 		ret = HAL::Set(screen, HAL::EDisplayMode, HALArg);
       
  1088 		test.Printf(_L("ret is %d dmode is %d\n"),ret, HALArg);
       
  1089 		test (KErrNone == ret);
       
  1090 
       
  1091 		ret = HAL::Get(screen, HAL::EDisplayMode, HALArg);
       
  1092 		test (KErrNone == ret);
       
  1093 		test (HALArg == displayMode);
       
  1094 
       
  1095 		}
       
  1096 #endif
       
  1097 	for (count = 0; count < totalModes; count++)
       
  1098 		{
       
  1099 			
       
  1100 #ifndef __X86__
       
  1101 		if (totalModes > 1)  //we must support mode change
       
  1102 			{
       
  1103 			test.Printf(_L("Setting Display Mode to %d\n"), count);
       
  1104 
       
  1105 			ret = HAL::Set(screen, HAL::EDisplayMode, count);
       
  1106 			test (KErrNone == ret);
       
  1107 
       
  1108 			ret = HAL::Get(screen, HAL::EDisplayMode, HALArg);
       
  1109 			test (KErrNone == ret);
       
  1110 			test (HALArg == count);
       
  1111 			}
       
  1112 #endif
       
  1113 
       
  1114 		/* PALETTE */
       
  1115 
       
  1116 		//get the palette entries
       
  1117 		//set a few to something else
       
  1118 		//set them again
       
  1119 
       
  1120 		TInt palettized = count;
       
  1121 		test.Next(_L("Get if we are using a palette using HAL"));
       
  1122 		ret = HAL::Get(screen, HAL::EDisplayIsPalettized, palettized);
       
  1123 		test (KErrNone == ret);
       
  1124 
       
  1125 		if (palettized)
       
  1126 			{
       
  1127 			HALArg = count;
       
  1128 			ret = HAL::Get(screen, HAL::EDisplayBitsPerPixel, HALArg);
       
  1129 			test (KErrNone == ret);
       
  1130 			test.Printf(_L("Bitsperpixel is  %d\n"),HALArg);
       
  1131 			test (HALArg <= 8);
       
  1132 
       
  1133 			TInt max = (1 << HALArg) - 1;
       
  1134 			test.Printf(_L("number of palette entries is %d\n"),max);
       
  1135 			
       
  1136 			test.Next(_L("Get legal Palette entries using HAL and driver in loop"));
       
  1137 			for (TInt x = 0; x <= max; x++)
       
  1138 				{
       
  1139 				HALArg = x;
       
  1140 				ret = HAL::Get(screen, HAL::EDisplayPaletteEntry, HALArg);
       
  1141 				test.Printf(_L("getting entry %d, ret is %d\n"),x, ret);
       
  1142 				test (KErrNone == ret);
       
  1143 
       
  1144 				}
       
  1145 
       
  1146 
       
  1147 			//try a few sets
       
  1148 			TInt saved;
       
  1149 
       
  1150 			test.Next(_L("Set Palette entry 0 to red using HAL"));
       
  1151 
       
  1152 			saved = 0;
       
  1153 			ret = HAL::Get(screen, HAL::EDisplayPaletteEntry, saved);
       
  1154 			test (KErrNone == ret);
       
  1155 
       
  1156 			HALArg = 0xFF0000;
       
  1157 			ret = HAL::Set(screen, HAL::EDisplayPaletteEntry, HALArg);
       
  1158 			test (KErrNone == ret || KErrNotSupported == ret);
       
  1159 			
       
  1160 			if (KErrNone == ret)
       
  1161 				{
       
  1162 				HALArg = 0;
       
  1163 				ret = HAL::Get(screen, HAL::EDisplayPaletteEntry, HALArg);
       
  1164 				test (KErrNone == ret);
       
  1165 				test (HALArg = 0xFF0000);
       
  1166 
       
  1167 				ret = HAL::Set(screen, HAL::EDisplayPaletteEntry, saved);
       
  1168 				test (KErrNone == ret);
       
  1169 
       
  1170 
       
  1171 				HALArg = 1;
       
  1172 				ret = HAL::Get(screen, HAL::EDisplayPaletteEntry, HALArg);
       
  1173 				test (KErrNone == ret);
       
  1174 
       
  1175 
       
  1176 				HALArg = (7 << 24) || 0xFFFF00;
       
  1177 				ret = HAL::Set(screen, HAL::EDisplayPaletteEntry, HALArg);
       
  1178 				test (KErrNone == ret);
       
  1179 
       
  1180 			
       
  1181 				}
       
  1182 				
       
  1183 
       
  1184 			
       
  1185 			HALArg = count;
       
  1186 			test (KErrNone == HAL::Get(screen, HAL::EDisplayBitsPerPixel, HALArg));
       
  1187 
       
  1188 			if (4 == HALArg)
       
  1189 				{
       
  1190 				test.Next(_L("Get Illegal palette entry using HAL"));
       
  1191 				HALArg = 18;
       
  1192 				ret = HAL::Get(screen, HAL::EDisplayPaletteEntry, HALArg);
       
  1193 				test (KErrArgument == ret);
       
  1194 
       
  1195 
       
  1196 				test.Next(_L("Set Illegal palette entry using HAL"));
       
  1197 				HALArg = 0x12 << 24 ;
       
  1198 				ret = HAL::Set(screen, HAL::EDisplayPaletteEntry, HALArg);
       
  1199 				test (KErrArgument == ret);
       
  1200 				}
       
  1201 		
       
  1202 			}
       
  1203 		else
       
  1204 			{
       
  1205 			//not palettized
       
  1206 			test.Next(_L("Get palette entry using HAL - should fail"));
       
  1207 			HALArg = 0;
       
  1208 			ret = HAL::Get(screen, HAL::EDisplayPaletteEntry, HALArg);
       
  1209 			test (KErrNotSupported == ret);
       
  1210 			}
       
  1211 
       
  1212 	
       
  1213 		}		
       
  1214 
       
  1215 #ifndef __X86__
       
  1216 	if (totalModes > 1)  //we must support mode change
       
  1217 		{
       
  1218 		ret = HAL::Set(screen, HAL::EDisplayMode, oldMode);
       
  1219 		test (KErrNone == ret);
       
  1220 		}
       
  1221 #endif
       
  1222 	
       
  1223 	
       
  1224 	
       
  1225 	
       
  1226 	/*	DISPLAY ON/OFF	*/
       
  1227 
       
  1228 	
       
  1229 	// get current display state
       
  1230 	TInt curDisplayState;
       
  1231 	ret = HAL::Get(screen, HAL::EDisplayState, curDisplayState);
       
  1232 	test (KErrNone == ret);
       
  1233 
       
  1234 	test.Next(_L("Turn Display on using HAL"));
       
  1235 	ret = HAL::Set(screen, HAL::EDisplayState, 1);
       
  1236 	test (KErrNone == ret || KErrNotSupported == ret);
       
  1237 
       
  1238 	TInt displayState;
       
  1239 
       
  1240 	test.Next(_L("Check Display is on using HAL"));
       
  1241 	displayState = EFalse;
       
  1242 	ret = HAL::Get(screen, HAL::EDisplayState, displayState);
       
  1243 	test (KErrNone == ret);
       
  1244 	test (displayState!=EFalse);
       
  1245 
       
  1246 	test.Next(_L("Turn Display Off using HAL"));
       
  1247 	ret = HAL::Set(screen, HAL::EDisplayState, 0);
       
  1248 	test (KErrNone == ret || KErrNotSupported == ret);
       
  1249 
       
  1250 	if (KErrNone == ret)
       
  1251 		{
       
  1252 		test.Next(_L("Check Display is off using HAL"));
       
  1253 		displayState = ETrue;
       
  1254 		ret = HAL::Get(screen, HAL::EDisplayState, displayState);
       
  1255 		test (KErrNone == ret);
       
  1256 		test (displayState==EFalse);
       
  1257 
       
  1258 	//	test.Next(_L("Display On using HAL"));
       
  1259 	//	ret = HAL::Set(screen, HAL::EDisplayState, 1);
       
  1260 	//	test (KErrNotSupported == ret);
       
  1261 		
       
  1262 
       
  1263 	//need some way of turning on the display!
       
  1264 		RTimer timer;
       
  1265 		test(timer.CreateLocal()==KErrNone);
       
  1266 		TTime now;
       
  1267 		now.HomeTime();
       
  1268 		TTime wakeup;
       
  1269 		wakeup=now+TTimeIntervalSeconds(10);
       
  1270 		TRequestStatus done;
       
  1271 		timer.At(done,wakeup);
       
  1272 
       
  1273 		UserHal::SwitchOff();
       
  1274 		User::WaitForRequest(done);
       
  1275 
       
  1276 		TRawEvent switchon;
       
  1277 		switchon.Set(TRawEvent::ESwitchOn);
       
  1278 		UserSvr::AddEvent(switchon);
       
  1279 		}
       
  1280 	else
       
  1281 		test.Printf(_L("Display On/Off not supported by HAL on this playform\n"));
       
  1282 
       
  1283 	// restore the original display state
       
  1284 	ret = HAL::Set(screen, HAL::EDisplayState, curDisplayState);
       
  1285 	test (KErrNone == ret || KErrNotSupported == ret);
       
  1286 
       
  1287 
       
  1288 // !!! Disable platform security tests until we get the new APIs
       
  1289 /*	
       
  1290 	test.Next(_L("Check if secure screen supported"));
       
  1291 	TInt secure = EFalse;
       
  1292 	ret = HAL::Get(screen, HAL::ESecureDisplay, secure);
       
  1293 	test (KErrNone == ret || KErrNotSupported == ret);
       
  1294 	if (KErrNone == ret)
       
  1295 		{
       
  1296 		//get the secure address
       
  1297 		TInt addr = 0;
       
  1298 		ret = HAL::Get(screen, HAL::ESecureDisplayMemoryAddress, addr);
       
  1299 		test (KErrNone == ret);
       
  1300 
       
  1301 		//switch to secure screen
       
  1302 		ret = HAL::Set(screen, HAL::ESecureDisplay, ETrue);
       
  1303 		test (KErrNone == ret);
       
  1304 		User::After(2000000);
       
  1305 
       
  1306 		//switch to insecure screen
       
  1307 		ret = HAL::Set(screen, HAL::ESecureDisplay, EFalse);
       
  1308 		test (KErrNone == ret);
       
  1309 		User::After(2000000);
       
  1310 
       
  1311 		//switch to secure screen
       
  1312 		ret = HAL::Set(screen, HAL::ESecureDisplay, ETrue);
       
  1313 		test (KErrNone == ret);
       
  1314 		User::After(2000000);
       
  1315 
       
  1316 		//switch to insecure screen
       
  1317 		ret = HAL::Set(screen, HAL::ESecureDisplay, EFalse);
       
  1318 		test (KErrNone == ret);
       
  1319 		}
       
  1320 	else
       
  1321 		test.Printf(_L("secure screen not supported on this platform\n"));
       
  1322 */
       
  1323 
       
  1324 	}
       
  1325 
       
  1326 
       
  1327 GLDEF_C TInt E32Main()
       
  1328 //
       
  1329 //
       
  1330     {
       
  1331 
       
  1332 	test.Title();
       
  1333 //
       
  1334 #if defined(__EPOC32__) && defined(__CPU_X86)
       
  1335 	test.Printf(_L("Doesn't run on X86\n"));
       
  1336 #else
       
  1337 
       
  1338 	test.Start(_L("Testing Video extension"));
       
  1339 
       
  1340 	RunTests();
       
  1341 	TInt screens=1;	// assume that we have at least 1 screen in case the HAL attr isn't supported
       
  1342 	TInt ret=HAL::Get(HAL::EDisplayNumberOfScreens, screens);
       
  1343 	test((ret==KErrNone) || (ret==KErrNotSupported));
       
  1344 
       
  1345 	TInt i;
       
  1346 	for(i=1;i<screens;i++)
       
  1347 		RunTestsAdditionalScreens(i);
       
  1348 
       
  1349 	test.Next(_L("Test more devices than the kernel can handle"));
       
  1350 	//this constant should have a value > KMaxHalEntries (defined in the kernel)
       
  1351 	const TInt KMoreThanKernelAllocates=10;
       
  1352 	for(i=screens;i<KMoreThanKernelAllocates;i++)
       
  1353 		{
       
  1354 		TInt val;
       
  1355 		test.Next(_L("Get DisplayXPixels using HAL"));
       
  1356 		ret = HAL::Get(i, HAL::EDisplayXPixels, val);
       
  1357 		test (KErrNotSupported == ret);
       
  1358 
       
  1359 		test.Next(_L("Get DisplayYPixels using HAL"));
       
  1360 		ret = HAL::Get(i, HAL::EDisplayYPixels, val);
       
  1361 		test (KErrNotSupported == ret);
       
  1362 
       
  1363 		TInt xtwips;
       
  1364 		test.Next(_L("Get DisplayXTwips using HAL"));
       
  1365 		ret = HAL::Get(i, HAL::EDisplayXTwips, xtwips);
       
  1366 		test (KErrNotSupported == ret);
       
  1367 
       
  1368 		TInt ytwips;
       
  1369 		test.Next(_L("Get DisplayYTwips using HAL"));
       
  1370 		ret = HAL::Get(i, HAL::EDisplayYTwips, ytwips);
       
  1371 		test (KErrNotSupported == ret);
       
  1372 
       
  1373 		TInt vaddr;
       
  1374 		test.Next(_L("Get video address using HAL"));
       
  1375 		ret = HAL::Get(i, HAL::EDisplayMemoryAddress, vaddr);
       
  1376 		test (KErrNotSupported == ret);
       
  1377 		}
       
  1378 
       
  1379 	test.Next(_L("Test HAL::GetAll"));
       
  1380 	TInt numEntries;
       
  1381 	HAL::SEntry* entries;
       
  1382 	ret=HAL::GetAll(numEntries, entries);
       
  1383 	test(ret==KErrNone);
       
  1384 
       
  1385 	test(numEntries==screens*(TInt)HAL::ENumHalAttributes);
       
  1386 
       
  1387 	User::Free(entries);
       
  1388 
       
  1389 	test.Next(_L("Test TRawEvent for multiple devices (screens)"));
       
  1390 
       
  1391 	TRawEvent event1;
       
  1392 	test(event1.Type()==0);
       
  1393 	test(event1.DeviceNumber()==KUndefinedDeviceNumber);
       
  1394 
       
  1395 	event1.SetDeviceNumber(0);
       
  1396 	test(event1.DeviceNumber()==0);
       
  1397 
       
  1398 	event1.SetDeviceNumber(KUndefinedDeviceNumber);
       
  1399 	test(event1.DeviceNumber()==KUndefinedDeviceNumber);
       
  1400 
       
  1401 	test(event1.Type()==0);
       
  1402 
       
  1403 	event1.Set(TRawEvent::EKeyDown);
       
  1404 	test(event1.Type()==TRawEvent::EKeyDown);
       
  1405 
       
  1406 	event1.Set(TRawEvent::EKeyUp,10);
       
  1407 	test(event1.Type()==TRawEvent::EKeyUp);
       
  1408 
       
  1409 	event1.Set(TRawEvent::EKeyDown,10,10);
       
  1410 	test(event1.Type()==TRawEvent::EKeyDown);
       
  1411 
       
  1412 	test.End();
       
  1413 	test.Close();
       
  1414 
       
  1415 #endif
       
  1416 
       
  1417 	return KErrNone;
       
  1418     }
       
  1419