dosservices/tsrc/dsytesttool/dsytfstifadapter/src/tfastiftestlog.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     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:  Implementation of CTFAStifTestLog class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "dsytesttooltrace.h"
       
    21 #include "tfastiftestlog.h"
       
    22 #include <stiflogger.h>
       
    23 
       
    24 #define __LOG_HTML__
       
    25 
       
    26 class TTFAOverflowHandler : public TDes16Overflow, public TDes8Overflow
       
    27     {
       
    28 public:
       
    29     void Overflow( TDes16& /*aDes*/ )
       
    30         {
       
    31         TRACE_ASSERT_ALWAYS;
       
    32         }
       
    33 
       
    34     void Overflow( TDes8& /*aDes*/ )
       
    35         {
       
    36         TRACE_ASSERT_ALWAYS;
       
    37         }
       
    38     };
       
    39     
       
    40     
       
    41 // -----------------------------------------------------------------------------
       
    42 // CTFAStifTestLog::NewLC
       
    43 // -----------------------------------------------------------------------------
       
    44 CTFAStifTestLog* CTFAStifTestLog::NewLC( void )
       
    45     {
       
    46     CTFAStifTestLog* log = new ( ELeave ) CTFAStifTestLog();
       
    47     CleanupStack::PushL( log );
       
    48     log->ConstructL();
       
    49     return log;
       
    50     }
       
    51     
       
    52     
       
    53 // -----------------------------------------------------------------------------
       
    54 // CTFAStifTestLog::CTFAStifTestLog
       
    55 // -----------------------------------------------------------------------------
       
    56 CTFAStifTestLog::CTFAStifTestLog( void )
       
    57     {
       
    58     }
       
    59     
       
    60     
       
    61 // -----------------------------------------------------------------------------
       
    62 // CTFAStifTestLog::ConstructL
       
    63 // -----------------------------------------------------------------------------
       
    64 void CTFAStifTestLog::ConstructL( void )
       
    65     {
       
    66     TFileName fileName;
       
    67     TTime time;
       
    68     time.HomeTime();
       
    69     TDateTime dateTime = time.DateTime();
       
    70     RThread thread;
       
    71 #ifdef __LOG_HTML__
       
    72     _LIT( KSuffix, "html" );
       
    73 #else
       
    74     _LIT( KSuffix, "txt" );
       
    75 #endif
       
    76     fileName.Format( _L( "%02d%02d%02d_%02d%02d%02d_%x.%S" ), 
       
    77         dateTime.Year() - 2000, dateTime.Month() + 1, dateTime.Day() + 1, 
       
    78         dateTime.Hour(), dateTime.Minute(), dateTime.Second(), 
       
    79         (TUint)thread.Id(), &KSuffix );
       
    80     iLogger = CStifLogger::NewL( _L( "c:\\logs\\testframework\\" ), fileName,
       
    81         CStifLogger::ETxt, CStifLogger::EFile, ETrue, EFalse, EFalse, EFalse, EFalse );
       
    82     iOverflowHandler = new ( ELeave ) TTFAOverflowHandler;
       
    83 #ifdef __LOG_HTML__
       
    84     iLogger->Log( _L8( "<html><head><title>TFA Log</title></head>\r\n<body>\r\n" ) );
       
    85 #endif
       
    86     }
       
    87     
       
    88     
       
    89 // -----------------------------------------------------------------------------
       
    90 // CTFAStifTestLog::~CTFAStifTestLog
       
    91 // -----------------------------------------------------------------------------
       
    92 CTFAStifTestLog::~CTFAStifTestLog( void )
       
    93     {
       
    94 #ifdef __LOG_HTML__
       
    95     if ( iLogger != NULL )
       
    96         {
       
    97         iLogger->Log( _L8( "\r\n</body></html>" ) );
       
    98         }
       
    99 #endif
       
   100     delete iLogger;
       
   101     delete iOverflowHandler;
       
   102     }
       
   103     
       
   104     
       
   105 // -----------------------------------------------------------------------------
       
   106 // CTFAStifTestLog::SetStyle
       
   107 // -----------------------------------------------------------------------------
       
   108 void CTFAStifTestLog::SetStyle( TTFLogStyle aStyle )
       
   109     {
       
   110 #ifdef __LOG_HTML__
       
   111     switch ( iStyle )
       
   112         {
       
   113         case ETFLogStyleBold:
       
   114             iLogger->Log( _L8( "</b>" ) );
       
   115             break;
       
   116         case ETFLogStyleItalic:
       
   117             iLogger->Log( _L8( "</i>" ) );
       
   118             break;
       
   119         case ETFLogStyleNormal:
       
   120         default:
       
   121             break;
       
   122         }
       
   123     iStyle = aStyle;
       
   124     switch ( iStyle )
       
   125         {
       
   126         case ETFLogStyleBold:
       
   127             iLogger->Log( _L8( "<b>" ) );
       
   128             break;
       
   129         case ETFLogStyleItalic:
       
   130             iLogger->Log( _L8( "<i>" ) );
       
   131             break;
       
   132         case ETFLogStyleNormal:
       
   133         default:
       
   134             break;
       
   135         }
       
   136 #endif
       
   137     }
       
   138     
       
   139     
       
   140 // -----------------------------------------------------------------------------
       
   141 // CTFAStifTestLog::SetColor
       
   142 // -----------------------------------------------------------------------------
       
   143 void CTFAStifTestLog::SetColor( TUint32 aColor )
       
   144     {
       
   145 #ifdef __LOG_HTML__
       
   146     if ( iColor != 0 )
       
   147         {
       
   148         iLogBuffer8.Format( _L8( "</font>" ) );
       
   149         }
       
   150     iColor = aColor;
       
   151     if ( iColor != 0 )
       
   152         {
       
   153         iLogBuffer8.Format( _L8( "<font color=\"0x%x\">" ), aColor );
       
   154         }
       
   155 #endif
       
   156     }
       
   157     
       
   158     
       
   159 // -----------------------------------------------------------------------------
       
   160 // CTFAStifTestLog::Write
       
   161 // -----------------------------------------------------------------------------
       
   162 void CTFAStifTestLog::Write( const TDesC& aDes )
       
   163     {
       
   164     iLogger->Log( aDes );
       
   165     }
       
   166     
       
   167     
       
   168 // -----------------------------------------------------------------------------
       
   169 // CTFAStifTestLog::Write
       
   170 // -----------------------------------------------------------------------------
       
   171 void CTFAStifTestLog::Write( const TDesC8& aDes )
       
   172     {
       
   173     iLogger->Log( aDes );
       
   174     }
       
   175     
       
   176     
       
   177 // -----------------------------------------------------------------------------
       
   178 // CTFAStifTestLog::Write
       
   179 // -----------------------------------------------------------------------------
       
   180 void CTFAStifTestLog::Write( TRefByValue<const TDesC> aDes, ... )
       
   181     {
       
   182     VA_LIST list;
       
   183     //lint -esym(960, 42) Comma operator used outside of 'for' expression
       
   184     VA_START( list, aDes );
       
   185     //lint +esym(960, 42)
       
   186     iLogBuffer.SetLength( 0 );
       
   187     iLogBuffer.AppendFormatList( aDes, list, iOverflowHandler );
       
   188     iLogger->Log( iLogBuffer );
       
   189     }
       
   190     
       
   191     
       
   192 // -----------------------------------------------------------------------------
       
   193 // CTFAStifTestLog::Write
       
   194 // -----------------------------------------------------------------------------
       
   195 void CTFAStifTestLog::Write( TRefByValue<const TDesC8> aDes, ... )
       
   196     {
       
   197     VA_LIST list;
       
   198     //lint -esym(960, 42) Comma operator used outside of 'for' expression
       
   199     VA_START( list, aDes );
       
   200     //lint +esym(960, 42)
       
   201     iLogBuffer8.SetLength( 0 );
       
   202     iLogBuffer8.AppendFormatList( aDes, list, iOverflowHandler );
       
   203     iLogger->Log( iLogBuffer8 );
       
   204     }
       
   205     
       
   206     
       
   207 // -----------------------------------------------------------------------------
       
   208 // CTFAStifTestLog::WriteBlock
       
   209 // -----------------------------------------------------------------------------
       
   210 void CTFAStifTestLog::WriteBlock( const TDesC& aDes )
       
   211     {
       
   212 #ifdef __LOG_HTML__
       
   213     iLogger->Log( _L8( "<pre><blockquote>" ) );
       
   214     iLogger->Log( aDes );
       
   215     iLogger->Log( _L8( "</blockquote></pre>" ) );
       
   216 #else
       
   217     iLogger->Log( aDes );
       
   218     iLogger->Log( _L8( "\r\n" ) );
       
   219 #endif
       
   220     }
       
   221     
       
   222     
       
   223 // -----------------------------------------------------------------------------
       
   224 // CTFAStifTestLog::WriteBlock
       
   225 // -----------------------------------------------------------------------------
       
   226 void CTFAStifTestLog::WriteBlock( const TDesC8& aDes )
       
   227     {
       
   228 #ifdef __LOG_HTML__
       
   229     iLogger->Log( _L8( "<pre><blockquote>" ) );
       
   230     iLogger->Log( aDes );
       
   231     iLogger->Log( _L8( "</blockquote></pre>" ) );
       
   232 #else
       
   233     iLogger->Log( aDes );
       
   234     iLogger->Log( _L8( "\r\n" ) );
       
   235 #endif
       
   236     }
       
   237     
       
   238     
       
   239 // -----------------------------------------------------------------------------
       
   240 // CTFAStifTestLog::EndLine
       
   241 // -----------------------------------------------------------------------------
       
   242 void CTFAStifTestLog::EndLine( void )
       
   243     {
       
   244 #ifdef __LOG_HTML__
       
   245     iLogger->Log( _L8( "<br>\r\n" ) );
       
   246 #else
       
   247     iLogger->Log( _L8( "\r\n" ) );
       
   248 #endif
       
   249     }
       
   250     
       
   251     
       
   252 // -----------------------------------------------------------------------------
       
   253 // CTFAStifTestLog::StartChapter
       
   254 // -----------------------------------------------------------------------------
       
   255 void CTFAStifTestLog::StartChapter( void )
       
   256     {
       
   257 #ifdef __LOG_HTML__
       
   258     iLogger->Log( _L8( "<p>" ) );
       
   259 #else
       
   260     iLogger->Log( _L8( "\r\n\r\n" ) );
       
   261 #endif
       
   262     }
       
   263     
       
   264     
       
   265 // -----------------------------------------------------------------------------
       
   266 // CTFAStifTestLog::StartList
       
   267 // -----------------------------------------------------------------------------
       
   268 void CTFAStifTestLog::StartList( void )
       
   269     {
       
   270     iCurrentDepth = 0;
       
   271 #ifdef __LOG_HTML__
       
   272     iLogger->Log( _L8( "<ul>" ) );
       
   273 #endif
       
   274     }
       
   275     
       
   276     
       
   277 // -----------------------------------------------------------------------------
       
   278 // CTFAStifTestLog::WriteListEntryStart
       
   279 // -----------------------------------------------------------------------------
       
   280 void CTFAStifTestLog::WriteListEntryStart( TInt aDepth )
       
   281     {
       
   282 #ifdef __LOG_HTML__
       
   283     if ( iCurrentDepth > aDepth )
       
   284         {
       
   285         while ( iCurrentDepth > aDepth )
       
   286             {
       
   287             iLogger->Log( _L8( "</ul>\r\n" ) );
       
   288             iCurrentDepth--;
       
   289             }
       
   290         }
       
   291     else if ( iCurrentDepth < aDepth )
       
   292         {
       
   293         while ( iCurrentDepth < aDepth )
       
   294             {
       
   295             iLogger->Log( _L8( "<ul>" ) );
       
   296             iCurrentDepth++;
       
   297             }
       
   298         }
       
   299     else
       
   300         {
       
   301         }
       
   302 #else
       
   303     if ( aDepth > iCurrentDepth )
       
   304         {
       
   305         iLogger->Log( _L8( ":\r\n" ) );
       
   306         }
       
   307     else
       
   308         {
       
   309         iLogger->Log( _L8( "\r\n" ) );
       
   310         }
       
   311     for ( TInt i = 0; i <= aDepth; i++ )
       
   312         {
       
   313         iLogger->Log( _L8( "  " ) );
       
   314         }
       
   315     iLogger->Log( _L8( "- " ) );
       
   316     iCurrentDepth = aDepth;
       
   317 #endif
       
   318     }
       
   319     
       
   320     
       
   321 // -----------------------------------------------------------------------------
       
   322 // CTFAStifTestLog::WriteList
       
   323 // -----------------------------------------------------------------------------
       
   324 void CTFAStifTestLog::WriteList( TInt aDepth, TRefByValue<const TDesC> aDes, ... )
       
   325     {
       
   326     WriteListEntryStart( aDepth );
       
   327     VA_LIST list;
       
   328     //lint -esym(960, 42) Comma operator used outside of 'for' expression
       
   329     VA_START( list, aDes );
       
   330     //lint +esym(960, 42)
       
   331 #ifdef __LOG_HTML__
       
   332     iLogBuffer.Copy( _L( "<li>" ) );
       
   333 #else
       
   334     iLogBuffer.SetLength( 0 );
       
   335 #endif
       
   336     iLogBuffer.AppendFormatList( aDes, list, iOverflowHandler );
       
   337     iLogger->Log( iLogBuffer );
       
   338 #ifdef __LOG_HTML__
       
   339     iLogger->Log( _L8( "</li>\r\n" ) );
       
   340 #endif
       
   341     }
       
   342     
       
   343     
       
   344 // -----------------------------------------------------------------------------
       
   345 // CTFAStifTestLog::WriteList
       
   346 // -----------------------------------------------------------------------------
       
   347 void CTFAStifTestLog::WriteList( TInt aDepth, TRefByValue<const TDesC8> aDes, ... )
       
   348     {
       
   349     WriteListEntryStart( aDepth );
       
   350     VA_LIST list;
       
   351     //lint -esym(960, 42) Comma operator used outside of 'for' expression
       
   352     VA_START( list, aDes );
       
   353     //lint +esym(960, 42)
       
   354 #ifdef __LOG_HTML__
       
   355     iLogBuffer8.Copy( _L8( "<li>" ) );
       
   356 #else
       
   357     iLogBuffer8.SetLength( 0 );
       
   358 #endif
       
   359     iLogBuffer8.AppendFormatList( aDes, list, iOverflowHandler );
       
   360     iLogger->Log( iLogBuffer8 );
       
   361 #ifdef __LOG_HTML__
       
   362     iLogger->Log( _L8( "</li>\r\n" ) );
       
   363 #endif
       
   364     }
       
   365     
       
   366     
       
   367 // -----------------------------------------------------------------------------
       
   368 // CTFAStifTestLog::EndList
       
   369 // -----------------------------------------------------------------------------
       
   370 void CTFAStifTestLog::EndList( void )
       
   371     {
       
   372 #ifdef __LOG_HTML__
       
   373     while ( iCurrentDepth >= 0 )
       
   374         {
       
   375         iLogger->Log( _L8( "</ul>\r\n" ) );
       
   376         iCurrentDepth--;
       
   377         }
       
   378 #else
       
   379     iLogger->Log( _L8( "\r\n" ) );
       
   380 #endif
       
   381     }
       
   382