summaryrefslogtreecommitdiff
path: root/test/run_decoder.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2018-02-12 23:55:28 +0100
committerMax Kellermann <max@musicpd.org>2018-02-13 00:00:00 +0100
commit53acb7bfcbed943d7592cb868d427d8b48dd1bcb (patch)
tree552b1362d5ec4ad701c71512d49b7cfacc265b17 /test/run_decoder.cxx
parent65bbb0e0aa0f613a9da683900838d2912f2454ba (diff)
test/run_decder: RAII-style global initialization
Diffstat (limited to 'test/run_decoder.cxx')
-rw-r--r--test/run_decoder.cxx29
1 files changed, 19 insertions, 10 deletions
diff --git a/test/run_decoder.cxx b/test/run_decoder.cxx
index 5bc00199c..90f93420e 100644
--- a/test/run_decoder.cxx
+++ b/test/run_decoder.cxx
@@ -35,6 +35,23 @@
#include <stdlib.h>
#include <stdio.h>
+class GlobalInit {
+ EventThread io_thread;
+
+public:
+ GlobalInit() {
+ io_thread.Start();
+
+ input_stream_global_init(io_thread.GetEventLoop());
+ decoder_plugin_init_all();
+ }
+
+ ~GlobalInit() {
+ decoder_plugin_deinit_all();
+ input_stream_global_finish();
+ }
+};
+
int main(int argc, char **argv)
try {
if (argc != 3) {
@@ -42,16 +59,10 @@ try {
return EXIT_FAILURE;
}
- FakeDecoder decoder;
const char *const decoder_name = argv[1];
const char *const uri = argv[2];
- EventThread io_thread;
- io_thread.Start();
-
- input_stream_global_init(io_thread.GetEventLoop());
-
- decoder_plugin_init_all();
+ const GlobalInit init;
const DecoderPlugin *plugin = decoder_plugin_from_name(decoder_name);
if (plugin == nullptr) {
@@ -59,6 +70,7 @@ try {
return EXIT_FAILURE;
}
+ FakeDecoder decoder;
if (plugin->file_decode != nullptr) {
plugin->FileDecode(decoder, Path::FromFS(uri));
} else if (plugin->stream_decode != nullptr) {
@@ -70,9 +82,6 @@ try {
return EXIT_FAILURE;
}
- decoder_plugin_deinit_all();
- input_stream_global_finish();
-
if (!decoder.initialized) {
fprintf(stderr, "Decoding failed\n");
return EXIT_FAILURE;