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