cryptoservices/certificateandkeymgmt/tasn1/testnull.cpp
changeset 0 2c201484c85f
child 8 35751d3474b7
equal deleted inserted replaced
-1:000000000000 0:2c201484c85f
       
     1 /*
       
     2 * Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     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".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 * Implementation for testing null object encoding/decoding
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include "testnull.h"
       
    21 #include "tasn1normaltest.h"
       
    22 #include <asn1enc.h>
       
    23 #include <asn1dec.h>
       
    24 
       
    25 #include <e32cons.h>
       
    26 
       
    27 CTestNull* CTestNull::NewL(CASN1NormalTest &aASN1Action)
       
    28 	{
       
    29 	CTestNull* test = new (ELeave) CTestNull(aASN1Action);
       
    30 	return test;
       
    31 	}
       
    32 
       
    33 CTestNull::CTestNull(CASN1NormalTest &aASN1Action) : CTestBase(aASN1Action)
       
    34 	{
       
    35 	};
       
    36 
       
    37 void CTestNull::GetName(TDes& aBuf)
       
    38 	{
       
    39 	aBuf.Copy(_L("Test Null"));
       
    40 	}
       
    41 
       
    42 TBool CTestNull::PerformTestsL(CConsoleBase& aConsole)
       
    43 	{
       
    44 	// Get the encoder and decoder
       
    45 	CASN1EncNull* encoder = CASN1EncNull::NewLC();
       
    46 	TASN1DecNull decoder;
       
    47 
       
    48 	// Prepare a buffer
       
    49 	TInt totalLength = encoder->LengthDER();
       
    50 	HBufC8* buf = HBufC8::NewMaxLC(totalLength);
       
    51 	TPtr8 tBuf = buf->Des();
       
    52 	
       
    53 	// Write into the buffer
       
    54 	TUint writeLength = 0;
       
    55 	encoder->WriteDERL(tBuf, writeLength);
       
    56 
       
    57 	// Read it out again + check lengths
       
    58 	TInt readLength = 0;
       
    59 	decoder.DecodeDERL(tBuf, readLength);
       
    60 
       
    61 	if (writeLength != STATIC_CAST(TUint, readLength))
       
    62 		{
       
    63 		aConsole.Write(_L("ERROR!\n"));
       
    64 		iASN1Action.ReportProgressL(KErrASN1EncodingError, 1, 1);
       
    65 		CleanupStack::PopAndDestroy(2); // buf, encoder
       
    66 		return(EFalse);
       
    67 		}
       
    68 	else
       
    69 		{
       
    70 		iASN1Action.ReportProgressL(KErrNone, 1, 1);
       
    71 		CleanupStack::PopAndDestroy(2); // buf, encoder
       
    72 		return(ETrue);
       
    73 		}
       
    74 	}