crypto/weakcrypto/test/tbigint/tbasicmathsvector.cpp
changeset 0 2c201484c85f
equal deleted inserted replaced
-1:000000000000 0:2c201484c85f
       
     1 /*
       
     2 * Copyright (c) 2002-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 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "tbasicmathsvector.h"
       
    20 #include "t_input.h"
       
    21 #include <bigint.h>
       
    22 
       
    23 CTestAction* CBasicMathsVector::NewL(RFs& aFs, CConsoleBase& aConsole, 
       
    24 	Output& aOut, const TTestActionSpec& aTestActionSpec)
       
    25 	{
       
    26 	CTestAction* self = CBasicMathsVector::NewLC(aFs, aConsole,
       
    27 		aOut, aTestActionSpec);
       
    28 	CleanupStack::Pop();
       
    29 	return self;
       
    30 	}
       
    31 
       
    32 CTestAction* CBasicMathsVector::NewLC(RFs& aFs, CConsoleBase& aConsole, 
       
    33 	Output& aOut, const TTestActionSpec& aTestActionSpec)
       
    34 	{
       
    35 	CBasicMathsVector* self = new(ELeave) CBasicMathsVector(aFs, aConsole, aOut);
       
    36 	CleanupStack::PushL(self);
       
    37 	self->ConstructL(aTestActionSpec);
       
    38 	return self;
       
    39 	}
       
    40 
       
    41 CBasicMathsVector::~CBasicMathsVector()
       
    42 	{
       
    43 	delete iBody;
       
    44 	delete iA;
       
    45 	delete iB;
       
    46 	delete iAns;
       
    47 	}
       
    48 
       
    49 CBasicMathsVector::CBasicMathsVector(RFs& aFs, CConsoleBase& aConsole, 
       
    50 	Output& aOut) : CTestAction(aConsole, aOut), iFs(aFs)
       
    51 	{
       
    52 	}
       
    53 
       
    54 void CBasicMathsVector::ConstructL(const TTestActionSpec& aTestActionSpec)
       
    55 	{
       
    56 	CTestAction::ConstructL(aTestActionSpec);
       
    57 	iBody = HBufC8::NewL(aTestActionSpec.iActionBody.Length());
       
    58 	iBody->Des().Copy(aTestActionSpec.iActionBody);
       
    59 
       
    60 	iA = Input::ParseElementHexL(*iBody, _L8("<a>"));
       
    61 	iB = Input::ParseElementHexL(*iBody, _L8("<b>"));
       
    62 	iAns = Input::ParseElementHexL(*iBody, _L8("<ans>"));
       
    63 	TPtrC8 op = Input::ParseElement(*iBody, _L8("<op>"));
       
    64 	if( op == _L8("add") )
       
    65 		{
       
    66 		iOp = EAdd;
       
    67 		}
       
    68 	else if( op == _L8("subtract") )
       
    69 		{
       
    70 		iOp = ESubtract;
       
    71 		}
       
    72 	else if( op == _L8("multiply") )
       
    73 		{
       
    74 		iOp = EMultiply;
       
    75 		}
       
    76 	else if( op == _L8("divide") )
       
    77 		{
       
    78 		iOp = EDivide;
       
    79 		}
       
    80 	else if( op == _L8("modulus") )
       
    81 		{
       
    82 		iOp = EModulus;
       
    83 		}
       
    84 	else if( op == _L8("gcd") )
       
    85 		{
       
    86 		iOp = EGCD;
       
    87 		}
       
    88 	else if( op == _L8("inversemod") )
       
    89 		{
       
    90 		iOp = EInverseMod;
       
    91 		}
       
    92 	else 
       
    93 		{
       
    94 		User::Panic(_L("tbasicmathsvector"), 1);
       
    95 		}
       
    96 	}
       
    97 
       
    98 void CBasicMathsVector::DoPerformPrerequisite(TRequestStatus& aStatus)
       
    99 	{
       
   100 	TRequestStatus* status = &aStatus;
       
   101 	User::RequestComplete(status, KErrNone);
       
   102 	iActionState = CTestAction::EAction;
       
   103 	}
       
   104 
       
   105 void CBasicMathsVector::DoPerformPostrequisite(TRequestStatus& aStatus)
       
   106 	{
       
   107 	TRequestStatus* status = &aStatus;
       
   108 	iFinished = ETrue;
       
   109 	User::RequestComplete(status, KErrNone);
       
   110 	}
       
   111 
       
   112 void CBasicMathsVector::DoReportAction(void)
       
   113 	{
       
   114 	}
       
   115 
       
   116 void CBasicMathsVector::DoCheckResult(TInt)
       
   117 	{
       
   118 	}
       
   119 
       
   120 void CBasicMathsVector::PerformAction(TRequestStatus& aStatus)
       
   121 	{
       
   122 	__UHEAP_MARK;
       
   123 	TRequestStatus* status = &aStatus;
       
   124 	iResult = ETrue;
       
   125 
       
   126  	RInteger a = RInteger::NewL(*iA);
       
   127 	CleanupStack::PushL(a);
       
   128 	RInteger b = RInteger::NewL(*iB);
       
   129 	CleanupStack::PushL(b);
       
   130 	RInteger ans = RInteger::NewL(*iAns);
       
   131 	CleanupStack::PushL(ans);
       
   132 	RInteger result;
       
   133 	switch(iOp)
       
   134 		{
       
   135 		case EAdd:
       
   136 			a += b;
       
   137 			break;
       
   138 		case ESubtract:
       
   139 			a -= b;
       
   140 			break;
       
   141 		case EMultiply:
       
   142 			a *= b;
       
   143 			break;
       
   144 		case EDivide:
       
   145 			a /= b;
       
   146 			break;
       
   147 		case EModulus:
       
   148 			a %= b;
       
   149 			break;
       
   150 		case EGCD:
       
   151 			result = a.GCDL(b);
       
   152 			a.Set(result);
       
   153 			break;
       
   154 		case EInverseMod:
       
   155 			result = a.InverseModL(b);
       
   156 			a.Set(result);
       
   157 			break;
       
   158 		default:
       
   159 			User::Panic(_L("tbasicmathsvector"), 2);
       
   160 			break;
       
   161 		}
       
   162 
       
   163 	if( a != ans )
       
   164 		{
       
   165 		iResult = EFalse;
       
   166 		}
       
   167 	CleanupStack::PopAndDestroy(&ans);
       
   168 	CleanupStack::PopAndDestroy(&b);
       
   169 	CleanupStack::PopAndDestroy(&a);
       
   170 
       
   171 	User::RequestComplete(status, KErrNone);
       
   172 	iActionState = CTestAction::EPostrequisite;
       
   173 	__UHEAP_MARKEND;
       
   174 	}