test/*: catch and print all exceptions

This commit is contained in:
Max Kellermann
2018-07-17 21:56:43 +02:00
parent edb44a536a
commit d6529d8c60
24 changed files with 116 additions and 122 deletions

View File

@@ -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 */
ssize_t nbytes;
while ((nbytes = read(0, buffer, sizeof(buffer))) > 0) {
encoder->Write(buffer, nbytes);
EncoderToOutputStream(os, *encoder);
/* do it */
ssize_t nbytes;
while ((nbytes = read(0, buffer, sizeof(buffer))) > 0) {
encoder->Write(buffer, nbytes);
EncoderToOutputStream(os, *encoder);
}
encoder->End();
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;
}