telephonyutils/telephonywatchers/Test/TE_TelWatchers/TE_TelWatchersUnitWatcherLog.cpp
changeset 0 3553901f7fa8
child 24 6638e7f4bd8f
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     1 // Copyright (c) 2004-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 //
       
    15 
       
    16 #include "TE_TelWatchersUnitWatcherLog.h"
       
    17 
       
    18 /**
       
    19  *  @file
       
    20  *  Telephony Watchers Unit Test Watcher logging.
       
    21  */
       
    22 
       
    23 /* 
       
    24    Class used for logging in telephony watcher unit tests - normally watchers will link
       
    25    with watcher.lib and use the watcher implementation of CWatcherLog, but under unit
       
    26    test conditions, we want the extra functionality provided by this CWatcherLog, so link
       
    27    to this file
       
    28 */
       
    29 
       
    30 //
       
    31 // Switch this define on for extra output!
       
    32 //
       
    33 //#define WATCHERS_VERBOSE_OUTPUT 
       
    34 
       
    35 CWatcherLog::CWatcherLog(CTestExecuteLogger& aTestExecuteLogger)
       
    36   : iTestExecuteLogger(aTestExecuteLogger)
       
    37 	{
       
    38 	// NOP
       
    39 	} // CWatcherLog::CWatcherLog
       
    40 
       
    41 
       
    42 /**
       
    43  *  Print to the Test Execute log...
       
    44  *
       
    45  *  @param aFmt  A format string.
       
    46  *  @param ...   An optional list of parameters.
       
    47  */
       
    48 void CWatcherLog::PrintToTestExecuteLogL(TRefByValue<const TDesC> aFmt, VA_LIST aParamList)
       
    49 	{
       
    50 	//
       
    51 	// Convert the text to a single string.  We do this regardless of whether
       
    52 	// we need to, so that the EABI warning about unused parameters does not
       
    53 	// occur.
       
    54 	//
       
    55 	HBufC*  buffer = HBufC::NewLC(KMaxTestExecuteLogLineLength);
       
    56 	TPtr  ptr(buffer->Des());
       
    57 
       
    58 	ptr.AppendFormatList(aFmt, aParamList);
       
    59 
       
    60 #ifdef WATCHERS_VERBOSE_OUTPUT
       
    61 	//
       
    62 	// If this string is of the form "<Class> : <Some Text>" then use the Test
       
    63 	// Execute format, otherwise write it all...
       
    64 	//
       
    65 	_LIT(KWatcherLogSplitText, " : ");
       
    66 	TInt  offset = ptr.Find(KWatcherLogSplitText);
       
    67 
       
    68 	if (offset >= 0)
       
    69 		{
       
    70 		HBufC8*  className = HBufC8::NewLC(buffer->Size());
       
    71 		HBufC*  textString = HBufC::NewLC(buffer->Size());
       
    72 
       
    73 		_LIT8(KNullChar,"\000");
       
    74 		className->Des().Append(ptr.Left(offset));
       
    75 		className->Des().Append(KNullChar);
       
    76 
       
    77 		textString->Des().Append(ptr.Mid(offset + TDesC(KWatcherLogSplitText).Length()));
       
    78 
       
    79 		iTestExecuteLogger.LogExtra(&((*className)[0]), 0, ESevrInfo, 
       
    80 									  _L("%S"), textString);
       
    81 		
       
    82 		CleanupStack::PopAndDestroy(textString);
       
    83 		CleanupStack::PopAndDestroy(className);
       
    84 		}
       
    85 	else
       
    86 		{
       
    87 		iTestExecuteLogger.LogExtra(((TText8*) "CWatcherLog"), 0, ESevrInfo,
       
    88 									  _L("%S"), buffer);
       
    89 		}
       
    90 #endif
       
    91 
       
    92 	CleanupStack::PopAndDestroy(buffer);
       
    93 	} // CWatcherLog::PrintToTestExecuteLogL
       
    94 
       
    95 
       
    96 /**
       
    97  *  Convert the log request into a Test Execute logging request.
       
    98  *
       
    99  *  @param aFmt  A format string.
       
   100  *  @param ...   An optional list of parameters.
       
   101  */
       
   102 void CWatcherLog::Printf(TRefByValue<const TDesC> aFmt, ...)
       
   103 	{
       
   104 	//
       
   105 	// Call the PrintToTestExecuteLogL() procedure which may leave.  There's
       
   106 	// not much that can be done if the function leaves.
       
   107 	//
       
   108 	VA_LIST  list;
       
   109 	VA_START(list, aFmt);
       
   110 	TRAP_IGNORE(PrintToTestExecuteLogL(aFmt, list));
       
   111 	VA_END(list);
       
   112 	} // CWatcherLog::Printf