|
1 /* |
|
2 * Copyright (c) 2007 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: Provides testing of CPosLandmarkCategory class methods |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <EPos_CPosLandmark.h> |
|
22 #include <EPos_CPosLandmarkDatabase.h> |
|
23 #include <EPos_CPosLmCategoryManager.h> |
|
24 #include <EPos_CPosLandmarkCategory.h> |
|
25 #include <LbsPosition.h> |
|
26 #include "testcposlandmarkcategory.h" |
|
27 #include <StifParser.h> |
|
28 #include <Stiftestinterface.h> |
|
29 |
|
30 // Literals |
|
31 // Test Database URI |
|
32 _LIT( KDBUri, "file://c:eposlmtest.ldb" ); |
|
33 |
|
34 // ============================ MEMBER FUNCTIONS =============================== |
|
35 |
|
36 // ----------------------------------------------------------------------------- |
|
37 // CTestPosLandmarkCategory::CTestPosLandmarkCategory |
|
38 // C++ default constructor can NOT contain any code, that |
|
39 // might leave. |
|
40 // ----------------------------------------------------------------------------- |
|
41 // |
|
42 CTestPosLandmarkCategory::CTestPosLandmarkCategory( CStifLogger* aLog ) |
|
43 { |
|
44 iLog = aLog; |
|
45 } |
|
46 |
|
47 // ----------------------------------------------------------------------------- |
|
48 // CTestPosLandmarkCategory::NewL |
|
49 // |
|
50 // |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 CTestPosLandmarkCategory* CTestPosLandmarkCategory::NewL(CStifLogger* aLog) |
|
54 { |
|
55 CTestPosLandmarkCategory* self = new (ELeave) CTestPosLandmarkCategory( aLog ); |
|
56 CleanupStack::PushL( self ); |
|
57 self->ConstructL(); |
|
58 CleanupStack::Pop(); |
|
59 return self; |
|
60 } |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // CTestPosLandmarkCategory::ConstructL |
|
64 // |
|
65 // |
|
66 // ----------------------------------------------------------------------------- |
|
67 // |
|
68 void CTestPosLandmarkCategory::ConstructL() |
|
69 { |
|
70 |
|
71 } |
|
72 |
|
73 // ----------------------------------------------------------------------------- |
|
74 // CTestPosLandmarkCategory::~CTestPosLandmarkCategory |
|
75 // |
|
76 // |
|
77 // ----------------------------------------------------------------------------- |
|
78 // |
|
79 CTestPosLandmarkCategory::~CTestPosLandmarkCategory() |
|
80 { |
|
81 |
|
82 } |
|
83 |
|
84 // ----------------------------------------------------------------------------- |
|
85 // CTestPosLandmarkCategory::NewLCreateCategory |
|
86 // |
|
87 // |
|
88 // ----------------------------------------------------------------------------- |
|
89 // |
|
90 TInt CTestPosLandmarkCategory::NewLCreateCategoryL( CStifItemParser& /*aItem*/ ) |
|
91 { |
|
92 // Create category using NewL |
|
93 CPosLandmarkCategory* category = CPosLandmarkCategory::NewL(); |
|
94 delete category; |
|
95 return KErrNone; |
|
96 } |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // CTestPosLandmarkCategory::NewLCCreateCategory |
|
100 // |
|
101 // |
|
102 // ----------------------------------------------------------------------------- |
|
103 // |
|
104 TInt CTestPosLandmarkCategory::NewLCCreateCategoryLC( CStifItemParser& /*aItem*/ ) |
|
105 { |
|
106 // Create category using NewLC |
|
107 CPosLandmarkCategory* category = CPosLandmarkCategory::NewLC(); |
|
108 CleanupStack::PopAndDestroy( category ); |
|
109 return KErrNone; |
|
110 } |
|
111 |
|
112 // ----------------------------------------------------------------------------- |
|
113 // CTestPosLandmarkCategory::NewLCreateCategoryCopy |
|
114 // |
|
115 // |
|
116 // ----------------------------------------------------------------------------- |
|
117 // |
|
118 TInt CTestPosLandmarkCategory::NewLCreateCategoryCopyL( CStifItemParser& /*aItem*/ ) |
|
119 { |
|
120 // Create category using NewL |
|
121 CPosLandmarkCategory* category = category = CPosLandmarkCategory::NewL(); |
|
122 CleanupStack::PushL( category ); |
|
123 // Create copy using NewL |
|
124 CPosLandmarkCategory* categoryCopy = CPosLandmarkCategory::NewL( *category ); |
|
125 iLog->Log(_L("NewLCreateCategoryCopy Successful")); |
|
126 delete categoryCopy; |
|
127 CleanupStack::PopAndDestroy( category ); |
|
128 return KErrNone; |
|
129 } |
|
130 |
|
131 // ----------------------------------------------------------------------------- |
|
132 // CTestPosLandmarkCategory::NewLCCreateCategoryCopy |
|
133 // |
|
134 // |
|
135 // ----------------------------------------------------------------------------- |
|
136 // |
|
137 TInt CTestPosLandmarkCategory::NewLCCreateCategoryCopyLC( CStifItemParser& /*aItem*/ ) |
|
138 { |
|
139 // Create category using NewL |
|
140 CPosLandmarkCategory* category = CPosLandmarkCategory::NewL(); |
|
141 CleanupStack::PushL( category ); |
|
142 // Create copy using NewLC |
|
143 CPosLandmarkCategory* categoryCopy = CPosLandmarkCategory::NewLC( *category ); |
|
144 iLog->Log(_L("NewLCCreateCategoryCopy Successful")); |
|
145 CleanupStack::PopAndDestroy( 2, category ); |
|
146 return KErrNone; |
|
147 } |
|
148 |
|
149 // ----------------------------------------------------------------------------- |
|
150 // CTestPosLandmarkCategory::SetAndGetCategoryName |
|
151 // |
|
152 // |
|
153 // ----------------------------------------------------------------------------- |
|
154 // |
|
155 TInt CTestPosLandmarkCategory::SetAndGetCategoryNameL( CStifItemParser& aItem ) |
|
156 { |
|
157 TInt num; |
|
158 TInt error = aItem.GetNextInt( num ); |
|
159 TPtrC setNamePtr; |
|
160 error = aItem.GetNextString( setNamePtr ); |
|
161 // Create category using NewL |
|
162 CPosLandmarkCategory* category = CPosLandmarkCategory::NewL(); |
|
163 CleanupStack::PushL( category ); |
|
164 // Set name |
|
165 if( num == 1 ) |
|
166 { |
|
167 category->SetCategoryNameL( setNamePtr ); |
|
168 } |
|
169 |
|
170 // Get name |
|
171 TPtrC getNamePtr; |
|
172 error = category->GetCategoryName( getNamePtr ); |
|
173 if( KErrNone != error ) |
|
174 { |
|
175 // Error |
|
176 iLog->Log(_L("Error in getting category name")); |
|
177 User::Leave( KErrNotFound ); |
|
178 } |
|
179 // Compare name |
|
180 if( getNamePtr.Compare( setNamePtr ) != 0 ) |
|
181 { |
|
182 // Error |
|
183 iLog->Log(_L("Set name and Get name does not match, error in SetAndGetCategoryName")); |
|
184 User::Leave( KErrGeneral ); |
|
185 } |
|
186 iLog->Log(_L("SetAndGetCategoryName Successful")); |
|
187 CleanupStack::PopAndDestroy( category ); |
|
188 return KErrNone; |
|
189 } |
|
190 |
|
191 // ----------------------------------------------------------------------------- |
|
192 // CTestPosLandmarkCategory::SetAndGetCategoryIcon |
|
193 // |
|
194 // |
|
195 // ----------------------------------------------------------------------------- |
|
196 // |
|
197 TInt CTestPosLandmarkCategory::SetAndGetCategoryIconL( CStifItemParser& aItem ) |
|
198 { |
|
199 TInt num; |
|
200 TInt err = aItem.GetNextInt( num ); |
|
201 TPtrC setIconFilePtr; |
|
202 err = aItem.GetNextString( setIconFilePtr ); |
|
203 |
|
204 // Create category using NewL |
|
205 CPosLandmarkCategory* category = CPosLandmarkCategory::NewL(); |
|
206 CleanupStack::PushL( category ); |
|
207 // Set Icon for category if num == 1 |
|
208 if ( num == 1 ) |
|
209 { |
|
210 category->SetIconL( setIconFilePtr, 1, 1 ); |
|
211 } |
|
212 // Get Icon |
|
213 TPtrC getIconFilePtr; |
|
214 TInt index; |
|
215 TInt mask; |
|
216 TInt error = category->GetIcon( getIconFilePtr, index, mask ); |
|
217 if( KErrNone != error ) |
|
218 { |
|
219 iLog->Log( _L("Error in Getting Icon")); |
|
220 User::Leave( error ); |
|
221 } |
|
222 iLog->Log(getIconFilePtr); |
|
223 iLog->Log(_L("SetAndGetCategoryIcon Successful")); |
|
224 CleanupStack::PopAndDestroy( category ); |
|
225 return KErrNone; |
|
226 } |
|
227 |
|
228 // ----------------------------------------------------------------------------- |
|
229 // CTestPosLandmarkCategory::CategoryId |
|
230 // |
|
231 // |
|
232 // ----------------------------------------------------------------------------- |
|
233 // |
|
234 TInt CTestPosLandmarkCategory::CategoryIdL( CStifItemParser& aItem ) |
|
235 { |
|
236 TPtrC catNamePtr; |
|
237 TInt err = aItem.GetNextString( catNamePtr ); |
|
238 // Create category using NewL |
|
239 CPosLandmarkCategory* category = CPosLandmarkCategory::NewL(); |
|
240 CleanupStack::PushL( category ); |
|
241 // Check id, should return KPosLmNullItemId as category is not yet added to database |
|
242 TPosLmItemId getCategoryId = category->CategoryId(); |
|
243 if( KPosLmNullItemId != getCategoryId ) |
|
244 { |
|
245 iLog->Log(_L("Error in getting category id")); |
|
246 User::Leave( KErrGeneral ); |
|
247 } |
|
248 // Add category to default database |
|
249 // Open and intialize default database |
|
250 CPosLandmarkDatabase* lmkDatabase = CPosLandmarkDatabase::OpenL( KDBUri ); |
|
251 CleanupStack::PushL( lmkDatabase ); |
|
252 ExecuteAndDeleteLD( lmkDatabase->InitializeL() ); |
|
253 // Create category manager |
|
254 CPosLmCategoryManager* categoryMgr = CPosLmCategoryManager::NewL( *lmkDatabase ); |
|
255 CleanupStack::PushL( categoryMgr ); |
|
256 // Add category to databse |
|
257 // Set name, a category must have name set before being added to the database |
|
258 category->SetCategoryNameL( catNamePtr ); |
|
259 // Add |
|
260 TPosLmItemId addCategoryId; |
|
261 addCategoryId = categoryMgr->AddCategoryL( *category ); |
|
262 // Get category id, should return proper id as category is now added to database |
|
263 getCategoryId = category->CategoryId(); |
|
264 // Compare ids |
|
265 if( getCategoryId != addCategoryId ) |
|
266 { |
|
267 iLog->Log(_L("Error in getting category id")); |
|
268 //Remove category from database |
|
269 ExecuteAndDeleteLD( categoryMgr->RemoveCategoryL( addCategoryId ) ); |
|
270 User::Leave( KErrGeneral ); |
|
271 //ReleaseLandmarkResources(); //????? |
|
272 } |
|
273 iLog->Log(_L("CategoryId Successful")); |
|
274 //Remove category from database |
|
275 ExecuteAndDeleteLD( categoryMgr->RemoveCategoryL( addCategoryId ) ); |
|
276 CleanupStack::PopAndDestroy( 3, category ); |
|
277 ReleaseLandmarkResources(); |
|
278 return KErrNone; |
|
279 } |
|
280 |
|
281 // ----------------------------------------------------------------------------- |
|
282 // CTestPosLandmarkCategory::CheckGlobal |
|
283 // |
|
284 // |
|
285 // ----------------------------------------------------------------------------- |
|
286 // |
|
287 TInt CTestPosLandmarkCategory::CheckGlobalL( CStifItemParser& /*aItem*/ ) |
|
288 { |
|
289 // Create a category using NewL |
|
290 CPosLandmarkCategory* category = CPosLandmarkCategory::NewL(); |
|
291 CleanupStack::PushL( category ); |
|
292 // Check if global, should return KPosLmNullGlobalCategory |
|
293 TPosLmGlobalCategory globalId = category->GlobalCategory(); |
|
294 if( KPosLmNullGlobalCategory != globalId ) |
|
295 { |
|
296 //Error |
|
297 iLog->Log(_L("Error in GlobalCategory")); |
|
298 User::Leave( KErrGeneral ); |
|
299 } |
|
300 iLog->Log(_L("SetAndCheckGlobal successful")); |
|
301 CleanupStack::PopAndDestroy( category ); |
|
302 return KErrNone; |
|
303 } |
|
304 |
|
305 // ----------------------------------------------------------------------------- |
|
306 // CTestPosLandmarkCategory::RemoveCategoryAttributes |
|
307 // |
|
308 // |
|
309 // ----------------------------------------------------------------------------- |
|
310 // |
|
311 TInt CTestPosLandmarkCategory::RemoveCategoryAttributesL( CStifItemParser& /*aItem*/ ) |
|
312 { |
|
313 // Create a category using NewL |
|
314 _LIT( KIconFilePath, "z:\\resource\\eposlmglcategories.mif" ); |
|
315 CPosLandmarkCategory* category = CPosLandmarkCategory::NewL(); |
|
316 CleanupStack::PushL( category ); |
|
317 // Set Name |
|
318 _LIT( KCatName, "A Test Category" ); |
|
319 category->SetCategoryNameL( KCatName ); |
|
320 // Set Icon |
|
321 category->SetIconL( KIconFilePath, 1, 1); |
|
322 // Remove name |
|
323 category->RemoveCategoryAttributes( CPosLandmarkCategory::ECategoryName ); |
|
324 // Check |
|
325 TPtrC catName; |
|
326 TInt error = category->GetCategoryName( catName ); |
|
327 if( KErrNotFound != error ) |
|
328 { |
|
329 iLog->Log(_L("RemoveCategoryAttributes failed")); |
|
330 User::Leave( KErrGeneral ); |
|
331 } |
|
332 // Remove Icon |
|
333 category->RemoveCategoryAttributes( CPosLandmarkCategory::EIcon ); |
|
334 // Check |
|
335 TPtrC fileName; |
|
336 TInt index; |
|
337 TInt mask; |
|
338 error = category->GetIcon( fileName, index, mask); |
|
339 if( KErrNotFound != error ) |
|
340 { |
|
341 iLog->Log(_L("RemoveCategoryAttributes failed")); |
|
342 User::Leave( KErrGeneral ); |
|
343 } |
|
344 iLog->Log(_L("RemoveCategoryAttributes successful")); |
|
345 CleanupStack::PopAndDestroy( category ); |
|
346 return KErrNone; |
|
347 } |