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