13
0

temporal: add (back) first set of unit tests

This just uses the old Evoral BeatTest. Some of the tests needed amending
because temporal uses rint() to convert between float and int, not just
a cast.
This commit is contained in:
Paul Davis 2022-02-12 15:12:24 -07:00
parent 9cea6b7359
commit 04bd9187e4
4 changed files with 136 additions and 0 deletions

View File

@ -35,6 +35,7 @@ run_tests midi++2
run_tests evoral
run_tests pbd
run_tests ardour
run_tests temporal
if test "$ALLGOOD" != "yes"; then
echo ""

View File

@ -0,0 +1,22 @@
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
class BeatsTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(BeatsTest);
CPPUNIT_TEST(createTest);
CPPUNIT_TEST(addTest);
CPPUNIT_TEST(subtractTest);
CPPUNIT_TEST(multiplyTest);
CPPUNIT_TEST(convertTest);
CPPUNIT_TEST(roundTest);
CPPUNIT_TEST_SUITE_END();
public:
void createTest();
void addTest();
void subtractTest();
void multiplyTest();
void convertTest();
void roundTest();
};

View File

@ -0,0 +1,70 @@
#include <getopt.h>
#include <glibmm/thread.h>
#include <cppunit/CompilerOutputter.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/TestResult.h>
#include <cppunit/TestResultCollector.h>
#include <cppunit/TestRunner.h>
#include <cppunit/BriefTestProgressListener.h>
#include "pbd/debug.h"
#include "pbd/pbd.h"
#include "temporal/types.h"
int
main(int argc, char* argv[])
{
if (!Glib::thread_supported()) {
Glib::thread_init();
}
const struct option longopts[] = {
{ "debug", 1, 0, 'D' },
{ 0, 0, 0, 0 }
};
const char *optstring = "D:";
int option_index = 0;
int c = 0;
while (1) {
c = getopt_long (argc, argv, optstring, longopts, &option_index);
if (c == -1) {
break;
}
switch (c) {
case 0:
break;
case 'D':
if (PBD::parse_debug_options (optarg)) {
exit (0);
}
break;
}
}
if (!PBD::init ()) return 1;
Temporal::init ();
CppUnit::TestResult testresult;
CppUnit::TestResultCollector collectedresults;
testresult.addListener (&collectedresults);
CppUnit::BriefTestProgressListener progress;
testresult.addListener (&progress);
CppUnit::TestRunner testrunner;
testrunner.addTest (CppUnit::TestFactoryRegistry::getRegistry ().makeTest ());
testrunner.run (testresult);
CppUnit::CompilerOutputter compileroutputter (&collectedresults, std::cerr);
compileroutputter.write ();
return collectedresults.wasSuccessful () ? 0 : 1;
}

View File

@ -63,5 +63,48 @@ def build(bld):
obj.uselib = [ 'GLIBMM', 'XML', 'OSX' ]
obj.use = [ 'libpbd' ]
if bld.env['BUILD_TESTS'] and bld.is_defined('HAVE_CPPUNIT'):
# Static library (for unit test code coverage)
obj = bld(features = 'cxx cstlib')
obj.source = temporal_sources
obj.export_includes = ['.']
obj.includes = ['.']
obj.name = 'libtemporal_static'
obj.target = 'temporal_static'
obj.uselib = 'GLIBMM GTHREAD XML LIBPBD'
obj.use = 'libpbd'
obj.vnum = TEMPORAL_VERSION
obj.install_path = ''
if bld.env['TEST_COVERAGE']:
obj.linkflags = ['--coverage']
obj.cflags = ['--coverage']
obj.cxxflags = ['--coverage']
obj.defines = ['PACKAGE="libevoral"']
# Unit tests
obj = bld(features = 'cxx cxxprogram')
obj.source = '''
test/beats.cc
test/testrunner.cc
'''
obj.includes = ['.']
obj.use = 'libtemporal_static'
obj.uselib = 'GLIBMM GTHREAD XML LIBPBD CPPUNIT'
obj.target = 'run-tests'
obj.name = 'libtemporal-tests'
obj.install_path = ''
obj.defines = ['PACKAGE="libtemporaltest"']
if bld.env['TEST_COVERAGE']:
obj.linkflags = ['--coverage']
obj.cflags = ['--coverage']
obj.cxxflags = ['--coverage']
def test(ctx):
autowaf.pre_test(ctx, APPNAME)
print(os.getcwd())
os.environ['EVORAL_TEST_PATH'] = os.path.abspath('../test/testdata/')
autowaf.run_tests(ctx, APPNAME, ['./run-tests'])
autowaf.post_test(ctx, APPNAME)
def shutdown():
autowaf.shutdown()