imagingtestenv/imagingtestfw/Source/TestFrameworkClient/Log.cpp
changeset 0 5752a19fdefe
equal deleted inserted replaced
-1:000000000000 0:5752a19fdefe
       
     1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Client / server logging for Test Framework
       
    15 // NOTE : does NOT include secure API changes in EKA2
       
    16 // 
       
    17 //
       
    18 
       
    19 
       
    20 // Test system includes
       
    21 #include <testframework.h>
       
    22 
       
    23 // do not export if Unit Testing
       
    24 #if defined (__TSU_TESTFRAMEWORK__)
       
    25 #undef EXPORT_C
       
    26 #define EXPORT_C
       
    27 #endif
       
    28 
       
    29 /**
       
    30  *
       
    31  * HTML font formatting strings
       
    32  *
       
    33  * @xxxx
       
    34  *
       
    35  */
       
    36 _LIT(KResultPass, "<font size=4 color=00AF00>");
       
    37 _LIT(KResultFail, "<font size=4 color=FF0000>");
       
    38 _LIT(KResultInconclusive, "<font size=4 color=0000FF>");
       
    39 _LIT(KResultUndefined, "<font size=4 color=FF00FF>");
       
    40 _LIT(KResultEnd, "</font>");
       
    41 _LIT(KResultNonHtml, "");
       
    42 
       
    43 _LIT(KResultKnownFailure, "<font size=4 color=008080>"); //A new TVerdict for a known failed test
       
    44 
       
    45 // logging macro used only for verdicts - not for external use
       
    46 #define VER_PRINTF(r1, r2, r3)		LogExtra(__FILE8__, __LINE__, ESevrVer, _L("%S%S%S\n"), (r1), (r2), (r3)) 
       
    47 
       
    48 /**
       
    49  *
       
    50  * Static constructor for CLog.
       
    51  *
       
    52  *
       
    53  * @return	"CLog*"
       
    54  *			The constructed CLog
       
    55  *
       
    56  * @xxxx
       
    57  *
       
    58  */
       
    59 EXPORT_C CLog* CLog::NewL()
       
    60 	{
       
    61 	CLog* self = new(ELeave) CLog;
       
    62 	self->Construct();
       
    63 	return self;
       
    64 	}
       
    65 
       
    66 /**
       
    67  *
       
    68  * Static NewLC constructor for CLog.
       
    69  *
       
    70  *
       
    71  * @return	"CLog*"
       
    72  *			The constructed CLog
       
    73  *
       
    74  * @xxxx
       
    75  *
       
    76  */
       
    77 EXPORT_C CLog* CLog::NewLC()
       
    78 	{
       
    79 	CLog* self = new(ELeave) CLog;
       
    80 	CleanupStack::PushL(self);
       
    81 	self->Construct();
       
    82 	return self;
       
    83 	}
       
    84 
       
    85 /**
       
    86  *
       
    87  * Second-phase constructor for CLog.
       
    88  *
       
    89  * @xxxx
       
    90  *
       
    91  */
       
    92 EXPORT_C void CLog::Construct()
       
    93 	{
       
    94 	iLogStatus = 0;		// no outputs enabled yet
       
    95 	iSeverity = ESevrAll;
       
    96 	//Do we need to put information about source file & #line?
       
    97 	//Default is yes.
       
    98 	iLogFlags = ELogPutSrcInfo | ELogHtmlMode;
       
    99 	}
       
   100 
       
   101 /**
       
   102  *
       
   103  * Destructor for CLog.
       
   104  *
       
   105  * @xxxx
       
   106  *
       
   107  */
       
   108 EXPORT_C CLog::~CLog()
       
   109 	{
       
   110 	// tell server to close logs here
       
   111 	iClientSession.Close();
       
   112 	}
       
   113 
       
   114 /**
       
   115  *
       
   116  * Open a new test log.
       
   117  *
       
   118  * @param	"const TDesC& aLogName"
       
   119  *			Log file or console name
       
   120  *
       
   121  * @param	"TInt aLogMode"
       
   122  *			Log modes (a bitmask of TTestFrameworkLogMode).
       
   123  *
       
   124  * @xxxx
       
   125  *
       
   126  */
       
   127 EXPORT_C void CLog::OpenLogFileL(const TDesC& aLogName, TInt aLogMode)
       
   128 	{
       
   129 	User::LeaveIfError(iClientSession.Connect());
       
   130 
       
   131 	iClientSession.OpenLog(aLogName, aLogMode);
       
   132 	// get and store the log status - this will determine whether we
       
   133 	// e.g. do any formatting for file output
       
   134 	iLogStatus = iClientSession.LogStatus();
       
   135 	}
       
   136 
       
   137 /**
       
   138  *
       
   139  * Open an existing test log.
       
   140  *
       
   141  * @xxxx
       
   142  *
       
   143  */
       
   144 EXPORT_C void CLog::OpenLogFileL()
       
   145 	{
       
   146 	User::LeaveIfError(iClientSession.Connect());
       
   147 	iLogStatus = iClientSession.LogStatus();
       
   148 	}
       
   149 
       
   150 /**
       
   151  *
       
   152  * Set put source info (i.e. traceable logging).
       
   153  *
       
   154  * @param	"TBool aPutSrcInfo"
       
   155  *			Put source info on or off.
       
   156  *
       
   157  * @xxxx
       
   158  *
       
   159  */
       
   160 EXPORT_C void CLog::SetPutSrcInfo(TBool aPutSrcInfo)
       
   161 	{
       
   162 	if(aPutSrcInfo)
       
   163 		iLogFlags |= ELogPutSrcInfo;
       
   164 	else
       
   165 		iLogFlags &= ~ELogPutSrcInfo;
       
   166 	}
       
   167 	
       
   168 /**
       
   169  *
       
   170  * Set HTML logging mode.
       
   171  *
       
   172  * @param	"TBool aArg"
       
   173  *			HTML mode on or off.
       
   174  *
       
   175  * @xxxx
       
   176  *
       
   177  */
       
   178 EXPORT_C void CLog::SetHtmlLogMode(TBool aArg)
       
   179 	{
       
   180 	if(aArg)
       
   181 		iLogFlags |= ELogHtmlMode;
       
   182 	else
       
   183 		iLogFlags &= ~ELogHtmlMode;
       
   184 	}
       
   185  
       
   186 /**
       
   187  *
       
   188  * Get HTML logging mode.
       
   189  *
       
   190  * @return	"TBool"
       
   191  *			HTML mode on or off.
       
   192  *
       
   193  * @xxxx
       
   194  *
       
   195  */
       
   196 EXPORT_C TBool CLog::HtmlLogMode() const
       
   197 	{
       
   198 	return ((iLogFlags & ELogHtmlMode) != 0);
       
   199 	}
       
   200 
       
   201 
       
   202 /**
       
   203  *
       
   204  * General logging function.
       
   205  *
       
   206  * @param	"TRefByValue<const TDesC16> aFmt"
       
   207  *			Printf-style format.
       
   208  *
       
   209  * @param	"..."
       
   210  *			Variable print parameters
       
   211  *
       
   212  * @xxxx
       
   213  *
       
   214  */
       
   215 EXPORT_C void CLog::Log(TRefByValue<const TDesC16> aFmt, ...)
       
   216 	{
       
   217     VA_LIST aList;
       
   218 	VA_START(aList, aFmt);
       
   219 
       
   220 	TIntegrationTestLog16Overflow overflow16;
       
   221 
       
   222 	// decode formatted data for display on console
       
   223 	TBuf<KMaxLogLineLength> lineBuf;
       
   224 	lineBuf = KNullDesC;
       
   225 	lineBuf.AppendFormatList(aFmt, aList, &overflow16);
       
   226 
       
   227 	// write to the console
       
   228 	if(iLogStatus & ELogConsoleFull)
       
   229 		iClientSession.WriteLog(lineBuf, ELogToConsole);
       
   230 
       
   231 	// write to log file
       
   232 	WriteFormat(_L("%S\n"), &lineBuf);
       
   233 
       
   234 	VA_END(aList); 
       
   235 	}
       
   236 
       
   237 /**
       
   238  *
       
   239  * General logging function with severity.
       
   240  *
       
   241  * @param	"TInt aSeverity"
       
   242  *			Severity level required to log
       
   243  *
       
   244  * @param	"TRefByValue<const TDesC16> aFmt"
       
   245  *			Printf-style format.
       
   246  *
       
   247  * @param	"..."
       
   248  *			Variable print parameters
       
   249  *
       
   250  * @xxxx
       
   251  *
       
   252  */
       
   253 EXPORT_C void CLog::Log(TInt aSeverity, TRefByValue<const TDesC16> aFmt, ...)
       
   254 	{
       
   255     VA_LIST aList;
       
   256 	VA_START(aList, aFmt);
       
   257 
       
   258 	if(LogSeverity::IsActive(aSeverity, Severity()))
       
   259 		{
       
   260 		Log(aFmt, aList);
       
   261 		}
       
   262 
       
   263 	VA_END(aList); 
       
   264 	}
       
   265 
       
   266 /**
       
   267  *
       
   268  * General logging function.
       
   269  *
       
   270  * @param	"TRefByValue<const TDesC16> aFmt"
       
   271  *			Printf-style format.
       
   272  *
       
   273  * @param	"VA_LIST aList"
       
   274  *			Variable print parameters
       
   275  *
       
   276  * @xxxx
       
   277  *
       
   278  */
       
   279 EXPORT_C void CLog::Log(TRefByValue<const TDesC16> aFmt, VA_LIST aList)
       
   280 	{
       
   281 	// decode formatted data for display on console
       
   282 	TBuf<KMaxLogLineLength> lineBuf;
       
   283 	TIntegrationTestLog16Overflow overflow16;
       
   284 
       
   285 	lineBuf = KNullDesC;
       
   286 	lineBuf.AppendFormatList(aFmt, aList, &overflow16);
       
   287 
       
   288 	// write to log file
       
   289 	WriteFormat(_L("%S\n"),&lineBuf);
       
   290 
       
   291 	// write to the console
       
   292 	if(iLogStatus & ELogConsoleFull)
       
   293 		iClientSession.WriteLog(lineBuf, ELogToConsole);
       
   294 
       
   295 	}
       
   296 
       
   297 /**
       
   298  *
       
   299  * Traceable logging function
       
   300  *
       
   301  * Should be used for macros only
       
   302  *
       
   303  * @param	"const TText8* aFile"
       
   304  *			Source code file name
       
   305  *
       
   306  * @param	"TInt aLine"
       
   307  *			Source code line
       
   308  *
       
   309  * @param	"TInt aSeverity"
       
   310  *			Severity level required to log
       
   311  *
       
   312  * @param	"TRefByValue<const TDesC16> aFmt"
       
   313  *			Printf-style format.
       
   314  *
       
   315  * @param	"VA_LIST aList"
       
   316  *			Variable print parameters
       
   317  *
       
   318  * @xxxx
       
   319  *
       
   320  */
       
   321 #ifdef EXCLUDE_FOR_UNITTEST
       
   322 EXPORT_C void CLog::LogExtra(const TText8* /*aFile*/, TInt /*aLine*/, TInt /*aSeverity*/,
       
   323 							 TRefByValue<const TDesC16> /*aFmt*/, VA_LIST /*aList*/)
       
   324 	{
       
   325 	}
       
   326 #else
       
   327 EXPORT_C void CLog::LogExtra(const TText8* aFile, TInt aLine, TInt aSeverity,
       
   328 							 TRefByValue<const TDesC16> aFmt, VA_LIST aList)
       
   329 	{
       
   330 	if(LogSeverity::IsActive(aSeverity, Severity()))
       
   331 		{
       
   332 
       
   333 		TIntegrationTestLog16Overflow overflow16;
       
   334 
       
   335 		// decode formatted data for display on console
       
   336 		TBuf<KMaxLogLineLength> lineBuf;
       
   337 
       
   338 		lineBuf = KNullDesC;
       
   339 		lineBuf.AppendFormatList(aFmt, aList, &overflow16);
       
   340 
       
   341 		// write to the console
       
   342 		if(iLogStatus & ELogConsoleFull)
       
   343 			WriteLogConsole(lineBuf);
       
   344 
       
   345 		// log severity
       
   346 		TBuf<1> charSevr;
       
   347 		switch(aSeverity)
       
   348 			{
       
   349 			case ESevrVer:
       
   350 				charSevr = _L("V");
       
   351 				break;
       
   352 			case ESevrErr:
       
   353 				charSevr = _L("E");
       
   354 				break;
       
   355 			case ESevrWarn:
       
   356 				charSevr = _L("W");
       
   357 				break;
       
   358 			case ESevrInfo:
       
   359 			default:
       
   360 				charSevr = _L("I");
       
   361 				break;
       
   362 			}
       
   363 
       
   364 		// Do we need to put information about source file & #line?
       
   365 		if(iLogFlags & ELogPutSrcInfo)
       
   366 			{		// Braces used to scope lifetime of TBuf objects
       
   367 			TPtrC8 fileName8(aFile);
       
   368 			TBuf<256> fileName;
       
   369 			TParse printFileName;
       
   370 			fileName.Copy(fileName8);  // TText8->TBuf16
       
   371 			// We don't need full file name.
       
   372 			printFileName.Set(fileName, NULL, NULL) ;
       
   373 			fileName.Copy(printFileName.NameAndExt()) ;
       
   374 			// write to log file
       
   375 			WriteFormat(_L("%S\t%S\t%d\t%S\n"), &charSevr, &fileName, aLine, &lineBuf);
       
   376 			}
       
   377 		else
       
   378 			{
       
   379 			// write to log file
       
   380 			WriteFormat(_L("%S\t%S\n"), &charSevr, &lineBuf);
       
   381 			}
       
   382 		}
       
   383 	}
       
   384 #endif // EXCLUDE_FOR_UNITTEST
       
   385 
       
   386 /**
       
   387  *
       
   388  * Traceable logging function with variable param list.
       
   389  *
       
   390  * Should be used for macros only
       
   391  *
       
   392  * @param	"const TText8* aFile"
       
   393  *			Source code file name
       
   394  *
       
   395  * @param	"TInt aLine"
       
   396  *			Source code line
       
   397  *
       
   398  * @param	"TInt aSeverity"
       
   399  *			Severity level required to log
       
   400  *
       
   401  * @param	"TRefByValue<const TDesC16> aFmt"
       
   402  *			Printf-style format.
       
   403  *
       
   404  * @param	"..."
       
   405  *			Variable print parameters
       
   406  *
       
   407  * @xxxx
       
   408  *
       
   409  */
       
   410 EXPORT_C void CLog::LogExtra(const TText8* aFile, TInt aLine, TInt aSeverity,
       
   411 		TRefByValue<const TDesC16> aFmt,...)
       
   412 	{
       
   413 	VA_LIST aList;
       
   414 	VA_START(aList, aFmt);
       
   415 	LogExtra(aFile, aLine, aSeverity, aFmt, aList);
       
   416 	VA_END(aList); 
       
   417 	}
       
   418 
       
   419 
       
   420 /**
       
   421  *
       
   422  * Write a test result highlighted to the log.
       
   423  *
       
   424  * @param	"TVerdict aVerdict"
       
   425  *			The test verdict.
       
   426  *
       
   427  * @param	"TRefByValue<const TDesC16> aFmt"
       
   428  *			Printf-style format.
       
   429  *
       
   430  * @param	"..."
       
   431  *			Variable print parameters
       
   432  *
       
   433  * @xxxx
       
   434  *
       
   435  */
       
   436 EXPORT_C void CLog::LogResult(TVerdict aVerdict, TRefByValue<const TDesC16> aFmt, ...)
       
   437 	{
       
   438     VA_LIST aList;
       
   439 	VA_START(aList, aFmt);
       
   440 
       
   441 	TIntegrationTestLog16Overflow iOverflow16;
       
   442 
       
   443 	// decode formatted data for display on console
       
   444 	TBuf <KMaxLogLineLength> lineBuf;
       
   445 	lineBuf.AppendFormatList(aFmt, aList, &iOverflow16);
       
   446 
       
   447 	// write to the console
       
   448 	iClientSession.WriteLog(lineBuf, ELogToConsole);
       
   449 
       
   450 	// write to log file
       
   451 	if(iLogFlags & ELogHtmlMode)
       
   452 		{ 
       
   453 		switch(aVerdict)
       
   454 			{
       
   455 		case EPass:
       
   456 			VER_PRINTF(&KResultPass(), &lineBuf, &KResultEnd());
       
   457 			break;
       
   458 		case EFail:
       
   459 			VER_PRINTF(&KResultFail(), &lineBuf, &KResultEnd());
       
   460 			break;
       
   461 		case EInconclusive:
       
   462 		case ETestSuiteError:
       
   463 		case EAbort:
       
   464 			VER_PRINTF(&KResultInconclusive(), &lineBuf, &KResultEnd());
       
   465 			break;
       
   466 		case EKnownFailure:	//A new TVerdict for a known failed test
       
   467 			VER_PRINTF(&KResultKnownFailure(), &lineBuf, &KResultEnd());
       
   468 			break;
       
   469 
       
   470 		default: // undefined
       
   471 			VER_PRINTF(&KResultUndefined(), &lineBuf, &KResultEnd());
       
   472 			break;
       
   473 			}
       
   474 		}
       
   475 	else
       
   476 		{
       
   477 			VER_PRINTF(&KResultNonHtml(), &lineBuf, &KResultNonHtml());
       
   478 		}	
       
   479 	VA_END(aList); 
       
   480 	}
       
   481 
       
   482 /**
       
   483  *
       
   484  * Make a readable string out of an EPOC error code.
       
   485  *
       
   486  * @param	"TInt aError"
       
   487  *			The error code
       
   488  *
       
   489  * @return	"TPtrC"
       
   490  *			The error code as a readable string
       
   491  *
       
   492  * @xxxx
       
   493  *
       
   494  */
       
   495 EXPORT_C TPtrC CLog::EpocErrorToText(TInt aError)
       
   496 	{
       
   497 	switch (aError)
       
   498 		{
       
   499 	case KErrNone:
       
   500 		return _L("KErrNone");
       
   501 	case KErrNotFound:
       
   502 		return _L("KErrNotFound");
       
   503 	case KErrGeneral:
       
   504 		return _L("KErrGeneral");
       
   505 	case KErrCancel:
       
   506 		return _L("KErrCancel");
       
   507 	case KErrNoMemory:
       
   508 		return _L("KErrNoMemory");
       
   509 	case KErrNotSupported:
       
   510 		return _L("KErrNotSupported");
       
   511 	case KErrArgument:
       
   512 		return _L("KErrArgument");
       
   513 	case KErrTotalLossOfPrecision:
       
   514 		return _L("KErrTotalLossOfPrecision");
       
   515 	case KErrBadHandle:
       
   516 		return _L("KErrBadHandle");
       
   517 	case KErrOverflow:
       
   518 		return _L("KErrOverflow");
       
   519 	case KErrUnderflow:
       
   520 		return _L("KErrUnderflow");
       
   521 	case KErrAlreadyExists:
       
   522 		return _L("KErrAlreadyExists");
       
   523 	case KErrPathNotFound:
       
   524 		return _L("KErrPathNotFound");
       
   525 	case KErrDied:
       
   526 		return _L("KErrDied");
       
   527 	case KErrInUse:
       
   528 		return _L("KErrInUse");
       
   529 	case KErrServerTerminated:
       
   530 		return _L("KErrServerTerminated");
       
   531 	case KErrServerBusy:
       
   532 		return _L("KErrServerBusy");
       
   533 	case KErrCompletion:
       
   534 		return _L("KErrCompletion");
       
   535 	case KErrNotReady:
       
   536 		return _L("KErrNotReady");
       
   537 	case KErrUnknown:
       
   538 		return _L("KErrUnknown");
       
   539 	case KErrCorrupt:
       
   540 		return _L("KErrCorrupt");
       
   541 	case KErrAccessDenied:
       
   542 		return _L("KErrAccessDenied");
       
   543 	case KErrLocked:
       
   544 		return _L("KErrLocked");
       
   545 	case KErrWrite:
       
   546 		return _L("KErrWrite");
       
   547 	case KErrDisMounted:
       
   548 		return _L("KErrDisMounted");
       
   549 	case KErrEof:
       
   550 		return _L("KErrEof");
       
   551 	case KErrDiskFull:
       
   552 		return _L("KErrDiskFull");
       
   553 	case KErrBadDriver:
       
   554 		return _L("KErrBadDriver");
       
   555 	case KErrBadName:
       
   556 		return _L("KErrBadName");
       
   557 	case KErrCommsLineFail:
       
   558 		return _L("KErrCommsLineFail");
       
   559 	case KErrCommsFrame:
       
   560 		return _L("KErrCommsFrame");
       
   561 	case KErrCommsOverrun:
       
   562 		return _L("KErrCommsOverrun");
       
   563 	case KErrCommsParity:
       
   564 		return _L("KErrCommsParity");
       
   565 	case KErrTimedOut:
       
   566 		return _L("KErrTimedOut");
       
   567 	case KErrCouldNotConnect:
       
   568 		return _L("KErrCouldNotConnect");
       
   569 	case KErrCouldNotDisconnect:
       
   570 		return _L("KErrCouldNotDisconnect");
       
   571 	case KErrDisconnected:
       
   572 		return _L("KErrDisconnected");
       
   573 	case KErrBadLibraryEntryPoint:
       
   574 		return _L("KErrBadLibraryEntryPoint");
       
   575 	case KErrBadDescriptor:
       
   576 		return _L("KErrBadDescriptor");
       
   577 	case KErrAbort:
       
   578 		return _L("KErrAbort");
       
   579 	case KErrTooBig:
       
   580 		return _L("KErrTooBig");
       
   581 	default:
       
   582 		return _L("Unknown");
       
   583 		} // end switch
       
   584 	}
       
   585 
       
   586 
       
   587 /**
       
   588  *
       
   589  * Make a readable string out of a test verdict.
       
   590  *
       
   591  * @param	"TVerdict aTestVerdict"
       
   592  *			The test verdict
       
   593  *
       
   594  * @return	"TPtrC"
       
   595  *			The test verdict as a readable string
       
   596  *
       
   597  * @xxxx
       
   598  *
       
   599  */
       
   600 EXPORT_C TPtrC CLog::TestResultText(TVerdict aTestVerdict)
       
   601 	{
       
   602 	switch (aTestVerdict)
       
   603 		{
       
   604 	case EPass:
       
   605 		return _L("PASS");
       
   606 	case EFail:
       
   607 		return _L("FAIL");
       
   608 	case EInconclusive:
       
   609 		return _L("INCONCLUSIVE");
       
   610 	case ETestSuiteError:
       
   611 		return _L("TEST_SUITE_ERROR");
       
   612 	case EAbort:
       
   613 		return _L("ABORT");
       
   614 	case EKnownFailure: //A new TVerdict for a known failed test
       
   615 		return _L("KNOWN_Failure"); //using lower case in 'Failure' can remove the confusion on 'savres2html.bat' making test summary
       
   616 	default:
       
   617 		return _L("undefined");
       
   618 
       
   619 		}
       
   620 	}
       
   621 
       
   622 /**
       
   623  *
       
   624  * Write blank lines to the log.
       
   625  *
       
   626  * @param	"TInt number"
       
   627  *			Number of lines to write
       
   628  *
       
   629  * @xxxx
       
   630  *
       
   631  */
       
   632 EXPORT_C void CLog::LogBlankLine(TInt aNumber)
       
   633 	{
       
   634 	for (TInt i = 0; i < aNumber; i++)
       
   635 		Log(_L(" "));
       
   636 	}
       
   637 
       
   638 /**
       
   639  *
       
   640  * Close the log.
       
   641  *
       
   642  * @xxxx
       
   643  *
       
   644  */
       
   645 EXPORT_C void CLog::CloseLogFile()
       
   646 	{
       
   647 	// add the htm end
       
   648 	WriteFormat(_L("</end>"));
       
   649 	
       
   650 	iClientSession.CloseLog();
       
   651 	}
       
   652 
       
   653 /**
       
   654  *
       
   655  * Set log severity.
       
   656  *
       
   657  * @param	"TInt aSeverity"
       
   658  *			The required severity
       
   659  *
       
   660  * @xxxx
       
   661  *
       
   662  */
       
   663 EXPORT_C void CLog::SetSeverity(TInt aSeverity)
       
   664 {
       
   665 	iSeverity = aSeverity;
       
   666 }
       
   667 
       
   668 /**
       
   669  *
       
   670  * Get log severity.
       
   671  *
       
   672  * @return	"TInt"
       
   673  *			The current severity
       
   674  *
       
   675  * @xxxx
       
   676  *
       
   677  */
       
   678 EXPORT_C TInt CLog::Severity() const
       
   679 {
       
   680 	return iSeverity;
       
   681 }
       
   682 
       
   683 /**
       
   684  *
       
   685  * Get log status from this logger's client session.
       
   686  *
       
   687  * @return	"TInt"
       
   688  *			The current log status (a bitmask of TTestFrameworkLogMode)
       
   689  *
       
   690  * @xxxx
       
   691  *
       
   692  */
       
   693 EXPORT_C TInt CLog::LogStatus()
       
   694 	{
       
   695 	return iClientSession.LogStatus();
       
   696 	}
       
   697 
       
   698 
       
   699 /**
       
   700  *
       
   701  * Write formatted output to the log.
       
   702  *
       
   703  * @param	"TRefByValue<const TDesC16> aFmt"
       
   704  *			Printf-style format.
       
   705  *
       
   706  * @param	"..."
       
   707  *			Variable print parameters
       
   708  *
       
   709  * @xxxx
       
   710  *
       
   711  */
       
   712 EXPORT_C void CLog::WriteFormat(TRefByValue<const TDesC16> aFmt, ...)
       
   713 	{
       
   714 
       
   715 	// file / port logging not enabled
       
   716 	if (!(iLogStatus & ELogToFile))
       
   717 		if (!(iLogStatus & ELogToPort))
       
   718 			return;
       
   719 
       
   720     VA_LIST aList;
       
   721 	VA_START(aList, aFmt);
       
   722 
       
   723 	TIntegrationTestLog16Overflow overflow16;
       
   724 
       
   725 	TUint16* dataBufPtr = (TUint16*)(iDataBuf.Ptr());
       
   726 	TPtr16 lineBuf(dataBufPtr, 0, KMaxLogLineLength);
       
   727 	lineBuf.Fill('\0', KMaxLogLineLength);
       
   728 
       
   729 	// get the current time and date
       
   730 	TTime now;
       
   731 	now.HomeTime();
       
   732 	TDateTime dateTime = now.DateTime() ;
       
   733 
       
   734 	// add the current time and date 
       
   735 	lineBuf.Format(_L("%02d/%02d/%04d\t%02d:%02d:%02d:%03d\t"),
       
   736 		dateTime.Day()+1,
       
   737 		dateTime.Month()+1,
       
   738 		dateTime.Year(),
       
   739 		dateTime.Hour(),
       
   740 		dateTime.Minute(),
       
   741 		dateTime.Second(),
       
   742 		(dateTime.MicroSecond() / 1000)); 
       
   743 
       
   744 	// followed by the formatted data
       
   745 	lineBuf.AppendFormatList(aFmt, aList, &overflow16);
       
   746 	VA_END(aList); 
       
   747 
       
   748 	// send one message - the server will write to both if enabled
       
   749 	TInt theStatus = 0;
       
   750 	if (iLogStatus & ELogToFile)
       
   751 		theStatus |= ELogToFile;
       
   752 	if (iLogStatus & ELogToPort)
       
   753 		theStatus |= ELogToPort;
       
   754 
       
   755 	iClientSession.WriteLog(lineBuf, theStatus);
       
   756 	}
       
   757 
       
   758 /**
       
   759  *
       
   760  * Write output to the console with date/time stamp
       
   761  *
       
   762  * @param	"const TDesC& aBuf"
       
   763  *			The output.
       
   764  *
       
   765  * @xxxx
       
   766  *
       
   767  */
       
   768 EXPORT_C void CLog::WriteLogConsole(const TDesC& aBuf)
       
   769 	{
       
   770 
       
   771 	// console logging not enabled
       
   772 	if (!(iLogStatus & ELogConsoleFull))
       
   773 		return;
       
   774 
       
   775 	// decode formatted data for display on console
       
   776 	TUint16* dataBufPtr = (TUint16*)(iDataBuf.Ptr());
       
   777 	TPtr16 lineBuf(dataBufPtr, 0, KMaxLogLineLength);
       
   778 	lineBuf.Fill('\0', KMaxLogLineLength);
       
   779 
       
   780 	// get the current time and date
       
   781 	TTime now;
       
   782 	now.HomeTime();
       
   783 	TDateTime dateTime = now.DateTime() ;
       
   784 
       
   785 	// add the current time and date 
       
   786 	lineBuf.Format(_L("%02d/%02d/%04d\t%02d:%02d:%02d:%03d\t%S"),
       
   787 		dateTime.Day()+1,
       
   788 		dateTime.Month()+1,
       
   789 		dateTime.Year(),
       
   790 		dateTime.Hour(),
       
   791 		dateTime.Minute(),
       
   792 		dateTime.Second(),
       
   793 		(dateTime.MicroSecond() / 1000),
       
   794 		&aBuf); 
       
   795 
       
   796 	iClientSession.WriteLog(lineBuf, ELogToConsole);
       
   797 	}
       
   798 
       
   799 /**
       
   800  *
       
   801  * This function is used to avoid a panic if format text overflows 
       
   802  * the internal buffer.
       
   803  *
       
   804  * @param "TDes16&"
       
   805  *		  the overflowing string
       
   806  *
       
   807  * @xxxx
       
   808  *
       
   809  */
       
   810 void TIntegrationTestLog16Overflow::Overflow(TDes16& aDes)
       
   811 	{
       
   812 	aDes = _L("*** ERROR : line too long, cannot log ***");
       
   813 	}
       
   814 
       
   815 /**
       
   816  *
       
   817  * Check a severity value is valid.
       
   818  *
       
   819  * @param "TInt aSev"
       
   820  *		  The value to check.
       
   821  *
       
   822  * @return "TBool"
       
   823  *			Valid (ETrue) or not (EFalse).
       
   824  *
       
   825  * @xxxx
       
   826  *
       
   827  */
       
   828 EXPORT_C TBool LogSeverity::IsValid(TInt aSev)
       
   829 	{ 
       
   830 	return ((aSev & ~(ESevrAll)) == 0);
       
   831 	}
       
   832 
       
   833 /**
       
   834  *
       
   835  * Check a severity value is active
       
   836  *
       
   837  * @param "TInt aThisSev"
       
   838  *		  The value to check.
       
   839  *
       
   840  * @param "TInt aGlobalSev"
       
   841  *		  The value to check against (e.g. global severity value of a log).
       
   842  *
       
   843  * @return "TBool"
       
   844  *			Active (ETrue) or not (EFalse).
       
   845  *
       
   846  * @xxxx
       
   847  *
       
   848  */
       
   849 EXPORT_C TBool LogSeverity::IsActive(TInt aThisSev, TInt aGlobalSev)
       
   850 	{ 
       
   851 	return ((aThisSev & aGlobalSev) != 0);
       
   852 	}