1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/cryptomgmtlibs/securitytestfw/test/testhandler2/t_testactionspec.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,362 @@
1.4 +/*
1.5 +* Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +#include "t_testactionspec.h"
1.23 +#include "t_testsetup.h"
1.24 +#include "tScriptSetup.h"
1.25 +#include "t_input.h"
1.26 +#include "tScriptTests.h"
1.27 +#include "t_tefinput.h"
1.28 +
1.29 +_LIT8(KTrue, "true");
1.30 +_LIT8(KFalse, "false");
1.31 +
1.32 +_LIT8(KExOOMStart, "<exoom>");
1.33 +_LIT8(KExOOMEnd, "</exoom>");
1.34 +_LIT8(KInOOMStart, "<inoom>");
1.35 +_LIT8(KInOOMEnd, "</inoom>");
1.36 +_LIT8(KExCancelStart, "<excancel>");
1.37 +_LIT8(KExCancelEnd, "</excancel>");
1.38 +_LIT8(KInCancelStart, "<incancel>");
1.39 +_LIT8(KInCancelEnd, "</incancel>");
1.40 +_LIT8(KSkippedStart, "<skipped>");
1.41 +_LIT8(KSkippedEnd, "</skipped>");
1.42 +_LIT8(KSmokeStart, "<smoke>");
1.43 +_LIT8(KSmokeEnd, "</smoke>");
1.44 +_LIT8(KInteractiveStart, "<interactive>");
1.45 +_LIT8(KInteractiveEnd, "</interactive>");
1.46 +
1.47 +
1.48 +TTestActionSpec::TTestActionSpec()
1.49 + {
1.50 + }
1.51 +
1.52 +TTestActionSpec::~TTestActionSpec()
1.53 + {
1.54 + iniSectionResultBody.Close();
1.55 + }
1.56 +
1.57 +TInt TTestActionSpec::Init(const TDesC8& aInput,
1.58 + TInt& aPos,
1.59 + CConsoleBase& /*aConsole*/,
1.60 + Output& aOut,
1.61 + TInt& aBitFlag)
1.62 + {
1.63 + TInt err = KErrNone;
1.64 + iActionName.Set(Input::ParseElement(aInput, KActionNameStart, KActionNameEnd, aPos, err));
1.65 + if (err != KErrNone)
1.66 + {
1.67 + aOut.writeString(_L("Error couldn't find actionname in test case spec"));
1.68 + aOut.writeNewLine();
1.69 + return err;
1.70 + }
1.71 +
1.72 + iActionType.Set(Input::ParseElement(aInput, KActionTypeStart, KActionTypeEnd, aPos, err));
1.73 + if (err != KErrNone)
1.74 + {
1.75 + aOut.writeString(_L("Error couldn't find actiontype in test case spec"));
1.76 + aOut.writeNewLine();
1.77 + return err;
1.78 + }
1.79 +
1.80 + iActionGroup.Set(Input::ParseElement(aInput, KActionGroupingStart, KActionGroupingEnd, aPos, err));
1.81 + if (err == KErrNone)
1.82 + {
1.83 + //Do parsing of the returned groupings string
1.84 + TInt relativePos=0;
1.85 + TPtrC8 excludeOOM = Input::ParseElement(iActionGroup, KExOOMStart, KExOOMEnd, relativePos, err);
1.86 + relativePos=0;
1.87 + TPtrC8 includeOOM = Input::ParseElement(iActionGroup, KInOOMStart, KInOOMEnd, relativePos, err);
1.88 + relativePos=0;
1.89 + TPtrC8 excludeCancel = Input::ParseElement(iActionGroup, KExCancelStart, KExCancelEnd, relativePos, err);
1.90 + relativePos=0;
1.91 + TPtrC8 includeCancel = Input::ParseElement(iActionGroup, KInCancelStart, KInCancelEnd, relativePos, err);
1.92 + relativePos=0;
1.93 + TPtrC8 skipped = Input::ParseElement(iActionGroup, KSkippedStart, KSkippedEnd, relativePos, err);
1.94 + relativePos=0;
1.95 + TPtrC8 smoketest = Input::ParseElement(iActionGroup, KSmokeStart, KSmokeEnd, relativePos, err);
1.96 + relativePos=0;
1.97 + TPtrC8 interactive = Input::ParseElement(iActionGroup, KInteractiveStart, KInteractiveEnd, relativePos, err);
1.98 +
1.99 + if (excludeOOM==KTrue)
1.100 + {
1.101 + aBitFlag|=EXOOM;
1.102 + }
1.103 + else if (excludeOOM==KFalse)
1.104 + {
1.105 + aBitFlag&= (~EXOOM);
1.106 + }
1.107 +
1.108 + if (includeOOM==KTrue)
1.109 + {
1.110 + aBitFlag|=INOOM;
1.111 + }
1.112 + else if (includeOOM==KFalse)
1.113 + {
1.114 + aBitFlag&= (~INOOM);
1.115 + }
1.116 +
1.117 + if (excludeCancel==KTrue)
1.118 + {
1.119 + aBitFlag|=EXCANCEL;
1.120 + }
1.121 + else if (excludeCancel==KFalse)
1.122 + {
1.123 + aBitFlag&= (~EXCANCEL);
1.124 + }
1.125 +
1.126 + if (includeCancel==KTrue)
1.127 + {
1.128 + aBitFlag|=INCANCEL;
1.129 + }
1.130 + else if (includeCancel==KFalse)
1.131 + {
1.132 + aBitFlag&= (~INCANCEL);
1.133 + }
1.134 +
1.135 + if (skipped==KTrue)
1.136 + {
1.137 + aBitFlag|=SKIP;
1.138 + }
1.139 + else if (skipped==KFalse)
1.140 + {
1.141 + aBitFlag&= (~SKIP);
1.142 + }
1.143 +
1.144 + if (smoketest==KTrue)
1.145 + {
1.146 + aBitFlag|=SMOKE;
1.147 + }
1.148 + else if (smoketest==KFalse)
1.149 + {
1.150 + aBitFlag&= (~SMOKE);
1.151 + }
1.152 +
1.153 + if (interactive==KTrue)
1.154 + {
1.155 + aBitFlag|=INTER;
1.156 + }
1.157 + else if (interactive==KFalse)
1.158 + {
1.159 + aBitFlag&= (~INTER);
1.160 + }
1.161 + }
1.162 +
1.163 + iActionBody.Set(Input::ParseElement(aInput, KActionBodyStart, KActionBodyEnd, aPos, err));
1.164 + iActionResult.Set(Input::ParseElement(aInput, KActionResultStart, KActionResultEnd, aPos, err));
1.165 + iTefScript = EFalse;
1.166 +
1.167 + return KErrNone;
1.168 + }
1.169 +
1.170 +
1.171 +// Extracts information from *.script and *.ini files to the appropriate member variables.
1.172 +
1.173 +TInt TTestActionSpec::TEFInit(RFs& aFs,
1.174 + const TDesC8& aInput,
1.175 + const TDesC8& aTestCaseID,
1.176 + TDesC8& aPrevTestCaseID,
1.177 + TBool& tefFile,
1.178 + TBool& runtest,
1.179 + TBool& inifile,
1.180 + TDes8& aScriptResult,
1.181 + TDes8& aActionType,
1.182 + const TDesC& aScriptPath,
1.183 + CConsoleBase& /*aConsole*/,
1.184 + Output& aOut)
1.185 + {
1.186 +
1.187 + TInt err = KErrNone;
1.188 + TInt actionTypePos=3;
1.189 + TBool scriptactionResultSet = EFalse;
1.190 +// TBool iniactionResultSet = EFalse;
1.191 + TBuf8<512> prevTestCaseID;
1.192 + TBuf8<512> prevTestDescription;
1.193 +
1.194 +
1.195 +
1.196 +// Checks if the first word from the script file is an error code
1.197 +// if(error code)
1.198 +// sets 'actionResult' to the relevent error code with the <return></return> tags
1.199 +
1.200 + TPtrC8 firstWord = Tefinput::ParseNthElement(aInput,1, err);
1.201 + if(err == KErrNone)
1.202 + {
1.203 + TInt tmpno;
1.204 + TLex8 lex8(firstWord);
1.205 + err = lex8.Val(tmpno);
1.206 + if(err != KErrNone)
1.207 + {
1.208 + actionTypePos = 4;
1.209 + err = Tefinput::ParseActionResult(firstWord, aScriptResult);
1.210 + scriptactionResultSet = ETrue;
1.211 + }
1.212 + }
1.213 +
1.214 +//1. Extracts the .ini file name from the .script file
1.215 +//2. Reads in the [section] name from the .script file
1.216 +//3. Generates .ini path from .script file path and .ini file name
1.217 +//4. Sets iActionBody with the info from .ini file
1.218 +
1.219 + TBuf<KMaxPath + KMaxFileName> iniFilePath;
1.220 + TBuf<512> iniFileData;
1.221 + TPtrC8 iniSectionData;
1.222 +
1.223 +
1.224 + TPtrC8 iniFileName = Tefinput::ParseNthElement(aInput,actionTypePos+1,err);
1.225 + if(err == KErrNone)
1.226 + {
1.227 + TPtrC8 iniSectionName = Tefinput::ParseNthElement(aInput,actionTypePos+2,err);
1.228 + if(err == KErrNone)
1.229 + {
1.230 + err = Tefinput::ParseiniPath(iniFileName, aScriptPath, iniFilePath);
1.231 + if(err == KErrNone)
1.232 + {
1.233 + aTestIniFilePtr.Assign(Tefinput::GetiniFile(aFs, iniFilePath, err)); // Load up our local RBuf ptr to takeover the management of the inifile data in Heap
1.234 +
1.235 + if(err == KErrNone)
1.236 + {
1.237 + TPtrC8 iniFile = aTestIniFilePtr.Ptr();
1.238 + inifile = ETrue;
1.239 + err = Tefinput::ParseActionbody(iniFile, iniSectionName, iniSectionData);
1.240 + if(err == KErrNone)
1.241 + {
1.242 + TInt pos = 0;
1.243 + iActionBody.Set(Input::ParseElement(iniSectionData, KActionBodyStart, KActionBodyEnd, pos, err));
1.244 + if (err == KErrNotFound)
1.245 + {
1.246 + aOut.writeString(_L("Error couldn't find actionbody in test case spec"));
1.247 + aOut.writeNewLine();
1.248 + return err;
1.249 + }
1.250 + }
1.251 + }
1.252 + else
1.253 + {
1.254 + inifile = EFalse;
1.255 + }
1.256 + }
1.257 + }
1.258 + }
1.259 + else
1.260 + {
1.261 + inifile = EFalse;
1.262 + }
1.263 +
1.264 + TInt pos = 0;
1.265 +
1.266 +// Extracts info b/w <actionresult> </actionresult> tags
1.267 +// Sets iActionResult with info both from .script and .ini file
1.268 + TPtrC8 tempResult;
1.269 + TPtrC8 scriptResult;
1.270 + TInt resultlen ;
1.271 +
1.272 + if(scriptactionResultSet)
1.273 + {
1.274 + scriptResult.Set(aScriptResult);
1.275 + tempResult.Set(Input::ParseElement(iniSectionData, KActionResultStart, KActionResultEnd, pos, err));
1.276 + if (err == KErrNone)
1.277 + {
1.278 + resultlen = scriptResult.Length() + tempResult.Length();
1.279 + iniSectionResultBody.Create(tempResult,resultlen);
1.280 + iniSectionResultBody.Insert(0,scriptResult);
1.281 + iActionResult.Set(iniSectionResultBody);
1.282 +// iniactionResultSet = ETrue;
1.283 + }
1.284 + else
1.285 + {
1.286 + iniSectionResultBody.Create(scriptResult);
1.287 + iActionResult.Set(iniSectionResultBody);
1.288 + }
1.289 + }
1.290 + else
1.291 + {
1.292 + tempResult.Set(Input::ParseElement(iniSectionData, KActionResultStart, KActionResultEnd, pos, err));
1.293 + err = Tefinput::GetActionResult(KErrNone, aScriptResult);
1.294 + if(err == KErrNone)
1.295 + {
1.296 + scriptResult.Set(aScriptResult);
1.297 + resultlen = tempResult.Length() + scriptResult.Length();
1.298 + iniSectionResultBody.Create(tempResult, resultlen);
1.299 + iniSectionResultBody.Insert(0,aScriptResult);
1.300 + iActionResult.Set(iniSectionResultBody);
1.301 + }
1.302 + else
1.303 + {
1.304 + iniSectionResultBody.Create(tempResult);
1.305 + iActionResult.Set(iniSectionResultBody);
1.306 + }
1.307 + }
1.308 +
1.309 +
1.310 +// aPrevTestCaseID = aTestCaseID;
1.311 +//Sets iActionName with the @SYMTestCaseID
1.312 + if(!runtest)
1.313 + {
1.314 + iActionName.Set(aPrevTestCaseID);
1.315 + }
1.316 + else
1.317 + {
1.318 + iActionName.Set(aTestCaseID);
1.319 + }
1.320 +
1.321 +
1.322 +
1.323 +//Sets iActionType from .script file
1.324 +
1.325 + TBuf8<512> modifiedType;
1.326 + TBuf8<512> modifiedTypeTemp;
1.327 + TPtrC8 actionTypeTemp;
1.328 + TPtrC8 actionType;
1.329 + TPtrC8 TempType;
1.330 +
1.331 +
1.332 + iActionType.Set(Tefinput::ParseNthElement(aInput,actionTypePos,err));
1.333 + if (err == KErrNone)
1.334 + {
1.335 + modifiedType.Copy(iActionType);
1.336 + modifiedType.Copy(Tefinput::TrimActionType(modifiedType, aActionType));
1.337 +
1.338 + iActionType.Set(aActionType);
1.339 + }
1.340 + else
1.341 + {
1.342 + aOut.writeString(_L("Error couldn't find actiontype in test case spec"));
1.343 + aOut.writeNewLine();
1.344 + return err;
1.345 + }
1.346 +
1.347 +
1.348 +
1.349 + iTefScript = tefFile;
1.350 +
1.351 +
1.352 +
1.353 +
1.354 + return KErrNone;
1.355 + }
1.356 +
1.357 +
1.358 +void TTestActionSpec::HardcodedInit(const TDesC8& aInput)
1.359 + {
1.360 + iActionName.Set(aInput);
1.361 + iActionType.Set(KNullDesC8);
1.362 + iActionGroup.Set(KNullDesC8);
1.363 + iActionBody.Set(KNullDesC8);
1.364 + iActionResult.Set(KNullDesC8);
1.365 + }