|
1 /* |
|
2 * Copyright (c) 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: Testing context wrapper |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include <e32std.h> |
|
21 |
|
22 #include <eunitmacros.h> |
|
23 |
|
24 #include "prfwtestcontextwrapper.h" |
|
25 #include <ximpclient.h> |
|
26 #include <ximpcontext.h> |
|
27 #include <ximpcontextstateevent.h> |
|
28 #include <ximprequestcompleteevent.h> |
|
29 #include <ximpstatus.h> |
|
30 #include <presencefeatures.h> |
|
31 |
|
32 |
|
33 #include "prfwteststatuseventlistener.h" |
|
34 #include "prfwtestmessenger.h" |
|
35 #include "prfwtestmessaging.h" |
|
36 #include "prfwtestfiletool.h" |
|
37 #include "prfwtestprotocols.h" |
|
38 |
|
39 _LIT( KInstanceAsNumber, "%d" ); |
|
40 // ======== LOCAL FUNCTIONS ======== |
|
41 |
|
42 // --------------------------------------------------------------------------- |
|
43 // Length of number in characters (e.g. 501 --> 3) |
|
44 // --------------------------------------------------------------------------- |
|
45 // |
|
46 TInt NumLenInChars( TInt aNum ) |
|
47 { |
|
48 TInt len = 0; |
|
49 TInt tmp = aNum; |
|
50 do |
|
51 { |
|
52 tmp /= 10; // number is base-10 |
|
53 len++; |
|
54 } |
|
55 while ( tmp > 0 ); |
|
56 return len; |
|
57 } |
|
58 |
|
59 |
|
60 // ======== MEMBER FUNCTIONS ======== |
|
61 |
|
62 // --------------------------------------------------------------------------- |
|
63 // Instance id |
|
64 // --------------------------------------------------------------------------- |
|
65 // |
|
66 EXPORT_C const TDesC16& CXIMPTestContextWrapper::InstanceId() const |
|
67 { |
|
68 return *iInstance; |
|
69 } |
|
70 |
|
71 |
|
72 // --------------------------------------------------------------------------- |
|
73 // ?description_if_needed |
|
74 // --------------------------------------------------------------------------- |
|
75 // |
|
76 CXIMPTestContextWrapper::CXIMPTestContextWrapper( TInt aIndex, |
|
77 MXIMPClient* aClient ) : |
|
78 iIndex( aIndex ), |
|
79 iClient( aClient ) |
|
80 { |
|
81 } |
|
82 |
|
83 // --------------------------------------------------------------------------- |
|
84 // ?description_if_needed |
|
85 // --------------------------------------------------------------------------- |
|
86 // |
|
87 void CXIMPTestContextWrapper::ConstructL() |
|
88 { |
|
89 iContext = iClient->NewPresenceContextLC(); |
|
90 CleanupStack::Pop(); // iContext |
|
91 iListener = CXIMPTestStatusEventListener::NewL( 20, iContext ); |
|
92 iMessenger = CXIMPTestMessenger::NewForClientSideL( iIndex ); |
|
93 iPresFeatures = MPresenceFeatures::NewL(iContext); |
|
94 TInt instanceLength = NumLenInChars( iIndex ); |
|
95 iInstance = HBufC::NewL( instanceLength ); |
|
96 iInstance->Des().AppendFormat( KInstanceAsNumber, iIndex ); |
|
97 } |
|
98 |
|
99 // --------------------------------------------------------------------------- |
|
100 // ?description_if_needed |
|
101 // --------------------------------------------------------------------------- |
|
102 // |
|
103 EXPORT_C CXIMPTestContextWrapper* CXIMPTestContextWrapper::NewL( |
|
104 TInt aIndex, MXIMPClient* aClient ) |
|
105 { |
|
106 CXIMPTestContextWrapper* self = new( ELeave ) CXIMPTestContextWrapper( aIndex, aClient ); |
|
107 CleanupStack::PushL( self ); |
|
108 self->ConstructL(); |
|
109 CleanupStack::Pop( self ); |
|
110 return self; |
|
111 } |
|
112 |
|
113 // --------------------------------------------------------------------------- |
|
114 // ?description_if_needed |
|
115 // --------------------------------------------------------------------------- |
|
116 // |
|
117 CXIMPTestContextWrapper::~CXIMPTestContextWrapper() |
|
118 { |
|
119 iStatusEventTraits.Close(); |
|
120 |
|
121 delete iMessenger; |
|
122 delete iListener; |
|
123 delete iContext; |
|
124 delete iFileTool; |
|
125 delete iInstance; |
|
126 delete iPresFeatures; |
|
127 } |
|
128 |
|
129 // --------------------------------------------------------------------------- |
|
130 // ?description_if_needed |
|
131 // --------------------------------------------------------------------------- |
|
132 // |
|
133 EXPORT_C MXIMPContext* CXIMPTestContextWrapper::GetContext() |
|
134 { |
|
135 return iContext; |
|
136 } |
|
137 |
|
138 // --------------------------------------------------------------------------- |
|
139 // ?description_if_needed |
|
140 // --------------------------------------------------------------------------- |
|
141 // |
|
142 EXPORT_C MPresenceFeatures* CXIMPTestContextWrapper::GetPresenceFeatures() |
|
143 { |
|
144 return iPresFeatures; |
|
145 } |
|
146 // --------------------------------------------------------------------------- |
|
147 // ?description_if_needed |
|
148 // --------------------------------------------------------------------------- |
|
149 // |
|
150 EXPORT_C CXIMPTestStatusEventListener* CXIMPTestContextWrapper::GetEventListener() |
|
151 { |
|
152 return iListener; |
|
153 } |
|
154 |
|
155 // --------------------------------------------------------------------------- |
|
156 // ?description_if_needed |
|
157 // --------------------------------------------------------------------------- |
|
158 // |
|
159 EXPORT_C CXIMPTestMessenger* CXIMPTestContextWrapper::GetMessenger() |
|
160 { |
|
161 return iMessenger; |
|
162 } |
|
163 |
|
164 // --------------------------------------------------------------------------- |
|
165 // ?description_if_needed |
|
166 // --------------------------------------------------------------------------- |
|
167 // |
|
168 EXPORT_C MXIMPClient* CXIMPTestContextWrapper::GetClient() |
|
169 { |
|
170 return iClient; |
|
171 } |
|
172 |
|
173 // --------------------------------------------------------------------------- |
|
174 // ?description_if_needed |
|
175 // --------------------------------------------------------------------------- |
|
176 // |
|
177 EXPORT_C void CXIMPTestContextWrapper::DeletePresenceContext() |
|
178 { |
|
179 // used to test abrupt handle closings |
|
180 iListener->SetEventSourceL( NULL ); |
|
181 delete iContext; |
|
182 iContext = NULL; |
|
183 } |
|
184 |
|
185 // --------------------------------------------------------------------------- |
|
186 // ?description_if_needed |
|
187 // --------------------------------------------------------------------------- |
|
188 // |
|
189 EXPORT_C void CXIMPTestContextWrapper::SetupEmptyListener() |
|
190 { |
|
191 iListener->ResetEventStack(); |
|
192 iStatusEventTraits.Reset(); |
|
193 } |
|
194 |
|
195 // --------------------------------------------------------------------------- |
|
196 // ?description_if_needed |
|
197 // --------------------------------------------------------------------------- |
|
198 // |
|
199 EXPORT_C RArray<TXIMPTestStatusEventSnapshot>* CXIMPTestContextWrapper::GetStatusTraits() |
|
200 { |
|
201 return &iStatusEventTraits; |
|
202 } |
|
203 |
|
204 // --------------------------------------------------------------------------- |
|
205 // ?description_if_needed |
|
206 // --------------------------------------------------------------------------- |
|
207 // |
|
208 EXPORT_C void CXIMPTestContextWrapper::SetupListenerL( TXIMPTestStatusEventTemplate aEventType ) |
|
209 { |
|
210 ResetListener(); |
|
211 iListener->GetEventTemplateL( iStatusEventTraits, aEventType ); |
|
212 iMessenger->SetPluginIndex( iIndex ); |
|
213 } |
|
214 |
|
215 // --------------------------------------------------------------------------- |
|
216 // ?description_if_needed |
|
217 // --------------------------------------------------------------------------- |
|
218 // |
|
219 EXPORT_C void CXIMPTestContextWrapper::AppendToTraitsL( TXIMPTestStatusEventTemplate aEventType ) |
|
220 { |
|
221 iListener->GetEventTemplateL( iStatusEventTraits, aEventType ); |
|
222 } |
|
223 |
|
224 // --------------------------------------------------------------------------- |
|
225 // ?description_if_needed |
|
226 // --------------------------------------------------------------------------- |
|
227 // |
|
228 EXPORT_C void CXIMPTestContextWrapper::SetupListenerReqCompleteL( |
|
229 TXIMPTestStatusEventTemplate aEventType, |
|
230 RArray< TInt32 >* aAdditionalEvents ) |
|
231 { |
|
232 iListener->ResetEventStack(); |
|
233 iListener->AcceptedEventTypes().Reset(); |
|
234 iListener->AcceptedEventTypes().AppendL( MXIMPRequestCompleteEvent::KInterfaceId ); |
|
235 |
|
236 if ( aAdditionalEvents ) |
|
237 { |
|
238 for ( TInt i = 0; i < aAdditionalEvents->Count(); i++ ) |
|
239 { |
|
240 iListener->AcceptedEventTypes().AppendL( (*aAdditionalEvents)[ i ] ); |
|
241 } |
|
242 } |
|
243 |
|
244 iListener->ReRegisterEventFilterL(); |
|
245 iStatusEventTraits.Reset(); |
|
246 iListener->GetEventTemplateL( iStatusEventTraits, aEventType ); |
|
247 |
|
248 iMessenger->SetPluginIndex( iIndex ); |
|
249 } |
|
250 |
|
251 // --------------------------------------------------------------------------- |
|
252 // ?description_if_needed |
|
253 // --------------------------------------------------------------------------- |
|
254 // |
|
255 EXPORT_C void CXIMPTestContextWrapper::ClearListener() |
|
256 { |
|
257 iListener->ResetEventStack(); |
|
258 iListener->SetEventSourceL( NULL ); |
|
259 |
|
260 iStatusEventTraits.Reset(); |
|
261 } |
|
262 |
|
263 |
|
264 // --------------------------------------------------------------------------- |
|
265 // ?description_if_needed |
|
266 // --------------------------------------------------------------------------- |
|
267 // |
|
268 EXPORT_C void CXIMPTestContextWrapper::ResetListener() |
|
269 { |
|
270 iListener->ResetEventStack(); |
|
271 iListener->ResetEventTypeStack(); |
|
272 iStatusEventTraits.Reset(); |
|
273 iListener->ReRegisterEventFilterL(); |
|
274 } |
|
275 |
|
276 // --------------------------------------------------------------------------- |
|
277 // ?description_if_needed |
|
278 // --------------------------------------------------------------------------- |
|
279 // |
|
280 EXPORT_C void CXIMPTestContextWrapper::WaitRequestAndStackEvents( TXIMPRequestId aReqId ) |
|
281 { |
|
282 iListener->WaitRequestAndStackEvents( aReqId ); |
|
283 } |
|
284 |
|
285 // --------------------------------------------------------------------------- |
|
286 // ?description_if_needed |
|
287 // --------------------------------------------------------------------------- |
|
288 // |
|
289 EXPORT_C void CXIMPTestContextWrapper::VerifyEventStackL( const TPtrC8& aDesc ) |
|
290 { |
|
291 iListener->VerifyEventStackL( iStatusEventTraits.Array(), aDesc ); |
|
292 } |
|
293 |
|
294 // --------------------------------------------------------------------------- |
|
295 // CXIMPTestContextWrapper::WaitAnyEvent |
|
296 // --------------------------------------------------------------------------- |
|
297 // |
|
298 EXPORT_C void CXIMPTestContextWrapper::WaitAnyEvent() |
|
299 { |
|
300 iListener->WaitAnyEvent(); |
|
301 } |
|
302 |
|
303 // --------------------------------------------------------------------------- |
|
304 // ?description_if_needed |
|
305 // --------------------------------------------------------------------------- |
|
306 // |
|
307 EXPORT_C void CXIMPTestContextWrapper::BindL( |
|
308 TUid aUid, |
|
309 const TDesC& aServer, |
|
310 const TDesC& aUser, |
|
311 const TDesC& aPassword ) |
|
312 { |
|
313 SetupListenerL( EXIMPTestStatusEvents_BindingOk ); |
|
314 iMessenger->SetNoError(); |
|
315 iMessenger->SetPluginIndex( iIndex ); |
|
316 |
|
317 delete iFileTool; |
|
318 iFileTool = NULL; |
|
319 iFileTool = CXIMPTestFileTool::NewL( aUid.iUid, iIndex ); |
|
320 |
|
321 TXIMPRequestId reqId = iContext->BindToL( |
|
322 aUid, |
|
323 aServer, |
|
324 aUser, |
|
325 aPassword, |
|
326 *iInstance, |
|
327 iIndex ); |
|
328 |
|
329 WaitRequestAndStackEvents( reqId ); |
|
330 VerifyEventStackL( _L8("Binding (wrapper BindL): ") ); |
|
331 |
|
332 EUNIT_ASSERT_DESC( iMessenger->GetBoolean( EXIMPPlgTestOpenSessionCalled ) || |
|
333 iMessenger->GetBoolean( EXIMPPlgTestShareSessionCalled ), "OpenSessionL was not called" ); |
|
334 } |
|
335 |
|
336 // --------------------------------------------------------------------------- |
|
337 // Bind alternative |
|
338 // --------------------------------------------------------------------------- |
|
339 // |
|
340 const TUid KTestProtocolUid = { K_PRFW_TST_PROTOCOL_1_IMPLEMENTATION_UID }; // hardcoded... |
|
341 |
|
342 _LIT( KTestFakeServer, "www.imps%d.no/wv" ); |
|
343 _LIT( KTestFakeUser, "user%d" ); |
|
344 _LIT( KTestFakePassword, "password%d" ); |
|
345 |
|
346 EXPORT_C void CXIMPTestContextWrapper::BindL( TInt aId ) |
|
347 { |
|
348 SetupListenerL( EXIMPTestStatusEvents_BindingOk ); |
|
349 iMessenger->SetNoError(); |
|
350 iMessenger->SetPluginIndex( aId ); |
|
351 |
|
352 // create fake info |
|
353 TInt extraLength = 8; // bad style... but length is enough |
|
354 |
|
355 HBufC* fakeSrv = HBufC::NewLC( KTestFakeServer().Length() + extraLength ); |
|
356 fakeSrv->Des().AppendFormat( KTestFakeServer, aId ); |
|
357 |
|
358 HBufC* fakeUser = HBufC::NewLC( KTestFakeUser().Length() + extraLength ); |
|
359 fakeUser->Des().AppendFormat( KTestFakeUser, aId ); |
|
360 |
|
361 HBufC* fakePass = HBufC::NewLC( KTestFakePassword().Length() + extraLength ); |
|
362 fakePass->Des().AppendFormat( KTestFakePassword, aId ); |
|
363 |
|
364 delete iFileTool; |
|
365 iFileTool = NULL; |
|
366 iFileTool = CXIMPTestFileTool::NewL( KTestProtocolUid.iUid, iIndex ); |
|
367 |
|
368 TXIMPRequestId reqId = iContext->BindToL( |
|
369 KTestProtocolUid, |
|
370 *fakeSrv, |
|
371 *fakeUser, |
|
372 *fakePass, |
|
373 *iInstance, |
|
374 aId ); |
|
375 |
|
376 CleanupStack::PopAndDestroy( 3, fakeSrv ); |
|
377 |
|
378 WaitRequestAndStackEvents( reqId ); |
|
379 VerifyEventStackL( _L8("Binding (wrapper BindL): ") ); |
|
380 |
|
381 EUNIT_ASSERT_DESC( iMessenger->GetBoolean( EXIMPPlgTestOpenSessionCalled ) || |
|
382 iMessenger->GetBoolean( EXIMPPlgTestShareSessionCalled ), "OpenSessionL was not called" ); |
|
383 } |
|
384 |
|
385 |
|
386 |
|
387 ///NEW BIND |
|
388 EXPORT_C void CXIMPTestContextWrapper::BindWithSettingsL( TInt aId ) |
|
389 { |
|
390 SetupListenerL( EXIMPTestStatusEvents_BindingOk ); |
|
391 iMessenger->SetNoError(); |
|
392 iMessenger->SetPluginIndex( 0/*aId*/ ); |
|
393 |
|
394 // create fake info |
|
395 TInt extraLength = 8; // bad style... but length is enough |
|
396 |
|
397 HBufC* fakeSrv = HBufC::NewLC( KTestFakeServer().Length() + extraLength ); |
|
398 fakeSrv->Des().AppendFormat( KTestFakeServer, aId ); |
|
399 |
|
400 HBufC* fakeUser = HBufC::NewLC( KTestFakeUser().Length() + extraLength ); |
|
401 fakeUser->Des().AppendFormat( KTestFakeUser, aId ); |
|
402 |
|
403 HBufC* fakePass = HBufC::NewLC( KTestFakePassword().Length() + extraLength ); |
|
404 fakePass->Des().AppendFormat( KTestFakePassword, aId ); |
|
405 |
|
406 delete iFileTool; |
|
407 iFileTool = NULL; |
|
408 iFileTool = CXIMPTestFileTool::NewL( KTestProtocolUid.iUid, iIndex ); |
|
409 |
|
410 TXIMPRequestId reqId = iContext->BindToL( |
|
411 KTestProtocolUid, aId ); |
|
412 |
|
413 CleanupStack::PopAndDestroy( 3, fakeSrv ); |
|
414 |
|
415 WaitRequestAndStackEvents( reqId ); |
|
416 VerifyEventStackL( _L8("Binding (wrapper BindWithSettingsL): ") ); |
|
417 |
|
418 EUNIT_ASSERT_DESC( iMessenger->GetBoolean( EXIMPPlgTestOpenSessionCalled ) || |
|
419 iMessenger->GetBoolean( EXIMPPlgTestShareSessionCalled ), "OpenSessionL was not called" ); |
|
420 } |
|
421 |
|
422 // --------------------------------------------------------------------------- |
|
423 // ?description_if_needed |
|
424 // --------------------------------------------------------------------------- |
|
425 // |
|
426 EXPORT_C void CXIMPTestContextWrapper::UnbindL() |
|
427 { |
|
428 SetupListenerL( EXIMPTestStatusEvents_UnbindingOk ); |
|
429 iMessenger->SetNoError(); |
|
430 TXIMPRequestId reqId = iContext->UnbindL(); |
|
431 |
|
432 WaitRequestAndStackEvents( reqId ); |
|
433 VerifyEventStackL( _L8("Unbinding (wrapper UnbindL): ") ); |
|
434 |
|
435 EUNIT_ASSERT_DESC( iMessenger->GetBoolean( EXIMPPlgTestCloseSessionCalled ) || |
|
436 iMessenger->GetBoolean( EXIMPPlgTestUnshareSessionCalled ) , "CloseSession was not called" ); |
|
437 if( iMessenger->GetBoolean( EXIMPPlgTestCloseSessionCalled ) ) |
|
438 { |
|
439 DeletePresenceContext(); |
|
440 //EUNIT_ASSERT_DESC( iMessenger->GetBoolean( EXIMPPlgTestDeath ), "Plugin did not die, destructor not called."); |
|
441 } |
|
442 } |
|
443 |
|
444 // --------------------------------------------------------------------------- |
|
445 // ?description_if_needed |
|
446 // --------------------------------------------------------------------------- |
|
447 // |
|
448 EXPORT_C CXIMPTestFileTool& CXIMPTestContextWrapper::FileTool() const |
|
449 { |
|
450 return *iFileTool; |
|
451 } |
|
452 |
|
453 // End of file |