summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--Makefile.am10
-rw-r--r--test/test_mixramp.cxx82
3 files changed, 94 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index a20d3c54b..a520f12d0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -68,7 +68,9 @@ test/run_tcp_connect
test/test_pcm
test/dump_rva2
test/dump_text_file
+test/test_util
test/test_byte_reverse
+test/test_mixramp
test/test_vorbis_encoder
test/DumpDatabase
diff --git a/Makefile.am b/Makefile.am
index dea7bdb56..48a143f39 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1058,6 +1058,7 @@ if ENABLE_TEST
C_TESTS = \
test/test_util \
test/test_byte_reverse \
+ test/test_mixramp \
test/test_pcm \
test/test_queue_priority
@@ -1483,6 +1484,15 @@ test_test_byte_reverse_LDADD = \
libutil.a \
$(CPPUNIT_LIBS)
+test_test_mixramp_SOURCES = \
+ src/Log.cxx \
+ test/test_mixramp.cxx
+test_test_mixramp_CPPFLAGS = $(AM_CPPFLAGS) $(CPPUNIT_CFLAGS) -DCPPUNIT_HAVE_RTTI=0
+test_test_mixramp_CXXFLAGS = $(AM_CXXFLAGS) -Wno-error=deprecated-declarations
+test_test_mixramp_LDADD = \
+ $(GLIB_LIBS) \
+ $(CPPUNIT_LIBS)
+
test_test_pcm_SOURCES = \
test/test_pcm_util.hxx \
test/test_pcm_dither.cxx \
diff --git a/test/test_mixramp.cxx b/test/test_mixramp.cxx
new file mode 100644
index 000000000..83d266d48
--- /dev/null
+++ b/test/test_mixramp.cxx
@@ -0,0 +1,82 @@
+/*
+ * Unit tests for mixramp_interpolate()
+ */
+
+#include "config.h"
+#include "CrossFade.cxx"
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/ui/text/TestRunner.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <string.h>
+
+class MixRampTest : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(MixRampTest);
+ CPPUNIT_TEST(TestInterpolate);
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+ void TestInterpolate() {
+ const char *input = "1.0 0.00;3.0 0.10;6.0 2.50;";
+
+ char *foo = strdup(input);
+ CPPUNIT_ASSERT(!std::isnan(mixramp_interpolate(foo, 0)));
+ free(foo);
+
+ foo = strdup(input);
+ CPPUNIT_ASSERT_EQUAL(float(0),
+ mixramp_interpolate(foo, 1));
+ free(foo);
+
+ foo = strdup(input);
+ CPPUNIT_ASSERT_EQUAL(float(0.1),
+ mixramp_interpolate(foo, 3));
+ free(foo);
+
+ foo = strdup(input);
+ CPPUNIT_ASSERT_EQUAL(float(2.5),
+ mixramp_interpolate(foo, 6));
+ free(foo);
+
+ foo = strdup(input);
+ CPPUNIT_ASSERT(!std::isnan(mixramp_interpolate(foo, 3)));
+ free(foo);
+
+ foo = strdup(input);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(float(0.05),
+ mixramp_interpolate(foo, 2),
+ 0.05);
+ free(foo);
+
+ foo = strdup(input);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(float(1.3),
+ mixramp_interpolate(foo, 4.5),
+ 0.05);
+ free(foo);
+
+ foo = strdup(input);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(float(0.9),
+ mixramp_interpolate(foo, 4),
+ 0.05);
+ free(foo);
+
+ foo = strdup(input);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(float(1.7),
+ mixramp_interpolate(foo, 5),
+ 0.05);
+ free(foo);
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(MixRampTest);
+
+int
+main(gcc_unused int argc, gcc_unused char **argv)
+{
+ CppUnit::TextUi::TestRunner runner;
+ auto &registry = CppUnit::TestFactoryRegistry::getRegistry();
+ runner.addTest(registry.makeTest());
+ return runner.run() ? EXIT_SUCCESS : EXIT_FAILURE;
+}