|
1 /* |
|
2 * Copyright (c) 2005 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: |
|
15 * ?description_line |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDES |
|
21 |
|
22 #include "FT_CPosTp19.h" |
|
23 #include <EPos_CPosLandmarkDatabase.h> |
|
24 #include <EPos_CPosLandmarkDatabase.h> |
|
25 #include <EPos_CPosLandmarkSearch.h> |
|
26 |
|
27 // ================= MEMBER FUNCTIONS ======================= |
|
28 // --------------------------------------------------------- |
|
29 // CPosTp19::CloseTest |
|
30 // |
|
31 // (other items were commented in a header). |
|
32 // --------------------------------------------------------- |
|
33 // |
|
34 void CPosTp19::CloseTest() |
|
35 { |
|
36 delete iDatabase; |
|
37 iDatabase = NULL; |
|
38 |
|
39 delete iCategoryManager; |
|
40 iCategoryManager = NULL; |
|
41 |
|
42 iCategoryIds.Close(); |
|
43 iCategoryNames.ResetAndDestroy(); |
|
44 |
|
45 iGlobalCategoryNames.Close(); |
|
46 iGlobalCategoryIds.Close(); |
|
47 |
|
48 iCategories.ResetAndDestroy(); |
|
49 iCategories.Close(); |
|
50 } |
|
51 |
|
52 // --------------------------------------------------------- |
|
53 // CPosTp19::StartL |
|
54 // |
|
55 // (other items were commented in a header). |
|
56 // --------------------------------------------------------- |
|
57 // |
|
58 void CPosTp19::StartL() |
|
59 { |
|
60 iLog->Log(_L("**** Testing CPosCategoryManager():: GetCategoires methods ****")); |
|
61 |
|
62 |
|
63 RemoveDefaultDbL(); |
|
64 RemoveAllLmDatabasesL(); |
|
65 |
|
66 iDatabase = CPosLandmarkDatabase::OpenL(); // return default database |
|
67 if (iDatabase->IsInitializingNeeded()) |
|
68 { |
|
69 ExecuteAndDeleteLD(iDatabase->InitializeL()); |
|
70 } |
|
71 |
|
72 iLog->Log(_L(" Default database opened and initialised ")); |
|
73 |
|
74 iCategoryManager = CPosLmCategoryManager::NewL(*iDatabase); |
|
75 |
|
76 // Test with non-global categories |
|
77 TestGetByNameL(); |
|
78 |
|
79 /* |
|
80 * Test with global categories |
|
81 */ |
|
82 |
|
83 // Added for testing |
|
84 ExecuteAndDeleteLD(iCategoryManager->ResetGlobalCategoriesL()); |
|
85 |
|
86 iLog->Log(_L(" ******** Testing with global categories ******")); |
|
87 |
|
88 TestGetGlobalL(); |
|
89 } |
|
90 |
|
91 // --------------------------------------------------------- |
|
92 // CPosTp19::TestGetGlobal |
|
93 // |
|
94 // (other items were commented in a header). |
|
95 // --------------------------------------------------------- |
|
96 // |
|
97 void CPosTp19::TestGetGlobalL() |
|
98 { |
|
99 _LIT(KGetGlobalErr, "GetGlobalCategoryL should return KPosLmNullItemId for category Id = 0"); |
|
100 _LIT(KGetGlobalErr2, "GetGlobalCategoryL should return KPosLmNullItemId for non existing categories"); // Rajesh : Commented |
|
101 |
|
102 SetupGlobalCategoriesL(); |
|
103 TBuf<100> info; |
|
104 info.Zero(); |
|
105 TPosLmItemId id(0); |
|
106 |
|
107 /* |
|
108 * Test with global categories |
|
109 */ |
|
110 iLog->Log(_L("Testing GetGlobalCategoryL() with non existing global category( catId 0 )")); |
|
111 id = iCategoryManager->GetGlobalCategoryL(0); |
|
112 AssertTrueSecL(id == KPosLmNullItemId, KGetGlobalErr); |
|
113 |
|
114 iLog->Log(_L("Testing GlobalCategoryNameL() with non existing global category (catid 0)")); |
|
115 HBufC* name = iCategoryManager->GlobalCategoryNameL(0); |
|
116 CleanupStack::PushL(name); |
|
117 AssertTrueSecL(name == NULL, KGetGlobalErr); |
|
118 CleanupStack::PopAndDestroy(name); |
|
119 |
|
120 // Test with non existing category id |
|
121 iLog->Log(_L("Testing GetGlobalCategoryL() with non existing global category (CatId = 500)")); |
|
122 id = iCategoryManager->GetGlobalCategoryL(500); |
|
123 AssertTrueSecL(id == KPosLmNullItemId, KGetGlobalErr2); |
|
124 |
|
125 iLog->Log(_L("Testing GlobalCategoryNameL() with non existing global category (CatId = 500)")); |
|
126 name = iCategoryManager->GlobalCategoryNameL(500); |
|
127 CleanupStack::PushL(name); |
|
128 AssertTrueSecL(name == NULL, KGetGlobalErr2); |
|
129 CleanupStack::PopAndDestroy(name); |
|
130 |
|
131 iLog->Log(_L("Testing GetGlobalCategoryL() and GlobalCategoryNameL() with valid categories)")); |
|
132 |
|
133 for (TInt i=0; i<iGlobalCategoryNames.Count(); i++) |
|
134 { |
|
135 // Get the id of the global category in the db |
|
136 TPosLmItemId catId = iCategoryManager->GetGlobalCategoryL(iGlobalCategoryIds[i]); |
|
137 CPosLandmarkCategory* category = iCategoryManager->ReadCategoryLC( catId ); |
|
138 |
|
139 // Compare the Ids of the global categories |
|
140 if ( category->GlobalCategory() != iGlobalCategoryIds[i]) |
|
141 { |
|
142 iLog->Log(_L("Incorrect category id returned")); |
|
143 _LIT(KIds, "Expected: %d, returned %d"); |
|
144 info.Format(KIds, iGlobalCategoryIds[i], category->GlobalCategory()); |
|
145 iLog->Log(info); |
|
146 info.Zero(); |
|
147 User::Leave(KErrGeneral); |
|
148 } |
|
149 CleanupStack::PopAndDestroy( category); |
|
150 |
|
151 HBufC* name = iCategoryManager->GlobalCategoryNameL(iGlobalCategoryIds[i]); |
|
152 CleanupStack::PushL(name); |
|
153 |
|
154 if (name->CompareC(*iGlobalCategoryNames[i])) |
|
155 { |
|
156 iLog->Log(_L("Incorrect global category name")); |
|
157 iLog->Log(_L("Expected: ")); |
|
158 iLog->Log(*iGlobalCategoryNames[i]); |
|
159 iLog->Log(_L("Returned: ")); |
|
160 iLog->Log(*name); |
|
161 User::Leave(KErrGeneral); |
|
162 } |
|
163 CleanupStack::PopAndDestroy(name); |
|
164 } |
|
165 } |
|
166 |
|
167 // --------------------------------------------------------- |
|
168 // CLandmarkTestProcedureBase::SetupGlobalCategoriesL() |
|
169 // |
|
170 // (other items were commented in a header). |
|
171 // --------------------------------------------------------- |
|
172 // |
|
173 |
|
174 void CPosTp19::SetupGlobalCategoriesL() |
|
175 { |
|
176 ReadGlobalCategoriesFromResourceL( iGlobalCategoryIds, iGlobalCategoryNames ); |
|
177 } |
|
178 |
|
179 |
|
180 // --------------------------------------------------------- |
|
181 // CPosTp19::TestGetByName |
|
182 // |
|
183 // (other items were commented in a header). |
|
184 // --------------------------------------------------------- |
|
185 // |
|
186 void CPosTp19::TestGetByNameL() |
|
187 { |
|
188 _LIT(KEmptyStringErr, "GetCategoryL with an empty string should return KErrArgument, not %d"); |
|
189 _LIT(KMaxStringErr, "GetCategoryL with an maximum length string should return KErrArgument, not %d"); |
|
190 _LIT(KNotFoundErr, "GetCategoryL should return KPosLmNullItemId for a category that doesn't exist in the db, not %d"); |
|
191 |
|
192 iLog->Log(_L(" Testing CPosCategoryManager::GetCategoryL() with wrong arguement (Empty name string)")); |
|
193 TRAPD(err, iCategoryManager->GetCategoryL(_L(""))); |
|
194 AssertTrueSecL(err == KErrArgument, KEmptyStringErr, err); |
|
195 |
|
196 iLog->Log(_L(" Testing CPosCategoryManager::GetCategoryL() with wrong arguement (Name not existing)")); |
|
197 TPosLmItemId categoryId = iCategoryManager->GetCategoryL(_L("kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk")); |
|
198 AssertTrueSecL(categoryId == KPosLmNullItemId, KNotFoundErr, categoryId); |
|
199 |
|
200 // Test with maximum lenght of name |
|
201 iLog->Log(_L(" Testing CPosCategoryManager::GetCategoryL() with wrong arguement (With max length of Name not existing)")); |
|
202 _LIT(KMaxName124, "Category12Category12Category12Category12Category12Category12Category12Category12Category12Category12Category12Category12_ABC"); |
|
203 categoryId = iCategoryManager->GetCategoryL(KMaxName124); |
|
204 AssertTrueSecL(categoryId == KPosLmNullItemId, KNotFoundErr, categoryId); |
|
205 |
|
206 // Test with more than maximum lenght of name |
|
207 iLog->Log(_L(" Testing CPosCategoryManager::GetCategoryL() with wrong arguement (With more than max length of Name not existing)")); |
|
208 _LIT(KMaxName, "Category12Category12Category12Category12Category12Category12Category12Category12Category12Category12Category12Category12Category12"); |
|
209 TRAP(err, iCategoryManager->GetCategoryL(KMaxName)); |
|
210 AssertTrueSecL(err == KErrArgument, KMaxStringErr, err); |
|
211 |
|
212 // Add some categories and verify the addition |
|
213 iLog->Log(_L(" Testing with some valid categories in the database ( +ve testing )")); |
|
214 AddCategoriesL (10); |
|
215 VerifyAddedCategoriesL(); |
|
216 } |
|
217 |
|
218 // --------------------------------------------------------- |
|
219 // CPosTp19:AddCategoriesL |
|
220 // (other items were commented in a header). |
|
221 // --------------------------------------------------------- |
|
222 // |
|
223 void CPosTp19::AddCategoriesL( TInt aNumofCats ) |
|
224 { |
|
225 _LIT(KName, "Category - %d"); |
|
226 TInt err = KErrLocked; |
|
227 for (TUint i = 0; i<aNumofCats ; i++) |
|
228 { |
|
229 TBuf<100> categoryName; |
|
230 categoryName.Format( KName,i ); |
|
231 CPosLandmarkCategory* lmc = CPosLandmarkCategory::NewLC(); |
|
232 lmc->SetCategoryNameL( categoryName ); |
|
233 err = KErrLocked; |
|
234 while ( err == KErrLocked ) |
|
235 { |
|
236 TRAP(err, iCategoryManager->AddCategoryL( *lmc )); |
|
237 } |
|
238 iCategories.Append(lmc); |
|
239 CleanupStack::Pop( lmc ); |
|
240 } |
|
241 } |
|
242 |
|
243 // --------------------------------------------------------- |
|
244 // CPosTp19:VerifyAddedCategoriesL() |
|
245 // (other items were commented in a header). |
|
246 // --------------------------------------------------------- |
|
247 // |
|
248 void CPosTp19::VerifyAddedCategoriesL() |
|
249 { |
|
250 TInt noOfCats = iCategoryNames.Count(); |
|
251 // Verify the added categories |
|
252 for ( TUint i = 0; i < noOfCats; i++ ) |
|
253 { |
|
254 CPosLandmarkCategory* cat = iCategories[i]; |
|
255 TPtrC catName; |
|
256 cat->GetCategoryName( catName ); |
|
257 // Get the categories from the database using name |
|
258 TPosLmItemId catId = iCategoryManager->GetCategoryL( catName); |
|
259 |
|
260 if ( catId != cat->CategoryId()) |
|
261 { |
|
262 TBuf<150> buf; |
|
263 buf.Format(_L("Unable to verify the added non-global category Id %d "), cat->CategoryId() ); |
|
264 iLog->Log(buf); |
|
265 User::Leave(-1); |
|
266 } |
|
267 } |
|
268 } |
|
269 // End of File |