aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-10-07 20:02:13 +0200
committerMax Kellermann <max@duempel.org>2014-10-07 20:02:13 +0200
commit1aac0b10c9499db77cbe39e43a0abc8cccc72079 (patch)
tree4a8fa128ac33a33a7223dd53e397547b086f6fff /test
parente5ff85b63c0ef342b11cb1ac5b5808091f51b667 (diff)
downloadmpd-1aac0b10c9499db77cbe39e43a0abc8cccc72079.tar.gz
mpd-1aac0b10c9499db77cbe39e43a0abc8cccc72079.tar.xz
mpd-1aac0b10c9499db77cbe39e43a0abc8cccc72079.zip
test/run_input, ...: add struct ScopeIOThread
Auto-stop the IO thread in all error handlers.
Diffstat (limited to 'test')
-rw-r--r--test/ScopeIOThread.hxx36
-rw-r--r--test/dump_playlist.cxx6
-rw-r--r--test/dump_text_file.cxx7
-rw-r--r--test/read_tags.cxx6
-rw-r--r--test/run_decoder.cxx6
-rw-r--r--test/run_input.cxx7
-rw-r--r--test/run_output.cxx7
-rw-r--r--test/visit_archive.cxx7
8 files changed, 50 insertions, 32 deletions
diff --git a/test/ScopeIOThread.hxx b/test/ScopeIOThread.hxx
new file mode 100644
index 000000000..06d27a4b8
--- /dev/null
+++ b/test/ScopeIOThread.hxx
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * http://www.musicpd.org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef MPD_SCOPE_IO_THREAD_HXX
+#define MPD_SCOPE_IO_THREAD_HXX
+
+#include "IOThread.hxx"
+
+struct ScopeIOThread {
+ ScopeIOThread() {
+ io_thread_init();
+ io_thread_start();
+ }
+
+ ~ScopeIOThread() {
+ io_thread_deinit();
+ }
+};
+
+#endif
diff --git a/test/dump_playlist.cxx b/test/dump_playlist.cxx
index 6205c8a79..0047ef427 100644
--- a/test/dump_playlist.cxx
+++ b/test/dump_playlist.cxx
@@ -25,7 +25,7 @@
#include "config/ConfigGlobal.hxx"
#include "decoder/DecoderList.hxx"
#include "input/Init.hxx"
-#include "IOThread.hxx"
+#include "ScopeIOThread.hxx"
#include "playlist/PlaylistRegistry.hxx"
#include "playlist/PlaylistPlugin.hxx"
#include "fs/Path.hxx"
@@ -82,8 +82,7 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}
- io_thread_init();
- io_thread_start();
+ const ScopeIOThread io_thread;
if (!input_stream_global_init(error)) {
LogError(error);
@@ -155,7 +154,6 @@ int main(int argc, char **argv)
decoder_plugin_deinit_all();
playlist_list_global_finish();
input_stream_global_finish();
- io_thread_deinit();
config_global_finish();
return 0;
diff --git a/test/dump_text_file.cxx b/test/dump_text_file.cxx
index 03f8114a4..5bfd316a5 100644
--- a/test/dump_text_file.cxx
+++ b/test/dump_text_file.cxx
@@ -18,7 +18,7 @@
*/
#include "config.h"
-#include "IOThread.hxx"
+#include "ScopeIOThread.hxx"
#include "input/Init.hxx"
#include "input/InputStream.hxx"
#include "input/TextInputStream.hxx"
@@ -91,8 +91,7 @@ int main(int argc, char **argv)
config_global_init();
- io_thread_init();
- io_thread_start();
+ const ScopeIOThread io_thread;
#ifdef ENABLE_ARCHIVE
archive_plugin_init_all();
@@ -129,8 +128,6 @@ int main(int argc, char **argv)
archive_plugin_deinit_all();
#endif
- io_thread_deinit();
-
config_global_finish();
return ret;
diff --git a/test/read_tags.cxx b/test/read_tags.cxx
index 67962062c..91ac9c674 100644
--- a/test/read_tags.cxx
+++ b/test/read_tags.cxx
@@ -18,7 +18,7 @@
*/
#include "config.h"
-#include "IOThread.hxx"
+#include "ScopeIOThread.hxx"
#include "decoder/DecoderList.hxx"
#include "decoder/DecoderPlugin.hxx"
#include "input/Init.hxx"
@@ -96,8 +96,7 @@ int main(int argc, char **argv)
#endif
#endif
- io_thread_init();
- io_thread_start();
+ const ScopeIOThread io_thread;
Error error;
if (!input_stream_global_init(error)) {
@@ -132,7 +131,6 @@ int main(int argc, char **argv)
decoder_plugin_deinit_all();
input_stream_global_finish();
- io_thread_deinit();
if (!success) {
fprintf(stderr, "Failed to read tags\n");
diff --git a/test/run_decoder.cxx b/test/run_decoder.cxx
index 3980340cc..0e9af6a1a 100644
--- a/test/run_decoder.cxx
+++ b/test/run_decoder.cxx
@@ -18,7 +18,7 @@
*/
#include "config.h"
-#include "IOThread.hxx"
+#include "ScopeIOThread.hxx"
#include "decoder/DecoderList.hxx"
#include "decoder/DecoderPlugin.hxx"
#include "FakeDecoderAPI.hxx"
@@ -56,8 +56,7 @@ int main(int argc, char **argv)
#endif
#endif
- io_thread_init();
- io_thread_start();
+ const ScopeIOThread io_thread;
Error error;
if (!input_stream_global_init(error)) {
@@ -98,7 +97,6 @@ int main(int argc, char **argv)
decoder_plugin_deinit_all();
input_stream_global_finish();
- io_thread_deinit();
if (!decoder.initialized) {
fprintf(stderr, "Decoding failed\n");
diff --git a/test/run_input.cxx b/test/run_input.cxx
index 1d8cf3a28..de5bd9632 100644
--- a/test/run_input.cxx
+++ b/test/run_input.cxx
@@ -24,7 +24,7 @@
#include "config/ConfigGlobal.hxx"
#include "input/InputStream.hxx"
#include "input/Init.hxx"
-#include "IOThread.hxx"
+#include "ScopeIOThread.hxx"
#include "util/Error.hxx"
#include "thread/Cond.hxx"
#include "Log.hxx"
@@ -123,8 +123,7 @@ int main(int argc, char **argv)
config_global_init();
- io_thread_init();
- io_thread_start();
+ const ScopeIOThread io_thread;
#ifdef ENABLE_ARCHIVE
archive_plugin_init_all();
@@ -160,8 +159,6 @@ int main(int argc, char **argv)
archive_plugin_deinit_all();
#endif
- io_thread_deinit();
-
config_global_finish();
return ret;
diff --git a/test/run_output.cxx b/test/run_output.cxx
index e6c11669d..345127556 100644
--- a/test/run_output.cxx
+++ b/test/run_output.cxx
@@ -26,7 +26,7 @@
#include "Idle.hxx"
#include "Main.hxx"
#include "event/Loop.hxx"
-#include "IOThread.hxx"
+#include "ScopeIOThread.hxx"
#include "fs/Path.hxx"
#include "AudioParser.hxx"
#include "pcm/PcmConvert.hxx"
@@ -179,8 +179,7 @@ int main(int argc, char **argv)
EventLoop event_loop;
- io_thread_init();
- io_thread_start();
+ const ScopeIOThread io_thread;
/* initialize the audio output */
@@ -205,8 +204,6 @@ int main(int argc, char **argv)
audio_output_free(ao);
- io_thread_deinit();
-
config_global_finish();
return success ? EXIT_SUCCESS : EXIT_FAILURE;
diff --git a/test/visit_archive.cxx b/test/visit_archive.cxx
index d4854d8f1..f5dba5c8e 100644
--- a/test/visit_archive.cxx
+++ b/test/visit_archive.cxx
@@ -21,7 +21,7 @@
#include "stdbin.h"
#include "tag/Tag.hxx"
#include "config/ConfigGlobal.hxx"
-#include "IOThread.hxx"
+#include "ScopeIOThread.hxx"
#include "input/Init.hxx"
#include "archive/ArchiveList.hxx"
#include "archive/ArchivePlugin.hxx"
@@ -65,8 +65,7 @@ main(int argc, char **argv)
config_global_init();
- io_thread_init();
- io_thread_start();
+ const ScopeIOThread io_thread;
archive_plugin_init_all();
@@ -101,8 +100,6 @@ main(int argc, char **argv)
archive_plugin_deinit_all();
- io_thread_deinit();
-
config_global_finish();
return result;