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
|
|
4 |
// under the terms of the License "Symbian Foundation License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
//
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
#include <e32base.h>
|
|
19 |
#include <f32file.h>
|
|
20 |
#include <LbsPositionInfo.h>
|
|
21 |
#include <Lbs.h>
|
|
22 |
#include <LbsCommon.h>
|
|
23 |
#include <LbsRequestor.h>
|
|
24 |
#include <EPos_CPosModules.h>
|
|
25 |
#include <EPos_CPosModuleUpdate.h>
|
|
26 |
#include <EPos_CPosModuleIdList.h>
|
|
27 |
|
|
28 |
TInt DoTestL();
|
|
29 |
|
|
30 |
TInt TestMainL()
|
|
31 |
{
|
|
32 |
// Create and install the active scheduler
|
|
33 |
CActiveScheduler* exampleScheduler=new (ELeave) CActiveScheduler;
|
|
34 |
CleanupStack::PushL(exampleScheduler);
|
|
35 |
CActiveScheduler::Install(exampleScheduler);
|
|
36 |
// Call function
|
|
37 |
TInt result = DoTestL();
|
|
38 |
CleanupStack::PopAndDestroy(exampleScheduler);
|
|
39 |
return result;
|
|
40 |
}
|
|
41 |
|
|
42 |
void TraceL(const TDesC& aMsg, RFile& aFile)
|
|
43 |
{
|
|
44 |
const TInt KBufSize = 200;
|
|
45 |
TBuf8<KBufSize> tmp;
|
|
46 |
tmp.Copy(aMsg);
|
|
47 |
_LIT(KEnd,";\r\n");
|
|
48 |
tmp.Append(KEnd);
|
|
49 |
aFile.Write(tmp);
|
|
50 |
}
|
|
51 |
|
|
52 |
/**
|
|
53 |
* Setup PSY
|
|
54 |
*/
|
|
55 |
void SetupPsyL(const TUid aPsyUid)
|
|
56 |
{
|
|
57 |
CPosModules* db = CPosModules::OpenL();
|
|
58 |
CleanupStack::PushL(db);
|
|
59 |
|
|
60 |
CPosModuleUpdate* enable = CPosModuleUpdate::NewLC();
|
|
61 |
CPosModuleUpdate* disable = CPosModuleUpdate::NewLC();
|
|
62 |
|
|
63 |
disable->SetUpdateAvailability(EFalse);
|
|
64 |
enable->SetUpdateAvailability(ETrue);
|
|
65 |
|
|
66 |
CPosModuleIdList* prioList = db->ModuleIdListLC();
|
|
67 |
|
|
68 |
for (TInt i = 0 ; i < prioList->Count(); i++)
|
|
69 |
{
|
|
70 |
if ((*prioList)[i] != aPsyUid)
|
|
71 |
{
|
|
72 |
// Disable all PSYs except one given as parameter
|
|
73 |
db->UpdateModuleL((*prioList)[i], *disable);
|
|
74 |
}
|
|
75 |
else
|
|
76 |
{
|
|
77 |
// Enable the PSY that came as an in parameter
|
|
78 |
db->UpdateModuleL((*prioList)[i], *enable);
|
|
79 |
}
|
|
80 |
}
|
|
81 |
|
|
82 |
CleanupStack::PopAndDestroy(prioList);
|
|
83 |
CleanupStack::PopAndDestroy(disable);
|
|
84 |
CleanupStack::PopAndDestroy(enable);
|
|
85 |
CleanupStack::PopAndDestroy(db);
|
|
86 |
}
|
|
87 |
|
|
88 |
/**
|
|
89 |
* Method used to generate a file name for trace.
|
|
90 |
* If a trace file exist an index number i counted
|
|
91 |
* one step until a trace file can be created.
|
|
92 |
* Maximun number of exe client are currently hard
|
|
93 |
* coded to 10;
|
|
94 |
*/
|
|
95 |
TBuf<40> GenerateFileNameForTraceL()
|
|
96 |
{
|
|
97 |
_LIT(KFileTrace, "c:\\logs\\execlientresult%d.txt");
|
|
98 |
RFs fileserver;
|
|
99 |
RFile file;
|
|
100 |
User::LeaveIfError(fileserver.Connect());
|
|
101 |
TBuf<40> ff;
|
|
102 |
ff.Append(KFileTrace);
|
|
103 |
|
|
104 |
for (TInt i = 1; i<10;i++)
|
|
105 |
{
|
|
106 |
ff.Format(KFileTrace,i);
|
|
107 |
TInt err = file.Open(fileserver,ff, EFileWrite);
|
|
108 |
if (err == KErrNotFound)
|
|
109 |
{
|
|
110 |
User::LeaveIfError(file.Create(fileserver,ff, EFileWrite));
|
|
111 |
break;
|
|
112 |
}
|
|
113 |
}
|
|
114 |
file.Close();
|
|
115 |
fileserver.Close();
|
|
116 |
return ff;
|
|
117 |
}
|
|
118 |
|
|
119 |
/**
|
|
120 |
* Error checking and output error to Trace File.
|
|
121 |
*/
|
|
122 |
void AssertTrueL(TBool aCondition, const TDesC& aErrorMsg, TInt aErrorCode, RFile& aFile)
|
|
123 |
{
|
|
124 |
if (!aCondition)
|
|
125 |
{
|
|
126 |
TBuf<100> buf;
|
|
127 |
buf.Format(aErrorMsg, aErrorCode);
|
|
128 |
TraceL(buf, aFile);
|
|
129 |
//User::Leave(aErrorCode);
|
|
130 |
}
|
|
131 |
}
|
|
132 |
|
|
133 |
/**
|
|
134 |
* Performes the test by connecting to MLFW and makes 50 Location request
|
|
135 |
*/
|
|
136 |
TInt DoTestL()
|
|
137 |
{
|
|
138 |
TBuf<40> traceFile = GenerateFileNameForTraceL();
|
|
139 |
|
|
140 |
RFs fileserver;
|
|
141 |
RFile file;
|
|
142 |
User::LeaveIfError(fileserver.Connect());
|
|
143 |
CleanupClosePushL(fileserver);
|
|
144 |
User::LeaveIfError(file.Open(fileserver, traceFile, EFileWrite));
|
|
145 |
CleanupClosePushL(file);
|
|
146 |
_LIT(KClientStarted, "Client Started");
|
|
147 |
TraceL(KClientStarted, file);
|
|
148 |
|
|
149 |
const TInt32 KUidMultiPsy = 0x01010176;
|
|
150 |
TUid uidMultiPsy;
|
|
151 |
uidMultiPsy.iUid = KUidMultiPsy;
|
|
152 |
SetupPsyL(uidMultiPsy);
|
|
153 |
|
|
154 |
_LIT(KMultiPsySetup, "MultiPsy set up");
|
|
155 |
TraceL(KMultiPsySetup, file);
|
|
156 |
|
|
157 |
TInt numberOfRuns = 50;
|
|
158 |
|
|
159 |
RPositionServer posServer;
|
|
160 |
CleanupClosePushL(posServer);
|
|
161 |
RPositioner positioner;
|
|
162 |
CleanupClosePushL(positioner);
|
|
163 |
TPositionInfo positionInfo = TPositionInfo();
|
|
164 |
|
|
165 |
_LIT(KConnectErr, "ERROR: Error when connecing to EPos server, %d");
|
|
166 |
TInt err = posServer.Connect();
|
|
167 |
AssertTrueL(err == KErrNone, KConnectErr, err, file);
|
|
168 |
|
|
169 |
_LIT(KOpenErr, "ERROR: Error when opening positioner, %d");
|
|
170 |
err = positioner.Open(posServer, uidMultiPsy);
|
|
171 |
AssertTrueL(err == KErrNone, KOpenErr, err, file);
|
|
172 |
|
|
173 |
_LIT(KService ,"Service");
|
|
174 |
err = positioner.SetRequestor(CRequestor::ERequestorService,
|
|
175 |
CRequestor::EFormatApplication, KService);
|
|
176 |
_LIT(KRequestor, "ERROR: Not possible to set requestor");
|
|
177 |
AssertTrueL(err == KErrNone, KRequestor, err, file);
|
|
178 |
|
|
179 |
TTime now, startTime;
|
|
180 |
TTimeIntervalMicroSeconds requestTime;
|
|
181 |
TRequestStatus status;
|
|
182 |
TInt64 reqTime;
|
|
183 |
TCoordinate corr(0,0,0);
|
|
184 |
TLocality loca(corr,0);
|
|
185 |
TPosition pos(loca, TTime(0));
|
|
186 |
TBool success = ETrue;
|
|
187 |
_LIT(KStartingRequests, "Starting requests");
|
|
188 |
TraceL(KStartingRequests, file);
|
|
189 |
|
|
190 |
for (TInt i = 0; i < numberOfRuns; i++)
|
|
191 |
{
|
|
192 |
startTime.UniversalTime();
|
|
193 |
positionInfo.SetPosition(pos);
|
|
194 |
positioner.NotifyPositionUpdate(positionInfo, status);
|
|
195 |
User::WaitForRequest(status);
|
|
196 |
err = status.Int();
|
|
197 |
if (err != KErrNone)
|
|
198 |
{
|
|
199 |
success=EFalse;
|
|
200 |
}
|
|
201 |
now.UniversalTime();
|
|
202 |
requestTime = now.MicroSecondsFrom(startTime);
|
|
203 |
_LIT(KError, "Request time, %d µs. Error code from Notify = %d");
|
|
204 |
TBuf<100> buf;
|
|
205 |
reqTime = requestTime.Int64();
|
|
206 |
buf.Format(KError, reqTime, err);
|
|
207 |
TraceL(buf, file);
|
|
208 |
TPosition result;
|
|
209 |
positionInfo.GetPosition(result);
|
|
210 |
// Sanity check
|
|
211 |
if (result.Latitude() == pos.Latitude() ||
|
|
212 |
result.Longitude() == pos.Longitude() ||
|
|
213 |
result.Altitude() == pos.Altitude())
|
|
214 |
{
|
|
215 |
success = EFalse;
|
|
216 |
_LIT(KErrorPositon, "ERROR:: The postion was not updated");
|
|
217 |
TraceL(KErrorPositon, file);
|
|
218 |
}
|
|
219 |
}
|
|
220 |
|
|
221 |
CleanupStack::PopAndDestroy(&positioner);
|
|
222 |
CleanupStack::PopAndDestroy(&posServer);
|
|
223 |
|
|
224 |
if (success)
|
|
225 |
{
|
|
226 |
_LIT(KOk, "SUCCESS");
|
|
227 |
TraceL(KOk, file);
|
|
228 |
}
|
|
229 |
else
|
|
230 |
{
|
|
231 |
_LIT(KErr, "FAILED");
|
|
232 |
TraceL(KErr, file);
|
|
233 |
}
|
|
234 |
|
|
235 |
CleanupStack::PopAndDestroy(&file);
|
|
236 |
CleanupStack::PopAndDestroy(&fileserver);
|
|
237 |
|
|
238 |
return (success) ? 0 : 1;
|
|
239 |
}
|
|
240 |
|
|
241 |
// Cleanup stack harness
|
|
242 |
GLDEF_C TInt E32Main()
|
|
243 |
{
|
|
244 |
__UHEAP_MARK;
|
|
245 |
CTrapCleanup* cleanupStack = CTrapCleanup::New();
|
|
246 |
TInt result = 1;
|
|
247 |
TRAPD(error, result = TestMainL());
|
|
248 |
_LIT(KLbsExeClient, "CT Lbs Exe Client");
|
|
249 |
__ASSERT_ALWAYS(!error, User::Panic(KLbsExeClient, error));
|
|
250 |
delete cleanupStack;
|
|
251 |
__UHEAP_MARKEND;
|
|
252 |
return result;
|
|
253 |
}
|
|
254 |
|