testexecfw/stf/api/api_platform/inc/StifLogger.h
changeset 2 8bb370ba6d1d
equal deleted inserted replaced
1:bbd31066657e 2:8bb370ba6d1d
       
     1 /*
       
     2 * Copyright (c) 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: This file contains the header file of the 
       
    15 * CStifLogger.
       
    16 *
       
    17 */
       
    18 
       
    19 #ifndef STIFLOGGER_H
       
    20 #define STIFLOGGER_H
       
    21 
       
    22 //  INCLUDES
       
    23 #include <e32base.h>
       
    24 #include <e32std.h>  // TBuf
       
    25 
       
    26 
       
    27 // If using older STIF TF than STIF200414 there is no this definition.
       
    28 // If is need to combile e.g. testmodule with older STIF TF there may use
       
    29 // in the testmodule this flag to indicating which enum definition is used.
       
    30 // Example:
       
    31 //          #ifdef __NEW_LOGGER_ENUMS_DEFS__
       
    32 //              logger->Log( CStifLogger::ERed, _L( "Logged text" ) );
       
    33 //          #else
       
    34 //              logger->Log( ERed, _L( "Logged text" ) );
       
    35 //          #endif
       
    36 #define __NEW_LOGGER_ENUMS_DEFS__
       
    37 
       
    38 // Maximum length of the data. Must be over 26 because HTML page initializing.
       
    39 // Can be only max 254 length because rdebug prints max 256 length text and
       
    40 // that includes line break(+2 character)
       
    41 const TInt KMaxLogData = 254;
       
    42 
       
    43 // This is for making partitions of the rdebug( minus 3 is for ' ->')
       
    44 const TInt KMaxRDebug = KMaxLogData - 3;
       
    45 
       
    46 // Maximum count of file type plus dot e.g. ".txt"
       
    47 const TInt KMaxFileType = 10;
       
    48 
       
    49 // Maximum length of the date and time logging
       
    50 // Includes date, time, spaces(5) and end of line(2):
       
    51 // e.g. "'06.Nov.2003 15:12:18.123    '...logged data...'  '"
       
    52 const TInt KMaxTimeStamp = 30;
       
    53 
       
    54 // MACROS
       
    55 // None
       
    56 
       
    57 // DATA TYPES
       
    58 
       
    59 // For 16 bit data size definition.
       
    60 typedef TBuf<KMaxLogData> TLogInfo;
       
    61 
       
    62 // For 8 bit data size definition.
       
    63 typedef TBuf8<KMaxLogData> TLogInfo8;
       
    64 
       
    65 // For file type size definition.
       
    66 typedef TBuf<KMaxFileType> TFileType;
       
    67 
       
    68 // For time stamp size definition.
       
    69 typedef TBuf8<KMaxTimeStamp> TStifLoggerTimeStamp;
       
    70 
       
    71 // For time stamp size definition.
       
    72 typedef TBuf<KMaxTimeStamp> TStifLoggerTimeStamp8;
       
    73 
       
    74 // FUNCTION PROTOTYPES
       
    75 // None
       
    76 
       
    77 
       
    78 
       
    79 // Structs are defined at the end of this file.
       
    80 struct TOverwritedSettings;
       
    81 struct TLoggerSettings;
       
    82 
       
    83 
       
    84 // FORWARD DECLARATIONS
       
    85 class COutput;
       
    86 class RSTFLogger;
       
    87 
       
    88 
       
    89 // CLASS DECLARATION
       
    90 
       
    91 // DESCRIPTION
       
    92 // CStifLogger is a STIF Test Framework StifLogger class.
       
    93 // Class contains a file logging operations.
       
    94 
       
    95 
       
    96 class CStifLogger 
       
    97         :public CBase
       
    98     {
       
    99     public:     // Enumerations
       
   100 
       
   101         // Different StifLogger presentations types.
       
   102         enum TLoggerType
       
   103             {
       
   104             ETxt,       // txt file logging
       
   105             EData,      // data file logging(e.g. web page downloading )
       
   106             EHtml       // html file logging
       
   107             };
       
   108 
       
   109         // Different StifLogger output modules.
       
   110         enum TOutput
       
   111             {
       
   112             EFile,      // File logging
       
   113             ERDebug     // RDebug logging
       
   114             };
       
   115 
       
   116         // Different style forms for text.
       
   117         enum TStyle
       
   118             {
       
   119             ENoStyle    = 0x00000,  // No style parameter
       
   120             EBold       = 0x00001,  // Bold
       
   121             ECursive    = 0x00002,  // Cursive
       
   122             EUnderline  = 0x00004,  // Underline
       
   123             EBlue       = 0x00008,  // Blue
       
   124             EGreen      = 0x00010,  // Green
       
   125             ERed        = 0x00020,  // Red
       
   126             EImportant  = 0x00040,  // Important (Line will starts a 'IMPORTANT' text)
       
   127             EWarning    = 0x00080,  // Warning (Line will starts a 'WARNING' text)
       
   128             EError      = 0x00100   // Error (Line will starts a 'ERROR' text)
       
   129             };
       
   130 
       
   131     private:    // Enumerations
       
   132 
       
   133     public:     // Constructors and destructor
       
   134 
       
   135         /**
       
   136         * Two-phased constructor.
       
   137         */
       
   138         IMPORT_C static CStifLogger* NewL( const TDesC& aTestPath,
       
   139                                             const TDesC& aTestFile,
       
   140                                             // Default logger type is .txt
       
   141                                             TLoggerType aLoggerType = ETxt,
       
   142                                             // By default output is file
       
   143                                             TOutput aOutput = EFile,
       
   144                                             // By default overwrite is used
       
   145                                             TBool aOverWrite = ETrue,
       
   146                                             // By default time stamp is used
       
   147                                             TBool aWithTimeStamp = ETrue,
       
   148                                             // By default line break is used
       
   149                                             TBool aWithLineBreak = ETrue,
       
   150                                             // By default even ranking is not
       
   151                                             // used
       
   152                                             TBool aWithEventRanking = EFalse,
       
   153                                             // By default thread id is added
       
   154                                             // after the log file
       
   155                                             TBool aThreadIdToLogFile = ETrue,
       
   156                                             // By default log directory will
       
   157                                             // not create
       
   158                                             TBool aCreateLogDir = EFalse,
       
   159                                             // Static logger implementation is
       
   160                                             // not yet permanent, may change 
       
   161                                             TInt aStaticBufferSize = 0,
       
   162                                             // By default files are not written
       
   163                                             // in unicode format
       
   164                                             TBool aUnicode = EFalse );
       
   165 
       
   166         virtual ~CStifLogger();
       
   167 
       
   168     public:     // New functions
       
   169 
       
   170         CStifLogger();
       
   171 
       
   172         /**
       
   173         * Log a 16 bit information to some storage e.g. text file.
       
   174         */
       
   175         IMPORT_C TInt Log( const TDesC& aLogInfo );
       
   176 
       
   177         /**
       
   178         * Log a 8 bit information to some storage e.g. text file.
       
   179         */
       
   180         IMPORT_C TInt Log( const TDesC8& aLogInfo );
       
   181 
       
   182         /**
       
   183         * Log a 16 bit information to some storage e.g. text file. There is
       
   184         * also parameter to styling text information e.g. text color.
       
   185         */
       
   186         IMPORT_C TInt Log( TInt aStyle, const TDesC& aLogInfo );
       
   187 
       
   188         /**
       
   189         * Log a 8 bit information to some storage e.g. text file. There is
       
   190         * also parameter to styling text information e.g. text color.
       
   191         */
       
   192         IMPORT_C TInt Log( TInt aStyle, const TDesC8& aLogInfo );
       
   193 
       
   194         /**
       
   195         * Log a 16 bit information to some storage e.g. text file. In this log
       
   196         * method may set several parameters.
       
   197         */
       
   198         IMPORT_C TInt Log( TRefByValue<const TDesC> aLogInfo,... );
       
   199 
       
   200         /**
       
   201         * Log a 8 bit information to some storage e.g. text file. In this log
       
   202         * method may set several parameters.
       
   203         */
       
   204         IMPORT_C TInt Log( TRefByValue<const TDesC8> aLogInfo,... );
       
   205 
       
   206         /**
       
   207         * Log a 16 bit information to some storage e.g. text file. There is
       
   208         * also parameter to styling text information e.g. text color.
       
   209         */
       
   210         IMPORT_C TInt Log( TInt aStyle,
       
   211             TRefByValue<const TDesC> aLogInfo,... );
       
   212 
       
   213         /**
       
   214         * Log a 8 bit information to some storage e.g. text file. There is
       
   215         * also parameter to styling text information e.g. text color.
       
   216         */
       
   217         IMPORT_C TInt Log( TInt aStyle,
       
   218             TRefByValue<const TDesC8> aLogInfo,... );
       
   219 
       
   220         /**
       
   221         * Log a 16 bit delimiter. Default char is '#' and default
       
   222         * repeat count is 60.
       
   223         * This will be used if parameters are not given when calling
       
   224         * this method.
       
   225         */
       
   226         IMPORT_C TInt WriteDelimiter( const TDesC& aDelimiter = _L( "#"),
       
   227                                         TInt aCount = 60 );
       
   228 
       
   229         /**
       
   230         * Log a 8 bit delimiter. 8 bit delimiter includes no default values.
       
   231         * Delimiter may be '#' or 'XO' etc.
       
   232         */
       
   233         IMPORT_C TInt WriteDelimiter( const TDesC8& aDelimiter, TInt aCount );
       
   234 
       
   235         /**
       
   236         * Used when is need to save file or data to storage e.g. web page.
       
   237         * 16 bit.
       
   238         */
       
   239         IMPORT_C TInt SaveData( TDesC& aData );
       
   240 
       
   241         /**
       
   242         * Used when is need to save file or data to storage e.g. web page.
       
   243         * 8 bit.
       
   244         */
       
   245         IMPORT_C TInt SaveData( TDesC8& aData );
       
   246         
       
   247         /**
       
   248         * Get creation result.
       
   249         */
       
   250         IMPORT_C TInt CreationResult();
       
   251 
       
   252         /**
       
   253         * Get output type. Valid only if CreationResult returns KErrNone.
       
   254         */
       
   255         IMPORT_C TOutput OutputType();
       
   256 
       
   257         /**
       
   258         * Pure virtual. Send style information and data to the output module.
       
   259         * 16 bit.
       
   260         */
       
   261         virtual TInt Send( TInt /*aStyle*/, const TDesC& /*aData*/ );
       
   262 
       
   263         /**
       
   264         * Pure virtual. Send style information and data to the output module.
       
   265         * 8 bit.
       
   266         */
       
   267         virtual TInt Send( TInt /*aStyle*/, const TDesC8& /*aData*/ );
       
   268 
       
   269         /**
       
   270         * Log 16 bit _LIT information to some storage e.g. text file.
       
   271         */
       
   272         template<TInt S> TInt Log( const TLitC<S>& aLogInfo )
       
   273             { 
       
   274             return Send( ENoStyle, (TDesC&)aLogInfo );
       
   275             };
       
   276 
       
   277         /**
       
   278         * Log 8 bit _LIT information to some storage e.g. text file.
       
   279         */
       
   280         template<TInt S> TInt Log( const TLitC8<S>& aLogInfo )
       
   281             { 
       
   282             return Send( ENoStyle, (TDesC8&)aLogInfo );
       
   283             };
       
   284 
       
   285         /**
       
   286         * Log 16 bit _LIT information to some storage e.g. text file. There is
       
   287         * also parameter to styling text information e.g. text color.
       
   288         */
       
   289         template<TInt S> TInt Log( TInt aStyle, const TLitC<S>& aLogInfo )
       
   290             { 
       
   291             return Send( aStyle, (TDesC&)aLogInfo );
       
   292             };
       
   293 
       
   294         /**
       
   295         * Log 8 bit _LIT information to some storage e.g. text file.  There is
       
   296         * also parameter to styling text information e.g. text color.
       
   297         */
       
   298         template<TInt S> TInt Log( TInt aStyle, const TLitC8<S>& aLogInfo )
       
   299             { 
       
   300             return Send( aStyle, (TDesC8&)aLogInfo );
       
   301             };
       
   302 
       
   303      protected:
       
   304 
       
   305         IMPORT_C static CStifLogger* NewL( const TDesC& aTestPath,
       
   306                                             const TDesC& aTestFile,
       
   307                                             TLoggerSettings& aLoggerSettings );
       
   308 
       
   309     protected:
       
   310 
       
   311         /**
       
   312         * Deprecated
       
   313         */
       
   314         static void OverwriteLoggerSettings( TLoggerSettings& aLoggerSettings,
       
   315                                                 TName& aTestPath,
       
   316                                                 TName& aTestFile,
       
   317                                                 TLoggerType& aLoggerType,
       
   318                                                 TOutput& aOutput,
       
   319                                                 TBool& aOverWrite,
       
   320                                                 TBool& aWithTimeStamp,
       
   321                                                 TBool& aWithLineBreak,
       
   322                                                 TBool& aWithEventRanking,
       
   323                                                 TBool& aThreadIdToLogFile,
       
   324                                                 TBool& aCreateLogDir,
       
   325                                                 TBool& aUnicode );
       
   326 
       
   327     private:
       
   328         void ConstructL(const TDesC& aTestPath,
       
   329                 const TDesC& aTestFile,
       
   330                 TLoggerType aLoggerType,
       
   331                 TOutput aOutput,
       
   332                 TBool aOverWrite,
       
   333                 TBool aWithTimeStamp,
       
   334                 TBool aWithLineBreak,
       
   335                 TBool aWithEventRanking,
       
   336                 TBool aThreadIdToLogFile,
       
   337                 TBool aCreateLogDir,
       
   338                 TInt  aStaticBufferSize,
       
   339                 TBool aUnicode);
       
   340         
       
   341         void ConstructL(const TDesC& aTestPath,
       
   342                 const TDesC& aTestFile,
       
   343                 TLoggerSettings& aLoggerSettings);
       
   344 
       
   345     protected:  // Data
       
   346         RSTFLogger* iLogger;
       
   347     private:    // Friend classes
       
   348 
       
   349         // TestEngine classes
       
   350         friend class CTestEngineServer;
       
   351         friend class CTestReport;
       
   352         friend class CTestCaseController;
       
   353         friend class CTestEngine;
       
   354 
       
   355         // TestServer classes
       
   356         friend class CTestModuleContainer;
       
   357         friend class CTestServer;
       
   358         friend class CTestThreadContainer;
       
   359         friend class CTestThreadContainerRunner;
       
   360 
       
   361         // UIEngine classes
       
   362         friend class CUIEngine;
       
   363 
       
   364         // SettingServer classes
       
   365         friend class CSettingServer;
       
   366     };
       
   367 
       
   368 // Struct to indicate StifLogger's settings overwriting
       
   369 struct TOverwritedSettings
       
   370     {
       
   371     TBool               iCreateLogDir;
       
   372     TBool               iPath;
       
   373     TBool               iHwPath;
       
   374     TBool               iFormat;
       
   375     TBool               iHwFormat;
       
   376     TBool               iOutput;
       
   377     TBool               iHwOutput;
       
   378     TBool               iOverwrite;
       
   379     TBool               iTimeStamp;
       
   380     TBool               iLineBreak;
       
   381     TBool               iEventRanking;
       
   382     TBool               iThreadId;
       
   383     TBool               iUnicode;
       
   384     TBool               iAddTestCaseTitle;
       
   385     };
       
   386 
       
   387 // Struct to StifLogger overwrite settings
       
   388 struct TLoggerSettings
       
   389     {
       
   390     TBool                       iCreateLogDirectories;
       
   391     TName                       iEmulatorPath;
       
   392     CStifLogger::TLoggerType    iEmulatorFormat;
       
   393     CStifLogger::TOutput        iEmulatorOutput;
       
   394     TName                       iHardwarePath;
       
   395     CStifLogger::TLoggerType    iHardwareFormat;
       
   396     CStifLogger::TOutput        iHardwareOutput;
       
   397     TBool                       iOverwrite;
       
   398     TBool                       iTimeStamp;
       
   399     TBool                       iLineBreak;
       
   400     TBool                       iEventRanking;
       
   401     TBool                       iThreadId;
       
   402     TBool                       iUnicode;
       
   403     TBool                       iAddTestCaseTitle;
       
   404     TOverwritedSettings         iIsDefined;
       
   405     };
       
   406 
       
   407 #endif      // STIFLOGGER_H
       
   408 
       
   409 // End of File