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