os/security/cryptomgmtlibs/securitytestfw/test/testhandler2/t_testactionspec.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
#include "t_testactionspec.h"
sl@0
    20
#include "t_testsetup.h"
sl@0
    21
#include "tScriptSetup.h"
sl@0
    22
#include "t_input.h"
sl@0
    23
#include "tScriptTests.h"
sl@0
    24
#include "t_tefinput.h"
sl@0
    25
sl@0
    26
_LIT8(KTrue, "true");
sl@0
    27
_LIT8(KFalse, "false");
sl@0
    28
sl@0
    29
_LIT8(KExOOMStart, "<exoom>");
sl@0
    30
_LIT8(KExOOMEnd, "</exoom>");
sl@0
    31
_LIT8(KInOOMStart, "<inoom>");
sl@0
    32
_LIT8(KInOOMEnd, "</inoom>");
sl@0
    33
_LIT8(KExCancelStart, "<excancel>");
sl@0
    34
_LIT8(KExCancelEnd, "</excancel>");
sl@0
    35
_LIT8(KInCancelStart, "<incancel>");
sl@0
    36
_LIT8(KInCancelEnd, "</incancel>");
sl@0
    37
_LIT8(KSkippedStart, "<skipped>");
sl@0
    38
_LIT8(KSkippedEnd, "</skipped>");
sl@0
    39
_LIT8(KSmokeStart, "<smoke>");
sl@0
    40
_LIT8(KSmokeEnd, "</smoke>");
sl@0
    41
_LIT8(KInteractiveStart, "<interactive>");
sl@0
    42
_LIT8(KInteractiveEnd, "</interactive>");
sl@0
    43
sl@0
    44
sl@0
    45
TTestActionSpec::TTestActionSpec()
sl@0
    46
	{
sl@0
    47
	}
sl@0
    48
sl@0
    49
TTestActionSpec::~TTestActionSpec()
sl@0
    50
	{
sl@0
    51
	iniSectionResultBody.Close();
sl@0
    52
	}
sl@0
    53
sl@0
    54
TInt TTestActionSpec::Init(const TDesC8& aInput, 
sl@0
    55
						   TInt& aPos,
sl@0
    56
						   CConsoleBase& /*aConsole*/,
sl@0
    57
						   Output& aOut,
sl@0
    58
						   TInt& aBitFlag)
sl@0
    59
	{
sl@0
    60
	TInt err = KErrNone;
sl@0
    61
	iActionName.Set(Input::ParseElement(aInput, KActionNameStart, KActionNameEnd, aPos, err));
sl@0
    62
	if (err != KErrNone)
sl@0
    63
		{
sl@0
    64
		aOut.writeString(_L("Error couldn't find actionname in test case spec"));
sl@0
    65
		aOut.writeNewLine();
sl@0
    66
		return err;
sl@0
    67
		}
sl@0
    68
	
sl@0
    69
	iActionType.Set(Input::ParseElement(aInput, KActionTypeStart, KActionTypeEnd, aPos, err));
sl@0
    70
	if (err != KErrNone)
sl@0
    71
		{
sl@0
    72
		aOut.writeString(_L("Error couldn't find actiontype in test case spec"));
sl@0
    73
		aOut.writeNewLine();
sl@0
    74
		return err;
sl@0
    75
		}
sl@0
    76
	
sl@0
    77
	iActionGroup.Set(Input::ParseElement(aInput, KActionGroupingStart, KActionGroupingEnd, aPos, err));
sl@0
    78
	if (err == KErrNone)
sl@0
    79
		{
sl@0
    80
		//Do parsing of the returned groupings string
sl@0
    81
		TInt relativePos=0;
sl@0
    82
		TPtrC8 excludeOOM = Input::ParseElement(iActionGroup, KExOOMStart, KExOOMEnd, relativePos, err);
sl@0
    83
		relativePos=0;
sl@0
    84
		TPtrC8 includeOOM = Input::ParseElement(iActionGroup, KInOOMStart, KInOOMEnd, relativePos, err);
sl@0
    85
		relativePos=0;
sl@0
    86
		TPtrC8 excludeCancel = Input::ParseElement(iActionGroup, KExCancelStart, KExCancelEnd, relativePos, err);
sl@0
    87
		relativePos=0;
sl@0
    88
		TPtrC8 includeCancel = Input::ParseElement(iActionGroup, KInCancelStart, KInCancelEnd, relativePos, err);
sl@0
    89
		relativePos=0;
sl@0
    90
		TPtrC8 skipped = Input::ParseElement(iActionGroup, KSkippedStart, KSkippedEnd, relativePos, err);
sl@0
    91
		relativePos=0;
sl@0
    92
		TPtrC8 smoketest = Input::ParseElement(iActionGroup, KSmokeStart, KSmokeEnd, relativePos, err);
sl@0
    93
		relativePos=0;
sl@0
    94
		TPtrC8 interactive = Input::ParseElement(iActionGroup, KInteractiveStart, KInteractiveEnd, relativePos, err);
sl@0
    95
sl@0
    96
		if (excludeOOM==KTrue)
sl@0
    97
			{
sl@0
    98
			aBitFlag|=EXOOM;
sl@0
    99
			}
sl@0
   100
		else if (excludeOOM==KFalse)
sl@0
   101
			{
sl@0
   102
			aBitFlag&= (~EXOOM);
sl@0
   103
			}
sl@0
   104
		
sl@0
   105
		if (includeOOM==KTrue)
sl@0
   106
			{
sl@0
   107
			aBitFlag|=INOOM;
sl@0
   108
			}
sl@0
   109
		else if (includeOOM==KFalse)
sl@0
   110
			{
sl@0
   111
			aBitFlag&= (~INOOM);
sl@0
   112
			}
sl@0
   113
sl@0
   114
		if (excludeCancel==KTrue)
sl@0
   115
			{
sl@0
   116
			aBitFlag|=EXCANCEL;
sl@0
   117
			}
sl@0
   118
		else if (excludeCancel==KFalse)
sl@0
   119
			{
sl@0
   120
			aBitFlag&= (~EXCANCEL);
sl@0
   121
			}
sl@0
   122
sl@0
   123
		if (includeCancel==KTrue)
sl@0
   124
			{
sl@0
   125
			aBitFlag|=INCANCEL;
sl@0
   126
			}
sl@0
   127
		else if (includeCancel==KFalse)
sl@0
   128
			{
sl@0
   129
			aBitFlag&= (~INCANCEL);
sl@0
   130
			}
sl@0
   131
sl@0
   132
		if (skipped==KTrue)
sl@0
   133
			{
sl@0
   134
			aBitFlag|=SKIP;
sl@0
   135
			}
sl@0
   136
		else if (skipped==KFalse)
sl@0
   137
			{
sl@0
   138
			aBitFlag&= (~SKIP);
sl@0
   139
			}
sl@0
   140
	
sl@0
   141
		if (smoketest==KTrue)
sl@0
   142
			{
sl@0
   143
			aBitFlag|=SMOKE;
sl@0
   144
			}
sl@0
   145
		else if (smoketest==KFalse)
sl@0
   146
			{
sl@0
   147
			aBitFlag&= (~SMOKE);
sl@0
   148
			}
sl@0
   149
sl@0
   150
		if (interactive==KTrue)
sl@0
   151
			{
sl@0
   152
			aBitFlag|=INTER;
sl@0
   153
			}
sl@0
   154
		else if (interactive==KFalse)
sl@0
   155
			{
sl@0
   156
			aBitFlag&= (~INTER);
sl@0
   157
			}
sl@0
   158
		}
sl@0
   159
	
sl@0
   160
	iActionBody.Set(Input::ParseElement(aInput, KActionBodyStart, KActionBodyEnd, aPos, err));
sl@0
   161
	iActionResult.Set(Input::ParseElement(aInput, KActionResultStart, KActionResultEnd, aPos, err));
sl@0
   162
	iTefScript = EFalse;
sl@0
   163
	
sl@0
   164
	return KErrNone; 
sl@0
   165
	}
sl@0
   166
sl@0
   167
sl@0
   168
// Extracts information from *.script and *.ini files to the appropriate member variables.
sl@0
   169
sl@0
   170
TInt TTestActionSpec::TEFInit(RFs& aFs, 
sl@0
   171
						   const TDesC8& aInput,
sl@0
   172
						   const TDesC8& aTestCaseID,
sl@0
   173
						   TDesC8& aPrevTestCaseID,
sl@0
   174
						   TBool& tefFile,
sl@0
   175
						   TBool& runtest,
sl@0
   176
						   TBool& inifile,
sl@0
   177
						   TDes8& aScriptResult,
sl@0
   178
						   TDes8& aActionType,
sl@0
   179
						   const TDesC& aScriptPath,
sl@0
   180
						   CConsoleBase& /*aConsole*/,
sl@0
   181
						   Output& aOut)
sl@0
   182
	{
sl@0
   183
	
sl@0
   184
	TInt 		err = KErrNone;
sl@0
   185
	TInt 		actionTypePos=3;
sl@0
   186
	TBool 		scriptactionResultSet = EFalse;
sl@0
   187
//	TBool 		iniactionResultSet = EFalse;
sl@0
   188
	TBuf8<512> 	prevTestCaseID;
sl@0
   189
	TBuf8<512> 	prevTestDescription;
sl@0
   190
sl@0
   191
sl@0
   192
	
sl@0
   193
// Checks if the first word from the script file is an error code
sl@0
   194
// if(error code)
sl@0
   195
//		sets 'actionResult' to the relevent error code with the <return></return> tags
sl@0
   196
sl@0
   197
	TPtrC8 firstWord = Tefinput::ParseNthElement(aInput,1, err);
sl@0
   198
	if(err == KErrNone)
sl@0
   199
		{
sl@0
   200
		TInt tmpno;
sl@0
   201
		TLex8 lex8(firstWord); 
sl@0
   202
		err = lex8.Val(tmpno);			
sl@0
   203
		if(err != KErrNone)
sl@0
   204
			{
sl@0
   205
			actionTypePos = 4;
sl@0
   206
			err = Tefinput::ParseActionResult(firstWord, aScriptResult);
sl@0
   207
			scriptactionResultSet = ETrue;
sl@0
   208
			}
sl@0
   209
		}
sl@0
   210
	
sl@0
   211
//1. Extracts the .ini file name from the .script file
sl@0
   212
//2. Reads in the [section] name from the .script file
sl@0
   213
//3. Generates  .ini path from .script file path and .ini file name
sl@0
   214
//4. Sets iActionBody with the info from .ini file
sl@0
   215
	
sl@0
   216
	TBuf<KMaxPath + KMaxFileName> 	iniFilePath;
sl@0
   217
	TBuf<512> 						iniFileData;
sl@0
   218
	TPtrC8 							iniSectionData;
sl@0
   219
	
sl@0
   220
	
sl@0
   221
	TPtrC8 iniFileName = Tefinput::ParseNthElement(aInput,actionTypePos+1,err);
sl@0
   222
	if(err == KErrNone)
sl@0
   223
		{
sl@0
   224
		TPtrC8 iniSectionName = Tefinput::ParseNthElement(aInput,actionTypePos+2,err);
sl@0
   225
		if(err == KErrNone)
sl@0
   226
			{
sl@0
   227
			err = Tefinput::ParseiniPath(iniFileName, aScriptPath, iniFilePath);
sl@0
   228
			if(err == KErrNone)
sl@0
   229
				{
sl@0
   230
				aTestIniFilePtr.Assign(Tefinput::GetiniFile(aFs, iniFilePath, err)); // Load up our local RBuf ptr to takeover the management of the inifile data in Heap
sl@0
   231
				
sl@0
   232
				if(err == KErrNone)
sl@0
   233
					{
sl@0
   234
					TPtrC8 iniFile = aTestIniFilePtr.Ptr();
sl@0
   235
					inifile = ETrue;
sl@0
   236
					err = Tefinput::ParseActionbody(iniFile, iniSectionName, iniSectionData);
sl@0
   237
					if(err == KErrNone)
sl@0
   238
						{
sl@0
   239
						TInt pos = 0;
sl@0
   240
						iActionBody.Set(Input::ParseElement(iniSectionData, KActionBodyStart, KActionBodyEnd, pos, err));
sl@0
   241
						if (err == KErrNotFound)
sl@0
   242
							{
sl@0
   243
							aOut.writeString(_L("Error couldn't find actionbody in test case spec"));
sl@0
   244
							aOut.writeNewLine();
sl@0
   245
							return err;
sl@0
   246
							}
sl@0
   247
						}
sl@0
   248
					}
sl@0
   249
				else
sl@0
   250
					{
sl@0
   251
					inifile = EFalse;
sl@0
   252
					}
sl@0
   253
				}
sl@0
   254
			}
sl@0
   255
		}
sl@0
   256
	else
sl@0
   257
		{
sl@0
   258
		inifile = EFalse;
sl@0
   259
		}
sl@0
   260
		
sl@0
   261
	TInt pos = 0;
sl@0
   262
sl@0
   263
// Extracts info b/w <actionresult> </actionresult> tags
sl@0
   264
// 	Sets iActionResult with info both from .script and .ini file
sl@0
   265
	TPtrC8 tempResult;
sl@0
   266
	TPtrC8 scriptResult;
sl@0
   267
	TInt resultlen ;
sl@0
   268
	
sl@0
   269
	if(scriptactionResultSet)
sl@0
   270
		{
sl@0
   271
		scriptResult.Set(aScriptResult);
sl@0
   272
		tempResult.Set(Input::ParseElement(iniSectionData, KActionResultStart, KActionResultEnd, pos, err));
sl@0
   273
		if (err == KErrNone)
sl@0
   274
			{
sl@0
   275
			resultlen = scriptResult.Length() + tempResult.Length();
sl@0
   276
			iniSectionResultBody.Create(tempResult,resultlen);
sl@0
   277
			iniSectionResultBody.Insert(0,scriptResult);			
sl@0
   278
			iActionResult.Set(iniSectionResultBody);
sl@0
   279
//			iniactionResultSet = ETrue;
sl@0
   280
			}
sl@0
   281
		else
sl@0
   282
			{
sl@0
   283
			iniSectionResultBody.Create(scriptResult);
sl@0
   284
			iActionResult.Set(iniSectionResultBody);
sl@0
   285
			}
sl@0
   286
		}
sl@0
   287
	else
sl@0
   288
		{
sl@0
   289
		tempResult.Set(Input::ParseElement(iniSectionData, KActionResultStart, KActionResultEnd, pos, err));
sl@0
   290
		err = Tefinput::GetActionResult(KErrNone, aScriptResult);
sl@0
   291
		if(err == KErrNone)
sl@0
   292
			{
sl@0
   293
			scriptResult.Set(aScriptResult);
sl@0
   294
			resultlen = tempResult.Length() + scriptResult.Length();
sl@0
   295
			iniSectionResultBody.Create(tempResult, resultlen);
sl@0
   296
			iniSectionResultBody.Insert(0,aScriptResult);
sl@0
   297
			iActionResult.Set(iniSectionResultBody);
sl@0
   298
			}
sl@0
   299
		else
sl@0
   300
			{
sl@0
   301
			iniSectionResultBody.Create(tempResult);
sl@0
   302
			iActionResult.Set(iniSectionResultBody);
sl@0
   303
			}
sl@0
   304
		}
sl@0
   305
	
sl@0
   306
		
sl@0
   307
//	aPrevTestCaseID = aTestCaseID;
sl@0
   308
//Sets iActionName with the @SYMTestCaseID
sl@0
   309
	if(!runtest)
sl@0
   310
		{
sl@0
   311
		iActionName.Set(aPrevTestCaseID);
sl@0
   312
		}
sl@0
   313
	else
sl@0
   314
		{
sl@0
   315
		iActionName.Set(aTestCaseID);
sl@0
   316
		}
sl@0
   317
sl@0
   318
	
sl@0
   319
sl@0
   320
//Sets iActionType from .script file
sl@0
   321
	
sl@0
   322
	TBuf8<512> modifiedType;
sl@0
   323
	TBuf8<512> modifiedTypeTemp;
sl@0
   324
	TPtrC8 actionTypeTemp;
sl@0
   325
	TPtrC8 actionType;
sl@0
   326
	TPtrC8 TempType;
sl@0
   327
	
sl@0
   328
	
sl@0
   329
	iActionType.Set(Tefinput::ParseNthElement(aInput,actionTypePos,err));
sl@0
   330
	if (err == KErrNone)
sl@0
   331
		{
sl@0
   332
		modifiedType.Copy(iActionType);
sl@0
   333
		modifiedType.Copy(Tefinput::TrimActionType(modifiedType, aActionType));
sl@0
   334
sl@0
   335
		iActionType.Set(aActionType);
sl@0
   336
		}
sl@0
   337
	else
sl@0
   338
		{
sl@0
   339
		aOut.writeString(_L("Error couldn't find actiontype in test case spec"));
sl@0
   340
		aOut.writeNewLine();
sl@0
   341
		return err;
sl@0
   342
		}
sl@0
   343
sl@0
   344
	
sl@0
   345
sl@0
   346
	iTefScript = tefFile;
sl@0
   347
sl@0
   348
sl@0
   349
	
sl@0
   350
	
sl@0
   351
	return KErrNone; 
sl@0
   352
	}
sl@0
   353
sl@0
   354
sl@0
   355
void TTestActionSpec::HardcodedInit(const TDesC8& aInput)
sl@0
   356
	{
sl@0
   357
	iActionName.Set(aInput);
sl@0
   358
	iActionType.Set(KNullDesC8);
sl@0
   359
	iActionGroup.Set(KNullDesC8);
sl@0
   360
	iActionBody.Set(KNullDesC8);
sl@0
   361
	iActionResult.Set(KNullDesC8);
sl@0
   362
	}