[Libreoffice-commits] core.git: 2 commits - sal/cppunittester sal/qa

Tor Lillqvist tml at collabora.com
Thu Apr 24 00:44:38 PDT 2014


 sal/cppunittester/cppunittester.cxx |   41 +++++++++++++++++++++++++++++++++++-
 sal/qa/rtl/textenc/rtl_textcvt.cxx  |   14 ++++++------
 2 files changed, 47 insertions(+), 8 deletions(-)

New commits:
commit ca54d372453fbbea136592bbab2e64d44af46373
Author: Tor Lillqvist <tml at collabora.com>
Date:   Thu Apr 24 10:32:38 2014 +0300

    Add a test listener that outputs failures to stderr as they happen
    
    Makes them intermix properly with debugging output from the tested
    functionality.
    
    After the test has run, don't repeat the failure messages, just print a short
    summary.
    
    Change-Id: I6b491d3a34094df2da11df5e404adb63299de342

diff --git a/sal/cppunittester/cppunittester.cxx b/sal/cppunittester/cppunittester.cxx
index 68858fe..0888d1b 100644
--- a/sal/cppunittester/cppunittester.cxx
+++ b/sal/cppunittester/cppunittester.cxx
@@ -37,6 +37,8 @@
 #include "sal/main.h"
 
 #include "cppunit/CompilerOutputter.h"
+#include "cppunit/Exception.h"
+#include "cppunit/TestFailure.h"
 #include "cppunit/TestResult.h"
 #include "cppunit/TestResultCollector.h"
 #include "cppunit/TestRunner.h"
@@ -130,6 +132,37 @@ public:
 };
 #endif
 
+class LogFailuresAsTheyHappen : public CppUnit::TestListener
+{
+public:
+    virtual void addFailure( const CppUnit::TestFailure &failure ) SAL_OVERRIDE
+    {
+        printFailureLocation( failure.sourceLine() );
+        printFailedTestName( failure );
+        printFailureMessage( failure );
+    }
+
+private:
+    void printFailureLocation( const CppUnit::SourceLine &sourceLine )
+    {
+        if ( !sourceLine.isValid() )
+            std::cerr << "unknown:0:";
+        else
+            std::cerr << sourceLine.fileName() << ":" << sourceLine.lineNumber() << ":";
+    }
+
+    void printFailedTestName( const CppUnit::TestFailure &failure )
+    {
+        std::cerr << failure.failedTestName() << std::endl;
+    }
+
+    void printFailureMessage( const CppUnit::TestFailure &failure )
+    {
+        std::cerr << failure.thrownException()->message().shortDescription() << std::endl;
+        std::cerr << failure.thrownException()->message().details() << std::endl;
+    }
+};
+
 //Allow the whole uniting testing framework to be run inside a "Protector"
 //which knows about uno exceptions, so it can print the content of the
 //exception before falling over and dying
@@ -182,6 +215,9 @@ public:
         CppUnit::TestResultCollector collector;
         result.addListener(&collector);
 
+        LogFailuresAsTheyHappen logger;
+        result.addListener(&logger);
+
 #ifdef TIMETESTS
         TimingListener timer;
         result.addListener(&timer);
@@ -199,7 +235,10 @@ public:
         for (size_t i = 0; i < protectors.size(); ++i)
             result.popProtector();
 
-        CppUnit::CompilerOutputter(&collector, CppUnit::stdCErr()).write();
+        if (collector.wasSuccessful())
+            CppUnit::CompilerOutputter(&collector, CppUnit::stdCErr()).printSuccess();
+        else
+            CppUnit::CompilerOutputter(&collector, CppUnit::stdCErr()).printStatistics();
         return collector.wasSuccessful();
     }
     virtual bool operator()() const SAL_OVERRIDE
commit 70c773d30c1c84da24de4c2c3ddc936575996662
Author: Tor Lillqvist <tml at collabora.com>
Date:   Thu Apr 24 10:27:30 2014 +0300

    Add missing right paren in assertion log messages
    
    Change-Id: Ia6f3f0f74b6de127d8989935e10c15a6cf52e5d7

diff --git a/sal/qa/rtl/textenc/rtl_textcvt.cxx b/sal/qa/rtl/textenc/rtl_textcvt.cxx
index bd90bb7..fda1f9a 100644
--- a/sal/qa/rtl/textenc/rtl_textcvt.cxx
+++ b/sal/qa/rtl/textenc/rtl_textcvt.cxx
@@ -54,7 +54,7 @@ void testSingleByteCharSet(SingleByteCharSet const & rSet) {
     {
         rtl_TextToUnicodeConverter aConverter
             = rtl_createTextToUnicodeConverter(rSet.m_nEncoding);
-        CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("rtl_createTextToUnicodeConverter(" + OUString::createFromAscii(rtl_getMimeCharsetFromTextEncoding(rSet.m_nEncoding)) + " failed"),
+        CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("rtl_createTextToUnicodeConverter(" + OUString::createFromAscii(rtl_getMimeCharsetFromTextEncoding(rSet.m_nEncoding)) + ") failed"),
                                                  RTL_TEXTENCODING_UTF8).getStr(),
                                aConverter != NULL);
         rtl_TextToUnicodeContext aContext
@@ -100,7 +100,7 @@ void testSingleByteCharSet(SingleByteCharSet const & rSet) {
     {
         rtl_UnicodeToTextConverter aConverter
             = rtl_createUnicodeToTextConverter(rSet.m_nEncoding);
-        CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("rtl_createTextToUnicodeConverter(" + OUString::createFromAscii(rtl_getMimeCharsetFromTextEncoding(rSet.m_nEncoding)) + " failed"),
+        CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("rtl_createTextToUnicodeConverter(" + OUString::createFromAscii(rtl_getMimeCharsetFromTextEncoding(rSet.m_nEncoding)) + ") failed"),
                                                  RTL_TEXTENCODING_UTF8).getStr(),
                                aConverter != NULL);
         rtl_UnicodeToTextContext aContext
@@ -144,7 +144,7 @@ void testSingleByteCharSet(SingleByteCharSet const & rSet) {
             aText[0] = static_cast< sal_Char >(i);
             rtl_TextToUnicodeConverter aConverter
                 = rtl_createTextToUnicodeConverter(rSet.m_nEncoding);
-            CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("rtl_createTextToUnicodeConverter(" + OUString::createFromAscii(rtl_getMimeCharsetFromTextEncoding(rSet.m_nEncoding)) + " failed"),
+            CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("rtl_createTextToUnicodeConverter(" + OUString::createFromAscii(rtl_getMimeCharsetFromTextEncoding(rSet.m_nEncoding)) + ") failed"),
                                                      RTL_TEXTENCODING_UTF8).getStr(),
                                aConverter != NULL);
             rtl_TextToUnicodeContext aContext
@@ -192,7 +192,7 @@ void doComplexCharSetTest(ComplexCharSetTest const & rTest) {
         sal_Unicode aUnicode[TEST_STRING_SIZE];
         rtl_TextToUnicodeConverter aConverter
             = rtl_createTextToUnicodeConverter(rTest.m_nEncoding);
-        CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("rtl_createTextToUnicodeConverter(" + OUString::createFromAscii(rtl_getMimeCharsetFromTextEncoding(rTest.m_nEncoding)) + " failed"),
+        CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("rtl_createTextToUnicodeConverter(" + OUString::createFromAscii(rtl_getMimeCharsetFromTextEncoding(rTest.m_nEncoding)) + ") failed"),
                                                  RTL_TEXTENCODING_UTF8).getStr(),
                                aConverter != NULL);
         rtl_TextToUnicodeContext aContext
@@ -232,7 +232,7 @@ void doComplexCharSetTest(ComplexCharSetTest const & rTest) {
         sal_Unicode aUnicode[TEST_STRING_SIZE];
         rtl_TextToUnicodeConverter aConverter
             = rtl_createTextToUnicodeConverter(rTest.m_nEncoding);
-        CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("rtl_createTextToUnicodeConverter(" + OUString::createFromAscii(rtl_getMimeCharsetFromTextEncoding(rTest.m_nEncoding)) + " failed"),
+        CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("rtl_createTextToUnicodeConverter(" + OUString::createFromAscii(rtl_getMimeCharsetFromTextEncoding(rTest.m_nEncoding)) + ") failed"),
                                                  RTL_TEXTENCODING_UTF8).getStr(),
                                aConverter != NULL);
         rtl_TextToUnicodeContext aContext
@@ -288,7 +288,7 @@ void doComplexCharSetTest(ComplexCharSetTest const & rTest) {
         int nSize = 0;
         rtl_TextToUnicodeConverter aConverter
             = rtl_createTextToUnicodeConverter(rTest.m_nEncoding);
-        CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("rtl_createTextToUnicodeConverter(" + OUString::createFromAscii(rtl_getMimeCharsetFromTextEncoding(rTest.m_nEncoding)) + " failed"),
+        CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("rtl_createTextToUnicodeConverter(" + OUString::createFromAscii(rtl_getMimeCharsetFromTextEncoding(rTest.m_nEncoding)) + ") failed"),
                                                  RTL_TEXTENCODING_UTF8).getStr(),
                                aConverter != NULL);
         for (sal_Size i = 0;;) {
@@ -409,7 +409,7 @@ void doComplexCharSetCutTest(ComplexCharSetTest const & rTest) {
         sal_Unicode aUnicode[TEST_STRING_SIZE];
         rtl_TextToUnicodeConverter aConverter
             = rtl_createTextToUnicodeConverter(rTest.m_nEncoding);
-        CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("rtl_createTextToUnicodeConverter(" + OUString::createFromAscii(rtl_getMimeCharsetFromTextEncoding(rTest.m_nEncoding)) + " failed"),
+        CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("rtl_createTextToUnicodeConverter(" + OUString::createFromAscii(rtl_getMimeCharsetFromTextEncoding(rTest.m_nEncoding)) + ") failed"),
                                                  RTL_TEXTENCODING_UTF8).getStr(),
                                aConverter != NULL);
         sal_Size nSize;


More information about the Libreoffice-commits mailing list