Add mechanics for Unit Tests, unit tests for AudioBuffer, and fix some minor AudioBuffer issues

main
Georg Krause 2019-05-23 17:14:04 +02:00
parent 40035dee3c
commit e7b45bc11a
12 changed files with 15222 additions and 51 deletions

View File

@ -8,6 +8,8 @@ stages:
# - template: Code-Quality.gitlab-ci.yml
static-analysis:
tags:
- docker
stage: test
allow_failure: true
script:
@ -16,8 +18,23 @@ static-analysis:
paths:
- lizard.txt
expire_in: 2 days
dependencies: []
build:
build-test:
tags:
- docker
stage: build
script:
- meson buildDir -DunitTests=true -Db_coverage=true
- ninja -C buildDir
artifacts:
untracked: true
expire_in: 1 days
dependencies: []
build-publish:
tags:
- docker
stage: build
script:
- meson --prefix /usr buildDir
@ -27,15 +44,27 @@ build:
expire_in: 1 days
test:
tags:
- docker
stage: test
dependencies:
- build
script: ninja -C buildDir test
- build-test
script:
- ninja -C buildDir test
- gcovr -b -e buildDir/luppp@exe/catch.hpp -e buildDir/luppp@exe/test_ <&1 | tee buildDir/coverage.txt
artifacts:
paths:
- buildDir/coverage.txt
reports:
junit: buildDir/junit.xml
coverage: '/^TOTAL.*\s+(\d+\%)$/'
deploy-AppImage:
package-AppImage:
tags:
- docker
stage: package
dependencies:
- build
- build-publish
script:
- DESTDIR=./appdir ninja -C buildDir install ; find ./buildDir/appdir
- unset QTDIR; unset QT_PLUGIN_PATH ; unset LD_LIBRARY_PATH

View File

@ -38,10 +38,14 @@ foreach dep : dep_names
endforeach
# compile the main project
executable('luppp', luppp_src + [version_hxx],
exe = executable('luppp', luppp_src + [version_hxx],
install: true,
dependencies: deps)
if get_option('unitTests')
test('Unit Tests', exe, args : ['-r junit', '-o junit.xml'])
endif
install_data('resources/metadata/luppp.desktop', install_dir: 'share/applications')
install_data('resources/metadata/luppp.appdata.xml', install_dir: 'share/appdata')
install_data('resources/icons/luppp.png', install_dir: 'share/pixmaps')

View File

@ -1 +1,2 @@
option('tests', type : 'boolean', value : true, description : 'Build tests')
option('tests', type : 'boolean', value : false, description : 'Build tests')
option('unitTests', type : 'boolean', value : false, description : 'Build unit tests')

View File

@ -83,12 +83,21 @@ void AudioBuffer::setBeats(int b)
numBeats = b;
}
void AudioBuffer::setAudioFrames(long af)
bool
AudioBuffer::setAudioFrames(long af)
{
audioFrames = af;
if(af <= getSize()) {
audioFrames = af;
#ifdef DEBUG_BUFFER
cout << "AudioBuffer " << ID << " has " << audioFrames << " audioFrames" << " and " << getSize() << " Buffersize\n" << endl;
cout << "AudioBuffer " << ID << " has " << audioFrames
<< " audioFrames"
<< " and " << getSize() << " Buffersize\n"
<< endl;
#endif
return true;
} else {
return false;
}
}
long AudioBuffer::getAudioFrames()
@ -117,9 +126,4 @@ void AudioBuffer::nonRtSetSample(std::vector<float>& sampleL, std::vector<float>
{
bufferL.swap(sampleL);
bufferR.swap(sampleR);
}
void AudioBuffer::nonRtResize(unsigned long size)
{
bufferL.resize(size);
bufferR.resize(size);
}

View File

@ -48,7 +48,7 @@ public:
void setBeats(int b);
void setAudioFrames(long af);
bool setAudioFrames(long af);
long getAudioFrames();
@ -59,8 +59,6 @@ public:
void nonRtSetSample(std::vector<float>& sampleL, std::vector<float>& sampleR);
void nonRtResize(unsigned long size);
protected:
static int privateID;
int ID;

View File

@ -3,39 +3,48 @@ version_hxx = vcs_tag(
output : 'version.hxx',
fallback: 'Version info could not be read.')
luppp_src = files(
'audiobuffer.cxx',
'controllerupdater.cxx',
'debug.cxx',
'diskreader.cxx',
'diskwriter.cxx',
'event.cxx',
'eventhandlerdsp.cxx',
'eventhandlergui.cxx',
'gaudioeditor.cxx',
'gmastertrack.cxx',
'goptions.cxx',
'gridlogic.cxx',
'gtrack.cxx',
'gui.cxx',
'jack.cxx',
'jacksendreturn.cxx',
'logic.cxx',
'looperclip.cxx',
'looper.cxx',
'main.cxx',
'metronome.cxx',
'timemanager.cxx',
'trackoutput.cxx'
)
if not get_option('unitTests')
message('Create build config for publishing')
luppp_src = files(
'audiobuffer.cxx',
'controllerupdater.cxx',
'debug.cxx',
'diskreader.cxx',
'diskwriter.cxx',
'event.cxx',
'eventhandlerdsp.cxx',
'eventhandlergui.cxx',
'gaudioeditor.cxx',
'gmastertrack.cxx',
'goptions.cxx',
'gridlogic.cxx',
'gtrack.cxx',
'gui.cxx',
'jack.cxx',
'jacksendreturn.cxx',
'logic.cxx',
'looperclip.cxx',
'looper.cxx',
'main.cxx',
'metronome.cxx',
'timemanager.cxx',
'trackoutput.cxx'
)
subdir('cjson')
subdir('dsp')
subdir('controller')
subdir('observer')
subdir('state')
subdir('avtk')
subdir('cjson')
subdir('dsp')
subdir('controller')
subdir('observer')
subdir('state')
subdir('avtk')
if(get_option('tests') == true)
subdir('tests')
if get_option('tests')
message('Built with Diskwriter Tests')
subdir('tests')
endif
endif
if get_option('unitTests')
message('Create build config for unit tests')
subdir('unitTests')
endif

15003
src/unitTests/catch.hpp Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,5 @@
luppp_src = files(
'test_audiobuffer.cxx',
'test_entrypoint.cxx',
'test_debug.cxx',
'../audiobuffer.cxx')

View File

@ -0,0 +1,79 @@
#include "catch.hpp"
#include "test_debug.hxx"
#include "../audiobuffer.hxx"
extern OUTPUT output;
int AudioBuffer::privateID = 0;
TEST_CASE("AudioBuffer Tests")
{
AudioBuffer *ab_sizeless = new AudioBuffer();
AudioBuffer *ab_size = new AudioBuffer(1000);
SECTION("Test correct initial state")
{
REQUIRE(ab_size->getBeats() == 0);
REQUIRE(ab_size->getAudioFrames() == 0);
REQUIRE(ab_size->getSize() == 1000);
REQUIRE(ab_sizeless->getBeats() == 0);
REQUIRE(ab_sizeless->getAudioFrames() == 0);
REQUIRE(ab_sizeless->getSize() == 0);
}
SECTION("Test ID changes")
{
ab_size->setID(500);
REQUIRE(ab_size->getID() == 500);
ab_sizeless->setID(501);
REQUIRE(ab_sizeless->getID() == 501);
}
SECTION("Test name changes")
{
ab_size->setName("abcdef");
REQUIRE(ab_size->getName() == "abcdef");
ab_size->setName("Lorem ipsum dolor sit amet");
REQUIRE(ab_size->getName() == "Lorem ipsum dolor si");
}
SECTION("Test beat num changes") {
ab_size->setBeats(5);
REQUIRE(ab_size->getBeats() == 5);
}
SECTION("Test audio frames change") {
ab_size->setAudioFrames(900);
REQUIRE(ab_size->getAudioFrames() == 900);
// Set AudioFrames higher than size
REQUIRE(ab_size->setAudioFrames(1500) == false);
REQUIRE(ab_size->getAudioFrames() == 900);
}
SECTION("Test Set Audio Buffer with different Length") {
std::vector<float> tempL;
for(int i = 0; i < 500; i++) {
tempL.push_back(rand());
}
std::vector<float> tempR;
for(int i = 0; i < 900; i++) {
tempR.push_back(rand());
}
std::vector<float> argL = tempL;
std::vector<float> argR = tempR;
ab_size->nonRtSetSample(argL, argR);
REQUIRE(ab_size->getSize() == 500);
REQUIRE(strcmp(output.format,
"left and right channels of audio buffer have different size: %i vs %i") == 0);
REQUIRE(output.warnLevel == 1);
REQUIRE(ab_size->getDataL() == tempL);
REQUIRE(ab_size->getDataR() == tempR);
output.reset();
}
}

View File

@ -0,0 +1,26 @@
#include "test_debug.hxx"
OUTPUT output;
void
luppp_debug(int warnLevel, const char *name, const char *file, const char *func,
int line, const char *format, ...)
{
output.warnLevel = warnLevel;
output.name = name;
output.file = file;
output.func = func;
output.line = line;
output.format = format;
}
void
OUTPUT::reset()
{
warnLevel = 0;
name = "";
file = "";
func = "";
line = 0;
format = "";
}

View File

@ -0,0 +1,11 @@
struct OUTPUT {
int warnLevel;
const char *name;
const char *file;
const char *func;
int line;
const char *format;
void
reset();
};

View File

@ -0,0 +1,2 @@
#define CATCH_CONFIG_MAIN
#include "catch.hpp"