|
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". |
|
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 "graphicsscreencomparison.h" |
|
23 #include "graphicsimagecomparison.h" |
|
24 |
|
25 /** |
|
26 Creates an instance of the CTGraphicsScreenComparison class. The class is |
|
27 destroyed by a call to the class destructor when no longer required. |
|
28 |
|
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 |
|
31 |
|
32 The function will panic if the CWsScreenDevice object has not been constructed |
|
33 |
|
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. |
|
41 */ |
|
42 EXPORT_C CTGraphicsScreenComparison* CTGraphicsScreenComparison::NewL(CWsScreenDevice& aScreenDevice) |
|
43 { |
|
44 CTGraphicsScreenComparison* self = new(ELeave) CTGraphicsScreenComparison(); |
|
45 CleanupStack::PushL(self); |
|
46 self->ConstructL(aScreenDevice); |
|
47 CleanupStack::Pop(self); |
|
48 return self; |
|
49 } |
|
50 |
|
51 void CTGraphicsScreenComparison::ConstructL(CWsScreenDevice& aScreenDevice) |
|
52 { |
|
53 iScreenSize = aScreenDevice.SizeInPixels(); |
|
54 |
|
55 //Create a screen sized bitmap for use in screen comparison |
|
56 iBmp = new (ELeave) CFbsBitmap; |
|
57 |
|
58 //push the git |
|
59 User::LeaveIfError(iBmp->Create(aScreenDevice.SizeInPixels(), EColor16MU)); |
|
60 |
|
61 |
|
62 //Access the screen comparison class - render stage must be available |
|
63 iCsc = static_cast<MTestScreenCapture*> (aScreenDevice.GetInterface(MTestScreenCapture::KUidTestScreenCaptureIf)); |
|
64 if(!iCsc) |
|
65 { |
|
66 RDebug::Printf("Failed to create CTGraphicsScreenComparison, (CSC render stage may not be specified in wsini.ini?) , aborting"); |
|
67 User::Leave(0); |
|
68 } |
|
69 |
|
70 //pop the git |
|
71 |
|
72 } |
|
73 |
|
74 /** |
|
75 Compares the contents of a rectangular region of the screen with a similarly sized |
|
76 rectangular region of a reference bitmap. |
|
77 |
|
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 |
|
90 reference bitmap. |
|
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 |
|
101 */ |
|
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) |
|
107 { |
|
108 if(aRefBitmap.DisplayMode() != EColor16MU) |
|
109 { |
|
110 return KErrArgument; |
|
111 } |
|
112 |
|
113 TInt err = iCsc->ComposeScreen(*iBmp); |
|
114 if(err != KErrNone) |
|
115 { |
|
116 return err; |
|
117 } |
|
118 |
|
119 err = CTGraphicsImageComparison::CompareBitmaps(aCompareSize, |
|
120 aBitmapPoint, |
|
121 aScreenPoint, |
|
122 aRefBitmap, |
|
123 *iBmp); |
|
124 if (err != KErrNone) |
|
125 { |
|
126 TRAP_IGNORE(SaveBitmapL(*iBmp, aTestStepName)); |
|
127 } |
|
128 return err; |
|
129 } |
|
130 |
|
131 /** |
|
132 Compares the contents of a rectangular region of the screen with a reference colour. |
|
133 |
|
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 |
|
153 */ |
|
154 EXPORT_C TInt CTGraphicsScreenComparison::CompareScreenImageL(const TSize& aCompareSize, |
|
155 const TPoint& aScreenPoint, |
|
156 const TRgb& aColor, |
|
157 const TDesC& aTestStepName) |
|
158 { |
|
159 TInt err = iCsc->ComposeScreen(*iBmp); |
|
160 if(err != KErrNone) |
|
161 { |
|
162 return err; |
|
163 } |
|
164 |
|
165 err = CTGraphicsImageComparison::CompareBitmaps(aCompareSize, |
|
166 aScreenPoint, |
|
167 *iBmp, |
|
168 aColor); |
|
169 if (err != KErrNone) |
|
170 { |
|
171 TRAP_IGNORE(SaveBitmapL(*iBmp, aTestStepName)); |
|
172 } |
|
173 return err; |
|
174 } |
|
175 /** |
|
176 Returns a pointer to the underlying MTestScreenCapture class |
|
177 @return the MTestScreenCapture* pointer |
|
178 */ |
|
179 EXPORT_C MTestScreenCapture* CTGraphicsScreenComparison::GetMTestScreenCapture() const |
|
180 { |
|
181 return iCsc; |
|
182 } |
|
183 |
|
184 /** |
|
185 CTGraphicsScreenComparison class destructor. Destroys the instance of the |
|
186 CTGraphicsScreenComparison class created by a call to CTGraphicsScreenComparison::NewL() |
|
187 */ |
|
188 EXPORT_C CTGraphicsScreenComparison::~CTGraphicsScreenComparison() |
|
189 { |
|
190 delete iBmp; |
|
191 iBmp = 0; |
|
192 } |
|
193 |
|
194 CTGraphicsScreenComparison::CTGraphicsScreenComparison() |
|
195 { |
|
196 } |
|
197 |
|
198 void CTGraphicsScreenComparison::SaveBitmapL(CFbsBitmap& aBitmap, const TDesC& aTestStepName) |
|
199 { |
|
200 RBuf fileName; |
|
201 fileName.CreateL(KDir.iTypeLength + aTestStepName.Length() + KMbmSuffix.iTypeLength + KFixedNumWidth + 1); |
|
202 fileName.CleanupClosePushL(); |
|
203 |
|
204 fileName.Insert(0, KDir); |
|
205 fileName.Append(aTestStepName); |
|
206 fileName.Append('_'); |
|
207 fileName.AppendNumFixedWidth((++iSavedBitmapCounter), EDecimal, KFixedNumWidth); |
|
208 fileName.Append(KMbmSuffix); |
|
209 |
|
210 User::LeaveIfError(aBitmap.Save(fileName)); |
|
211 CleanupStack::PopAndDestroy(&fileName); |
|
212 } |