-Updated tests, added lupppTestMaterial, updated DiskReader tests

main
Harry van Haaren 2013-09-23 12:21:33 +01:00
parent 3e9cd31dd7
commit a12eef7974
12 changed files with 166 additions and 30 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -8,6 +8,7 @@
#include <libgen.h>
#include <sys/stat.h>
#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<float> 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;
}

View File

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

View File

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

View File

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

View File

@ -0,0 +1,5 @@
{
"beat.wav": {
"beats": 4
}
}

Binary file not shown.

View File

@ -0,0 +1,2 @@
{
}

View File

@ -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": ["", "", "", "", "", "", "", "", "", ""]
}]
}