diff options
author | Max Kellermann <max@duempel.org> | 2014-03-15 09:50:44 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-03-15 10:00:47 +0100 |
commit | 729304aef54ddecfb124c168ec1160f3bf970a47 (patch) | |
tree | 0da1c6ed1b8dbd74b83ca55d601b1c52fbaba690 /test/test_pcm_format.cxx | |
parent | 40cce050e7f6105320c5d7ab1e061b343c186ceb (diff) |
test/test_pcm_format: add unit test for float clamping
Diffstat (limited to 'test/test_pcm_format.cxx')
-rw-r--r-- | test/test_pcm_format.cxx | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/test/test_pcm_format.cxx b/test/test_pcm_format.cxx index 94c55ab16..381554921 100644 --- a/test/test_pcm_format.cxx +++ b/test/test_pcm_format.cxx @@ -97,4 +97,24 @@ PcmFormatTest::TestFormatFloat() for (size_t i = 0; i < N; ++i) CPPUNIT_ASSERT_EQUAL(src[i], d[i]); + + /* check if clamping works */ + float *writable = const_cast<float *>(f.data); + *writable++ = 1.01; + *writable++ = 10; + *writable++ = -1.01; + *writable++ = -10; + + d = pcm_convert_to_16(buffer2, dither, + SampleFormat::FLOAT, + f.ToVoid()); + CPPUNIT_ASSERT_EQUAL(N, d.size); + + CPPUNIT_ASSERT_EQUAL(32767, int(d[0])); + CPPUNIT_ASSERT_EQUAL(32767, int(d[1])); + CPPUNIT_ASSERT_EQUAL(-32768, int(d[2])); + CPPUNIT_ASSERT_EQUAL(-32768, int(d[3])); + + for (size_t i = 4; i < N; ++i) + CPPUNIT_ASSERT_EQUAL(src[i], d[i]); } |