author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 24 Nov 2009 08:56:33 +0200 | |
changeset 33 | 50974a8b132e |
parent 19 | 989d2f495d90 |
permissions | -rw-r--r-- |
19 | 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 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: |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
33
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
18 |
#include <EPos_CPosLandmarkParser.h> |
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
19 |
#include <EPos_CPosLandmarkEncoder.h> |
19 | 20 |
#include <lbsposition.h> |
21 |
#include <EPos_CPosLmTextCriteria.h> |
|
33
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
22 |
#include <EPos_CPosLandmarkDatabase.h> |
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
23 |
#include <EPos_CPosLmItemIterator.h> |
19 | 24 |
#include "clandmarkfilter.h" |
25 |
#include "landmarkservice.h" |
|
33
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
26 |
#include "clandmarkasynctests.h" |
19 | 27 |
|
28 |
_LIT(KLmName1, "lm1"); |
|
29 |
_LIT(KLmName2, "lm2"); |
|
30 |
_LIT(KLmName3, "lm3"); |
|
31 |
_LIT(KLmName4, "landmark1"); |
|
32 |
_LIT(KLmName5, "landmark2"); |
|
33 |
_LIT(KLmName6, "landmark3"); |
|
34 |
||
35 |
_LIT(KLmSearchString, "lm*"); |
|
36 |
||
37 |
// ----------------------------------------------------------------------------- |
|
38 |
// CLandmarkAsyncTests::NewL |
|
39 |
// object creation |
|
40 |
// ----------------------------------------------------------------------------- |
|
41 |
// |
|
42 |
CLandmarkAsyncTests* CLandmarkAsyncTests::NewL(CLandmarkAsyncTests::TESTID aTestID) |
|
43 |
{ |
|
44 |
CLandmarkAsyncTests* self = new(ELeave)CLandmarkAsyncTests(aTestID); |
|
45 |
self->ConstructL(); |
|
46 |
return self; |
|
47 |
} |
|
48 |
// ----------------------------------------------------------------------------- |
|
49 |
// CLandmarkAsyncTests::CLandmarkAsyncTests |
|
50 |
// constructor |
|
51 |
// ----------------------------------------------------------------------------- |
|
52 |
// |
|
53 |
CLandmarkAsyncTests::CLandmarkAsyncTests(TESTID aTestID): |
|
54 |
CActive(EPriorityStandard),iTestID(aTestID) |
|
55 |
{ |
|
56 |
} |
|
57 |
// ----------------------------------------------------------------------------- |
|
58 |
// CLandmarkAsyncTests::~CLandmarkAsyncTests |
|
59 |
// destructor |
|
60 |
// ----------------------------------------------------------------------------- |
|
61 |
// |
|
62 |
CLandmarkAsyncTests::~CLandmarkAsyncTests() |
|
63 |
{ |
|
64 |
Cancel(); |
|
65 |
||
66 |
if(iWaitSchedular->IsStarted()) |
|
67 |
iWaitSchedular->AsyncStop(); |
|
68 |
||
69 |
delete iService; |
|
70 |
delete iDefaultLmHandle; |
|
71 |
if(iWaitSchedular) |
|
72 |
delete iWaitSchedular; |
|
73 |
} |
|
74 |
// ----------------------------------------------------------------------------- |
|
75 |
// CLandmarkAsyncTests::ConstructL |
|
76 |
// two phase constructor |
|
77 |
// ----------------------------------------------------------------------------- |
|
78 |
// |
|
79 |
void CLandmarkAsyncTests::ConstructL() |
|
80 |
{ |
|
81 |
CActiveScheduler::Add(this); |
|
82 |
||
83 |
iDefaultLmHandle = CPosLandmarkDatabase::OpenL (); |
|
84 |
CleanupStack::PushL(iDefaultLmHandle); |
|
85 |
if (iDefaultLmHandle->IsInitializingNeeded()) |
|
86 |
ExecuteAndDeleteLD(iDefaultLmHandle->InitializeL()); |
|
87 |
||
88 |
iService = CLandmarkService::NewL(); |
|
89 |
iService->RegisterObserver(this); |
|
90 |
||
91 |
CleanupStack::Pop(iDefaultLmHandle); |
|
92 |
||
93 |
iWaitSchedular = new(ELeave) CActiveSchedulerWait(); |
|
94 |
} |
|
95 |
// ----------------------------------------------------------------------------- |
|
96 |
// CLandmarkAsyncTests::StartL |
|
97 |
// Starts the execution of the ASync test |
|
98 |
// ----------------------------------------------------------------------------- |
|
99 |
// |
|
100 |
void CLandmarkAsyncTests::StartL() |
|
101 |
{ |
|
102 |
SetActive(); |
|
103 |
TRequestStatus* temp = &iStatus; |
|
104 |
User::RequestComplete(temp, KErrNone); |
|
105 |
iWaitSchedular->Start(); |
|
106 |
} |
|
107 |
// ----------------------------------------------------------------------------- |
|
108 |
// CLandmarkAsyncTests::Result |
|
109 |
// returns the result of the test |
|
110 |
// ----------------------------------------------------------------------------- |
|
111 |
// |
|
112 |
TInt CLandmarkAsyncTests::Result() |
|
113 |
{ |
|
114 |
return iResult; |
|
115 |
} |
|
116 |
||
117 |
// ----------------------------------------------------------------------------- |
|
118 |
// CLandmarkAsyncTests::HandleLandmarkItemsL |
|
119 |
// MLmObserver observer callback method for async getlist of landmark request. |
|
120 |
// ----------------------------------------------------------------------------- |
|
121 |
// |
|
122 |
void CLandmarkAsyncTests::HandleLandmarkItemsL( CPosLmItemIterator* aIterator, |
|
123 |
TInt32 /*aTransactionId*/, |
|
124 |
TInt aError, const TDesC& /*aDatabaseUri*/) |
|
125 |
{ |
|
126 |
TPosLmItemId lmID; |
|
127 |
TInt count = 0; |
|
128 |
||
129 |
iResult = 0; |
|
130 |
switch ( iTestID ) |
|
131 |
{ |
|
132 |
case ETEST1: |
|
133 |
while ((lmID = aIterator->NextL()) != KPosLmNullItemId) |
|
134 |
{ |
|
135 |
CPosLandmark* lm = iDefaultLmHandle->ReadLandmarkLC(lmID); |
|
136 |
TPtrC lmname; |
|
137 |
if ( !lm->GetLandmarkName(lmname) ) |
|
138 |
{ |
|
139 |
if ( lmname.Compare(KLmName1) || lmname.Compare(KLmName2) || lmname.Compare(KLmName3) ) |
|
140 |
count++; |
|
141 |
} |
|
142 |
else |
|
143 |
{ |
|
144 |
break; |
|
145 |
} |
|
146 |
||
147 |
CleanupStack::PopAndDestroy(lm); |
|
148 |
} |
|
149 |
if ( count != 3 ) |
|
150 |
{ |
|
151 |
iResult = 1; |
|
152 |
} |
|
153 |
break; |
|
154 |
case ETEST2: |
|
155 |
while ((lmID = aIterator->NextL()) != KPosLmNullItemId) |
|
156 |
{ |
|
157 |
CPosLandmark* lm = iDefaultLmHandle->ReadLandmarkLC(lmID); |
|
158 |
TPtrC lmname; |
|
159 |
if ( !lm->GetLandmarkName(lmname) ) |
|
160 |
{ |
|
161 |
if ( !lmname.Compare(KLmName1) || !lmname.Compare(KLmName2) || !lmname.Compare(KLmName3) ) |
|
162 |
count++; |
|
163 |
if ( !lmname.Compare(KLmName4) || !lmname.Compare(KLmName5) || !lmname.Compare(KLmName6)) |
|
164 |
count++; |
|
165 |
} |
|
166 |
else |
|
167 |
{ |
|
168 |
break; |
|
169 |
} |
|
170 |
||
171 |
CleanupStack::PopAndDestroy(lm); |
|
172 |
} |
|
173 |
if ( count != 6 ) |
|
174 |
{ |
|
175 |
iResult = 1; |
|
176 |
} |
|
177 |
break; |
|
178 |
} |
|
179 |
iResult |= ( !(KErrNone == aError) ); |
|
180 |
||
181 |
delete aIterator; |
|
182 |
iWaitSchedular->AsyncStop(); |
|
183 |
} |
|
184 |
||
185 |
// ----------------------------------------------------------------------------- |
|
186 |
// CLandmarkAsyncTests::HandleCategoryItemsL |
|
187 |
// MLmObserver observer callback method for async getlist of categories request. |
|
188 |
// ----------------------------------------------------------------------------- |
|
189 |
// |
|
190 |
void CLandmarkAsyncTests::HandleCategoryItemsL( CPosLmItemIterator* /*aIterator*/, |
|
191 |
TInt32 /*aTransactionId*/, |
|
192 |
TInt /*aError*/, const TDesC& /*aDatabaseUri*/) |
|
193 |
{ |
|
194 |
} |
|
195 |
// ----------------------------------------------------------------------------- |
|
196 |
// CLandmarkAsyncTests::RunL |
|
197 |
// Executes specified test |
|
198 |
// ----------------------------------------------------------------------------- |
|
199 |
// |
|
200 |
void CLandmarkAsyncTests::RunL() |
|
201 |
{ |
|
202 |
switch(iTestID) |
|
203 |
{ |
|
204 |
case ETEST1: |
|
205 |
AsyncTestFunc1L(); |
|
206 |
break; |
|
207 |
case ETEST2: |
|
208 |
AsyncTestFunc2L(); |
|
209 |
break; |
|
210 |
} |
|
211 |
} |
|
212 |
// ----------------------------------------------------------------------------- |
|
213 |
// CLandmarkAsyncTests::DoCancel |
|
214 |
// Cancels ongoing Async operationby this active object |
|
215 |
// ----------------------------------------------------------------------------- |
|
216 |
// |
|
217 |
void CLandmarkAsyncTests::DoCancel() |
|
218 |
{ |
|
219 |
||
220 |
} |
|
221 |
// ----------------------------------------------------------------------------- |
|
222 |
// CLandmarkAsyncTests::AsyncTestFunc1L |
|
223 |
// |
|
224 |
// ----------------------------------------------------------------------------- |
|
225 |
// |
|
226 |
void CLandmarkAsyncTests::AsyncTestFunc1L() |
|
227 |
{ |
|
228 |
TInt err = 0; |
|
229 |
TPosLmSortPref SortPref(CPosLandmark::ELandmarkName,TPosLmSortPref:: EAscending); |
|
230 |
||
231 |
CreateLandmarksL (); |
|
232 |
||
233 |
CLandmarkFilter* filter = CLandmarkFilter::NewLC(CLandmarkFilter::ELandmark); |
|
234 |
||
235 |
CPosLmTextCriteria* crit = CPosLmTextCriteria::NewLC(); |
|
236 |
||
237 |
crit->SetTextL(KLmSearchString); |
|
238 |
crit->SetAttributesToSearch ( CPosLandmark::ELandmarkName ); |
|
239 |
||
240 |
filter->SetCriteria(crit); |
|
241 |
filter->SetLmSortPref(SortPref); |
|
242 |
// filter->SetIsLandmark(ETrue); |
|
243 |
||
244 |
TInt32 tranId = 0; |
|
245 |
TRAP (err,iService->GetListL (tranId,*filter)); |
|
246 |
CleanupStack::Pop(crit); |
|
247 |
CleanupStack::PopAndDestroy(filter); |
|
248 |
} |
|
249 |
// ----------------------------------------------------------------------------- |
|
250 |
// CLandmarkAsyncTests::AsyncTestFunc2L |
|
251 |
// |
|
252 |
// ----------------------------------------------------------------------------- |
|
253 |
// |
|
254 |
void CLandmarkAsyncTests::AsyncTestFunc2L() |
|
255 |
{ |
|
256 |
TInt err = 0; |
|
257 |
TPosLmSortPref SortPref(CPosLandmark::ELandmarkName,TPosLmSortPref:: EAscending); |
|
258 |
||
259 |
CreateLandmarksL (); |
|
260 |
||
261 |
CLandmarkFilter* filter = CLandmarkFilter::NewLC(CLandmarkFilter::ELandmark); |
|
262 |
||
263 |
// filter->SetCriteria(NULL); |
|
264 |
filter->SetLmSortPref(SortPref); |
|
265 |
||
266 |
TInt32 tranId = 0; |
|
267 |
TRAP (err,iService->GetListL (tranId,*filter)); |
|
268 |
||
269 |
CleanupStack::PopAndDestroy(1,filter); |
|
270 |
} |
|
271 |
// ----------------------------------------------------------------------------- |
|
272 |
// CLandmarkAsyncTests::CreateLandmarksL |
|
273 |
// pre condition |
|
274 |
// ----------------------------------------------------------------------------- |
|
275 |
// |
|
276 |
void CLandmarkAsyncTests::CreateLandmarksL() |
|
277 |
{ |
|
278 |
TLocality pos; |
|
279 |
pos.SetCoordinate(45.1122,34.0099); |
|
280 |
||
281 |
CPosLandmark* lm = CPosLandmark::NewLC (); |
|
282 |
lm->SetLandmarkNameL (KLmName1); |
|
283 |
lm->SetLandmarkDescriptionL (KLmName1); |
|
284 |
lm->SetPositionL(pos); |
|
285 |
iDefaultLmHandle->AddLandmarkL (*lm); |
|
286 |
||
287 |
lm->SetLandmarkNameL (KLmName2); |
|
288 |
lm->SetLandmarkDescriptionL (KLmName2); |
|
289 |
lm->SetPositionL(pos); |
|
290 |
iDefaultLmHandle->AddLandmarkL (*lm); |
|
291 |
||
292 |
lm->SetLandmarkNameL (KLmName3); |
|
293 |
lm->SetLandmarkDescriptionL (KLmName3); |
|
294 |
lm->SetPositionL(pos); |
|
295 |
iDefaultLmHandle->AddLandmarkL (*lm); |
|
296 |
||
297 |
lm->SetLandmarkNameL (KLmName4); |
|
298 |
lm->SetLandmarkDescriptionL (KLmName4); |
|
299 |
lm->SetPositionL(pos); |
|
300 |
iDefaultLmHandle->AddLandmarkL (*lm); |
|
301 |
||
302 |
lm->SetLandmarkNameL (KLmName5); |
|
303 |
lm->SetLandmarkDescriptionL (KLmName5); |
|
304 |
lm->SetPositionL(pos); |
|
305 |
iDefaultLmHandle->AddLandmarkL (*lm); |
|
306 |
||
307 |
lm->SetLandmarkNameL (KLmName6); |
|
308 |
lm->SetLandmarkDescriptionL (KLmName6); |
|
309 |
lm->SetPositionL(pos); |
|
310 |
iDefaultLmHandle->AddLandmarkL (*lm); |
|
311 |
||
312 |
CleanupStack::PopAndDestroy(lm); |
|
313 |
} |