sl@0: /* sl@0: * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "bitsetstep.h" sl@0: sl@0: const TInt KAttrTop = 10; sl@0: sl@0: using namespace ContentAccess; sl@0: sl@0: CBitsetBaseStep::CBitsetBaseStep(const TDesC& aStepName) sl@0: { sl@0: SetTestStepName(aStepName); sl@0: } sl@0: sl@0: TVerdict CBitsetBaseStep::doTestStepPreambleL() sl@0: { sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: TVerdict CBitsetBaseStep::doTestStepPostambleL() sl@0: { sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: CBitset* CBitsetBaseStep::GetBitsetLC(const TDesC& aHeader) sl@0: { sl@0: _LIT(KBitCount, "bitcount"); sl@0: _LIT(KBit, "bit%02d"); sl@0: sl@0: // Firstly, from the script, get the number of bits to set. If aHeader sl@0: // is "left-", then the bitcount key is "left-bitcount" sl@0: HBufC* buf = HBufC::NewLC(aHeader.Length() + KBitCount().Length()); sl@0: TPtr ptr(buf->Des()); sl@0: ptr = aHeader; sl@0: ptr.Append(KBitCount()); sl@0: TInt bitcount = 0; sl@0: GetIntFromConfig(ConfigSection(), ptr, bitcount); sl@0: sl@0: INFO_PRINTF3(_L("%S = %d"), &ptr, bitcount); sl@0: sl@0: // Now, create the bitset sl@0: CBitset* bitset = CBitset::NewLC(bitcount); sl@0: sl@0: TInt i = 0; sl@0: for (; i < bitcount; ++i) sl@0: { sl@0: TInt bit = 0; sl@0: ptr = aHeader; sl@0: ptr.AppendFormat(KBit, i); sl@0: GetIntFromConfig(ConfigSection(), ptr, bit); sl@0: if (bit) sl@0: { sl@0: bitset->Set(i); sl@0: INFO_PRINTF2(_L("%S is set"), &ptr); sl@0: } sl@0: } sl@0: sl@0: CleanupStack::Pop(bitset); sl@0: CleanupStack::PopAndDestroy(buf); sl@0: CleanupStack::PushL(bitset); sl@0: return bitset; sl@0: } sl@0: sl@0: /* sl@0: * Step2 performs some basic internal Bitset sanity tests sl@0: * sl@0: */ sl@0: sl@0: CBasicBitsetStep::CBasicBitsetStep() sl@0: : CBitsetBaseStep(KBasicBitsetStep) sl@0: { sl@0: } sl@0: sl@0: // EIsProtected EIsForwardable EIsModifyable EIsCopyable sl@0: TVerdict CBasicBitsetStep::doTestStepL() sl@0: { sl@0: TInt i; sl@0: SetTestStepResult(EPass); // Default result to PASS sl@0: sl@0: __UHEAP_MARK; sl@0: INFO_PRINTF1(_L("Basic Bitset Test")); sl@0: sl@0: // Note we must size according to current EAttrTop (attribute.h) sl@0: INFO_PRINTF1(_L("Creating set1...")); sl@0: CBitset *set1 = CBitset::NewLC((TAttribute) KAttrTop); // on cleanup sl@0: sl@0: // check that all the bits are initially not set sl@0: for(i = 0; i < KAttrTop; i++) sl@0: { sl@0: if (set1->IsSet(i)) sl@0: { sl@0: INFO_PRINTF1(_L("Bitset::NewLC() test failed.")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: } sl@0: sl@0: INFO_PRINTF1(_L("Performing single bit set/test...")); sl@0: set1->Set(EIsForwardable); sl@0: sl@0: // check that only EIsForwardable is set sl@0: for(i = 0; i < KAttrTop; i++) sl@0: { sl@0: if (set1->IsSet(i) && i != EIsForwardable) sl@0: { sl@0: INFO_PRINTF1(_L("Single test/set(1) test failed.")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: } sl@0: if (!set1->IsSet(EIsForwardable)) sl@0: { sl@0: INFO_PRINTF1(_L("Single test/set(2) failed.")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: set1->Unset(EIsForwardable); sl@0: sl@0: // check that none of the bits are set sl@0: for(i = 0; i < KAttrTop; i++) sl@0: { sl@0: if (set1->IsSet(i)) sl@0: { sl@0: INFO_PRINTF1(_L("Single test/set(3) failed.")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: } sl@0: sl@0: INFO_PRINTF1(_L("Performing setall tests...")); sl@0: set1->SetAll(); sl@0: sl@0: // check that all bits are set sl@0: for(i = 0; i < KAttrTop; i++) sl@0: { sl@0: if (!set1->IsSet(i)) sl@0: { sl@0: INFO_PRINTF1(_L("SetAll test failed.")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: } sl@0: sl@0: set1->Reset(); sl@0: sl@0: // check all bits are reset sl@0: for(i = 0; i < KAttrTop; i++) sl@0: { sl@0: if (set1->IsSet(i)) sl@0: { sl@0: INFO_PRINTF1(_L("Reset test failed.")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(set1); sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: // -------------------------------------------------------------------------- sl@0: // This step tests the bitset SetList and IsSetList functions sl@0: sl@0: CBitsetListStep::CBitsetListStep() sl@0: : CBitsetBaseStep(KBitsetListStep) sl@0: { sl@0: } sl@0: sl@0: TVerdict CBitsetListStep::doTestStepL() sl@0: { sl@0: TInt i; sl@0: SetTestStepResult(EPass); sl@0: sl@0: __UHEAP_MARK; sl@0: sl@0: INFO_PRINTF1(_L("Creating set1...")); sl@0: sl@0: CBitset *set1 = CBitset::NewLC(KAttrTop); sl@0: sl@0: INFO_PRINTF1(_L("Performing SetList call")); sl@0: set1->SetListL(2, EIsCopyable, EIsModifyable); sl@0: sl@0: for(i = 0; i < KAttrTop; i++) sl@0: { sl@0: if (set1->IsSet(i) && i != EIsCopyable && i != EIsModifyable) sl@0: { sl@0: INFO_PRINTF1(_L("SetList(1) failed.")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: } sl@0: sl@0: if (!set1->IsSet(EIsModifyable) || !set1->IsSet(EIsCopyable)) sl@0: { sl@0: INFO_PRINTF1(_L("SetList(2) failed.")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: // Now check the IsSetList call sl@0: INFO_PRINTF1(_L("Performing IsSetList calls")); sl@0: if (!set1->IsSetList(2, EIsCopyable, EIsModifyable)) sl@0: { sl@0: INFO_PRINTF1(_L("IsSetList call(3) failed.")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: if (set1->IsSetList(2, EIsProtected, EIsForwardable)) sl@0: { sl@0: INFO_PRINTF1(_L("IsSetList call(4) failed.")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(set1); sl@0: __UHEAP_MARKEND; sl@0: sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: // -------------------------------------------------------------------------- sl@0: sl@0: CBitsetEqualityStep::CBitsetEqualityStep() sl@0: : CBitsetBaseStep(KBitsetEqualityStep) sl@0: { sl@0: } sl@0: sl@0: TVerdict CBitsetEqualityStep::doTestStepL() sl@0: { sl@0: SetTestStepResult(EPass); // Default result to EPass sl@0: sl@0: __UHEAP_MARK; sl@0: // Get the bitset from the script section sl@0: CBitset* left = GetBitsetLC(_L("left-")); sl@0: CBitset* right = GetBitsetLC(_L("right-")); sl@0: sl@0: // Now see whether we expect the result to be equal sl@0: TBool equalExpected = EFalse; sl@0: GetIntFromConfig(ConfigSection(), _L("equal"), equalExpected); sl@0: sl@0: if (equalExpected) sl@0: { sl@0: INFO_PRINTF1(_L("Equality expected")); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Inequality expected")); sl@0: } sl@0: sl@0: TBool result = (*left == *right); sl@0: if (!result != !equalExpected) sl@0: { sl@0: INFO_PRINTF1(_L("Equality test failed.")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: CleanupStack::PopAndDestroy(2, left); sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: // -------------------------------------------------------------------------- sl@0: sl@0: CBitsetCopyStep::CBitsetCopyStep() sl@0: : CBitsetBaseStep(KBitsetCopyStep) sl@0: { sl@0: } sl@0: sl@0: TVerdict CBitsetCopyStep::doTestStepL() sl@0: { sl@0: SetTestStepResult(EPass); // Default result to EPass sl@0: sl@0: __UHEAP_MARK; sl@0: // Get the bitset from the script section sl@0: CBitset* set = GetBitsetLC(KNullDesC); sl@0: sl@0: // Now, create a copy sl@0: CBitset* copy = CBitset::NewLC(*set); sl@0: sl@0: // Now check the copy sl@0: if (*set != *copy) sl@0: { sl@0: INFO_PRINTF1(_L("Copy constructor return unequal result.")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: // Now create another bitset of arbitrary length sl@0: CBitset* another = CBitset::NewLC(5); sl@0: sl@0: // Perform assignment sl@0: *another = *copy; sl@0: sl@0: // Now check another equals the original set sl@0: if (*set != *another) sl@0: { sl@0: INFO_PRINTF1(_L("operator= returned unequal result.")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: // Now invert another and copy and make sure they are equal sl@0: another->Invert(); sl@0: copy->Invert(); sl@0: sl@0: if (*copy != *another) sl@0: { sl@0: INFO_PRINTF1(_L("Invert returned unequal result.")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: // Invert the copy again and ensure it is equal to the original sl@0: copy->Invert(); sl@0: if (*set != *copy) sl@0: { sl@0: INFO_PRINTF1(_L("Double invert fails.")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(3, set); sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: // -------------------------------------------------------------------------- sl@0: sl@0: CBitsetSerialiseStep::CBitsetSerialiseStep() sl@0: : CBitsetBaseStep(KBitsetSerialiseStep) sl@0: { sl@0: } sl@0: sl@0: TVerdict CBitsetSerialiseStep::doTestStepL() sl@0: { sl@0: SetTestStepResult(EPass); // Default result to EPass sl@0: sl@0: __UHEAP_MARK; sl@0: // Get the bitset from the script section sl@0: CBitset* set = GetBitsetLC(KNullDesC); sl@0: sl@0: // Create a buffer stream sl@0: CBufFlat* buf = CBufFlat::NewL(50); sl@0: CleanupStack::PushL(buf); sl@0: RBufWriteStream stream(*buf); sl@0: CleanupClosePushL(stream); sl@0: sl@0: // call the stream function sl@0: stream << *set; sl@0: CleanupStack::PopAndDestroy(&stream); sl@0: sl@0: // Now, create an HBufC8 from the stream buf's length, and copy sl@0: // the stream buffer into this descriptor sl@0: HBufC8* des = HBufC8::NewL(buf->Size()); sl@0: TPtr8 ptr(des->Des()); sl@0: buf->Read(0, ptr, buf->Size()); sl@0: sl@0: // destroy the buffer sl@0: CleanupStack::PopAndDestroy(buf); sl@0: CleanupStack::PushL(des); sl@0: sl@0: // Now, stream a new bitset from the descriptor sl@0: CBitset* newset = CBitset::NewLC(5); sl@0: RDesReadStream readstream(*des); sl@0: CleanupClosePushL(readstream); sl@0: readstream >> *newset; sl@0: CleanupStack::PopAndDestroy(&readstream); sl@0: sl@0: // Now check that the new bitset equals the old one sl@0: if (*set != *newset) sl@0: { sl@0: INFO_PRINTF1(_L("serialisation returned unequal result.")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(3, set); sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: // -------------------------------------------------------------------------- sl@0: sl@0: CBitsetPanicStep::CBitsetPanicStep() sl@0: : CBitsetBaseStep(KBitsetPanicStep) sl@0: { sl@0: } sl@0: sl@0: TVerdict CBitsetPanicStep::doTestStepL() sl@0: { sl@0: SetTestStepResult(EPass); // Default result to EPass sl@0: sl@0: __UHEAP_MARK; sl@0: // Get the bitset from the script section sl@0: CBitset* panic = GetBitsetLC(_L("panic-")); sl@0: sl@0: // Now see whether we expect the result to be equal sl@0: TInt panictest = -1; sl@0: GetIntFromConfig(ConfigSection(), _L("panictest"), panictest); sl@0: sl@0: // all of the following cases should panic sl@0: switch(panictest) sl@0: { sl@0: case 1: sl@0: INFO_PRINTF1(_L("IsSet(-1)")); sl@0: panic->IsSet(-1); sl@0: break; sl@0: case 2: sl@0: INFO_PRINTF1(_L("IsSet(MaxBits()+1)")); sl@0: panic->IsSet(panic->MaxBits()+1); sl@0: break; sl@0: case 3: sl@0: INFO_PRINTF1(_L("Set(-1)")); sl@0: panic->Set(-1); sl@0: break; sl@0: case 4: sl@0: INFO_PRINTF1(_L("Set(MaxBits()+1)")); sl@0: panic->Set(panic->MaxBits()+1); sl@0: break; sl@0: case 5: sl@0: INFO_PRINTF1(_L("UnSet(-1)")); sl@0: panic->Unset(-1); sl@0: break; sl@0: case 6: sl@0: INFO_PRINTF1(_L("UnSet(MaxBits()+1)")); sl@0: panic->Unset(panic->MaxBits()+1); sl@0: break; sl@0: sl@0: default: sl@0: SetTestStepResult(EFail); sl@0: }; sl@0: sl@0: SetTestStepResult(EFail); sl@0: CleanupStack::PopAndDestroy(panic); sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: return TestStepResult(); sl@0: } sl@0: