cryptomgmtlibs/securitytestfw/test/testhandler2/t_testhandler.cpp
changeset 8 35751d3474b7
parent 0 2c201484c85f
equal deleted inserted replaced
2:675a964f4eb5 8:35751d3474b7
    31 	}
    31 	}
    32 
    32 
    33 void TTestSummary::PrintL(Output& aOut)
    33 void TTestSummary::PrintL(Output& aOut)
    34 	{
    34 	{
    35 	aOut.write(_L("%d tests failed out of %d\n"), iTestsFailed, iTestsRun);
    35 	aOut.write(_L("%d tests failed out of %d\n"), iTestsFailed, iTestsRun);
       
    36 	aOut.write(_L("\r\n</pre></body></html>\r\n"));
    36 	}
    37 	}
    37 
    38 
    38 TBool TTestSummary::AllTestsPassed()
    39 TBool TTestSummary::AllTestsPassed()
    39 	{
    40 	{
    40 	return iTestsRun > 0 && iTestsFailed == 0;
    41 	return iTestsRun > 0 && iTestsFailed == 0;
   101 	result.iTestsFailed = iFailedTests.Count();
   102 	result.iTestsFailed = iFailedTests.Count();
   102 	return result;
   103 	return result;
   103 	}
   104 	}
   104 
   105 
   105 EXPORT_C void CTestHandler::RunTestsL()
   106 EXPORT_C void CTestHandler::RunTestsL()
   106 	{
   107  {
       
   108 	
       
   109 	TBuf8<32>timeBuf;
       
   110 	TTime time;
       
   111 	time.UniversalTime();
       
   112 	TDateTime dateTime = time.DateTime();
       
   113 	_LIT8(KDateFormat,"%02d:%02d:%02d:%03d "); 
       
   114 	timeBuf.AppendFormat(KDateFormat,dateTime.Hour(),dateTime.Minute(),dateTime.Second(),(dateTime.MicroSecond()/1000));
       
   115 
   107 	iActionNumber = 0;
   116 	iActionNumber = 0;
   108     CTestAction* action;
   117     CTestAction* action;
       
   118     HBufC8* currentID=NULL;
       
   119     HBufC8* previousID=NULL;
       
   120     TBool testCaseResult=ETrue;
       
   121     TBool isTefScript = EFalse;
   109     while(iTestSpec.GetNextTest(action))
   122     while(iTestSpec.GetNextTest(action))
   110         {
   123         {
   111         iActionCount++;
   124         iActionCount++;
   112         iActionNumber++;
   125         iActionNumber++;
       
   126         isTefScript = action->iTefScript;
       
   127 //        action->iTefScript = EFalse;
       
   128         delete previousID;
       
   129         previousID = currentID;
       
   130         currentID = action->iNameInfo->AllocLC();
   113         
   131         
       
   132         if ( (previousID == NULL) || (*currentID != *previousID) )
       
   133         	{
       
   134         	if (previousID != NULL)
       
   135         		{  
       
   136         				
       
   137         		
       
   138         		if(action->iTefScript)
       
   139         			{
       
   140         			iOut->writeString(timeBuf);
       
   141         			iOut->writeString(_L("Command = END_TESTCASE "));
       
   142         			}
       
   143 	    		iOut->writeString(*previousID);
       
   144 	    		if(action->iTefScript)
       
   145 	    			{
       
   146 	    			iOut->writeString(_L(" ***TestCaseResult = "));
       
   147 	    			}
       
   148 
       
   149 	    		if (testCaseResult)
       
   150 	    			{
       
   151 	    			iOut->writeString(_L("PASS"));
       
   152 	    			}
       
   153 	    		else
       
   154 	    			{
       
   155 	    			iOut->writeString(_L("FAIL"));
       
   156 	    			}
       
   157 		    	iOut->writeString(_L("\r\n"));
       
   158 		    	iOut->writeString(_L("\r\n"));
       
   159         		}
       
   160         	
       
   161         	
       
   162         	if(action->iTefScript)
       
   163         		{
       
   164         		iOut->writeString(timeBuf);
       
   165     	        iOut->writeString(_L("Command = START_TESTCASE  "));
       
   166         		}
       
   167 	    	iOut->writeString(*(currentID));
       
   168 	    	iOut->writeString(_L("\r\n"));
       
   169 	    	testCaseResult = ETrue;
       
   170         	}
       
   171        
   114         TRAPD(err, RunTestL(action));
   172         TRAPD(err, RunTestL(action));
       
   173         if (!action->iResult)
       
   174         	{
       
   175         	testCaseResult = EFalse;
       
   176         	}
   115         if (err != KErrNone)
   177         if (err != KErrNone)
   116             {
   178             {
   117             FailTestL(action, EFailInTestHandler, err);
   179             FailTestL(action, EFailInTestHandler, err);
   118             }
   180             }
   119         }
   181         CleanupStack::Pop(currentID);
   120 	DisplaySummary();
   182 	    }
   121 	}
   183    
       
   184     if (currentID != NULL)
       
   185     	{    	
       
   186     	    	
       
   187 		
       
   188 		if(isTefScript)
       
   189 			{
       
   190 			iOut->writeString(timeBuf);
       
   191 			iOut->writeString(_L("Command = END_TESTCASE "));
       
   192 			}
       
   193 		iOut->writeString(*currentID);
       
   194 		if(isTefScript)
       
   195 			{
       
   196 			iOut->writeString(_L(" ***TestCaseResult = "));
       
   197 			}
       
   198 		
       
   199 		if (testCaseResult)
       
   200 			{
       
   201 			iOut->writeString(_L("PASS"));
       
   202 			}
       
   203 		else
       
   204 			{
       
   205 			iOut->writeString(_L("FAIL"));
       
   206 			}
       
   207 		iOut->writeString(_L("\r\n"));
       
   208 		iOut->writeString(_L("\r\n"));
       
   209 		}	
       
   210 	delete previousID;
       
   211 	delete currentID;
       
   212     
       
   213     DisplaySummary();
       
   214  }
       
   215 
       
   216 
   122 
   217 
   123 void CTestHandler::RunTestL(CTestAction* aAction)
   218 void CTestHandler::RunTestL(CTestAction* aAction)
   124     {
   219     {
   125     // If the last test set a new test runner, install it here
   220     // If the last test set a new test runner, install it here
   126     if (iNextTestRunner)
   221     if (iNextTestRunner)
   131         }
   226         }
   132 
   227 
   133     iOut->writeString(_L("Test "));
   228     iOut->writeString(_L("Test "));
   134     iOut->writeNum(iActionNumber);
   229     iOut->writeNum(iActionNumber);
   135     iOut->writeNewLine();
   230     iOut->writeNewLine();
   136 
   231     
   137 	if (iActionNumber > 1)
   232     if (iActionNumber > 1)
   138 		{
   233 		{
   139 		iConsole->Printf(_L(", "));
   234 		iConsole->Printf(_L(", "));
   140 		}
   235 		}
   141 	iConsole->Printf(_L("%d: "), iActionNumber);
   236 	iConsole->Printf(_L("%d: "), iActionNumber);
   142 
   237