-Updated Tup build, now has Tupfile in each directory. Added QUnit testing framework
parent
ed803634e2
commit
91419b60f3
2
Tupfile
2
Tupfile
|
@ -10,4 +10,4 @@ LDFLAGS +=-lgcov
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# LINK
|
# LINK
|
||||||
: src/*.o |> ^c^ g++ %f $(LDFLAGS) -o %o |> luppp
|
: src/*.o src/avtk/*.o src/cjson/*.o src/controller/*.o src/dsp/*.o src/observer/*.o src/state/*.o src/tests/*.o |> ^c^ g++ %f $(LDFLAGS) -o %o |> luppp
|
||||||
|
|
15
src/Tupfile
15
src/Tupfile
|
@ -2,26 +2,15 @@
|
||||||
# Tup build file for Luppp
|
# Tup build file for Luppp
|
||||||
|
|
||||||
# GENERAL
|
# GENERAL
|
||||||
OUTPUT = %B.o
|
OUTPUT=%B.o
|
||||||
CFLAGS += -g -Wall -march=native -msse -mfpmath=sse -ffast-math
|
CFLAGS += -g -Wall -march=native -msse -mfpmath=sse -ffast-math
|
||||||
INCLUDES += `pkg-config --cflags jack sndfile cairomm-1.0 ntk ntk_images`
|
INCLUDES += `pkg-config --cflags jack sndfile cairomm-1.0 ntk ntk_images`
|
||||||
|
|
||||||
|
|
||||||
# CONFIGURE
|
|
||||||
ifeq (@(LUPPP_BUILD_TESTS),y)
|
ifeq (@(LUPPP_BUILD_TESTS),y)
|
||||||
|
OUTPUT+=| %B.gcno
|
||||||
CFLAGS += -fprofile-arcs -ftest-coverage -DBUILD_TESTS -DBUILD_COVERAGE_TEST -DDEBUG_KILL_ON_ERR
|
CFLAGS += -fprofile-arcs -ftest-coverage -DBUILD_TESTS -DBUILD_COVERAGE_TEST -DDEBUG_KILL_ON_ERR
|
||||||
OUTPUT += | %B.gcno
|
|
||||||
: foreach tests/*.cxx |> ^c^ g++ $(CFLAGS) -c %f $(INCLUDES) -o %o |> $(OUTPUT)
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
# COMPILE
|
# COMPILE
|
||||||
: foreach *.cxx |> ^c^ g++ $(CFLAGS) -c %f $(INCLUDES) -o %o |> $(OUTPUT)
|
: foreach *.cxx |> ^c^ g++ $(CFLAGS) -c %f $(INCLUDES) -o %o |> $(OUTPUT)
|
||||||
: foreach avtk/*.cxx |> ^c^ g++ $(CFLAGS) -c %f $(INCLUDES) -o %o |> $(OUTPUT)
|
|
||||||
: foreach controller/*.cxx |> ^c^ g++ $(CFLAGS) -c %f $(INCLUDES) -o %o |> $(OUTPUT)
|
|
||||||
: foreach dsp/*.cxx |> ^c^ g++ $(CFLAGS) -c %f $(INCLUDES) -o %o |> $(OUTPUT)
|
|
||||||
: foreach cjson/*.c |> ^c^ g++ $(CFLAGS) -c %f $(INCLUDES) -o %o |> $(OUTPUT)
|
|
||||||
: foreach state/*.cxx |> ^c^ g++ $(CFLAGS) -c %f $(INCLUDES) -o %o |> $(OUTPUT)
|
|
||||||
: foreach observer/*.cxx |> ^c^ g++ $(CFLAGS) -c %f $(INCLUDES) -o %o |> $(OUTPUT)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
|
||||||
|
# Tup build file for Luppp
|
||||||
|
|
||||||
|
# GENERAL
|
||||||
|
OUTPUT=%B.o
|
||||||
|
CFLAGS += -g -Wall -march=native -msse -mfpmath=sse -ffast-math
|
||||||
|
INCLUDES += `pkg-config --cflags jack sndfile cairomm-1.0 ntk ntk_images`
|
||||||
|
|
||||||
|
|
||||||
|
ifeq (@(LUPPP_BUILD_TESTS),y)
|
||||||
|
OUTPUT+=| %B.gcno
|
||||||
|
CFLAGS += -fprofile-arcs -ftest-coverage -DBUILD_TESTS -DBUILD_COVERAGE_TEST -DDEBUG_KILL_ON_ERR
|
||||||
|
endif
|
||||||
|
|
||||||
|
# COMPILE
|
||||||
|
: foreach *.cxx |> ^c^ g++ $(CFLAGS) -c %f $(INCLUDES) -o %o |> $(OUTPUT)
|
|
@ -0,0 +1,16 @@
|
||||||
|
|
||||||
|
# Tup build file for Luppp
|
||||||
|
|
||||||
|
# GENERAL
|
||||||
|
OUTPUT=%B.o
|
||||||
|
CFLAGS += -g -Wall -march=native -msse -mfpmath=sse -ffast-math
|
||||||
|
INCLUDES += `pkg-config --cflags jack sndfile cairomm-1.0 ntk ntk_images`
|
||||||
|
|
||||||
|
|
||||||
|
ifeq (@(LUPPP_BUILD_TESTS),y)
|
||||||
|
OUTPUT+=| %B.gcno
|
||||||
|
CFLAGS += -fprofile-arcs -ftest-coverage -DBUILD_TESTS -DBUILD_COVERAGE_TEST -DDEBUG_KILL_ON_ERR
|
||||||
|
endif
|
||||||
|
|
||||||
|
# COMPILE
|
||||||
|
: foreach *.c |> ^c^ g++ $(CFLAGS) -c %f $(INCLUDES) -o %o |> $(OUTPUT)
|
|
@ -31,11 +31,13 @@
|
||||||
// nsamples remaining during recording before Looper requests larger buffer
|
// nsamples remaining during recording before Looper requests larger buffer
|
||||||
#define LOOPER_SAMPLES_BEFORE_REQUEST 44100
|
#define LOOPER_SAMPLES_BEFORE_REQUEST 44100
|
||||||
|
|
||||||
|
#define LUPPP_RETURN_OK 0
|
||||||
|
#define LUPPP_RETURN_ERROR 1
|
||||||
|
|
||||||
/// include debug.hxx for printing convienience
|
|
||||||
|
/// debug.hxx for printing convienience
|
||||||
#include "debug.hxx"
|
#include "debug.hxx"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // LUPPP_CONFIG_H
|
#endif // LUPPP_CONFIG_H
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
|
||||||
|
# Tup build file for Luppp
|
||||||
|
|
||||||
|
# GENERAL
|
||||||
|
CFLAGS += -g -Wall -march=native -msse -mfpmath=sse -ffast-math
|
||||||
|
INCLUDES += `pkg-config --cflags jack sndfile cairomm-1.0 ntk ntk_images`
|
||||||
|
|
||||||
|
# COMPILE
|
||||||
|
: foreach *.cxx |> ^c^ g++ $(CFLAGS) -c %f $(INCLUDES) -o %o |> %B.o
|
|
@ -31,7 +31,7 @@ void DiskWriter::initialize(std::string path, std::string name )
|
||||||
sample = cJSON_CreateObject();
|
sample = cJSON_CreateObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiskWriter::writeAudioBuffer(int track, int scene, AudioBuffer* ab )
|
int DiskWriter::writeAudioBuffer(int track, int scene, AudioBuffer* ab )
|
||||||
{
|
{
|
||||||
// get the filename
|
// get the filename
|
||||||
stringstream filename;
|
stringstream filename;
|
||||||
|
@ -74,6 +74,8 @@ void DiskWriter::writeAudioBuffer(int track, int scene, AudioBuffer* ab )
|
||||||
|
|
||||||
// de allocate the AudioBuffer
|
// de allocate the AudioBuffer
|
||||||
delete ab;
|
delete ab;
|
||||||
|
|
||||||
|
return LUPPP_RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiskWriter::writeMaster()
|
void DiskWriter::writeMaster()
|
||||||
|
@ -109,7 +111,7 @@ void DiskWriter::writeMaster()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiskWriter::writeSession( std::string path, std::string sessionName )
|
int DiskWriter::writeSession( std::string path, std::string sessionName )
|
||||||
{
|
{
|
||||||
// add session metadata
|
// add session metadata
|
||||||
cJSON_AddItemToObject ( session, "session", cJSON_CreateString( sessionName.c_str() ));
|
cJSON_AddItemToObject ( session, "session", cJSON_CreateString( sessionName.c_str() ));
|
||||||
|
@ -202,4 +204,6 @@ void DiskWriter::writeSession( std::string path, std::string sessionName )
|
||||||
|
|
||||||
// clear the clipData, clean page for next save
|
// clear the clipData, clean page for next save
|
||||||
clipData.clear();
|
clipData.clear();
|
||||||
|
|
||||||
|
return LUPPP_RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,9 +33,13 @@ class DiskWriter
|
||||||
void initialize( std::string path, std::string sessionName );
|
void initialize( std::string path, std::string sessionName );
|
||||||
|
|
||||||
/// writes a single audio buffer to disk
|
/// writes a single audio buffer to disk
|
||||||
void writeAudioBuffer(int track, int scene, AudioBuffer* ab );
|
int writeAudioBuffer(int track, int scene, AudioBuffer* ab );
|
||||||
|
|
||||||
void writeSession( std::string path, std::string sessionName );
|
int writeSession( std::string path, std::string sessionName );
|
||||||
|
|
||||||
|
#ifdef BUILD_TESTS
|
||||||
|
int runTests();
|
||||||
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
cJSON* session;
|
cJSON* session;
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
|
||||||
|
# Tup build file for Luppp
|
||||||
|
|
||||||
|
# GENERAL
|
||||||
|
CFLAGS += -g -Wall -march=native -msse -mfpmath=sse -ffast-math
|
||||||
|
INCLUDES += `pkg-config --cflags jack sndfile cairomm-1.0 ntk ntk_images`
|
||||||
|
|
||||||
|
# COMPILE
|
||||||
|
: foreach *.cxx |> ^c^ g++ $(CFLAGS) -c %f $(INCLUDES) -o %o |> %B.o
|
|
@ -38,15 +38,16 @@ int main(int argc, char** argv)
|
||||||
jack = new Jack();
|
jack = new Jack();
|
||||||
|
|
||||||
#ifdef BUILD_TESTS
|
#ifdef BUILD_TESTS
|
||||||
|
// test offline functionality
|
||||||
|
gui->getDiskWriter()->runTests();
|
||||||
|
// test realtime functionality
|
||||||
jack->getGridLogic()->runTests();
|
jack->getGridLogic()->runTests();
|
||||||
|
|
||||||
#ifdef BUILD_COVERAGE_TEST
|
#ifdef BUILD_COVERAGE_TEST
|
||||||
LUPPP_NOTE("%s","Done testing, quitting!");
|
LUPPP_NOTE("%s","Done testing, quitting!");
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// FIXME: Reset the state of GUI / GridLogic here. Create a "new session"?
|
// FIXME: Reset the state of GUI / GridLogic here. Create a "new session"?
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
cout << "Done testing... launching Luppp." << endl;
|
cout << "Done testing... launching Luppp." << endl;
|
||||||
jack->activate();
|
jack->activate();
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
|
||||||
|
# Tup build file for Luppp
|
||||||
|
|
||||||
|
# GENERAL
|
||||||
|
CFLAGS += -g -Wall -march=native -msse -mfpmath=sse -ffast-math
|
||||||
|
INCLUDES += `pkg-config --cflags jack sndfile cairomm-1.0 ntk ntk_images`
|
||||||
|
|
||||||
|
# COMPILE
|
||||||
|
: foreach *.cxx |> ^c^ g++ $(CFLAGS) -c %f $(INCLUDES) -o %o |> %B.o
|
|
@ -0,0 +1,9 @@
|
||||||
|
|
||||||
|
# Tup build file for Luppp
|
||||||
|
|
||||||
|
# GENERAL
|
||||||
|
CFLAGS += -g -Wall -march=native -msse -mfpmath=sse -ffast-math
|
||||||
|
INCLUDES += `pkg-config --cflags jack sndfile cairomm-1.0 ntk ntk_images`
|
||||||
|
|
||||||
|
# COMPILE
|
||||||
|
: foreach *.cxx |> ^c^ g++ $(CFLAGS) -c %f $(INCLUDES) -o %o |> %B.o
|
|
@ -0,0 +1,13 @@
|
||||||
|
|
||||||
|
# Tup build file for Luppp
|
||||||
|
|
||||||
|
# GENERAL
|
||||||
|
CFLAGS += -g -Wall -march=native -msse -mfpmath=sse -ffast-math
|
||||||
|
INCLUDES += `pkg-config --cflags jack sndfile cairomm-1.0 ntk ntk_images`
|
||||||
|
|
||||||
|
|
||||||
|
# CONFIGURE
|
||||||
|
ifeq (@(LUPPP_BUILD_TESTS),y)
|
||||||
|
CFLAGS += -fprofile-arcs -ftest-coverage -DBUILD_TESTS -DBUILD_COVERAGE_TEST -DDEBUG_KILL_ON_ERR
|
||||||
|
: foreach *.cxx |> ^c^ g++ $(CFLAGS) -c %f $(INCLUDES) -o %o |> %B.o | %B.gcno
|
||||||
|
endif
|
7850
src/tests/catch.hxx
7850
src/tests/catch.hxx
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,27 @@
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef BUILD_TESTS
|
||||||
|
|
||||||
|
#include "../config.hxx"
|
||||||
|
|
||||||
|
#include "../gui.hxx"
|
||||||
|
#include "../audiobuffer.hxx"
|
||||||
|
#include "../diskwriter.hxx"
|
||||||
|
|
||||||
|
#include "qunit.hxx"
|
||||||
|
|
||||||
|
extern Gui* gui;
|
||||||
|
|
||||||
|
int DiskWriter::runTests()
|
||||||
|
{
|
||||||
|
QUnit::UnitTest qunit( QUnit::verbose );
|
||||||
|
//AudioBuffer ab;
|
||||||
|
//QUNIT_IS_TRUE( gui->getDiskWriter()->writeAudioBuffer(0, 0, &ab) == LUPPP_RETURN_OK );
|
||||||
|
|
||||||
|
QUNIT_IS_TRUE( gui->getDiskWriter()->writeSession("/tmp","luppTestSession") == LUPPP_RETURN_OK );
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
@ -1,77 +1,65 @@
|
||||||
|
|
||||||
|
|
||||||
#include "../gridlogic.hxx"
|
#include "../gridlogic.hxx"
|
||||||
|
|
||||||
#include "../jack.hxx"
|
#include "../jack.hxx"
|
||||||
#include "../looperclip.hxx"
|
#include "../looperclip.hxx"
|
||||||
|
|
||||||
|
|
||||||
extern Jack* jack;
|
extern Jack* jack;
|
||||||
|
|
||||||
#ifdef BUILD_TESTS
|
#ifdef BUILD_TESTS
|
||||||
#define CATCH_CONFIG_RUNNER
|
|
||||||
#include "catch.hxx"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef BUILD_TESTS
|
#include "../config.hxx"
|
||||||
|
#include "qunit.hxx"
|
||||||
|
|
||||||
int GridLogic::runTests()
|
int GridLogic::runTests()
|
||||||
{
|
{
|
||||||
char* const tmp = "-s";
|
QUnit::UnitTest qunit( QUnit::verbose );
|
||||||
return Catch::Session().run( 1, &tmp );
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE( "Gridlogic press events", "[gridlogic]" )
|
|
||||||
{
|
|
||||||
int t = 0;
|
int t = 0;
|
||||||
int s = 0;
|
int s = 0;
|
||||||
LooperClip* lc = jack->getLooper( t )->getClip( s );
|
LooperClip* lc = jack->getLooper( t )->getClip( s );
|
||||||
|
|
||||||
for(int t = 0; t < NTRACKS; t++)
|
/// LA
|
||||||
{
|
lc->init();
|
||||||
lc->init();
|
GridLogic::State s1 = lc->getState();
|
||||||
GridLogic::State s1 = lc->getState();
|
|
||||||
REQUIRE( lc->getState() == GridLogic::STATE_EMPTY );
|
|
||||||
jack->getGridLogic()->launchScene( s );
|
|
||||||
|
|
||||||
REQUIRE( lc->getQueuePlay() == false );
|
|
||||||
jack->getGridLogic()->bar();
|
|
||||||
REQUIRE( lc->getQueuePlay() == true );
|
|
||||||
|
|
||||||
REQUIRE( jack->getGridLogic()->getLaunchedScene() == s );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// SCENE LAUNCH
|
/// SCENE LAUNCH
|
||||||
lc->init();
|
lc->init();
|
||||||
jack->getGridLogic()->launchScene( s );
|
jack->getGridLogic()->launchScene( s );
|
||||||
REQUIRE( jack->getGridLogic()->getLaunchedScene() == s );
|
QUNIT_IS_TRUE( jack->getGridLogic()->getLaunchedScene() == s );
|
||||||
|
|
||||||
/// PAD STATE CHECKS
|
/// PAD STATE CHECKS
|
||||||
// empty -> recording
|
// empty -> recording
|
||||||
lc->init();
|
lc->init();
|
||||||
REQUIRE( lc->getState() == GridLogic::STATE_EMPTY );
|
QUNIT_IS_TRUE( lc->getState() == GridLogic::STATE_EMPTY );
|
||||||
jack->getGridLogic()->pressed( t, s );
|
jack->getGridLogic()->pressed( t, s );
|
||||||
jack->getGridLogic()->released( t, s );
|
jack->getGridLogic()->released( t, s );
|
||||||
REQUIRE( lc->getState() == GridLogic::STATE_RECORD_QUEUED );
|
QUNIT_IS_TRUE( lc->getState() == GridLogic::STATE_RECORD_QUEUED );
|
||||||
jack->getGridLogic()->bar();
|
jack->getGridLogic()->bar();
|
||||||
REQUIRE( lc->getState() == GridLogic::STATE_RECORDING );
|
QUNIT_IS_TRUE( lc->getState() == GridLogic::STATE_RECORDING );
|
||||||
// recording -> playing
|
// recording -> playing
|
||||||
jack->getGridLogic()->pressed( t, s );
|
jack->getGridLogic()->pressed( t, s );
|
||||||
jack->getGridLogic()->released( t, s );
|
jack->getGridLogic()->released( t, s );
|
||||||
REQUIRE( lc->getState() == GridLogic::STATE_PLAY_QUEUED );
|
QUNIT_IS_TRUE( lc->getState() == GridLogic::STATE_PLAY_QUEUED );
|
||||||
jack->getGridLogic()->bar();
|
jack->getGridLogic()->bar();
|
||||||
REQUIRE( lc->getState() == GridLogic::STATE_PLAYING );
|
QUNIT_IS_TRUE( lc->getState() == GridLogic::STATE_PLAYING );
|
||||||
// playing -> stopped
|
// playing -> stopped
|
||||||
jack->getGridLogic()->pressed( t, s );
|
jack->getGridLogic()->pressed( t, s );
|
||||||
jack->getGridLogic()->released( t, s );
|
jack->getGridLogic()->released( t, s );
|
||||||
REQUIRE( lc->getState() == GridLogic::STATE_STOP_QUEUED );
|
QUNIT_IS_TRUE( lc->getState() == GridLogic::STATE_STOP_QUEUED );
|
||||||
jack->getGridLogic()->bar();
|
jack->getGridLogic()->bar();
|
||||||
REQUIRE( lc->getState() == GridLogic::STATE_STOPPED );
|
QUNIT_IS_TRUE( lc->getState() == GridLogic::STATE_STOPPED );
|
||||||
// stopped -> playing
|
// stopped -> playing
|
||||||
jack->getGridLogic()->pressed( t, s );
|
jack->getGridLogic()->pressed( t, s );
|
||||||
jack->getGridLogic()->released( t, s );
|
jack->getGridLogic()->released( t, s );
|
||||||
REQUIRE( lc->getState() == GridLogic::STATE_PLAY_QUEUED );
|
QUNIT_IS_TRUE( lc->getState() == GridLogic::STATE_PLAY_QUEUED );
|
||||||
jack->getGridLogic()->bar();
|
jack->getGridLogic()->bar();
|
||||||
REQUIRE( lc->getState() == GridLogic::STATE_PLAYING );
|
QUNIT_IS_TRUE( lc->getState() == GridLogic::STATE_PLAYING );
|
||||||
|
|
||||||
|
|
||||||
|
return qunit.errors();
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
#endif // BUILD_TESTS
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,140 @@
|
||||||
|
// QUnit.hpp - a simple unit test framework for C++
|
||||||
|
//
|
||||||
|
// Original: svn r26
|
||||||
|
// Updated to coloured printing by Harry van Haaren <harryhaaren@gmail.com>
|
||||||
|
//
|
||||||
|
// Typical usage:
|
||||||
|
//
|
||||||
|
// #include "QUnit.hpp"
|
||||||
|
//
|
||||||
|
// int main() {
|
||||||
|
// QUnit::UnitTest qunit(std::cerr, QUnit::verbose);
|
||||||
|
//
|
||||||
|
// QUNIT_IS_TRUE(true);
|
||||||
|
// QUNIT_IS_FALSE(4!=4);
|
||||||
|
// QUNIT_IS_EQUAL(42, 42.0);
|
||||||
|
// QUNIT_IS_NOT_EQUAL(42,"43");
|
||||||
|
//
|
||||||
|
// return qunit.errors();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef _QUNIT_HPP_
|
||||||
|
#define _QUNIT_HPP_
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
#define QUNIT_COLOUR_PASS "\033[1;32m"
|
||||||
|
#define QUNIT_COLOUR_ERROR "\033[1;31m"
|
||||||
|
#define QUNIT_COLOUR_RESET "\033[0m"
|
||||||
|
|
||||||
|
#define QUNIT_IS_EQUAL(expr1,expr2) QUNIT_COMPARE(true,true,expr1,expr2)
|
||||||
|
#define QUNIT_IS_NOT_EQUAL(expr1,expr2) QUNIT_COMPARE(true,false,expr1,expr2)
|
||||||
|
#define QUNIT_IS_TRUE(expr) QUNIT_COMPARE(false,true,expr,true)
|
||||||
|
#define QUNIT_IS_FALSE(expr) QUNIT_COMPARE(false,true,expr,false)
|
||||||
|
|
||||||
|
#define QUNIT_COMPARE(compare,result,expr1,expr2) { \
|
||||||
|
std::stringstream s1, s2; \
|
||||||
|
s1 << std::boolalpha << (expr1); \
|
||||||
|
s2 << std::boolalpha << (expr2); \
|
||||||
|
qunit.evaluate( \
|
||||||
|
compare, result, s1.str(), s2.str(), #expr1, #expr2, \
|
||||||
|
__FILE__, __LINE__, __FUNCTION__ ); \
|
||||||
|
}; \
|
||||||
|
|
||||||
|
namespace QUnit {
|
||||||
|
|
||||||
|
enum { silent, quiet, normal, verbose, noisy };
|
||||||
|
|
||||||
|
class UnitTest {
|
||||||
|
|
||||||
|
public:
|
||||||
|
UnitTest( int verboseLevel );
|
||||||
|
~UnitTest();
|
||||||
|
|
||||||
|
void verboseLevel(int level);
|
||||||
|
int verboseLevel();
|
||||||
|
|
||||||
|
void printStatus();
|
||||||
|
|
||||||
|
int errors() const;
|
||||||
|
|
||||||
|
void evaluate(bool, bool,
|
||||||
|
std::string, std::string, std::string, std::string,
|
||||||
|
const char *, int, const char *);
|
||||||
|
|
||||||
|
private:
|
||||||
|
int verboseLevel_;
|
||||||
|
int errors_;
|
||||||
|
int tests_;
|
||||||
|
};
|
||||||
|
|
||||||
|
inline UnitTest::UnitTest( int verboseLevel)
|
||||||
|
: verboseLevel_(verboseLevel) , errors_(0) , tests_(0) {
|
||||||
|
}
|
||||||
|
|
||||||
|
inline UnitTest::~UnitTest() {
|
||||||
|
if ( verboseLevel_ > quiet )
|
||||||
|
printStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void UnitTest::verboseLevel(int level) {
|
||||||
|
verboseLevel_ = level;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int UnitTest::verboseLevel() {
|
||||||
|
return verboseLevel_;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void UnitTest::printStatus() {
|
||||||
|
if ( errors_ ) {
|
||||||
|
cout << QUNIT_COLOUR_ERROR;
|
||||||
|
} else {
|
||||||
|
cout << QUNIT_COLOUR_PASS;
|
||||||
|
}
|
||||||
|
cout << "Testing " << ( errors_ ? "FAILED" : "OK" ) << " ("
|
||||||
|
<< tests_ << " tests, " << ( tests_ - errors_ ) << " ok, "
|
||||||
|
<< errors_ << " failed)" << QUNIT_COLOUR_RESET << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int UnitTest::errors() const {
|
||||||
|
return errors_;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void UnitTest::evaluate(
|
||||||
|
bool compare, bool result,
|
||||||
|
std::string val1, std::string val2,
|
||||||
|
std::string str1, std::string str2,
|
||||||
|
const char * file, int line, const char * func)
|
||||||
|
{
|
||||||
|
|
||||||
|
bool ok = result ? (val1 == val2) : (val1 != val2);
|
||||||
|
tests_ += 1;
|
||||||
|
errors_ += ok ? 0 : 1;
|
||||||
|
|
||||||
|
if( (ok && !(verboseLevel_ > normal)) || verboseLevel_ == silent )
|
||||||
|
return;
|
||||||
|
|
||||||
|
cout << file << ( ok ? ";" : ":" ) << line << ": ";
|
||||||
|
if ( ok ) {
|
||||||
|
cout << QUNIT_COLOUR_PASS;
|
||||||
|
} else {
|
||||||
|
cout << QUNIT_COLOUR_ERROR;
|
||||||
|
}
|
||||||
|
cout << ( ok ? "OK" : "FAILED" ) << QUNIT_COLOUR_RESET << "/" << func << "(): ";
|
||||||
|
//cout << QUNIT_COLOUR_RESET;
|
||||||
|
if( compare ) {
|
||||||
|
const std::string cmp = ( result ? "==" : "!=" );
|
||||||
|
cout << "compare {" << str1 << "} " << cmp << " {" << str2 << "} "
|
||||||
|
<< "got {\"" << val1 << "\"} " << cmp << " {\"" << val2 << "\"}";
|
||||||
|
} else {
|
||||||
|
cout << "evaluate {" << str1 << "} == " << val1;
|
||||||
|
}
|
||||||
|
cout << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // _QUNIT_HPP_
|
Loading…
Reference in New Issue