|
1 /* |
|
2 * Copyright (c) 2002 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 the License "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: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include <e32svr.h> |
|
23 #include <StifParser.h> |
|
24 #include <Stiftestinterface.h> |
|
25 #include "sapiloctotest.h" |
|
26 #include <f32file.h> |
|
27 #include <LbsPosition.h> |
|
28 |
|
29 |
|
30 _LIT(LogFileName , "C:\\Notifications.txt") ; |
|
31 TInt returnCode; |
|
32 RFile LogFile ; |
|
33 RFs LogSession ; |
|
34 |
|
35 void OpenFile() |
|
36 { |
|
37 LogSession.Connect() ; |
|
38 |
|
39 if(LogFile.Open(LogSession ,LogFileName , EFileWrite | EFileShareAny ) == KErrNotFound) |
|
40 { |
|
41 LogFile.Create(LogSession ,LogFileName , EFileWrite | EFileShareAny ) ; |
|
42 } |
|
43 |
|
44 TInt End = 0 ; |
|
45 LogFile.Seek(ESeekEnd , End) ; |
|
46 } |
|
47 |
|
48 void CloseFile() |
|
49 { |
|
50 LogFile.Close() ; |
|
51 LogSession.Close() ; |
|
52 } |
|
53 |
|
54 TInt ValidatePosition(TPosition& aPos) |
|
55 { |
|
56 TReal64 aLatitude = aPos.Latitude(); |
|
57 TReal64 aLongitude = aPos.Longitude() ; |
|
58 TReal32 aAltitude = aPos.Altitude() ; |
|
59 |
|
60 if( (-90<=aLatitude<=90) && (-180<=aLongitude<=180) && (aAltitude) ) |
|
61 { |
|
62 OpenFile(); |
|
63 TBuf8<50> buf ; |
|
64 TRealFormat format ; |
|
65 |
|
66 //Logging Latitude |
|
67 buf.Num(aLatitude , format) ; |
|
68 LogFile.Write(_L8("Latitude = ")); |
|
69 LogFile.Write(buf) ; |
|
70 LogFile.Write(_L8("\n")) ; |
|
71 //Logging Longitude |
|
72 buf.Num(aLongitude , format); |
|
73 LogFile.Write(_L8("Longitude = ")); |
|
74 LogFile.Write(buf) ; |
|
75 LogFile.Write(_L8("\n")) ; |
|
76 //Logging Altitude |
|
77 buf.Num(aAltitude , format) ; |
|
78 LogFile.Write(_L8("Altitude = ")); |
|
79 LogFile.Write(buf) ; |
|
80 LogFile.Write(_L8("\n")) ; |
|
81 CloseFile(); |
|
82 return KErrNone; |
|
83 } |
|
84 else |
|
85 { |
|
86 OpenFile(); |
|
87 LogFile.Write(_L8("Test case failed..")); |
|
88 CloseFile(); |
|
89 return KErrGeneral; |
|
90 } |
|
91 } |
|
92 |
|
93 void Csapiloctotest::Delete() |
|
94 { |
|
95 |
|
96 } |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // Csapiloctotest::RunMethodL |
|
100 // Run specified method. Contains also table of test mothods and their names. |
|
101 // ----------------------------------------------------------------------------- |
|
102 // |
|
103 TInt Csapiloctotest::RunMethodL( |
|
104 CStifItemParser& aItem ) |
|
105 { |
|
106 |
|
107 static TStifFunctionInfo const KFunctions[] = |
|
108 { |
|
109 // Copy this line for every implemented function. |
|
110 // First string is the function name used in TestScripter script file. |
|
111 // Second is the actual implementation member function. |
|
112 ENTRY( "GetPositionTO", Csapiloctotest::GetPositionTO ), |
|
113 // ENTRY( "GetPositionAsyncTO", Csapiloctotest::GetPositionAsyncTO ), |
|
114 // ENTRY( "TraceLPositionTO", Csapiloctotest::TraceLPositionTO), |
|
115 |
|
116 }; |
|
117 |
|
118 const TInt count = sizeof( KFunctions ) / |
|
119 sizeof( TStifFunctionInfo ); |
|
120 |
|
121 return RunInternalL( KFunctions, count, aItem ); |
|
122 |
|
123 } |
|
124 |
|
125 // ----------------------------------------------------------------------------- |
|
126 // Csapiloctotest::GetPositionTO |
|
127 // ----------------------------------------------------------------------------- |
|
128 // |
|
129 TInt Csapiloctotest::GetPositionTO( CStifItemParser& /*aItem*/ ) |
|
130 { |
|
131 TInt aRet; |
|
132 TPositionInfo currpos; |
|
133 returnCode = KErrNone; |
|
134 |
|
135 // Print to UI |
|
136 _LIT( KSAPILocTest, "SAPILocTest" ); |
|
137 _LIT( KExample, "GetLocationTO" ); |
|
138 TestModuleIf().Printf( 0, KSAPILocTest, KExample ); |
|
139 |
|
140 __UHEAP_MARK; |
|
141 |
|
142 CLocationService *CoreObj = CLocationService :: NewL(); |
|
143 |
|
144 if( NULL == CoreObj ) |
|
145 { |
|
146 OpenFile(); |
|
147 LogFile.Write(_L8("\n<GetPositionTO Test>\n")); |
|
148 LogFile.Write(_L8("Failed..\n")); |
|
149 CloseFile(); |
|
150 return KErrGeneral; |
|
151 } |
|
152 |
|
153 _LIT(Kidentity ,"Coreclass Testing" ) ; |
|
154 //Not required anymore |
|
155 /*RRequestorStack aRequestorStack; |
|
156 const CRequestor* identityInfo = CRequestor::NewL(1 , 1 , Kidentity) ; |
|
157 aRequestorStack.Insert(identityInfo,0); |
|
158 CoreObj->SetRequestorIdentityL(aRequestorStack) ;*/ |
|
159 |
|
160 aRet = CoreObj->GetLocationL(&currpos); |
|
161 |
|
162 if( KErrTimedOut == aRet ) |
|
163 { |
|
164 OpenFile(); |
|
165 LogFile.Write(_L8("\n<GetPositionTO Test>\n")); |
|
166 LogFile.Write(_L8("Passed..\n")); |
|
167 CloseFile(); |
|
168 returnCode = KErrNone; |
|
169 } |
|
170 |
|
171 else |
|
172 { |
|
173 OpenFile(); |
|
174 LogFile.Write(_L8("\n<GetPositionTO Test>\n")); |
|
175 LogFile.Write(_L8("Failed..\n")); |
|
176 CloseFile(); |
|
177 returnCode = KErrGeneral; |
|
178 } |
|
179 |
|
180 /*delete identityInfo; |
|
181 aRequestorStack.Close();*/ |
|
182 delete CoreObj; |
|
183 |
|
184 __UHEAP_MARKEND; |
|
185 |
|
186 return KErrNone; |
|
187 |
|
188 } |
|
189 |
|
190 |
|
191 // ----------------------------------------------------------------------------- |
|
192 // Csapiloctotest::GetPositionAsyncTO |
|
193 // ----------------------------------------------------------------------------- |
|
194 // |
|
195 /*class LocUpdateCallBackTO : public MLocationCallBack |
|
196 { |
|
197 TInt iCount ; |
|
198 TInt iRetStatus ; |
|
199 public : |
|
200 TInt HandleNotifyL(HPositionGenericInfo *aOutPos , TInt aError) ; |
|
201 LocUpdateCallBackTO() :iCount(0) , iRetStatus(KErrGeneral) //Default constructor |
|
202 {;} |
|
203 }; |
|
204 |
|
205 |
|
206 TInt LocUpdateCallBackTO :: HandleNotifyL(HPositionGenericInfo *currPos , TInt aError) |
|
207 { |
|
208 |
|
209 if(KErrTimedOut == aError) |
|
210 { |
|
211 OpenFile(); |
|
212 LogFile.Write(_L8("\n<GetPositionAsyncTO test>\n ")); |
|
213 LogFile.Write(_L8("Passed..\n ")); |
|
214 CloseFile(); |
|
215 returnCode = KErrNone; |
|
216 } |
|
217 |
|
218 else |
|
219 { |
|
220 OpenFile(); |
|
221 LogFile.Write(_L8("\n<GetPositionAsyncTO test>\n ")); |
|
222 LogFile.Write(_L8("Failed..\n ")); |
|
223 CloseFile(); |
|
224 returnCode = KErrGeneral; |
|
225 } |
|
226 |
|
227 CActiveScheduler *Current = CActiveScheduler :: Current() ; |
|
228 |
|
229 Current->Stop() ; |
|
230 |
|
231 return KErrNone ; |
|
232 } |
|
233 |
|
234 TInt GetLocFunctionTOL() |
|
235 { |
|
236 CLocationService *CoreObj = CLocationService ::NewL() ; |
|
237 |
|
238 if( NULL == CoreObj ) |
|
239 { |
|
240 OpenFile(); |
|
241 LogFile.Write(_L8("\n<GetPositionAsyncTO Test>\n")); |
|
242 LogFile.Write(_L8("Failed..\n")); |
|
243 CloseFile(); |
|
244 return KErrGeneral; |
|
245 } |
|
246 |
|
247 _LIT(Kidentity ,"Coreclass Testing" ) ; |
|
248 |
|
249 RRequestorStack aRequestorStack; |
|
250 const CRequestor* identityInfo = CRequestor::NewL(1 , 1 , Kidentity) ; |
|
251 aRequestorStack.Insert(identityInfo,0); |
|
252 |
|
253 CoreObj->SetRequestorIdentityL(aRequestorStack) ; |
|
254 |
|
255 LocUpdateCallBackTO MyUpdates ; |
|
256 CoreObj->GetLocationL(&MyUpdates) ; |
|
257 CActiveScheduler :: Start() ; |
|
258 |
|
259 aRequestorStack.Close(); |
|
260 delete identityInfo; |
|
261 delete CoreObj; |
|
262 return KErrNone; |
|
263 } |
|
264 |
|
265 |
|
266 TInt Csapiloctotest::GetPositionAsyncTO( CStifItemParser& aItem ) |
|
267 { |
|
268 TInt aRet = KErrNone; |
|
269 TRequestStatus status = KRequestPending; |
|
270 returnCode = KErrNone; |
|
271 // Print to UI |
|
272 _LIT( KSAPILocTest, "SAPILocTest" ); |
|
273 _LIT( KExample, "GetPositionAsyncTO" ); |
|
274 TestModuleIf().Printf( 0, KSAPILocTest, KExample ); |
|
275 |
|
276 __UHEAP_MARK; |
|
277 |
|
278 TRAPD(err , aRet = GetLocFunctionTOL()) ; |
|
279 |
|
280 if( err || aRet ) |
|
281 returnCode = KErrGeneral; |
|
282 |
|
283 __UHEAP_MARKEND; |
|
284 |
|
285 return returnCode; |
|
286 } |
|
287 |
|
288 */ |
|
289 // ----------------------------------------------------------------------------- |
|
290 // Csapiloctotest::TraceLPositionTO |
|
291 // ----------------------------------------------------------------------------- |
|
292 // |
|
293 |
|
294 /*class TraceLCallBackTO : public MLocationCallBack |
|
295 { |
|
296 TInt iCount ; |
|
297 TInt iRetStatus ; |
|
298 public : |
|
299 TInt HandleNotifyL(HPositionGenericInfo *aOutPos , TInt aError) ; |
|
300 TraceLCallBackTO() :iCount(0) , iRetStatus(KErrGeneral){;} |
|
301 }; |
|
302 |
|
303 TInt TraceLCallBackTO :: HandleNotifyL(HPositionGenericInfo *currPos , TInt aError) |
|
304 { |
|
305 |
|
306 if(KErrTimedOut == aError) |
|
307 { |
|
308 CActiveScheduler *Current = CActiveScheduler :: Current() ; |
|
309 Current->Stop() ; |
|
310 OpenFile(); |
|
311 LogFile.Write(_L8("Passed..\n")); |
|
312 CloseFile(); |
|
313 returnCode = KErrNone; |
|
314 return KErrNone ; |
|
315 } |
|
316 else |
|
317 { |
|
318 CActiveScheduler *Current = CActiveScheduler :: Current() ; |
|
319 Current->Stop() ; |
|
320 OpenFile(); |
|
321 LogFile.Write(_L8("Failed..\n")); |
|
322 CloseFile(); |
|
323 returnCode = KErrGeneral; |
|
324 return KErrNone; |
|
325 } |
|
326 |
|
327 } |
|
328 |
|
329 |
|
330 TInt TraceLFunctionTOL() |
|
331 { |
|
332 TInt ret1; |
|
333 TPositionInfo aPosition1; |
|
334 CLocationService *CoreObj = CLocationService ::NewL() ; |
|
335 |
|
336 if( NULL == CoreObj ) |
|
337 { |
|
338 OpenFile(); |
|
339 LogFile.Write(_L8("\n<TraceLPositionTO Test>\n")); |
|
340 LogFile.Write(_L8("Failed..\n")); |
|
341 CloseFile(); |
|
342 return KErrGeneral; |
|
343 } |
|
344 |
|
345 _LIT(Kidentity ,"Coreclass Testing" ) ; |
|
346 RRequestorStack aRequestorStack; |
|
347 const CRequestor* identityInfo = CRequestor::NewL(1 , 1 , Kidentity) ; |
|
348 aRequestorStack.Insert(identityInfo,0); |
|
349 CoreObj->SetRequestorIdentityL(aRequestorStack) ; |
|
350 |
|
351 TraceLCallBackTO MyUpdates ; |
|
352 |
|
353 ret1 = CoreObj->TraceL(&MyUpdates) ; |
|
354 |
|
355 if( KErrNone == ret1 ) |
|
356 { |
|
357 OpenFile(); |
|
358 LogFile.Write(_L8("\n<TraceLPosition test>\n")); |
|
359 CloseFile(); |
|
360 returnCode = KErrNone; |
|
361 CActiveScheduler :: Start() ; |
|
362 } |
|
363 |
|
364 else |
|
365 { |
|
366 returnCode = KErrGeneral; |
|
367 } |
|
368 |
|
369 aRequestorStack.Close(); |
|
370 delete identityInfo; |
|
371 delete CoreObj; |
|
372 return 0; |
|
373 } |
|
374 |
|
375 |
|
376 TInt Csapiloctotest::TraceLPositionTO( CStifItemParser& aItem ) |
|
377 { |
|
378 TInt aRet = KErrNone; |
|
379 returnCode = KErrNone; |
|
380 |
|
381 // Print to UI |
|
382 _LIT( KSAPILocTest, "SAPILocTest" ); |
|
383 _LIT( KExample, "TraceLPositionTO" ); |
|
384 TestModuleIf().Printf( 0, KSAPILocTest, KExample ); |
|
385 |
|
386 __UHEAP_MARK; |
|
387 |
|
388 TRAPD(err ,aRet = TraceLFunctionTOL()) ; |
|
389 if( err || aRet ) |
|
390 returnCode = KErrGeneral; |
|
391 |
|
392 __UHEAP_MARKEND; |
|
393 |
|
394 return returnCode; |
|
395 } */ |