Show
Ignore:
Timestamp:
08/05/09 14:40:03 (15 years ago)
Author:
mido
Message:

panove, vite, jak jsem peclivej na upravu kodu.. snad se vam bude libit:) konfigurace je v souboru /system/astylerc

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • library/tests/unittest-cpp/XmlTestReporter.cpp

    r418 r477  
    1212namespace { 
    1313 
    14 void ReplaceChar(string& str, char c, string const& replacement) 
    15 { 
    16     for (size_t pos = str.find(c); pos != string::npos; pos = str.find(c, pos + 1)) 
    17         str.replace(pos, 1, replacement); 
     14void ReplaceChar ( string& str, char c, string const& replacement ) { 
     15        for ( size_t pos = str.find ( c ); pos != string::npos; pos = str.find ( c, pos + 1 ) ) 
     16                str.replace ( pos, 1, replacement ); 
    1817} 
    1918 
    20 string XmlEscape(string const& value) 
    21 { 
    22     string escaped = value; 
     19string XmlEscape ( string const& value ) { 
     20        string escaped = value; 
    2321 
    24     ReplaceChar(escaped, '&', "&"); 
    25     ReplaceChar(escaped, '<', "&lt;"); 
    26     ReplaceChar(escaped, '>', "&gt;"); 
    27     ReplaceChar(escaped, '\'', "&apos;"); 
    28     ReplaceChar(escaped, '\"', "&quot;"); 
    29   
    30     return escaped; 
     22        ReplaceChar ( escaped, '&', "&amp;" ); 
     23        ReplaceChar ( escaped, '<', "&lt;" ); 
     24        ReplaceChar ( escaped, '>', "&gt;" ); 
     25        ReplaceChar ( escaped, '\'', "&apos;" ); 
     26        ReplaceChar ( escaped, '\"', "&quot;" ); 
     27 
     28        return escaped; 
    3129} 
    3230 
    33 string BuildFailureMessage(string const& file, int line, string const& message) 
    34 { 
    35     ostringstream failureMessage; 
    36     failureMessage << file << "(" << line << ") : " << message; 
    37     return failureMessage.str(); 
     31string BuildFailureMessage ( string const& file, int line, string const& message ) { 
     32        ostringstream failureMessage; 
     33        failureMessage << file << "(" << line << ") : " << message; 
     34        return failureMessage.str(); 
    3835} 
    3936 
     
    4239namespace UnitTest { 
    4340 
    44 XmlTestReporter::XmlTestReporter(ostream& ostream) 
    45     : m_ostream(ostream) 
    46 { 
     41XmlTestReporter::XmlTestReporter ( ostream& ostream ) 
     42                : m_ostream ( ostream ) { 
    4743} 
    4844 
    49 void XmlTestReporter::ReportSummary(int totalTestCount, int failedTestCount, 
    50                                     int failureCount, float secondsElapsed) 
    51 { 
    52     AddXmlElement(m_ostream, NULL); 
     45void XmlTestReporter::ReportSummary ( int totalTestCount, int failedTestCount, 
     46                                      int failureCount, float secondsElapsed ) { 
     47        AddXmlElement ( m_ostream, NULL ); 
    5348 
    54     BeginResults(m_ostream, totalTestCount, failedTestCount, failureCount, secondsElapsed); 
     49        BeginResults ( m_ostream, totalTestCount, failedTestCount, failureCount, secondsElapsed ); 
    5550 
    56     DeferredTestResultList const& results = GetResults(); 
    57     for (DeferredTestResultList::const_iterator i = results.begin(); i != results.end(); ++i) 
    58     { 
    59         BeginTest(m_ostream, *i); 
     51        DeferredTestResultList const& results = GetResults(); 
     52        for ( DeferredTestResultList::const_iterator i = results.begin(); i != results.end(); ++i ) { 
     53                BeginTest ( m_ostream, *i ); 
    6054 
    61         if (i->failed) 
    62             AddFailure(m_ostream, *i); 
     55                if ( i->failed ) 
     56                        AddFailure ( m_ostream, *i ); 
    6357 
    64         EndTest(m_ostream, *i); 
    65     } 
     58                EndTest ( m_ostream, *i ); 
     59        } 
    6660 
    67     EndResults(m_ostream); 
     61        EndResults ( m_ostream ); 
    6862} 
    6963 
    70 void XmlTestReporter::AddXmlElement(ostream& os, char const* encoding) 
    71 { 
    72     os << "<?xml version=\"1.0\""; 
     64void XmlTestReporter::AddXmlElement ( ostream& os, char const* encoding ) { 
     65        os << "<?xml version=\"1.0\""; 
    7366 
    74     if (encoding != NULL) 
    75         os << " encoding=\"" << encoding << "\""; 
     67        if ( encoding != NULL ) 
     68                os << " encoding=\"" << encoding << "\""; 
    7669 
    77     os << "?>"; 
     70        os << "?>"; 
    7871} 
    7972 
    80 void XmlTestReporter::BeginResults(std::ostream& os, int totalTestCount, int failedTestCount,  
    81                                    int failureCount, float secondsElapsed) 
    82 { 
    83    os << "<unittest-results" 
    84        << " tests=\"" << totalTestCount << "\""  
    85        << " failedtests=\"" << failedTestCount << "\""  
    86        << " failures=\"" << failureCount << "\""  
    87        << " time=\"" << secondsElapsed << "\"" 
    88        << ">"; 
     73void XmlTestReporter::BeginResults ( std::ostream& os, int totalTestCount, int failedTestCount, 
     74                                     int failureCount, float secondsElapsed ) { 
     75        os << "<unittest-results" 
     76        << " tests=\"" << totalTestCount << "\"" 
     77        << " failedtests=\"" << failedTestCount << "\"" 
     78        << " failures=\"" << failureCount << "\"" 
     79        << " time=\"" << secondsElapsed << "\"" 
     80        << ">"; 
    8981} 
    9082 
    91 void XmlTestReporter::EndResults(std::ostream& os) 
    92 { 
    93     os << "</unittest-results>"; 
     83void XmlTestReporter::EndResults ( std::ostream& os ) { 
     84        os << "</unittest-results>"; 
    9485} 
    9586 
    96 void XmlTestReporter::BeginTest(std::ostream& os, DeferredTestResult const& result) 
    97 { 
    98     os << "<test" 
    99         << " suite=\"" << result.suiteName << "\""  
    100         << " name=\"" << result.testName << "\"" 
    101         << " time=\"" << result.timeElapsed << "\""; 
     87void XmlTestReporter::BeginTest ( std::ostream& os, DeferredTestResult const& result ) { 
     88        os << "<test" 
     89        << " suite=\"" << result.suiteName << "\"" 
     90        << " name=\"" << result.testName << "\"" 
     91        << " time=\"" << result.timeElapsed << "\""; 
    10292} 
    10393 
    104 void XmlTestReporter::EndTest(std::ostream& os, DeferredTestResult const& result) 
    105 { 
    106     if (result.failed) 
    107         os << "</test>"; 
    108     else 
    109         os << "/>"; 
     94void XmlTestReporter::EndTest ( std::ostream& os, DeferredTestResult const& result ) { 
     95        if ( result.failed ) 
     96                os << "</test>"; 
     97        else 
     98                os << "/>"; 
    11099} 
    111100 
    112 void XmlTestReporter::AddFailure(std::ostream& os, DeferredTestResult const& result) 
    113 { 
    114     os << ">"; // close <test> element 
     101void XmlTestReporter::AddFailure ( std::ostream& os, DeferredTestResult const& result ) { 
     102        os << ">"; // close <test> element 
    115103 
    116     for (DeferredTestResult::FailureVec::const_iterator it = result.failures.begin();  
    117          it != result.failures.end();  
    118          ++it) 
    119     { 
    120         string const escapedMessage = XmlEscape(it->second); 
    121         string const message = BuildFailureMessage(result.failureFile, it->first, escapedMessage); 
     104        for ( DeferredTestResult::FailureVec::const_iterator it = result.failures.begin(); 
     105                it != result.failures.end(); 
     106                ++it ) { 
     107                string const escapedMessage = XmlEscape ( it->second ); 
     108                string const message = BuildFailureMessage ( result.failureFile, it->first, escapedMessage ); 
    122109 
    123         os << "<failure" << " message=\"" << message << "\"" << "/>"; 
    124     } 
     110                os << "<failure" << " message=\"" << message << "\"" << "/>"; 
     111        } 
    125112} 
    126113