|
1 // Copyright (c) 2005-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 */ |
|
20 |
|
21 #include <basched.h> |
|
22 #include <eikenv.h> |
|
23 #include <eikappui.h> |
|
24 #include <techview/eikon.hrh> |
|
25 #include <eikapp.h> |
|
26 #include <eikdoc.h> |
|
27 #include <techview/eiklabel.h> |
|
28 #include <eikfctry.h> |
|
29 #include <coecntrl.h> |
|
30 #include <barsread.h> |
|
31 #include "TLOADDLL.H" |
|
32 #include <external.rsg> |
|
33 #include <techview/eiktbar.h> |
|
34 #include <techview/eikmenub.h> |
|
35 #include <ecom/ecom.h> |
|
36 |
|
37 |
|
38 #include "Tautolib.h" |
|
39 |
|
40 |
|
41 _LIT(KTAutoLibResourceFilePath, ""); |
|
42 |
|
43 |
|
44 //#define FORCE_AUTO |
|
45 |
|
46 |
|
47 //! A CTestAutoContainer test control class. |
|
48 /** |
|
49 The class represents the test Container control. |
|
50 */ |
|
51 class CTestAutoContainer : public CCoeControl |
|
52 { |
|
53 public: |
|
54 CTestAutoContainer(CTestAppUi* aApp); |
|
55 ~CTestAutoContainer(); |
|
56 void ConstructL(const TRect& aRect); |
|
57 virtual TInt CountComponentControls() const; |
|
58 virtual CCoeControl* ComponentControl(TInt aIndex) const; |
|
59 private: |
|
60 void Draw(const TRect& aRect) const; |
|
61 private: |
|
62 CTestEikDllLoadedLabel* iLabel2; |
|
63 CTestAppUi* iApp; |
|
64 }; |
|
65 |
|
66 CTestAutoContainer::CTestAutoContainer(CTestAppUi* aApp) : |
|
67 iApp(aApp) |
|
68 /** |
|
69 Constructor |
|
70 */ |
|
71 { |
|
72 |
|
73 } |
|
74 |
|
75 /** |
|
76 Auxiliary function for Container |
|
77 |
|
78 This method is the second phase constructor for CTestAutoContainer. |
|
79 It is used to create the applications control. This method calls the control |
|
80 factory function to create the control. The method then uses Cone to |
|
81 construct the control by reading information from the resource file that was |
|
82 added. |
|
83 |
|
84 */ |
|
85 void CTestAutoContainer::ConstructL(const TRect& aRect) |
|
86 { |
|
87 CreateWindowL(); |
|
88 Window().SetShadowDisabled(ETrue); |
|
89 Window().SetBackgroundColor(KRgbWhite); |
|
90 iApp->INFO_PRINTF1(_L("ASKING THE EIKON CONTROL FACTORY TO CREATE THIS APPLICATION'S CONTROL")); |
|
91 |
|
92 |
|
93 // For ECom Plugin DLL |
|
94 iApp->INFO_PRINTF1(_L("Creating control from ECom plugin DLL")); |
|
95 SEikControlInfo control2Info = EikControlFactory::CreateByTypeL(CTestEikDllLoadedLabel::ECtTestEikEComDllLoadedLabel); |
|
96 iLabel2 = STATIC_CAST(CTestEikDllLoadedLabel*, control2Info.iControl); |
|
97 iApp->TEST(iLabel2 != NULL); |
|
98 if (iLabel2) |
|
99 { |
|
100 iLabel2->SetContainerWindowL(*this); |
|
101 iLabel2->SetControlContext(iLabel2); |
|
102 |
|
103 iApp->INFO_PRINTF1(_L("ASKING CONE TO CONSTRUCT THIS APPLICATION'S CONTROL FROM THE LOCAL RESOURCE FILE")); |
|
104 TResourceReader reader2; |
|
105 iCoeEnv->CreateResourceReaderLC(reader2,R_TESTAUTOLIB_LABEL); |
|
106 iLabel2->ConstructFromResourceL(reader2); |
|
107 CleanupStack::PopAndDestroy();// resource readers |
|
108 iLabel2->SetRect(TRect(TPoint(260,130),iLabel2->MinimumSize())); |
|
109 iLabel2->ActivateL(); |
|
110 } |
|
111 else |
|
112 { |
|
113 iApp->INFO_PRINTF1(_L("Error may be related to binaries in TLOADDLLV2.MMP")); |
|
114 } |
|
115 |
|
116 if (iLabel2) |
|
117 { |
|
118 SetRect(aRect); |
|
119 ActivateL(); |
|
120 } |
|
121 } |
|
122 |
|
123 CTestAutoContainer::~CTestAutoContainer() |
|
124 /** |
|
125 Destructor |
|
126 */ |
|
127 { |
|
128 delete iLabel2; |
|
129 } |
|
130 |
|
131 /** |
|
132 Auxiliary function for Container |
|
133 |
|
134 This method is an override from CCoeControl. It returns the number of |
|
135 controls contained in a compound control. |
|
136 |
|
137 */ |
|
138 TInt CTestAutoContainer::CountComponentControls() const |
|
139 { |
|
140 return(1); |
|
141 } |
|
142 |
|
143 /** |
|
144 Auxiliary function for Container |
|
145 |
|
146 This method is an override from CCoeControl. It returns the label component |
|
147 from the container control. |
|
148 |
|
149 */ |
|
150 CCoeControl* CTestAutoContainer::ComponentControl(TInt aIndex) const |
|
151 { |
|
152 switch (aIndex) |
|
153 { |
|
154 case 0: |
|
155 default: |
|
156 { |
|
157 return iLabel2; |
|
158 } |
|
159 } |
|
160 } |
|
161 |
|
162 |
|
163 /** |
|
164 Auxiliary function for refreshing Container |
|
165 |
|
166 This method is an override from CCoeControl. It draws the container control. |
|
167 |
|
168 */ |
|
169 void CTestAutoContainer::Draw(const TRect& aRect) const |
|
170 { |
|
171 CWindowGc& gc=SystemGc(); |
|
172 gc.SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
173 gc.SetBrushColor(KRgbWhite); |
|
174 gc.SetPenStyle(CGraphicsContext::ESolidPen); |
|
175 gc.SetPenColor(KRgbWhite); |
|
176 gc.DrawRect(aRect); |
|
177 } |
|
178 |
|
179 |
|
180 //! A CTestAutoAddLibraryAppUi test class. |
|
181 /** |
|
182 The class handles work with resources. |
|
183 */ |
|
184 class CTestAutoAddLibraryAppUi : public CTestAppUi |
|
185 { |
|
186 public: |
|
187 CTestAutoAddLibraryAppUi(CTmsTestStep* aStep) : |
|
188 CTestAppUi(aStep, KTAutoLibResourceFilePath) {} //, TESTAUTOLIB_HOT_KEYS, TESTAUTOLIB_MENU_BAR){} |
|
189 ~CTestAutoAddLibraryAppUi(); |
|
190 void ConstructL(); |
|
191 virtual void HandleCommandL(TInt aCommand); |
|
192 |
|
193 //from CCoeAppUi |
|
194 void PrepareToExit(); |
|
195 |
|
196 private: |
|
197 void RunTestStepL(TInt aNumStep); |
|
198 |
|
199 CTestAutoContainer* iContainer; |
|
200 }; |
|
201 |
|
202 |
|
203 CTestAutoAddLibraryAppUi::~CTestAutoAddLibraryAppUi() |
|
204 /** |
|
205 Destructor |
|
206 */ |
|
207 { |
|
208 } |
|
209 |
|
210 void CTestAutoAddLibraryAppUi::PrepareToExit() |
|
211 { |
|
212 // Need to delete iContainer here rather than in the destructor because iContainer |
|
213 // owns a control (CTestEikDllLoadedLabel) which is defined in an ECom DLL. |
|
214 // Because this app is the only user of that Ecom DLL, it will be expunged from RAM |
|
215 // (when run from an On-Demand-Paging ROM) before the AppUi is deleted. |
|
216 // See DEF112572 |
|
217 RemoveFromStack(iContainer); |
|
218 delete iContainer; |
|
219 } |
|
220 |
|
221 |
|
222 /** |
|
223 Auxiliary function for all Test Cases |
|
224 |
|
225 The method creates a container and sets active object with lowest |
|
226 priority for running test in auto mode. |
|
227 |
|
228 */ |
|
229 void CTestAutoAddLibraryAppUi::ConstructL() |
|
230 { |
|
231 //BaseConstructL(); |
|
232 CTestAppUi::ConstructL(); |
|
233 |
|
234 TRect boundingRect=ClientRect(); // make toolband stretch to the screen width by default |
|
235 //menu |
|
236 iContainer=new(ELeave) CTestAutoContainer(this); |
|
237 ReduceRect(boundingRect); |
|
238 iContainer->ConstructL(boundingRect); |
|
239 AddToStackL(iContainer); |
|
240 |
|
241 AutoTestManager().StartAutoTest(); |
|
242 |
|
243 } |
|
244 |
|
245 |
|
246 /** |
|
247 Auxiliary function for all Test Cases |
|
248 |
|
249 The method is an override from CTestAppUi. The method initiates all tests |
|
250 to be performed. |
|
251 |
|
252 */ |
|
253 void CTestAutoAddLibraryAppUi::RunTestStepL(TInt aNumStep) |
|
254 { |
|
255 |
|
256 User::After(TTimeIntervalMicroSeconds32(1000000)); |
|
257 switch(aNumStep) |
|
258 { |
|
259 case 1: |
|
260 AutoTestManager().FinishAllTestCases(CAutoTestManager::EPass); |
|
261 break; |
|
262 } |
|
263 } |
|
264 |
|
265 |
|
266 /** |
|
267 Auxiliary function for all Test Cases |
|
268 |
|
269 This method is called by CTestAutoAddLibraryAppUi::RunTestStepL() to initiate |
|
270 the tests. |
|
271 |
|
272 */ |
|
273 void CTestAutoAddLibraryAppUi::HandleCommandL(TInt aCommand) |
|
274 { |
|
275 switch (aCommand) |
|
276 { |
|
277 case EEikCmdExit: |
|
278 iCoeEnv->Flush(); |
|
279 Exit(); |
|
280 break; |
|
281 } |
|
282 } |
|
283 |
|
284 |
|
285 |
|
286 //---------- |
|
287 |
|
288 CTestAutoLibStep::CTestAutoLibStep() |
|
289 /** |
|
290 Constructor |
|
291 */ |
|
292 { |
|
293 SetTestStepName(KTestAutoLibStep); |
|
294 } |
|
295 |
|
296 CTestAutoLibStep::~CTestAutoLibStep() |
|
297 /** |
|
298 Destructor |
|
299 */ |
|
300 { |
|
301 } |
|
302 |
|
303 /** |
|
304 Auxiliary function for all Test Cases |
|
305 |
|
306 The method creates & sets the application's user interface object. |
|
307 |
|
308 */ |
|
309 void CTestAutoLibStep::ConstructAppL(CEikonEnv* aCoe) |
|
310 { // runs inside a TRAP harness |
|
311 aCoe->ConstructL(); |
|
312 |
|
313 CTestAppUi* appUi= new (ELeave) CTestAutoAddLibraryAppUi(this); |
|
314 aCoe->SetAppUi(appUi); |
|
315 appUi->ConstructL(); |
|
316 } |
|
317 |
|
318 /** |
|
319 Auxiliary function for all Test Cases |
|
320 |
|
321 The method creates & sets the application's user interface object to |
|
322 launch the application which will initiate the tests. |
|
323 |
|
324 */ |
|
325 TVerdict CTestAutoLibStep::doTestStepL() // main function called by E32 |
|
326 { |
|
327 PreallocateHALBuffer(); |
|
328 __UHEAP_MARK; |
|
329 |
|
330 CEikonEnv* coe=new CEikonEnv; |
|
331 TRAPD(err,ConstructAppL(coe)); |
|
332 |
|
333 if (!err) |
|
334 coe->ExecuteD(); |
|
335 |
|
336 REComSession::FinalClose(); |
|
337 |
|
338 __UHEAP_MARKEND; |
|
339 |
|
340 return TestStepResult(); |
|
341 } |
|
342 |
|
343 |
|
344 |
|
345 |