resourcemgmt/hwresourcesmgr/test/multiclient/common/tc_log.h
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 /*
       
     2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19  
       
    20 #ifndef TC_LOG_H
       
    21 #define TC_LOG_H
       
    22 
       
    23 //Includes
       
    24 
       
    25 #include "tc_config.h"
       
    26 
       
    27 // This class implements writing results to log files
       
    28 class Log : public CBase
       
    29 {
       
    30 public:
       
    31 
       
    32 	// this enumeration defines priorities of printed lines.
       
    33     enum Priority
       
    34     {
       
    35 
       
    36         ZERO = 0,
       
    37         PASS,              // priority of passed line
       
    38         NOTIFY,            // priority of notification
       
    39 		SCHEDULER,         // priority of scheduler line
       
    40 		MONITOR,           // priority of monitor
       
    41 		WARNING,           // priority of warning line
       
    42         FAIL,              // priority of failed line
       
    43         COMMENT,           // priority of comment line
       
    44         SUMMARY,           // priority of summary line
       
    45 		SESSION_MARK,      // priority of session line
       
    46 		BEGIN_TESTCASE,    // priority of beginning test case line
       
    47 		END_TESTCASE,      // priority of ending test case line
       
    48     };
       
    49 
       
    50 
       
    51 	Log();
       
    52 	virtual ~Log();
       
    53 
       
    54 	void OpenL(const TDesC &aFileName, TBool aBatch, TBool aEchoOn, TBool aTimestamp, Priority aPriorityFilter);
       
    55 
       
    56 
       
    57 	// print EPOC descriptors
       
    58 	virtual void Printf(Priority priority, TRefByValue<const TDesC> aFmt, ...);
       
    59 
       
    60 	// some TSY wrappers use this function jlof 13-12-2001
       
    61 	virtual void Printf(TRefByValue<const TDesC>, ...);
       
    62 
       
    63 	// write descriptor
       
    64 	virtual void Write(Priority priority, const TDesC& aStr);
       
    65 
       
    66 	// print C -strings
       
    67 	virtual void Printf(Priority priority, const char *fmt, ...);
       
    68 
       
    69 	// prints summary report
       
    70 	virtual void SummaryReport(const TDesC& aTestCaseName);
       
    71 
       
    72 	// used to implement pause stuff..
       
    73 	virtual void  RequestKeyPress();
       
    74 	virtual TBool ReceiveKeyPress();
       
    75 	virtual void  WaitKeyPress();
       
    76 
       
    77 	// multiple choice
       
    78 	virtual TInt MultipleChoice(TInt aMin, TInt aMax);
       
    79 
       
    80 	// set console title
       
    81 	virtual void SetTitle(const TDesC& aTitle);
       
    82 
       
    83 private:
       
    84 
       
    85     CConsoleBase*  iConsole;
       
    86 	TRequestStatus iConsoleKeyRequest;
       
    87 
       
    88 	// if true, dont ask anything from user
       
    89 	TBool iBatch;
       
    90 
       
    91 	// if true write timestamps to log
       
    92 	TBool iWriteTimestamp;
       
    93 
       
    94 	// log message priority filter
       
    95     Priority iPriorityFilter;
       
    96 
       
    97 	// TBuf for log functions
       
    98 	TBuf<MAX_LEN*2> iStr;
       
    99 
       
   100 	// output to file
       
   101 	TBuf8<MAX_LEN*2> iOut8;
       
   102 
       
   103 	// log output buffer
       
   104 	TBuf<MAX_LEN*2> iLog_bufout; 
       
   105 
       
   106 	// TUint8 buffer
       
   107 	TUint8 iUint8[MAX_LEN*2];
       
   108 
       
   109     // current time to log
       
   110 	TTime iTime;
       
   111 
       
   112 
       
   113 	// file pointer for log file
       
   114 	void* iFile; // using void* insteand of file to avoid including stdio.h
       
   115 
       
   116 	// helper class used for counting some statistics
       
   117 	class Counter
       
   118 	{
       
   119 		const TDesC& iName;
       
   120 		TInt         iCount;
       
   121 		TInt         iTotal;
       
   122 	public:
       
   123 		Counter(const TDesC& aName):iName(aName),iCount(0),iTotal(0)
       
   124 		{
       
   125 		}
       
   126 		void operator++(int)
       
   127 		{
       
   128 			iCount++;
       
   129 			iTotal++;
       
   130 		}
       
   131 		void Summary(Log& aLog)
       
   132 		{
       
   133 			TBuf<MAX_LEN> buf;
       
   134 			buf.AppendFormat(_L("%S: %d"), &iName, iCount);
       
   135 			aLog.Write(Log::SUMMARY, buf);
       
   136 			iCount = 0;
       
   137 		}
       
   138 		void Total(Log& aLog)
       
   139 		{
       
   140 			TBuf<MAX_LEN> buf;
       
   141 			buf.AppendFormat(_L("%S: %d"), &iName, iTotal);
       
   142 			aLog.Write(Log::SUMMARY, buf);
       
   143 			iCount = 0;
       
   144 			iTotal = 0;
       
   145 		}
       
   146 	};
       
   147 	friend class Log::Counter; // counter should be friend of log..
       
   148 
       
   149 	// line counters...
       
   150 	Counter iPassed;
       
   151 	Counter iFailed;
       
   152 	Counter iWarnings;
       
   153 	Counter iComments;
       
   154 };
       
   155 
       
   156 
       
   157 
       
   158 
       
   159 #endif // TC_LOG_H
       
   160