|
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 CTestCustomPropertyStep class |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalTechnology |
|
21 */ |
|
22 |
|
23 // System Includes |
|
24 #include <bookmarkdatabase.h> |
|
25 |
|
26 // User Include |
|
27 #include "TestCustomPropertyStep.h" |
|
28 |
|
29 /** |
|
30 Constructor. Sets the test step name |
|
31 @internalTechnology |
|
32 @test |
|
33 */ |
|
34 CTestCustomPropertyStep::CTestCustomPropertyStep(CTestBookmarksServer& aTestServer) : CTestBookmarksBaseStep(aTestServer) |
|
35 { |
|
36 //Call base class method to set human readable name for test step |
|
37 SetTestStepName(KTestCustomPropertyStep); |
|
38 } |
|
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 CTestCustomPropertyStep::doTestStepL() |
|
49 { |
|
50 TPtrC operation; |
|
51 TPtrC category; |
|
52 TPtrC uniqueId; |
|
53 if(!GetStringFromConfig(ConfigSection(), KIniOperation, operation ) || |
|
54 !GetStringFromConfig(ConfigSection(), KIniCategory, category ) || |
|
55 !GetStringFromConfig(ConfigSection(), KIniUid, uniqueId ) |
|
56 ) |
|
57 { |
|
58 ERR_PRINTF4(_L("Problem in reading values from ini. \ |
|
59 \nExpected fields are: \n%S\n%S\n%S\n" |
|
60 ),&KIniOperation, &KIniCategory, &KIniUid |
|
61 ); |
|
62 SetTestStepResult(EFail); |
|
63 } |
|
64 else |
|
65 { |
|
66 if(operation.Compare(KRegisterOperation) == KErrNone || operation.Compare(KDeRegisterOperation) == KErrNone) |
|
67 {// Register or deregister custom property |
|
68 DoRegDeregCustomProperty(operation, category, uniqueId); |
|
69 } |
|
70 else if(operation.Compare(KSetOperation) == KErrNone || operation.Compare(KGetOperation) == KErrNone) |
|
71 {// Set or get custom property |
|
72 TRAPD(error, DoSetGetCustomPropertyL(operation, category, uniqueId)); |
|
73 if(error != KErrNone) |
|
74 { |
|
75 ERR_PRINTF3(_L("Error occured while doing %S operation: %D"), operation, error); |
|
76 SetTestStepResult(EFail); |
|
77 } |
|
78 } |
|
79 else |
|
80 { |
|
81 ERR_PRINTF2(_L("Invalid operation : %S"), &operation); |
|
82 SetTestStepResult(EFail); |
|
83 } |
|
84 } |
|
85 return TestStepResult(); |
|
86 } // doTestStepL |
|
87 |
|
88 /** |
|
89 Registers or deregisters a custom property |
|
90 @internalTechnology |
|
91 @test |
|
92 @param Operation to be performed : set/get/register/deregister |
|
93 @param Category: db/folder/bookmark |
|
94 @param Uid of the custom property |
|
95 @return None |
|
96 */ |
|
97 void CTestCustomPropertyStep::DoRegDeregCustomProperty(const TPtrC& aOperation, const TPtrC& aCategory, const TPtrC& aUid) |
|
98 { |
|
99 TInt error = KErrNone; |
|
100 TPtrC dataType; |
|
101 if(aOperation.Compare(KRegisterOperation) == KErrNone) |
|
102 { |
|
103 if(!GetStringFromConfig(ConfigSection(), KIniDataType, dataType)) |
|
104 { |
|
105 ERR_PRINTF2(_L("%S should be mentioned in ini for registering a property"), &KIniDataType); |
|
106 SetTestStepResult(EFail); |
|
107 } |
|
108 else |
|
109 { |
|
110 // Register property |
|
111 error = RegisterCustomProperty(aUid, aCategory, dataType); |
|
112 } |
|
113 } |
|
114 else if(aOperation.Compare(KDeRegisterOperation) == KErrNone) |
|
115 { |
|
116 // Deregister property |
|
117 error = DeRegisterCustomProperty(aUid, aCategory); |
|
118 } |
|
119 |
|
120 // Examine the result |
|
121 CheckErrorAndCommit(error); |
|
122 } // DoRegDeregCustomProperty |
|
123 |
|
124 /** |
|
125 Resolves and returns the enumeration indicating the custom property type |
|
126 function |
|
127 @internalTechnology |
|
128 @test |
|
129 @param Descriptor indicating the data type of the custom property |
|
130 @return Bookmark::TPropertyType enumeration indicating the type of property |
|
131 */ |
|
132 Bookmark::TPropertyType CTestCustomPropertyStep::GetPropertyType(const TPtrC& aDataType) |
|
133 { |
|
134 if(aDataType.Compare(KTypeInt) == KErrNone) |
|
135 { |
|
136 return Bookmark::EDataTypeInt; |
|
137 } |
|
138 else if(aDataType.Compare(KTypeReal) == KErrNone) |
|
139 { |
|
140 return Bookmark::EDataTypeReal; |
|
141 } |
|
142 else if(aDataType.Compare(KTypeDes8) == KErrNone) |
|
143 { |
|
144 return Bookmark::EDataTypeDes8; |
|
145 } |
|
146 else |
|
147 { |
|
148 return Bookmark::EDataTypeDes16; |
|
149 } |
|
150 } |
|
151 |
|
152 /** |
|
153 Registers the custom property |
|
154 @internalTechnology |
|
155 @test |
|
156 @param Descriptor indicating the UID of the property |
|
157 @param Category: db/folder/bookmark |
|
158 @param Datatype of the custom property |
|
159 @return Error code as a result of the register operation |
|
160 */ |
|
161 TInt CTestCustomPropertyStep::RegisterCustomProperty(const TPtrC& aUid, const TPtrC& aCategory, const TPtrC& aDataType) |
|
162 { |
|
163 // Resolve property type |
|
164 Bookmark::TPropertyType propertyType = GetPropertyType(aDataType); |
|
165 // Register property |
|
166 TInt error = KErrNone; |
|
167 if(aCategory.Compare(KDb()) == KErrNone) |
|
168 { |
|
169 TRAP(error, iBkDb.RegisterDatabasePropertyL(TUid::Uid(CTestBookmarksServer::GetTUint32(aUid)), propertyType)); |
|
170 } |
|
171 else if(aCategory.Compare(KFolder()) == KErrNone) |
|
172 { |
|
173 TRAP(error, iBkDb.RegisterFolderPropertyL(TUid::Uid(CTestBookmarksServer::GetTUint32(aUid)), propertyType)); |
|
174 } |
|
175 else if(aCategory.Compare(KBookmark()) == KErrNone) |
|
176 { |
|
177 TRAP(error, iBkDb.RegisterBookmarkPropertyL(TUid::Uid(CTestBookmarksServer::GetTUint32(aUid)), propertyType)); |
|
178 } |
|
179 else |
|
180 { |
|
181 ERR_PRINTF2(_L("Invalid category: %S"), aCategory); |
|
182 SetTestStepResult(EFail); |
|
183 } |
|
184 return error; |
|
185 } |
|
186 |
|
187 /** |
|
188 De-registers the custom property |
|
189 @internalTechnology |
|
190 @test |
|
191 @param Descriptor indicating the UID of the property |
|
192 @param Category: db/folder/bookmark |
|
193 @return Error code as a result of the de-register operation |
|
194 */ |
|
195 TInt CTestCustomPropertyStep::DeRegisterCustomProperty(const TPtrC& aUid, const TPtrC& aCategory) |
|
196 { |
|
197 TInt error = KErrNone; |
|
198 if(aCategory.Compare(KDb()) == KErrNone) |
|
199 { |
|
200 TRAP(error, iBkDb.DeregisterDatabasePropertyL(TUid::Uid(CTestBookmarksServer::GetTUint32(aUid)))); |
|
201 } |
|
202 else if(aCategory.Compare(KFolder()) == KErrNone) |
|
203 { |
|
204 TRAP(error, iBkDb.DeregisterFolderPropertyL(TUid::Uid(CTestBookmarksServer::GetTUint32(aUid)))); |
|
205 } |
|
206 else if(aCategory.Compare(KBookmark()) == KErrNone) |
|
207 { |
|
208 TRAP(error, iBkDb.DeregisterBookmarkPropertyL(TUid::Uid(CTestBookmarksServer::GetTUint32(aUid)))); |
|
209 } |
|
210 else |
|
211 { |
|
212 ERR_PRINTF2(_L("Invalid category: %S"), aCategory); |
|
213 SetTestStepResult(EFail); |
|
214 } |
|
215 return error; |
|
216 } |
|
217 |
|
218 /** |
|
219 Resolves whether to set or get a custom property and calls tha appropriate |
|
220 function |
|
221 @internalTechnology |
|
222 @test |
|
223 @param Operation to be performed : set/get/register/deregister |
|
224 @param Category: db/folder/bookmark |
|
225 @param Uid of the custom property |
|
226 @return None |
|
227 */ |
|
228 void CTestCustomPropertyStep::DoSetGetCustomPropertyL(const TPtrC& aOperation, const TPtrC& aCategory, const TPtrC& aUid) |
|
229 { |
|
230 TPtrC dataType; |
|
231 if(!GetStringFromConfig(ConfigSection(), KIniDataType, dataType)) |
|
232 { |
|
233 ERR_PRINTF2(_L("%S should be mentioned in ini for setting/getting a property"), &KIniDataType); |
|
234 SetTestStepResult(EFail); |
|
235 } |
|
236 else |
|
237 { |
|
238 if(aCategory.Compare(KDb) == KErrNone) |
|
239 { |
|
240 if(aOperation.Compare(KSetOperation) == KErrNone) |
|
241 { |
|
242 DoSetPropertyL(iBkDb, dataType, aUid); |
|
243 } |
|
244 else |
|
245 { |
|
246 DoGetPropertyL(iBkDb, dataType, aUid); |
|
247 } |
|
248 } |
|
249 else |
|
250 { |
|
251 TPtrC title; |
|
252 TPtrC typeOfItem; |
|
253 if(!GetStringFromConfig(ConfigSection(), KIniTypeOfItem, typeOfItem ) || |
|
254 !GetStringFromConfig(ConfigSection(), KIniTitle, title ) |
|
255 ) |
|
256 { |
|
257 ERR_PRINTF3(_L("%S and %S should be mentioned in ini for setting property for bookmark or a folder"), &KIniTypeOfItem, &KIniTitle); |
|
258 SetTestStepResult(EFail); |
|
259 } |
|
260 else |
|
261 { |
|
262 TInt error = KErrNone; |
|
263 RBkNode bkNode; |
|
264 if((error = GetBkNode(title, typeOfItem, bkNode)) != KErrNone) |
|
265 { |
|
266 ERR_PRINTF3(_L("Error occured while opening item %S : %D"), &title, error); |
|
267 SetTestStepError(error); |
|
268 } |
|
269 else |
|
270 {// Node opened successfully. Can Set or Get property |
|
271 if(aOperation.Compare(KSetOperation) == KErrNone) |
|
272 { |
|
273 DoSetPropertyL(bkNode, dataType, aUid); |
|
274 } |
|
275 else |
|
276 { |
|
277 DoGetPropertyL(bkNode, dataType, aUid); |
|
278 } |
|
279 bkNode.Close(); |
|
280 } |
|
281 } |
|
282 } |
|
283 } |
|
284 } // DoSetGetCustomProperty |
|
285 |
|
286 /** |
|
287 Template that sets the custom property using SetCustomPropertyL |
|
288 @internalTechnology |
|
289 @test |
|
290 @param Reference to handle to the DB/Folder/Bookmark |
|
291 @param Datatype of the property : int/real/des8/des16 |
|
292 @param Uid of the custom property |
|
293 @return None |
|
294 */ |
|
295 template <class RType> |
|
296 void CTestCustomPropertyStep::DoSetPropertyL(RType &aBkWho, const TPtrC& aDataType, const TPtrC& aUid) |
|
297 { |
|
298 TPtrC value; |
|
299 if(!GetStringFromConfig(ConfigSection(), KIniValue, value)) |
|
300 { |
|
301 ERR_PRINTF2(_L("%S should be mentioned in ini for setting a property"), &KIniValue); |
|
302 SetTestStepResult(EFail); |
|
303 } |
|
304 else |
|
305 { |
|
306 TInt error = KErrNone; |
|
307 INFO_PRINTF2(_L("Setting val for : %U"), CTestBookmarksServer::GetTUint32(aUid)); |
|
308 if(aDataType.Compare(KTypeInt) == KErrNone) |
|
309 { |
|
310 TRAP(error, aBkWho.SetCustomPropertyL(TUid::Uid(CTestBookmarksServer::GetTUint32(aUid)), CTestBookmarksServer::GetTInt(value))); |
|
311 } |
|
312 else if(aDataType.Compare(KTypeReal) == KErrNone) |
|
313 { |
|
314 TRAP(error, aBkWho.SetCustomPropertyL(TUid::Uid(CTestBookmarksServer::GetTUint32(aUid)), CTestBookmarksServer::GetTReal(value))); |
|
315 } |
|
316 else if(aDataType.Compare(KTypeDes8) == KErrNone) |
|
317 { |
|
318 // Construct 8-bit descriptor |
|
319 HBufC8* hBufC8 = HBufC8::NewL(value.Length()); |
|
320 hBufC8->Des().Copy(value); |
|
321 TRAP(error, aBkWho.SetCustomPropertyL(TUid::Uid(CTestBookmarksServer::GetTUint32(aUid)), hBufC8->Des())); |
|
322 delete hBufC8; |
|
323 } |
|
324 else if(aDataType.Compare(KTypeDes16) == KErrNone) |
|
325 { |
|
326 TRAP(error, aBkWho.SetCustomPropertyL(TUid::Uid(CTestBookmarksServer::GetTUint32(aUid)), value)); |
|
327 } |
|
328 else |
|
329 { |
|
330 ERR_PRINTF2(_L("Invalid datatype: %S"), &aDataType); |
|
331 SetTestStepResult(EFail); |
|
332 } |
|
333 |
|
334 // Examine the result |
|
335 CheckErrorAndCommit(error); |
|
336 } |
|
337 } // DoSetPropertyL |
|
338 |
|
339 /** |
|
340 Gets the custom property using GetCustomPropertyL and compares with |
|
341 expected result |
|
342 @internalTechnology |
|
343 @test |
|
344 @param Reference to handle to the DB/Folder/Bookmark |
|
345 @param Datatype of the property : int/real/des8/des16 |
|
346 @param Uid of the custom property |
|
347 @return None |
|
348 */ |
|
349 template <class RType> |
|
350 void CTestCustomPropertyStep::DoGetPropertyL(RType &aBkWho, const TPtrC& aDataType, const TPtrC& aUid) |
|
351 { |
|
352 TPtrC expectedValue; |
|
353 if(!GetStringFromConfig(ConfigSection(), KIniExpectedValue, expectedValue)) |
|
354 { |
|
355 ERR_PRINTF2(_L("%S should be mentioned in ini for setting a property"), &KIniExpectedValue); |
|
356 SetTestStepResult(EFail); |
|
357 } |
|
358 else |
|
359 { |
|
360 TInt error = KErrNone; |
|
361 TVerdict verdict = EPass; |
|
362 |
|
363 // Check the datatype and process accordingly |
|
364 if(aDataType.Compare(KTypeInt) == KErrNone) |
|
365 { |
|
366 TInt retVal = KErrNone; |
|
367 TRAP(error, aBkWho.GetCustomPropertyL(TUid::Uid(CTestBookmarksServer::GetTUint32(aUid)), retVal)); |
|
368 if(error == KErrNone) |
|
369 { |
|
370 verdict = CompareTInts(retVal, CTestBookmarksServer::GetTInt(expectedValue)); |
|
371 } |
|
372 } |
|
373 else if(aDataType.Compare(KTypeReal) == KErrNone) |
|
374 { |
|
375 TReal retVal = KErrNone; |
|
376 TRAP(error, aBkWho.GetCustomPropertyL(TUid::Uid(CTestBookmarksServer::GetTUint32(aUid)), retVal)); |
|
377 if(error == KErrNone) |
|
378 { |
|
379 verdict = CompareTReals(retVal, CTestBookmarksServer::GetTReal(expectedValue)); |
|
380 } |
|
381 } |
|
382 else if(aDataType.Compare(KTypeDes8) == KErrNone) |
|
383 { |
|
384 // Construct 8-bit descriptor |
|
385 HBufC8* retVal8 = HBufC8::NewL(Bookmark::KMaxDataLength); |
|
386 TPtr8 ptr8 = retVal8->Des(); |
|
387 TRAP(error, aBkWho.GetCustomPropertyL(TUid::Uid(CTestBookmarksServer::GetTUint32(aUid)), ptr8)); |
|
388 if(error == KErrNone) |
|
389 { |
|
390 CleanupStack::PushL(retVal8); |
|
391 HBufC* retVal = HBufC::NewL(ptr8.Length()); |
|
392 retVal->Des().Copy(ptr8); |
|
393 verdict = CompareStrings(retVal->Des(), expectedValue); |
|
394 delete retVal; |
|
395 } |
|
396 CleanupStack::PopAndDestroy(retVal8); |
|
397 } |
|
398 else if(aDataType.Compare(KTypeDes16) == KErrNone) |
|
399 { |
|
400 HBufC* retVal = HBufC::NewL(Bookmark::KMaxDataLength); |
|
401 TPtr ptr = retVal->Des(); |
|
402 TRAP(error, aBkWho.GetCustomPropertyL(TUid::Uid(CTestBookmarksServer::GetTUint32(aUid)), ptr)); |
|
403 if(error == KErrNone) |
|
404 { |
|
405 verdict = CompareStrings(ptr, expectedValue); |
|
406 } |
|
407 delete retVal; |
|
408 } |
|
409 else |
|
410 { |
|
411 ERR_PRINTF2(_L("Invalid datatype: %S"), &aDataType); |
|
412 SetTestStepResult(EFail); |
|
413 } |
|
414 |
|
415 // Examine the result |
|
416 CheckErrorAndVerdict(error, verdict); |
|
417 } |
|
418 } // DoGetPropertyL |
|
419 |
|
420 |