diff options
author | Max Kellermann <max@duempel.org> | 2013-10-16 21:55:00 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-10-16 23:36:36 +0200 |
commit | 401a799a1b5de5d70a6b4c1d49235af0d5618f37 (patch) | |
tree | 503db86df98400dac818fa3bbfbe20e2055a1fa4 | |
parent | ba98518c69d0501e67ef707f0d718cc678851415 (diff) |
test: use the CPPUNIT framework for unit tests
-rw-r--r-- | Makefile.am | 11 | ||||
-rw-r--r-- | configure.ac | 6 | ||||
-rw-r--r-- | test/test_byte_reverse.cxx | 62 | ||||
-rw-r--r-- | test/test_pcm_all.hxx | 150 | ||||
-rw-r--r-- | test/test_pcm_channels.cxx | 38 | ||||
-rw-r--r-- | test/test_pcm_dither.cxx | 14 | ||||
-rw-r--r-- | test/test_pcm_format.cxx | 32 | ||||
-rw-r--r-- | test/test_pcm_main.cxx | 35 | ||||
-rw-r--r-- | test/test_pcm_mix.cxx | 18 | ||||
-rw-r--r-- | test/test_pcm_pack.cxx | 8 | ||||
-rw-r--r-- | test/test_pcm_util.hxx | 6 | ||||
-rw-r--r-- | test/test_pcm_volume.cxx | 126 | ||||
-rw-r--r-- | test/test_queue_priority.cxx | 75 |
13 files changed, 326 insertions, 255 deletions
diff --git a/Makefile.am b/Makefile.am index ebc4ac920..e37d49f15 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1411,9 +1411,11 @@ endif test_test_byte_reverse_SOURCES = \ test/test_byte_reverse.cxx +test_test_byte_reverse_CPPFLAGS = $(AM_CPPFLAGS) $(CPPUNIT_CFLAGS) -DCPPUNIT_HAVE_RTTI=0 +test_test_byte_reverse_CXXFLAGS = $(AM_CXXFLAGS) -Wno-error=deprecated-declarations test_test_byte_reverse_LDADD = \ libutil.a \ - $(GLIB_LIBS) + $(CPPUNIT_LIBS) test_test_pcm_SOURCES = \ test/test_pcm_util.hxx \ @@ -1425,18 +1427,23 @@ test_test_pcm_SOURCES = \ test/test_pcm_mix.cxx \ test/test_pcm_all.hxx \ test/test_pcm_main.cxx +test_test_pcm_CPPFLAGS = $(AM_CPPFLAGS) $(CPPUNIT_CFLAGS) -DCPPUNIT_HAVE_RTTI=0 +test_test_pcm_CXXFLAGS = $(AM_CXXFLAGS) -Wno-error=deprecated-declarations test_test_pcm_LDADD = \ $(PCM_LIBS) \ libutil.a \ + $(CPPUNIT_LIBS) \ $(GLIB_LIBS) test_test_queue_priority_SOURCES = \ src/Queue.cxx \ test/test_queue_priority.cxx +test_test_queue_priority_CPPFLAGS = $(AM_CPPFLAGS) $(CPPUNIT_CFLAGS) -DCPPUNIT_HAVE_RTTI=0 +test_test_queue_priority_CXXFLAGS = $(AM_CXXFLAGS) -Wno-error=deprecated-declarations test_test_queue_priority_LDADD = \ libsystem.a \ libutil.a \ - $(GLIB_LIBS) + $(CPPUNIT_LIBS) noinst_PROGRAMS += src/pcm/dsd2pcm/dsd2pcm diff --git a/configure.ac b/configure.ac index 0a98943cf..d411502e0 100644 --- a/configure.ac +++ b/configure.ac @@ -1483,6 +1483,12 @@ AM_CONDITIONAL(ENABLE_DOCUMENTATION, test x$enable_documentation = xyes) dnl --------------------------------------------------------------------------- dnl test suite dnl --------------------------------------------------------------------------- + +if test "x$enable_test" = xyes; then + PKG_CHECK_MODULES([CPPUNIT], [cppunit],, + [AC_MSG_ERROR([cppunit not found])]) +fi + AM_CONDITIONAL(ENABLE_TEST, test "x$enable_test" = xyes) dnl --------------------------------------------------------------------------- diff --git a/test/test_byte_reverse.cxx b/test/test_byte_reverse.cxx index 67e394454..2730dbdb0 100644 --- a/test/test_byte_reverse.cxx +++ b/test/test_byte_reverse.cxx @@ -19,11 +19,34 @@ #include "util/ByteReverse.hxx" #include "util/Macros.hxx" +#include "Compiler.h" -#include <glib.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> +#include <cppunit/ui/text/TestRunner.h> -static void -test_byte_reverse_2(void) +#include <string.h> + +class ByteReverseTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(ByteReverseTest); + CPPUNIT_TEST(TestByteReverse2); + CPPUNIT_TEST(TestByteReverse3); + CPPUNIT_TEST(TestByteReverse4); + CPPUNIT_TEST(TestByteReverse5); + CPPUNIT_TEST_SUITE_END(); + +public: + void TestByteReverse2(); + void TestByteReverse3(); + void TestByteReverse4(); + void TestByteReverse5(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(ByteReverseTest); + +void +ByteReverseTest::TestByteReverse2() { static const char src[] = "123456"; static const char result[] = "214365"; @@ -31,11 +54,11 @@ test_byte_reverse_2(void) reverse_bytes(dest, (const uint8_t *)src, (const uint8_t *)(src + ARRAY_SIZE(src) - 1), 2); - g_assert_cmpstr((const char *)dest, ==, result); + CPPUNIT_ASSERT(strcmp(result, (const char *)dest) == 0); } -static void -test_byte_reverse_3(void) +void +ByteReverseTest::TestByteReverse3() { static const char src[] = "123456"; static const char result[] = "321654"; @@ -43,11 +66,11 @@ test_byte_reverse_3(void) reverse_bytes(dest, (const uint8_t *)src, (const uint8_t *)(src + ARRAY_SIZE(src) - 1), 3); - g_assert_cmpstr((const char *)dest, ==, result); + CPPUNIT_ASSERT(strcmp(result, (const char *)dest) == 0); } -static void -test_byte_reverse_4(void) +void +ByteReverseTest::TestByteReverse4() { static const char src[] = "12345678"; static const char result[] = "43218765"; @@ -55,11 +78,11 @@ test_byte_reverse_4(void) reverse_bytes(dest, (const uint8_t *)src, (const uint8_t *)(src + ARRAY_SIZE(src) - 1), 4); - g_assert_cmpstr((const char *)dest, ==, result); + CPPUNIT_ASSERT(strcmp(result, (const char *)dest) == 0); } -static void -test_byte_reverse_5(void) +void +ByteReverseTest::TestByteReverse5() { static const char src[] = "1234567890"; static const char result[] = "5432109876"; @@ -67,17 +90,14 @@ test_byte_reverse_5(void) reverse_bytes(dest, (const uint8_t *)src, (const uint8_t *)(src + ARRAY_SIZE(src) - 1), 5); - g_assert_cmpstr((const char *)dest, ==, result); + CPPUNIT_ASSERT(strcmp(result, (const char *)dest) == 0); } int -main(int argc, char **argv) +main(gcc_unused int argc, gcc_unused char **argv) { - g_test_init (&argc, &argv, NULL); - g_test_add_func("/util/byte_reverse/2", test_byte_reverse_2); - g_test_add_func("/util/byte_reverse/3", test_byte_reverse_3); - g_test_add_func("/util/byte_reverse/4", test_byte_reverse_4); - g_test_add_func("/util/byte_reverse/5", test_byte_reverse_5); - - g_test_run(); + CppUnit::TextUi::TestRunner runner; + auto ®istry = CppUnit::TestFactoryRegistry::getRegistry(); + runner.addTest(registry.makeTest()); + return runner.run() ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/test/test_pcm_all.hxx b/test/test_pcm_all.hxx index 18202454b..2a0aa8628 100644 --- a/test/test_pcm_all.hxx +++ b/test/test_pcm_all.hxx @@ -20,61 +20,99 @@ #ifndef MPD_TEST_PCM_ALL_HXX #define MPD_TEST_PCM_ALL_HXX -void -test_pcm_dither_24(); - -void -test_pcm_dither_32(); - -void -test_pcm_pack_24(); - -void -test_pcm_unpack_24(); - -void -test_pcm_channels_16(); - -void -test_pcm_channels_32(); - -void -test_pcm_volume_8(); - -void -test_pcm_volume_16(); - -void -test_pcm_volume_24(); - -void -test_pcm_volume_32(); - -void -test_pcm_volume_float(); - -void -test_pcm_format_8_to_16(); - -void -test_pcm_format_16_to_24(); - -void -test_pcm_format_16_to_32(); - -void -test_pcm_format_float(); - -void -test_pcm_mix_8(); - -void -test_pcm_mix_16(); - -void -test_pcm_mix_24(); - -void -test_pcm_mix_32(); +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> + +class PcmDitherTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(PcmDitherTest); + CPPUNIT_TEST(TestDither24); + CPPUNIT_TEST(TestDither32); + CPPUNIT_TEST_SUITE_END(); + +public: + void TestDither24(); + void TestDither32(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(PcmDitherTest); + +class PcmPackTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(PcmPackTest); + CPPUNIT_TEST(TestPack24); + CPPUNIT_TEST(TestUnpack24); + CPPUNIT_TEST_SUITE_END(); + +public: + void TestPack24(); + void TestUnpack24(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(PcmPackTest); + +class PcmChannelsTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(PcmChannelsTest); + CPPUNIT_TEST(TestChannels16); + CPPUNIT_TEST(TestChannels32); + CPPUNIT_TEST_SUITE_END(); + +public: + void TestChannels16(); + void TestChannels32(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(PcmChannelsTest); + +class PcmVolumeTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(PcmVolumeTest); + CPPUNIT_TEST(TestVolume8); + CPPUNIT_TEST(TestVolume16); + CPPUNIT_TEST(TestVolume24); + CPPUNIT_TEST(TestVolume32); + CPPUNIT_TEST(TestVolumeFloat); + CPPUNIT_TEST_SUITE_END(); + +public: + void TestVolume8(); + void TestVolume16(); + void TestVolume24(); + void TestVolume32(); + void TestVolumeFloat(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(PcmVolumeTest); + +class PcmFormatTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(PcmFormatTest); + CPPUNIT_TEST(TestFormat8to16); + CPPUNIT_TEST(TestFormat16to24); + CPPUNIT_TEST(TestFormat16to32); + CPPUNIT_TEST(TestFormatFloat); + CPPUNIT_TEST_SUITE_END(); + +public: + void TestFormat8to16(); + void TestFormat16to24(); + void TestFormat16to32(); + void TestFormatFloat(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(PcmFormatTest); + +class PcmMixTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(PcmMixTest); + CPPUNIT_TEST(TestMix8); + CPPUNIT_TEST(TestMix16); + CPPUNIT_TEST(TestMix24); + CPPUNIT_TEST(TestMix32); + CPPUNIT_TEST_SUITE_END(); + +public: + void TestMix8(); + void TestMix16(); + void TestMix24(); + void TestMix32(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(PcmMixTest); #endif diff --git a/test/test_pcm_channels.cxx b/test/test_pcm_channels.cxx index 6642ed3d4..85c872674 100644 --- a/test/test_pcm_channels.cxx +++ b/test/test_pcm_channels.cxx @@ -23,10 +23,8 @@ #include "pcm/PcmChannels.hxx" #include "pcm/PcmBuffer.hxx" -#include <glib.h> - void -test_pcm_channels_16() +PcmChannelsTest::TestChannels16() { constexpr unsigned N = 256; const auto src = TestDataBuffer<int16_t, N * 2>(); @@ -39,26 +37,26 @@ test_pcm_channels_16() const int16_t *dest = pcm_convert_channels_16(buffer, 1, 2, src, sizeof(src), &dest_size); - g_assert(dest != NULL); - g_assert_cmpint(dest_size, ==, sizeof(src) / 2); + CPPUNIT_ASSERT(dest != NULL); + CPPUNIT_ASSERT_EQUAL(sizeof(src) / 2, dest_size); for (unsigned i = 0; i < N; ++i) - g_assert_cmpint(dest[i], ==, - (src[i * 2] + src[i * 2 + 1]) / 2); + CPPUNIT_ASSERT_EQUAL(int16_t((src[i * 2] + src[i * 2 + 1]) / 2), + dest[i]); /* mono to stereo */ dest = pcm_convert_channels_16(buffer, 2, 1, src, sizeof(src), &dest_size); - g_assert(dest != NULL); - g_assert_cmpint(dest_size, ==, sizeof(src) * 2); + CPPUNIT_ASSERT(dest != NULL); + CPPUNIT_ASSERT_EQUAL(sizeof(src) * 2, dest_size); for (unsigned i = 0; i < N; ++i) { - g_assert_cmpint(dest[i * 2], ==, src[i]); - g_assert_cmpint(dest[i * 2 + 1], ==, src[i]); + CPPUNIT_ASSERT_EQUAL(src[i], dest[i * 2]); + CPPUNIT_ASSERT_EQUAL(src[i], dest[i * 2 + 1]); } } void -test_pcm_channels_32() +PcmChannelsTest::TestChannels32() { constexpr unsigned N = 256; const auto src = TestDataBuffer<int32_t, N * 2>(); @@ -71,20 +69,20 @@ test_pcm_channels_32() const int32_t *dest = pcm_convert_channels_32(buffer, 1, 2, src, sizeof(src), &dest_size); - g_assert(dest != NULL); - g_assert_cmpint(dest_size, ==, sizeof(src) / 2); + CPPUNIT_ASSERT(dest != NULL); + CPPUNIT_ASSERT_EQUAL(sizeof(src) / 2, dest_size); for (unsigned i = 0; i < N; ++i) - g_assert_cmpint(dest[i], ==, - ((int64_t)src[i * 2] + (int64_t)src[i * 2 + 1]) / 2); + CPPUNIT_ASSERT_EQUAL(int32_t(((int64_t)src[i * 2] + (int64_t)src[i * 2 + 1]) / 2), + dest[i]); /* mono to stereo */ dest = pcm_convert_channels_32(buffer, 2, 1, src, sizeof(src), &dest_size); - g_assert(dest != NULL); - g_assert_cmpint(dest_size, ==, sizeof(src) * 2); + CPPUNIT_ASSERT(dest != NULL); + CPPUNIT_ASSERT_EQUAL(sizeof(src) * 2, dest_size); for (unsigned i = 0; i < N; ++i) { - g_assert_cmpint(dest[i * 2], ==, src[i]); - g_assert_cmpint(dest[i * 2 + 1], ==, src[i]); + CPPUNIT_ASSERT_EQUAL(src[i], dest[i * 2]); + CPPUNIT_ASSERT_EQUAL(src[i], dest[i * 2 + 1]); } } diff --git a/test/test_pcm_dither.cxx b/test/test_pcm_dither.cxx index 5694c17f8..5df64c2d1 100644 --- a/test/test_pcm_dither.cxx +++ b/test/test_pcm_dither.cxx @@ -21,10 +21,8 @@ #include "test_pcm_util.hxx" #include "pcm/PcmDither.hxx" -#include <glib.h> - void -test_pcm_dither_24() +PcmDitherTest::TestDither24() { constexpr unsigned N = 256; const auto src = TestDataBuffer<int32_t, N>(GlibRandomInt24()); @@ -34,13 +32,13 @@ test_pcm_dither_24() dither.Dither24To16(dest, src.begin(), src.end()); for (unsigned i = 0; i < N; ++i) { - g_assert_cmpint(dest[i], >=, (src[i] >> 8) - 8); - g_assert_cmpint(dest[i], <, (src[i] >> 8) + 8); + CPPUNIT_ASSERT(dest[i] >= (src[i] >> 8) - 8); + CPPUNIT_ASSERT(dest[i] < (src[i] >> 8) + 8); } } void -test_pcm_dither_32() +PcmDitherTest::TestDither32() { constexpr unsigned N = 256; const auto src = TestDataBuffer<int32_t, N>(); @@ -50,7 +48,7 @@ test_pcm_dither_32() dither.Dither32To16(dest, src.begin(), src.end()); for (unsigned i = 0; i < N; ++i) { - g_assert_cmpint(dest[i], >=, (src[i] >> 16) - 8); - g_assert_cmpint(dest[i], <, (src[i] >> 16) + 8); + CPPUNIT_ASSERT(dest[i] >= (src[i] >> 16) - 8); + CPPUNIT_ASSERT(dest[i] < (src[i] >> 16) + 8); } } diff --git a/test/test_pcm_format.cxx b/test/test_pcm_format.cxx index 65d744671..49f4ccd4b 100644 --- a/test/test_pcm_format.cxx +++ b/test/test_pcm_format.cxx @@ -26,10 +26,8 @@ #include "pcm/PcmBuffer.hxx" #include "AudioFormat.hxx" -#include <glib.h> - void -test_pcm_format_8_to_16() +PcmFormatTest::TestFormat8to16() { constexpr unsigned N = 256; const auto src = TestDataBuffer<int8_t, N>(); @@ -41,14 +39,14 @@ test_pcm_format_8_to_16() auto d = pcm_convert_to_16(buffer, dither, SampleFormat::S8, src, sizeof(src), &d_size); auto d_end = pcm_end_pointer(d, d_size); - g_assert_cmpint(d_end - d, ==, N); + CPPUNIT_ASSERT_EQUAL(N, unsigned(d_end - d)); for (size_t i = 0; i < N; ++i) - g_assert_cmpint(src[i], ==, d[i] >> 8); + CPPUNIT_ASSERT_EQUAL(int(src[i]), d[i] >> 8); } void -test_pcm_format_16_to_24() +PcmFormatTest::TestFormat16to24() { constexpr unsigned N = 256; const auto src = TestDataBuffer<int16_t, N>(); @@ -59,14 +57,14 @@ test_pcm_format_16_to_24() auto d = pcm_convert_to_24(buffer, SampleFormat::S16, src, sizeof(src), &d_size); auto d_end = pcm_end_pointer(d, d_size); - g_assert_cmpint(d_end - d, ==, N); + CPPUNIT_ASSERT_EQUAL(N, unsigned(d_end - d)); for (size_t i = 0; i < N; ++i) - g_assert_cmpint(src[i], ==, d[i] >> 8); + CPPUNIT_ASSERT_EQUAL(int(src[i]), d[i] >> 8); } void -test_pcm_format_16_to_32() +PcmFormatTest::TestFormat16to32() { constexpr unsigned N = 256; const auto src = TestDataBuffer<int16_t, N>(); @@ -77,14 +75,14 @@ test_pcm_format_16_to_32() auto d = pcm_convert_to_32(buffer, SampleFormat::S16, src, sizeof(src), &d_size); auto d_end = pcm_end_pointer(d, d_size); - g_assert_cmpint(d_end - d, ==, N); + CPPUNIT_ASSERT_EQUAL(N, unsigned(d_end - d)); for (size_t i = 0; i < N; ++i) - g_assert_cmpint(src[i], ==, d[i] >> 16); + CPPUNIT_ASSERT_EQUAL(int(src[i]), d[i] >> 16); } void -test_pcm_format_float() +PcmFormatTest::TestFormatFloat() { constexpr unsigned N = 256; const auto src = TestDataBuffer<int16_t, N>(); @@ -95,11 +93,11 @@ test_pcm_format_float() auto f = pcm_convert_to_float(buffer1, SampleFormat::S16, src, sizeof(src), &f_size); auto f_end = pcm_end_pointer(f, f_size); - g_assert_cmpint(f_end - f, ==, N); + CPPUNIT_ASSERT_EQUAL(N, unsigned(f_end - f)); for (auto i = f; i != f_end; ++i) { - g_assert(*i >= -1.); - g_assert(*i <= 1.); + CPPUNIT_ASSERT(*i >= -1.); + CPPUNIT_ASSERT(*i <= 1.); } PcmDither dither; @@ -109,8 +107,8 @@ test_pcm_format_float() SampleFormat::FLOAT, f, f_size, &d_size); auto d_end = pcm_end_pointer(d, d_size); - g_assert_cmpint(d_end - d, ==, N); + CPPUNIT_ASSERT_EQUAL(N, unsigned(d_end - d)); for (size_t i = 0; i < N; ++i) - g_assert_cmpint(src[i], ==, d[i]); + CPPUNIT_ASSERT_EQUAL(src[i], d[i]); } diff --git a/test/test_pcm_main.cxx b/test/test_pcm_main.cxx index a221b26af..1fa580441 100644 --- a/test/test_pcm_main.cxx +++ b/test/test_pcm_main.cxx @@ -18,35 +18,16 @@ */ #include "test_pcm_all.hxx" +#include "Compiler.h" -#include <glib.h> +#include <cppunit/extensions/TestFactoryRegistry.h> +#include <cppunit/ui/text/TestRunner.h> int -main(int argc, char **argv) +main(gcc_unused int argc, gcc_unused char **argv) { - g_test_init (&argc, &argv, NULL); - g_test_add_func("/pcm/dither/24", test_pcm_dither_24); - g_test_add_func("/pcm/dither/32", test_pcm_dither_32); - g_test_add_func("/pcm/pack/pack24", test_pcm_pack_24); - g_test_add_func("/pcm/pack/unpack24", test_pcm_unpack_24); - g_test_add_func("/pcm/channels/16", test_pcm_channels_16); - g_test_add_func("/pcm/channels/32", test_pcm_channels_32); - - g_test_add_func("/pcm/volume/8", test_pcm_volume_8); - g_test_add_func("/pcm/volume/16", test_pcm_volume_16); - g_test_add_func("/pcm/volume/24", test_pcm_volume_24); - g_test_add_func("/pcm/volume/32", test_pcm_volume_32); - g_test_add_func("/pcm/volume/float", test_pcm_volume_float); - - g_test_add_func("/pcm/format/8_to_16", test_pcm_format_8_to_16); - g_test_add_func("/pcm/format/16_to_24", test_pcm_format_16_to_24); - g_test_add_func("/pcm/format/16_to_32", test_pcm_format_16_to_32); - g_test_add_func("/pcm/format/float", test_pcm_format_float); - - g_test_add_func("/pcm/mix/8", test_pcm_mix_8); - g_test_add_func("/pcm/mix/16", test_pcm_mix_16); - g_test_add_func("/pcm/mix/24", test_pcm_mix_24); - g_test_add_func("/pcm/mix/32", test_pcm_mix_32); - - g_test_run(); + CppUnit::TextUi::TestRunner runner; + auto ®istry = CppUnit::TestFactoryRegistry::getRegistry(); + runner.addTest(registry.makeTest()); + return runner.run() ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/test/test_pcm_mix.cxx b/test/test_pcm_mix.cxx index b0e89639c..9c78399dc 100644 --- a/test/test_pcm_mix.cxx +++ b/test/test_pcm_mix.cxx @@ -22,10 +22,8 @@ #include "test_pcm_util.hxx" #include "pcm/PcmMix.hxx" -#include <glib.h> - template<typename T, SampleFormat format, typename G=GlibRandomInt<T>> -void +static void TestPcmMix(G g=G()) { constexpr unsigned N = 256; @@ -36,21 +34,21 @@ TestPcmMix(G g=G()) auto result = src1; bool success = pcm_mix(result.begin(), src2.begin(), sizeof(result), format, 1.0); - g_assert(success); + CPPUNIT_ASSERT(success); AssertEqualWithTolerance(result, src1, 1); /* portion1=0.0: result must be equal to src2 */ result = src1; success = pcm_mix(result.begin(), src2.begin(), sizeof(result), format, 0.0); - g_assert(success); + CPPUNIT_ASSERT(success); AssertEqualWithTolerance(result, src2, 1); /* portion1=0.5 */ result = src1; success = pcm_mix(result.begin(), src2.begin(), sizeof(result), format, 0.5); - g_assert(success); + CPPUNIT_ASSERT(success); auto expected = src1; for (unsigned i = 0; i < N; ++i) @@ -60,25 +58,25 @@ TestPcmMix(G g=G()) } void -test_pcm_mix_8() +PcmMixTest::TestMix8() { TestPcmMix<int8_t, SampleFormat::S8>(); } void -test_pcm_mix_16() +PcmMixTest::TestMix16() { TestPcmMix<int16_t, SampleFormat::S16>(); } void -test_pcm_mix_24() +PcmMixTest::TestMix24() { TestPcmMix<int32_t, SampleFormat::S24_P32>(GlibRandomInt24()); } void -test_pcm_mix_32() +PcmMixTest::TestMix32() { TestPcmMix<int32_t, SampleFormat::S32>(); } diff --git a/test/test_pcm_pack.cxx b/test/test_pcm_pack.cxx index 49840ddb0..0033ceb07 100644 --- a/test/test_pcm_pack.cxx +++ b/test/test_pcm_pack.cxx @@ -25,7 +25,7 @@ #include <glib.h> void -test_pcm_pack_24() +PcmPackTest::TestPack24() { constexpr unsigned N = 256; const auto src = TestDataBuffer<int32_t, N>(GlibRandomInt24()); @@ -44,12 +44,12 @@ test_pcm_pack_24() if (d & 0x800000) d |= 0xff000000; - g_assert_cmpint(d, ==, src[i]); + CPPUNIT_ASSERT_EQUAL(d, src[i]); } } void -test_pcm_unpack_24() +PcmPackTest::TestUnpack24() { constexpr unsigned N = 256; const auto src = TestDataBuffer<uint8_t, N * 3>(); @@ -68,6 +68,6 @@ test_pcm_unpack_24() if (s & 0x800000) s |= 0xff000000; - g_assert_cmpint(s, ==, dest[i]); + CPPUNIT_ASSERT_EQUAL(s, dest[i]); } } diff --git a/test/test_pcm_util.hxx b/test/test_pcm_util.hxx index 84ba074fd..df12aa067 100644 --- a/test/test_pcm_util.hxx +++ b/test/test_pcm_util.hxx @@ -72,13 +72,13 @@ template<typename T> bool AssertEqualWithTolerance(const T &a, const T &b, unsigned tolerance) { - g_assert_cmpint(a.size(), ==, b.size()); + CPPUNIT_ASSERT_EQUAL(a.size(), b.size()); for (unsigned i = 0; i < a.size(); ++i) { int64_t x = a[i], y = b[i]; - g_assert_cmpint(x, >=, y - int64_t(tolerance)); - g_assert_cmpint(x, <=, y + int64_t(tolerance)); + CPPUNIT_ASSERT(x >= y - int64_t(tolerance)); + CPPUNIT_ASSERT(x <= y + int64_t(tolerance)); } return true; diff --git a/test/test_pcm_volume.cxx b/test/test_pcm_volume.cxx index d5aa3782e..1c6730c36 100644 --- a/test/test_pcm_volume.cxx +++ b/test/test_pcm_volume.cxx @@ -21,14 +21,12 @@ #include "pcm/PcmVolume.hxx" #include "test_pcm_util.hxx" -#include <glib.h> - #include <algorithm> #include <string.h> void -test_pcm_volume_8() +PcmVolumeTest::TestVolume8() { constexpr unsigned N = 256; static int8_t zero[N]; @@ -37,27 +35,30 @@ test_pcm_volume_8() int8_t dest[N]; std::copy(src.begin(), src.end(), dest); - g_assert_cmpint(pcm_volume(dest, sizeof(dest), SampleFormat::S8, - 0), ==, true); - g_assert_cmpint(memcmp(dest, zero, sizeof(zero)), ==, 0); + CPPUNIT_ASSERT_EQUAL(true, + pcm_volume(dest, sizeof(dest), + SampleFormat::S8, 0)); + CPPUNIT_ASSERT_EQUAL(0, memcmp(dest, zero, sizeof(zero))); std::copy(src.begin(), src.end(), dest); - g_assert_cmpint(pcm_volume(dest, sizeof(dest), SampleFormat::S8, - PCM_VOLUME_1), ==, true); - g_assert_cmpint(memcmp(dest, src, sizeof(src)), ==, 0); + CPPUNIT_ASSERT_EQUAL(true, + pcm_volume(dest, sizeof(dest), + SampleFormat::S8, PCM_VOLUME_1)); + CPPUNIT_ASSERT_EQUAL(0, memcmp(dest, src, sizeof(src))); std::copy(src.begin(), src.end(), dest); - g_assert_cmpint(pcm_volume(dest, sizeof(dest), SampleFormat::S8, - PCM_VOLUME_1 / 2), ==, true); + CPPUNIT_ASSERT_EQUAL(true, + pcm_volume(dest, sizeof(dest), + SampleFormat::S8, PCM_VOLUME_1 / 2)); for (unsigned i = 0; i < N; ++i) { - g_assert_cmpint(dest[i], >=, (src[i] - 1) / 2); - g_assert_cmpint(dest[i], <=, src[i] / 2 + 1); + CPPUNIT_ASSERT(dest[i] >= (src[i] - 1) / 2); + CPPUNIT_ASSERT(dest[i] <= src[i] / 2 + 1); } } void -test_pcm_volume_16() +PcmVolumeTest::TestVolume16() { constexpr unsigned N = 256; static int16_t zero[N]; @@ -66,27 +67,30 @@ test_pcm_volume_16() int16_t dest[N]; std::copy(src.begin(), src.end(), dest); - g_assert_cmpint(pcm_volume(dest, sizeof(dest), SampleFormat::S16, - 0), ==, true); - g_assert_cmpint(memcmp(dest, zero, sizeof(zero)), ==, 0); + CPPUNIT_ASSERT_EQUAL(true, + pcm_volume(dest, sizeof(dest), + SampleFormat::S16, 0)); + CPPUNIT_ASSERT_EQUAL(0, memcmp(dest, zero, sizeof(zero))); std::copy(src.begin(), src.end(), dest); - g_assert_cmpint(pcm_volume(dest, sizeof(dest), SampleFormat::S16, - PCM_VOLUME_1), ==, true); - g_assert_cmpint(memcmp(dest, src, sizeof(src)), ==, 0); + CPPUNIT_ASSERT_EQUAL(true, + pcm_volume(dest, sizeof(dest), + SampleFormat::S16, PCM_VOLUME_1)); + CPPUNIT_ASSERT_EQUAL(0, memcmp(dest, src, sizeof(src))); std::copy(src.begin(), src.end(), dest); - g_assert_cmpint(pcm_volume(dest, sizeof(dest), SampleFormat::S16, - PCM_VOLUME_1 / 2), ==, true); + CPPUNIT_ASSERT_EQUAL(true, + pcm_volume(dest, sizeof(dest), + SampleFormat::S16, PCM_VOLUME_1 / 2)); for (unsigned i = 0; i < N; ++i) { - g_assert_cmpint(dest[i], >=, (src[i] - 1) / 2); - g_assert_cmpint(dest[i], <=, src[i] / 2 + 1); + CPPUNIT_ASSERT(dest[i] >= (src[i] - 1) / 2); + CPPUNIT_ASSERT(dest[i] <= src[i] / 2 + 1); } } void -test_pcm_volume_24() +PcmVolumeTest::TestVolume24() { constexpr unsigned N = 256; static int32_t zero[N]; @@ -95,27 +99,30 @@ test_pcm_volume_24() int32_t dest[N]; std::copy(src.begin(), src.end(), dest); - g_assert_cmpint(pcm_volume(dest, sizeof(dest), SampleFormat::S24_P32, - 0), ==, true); - g_assert_cmpint(memcmp(dest, zero, sizeof(zero)), ==, 0); + CPPUNIT_ASSERT_EQUAL(true, + pcm_volume(dest, sizeof(dest), + SampleFormat::S24_P32, 0)); + CPPUNIT_ASSERT_EQUAL(0, memcmp(dest, zero, sizeof(zero))); std::copy(src.begin(), src.end(), dest); - g_assert_cmpint(pcm_volume(dest, sizeof(dest), SampleFormat::S24_P32, - PCM_VOLUME_1), ==, true); - g_assert_cmpint(memcmp(dest, src, sizeof(src)), ==, 0); + CPPUNIT_ASSERT_EQUAL(true, + pcm_volume(dest, sizeof(dest), + SampleFormat::S24_P32, PCM_VOLUME_1)); + CPPUNIT_ASSERT_EQUAL(0, memcmp(dest, src, sizeof(src))); std::copy(src.begin(), src.end(), dest); - g_assert_cmpint(pcm_volume(dest, sizeof(dest), SampleFormat::S24_P32, - PCM_VOLUME_1 / 2), ==, true); + CPPUNIT_ASSERT_EQUAL(true, + pcm_volume(dest, sizeof(dest), + SampleFormat::S24_P32, PCM_VOLUME_1 / 2)); for (unsigned i = 0; i < N; ++i) { - g_assert_cmpint(dest[i], >=, (src[i] - 1) / 2); - g_assert_cmpint(dest[i], <=, src[i] / 2 + 1); + CPPUNIT_ASSERT(dest[i] >= (src[i] - 1) / 2); + CPPUNIT_ASSERT(dest[i] <= src[i] / 2 + 1); } } void -test_pcm_volume_32() +PcmVolumeTest::TestVolume32() { constexpr unsigned N = 256; static int32_t zero[N]; @@ -124,27 +131,30 @@ test_pcm_volume_32() int32_t dest[N]; std::copy(src.begin(), src.end(), dest); - g_assert_cmpint(pcm_volume(dest, sizeof(dest), SampleFormat::S32, - 0), ==, true); - g_assert_cmpint(memcmp(dest, zero, sizeof(zero)), ==, 0); + CPPUNIT_ASSERT_EQUAL(true, + pcm_volume(dest, sizeof(dest), + SampleFormat::S32, 0)); + CPPUNIT_ASSERT_EQUAL(0, memcmp(dest, zero, sizeof(zero))); std::copy(src.begin(), src.end(), dest); - g_assert_cmpint(pcm_volume(dest, sizeof(dest), SampleFormat::S32, - PCM_VOLUME_1), ==, true); - g_assert_cmpint(memcmp(dest, src, sizeof(src)), ==, 0); + CPPUNIT_ASSERT_EQUAL(true, + pcm_volume(dest, sizeof(dest), + SampleFormat::S32, PCM_VOLUME_1)); + CPPUNIT_ASSERT_EQUAL(0, memcmp(dest, src, sizeof(src))); std::copy(src.begin(), src.end(), dest); - g_assert_cmpint(pcm_volume(dest, sizeof(dest), SampleFormat::S32, - PCM_VOLUME_1 / 2), ==, true); + CPPUNIT_ASSERT_EQUAL(true, + pcm_volume(dest, sizeof(dest), + SampleFormat::S32, PCM_VOLUME_1 / 2)); for (unsigned i = 0; i < N; ++i) { - g_assert_cmpint(dest[i], >=, (src[i] - 1) / 2); - g_assert_cmpint(dest[i], <=, src[i] / 2 + 1); + CPPUNIT_ASSERT(dest[i] >= (src[i] - 1) / 2); + CPPUNIT_ASSERT(dest[i] <= src[i] / 2 + 1); } } void -test_pcm_volume_float() +PcmVolumeTest::TestVolumeFloat() { constexpr unsigned N = 256; static float zero[N]; @@ -153,19 +163,23 @@ test_pcm_volume_float() float dest[N]; std::copy(src.begin(), src.end(), dest); - g_assert_cmpint(pcm_volume(dest, sizeof(dest), SampleFormat::FLOAT, - 0), ==, true); - g_assert_cmpint(memcmp(dest, zero, sizeof(zero)), ==, 0); + CPPUNIT_ASSERT_EQUAL(true, + pcm_volume(dest, sizeof(dest), + SampleFormat::FLOAT, 0)); + CPPUNIT_ASSERT_EQUAL(0, memcmp(dest, zero, sizeof(zero))); std::copy(src.begin(), src.end(), dest); - g_assert_cmpint(pcm_volume(dest, sizeof(dest), SampleFormat::FLOAT, - PCM_VOLUME_1), ==, true); - g_assert_cmpint(memcmp(dest, src, sizeof(src)), ==, 0); + CPPUNIT_ASSERT_EQUAL(true, + pcm_volume(dest, sizeof(dest), + SampleFormat::FLOAT, PCM_VOLUME_1)); + CPPUNIT_ASSERT_EQUAL(0, memcmp(dest, src, sizeof(src))); std::copy(src.begin(), src.end(), dest); - g_assert_cmpint(pcm_volume(dest, sizeof(dest), SampleFormat::FLOAT, - PCM_VOLUME_1 / 2), ==, true); + CPPUNIT_ASSERT_EQUAL(true, + pcm_volume(dest, sizeof(dest), + SampleFormat::FLOAT, + PCM_VOLUME_1 / 2)); for (unsigned i = 0; i < N; ++i) - g_assert_cmpfloat(dest[i], ==, src[i] / 2); + CPPUNIT_ASSERT_DOUBLES_EQUAL(src[i] / 2, dest[i], 1); } diff --git a/test/test_queue_priority.cxx b/test/test_queue_priority.cxx index 11896978e..a1037798c 100644 --- a/test/test_queue_priority.cxx +++ b/test/test_queue_priority.cxx @@ -4,7 +4,10 @@ #include "Directory.hxx" #include "util/Macros.hxx" -#include <glib.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/TestFactoryRegistry.h> +#include <cppunit/ui/text/TestRunner.h> +#include <cppunit/extensions/HelperMacros.h> Directory detached_root; @@ -22,19 +25,9 @@ Song::Free() { } -gcc_unused -static void -dump_order(const struct queue *queue) -{ - g_printerr("queue length=%u, order:\n", queue->GetLength()); - for (unsigned i = 0; i < queue->GetLength(); ++i) - g_printerr(" [%u] -> %u (prio=%u)\n", i, queue->order[i], - queue->items[queue->order[i]].priority); -} - static void check_descending_priority(const struct queue *queue, - unsigned start_order) + unsigned start_order) { assert(start_order < queue->GetLength()); @@ -48,8 +41,17 @@ check_descending_priority(const struct queue *queue, } } -int -main(gcc_unused int argc, gcc_unused char **argv) +class QueuePriorityTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(QueuePriorityTest); + CPPUNIT_TEST(TestPriority); + CPPUNIT_TEST_SUITE_END(); + +public: + void TestPriority(); +}; + +void +QueuePriorityTest::TestPriority() { static Song songs[16]; @@ -58,7 +60,7 @@ main(gcc_unused int argc, gcc_unused char **argv) for (unsigned i = 0; i < ARRAY_SIZE(songs); ++i) queue.Append(&songs[i], 0); - assert(queue.GetLength() == ARRAY_SIZE(songs)); + CPPUNIT_ASSERT_EQUAL(unsigned(ARRAY_SIZE(songs)), queue.GetLength()); /* priority=10 for 4 items */ @@ -85,7 +87,7 @@ main(gcc_unused int argc, gcc_unused char **argv) queue.SetPriorityRange(15, 16, 50, -1); check_descending_priority(&queue, 0); - assert(queue.PositionToOrder(15) == 0); + CPPUNIT_ASSERT_EQUAL(0u, queue.PositionToOrder(15)); for (unsigned i = 0; i < 4; ++i) { assert(queue.PositionToOrder(i) >= 4); @@ -105,8 +107,8 @@ main(gcc_unused int argc, gcc_unused char **argv) queue.SetPriorityRange(3, 4, 20, -1); check_descending_priority(&queue, 0); - assert(queue.PositionToOrder(3) == 1); - assert(queue.PositionToOrder(15) == 0); + CPPUNIT_ASSERT_EQUAL(1u, queue.PositionToOrder(3)); + CPPUNIT_ASSERT_EQUAL(0u, queue.PositionToOrder(15)); for (unsigned i = 0; i < 3; ++i) { assert(queue.PositionToOrder(i) >= 5); @@ -131,14 +133,14 @@ main(gcc_unused int argc, gcc_unused char **argv) unsigned a_order = 3; unsigned a_position = queue.OrderToPosition(a_order); - assert(queue.items[a_position].priority == 10); + CPPUNIT_ASSERT_EQUAL(10u, unsigned(queue.items[a_position].priority)); queue.SetPriority(a_position, 20, current_order); current_order = queue.PositionToOrder(current_position); - assert(current_order == 3); + CPPUNIT_ASSERT_EQUAL(3u, current_order); a_order = queue.PositionToOrder(a_position); - assert(a_order == 4); + CPPUNIT_ASSERT_EQUAL(4u, a_order); check_descending_priority(&queue, current_order + 1); @@ -148,14 +150,14 @@ main(gcc_unused int argc, gcc_unused char **argv) unsigned b_order = 10; unsigned b_position = queue.OrderToPosition(b_order); - assert(queue.items[b_position].priority == 0); + CPPUNIT_ASSERT_EQUAL(0u, unsigned(queue.items[b_position].priority)); queue.SetPriority(b_position, 70, current_order); current_order = queue.PositionToOrder(current_position); - assert(current_order == 3); + CPPUNIT_ASSERT_EQUAL(3u, current_order); b_order = queue.PositionToOrder(b_position); - assert(b_order == 4); + CPPUNIT_ASSERT_EQUAL(4u, b_order); check_descending_priority(&queue, current_order + 1); @@ -165,25 +167,36 @@ main(gcc_unused int argc, gcc_unused char **argv) unsigned c_order = 0; unsigned c_position = queue.OrderToPosition(c_order); - assert(queue.items[c_position].priority == 50); + CPPUNIT_ASSERT_EQUAL(50u, unsigned(queue.items[c_position].priority)); queue.SetPriority(c_position, 60, current_order); current_order = queue.PositionToOrder(current_position); - assert(current_order == 3); + CPPUNIT_ASSERT_EQUAL(3u, current_order); c_order = queue.PositionToOrder(c_position); - assert(c_order == 0); + CPPUNIT_ASSERT_EQUAL(0u, c_order); /* move the prio=20 item back */ a_order = queue.PositionToOrder(a_position); - assert(a_order == 5); - assert(queue.items[a_position].priority == 20); + CPPUNIT_ASSERT_EQUAL(5u, a_order); + CPPUNIT_ASSERT_EQUAL(20u, unsigned(queue.items[a_position].priority)); queue.SetPriority(a_position, 5, current_order); current_order = queue.PositionToOrder(current_position); - assert(current_order == 3); + CPPUNIT_ASSERT_EQUAL(3u, current_order); a_order = queue.PositionToOrder(a_position); - assert(a_order == 6); + CPPUNIT_ASSERT_EQUAL(6u, a_order); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(QueuePriorityTest); + +int +main(gcc_unused int argc, gcc_unused char **argv) +{ + CppUnit::TextUi::TestRunner runner; + auto ®istry = CppUnit::TestFactoryRegistry::getRegistry(); + runner.addTest(registry.makeTest()); + return runner.run() ? EXIT_SUCCESS : EXIT_FAILURE; } |