graphicsapitest/graphicssvs/gdi/src/T_DataMeasureTextInput.cpp
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     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 "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-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_DataMeasureTextInput
       
    23 */
       
    24 
       
    25 #include "T_DataMeasureTextInput.h"
       
    26 
       
    27 
       
    28 /*@{*/
       
    29 ///	Parameters
       
    30 _LIT(KValue,									"value");
       
    31 _LIT(KFlag,										"flag%d");
       
    32 
       
    33 ///	CFont::TMeasureTextInput::TFlags
       
    34 _LIT(KEFVisualOrder,							"EFVisualOrder");
       
    35 _LIT(KEFVisualOrderRightToLeft,					"EFVisualOrderRightToLeft");
       
    36 _LIT(KEFIncludePenPositionInBoundsCheck,		"EFIncludePenPositionInBoundsCheck");
       
    37 
       
    38 ///	Commands
       
    39 _LIT(KCmdNew,									"new");
       
    40 _LIT(KCmdDestructor,							"~");
       
    41 _LIT(KCmdSetCharJustExcess,						"iCharJustExcess");
       
    42 _LIT(KCmdSetCharJustNum,						"iCharJustNum");
       
    43 _LIT(KCmdSetDirection,							"iDirection");
       
    44 _LIT(KCmdSetEndInputChar,						"iEndInputChar");
       
    45 _LIT(KCmdSetFlags,								"iFlags");
       
    46 _LIT(KCmdSetMaxAdvance,							"iMaxAdvance");
       
    47 _LIT(KCmdSetMaxBounds,							"iMaxBounds");
       
    48 _LIT(KCmdSetStartInputChar,						"iStartInputChar");
       
    49 _LIT(KCmdSetWordJustExcess,						"iWordJustExcess");
       
    50 _LIT(KCmdSetWordJustNum,						"iWordJustNum");
       
    51 /*@}*/
       
    52 
       
    53 
       
    54 /**
       
    55 * Two phase constructor
       
    56 */
       
    57 CT_DataMeasureTextInput* CT_DataMeasureTextInput::NewL()
       
    58 	{
       
    59 	CT_DataMeasureTextInput* ret = new (ELeave) CT_DataMeasureTextInput();
       
    60 	CleanupStack::PushL(ret);
       
    61 	ret->ConstructL();
       
    62 	CleanupStack::Pop(ret);
       
    63 	return ret;
       
    64 	}
       
    65 
       
    66 
       
    67 /**
       
    68 * Protected constructor. First phase construction
       
    69 */
       
    70 CT_DataMeasureTextInput::CT_DataMeasureTextInput()
       
    71 :	CDataWrapperBase()
       
    72 ,	iMeasureTextInput(NULL)
       
    73 	{
       
    74 	}
       
    75 
       
    76 
       
    77 /**
       
    78 * Protected second phase construction
       
    79 */
       
    80 void CT_DataMeasureTextInput::ConstructL()
       
    81 	{
       
    82 	}
       
    83 
       
    84 
       
    85 /**
       
    86 * Destructor.
       
    87 */
       
    88 CT_DataMeasureTextInput::~CT_DataMeasureTextInput()
       
    89 	{
       
    90 	DestroyData();
       
    91 	}
       
    92 
       
    93 
       
    94 /**
       
    95 * cleanup implementation.
       
    96 */
       
    97 void CT_DataMeasureTextInput::DestroyData()
       
    98 	{
       
    99 	delete iMeasureTextInput;
       
   100 	iMeasureTextInput = NULL;
       
   101 	}
       
   102 
       
   103 
       
   104 /**
       
   105 * Return a pointer to the object that the data wraps
       
   106 *
       
   107 * @return pointer to the object that the data wraps
       
   108 */
       
   109 TAny* CT_DataMeasureTextInput::GetObject()
       
   110 	{
       
   111 	return iMeasureTextInput;
       
   112 	}
       
   113 
       
   114 
       
   115 /**
       
   116 * Process a command read from the ini file
       
   117 *
       
   118 * @param aDataWrapper	test step requiring command to be processed
       
   119 * @param aCommand	the command to process
       
   120 * @param aSection		the entry in the ini file requiring the command to be processed
       
   121 *
       
   122 * @return ETrue if the command is processed
       
   123 */
       
   124 TBool CT_DataMeasureTextInput::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/)
       
   125 	{
       
   126 	TBool retVal = ETrue;
       
   127 
       
   128 	if (aCommand == KCmdNew)
       
   129 		{
       
   130 		DoCmdNew();
       
   131 		}
       
   132 	else if (aCommand == KCmdDestructor)
       
   133 		{
       
   134 		DoCmdDestructor();
       
   135 		}
       
   136 	else if (aCommand == KCmdSetCharJustExcess)
       
   137 		{
       
   138 		DoCmdSetCharJustExcess(aSection);
       
   139 		}
       
   140 	else if (aCommand == KCmdSetCharJustNum)
       
   141 		{
       
   142 		DoCmdSetCharJustNum(aSection);
       
   143 		}
       
   144 	else if (aCommand == KCmdSetDirection)
       
   145 		{
       
   146 		DoCmdSetDirection(aSection);
       
   147 		}
       
   148 	else if (aCommand == KCmdSetEndInputChar)
       
   149 		{
       
   150 		DoCmdSetEndInputChar(aSection);
       
   151 		}
       
   152 	else if (aCommand == KCmdSetFlags)
       
   153 		{
       
   154 		DoCmdSetFlags(aSection);
       
   155 		}
       
   156 	else if (aCommand == KCmdSetMaxAdvance)
       
   157 		{
       
   158 		DoCmdSetMaxAdvance(aSection);
       
   159 		}
       
   160 	else if (aCommand == KCmdSetMaxBounds)
       
   161 		{
       
   162 		DoCmdSetMaxBounds(aSection);
       
   163 		}
       
   164 	else if (aCommand == KCmdSetStartInputChar)
       
   165 		{
       
   166 		DoCmdSetStartInputChar(aSection);
       
   167 		}
       
   168 	else if (aCommand == KCmdSetWordJustExcess)
       
   169 		{
       
   170 		DoCmdSetWordJustExcess(aSection);
       
   171 		}
       
   172 	else if (aCommand == KCmdSetWordJustNum)
       
   173 		{
       
   174 		DoCmdSetWordJustNum(aSection);
       
   175 		}
       
   176 	else
       
   177 		{
       
   178 		retVal=EFalse;
       
   179 		}
       
   180 
       
   181 	return retVal;
       
   182 	}
       
   183 
       
   184 
       
   185 ////////////////// COMMANDS IMPLEMENTATION  ////////////////////////
       
   186 
       
   187 /** Creates an instance of TMeasureTextInput structure */
       
   188 void CT_DataMeasureTextInput::DoCmdNew()
       
   189 	{
       
   190 	INFO_PRINTF1(_L("Creates an instance of TMeasureTextInput structure"));
       
   191 
       
   192 	// cleanup if any
       
   193 	delete iMeasureTextInput;
       
   194 	iMeasureTextInput = NULL;
       
   195 
       
   196 	// call new operator
       
   197 	TRAPD(err, iMeasureTextInput = new (ELeave) CFont::TMeasureTextInput());
       
   198 
       
   199 	// check error code
       
   200 	if (err != KErrNone)
       
   201 		{
       
   202 		ERR_PRINTF2(_L("Error creating an instance: %d"), err);
       
   203 		SetError(err);
       
   204 		}
       
   205 	}
       
   206 
       
   207 
       
   208 /** Destructor */
       
   209 void CT_DataMeasureTextInput::DoCmdDestructor()
       
   210 	{
       
   211 	DestroyData();
       
   212 	}
       
   213 
       
   214 /** Sets TMeasureTextInputData::iStartInputChar */
       
   215 void CT_DataMeasureTextInput::DoCmdSetStartInputChar(const TDesC& aSection)
       
   216 	{
       
   217 	INFO_PRINTF1(_L("Sets TMeasureTextInputData::iStartInputChar"));
       
   218 
       
   219 	// get value from parameters
       
   220 	TInt	value;
       
   221 	if (GetValueFromConfig(aSection, value))
       
   222 		{
       
   223 		iMeasureTextInput->iStartInputChar = value;
       
   224 		}
       
   225 	}
       
   226 
       
   227 
       
   228 /** Sets TMeasureTextInputData::iEndInputChar */
       
   229 void CT_DataMeasureTextInput::DoCmdSetEndInputChar(const TDesC& aSection)
       
   230 	{
       
   231 	INFO_PRINTF2(_L("Sets TMeasureTextInputData::iEndInputChar %S"), &aSection);
       
   232 
       
   233 	// get value from parameters
       
   234 	TInt	value;
       
   235 	if (GetValueFromConfig(aSection, value))
       
   236 		{
       
   237 		iMeasureTextInput->iEndInputChar = value;
       
   238 		}
       
   239 	}
       
   240 
       
   241 
       
   242 /** Sets TMeasureTextInputData::iDirection */
       
   243 void CT_DataMeasureTextInput::DoCmdSetDirection(const TDesC& aSection)
       
   244 	{
       
   245 	INFO_PRINTF1(_L("Sets TMeasureTextInputData::iDirection"));
       
   246 
       
   247 	// get value from parameters
       
   248 	TInt	value;
       
   249 	if (GetValueFromConfig(aSection, value))
       
   250 		{
       
   251 		iMeasureTextInput->iDirection = value;
       
   252 		}
       
   253 	}
       
   254 
       
   255 
       
   256 /** Sets TMeasureTextInputData::iFlags */
       
   257 void CT_DataMeasureTextInput::DoCmdSetFlags(const TDesC& aSection)
       
   258 	{
       
   259 	INFO_PRINTF1(_L("Sets TMeasureTextInputData::iFlags"));
       
   260 
       
   261 	// get value from parameters
       
   262 	if ( !ReadFlags(aSection, iMeasureTextInput->iFlags) )
       
   263 		{
       
   264 		ERR_PRINTF2(_L("No %S"), &aSection);
       
   265 		SetBlockResult(EFail);
       
   266 		}
       
   267 	}
       
   268 
       
   269 
       
   270 /** Sets TMeasureTextInputData::iMaxAdvance */
       
   271 void CT_DataMeasureTextInput::DoCmdSetMaxAdvance(const TDesC& aSection)
       
   272 	{
       
   273 	INFO_PRINTF1(_L("Sets TMeasureTextInputData::iMaxAdvance"));
       
   274 
       
   275 	// get value from parameters
       
   276 	TInt	value;
       
   277 	if (GetValueFromConfig(aSection, value))
       
   278 		{
       
   279 		iMeasureTextInput->iMaxAdvance = value;
       
   280 		}
       
   281 	}
       
   282 
       
   283 
       
   284 /** Sets TMeasureTextInputData::iMaxBounds */
       
   285 void CT_DataMeasureTextInput::DoCmdSetMaxBounds(const TDesC& aSection)
       
   286 	{
       
   287 	INFO_PRINTF1(_L("Sets TMeasureTextInputData::iMaxBounds"));
       
   288 
       
   289 	// get value from parameters
       
   290 	TInt	value;
       
   291 	if (GetValueFromConfig(aSection, value))
       
   292 		{
       
   293 		iMeasureTextInput->iMaxBounds = value;
       
   294 		}
       
   295 	}
       
   296 
       
   297 
       
   298 /** Sets TMeasureTextInputData::iCharJustNum */
       
   299 void CT_DataMeasureTextInput::DoCmdSetCharJustNum(const TDesC& aSection)
       
   300 	{
       
   301 	INFO_PRINTF1(_L("Sets TMeasureTextInputData::iCharJustNum"));
       
   302 
       
   303 	// get value from parameters
       
   304 	TInt	value;
       
   305 	if (GetValueFromConfig(aSection, value))
       
   306 		{
       
   307 		iMeasureTextInput->iCharJustNum = value;
       
   308 		}
       
   309 	}
       
   310 
       
   311 
       
   312 /** Sets TMeasureTextInputData::iCharJustExcess */
       
   313 void CT_DataMeasureTextInput::DoCmdSetCharJustExcess(const TDesC& aSection)
       
   314 	{
       
   315 	INFO_PRINTF1(_L("Sets TMeasureTextInputData::iCharJustExcess"));
       
   316 
       
   317 	// get value from parameters
       
   318 	TInt	value;
       
   319 	if (GetValueFromConfig(aSection, value))
       
   320 		{
       
   321 		iMeasureTextInput->iCharJustExcess = value;
       
   322 		}
       
   323 	}
       
   324 
       
   325 
       
   326 /** Sets TMeasureTextInputData::iWordJustNum */
       
   327 void CT_DataMeasureTextInput::DoCmdSetWordJustNum(const TDesC& aSection)
       
   328 	{
       
   329 	INFO_PRINTF1(_L("Sets TMeasureTextInputData::iWordJustNum"));
       
   330 
       
   331 	// get value from parameters
       
   332 	TInt	value;
       
   333 	if (GetValueFromConfig(aSection, value))
       
   334 		{
       
   335 		iMeasureTextInput->iWordJustNum = value;
       
   336 		}
       
   337 	}
       
   338 
       
   339 
       
   340 /** Sets TMeasureTextInputData::iWordJustExcess */
       
   341 void CT_DataMeasureTextInput::DoCmdSetWordJustExcess(const TDesC& aSection)
       
   342 	{
       
   343 	INFO_PRINTF1(_L("Sets TMeasureTextInputData::iWordJustExcess"));
       
   344 
       
   345 	// get value from parameters
       
   346 	TInt	value;
       
   347 	if (GetValueFromConfig(aSection, value))
       
   348 		{
       
   349 		iMeasureTextInput->iWordJustExcess = value;
       
   350 		}
       
   351 	}
       
   352 
       
   353 
       
   354 ///////////////////////////////// UTIL METHODS //////////////////////////////////////
       
   355 
       
   356 
       
   357 /**
       
   358 * Utility method that fetches a int value from parameters
       
   359 */
       
   360 TBool CT_DataMeasureTextInput::GetValueFromConfig(const TDesC& aSection, TInt& aValue)
       
   361 	{
       
   362 	TBool	ret=GetIntFromConfig(aSection, KValue(), aValue);
       
   363 	if ( !ret )
       
   364 		{
       
   365 		ERR_PRINTF2(_L("No %S"), &KValue());
       
   366 		SetBlockResult(EFail);
       
   367 		}
       
   368 
       
   369 	return ret;
       
   370 	}
       
   371 
       
   372 /**
       
   373  ReadFlags - read in bitwise measeure text input flags
       
   374  @internalComponent
       
   375  @param aSection - main entry in .ini file
       
   376  @param aFlags - bitwise flags output
       
   377  @return ETrue if data is valid in the ini file
       
   378  @pre None
       
   379  @post 2nd stage construction complete
       
   380 */
       
   381 TBool CT_DataMeasureTextInput::ReadFlags(const TDesC& aSection, TUint16& aFlags)
       
   382 	{
       
   383 	TBuf<KMaxTestExecuteCommandLength>	tempStore;
       
   384 	TInt								index=0;
       
   385 	TBool								moreData=ETrue;
       
   386 	TPtrC								flagString;
       
   387 	TBool								ret=ETrue;
       
   388 
       
   389 	aFlags=0;
       
   390 	while ( moreData && ret )
       
   391 		{
       
   392 		tempStore.Format(KFlag(), &aSection, ++index);
       
   393 		if ( GetStringFromConfig(aSection, tempStore, flagString) )
       
   394 			{
       
   395 			TInt	flag=0;
       
   396 
       
   397 			if ( flagString==KEFVisualOrder )
       
   398 				{
       
   399 				flag=CFont::TMeasureTextInput::EFVisualOrder;
       
   400 				}
       
   401 			else if ( flagString==KEFVisualOrderRightToLeft )
       
   402 				{
       
   403 				flag=CFont::TMeasureTextInput::EFVisualOrderRightToLeft;
       
   404 				}
       
   405 			else if ( flagString==KEFIncludePenPositionInBoundsCheck )
       
   406 				{
       
   407 				flag=CFont::TMeasureTextInput::EFIncludePenPositionInBoundsCheck;
       
   408 				}
       
   409 			else
       
   410 				{
       
   411 				ret=GetIntFromConfig(aSection, tempStore, flag);
       
   412 				}
       
   413 
       
   414 			if ( ret )
       
   415 				{
       
   416 				aFlags |= flag;
       
   417 				}
       
   418 			}
       
   419 		else
       
   420 			{
       
   421 			moreData=EFalse;
       
   422 			}
       
   423 		}
       
   424 
       
   425 	return ret;
       
   426 	}