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 /test/test_pcm_volume.cxx | |
parent | ba98518c69d0501e67ef707f0d718cc678851415 (diff) | |
download | mpd-401a799a1b5de5d70a6b4c1d49235af0d5618f37.tar.gz mpd-401a799a1b5de5d70a6b4c1d49235af0d5618f37.tar.xz mpd-401a799a1b5de5d70a6b4c1d49235af0d5618f37.zip |
test: use the CPPUNIT framework for unit tests
Diffstat (limited to 'test/test_pcm_volume.cxx')
-rw-r--r-- | test/test_pcm_volume.cxx | 126 |
1 files changed, 70 insertions, 56 deletions
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); } |