First public contribution.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
19 @internalComponent - Internal Symbian test code
22 #include <test/testexecutestepbase.h>
24 #include <test/thashreferenceimages.h>
27 _LIT(KHashIDFormat, "%S_%d_%S_%S_%d");
28 const TInt KLengthOfHashValue = 256;
29 const TInt KNumOfDisplayModes = 12;
31 /* This is a list of display modes used - the parameter passed to the string
32 creation function is an index into this table
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");
62 //Uncomment the line below to save the image of the screen to a mbm file.
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
71 CTHashReferenceImages::CTHashReferenceImages(CTestStep* aStep, RFbsSession* aFbs):CBase(),iFbs(aFbs),iStep(aStep) { }
73 EXPORT_C CTHashReferenceImages* CTHashReferenceImages::NewL(CTestStep* aStep, RFbsSession* aFbs, const TDesC *aPath)
75 CTHashReferenceImages* ptr = new (ELeave)CTHashReferenceImages(aStep,aFbs);
76 CleanupStack::PushL(ptr);
77 ptr->ConstructL(aPath);
82 void CTHashReferenceImages::ConstructL(const TDesC *aPath)
84 iPath = aPath->AllocL();
88 EXPORT_C CTHashReferenceImages::~CTHashReferenceImages()
90 //nothing is owned by this class, except iPath
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
98 EXPORT_C void CTHashReferenceImages::GenerateHashAndReturnInHexFormatL(TDes &aHexString)
100 TInt bufLen = CFbsBitmap::ScanLineLength(iBitmapDevice->SizeInPixels().iWidth, iBitmapDevice->DisplayMode());
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++)
108 iBitmapDevice->GetScanLine(buff,pos,iBitmapDevice->SizeInPixels().iWidth,iBitmapDevice->DisplayMode());
112 TBuf8<KLengthOfHashValue> hashString;
113 //md will be reset after calling CMD5::Final() as Final will call Reset.
114 hashString.Copy(md->Final());
117 for(TInt icount=0; icount < hashString.Length(); icount++)
119 aHexString.AppendNumFixedWidth(hashString[icount], EHex, 4);
121 CleanupStack::PopAndDestroy(2, &buff);
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.
128 EXPORT_C void CTHashReferenceImages::CompareHashValuesL(const TDesC& aHashIndex)
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);
137 //cannot use the macro //TEST((hashFromConfig.Compare(hexString)) == 0); since iStep needs to be
139 iStep->testBooleanTrue((hashFromConfig.Compare(hexString)) == 0, (TText8*)__FILE__, __LINE__, ETrue);
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__);
148 CopyScreenToBitmapL(aHashIndex);
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__);
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
166 EXPORT_C HBufC* CTHashReferenceImages::GenerateHashIdStringLC(const TDesC& aTestCase, TInt aSubTestNumber, const TPtrC aName[], TInt aNameIndex,
167 TInt aDisplayMode, TInt aOrientation)
169 //this is here because at file scope there is uninitialised writable data
170 const TDesC * KDisplayModeNames[KNumOfDisplayModes] =
186 TBuf<KLengthOfHashValue> tempBuffer;
187 tempBuffer.Format(KHashIDFormat, &aTestCase, aSubTestNumber, &aName[aNameIndex], KDisplayModeNames[aDisplayMode], aOrientation);
188 return tempBuffer.AllocLC();
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
197 EXPORT_C void CTHashReferenceImages::CopyScreenToBitmapL(const TDesC& aHashIndex)
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);
206 User::LeaveIfError(device->CreateContext(gc));
207 gc->SetDrawMode(CGraphicsContext::EDrawModeWriteAlpha);
208 gc->BitBlt(TPoint(), iBitmap, rect);
210 mbmFile.Format(iPath->Des(), &aHashIndex);
211 bitmap->Save(mbmFile);
213 CleanupStack::PopAndDestroy(2);
217 Auxilary function used to change the referenced member data (ownership is not transferred)
219 EXPORT_C void CTHashReferenceImages::SetScreenDeviceAndBitmap(CBitmapDevice* aBitmapDevice, CFbsBitmap* aBitmap, CFbsBitGc* aGc )
221 iBitmapDevice = aBitmapDevice;