diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2018-06-16 18:05:00 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2018-06-16 18:15:59 +0200 |
commit | 2abc107b24f73b8c4664189c34196d9a27a3e339 (patch) | |
tree | b7067a45f7294dbd143c410bdfb690157c976e3c | |
parent | e694a23ab28686ecc0635c2ac8c625e743b89a3b (diff) |
Port the rest of the unittests to DGUnit and remove the CppUnit dependency.
-rw-r--r-- | configure.ac | 10 | ||||
-rw-r--r-- | plugin/Makefile.mingw32.in | 1 | ||||
-rw-r--r-- | src/memchecker.cc | 137 | ||||
-rw-r--r-- | src/memchecker.h | 52 | ||||
-rw-r--r-- | test/Makefile.am | 120 | ||||
-rw-r--r-- | test/atomictest.cc | 94 | ||||
-rw-r--r-- | test/audiocacheeventhandlertest.cc | 18 | ||||
-rw-r--r-- | test/audiocachefiletest.cc | 50 | ||||
-rw-r--r-- | test/audiocacheidmanagertest.cc | 50 | ||||
-rw-r--r-- | test/audiocachetest.cc | 32 | ||||
-rw-r--r-- | test/bytesizeparsertest.cc | 61 | ||||
-rw-r--r-- | test/configtest.cc | 260 | ||||
-rw-r--r-- | test/dgunit.h | 1 | ||||
-rw-r--r-- | test/drumkitcreatortest.cc | 20 | ||||
-rw-r--r-- | test/drumkitparsertest.cc | 4 | ||||
-rw-r--r-- | test/enginetest.cc | 18 | ||||
-rw-r--r-- | test/imagecachetest.cc | 44 | ||||
-rw-r--r-- | test/instrumentparsertest.cc | 71 | ||||
-rw-r--r-- | test/lv2.cc | 88 | ||||
-rw-r--r-- | test/memcheckertest.cc | 121 | ||||
-rw-r--r-- | test/notifiertest.cc | 28 | ||||
-rw-r--r-- | test/paintertest.cc | 18 | ||||
-rw-r--r-- | test/randomtest.cc | 40 | ||||
-rw-r--r-- | test/resampler.cc | 141 | ||||
-rw-r--r-- | test/resource_test.cc | 32 | ||||
-rw-r--r-- | test/scopedfile.cc | 3 | ||||
-rw-r--r-- | test/semaphoretest.cc | 25 | ||||
-rw-r--r-- | test/syncedsettings.cc | 329 | ||||
-rw-r--r-- | test/test.cc | 53 |
29 files changed, 755 insertions, 1166 deletions
diff --git a/configure.ac b/configure.ac index f60493c..456cb74 100644 --- a/configure.ac +++ b/configure.ac @@ -207,16 +207,6 @@ dnl ====================== AC_ARG_WITH([test], AS_HELP_STRING([--with-test], [Build unit tests])) -AS_IF([test x$with_test == xyes], - [ - AC_MSG_WARN([*** Building unittests!]) - PKG_CHECK_MODULES([CPPUNIT], [ cppunit >= 1.9.6 ], [], - [ - AC_MSG_ERROR([$CPPUNIT_PKG_ERRORS]) - ]) - ] -) - AM_CONDITIONAL([ENABLE_TESTS], [test "x$with_test" = "xyes"]) dnl ====================== diff --git a/plugin/Makefile.mingw32.in b/plugin/Makefile.mingw32.in index d224bcf..3330e35 100644 --- a/plugin/Makefile.mingw32.in +++ b/plugin/Makefile.mingw32.in @@ -29,7 +29,6 @@ DG_SRC = \ @top_srcdir@/src/instrument.cc \ @top_srcdir@/src/instrumentparser.cc \ @top_srcdir@/src/latencyfilter.cc \ - @top_srcdir@/src/memchecker.cc \ @top_srcdir@/src/midimapparser.cc \ @top_srcdir@/src/midimapper.cc \ @top_srcdir@/src/path.cc \ diff --git a/src/memchecker.cc b/src/memchecker.cc deleted file mode 100644 index ec0c9df..0000000 --- a/src/memchecker.cc +++ /dev/null @@ -1,137 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/*************************************************************************** - * memchecker.cc - * - * Sat Jan 16 18:27:52 CET 2016 - * Copyright 2016 André Nusser - * andre.nusser@googlemail.com - ****************************************************************************/ - -/* - * This file is part of DrumGizmo. - * - * DrumGizmo is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * DrumGizmo is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with DrumGizmo; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ -#include "memchecker.h" - -#include "platform.h" - -#if DG_PLATFORM == DG_PLATFORM_LINUX -#include <sys/sysinfo.h> -#elif DG_PLATFORM == DG_PLATFORM_OSX -#include <mach/vm_statistics.h> -#include <mach/mach_types.h> -#include <mach/mach_init.h> -#include <mach/mach_host.h> -#elif DG_PLATFORM == DG_PLATFORM_FREEBSD -#include <sys/types.h> -#include <sys/sysctl.h> -#include <sys/vmmeter.h> -#endif - -#include <sndfile.h> -#include <hugin.hpp> - -bool MemChecker::enoughFreeMemory(const DrumKit& drumkit) const -{ - uint64_t free_memory = calcFreeMemory(); - uint64_t needed_memory = calcNeededMemory(drumkit); - - return free_memory >= needed_memory; -} - -uint64_t MemChecker::calcFreeMemory() const -{ - uint64_t free_memory = 0; - - // Platform specific calculation of the amount of free memory. -#if DG_PLATFORM == DG_PLATFORM_LINUX - struct sysinfo sys_info; - sysinfo(&sys_info); - free_memory = (uint64_t)sys_info.freeram * (uint64_t)sys_info.mem_unit; -#elif DG_PLATFORM == DG_PLATFORM_WINDOWS - MEMORYSTATUSEX status; - status.dwLength = sizeof(status); - GlobalMemoryStatusEx(&status); - free_memory = status.ullAvailPhys; -#elif DG_PLATFORM == DG_PLATFORM_OSX - vm_size_t page_size; - vm_statistics64_data_t vm_stats; - mach_port_t mach_port = mach_host_self(); - mach_msg_type_number_t count = sizeof(vm_stats) / sizeof(natural_t); - - if (KERN_SUCCESS == host_page_size(mach_port, &page_size) && - KERN_SUCCESS == host_statistics64(mach_port, HOST_VM_INFO, (host_info64_t)&vm_stats, &count)) - { - free_memory = (uint64_t)vm_stats.free_count * (uint64_t)page_size; - } -#elif DG_PLATFORM == DG_PLATFORM_FREEBSD - u_int page_size; - struct vmtotal vmt; - size_t vmt_size, uint_size; - - vmt_size = sizeof(vmt); - uint_size = sizeof(page_size); - - sysctlbyname("vm.vmtotal", &vmt, &vmt_size, NULL, 0); - sysctlbyname("vm.stats.vm.v_page_size", &page_size, &uint_size, NULL, 0); - - free_memory = vmt.t_free * (u_int64_t)page_size; -#elif DG_PLATFORM == DG_PLATFORM_UNIX - // TODO -#endif - - DEBUG(memchecker, "Calculated %" PRIu64 " free memory.\n", free_memory); - - return free_memory; -} - -uint64_t MemChecker::calcNeededMemory(const DrumKit& drumkit) const -{ - uint64_t needed_memory = 0; - - // Calculate memory usage of all instruments of drumkit. - for(auto& instr_ptr: drumkit.instruments) - { - const auto& audiofiles = instr_ptr->audiofiles; - - // Calculate memory usage of all audiofiles. - for(auto& audiofile: audiofiles) - { - needed_memory += calcBytesPerChannel(audiofile->filename); - } - } - - DEBUG(memchecker, "Calculated %" PRIu64 " needed memory.\n", needed_memory); - - return needed_memory; -} - -uint64_t MemChecker::calcBytesPerChannel(const std::string& filename) const -{ - SF_INFO sf_info{}; - - SNDFILE* f = sf_open(filename.c_str(), SFM_READ, &sf_info); - if(!f) - { - ERR(memchecker, "SNDFILE Error (%s): %s\n", - filename.c_str(), sf_strerror(f)); - return 0; - } - - sf_close(f); - - return sf_info.frames * sizeof(sample_t); -} diff --git a/src/memchecker.h b/src/memchecker.h deleted file mode 100644 index aeefb3a..0000000 --- a/src/memchecker.h +++ /dev/null @@ -1,52 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/*************************************************************************** - * memchecker.h - * - * Sat Jan 16 18:27:52 CET 2016 - * Copyright 2016 André Nusser - * andre.nusser@googlemail.com - ****************************************************************************/ - -/* - * This file is part of DrumGizmo. - * - * DrumGizmo is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * DrumGizmo is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with DrumGizmo; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ -#pragma once - -#include "drumkit.h" - -#include <string> -// includes cstdint automatically and is needed for the PRIu64 macro -#include <cinttypes> - -class MemChecker -{ -public: - //! Checks if there is enough memory left to load drumkit into RAM. - //! \param drumkit The drumkit for which it is checked if there's enough memory left. - //! \return True iff there is enough memory left. - bool enoughFreeMemory(const DrumKit& drumkit) const; - -protected: - // Computes how much RAM (in bytes) is left. - uint64_t calcFreeMemory() const; - - // Computes how much memory the drumkit takes when loaded into RAM (in bytes). - uint64_t calcNeededMemory(const DrumKit& drumkit) const; - - // Computes the number of bytes per channel of <filename> using libsnd. - uint64_t calcBytesPerChannel(const std::string& filename) const; -}; diff --git a/test/Makefile.am b/test/Makefile.am index 56b7f72..6a7d244 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -15,23 +15,23 @@ endif check_PROGRAMS = $(TESTS) -resource_CXXFLAGS = -DOUTPUT=\"resource\" $(CPPUNIT_CFLAGS) \ +resource_CXXFLAGS = -DOUTPUT=\"resource\" \ -I$(top_srcdir)/src \ -I$(top_srcdir)/hugin -resource_LDFLAGS = $(CPPUNIT_LIBS) $(SNDFILE_LIBS) +resource_LDFLAGS = $(SNDFILE_LIBS) resource_SOURCES = \ $(top_srcdir)/plugingui/resource.cc \ $(top_srcdir)/plugingui/resource_data.cc \ $(top_srcdir)/hugin/hugin.c \ $(top_srcdir)/src/random.cc \ - test.cc \ + dgtest.cc \ drumkit_creator.cc \ resource_test.cc -audiocache_CXXFLAGS = -DOUTPUT=\"audiocache\" $(CPPUNIT_CFLAGS) \ +audiocache_CXXFLAGS = -DOUTPUT=\"audiocache\" \ -I$(top_srcdir)/src -I$(top_srcdir)/include \ -I$(top_srcdir)/hugin -DDISABLE_HUGIN $(PTHREAD_CFLAGS) $(SNDFILE_CFLAGS) -audiocache_LDFLAGS = $(PTHREAD_LIBS) $(CPPUNIT_LIBS) $(SNDFILE_LIBS) +audiocache_LDFLAGS = $(PTHREAD_LIBS) $(SNDFILE_LIBS) audiocache_SOURCES = \ $(top_srcdir)/src/audiocache.cc \ $(top_srcdir)/src/audiocacheeventhandler.cc \ @@ -41,187 +41,187 @@ audiocache_SOURCES = \ $(top_srcdir)/src/semaphore.cc \ $(top_srcdir)/src/audiofile.cc \ $(top_srcdir)/src/random.cc \ - test.cc \ + dgtest.cc \ drumkit_creator.cc \ audiocachetest.cc -audiocachefile_CXXFLAGS = -DOUTPUT=\"audiocachefile\" $(CPPUNIT_CFLAGS) \ +audiocachefile_CXXFLAGS = -DOUTPUT=\"audiocachefile\" \ -I$(top_srcdir)/src -I$(top_srcdir)/include \ -I$(top_srcdir)/hugin -DDISABLE_HUGIN $(PTHREAD_CFLAGS) $(SNDFILE_CFLAGS) -audiocachefile_LDFLAGS = $(PTHREAD_LIBS) $(CPPUNIT_LIBS) $(SNDFILE_LIBS) +audiocachefile_LDFLAGS = $(PTHREAD_LIBS) $(SNDFILE_LIBS) audiocachefile_SOURCES = \ $(top_srcdir)/src/audiocachefile.cc \ $(top_srcdir)/src/thread.cc \ $(top_srcdir)/src/semaphore.cc \ $(top_srcdir)/src/audiofile.cc \ $(top_srcdir)/src/random.cc \ - test.cc \ + dgtest.cc \ drumkit_creator.cc \ audiocachefiletest.cc audiocacheidmanager_CXXFLAGS = -DOUTPUT=\"audiocacheidmanager\" \ - $(CPPUNIT_CFLAGS) \ + \ -I$(top_srcdir)/src -I$(top_srcdir)/include \ -I$(top_srcdir)/hugin -DDISABLE_HUGIN $(SNDFILE_CFLAGS) -audiocacheidmanager_LDFLAGS = $(CPPUNIT_LIBS) $(SNDFILE_LIBS) +audiocacheidmanager_LDFLAGS = $(SNDFILE_LIBS) audiocacheidmanager_SOURCES = \ $(top_srcdir)/src/audiocacheidmanager.cc \ - test.cc \ + dgtest.cc \ audiocacheidmanagertest.cc audiocacheeventhandler_CXXFLAGS = -DOUTPUT=\"audiocacheeventhandler\" \ - $(CPPUNIT_CFLAGS) \ + \ -I$(top_srcdir)/src -I$(top_srcdir)/include \ -I$(top_srcdir)/hugin -DDISABLE_HUGIN $(PTHREAD_CFLAGS) $(SNDFILE_CFLAGS) -audiocacheeventhandler_LDFLAGS = $(PTHREAD_LIBS) $(CPPUNIT_LIBS) $(SNDFILE_LIBS) +audiocacheeventhandler_LDFLAGS = $(PTHREAD_LIBS) $(SNDFILE_LIBS) audiocacheeventhandler_SOURCES = \ $(top_srcdir)/src/audiocacheeventhandler.cc \ $(top_srcdir)/src/audiocacheidmanager.cc \ $(top_srcdir)/src/audiocachefile.cc \ $(top_srcdir)/src/thread.cc \ $(top_srcdir)/src/semaphore.cc \ - test.cc \ + dgtest.cc \ audiocacheeventhandlertest.cc -enginetest_CXXFLAGS = -DOUTPUT=\"enginetest\" $(CPPUNIT_CFLAGS) \ +enginetest_CXXFLAGS = -DOUTPUT=\"enginetest\" \ -I$(top_srcdir)/src -I$(top_srcdir)/include \ -I$(top_srcdir)/hugin $(PTHREAD_CFLAGS) -enginetest_LDFLAGS = $(CPPUNIT_LIBS) $(PTHREAD_LIBS) $(SNDFILE_LIBS) \ +enginetest_LDFLAGS = $(PTHREAD_LIBS) $(SNDFILE_LIBS) \ $(top_srcdir)/src/libdg.la enginetest_SOURCES = \ $(top_srcdir)/hugin/hugin.c \ - test.cc \ + dgtest.cc \ drumkit_creator.cc \ enginetest.cc -paintertest_CXXFLAGS = -DOUTPUT=\"paintertest\" $(CPPUNIT_CFLAGS) \ +paintertest_CXXFLAGS = -DOUTPUT=\"paintertest\" \ -I$(top_srcdir)/src -I$(top_srcdir)/include -I$(top_srcdir)/plugingui \ -I$(top_srcdir)/hugin $(PTHREAD_CFLAGS) -paintertest_LDFLAGS = $(CPPUNIT_LIBS) $(top_srcdir)/plugingui/libdggui.la +paintertest_LDFLAGS = $(top_srcdir)/plugingui/libdggui.la paintertest_SOURCES = \ $(top_srcdir)/hugin/hugin.c \ - test.cc \ + dgtest.cc \ paintertest.cc -resampler_CXXFLAGS = -DOUTPUT=\"resampler\" $(CPPUNIT_CFLAGS) \ +resampler_CXXFLAGS = -DOUTPUT=\"resampler\" \ $(ZITA_CXXFLAGS) $(SAMPLERATE_CFLAGS) \ -I$(top_srcdir)/hugin -DDISABLE_HUGIN -resampler_LDFLAGS = $(ZITA_LIBS) $(SAMPLERATE_LIBS) $(CPPUNIT_LIBS) +resampler_LDFLAGS = $(ZITA_LIBS) $(SAMPLERATE_LIBS) resampler_SOURCES = \ $(top_srcdir)/src/chresampler.cc \ - test.cc \ + dgtest.cc \ resampler.cc -lv2_CXXFLAGS = -DOUTPUT=\"lv2\" $(CPPUNIT_CFLAGS) \ +lv2_CXXFLAGS = -DOUTPUT=\"lv2\" \ -I$(top_srcdir)/src \ `pkg-config --cflags serd-0` `pkg-config --cflags lilv-0` \ -DLV2_PATH=\"@LV2DIR@\" -lv2_LDFLAGS = $(CPPUNIT_LIBS) `pkg-config --libs serd-0` \ +lv2_LDFLAGS = `pkg-config --libs serd-0` \ `pkg-config --libs lilv-0` -lcrypto \ $(SNDFILE_LIBS) lv2_SOURCES = \ $(top_srcdir)/src/random.cc \ - test.cc \ + dgtest.cc \ drumkit_creator.cc \ lv2_test_host.cc \ lv2.cc -configfile_CXXFLAGS = -DOUTPUT=\"configfile\" $(CPPUNIT_CFLAGS) \ +configfile_CXXFLAGS = -DOUTPUT=\"configfile\" \ -I$(top_srcdir)/hugin -configfile_LDFLAGS = $(CPPUNIT_LIBS) +configfile_LDFLAGS = configfile_SOURCES = \ $(top_srcdir)/src/configfile.cc \ $(top_srcdir)/hugin/hugin.c \ - test.cc \ + dgtest.cc \ configtest.cc -memchecker_CXXFLAGS = -DOUTPUT=\"memchecker\" $(CPPUNIT_CFLAGS) \ +memchecker_CXXFLAGS = -DOUTPUT=\"memchecker\" \ -I$(top_srcdir)/src -I$(top_srcdir)/include \ -I$(top_srcdir)/hugin $(PTHREAD_CFLAGS) -memchecker_LDFLAGS = $(CPPUNIT_LIBS) $(PTHREAD_LIBS) \ +memchecker_LDFLAGS = $(PTHREAD_LIBS) \ $(top_srcdir)/src/libdg.la memchecker_SOURCES = \ $(top_srcdir)/hugin/hugin.c \ - test.cc \ + dgtest.cc \ drumkit_creator.cc \ memcheckertest.cc -randomtest_CXXFLAGS = -DOUTPUT=\"randomtest\" $(CPPUNIT_CFLAGS) \ +randomtest_CXXFLAGS = -DOUTPUT=\"randomtest\" \ -I$(top_srcdir)/src \ -I$(top_srcdir)/hugin -DDISABLE_HUGIN randomtest_CFLAGS = -DDISABLE_HUGIN -randomtest_LDFLAGS = $(CPPUNIT_LIBS) +randomtest_LDFLAGS = randomtest_SOURCES = \ $(top_srcdir)/src/random.cc \ - test.cc \ + dgtest.cc \ randomtest.cc -atomictest_CXXFLAGS = -DOUTPUT=\"atomictest\" $(CPPUNIT_CFLAGS) \ +atomictest_CXXFLAGS = -DOUTPUT=\"atomictest\" \ -I$(top_srcdir)/src -I$(top_srcdir)/hugin -atomictest_LDFLAGS = $(CPPUNIT_LIBS) -atomictest_SOURCES = atomictest.cc test.cc +atomictest_LDFLAGS = +atomictest_SOURCES = atomictest.cc dgtest.cc syncedsettingstest_CXXFLAGS = -DOUTPUT=\"syncedsettingstest\" \ - $(CPPUNIT_CFLAGS) -I$(top_srcdir)/src -I$(top_srcdir)/hugin -syncedsettingstest_LDFLAGS = $(CPPUNIT_LIBS) -syncedsettingstest_SOURCES = syncedsettings.cc test.cc + -I$(top_srcdir)/src -I$(top_srcdir)/hugin +syncedsettingstest_LDFLAGS = +syncedsettingstest_SOURCES = syncedsettings.cc dgtest.cc EXTRA_DIST = \ lv2_test_host.h \ drumkit_creator.h -imagecachetest_CXXFLAGS = -DOUTPUT=\"imagecachetest\" $(CPPUNIT_CFLAGS) \ +imagecachetest_CXXFLAGS = -DOUTPUT=\"imagecachetest\" \ -I$(top_srcdir)/src -I$(top_srcdir)/plugingui -I$(top_srcdir)/hugin -imagecachetest_LDFLAGS = $(CPPUNIT_LIBS) $(top_srcdir)/plugingui/libdggui.la +imagecachetest_LDFLAGS = $(top_srcdir)/plugingui/libdggui.la imagecachetest_SOURCES = \ $(top_srcdir)/hugin/hugin.c \ imagecachetest.cc \ - test.cc + dgtest.cc -semaphoretest_CXXFLAGS = -DOUTPUT=\"semaphoretest\" $(CPPUNIT_CFLAGS) \ +semaphoretest_CXXFLAGS = -DOUTPUT=\"semaphoretest\" \ -I$(top_srcdir)/src -I$(top_srcdir)/hugin $(PTHREAD_CFLAGS) -semaphoretest_LDFLAGS = $(CPPUNIT_LIBS) $(PTHREAD_LIBS) +semaphoretest_LDFLAGS = $(PTHREAD_LIBS) semaphoretest_SOURCES = \ $(top_srcdir)/hugin/hugin.c \ $(top_srcdir)/src/semaphore.cc \ semaphoretest.cc \ - test.cc + dgtest.cc -drumkitcreatortest_CXXFLAGS = -DOUTPUT=\"drumkitcreatortest\" $(CPPUNIT_CFLAGS) \ +drumkitcreatortest_CXXFLAGS = -DOUTPUT=\"drumkitcreatortest\" \ -I$(top_srcdir)/src \ -I$(top_srcdir)/hugin -DDISABLE_HUGIN drumkitcreatortest_CFLAGS = -DDISABLE_HUGIN -drumkitcreatortest_LDFLAGS = $(CPPUNIT_LIBS) $(SNDFILE_LIBS) +drumkitcreatortest_LDFLAGS = $(SNDFILE_LIBS) drumkitcreatortest_SOURCES = \ $(top_srcdir)/src/random.cc \ - test.cc \ + dgtest.cc \ drumkit_creator.cc \ drumkitcreatortest.cc -bytesizeparsertest_CXXFLAGS = -DOUTPUT=\"bytesizeparsertest\" $(CPPUNIT_CFLAGS) \ +bytesizeparsertest_CXXFLAGS = -DOUTPUT=\"bytesizeparsertest\" \ -I$(top_srcdir)/src -bytesizeparsertest_LDFLAGS = $(CPPUNIT_LIBS) +bytesizeparsertest_LDFLAGS = bytesizeparsertest_SOURCES = \ $(top_srcdir)/src/bytesizeparser.cc \ bytesizeparsertest.cc \ - test.cc + dgtest.cc -notifiertest_CXXFLAGS = -DOUTPUT=\"notifiertest\" $(CPPUNIT_CFLAGS) \ +notifiertest_CXXFLAGS = -DOUTPUT=\"notifiertest\" \ -I$(top_srcdir)/src -notifiertest_LDFLAGS = $(CPPUNIT_LIBS) +notifiertest_LDFLAGS = notifiertest_SOURCES = \ notifiertest.cc \ - test.cc + dgtest.cc -instrumentparsertest_CXXFLAGS = -DOUTPUT=\"instrumentparsertest\" $(CPPUNIT_CFLAGS) \ +instrumentparsertest_CXXFLAGS = -DOUTPUT=\"instrumentparsertest\" \ -I$(top_srcdir)/src -I$(top_srcdir)/include -instrumentparsertest_LDFLAGS = $(CPPUNIT_LIBS) \ +instrumentparsertest_LDFLAGS = \ $(top_srcdir)/src/libdg.la instrumentparsertest_SOURCES = \ $(top_srcdir)/hugin/hugin.c \ instrumentparsertest.cc \ scopedfile.cc \ - test.cc + dgtest.cc drumkitparsertest_CXXFLAGS = -DOUTPUT=\"drumkitparsertest\" \ -I$(top_srcdir)/src -I$(top_srcdir)/include diff --git a/test/atomictest.cc b/test/atomictest.cc index 9d2220c..223c6f3 100644 --- a/test/atomictest.cc +++ b/test/atomictest.cc @@ -24,48 +24,46 @@ * along with DrumGizmo; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#include <cppunit/extensions/HelperMacros.h> +#include "dgunit.h" #include <atomic.h> class AtomicTest - : public CppUnit::TestFixture + : public DGUnit { - CPPUNIT_TEST_SUITE(AtomicTest); - CPPUNIT_TEST(podAtomicsUseStandardImpl); - CPPUNIT_TEST(nonPodAtomicsUseOwnImpl); - CPPUNIT_TEST(podAtomicCanBeDefaultInitialized); - CPPUNIT_TEST(nonPodAtomicCanBeDefaultInitialized); - CPPUNIT_TEST(podAtomicCanBeValueInitialized); - CPPUNIT_TEST(nonPodAtomicCanBeValueInitialized); - CPPUNIT_TEST(podAtomicCanBeValueAssigned); - CPPUNIT_TEST(nonPodAtomicCanBeValueAssigned); - CPPUNIT_TEST(podAtomicsAreLockFree); - CPPUNIT_TEST_SUITE_END(); - public: - void setUp() {} - void tearDown() {} + AtomicTest() + { + DGUNIT_TEST(AtomicTest::podAtomicsUseStandardImpl); + DGUNIT_TEST(AtomicTest::nonPodAtomicsUseOwnImpl); + DGUNIT_TEST(AtomicTest::podAtomicCanBeDefaultInitialized); + DGUNIT_TEST(AtomicTest::nonPodAtomicCanBeDefaultInitialized); + DGUNIT_TEST(AtomicTest::podAtomicCanBeValueInitialized); + DGUNIT_TEST(AtomicTest::nonPodAtomicCanBeValueInitialized); + DGUNIT_TEST(AtomicTest::podAtomicCanBeValueAssigned); + DGUNIT_TEST(AtomicTest::nonPodAtomicCanBeValueAssigned); + DGUNIT_TEST(AtomicTest::podAtomicsAreLockFree); + } void podAtomicsUseStandardImpl() { - CPPUNIT_ASSERT(isUsingStandardImpl<bool>()); - CPPUNIT_ASSERT(isUsingStandardImpl<unsigned short int>()); - CPPUNIT_ASSERT(isUsingStandardImpl<short int>()); - CPPUNIT_ASSERT(isUsingStandardImpl<unsigned int>()); - CPPUNIT_ASSERT(isUsingStandardImpl<int>()); - CPPUNIT_ASSERT(isUsingStandardImpl<unsigned long int>()); - CPPUNIT_ASSERT(isUsingStandardImpl<long int>()); - CPPUNIT_ASSERT(isUsingStandardImpl<unsigned long long int>()); - CPPUNIT_ASSERT(isUsingStandardImpl<long long int>()); - CPPUNIT_ASSERT(isUsingStandardImpl<float>()); - CPPUNIT_ASSERT(isUsingStandardImpl<double>()); - CPPUNIT_ASSERT(isUsingStandardImpl<long double>()); + DGUNIT_ASSERT(isUsingStandardImpl<bool>()); + DGUNIT_ASSERT(isUsingStandardImpl<unsigned short int>()); + DGUNIT_ASSERT(isUsingStandardImpl<short int>()); + DGUNIT_ASSERT(isUsingStandardImpl<unsigned int>()); + DGUNIT_ASSERT(isUsingStandardImpl<int>()); + DGUNIT_ASSERT(isUsingStandardImpl<unsigned long int>()); + DGUNIT_ASSERT(isUsingStandardImpl<long int>()); + DGUNIT_ASSERT(isUsingStandardImpl<unsigned long long int>()); + DGUNIT_ASSERT(isUsingStandardImpl<long long int>()); + DGUNIT_ASSERT(isUsingStandardImpl<float>()); + DGUNIT_ASSERT(isUsingStandardImpl<double>()); + DGUNIT_ASSERT(isUsingStandardImpl<long double>()); } void nonPodAtomicsUseOwnImpl() { - CPPUNIT_ASSERT(!isUsingStandardImpl<std::string>()); + DGUNIT_ASSERT(!isUsingStandardImpl<std::string>()); } void podAtomicCanBeDefaultInitialized() @@ -78,52 +76,52 @@ public: void nonPodAtomicCanBeDefaultInitialized() { Atomic<std::string> s; - CPPUNIT_ASSERT_EQUAL(s.load(), std::string{}); + DGUNIT_ASSERT_EQUAL(s.load(), std::string{}); } void podAtomicCanBeValueInitialized() { Atomic<int> i{5}; - CPPUNIT_ASSERT_EQUAL(i.load(), 5); + DGUNIT_ASSERT_EQUAL(i.load(), 5); } void nonPodAtomicCanBeValueInitialized() { Atomic<std::string> s{"hello world"}; - CPPUNIT_ASSERT_EQUAL(s.load(), std::string{"hello world"}); + DGUNIT_ASSERT_EQUAL(s.load(), std::string{"hello world"}); } void podAtomicCanBeValueAssigned() { Atomic<int> i; i = 5; - CPPUNIT_ASSERT_EQUAL(i.load(), 5); + DGUNIT_ASSERT_EQUAL(i.load(), 5); } void nonPodAtomicCanBeValueAssigned() { Atomic<std::string> s; s = "hello world"; - CPPUNIT_ASSERT_EQUAL(s.load(), std::string{"hello world"}); + DGUNIT_ASSERT_EQUAL(s.load(), std::string{"hello world"}); } void podAtomicsAreLockFree() { - CPPUNIT_ASSERT(isLockFree<bool>()); - CPPUNIT_ASSERT(isLockFree<unsigned short int>()); - CPPUNIT_ASSERT(isLockFree<short int>()); - CPPUNIT_ASSERT(isLockFree<unsigned int>()); - CPPUNIT_ASSERT(isLockFree<int>()); - CPPUNIT_ASSERT(isLockFree<unsigned long int>()); - CPPUNIT_ASSERT(isLockFree<long int>()); - CPPUNIT_ASSERT(isLockFree<float>()); - CPPUNIT_ASSERT(isLockFree<std::size_t>()); + DGUNIT_ASSERT(isLockFree<bool>()); + DGUNIT_ASSERT(isLockFree<unsigned short int>()); + DGUNIT_ASSERT(isLockFree<short int>()); + DGUNIT_ASSERT(isLockFree<unsigned int>()); + DGUNIT_ASSERT(isLockFree<int>()); + DGUNIT_ASSERT(isLockFree<unsigned long int>()); + DGUNIT_ASSERT(isLockFree<long int>()); + DGUNIT_ASSERT(isLockFree<float>()); + DGUNIT_ASSERT(isLockFree<std::size_t>()); // NOTE: Not lock free on small systems - //CPPUNIT_ASSERT(isLockFree<unsigned long long int>()); - //CPPUNIT_ASSERT(isLockFree<long long int>()); - //CPPUNIT_ASSERT(isLockFree<double>()); - //CPPUNIT_ASSERT(isLockFree<long double>()); + //DGUNIT_ASSERT(isLockFree<unsigned long long int>()); + //DGUNIT_ASSERT(isLockFree<long long int>()); + //DGUNIT_ASSERT(isLockFree<double>()); + //DGUNIT_ASSERT(isLockFree<long double>()); } private: @@ -142,4 +140,4 @@ private: }; // Registers the fixture into the 'registry' -CPPUNIT_TEST_SUITE_REGISTRATION(AtomicTest); +static AtomicTest test; diff --git a/test/audiocacheeventhandlertest.cc b/test/audiocacheeventhandlertest.cc index 0b408e0..a2639fb 100644 --- a/test/audiocacheeventhandlertest.cc +++ b/test/audiocacheeventhandlertest.cc @@ -24,20 +24,22 @@ * along with DrumGizmo; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#include <cppunit/extensions/HelperMacros.h> +#include "dgunit.h" #include <audiocacheeventhandler.h> class AudioCacheEventHandlerTest - : public CppUnit::TestFixture + : public DGUnit { - CPPUNIT_TEST_SUITE(AudioCacheEventHandlerTest); - CPPUNIT_TEST(threadedTest); - CPPUNIT_TEST_SUITE_END(); +public: + AudioCacheEventHandlerTest() + { + DGUNIT_TEST(AudioCacheEventHandlerTest::threadedTest); + } public: - void setUp() {} - void tearDown() {} + void setup() override {} + void teardown() override {} void threadedTest() { @@ -49,4 +51,4 @@ public: }; // Registers the fixture into the 'registry' -CPPUNIT_TEST_SUITE_REGISTRATION(AudioCacheEventHandlerTest); +static AudioCacheEventHandlerTest test; diff --git a/test/audiocachefiletest.cc b/test/audiocachefiletest.cc index 83aece8..267d787 100644 --- a/test/audiocachefiletest.cc +++ b/test/audiocachefiletest.cc @@ -24,7 +24,7 @@ * along with DrumGizmo; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#include <cppunit/extensions/HelperMacros.h> +#include "dgunit.h" #include <cstring> @@ -53,20 +53,18 @@ public: }; class AudioCacheFileTest - : public CppUnit::TestFixture + : public DGUnit { - CPPUNIT_TEST_SUITE(AudioCacheFileTest); - CPPUNIT_TEST(refTest); - CPPUNIT_TEST(readTest); - CPPUNIT_TEST(noFileTest); - CPPUNIT_TEST_SUITE_END(); +public: + AudioCacheFileTest() + { + DGUNIT_TEST(AudioCacheFileTest::refTest); + DGUNIT_TEST(AudioCacheFileTest::readTest); + DGUNIT_TEST(AudioCacheFileTest::noFileTest); + } DrumkitCreator drumkit_creator; -public: - void setUp() {} - void tearDown() {} - void refTest() { // Create the audio file @@ -74,19 +72,19 @@ public: // Conduct tests TestableAudioCacheFiles audiofiles; - CPPUNIT_ASSERT_EQUAL(-1, audiofiles.getRef(filename)); + DGUNIT_ASSERT_EQUAL(-1, audiofiles.getRef(filename)); audiofiles.getFile(filename); - CPPUNIT_ASSERT_EQUAL(1, audiofiles.getRef(filename)); + DGUNIT_ASSERT_EQUAL(1, audiofiles.getRef(filename)); audiofiles.getFile(filename); - CPPUNIT_ASSERT_EQUAL(2, audiofiles.getRef(filename)); + DGUNIT_ASSERT_EQUAL(2, audiofiles.getRef(filename)); audiofiles.releaseFile(filename); - CPPUNIT_ASSERT_EQUAL(1, audiofiles.getRef(filename)); + DGUNIT_ASSERT_EQUAL(1, audiofiles.getRef(filename)); audiofiles.releaseFile(filename); - CPPUNIT_ASSERT_EQUAL(-1, audiofiles.getRef(filename)); + DGUNIT_ASSERT_EQUAL(-1, audiofiles.getRef(filename)); } void readTestHelper(size_t buffer_size) @@ -107,8 +105,8 @@ public: std::vector<sample_t> read_buffer; AudioCacheFile file(filename, read_buffer); - CPPUNIT_ASSERT_EQUAL(filename, file.getFilename()); - CPPUNIT_ASSERT_EQUAL(13, (int)file.getChannelCount()); // Sanity check + DGUNIT_ASSERT_EQUAL(filename, file.getFilename()); + DGUNIT_ASSERT_EQUAL(13, (int)file.getChannelCount()); // Sanity check CacheChannels channels; @@ -152,7 +150,7 @@ public: for(size_t c = 0; c < 13; ++c) { - CPPUNIT_ASSERT_EQUAL(true, ready[c]?true:false); + DGUNIT_ASSERT_EQUAL(true, ready[c]?true:false); } sample_t diff[13] = {0.0}; @@ -166,7 +164,7 @@ public: for(int c = 0; c < 13; ++c) { - CPPUNIT_ASSERT_EQUAL((sample_t)0.0, diff[c]); + DGUNIT_ASSERT_EQUAL((sample_t)0.0, diff[c]); } } @@ -205,9 +203,9 @@ public: std::vector<sample_t> read_buffer; AudioCacheFile file(filename, read_buffer); - CPPUNIT_ASSERT_EQUAL(filename, file.getFilename()); - CPPUNIT_ASSERT_EQUAL(0u, (unsigned int)file.getSize()); - CPPUNIT_ASSERT_EQUAL(0u, (unsigned int)file.getChannelCount()); + DGUNIT_ASSERT_EQUAL(filename, file.getFilename()); + DGUNIT_ASSERT_EQUAL(0u, (unsigned int)file.getSize()); + DGUNIT_ASSERT_EQUAL(0u, (unsigned int)file.getChannelCount()); CacheChannels channels; @@ -239,18 +237,18 @@ public: for(size_t c = 0; c < 13; ++c) { - CPPUNIT_ASSERT_EQUAL(false, ready[c]?true:false); + DGUNIT_ASSERT_EQUAL(false, ready[c]?true:false); } for(size_t c = 0; c < 13; ++c) { for(size_t i = 0; i < buffer_size; ++i) { - CPPUNIT_ASSERT_EQUAL(42.0f, samples[c][i]); + DGUNIT_ASSERT_EQUAL(42.0f, samples[c][i]); } } } }; // Registers the fixture into the 'registry' -CPPUNIT_TEST_SUITE_REGISTRATION(AudioCacheFileTest); +static AudioCacheFileTest test; diff --git a/test/audiocacheidmanagertest.cc b/test/audiocacheidmanagertest.cc index 74aaaf6..75a7c51 100644 --- a/test/audiocacheidmanagertest.cc +++ b/test/audiocacheidmanagertest.cc @@ -24,7 +24,7 @@ * along with DrumGizmo; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#include <cppunit/extensions/HelperMacros.h> +#include "dgunit.h" #include <audiocacheidmanager.h> @@ -39,15 +39,13 @@ public: }; class AudioCacheIDManagerTest - : public CppUnit::TestFixture + : public DGUnit { - CPPUNIT_TEST_SUITE(AudioCacheIDManagerTest); - CPPUNIT_TEST(registerReleaseTest); - CPPUNIT_TEST_SUITE_END(); - public: - void setUp() {} - void tearDown() {} + AudioCacheIDManagerTest() + { + DGUNIT_TEST(AudioCacheIDManagerTest::registerReleaseTest); + } void registerReleaseTest() { @@ -56,46 +54,46 @@ public: cache_t c1; c1.afile = (AudioCacheFile*)1; auto id1 = manager.registerID(c1); - CPPUNIT_ASSERT(id1 != CACHE_DUMMYID); - CPPUNIT_ASSERT(id1 != CACHE_NOID); - CPPUNIT_ASSERT_EQUAL(1, manager.getAvailableIDs()); + DGUNIT_ASSERT(id1 != CACHE_DUMMYID); + DGUNIT_ASSERT(id1 != CACHE_NOID); + DGUNIT_ASSERT_EQUAL(1, manager.getAvailableIDs()); cache_t c2; c2.afile = (AudioCacheFile*)2; auto id2 = manager.registerID(c2); - CPPUNIT_ASSERT(id2 != CACHE_DUMMYID); - CPPUNIT_ASSERT(id2 != CACHE_NOID); - CPPUNIT_ASSERT_EQUAL(0, manager.getAvailableIDs()); + DGUNIT_ASSERT(id2 != CACHE_DUMMYID); + DGUNIT_ASSERT(id2 != CACHE_NOID); + DGUNIT_ASSERT_EQUAL(0, manager.getAvailableIDs()); cache_t c3; c3.afile = (AudioCacheFile*)3; auto id3 = manager.registerID(c3); - CPPUNIT_ASSERT(id3 == CACHE_DUMMYID); - CPPUNIT_ASSERT_EQUAL(0, manager.getAvailableIDs()); + DGUNIT_ASSERT(id3 == CACHE_DUMMYID); + DGUNIT_ASSERT_EQUAL(0, manager.getAvailableIDs()); cache_t& tc1 = manager.getCache(id1); - CPPUNIT_ASSERT_EQUAL(c1.afile, tc1.afile); + DGUNIT_ASSERT_EQUAL(c1.afile, tc1.afile); cache_t& tc2 = manager.getCache(id2); - CPPUNIT_ASSERT_EQUAL(c2.afile, tc2.afile); + DGUNIT_ASSERT_EQUAL(c2.afile, tc2.afile); manager.releaseID(id1); - CPPUNIT_ASSERT_EQUAL(1, manager.getAvailableIDs()); + DGUNIT_ASSERT_EQUAL(1, manager.getAvailableIDs()); cache_t c4; c4.afile = (AudioCacheFile*)4; auto id4 = manager.registerID(c4); - CPPUNIT_ASSERT(id4 != CACHE_DUMMYID); - CPPUNIT_ASSERT(id4 != CACHE_NOID); - CPPUNIT_ASSERT_EQUAL(0, manager.getAvailableIDs()); + DGUNIT_ASSERT(id4 != CACHE_DUMMYID); + DGUNIT_ASSERT(id4 != CACHE_NOID); + DGUNIT_ASSERT_EQUAL(0, manager.getAvailableIDs()); cache_t& tc4 = manager.getCache(id4); - CPPUNIT_ASSERT_EQUAL(c4.afile, tc4.afile); + DGUNIT_ASSERT_EQUAL(c4.afile, tc4.afile); manager.releaseID(id2); - CPPUNIT_ASSERT_EQUAL(1, manager.getAvailableIDs()); + DGUNIT_ASSERT_EQUAL(1, manager.getAvailableIDs()); manager.releaseID(id4); - CPPUNIT_ASSERT_EQUAL(2, manager.getAvailableIDs()); + DGUNIT_ASSERT_EQUAL(2, manager.getAvailableIDs()); } }; // Registers the fixture into the 'registry' -CPPUNIT_TEST_SUITE_REGISTRATION(AudioCacheIDManagerTest); +static AudioCacheIDManagerTest test; diff --git a/test/audiocachetest.cc b/test/audiocachetest.cc index c03bee4..9f5a858 100644 --- a/test/audiocachetest.cc +++ b/test/audiocachetest.cc @@ -24,7 +24,7 @@ * along with DrumGizmo; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#include <cppunit/extensions/HelperMacros.h> +#include "dgunit.h" #include <thread> #include <chrono> @@ -38,21 +38,19 @@ #define FRAMESIZE 64 class AudioCacheTest - : public CppUnit::TestFixture + : public DGUnit { - CPPUNIT_TEST_SUITE(AudioCacheTest); - CPPUNIT_TEST(singleChannelNonThreaded); - CPPUNIT_TEST(singleChannelThreaded); - CPPUNIT_TEST(multiChannelNonThreaded); - CPPUNIT_TEST(multiChannelThreaded); - CPPUNIT_TEST_SUITE_END(); +public: + AudioCacheTest() + { + DGUNIT_TEST(AudioCacheTest::singleChannelNonThreaded); + DGUNIT_TEST(AudioCacheTest::singleChannelThreaded); + DGUNIT_TEST(AudioCacheTest::multiChannelNonThreaded); + DGUNIT_TEST(AudioCacheTest::multiChannelThreaded); + } DrumkitCreator drumkit_creator; -public: - void setUp() {} - void tearDown() {} - //! Test runner. //! \param filename The name of the file to read. //! \param channel The channel number to do comparison on. @@ -97,7 +95,7 @@ public: // Test pre cache: for(size_t i = 0; i < size; ++i) { - CPPUNIT_ASSERT_EQUAL(audio_file_ref.data[offset], samples[i]); + DGUNIT_ASSERT_EQUAL(audio_file_ref.data[offset], samples[i]); ++offset; } @@ -113,14 +111,14 @@ public: std::this_thread::sleep_for(std::chrono::milliseconds(1)); if(--timeout == 0) { - CPPUNIT_ASSERT(false); // timeout + DGUNIT_ASSERT(false); // timeout } } } samples = audio_cache.next(id, size); - CPPUNIT_ASSERT_EQUAL(std::size_t(0), settings.number_of_underruns.load()); + DGUNIT_ASSERT_EQUAL(std::size_t(0), settings.number_of_underruns.load()); for(size_t i = 0; (i < size) && (offset < audio_file_ref.size); ++i) { @@ -132,7 +130,7 @@ public: (int)(audio_file_ref.size - offset), (int)i, (int)size, (int)(size - i)); } - CPPUNIT_ASSERT_EQUAL(audio_file_ref.data[offset], samples[i]); + DGUNIT_ASSERT_EQUAL(audio_file_ref.data[offset], samples[i]); ++offset; } } @@ -202,4 +200,4 @@ public: }; // Registers the fixture into the 'registry' -CPPUNIT_TEST_SUITE_REGISTRATION(AudioCacheTest); +static AudioCacheTest test; diff --git a/test/bytesizeparsertest.cc b/test/bytesizeparsertest.cc index e4776fe..ea082e2 100644 --- a/test/bytesizeparsertest.cc +++ b/test/bytesizeparsertest.cc @@ -24,25 +24,22 @@ * along with DrumGizmo; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#include <cppunit/extensions/HelperMacros.h> +#include "dgunit.h" #include "bytesizeparser.h" class ByteSizeParserTest - : public CppUnit::TestFixture + : public DGUnit { - CPPUNIT_TEST_SUITE(ByteSizeParserTest); - CPPUNIT_TEST(suffixTest); - CPPUNIT_TEST(falseSuffixTest); - CPPUNIT_TEST(falseNumberTest); - CPPUNIT_TEST(tooBigNumberTest); - CPPUNIT_TEST_SUITE_END(); - public: - void setUp() {} - - void tearDown() {} + ByteSizeParserTest() + { + DGUNIT_TEST(ByteSizeParserTest::suffixTest); + DGUNIT_TEST(ByteSizeParserTest::falseSuffixTest); + DGUNIT_TEST(ByteSizeParserTest::falseNumberTest); + DGUNIT_TEST(ByteSizeParserTest::tooBigNumberTest); + } void suffixTest() { @@ -50,78 +47,78 @@ public: std::size_t kilo = 1024, mega = kilo * 1024, giga = mega * 1024; computed_size = byteSizeParser("3"); expected_size = 3; - CPPUNIT_ASSERT_EQUAL(expected_size, computed_size); + DGUNIT_ASSERT_EQUAL(expected_size, computed_size); computed_size = byteSizeParser("3k"); expected_size = 3 * kilo; - CPPUNIT_ASSERT_EQUAL(expected_size, computed_size); + DGUNIT_ASSERT_EQUAL(expected_size, computed_size); computed_size = byteSizeParser("3M"); expected_size = 3 * mega; - CPPUNIT_ASSERT_EQUAL(expected_size, computed_size); + DGUNIT_ASSERT_EQUAL(expected_size, computed_size); computed_size = byteSizeParser("3G"); expected_size = 3 * giga; - CPPUNIT_ASSERT_EQUAL(expected_size, computed_size); + DGUNIT_ASSERT_EQUAL(expected_size, computed_size); } void falseSuffixTest() { std::size_t computed_size, expected_size = 0; computed_size = byteSizeParser("3K"); - CPPUNIT_ASSERT_EQUAL(expected_size, computed_size); + DGUNIT_ASSERT_EQUAL(expected_size, computed_size); computed_size = byteSizeParser("3m"); - CPPUNIT_ASSERT_EQUAL(expected_size, computed_size); + DGUNIT_ASSERT_EQUAL(expected_size, computed_size); computed_size = byteSizeParser("3g"); - CPPUNIT_ASSERT_EQUAL(expected_size, computed_size); + DGUNIT_ASSERT_EQUAL(expected_size, computed_size); computed_size = byteSizeParser("3ddDD"); - CPPUNIT_ASSERT_EQUAL(expected_size, computed_size); + DGUNIT_ASSERT_EQUAL(expected_size, computed_size); } void falseNumberTest() { std::size_t computed_size, expected_size = 0; computed_size = byteSizeParser("K3k"); - CPPUNIT_ASSERT_EQUAL(expected_size, computed_size); + DGUNIT_ASSERT_EQUAL(expected_size, computed_size); computed_size = byteSizeParser("-3"); - CPPUNIT_ASSERT_EQUAL(expected_size, computed_size); + DGUNIT_ASSERT_EQUAL(expected_size, computed_size); computed_size = byteSizeParser("-3k"); - CPPUNIT_ASSERT_EQUAL(expected_size, computed_size); + DGUNIT_ASSERT_EQUAL(expected_size, computed_size); computed_size = byteSizeParser("-3M"); - CPPUNIT_ASSERT_EQUAL(expected_size, computed_size); + DGUNIT_ASSERT_EQUAL(expected_size, computed_size); computed_size = byteSizeParser("-3G"); - CPPUNIT_ASSERT_EQUAL(expected_size, computed_size); + DGUNIT_ASSERT_EQUAL(expected_size, computed_size); computed_size = byteSizeParser("3-"); - CPPUNIT_ASSERT_EQUAL(expected_size, computed_size); + DGUNIT_ASSERT_EQUAL(expected_size, computed_size); computed_size = byteSizeParser("3-k"); - CPPUNIT_ASSERT_EQUAL(expected_size, computed_size); + DGUNIT_ASSERT_EQUAL(expected_size, computed_size); computed_size = byteSizeParser("k-3"); - CPPUNIT_ASSERT_EQUAL(expected_size, computed_size); + DGUNIT_ASSERT_EQUAL(expected_size, computed_size); computed_size = byteSizeParser("3-1"); - CPPUNIT_ASSERT_EQUAL(expected_size, computed_size); + DGUNIT_ASSERT_EQUAL(expected_size, computed_size); computed_size = byteSizeParser(" -3"); - CPPUNIT_ASSERT_EQUAL(expected_size, computed_size); + DGUNIT_ASSERT_EQUAL(expected_size, computed_size); } void tooBigNumberTest() { std::size_t computed_size, expected_size = 0; computed_size = byteSizeParser("999999999999999999999999999999999999G"); - CPPUNIT_ASSERT_EQUAL(expected_size, computed_size); + DGUNIT_ASSERT_EQUAL(expected_size, computed_size); } }; // Registers the fixture into the 'registry' -CPPUNIT_TEST_SUITE_REGISTRATION(ByteSizeParserTest); +static ByteSizeParserTest test; diff --git a/test/configtest.cc b/test/configtest.cc index 1b8b265..a4d5228 100644 --- a/test/configtest.cc +++ b/test/configtest.cc @@ -24,196 +24,196 @@ * along with DrumGizmo; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#include <cppunit/extensions/HelperMacros.h> +#include "dgunit.h" #include <unistd.h> #include <stdio.h> #include "../src/configfile.h" -class TestConfigFile : public ConfigFile { +class TestConfigFile + : public ConfigFile { public: - TestConfigFile() : ConfigFile("") {} + TestConfigFile() + : ConfigFile("") + { + } protected: - // Overload the built-in open method to use local file instead of homedir. - virtual bool open(std::string mode) - { - fp = fopen("test.conf", mode.c_str()); - return fp != NULL; - } + // Overload the built-in open method to use local file instead of homedir. + virtual bool open(std::string mode) + { + fp = fopen("test.conf", mode.c_str()); + return fp != NULL; + } }; -class test_configtest : public CppUnit::TestFixture +class test_configtest + : public DGUnit { - CPPUNIT_TEST_SUITE(test_configtest); - CPPUNIT_TEST(loading_no_newline); - CPPUNIT_TEST(loading_equal_sign); - CPPUNIT_TEST(loading_newline); - CPPUNIT_TEST(loading_padding_space); - CPPUNIT_TEST(loading_padding_space_newline); - CPPUNIT_TEST(loading_padding_tab); - CPPUNIT_TEST(loading_padding_tab_newline); - CPPUNIT_TEST(loading_comment); - CPPUNIT_TEST(loading_inline_comment); - CPPUNIT_TEST(loading_single_quoted_string); - CPPUNIT_TEST(loading_double_quoted_string); - CPPUNIT_TEST(loading_error_no_key); - CPPUNIT_TEST(loading_error_no_value); - CPPUNIT_TEST(loading_error_string_not_terminated_single); - CPPUNIT_TEST(loading_error_string_not_terminated_double); - CPPUNIT_TEST_SUITE_END(); - public: - void setUp() - { - } + test_configtest() + { + DGUNIT_TEST(test_configtest::loading_no_newline); + DGUNIT_TEST(test_configtest::loading_equal_sign); + DGUNIT_TEST(test_configtest::loading_newline); + DGUNIT_TEST(test_configtest::loading_padding_space); + DGUNIT_TEST(test_configtest::loading_padding_space_newline); + DGUNIT_TEST(test_configtest::loading_padding_tab); + DGUNIT_TEST(test_configtest::loading_padding_tab_newline); + DGUNIT_TEST(test_configtest::loading_comment); + DGUNIT_TEST(test_configtest::loading_inline_comment); + DGUNIT_TEST(test_configtest::loading_single_quoted_string); + DGUNIT_TEST(test_configtest::loading_double_quoted_string); + DGUNIT_TEST(test_configtest::loading_error_no_key); + DGUNIT_TEST(test_configtest::loading_error_no_value); + DGUNIT_TEST(test_configtest::loading_error_string_not_terminated_single); + DGUNIT_TEST(test_configtest::loading_error_string_not_terminated_double); + } - void tearDown() - { - unlink("test.conf"); - } + void teardown() override + { + unlink("test.conf"); + } - void writeFile(const char* str) - { - FILE* fp = fopen("test.conf", "w"); - fprintf(fp, "%s", str); - fclose(fp); - } + void writeFile(const char* str) + { + FILE* fp = fopen("test.conf", "w"); + fprintf(fp, "%s", str); + fclose(fp); + } - void loading_no_newline() - { - writeFile("a:b"); + void loading_no_newline() + { + writeFile("a:b"); - TestConfigFile cf; - CPPUNIT_ASSERT_EQUAL(true, cf.load()); - CPPUNIT_ASSERT_EQUAL(std::string("b"), cf.getValue("a")); + TestConfigFile cf; + DGUNIT_ASSERT_EQUAL(true, cf.load()); + DGUNIT_ASSERT_EQUAL(std::string("b"), cf.getValue("a")); } - void loading_equal_sign() - { - writeFile(" a =\tb\t\n"); + void loading_equal_sign() + { + writeFile(" a =\tb\t\n"); - TestConfigFile cf; - CPPUNIT_ASSERT_EQUAL(true, cf.load()); - CPPUNIT_ASSERT_EQUAL(std::string("b"), cf.getValue("a")); + TestConfigFile cf; + DGUNIT_ASSERT_EQUAL(true, cf.load()); + DGUNIT_ASSERT_EQUAL(std::string("b"), cf.getValue("a")); } - void loading_newline() - { - writeFile("a:b\n"); + void loading_newline() + { + writeFile("a:b\n"); - TestConfigFile cf; - CPPUNIT_ASSERT_EQUAL(true, cf.load()); - CPPUNIT_ASSERT_EQUAL(std::string("b"), cf.getValue("a")); + TestConfigFile cf; + DGUNIT_ASSERT_EQUAL(true, cf.load()); + DGUNIT_ASSERT_EQUAL(std::string("b"), cf.getValue("a")); } - void loading_padding_space() - { - writeFile(" a : b "); + void loading_padding_space() + { + writeFile(" a : b "); - TestConfigFile cf; - CPPUNIT_ASSERT_EQUAL(true, cf.load()); - CPPUNIT_ASSERT_EQUAL(std::string("b"), cf.getValue("a")); + TestConfigFile cf; + DGUNIT_ASSERT_EQUAL(true, cf.load()); + DGUNIT_ASSERT_EQUAL(std::string("b"), cf.getValue("a")); } - void loading_padding_tab() - { - writeFile("\ta\t:\tb\t"); + void loading_padding_tab() + { + writeFile("\ta\t:\tb\t"); - TestConfigFile cf; - CPPUNIT_ASSERT_EQUAL(true, cf.load()); - CPPUNIT_ASSERT_EQUAL(std::string("b"), cf.getValue("a")); + TestConfigFile cf; + DGUNIT_ASSERT_EQUAL(true, cf.load()); + DGUNIT_ASSERT_EQUAL(std::string("b"), cf.getValue("a")); } - void loading_padding_space_newline() - { - writeFile(" a : b \n"); + void loading_padding_space_newline() + { + writeFile(" a : b \n"); - TestConfigFile cf; - CPPUNIT_ASSERT_EQUAL(true, cf.load()); - CPPUNIT_ASSERT_EQUAL(std::string("b"), cf.getValue("a")); + TestConfigFile cf; + DGUNIT_ASSERT_EQUAL(true, cf.load()); + DGUNIT_ASSERT_EQUAL(std::string("b"), cf.getValue("a")); } - void loading_padding_tab_newline() - { - writeFile("\ta\t:\tb\t\n"); + void loading_padding_tab_newline() + { + writeFile("\ta\t:\tb\t\n"); - TestConfigFile cf; - CPPUNIT_ASSERT_EQUAL(true, cf.load()); - CPPUNIT_ASSERT_EQUAL(std::string("b"), cf.getValue("a")); + TestConfigFile cf; + DGUNIT_ASSERT_EQUAL(true, cf.load()); + DGUNIT_ASSERT_EQUAL(std::string("b"), cf.getValue("a")); } - void loading_comment() - { - writeFile("# comment\na:b\n"); + void loading_comment() + { + writeFile("# comment\na:b\n"); - TestConfigFile cf; - CPPUNIT_ASSERT_EQUAL(true, cf.load()); - CPPUNIT_ASSERT_EQUAL(std::string("b"), cf.getValue("a")); + TestConfigFile cf; + DGUNIT_ASSERT_EQUAL(true, cf.load()); + DGUNIT_ASSERT_EQUAL(std::string("b"), cf.getValue("a")); } - void loading_inline_comment() - { - writeFile("a:b #comment\n"); + void loading_inline_comment() + { + writeFile("a:b #comment\n"); - TestConfigFile cf; - CPPUNIT_ASSERT_EQUAL(true, cf.load()); - CPPUNIT_ASSERT_EQUAL(std::string("b"), cf.getValue("a")); + TestConfigFile cf; + DGUNIT_ASSERT_EQUAL(true, cf.load()); + DGUNIT_ASSERT_EQUAL(std::string("b"), cf.getValue("a")); } - void loading_single_quoted_string() - { - writeFile("a: '#\"b\" ' \n"); + void loading_single_quoted_string() + { + writeFile("a: '#\"b\" ' \n"); - TestConfigFile cf; - CPPUNIT_ASSERT_EQUAL(true, cf.load()); - CPPUNIT_ASSERT_EQUAL(std::string("#\"b\" "), cf.getValue("a")); + TestConfigFile cf; + DGUNIT_ASSERT(cf.load()); + DGUNIT_ASSERT_EQUAL(std::string("#\"b\" "), cf.getValue("a")); } - void loading_double_quoted_string() - { - writeFile("a: \"#'b' \" \n"); + void loading_double_quoted_string() + { + writeFile("a: \"#'b' \" \n"); - TestConfigFile cf; - CPPUNIT_ASSERT_EQUAL(true, cf.load()); - CPPUNIT_ASSERT_EQUAL(std::string("#'b' "), cf.getValue("a")); + TestConfigFile cf; + DGUNIT_ASSERT_EQUAL(true, cf.load()); + DGUNIT_ASSERT_EQUAL(std::string("#'b' "), cf.getValue("a")); } - void loading_error_no_key() - { - writeFile(":foo"); + void loading_error_no_key() + { + writeFile(":foo"); - TestConfigFile cf; - CPPUNIT_ASSERT_EQUAL(false, cf.load()); + TestConfigFile cf; + DGUNIT_ASSERT_EQUAL(false, cf.load()); } - void loading_error_no_value() - { - writeFile("key"); + void loading_error_no_value() + { + writeFile("key"); - TestConfigFile cf; - CPPUNIT_ASSERT_EQUAL(false, cf.load()); + TestConfigFile cf; + DGUNIT_ASSERT_EQUAL(false, cf.load()); } - void loading_error_string_not_terminated_single() - { - writeFile("a:'b\n"); + void loading_error_string_not_terminated_single() + { + writeFile("a:'b\n"); - TestConfigFile cf; - CPPUNIT_ASSERT_EQUAL(false, cf.load()); + TestConfigFile cf; + DGUNIT_ASSERT_EQUAL(false, cf.load()); } - void loading_error_string_not_terminated_double() - { - writeFile("a:\"b\n"); + void loading_error_string_not_terminated_double() + { + writeFile("a:\"b\n"); - TestConfigFile cf; - CPPUNIT_ASSERT_EQUAL(false, cf.load()); + TestConfigFile cf; + DGUNIT_ASSERT_EQUAL(false, cf.load()); } }; // Registers the fixture into the 'registry' -CPPUNIT_TEST_SUITE_REGISTRATION(test_configtest); - - +static test_configtest test; diff --git a/test/dgunit.h b/test/dgunit.h index 5bb47bb..a010092 100644 --- a/test/dgunit.h +++ b/test/dgunit.h @@ -98,6 +98,7 @@ public: result.id = test_num; result.func = test.second; failed_tests.push_back(result); + ++failed; continue; } catch(...) diff --git a/test/drumkitcreatortest.cc b/test/drumkitcreatortest.cc index 1b6321b..bde58ef 100644 --- a/test/drumkitcreatortest.cc +++ b/test/drumkitcreatortest.cc @@ -24,28 +24,20 @@ * along with DrumGizmo; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#include <cppunit/extensions/HelperMacros.h> +#include "dgunit.h" #include "drumkit_creator.h" class DrumkitcreatorTest - : public CppUnit::TestFixture + : public DGUnit { - CPPUNIT_TEST_SUITE(DrumkitcreatorTest); - CPPUNIT_TEST(testTest); - CPPUNIT_TEST_SUITE_END(); - - DrumkitCreator drumkit_creator; - public: - void setUp() + DrumkitcreatorTest() { + DGUNIT_TEST(DrumkitcreatorTest::testTest); } - void tearDown() - { - - } + DrumkitCreator drumkit_creator; //! This just creates some drumkit. void testTest() @@ -55,4 +47,4 @@ public: }; // Registers the fixture into the 'registry' -CPPUNIT_TEST_SUITE_REGISTRATION(DrumkitcreatorTest); +static DrumkitcreatorTest test; diff --git a/test/drumkitparsertest.cc b/test/drumkitparsertest.cc index e2d30fc..10ffeb3 100644 --- a/test/drumkitparsertest.cc +++ b/test/drumkitparsertest.cc @@ -36,9 +36,7 @@ class DrumkitParserTest { public: DrumkitParserTest() - : DGUnit() { - std::cout << __PRETTY_FUNCTION__ << "\n"; DGUNIT_TEST(DrumkitParserTest::testTest); } @@ -134,4 +132,4 @@ public: }; // Registers the fixture into the 'registry' -DrumkitParserTest drumkit_parser_test; +static DrumkitParserTest test; diff --git a/test/enginetest.cc b/test/enginetest.cc index ad4315d..cb21609 100644 --- a/test/enginetest.cc +++ b/test/enginetest.cc @@ -24,7 +24,7 @@ * along with DrumGizmo; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#include <cppunit/extensions/HelperMacros.h> +#include "dgunit.h" #include <thread> #include <chrono> @@ -67,18 +67,16 @@ public: bool isFreewheeling() const { return true; } }; -class test_engine : public CppUnit::TestFixture +class test_engine : public DGUnit { - CPPUNIT_TEST_SUITE(test_engine); - CPPUNIT_TEST(loading); - CPPUNIT_TEST_SUITE_END(); +public: + test_engine() + { + DGUNIT_TEST(test_engine::loading); + } DrumkitCreator drumkit_creator; -public: - void setUp() {} - void tearDown() {} - void loading() { Settings settings; @@ -119,4 +117,4 @@ public: }; // Registers the fixture into the 'registry' -CPPUNIT_TEST_SUITE_REGISTRATION(test_engine); +static test_engine test; diff --git a/test/imagecachetest.cc b/test/imagecachetest.cc index 9321cf0..ea2c99d 100644 --- a/test/imagecachetest.cc +++ b/test/imagecachetest.cc @@ -24,7 +24,7 @@ * along with DrumGizmo; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#include <cppunit/extensions/HelperMacros.h> +#include "dgunit.h" #include <cassert> @@ -49,50 +49,48 @@ public: }; class ImageCacheTest - : public CppUnit::TestFixture + : public DGUnit { - CPPUNIT_TEST_SUITE(ImageCacheTest); - CPPUNIT_TEST(refCountTest); - CPPUNIT_TEST_SUITE_END(); - public: - void setUp() {} - void tearDown() {} + ImageCacheTest() + { + DGUNIT_TEST(ImageCacheTest::refCountTest); + } void refCountTest() { TestableImageCache imageCache; - CPPUNIT_ASSERT_EQUAL(imageCache.count("foo"), std::size_t(0u)); - CPPUNIT_ASSERT_EQUAL(imageCache.count("bar"), std::size_t(0u)); + DGUNIT_ASSERT_EQUAL(imageCache.count("foo"), std::size_t(0u)); + DGUNIT_ASSERT_EQUAL(imageCache.count("bar"), std::size_t(0u)); { auto image1{imageCache.getImage("foo")}; (void)image1; - CPPUNIT_ASSERT_EQUAL(imageCache.count("foo"), std::size_t(1u)); - CPPUNIT_ASSERT_EQUAL(imageCache.count("bar"), std::size_t(0u)); + DGUNIT_ASSERT_EQUAL(imageCache.count("foo"), std::size_t(1u)); + DGUNIT_ASSERT_EQUAL(imageCache.count("bar"), std::size_t(0u)); auto image2 = imageCache.getImage("bar"); - CPPUNIT_ASSERT_EQUAL(imageCache.count("foo"), std::size_t(1u)); - CPPUNIT_ASSERT_EQUAL(imageCache.count("bar"), std::size_t(1u)); + DGUNIT_ASSERT_EQUAL(imageCache.count("foo"), std::size_t(1u)); + DGUNIT_ASSERT_EQUAL(imageCache.count("bar"), std::size_t(1u)); auto image3 = imageCache.getImage("foo"); - CPPUNIT_ASSERT_EQUAL(imageCache.count("foo"), std::size_t(2u)); - CPPUNIT_ASSERT_EQUAL(imageCache.count("bar"), std::size_t(1u)); + DGUNIT_ASSERT_EQUAL(imageCache.count("foo"), std::size_t(2u)); + DGUNIT_ASSERT_EQUAL(imageCache.count("bar"), std::size_t(1u)); { auto image4 = imageCache.getImage("foo"); - CPPUNIT_ASSERT_EQUAL(imageCache.count("foo"), std::size_t(3u)); - CPPUNIT_ASSERT_EQUAL(imageCache.count("bar"), std::size_t(1u)); + DGUNIT_ASSERT_EQUAL(imageCache.count("foo"), std::size_t(3u)); + DGUNIT_ASSERT_EQUAL(imageCache.count("bar"), std::size_t(1u)); } - CPPUNIT_ASSERT_EQUAL(imageCache.count("foo"), std::size_t(2u)); - CPPUNIT_ASSERT_EQUAL(imageCache.count("bar"), std::size_t(1u)); + DGUNIT_ASSERT_EQUAL(imageCache.count("foo"), std::size_t(2u)); + DGUNIT_ASSERT_EQUAL(imageCache.count("bar"), std::size_t(1u)); } - CPPUNIT_ASSERT_EQUAL(imageCache.count("foo"), std::size_t(0u)); - CPPUNIT_ASSERT_EQUAL(imageCache.count("bar"), std::size_t(0u)); + DGUNIT_ASSERT_EQUAL(imageCache.count("foo"), std::size_t(0u)); + DGUNIT_ASSERT_EQUAL(imageCache.count("bar"), std::size_t(0u)); } }; // Registers the fixture into the 'registry' -CPPUNIT_TEST_SUITE_REGISTRATION(ImageCacheTest); +static ImageCacheTest test; diff --git a/test/instrumentparsertest.cc b/test/instrumentparsertest.cc index 44011e1..2fb81d0 100644 --- a/test/instrumentparsertest.cc +++ b/test/instrumentparsertest.cc @@ -24,29 +24,22 @@ * along with DrumGizmo; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#include <cppunit/extensions/HelperMacros.h> +#include "dgunit.h" #include <instrumentparser.h> #include "scopedfile.h" class InstrumentParserTest - : public CppUnit::TestFixture + : public DGUnit { - CPPUNIT_TEST_SUITE(InstrumentParserTest); - CPPUNIT_TEST(testTest); - CPPUNIT_TEST_SUITE_END(); - - Settings settings; - Random rand; - public: - void setUp() + InstrumentParserTest() { + DGUNIT_TEST(InstrumentParserTest::testTest); } - void tearDown() - { - } + Settings settings; + Random rand; //! This just creates some drumkit. void testTest() @@ -71,45 +64,45 @@ public: "</instrument>"); Instrument instrument(settings, rand); InstrumentParser parser(instrument, settings); - CPPUNIT_ASSERT_EQUAL(0, parser.parseFile(scoped_file.filename())); + DGUNIT_ASSERT_EQUAL(0, parser.parseFile(scoped_file.filename())); - CPPUNIT_ASSERT_EQUAL(std::string(""), instrument._group); - CPPUNIT_ASSERT_EQUAL(std::string("Snare"), instrument._name); - CPPUNIT_ASSERT_EQUAL(std::string(""), instrument._description); + DGUNIT_ASSERT_EQUAL(std::string(""), instrument._group); + DGUNIT_ASSERT_EQUAL(std::string("Snare"), instrument._name); + DGUNIT_ASSERT_EQUAL(std::string(""), instrument._description); - CPPUNIT_ASSERT(VersionStr("2.0.0") == instrument.version); + DGUNIT_ASSERT(VersionStr("2.0.0") == instrument.version); // NOTE: instrument.samples are the sample map belonging to version 1.0 - CPPUNIT_ASSERT_EQUAL(std::size_t(2), instrument.samplelist.size()); + DGUNIT_ASSERT_EQUAL(std::size_t(2), instrument.samplelist.size()); { const auto& sample = *instrument.samplelist[0]; - CPPUNIT_ASSERT_EQUAL(std::string("Snare-1"), sample.name); - CPPUNIT_ASSERT_EQUAL(0.00985718f, sample.power); - CPPUNIT_ASSERT_EQUAL(std::size_t(4), sample.audiofiles.size()); + DGUNIT_ASSERT_EQUAL(std::string("Snare-1"), sample.name); + DGUNIT_ASSERT_EQUAL(0.00985718f, sample.power); + DGUNIT_ASSERT_EQUAL(std::size_t(4), sample.audiofiles.size()); for(const auto& audiofile : sample.audiofiles) { - CPPUNIT_ASSERT_EQUAL(std::string("/tmp/1-Snare.wav"), audiofile.second->filename); + DGUNIT_ASSERT_EQUAL(std::string("/tmp/1-Snare.wav"), audiofile.second->filename); switch(audiofile.second->filechannel) { // NOTE: Channel numbers are zero based - they are 1 based in the xml case 0: - CPPUNIT_ASSERT_EQUAL(std::string("AmbLeft"), + DGUNIT_ASSERT_EQUAL(std::string("AmbLeft"), audiofile.second->instrument_channel->name); break; case 1: - CPPUNIT_ASSERT_EQUAL(std::string("AmbRight"), + DGUNIT_ASSERT_EQUAL(std::string("AmbRight"), audiofile.second->instrument_channel->name); break; case 11: - CPPUNIT_ASSERT_EQUAL(std::string("SnareBottom"), + DGUNIT_ASSERT_EQUAL(std::string("SnareBottom"), audiofile.second->instrument_channel->name); break; case 12: - CPPUNIT_ASSERT_EQUAL(std::string("SnareTop"), + DGUNIT_ASSERT_EQUAL(std::string("SnareTop"), audiofile.second->instrument_channel->name); break; default: - CPPUNIT_ASSERT(false); + DGUNIT_ASSERT(false); break; } } @@ -117,39 +110,39 @@ public: { const auto& sample = *instrument.samplelist[1]; - CPPUNIT_ASSERT_EQUAL(std::string("Snare-2"), sample.name); - CPPUNIT_ASSERT_EQUAL(0.0124808f, sample.power); - CPPUNIT_ASSERT_EQUAL(std::size_t(4), sample.audiofiles.size()); + DGUNIT_ASSERT_EQUAL(std::string("Snare-2"), sample.name); + DGUNIT_ASSERT_EQUAL(0.0124808f, sample.power); + DGUNIT_ASSERT_EQUAL(std::size_t(4), sample.audiofiles.size()); for(const auto& audiofile : sample.audiofiles) { - CPPUNIT_ASSERT_EQUAL(std::string("/tmp/2-Snare.wav"), audiofile.second->filename); + DGUNIT_ASSERT_EQUAL(std::string("/tmp/2-Snare.wav"), audiofile.second->filename); switch(audiofile.second->filechannel) { // NOTE: Channel numbers are zero based - they are 1 based in the xml case 0: - CPPUNIT_ASSERT_EQUAL(std::string("AmbLeft"), + DGUNIT_ASSERT_EQUAL(std::string("AmbLeft"), audiofile.second->instrument_channel->name); break; case 1: - CPPUNIT_ASSERT_EQUAL(std::string("AmbRight"), + DGUNIT_ASSERT_EQUAL(std::string("AmbRight"), audiofile.second->instrument_channel->name); break; case 11: - CPPUNIT_ASSERT_EQUAL(std::string("SnareBottom"), + DGUNIT_ASSERT_EQUAL(std::string("SnareBottom"), audiofile.second->instrument_channel->name); break; case 12: - CPPUNIT_ASSERT_EQUAL(std::string("SnareTop"), + DGUNIT_ASSERT_EQUAL(std::string("SnareTop"), audiofile.second->instrument_channel->name); break; default: - CPPUNIT_ASSERT(false); + DGUNIT_ASSERT(false); break; } } } -//CPPUNIT_ASSERT(ref.samples.values == instrument.samples.values); +//DGUNIT_ASSERT(ref.samples.values == instrument.samples.values); //std::vector<Sample*> samplelist; //std::deque<InstrumentChannel> instrument_channels; // @@ -162,4 +155,4 @@ public: }; // Registers the fixture into the 'registry' -CPPUNIT_TEST_SUITE_REGISTRATION(InstrumentParserTest); +static InstrumentParserTest test; diff --git a/test/lv2.cc b/test/lv2.cc index a386b7d..0f80dea 100644 --- a/test/lv2.cc +++ b/test/lv2.cc @@ -24,7 +24,7 @@ * along with DrumGizmo; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#include <cppunit/extensions/HelperMacros.h> +#include "dgunit.h" #include <thread> #include <chrono> @@ -54,21 +54,19 @@ enum class Ports { * - Run with buffer size a prime number (and thereby not power of 2) * - Run with HUGE number of midi events in one buffer (10000) */ -class test_lv2 : public CppUnit::TestFixture +class test_lv2 : public DGUnit { - CPPUNIT_TEST_SUITE(test_lv2); - CPPUNIT_TEST(open_and_verify); - CPPUNIT_TEST(run_no_ports_connected); - CPPUNIT_TEST(run_no_output_ports_connected); - CPPUNIT_TEST(test1); - CPPUNIT_TEST_SUITE_END(); +public: + test_lv2() + { + DGUNIT_TEST(test_lv2::open_and_verify); + DGUNIT_TEST(test_lv2::run_no_ports_connected); + DGUNIT_TEST(test_lv2::run_no_output_ports_connected); + DGUNIT_TEST(test_lv2::test1); + } DrumkitCreator drumkit_creator; -public: - void setUp() {} - void tearDown() {} - void open_and_verify() { int res; @@ -76,13 +74,13 @@ public: LV2TestHost h(LV2_PATH); res = h.open(DG_URI); - CPPUNIT_ASSERT_EQUAL(0, res); + DGUNIT_ASSERT_EQUAL(0, res); res = h.verify(); - CPPUNIT_ASSERT_EQUAL(0, res); + DGUNIT_ASSERT_EQUAL(0, res); res = h.close(); - CPPUNIT_ASSERT_EQUAL(0, res); + DGUNIT_ASSERT_EQUAL(0, res); } void run_no_ports_connected() @@ -92,13 +90,13 @@ public: LV2TestHost h(LV2_PATH); res = h.open(DG_URI); - CPPUNIT_ASSERT_EQUAL(0, res); + DGUNIT_ASSERT_EQUAL(0, res); res = h.verify(); - CPPUNIT_ASSERT_EQUAL(0, res); + DGUNIT_ASSERT_EQUAL(0, res); res = h.createInstance(44100); - CPPUNIT_ASSERT_EQUAL(0, res); + DGUNIT_ASSERT_EQUAL(0, res); const char config_fmt[] = "<config>\n" @@ -167,21 +165,21 @@ public: latency_regain); res = h.loadConfig(config, strlen(config)); - CPPUNIT_ASSERT_EQUAL(0, res); + DGUNIT_ASSERT_EQUAL(0, res); // run for 1 samples to trigger kit loading res = h.run(1); - CPPUNIT_ASSERT_EQUAL(0, res); + DGUNIT_ASSERT_EQUAL(0, res); std::this_thread::sleep_for(std::chrono::milliseconds(1)); // wait for kit to get loaded (async), res = h.run(100); - CPPUNIT_ASSERT_EQUAL(0, res); + DGUNIT_ASSERT_EQUAL(0, res); res = h.destroyInstance(); - CPPUNIT_ASSERT_EQUAL(0, res); + DGUNIT_ASSERT_EQUAL(0, res); res = h.close(); - CPPUNIT_ASSERT_EQUAL(0, res); + DGUNIT_ASSERT_EQUAL(0, res); } void run_no_output_ports_connected() @@ -191,13 +189,13 @@ public: LV2TestHost h(LV2_PATH); res = h.open(DG_URI); - CPPUNIT_ASSERT_EQUAL(0, res); + DGUNIT_ASSERT_EQUAL(0, res); res = h.verify(); - CPPUNIT_ASSERT_EQUAL(0, res); + DGUNIT_ASSERT_EQUAL(0, res); res = h.createInstance(44100); - CPPUNIT_ASSERT_EQUAL(0, res); + DGUNIT_ASSERT_EQUAL(0, res); const char config_fmt[] = "<config>\n" @@ -266,7 +264,7 @@ public: latency_regain); res = h.loadConfig(config, strlen(config)); - CPPUNIT_ASSERT_EQUAL(0, res); + DGUNIT_ASSERT_EQUAL(0, res); // Port buffers: char sequence_buffer[4096]; @@ -277,22 +275,22 @@ public: LV2TestHost::Sequence seq(sequence_buffer, sizeof(sequence_buffer)); res = h.connectPort((int)Ports::MidiPort, seq.data()); - CPPUNIT_ASSERT_EQUAL(0, res); + DGUNIT_ASSERT_EQUAL(0, res); // run for 1 samples to trigger kit loading res = h.run(1); - CPPUNIT_ASSERT_EQUAL(0, res); + DGUNIT_ASSERT_EQUAL(0, res); std::this_thread::sleep_for(std::chrono::milliseconds(1)); // wait for kit to get loaded (async), seq.addMidiNote(5, 1, 127); res = h.run(100); - CPPUNIT_ASSERT_EQUAL(0, res); + DGUNIT_ASSERT_EQUAL(0, res); res = h.destroyInstance(); - CPPUNIT_ASSERT_EQUAL(0, res); + DGUNIT_ASSERT_EQUAL(0, res); res = h.close(); - CPPUNIT_ASSERT_EQUAL(0, res); + DGUNIT_ASSERT_EQUAL(0, res); } void test1() @@ -302,13 +300,13 @@ public: LV2TestHost h(LV2_PATH); res = h.open(DG_URI); - CPPUNIT_ASSERT_EQUAL(0, res); + DGUNIT_ASSERT_EQUAL(0, res); res = h.verify(); - CPPUNIT_ASSERT_EQUAL(0, res); + DGUNIT_ASSERT_EQUAL(0, res); res = h.createInstance(44100); - CPPUNIT_ASSERT_EQUAL(0, res); + DGUNIT_ASSERT_EQUAL(0, res); const char config_fmt[] = "<config>\n" @@ -377,7 +375,7 @@ public: latency_regain); res = h.loadConfig(config, strlen(config)); - CPPUNIT_ASSERT_EQUAL(0, res); + DGUNIT_ASSERT_EQUAL(0, res); // Port buffers: char sequence_buffer[4096]; @@ -389,7 +387,7 @@ public: LV2TestHost::Sequence seq(sequence_buffer, sizeof(sequence_buffer)); res = h.connectPort((int)Ports::MidiPort, seq.data()); - CPPUNIT_ASSERT_EQUAL(0, res); + DGUNIT_ASSERT_EQUAL(0, res); for(int i = 0; i < 16; ++i) { @@ -399,11 +397,11 @@ public: } res += h.connectPort((int)Ports::AudioPortOffset + i, pcm_buffer[i]); } - CPPUNIT_ASSERT_EQUAL(0, res); + DGUNIT_ASSERT_EQUAL(0, res); // run for 1 samples to trigger kit loading res = h.run(1); - CPPUNIT_ASSERT_EQUAL(0, res); + DGUNIT_ASSERT_EQUAL(0, res); std::this_thread::sleep_for(std::chrono::seconds(1)); // wait for kit to get loaded (async), seq.addMidiNote(5, 1, 127); @@ -411,7 +409,7 @@ public: { res = h.run(10); std::this_thread::sleep_for(std::chrono::milliseconds(1)); - CPPUNIT_ASSERT_EQUAL(0, res); + DGUNIT_ASSERT_EQUAL(0, res); //printf("Iteration:\n"); //for(int k = 0; k < 16; k++) { @@ -428,7 +426,7 @@ public: seq.addMidiNote(5, 1, 127); res = h.run(10); std::this_thread::sleep_for(std::chrono::milliseconds(1)); - CPPUNIT_ASSERT_EQUAL(0, res); + DGUNIT_ASSERT_EQUAL(0, res); /* printf("Iteration:\n"); @@ -451,18 +449,18 @@ public: { for(int j = 0; j < 10; j++) { - CPPUNIT_ASSERT_EQUAL(((j==5)?comp_val.f:0), pcm_buffer[k][j]); + DGUNIT_ASSERT_EQUAL(((j==5)?comp_val.f:0), pcm_buffer[k][j]); } } seq.clear(); res = h.destroyInstance(); - CPPUNIT_ASSERT_EQUAL(0, res); + DGUNIT_ASSERT_EQUAL(0, res); res = h.close(); - CPPUNIT_ASSERT_EQUAL(0, res); + DGUNIT_ASSERT_EQUAL(0, res); } }; // Registers the fixture into the 'registry' -CPPUNIT_TEST_SUITE_REGISTRATION(test_lv2); +static test_lv2 test; diff --git a/test/memcheckertest.cc b/test/memcheckertest.cc deleted file mode 100644 index da5eae6..0000000 --- a/test/memcheckertest.cc +++ /dev/null @@ -1,121 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/*************************************************************************** - * memcheckertest.cc - * - * Mon Jan 18 15:08:31 CET 2016 - * Copyright 2016 André Nusser - * andre.nusser@googlemail.com - ****************************************************************************/ - -/* - * This file is part of DrumGizmo. - * - * DrumGizmo is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * DrumGizmo is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with DrumGizmo; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ - -// This test should include: -// ------------------------- -// * Load a small drumkit and check that the memchecker doesn't warn. -// -> this assumes that the system is not already swapping which is sane imo. -// * Load a huge drumkit and check that the memchecker does warn. -// * Load a kit where we exactly know the size of the audio files and check if it's correct. -// * Check if the amount of free ram is in a realistic range. -// -// NOTE: This test will fail if your system is currently swapping or has an extremely small amount of RAM. - -#include <cppunit/extensions/HelperMacros.h> - -#include "../src/memchecker.h" -#include "../src/drumkit.h" -#include "../src/drumkitparser.h" - -#include "drumkit_creator.h" - -class MemCheckerTest - : public CppUnit::TestFixture - , public MemChecker -{ - CPPUNIT_TEST_SUITE(MemCheckerTest); - CPPUNIT_TEST(small_drumkit); - CPPUNIT_TEST(huge_drumkit); - CPPUNIT_TEST(correct_size); - CPPUNIT_TEST(check_free_ram); - CPPUNIT_TEST_SUITE_END(); -private: - Settings settings; - DrumKit kit; - Random random; - DrumkitCreator drumkit_creator; - - const std::string small_kit_path = drumkit_creator.createSmallKit("small_kit"); - const std::string huge_kit_path = drumkit_creator.createHugeKit("huge_kit"); - const std::string audiofile = drumkit_creator.createMultiChannelWav("multi_channel.wav"); -public: - void setUp() - { - // just to be sure - kit.clear(); - } - - void tearDown() - {} - - void small_drumkit() - { - // load the small kit - DrumKitParser parser(settings, kit, random); - CPPUNIT_ASSERT(!parser.parseFile(small_kit_path)); - - // check if the memchecker thinks it fits into memory - CPPUNIT_ASSERT(enoughFreeMemory(kit)); - } - - void huge_drumkit() - { - // load the huge kit - DrumKitParser parser(settings, kit, random); - CPPUNIT_ASSERT(!parser.parseFile(huge_kit_path)); - - // check if the memchecker thinks it doesn't fit into memory - CPPUNIT_ASSERT(!enoughFreeMemory(kit)); - } - - void correct_size() - { - // check if the memchecker reports the right audiofile size - uint64_t bytes_per_channel = 2199332; - CPPUNIT_ASSERT_EQUAL(bytes_per_channel, calcBytesPerChannel(audiofile)); - - // load the huge kit - DrumKitParser parser(settings, kit, random); - CPPUNIT_ASSERT(!parser.parseFile(huge_kit_path)); - - // check if the protected method of the memchecker reports the correct size - uint64_t needed_memory = 71478290000; - CPPUNIT_ASSERT_EQUAL(needed_memory, calcNeededMemory(kit)); - } - - void check_free_ram() - { - // check if the protected method reports a sane value of free ram - uint64_t free_memory = calcFreeMemory(); - uint64_t min_free_memory = 1000; - uint64_t max_free_memory = 50000000000; - CPPUNIT_ASSERT(free_memory >= min_free_memory && free_memory <= max_free_memory); - } -}; - -// Registers the fixture into the 'registry' -CPPUNIT_TEST_SUITE_REGISTRATION(MemCheckerTest); diff --git a/test/notifiertest.cc b/test/notifiertest.cc index 2b2e92e..fe00597 100644 --- a/test/notifiertest.cc +++ b/test/notifiertest.cc @@ -24,7 +24,7 @@ * along with DrumGizmo; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#include <cppunit/extensions/HelperMacros.h> +#include "dgunit.h" #include <vector> @@ -48,15 +48,13 @@ public: }; class NotifierTest - : public CppUnit::TestFixture + : public DGUnit { - CPPUNIT_TEST_SUITE(NotifierTest); - CPPUNIT_TEST(testTest); - CPPUNIT_TEST_SUITE_END(); - public: - void setUp() { } - void tearDown() { } + NotifierTest() + { + DGUNIT_TEST(NotifierTest::testTest); + } //! This just creates some drumkit. void testTest() @@ -73,9 +71,9 @@ public: std::vector<Probe*> ref; ref.push_back(&foo1); ref.push_back(&foo2); - CPPUNIT_ASSERT_EQUAL(ref.size(), triggers.size()); - CPPUNIT_ASSERT_EQUAL(ref[0], triggers[0]); - CPPUNIT_ASSERT_EQUAL(ref[1], triggers[1]); + DGUNIT_ASSERT_EQUAL(ref.size(), triggers.size()); + DGUNIT_ASSERT_EQUAL(ref[0], triggers[0]); + DGUNIT_ASSERT_EQUAL(ref[1], triggers[1]); notifier.disconnect(&foo1); notifier.disconnect(&foo2); triggers.clear(); @@ -88,9 +86,9 @@ public: std::vector<Probe*> ref; ref.push_back(&foo2); ref.push_back(&foo1); - CPPUNIT_ASSERT_EQUAL(ref.size(), triggers.size()); - CPPUNIT_ASSERT_EQUAL(ref[0], triggers[0]); - CPPUNIT_ASSERT_EQUAL(ref[1], triggers[1]); + DGUNIT_ASSERT_EQUAL(ref.size(), triggers.size()); + DGUNIT_ASSERT_EQUAL(ref[0], triggers[0]); + DGUNIT_ASSERT_EQUAL(ref[1], triggers[1]); notifier.disconnect(&foo1); notifier.disconnect(&foo2); triggers.clear(); @@ -100,4 +98,4 @@ public: }; // Registers the fixture into the 'registry' -CPPUNIT_TEST_SUITE_REGISTRATION(NotifierTest); +static NotifierTest test; diff --git a/test/paintertest.cc b/test/paintertest.cc index 75f97fa..c6e8615 100644 --- a/test/paintertest.cc +++ b/test/paintertest.cc @@ -24,7 +24,7 @@ * along with DrumGizmo; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#include <cppunit/extensions/HelperMacros.h> +#include "dgunit.h" #include "../plugingui/canvas.h" #include "../plugingui/painter.h" @@ -49,16 +49,14 @@ private: }; class PainterTest - : public CppUnit::TestFixture + : public DGUnit { - CPPUNIT_TEST_SUITE(PainterTest); - CPPUNIT_TEST(testDrawImage); - CPPUNIT_TEST(testDrawText); - CPPUNIT_TEST_SUITE_END(); - public: - void setUp() {} - void tearDown() {} + PainterTest() + { + DGUNIT_TEST(PainterTest::testDrawImage); + DGUNIT_TEST(PainterTest::testDrawText); + } void testDrawImage() { @@ -158,4 +156,4 @@ public: }; // Registers the fixture into the 'registry' -CPPUNIT_TEST_SUITE_REGISTRATION(PainterTest); +static PainterTest test; diff --git a/test/randomtest.cc b/test/randomtest.cc index 16a16c4..bc79432 100644 --- a/test/randomtest.cc +++ b/test/randomtest.cc @@ -24,7 +24,7 @@ * along with DrumGizmo; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#include <cppunit/extensions/HelperMacros.h> +#include "dgunit.h" #include <random.h> @@ -32,22 +32,14 @@ #include <cmath> class RandomTest - : public CppUnit::TestFixture + : public DGUnit { - CPPUNIT_TEST_SUITE(RandomTest); - CPPUNIT_TEST(rangeTest); - CPPUNIT_TEST(normalTest); - CPPUNIT_TEST(chooseTest); - CPPUNIT_TEST_SUITE_END(); - public: - void setUp() + RandomTest() { - } - - void tearDown() - { - + DGUNIT_TEST(RandomTest::rangeTest); + DGUNIT_TEST(RandomTest::normalTest); + DGUNIT_TEST(RandomTest::chooseTest); } void rangeTest() @@ -63,16 +55,16 @@ public: { float rand_float = rand.floatInRange(float_lb, float_ub); float rand_int = rand.intInRange(int_lb, int_ub); - CPPUNIT_ASSERT(rand_float >= float_lb && rand_float <= float_ub); - CPPUNIT_ASSERT(rand_int >= int_lb && rand_int <= int_ub); + DGUNIT_ASSERT(rand_float >= float_lb && rand_float <= float_ub); + DGUNIT_ASSERT(rand_int >= int_lb && rand_int <= int_ub); } - + // check if the series of random numbers is the one we expect // for a certain seed. rand = Random(666); - CPPUNIT_ASSERT_EQUAL(0, rand.intInRange(0,100)); - CPPUNIT_ASSERT_EQUAL(61, rand.intInRange(0,100)); - CPPUNIT_ASSERT_EQUAL(23, rand.intInRange(0,100)); + DGUNIT_ASSERT_EQUAL(0, rand.intInRange(0,100)); + DGUNIT_ASSERT_EQUAL(61, rand.intInRange(0,100)); + DGUNIT_ASSERT_EQUAL(23, rand.intInRange(0,100)); } void normalTest() @@ -97,8 +89,8 @@ public: float estimated_stddev = sqrt(sum_of_squares/nr_of_samples - estimated_mean*estimated_mean); float epsilon = 0.1; - CPPUNIT_ASSERT(estimated_mean >= real_mean-epsilon && estimated_mean <= real_mean+epsilon); - CPPUNIT_ASSERT(estimated_stddev >= real_stddev-epsilon && estimated_stddev <= real_stddev+epsilon); + DGUNIT_ASSERT(estimated_mean >= real_mean-epsilon && estimated_mean <= real_mean+epsilon); + DGUNIT_ASSERT(estimated_stddev >= real_stddev-epsilon && estimated_stddev <= real_stddev+epsilon); } void chooseTest() @@ -110,10 +102,10 @@ public: for (int i=0; i<nr_of_samples; i++) { - CPPUNIT_ASSERT_EQUAL(42, rand.choose(vec)); + DGUNIT_ASSERT_EQUAL(42, rand.choose(vec)); } } }; // Registers the fixture into the 'registry' -CPPUNIT_TEST_SUITE_REGISTRATION(RandomTest); +static RandomTest test; diff --git a/test/resampler.cc b/test/resampler.cc index 2b6862d..12732c1 100644 --- a/test/resampler.cc +++ b/test/resampler.cc @@ -24,7 +24,7 @@ * along with DrumGizmo; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#include <cppunit/extensions/HelperMacros.h> +#include "dgunit.h" #include "../src/chresampler.h" @@ -32,80 +32,79 @@ static float round(float a) { return a<0.5?0:1; } -class test_resampler : public CppUnit::TestFixture +class test_resampler + : public DGUnit { - CPPUNIT_TEST_SUITE(test_resampler); - CPPUNIT_TEST(resampling); - CPPUNIT_TEST(resampling_buffer_sizes); - CPPUNIT_TEST_SUITE_END(); - public: - void setUp() {} - void tearDown() {} - - void resampling() - { - CHResampler r; - CPPUNIT_ASSERT_EQUAL(1.0, r.getRatio()); - - r.setup(44100, 48000); - CPPUNIT_ASSERT_EQUAL(44100.0/48000.0, r.getRatio()); - - float in[BUFSZ]; - for(int i = 0; i < BUFSZ; i++) in[i] = 0;//(float)i/(float)BUFSZ; - in[100] = 1.0; - - float out[BUFSZ]; - r.setInputSamples(in, sizeof(in) / sizeof(float)); - r.setOutputSamples(out, sizeof(out) / sizeof(float)); - r.process(); - CPPUNIT_ASSERT_EQUAL((size_t)0, r.getInputSampleCount()); - - // CPPUNIT_ASSERT_EQUAL(, r.getOutputSampleCount()); - - int outidx = -1; - int inidx = -1; - for(int i = 0; i < BUFSZ - (int)r.getOutputSampleCount(); i++) { - if(in[i] == 1.0) inidx = i; - if(round(out[i]) == 1.0) outidx = i; - //printf("in[% 4d]\t= %f\t", i, in[i]); - //printf("out[% 4d]\t= %f\n", i, out[i]); - } - - CPPUNIT_ASSERT(inidx != -1); - CPPUNIT_ASSERT(outidx != -1); - - //printf("inidx: %d - outidx: %d\n", inidx, outidx); - //CPPUNIT_ASSERT_EQUAL(71, inidx - outidx); // This does not make sense... + test_resampler() + { + DGUNIT_TEST(test_resampler::resampling); + DGUNIT_TEST(test_resampler::resampling_buffer_sizes); } - void resampling_buffer_sizes() - { - CHResampler r; - CPPUNIT_ASSERT_EQUAL(1.0, r.getRatio()); - - double infs = 24000; - double outfs = 48000; - r.setup(infs, outfs); - CPPUNIT_ASSERT_EQUAL(infs / outfs, r.getRatio()); - - float in[BUFSZ]; - float out[(int)(BUFSZ / r.getRatio())]; - - // Preload resampler - r.setOutputSamples(out, 1); - while(r.getOutputSampleCount()) { - r.setInputSamples(in, 1); - r.process(); - } - - r.setInputSamples(in, sizeof(in) / sizeof(float)); - r.setOutputSamples(out, sizeof(out) / sizeof(float)); - r.process(); - CPPUNIT_ASSERT_EQUAL((size_t)0, r.getInputSampleCount()); - CPPUNIT_ASSERT_EQUAL((size_t)0, r.getOutputSampleCount()); - } + void resampling() + { + CHResampler r; + DGUNIT_ASSERT_EQUAL(1.0, r.getRatio()); + + r.setup(44100, 48000); + DGUNIT_ASSERT_EQUAL(44100.0/48000.0, r.getRatio()); + + float in[BUFSZ]; + for(int i = 0; i < BUFSZ; i++) in[i] = 0;//(float)i/(float)BUFSZ; + in[100] = 1.0; + + float out[BUFSZ]; + r.setInputSamples(in, sizeof(in) / sizeof(float)); + r.setOutputSamples(out, sizeof(out) / sizeof(float)); + r.process(); + DGUNIT_ASSERT_EQUAL((size_t)0, r.getInputSampleCount()); + + // DGUNIT_ASSERT_EQUAL(, r.getOutputSampleCount()); + + int outidx = -1; + int inidx = -1; + for(int i = 0; i < BUFSZ - (int)r.getOutputSampleCount(); i++) { + if(in[i] == 1.0) inidx = i; + if(round(out[i]) == 1.0) outidx = i; + //printf("in[% 4d]\t= %f\t", i, in[i]); + //printf("out[% 4d]\t= %f\n", i, out[i]); + } + + DGUNIT_ASSERT(inidx != -1); + DGUNIT_ASSERT(outidx != -1); + + //printf("inidx: %d - outidx: %d\n", inidx, outidx); + //DGUNIT_ASSERT_EQUAL(71, inidx - outidx); // This does not make sense... + } + + void resampling_buffer_sizes() + { + CHResampler r; + DGUNIT_ASSERT_EQUAL(1.0, r.getRatio()); + + double infs = 24000; + double outfs = 48000; + r.setup(infs, outfs); + DGUNIT_ASSERT_EQUAL(infs / outfs, r.getRatio()); + + float in[BUFSZ]; + float out[(int)(BUFSZ / r.getRatio())]; + + // Preload resampler + r.setOutputSamples(out, 1); + while(r.getOutputSampleCount()) { + r.setInputSamples(in, 1); + r.process(); + } + + r.setInputSamples(in, sizeof(in) / sizeof(float)); + r.setOutputSamples(out, sizeof(out) / sizeof(float)); + r.process(); + DGUNIT_ASSERT_EQUAL((size_t)0, r.getInputSampleCount()); + DGUNIT_ASSERT_EQUAL((size_t)0, r.getOutputSampleCount()); + } }; // Registers the fixture into the 'registry' -CPPUNIT_TEST_SUITE_REGISTRATION(test_resampler); +static test_resampler test; diff --git a/test/resource_test.cc b/test/resource_test.cc index 93dae8b..2e88c45 100644 --- a/test/resource_test.cc +++ b/test/resource_test.cc @@ -24,7 +24,7 @@ * along with DrumGizmo; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#include <cppunit/extensions/HelperMacros.h> +#include "dgunit.h" #include "../plugingui/resource.h" @@ -42,37 +42,35 @@ public: } }; -class ResourceTest : public CppUnit::TestFixture +class ResourceTest : public DGUnit { - CPPUNIT_TEST_SUITE(ResourceTest); - CPPUNIT_TEST(externalReadTest); - CPPUNIT_TEST(internalReadTest); - CPPUNIT_TEST_SUITE_END(); +public: + ResourceTest() + { + DGUNIT_TEST(ResourceTest::externalReadTest); + DGUNIT_TEST(ResourceTest::internalReadTest); + } DrumkitCreator drumkit_creator; -public: - void setUp() {} - void tearDown() {} - void externalReadTest() { auto filename = drumkit_creator.create0000Wav("0000.wav"); ResourceTester rc(filename); - CPPUNIT_ASSERT(!rc.probeIsInternal()); - CPPUNIT_ASSERT(rc.valid()); - CPPUNIT_ASSERT_EQUAL((size_t)46, rc.size()); + DGUNIT_ASSERT(!rc.probeIsInternal()); + DGUNIT_ASSERT(rc.valid()); + DGUNIT_ASSERT_EQUAL((size_t)46, rc.size()); } void internalReadTest() { ResourceTester rc(":resources/bg.png"); - CPPUNIT_ASSERT(rc.probeIsInternal()); - CPPUNIT_ASSERT(rc.valid()); - CPPUNIT_ASSERT_EQUAL((size_t)1123, rc.size()); + DGUNIT_ASSERT(rc.probeIsInternal()); + DGUNIT_ASSERT(rc.valid()); + DGUNIT_ASSERT_EQUAL((size_t)1123, rc.size()); } }; // Registers the fixture into the 'registry' -CPPUNIT_TEST_SUITE_REGISTRATION(ResourceTest); +static ResourceTest test; diff --git a/test/scopedfile.cc b/test/scopedfile.cc index 02af3f8..e63972e 100644 --- a/test/scopedfile.cc +++ b/test/scopedfile.cc @@ -43,7 +43,8 @@ ScopedFile::ScopedFile(const std::string& data) char templ[] = "/tmp/dg-scoped-file-XXXXXX"; // buffer for filename pimpl->fd = mkstemp(templ); pimpl->filename = templ; - write(pimpl->fd, data.data(), data.size()); + auto sz = write(pimpl->fd, data.data(), data.size()); + (void)sz; close(pimpl->fd); } diff --git a/test/semaphoretest.cc b/test/semaphoretest.cc index 1c137c4..c99e9a6 100644 --- a/test/semaphoretest.cc +++ b/test/semaphoretest.cc @@ -24,7 +24,7 @@ * along with DrumGizmo; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#include <cppunit/extensions/HelperMacros.h> +#include "dgunit.h" #include <cassert> @@ -45,16 +45,15 @@ std::chrono::nanoseconds dist(const std::chrono::duration<float>& a, } class SemaphoreTest - : public CppUnit::TestFixture + : public DGUnit { - CPPUNIT_TEST_SUITE(SemaphoreTest); - CPPUNIT_TEST(timeoutTest); - CPPUNIT_TEST_SUITE_END(); - public: - void setUp() {} - void tearDown() {} + SemaphoreTest() + { + DGUNIT_TEST(SemaphoreTest::timeoutTest); + } +public: void timeoutTest() { Semaphore sem(0); @@ -62,26 +61,26 @@ public: { // 1000ms timeout auto start = std::chrono::steady_clock::now(); bool res = sem.wait(std::chrono::milliseconds(1000)); - CPPUNIT_ASSERT(!res); // false means timeout + DGUNIT_ASSERT(!res); // false means timeout auto stop = std::chrono::steady_clock::now(); // Allow +/-1ms skew - CPPUNIT_ASSERT(dist((stop - start), std::chrono::milliseconds(1000)) + DGUNIT_ASSERT(dist((stop - start), std::chrono::milliseconds(1000)) < std::chrono::milliseconds(60)); } { // 100ms timeout auto start = std::chrono::steady_clock::now(); bool res = sem.wait(std::chrono::milliseconds(100)); - CPPUNIT_ASSERT(!res); // false means timeout + DGUNIT_ASSERT(!res); // false means timeout auto stop = std::chrono::steady_clock::now(); // Allow +/-1ms skew - CPPUNIT_ASSERT(dist((stop - start), std::chrono::milliseconds(100)) + DGUNIT_ASSERT(dist((stop - start), std::chrono::milliseconds(100)) < std::chrono::milliseconds(60)); } } }; // Registers the fixture into the 'registry' -CPPUNIT_TEST_SUITE_REGISTRATION(SemaphoreTest); +static SemaphoreTest test; diff --git a/test/syncedsettings.cc b/test/syncedsettings.cc index 1d8e102..5e1e2fd 100644 --- a/test/syncedsettings.cc +++ b/test/syncedsettings.cc @@ -24,180 +24,189 @@ * along with DrumGizmo; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#include <cppunit/extensions/HelperMacros.h> +#include "dgunit.h" #include <syncedsettings.h> class SyncedSettingsTest - : public CppUnit::TestFixture { - - CPPUNIT_TEST_SUITE(SyncedSettingsTest); - CPPUNIT_TEST(groupCanBeDefaultInitialized); - CPPUNIT_TEST(groupDataCanBeCopied); - - CPPUNIT_TEST(accessorCanGetFields); - CPPUNIT_TEST(accessorCanSetFields); - - CPPUNIT_TEST(groupHasCopyCtor); - CPPUNIT_TEST(groupHasMoveCtor); - CPPUNIT_TEST(groupHasCopyAssignOp); - CPPUNIT_TEST(groupHasMoveAssignOp); - - CPPUNIT_TEST(mimicRealUse); - CPPUNIT_TEST_SUITE_END(); - - private: - struct TestData { - float foo; - bool bar; - std::string msg; - }; - - public: - void setUp() {} - void tearDown() {} - - void groupCanBeDefaultInitialized() { - Group<TestData> data; - } - - void groupDataCanBeCopied() { - Group<TestData> data; - (TestData)data; // copies + : public DGUnit +{ +public: + SyncedSettingsTest() + { + DGUNIT_TEST(SyncedSettingsTest::groupCanBeDefaultInitialized); + DGUNIT_TEST(SyncedSettingsTest::groupDataCanBeCopied); + + DGUNIT_TEST(SyncedSettingsTest::accessorCanGetFields); + DGUNIT_TEST(SyncedSettingsTest::accessorCanSetFields); + + DGUNIT_TEST(SyncedSettingsTest::groupHasCopyCtor); + DGUNIT_TEST(SyncedSettingsTest::groupHasMoveCtor); + DGUNIT_TEST(SyncedSettingsTest::groupHasCopyAssignOp); + DGUNIT_TEST(SyncedSettingsTest::groupHasMoveAssignOp); + + DGUNIT_TEST(SyncedSettingsTest::mimicRealUse); + } + +private: + struct TestData + { + float foo; + bool bar; + std::string msg; + }; + +public: + void groupCanBeDefaultInitialized() + { + Group<TestData> data; + } + + void groupDataCanBeCopied() + { + Group<TestData> data; + (TestData)data; // copies + } + + void accessorCanSetFields() + { + Group<TestData> data; + { + Accessor<TestData> a{data}; + a.data.foo = 3.f; + a.data.bar = false; + a.data.msg = "hello"; } - - void accessorCanSetFields() { - Group<TestData> data; - { - Accessor<TestData> a{data}; - a.data.foo = 3.f; - a.data.bar = false; - a.data.msg = "hello"; - } - TestData copy = data; - CPPUNIT_ASSERT_EQUAL(copy.foo, 3.f); - CPPUNIT_ASSERT_EQUAL(copy.bar, false); - CPPUNIT_ASSERT_EQUAL(copy.msg, std::string{"hello"}); + TestData copy = data; + DGUNIT_ASSERT_EQUAL(copy.foo, 3.f); + DGUNIT_ASSERT_EQUAL(copy.bar, false); + DGUNIT_ASSERT_EQUAL(copy.msg, std::string{"hello"}); + } + + void accessorCanGetFields() + { + Group<TestData> data; + { + Accessor<TestData> a{data}; + a.data.foo = 3.f; + a.data.bar = false; + a.data.msg = "hello"; } - - void accessorCanGetFields() { - Group<TestData> data; - { - Accessor<TestData> a{data}; - a.data.foo = 3.f; - a.data.bar = false; - a.data.msg = "hello"; - } - // now read - { - Accessor<TestData> a{data}; - CPPUNIT_ASSERT_EQUAL(a.data.foo, 3.f); - CPPUNIT_ASSERT_EQUAL(a.data.bar, false); - CPPUNIT_ASSERT_EQUAL(a.data.msg, std::string{"hello"}); - } + // now read + { + Accessor<TestData> a{data}; + DGUNIT_ASSERT_EQUAL(a.data.foo, 3.f); + DGUNIT_ASSERT_EQUAL(a.data.bar, false); + DGUNIT_ASSERT_EQUAL(a.data.msg, std::string{"hello"}); } - - void groupHasCopyCtor() { - Group<TestData> tmp; - { - Accessor<TestData> a{tmp}; - a.data.foo = 3.f; - a.data.bar = false; - a.data.msg = "hello"; - } - Group<TestData> data{tmp}; - TestData copy = data; - CPPUNIT_ASSERT_EQUAL(copy.foo, 3.f); - CPPUNIT_ASSERT_EQUAL(copy.bar, false); - CPPUNIT_ASSERT_EQUAL(copy.msg, std::string{"hello"}); + } + + void groupHasCopyCtor() + { + Group<TestData> tmp; + { + Accessor<TestData> a{tmp}; + a.data.foo = 3.f; + a.data.bar = false; + a.data.msg = "hello"; } - - void groupHasMoveCtor() { - Group<TestData> tmp; - { - Accessor<TestData> a{tmp}; - a.data.foo = 3.f; - a.data.bar = false; - a.data.msg = "hello"; - } - Group<TestData> data{std::move(tmp)}; - TestData copy = data; - CPPUNIT_ASSERT_EQUAL(copy.foo, 3.f); - CPPUNIT_ASSERT_EQUAL(copy.bar, false); - CPPUNIT_ASSERT_EQUAL(copy.msg, std::string{"hello"}); + Group<TestData> data{tmp}; + TestData copy = data; + DGUNIT_ASSERT_EQUAL(copy.foo, 3.f); + DGUNIT_ASSERT_EQUAL(copy.bar, false); + DGUNIT_ASSERT_EQUAL(copy.msg, std::string{"hello"}); + } + + void groupHasMoveCtor() + { + Group<TestData> tmp; + { + Accessor<TestData> a{tmp}; + a.data.foo = 3.f; + a.data.bar = false; + a.data.msg = "hello"; } - - void groupHasCopyAssignOp() { - Group<TestData> tmp; - { - Accessor<TestData> a{tmp}; - a.data.foo = 3.f; - a.data.bar = false; - a.data.msg = "hello"; - } - Group<TestData> data = tmp; - TestData copy = data; - CPPUNIT_ASSERT_EQUAL(copy.foo, 3.f); - CPPUNIT_ASSERT_EQUAL(copy.bar, false); - CPPUNIT_ASSERT_EQUAL(copy.msg, std::string{"hello"}); + Group<TestData> data{std::move(tmp)}; + TestData copy = data; + DGUNIT_ASSERT_EQUAL(copy.foo, 3.f); + DGUNIT_ASSERT_EQUAL(copy.bar, false); + DGUNIT_ASSERT_EQUAL(copy.msg, std::string{"hello"}); + } + + void groupHasCopyAssignOp() + { + Group<TestData> tmp; + { + Accessor<TestData> a{tmp}; + a.data.foo = 3.f; + a.data.bar = false; + a.data.msg = "hello"; } - - void groupHasMoveAssignOp() { - Group<TestData> tmp; - { - Accessor<TestData> a{tmp}; - a.data.foo = 3.f; - a.data.bar = false; - a.data.msg = "hello"; - } - Group<TestData> data = std::move(tmp); - TestData copy = data; - CPPUNIT_ASSERT_EQUAL(copy.foo, 3.f); - CPPUNIT_ASSERT_EQUAL(copy.bar, false); - CPPUNIT_ASSERT_EQUAL(copy.msg, std::string{"hello"}); + Group<TestData> data = tmp; + TestData copy = data; + DGUNIT_ASSERT_EQUAL(copy.foo, 3.f); + DGUNIT_ASSERT_EQUAL(copy.bar, false); + DGUNIT_ASSERT_EQUAL(copy.msg, std::string{"hello"}); + } + + void groupHasMoveAssignOp() + { + Group<TestData> tmp; + { + Accessor<TestData> a{tmp}; + a.data.foo = 3.f; + a.data.bar = false; + a.data.msg = "hello"; } - - void mimicRealUse() { - struct Settings { - struct Foo { - float a{5}; - float b{3}; - bool enabled{true}; - }; - struct Bar { - std::string label{"empty"}; - float bla{0.f}; - }; - - Group<Foo> foo; - Group<Bar> bar; + Group<TestData> data = std::move(tmp); + TestData copy = data; + DGUNIT_ASSERT_EQUAL(copy.foo, 3.f); + DGUNIT_ASSERT_EQUAL(copy.bar, false); + DGUNIT_ASSERT_EQUAL(copy.msg, std::string{"hello"}); + } + + void mimicRealUse() + { + struct Settings + { + struct Foo { + float a{5}; + float b{3}; + bool enabled{true}; }; - - Settings s; - - // set bar settings - { - Accessor<Settings::Bar> tmp{s.bar}; - tmp.data.label = "hello world"; - tmp.data.bla = 3.14f; - } - - // read foo settings - { - Accessor<Settings::Foo> tmp{s.foo}; - if (tmp.data.enabled) { - // do some while locked - } - } - // or: - Settings::Foo copy = s.foo; - if (copy.enabled) { - // do some stuff without locking + struct Bar { + std::string label{"empty"}; + float bla{0.f}; + }; + + Group<Foo> foo; + Group<Bar> bar; + }; + + Settings s; + + // set bar settings + { + Accessor<Settings::Bar> tmp{s.bar}; + tmp.data.label = "hello world"; + tmp.data.bla = 3.14f; + } + + // read foo settings + { + Accessor<Settings::Foo> tmp{s.foo}; + if (tmp.data.enabled) { + // do some while locked } - CPPUNIT_ASSERT(copy.enabled); } + // or: + Settings::Foo copy = s.foo; + if (copy.enabled) { + // do some stuff without locking + } + DGUNIT_ASSERT(copy.enabled); + } }; // Registers the fixture into the 'registry' -CPPUNIT_TEST_SUITE_REGISTRATION(SyncedSettingsTest); - +static SyncedSettingsTest test; diff --git a/test/test.cc b/test/test.cc deleted file mode 100644 index 925a938..0000000 --- a/test/test.cc +++ /dev/null @@ -1,53 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/*************************************************************************** - * test.cc - * - * Fri Nov 29 17:45:40 CET 2013 - * Copyright 2013 Bent Bisballe Nyeng - * deva@aasimon.org - ****************************************************************************/ - -/* - * This file is part of DrumGizmo. - * - * DrumGizmo is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * DrumGizmo is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with DrumGizmo; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ -#include <cppunit/XmlOutputter.h> -#include <cppunit/extensions/TestFactoryRegistry.h> -#include <cppunit/ui/text/TestRunner.h> - -#include <fstream> - -int main(int argc, char* argv[]) -{ - // Get the top level suite from the registry - CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest(); - - // Adds the test to the list of test to run - CppUnit::TextUi::TestRunner runner; - runner.addTest( suite ); - - std::ofstream myfile; - myfile.open("result_" OUTPUT ".xml"); - runner.setOutputter(new CppUnit::XmlOutputter(&runner.result(), myfile)); - - // Run the tests. - bool wasSucessful = runner.run(); - - myfile.close(); - - // Return error code 1 if the one of test failed. - return wasSucessful ? 0 : 1; -} |