|
1 /* |
|
2 * Copyright (c) 2006-2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Test case. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <apgtask.h> |
|
20 #include <eikappui.h> |
|
21 #include <sysutil.h> |
|
22 #include <s32file.h> |
|
23 |
|
24 #include "bctestapplication.h" |
|
25 #include "bctestlauncher.hrh" |
|
26 #include "bcteststrmlogger.h" |
|
27 |
|
28 #include <e32property.h> |
|
29 using namespace BCTest; |
|
30 |
|
31 const TInt KDelay = 500*1000; //500 ms |
|
32 const TUid KPSUidAvkonDomainForBC = { 0x10207218 }; // Same as KPSUidAvkonDomain |
|
33 const TUint32 KAknMenuOptionNoTaskSwapper = 0x10000002; |
|
34 |
|
35 enum TAknMenuOptionNoTaskSwapper |
|
36 { |
|
37 ETaskSwapper, |
|
38 ENoTaskSwapper |
|
39 }; |
|
40 |
|
41 // ================================== local functions ======================== |
|
42 inline static void Wait(TInt aSec) |
|
43 { |
|
44 User::After(aSec*KDelay*2); |
|
45 } |
|
46 |
|
47 inline static void Wait() |
|
48 { |
|
49 User::After( KDelay ); |
|
50 } |
|
51 |
|
52 static TInt ManualSDKVersion() |
|
53 { |
|
54 RFs fs; |
|
55 User::LeaveIfError( fs.Connect() ); |
|
56 RFileReadStream readStream; |
|
57 if ( readStream.Open( fs, KSdkVerFile, EFileRead ) < 0 ) |
|
58 { |
|
59 fs.Close(); |
|
60 readStream.Release (); |
|
61 return 0; |
|
62 } |
|
63 readStream.PushL(); |
|
64 TInt ver = static_cast<TInt>(readStream.ReadInt32L()); |
|
65 readStream.Pop (); |
|
66 readStream.Release (); |
|
67 fs.Close(); |
|
68 return ver; |
|
69 } |
|
70 static TInt SDKVersion() |
|
71 { |
|
72 TInt swver = 30; |
|
73 TInt taskSwapper( ENoTaskSwapper ) ;// taskSwapper |
|
74 TInt result = RProperty::Get( KPSUidAvkonDomainForBC, |
|
75 KAknMenuOptionNoTaskSwapper, taskSwapper ); |
|
76 TInt ret = RProperty::Define( KPSUidAvkonDomainForBC, |
|
77 KAknMenuOptionNoTaskSwapper, RProperty::EInt ); |
|
78 if (ret == KErrAlreadyExists) |
|
79 { |
|
80 if ( result == KErrNotFound ) |
|
81 { |
|
82 swver = 30; |
|
83 } |
|
84 else |
|
85 { |
|
86 if ( taskSwapper == 0 ) |
|
87 { |
|
88 swver = 50; |
|
89 } |
|
90 else |
|
91 { |
|
92 swver = 30; |
|
93 } |
|
94 } |
|
95 } |
|
96 else |
|
97 { |
|
98 RProperty::Set( KPSUidAvkonDomainForBC, |
|
99 KAknMenuOptionNoTaskSwapper, ENoTaskSwapper ); |
|
100 } |
|
101 |
|
102 return swver; |
|
103 } |
|
104 |
|
105 // ======== MEMBER FUNCTIONS ======== |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // Constructor |
|
109 // --------------------------------------------------------------------------- |
|
110 // |
|
111 CBCTestApplication::CBCTestApplication( |
|
112 const TDesC& aName, TInt aAppUID, TInt aViewUID, |
|
113 TInt aTimeout, TInt aVersion): |
|
114 iName(aName), iAppUID(aAppUID), iViewUID(aViewUID), iTimeout(aTimeout), |
|
115 iVersion(aVersion), |
|
116 iSelected(EFalse) |
|
117 { |
|
118 } |
|
119 |
|
120 // --------------------------------------------------------------------------- |
|
121 // CBCTestApplication::~CBCTestApplication() |
|
122 // Destructor |
|
123 // --------------------------------------------------------------------------- |
|
124 // |
|
125 CBCTestApplication::~CBCTestApplication() |
|
126 { |
|
127 } |
|
128 |
|
129 // --------------------------------------------------------------------------- |
|
130 // CBCTestApplication::NewL() |
|
131 // |
|
132 // --------------------------------------------------------------------------- |
|
133 // |
|
134 CBCTestApplication* CBCTestApplication::NewL( const TDesC& aName, |
|
135 TInt aAppUID, TInt aViewUID, TInt aTimeout, TInt aVersion ) |
|
136 { |
|
137 CBCTestApplication* self= new ( ELeave ) CBCTestApplication( |
|
138 aName, aAppUID, aViewUID, aTimeout, aVersion ); |
|
139 return self; |
|
140 } |
|
141 |
|
142 // --------------------------------------------------------------------------- |
|
143 // CBCTestApplication::RunL. |
|
144 // --------------------------------------------------------------------------- |
|
145 // |
|
146 void CBCTestApplication::RunL( TInt aCommand ) |
|
147 { |
|
148 if( iVersion > SDKVersion() ) |
|
149 { |
|
150 if ( iVersion > ManualSDKVersion() ) |
|
151 { |
|
152 return; |
|
153 } |
|
154 } |
|
155 |
|
156 if( iSelected || aCommand == EAutoTestAll ) |
|
157 { |
|
158 SetupL(); |
|
159 StartAutoTest(); |
|
160 WatchDogL(); |
|
161 TearDown(); |
|
162 } |
|
163 } |
|
164 |
|
165 // --------------------------------------------------------------------------- |
|
166 // CBCTestApplication::SetupL. |
|
167 // --------------------------------------------------------------------------- |
|
168 // |
|
169 void CBCTestApplication::SetupL() |
|
170 { |
|
171 TInt mem = GetFreeMem(); |
|
172 |
|
173 CEikonEnv::Static()->EikAppUi()->ActivateViewL( |
|
174 TVwsViewId(TUid::Uid(iAppUID), TUid::Uid(iViewUID))); |
|
175 |
|
176 LOG<<iName<<_L("[SDK ")<<SDKVersion()<<_L("]: start, with memory: ") |
|
177 << mem << EndLine << End; |
|
178 } |
|
179 |
|
180 // --------------------------------------------------------------------------- |
|
181 // CBCTestApplication::StartAutoTest. |
|
182 // by simulate menu operations |
|
183 // --------------------------------------------------------------------------- |
|
184 // |
|
185 void CBCTestApplication::StartAutoTest() |
|
186 { |
|
187 Wait(2); |
|
188 KeyPress( EKeyDevice0, EStdKeyDevice0 ); // open menu |
|
189 |
|
190 TInt sdkVer = SDKVersion(); |
|
191 TInt loop = 2; |
|
192 if ( ( sdkVer == 32 ) || ( sdkVer == 33 ) || ( sdkVer == 50 ) ) |
|
193 { |
|
194 loop = 3; |
|
195 } |
|
196 for ( TInt i = 0; i < loop; i++ ) |
|
197 { |
|
198 Wait(); |
|
199 KeyPress( EKeyUpArrow, EStdKeyUpArrow ); |
|
200 } |
|
201 |
|
202 Wait(); |
|
203 KeyPress( EKeyDevice0, EStdKeyDevice0 ); // start autotest |
|
204 } |
|
205 |
|
206 // --------------------------------------------------------------------------- |
|
207 // CBCTestApplication::WatchDogL. |
|
208 // --------------------------------------------------------------------------- |
|
209 // |
|
210 void CBCTestApplication::WatchDogL() |
|
211 { |
|
212 TInt durationCount = iTimeout*6*5; |
|
213 TApaTaskList taskList(CEikonEnv::Static()->WsSession()); |
|
214 while (taskList.FindApp(TUid::Uid(iAppUID)).Exists() && durationCount--) |
|
215 { |
|
216 Wait(2); //monitor every 2 seconds |
|
217 } |
|
218 |
|
219 if ( taskList.FindApp( TUid::Uid( iAppUID ) ).Exists() ) |
|
220 { |
|
221 // still alive, kill it! |
|
222 taskList.FindApp( TUid::Uid( iAppUID ) ).KillTask(); |
|
223 // wait for application actually killed |
|
224 while ( taskList.FindApp( TUid::Uid( iAppUID ) ).Exists() ) |
|
225 { |
|
226 Wait(); |
|
227 } |
|
228 User::Leave( KErrTimedOut ); |
|
229 } |
|
230 } |
|
231 |
|
232 void CBCTestApplication::TearDown() |
|
233 { |
|
234 LOG<<iName<<_L(": End with memory: ") |
|
235 <<GetFreeMem()<<EndLine<<End; |
|
236 } |
|
237 |
|
238 // --------------------------------------------------------------------------- |
|
239 // CBCTestRunner::KeyPress(TInt aCode, TInt aScanCode) |
|
240 // Simulates keypress event |
|
241 // --------------------------------------------------------------------------- |
|
242 // |
|
243 void CBCTestApplication::KeyPress( TInt aCode, TInt aScanCode ) |
|
244 { |
|
245 User::ResetInactivityTime();// Reset user inactivity timers |
|
246 TKeyEvent event = { aCode, aScanCode, 0, 0 }; |
|
247 CEikonEnv::Static()->WsSession().SimulateKeyEvent(event); |
|
248 CEikonEnv::Static()->WsSession().Flush(); |
|
249 } |
|
250 |
|
251 // --------------------------------------------------------------------------- |
|
252 // CBCTestRunner::GetFreeMem() |
|
253 // --------------------------------------------------------------------------- |
|
254 // |
|
255 TInt CBCTestApplication::GetFreeMem() |
|
256 { |
|
257 User::CompressAllHeaps(); |
|
258 TMemoryInfoV1Buf meminfo; |
|
259 UserHal::MemoryInfo( meminfo ); |
|
260 return meminfo().iFreeRamInBytes; |
|
261 } |
|
262 |