-Updated Tup build, now has Tupfile in each directory. Added QUnit testing framework

main
Harry van Haaren 2013-09-16 10:17:27 +01:00
parent ed803634e2
commit 91419b60f3
17 changed files with 293 additions and 7907 deletions

View File

@ -10,4 +10,4 @@ LDFLAGS +=-lgcov
endif
# 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

View File

@ -2,26 +2,15 @@
# Tup build file for Luppp
# GENERAL
OUTPUT = %B.o
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`
# CONFIGURE
ifeq (@(LUPPP_BUILD_TESTS),y)
OUTPUT+=| %B.gcno
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
# COMPILE
: 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)

16
src/avtk/Tupfile Normal file
View File

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

16
src/cjson/Tupfile Normal file
View File

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

View File

@ -31,11 +31,13 @@
// nsamples remaining during recording before Looper requests larger buffer
#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"
#endif // LUPPP_CONFIG_H

9
src/controller/Tupfile Normal file
View File

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

View File

@ -31,7 +31,7 @@ void DiskWriter::initialize(std::string path, std::string name )
sample = cJSON_CreateObject();
}
void DiskWriter::writeAudioBuffer(int track, int scene, AudioBuffer* ab )
int DiskWriter::writeAudioBuffer(int track, int scene, AudioBuffer* ab )
{
// get the filename
stringstream filename;
@ -74,6 +74,8 @@ void DiskWriter::writeAudioBuffer(int track, int scene, AudioBuffer* ab )
// de allocate the AudioBuffer
delete ab;
return LUPPP_RETURN_OK;
}
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
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
clipData.clear();
return LUPPP_RETURN_OK;
}

View File

@ -33,9 +33,13 @@ class DiskWriter
void initialize( std::string path, std::string sessionName );
/// 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:
cJSON* session;

9
src/dsp/Tupfile Normal file
View File

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

View File

@ -38,15 +38,16 @@ int main(int argc, char** argv)
jack = new Jack();
#ifdef BUILD_TESTS
// test offline functionality
gui->getDiskWriter()->runTests();
// test realtime functionality
jack->getGridLogic()->runTests();
#ifdef BUILD_COVERAGE_TEST
LUPPP_NOTE("%s","Done testing, quitting!");
return 0;
#endif
// FIXME: Reset the state of GUI / GridLogic here. Create a "new session"?
#endif
cout << "Done testing... launching Luppp." << endl;
jack->activate();

9
src/observer/Tupfile Normal file
View File

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

9
src/state/Tupfile Normal file
View File

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

13
src/tests/Tupfile Normal file
View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -1,77 +1,65 @@
#include "../gridlogic.hxx"
#include "../jack.hxx"
#include "../looperclip.hxx"
extern Jack* jack;
#ifdef BUILD_TESTS
#define CATCH_CONFIG_RUNNER
#include "catch.hxx"
#endif
#ifdef BUILD_TESTS
#include "../config.hxx"
#include "qunit.hxx"
int GridLogic::runTests()
{
char* const tmp = "-s";
return Catch::Session().run( 1, &tmp );
}
TEST_CASE( "Gridlogic press events", "[gridlogic]" )
{
QUnit::UnitTest qunit( QUnit::verbose );
int t = 0;
int s = 0;
LooperClip* lc = jack->getLooper( t )->getClip( s );
for(int t = 0; t < NTRACKS; t++)
{
lc->init();
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 );
}
/// LA
lc->init();
GridLogic::State s1 = lc->getState();
/// SCENE LAUNCH
lc->init();
jack->getGridLogic()->launchScene( s );
REQUIRE( jack->getGridLogic()->getLaunchedScene() == s );
QUNIT_IS_TRUE( jack->getGridLogic()->getLaunchedScene() == s );
/// PAD STATE CHECKS
// empty -> recording
lc->init();
REQUIRE( lc->getState() == GridLogic::STATE_EMPTY );
QUNIT_IS_TRUE( lc->getState() == GridLogic::STATE_EMPTY );
jack->getGridLogic()->pressed( 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();
REQUIRE( lc->getState() == GridLogic::STATE_RECORDING );
QUNIT_IS_TRUE( lc->getState() == GridLogic::STATE_RECORDING );
// recording -> playing
jack->getGridLogic()->pressed( 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();
REQUIRE( lc->getState() == GridLogic::STATE_PLAYING );
QUNIT_IS_TRUE( lc->getState() == GridLogic::STATE_PLAYING );
// playing -> stopped
jack->getGridLogic()->pressed( 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();
REQUIRE( lc->getState() == GridLogic::STATE_STOPPED );
QUNIT_IS_TRUE( lc->getState() == GridLogic::STATE_STOPPED );
// stopped -> playing
jack->getGridLogic()->pressed( 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();
REQUIRE( lc->getState() == GridLogic::STATE_PLAYING );
QUNIT_IS_TRUE( lc->getState() == GridLogic::STATE_PLAYING );
return qunit.errors();
}
#endif
#endif // BUILD_TESTS

140
src/tests/qunit.hxx Normal file
View File

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