|
1 /* |
|
2 * Copyright (c) 2009 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: |
|
15 * |
|
16 */ |
|
17 #include "LocationManagerTestScripter.h" |
|
18 #include "mdeobject.h" |
|
19 #include "mdenamespacedef.h" |
|
20 #include "mdeobjectdef.h" |
|
21 #include "mdepropertydef.h" |
|
22 #include "mdeconstants.h" |
|
23 #include "locationdatatype.h" |
|
24 #include "mdsutils.h" |
|
25 #include <etel3rdparty.h> |
|
26 #include <StifTestEventInterface.h> |
|
27 #include <StifParser.h> |
|
28 #include <StifTestEventInterface.h> |
|
29 #include <StifTestInterface.h> |
|
30 |
|
31 using namespace MdeConstants; |
|
32 |
|
33 TInt CLocationManagerTestScripter::PrepareSessionL( CStifItemParser& /*aItem*/ ) |
|
34 { |
|
35 _LIT( KMsg1, "PrepareSessionL" ); |
|
36 iLog->Log( KMsg1 ); |
|
37 RDebug::Print( KMsg1 ); |
|
38 |
|
39 User::LeaveIfError( iOM.Connect() ); |
|
40 iMdeSession = CMdESession::NewL( *this ); |
|
41 |
|
42 return KErrNone; |
|
43 } |
|
44 |
|
45 TInt CLocationManagerTestScripter::SetupOML( CStifItemParser& /*aItem*/ ) |
|
46 { |
|
47 _LIT( KMsg1, "Enter SetupOM" ); |
|
48 iLog->Log( KMsg1 ); |
|
49 RDebug::Print( KMsg1 ); |
|
50 |
|
51 iSourceObject = CreateMetadataObjectL(); |
|
52 TLocationData locationData; |
|
53 TestLocationData( locationData ); |
|
54 TInt error( KErrNone ); |
|
55 error = iOM.CreateLocationObject( locationData, iSourceObject->Id() ); |
|
56 if( error != KErrNone ) |
|
57 { |
|
58 return error; |
|
59 } |
|
60 iTargetObject = CreateMetadataObjectL(); |
|
61 |
|
62 _LIT( KMsg2, "Exit SetupOM" ); |
|
63 iLog->Log( KMsg2 ); |
|
64 RDebug::Print( KMsg2 ); |
|
65 |
|
66 return KErrNone; |
|
67 } |
|
68 |
|
69 TInt CLocationManagerTestScripter::LocationSnapshotL( CStifItemParser& /*aItem*/ ) |
|
70 { |
|
71 _LIT( KMsg1, "Enter LocationSnapshotL" ); |
|
72 iLog->Log( KMsg1 ); |
|
73 RDebug::Print( KMsg1 ); |
|
74 |
|
75 iSourceObject = CreateMetadataObjectL(); |
|
76 TInt error( KErrNone ); |
|
77 error = iOM.LocationSnapshot( iSourceObject->Id() ); |
|
78 |
|
79 _LIT( KMsg2, "Exit LocationSnapshotL" ); |
|
80 iLog->Log( KMsg2 ); |
|
81 RDebug::Print( KMsg2 ); |
|
82 |
|
83 return error; |
|
84 } |
|
85 |
|
86 TInt CLocationManagerTestScripter::RemoveLocationObjectL( CStifItemParser& /*aItem*/ ) |
|
87 { |
|
88 _LIT( KMsg1, "Enter RemoveLocationObjectL" ); |
|
89 iLog->Log( KMsg1 ); |
|
90 RDebug::Print( KMsg1 ); |
|
91 |
|
92 TInt error( KErrNone ); |
|
93 error = iOM.RemoveLocationObject( iSourceObject->Id() ); |
|
94 |
|
95 _LIT( KMsg2, "Exit RemoveLocationObjectL" ); |
|
96 iLog->Log( KMsg2 ); |
|
97 RDebug::Print( KMsg2 ); |
|
98 |
|
99 return error; |
|
100 } |
|
101 |
|
102 TInt CLocationManagerTestScripter::TearDownOML( CStifItemParser& /*aItem*/ ) |
|
103 { |
|
104 _LIT( KMsg1, "Enter TearDownOM" ); |
|
105 iLog->Log( KMsg1 ); |
|
106 RDebug::Print( KMsg1 ); |
|
107 |
|
108 iOM.Close(); |
|
109 |
|
110 if( iSourceObject && iMdeSession ) |
|
111 { |
|
112 TRAP_IGNORE( iMdeSession->RemoveObjectL( iSourceObject->Id() ) ); |
|
113 } |
|
114 delete iSourceObject; |
|
115 iSourceObject = NULL; |
|
116 if( iTargetObject && iMdeSession ) |
|
117 { |
|
118 TRAP_IGNORE( iMdeSession->RemoveObjectL( iTargetObject->Id() ) ); |
|
119 } |
|
120 delete iTargetObject; |
|
121 iTargetObject = NULL; |
|
122 delete iMdeSession; |
|
123 iMdeSession = NULL; |
|
124 |
|
125 _LIT( KMsg2, "Exit TearDownOM" ); |
|
126 iLog->Log( KMsg2 ); |
|
127 RDebug::Print( KMsg2 ); |
|
128 |
|
129 return KErrNone; |
|
130 } |
|
131 |
|
132 TInt CLocationManagerTestScripter::CloseOML( CStifItemParser& /*aItem*/ ) |
|
133 { |
|
134 _LIT( KMsg1, "CloseOML" ); |
|
135 iLog->Log( KMsg1 ); |
|
136 RDebug::Print( KMsg1 ); |
|
137 |
|
138 iOM.Close(); |
|
139 |
|
140 return KErrNone; |
|
141 } |
|
142 |
|
143 TInt CLocationManagerTestScripter::RLocationObjectManipulatorTest_CopyByIDL( CStifItemParser& /*aItem*/ ) |
|
144 { |
|
145 _LIT( KMsg1, "Enter RLocationObjectManipulatorTest_CopyByIDL" ); |
|
146 iLog->Log( KMsg1 ); |
|
147 RDebug::Print( KMsg1 ); |
|
148 |
|
149 TRequestStatus status = KRequestPending; |
|
150 RArray<TItemId> items; |
|
151 items.Append( iTargetObject->Id() ); |
|
152 iOM.CopyLocationData( iSourceObject->Id(), items, status ); |
|
153 User::WaitForRequest( status ); |
|
154 TL( status.Int() == KErrNone ); |
|
155 |
|
156 status = KRequestPending; |
|
157 iOM.CopyLocationData( TItemId(12345678), items, status ); |
|
158 User::WaitForRequest( status ); |
|
159 TL( status.Int() == KErrNotFound ); |
|
160 |
|
161 items.Reset(); |
|
162 items.Append(TItemId(12345678)); |
|
163 status = KRequestPending; |
|
164 iOM.CopyLocationData( iSourceObject->Id(), items, status ); |
|
165 User::WaitForRequest( status ); |
|
166 TL( status.Int() == KErrNotFound ); |
|
167 |
|
168 status = KRequestPending; |
|
169 iOM.CopyLocationData( TItemId(12345678), items, status ); |
|
170 User::WaitForRequest( status ); |
|
171 TL( status.Int() == KErrNotFound ); |
|
172 |
|
173 items.Close(); |
|
174 |
|
175 _LIT( KMsg2, "Exit RLocationObjectManipulatorTest_CopyByIDL" ); |
|
176 iLog->Log( KMsg2 ); |
|
177 RDebug::Print( KMsg2 ); |
|
178 |
|
179 return KErrNone; |
|
180 } |
|
181 |
|
182 TInt CLocationManagerTestScripter::RLocationObjectManipulatorTest_CopyByURIL( CStifItemParser& /*aItem*/ ) |
|
183 { |
|
184 _LIT(KURIThatDoesNotExist, "qwerty"); |
|
185 |
|
186 TRequestStatus status = KRequestPending; |
|
187 RPointerArray<TDesC> items; |
|
188 items.AppendL( &iTargetObject->Uri() ); |
|
189 TBuf<256> source( iSourceObject->Uri() ); |
|
190 iOM.CopyLocationData( source, items, status ); |
|
191 User::WaitForRequest( status ); |
|
192 TL( status.Int() == KErrNone ); |
|
193 |
|
194 source.Copy( KURIThatDoesNotExist ); |
|
195 status = KRequestPending; |
|
196 iOM.CopyLocationData( source, items, status ); |
|
197 User::WaitForRequest( status ); |
|
198 TL( status.Int() == KErrNotFound ); |
|
199 |
|
200 items.Reset(); |
|
201 HBufC* nouri = source.AllocL(); |
|
202 items.Append( nouri ); |
|
203 source.Copy( iSourceObject->Uri() ); |
|
204 status = KRequestPending; |
|
205 iOM.CopyLocationData( source, items, status ); |
|
206 User::WaitForRequest( status ); |
|
207 TL( status.Int() == KErrNotFound ); |
|
208 |
|
209 status = KRequestPending; |
|
210 source.Copy( KURIThatDoesNotExist ); |
|
211 iOM.CopyLocationData( source, items, status ); |
|
212 User::WaitForRequest( status ); |
|
213 TL( status.Int() == KErrNotFound ); |
|
214 |
|
215 items.ResetAndDestroy(); |
|
216 |
|
217 return KErrNone; |
|
218 } |
|
219 |
|
220 TInt CLocationManagerTestScripter::RLocationObjectManipulatorTest_CopyByID_DisconnectedL( |
|
221 CStifItemParser& /*aItem*/ ) |
|
222 { |
|
223 TRequestStatus status = KRequestPending; |
|
224 RArray<TItemId> items; |
|
225 items.Append( 97976479 ); |
|
226 iOM.CopyLocationData( iSourceObject->Id(), items, status ); |
|
227 User::WaitForRequest( status ); |
|
228 TL( status.Int() == KErrDisconnected ); |
|
229 |
|
230 return KErrNone; |
|
231 } |
|
232 |
|
233 TInt CLocationManagerTestScripter::RLocationObjectManipulatorTest_CopyByURI_DisconnectedL( |
|
234 CStifItemParser& /*aItem*/ ) |
|
235 { |
|
236 _LIT(KURIThatDoesNotExist, "notexistinganywhere"); |
|
237 |
|
238 TRequestStatus status = KRequestPending; |
|
239 RPointerArray<TDesC> items; |
|
240 items.AppendL( &KURIThatDoesNotExist ); |
|
241 TBuf<256> source( iSourceObject->Uri() ); |
|
242 iOM.CopyLocationData( source, items, status ); |
|
243 User::WaitForRequest( status ); |
|
244 TL( status.Int() == KErrDisconnected ); |
|
245 |
|
246 return KErrNone; |
|
247 } |
|
248 |
|
249 CMdEObject* CLocationManagerTestScripter::CreateMetadataObjectL( ) |
|
250 { |
|
251 CMdENamespaceDef& namespaceDef = iMdeSession->GetDefaultNamespaceDefL(); |
|
252 CMdEObjectDef& objectDef = namespaceDef.GetObjectDefL( Image::KImageObject ); |
|
253 CMdEObject *obj = iMdeSession->NewObjectLC( objectDef, Object::KAutomaticUri ); |
|
254 |
|
255 // required object properties |
|
256 CMdEPropertyDef& creationDef = objectDef.GetPropertyDefL( Object::KCreationDateProperty ); |
|
257 CMdEPropertyDef& modifiedDef = objectDef.GetPropertyDefL( Object::KLastModifiedDateProperty ); |
|
258 CMdEPropertyDef& sizeDef = objectDef.GetPropertyDefL( Object::KSizeProperty ); |
|
259 CMdEPropertyDef& itemTypeDef = objectDef.GetPropertyDefL( Object::KItemTypeProperty ); |
|
260 |
|
261 TTime timestamp( 0 ); |
|
262 timestamp.UniversalTime(); |
|
263 |
|
264 // required object properties |
|
265 obj->AddTimePropertyL( creationDef, timestamp ); |
|
266 obj->AddTimePropertyL( modifiedDef, timestamp ); |
|
267 obj->AddUint32PropertyL( sizeDef, 0 ); // always zero size for location objects |
|
268 obj->AddTextPropertyL( itemTypeDef, Location::KLocationItemType ); |
|
269 |
|
270 iMdeSession->AddObjectL( *obj ); |
|
271 CMdEObject* obj2 = iMdeSession->GetObjectL( obj->Id() ); |
|
272 CleanupStack::Pop( obj ); |
|
273 |
|
274 return obj2; |
|
275 } |
|
276 |
|
277 void CLocationManagerTestScripter::HandleSessionOpened(CMdESession& /*aSession*/, TInt aError) |
|
278 { |
|
279 _LIT( KMsg, "CallBck HandleSessionOpened - Error code : %d" ); |
|
280 TBuf <100> msg; |
|
281 msg.Format(KMsg, aError); |
|
282 iLog->Log( msg ); |
|
283 RDebug::Print(msg); |
|
284 |
|
285 // session event |
|
286 TEventIf event( TEventIf::ESetEvent, _L("Session") ); |
|
287 TestModuleIf().Event( event ); |
|
288 } |
|
289 |
|
290 void CLocationManagerTestScripter::HandleSessionError(CMdESession& /*aSession*/, TInt aError) |
|
291 { |
|
292 _LIT( KMsg, "CallBck HandleSessionError - Error code : %d" ); |
|
293 TBuf <100> msg; |
|
294 msg.Format(KMsg, aError); |
|
295 iLog->Log( msg ); |
|
296 RDebug::Print(msg); |
|
297 |
|
298 // session event |
|
299 TEventIf event( TEventIf::ESetEvent, _L("Session") ); |
|
300 TestModuleIf().Event( event ); |
|
301 } |
|
302 |
|
303 void CLocationManagerTestScripter::TestLocationData( TLocationData& aLocationData ) |
|
304 { |
|
305 _LIT( temp, "XXX" ); |
|
306 TBuf<3> countryTxt( temp ); |
|
307 |
|
308 TPosition testLocality; |
|
309 testLocality.SetCoordinate( (TReal64)Math::Random()/KMaxTUint*180.0, (TReal64)Math::Random()/KMaxTUint*90.0, 10.0 ); |
|
310 testLocality.SetAccuracy( 2.0, 2.0 ); |
|
311 |
|
312 CTelephony::TNetworkInfoV1 networkInfo; |
|
313 networkInfo.iAccess = CTelephony::ENetworkAccessGsm; |
|
314 networkInfo.iAreaKnown = ETrue; |
|
315 networkInfo.iBandInfo = CTelephony::E800BandA; |
|
316 networkInfo.iCellId = 1; |
|
317 networkInfo.iLocationAreaCode = 1; |
|
318 networkInfo.iMode = CTelephony::ENetworkModeGsm; |
|
319 networkInfo.iStatus = CTelephony::ENetworkStatusCurrent; |
|
320 networkInfo.iCountryCode = countryTxt; |
|
321 networkInfo.iNetworkId = countryTxt; |
|
322 |
|
323 TCourse kurssi; |
|
324 kurssi.SetCourse( 1.0 ); |
|
325 kurssi.SetCourseAccuracy( 1.0 ); |
|
326 kurssi.SetHeading( 10.0 ); |
|
327 kurssi.SetSpeed( 10.0 ); |
|
328 |
|
329 aLocationData.iPosition = testLocality; |
|
330 aLocationData.iCountry = countryTxt; |
|
331 aLocationData.iNetworkInfo = networkInfo; |
|
332 aLocationData.iSatellites = 4; |
|
333 aLocationData.iCourse = kurssi; |
|
334 aLocationData.iQuality = 1; |
|
335 } |
|
336 |
|
337 // End of file |
|
338 |