Added option (#define CAPTURE_STDERR)

if set then the DebugTrace calls only for failing tests are shown
This commit is contained in:
Dmitry Panin
2013-11-19 02:41:30 +04:00
parent 6294bb1eed
commit 6c41e5c92c
7 changed files with 63 additions and 2 deletions

View File

@@ -4,6 +4,8 @@
// dirty, but I get OS header includes this way
#include "JGE.h"
#include "OutputCapturer.h"
#include <ostream>
#include <iostream>
#include <iomanip>
@@ -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 <android/log.h>
#define DebugTrace(inString) \

View File

@@ -0,0 +1,28 @@
#ifndef OUTPUTCAPTURER_H
#define OUTPUTCAPTURER_H
#if defined(QT_CONFIG)
#include <Qt>
#include <string>
#include <sstream>
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

View File

@@ -0,0 +1,3 @@
#include "../include/OutputCapturer.h"
std::ostringstream OutputCapturer::stream;

View File

@@ -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;
}

View File

@@ -433,6 +433,15 @@ void TestSuiteGame::assertGame()
Log("<span class=\"success\">==Test Succesful !==</span>");
else
Log("<span class=\"error\">==Test Failed !==</span>");
#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<TestSuite*>(inParam);
#ifdef CAPTURE_STDERR
OutputCapturer::debugAndClear();
#endif
if (instance)
{
string filename;

View File

@@ -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\

View File

@@ -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