summaryrefslogtreecommitdiff
path: root/test/run_encoder.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2018-07-17 21:56:43 +0200
committerMax Kellermann <max@musicpd.org>2018-07-17 21:58:39 +0200
commitd6529d8c6005e42c69a9402b31ddcd9f4be4cfa6 (patch)
treeb98690cc13e49bff6a58b0e5a754e17ac056e9b8 /test/run_encoder.cxx
parentedb44a536a726e6889f02ee26fb393432152ae7b (diff)
test/*: catch and print all exceptions
Diffstat (limited to 'test/run_encoder.cxx')
-rw-r--r--test/run_encoder.cxx46
1 files changed, 22 insertions, 24 deletions
diff --git a/test/run_encoder.cxx b/test/run_encoder.cxx
index 1c432558d..a1de40746 100644
--- a/test/run_encoder.cxx
+++ b/test/run_encoder.cxx
@@ -26,7 +26,7 @@
#include "AudioParser.hxx"
#include "config/Block.hxx"
#include "fs/io/StdioOutputStream.hxx"
-#include "Log.hxx"
+#include "util/PrintException.hxx"
#include <memory>
@@ -36,7 +36,7 @@
#include <unistd.h>
int main(int argc, char **argv)
-{
+try {
const char *encoder_name;
static char buffer[32768];
@@ -64,35 +64,33 @@ int main(int argc, char **argv)
ConfigBlock block;
block.AddBlockParam("quality", "5.0", -1);
- try {
- std::unique_ptr<PreparedEncoder> p_encoder(encoder_init(*plugin, block));
+ std::unique_ptr<PreparedEncoder> p_encoder(encoder_init(*plugin, block));
- /* open the encoder */
+ /* open the encoder */
- AudioFormat audio_format(44100, SampleFormat::S16, 2);
- if (argc > 2)
- audio_format = ParseAudioFormat(argv[2], false);
+ AudioFormat audio_format(44100, SampleFormat::S16, 2);
+ if (argc > 2)
+ audio_format = ParseAudioFormat(argv[2], false);
- std::unique_ptr<Encoder> encoder(p_encoder->Open(audio_format));
+ std::unique_ptr<Encoder> encoder(p_encoder->Open(audio_format));
- StdioOutputStream os(stdout);
+ StdioOutputStream os(stdout);
- EncoderToOutputStream(os, *encoder);
-
- /* do it */
+ EncoderToOutputStream(os, *encoder);
- ssize_t nbytes;
- while ((nbytes = read(0, buffer, sizeof(buffer))) > 0) {
- encoder->Write(buffer, nbytes);
- EncoderToOutputStream(os, *encoder);
- }
+ /* do it */
- encoder->End();
+ ssize_t nbytes;
+ while ((nbytes = read(0, buffer, sizeof(buffer))) > 0) {
+ encoder->Write(buffer, nbytes);
EncoderToOutputStream(os, *encoder);
-
- return EXIT_SUCCESS;
- } catch (const std::exception &e) {
- LogError(e);
- return EXIT_FAILURE;
}
+
+ encoder->End();
+ EncoderToOutputStream(os, *encoder);
+
+ return EXIT_SUCCESS;
+} catch (...) {
+ PrintException(std::current_exception());
+ return EXIT_FAILURE;
}