diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/run_convert.cxx | 12 | ||||
-rw-r--r-- | test/run_encoder.cxx | 3 | ||||
-rw-r--r-- | test/run_resolver.cxx | 12 | ||||
-rw-r--r-- | test/test_pcm_channels.cxx | 49 | ||||
-rw-r--r-- | test/test_vorbis_encoder.cxx | 10 |
5 files changed, 44 insertions, 42 deletions
diff --git a/test/run_convert.cxx b/test/run_convert.cxx index 0e873a3b3..d9a1b7f08 100644 --- a/test/run_convert.cxx +++ b/test/run_convert.cxx @@ -90,6 +90,11 @@ int main(int argc, char **argv) const size_t in_frame_size = in_audio_format.GetFrameSize(); PcmConvert state; + if (!state.Open(in_audio_format, out_audio_format_mask, error)) { + g_printerr("Failed to open PcmConvert: %s\n", + error.GetMessage()); + return EXIT_FAILURE; + } FifoBuffer<uint8_t, 4096> buffer; @@ -115,9 +120,10 @@ int main(int argc, char **argv) buffer.Consume(src.size); size_t length; - output = state.Convert(in_audio_format, src.data, src.size, - out_audio_format, &length, error); + output = state.Convert(src.data, src.size, + &length, error); if (output == NULL) { + state.Close(); g_printerr("Failed to convert: %s\n", error.GetMessage()); return 2; } @@ -125,5 +131,7 @@ int main(int argc, char **argv) gcc_unused ssize_t ignored = write(1, output, length); } + state.Close(); + return EXIT_SUCCESS; } diff --git a/test/run_encoder.cxx b/test/run_encoder.cxx index 838ee708e..0eba87d64 100644 --- a/test/run_encoder.cxx +++ b/test/run_encoder.cxx @@ -117,4 +117,7 @@ int main(int argc, char **argv) } encoder_to_stdout(*encoder); + + encoder_close(encoder); + encoder_finish(encoder); } diff --git a/test/run_resolver.cxx b/test/run_resolver.cxx index 7da2fd5b2..65c55b4df 100644 --- a/test/run_resolver.cxx +++ b/test/run_resolver.cxx @@ -51,16 +51,8 @@ int main(int argc, char **argv) } for (const struct addrinfo *i = ai; i != NULL; i = i->ai_next) { - char *p = sockaddr_to_string(i->ai_addr, i->ai_addrlen, - error); - if (p == NULL) { - freeaddrinfo(ai); - LogError(error); - return EXIT_FAILURE; - } - - g_print("%s\n", p); - g_free(p); + const auto s = sockaddr_to_string(i->ai_addr, i->ai_addrlen); + g_print("%s\n", s.c_str()); } freeaddrinfo(ai); diff --git a/test/test_pcm_channels.cxx b/test/test_pcm_channels.cxx index 85c872674..355553687 100644 --- a/test/test_pcm_channels.cxx +++ b/test/test_pcm_channels.cxx @@ -22,67 +22,60 @@ #include "test_pcm_util.hxx" #include "pcm/PcmChannels.hxx" #include "pcm/PcmBuffer.hxx" +#include "util/ConstBuffer.hxx" void PcmChannelsTest::TestChannels16() { - constexpr unsigned N = 256; + constexpr size_t N = 256; const auto src = TestDataBuffer<int16_t, N * 2>(); PcmBuffer buffer; /* stereo to mono */ - size_t dest_size; - const int16_t *dest = - pcm_convert_channels_16(buffer, 1, 2, src, sizeof(src), - &dest_size); - CPPUNIT_ASSERT(dest != NULL); - CPPUNIT_ASSERT_EQUAL(sizeof(src) / 2, dest_size); + auto dest = pcm_convert_channels_16(buffer, 1, 2, { src, N * 2 }); + CPPUNIT_ASSERT(!dest.IsNull()); + CPPUNIT_ASSERT_EQUAL(N, dest.size); for (unsigned i = 0; i < N; ++i) CPPUNIT_ASSERT_EQUAL(int16_t((src[i * 2] + src[i * 2 + 1]) / 2), - dest[i]); + dest.data[i]); /* mono to stereo */ - dest = pcm_convert_channels_16(buffer, 2, 1, src, sizeof(src), - &dest_size); - CPPUNIT_ASSERT(dest != NULL); - CPPUNIT_ASSERT_EQUAL(sizeof(src) * 2, dest_size); + dest = pcm_convert_channels_16(buffer, 2, 1, { src, N * 2 }); + CPPUNIT_ASSERT(!dest.IsNull()); + CPPUNIT_ASSERT_EQUAL(N * 4, dest.size); for (unsigned i = 0; i < N; ++i) { - CPPUNIT_ASSERT_EQUAL(src[i], dest[i * 2]); - CPPUNIT_ASSERT_EQUAL(src[i], dest[i * 2 + 1]); + CPPUNIT_ASSERT_EQUAL(src[i], dest.data[i * 2]); + CPPUNIT_ASSERT_EQUAL(src[i], dest.data[i * 2 + 1]); } } void PcmChannelsTest::TestChannels32() { - constexpr unsigned N = 256; + constexpr size_t N = 256; const auto src = TestDataBuffer<int32_t, N * 2>(); PcmBuffer buffer; /* stereo to mono */ - size_t dest_size; - const int32_t *dest = - pcm_convert_channels_32(buffer, 1, 2, src, sizeof(src), - &dest_size); - CPPUNIT_ASSERT(dest != NULL); - CPPUNIT_ASSERT_EQUAL(sizeof(src) / 2, dest_size); + auto dest = pcm_convert_channels_32(buffer, 1, 2, { src, N * 2 }); + CPPUNIT_ASSERT(!dest.IsNull()); + CPPUNIT_ASSERT_EQUAL(N, dest.size); for (unsigned i = 0; i < N; ++i) CPPUNIT_ASSERT_EQUAL(int32_t(((int64_t)src[i * 2] + (int64_t)src[i * 2 + 1]) / 2), - dest[i]); + dest.data[i]); /* mono to stereo */ - dest = pcm_convert_channels_32(buffer, 2, 1, src, sizeof(src), - &dest_size); - CPPUNIT_ASSERT(dest != NULL); - CPPUNIT_ASSERT_EQUAL(sizeof(src) * 2, dest_size); + dest = pcm_convert_channels_32(buffer, 2, 1, { src, N * 2 }); + CPPUNIT_ASSERT(!dest.IsNull()); + CPPUNIT_ASSERT_EQUAL(N * 4, dest.size); for (unsigned i = 0; i < N; ++i) { - CPPUNIT_ASSERT_EQUAL(src[i], dest[i * 2]); - CPPUNIT_ASSERT_EQUAL(src[i], dest[i * 2 + 1]); + CPPUNIT_ASSERT_EQUAL(src[i], dest.data[i * 2]); + CPPUNIT_ASSERT_EQUAL(src[i], dest.data[i * 2 + 1]); } } diff --git a/test/test_vorbis_encoder.cxx b/test/test_vorbis_encoder.cxx index 1d95f6deb..bb8731c2f 100644 --- a/test/test_vorbis_encoder.cxx +++ b/test/test_vorbis_encoder.cxx @@ -24,6 +24,7 @@ #include "ConfigData.hxx" #include "stdbin.h" #include "tag/Tag.hxx" +#include "tag/TagBuilder.hxx" #include "util/Error.hxx" #include <stddef.h> @@ -81,8 +82,13 @@ main(gcc_unused int argc, gcc_unused char **argv) encoder_to_stdout(*encoder); Tag tag; - tag.AddItem(TAG_ARTIST, "Foo"); - tag.AddItem(TAG_TITLE, "Bar"); + + { + TagBuilder tag_builder; + tag_builder.AddItem(TAG_ARTIST, "Foo"); + tag_builder.AddItem(TAG_TITLE, "Bar"); + tag_builder.Commit(tag); + } success = encoder_tag(encoder, &tag, IgnoreError()); assert(success); |