|
1 // Copyright (c) 2005-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 "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Contains implementation of CTestBookmarksBaseStep class |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalTechnology |
|
21 */ |
|
22 |
|
23 // User Include |
|
24 #include "TestBookmarksBaseStep.h" |
|
25 |
|
26 /** |
|
27 Constructor. Sets the test step name and initialises the TestServer |
|
28 reference. |
|
29 @internalTechnology |
|
30 @test |
|
31 */ |
|
32 CTestBookmarksBaseStep::CTestBookmarksBaseStep(CTestBookmarksServer& aTestServer) : iTestServer(aTestServer) |
|
33 { |
|
34 //Call base class method to set human readable name for test step |
|
35 SetTestStepName(KTestBookmarksBaseStep); |
|
36 } |
|
37 |
|
38 /** |
|
39 Destructor. Closes the database handle |
|
40 @internalTechnology |
|
41 @test |
|
42 */ |
|
43 CTestBookmarksBaseStep::~CTestBookmarksBaseStep() |
|
44 { |
|
45 iBkDb.Close(); |
|
46 } |
|
47 |
|
48 /** |
|
49 Base class virtual. Opens connection with the bookmark database. |
|
50 @internalTechnology |
|
51 @test |
|
52 @param None |
|
53 @return EPass or EFail indicating the result of opening the DB. |
|
54 */ |
|
55 TVerdict CTestBookmarksBaseStep::doTestStepPreambleL() |
|
56 { |
|
57 TSecurityInfo info; |
|
58 info.Set(RProcess()); |
|
59 INFO_PRINTF2(_L("\n\nSecure id = %U\n\n"), info.iSecureId); |
|
60 |
|
61 TInt error = KErrNone; |
|
62 TPtrC dbMode; |
|
63 // Get DB mode from ini |
|
64 if(!GetStringFromConfig(ConfigSection(), KIniDbMode, dbMode)) |
|
65 { |
|
66 TRAP(error, iBkDb.OpenL()); |
|
67 } |
|
68 else |
|
69 { |
|
70 INFO_PRINTF2(_L("Opening DB in %S mode"), &dbMode); |
|
71 TRAP(error, iBkDb.OpenL(GetDbOpenMode(dbMode))); |
|
72 } |
|
73 if(error != KErrNone) |
|
74 { |
|
75 ERR_PRINTF2(_L("Error occured while opening DB : %D"), error); |
|
76 SetTestStepError(error); |
|
77 } |
|
78 else |
|
79 { |
|
80 INFO_PRINTF1(_L("DB opened successfully")); |
|
81 } |
|
82 return TestStepResult(); |
|
83 } // doTestPreambleL |
|
84 |
|
85 /** |
|
86 Base class pure virtual. Just returns the test step result. |
|
87 @internalTechnology |
|
88 @test |
|
89 @param None |
|
90 @return EPass or EFail indicating the result of the test step. |
|
91 */ |
|
92 TVerdict CTestBookmarksBaseStep::doTestStepL() |
|
93 { |
|
94 return TestStepResult(); |
|
95 } // doTestStepL |
|
96 |
|
97 /** |
|
98 Commits the Bookmarks Database |
|
99 @internalTechnology |
|
100 @test |
|
101 @param None |
|
102 @return None |
|
103 */ |
|
104 void CTestBookmarksBaseStep::CommitDb() |
|
105 { |
|
106 TRAPD(err, iBkDb.CommitL()); |
|
107 if(err == KErrNone) |
|
108 { |
|
109 INFO_PRINTF1(_L("Commit succeeded")); |
|
110 } |
|
111 else |
|
112 { |
|
113 ERR_PRINTF2(_L("Error occured during commit: %D"), err); |
|
114 SetTestStepError(err); |
|
115 } |
|
116 } |
|
117 |
|
118 /** |
|
119 Gets the array index of the id for the item with the particular title |
|
120 @internalTechnology |
|
121 @test |
|
122 @param Title of the Bookmark item |
|
123 @return The index of the item in the array of ids |
|
124 */ |
|
125 TInt CTestBookmarksBaseStep::GetArrayIndex(const TPtrC& aTitle) |
|
126 { |
|
127 for(TInt index = 0; index < iTestServer.iTitles.Count(); ++index) |
|
128 { |
|
129 if (iTestServer.iTitles[index]->Des().Compare(aTitle) == KErrNone) |
|
130 { |
|
131 return index; |
|
132 } |
|
133 } |
|
134 return KErrGeneral; |
|
135 } |
|
136 |
|
137 /** |
|
138 Opens a folder or root based on title passed |
|
139 @internalTechnology |
|
140 @test |
|
141 @param Title of the parent folder |
|
142 @param Reference to a non-open folder handle. |
|
143 @return Error code that indicates the result of the operation. |
|
144 */ |
|
145 TInt CTestBookmarksBaseStep::GetParentFolder(const TPtrC& aParent, RBkFolder& aParentFolder) |
|
146 { |
|
147 TInt error = KErrNone; |
|
148 if(aParent == KRoot) |
|
149 { |
|
150 TRAP(error, aParentFolder = iBkDb.OpenRootL()); |
|
151 } |
|
152 else |
|
153 { |
|
154 TRAP(error, aParentFolder = iBkDb.OpenFolderL(aParent)); |
|
155 } |
|
156 return error; |
|
157 } |
|
158 |
|
159 /** |
|
160 Opens the node which has a particular title |
|
161 @internalTechnology |
|
162 @test |
|
163 @param Title of the item to be opened |
|
164 @param Type of item : bookmark/folder |
|
165 @param Type of item |
|
166 @param Reference to a non-open node handle. |
|
167 @return Error code that indicates the result of the operation. |
|
168 */ |
|
169 TInt CTestBookmarksBaseStep::GetBkNode(const TPtrC& aTitle, \ |
|
170 const TPtrC& aTypeOfItem,\ |
|
171 RBkNode& aBkNode) |
|
172 { |
|
173 TInt error = KErrNone; |
|
174 if(aTitle == KRoot) |
|
175 { |
|
176 TRAP(error, aBkNode = iBkDb.OpenRootL()); |
|
177 } |
|
178 else if(aTypeOfItem == KFolder) |
|
179 { |
|
180 TRAP(error, aBkNode = iBkDb.OpenFolderL(aTitle)); |
|
181 } |
|
182 else if(aTypeOfItem == KBookmark) |
|
183 { |
|
184 // If type is bookmark, try to find it in the array |
|
185 TInt index = GetArrayIndex(aTitle); |
|
186 if(index < KErrNone) |
|
187 { |
|
188 // Not found in array, do a search in the tree |
|
189 INFO_PRINTF1(_L("Item not found in Titles array")); |
|
190 Bookmark::TItemId id = Bookmark::KNullItemID; |
|
191 RBkFolder root; |
|
192 TRAP(error, root = iBkDb.OpenRootL()); |
|
193 if(error != KErrNone) |
|
194 { |
|
195 ERR_PRINTF2(_L("Error occured while opening root: %D"), error); |
|
196 } |
|
197 else |
|
198 { |
|
199 TRAP(error, id = GetItemFromTreeL(aTitle, root)); |
|
200 root.Close(); |
|
201 if(error != KErrNone) |
|
202 { |
|
203 ERR_PRINTF2(_L("Error occured in IsItemInFolderL: %D"), error); |
|
204 } |
|
205 else if(id == Bookmark::KNullItemID) |
|
206 { |
|
207 INFO_PRINTF1(_L("Item not found in folder tree")); |
|
208 error = KErrNotFound; |
|
209 } |
|
210 else |
|
211 { |
|
212 INFO_PRINTF2(_L("Trying to open item with id %U"), id); |
|
213 TRAP(error, aBkNode = iBkDb.OpenBookmarkL(id)); |
|
214 } |
|
215 } |
|
216 } |
|
217 else |
|
218 { |
|
219 TRAP(error, aBkNode = iBkDb.OpenBookmarkL(iTestServer.iIds[index])); |
|
220 } |
|
221 } |
|
222 if(error != KErrNone) |
|
223 { |
|
224 ERR_PRINTF2(_L("Error occured in GetBkNode : %D"), error); |
|
225 } |
|
226 return error; |
|
227 } |
|
228 |
|
229 /** |
|
230 Resolves DB open mode from the string passed |
|
231 @internalTechnology |
|
232 @test |
|
233 @param Descriptor indicating mode to open the DB |
|
234 @return Bookmark::TVisibility enumeration based on the open-mode |
|
235 */ |
|
236 Bookmark::TVisibility CTestBookmarksBaseStep::GetDbOpenMode(const TPtrC& aMode) |
|
237 { |
|
238 if(aMode.Compare(KDbModePublic) == KErrNone) |
|
239 { |
|
240 return Bookmark::EVisibilityPublic; |
|
241 } |
|
242 else if(aMode.Compare(KDbModePrivate) == KErrNone) |
|
243 { |
|
244 return Bookmark::EVisibilityPrivate; |
|
245 } |
|
246 else if(aMode.Compare(KDbModeAll) == KErrNone) |
|
247 { |
|
248 return Bookmark::EVisibilityAll; |
|
249 } |
|
250 else if(aMode.Compare(KDbModeManager) == KErrNone) |
|
251 { |
|
252 return Bookmark::EVisibilityManager; |
|
253 } |
|
254 else |
|
255 { |
|
256 return Bookmark::EVisibilityDefault; |
|
257 } |
|
258 } |
|
259 |
|
260 /** |
|
261 A recursive routine to find an item with a particular title from the tree |
|
262 @internalTechnology |
|
263 @test |
|
264 @param Title of the item to be found |
|
265 @param Handle to the main folder from which search is to begin. |
|
266 @return Id of the bookmark item if found. Null Id if not. |
|
267 */ |
|
268 Bookmark::TItemId CTestBookmarksBaseStep::GetItemFromTreeL(const TDesC& aName, RBkFolder aFolder) |
|
269 { |
|
270 RBkNode item; |
|
271 Bookmark::TItemId id = Bookmark::KNullItemID; |
|
272 // Loop through all children |
|
273 TInt index = aFolder.Count() - 1; |
|
274 for (;index >= 0; --index) |
|
275 { |
|
276 item = aFolder.OpenItemL(index); |
|
277 CleanupClosePushL(item); |
|
278 const TDesC& title = item.Title(); |
|
279 |
|
280 INFO_PRINTF3(_L("Parent-title = %S, id = %U"), &(aFolder.Title()), aFolder.Id()); |
|
281 INFO_PRINTF4(_L("index = %D Title = %S, id = %U"), index, &title, item.Id()); |
|
282 |
|
283 if (title.Compare(aName) == 0) |
|
284 {// Title matched |
|
285 id = item.Id(); |
|
286 } |
|
287 else if (item.Type() == Bookmark::ETypeFolder) |
|
288 {// Title did not match, but item is a folder, so recurse into it |
|
289 RBkFolder folder = item.OpenFolderL(); |
|
290 CleanupClosePushL(folder); |
|
291 // recurse |
|
292 id = GetItemFromTreeL(aName, folder); |
|
293 CleanupStack::PopAndDestroy(&folder); |
|
294 } |
|
295 CleanupStack::PopAndDestroy(&item); |
|
296 if (id != Bookmark::KNullItemID) |
|
297 {// If valid id, then we are done |
|
298 break; |
|
299 } |
|
300 } |
|
301 return id; |
|
302 } |
|
303 |
|
304 /** |
|
305 Compare two TUints and return verdict |
|
306 @internalTechnology |
|
307 @test |
|
308 @param TUint32 Value 1 to be compared |
|
309 @param TUint32 Value 2 to be compared |
|
310 @return EPass or EFail based on comparison |
|
311 */ |
|
312 TVerdict CTestBookmarksBaseStep::CompareTUints(const TUint32& aTUint32Val1, const TUint32& aTUint32Val2) |
|
313 { |
|
314 INFO_PRINTF2(_L("Value 1 = %U"), aTUint32Val1); |
|
315 INFO_PRINTF2(_L("Value 2 = %U"), aTUint32Val2); |
|
316 return (aTUint32Val1 == aTUint32Val2) ? EPass : EFail; |
|
317 } |
|
318 |
|
319 /** |
|
320 Compare two TBools and return verdict |
|
321 @internalTechnology |
|
322 @test |
|
323 @param TBool Value 1 to be compared |
|
324 @param TBool Value 2 to be compared |
|
325 @return EPass or EFail based on comparison |
|
326 */ |
|
327 TVerdict CTestBookmarksBaseStep::CompareBools(const TBool& aBoolVal1, const TBool& aBoolVal2) |
|
328 { |
|
329 INFO_PRINTF2(_L("Value 1 = %S"), &(aBoolVal1 ? KTrue() : KFalse())); |
|
330 INFO_PRINTF2(_L("Value 2 = %S"), &(aBoolVal2 ? KTrue() : KFalse())); |
|
331 return (!aBoolVal1 == !aBoolVal2) ? EPass : EFail; |
|
332 } |
|
333 |
|
334 /** |
|
335 Compare two strings and return verdict |
|
336 @internalTechnology |
|
337 @test |
|
338 @param Descriptor Value 1 to be compared |
|
339 @param Descriptor Value 2 to be compared |
|
340 @return EPass or EFail based on comparison |
|
341 */ |
|
342 TVerdict CTestBookmarksBaseStep::CompareStrings(const TPtrC& aStrVal1, const TPtrC& aStrVal2) |
|
343 { |
|
344 INFO_PRINTF2(_L("Value 1 = %S"), &aStrVal1); |
|
345 INFO_PRINTF2(_L("Value 2 = %S"), &aStrVal2); |
|
346 return (aStrVal1.Compare(aStrVal2) == KErrNone) ? EPass : EFail; |
|
347 } |
|
348 |
|
349 /** |
|
350 Compare two TInts and return verdict |
|
351 @internalTechnology |
|
352 @test |
|
353 @param TInt Value 1 to be compared |
|
354 @param TInt Value 2 to be compared |
|
355 @return EPass or EFail based on comparison |
|
356 */ |
|
357 TVerdict CTestBookmarksBaseStep::CompareTInts(const TInt& aTIntVal1, const TInt& aTIntVal2) |
|
358 { |
|
359 INFO_PRINTF2(_L("Value 1 = %D"), aTIntVal1); |
|
360 INFO_PRINTF2(_L("Value 2 = %D"), aTIntVal2); |
|
361 return (aTIntVal1 == aTIntVal2) ? EPass : EFail; |
|
362 } |
|
363 |
|
364 /** |
|
365 Compare two TReals and return verdict |
|
366 @internalTechnology |
|
367 @test |
|
368 @param TReal Value 1 to be compared |
|
369 @param TReal Value 2 to be compared |
|
370 @return EPass or EFail based on comparison |
|
371 */ |
|
372 TVerdict CTestBookmarksBaseStep::CompareTReals(const TReal& aTRealVal1, const TReal& aTRealVal2) |
|
373 { |
|
374 INFO_PRINTF2(_L("Value 1 = %g"), aTRealVal1); |
|
375 INFO_PRINTF2(_L("Value 2 = %g"), aTRealVal2); |
|
376 return (aTRealVal1 == aTRealVal2) ? EPass : EFail; |
|
377 } |
|
378 |
|
379 /** |
|
380 Compare two TTimes and return verdict |
|
381 @internalTechnology |
|
382 @test |
|
383 @param TTime Value 1 to be compared |
|
384 @param TTime Value 2 to be compared |
|
385 @return EPass or EFail based on comparison |
|
386 */ |
|
387 TVerdict CTestBookmarksBaseStep::CompareTTimes(const TTime& aTTimeVal1, const TTime& aTTimeVal2) |
|
388 { |
|
389 INFO_PRINTF2(_L("Value 1 = %g"), aTTimeVal1.Int64()); |
|
390 INFO_PRINTF2(_L("Value 2 = %g"), aTTimeVal2.Int64()); |
|
391 return (aTTimeVal1 == aTTimeVal2) ? EPass : EFail; |
|
392 } |
|
393 |
|
394 /** |
|
395 Checks error and commits the DB if error is KErrNone |
|
396 @internalTechnology |
|
397 @test |
|
398 @param Error value to be checked |
|
399 @return None |
|
400 */ |
|
401 void CTestBookmarksBaseStep::CheckErrorAndCommit(const TInt& aError) |
|
402 { |
|
403 // Examine the result |
|
404 if(TestStepResult() == EPass) |
|
405 { |
|
406 if(aError != KErrNone) |
|
407 { |
|
408 ERR_PRINTF2(_L("The operation failed with error: %D"), aError); |
|
409 SetTestStepError(aError); |
|
410 } |
|
411 else |
|
412 { |
|
413 INFO_PRINTF1(_L("The operation was successful.")); |
|
414 CommitDb(); |
|
415 } |
|
416 } |
|
417 } |
|
418 |
|
419 /** |
|
420 Checks error and if error is KErrNone, checks and sets the verdict |
|
421 @internalTechnology |
|
422 @test |
|
423 @param Error value to be checked |
|
424 @param Verdict as a result of some operation |
|
425 @return None |
|
426 */ |
|
427 void CTestBookmarksBaseStep::CheckErrorAndVerdict(const TInt& aError, const TVerdict& aVerdict) |
|
428 { |
|
429 if(TestStepResult() == EPass) |
|
430 { |
|
431 if(aError != KErrNone) |
|
432 { |
|
433 ERR_PRINTF2(_L("The operation failed with error: %D"), aError); |
|
434 SetTestStepError(aError); |
|
435 } |
|
436 else |
|
437 { |
|
438 if(aVerdict == EPass) |
|
439 { |
|
440 INFO_PRINTF1(_L("The returned and the expected values matched.")); |
|
441 } |
|
442 else |
|
443 { |
|
444 INFO_PRINTF1(_L("The returned and the expected values did not match.")); |
|
445 SetTestStepResult(aVerdict); |
|
446 } |
|
447 } |
|
448 } |
|
449 } |
|
450 |
|
451 |