Update contrib.
1 // Copyright (c) 2007-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 "graphicsscreencomparison.h"
23 #include "graphicsimagecomparison.h"
26 Creates an instance of the CTGraphicsScreenComparison class. The class is
27 destroyed by a call to the class destructor when no longer required.
29 This function will leave if memory cannot be allocated for the class object or it's
30 construction fails. e.g. the CSC renderstage plugin is not accessible
32 The function will panic if the CWsScreenDevice object has not been constructed
34 @param aScreenDevice, a reference to a CWsScreenDevice object created for the
35 screen for which image comparison is required.
36 @pre The CSC renderstage plugin must be accessible.
37 @pre The CWsScreenDevice object must have been constructed
38 @post The CTGraphicsScreenComparison object has been created
39 @return On success, a pointer to the CTGraphicsScreenComparison object, on failure,
40 the function will leave or panic.
42 EXPORT_C CTGraphicsScreenComparison* CTGraphicsScreenComparison::NewL(CWsScreenDevice& aScreenDevice)
44 CTGraphicsScreenComparison* self = new(ELeave) CTGraphicsScreenComparison();
45 CleanupStack::PushL(self);
46 self->ConstructL(aScreenDevice);
47 CleanupStack::Pop(self);
51 void CTGraphicsScreenComparison::ConstructL(CWsScreenDevice& aScreenDevice)
53 iScreenSize = aScreenDevice.SizeInPixels();
55 //Create a screen sized bitmap for use in screen comparison
56 iBmp = new (ELeave) CFbsBitmap;
59 User::LeaveIfError(iBmp->Create(aScreenDevice.SizeInPixels(), EColor16MU));
62 //Access the screen comparison class - render stage must be available
63 iCsc = static_cast<MTestScreenCapture*> (aScreenDevice.GetInterface(MTestScreenCapture::KUidTestScreenCaptureIf));
66 RDebug::Printf("Failed to create CTGraphicsScreenComparison, (CSC render stage may not be specified in wsini.ini?) , aborting");
75 Compares the contents of a rectangular region of the screen with a similarly sized
76 rectangular region of a reference bitmap.
78 @param aCompareSize, a const reference to a TSize object denoting the size of the
79 rectangular region for comparison. Negative and zero dimensions of this argument can
80 be passed in without returning a KErrArgument error.
81 @param aScreenPoint, a const reference to a TPoint object denoting the top left
82 point of the screen rectangle for comparison.
83 @param aBitmapPoint, a const reference to a TPoint object denoting the top left
84 point of the bitmap rectangle for comparison.
85 @param aRefBitmap, a const reference to the reference CFbsBitmap for use in comparison
86 @param aTestStepName, a desciptor to identify output files in the event of a mismatch.
87 Defaults to KNullDesC.
88 @pre The aRefBitmap must have been created with mode EColor16MU.
89 @pre The rectanglular comparison region must reside wholly inside the screen and
91 @pre To enable outputting of screen snapshots in the event of a mismatch, the
92 c:\logs\testexecute\screencomparison\ folder must exist.
93 @return KErrNone if the pixels contained in the screen and bitmap rectangles are an
94 exact match or, otherwise, the count of the first unmatched pixel. Pixels are compared
95 from TRUE top-left to bottom-right in the horizontal direction (TRUE to cope with
96 negative dimensions of the aCompareSize object) An area of zero size will return
97 KErrNone so long as the pre-conditions are satisfied.
98 KErrArgument if the pre-conditions are not met.
99 @post If an mismatch has occured, a snapshot of the screen is saved in an MBM file in the
100 c:\logs\testexecute\screencomparison\ folder
102 EXPORT_C TInt CTGraphicsScreenComparison::CompareScreenImageL(const TSize& aCompareSize,
103 const TPoint& aScreenPoint,
104 const TPoint& aBitmapPoint,
105 const CFbsBitmap& aRefBitmap,
106 const TDesC& aTestStepName)
108 if(aRefBitmap.DisplayMode() != EColor16MU)
113 TInt err = iCsc->ComposeScreen(*iBmp);
119 err = CTGraphicsImageComparison::CompareBitmaps(aCompareSize,
126 TRAP_IGNORE(SaveBitmapL(*iBmp, aTestStepName));
132 Compares the contents of a rectangular region of the screen with a reference colour.
134 @param aCompareSize, a const reference to a TSize object denoting the size of the
135 rectangular region for comparison. Negative and zero dimensions of this argument can
136 be passed in without returning a KErrArgument error.
137 @param aScreenPoint, a const reference to a TPoint object denoting the top left
138 point of the screen rectangle for comparison.
139 @param aColor, the TRgb colour value to compare the region to.
140 @param aTestStepName, a desciptor to identify output files in the event of a mismatch.
141 Defaults to KNullDesC.
142 @pre The rectanglular comparison region must reside wholly inside the screen
143 @pre To enable outputting of screen snapshots in the event of a mismatch, the
144 c:\logs\testexecute\screencomparison\ folder must exist.
145 @return KErrNone if the pixels contained in the screen rectangle matches the reference
146 colour or, otherwise, the count of the first unmatched pixel. Pixels are compared
147 from TRUE top-left to bottom-right in the horizontal direction (TRUE to cope with
148 negative dimensions of the aCompareSize object) An area of zero size will return
149 KErrNone so long as the pre-conditions are satisfied.
150 KErrArgument if the pre-conditions are not met.
151 @post If an mismatch has occured, a snapshot of the screen is saved in an MBM file in the
152 c:\logs\testexecute\screencomparison\ folder
154 EXPORT_C TInt CTGraphicsScreenComparison::CompareScreenImageL(const TSize& aCompareSize,
155 const TPoint& aScreenPoint,
157 const TDesC& aTestStepName)
159 TInt err = iCsc->ComposeScreen(*iBmp);
165 err = CTGraphicsImageComparison::CompareBitmaps(aCompareSize,
171 TRAP_IGNORE(SaveBitmapL(*iBmp, aTestStepName));
176 Returns a pointer to the underlying MTestScreenCapture class
177 @return the MTestScreenCapture* pointer
179 EXPORT_C MTestScreenCapture* CTGraphicsScreenComparison::GetMTestScreenCapture() const
185 CTGraphicsScreenComparison class destructor. Destroys the instance of the
186 CTGraphicsScreenComparison class created by a call to CTGraphicsScreenComparison::NewL()
188 EXPORT_C CTGraphicsScreenComparison::~CTGraphicsScreenComparison()
194 CTGraphicsScreenComparison::CTGraphicsScreenComparison()
198 void CTGraphicsScreenComparison::SaveBitmapL(CFbsBitmap& aBitmap, const TDesC& aTestStepName)
201 fileName.CreateL(KDir.iTypeLength + aTestStepName.Length() + KMbmSuffix.iTypeLength + KFixedNumWidth + 1);
202 fileName.CleanupClosePushL();
204 fileName.Insert(0, KDir);
205 fileName.Append(aTestStepName);
206 fileName.Append('_');
207 fileName.AppendNumFixedWidth((++iSavedBitmapCounter), EDecimal, KFixedNumWidth);
208 fileName.Append(KMbmSuffix);
210 User::LeaveIfError(aBitmap.Save(fileName));
211 CleanupStack::PopAndDestroy(&fileName);