First public contribution.
2 * Copyright (c) 2001-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.
15 * Implementation for testing boolean object encoding/decoding
20 #include "testboolean.h"
21 #include "tasn1normaltest.h"
27 CTestBoolean* CTestBoolean::NewL(CASN1NormalTest &aASN1Action)
29 CTestBoolean* test = new (ELeave) CTestBoolean(aASN1Action);
33 CTestBoolean::CTestBoolean(CASN1NormalTest &aASN1Action) : CTestBase(aASN1Action)
37 void CTestBoolean::GetName(TDes& aBuf)
39 aBuf.Copy(_L("Test Boolean"));
42 void CTestBoolean::FillParameterArray(void)
44 iParameters->Append(CTestParameter::EInt);
48 TBool CTestBoolean::PerformTest(CConsoleBase& aConsole, const TBool& aTest)
51 CASN1EncBoolean* encoder = CASN1EncBoolean::NewLC(aTest);
54 TInt length = encoder->LengthDER();
55 HBufC8* buf = HBufC8::NewMaxLC(length);
56 TPtr8 tBuf = buf->Des();
58 // Write into the buffer
59 TUint writeLength = 0;
60 encoder->WriteDERL(tBuf, writeLength);
62 // Read it out again + check lengths
63 TASN1DecBoolean decoder;
65 TBool decodedValue = decoder.DecodeDERL(tBuf, readLength);
67 if (writeLength != STATIC_CAST(TUint, readLength) || decodedValue != aTest)
69 aConsole.Write(_L("ERROR!\n"));
70 iASN1Action.ReportProgressL(KErrASN1EncodingError, 1, 1);
71 CleanupStack::PopAndDestroy(2); // buf, encoder
76 iASN1Action.ReportProgressL(KErrNone, 1, 1);
77 CleanupStack::PopAndDestroy(2); // buf, encoder
83 TBool CTestBoolean::PerformTestsL(CConsoleBase& aConsole)
88 if(!CountTests(totalTests)) return(EFalse);
90 for(TInt pos = 0; pos < iValues->Count(); pos++)
92 test = (*iValues)[pos];
94 switch(test->GetType())
96 case CTestParameter::EInt :
98 CIntTestParameter *rangeInt = REINTERPRET_CAST(CIntTestParameter*, test);
100 if(!PerformTest(aConsole, rangeInt->Value()))
104 case CTestParameter::EIntRange :
106 CIntRangeTestParameter *rangeInt = REINTERPRET_CAST(CIntRangeTestParameter*, test);
108 for(TInt test = rangeInt->Start(); test <= rangeInt->Finish(); test++)
110 if(!PerformTest(aConsole, test))
121 iASN1Action.ReportProgressL(KErrNone, totalTests, totalTests);