Update contrib.
2 * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
20 #include <caf/bitset.h>
21 #include <caf/attribute.h>
23 #include "bitsetstep.h"
25 const TInt KAttrTop = 10;
27 using namespace ContentAccess;
29 CBitsetBaseStep::CBitsetBaseStep(const TDesC& aStepName)
31 SetTestStepName(aStepName);
34 TVerdict CBitsetBaseStep::doTestStepPreambleL()
36 return TestStepResult();
39 TVerdict CBitsetBaseStep::doTestStepPostambleL()
41 return TestStepResult();
44 CBitset* CBitsetBaseStep::GetBitsetLC(const TDesC& aHeader)
46 _LIT(KBitCount, "bitcount");
47 _LIT(KBit, "bit%02d");
49 // Firstly, from the script, get the number of bits to set. If aHeader
50 // is "left-", then the bitcount key is "left-bitcount"
51 HBufC* buf = HBufC::NewLC(aHeader.Length() + KBitCount().Length());
54 ptr.Append(KBitCount());
56 GetIntFromConfig(ConfigSection(), ptr, bitcount);
58 INFO_PRINTF3(_L("%S = %d"), &ptr, bitcount);
60 // Now, create the bitset
61 CBitset* bitset = CBitset::NewLC(bitcount);
64 for (; i < bitcount; ++i)
68 ptr.AppendFormat(KBit, i);
69 GetIntFromConfig(ConfigSection(), ptr, bit);
73 INFO_PRINTF2(_L("%S is set"), &ptr);
77 CleanupStack::Pop(bitset);
78 CleanupStack::PopAndDestroy(buf);
79 CleanupStack::PushL(bitset);
84 * Step2 performs some basic internal Bitset sanity tests
88 CBasicBitsetStep::CBasicBitsetStep()
89 : CBitsetBaseStep(KBasicBitsetStep)
93 // EIsProtected EIsForwardable EIsModifyable EIsCopyable
94 TVerdict CBasicBitsetStep::doTestStepL()
97 SetTestStepResult(EPass); // Default result to PASS
100 INFO_PRINTF1(_L("Basic Bitset Test"));
102 // Note we must size according to current EAttrTop (attribute.h)
103 INFO_PRINTF1(_L("Creating set1..."));
104 CBitset *set1 = CBitset::NewLC((TAttribute) KAttrTop); // on cleanup
106 // check that all the bits are initially not set
107 for(i = 0; i < KAttrTop; i++)
111 INFO_PRINTF1(_L("Bitset::NewLC() test failed."));
112 SetTestStepResult(EFail);
116 INFO_PRINTF1(_L("Performing single bit set/test..."));
117 set1->Set(EIsForwardable);
119 // check that only EIsForwardable is set
120 for(i = 0; i < KAttrTop; i++)
122 if (set1->IsSet(i) && i != EIsForwardable)
124 INFO_PRINTF1(_L("Single test/set(1) test failed."));
125 SetTestStepResult(EFail);
128 if (!set1->IsSet(EIsForwardable))
130 INFO_PRINTF1(_L("Single test/set(2) failed."));
131 SetTestStepResult(EFail);
134 set1->Unset(EIsForwardable);
136 // check that none of the bits are set
137 for(i = 0; i < KAttrTop; i++)
141 INFO_PRINTF1(_L("Single test/set(3) failed."));
142 SetTestStepResult(EFail);
146 INFO_PRINTF1(_L("Performing setall tests..."));
149 // check that all bits are set
150 for(i = 0; i < KAttrTop; i++)
154 INFO_PRINTF1(_L("SetAll test failed."));
155 SetTestStepResult(EFail);
161 // check all bits are reset
162 for(i = 0; i < KAttrTop; i++)
166 INFO_PRINTF1(_L("Reset test failed."));
167 SetTestStepResult(EFail);
171 CleanupStack::PopAndDestroy(set1);
175 return TestStepResult();
178 // --------------------------------------------------------------------------
179 // This step tests the bitset SetList and IsSetList functions
181 CBitsetListStep::CBitsetListStep()
182 : CBitsetBaseStep(KBitsetListStep)
186 TVerdict CBitsetListStep::doTestStepL()
189 SetTestStepResult(EPass);
193 INFO_PRINTF1(_L("Creating set1..."));
195 CBitset *set1 = CBitset::NewLC(KAttrTop);
197 INFO_PRINTF1(_L("Performing SetList call"));
198 set1->SetListL(2, EIsCopyable, EIsModifyable);
200 for(i = 0; i < KAttrTop; i++)
202 if (set1->IsSet(i) && i != EIsCopyable && i != EIsModifyable)
204 INFO_PRINTF1(_L("SetList(1) failed."));
205 SetTestStepResult(EFail);
209 if (!set1->IsSet(EIsModifyable) || !set1->IsSet(EIsCopyable))
211 INFO_PRINTF1(_L("SetList(2) failed."));
212 SetTestStepResult(EFail);
215 // Now check the IsSetList call
216 INFO_PRINTF1(_L("Performing IsSetList calls"));
217 if (!set1->IsSetList(2, EIsCopyable, EIsModifyable))
219 INFO_PRINTF1(_L("IsSetList call(3) failed."));
220 SetTestStepResult(EFail);
223 if (set1->IsSetList(2, EIsProtected, EIsForwardable))
225 INFO_PRINTF1(_L("IsSetList call(4) failed."));
226 SetTestStepResult(EFail);
229 CleanupStack::PopAndDestroy(set1);
232 return TestStepResult();
235 // --------------------------------------------------------------------------
237 CBitsetEqualityStep::CBitsetEqualityStep()
238 : CBitsetBaseStep(KBitsetEqualityStep)
242 TVerdict CBitsetEqualityStep::doTestStepL()
244 SetTestStepResult(EPass); // Default result to EPass
247 // Get the bitset from the script section
248 CBitset* left = GetBitsetLC(_L("left-"));
249 CBitset* right = GetBitsetLC(_L("right-"));
251 // Now see whether we expect the result to be equal
252 TBool equalExpected = EFalse;
253 GetIntFromConfig(ConfigSection(), _L("equal"), equalExpected);
257 INFO_PRINTF1(_L("Equality expected"));
261 INFO_PRINTF1(_L("Inequality expected"));
264 TBool result = (*left == *right);
265 if (!result != !equalExpected)
267 INFO_PRINTF1(_L("Equality test failed."));
268 SetTestStepResult(EFail);
270 CleanupStack::PopAndDestroy(2, left);
274 return TestStepResult();
277 // --------------------------------------------------------------------------
279 CBitsetCopyStep::CBitsetCopyStep()
280 : CBitsetBaseStep(KBitsetCopyStep)
284 TVerdict CBitsetCopyStep::doTestStepL()
286 SetTestStepResult(EPass); // Default result to EPass
289 // Get the bitset from the script section
290 CBitset* set = GetBitsetLC(KNullDesC);
292 // Now, create a copy
293 CBitset* copy = CBitset::NewLC(*set);
295 // Now check the copy
298 INFO_PRINTF1(_L("Copy constructor return unequal result."));
299 SetTestStepResult(EFail);
302 // Now create another bitset of arbitrary length
303 CBitset* another = CBitset::NewLC(5);
305 // Perform assignment
308 // Now check another equals the original set
309 if (*set != *another)
311 INFO_PRINTF1(_L("operator= returned unequal result."));
312 SetTestStepResult(EFail);
315 // Now invert another and copy and make sure they are equal
319 if (*copy != *another)
321 INFO_PRINTF1(_L("Invert returned unequal result."));
322 SetTestStepResult(EFail);
325 // Invert the copy again and ensure it is equal to the original
329 INFO_PRINTF1(_L("Double invert fails."));
330 SetTestStepResult(EFail);
333 CleanupStack::PopAndDestroy(3, set);
337 return TestStepResult();
340 // --------------------------------------------------------------------------
342 CBitsetSerialiseStep::CBitsetSerialiseStep()
343 : CBitsetBaseStep(KBitsetSerialiseStep)
347 TVerdict CBitsetSerialiseStep::doTestStepL()
349 SetTestStepResult(EPass); // Default result to EPass
352 // Get the bitset from the script section
353 CBitset* set = GetBitsetLC(KNullDesC);
355 // Create a buffer stream
356 CBufFlat* buf = CBufFlat::NewL(50);
357 CleanupStack::PushL(buf);
358 RBufWriteStream stream(*buf);
359 CleanupClosePushL(stream);
361 // call the stream function
363 CleanupStack::PopAndDestroy(&stream);
365 // Now, create an HBufC8 from the stream buf's length, and copy
366 // the stream buffer into this descriptor
367 HBufC8* des = HBufC8::NewL(buf->Size());
368 TPtr8 ptr(des->Des());
369 buf->Read(0, ptr, buf->Size());
371 // destroy the buffer
372 CleanupStack::PopAndDestroy(buf);
373 CleanupStack::PushL(des);
375 // Now, stream a new bitset from the descriptor
376 CBitset* newset = CBitset::NewLC(5);
377 RDesReadStream readstream(*des);
378 CleanupClosePushL(readstream);
379 readstream >> *newset;
380 CleanupStack::PopAndDestroy(&readstream);
382 // Now check that the new bitset equals the old one
385 INFO_PRINTF1(_L("serialisation returned unequal result."));
386 SetTestStepResult(EFail);
389 CleanupStack::PopAndDestroy(3, set);
393 return TestStepResult();
396 // --------------------------------------------------------------------------
398 CBitsetPanicStep::CBitsetPanicStep()
399 : CBitsetBaseStep(KBitsetPanicStep)
403 TVerdict CBitsetPanicStep::doTestStepL()
405 SetTestStepResult(EPass); // Default result to EPass
408 // Get the bitset from the script section
409 CBitset* panic = GetBitsetLC(_L("panic-"));
411 // Now see whether we expect the result to be equal
413 GetIntFromConfig(ConfigSection(), _L("panictest"), panictest);
415 // all of the following cases should panic
419 INFO_PRINTF1(_L("IsSet(-1)"));
423 INFO_PRINTF1(_L("IsSet(MaxBits()+1)"));
424 panic->IsSet(panic->MaxBits()+1);
427 INFO_PRINTF1(_L("Set(-1)"));
431 INFO_PRINTF1(_L("Set(MaxBits()+1)"));
432 panic->Set(panic->MaxBits()+1);
435 INFO_PRINTF1(_L("UnSet(-1)"));
439 INFO_PRINTF1(_L("UnSet(MaxBits()+1)"));
440 panic->Unset(panic->MaxBits()+1);
444 SetTestStepResult(EFail);
447 SetTestStepResult(EFail);
448 CleanupStack::PopAndDestroy(panic);
452 return TestStepResult();