|
1 // Copyright (c) 1996-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 // TFADECOUNT.CPP |
|
15 // Testing counted or absolute fade |
|
16 // |
|
17 // |
|
18 |
|
19 #include <e32std.h> |
|
20 #include "W32STD.H" |
|
21 #include <e32svr.h> |
|
22 #include "../tlib/testbase.h" |
|
23 |
|
24 const TInt ETestFailed = 1; |
|
25 |
|
26 class CFadeCountClient; |
|
27 |
|
28 class CFadeCountWindow : public CTTitledWindow |
|
29 { |
|
30 public: |
|
31 CFadeCountWindow(CFadeCountClient* aClient); |
|
32 ~CFadeCountWindow(); |
|
33 void ConstructL(CTWinBase &aParent); |
|
34 void Draw(); |
|
35 void SetWindowSize(); |
|
36 void WinKeyL(const TKeyEvent &aKey,const TTime& aTime); |
|
37 public: |
|
38 CFadeCountClient* iClient; |
|
39 TBool iAbsoluteFading; |
|
40 TBool iPass; |
|
41 TBool iComplete; |
|
42 }; |
|
43 |
|
44 |
|
45 class CFadeCountClient : public CTClient |
|
46 { |
|
47 public: |
|
48 CFadeCountClient(); |
|
49 ~CFadeCountClient(); |
|
50 void ConstructL(); |
|
51 void KeyL(const TKeyEvent &aKey,const TTime &aTime); |
|
52 void Exit(); |
|
53 void TestL(); |
|
54 void TestL(TInt aCondition); |
|
55 void CreateTestWindowsL(CTWinBase &aParent); |
|
56 TBool IsAbsoluteFadingOnL(); |
|
57 void TestFadeL(CTWin* aWin, TBool aAbs, TBool aCounted); |
|
58 private: |
|
59 TInt iNum; |
|
60 CFadeCountWindow *iFadeCountWin; |
|
61 CTWin* iWin1; |
|
62 CTWin* iWin2; |
|
63 TBool iAbsoluteFading; |
|
64 }; |
|
65 |
|
66 |
|
67 // |
|
68 // Individual window sub-classes |
|
69 // |
|
70 |
|
71 CFadeCountWindow::CFadeCountWindow(CFadeCountClient* aClient) |
|
72 : CTTitledWindow(), iClient(aClient) |
|
73 { |
|
74 } |
|
75 |
|
76 CFadeCountWindow::~CFadeCountWindow() |
|
77 { |
|
78 } |
|
79 |
|
80 void CFadeCountWindow::ConstructL(CTWinBase &aParent) |
|
81 { |
|
82 CTTitledWindow::ConstructL(aParent); |
|
83 SetWindowSize(); |
|
84 TSize screenSize=Client()->iScreen->SizeInPixels(); |
|
85 TSize dif(screenSize-Size()); |
|
86 iWin.SetPosition(TPoint(dif.iWidth/2,dif.iHeight/2)); |
|
87 |
|
88 Invalidate(); |
|
89 } |
|
90 |
|
91 void CFadeCountWindow::Draw() |
|
92 { |
|
93 CTTitledWindow::Draw(); |
|
94 TInt lineSpacing = iFont->AscentInPixels()+3; |
|
95 TPoint pos(3,iTitleHeight+lineSpacing); |
|
96 iGc->DrawText(_L("Fade count tests"),pos); |
|
97 |
|
98 pos.iY += lineSpacing; |
|
99 if (iAbsoluteFading) |
|
100 iGc->DrawText(_L("ABSOLUTEFADING is ON"),pos); |
|
101 else |
|
102 iGc->DrawText(_L("ABSOLUTEFADING is OFF"),pos); |
|
103 |
|
104 if (iComplete) |
|
105 { |
|
106 pos.iY += lineSpacing; |
|
107 if (iPass) |
|
108 iGc->DrawText(_L("Tests have passed"),pos); |
|
109 else |
|
110 iGc->DrawText(_L("Tests have failed"),pos); |
|
111 |
|
112 pos.iY += lineSpacing; |
|
113 iGc->DrawText(_L("Press any key to exit"),pos); |
|
114 } |
|
115 } |
|
116 |
|
117 void CFadeCountWindow::SetWindowSize() |
|
118 { |
|
119 TSize size(400,200); |
|
120 SetSize(size); |
|
121 } |
|
122 |
|
123 void CFadeCountWindow::WinKeyL(const TKeyEvent &/*aKey*/,const TTime& ) |
|
124 { |
|
125 iClient->Exit(); |
|
126 } |
|
127 |
|
128 |
|
129 // |
|
130 // End of CFadeCountWindow class // |
|
131 // |
|
132 |
|
133 |
|
134 CFadeCountClient::CFadeCountClient() |
|
135 { |
|
136 } |
|
137 |
|
138 CFadeCountClient::~CFadeCountClient() |
|
139 { |
|
140 delete iWin2; |
|
141 delete iWin1; |
|
142 delete iFadeCountWin; |
|
143 } |
|
144 |
|
145 void CFadeCountClient::ConstructL() |
|
146 { |
|
147 CTClient::ConstructL(); |
|
148 |
|
149 iGroup=new(ELeave) CTWindowGroup(this); |
|
150 iGroup->ConstructL(); |
|
151 |
|
152 CreateTestWindowsL(*iGroup); |
|
153 |
|
154 iFadeCountWin=new(ELeave) CFadeCountWindow(this); |
|
155 iFadeCountWin->iAbsoluteFading = iAbsoluteFading; |
|
156 iFadeCountWin->ConstructL(*iGroup); |
|
157 iFadeCountWin->Activate(); |
|
158 iFadeCountWin->AssignGC(*iGc); |
|
159 iGroup->SetCurrentWindow(iGroup->Child()); |
|
160 |
|
161 TRAP_IGNORE(TestL()); |
|
162 iFadeCountWin->iComplete = ETrue; |
|
163 } |
|
164 |
|
165 void CFadeCountClient::Exit() |
|
166 { |
|
167 CActiveScheduler::Stop(); |
|
168 } |
|
169 |
|
170 void CFadeCountClient::TestL() |
|
171 { |
|
172 // start condition - after absolute fade has been established |
|
173 TestFadeL(iWin1, EFalse, EFalse); |
|
174 TestFadeL(iWin2, EFalse, EFalse); |
|
175 TestFadeL(iFadeCountWin, EFalse, EFalse); |
|
176 |
|
177 // System fade and repeated fade |
|
178 // positive fade |
|
179 TInt ii; |
|
180 const TInt KFadeRepeat = 4; |
|
181 for (ii=0; ii<KFadeRepeat; ii++) |
|
182 { |
|
183 iWs.SetSystemFaded(ETrue); |
|
184 TestFadeL(iWin1, ETrue, ETrue); |
|
185 TestFadeL(iWin2, ETrue, ETrue); |
|
186 TestFadeL(iFadeCountWin, ETrue, ETrue); |
|
187 } |
|
188 |
|
189 for (ii=KFadeRepeat-1; ii>=0; ii--) |
|
190 { |
|
191 iWs.SetSystemFaded(EFalse); |
|
192 TestFadeL(iWin1, EFalse, ii); |
|
193 TestFadeL(iWin2, EFalse, ii); |
|
194 TestFadeL(iFadeCountWin, EFalse, ii); |
|
195 } |
|
196 |
|
197 // negative fade is not counted |
|
198 for (ii=0; ii<KFadeRepeat-1; ii++) |
|
199 { |
|
200 iWs.SetSystemFaded(EFalse); |
|
201 TestFadeL(iWin1, EFalse, EFalse); |
|
202 TestFadeL(iWin2, EFalse, EFalse); |
|
203 TestFadeL(iFadeCountWin, EFalse, EFalse); |
|
204 } |
|
205 |
|
206 iWs.SetSystemFaded(ETrue); |
|
207 TestFadeL(iWin1, ETrue, ETrue); |
|
208 TestFadeL(iWin2, ETrue, ETrue); |
|
209 TestFadeL(iFadeCountWin, ETrue, ETrue); |
|
210 |
|
211 iWs.SetSystemFaded(EFalse); |
|
212 TestFadeL(iWin1, EFalse, EFalse); |
|
213 TestFadeL(iWin2, EFalse, EFalse); |
|
214 TestFadeL(iFadeCountWin, EFalse, EFalse); |
|
215 |
|
216 // child fading |
|
217 // nested |
|
218 iWin2->WinTreeNode()->SetFaded(ETrue, RWindowTreeNode::EFadeIncludeChildren); |
|
219 TestFadeL(iWin1, EFalse, EFalse); |
|
220 TestFadeL(iWin2, ETrue, ETrue); |
|
221 iWin1->WinTreeNode()->SetFaded(ETrue, RWindowTreeNode::EFadeIncludeChildren); |
|
222 TestFadeL(iWin1, ETrue, ETrue); |
|
223 TestFadeL(iWin2, ETrue, ETrue); |
|
224 iWin1->WinTreeNode()->SetFaded(EFalse, RWindowTreeNode::EFadeIncludeChildren); |
|
225 TestFadeL(iWin1, EFalse, EFalse); |
|
226 TestFadeL(iWin2, EFalse, ETrue); |
|
227 iWin2->WinTreeNode()->SetFaded(EFalse, RWindowTreeNode::EFadeIncludeChildren); |
|
228 TestFadeL(iWin1, EFalse, EFalse); |
|
229 TestFadeL(iWin2, EFalse, EFalse); |
|
230 |
|
231 // interlaced |
|
232 iWin2->WinTreeNode()->SetFaded(ETrue, RWindowTreeNode::EFadeIncludeChildren); |
|
233 TestFadeL(iWin1, EFalse, EFalse); |
|
234 TestFadeL(iWin2, ETrue, ETrue); |
|
235 iWin1->WinTreeNode()->SetFaded(ETrue, RWindowTreeNode::EFadeIncludeChildren); |
|
236 TestFadeL(iWin1, ETrue, ETrue); |
|
237 TestFadeL(iWin2, ETrue, ETrue); |
|
238 iWin2->WinTreeNode()->SetFaded(EFalse, RWindowTreeNode::EFadeIncludeChildren); |
|
239 TestFadeL(iWin1, ETrue, ETrue); |
|
240 TestFadeL(iWin2, EFalse, ETrue); |
|
241 iWin1->WinTreeNode()->SetFaded(EFalse, RWindowTreeNode::EFadeIncludeChildren); |
|
242 TestFadeL(iWin1, EFalse, EFalse); |
|
243 TestFadeL(iWin2, EFalse, EFalse); |
|
244 |
|
245 iFadeCountWin->iPass = ETrue; |
|
246 } |
|
247 |
|
248 void CFadeCountClient::CreateTestWindowsL(CTWinBase &aParent) |
|
249 { |
|
250 iWin1 = new(ELeave) CTWin(); |
|
251 iWin1->ConstructL(aParent); |
|
252 iWin1->SetSize(TSize(20,20)); |
|
253 |
|
254 iWin2 = new(ELeave) CTWin(); |
|
255 iWin2->ConstructL(*iWin1); |
|
256 iWin2->SetSize(TSize(10,10)); |
|
257 |
|
258 iAbsoluteFading = IsAbsoluteFadingOnL(); |
|
259 } |
|
260 |
|
261 TBool CFadeCountClient::IsAbsoluteFadingOnL() |
|
262 { |
|
263 iWin1->WinTreeNode()->SetFaded(ETrue, RWindowTreeNode::EFadeWindowOnly); |
|
264 iWin1->WinTreeNode()->SetFaded(ETrue, RWindowTreeNode::EFadeWindowOnly); |
|
265 iWin1->WinTreeNode()->SetFaded(EFalse, RWindowTreeNode::EFadeWindowOnly); |
|
266 TBool absoluteFading = !iWin1->BaseWin()->IsFaded(); |
|
267 iWin1->WinTreeNode()->SetFaded(EFalse, RWindowTreeNode::EFadeWindowOnly); |
|
268 return absoluteFading; |
|
269 } |
|
270 |
|
271 void CFadeCountClient::TestL(TInt aCondition) |
|
272 { |
|
273 if (!aCondition) |
|
274 User::Leave(ETestFailed); |
|
275 } |
|
276 |
|
277 void CFadeCountClient::TestFadeL(CTWin* aWin, TBool aAbs, TBool aCounted) |
|
278 { |
|
279 TestL(!aWin->BaseWin()->IsFaded() == !(iAbsoluteFading ? aAbs : aCounted)); |
|
280 } |
|
281 |
|
282 |
|
283 GLDEF_C CTClient *CreateClientL() |
|
284 { |
|
285 return(new(ELeave) CFadeCountClient()); |
|
286 } |
|
287 |
|
288 GLDEF_C TInt E32Main() |
|
289 { |
|
290 return(TestLibStartUp(CreateClientL)); |
|
291 } |