diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/Makefile.am | 26 | ||||
-rw-r--r-- | test/audiocacheidmanagertest.cc | 14 | ||||
-rw-r--r-- | test/curvemaptest.cc | 267 | ||||
-rw-r--r-- | test/dgreftest/midiinputengine.h | 8 | ||||
-rw-r--r-- | test/paintertest.cc | 2 | ||||
-rw-r--r-- | test/powermaptest.cc | 51 |
6 files changed, 294 insertions, 74 deletions
diff --git a/test/Makefile.am b/test/Makefile.am index 6441fd3..0827cae 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -8,7 +8,7 @@ TESTS = resource enginetest paintertest configfile audiocache \ randomtest atomictest syncedsettingstest imagecachetest \ semaphoretest drumkitcreatortest bytesizeparsertest notifiertest \ dgxmlparsertest domloadertest configparsertest midimapparsertest \ - eventsdstest powermaptest midimappertest + eventsdstest curvemaptest midimappertest if WITH_NLS TESTS += translationtest @@ -51,7 +51,8 @@ audiocache_CXXFLAGS = \ -I$(top_srcdir)/src \ -I$(top_srcdir)/hugin -DDISABLE_HUGIN \ $(PTHREAD_CFLAGS) \ - $(SNDFILE_CFLAGS) + $(SNDFILE_CFLAGS) \ + -Wno-deprecated-declarations audiocache_LDFLAGS = $(PTHREAD_LIBS) $(SNDFILE_LIBS) audiocache_SOURCES = \ $(top_srcdir)/src/audiocache.cc \ @@ -72,7 +73,8 @@ audiocachefile_CXXFLAGS = \ -I$(top_srcdir)/src \ -I$(top_srcdir)/hugin -DDISABLE_HUGIN \ $(PTHREAD_CFLAGS) \ - $(SNDFILE_CFLAGS) + $(SNDFILE_CFLAGS) \ + -Wno-deprecated-declarations audiocachefile_LDFLAGS = $(PTHREAD_LIBS) $(SNDFILE_LIBS) audiocachefile_SOURCES = \ $(top_srcdir)/src/audiocachefile.cc \ @@ -102,7 +104,8 @@ audiocacheeventhandler_CXXFLAGS = \ -I$(top_srcdir)/src \ -I$(top_srcdir)/hugin -DDISABLE_HUGIN \ $(PTHREAD_CFLAGS) \ - $(SNDFILE_CFLAGS) + $(SNDFILE_CFLAGS) \ + -Wno-deprecated-declarations audiocacheeventhandler_LDFLAGS = $(PTHREAD_LIBS) $(SNDFILE_LIBS) audiocacheeventhandler_SOURCES = \ $(top_srcdir)/src/audiocacheeventhandler.cc \ @@ -218,7 +221,8 @@ semaphoretest_CXXFLAGS = \ $(DEBUG_FLAGS) \ -I$(top_srcdir)/src \ -I$(top_srcdir)/hugin \ - $(PTHREAD_CFLAGS) + $(PTHREAD_CFLAGS) \ + -Wno-deprecated-declarations semaphoretest_LDFLAGS = $(PTHREAD_LIBS) semaphoretest_SOURCES = \ $(top_srcdir)/hugin/hugin.c \ @@ -325,14 +329,14 @@ eventsdstest_SOURCES = \ eventsdstest.cc \ uunit/uunit.cc -powermaptest_CXXFLAGS = \ - -I$(top_srcdir)/test/uunit -DOUTPUT=\"powermaptest\" \ +curvemaptest_CXXFLAGS = \ + -I$(top_srcdir)/test/uunit -DOUTPUT=\"curvemaptest\" \ $(DEBUG_FLAGS) \ -I$(top_srcdir)/src -powermaptest_LDFLAGS = -powermaptest_SOURCES = \ - $(top_srcdir)/src/powermap.cc \ - powermaptest.cc \ +curvemaptest_LDFLAGS = +curvemaptest_SOURCES = \ + $(top_srcdir)/src/curvemap.cc \ + curvemaptest.cc \ uunit/uunit.cc midimappertest_CXXFLAGS = \ diff --git a/test/audiocacheidmanagertest.cc b/test/audiocacheidmanagertest.cc index c84926b..9d8be25 100644 --- a/test/audiocacheidmanagertest.cc +++ b/test/audiocacheidmanagertest.cc @@ -52,39 +52,39 @@ public: TestableAudioCacheIDManager manager; manager.init(2); - cache_t c1; c1.afile = (AudioCacheFile*)1; + CacheBuffer c1; c1.afile = (AudioCacheFile*)1; auto id1 = manager.registerID(c1); uUNIT_ASSERT(id1 != CACHE_DUMMYID); uUNIT_ASSERT(id1 != CACHE_NOID); uUNIT_ASSERT_EQUAL(1, manager.getAvailableIDs()); - cache_t c2; c2.afile = (AudioCacheFile*)2; + CacheBuffer c2; c2.afile = (AudioCacheFile*)2; auto id2 = manager.registerID(c2); uUNIT_ASSERT(id2 != CACHE_DUMMYID); uUNIT_ASSERT(id2 != CACHE_NOID); uUNIT_ASSERT_EQUAL(0, manager.getAvailableIDs()); - cache_t c3; c3.afile = (AudioCacheFile*)3; + CacheBuffer c3; c3.afile = (AudioCacheFile*)3; auto id3 = manager.registerID(c3); uUNIT_ASSERT(id3 == CACHE_DUMMYID); uUNIT_ASSERT_EQUAL(0, manager.getAvailableIDs()); - cache_t& tc1 = manager.getCache(id1); + CacheBuffer& tc1 = manager.getCache(id1); uUNIT_ASSERT_EQUAL(c1.afile, tc1.afile); - cache_t& tc2 = manager.getCache(id2); + CacheBuffer& tc2 = manager.getCache(id2); uUNIT_ASSERT_EQUAL(c2.afile, tc2.afile); manager.releaseID(id1); uUNIT_ASSERT_EQUAL(1, manager.getAvailableIDs()); - cache_t c4; c4.afile = (AudioCacheFile*)4; + CacheBuffer c4; c4.afile = (AudioCacheFile*)4; auto id4 = manager.registerID(c4); uUNIT_ASSERT(id4 != CACHE_DUMMYID); uUNIT_ASSERT(id4 != CACHE_NOID); uUNIT_ASSERT_EQUAL(0, manager.getAvailableIDs()); - cache_t& tc4 = manager.getCache(id4); + CacheBuffer& tc4 = manager.getCache(id4); uUNIT_ASSERT_EQUAL(c4.afile, tc4.afile); manager.releaseID(id2); diff --git a/test/curvemaptest.cc b/test/curvemaptest.cc new file mode 100644 index 0000000..cb90d1b --- /dev/null +++ b/test/curvemaptest.cc @@ -0,0 +1,267 @@ +/* -*- Mode: c++ -*- */ +/*************************************************************************** + * curvemaptest.cc + * + * Fri Jul 26 19:43:32 CEST 2024 + * Copyright 2024 Sander Vocke + * sandervocke@gmail.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 <uunit.h> +#include <map> + +#include "../src/curvemap.h" +#include <iostream> +#include <iomanip> + +class test_curvemaptest + : public uUnit +{ +public: + test_curvemaptest() + { + uUNIT_TEST(test_curvemaptest::check_default); + uUNIT_TEST(test_curvemaptest::check_default_invert); + uUNIT_TEST(test_curvemaptest::check_default_disabled_shelf); + uUNIT_TEST(test_curvemaptest::check_default_disabled_shelf_invert); + uUNIT_TEST(test_curvemaptest::check_fixed1_075_025); + uUNIT_TEST(test_curvemaptest::check_fixed1_075_025_invert); + uUNIT_TEST(test_curvemaptest::check_shelf_060); + uUNIT_TEST(test_curvemaptest::check_shelf_060_invert); + uUNIT_TEST(test_curvemaptest::check_reset); + } + + const std::map<double, double> default_map = { + {0.0, 1e-4}, + {1e-4, 1e-4}, + {0.1, 0.1}, + {0.2, 0.2}, + {0.3, 0.3}, + {0.4, 0.4}, + {0.5, 0.5}, + {0.6, 0.6}, + {0.7, 0.7}, + {0.8, 0.8}, + {0.9, 0.9}, + {1.0 - 1e-4, 1.0 - 1e-4}, + {1.0, 1.0 - 1e-4} + }; + + const std::map<double, double> identity_map = { + {0.0, 0.0}, + {0.1, 0.1}, + {0.2, 0.2}, + {0.3, 0.3}, + {0.4, 0.4}, + {0.5, 0.5}, + {0.6, 0.6}, + {0.7, 0.7}, + {0.8, 0.8}, + {0.9, 0.9}, + {1.0, 1.0} + }; + + const std::map<double, double> fixed1_075_025_map = { + {0.0, 1e-4}, + {1e-4, 1e-4}, + {0, 0.0001}, + {0.1, 0.0295469705015421}, + {0.2, 0.0536915548145771}, + {0.3, 0.0760560110211372}, + {0.4, 0.100195862352848}, + {0.5, 0.129666686058044}, + {0.6, 0.168024003505707}, + {0.7, 0.218823373317719}, + {0.8, 0.325357049703598}, + {0.9, 0.64416378736496}, + {1.0 - 1e-4, 1.0 - 1e-4}, + {1.0, 1.0 - 1e-4} + }; + + const std::map<double, double> shelf_060_map = { + {0.0, 1e-4}, + {1e-4, 1e-4}, + {0.1, 0.1}, + {0.2, 0.2}, + {0.3, 0.3}, + {0.4, 0.4}, + {0.5, 0.5}, + {0.6, 0.6}, + {0.7, 0.6}, + {0.8, 0.6}, + {0.9, 0.6}, + {1.0, 0.6} + }; + + void check_default() + { + auto dataset = this->default_map; + + CurveMap map; + + for (auto& entry : dataset) { + auto in = entry.first; + auto expect = entry.second; + uASSERT_EQUAL(expect, map.map(in)); + } + } + + void check_reset() + { + auto dataset = this->default_map; + + CurveMap map; + map.setFixed0({0.1, 0.2}); + map.setFixed1({0.2, 0.3}); + map.setFixed2({0.3, 0.4}); + map.setInvert(!map.getInvert()); + map.setShelf(!map.getShelf()); + + bool any_difference = false; + for (auto& entry : dataset) { + auto in = entry.first; + auto expect = entry.second; + if (expect != map.map(in)) { + any_difference = true; + break; + } + } + + uASSERT(any_difference); + + map.reset(); + + for (auto& entry : dataset) { + auto in = entry.first; + auto expect = entry.second; + uASSERT_EQUAL(expect, map.map(in)); + } + } + + void check_default_invert() + { + auto dataset = this->default_map; + + CurveMap map; + map.setInvert(true); + + for (auto& entry : dataset) { + auto in = 1.0 - entry.first; + auto expect = entry.second; + uASSERT_EQUAL(expect, map.map(in)); + } + } + + void check_default_disabled_shelf() + { + auto dataset = this->identity_map; + + CurveMap map; + map.setShelf(false); + map.setFixed2({0.6, 0.6}); + + for (auto& entry : dataset) { + auto in = entry.first; + auto expect = entry.second; + // std::cout << "{" << in << ", " << std::setprecision (15) << map.map(in) << "}," << std::endl; // FIXME + uASSERT_EQUAL(expect, map.map(in)); + } + } + + void check_default_disabled_shelf_invert() + { + auto dataset = this->identity_map; + + CurveMap map; + map.setShelf(false); + map.setFixed2({0.6, 0.6}); + map.setInvert(true); + + for (auto& entry : dataset) { + auto in = 1.0 - entry.first; + auto expect = entry.second; + uASSERT_EQUAL(expect, map.map(in)); + } + } + + void check_fixed1_075_025() + { + auto dataset = this->fixed1_075_025_map; + + CurveMap map; + map.setFixed1({0.75, 0.25}); + + for (auto& entry : dataset) { + auto in = entry.first; + auto expect = entry.second; + // std::cout << "{" << in << ", " << std::setprecision (15) << map.map(in) << "}," << std::endl; // FIXME + uASSERT_EQUAL(expect, map.map(in)); + } + } + + void check_fixed1_075_025_invert() + { + auto dataset = this->fixed1_075_025_map; + + CurveMap map; + map.setFixed1({0.75, 0.25}); + map.setInvert(true); + + for (auto& entry : dataset) { + auto in = 1.0 - entry.first; + auto expect = entry.second; + uASSERT_EQUAL(expect, map.map(in)); + } + } + + void check_shelf_060() + { + auto dataset = this->shelf_060_map; + + CurveMap map; + map.setFixed2({0.6, 0.6}); + map.setShelf(true); + + for (auto& entry : dataset) { + auto in = entry.first; + auto expect = entry.second; + uASSERT_EQUAL(expect, map.map(in)); + } + } + + void check_shelf_060_invert() + { + auto dataset = this->shelf_060_map; + + CurveMap map; + map.setFixed2({0.6, 0.6}); + map.setShelf(true); + map.setInvert(true); + + for (auto& entry : dataset) { + auto in = 1.0 - entry.first; + auto expect = entry.second; + uASSERT_EQUAL(expect, map.map(in)); + } + } +}; + +// Registers the fixture into the 'registry' +static test_curvemaptest test; diff --git a/test/dgreftest/midiinputengine.h b/test/dgreftest/midiinputengine.h index ffd22f8..e76a182 100644 --- a/test/dgreftest/midiinputengine.h +++ b/test/dgreftest/midiinputengine.h @@ -26,15 +26,15 @@ */ #pragma once -#include <audioinputenginemidi.h> -#include <midimapper.h> -#include <midimapparser.h> #include <string> #include <vector> -#include <event.h> #include <smf.h> +#include <audioinputenginemidi.h> +#include <midimapper.h> +#include <midimapparser.h> + class MidifileInputEngine : public AudioInputEngineMidi { diff --git a/test/paintertest.cc b/test/paintertest.cc index 5a1c44a..10b96dc 100644 --- a/test/paintertest.cc +++ b/test/paintertest.cc @@ -91,7 +91,7 @@ public: has_alpha = alpha; image_data.resize(_width * _height); - image_data_raw.resize(_width * _height); + image_data_raw.resize(4 * _width * _height); // Store x and y coordinates as red and green colour components for(std::uint8_t x = 0; x < _width; ++x) diff --git a/test/powermaptest.cc b/test/powermaptest.cc deleted file mode 100644 index bef5bdc..0000000 --- a/test/powermaptest.cc +++ /dev/null @@ -1,51 +0,0 @@ -/* -*- Mode: c++ -*- */ -/*************************************************************************** - * powermaptest.cc - * - * Sun Apr 19 23:23:37 CEST 2020 - * Copyright 2020 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 <uunit.h> - -#include "../src/powermap.h" - -class test_powermaptest - : public uUnit -{ -public: - test_powermaptest() - { - uUNIT_TEST(test_powermaptest::check_values); - } - - void check_values() - { - Powermap powermap; - - // TODO - // std::cout << powermap.map(.8) << std::endl; - // uUNIT_ASSERT_EQUAL(powermap.map(.8), .8); - } -}; - -// Registers the fixture into the 'registry' -static test_powermaptest test; |