graphics/gdi/src/T_DataGraphicsDevice.cpp
branchSymbian2
changeset 1 8758140453c0
child 6 c108117318cb
equal deleted inserted replaced
0:e8c1ea2c6496 1:8758140453c0
       
     1 /*
       
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Symbian Foundation License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 /**
       
    19 @test
       
    20 @internalComponent
       
    21 
       
    22 This contains CT_DataGraphicsDevice
       
    23 */
       
    24 
       
    25 #include "T_DataGraphicsDevice.h"
       
    26 #include "T_GraphicsUtil.h"
       
    27 
       
    28 /*@{*/
       
    29 ///	Commands
       
    30 _LIT(KCmdCreateContext,								"CreateContext");
       
    31 _LIT(KCmdDisplayMode,								"DisplayMode");
       
    32 _LIT(KCmdFontHeightInTwips,							"FontHeightInTwips");
       
    33 _LIT(KCmdGetPalette,								"GetPalette");
       
    34 _LIT(KCmdNumTypefaces,								"NumTypefaces");
       
    35 _LIT(KCmdPaletteAttributes,							"PaletteAttributes");
       
    36 _LIT(KCmdSetPalette,								"SetPalette");
       
    37 _LIT(KCmdSizeInPixels,								"SizeInPixels");
       
    38 _LIT(KCmdSizeInTwips,								"SizeInTwips");
       
    39 _LIT(KCmdTypefaceSupport,							"TypefaceSupport");
       
    40 
       
    41 ///	Fields
       
    42 _LIT(KFldContext,									"context");
       
    43 _LIT(KFldDisplayMode,								"displaymode");
       
    44 _LIT(KFldExpected,									"expected");
       
    45 _LIT(KFldExpectedEntries,							"expected_entries");
       
    46 _LIT(KFldExpectedModifiable,						"expected_modifiable");
       
    47 _LIT(KFldHeightIndex,								"height_index");
       
    48 _LIT(KFldIndex,										"index");
       
    49 _LIT(KFldPalette,									"palette");
       
    50 _LIT(KFldTypefaceIndex,								"typeface_index");
       
    51 
       
    52 ///	Logging
       
    53 _LIT(KLogError,										"Error=%d");
       
    54 _LIT(KLogMissingParameter,							"Missing parameter '%S'");
       
    55 _LIT(KLogMissingWrapper,							"Missing wrapper for '%S'");
       
    56 _LIT(KLogNotExpectedValue,							"Not expected value");
       
    57 /*@}*/
       
    58 
       
    59 
       
    60 /**
       
    61 * Constructor. First phase construction
       
    62 */
       
    63 CT_DataGraphicsDevice::CT_DataGraphicsDevice()
       
    64 :	CT_DataGraphicsDeviceMap()
       
    65 ,	iDisplayMode(ENone)
       
    66 	{
       
    67 	}
       
    68 
       
    69 /**
       
    70 * Process a command read from the ini file
       
    71 *
       
    72 * @param aDataWrapper	test step requiring command to be processed
       
    73 * @param aCommand	the command to process
       
    74 * @param aSection		the entry in the ini file requiring the command to be processed
       
    75 *
       
    76 * @return ETrue if the command is processed
       
    77 */
       
    78 TBool CT_DataGraphicsDevice::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex)
       
    79 	{
       
    80 	TBool	ret=ETrue;
       
    81 	if ( aCommand==KCmdCreateContext )
       
    82 		{
       
    83 		DoCmdCreateContextL(aSection);
       
    84 		}
       
    85 	else if ( aCommand==KCmdDisplayMode )
       
    86 		{
       
    87 		DoCmdDisplayMode(aSection);
       
    88 		}
       
    89 	else if ( aCommand==KCmdFontHeightInTwips )
       
    90 		{
       
    91 		DoCmdFontHeightInTwips(aSection);
       
    92 		}
       
    93 	else if ( aCommand==KCmdGetPalette )
       
    94 		{
       
    95 		DoCmdGetPaletteL(aSection);
       
    96 		}
       
    97 	else if ( aCommand==KCmdNumTypefaces )
       
    98 		{
       
    99 		DoCmdNumTypefaces(aSection);
       
   100 		}
       
   101 	else if ( aCommand==KCmdPaletteAttributes )
       
   102 		{
       
   103 		DoCmdPaletteAttributes(aSection);
       
   104 		}
       
   105 	else if ( aCommand==KCmdSetPalette )
       
   106 		{
       
   107 		DoCmdSetPaletteL(aSection);
       
   108 		}
       
   109 	else if ( aCommand==KCmdSizeInPixels )
       
   110 		{
       
   111 		DoCmdSizeInPixels(aSection);
       
   112 		}
       
   113 	else if ( aCommand==KCmdSizeInTwips )
       
   114 		{
       
   115 		DoCmdSizeInTwips(aSection);
       
   116 		}
       
   117 	else if ( aCommand==KCmdTypefaceSupport )
       
   118 		{
       
   119 		DoCmdTypefaceSupport(aSection);
       
   120 		}
       
   121 	else
       
   122 		{
       
   123 		ret=CT_DataGraphicsDeviceMap::DoCommandL(aCommand, aSection, aAsyncErrorIndex);
       
   124 		}
       
   125 
       
   126 	return ret;
       
   127 	}
       
   128 
       
   129 void CT_DataGraphicsDevice::DoCmdCreateContextL(const TDesC& aSection)
       
   130 	{
       
   131 	TPtrC	wrapperName;
       
   132 	// get BitmapUtilData object from parameters
       
   133 	if ( !GetStringFromConfig(aSection, KFldContext, wrapperName) )
       
   134 		{
       
   135 		ERR_PRINTF2(KLogMissingParameter, &KFldContext());
       
   136 		SetBlockResult(EFail);
       
   137 		}
       
   138 	else
       
   139 		{
       
   140 		CDataWrapper*	wrapper=GetDataWrapperL(wrapperName);
       
   141 		if ( wrapper==NULL )
       
   142 			{
       
   143 			ERR_PRINTF2(KLogMissingWrapper, &wrapperName);
       
   144 			SetBlockResult(EFail);
       
   145 			}
       
   146 		else
       
   147 			{
       
   148 			CGraphicsContext*	context=NULL;
       
   149 			INFO_PRINTF1(_L("execute CreateContext(CGraphicsContext*&)"));
       
   150 			TInt	err=GetGraphicsDevice()->CreateContext(context);
       
   151 			if ( err!=KErrNone )
       
   152 				{
       
   153 				ERR_PRINTF2(KLogError, err);
       
   154 				SetError(err);
       
   155 				}
       
   156 			else
       
   157 				{
       
   158 				wrapper->SetObjectL(context);
       
   159 				}
       
   160 			}
       
   161 		}
       
   162 	}
       
   163 
       
   164 void CT_DataGraphicsDevice::DoCmdDisplayMode(const TDesC& aSection)
       
   165 	{
       
   166 	INFO_PRINTF1(_L("execute DisplayMode()"));
       
   167 	iDisplayMode=GetGraphicsDevice()->DisplayMode();
       
   168 	INFO_PRINTF2(_L("Display Mode %d"), iDisplayMode);
       
   169 
       
   170 	// get display mode from parameters
       
   171 	TDisplayMode	expectedValue;
       
   172 	if ( CT_GraphicsUtil::ReadDisplayMode(*this, aSection, KFldDisplayMode(), expectedValue) )
       
   173 		{
       
   174 		// check value against NULL
       
   175 		if ( iDisplayMode!=expectedValue )
       
   176 			{
       
   177 			ERR_PRINTF1(KLogNotExpectedValue);
       
   178 			SetBlockResult(EFail);
       
   179 			}
       
   180 		}
       
   181 	}
       
   182 
       
   183 void CT_DataGraphicsDevice::DoCmdFontHeightInTwips(const TDesC& aSection)
       
   184 	{
       
   185 	TBool	dataOk=ETrue;
       
   186 
       
   187 	// get typeface index from parameters
       
   188 	TInt	typefaceIndex;
       
   189 	if ( !GetIntFromConfig(aSection, KFldTypefaceIndex(), typefaceIndex) )
       
   190 		{
       
   191 		dataOk=EFalse;
       
   192 		ERR_PRINTF2(KLogMissingParameter, &KFldTypefaceIndex());
       
   193 		SetBlockResult(EFail);
       
   194 		}
       
   195 
       
   196 	// get height index from parameters
       
   197 	TInt	heightIndex;
       
   198 	if ( !GetIntFromConfig(aSection, KFldHeightIndex(), heightIndex) )
       
   199 		{
       
   200 		dataOk=EFalse;
       
   201 		ERR_PRINTF2(KLogMissingParameter, &KFldHeightIndex());
       
   202 		SetBlockResult(EFail);
       
   203 		}
       
   204 
       
   205 	if ( dataOk )
       
   206 		{
       
   207 		INFO_PRINTF1(_L("execute FontHeightInTwips(TInt, TInt)"));
       
   208 		TInt	height=GetGraphicsDevice()->FontHeightInTwips(typefaceIndex, heightIndex);
       
   209 		INFO_PRINTF2(_L("Height %d"), height);
       
   210 
       
   211 		// get positive height check flag from parameters
       
   212 		TInt	expected;
       
   213 		if ( GetIntFromConfig(aSection, KFldExpected(), expected) )
       
   214 			{
       
   215 			if ( height!=expected )
       
   216 				{
       
   217 				ERR_PRINTF1(KLogNotExpectedValue);
       
   218 				SetBlockResult(EFail);
       
   219 				}
       
   220 			}
       
   221 		}
       
   222 	}
       
   223 
       
   224 void CT_DataGraphicsDevice::DoCmdGetPaletteL(const TDesC& aSection)
       
   225 	{
       
   226 	CPalette*	pallet=NULL;
       
   227 	INFO_PRINTF1(_L("execute GetPalette(CPalette*&)"));
       
   228 	TInt	err=GetGraphicsDevice()->GetPalette(pallet);
       
   229 
       
   230 	if ( err!=KErrNone )
       
   231 		{
       
   232 		ERR_PRINTF2(KLogError, err);
       
   233 		SetError(err);
       
   234 		}
       
   235 	else
       
   236 		{
       
   237 		CPalette*	expected=NULL;
       
   238 		if ( CT_GraphicsUtil::GetPaletteL(*this, aSection, KFldPalette(), expected) )
       
   239 			{
       
   240 			if ( pallet!=expected )
       
   241 				{
       
   242 				ERR_PRINTF1(KLogNotExpectedValue);
       
   243 				SetBlockResult(EFail);
       
   244 				}
       
   245 			}
       
   246 		}
       
   247 	}
       
   248 
       
   249 void CT_DataGraphicsDevice::DoCmdNumTypefaces(const TDesC& aSection)
       
   250 	{
       
   251 	INFO_PRINTF1(_L("execute NumTypefaces()"));
       
   252 	TInt	actual=GetGraphicsDevice()->NumTypefaces();
       
   253 	INFO_PRINTF2(_L("NumTypefaces=%d"), actual);
       
   254 
       
   255 	TInt	expected;
       
   256 	if ( GetIntFromConfig(aSection, KFldExpected(), expected) )
       
   257 		{
       
   258 		if ( actual!=expected )
       
   259 			{
       
   260 			ERR_PRINTF1(KLogNotExpectedValue);
       
   261 			SetBlockResult(EFail);
       
   262 			}
       
   263 		}
       
   264 	}
       
   265 
       
   266 void CT_DataGraphicsDevice::DoCmdPaletteAttributes(const TDesC& aSection)
       
   267 	{
       
   268 	INFO_PRINTF1(_L("execute PaletteAttributes(TBool&, TInt&)"));
       
   269 	TBool	modifiable;
       
   270 	TInt	entries;
       
   271 	GetGraphicsDevice()->PaletteAttributes(modifiable, entries);
       
   272 	INFO_PRINTF2(_L("modifiable %d"), modifiable);
       
   273 	INFO_PRINTF2(_L("entries    %d"), entries);
       
   274 
       
   275 	TBool	expectedModifiable;
       
   276 	if ( GetBoolFromConfig(aSection, KFldExpectedModifiable(), expectedModifiable) )
       
   277 		{
       
   278 		if ( modifiable!=expectedModifiable )
       
   279 			{
       
   280 			ERR_PRINTF1(KLogNotExpectedValue);
       
   281 			SetBlockResult(EFail);
       
   282 			}
       
   283 		}
       
   284 
       
   285 	TInt	expectedEntries;
       
   286 	if ( GetIntFromConfig(aSection, KFldExpectedEntries(), expectedEntries) )
       
   287 		{
       
   288 		if ( entries!=expectedEntries )
       
   289 			{
       
   290 			ERR_PRINTF1(KLogNotExpectedValue);
       
   291 			SetBlockResult(EFail);
       
   292 			}
       
   293 		}
       
   294 	}
       
   295 
       
   296 void CT_DataGraphicsDevice::DoCmdSetPaletteL(const TDesC& aSection)
       
   297 	{
       
   298 	CPalette*	pallet=NULL;
       
   299 	if ( !CT_GraphicsUtil::GetPaletteL(*this, aSection, KFldPalette(), pallet) )
       
   300 		{
       
   301 		ERR_PRINTF2(KLogMissingParameter, &KFldPalette());
       
   302 		SetBlockResult(EFail);
       
   303 		}
       
   304 	else
       
   305 		{
       
   306 		INFO_PRINTF1(_L("execute SetPalette(CPalette*)"));
       
   307 		GetGraphicsDevice()->SetPalette(pallet);
       
   308 		}
       
   309 	}
       
   310 
       
   311 void CT_DataGraphicsDevice::DoCmdSizeInPixels(const TDesC& aSection)
       
   312 	{
       
   313 	INFO_PRINTF1(_L("execute SizeInPixels()"));
       
   314 	iSizeInPixels=GetGraphicsDevice()->SizeInPixels();
       
   315 	INFO_PRINTF3(_L("CGraphicsDevice::SizeInPixels() height %d, width %d"), iSizeInPixels.iHeight, iSizeInPixels.iWidth);
       
   316 	
       
   317 	TSize	expected;
       
   318 	if ( GetSizeFromConfig(aSection, KFldExpected(), expected) )
       
   319 		{
       
   320 		if ( iSizeInPixels!=expected )
       
   321 			{
       
   322 			ERR_PRINTF1(KLogNotExpectedValue);
       
   323 			SetBlockResult(EFail);
       
   324 			}
       
   325 		}
       
   326 	}
       
   327 
       
   328 void CT_DataGraphicsDevice::DoCmdSizeInTwips(const TDesC& aSection)
       
   329 	{
       
   330 	INFO_PRINTF1(_L("execute SizeInTwips()"));
       
   331 	iSizeInTwips=GetGraphicsDevice()->SizeInTwips();
       
   332 	INFO_PRINTF3(_L("CGraphicsDevice::SizeInTwips() height %d, width %d"), iSizeInTwips.iHeight, iSizeInTwips.iWidth);
       
   333 	
       
   334 	TSize	expected;
       
   335 	if ( GetSizeFromConfig(aSection, KFldExpected(), expected) )
       
   336 		{
       
   337 		if ( iSizeInTwips!=expected )
       
   338 			{
       
   339 			ERR_PRINTF1(KLogNotExpectedValue);
       
   340 			SetBlockResult(EFail);
       
   341 			}
       
   342 		}
       
   343 	}
       
   344 
       
   345 void CT_DataGraphicsDevice::DoCmdTypefaceSupport(const TDesC& aSection)
       
   346 	{
       
   347 	TBool	dataOk=ETrue;
       
   348 
       
   349 	// get typeface index from parameters
       
   350 	TInt	index;
       
   351 	if ( !GetIntFromConfig(aSection, KFldIndex(), index) )
       
   352 		{
       
   353 		dataOk=EFalse;
       
   354 		ERR_PRINTF2(KLogMissingParameter, &KFldIndex());
       
   355 		SetBlockResult(EFail);
       
   356 		}
       
   357 
       
   358 	if ( dataOk )
       
   359 		{
       
   360 		INFO_PRINTF1(_L("execute TypefaceSupport(TTypefaceSupport&, TInt)"));
       
   361 		GetGraphicsDevice()->TypefaceSupport(iTypefaceSupport, index);
       
   362 		INFO_PRINTF2(_L("iIsScalable       %d"), iTypefaceSupport.iIsScalable);
       
   363 		INFO_PRINTF2(_L("iMaxHeightInTwips %d"), iTypefaceSupport.iMaxHeightInTwips);
       
   364 		INFO_PRINTF2(_L("iMinHeightInTwips %d"), iTypefaceSupport.iMinHeightInTwips);
       
   365 		INFO_PRINTF2(_L("iNumHeights       %d"), iTypefaceSupport.iNumHeights);
       
   366 		
       
   367 		TTypefaceSupport expectedTypeface;
       
   368 		if (CT_GraphicsUtil::ReadTypefaceSupport(*this, aSection, KFldExpected(),expectedTypeface ))
       
   369 			{
       
   370 			// just check font name
       
   371 			if (expectedTypeface.iTypeface.iName!=iTypefaceSupport.iTypeface.iName )
       
   372 				{
       
   373 				ERR_PRINTF3(_L("DoCmdTypefaceSupport expected=%S actual=%S"), 
       
   374 						&expectedTypeface.iTypeface.iName,&iTypefaceSupport.iTypeface.iName);
       
   375 				SetBlockResult(EFail);
       
   376 				}
       
   377 			
       
   378 			}
       
   379 		}
       
   380 	}