testexecfw/symbianunittestfw/sutfw/sutfwcore/sutfwoutput/src/symbianunittestoutputashtml.cpp
changeset 0 3e07fef1e154
child 1 bbd31066657e
equal deleted inserted replaced
-1:000000000000 0:3e07fef1e154
       
     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:  
       
    15 *
       
    16 */
       
    17 
       
    18 #include "symbianunittestresult.h"
       
    19 #include "symbianunittestfailure.h"
       
    20 #include "symbianunittestfileoutputwriter.h"
       
    21 #include "symbianunittestoutputashtml.h"
       
    22 
       
    23 // CONSTANTS
       
    24 _LIT8( KHtmlHeader, "<html><head><title>Unit test results</title></head>\n" );
       
    25 _LIT8( KHtmlFooter, "</html>\n" );
       
    26 _LIT8( KHtmlBodyStartTag, "<body bgcolor=\"#DDDDDD\" text=\"black\">\n" );
       
    27 _LIT8( KHtmlBodyEndTag, "</body>\n");
       
    28 _LIT8( KHtmlMainHeaderStartTag, "<h2> %d unit tests executed " );
       
    29 _LIT8( KHtmlMainHeaderEndTag, "</h2>\n" );
       
    30 _LIT8( KHtmlPassedTests, 
       
    31        "<h3><font color=\"green\">Passed tests: %d</b></font></h3>\n" );
       
    32 _LIT8( KHtmlFailedTests, 
       
    33        "<h3><font color=\"red\">Failed tests: %d</font></h3>\n" );
       
    34 _LIT8( KHtmlParagraphBreak, "<p></p>\n" );
       
    35 _LIT8( KHtmlTableStartTag, "<table border=\"0\">\n" );
       
    36 _LIT8( KHtmlTableEndTag, "</table>\n" );
       
    37 _LIT8( KHtmlTRStartTag, "<tr>\n" );
       
    38 _LIT8( KHtmlTREndTag, "</tr>\n" );
       
    39 _LIT8( KHtmlTitleColumnStart, "<td width=\"100\" bgcolor=\"#888888\"><b>" );
       
    40 _LIT8( KHtmlTitleColumnEnd,   "</b></td>\n" );
       
    41 _LIT8( KHtmlTestNameTitle,   "Test name" );
       
    42 _LIT8( KHtmlFileNameTitle,   "File name" );
       
    43 _LIT8( KHtmlLineNumberTitle, "Line number" );
       
    44 _LIT8( KHtmlReasonTitle,     "Reason" );
       
    45 _LIT8( KHtmlValueColumnStart, "<td bgcolor=\"#BBBBBB\">" );
       
    46 _LIT8( KHtmlValueColumnEnd,   "</td>\n" );
       
    47 
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 //
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 CSymbianUnitTestOutputAsHtml* CSymbianUnitTestOutputAsHtml::NewL(
       
    54     const TDesC& aFileName )
       
    55     {
       
    56     CSymbianUnitTestOutputAsHtml* self = 
       
    57         new( ELeave )CSymbianUnitTestOutputAsHtml;
       
    58     CleanupStack::PushL( self );
       
    59     self->ConstructL( aFileName );
       
    60     CleanupStack::Pop( self );
       
    61     return self;
       
    62     }
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 CSymbianUnitTestOutputAsHtml::CSymbianUnitTestOutputAsHtml()
       
    69     {
       
    70     }
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 // -----------------------------------------------------------------------------
       
    75 //
       
    76 CSymbianUnitTestOutputAsHtml::~CSymbianUnitTestOutputAsHtml()
       
    77     {
       
    78     }
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // From CSymbianUnitTestOutputFormatter
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 const TDesC& CSymbianUnitTestOutputAsHtml::FileExtension() const
       
    85     {
       
    86     return KHtmlOutput;
       
    87     }
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // From CSymbianUnitTestOutputFormatter
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 void CSymbianUnitTestOutputAsHtml::PrintHeaderL( 
       
    94     CSymbianUnitTestResult& aResult )
       
    95     {
       
    96     iOutputWriter->WriteL( KHtmlHeader );
       
    97     iOutputWriter->WriteL( KHtmlBodyStartTag );
       
    98     iOutputWriter->WriteL( KHtmlMainHeaderStartTag, aResult.TestCount() );
       
    99     iOutputWriter->WriteDateAndTimeL();
       
   100     iOutputWriter->WriteL( KHtmlMainHeaderEndTag );
       
   101     }
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 // From CSymbianUnitTestOutputFormatter
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 void CSymbianUnitTestOutputAsHtml::PrintPassedTestsL( 
       
   108     CSymbianUnitTestResult& aResult ) 
       
   109     {
       
   110     iOutputWriter->WriteL( KHtmlPassedTests, aResult.PassedTestCount() );
       
   111     }
       
   112 
       
   113 // -----------------------------------------------------------------------------
       
   114 // From CSymbianUnitTestOutputFormatter
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 void CSymbianUnitTestOutputAsHtml::PrintFailedTestsL( 
       
   118     CSymbianUnitTestResult& aResult ) 
       
   119     {
       
   120     iOutputWriter->WriteL( KHtmlFailedTests, aResult.Failures().Count() );
       
   121     for ( TInt i=0; i < aResult.Failures().Count(); i++ )
       
   122         {
       
   123         CSymbianUnitTestFailure* failure = aResult.Failures()[ i ];
       
   124         iOutputWriter->WriteL( KHtmlTableStartTag );
       
   125         PrintTableRowL( KHtmlTestNameTitle, failure->TestName() );
       
   126         PrintTableRowL( KHtmlReasonTitle, failure->FailureMessage() );        
       
   127         if ( failure->LineNumber() >= 0 )
       
   128             {
       
   129             TBuf8< 20 > value;
       
   130             value.AppendNum( failure->LineNumber() );
       
   131             PrintTableRowL( KHtmlLineNumberTitle, value );
       
   132             }
       
   133         if ( failure->FileName().Length() > 0 )
       
   134             {
       
   135             PrintTableRowL( KHtmlFileNameTitle, failure->FileName() );
       
   136             }
       
   137         iOutputWriter->WriteL( KHtmlTableEndTag );
       
   138         iOutputWriter->WriteL( KHtmlParagraphBreak );
       
   139         }
       
   140     }
       
   141 
       
   142 // -----------------------------------------------------------------------------
       
   143 // From CSymbianUnitTestOutputFormatter
       
   144 // -----------------------------------------------------------------------------
       
   145 //
       
   146 void CSymbianUnitTestOutputAsHtml::PrintFooterL()
       
   147     {
       
   148     iOutputWriter->WriteL( KHtmlBodyEndTag );
       
   149     iOutputWriter->WriteL( KHtmlFooter );
       
   150     }
       
   151 
       
   152 // -----------------------------------------------------------------------------
       
   153 //
       
   154 // -----------------------------------------------------------------------------
       
   155 //
       
   156 void CSymbianUnitTestOutputAsHtml::PrintTableRowL(
       
   157     const TDesC8& aTitle, 
       
   158     const TDesC8& aValue )
       
   159     {
       
   160     iOutputWriter->WriteL( KHtmlTRStartTag );
       
   161     iOutputWriter->WriteL( KHtmlTitleColumnStart );
       
   162     iOutputWriter->WriteL( aTitle );
       
   163     iOutputWriter->WriteL( KHtmlTitleColumnEnd );
       
   164     iOutputWriter->WriteL( KHtmlValueColumnStart );
       
   165     iOutputWriter->WriteL( aValue );
       
   166     iOutputWriter->WriteL( KHtmlValueColumnEnd );
       
   167     iOutputWriter->WriteL( KHtmlTREndTag );
       
   168     }