diff --git a/JGE/include/DebugRoutines.h b/JGE/include/DebugRoutines.h index 944d4e7a1..1ce188214 100644 --- a/JGE/include/DebugRoutines.h +++ b/JGE/include/DebugRoutines.h @@ -4,6 +4,8 @@ // dirty, but I get OS header includes this way #include "JGE.h" +#include "OutputCapturer.h" + #include #include #include @@ -29,12 +31,23 @@ std::string ToHex(T* pointer) #if defined (WIN32) || defined (LINUX) #ifdef QT_CONFIG + +#ifdef CAPTURE_STDERR #define DebugTrace(inString) \ { \ std::ostringstream stream; \ stream << inString; \ - qDebug("%s", stream.str().c_str()); \ + OutputCapturer::add(stream.str()); \ } +#else // CAPTURE_STDERR +#define DebugTrace(inString) \ +{ \ + std::ostringstream stream; \ + stream << inString; \ + qDebug("%s", stream.str().c_str()); \ +} +#endif // CAPTURE_STDERR + #elif defined (ANDROID) #include #define DebugTrace(inString) \ diff --git a/JGE/include/OutputCapturer.h b/JGE/include/OutputCapturer.h new file mode 100644 index 000000000..9e2f3d924 --- /dev/null +++ b/JGE/include/OutputCapturer.h @@ -0,0 +1,28 @@ +#ifndef OUTPUTCAPTURER_H +#define OUTPUTCAPTURER_H + +#if defined(QT_CONFIG) +#include +#include +#include + +class OutputCapturer +{ +private: + static std::ostringstream stream; +public: + static void add(const std::string& s) { + stream << s << "\n"; + } + static void debugAndClear() { + stream.flush(); + qDebug("%s", stream.str().c_str()); + stream.str(""); + } + static void clear() { + stream.str(""); + } +}; +#endif + +#endif // OUTPUTCAPTURER_H diff --git a/JGE/src/OutputCapturer.cpp b/JGE/src/OutputCapturer.cpp new file mode 100644 index 000000000..3c31da724 --- /dev/null +++ b/JGE/src/OutputCapturer.cpp @@ -0,0 +1,3 @@ +#include "../include/OutputCapturer.h" + +std::ostringstream OutputCapturer::stream; diff --git a/JGE/src/Qtconsole.cpp b/JGE/src/Qtconsole.cpp index 96b0c9efb..9f3078393 100644 --- a/JGE/src/Qtconsole.cpp +++ b/JGE/src/Qtconsole.cpp @@ -98,5 +98,8 @@ int main(int argc, char* argv[]) result = testSuite.run(); delete wagicCore; DebugTrace("TestSuite done: failed test: " << result); +#ifdef CAPTURE_STDERR + OutputCapturer::debugAndClear(); +#endif return result; } diff --git a/projects/mtg/src/TestSuiteAI.cpp b/projects/mtg/src/TestSuiteAI.cpp index 80c930ef8..eeb279fd2 100644 --- a/projects/mtg/src/TestSuiteAI.cpp +++ b/projects/mtg/src/TestSuiteAI.cpp @@ -433,6 +433,15 @@ void TestSuiteGame::assertGame() Log("==Test Succesful !=="); else Log("==Test Failed !=="); +#ifdef CAPTURE_STDERR + if (error) + { + OutputCapturer::debugAndClear(); + } else + { + OutputCapturer::clear(); + } +#endif mMutex.unlock(); } @@ -585,6 +594,9 @@ void TestSuite::ThreadProc(void* inParam) { LOG("Entering TestSuite::ThreadProc"); TestSuite* instance = reinterpret_cast(inParam); +#ifdef CAPTURE_STDERR + OutputCapturer::debugAndClear(); +#endif if (instance) { string filename; diff --git a/projects/mtg/wagic-qt.pro b/projects/mtg/wagic-qt.pro index 5f9544b9b..715823a8a 100644 --- a/projects/mtg/wagic-qt.pro +++ b/projects/mtg/wagic-qt.pro @@ -327,6 +327,7 @@ SOURCES += \ ../../JGE/src/pc/JSocket.cpp\ ../../JGE/src/pc/JSfx.cpp\ ../../JGE/src/JSprite.cpp\ + ../../JGE/src/OutputCapturer.cpp\ ../../JGE/src/Vector2D.cpp\ ../../JGE/src/tinyxml/tinystr.cpp\ ../../JGE/src/tinyxml/tinyxml.cpp\ @@ -393,6 +394,7 @@ HEADERS += \ ../../JGE/include/JSpline.h\ ../../JGE/include/JSprite.h\ ../../JGE/include/JTypes.h\ + ../../JGE/include/OutputCapturer.h\ ../../JGE/include/Vector2D.h\ ../../JGE/include/Vector3D.h\ ../../JGE/include/vram.h\ diff --git a/travis-script.sh b/travis-script.sh index f01edd15b..b9461e8a9 100755 --- a/travis-script.sh +++ b/travis-script.sh @@ -10,7 +10,7 @@ make -j 8 # let's try an Intel linux binary cd ../.. -qmake projects/mtg/wagic-qt.pro CONFIG+=console CONFIG+=debug +qmake projects/mtg/wagic-qt.pro CONFIG+=console CONFIG+=debug DEFINES+=CAPTURE_STDERR make -j 8 # and finish by running the testsuite