diff --git a/buildTest/compile.sh b/buildTest/compile.sh index 95d75a8..4a8fad8 100755 --- a/buildTest/compile.sh +++ b/buildTest/compile.sh @@ -10,6 +10,9 @@ trap 'err_handle' ERR set -e +# setup environment: Copy material for tests to /tmp +cp -r ../src/tests/lupppTestMaterial /tmp + cmake -DBUILD_TESTS=1 ../ make -j 2 diff --git a/src/config.hxx b/src/config.hxx index 9bba739..d340466 100644 --- a/src/config.hxx +++ b/src/config.hxx @@ -37,8 +37,9 @@ #define LOOPER_SAMPLES_BEFORE_REQUEST 44100 #define LOOPER_SAMPLES_UPDATE_SIZE 44100 -#define LUPPP_RETURN_OK 0 -#define LUPPP_RETURN_ERROR 1 +#define LUPPP_RETURN_OK 0 +#define LUPPP_RETURN_WARNING 1 +#define LUPPP_RETURN_ERROR 2 /// debug.hxx for printing convienience diff --git a/src/debug.cxx b/src/debug.cxx index 21c7a13..0ad6059 100644 --- a/src/debug.cxx +++ b/src/debug.cxx @@ -7,7 +7,7 @@ void luppp_debug( int warnLevel, const char* name, const char* file, const char* func, int line, const char* format, ... ) { - if ( warnLevel == DEBUG_LEVEL_KILL ) + if ( warnLevel == DEBUG_LEVEL_ERROR ) { printf( "[\033[1;31m%s\033[0m] %s:%i: ", NAME, func, line ); } diff --git a/src/debug.hxx b/src/debug.hxx index 23bbc03..ff797c2 100644 --- a/src/debug.hxx +++ b/src/debug.hxx @@ -14,7 +14,7 @@ LUPPP_KILL( "%s", "MessageHere" ); enum DEBUG_LEVEL { DEBUG_LEVEL_NOTE = 0, DEBUG_LEVEL_WARN, - DEBUG_LEVEL_KILL, + DEBUG_LEVEL_ERROR, DEBUG_LEVEL_TEST }; @@ -24,7 +24,7 @@ void luppp_debug( int warnLevel, const char* name, const char* file, const char* #define LUPPP_NOTE( format, args... ) luppp_debug( DEBUG_LEVEL_NOTE, NAME, __FILE__, __FUNCTION__, __LINE__, format, ## args ) #define LUPPP_WARN( format, args... ) luppp_debug( DEBUG_LEVEL_WARN, NAME, __FILE__, __FUNCTION__, __LINE__, format, ## args ) -#define LUPPP_KILL( format, args... ) luppp_debug( DEBUG_LEVEL_TEST, NAME, __FILE__, __FUNCTION__, __LINE__, format, ## args ) +#define LUPPP_ERROR( format, args... ) luppp_debug( DEBUG_LEVEL_ERROR, NAME, __FILE__, __FUNCTION__, __LINE__, format, ## args ) // only gets printed if #definde BUILD_TESTS #define LUPPP_PRINT_TEST( format, args... ) luppp_debug( DEBUG_LEVEL_DEBUG_ONLY, NAME, __FILE__, __FUNCTION__, __LINE__, format, ## args ) diff --git a/src/diskreader.cxx b/src/diskreader.cxx index 670daad..ffc35f8 100644 --- a/src/diskreader.cxx +++ b/src/diskreader.cxx @@ -8,6 +8,7 @@ #include #include +#include "config.hxx" #include "gui.hxx" #include "event.hxx" #include "audiobuffer.hxx" @@ -25,9 +26,8 @@ DiskReader::DiskReader() { }; -void DiskReader::loadSample( int track, int scene, string path ) +int DiskReader::loadSample( int track, int scene, string path ) { - /// load the sample SndfileHandle infile( path, SFM_READ ); std::vector buf( infile.frames() ); @@ -93,8 +93,8 @@ void DiskReader::loadSample( int track, int scene, string path ) cJSON* audioJson = cJSON_Parse( sampleString ); if (!audioJson) { - printf("Error in Sample JSON before: [%s]\n",cJSON_GetErrorPtr()); - return; + LUPPP_ERROR("%s %s","Error in Sample JSON before: ", cJSON_GetErrorPtr() ); + return LUPPP_RETURN_ERROR; } // retrieve sample metadata from sample.cfg using filename as key @@ -121,6 +121,7 @@ void DiskReader::loadSample( int track, int scene, string path ) else { LUPPP_WARN("%s %s","DiskReader::loadSample() empty or no sample.cfg found at ",base.str().c_str() ); + return LUPPP_RETURN_WARNING; } free( basePath ); @@ -130,9 +131,11 @@ void DiskReader::loadSample( int track, int scene, string path ) writeToDspRingbuffer( &e ); } + return LUPPP_RETURN_OK; + } -void DiskReader::readSession( std::string path ) +int DiskReader::readSession( std::string path ) { cout << "DiskReader::readSession() " << path << endl; sessionPath = path; @@ -157,21 +160,23 @@ void DiskReader::readSession( std::string path ) // create cJSON nodes from strings sessionJson = cJSON_Parse( sessionString ); if (!sessionJson) { - LUPPP_WARN("%s %s", "Error in Session JSON before: ", cJSON_GetErrorPtr() ); - return; + LUPPP_ERROR("%s %s", "Error in Session JSON before: ", cJSON_GetErrorPtr() ); + return LUPPP_RETURN_ERROR; } - readTracks(); + int tr = readTracks(); - readMaster(); + int mr = readMaster(); // cleanup cJSON_Delete( sessionJson ); free ( sessionString ); + + return LUPPP_RETURN_OK; } -void DiskReader::readMaster() +int DiskReader::readMaster() { cJSON* master = cJSON_GetObjectItem( sessionJson, "master"); if ( master ) @@ -233,16 +238,18 @@ void DiskReader::readMaster() } } - - - + } + else + { + LUPPP_ERROR("%s", "Error getting master from JSON" ); + return LUPPP_RETURN_ERROR; } - + return LUPPP_RETURN_OK; } -void DiskReader::readScenes(int t, cJSON* track) +int DiskReader::readScenes(int t, cJSON* track) { cJSON* clips = cJSON_GetObjectItem( track, "clips"); if ( clips ) @@ -266,11 +273,12 @@ void DiskReader::readScenes(int t, cJSON* track) } } // nClips loop + } - } + return LUPPP_RETURN_OK; } -void DiskReader::readTracks() +int DiskReader::readTracks() { cJSON* tracks = cJSON_GetObjectItem( sessionJson, "tracks"); if ( tracks ) @@ -307,10 +315,11 @@ void DiskReader::readTracks() } } // nTracks loop - } else { - cout << "DiskReader: Error getting clip" << endl; + LUPPP_ERROR("%s", "Error getting clip" ); + return LUPPP_RETURN_ERROR; } + return LUPPP_RETURN_OK; } diff --git a/src/diskreader.hxx b/src/diskreader.hxx index fad401d..b89ea96 100644 --- a/src/diskreader.hxx +++ b/src/diskreader.hxx @@ -26,10 +26,14 @@ class DiskReader DiskReader(); /// loads a sample into a new AudioBuffer, returning the buffer - void loadSample( int track, int scene, std::string path ); + int loadSample( int track, int scene, std::string path ); /// reads a session from disk, parsing and restoring state - void readSession( std::string path ); + int readSession( std::string path ); + +#ifdef BUILD_TESTS + int runTests(); +#endif private: cJSON* sessionJson; @@ -38,10 +42,9 @@ class DiskReader std::string sessionPath; // convinience functions - void readTracks(); - void readMaster(); - void readScenes(int t, cJSON* track); - + int readTracks(); + int readMaster(); + int readScenes(int t, cJSON* track); }; #endif // LUPPP_DISK_READER_H diff --git a/src/main.cxx b/src/main.cxx index 651f8d9..38258f0 100644 --- a/src/main.cxx +++ b/src/main.cxx @@ -69,6 +69,7 @@ int main(int argc, char** argv) jack = new Jack(); // test offline functionality + testResult += gui->getDiskReader()->runTests(); testResult += gui->getDiskWriter()->runTests(); // test realtime functionality diff --git a/src/tests/diskreadertest.cxx b/src/tests/diskreadertest.cxx new file mode 100644 index 0000000..5275237 --- /dev/null +++ b/src/tests/diskreadertest.cxx @@ -0,0 +1,36 @@ + + +#ifdef BUILD_TESTS + +#include "../config.hxx" + +#include "../gui.hxx" +#include "../audiobuffer.hxx" +#include "../diskreader.hxx" + +#include "qunit.hxx" + +extern Gui* gui; +extern bool testsPassed; + +int DiskReader::runTests() +{ + QUnit::UnitTest qunit( QUnit::normal ); + + // set the session path to /tmp for test writing + + string path = "/tmp"; + string session = "testSession"; + + //AudioBuffer ab(440); + //gui->getDiskWriter()->initialize(path, session); + + QUNIT_IS_TRUE( gui->getDiskReader()->loadSample( 0, 0,"/tmp/lupppTestMaterial/beat.wav" ) == LUPPP_RETURN_OK ); + + QUNIT_IS_TRUE( gui->getDiskReader()->readSession("/tmp/lupppTestMaterial/lupppTest" ) == LUPPP_RETURN_OK ); + + return qunit.errors(); +} + +#endif + diff --git a/src/tests/lupppTestMaterial/audio.cfg b/src/tests/lupppTestMaterial/audio.cfg new file mode 100644 index 0000000..6331828 --- /dev/null +++ b/src/tests/lupppTestMaterial/audio.cfg @@ -0,0 +1,5 @@ +{ + "beat.wav": { + "beats": 4 + } +} diff --git a/src/tests/lupppTestMaterial/beat.wav b/src/tests/lupppTestMaterial/beat.wav new file mode 100644 index 0000000..1642f21 Binary files /dev/null and b/src/tests/lupppTestMaterial/beat.wav differ diff --git a/src/tests/lupppTestMaterial/lupppTest/audio/audio.cfg b/src/tests/lupppTestMaterial/lupppTest/audio/audio.cfg new file mode 100644 index 0000000..7a73a41 --- /dev/null +++ b/src/tests/lupppTestMaterial/lupppTest/audio/audio.cfg @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file diff --git a/src/tests/lupppTestMaterial/lupppTest/session.luppp b/src/tests/lupppTestMaterial/lupppTest/session.luppp new file mode 100644 index 0000000..7586239 --- /dev/null +++ b/src/tests/lupppTestMaterial/lupppTest/session.luppp @@ -0,0 +1,76 @@ +{ + "session": "lupppTest", + "version_major": 1, + "version_minor": 0, + "version_patch": 0, + "master": { + "fader": 0.780000, + "bpm": 120, + "sceneNames": ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"] + }, + "tracks": [{ + "ID": 0, + "name": "Track 1", + "fader": 0.780000, + "side": 0, + "post": 0, + "reverb": 0, + "clips": ["", "", "", "", "", "", "", "", "", ""] + }, { + "ID": 1, + "name": "Track 2", + "fader": 0.780000, + "side": 0, + "post": 0, + "reverb": 0, + "clips": ["", "", "", "", "", "", "", "", "", ""] + }, { + "ID": 2, + "name": "Track 3", + "fader": 0.780000, + "side": 0, + "post": 0, + "reverb": 0, + "clips": ["", "", "", "", "", "", "", "", "", ""] + }, { + "ID": 3, + "name": "Track 4", + "fader": 0.780000, + "side": 0, + "post": 0, + "reverb": 0, + "clips": ["", "", "", "", "", "", "", "", "", ""] + }, { + "ID": 4, + "name": "Track 5", + "fader": 0.780000, + "side": 0, + "post": 0, + "reverb": 0, + "clips": ["", "", "", "", "", "", "", "", "", ""] + }, { + "ID": 5, + "name": "Track 6", + "fader": 0.780000, + "side": 0, + "post": 0, + "reverb": 0, + "clips": ["", "", "", "", "", "", "", "", "", ""] + }, { + "ID": 6, + "name": "Track 7", + "fader": 0.780000, + "side": 0, + "post": 0, + "reverb": 0, + "clips": ["", "", "", "", "", "", "", "", "", ""] + }, { + "ID": 7, + "name": "Track 8", + "fader": 0.780000, + "side": 0, + "post": 0, + "reverb": 0, + "clips": ["", "", "", "", "", "", "", "", "", ""] + }] +} \ No newline at end of file