748
|
1 |
// Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
872
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
748
|
5 |
// which accompanies this distribution, and is available
|
872
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
748
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
//
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
// INCLUDE FILES
|
|
19 |
#include "ctlbsclientpostp213.h"
|
|
20 |
#include "ctlbsclientrequestor.h"
|
|
21 |
#include "ctlbsclienteventtimer.h"
|
|
22 |
#include <LbsPositionInfo.h>
|
|
23 |
#include <Lbs.h>
|
|
24 |
#include <LbsCommon.h>
|
|
25 |
#include <LbsRequestor.h>
|
|
26 |
#include <s32file.h>
|
|
27 |
|
|
28 |
// CONSTANTS
|
|
29 |
_LIT(KClient1, "RunL client1");
|
|
30 |
_LIT(KClient2, "RunL client2");
|
|
31 |
_LIT(KClient3, "RunL client3");
|
|
32 |
|
|
33 |
_LIT(KClient1Default, "RunL client1, default psy");
|
|
34 |
_LIT(KClient2Default, "RunL client2, default psy");
|
|
35 |
_LIT(KClient3Default, "RunL client3, default psy");
|
|
36 |
|
|
37 |
//Error logs
|
|
38 |
_LIT( KErrStatusMismatch, "Statuses does not conform to each other!" );
|
|
39 |
_LIT( KEventReceived, "Client 3 received an event that shouldn't be received!" );
|
|
40 |
_LIT( KCanceledRequest, "Client 2 didn't receive KErrCancel, but %d!" );
|
|
41 |
_LIT( KFileNotDeleted, "File created by PSY NOT deleted! PSY really unloaded from memory?" );
|
|
42 |
|
|
43 |
//File name. Beware, also declared in EPos_CTestStatusPsy.h!!!!
|
|
44 |
_LIT(KDummyFileName, "c:\\TestStatusPsyIsNotUnloaded.txt");
|
|
45 |
|
|
46 |
// ================= MEMBER FUNCTIONS =======================
|
|
47 |
|
|
48 |
// Constructor.
|
|
49 |
CT_LbsClientPosTp213::CT_LbsClientPosTp213(CT_LbsServer& aParent): CT_LbsPortedStepBase(aParent)
|
|
50 |
{
|
|
51 |
_LIT(KTestName, "TP213 - Disabling psy during request");
|
|
52 |
SetTestStepName(KTestName);
|
|
53 |
}
|
|
54 |
|
|
55 |
// Destructor
|
|
56 |
CT_LbsClientPosTp213::~CT_LbsClientPosTp213()
|
|
57 |
{
|
|
58 |
}
|
|
59 |
|
|
60 |
// ---------------------------------------------------------
|
|
61 |
// CT_LbsClientPosTp213::CloseTest
|
|
62 |
//
|
|
63 |
// (other items were commented in a header).
|
|
64 |
// ---------------------------------------------------------
|
|
65 |
//
|
|
66 |
void CT_LbsClientPosTp213::CloseTest()
|
|
67 |
{
|
|
68 |
delete ieventtimer;
|
|
69 |
ieventtimer = NULL;
|
|
70 |
|
|
71 |
delete iclient1;
|
|
72 |
delete iclient2;
|
|
73 |
delete iclient3;
|
|
74 |
}
|
|
75 |
|
|
76 |
// ---------------------------------------------------------
|
|
77 |
// CT_LbsClientPosTp213::StartL
|
|
78 |
//
|
|
79 |
// (other items were commented in a header).
|
|
80 |
// ---------------------------------------------------------
|
|
81 |
//
|
|
82 |
void CT_LbsClientPosTp213::StartL()
|
|
83 |
{
|
|
84 |
TBool usedefaultpsy = FALSE; // Indicating if the default psy should be used
|
|
85 |
iNoFurtherEvents = FALSE; // Client should receive events!
|
|
86 |
iErrorDuringExecution = FALSE; // True if an error occurs
|
|
87 |
|
|
88 |
//Enable PSY
|
|
89 |
CPosModules* idb = CPosModules::OpenL();
|
|
90 |
CleanupStack::PushL(idb);
|
|
91 |
_LIT(KEnablePSY, "Enabling Test Status PSY");
|
|
92 |
INFO_PRINTF1(KEnablePSY);
|
|
93 |
EnablePsyL(*idb, iUidTestStatusPsy);
|
|
94 |
|
|
95 |
// Event timer
|
|
96 |
ieventtimer = CT_LbsClientEventTimer::NewL(Logger());
|
|
97 |
ieventtimer->SetObserver(this);
|
|
98 |
|
|
99 |
// 3 clients
|
|
100 |
iclient1 = CT_LbsClientRequestor::NewL(iUidTestStatusPsy, this, KClient1, Logger());
|
|
101 |
iclient2 = CT_LbsClientRequestor::NewL(iUidTestStatusPsy, this, KClient2, Logger());
|
|
102 |
iclient3 = CT_LbsClientRequestor::NewL(iUidTestStatusPsy, this, KClient3, Logger());
|
|
103 |
|
|
104 |
// Make a request with client 2
|
|
105 |
_LIT(KRequestClient2, "Calling StartRequestL for client2");
|
|
106 |
INFO_PRINTF1(KRequestClient2);
|
|
107 |
iclient2->StartRequestL(usedefaultpsy);
|
|
108 |
|
|
109 |
// Make client3 listen for status events
|
|
110 |
iclient3->RequestModuleStatusEvent();
|
|
111 |
|
|
112 |
// Disable Psy 3
|
|
113 |
User::After(100000); //a small delay
|
|
114 |
_LIT(KDisablePSY, "Disabling Test Status PSY");
|
|
115 |
INFO_PRINTF1(KDisablePSY);
|
|
116 |
DisablePsyL(*idb, iUidTestStatusPsy);
|
|
117 |
|
|
118 |
// Client1 reads Module Status
|
|
119 |
// Client API
|
|
120 |
TInt clientapistatus = iclient1->ReadModuleStatusClientApi(iUidTestStatusPsy);
|
|
121 |
_LIT(KClientApi, "Module Status from Client API: %d.");
|
|
122 |
TBuf<100> bufclientapi;
|
|
123 |
bufclientapi.Format(KClientApi, clientapistatus);
|
|
124 |
INFO_PRINTF1(bufclientapi);
|
|
125 |
|
|
126 |
// Modules API
|
|
127 |
TInt modulesapistatus = iclient1->ReadModuleStatusModulesApi(idb, iUidTestStatusPsy);
|
|
128 |
_LIT(KModulesApi, "Module Status from Module API: (IsAvailable=) %d.");
|
|
129 |
TBuf<100> bufmodulesapi;
|
|
130 |
bufmodulesapi.Format(KModulesApi, modulesapistatus);
|
|
131 |
INFO_PRINTF1(bufmodulesapi);
|
|
132 |
// Compare received statuses
|
|
133 |
if ( !((modulesapistatus == 0) && (clientapistatus == TPositionModuleStatus::EDeviceDisabled)) )
|
|
134 |
{
|
|
135 |
iErrorDuringExecution = TRUE;
|
|
136 |
ERR_PRINTF1(KErrStatusMismatch);
|
|
137 |
}
|
|
138 |
|
|
139 |
iclient2->ClosePositioner();
|
|
140 |
|
|
141 |
delete iclient1;
|
|
142 |
delete iclient2;
|
|
143 |
delete iclient3;
|
|
144 |
|
|
145 |
///////////////////// Default PSY /////////////////////////////////////
|
|
146 |
|
|
147 |
// Do the same as before but now use the default PSY
|
|
148 |
iNoFurtherEvents = FALSE; // Client should receive events!
|
|
149 |
_LIT(KDefaultPsyStart, "****** Testing Default PSY ******");
|
|
150 |
INFO_PRINTF1(KDefaultPsyStart);
|
|
151 |
|
|
152 |
// Enable Psy
|
|
153 |
INFO_PRINTF1(KEnablePSY);
|
|
154 |
EnablePsyL(*idb, iUidTestStatusPsy);
|
|
155 |
|
|
156 |
// 3 clients
|
|
157 |
iclient1 = CT_LbsClientRequestor::NewL(iUidTestStatusPsy, this, KClient1Default, Logger());
|
|
158 |
iclient2 = CT_LbsClientRequestor::NewL(iUidTestStatusPsy, this, KClient2Default, Logger());
|
|
159 |
iclient3 = CT_LbsClientRequestor::NewL(iUidTestStatusPsy, this, KClient3Default, Logger());
|
|
160 |
|
|
161 |
// Make a request with client 2
|
|
162 |
INFO_PRINTF1(KRequestClient2);
|
|
163 |
iclient2->StartRequestL(usedefaultpsy);
|
|
164 |
|
|
165 |
// Make client3 listen for status events
|
|
166 |
iclient3->RequestModuleStatusEvent();
|
|
167 |
|
|
168 |
// Disable Psy 3
|
|
169 |
User::After(1000000); //A small delay
|
|
170 |
usedefaultpsy = TRUE; //Use default PSY
|
|
171 |
INFO_PRINTF1(KDisablePSY);
|
|
172 |
DisablePsyL(*idb, iUidTestStatusPsy);
|
|
173 |
|
|
174 |
// Client1 reads Module Status
|
|
175 |
// Client API
|
|
176 |
clientapistatus = iclient1->ReadModuleStatusClientApi(iUidTestStatusPsy);
|
|
177 |
bufclientapi.Format(KClientApi, clientapistatus);
|
|
178 |
INFO_PRINTF1(bufclientapi);
|
|
179 |
|
|
180 |
// Modules API
|
|
181 |
modulesapistatus = iclient1->ReadModuleStatusModulesApi(idb, iUidTestStatusPsy);
|
|
182 |
bufmodulesapi.Format(KModulesApi, modulesapistatus);
|
|
183 |
INFO_PRINTF1(bufmodulesapi);
|
|
184 |
// Compare received statuses
|
|
185 |
if ( !((modulesapistatus == 0) && (clientapistatus == TPositionModuleStatus::EDeviceDisabled)) )
|
|
186 |
{
|
|
187 |
iErrorDuringExecution = TRUE;
|
|
188 |
ERR_PRINTF1(KErrStatusMismatch);
|
|
189 |
}
|
|
190 |
|
|
191 |
iclient2->ClosePositioner();
|
|
192 |
|
|
193 |
delete iclient1;
|
|
194 |
iclient1 = NULL;
|
|
195 |
delete iclient2;
|
|
196 |
iclient2 = NULL;
|
|
197 |
delete iclient3;
|
|
198 |
iclient3 = NULL;
|
|
199 |
|
|
200 |
// Connect to EPos
|
|
201 |
User::LeaveIfError(iPosServer.Connect());
|
|
202 |
|
|
203 |
// Enable Psy
|
|
204 |
INFO_PRINTF1(KEnablePSY);
|
|
205 |
EnablePsyL(*idb, iUidTestStatusPsy);
|
|
206 |
|
|
207 |
// Open subsession to Status Psy that still is disabled!!!
|
|
208 |
_LIT(KInfoStatusPSY, "Calling OpenPositionerByName for Test Status PSY");
|
|
209 |
INFO_PRINTF1(KInfoStatusPSY);
|
|
210 |
TInt err = OpenPositionerByName(iUidTestStatusPsy);
|
|
211 |
User::After(100000); //A small delay
|
|
212 |
|
|
213 |
if (err != KErrNone)
|
|
214 |
{
|
|
215 |
_LIT(KErrorRequest, "OpenPositionerByName failed, errCode = %d");
|
|
216 |
TBuf<100> buf;
|
|
217 |
buf.Format(KErrorRequest, err);
|
|
218 |
LogErrorAndLeaveL(buf);
|
|
219 |
}
|
|
220 |
|
|
221 |
// Make a position request
|
|
222 |
_LIT(KService, "service");
|
|
223 |
TPositionInfo positionInfo = TPositionInfo();
|
|
224 |
_LIT(KPerformSyncRequest, "Calling PerformSyncRequest");
|
|
225 |
INFO_PRINTF1(KPerformSyncRequest);
|
|
226 |
err = PerformSyncRequest(KService, &positionInfo);
|
|
227 |
|
|
228 |
if (err != KErrNone)
|
|
229 |
{
|
|
230 |
_LIT(KErrorRequest, "The last request was not completed with KErrorNone, errCode = %d");
|
|
231 |
TBuf<100> buf;
|
|
232 |
buf.Format(KErrorRequest, err);
|
|
233 |
LogErrorAndLeaveL(buf);
|
|
234 |
}
|
|
235 |
|
|
236 |
//Close Positioner
|
|
237 |
ClosePositioner();
|
|
238 |
|
|
239 |
//Disconnect from Epos
|
|
240 |
Disconnect();
|
|
241 |
|
|
242 |
CleanupStack::PopAndDestroy(idb);
|
|
243 |
|
|
244 |
//Checking if any errors occured during execution
|
|
245 |
if (iErrorDuringExecution)
|
|
246 |
{
|
|
247 |
_LIT(KErrorAndLeave, "Error(s) occured during execution, closing test!");
|
|
248 |
LogErrorAndLeaveL(KErrorAndLeave);
|
|
249 |
}
|
|
250 |
}
|
|
251 |
|
|
252 |
// ---------------------------------------------------------
|
|
253 |
// CT_LbsClientPosTp213::EnablePsyL
|
|
254 |
//
|
|
255 |
// (other items were commented in a header).
|
|
256 |
// ---------------------------------------------------------
|
|
257 |
//
|
|
258 |
void CT_LbsClientPosTp213::EnablePsyL(
|
|
259 |
CPosModules& aDb,
|
|
260 |
TUid aPsy)
|
|
261 |
{
|
|
262 |
CPosModuleUpdate* moduleUpdate = CPosModuleUpdate::NewLC();
|
|
263 |
// Enable Psy
|
|
264 |
moduleUpdate->SetUpdateAvailability(ETrue);
|
|
265 |
aDb.UpdateModuleL(aPsy, *moduleUpdate);
|
|
266 |
CleanupStack::PopAndDestroy(moduleUpdate);
|
|
267 |
}
|
|
268 |
|
|
269 |
// ---------------------------------------------------------
|
|
270 |
// CT_LbsClientPosTp213::DisablePsyL
|
|
271 |
//
|
|
272 |
// (other items were commented in a header).
|
|
273 |
// ---------------------------------------------------------
|
|
274 |
//
|
|
275 |
void CT_LbsClientPosTp213::DisablePsyL(
|
|
276 |
CPosModules& aDb,
|
|
277 |
TUid aPsy)
|
|
278 |
{
|
|
279 |
CPosModuleUpdate* moduleUpdate = CPosModuleUpdate::NewLC();
|
|
280 |
// Disable Psy
|
|
281 |
moduleUpdate->SetUpdateAvailability(EFalse);
|
|
282 |
aDb.UpdateModuleL(aPsy, *moduleUpdate);
|
|
283 |
CleanupStack::PopAndDestroy(moduleUpdate);
|
|
284 |
}
|
|
285 |
|
|
286 |
// ---------------------------------------------------------
|
|
287 |
// CT_LbsClientPosTp213::RequestCompleteL
|
|
288 |
//
|
|
289 |
// (other items were commented in a header).
|
|
290 |
// ---------------------------------------------------------
|
|
291 |
//
|
|
292 |
void CT_LbsClientPosTp213::RequestCompleteL()
|
|
293 |
{
|
|
294 |
if (iclient2->CompletionCode() != KNoEvent)
|
|
295 |
{
|
|
296 |
_LIT(KClient2Compl, "Client 2 request completed with %d.");
|
|
297 |
TBuf<100> bufclient2comp;
|
|
298 |
bufclient2comp.Format(KClient2Compl, iclient2->CompletionCode());
|
|
299 |
INFO_PRINTF1(bufclient2comp);
|
|
300 |
|
|
301 |
if (iclient2->CompletionCode() != KErrCancel)
|
|
302 |
{
|
|
303 |
TBuf<80> errorMessage;
|
|
304 |
errorMessage.Format( KCanceledRequest, iclient2->CompletionCode() );
|
|
305 |
ERR_PRINTF1( errorMessage );
|
|
306 |
}
|
|
307 |
|
|
308 |
/*Testing if PSY is unloaded from memory. PSY created a temp-file that only should
|
|
309 |
exist during its lifespan. */
|
|
310 |
User::After(5000000);
|
|
311 |
RFs fileserver;
|
|
312 |
RFile file;
|
|
313 |
User::LeaveIfError(fileserver.Connect());
|
|
314 |
TInt err = file.Open(fileserver, KDummyFileName, EFileWrite);
|
|
315 |
if (err == KErrNone || err == KErrInUse)
|
|
316 |
{
|
|
317 |
ERR_PRINTF1(KFileNotDeleted);
|
|
318 |
}
|
|
319 |
file.Close();
|
|
320 |
fileserver.Close();
|
|
321 |
|
|
322 |
iclient2->ClosePositioner();
|
|
323 |
iclient2->ResetCompletionCode();
|
|
324 |
}
|
|
325 |
|
|
326 |
else if (iclient3->CompletionCode() != KNoEvent)
|
|
327 |
{
|
|
328 |
iclient3->ResetCompletionCode();
|
|
329 |
_LIT(KClient3Compl, "Client 3 request completed, ");
|
|
330 |
INFO_PRINTF1(KClient3Compl);
|
|
331 |
|
|
332 |
if (iNoFurtherEvents) //Client 3 received event but should NOT have!
|
|
333 |
{
|
|
334 |
iErrorDuringExecution = TRUE;
|
|
335 |
ERR_PRINTF1(KEventReceived);
|
|
336 |
}
|
|
337 |
|
|
338 |
//Read what event was received!
|
|
339 |
TInt eventReading = iclient3->ReadModuleStatusEvent();
|
|
340 |
|
|
341 |
if (eventReading != TPositionModuleStatus::EDeviceDisabled) //NO Disable Event!
|
|
342 |
{
|
|
343 |
_LIT(KClientStatusRead, "Event received by client not EDeviceDisabled, but %d.");
|
|
344 |
TBuf<100> bufstatusread;
|
|
345 |
bufstatusread.Format(KClientStatusRead, eventReading);
|
|
346 |
INFO_PRINTF1(bufstatusread);
|
|
347 |
|
|
348 |
//Make client3 listen for status events again!!
|
|
349 |
iclient3->ContinueRequesting();
|
|
350 |
}
|
|
351 |
else //A Disable Event!
|
|
352 |
{
|
|
353 |
_LIT(KClient3ComplDisabled, "Client 3 received EDeviceDisabled event!");
|
|
354 |
INFO_PRINTF1(KClient3ComplDisabled);
|
|
355 |
|
|
356 |
//Make client3 listen for status events again!!
|
|
357 |
iclient3->ContinueRequesting();
|
|
358 |
|
|
359 |
/*Wait 5 s for events before halting the scheduler.
|
|
360 |
No further events for client 3 should be received! */
|
|
361 |
ieventtimer->Start(5000000);
|
|
362 |
iNoFurtherEvents = TRUE;
|
|
363 |
//Start Timer
|
|
364 |
_LIT(KStartTiming, "Start Timer, 5 s.");
|
|
365 |
INFO_PRINTF1(KStartTiming);
|
|
366 |
}
|
|
367 |
}
|
|
368 |
else if (ieventtimer->CompletionCode() != KNoEvent) //Time-out
|
|
369 |
{
|
|
370 |
ieventtimer->ResetCompletionCode() ;
|
|
371 |
|
|
372 |
//Stop Scheduler
|
|
373 |
_LIT(KTimeOut, "Timer Stopped.");
|
|
374 |
INFO_PRINTF1(KTimeOut);
|
|
375 |
CActiveScheduler::Stop();
|
|
376 |
}
|
|
377 |
else
|
|
378 |
{
|
|
379 |
_LIT(KUnknownEvent, "Unknown request was completed!");
|
|
380 |
LogErrorAndLeaveL(KUnknownEvent);
|
|
381 |
}
|
|
382 |
}
|
|
383 |
|
|
384 |
// End of File
|