graphicstest/graphicstestharness/src/thashreferenceimages.cpp
changeset 0 5d03bc08d59c
child 70 5e51caaeeb72
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @test
       
    19  @internalComponent - Internal Symbian test code
       
    20 */
       
    21 
       
    22 #include <test/testexecutestepbase.h>
       
    23 #include <openfont.h>
       
    24 #include <test/thashreferenceimages.h>
       
    25 #include <hash.h>
       
    26 
       
    27 _LIT(KHashIDFormat, "%S_%d_%S_%S_%d");
       
    28 const TInt KLengthOfHashValue = 256;
       
    29 const TInt KNumOfDisplayModes = 12;
       
    30 
       
    31 /* This is a list of display modes used - the parameter passed to the string 
       
    32    creation function is an index into this table
       
    33  
       
    34  	EGray2,
       
    35 	EGray4,
       
    36 	EGray16,
       
    37 	EGray256,
       
    38 	EColor16,
       
    39 	EColor256,
       
    40 	EColor64K,
       
    41 	EColor16M,
       
    42 	EColor4K,
       
    43 	EColor16MU,
       
    44 	EColor16MA,
       
    45 	EColor16MAP
       
    46 	
       
    47    */
       
    48 
       
    49 _LIT(KMode0,"EGray2");
       
    50 _LIT(KMode1,"EGray4");
       
    51 _LIT(KMode2,"EGray16");
       
    52 _LIT(KMode3,"EGray256");
       
    53 _LIT(KMode4,"EColor16");
       
    54 _LIT(KMode5,"EColor256");
       
    55 _LIT(KMode6,"EColor64K");
       
    56 _LIT(KMode7,"EColor16M");
       
    57 _LIT(KMode8,"EColor4K");
       
    58 _LIT(KMode9,"EColor16MU");
       
    59 _LIT(KMode10,"EColor16MA");
       
    60 _LIT(KMode11,"EColor16MAP");
       
    61 
       
    62 //Uncomment the line below to save the image of the screen to a mbm file.
       
    63 //#define SAVEBITMAP
       
    64 
       
    65 //Note: To updated existing hash values in toutlineandshadow.ini, you need to delete the previous entries along with hashid's in toutlineandshadow.ini and export this ini
       
    66 //If a existing test case need updating that will change the hash value, then the hash for this test case needs to be removed from the .ini file 
       
    67 //Uncomment the line below to add a new hash value for any test cases that do not already have a hash.
       
    68 //#define APPEND_NEW_OR_MISSING_HASH_DATA
       
    69 
       
    70 // Constructor
       
    71 CTHashReferenceImages::CTHashReferenceImages(CTestStep* aStep, RFbsSession* aFbs):CBase(),iFbs(aFbs),iStep(aStep) { }
       
    72 
       
    73 EXPORT_C CTHashReferenceImages* CTHashReferenceImages::NewL(CTestStep* aStep, RFbsSession* aFbs, const TDesC *aPath)
       
    74 	{
       
    75 	CTHashReferenceImages* ptr = new (ELeave)CTHashReferenceImages(aStep,aFbs);
       
    76 	CleanupStack::PushL(ptr);
       
    77 	ptr->ConstructL(aPath);
       
    78 	CleanupStack::Pop();
       
    79 	return ptr;
       
    80 	}
       
    81 
       
    82 void CTHashReferenceImages::ConstructL(const TDesC *aPath)
       
    83 	{
       
    84 	iPath = aPath->AllocL();
       
    85 	}
       
    86 
       
    87 // Destructor
       
    88 EXPORT_C CTHashReferenceImages::~CTHashReferenceImages()
       
    89 	{
       
    90 	//nothing is owned by this class, except iPath
       
    91 	delete iPath;
       
    92 	}
       
    93 
       
    94 /**
       
    95 Auxilary function should be called only when we need to generate hash values from the screen and returns its hex format.
       
    96 @param aHexString the output MD5 hash hex string obtained from iBitmapDevice
       
    97 */
       
    98 EXPORT_C void CTHashReferenceImages::GenerateHashAndReturnInHexFormatL(TDes &aHexString)
       
    99 	{
       
   100 	TInt bufLen = CFbsBitmap::ScanLineLength(iBitmapDevice->SizeInPixels().iWidth, iBitmapDevice->DisplayMode());
       
   101 	RBuf8 buff;
       
   102 	buff.CreateL(bufLen);
       
   103 	CleanupClosePushL(buff);	
       
   104 	CMD5 *md = CMD5::NewL();
       
   105 	CleanupStack::PushL(md);
       
   106 	for (TPoint pos(0, 0); pos.iY < iBitmapDevice->SizeInPixels().iHeight; pos.iY++)
       
   107 		{
       
   108 		iBitmapDevice->GetScanLine(buff,pos,iBitmapDevice->SizeInPixels().iWidth,iBitmapDevice->DisplayMode());
       
   109 		md->Update(buff);
       
   110 		}
       
   111 
       
   112 	TBuf8<KLengthOfHashValue> hashString;
       
   113 	//md will be reset after calling CMD5::Final() as Final will call Reset.
       
   114 	hashString.Copy(md->Final());
       
   115 	aHexString.Zero();
       
   116 
       
   117 	for(TInt icount=0; icount < hashString.Length(); icount++)
       
   118 		{
       
   119 		aHexString.AppendNumFixedWidth(hashString[icount], EHex, 4);
       
   120 		}
       
   121 	CleanupStack::PopAndDestroy(2, &buff);
       
   122 	}
       
   123 
       
   124 /**
       
   125 Auxilary function called to compare generated hash with reference hash and report error if they don't match.
       
   126 @param aHashIndex holds the hashId.
       
   127 */
       
   128 EXPORT_C void CTHashReferenceImages::CompareHashValuesL(const TDesC& aHashIndex)
       
   129 	{
       
   130 	TBuf<KLengthOfHashValue>  hexString;
       
   131 	//Gets the hash value for the current drawings
       
   132 	GenerateHashAndReturnInHexFormatL(hexString);
       
   133 	TPtrC hashFromConfig;
       
   134 	TBool stringFound = iStep->GetStringFromConfig(iStep->ConfigSection(), aHashIndex, hashFromConfig);
       
   135 	if (stringFound)
       
   136 		{
       
   137 		//cannot use the macro //TEST((hashFromConfig.Compare(hexString)) == 0); since iStep needs to be 
       
   138 		//referenced
       
   139 		iStep->testBooleanTrue((hashFromConfig.Compare(hexString)) == 0, (TText8*)__FILE__, __LINE__);
       
   140 		}
       
   141 	else
       
   142 		{
       
   143 #ifdef APPEND_NEW_OR_MISSING_HASH_DATA
       
   144 		//Hash data will be written to ini file if hash id is not found.
       
   145 		//If written the status will be as INI WRITE with the new hash id and value in test log file.
       
   146 		iStep->testBooleanTrue(iStep->WriteStringToConfig(iStep->ConfigSection(), aHashIndex, hexString), (TText8*)__FILE__, __LINE__);
       
   147 #ifdef SAVEBITMAP
       
   148 		CopyScreenToBitmapL(aHashIndex);
       
   149 #endif
       
   150 #else
       
   151 		//Report error in case hash data is missing and APPEND_NEW_OR_MISSING_HASH_DATA is not defined
       
   152 		iStep->testBooleanTrue( 0, (TText8*)__FILE__, __LINE__);
       
   153 #endif
       
   154 		}
       
   155 	}
       
   156 
       
   157 /**
       
   158 Auxilary function called to generate Hash ID String based on the parameters (test case ID, subtest etc...) and returns
       
   159 HashId looks like:Testcasecame_0010_9_Swiss_EGray2_0 (aTestCase = DrawText_0010 or DrawTextVertical_0010, aSubTestNumber = 9, aFontFaceIndex = Swiss, aDisplayMode = EGray2, aOrientation = 0)
       
   160 @param aTestCase holds the testcase ID
       
   161 @param aSubTestNumber holds the subtest number
       
   162 @param aFontFaceIndex holds the font face index (index used in KFontFace[])
       
   163 @param aDisplayMode holds the display mode
       
   164 @param aOrientation holds the orientation number
       
   165 */
       
   166 EXPORT_C HBufC* CTHashReferenceImages::GenerateHashIdStringLC(const TDesC& aTestCase, TInt aSubTestNumber, const TPtrC aName[], TInt aNameIndex,
       
   167 												TInt aDisplayMode, TInt aOrientation)
       
   168 	{
       
   169 	//this is here because at file scope there is uninitialised writable data
       
   170 	const TDesC * KDisplayModeNames[KNumOfDisplayModes] = 
       
   171 		{
       
   172 		&KMode0,
       
   173 		&KMode1,
       
   174 		&KMode2,
       
   175 		&KMode3,
       
   176 		&KMode4,
       
   177 		&KMode5,
       
   178 		&KMode6,
       
   179 		&KMode7,
       
   180 		&KMode8,
       
   181 		&KMode9,
       
   182 		&KMode10,
       
   183 		&KMode11,
       
   184 		};	
       
   185 	
       
   186 	TBuf<KLengthOfHashValue> tempBuffer;
       
   187 	tempBuffer.Format(KHashIDFormat, &aTestCase, aSubTestNumber, &aName[aNameIndex], KDisplayModeNames[aDisplayMode], aOrientation);
       
   188 	return tempBuffer.AllocLC();
       
   189 	}
       
   190 
       
   191 
       
   192 
       
   193 /**
       
   194 Auxilary function called to Copy the screen to bitmap (mbm) file.
       
   195 @param aHashIndex contains hashID. Bitmap is created with the aHashIndex as name
       
   196 */
       
   197 EXPORT_C void CTHashReferenceImages::CopyScreenToBitmapL(const TDesC& aHashIndex)
       
   198 	{
       
   199 	CFbsBitmap *bitmap = new(ELeave)CFbsBitmap();
       
   200 	CleanupStack::PushL(bitmap);
       
   201 	User::LeaveIfError(bitmap->Create(iBitmapDevice->SizeInPixels(), iBitmapDevice->DisplayMode()));
       
   202 	TRect rect = TRect(iBitmapDevice->SizeInPixels());
       
   203 	CFbsBitmapDevice *device=CFbsBitmapDevice::NewL(bitmap);
       
   204 	CleanupStack::PushL(device);
       
   205 	CFbsBitGc *gc;
       
   206 	User::LeaveIfError(device->CreateContext(gc));
       
   207 	gc->BitBlt(TPoint(), iBitmap, rect);
       
   208 	TFileName mbmFile;
       
   209 	mbmFile.Format(iPath->Des(), &aHashIndex);
       
   210 	bitmap->Save(mbmFile);
       
   211 	delete gc;
       
   212 	CleanupStack::PopAndDestroy(2);
       
   213 	}
       
   214 
       
   215 /* 
       
   216 Auxilary function used to change the referenced member data (ownership is not transferred)
       
   217 */
       
   218 EXPORT_C void CTHashReferenceImages::SetScreenDeviceAndBitmap(CBitmapDevice* aBitmapDevice, CFbsBitmap* aBitmap, CFbsBitGc* aGc )
       
   219 	{
       
   220 	iBitmapDevice = aBitmapDevice;
       
   221 	iBitmap = aBitmap;
       
   222 	iGc = aGc;
       
   223 	}