authenticationservices/authenticationserver/test/reftestplugin/tpinplugin/tpinpluginteststep.cpp
changeset 102 deec7e509f66
parent 94 0e6c5a9328b5
child 108 ca9a0fc2f082
equal deleted inserted replaced
94:0e6c5a9328b5 102:deec7e509f66
     1 /*
       
     2 * Copyright (c) 2006-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 "tpinpluginteststep.h"
       
    20 #include <test/testexecutelog.h>
       
    21 #include <s32file.h>
       
    22 
       
    23 _LIT(KProperties,   		"Property");
       
    24 _LIT(KDefaultData,			"DefaultData");
       
    25 _LIT(KIdentify,				"Identify");
       
    26 _LIT(KTrain,   				"Train");
       
    27 _LIT(KReTrain,   			"ReTrain");
       
    28 _LIT(KForget,   			"Forget");
       
    29 _LIT(KSequence,   			"Sequence");
       
    30 _LIT(KOom,   				"Oom");
       
    31 
       
    32 _LIT(KInputFile, 	"C:\\t_pinplugindlg_in.dat");
       
    33 _LIT(KOutputFile, "C:\\t_pinplugindlg_out.dat");
       
    34 
       
    35 using namespace AuthServer;
       
    36 
       
    37 CPinPluginTestStep::~CPinPluginTestStep()
       
    38 	{
       
    39 	}
       
    40 
       
    41 CPinPluginTestStep::CPinPluginTestStep()
       
    42 	{
       
    43 	// Call base class method to set up the human readable name for logging
       
    44 	SetTestStepName(KPinPluginTestStep);
       
    45 	}
       
    46 
       
    47 TVerdict CPinPluginTestStep::doTestStepPreambleL()
       
    48 	{
       
    49 	// get step parameters
       
    50 	if (!GetStringFromConfig(ConfigSection(), _L("pinprocesstype"), iPinProcessType))
       
    51 		{
       
    52 		ERR_PRINTF1(_L("Requested Pin Process Type is missing"));
       
    53 		SetTestStepResult(EFail);
       
    54 		}
       
    55 	else
       
    56 		{
       
    57 		if (iPinProcessType.CompareF(KProperties) != 0 
       
    58 			&& iPinProcessType.CompareF(KOom) != 0)
       
    59 			{
       
    60 			TInt id  = 0;
       
    61 			if (!GetIntFromConfig(ConfigSection(), _L("identityid"), id))
       
    62 				{
       
    63 				ERR_PRINTF1(_L("Identity Id Value is missing"));
       
    64 				SetTestStepResult(EFail);	
       
    65 				}
       
    66 			else
       
    67 				{
       
    68 				iIdentityId = TIdentityId(id);
       
    69 				SetTestStepResult(EPass);
       
    70 				INFO_PRINTF3(_L("\"%S\" the Identity '%d' using PinPlugin System"), &iPinProcessType, id/*iIdentityId*/);
       
    71 				}
       
    72 			}
       
    73 		}
       
    74 	return TestStepResult();
       
    75 	}
       
    76 
       
    77 TVerdict CPinPluginTestStep::doTestStepL()
       
    78 	{
       
    79 	if (TestStepResult() != EPass)
       
    80 		{
       
    81 		return TestStepResult();
       
    82 		}
       
    83 
       
    84 	CActiveScheduler* sched = NULL;
       
    85 	sched = new (ELeave) CActiveScheduler;
       
    86 	CleanupStack::PushL(sched);
       
    87 	CActiveScheduler::Install(sched);	
       
    88 	CPinPluginTestActive* activeObj = CPinPluginTestActive::NewL(Logger(), iIdentityId, iPinProcessType, *this);
       
    89 	CleanupStack::PushL(activeObj);
       
    90 	
       
    91 	if (iPinProcessType.CompareF(KProperties) == 0)
       
    92 		{
       
    93 		iVerdict = activeObj->DoTestPropertyL();
       
    94 		INFO_PRINTF1(activeObj->iLogInfo);
       
    95 		}
       
    96 	else if (iPinProcessType.CompareF(KDefaultData) == 0)
       
    97 		{
       
    98 		iVerdict = activeObj->DoTestDefaultDataL();
       
    99 		INFO_PRINTF1(activeObj->iLogInfo);
       
   100 		}
       
   101 	else if (iPinProcessType.CompareF(KIdentify) == 0)
       
   102 		{
       
   103 		iVerdict = activeObj->DoTestIdentifyL();
       
   104 		INFO_PRINTF1(activeObj->iLogInfo);
       
   105 		}
       
   106 	else if (iPinProcessType.CompareF(KTrain) == 0)
       
   107 		{
       
   108 		iVerdict = activeObj->DoTestTrainL();
       
   109 		INFO_PRINTF1(activeObj->iLogInfo);
       
   110 		}
       
   111 	else if (iPinProcessType.CompareF(KReTrain) == 0)
       
   112 		{
       
   113 		iVerdict = activeObj->DoTestReTrainL();
       
   114 		INFO_PRINTF1(activeObj->iLogInfo);
       
   115 		}
       
   116 	else if (iPinProcessType.CompareF(KForget) == 0)
       
   117 		{
       
   118 		iVerdict = activeObj->DoTestForgetL();
       
   119 		INFO_PRINTF1(activeObj->iLogInfo);
       
   120 		}
       
   121 	else if (iPinProcessType.CompareF(KTrainServerCancel) == 0
       
   122 			|| (iPinProcessType.CompareF(KReTrainServerCancel) == 0)
       
   123 			|| (iPinProcessType.CompareF(KIdentifyServerCancel) == 0))
       
   124 		{
       
   125 		iVerdict = activeObj->DoTestServerCancelL();
       
   126 		INFO_PRINTF1(activeObj->iLogInfo);
       
   127 		}
       
   128 	else if (iPinProcessType.CompareF(KSequence) == 0)
       
   129 		{
       
   130 		iVerdict = activeObj->DoTestSequenceL();
       
   131 		INFO_PRINTF1(activeObj->iLogInfo);
       
   132 		}
       
   133 	else if (iPinProcessType.CompareF(KOom) == 0)
       
   134 		{
       
   135 		iVerdict = activeObj->DoTestOomL();
       
   136 		INFO_PRINTF1(activeObj->iLogInfo);
       
   137 		}
       
   138 	CleanupStack::PopAndDestroy(2, sched);
       
   139 	SetTestStepResult(iVerdict);
       
   140 	return TestStepResult();
       
   141 	}
       
   142 
       
   143 TVerdict CPinPluginTestStep::doTestStepPostambleL()
       
   144 	{
       
   145 	CActiveScheduler::Install(NULL);
       
   146 	return TestStepResult();
       
   147 	}
       
   148 
       
   149 CCreateFile::~CCreateFile()
       
   150 	{}
       
   151 
       
   152 CCreateFile::CCreateFile()
       
   153 	{
       
   154 	// Call base class method to set up the human readable name for logging
       
   155 	SetTestStepName(KCreateInputFile);
       
   156 	}
       
   157 
       
   158 TVerdict CCreateFile::doTestStepPreambleL()
       
   159 	{
       
   160 	TPtrC pinProcessType;
       
   161 	// get step parameters
       
   162 	if (!GetStringFromConfig(ConfigSection(), _L("pinprocesstype"), pinProcessType))
       
   163 		{
       
   164 		ERR_PRINTF1(_L("Index not present"));
       
   165 		SetTestStepResult(EFail);
       
   166 		}
       
   167 	else
       
   168 		{
       
   169 		if (pinProcessType.CompareF(KTrain) == 0)
       
   170 			{
       
   171 			iOperation = EPinPluginTraining;
       
   172 			}
       
   173 		else if (pinProcessType.CompareF(KIdentify) == 0)
       
   174 			{
       
   175 			iOperation = EPinPluginIdentify;
       
   176 			}
       
   177 		}
       
   178 	TPtrC pinValue;
       
   179 	if (GetStringFromConfig(ConfigSection(), _L("pinvalue"), pinValue))
       
   180 		{
       
   181 		if(pinValue == _L("readoutput"))
       
   182 			{
       
   183 			iPinValue = GetPinFromOutputFileL();
       
   184 			}
       
   185 		else
       
   186 			{
       
   187 			iPinValue.Copy(pinValue);
       
   188 			}
       
   189 		}
       
   190 	
       
   191 	if (!GetIntFromConfig(ConfigSection(), _L("selectedindex"), iIndex))
       
   192 		{
       
   193 		ERR_PRINTF1(_L("Index not present"));
       
   194 		SetTestStepResult(EFail);
       
   195 		}
       
   196 	if (!GetIntFromConfig(ConfigSection(), _L("newpinlength"), iNewPinLength))
       
   197 		{
       
   198 		ERR_PRINTF1(_L("new pin length missing"));
       
   199 		SetTestStepResult(EFail);	
       
   200 		}
       
   201 	if (!GetIntFromConfig(ConfigSection(), _L("outputatdialog"), iDialogNumber))
       
   202 		{
       
   203 		ERR_PRINTF1(_L("dialog number missing"));
       
   204 		SetTestStepResult(EFail);	
       
   205 		}
       
   206 	
       
   207 	return TestStepResult();
       
   208 	}
       
   209 
       
   210 TVerdict CCreateFile::doTestStepL()
       
   211 	{
       
   212 	if (TestStepResult() != EPass)
       
   213 		{
       
   214 		return TestStepResult();
       
   215 		}
       
   216 	
       
   217 	RFileWriteStream stream;
       
   218 	RFs fs;
       
   219 	User::LeaveIfError(fs.Connect());
       
   220 	TInt err = stream.Replace(fs, KInputFile, EFileWrite | EFileShareExclusive);
       
   221 	User::LeaveIfError(err);
       
   222 	stream.PushL();
       
   223 	
       
   224 	MStreamBuf* streamBuf = stream.Sink();
       
   225 	streamBuf->SeekL(MStreamBuf::EWrite, EStreamEnd);
       
   226 	stream.WriteInt32L(iOperation);
       
   227 	stream.WriteInt32L(iPinValue.Length());
       
   228 	stream.WriteL(iPinValue);
       
   229 	stream.WriteInt32L(iIndex);
       
   230 	stream.WriteInt32L(iNewPinLength);
       
   231 	TPinPluginDialogResult cmdResult = EOk;
       
   232 	stream.WriteInt32L(cmdResult);
       
   233 	iOperation = EPinPluginInfo;
       
   234 	stream.WriteInt32L(iOperation);
       
   235 	TPinPluginDialogResult cmdFinalResult = EOk;
       
   236 	stream.WriteInt32L(cmdFinalResult);
       
   237 	stream.WriteInt32L(iDialogNumber);
       
   238 	stream.CommitL();
       
   239 	CleanupStack::PopAndDestroy(); // stream
       
   240 	
       
   241 	SetTestStepResult(EPass);
       
   242 	return TestStepResult();
       
   243 	}
       
   244 
       
   245 TPinValue CCreateFile::GetPinFromOutputFileL()
       
   246 	{
       
   247 	RFileReadStream stream;
       
   248 	RFs fs;
       
   249 	User::LeaveIfError(fs.Connect());
       
   250 	User::LeaveIfError(stream.Open(fs, KOutputFile, EFileRead | EFileShareExclusive));
       
   251 	stream.PushL();
       
   252 
       
   253 	TPinValue pinvalue;
       
   254 	
       
   255 	stream.ReadInt32L();
       
   256 	TInt pinValueLength = stream.ReadInt32L();
       
   257 	HBufC8* pinValueBuf = HBufC8::NewMaxLC(pinValueLength);
       
   258 	TPtr8 pinValuePtr(pinValueBuf->Des());
       
   259 	stream.ReadL(pinValuePtr, pinValueLength);
       
   260 	pinvalue.Copy(pinValuePtr);
       
   261 	
       
   262 	CleanupStack::PopAndDestroy(2, &stream);	
       
   263 
       
   264 	return pinvalue;
       
   265 	}
       
   266 
       
   267 TVerdict CCreateFile::doTestStepPostambleL()
       
   268 	{
       
   269 	CActiveScheduler::Install(NULL);
       
   270 	return TestStepResult();
       
   271 	}
       
   272 
       
   273 
       
   274 
       
   275 
       
   276