|
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 @internalComponent - Internal Symbian test code |
|
19 @test |
|
20 */ |
|
21 |
|
22 #include "statecon.h" |
|
23 #include "tconestateobs.h" |
|
24 |
|
25 const TFontSpec CStateObserverControl::iFontSpec(KFontName,256); |
|
26 |
|
27 |
|
28 /** |
|
29 Set up the control |
|
30 */ |
|
31 void CStateObserverControl::ConstructL() |
|
32 { |
|
33 TSize scrSize(iCoeEnv->ScreenDevice()->SizeInPixels()); |
|
34 SetExtent(TPoint(scrSize.iWidth/4,0),TSize(scrSize.iWidth-scrSize.iWidth/4,scrSize.iHeight)); |
|
35 CreateWindowL(); |
|
36 Window().SetBackgroundColor(TRgb(85,85,255)); //Bright Blue |
|
37 ActivateL(); |
|
38 iFont=iCoeEnv->CreateScreenFontL(iFontSpec); |
|
39 //iCoeEnv->WsSession().LogCommand(RWsSession::ELoggingStatusDump); //Useful for debugging window creation problems |
|
40 DrawNow(); |
|
41 Flush(); |
|
42 iShouldBeVisible=ETrue; //Initial State |
|
43 iShouldBeDimmed=EFalse; //Initial State |
|
44 } |
|
45 |
|
46 /** |
|
47 Delete the controls resources |
|
48 */ |
|
49 CStateObserverControl::~CStateObserverControl() |
|
50 { |
|
51 iCoeEnv->ReleaseScreenFont(iFont); |
|
52 } |
|
53 |
|
54 /** |
|
55 Set which interface should be recieving events |
|
56 */ |
|
57 void CStateObserverControl::SetRecievers(TBool aControlRecieving,TBool aCoeEnvRecieving) |
|
58 { |
|
59 iControlRecieving=aControlRecieving; |
|
60 iCoeEnvRecieving=aCoeEnvRecieving; |
|
61 } |
|
62 |
|
63 /** |
|
64 Reset the control counts so that a new test can be run |
|
65 */ |
|
66 void CStateObserverControl::ResetCount() |
|
67 { |
|
68 iTestNo=0; |
|
69 DrawNow(); |
|
70 Flush(); |
|
71 iLastCalled=0; |
|
72 iFailAt=0; |
|
73 } |
|
74 |
|
75 /** |
|
76 Draw the controls window |
|
77 */ |
|
78 void CStateObserverControl::Draw(const TRect& aRect) const |
|
79 { |
|
80 _LIT(KString1,"Win "); |
|
81 _LIT(KString2,"Faded"); |
|
82 _LIT(KString3,"Not Faded"); |
|
83 _LIT(KString4,", Subtest %d"); |
|
84 TBuf<32> buf; |
|
85 buf.Copy(KString1); |
|
86 buf.Append(IsDimmed()?KString2():KString3()); |
|
87 if (iTestNo>0) |
|
88 buf.AppendFormat(KString4,iTestNo); |
|
89 TRect rect(aRect); |
|
90 const TSize size(aRect.Size()); |
|
91 rect.Shrink(size.iWidth/5,size.iHeight/5); |
|
92 CWindowGc& gc=SystemGc(); |
|
93 gc.SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
94 gc.SetBrushColor(TRgb(85,255,85)); //Bright Green |
|
95 gc.DrawRect(rect); |
|
96 gc.SetBrushStyle(CGraphicsContext::ENullBrush); |
|
97 gc.SetPenStyle(CGraphicsContext::ESolidPen); |
|
98 gc.SetPenColor(TRgb(255,85,85)); //Bright Red |
|
99 gc.UseFont(iFont); |
|
100 gc.DrawText(buf,TPoint(rect.iTl.iX+20,aRect.Height()/2)); |
|
101 gc.DiscardFont(); |
|
102 } |
|
103 |
|
104 /** |
|
105 Set the control's and windows dimmed state |
|
106 */ |
|
107 void CStateObserverControl::DoSetDimmed(TBool aDimmed) |
|
108 { |
|
109 Window().SetFaded(aDimmed,RWindowTreeNode::EFadeWindowOnly,0,127); |
|
110 SetDimmed(aDimmed); |
|
111 } |
|
112 |
|
113 /** |
|
114 Run a set of tests on the control |
|
115 */ |
|
116 TInt CStateObserverControl::DoTest() |
|
117 { |
|
118 EnableReportControlStateChange(ETrue); |
|
119 DoTestStep(MCoeControlStateObserver::EStateDimmed,ETrue); |
|
120 DoTestStep(MCoeControlStateObserver::EStateVisibility,EFalse); |
|
121 DoTestStep(MCoeControlStateObserver::EStateVisibility,ETrue); |
|
122 DoTestStep(MCoeControlStateObserver::EStateDimmed,ETrue); |
|
123 DoTestStep(MCoeControlStateObserver::EStateDimmed,EFalse); |
|
124 DoTestStep(MCoeControlStateObserver::EStateDimmed,EFalse); |
|
125 DoTestStep(MCoeControlStateObserver::EStateVisibility,ETrue); |
|
126 DoTestStep(MCoeControlStateObserver::EStateVisibility,EFalse); |
|
127 DoTestStep(MCoeControlStateObserver::EStateVisibility,EFalse); |
|
128 DoTestStep(MCoeControlStateObserver::EStateDimmed,ETrue); |
|
129 DoTestStep(MCoeControlStateObserver::EStateDimmed,EFalse); |
|
130 DoTestStep(MCoeControlStateObserver::EStateVisibility,ETrue); |
|
131 EnableReportControlStateChange(EFalse); |
|
132 return iFailAt; |
|
133 } |
|
134 |
|
135 void CStateObserverControl::Failed() |
|
136 { |
|
137 if (!iFailAt) |
|
138 iFailAt=iTestNo; |
|
139 } |
|
140 |
|
141 /** |
|
142 Run a particular test on the control |
|
143 */ |
|
144 void CStateObserverControl::DoTestStep(MCoeControlStateObserver::TCoeState aStateToChange,TBool aNewState) |
|
145 { |
|
146 ++iTestNo; |
|
147 iCntCalled=EFalse; |
|
148 iEnvCalled=EFalse; |
|
149 iExpectedChange=aStateToChange; |
|
150 if (iExpectedChange==MCoeControlStateObserver::EStateVisibility) |
|
151 { |
|
152 iNoChange=(iShouldBeVisible==aNewState); |
|
153 iShouldBeVisible=aNewState; |
|
154 MakeVisible(aNewState); |
|
155 } |
|
156 else |
|
157 { |
|
158 iNoChange=(iShouldBeDimmed==aNewState); |
|
159 iShouldBeDimmed=aNewState; |
|
160 DoSetDimmed(aNewState); |
|
161 } |
|
162 if (IsVisible()) |
|
163 DrawNow(); |
|
164 Flush(); |
|
165 //Test to see that either |
|
166 //the control changed its state (iNoChange==EFalse) and function were called (iLastCalled==iTestNo) OR |
|
167 //the control state was unchanged (iNoChange==ETrue) and function was not called (iLastCalled<iTestNo) |
|
168 if ((iLastCalled!=iTestNo)==(!iNoChange)) |
|
169 Failed(); |
|
170 } |
|
171 |
|
172 /** |
|
173 Handles calls to the Mop interface on this control |
|
174 */ |
|
175 TInt CStateObserverControl::HandleControlStateChange(CCoeControl* aControl,MCoeControlStateObserver::TCoeState aState) |
|
176 { |
|
177 TestFail(!iControlRecieving,aControl,aState,iCntCalled); |
|
178 return KErrNone; |
|
179 } |
|
180 |
|
181 /** |
|
182 Handles calls to the Mop interface on the control enviroment |
|
183 */ |
|
184 TInt CStateObserverControl::ControlStateChangePassOn(CCoeControl* aControl,MCoeControlStateObserver::TCoeState aState) |
|
185 { |
|
186 TestFail(!iCoeEnvRecieving,aControl,aState,iEnvCalled); |
|
187 return KErrNone; |
|
188 } |
|
189 |
|
190 /** |
|
191 Check if calls to the Mop interface are correct |
|
192 */ |
|
193 void CStateObserverControl::TestFail(TBool aNotGetting,CCoeControl* aControl |
|
194 ,MCoeControlStateObserver::TCoeState aState,TBool& aCalled) |
|
195 { |
|
196 iLastCalled=iTestNo; |
|
197 //Check to see that: |
|
198 //The observer function hasn't been called before [aCalled=EFalse] |
|
199 //That we should be receiving calls [aNotGetting=EFalse] |
|
200 //That the control state has actually changed [iNoChange=EFalse] |
|
201 //The right control changed it's state [aControl==this] |
|
202 //The right state of the control changes [aState==iExpectedChange] |
|
203 //The control if dimmed or not if it should be [iShouldBeDimmed==IsDimmed()] |
|
204 //The control if visible or not if it should be [iShouldBeVisible==IsVisible()] |
|
205 if (aCalled || aNotGetting || iNoChange || aControl!=this || aState!=iExpectedChange |
|
206 || !iShouldBeDimmed!=!IsDimmed() || !iShouldBeVisible!=!IsVisible()) |
|
207 Failed(); |
|
208 aCalled=ETrue; |
|
209 } |
|
210 |
|
211 /** |
|
212 Returns a Mop interface |
|
213 */ |
|
214 TTypeUid::Ptr CStateObserverControl::MopSupplyObject(TTypeUid aId) |
|
215 { |
|
216 switch (iRetObserver) |
|
217 { |
|
218 case EObserver: |
|
219 if (aId.iUid==MCoeControlStateObserver::ETypeId) |
|
220 return aId.MakePtr(static_cast<MCoeControlStateObserver*>(this)); |
|
221 break; |
|
222 case ECoeEnvObserver: |
|
223 return iEnv->MopSupplyObject(aId); |
|
224 default:; |
|
225 } |
|
226 return CCoeControl::MopSupplyObject(aId); |
|
227 } |