|
1 /* |
|
2 * Copyright (c) 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 Class For RPositionServer |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // System Includes |
|
20 |
|
21 |
|
22 // User Includes |
|
23 #include "testpositionserver.h" |
|
24 |
|
25 |
|
26 // Constant Declarations |
|
27 |
|
28 |
|
29 // ======== MEMBER FUNCTIONS ======== |
|
30 |
|
31 // --------------------------------------------------------------------------- |
|
32 // C++ Default Constructor |
|
33 // --------------------------------------------------------------------------- |
|
34 // |
|
35 CTestPositionServer::CTestPositionServer(CStifLogger* aLog) |
|
36 :CActive(0),iLog(aLog) |
|
37 { |
|
38 CActiveScheduler::Add(this); |
|
39 } |
|
40 |
|
41 // --------------------------------------------------------------------------- |
|
42 // C++ Destructor |
|
43 // --------------------------------------------------------------------------- |
|
44 // |
|
45 CTestPositionServer::~CTestPositionServer() |
|
46 { |
|
47 if( IsActive() ) |
|
48 { |
|
49 Cancel(); |
|
50 } |
|
51 } |
|
52 |
|
53 // --------------------------------------------------------- |
|
54 // CTestPositionServer::RunL |
|
55 // |
|
56 // RunL to Handle Completed Request |
|
57 // --------------------------------------------------------- |
|
58 // |
|
59 void CTestPositionServer::RunL() |
|
60 { |
|
61 if(iStatus != KErrCancel) |
|
62 { |
|
63 iLog->Log(_L("RunL %d"),iStatus.Int()); |
|
64 CActiveScheduler::Stop(); |
|
65 } |
|
66 } |
|
67 |
|
68 // --------------------------------------------------------- |
|
69 // CTestPositionServer::DoCancel |
|
70 // |
|
71 // To Handle Cancel Request |
|
72 // --------------------------------------------------------- |
|
73 // |
|
74 void CTestPositionServer::DoCancel() |
|
75 { |
|
76 TInt err = iPosServer.CancelRequest(EPositionServerNotifyModuleStatusEvent); |
|
77 iLog->Log(_L("CancelL %d"),err); |
|
78 |
|
79 } |
|
80 |
|
81 // --------------------------------------------------------- |
|
82 // CTestPositionServer::CancelRequest |
|
83 // |
|
84 // To Cancel the Outstanding Request |
|
85 // --------------------------------------------------------- |
|
86 // |
|
87 TInt CTestPositionServer::CancelRequest() |
|
88 { |
|
89 TInt err = iPosServer.CancelRequest(EPositionServerNotifyModuleStatusEvent); |
|
90 iLog->Log(_L("CancelL %d"),err); |
|
91 return err; |
|
92 } |
|
93 |
|
94 // --------------------------------------------------------- |
|
95 // CTestPositionServer::RunError |
|
96 // |
|
97 // To Handle Error in RunL |
|
98 // --------------------------------------------------------- |
|
99 // |
|
100 TInt CTestPositionServer::RunError(TInt aError) |
|
101 { |
|
102 iLog->Log(_L("Leave in RunL %d"),aError); |
|
103 return aError; |
|
104 } |
|
105 |
|
106 // --------------------------------------------------------- |
|
107 // CTestPositionServer::PositionServer |
|
108 // |
|
109 // (other items are commented in a header). |
|
110 // --------------------------------------------------------- |
|
111 // |
|
112 RPositionServer& CTestPositionServer::PositionServer() |
|
113 { |
|
114 return iPosServer; |
|
115 } |
|
116 |
|
117 // --------------------------------------------------------- |
|
118 // CTestPositionServer::Connect |
|
119 // |
|
120 // (other items are commented in a header). |
|
121 // --------------------------------------------------------- |
|
122 // |
|
123 TInt CTestPositionServer::Connect() |
|
124 { |
|
125 TInt err = iPosServer.Connect(); |
|
126 if(err != KErrNone) |
|
127 { |
|
128 TBuf<100> msg; |
|
129 msg.Copy(_L("Position server connect failed with error code :")); |
|
130 msg.AppendNum(err); |
|
131 iLog->Log(msg); |
|
132 } |
|
133 else |
|
134 { |
|
135 iLog->Log(_L("Position Server connect - passed")); |
|
136 } |
|
137 return err; |
|
138 } |
|
139 |
|
140 // --------------------------------------------------------- |
|
141 // CTestPositionServer::Disconnect |
|
142 // |
|
143 // (other items are commented in a header). |
|
144 // --------------------------------------------------------- |
|
145 // |
|
146 TInt CTestPositionServer::Disconnect() |
|
147 { |
|
148 iPosServer.Close(); |
|
149 iLog->Log(_L("Closing Position Server - passed")); |
|
150 return KErrNone; |
|
151 } |
|
152 |
|
153 // --------------------------------------------------------- |
|
154 // CTestPositionServer::Disconnect |
|
155 // |
|
156 // (other items are commented in a header). |
|
157 // --------------------------------------------------------- |
|
158 // |
|
159 TInt CTestPositionServer::VersionCheck() |
|
160 { |
|
161 TVersion ver = iPosServer.Version(); |
|
162 if(ver.iMajor == 1 && ver.iMinor == 0 && ver.iBuild == 0 ) |
|
163 { |
|
164 iLog->Log(_L("Version numbers are Verified to be correct!")); |
|
165 return KErrNone; |
|
166 } |
|
167 else |
|
168 { |
|
169 iLog->Log(_L("Wrong Version")); |
|
170 return KErrGeneral; |
|
171 } |
|
172 } |
|
173 |
|
174 // --------------------------------------------------------- |
|
175 // CTestPositionServer::GetDefaultModule |
|
176 // |
|
177 // (other items are commented in a header). |
|
178 // --------------------------------------------------------- |
|
179 // |
|
180 TInt CTestPositionServer::GetDefaultModule() |
|
181 { |
|
182 TPositionModuleId moduleId; |
|
183 TInt err = iPosServer.GetDefaultModuleId(moduleId); |
|
184 TBuf<100> msg; |
|
185 |
|
186 if(err != KErrNone) |
|
187 { |
|
188 msg.Copy(_L("GetDefaultModule failed with error code :")); |
|
189 msg.AppendNum(err); |
|
190 iLog->Log(msg); |
|
191 } |
|
192 else |
|
193 { |
|
194 msg.Copy(_L("GetDefaultModule passed Id of Module is:")); |
|
195 msg.AppendNumUC(moduleId.iUid, EHex); |
|
196 iLog->Log(msg); |
|
197 } |
|
198 |
|
199 return err; |
|
200 |
|
201 } |
|
202 |
|
203 // --------------------------------------------------------- |
|
204 // CTestPositionServer::GetModuleNum |
|
205 // |
|
206 // (other items are commented in a header). |
|
207 // --------------------------------------------------------- |
|
208 // |
|
209 TInt CTestPositionServer::GetModuleNum() |
|
210 { |
|
211 TInt err; |
|
212 TUint number; |
|
213 |
|
214 err = iPosServer.GetNumModules(number); |
|
215 TBuf<100> msg; |
|
216 |
|
217 if(err != KErrNone) |
|
218 { |
|
219 msg.Copy(_L("GetModuleNumPanic failed with error code :")); |
|
220 msg.AppendNum(err); |
|
221 iLog->Log(msg); |
|
222 } |
|
223 else |
|
224 { |
|
225 msg.Copy(_L("GetModuleNumPanic passed Number of Module is:")); |
|
226 msg.AppendNum(number); |
|
227 iLog->Log(msg); |
|
228 } |
|
229 |
|
230 return err; |
|
231 } |
|
232 |
|
233 // --------------------------------------------------------- |
|
234 // CTestPositionServer::GetModuleInfoIndex |
|
235 // |
|
236 // (other items are commented in a header). |
|
237 // --------------------------------------------------------- |
|
238 // |
|
239 TInt CTestPositionServer::GetModuleInfoIndex(TInt aIndex) |
|
240 { |
|
241 TPositionModuleInfo infoModule; |
|
242 TInt err; |
|
243 err = iPosServer.GetModuleInfoByIndex(aIndex,infoModule); |
|
244 TBuf<100> msg; |
|
245 |
|
246 if(err != KErrNone) |
|
247 { |
|
248 msg.Copy(_L("GetModuleInfoByIndex failed with error code :")); |
|
249 msg.AppendNum(err); |
|
250 iLog->Log(msg); |
|
251 } |
|
252 else |
|
253 { |
|
254 TBuf<100> moduleName; |
|
255 infoModule.GetModuleName(moduleName); |
|
256 msg.Copy(_L("GetModuleInfoByIndex passed Module Name is:")); |
|
257 msg.Append(moduleName); |
|
258 iLog->Log(msg); |
|
259 } |
|
260 |
|
261 return err; |
|
262 |
|
263 } |
|
264 |
|
265 // --------------------------------------------------------- |
|
266 // CTestPositionServer::GetModuleInfoId |
|
267 // |
|
268 // (other items are commented in a header). |
|
269 // --------------------------------------------------------- |
|
270 // |
|
271 TInt CTestPositionServer::GetModuleInfoId(TPositionModuleId aUid) |
|
272 { |
|
273 TPositionModuleInfo infoModule; |
|
274 TInt err; |
|
275 |
|
276 err = iPosServer.GetModuleInfoById(aUid,infoModule); |
|
277 TBuf<100> msg; |
|
278 if(err != KErrNone) |
|
279 { |
|
280 msg.Copy(_L("GetModuleInfoById failed with error code :")); |
|
281 msg.AppendNum(err); |
|
282 iLog->Log(msg); |
|
283 } |
|
284 else |
|
285 { |
|
286 TBuf<100> moduleName; |
|
287 infoModule.GetModuleName(moduleName); |
|
288 msg.Copy(_L("GetModuleInfoById passed Module Name is:")); |
|
289 msg.Append(moduleName); |
|
290 iLog->Log(msg); |
|
291 } |
|
292 |
|
293 return err; |
|
294 |
|
295 } |
|
296 |
|
297 // --------------------------------------------------------- |
|
298 // CTestPositionServer::GetModuleStatus |
|
299 // |
|
300 // (other items are commented in a header). |
|
301 // --------------------------------------------------------- |
|
302 // |
|
303 TInt CTestPositionServer::GetModuleStatus(TPositionModuleId aUid) |
|
304 { |
|
305 TPositionModuleStatus moduleStatus; |
|
306 TInt err; |
|
307 TBuf<100> msg; |
|
308 err = iPosServer.GetModuleStatus(moduleStatus,aUid); |
|
309 if(err != KErrNone) |
|
310 { |
|
311 msg.Copy(_L("GetModuleStatus failed with error code :")); |
|
312 msg.AppendNum(err); |
|
313 iLog->Log(msg); |
|
314 } |
|
315 else |
|
316 { |
|
317 TBuf<20> intStatus; |
|
318 intStatus.Num(moduleStatus.DeviceStatus()); |
|
319 msg.Copy(_L("GetModuleStatus passed Device Status is :")); |
|
320 msg.Append(intStatus); |
|
321 iLog->Log(msg); |
|
322 } |
|
323 return err; |
|
324 |
|
325 } |
|
326 |
|
327 // --------------------------------------------------------- |
|
328 // CTestPositionServer::GetModuleChangeNotification |
|
329 // |
|
330 // (other items were commented in a header). |
|
331 // --------------------------------------------------------- |
|
332 // |
|
333 TInt CTestPositionServer::GetModuleChangeNotification(TInt aEvent, TPositionModuleId aUid) |
|
334 { |
|
335 TPositionModuleStatus moduleStatus; |
|
336 TPositionModuleStatusEventBase::_TModuleEvent event = TPositionModuleStatusEvent::EEventNone; |
|
337 |
|
338 //Setting of Event type according to aEvent parameter |
|
339 switch(aEvent) |
|
340 { |
|
341 case 0: |
|
342 event = TPositionModuleStatusEvent::EEventNone; |
|
343 break; |
|
344 case 4: |
|
345 event = TPositionModuleStatusEvent::EEventAll; |
|
346 break; |
|
347 } |
|
348 iModuleEvent.SetRequestedEvents(event); |
|
349 |
|
350 // Asynchronous module status |
|
351 iPosServer.NotifyModuleStatusEvent(iModuleEvent, iStatus, aUid); |
|
352 |
|
353 if(0 != aEvent) |
|
354 { |
|
355 SetActive(); |
|
356 TInt err = iPositioner.Open(iPosServer, aUid); |
|
357 CActiveScheduler::Start(); |
|
358 |
|
359 iPositioner.Close(); |
|
360 } |
|
361 TBuf<100> msg; |
|
362 msg.Copy(_L("In GetModuleChangeNotificationErr1: NotifyModuleStatusEvent returned with :")); |
|
363 msg.AppendNum(iStatus.Int()); |
|
364 iLog->Log(msg); |
|
365 return iStatus.Int(); |
|
366 } |
|
367 |
|
368 // --------------------------------------------------------- |
|
369 // CTestPositionServer::GetModuleChangeNotificationCancel |
|
370 // |
|
371 // (other items were commented in a header). |
|
372 // --------------------------------------------------------- |
|
373 // |
|
374 TInt CTestPositionServer::GetModuleChangeNotificationCancel(TInt aEvent, TPositionModuleId aUid) |
|
375 { |
|
376 TPositionModuleStatus moduleStatus; |
|
377 TPositionModuleStatusEventBase::_TModuleEvent event = TPositionModuleStatusEvent::EEventNone; |
|
378 |
|
379 //Setting of Event type according to aEvent parameter |
|
380 switch(aEvent) |
|
381 { |
|
382 case 0: |
|
383 event = TPositionModuleStatusEvent::EEventNone; |
|
384 break; |
|
385 case 4: |
|
386 event = TPositionModuleStatusEvent::EEventAll; |
|
387 break; |
|
388 } |
|
389 iModuleEvent.SetRequestedEvents(event); |
|
390 |
|
391 // Asynchronous module status |
|
392 iPosServer.NotifyModuleStatusEvent(iModuleEvent, iStatus, aUid); |
|
393 SetActive(); |
|
394 iLog->Log(_L("Started RunSession with status %d"),iStatus.Int()); |
|
395 |
|
396 Cancel(); |
|
397 |
|
398 TBuf<100> msg; |
|
399 msg.Copy(_L("In GetModuleChangeNotificationErr2: NotifyModuleStatusEvent returned with :")); |
|
400 msg.AppendNum(iStatus.Int()); |
|
401 iLog->Log(msg); |
|
402 return iStatus.Int(); |
|
403 } |
|
404 |
|
405 // --------------------------------------------------------- |
|
406 // CTestPositionServer::DisconnectPanicOutstanding |
|
407 // |
|
408 // (other items were commented in a header). |
|
409 // --------------------------------------------------------- |
|
410 // |
|
411 void CTestPositionServer::DisconnectPanicOutstanding(TInt aEvent, TPositionModuleId aUid) |
|
412 { |
|
413 TPositionModuleStatus moduleStatus; |
|
414 TPositionModuleStatusEventBase::_TModuleEvent event = TPositionModuleStatusEvent::EEventNone; |
|
415 |
|
416 //Setting of Event type according to aEvent parameter |
|
417 switch(aEvent) |
|
418 { |
|
419 case 0: |
|
420 event = TPositionModuleStatusEvent::EEventNone; |
|
421 break; |
|
422 case 4: |
|
423 event = TPositionModuleStatusEvent::EEventAll; |
|
424 break; |
|
425 } |
|
426 iModuleEvent.SetRequestedEvents(event); |
|
427 |
|
428 // Asynchronous module status |
|
429 iPosServer.NotifyModuleStatusEvent(iModuleEvent, iStatus, aUid); |
|
430 SetActive(); |
|
431 |
|
432 TBuf<100> msg; |
|
433 msg.Copy(_L("In DisconnectPanicOutstanding returned with :")); |
|
434 msg.AppendNum(iStatus.Int()); |
|
435 iLog->Log(msg); |
|
436 iPosServer.Close(); |
|
437 } |
|
438 |
|
439 // --------------------------------------------------------- |
|
440 // CTestPositionServer::GetModuleChangeNotificationPanicDuplicate |
|
441 // |
|
442 // (other items were commented in a header). |
|
443 // --------------------------------------------------------- |
|
444 // |
|
445 void CTestPositionServer::GetModuleChangeNotificationPanicDuplicate(TInt aEvent, TPositionModuleId aUid) |
|
446 { |
|
447 TPositionModuleStatus moduleStatus; |
|
448 TPositionModuleStatusEventBase::_TModuleEvent event = TPositionModuleStatusEvent::EEventNone; |
|
449 |
|
450 //Setting of Event type according to aEvent parameter |
|
451 switch(aEvent) |
|
452 { |
|
453 case 0: |
|
454 event = TPositionModuleStatusEvent::EEventNone; |
|
455 break; |
|
456 case 4: |
|
457 event = TPositionModuleStatusEvent::EEventAll; |
|
458 break; |
|
459 } |
|
460 iModuleEvent.SetRequestedEvents(event); |
|
461 |
|
462 // Asynchronous module status |
|
463 iPosServer.NotifyModuleStatusEvent(iModuleEvent, iStatus, aUid); |
|
464 SetActive(); |
|
465 TRequestStatus status; |
|
466 iPosServer.NotifyModuleStatusEvent(iModuleEvent, status, aUid); |
|
467 User::WaitForRequest(status); |
|
468 |
|
469 } |
|
470 |