|
1 /* |
|
2 * Copyright (c) 2005-2006 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: Tests GetPositionL() in various scenarios. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <e32base.h> |
|
19 #include <epos_comasuplposhandlerbase.h> |
|
20 #include <epos_comasuplpossessionbase.h> |
|
21 #include <epos_comasuplposition.h> |
|
22 #include <epos_eomasuplposerrors.h> |
|
23 |
|
24 #include "epos_comasuplpositiontest.h" |
|
25 #include "epos_comasupltesthandler.h" |
|
26 #include "epos_comasuplpostesterlogger.h" |
|
27 |
|
28 |
|
29 // --------------------------------------------------------------------------- |
|
30 // Named constructor |
|
31 // --------------------------------------------------------------------------- |
|
32 // |
|
33 COMASuplPositionTest* COMASuplPositionTest::NewL(COMASuplPosHandlerBase* |
|
34 aPosHandler |
|
35 , COMASuplPosTesterCategory* aCallBack) |
|
36 { |
|
37 COMASuplPositionTest* self = new(ELeave)COMASuplPositionTest(aPosHandler |
|
38 , aCallBack); |
|
39 CleanupStack::PushL(self); |
|
40 self->ConstructL(); |
|
41 CleanupStack::Pop(self); |
|
42 return self; |
|
43 } |
|
44 |
|
45 // --------------------------------------------------------------------------- |
|
46 // Destructor |
|
47 // --------------------------------------------------------------------------- |
|
48 // |
|
49 COMASuplPositionTest::~COMASuplPositionTest() |
|
50 { |
|
51 delete iPosition; |
|
52 delete iSessionBase; |
|
53 } |
|
54 |
|
55 COMASuplPositionTest::COMASuplPositionTest(COMASuplPosHandlerBase* |
|
56 aPosHandler |
|
57 , COMASuplPosTesterCategory* aCallBack) |
|
58 : COMASuplPosTesterCategory(aCallBack) |
|
59 , iPosHandler(*aPosHandler) |
|
60 { |
|
61 |
|
62 } |
|
63 |
|
64 // --------------------------------------------------------------------------- |
|
65 // Second phase constructor |
|
66 // --------------------------------------------------------------------------- |
|
67 // |
|
68 void COMASuplPositionTest::ConstructL() |
|
69 { |
|
70 CActiveScheduler::Add(this); |
|
71 } |
|
72 |
|
73 void COMASuplPositionTest::InitializePositionL() |
|
74 { |
|
75 delete iPosition; |
|
76 iPosition = NULL; |
|
77 iPosition = COMASuplPosition::NewL(); |
|
78 } |
|
79 |
|
80 void COMASuplPositionTest::RequestForPositionL() |
|
81 { |
|
82 TRAPD(err, InitializePositionL()); |
|
83 if(KErrNone != err) |
|
84 { |
|
85 iError++; |
|
86 iLogger->WriteStatus(KLeaveResettingPosition(), err, iTestNo); |
|
87 TestingAborted(KPositionTestAborted); |
|
88 return; |
|
89 } |
|
90 __ASSERT_ALWAYS(!IsActive(),User::Panic(KPanicSetActive, KErrAlreadyExists)); |
|
91 iSessionBase->GetPositionL(iStatus, iPosition); |
|
92 SetActive(); |
|
93 } |
|
94 |
|
95 // --------------------------------------------------------------------------- |
|
96 // This function is called by test handler. It is entry point of execution |
|
97 // of a test case. |
|
98 // --------------------------------------------------------------------------- |
|
99 // |
|
100 void COMASuplPositionTest::StartTestingL() |
|
101 { |
|
102 if(iCallBack) |
|
103 { |
|
104 iLogger->WriteTestHeader(KPositionTest, iTestNo); |
|
105 } |
|
106 iNextInSeq = EStartTest; |
|
107 __ASSERT_ALWAYS(!IsActive(),User::Panic(KPanicSetActive, KErrAlreadyExists)); |
|
108 DummyRequest(iStatus); |
|
109 SetActive(); |
|
110 } |
|
111 |
|
112 // --------------------------------------------------------------------------- |
|
113 // Handles an active object's request completion event. |
|
114 // --------------------------------------------------------------------------- |
|
115 // |
|
116 void COMASuplPositionTest::RunL() |
|
117 { |
|
118 switch(iNextInSeq) |
|
119 { |
|
120 case EStartTest: |
|
121 { |
|
122 iLogger->GetRequestStartTime(); |
|
123 TRAPD( err, iSessionBase = iPosHandler.CreateNewSessionL(this)); |
|
124 if( KErrNone != err ) |
|
125 { |
|
126 iError++; |
|
127 iLogger->WriteLine(KCreatingSessionFail, iTestNo); |
|
128 User::Leave(err); |
|
129 } |
|
130 iInfo++; |
|
131 iLogger->LogExecutionTime(KExecCreateNewSessionL); |
|
132 iInfo++; |
|
133 iLogger->WriteLine(KSessionCreated, iTestNo); |
|
134 __ASSERT_ALWAYS(!IsActive(),User::Panic(KPanicSetActive, KErrAlreadyExists)); |
|
135 iNextInSeq = EGetPositionBeforeInitialize; |
|
136 DummyRequest(iStatus); |
|
137 SetActive(); |
|
138 break; |
|
139 } |
|
140 case EGetPositionBeforeInitialize: |
|
141 { |
|
142 iNextInSeq = EGetPositionCompleteBeforeInitialize; |
|
143 iInfo++; |
|
144 iLogger->WriteLine(KGetPositionLInfo, iTestNo); |
|
145 RequestForPositionL(); |
|
146 break; |
|
147 } |
|
148 |
|
149 case EGetPositionCompleteBeforeInitialize: |
|
150 { |
|
151 iNextInSeq = EInitializeSession; |
|
152 if(iStatus == KErrOMASuplPosInActive) |
|
153 { |
|
154 iInfo++; |
|
155 iLogger->WriteStatus( |
|
156 _L8("Info: GetPositionL completed with ") |
|
157 , iStatus.Int(), iTestNo); |
|
158 } |
|
159 else |
|
160 { |
|
161 iWarning++; |
|
162 iLogger->WriteStatus( |
|
163 _L8("Warning: GetPositionL completed with ") |
|
164 , iStatus.Int(), iTestNo); |
|
165 } |
|
166 __ASSERT_ALWAYS(!IsActive(),User::Panic(KPanicSetActive, KErrAlreadyExists)); |
|
167 DummyRequest(iStatus); |
|
168 SetActive(); |
|
169 break; |
|
170 } |
|
171 |
|
172 case EInitializeSession: |
|
173 { |
|
174 __ASSERT_ALWAYS(!IsActive(),User::Panic(KPanicSetActive, KErrAlreadyExists)); |
|
175 iNextInSeq = EGetPositionAfterInitialize; |
|
176 iInfo++; |
|
177 iLogger->WriteLine(KInitializingSession); |
|
178 |
|
179 iSessionBase->InitializeL(iRequestID, iStatus); |
|
180 SetActive(); |
|
181 break; |
|
182 } |
|
183 |
|
184 case EGetPositionAfterInitialize: |
|
185 { |
|
186 if(iStatus != KErrNone) |
|
187 { |
|
188 iError++; |
|
189 iLogger->WriteStatus(KError, iStatus.Int(), iTestNo, &KReqCompWith()); |
|
190 TestingAborted(KPositionTestAborted); |
|
191 return; |
|
192 } |
|
193 else |
|
194 { |
|
195 iInfo++; |
|
196 iLogger->WriteStatus(KInfo, KErrNone, iTestNo, &KReqCompWith()); |
|
197 } |
|
198 iNextInSeq = EGetPositionCompleteAfterInitialize; |
|
199 iInfo++; |
|
200 iLogger->WriteLine(KGetPositionLSessionInitInfo, iTestNo); |
|
201 RequestForPositionL(); |
|
202 break; |
|
203 } |
|
204 case EGetPositionCompleteAfterInitialize: |
|
205 { |
|
206 iNextInSeq = EEndSessionAndGetPosition; |
|
207 if(iStatus != KErrNone) |
|
208 { |
|
209 iWarning++; |
|
210 iLogger->WriteStatus( |
|
211 _L8("Warning: GetPositionL completed with ") |
|
212 , iStatus.Int(), iTestNo); |
|
213 } |
|
214 else |
|
215 { |
|
216 iInfo++; |
|
217 iLogger->WriteStatus( |
|
218 _L8("Info: GetPositionL completed with ") |
|
219 , iStatus.Int(), iTestNo); |
|
220 } |
|
221 iLogger->LogSuplPosition(iPosition); |
|
222 __ASSERT_ALWAYS(!IsActive(),User::Panic(KPanicSetActive, KErrAlreadyExists)); |
|
223 DummyRequest(iStatus); |
|
224 SetActive(); |
|
225 break; |
|
226 } |
|
227 case EEndSessionAndGetPosition: |
|
228 { |
|
229 iNextInSeq = EGetPositionCompleteAfterEndSession; |
|
230 iInfo++; |
|
231 iLogger->WriteLine(KEndingSession, iTestNo); |
|
232 iSessionBase->SessionEnd(); |
|
233 iInfo++; |
|
234 iLogger->WriteLine(KGetPositionLSessionEndInfo, iTestNo); |
|
235 RequestForPositionL(); |
|
236 break; |
|
237 } |
|
238 case EGetPositionCompleteAfterEndSession: |
|
239 { |
|
240 if(iStatus == KErrOMASuplPosInActive) |
|
241 { |
|
242 iInfo++; |
|
243 iLogger->WriteStatus(KAfterEndSessionI, iStatus.Int() |
|
244 , iTestNo); |
|
245 } |
|
246 else |
|
247 { |
|
248 iWarning++; |
|
249 iLogger->WriteStatus(KAfterEndSessionW, iStatus.Int() |
|
250 , iTestNo); |
|
251 } |
|
252 iLogger->LogSuplPosition(iPosition); |
|
253 TestingComplete(KPositionTestComplete); |
|
254 break; |
|
255 } |
|
256 } |
|
257 } |
|
258 |
|
259 // --------------------------------------------------------------------------- |
|
260 // Implements cancellation of an outstanding request. |
|
261 // --------------------------------------------------------------------------- |
|
262 // |
|
263 void COMASuplPositionTest::DoCancel() |
|
264 { |
|
265 if(EGetPositionCompleteBeforeInitialize == iNextInSeq |
|
266 || EGetPositionCompleteAfterInitialize == iNextInSeq |
|
267 || EGetPositionCompleteAfterEndSession == iNextInSeq) |
|
268 { |
|
269 //Cancel position |
|
270 iSessionBase->CancelGetPosition(); |
|
271 return; |
|
272 } |
|
273 if(EGetPositionAfterInitialize == iNextInSeq) |
|
274 { |
|
275 //Cancel sessionInit |
|
276 iSessionBase->CancelInitialize(); |
|
277 return; |
|
278 } |
|
279 } |
|
280 |
|
281 // --------------------------------------------------------------------------- |
|
282 // Handles a leave occurring in the request completion event handler RunL(). |
|
283 // --------------------------------------------------------------------------- |
|
284 // |
|
285 TInt COMASuplPositionTest::RunError(TInt aError) |
|
286 { |
|
287 if(EStartTest == iNextInSeq) |
|
288 { |
|
289 iError++; |
|
290 iLogger->WriteStatus(KLeaveInCreateNewSession, aError, iTestNo); |
|
291 } |
|
292 if(EGetPositionCompleteBeforeInitialize == iNextInSeq |
|
293 || EGetPositionCompleteAfterInitialize == iNextInSeq |
|
294 || EGetPositionCompleteAfterEndSession == iNextInSeq) |
|
295 { |
|
296 //Leave in Position |
|
297 iError++; |
|
298 iLogger->WriteStatus(KLeaveInGetPosition, aError, iTestNo); |
|
299 } |
|
300 if(EGetPositionAfterInitialize == iNextInSeq) |
|
301 { |
|
302 //Leave in Session Initialization |
|
303 iError++; |
|
304 iLogger->WriteStatus(KLeaveInSessionInit, aError, iTestNo); |
|
305 } |
|
306 TestingAborted(KPositionTestAborted); |
|
307 return KErrNone; |
|
308 } |