|
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 CTestGetPropertyStep class |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalTechnology |
|
21 */ |
|
22 |
|
23 // System Includes |
|
24 #include <bookmarkdatabase.h> |
|
25 #include <escapeutils.h> |
|
26 |
|
27 // User Include |
|
28 #include "TestGetPropertyStep.h" |
|
29 |
|
30 /** |
|
31 Constructor. Sets the test step name |
|
32 @internalTechnology |
|
33 @test |
|
34 */ |
|
35 CTestGetPropertyStep::CTestGetPropertyStep(CTestBookmarksServer& aTestServer) : CTestBookmarksBaseStep(aTestServer) |
|
36 { |
|
37 //Call base class method to set human readable name for test step |
|
38 SetTestStepName(KTestGetPropertyStep); |
|
39 } |
|
40 |
|
41 /** |
|
42 Base class pure virtual. |
|
43 @internalTechnology |
|
44 @test |
|
45 @param None |
|
46 @return EPass or EFail indicating the result of the test step. |
|
47 */ |
|
48 TVerdict CTestGetPropertyStep::doTestStepL() |
|
49 { |
|
50 TInt property; |
|
51 TPtrC expectedValue; |
|
52 if(!GetIntFromConfig(ConfigSection(), KIniProperty, property ) || |
|
53 (!GetStringFromConfig(ConfigSection(), KIniExpectedValue, expectedValue ) && |
|
54 property != EBookmarkAuth && property != EDbVersion ) |
|
55 ) |
|
56 { |
|
57 ERR_PRINTF3(_L("Problem in reading values from ini. \ |
|
58 \nExpected fields are: \n%S\n%S\n" |
|
59 ),&KIniProperty, &KIniExpectedValue |
|
60 ); |
|
61 SetTestStepResult(EFail); |
|
62 } |
|
63 else |
|
64 { |
|
65 TRAPD(error, DoTestL(property, expectedValue)); |
|
66 if(error != KErrNone) |
|
67 { |
|
68 ERR_PRINTF2(_L("Error occured in CTestGetPropertyStep::DoTestL"), error); |
|
69 SetTestStepResult(EFail); |
|
70 } |
|
71 } |
|
72 return TestStepResult(); |
|
73 } // doTestStepL |
|
74 |
|
75 /** |
|
76 Checks whether DB or item property is to be retreived and calls the |
|
77 appropriate function |
|
78 @internalTechnology |
|
79 @test |
|
80 @param Enumeration indicating the property we have to get |
|
81 @param Expected value for the property |
|
82 @return None |
|
83 */ |
|
84 void CTestGetPropertyStep::DoTestL(const TInt& aProperty, const TPtrC& aExpectedValue) |
|
85 { |
|
86 TPtrC title; |
|
87 TPtrC typeOfItem; |
|
88 if(aProperty < KDbGeneralPropertiesStart) |
|
89 { |
|
90 if(!GetStringFromConfig(ConfigSection(), KIniTitle, title ) || |
|
91 !GetStringFromConfig(ConfigSection(), KIniTypeOfItem, typeOfItem ) |
|
92 ) |
|
93 { |
|
94 ERR_PRINTF3(_L("%S and %S must also be provided for item property"),&KIniTypeOfItem, &KIniTitle); |
|
95 SetTestStepResult(EFail); |
|
96 } |
|
97 else |
|
98 {// Item property |
|
99 TInt error = KErrNone; |
|
100 RBkNode bkNode; |
|
101 if((error = GetBkNode(title, typeOfItem, bkNode)) != KErrNone) |
|
102 { |
|
103 ERR_PRINTF3(_L("Error occured while opening item %S : %D"), &title, error); |
|
104 SetTestStepError(error); |
|
105 } |
|
106 else |
|
107 { |
|
108 CleanupClosePushL(bkNode); |
|
109 GetAndCompareItemPropertyValueL(bkNode, aProperty, aExpectedValue); |
|
110 CleanupStack::PopAndDestroy(&bkNode); |
|
111 } |
|
112 } |
|
113 } |
|
114 else |
|
115 {// DB property |
|
116 GetAndCompareDbPropertyValueL(aProperty, aExpectedValue); |
|
117 } |
|
118 } //DoTestL |
|
119 |
|
120 /** |
|
121 Gets and compares item property with expected value |
|
122 @internalTechnology |
|
123 @test |
|
124 @param Reference to the handle to the node whose property we have to get |
|
125 @param Enumeration indicating the property we have to get |
|
126 @param Expected value for the property |
|
127 @return None |
|
128 */ |
|
129 void CTestGetPropertyStep::GetAndCompareItemPropertyValueL(const RBkNode& aBkNode, const TInt& aProperty, const TPtrC& aExpectedValue) |
|
130 { |
|
131 TVerdict verdict = EPass; |
|
132 TInt error = KErrNone; |
|
133 TUint32 retTUint32Val; |
|
134 TBool retBoolVal; |
|
135 TPtrC retStrVal; |
|
136 switch(aProperty) |
|
137 { |
|
138 case EItemWritable: |
|
139 retBoolVal = aBkNode.IsWritable(); |
|
140 verdict = CompareBools(retBoolVal, CTestBookmarksServer::GetBool(aExpectedValue)); |
|
141 break; |
|
142 case EItemPublic: |
|
143 retBoolVal = aBkNode.IsPublic(); |
|
144 verdict = CompareBools(retBoolVal, CTestBookmarksServer::GetBool(aExpectedValue)); |
|
145 break; |
|
146 case EBookmarkIsHome: |
|
147 { |
|
148 RBkBookmark homePgBkMrk = aBkNode.OpenBookmarkL(); |
|
149 retBoolVal = homePgBkMrk.IsHomePage(); |
|
150 homePgBkMrk.Close(); |
|
151 verdict = CompareBools(retBoolVal, CTestBookmarksServer::GetBool(aExpectedValue)); |
|
152 break; |
|
153 } |
|
154 case EItemDescription: |
|
155 TRAP(error, retStrVal.Set(aBkNode.DescriptionL())); |
|
156 if(error == KErrNone) |
|
157 { |
|
158 verdict = CompareStrings(retStrVal, aExpectedValue); |
|
159 } |
|
160 break; |
|
161 case EItemParent: |
|
162 { |
|
163 error = GetItemParent(aBkNode, aExpectedValue, verdict); |
|
164 break; |
|
165 } |
|
166 case EItemTitle : |
|
167 retStrVal.Set(aBkNode.Title()); |
|
168 verdict = CompareStrings(retStrVal, aExpectedValue); |
|
169 break; |
|
170 case EBookmarkNap: |
|
171 { |
|
172 RBkBookmark bkBkMrk = aBkNode.OpenBookmarkL(); |
|
173 TRAP(error, retTUint32Val = bkBkMrk.GetNapL()); |
|
174 bkBkMrk.Close(); |
|
175 if(error == KErrNone) |
|
176 { |
|
177 verdict = CompareTUints(retTUint32Val, CTestBookmarksServer::GetTUint32(aExpectedValue)); |
|
178 } |
|
179 break; |
|
180 } |
|
181 case EBookmarkProxy: |
|
182 { |
|
183 RBkBookmark bkBkMrk = aBkNode.OpenBookmarkL(); |
|
184 TRAP(error, retTUint32Val = bkBkMrk.ProxyL()); |
|
185 bkBkMrk.Close(); |
|
186 if(error == KErrNone) |
|
187 { |
|
188 verdict = CompareTUints(retTUint32Val, CTestBookmarksServer::GetTUint32(aExpectedValue)); |
|
189 } |
|
190 break; |
|
191 } |
|
192 case EBookmarkUri: |
|
193 { |
|
194 RBkBookmark bkBkMrk = aBkNode.OpenBookmarkL(); |
|
195 CleanupClosePushL(bkBkMrk); |
|
196 // Convert to 16-bit |
|
197 HBufC* hBufC = EscapeUtils::ConvertToUnicodeFromUtf8L(bkBkMrk.Uri()); |
|
198 verdict = CompareStrings(hBufC->Des(), aExpectedValue); |
|
199 delete hBufC; |
|
200 CleanupStack::PopAndDestroy(&bkBkMrk); |
|
201 break; |
|
202 } |
|
203 case EBookmarkAuth: |
|
204 { |
|
205 RBkBookmark bkBkMrk = aBkNode.OpenBookmarkL(); |
|
206 TRAP(error, verdict = DoGetAuthenticationL(bkBkMrk)); |
|
207 bkBkMrk.Close(); |
|
208 break; |
|
209 } |
|
210 case EBookmarkLastVisited: |
|
211 { |
|
212 TTime retTTimeVal; |
|
213 RBkBookmark bkBkMrk = aBkNode.OpenBookmarkL(); |
|
214 TRAP(error, retTTimeVal = bkBkMrk.LastVisited()); |
|
215 if(error == KErrNone) |
|
216 { |
|
217 verdict = CompareTTimes(retTTimeVal, TTime(aExpectedValue)); |
|
218 } |
|
219 bkBkMrk.Close(); |
|
220 break; |
|
221 } |
|
222 case EBookmarkLastModified: |
|
223 { |
|
224 TTime retTTimeVal; |
|
225 RBkBookmark bkBkMrk = aBkNode.OpenBookmarkL(); |
|
226 TRAP(error, retTTimeVal = bkBkMrk.LastModifiedL()); |
|
227 if(error == KErrNone) |
|
228 { |
|
229 verdict = CompareTTimes(retTTimeVal, TTime(aExpectedValue)); |
|
230 } |
|
231 bkBkMrk.Close(); |
|
232 break; |
|
233 } |
|
234 case EItemOwner: |
|
235 TRAP(error, retTUint32Val = aBkNode.OwnerL()); |
|
236 if(error == KErrNone) |
|
237 { |
|
238 verdict = CompareTUints(retTUint32Val, CTestBookmarksServer::GetTUint32(aExpectedValue)); |
|
239 } |
|
240 break; |
|
241 default: |
|
242 INFO_PRINTF2(_L("Invalid property number : %D"), aProperty); |
|
243 SetTestStepResult(EFail); |
|
244 } |
|
245 |
|
246 // Examine the result |
|
247 CheckErrorAndVerdict(error, verdict); |
|
248 } // GetAndCompareItemPropertyValueL |
|
249 |
|
250 /** |
|
251 Gets and compares the item's parent with an expected value |
|
252 @internalTechnology |
|
253 @test |
|
254 @param Reference to the handle to the node whose parent we have to get |
|
255 @param The title of the expected parent folder |
|
256 @param Refernce to the verdict variable, that will be set by this method |
|
257 @return Error resulting out of the operation, if any. Else, KErrNone |
|
258 */ |
|
259 TInt CTestGetPropertyStep::GetItemParent(const RBkNode& aBkNode, const TPtrC& aExpectedValue, TVerdict& aVerdict) |
|
260 { |
|
261 RBkNode parentFolder; |
|
262 TRAPD(error, parentFolder = aBkNode.OpenParentL()); |
|
263 if(error == KErrNone) |
|
264 { |
|
265 TUint32 retTUint32Val = parentFolder.Id(); |
|
266 parentFolder.Close(); |
|
267 RBkFolder expectedParentFolder; |
|
268 if((error = GetBkNode(aExpectedValue, KFolder(), expectedParentFolder)) != KErrNone) |
|
269 { |
|
270 ERR_PRINTF3(_L("Error occured while opening item %S : %D"), &aExpectedValue, error); |
|
271 SetTestStepError(error); |
|
272 } |
|
273 else |
|
274 { |
|
275 aVerdict = CompareTUints(retTUint32Val, expectedParentFolder.Id()); |
|
276 expectedParentFolder.Close(); |
|
277 } |
|
278 } |
|
279 return error; |
|
280 } |
|
281 |
|
282 /** |
|
283 Gets and compares DB property with expected value |
|
284 @internalTechnology |
|
285 @test |
|
286 @param Enumeration indicating the property we have to get |
|
287 @param Expected value for the property |
|
288 @return None |
|
289 */ |
|
290 void CTestGetPropertyStep::GetAndCompareDbPropertyValueL(const TInt& aProperty, const TPtrC& aExpectedValue) |
|
291 { |
|
292 TInt error = KErrNone; |
|
293 TVerdict verdict = EPass; |
|
294 TPtrC retStrVal; |
|
295 TUint32 retTUint32Val; |
|
296 switch(aProperty) |
|
297 { |
|
298 case EDbDefaultNap: |
|
299 retTUint32Val = iBkDb.DefaultNap(); |
|
300 verdict = CompareTUints(retTUint32Val, CTestBookmarksServer::GetTUint32(aExpectedValue)); |
|
301 break; |
|
302 case EDbDefaultProxy: |
|
303 retTUint32Val = iBkDb.DefaultProxy(); |
|
304 verdict = CompareTUints(retTUint32Val, CTestBookmarksServer::GetTUint32(aExpectedValue)); |
|
305 break; |
|
306 case EDbHome: |
|
307 { |
|
308 error = GetAndCompareHomePageBookmark(aExpectedValue, verdict); |
|
309 break; |
|
310 } |
|
311 case EDbHomePageText: |
|
312 retStrVal.Set(iBkDb.HomePageText()); |
|
313 verdict = CompareStrings(retStrVal, aExpectedValue); |
|
314 break; |
|
315 case EDbSearchUri: |
|
316 { |
|
317 // Convert to 16-bit |
|
318 HBufC* hBufC = EscapeUtils::ConvertToUnicodeFromUtf8L(iBkDb.SearchUri()); |
|
319 retStrVal.Set(hBufC->Des()); |
|
320 verdict = CompareStrings(retStrVal, aExpectedValue); |
|
321 delete hBufC; |
|
322 break; |
|
323 } |
|
324 default: |
|
325 INFO_PRINTF2(_L("Invalid property number : %D"), aProperty); |
|
326 SetTestStepResult(EFail); |
|
327 } |
|
328 |
|
329 // Examine the result |
|
330 CheckErrorAndVerdict(error, verdict); |
|
331 } // GetAndCompareItemPropertyValueL |
|
332 |
|
333 /** |
|
334 Gets and compares the item's homepage bookmark with an expected value |
|
335 @internalTechnology |
|
336 @test |
|
337 @param Descriptor indicating the expected bookmark |
|
338 @param Reference to the verdict variable, that will be set by this method |
|
339 @return Error resulting out of the operation, if any. Else, KErrNone |
|
340 */ |
|
341 TInt CTestGetPropertyStep::GetAndCompareHomePageBookmark(const TPtrC& aExpectedValue, TVerdict& aVerdict) |
|
342 { |
|
343 TInt error = KErrNone; |
|
344 RBkBookmark homePageBkMrk; |
|
345 TRAP(error, homePageBkMrk = iBkDb.OpenHomeL()); |
|
346 if(error == KErrNone) |
|
347 { |
|
348 TUint32 retTUint32Val = homePageBkMrk.Id(); |
|
349 homePageBkMrk.Close(); |
|
350 RBkBookmark expectedNode; |
|
351 if((error = GetBkNode(aExpectedValue, KBookmark(), expectedNode)) != KErrNone) |
|
352 { |
|
353 ERR_PRINTF3(_L("Error occured while opening item %S : %D"), &aExpectedValue, error); |
|
354 SetTestStepError(error); |
|
355 } |
|
356 else |
|
357 { |
|
358 aVerdict = CompareTUints(retTUint32Val, expectedNode.Id()); |
|
359 expectedNode.Close(); |
|
360 } |
|
361 } |
|
362 return error; |
|
363 } |
|
364 |
|
365 /** |
|
366 Reads expected authentication details from ini, gets the authentication object |
|
367 from the bookmark and compares its components with the expected ones |
|
368 @internalTechnology |
|
369 @test |
|
370 @param Reference to handle to the bookmark whose auth-params we are to get |
|
371 @return EPass or EFail based on the result of the comparison |
|
372 */ |
|
373 TVerdict CTestGetPropertyStep::DoGetAuthenticationL(const RBkBookmark& bkBkMrk) |
|
374 { |
|
375 TVerdict verdict = EPass; |
|
376 TPtrC name; |
|
377 TPtrC password; |
|
378 TPtrC method; |
|
379 CAuthentication::TMethod tMethod = CAuthentication::EDigest; |
|
380 |
|
381 if(!GetStringFromConfig(ConfigSection(), KIniAuthName, name ) || |
|
382 !GetStringFromConfig(ConfigSection(), KIniAuthPassword, password ) |
|
383 ) |
|
384 { |
|
385 ERR_PRINTF3(_L("%S and %S must also be mentioned in ini file"),&KIniAuthName, &KIniAuthPassword); |
|
386 SetTestStepResult(EFail); |
|
387 return EFail; |
|
388 } |
|
389 else |
|
390 { |
|
391 if(GetStringFromConfig(ConfigSection(),KIniAuthMethod, method)) |
|
392 { |
|
393 if(method.Compare(KMethodBasic) == KErrNone) |
|
394 { |
|
395 tMethod = CAuthentication::EBasic; |
|
396 } |
|
397 } |
|
398 |
|
399 // Get auth-params |
|
400 // Construct 16-bit versions of the auth-params, so that we can compare |
|
401 HBufC* retName = EscapeUtils::ConvertToUnicodeFromUtf8L(const_cast<RBkBookmark&>(bkBkMrk).AuthenticationL().Name()); |
|
402 CleanupStack::PushL(retName); |
|
403 HBufC* retPassword = EscapeUtils::ConvertToUnicodeFromUtf8L(const_cast<RBkBookmark&>(bkBkMrk).AuthenticationL().Password()); |
|
404 CleanupStack::PushL(retPassword); |
|
405 |
|
406 CAuthentication::TMethod retTMethod = const_cast<RBkBookmark&>(bkBkMrk).AuthenticationL().Method(); |
|
407 |
|
408 // Compare and decide on the verdict |
|
409 if(CompareStrings(retName->Des(), name) == EFail) |
|
410 { |
|
411 INFO_PRINTF1(_L("The expected name and returned name did not match")); |
|
412 verdict = EFail; |
|
413 } |
|
414 if(CompareStrings(retPassword->Des(), password) == EFail) |
|
415 { |
|
416 INFO_PRINTF1(_L("The expected password and returned password did not match")); |
|
417 verdict = EFail; |
|
418 } |
|
419 if(CompareTInts(retTMethod, tMethod) == EFail) |
|
420 { |
|
421 INFO_PRINTF1(_L("The expected method and returned method did not match")); |
|
422 verdict = EFail; |
|
423 } |
|
424 CleanupStack::PopAndDestroy(2, retName); |
|
425 } |
|
426 return verdict; |
|
427 } // DoGetAuthenticationL |
|
428 |
|
429 |