symbianunittestfw/sutfw/sutfwcore/sutfwoutput/src/symbianunittestoutputasxml.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 "symbianunittestoutputasxml.h"
       
    22 
       
    23 
       
    24 _LIT8( KXmlResultOpenTag, "<SYMBIANUNITTEST_RESULT testcount=\"%d\">\r\n" );
       
    25 _LIT8( KXmlResultCloseTag, "</SYMBIANUNITTEST_RESULT>\r\n" );
       
    26 _LIT8( KXmlPassedTestsOpenTag, "\t<SYMBIANUNITTEST_PASSED count=\"%d\">\r\n" );
       
    27 _LIT8( KXmlPassedTestsCloseTag, "\t</SYMBIANUNITTEST_PASSED>\r\n" );
       
    28 _LIT8( KXmlFailedTestsOpenTag, "\t<SYMBIANUNITTEST_FAILED count=\"%d\">\r\n" );
       
    29 _LIT8( KXmlFailedTestsCloseTag, "\t</SYMBIANUNITTEST_FAILED>\r\n" );
       
    30 _LIT8( KXmlFailureOpenTag, "\t\t<SYMBIANUNITTEST_FAILURE>\r\n" );
       
    31 _LIT8( KXmlFailureCloseTag, "\t\t</SYMBIANUNITTEST_FAILURE>\r\n" );
       
    32 _LIT8( KXmlTestNameOpenTag, "\t\t\t<SYMBIANUNITTEST_NAME>\r\n" );
       
    33 _LIT8( KXmlTestNameCloseTag, "\r\n\t\t\t</SYMBIANUNITTEST_NAME>\r\n" );
       
    34 _LIT8( KXmlFileNameOpenTag, "\t\t\t<SYMBIANUNITTEST_FILE>\r\n" );
       
    35 _LIT8( KXmlFileNameCloseTag, "\r\n\t\t\t</SYMBIANUNITTEST_FILE>\r\n" );
       
    36 _LIT8( KXmlLineNumberOpenTag, "\t\t\t<SYMBIANUNITTEST_LINE>%d\r\n" );
       
    37 _LIT8( KXmlLineNumberCloseTag, "\r\n\t\t\t</SYMBIANUNITTEST_LINE>\r\n" );
       
    38 _LIT8( KXmlReasonOpenTag, "\t\t\t<SYMBIANUNITTEST_REASON>\r\n" );
       
    39 _LIT8( KXmlReasonCloseTag, "\r\n\t\t\t</SYMBIANUNITTEST_REASON>\r\n" );
       
    40 
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 CSymbianUnitTestOutputAsXml* CSymbianUnitTestOutputAsXml::NewL(
       
    47     const TDesC& aFileName )
       
    48     {
       
    49     CSymbianUnitTestOutputAsXml* self = 
       
    50         new( ELeave )CSymbianUnitTestOutputAsXml;
       
    51     CleanupStack::PushL( self );
       
    52     self->ConstructL( aFileName );
       
    53     CleanupStack::Pop( self );
       
    54     return self;
       
    55     }
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 CSymbianUnitTestOutputAsXml::CSymbianUnitTestOutputAsXml()
       
    62     {
       
    63     }
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 CSymbianUnitTestOutputAsXml::~CSymbianUnitTestOutputAsXml()
       
    70     {
       
    71     }
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // From CSymbianUnitTestOutputFormatter
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 const TDesC& CSymbianUnitTestOutputAsXml::FileExtension() const
       
    78     {
       
    79     return KXmlOutput;
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // From CSymbianUnitTestOutputFormatter
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 void CSymbianUnitTestOutputAsXml::PrintHeaderL( 
       
    87     CSymbianUnitTestResult& aResult )
       
    88     {
       
    89     iOutputWriter->WriteL( KXmlResultOpenTag, aResult.TestCount() );
       
    90     }
       
    91 
       
    92 // -----------------------------------------------------------------------------
       
    93 // From CSymbianUnitTestOutputFormatter
       
    94 // -----------------------------------------------------------------------------
       
    95 //
       
    96 void CSymbianUnitTestOutputAsXml::PrintPassedTestsL( 
       
    97     CSymbianUnitTestResult& aResult ) 
       
    98     {
       
    99     iOutputWriter->WriteL( KXmlPassedTestsOpenTag, aResult.PassedTestCount() );
       
   100     const CDesCArray& testCaseNames = aResult.TestCaseNames();
       
   101     for ( TInt i=0; i < testCaseNames.Count(); i++ )
       
   102         {
       
   103         iOutputWriter->WriteL( KXmlTestNameOpenTag );
       
   104         iOutputWriter->WriteL( testCaseNames[i]);
       
   105         iOutputWriter->WriteL( KXmlTestNameCloseTag );
       
   106         }
       
   107     iOutputWriter->WriteL( KXmlPassedTestsCloseTag );
       
   108     }
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // From CSymbianUnitTestOutputFormatter
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 void CSymbianUnitTestOutputAsXml::PrintFailedTestsL( 
       
   115     CSymbianUnitTestResult& aResult ) 
       
   116     {
       
   117     iOutputWriter->WriteL( KXmlFailedTestsOpenTag, aResult.Failures().Count() );
       
   118     for ( TInt i=0; i < aResult.Failures().Count(); i++ )
       
   119         {
       
   120         iOutputWriter->WriteL( KXmlFailureOpenTag );
       
   121         PrintFailureDetailsL( *( aResult.Failures()[ i ] ) );
       
   122         iOutputWriter->WriteL( KXmlFailureCloseTag );
       
   123         }
       
   124     iOutputWriter->WriteL( KXmlFailedTestsCloseTag );
       
   125     }
       
   126 
       
   127 // -----------------------------------------------------------------------------
       
   128 // From CSymbianUnitTestOutputFormatter
       
   129 // -----------------------------------------------------------------------------
       
   130 //
       
   131 void CSymbianUnitTestOutputAsXml::PrintFooterL()
       
   132     {
       
   133     iOutputWriter->WriteL( KXmlResultCloseTag );
       
   134     }
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 // -----------------------------------------------------------------------------
       
   139 //
       
   140 void CSymbianUnitTestOutputAsXml::PrintFailureDetailsL( 
       
   141     CSymbianUnitTestFailure& aTestFailure )
       
   142     {
       
   143     iOutputWriter->WriteL( KXmlTestNameOpenTag );
       
   144     iOutputWriter->WriteL( aTestFailure.TestName() );
       
   145     iOutputWriter->WriteL( KXmlTestNameCloseTag );
       
   146     if ( aTestFailure.FileName().Length() > 0 )
       
   147         {
       
   148         iOutputWriter->WriteL( KXmlFileNameOpenTag );
       
   149         iOutputWriter->WriteL( aTestFailure.FileName() );
       
   150         iOutputWriter->WriteL( KXmlFileNameCloseTag );
       
   151         }
       
   152     TInt lineNumber( aTestFailure.LineNumber() );
       
   153     if ( lineNumber >= 0 )
       
   154         {
       
   155         iOutputWriter->WriteL( KXmlLineNumberOpenTag, lineNumber );
       
   156         iOutputWriter->WriteL( KXmlLineNumberCloseTag );
       
   157         }
       
   158     iOutputWriter->WriteL( KXmlReasonOpenTag );
       
   159     iOutputWriter->WriteL( aTestFailure.FailureMessage() );
       
   160     iOutputWriter->WriteL( KXmlReasonCloseTag );
       
   161     }