diff options
author | Max Kellermann <max@duempel.org> | 2013-12-24 14:44:08 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-12-24 14:44:08 +0100 |
commit | 1ad52f131c7adf3396ea03d8da0da807da222bba (patch) | |
tree | 7556fa5d25352a5166342cbd582e62f473644123 /test | |
parent | 8064bbbc3f3d3bac50a9cd972106479fd32917cc (diff) | |
download | mpd-1ad52f131c7adf3396ea03d8da0da807da222bba.tar.gz mpd-1ad52f131c7adf3396ea03d8da0da807da222bba.tar.xz mpd-1ad52f131c7adf3396ea03d8da0da807da222bba.zip |
test/*: use fprintf(stderr,...) and Log() instead of g_printerr()
Avoid GLib.
Diffstat (limited to 'test')
-rw-r--r-- | test/FakeDecoderAPI.cxx | 8 | ||||
-rw-r--r-- | test/dump_playlist.cxx | 33 | ||||
-rw-r--r-- | test/dump_rva2.cxx | 21 | ||||
-rw-r--r-- | test/dump_text_file.cxx | 8 | ||||
-rw-r--r-- | test/read_mixer.cxx | 22 | ||||
-rw-r--r-- | test/read_tags.cxx | 26 | ||||
-rw-r--r-- | test/run_filter.cxx | 31 | ||||
-rw-r--r-- | test/run_inotify.cxx | 13 | ||||
-rw-r--r-- | test/run_output.cxx | 31 | ||||
-rw-r--r-- | test/run_resolver.cxx | 6 | ||||
-rw-r--r-- | test/software_volume.cxx | 12 |
11 files changed, 101 insertions, 110 deletions
diff --git a/test/FakeDecoderAPI.cxx b/test/FakeDecoderAPI.cxx index ca09ca982..3045722cf 100644 --- a/test/FakeDecoderAPI.cxx +++ b/test/FakeDecoderAPI.cxx @@ -129,13 +129,13 @@ decoder_replay_gain(gcc_unused Decoder &decoder, { const ReplayGainTuple *tuple = &rgi->tuples[REPLAY_GAIN_ALBUM]; if (tuple->IsDefined()) - g_printerr("replay_gain[album]: gain=%f peak=%f\n", - tuple->gain, tuple->peak); + fprintf(stderr, "replay_gain[album]: gain=%f peak=%f\n", + tuple->gain, tuple->peak); tuple = &rgi->tuples[REPLAY_GAIN_TRACK]; if (tuple->IsDefined()) - g_printerr("replay_gain[track]: gain=%f peak=%f\n", - tuple->gain, tuple->peak); + fprintf(stderr, "replay_gain[track]: gain=%f peak=%f\n", + tuple->gain, tuple->peak); } void diff --git a/test/dump_playlist.cxx b/test/dump_playlist.cxx index 87952158b..f0401249e 100644 --- a/test/dump_playlist.cxx +++ b/test/dump_playlist.cxx @@ -49,8 +49,8 @@ int main(int argc, char **argv) Song *song; if (argc != 3) { - g_printerr("Usage: dump_playlist CONFIG URI\n"); - return 1; + fprintf(stderr, "Usage: dump_playlist CONFIG URI\n"); + return EXIT_FAILURE; } const Path config_path = Path::FromFS(argv[1]); @@ -68,8 +68,8 @@ int main(int argc, char **argv) Error error; if (!ReadConfigFile(config_path, error)) { - g_printerr("%s\n", error.GetMessage()); - return 1; + LogError(error); + return EXIT_FAILURE; } io_thread_init(); @@ -77,7 +77,7 @@ int main(int argc, char **argv) if (!input_stream_global_init(error)) { LogError(error); - return 2; + return EXIT_FAILURE; } playlist_list_global_init(); @@ -97,7 +97,8 @@ int main(int argc, char **argv) if (error.IsDefined()) LogError(error); else - g_printerr("InputStream::Open() failed\n"); + fprintf(stderr, + "InputStream::Open() failed\n"); return 2; } @@ -108,7 +109,7 @@ int main(int argc, char **argv) playlist = playlist_list_open_stream(*is, uri); if (playlist == NULL) { is->Close(); - g_printerr("Failed to open playlist\n"); + fprintf(stderr, "Failed to open playlist\n"); return 2; } } @@ -116,18 +117,18 @@ int main(int argc, char **argv) /* dump the playlist */ while ((song = playlist->NextSong()) != NULL) { - g_print("%s\n", song->uri); + printf("%s\n", song->uri); if (song->end_ms > 0) - g_print("range: %u:%02u..%u:%02u\n", - song->start_ms / 60000, - (song->start_ms / 1000) % 60, - song->end_ms / 60000, - (song->end_ms / 1000) % 60); + printf("range: %u:%02u..%u:%02u\n", + song->start_ms / 60000, + (song->start_ms / 1000) % 60, + song->end_ms / 60000, + (song->end_ms / 1000) % 60); else if (song->start_ms > 0) - g_print("range: %u:%02u..\n", - song->start_ms / 60000, - (song->start_ms / 1000) % 60); + printf("range: %u:%02u..\n", + song->start_ms / 60000, + (song->start_ms / 1000) % 60); if (song->tag != NULL) tag_save(stdout, *song->tag); diff --git a/test/dump_rva2.cxx b/test/dump_rva2.cxx index e1ba5336a..c1683c895 100644 --- a/test/dump_rva2.cxx +++ b/test/dump_rva2.cxx @@ -24,11 +24,10 @@ #include "ConfigGlobal.hxx" #include "util/Error.hxx" #include "fs/Path.hxx" +#include "Log.hxx" #include <id3tag.h> -#include <glib.h> - #ifdef HAVE_LOCALE_H #include <locale.h> #endif @@ -50,8 +49,8 @@ int main(int argc, char **argv) #endif if (argc != 2) { - g_printerr("Usage: read_rva2 FILE\n"); - return 1; + fprintf(stderr, "Usage: read_rva2 FILE\n"); + return EXIT_FAILURE; } const char *path = argv[1]; @@ -60,9 +59,9 @@ int main(int argc, char **argv) struct id3_tag *tag = tag_id3_load(Path::FromFS(path), error); if (tag == NULL) { if (error.IsDefined()) - g_printerr("%s\n", error.GetMessage()); + LogError(error); else - g_printerr("No ID3 tag found\n"); + fprintf(stderr, "No ID3 tag found\n"); return EXIT_FAILURE; } @@ -74,19 +73,19 @@ int main(int argc, char **argv) id3_tag_delete(tag); if (!success) { - g_printerr("No RVA2 tag found\n"); + fprintf(stderr, "No RVA2 tag found\n"); return EXIT_FAILURE; } const ReplayGainTuple *tuple = &replay_gain.tuples[REPLAY_GAIN_ALBUM]; if (tuple->IsDefined()) - g_printerr("replay_gain[album]: gain=%f peak=%f\n", - tuple->gain, tuple->peak); + fprintf(stderr, "replay_gain[album]: gain=%f peak=%f\n", + tuple->gain, tuple->peak); tuple = &replay_gain.tuples[REPLAY_GAIN_TRACK]; if (tuple->IsDefined()) - g_printerr("replay_gain[track]: gain=%f peak=%f\n", - tuple->gain, tuple->peak); + fprintf(stderr, "replay_gain[track]: gain=%f peak=%f\n", + tuple->gain, tuple->peak); return EXIT_SUCCESS; } diff --git a/test/dump_text_file.cxx b/test/dump_text_file.cxx index dd0cba0f2..3da965f03 100644 --- a/test/dump_text_file.cxx +++ b/test/dump_text_file.cxx @@ -89,8 +89,8 @@ int main(int argc, char **argv) int ret; if (argc != 2) { - g_printerr("Usage: run_input URI\n"); - return 1; + fprintf(stderr, "Usage: run_input URI\n"); + return EXIT_FAILURE; } /* initialize GLib */ @@ -129,8 +129,8 @@ int main(int argc, char **argv) if (error.IsDefined()) LogError(error); else - g_printerr("input_stream::Open() failed\n"); - ret = 2; + fprintf(stderr, "input_stream::Open() failed\n"); + ret = EXIT_FAILURE; } /* deinitialize everything */ diff --git a/test/read_mixer.cxx b/test/read_mixer.cxx index 5decc5798..95aacf6db 100644 --- a/test/read_mixer.cxx +++ b/test/read_mixer.cxx @@ -27,6 +27,7 @@ #include "event/Loop.hxx" #include "ConfigData.hxx" #include "util/Error.hxx" +#include "Log.hxx" #include <glib.h> @@ -106,8 +107,8 @@ int main(int argc, gcc_unused char **argv) int volume; if (argc != 2) { - g_printerr("Usage: read_mixer PLUGIN\n"); - return 1; + fprintf(stderr, "Usage: read_mixer PLUGIN\n"); + return EXIT_FAILURE; } #if !GLIB_CHECK_VERSION(2,32,0) @@ -120,14 +121,14 @@ int main(int argc, gcc_unused char **argv) Mixer *mixer = mixer_new(&alsa_mixer_plugin, nullptr, config_param(), error); if (mixer == NULL) { - g_printerr("mixer_new() failed: %s\n", error.GetMessage()); - return 2; + LogError(error, "mixer_new() failed"); + return EXIT_FAILURE; } if (!mixer_open(mixer, error)) { mixer_free(mixer); - g_printerr("failed to open the mixer: %s\n", error.GetMessage()); - return 2; + LogError(error, "failed to open the mixer"); + return EXIT_FAILURE; } volume = mixer_get_volume(mixer, error); @@ -140,13 +141,12 @@ int main(int argc, gcc_unused char **argv) if (volume < 0) { if (error.IsDefined()) { - g_printerr("failed to read volume: %s\n", - error.GetMessage()); + LogError(error, "failed to read volume"); } else - g_printerr("failed to read volume\n"); - return 2; + fprintf(stderr, "failed to read volume\n"); + return EXIT_FAILURE; } - g_print("%d\n", volume); + printf("%d\n", volume); return 0; } diff --git a/test/read_tags.cxx b/test/read_tags.cxx index 52b2561b8..dac9aba00 100644 --- a/test/read_tags.cxx +++ b/test/read_tags.cxx @@ -47,20 +47,20 @@ static bool empty = true; static void print_duration(unsigned seconds, gcc_unused void *ctx) { - g_print("duration=%d\n", seconds); + printf("duration=%d\n", seconds); } static void print_tag(TagType type, const char *value, gcc_unused void *ctx) { - g_print("[%s]=%s\n", tag_item_names[type], value); + printf("[%s]=%s\n", tag_item_names[type], value); empty = false; } static void print_pair(const char *name, const char *value, gcc_unused void *ctx) { - g_print("\"%s\"=%s\n", name, value); + printf("\"%s\"=%s\n", name, value); } static const struct tag_handler print_handler = { @@ -80,8 +80,8 @@ int main(int argc, char **argv) #endif if (argc != 3) { - g_printerr("Usage: read_tags DECODER FILE\n"); - return 1; + fprintf(stderr, "Usage: read_tags DECODER FILE\n"); + return EXIT_FAILURE; } decoder_name = argv[1]; @@ -104,8 +104,8 @@ int main(int argc, char **argv) plugin = decoder_plugin_from_name(decoder_name); if (plugin == NULL) { - g_printerr("No such decoder: %s\n", decoder_name); - return 1; + fprintf(stderr, "No such decoder: %s\n", decoder_name); + return EXIT_FAILURE; } bool success = plugin->ScanFile(path, print_handler, nullptr); @@ -116,9 +116,8 @@ int main(int argc, char **argv) InputStream *is = InputStream::Open(path, mutex, cond, error); if (is == NULL) { - g_printerr("Failed to open %s: %s\n", - path, error.GetMessage()); - return 1; + FormatError(error, "Failed to open %s", path); + return EXIT_FAILURE; } mutex.lock(); @@ -128,8 +127,7 @@ int main(int argc, char **argv) if (!is->Check(error)) { mutex.unlock(); - g_printerr("Failed to read %s: %s\n", - path, error.GetMessage()); + FormatError(error, "Failed to read %s", path); return EXIT_FAILURE; } @@ -144,8 +142,8 @@ int main(int argc, char **argv) io_thread_deinit(); if (!success) { - g_printerr("Failed to read tags\n"); - return 1; + fprintf(stderr, "Failed to read tags\n"); + return EXIT_FAILURE; } if (empty) { diff --git a/test/run_filter.cxx b/test/run_filter.cxx index 790e2145d..6781700d8 100644 --- a/test/run_filter.cxx +++ b/test/run_filter.cxx @@ -30,6 +30,7 @@ #include "stdbin.h" #include "util/Error.hxx" #include "system/FatalError.hxx" +#include "Log.hxx" #include <glib.h> @@ -66,14 +67,14 @@ load_filter(const char *name) param = find_named_config_block(CONF_AUDIO_FILTER, name); if (param == NULL) { - g_printerr("No such configured filter: %s\n", name); + fprintf(stderr, "No such configured filter: %s\n", name); return nullptr; } Error error; Filter *filter = filter_configured_new(*param, error); if (filter == NULL) { - g_printerr("Failed to load filter: %s\n", error.GetMessage()); + LogError(error, "Failed to load filter"); return NULL; } @@ -87,8 +88,8 @@ int main(int argc, char **argv) char buffer[4096]; if (argc < 3 || argc > 4) { - g_printerr("Usage: run_filter CONFIG NAME [FORMAT] <IN\n"); - return 1; + fprintf(stderr, "Usage: run_filter CONFIG NAME [FORMAT] <IN\n"); + return EXIT_FAILURE; } const Path config_path = Path::FromFS(argv[1]); @@ -112,9 +113,8 @@ int main(int argc, char **argv) if (argc > 3) { Error error; if (!audio_format_parse(audio_format, argv[3], false, error)) { - g_printerr("Failed to parse audio format: %s\n", - error.GetMessage()); - return 1; + LogError(error, "Failed to parse audio format"); + return EXIT_FAILURE; } } @@ -122,20 +122,20 @@ int main(int argc, char **argv) Filter *filter = load_filter(argv[2]); if (filter == NULL) - return 1; + return EXIT_FAILURE; /* open the filter */ Error error; const AudioFormat out_audio_format = filter->Open(audio_format, error); if (!out_audio_format.IsDefined()) { - g_printerr("Failed to open filter: %s\n", error.GetMessage()); + LogError(error, "Failed to open filter"); delete filter; - return 1; + return EXIT_FAILURE; } - g_printerr("audio_format=%s\n", - audio_format_to_string(out_audio_format, &af_string)); + fprintf(stderr, "audio_format=%s\n", + audio_format_to_string(out_audio_format, &af_string)); /* play */ @@ -151,15 +151,16 @@ int main(int argc, char **argv) dest = filter->FilterPCM(buffer, (size_t)nbytes, &length, error); if (dest == NULL) { - g_printerr("Filter failed: %s\n", error.GetMessage()); + LogError(error, "Filter failed"); filter->Close(); delete filter; - return 1; + return EXIT_FAILURE; } nbytes = write(1, dest, length); if (nbytes < 0) { - g_printerr("Failed to write: %s\n", g_strerror(errno)); + fprintf(stderr, "Failed to write: %s\n", + strerror(errno)); filter->Close(); delete filter; return 1; diff --git a/test/run_inotify.cxx b/test/run_inotify.cxx index c57e6e9ef..8dcc371cc 100644 --- a/test/run_inotify.cxx +++ b/test/run_inotify.cxx @@ -24,8 +24,6 @@ #include "util/Error.hxx" #include "Log.hxx" -#include <glib.h> - #include <sys/inotify.h> static constexpr unsigned IN_MASK = @@ -39,7 +37,7 @@ static void my_inotify_callback(gcc_unused int wd, unsigned mask, const char *name, gcc_unused void *ctx) { - g_print("mask=0x%x name='%s'\n", mask, name); + printf("mask=0x%x name='%s'\n", mask, name); } int main(int argc, char **argv) @@ -47,8 +45,8 @@ int main(int argc, char **argv) const char *path; if (argc != 2) { - g_printerr("Usage: run_inotify PATH\n"); - return 1; + fprintf(stderr, "Usage: run_inotify PATH\n"); + return EXIT_FAILURE; } path = argv[1]; @@ -62,17 +60,18 @@ int main(int argc, char **argv) nullptr, error); if (source == NULL) { LogError(error); - return 2; + return EXIT_FAILURE; } int descriptor = source->Add(path, IN_MASK, error); if (descriptor < 0) { delete source; LogError(error); - return 2; + return EXIT_FAILURE; } event_loop.Run(); delete source; + return EXIT_SUCCESS; } diff --git a/test/run_output.cxx b/test/run_output.cxx index 7982bd7de..c7865bf2c 100644 --- a/test/run_output.cxx +++ b/test/run_output.cxx @@ -36,6 +36,7 @@ #include "PlayerControl.hxx" #include "stdbin.h" #include "util/Error.hxx" +#include "Log.hxx" #include <glib.h> @@ -83,7 +84,7 @@ load_audio_output(const char *name) param = find_named_config_block(CONF_AUDIO_OUTPUT, name); if (param == NULL) { - g_printerr("No such configured audio output: %s\n", name); + fprintf(stderr, "No such configured audio output: %s\n", name); return nullptr; } @@ -93,7 +94,7 @@ load_audio_output(const char *name) struct audio_output *ao = audio_output_new(*param, dummy_player_control, error); if (ao == nullptr) - g_printerr("%s\n", error.GetMessage()); + LogError(error); return ao; } @@ -105,21 +106,19 @@ run_output(struct audio_output *ao, AudioFormat audio_format) Error error; if (!ao_plugin_enable(ao, error)) { - g_printerr("Failed to enable audio output: %s\n", - error.GetMessage()); + LogError(error, "Failed to enable audio output"); return false; } if (!ao_plugin_open(ao, audio_format, error)) { ao_plugin_disable(ao); - g_printerr("Failed to open audio output: %s\n", - error.GetMessage()); + LogError(error, "Failed to open audio output"); return false; } struct audio_format_string af_string; - g_printerr("audio_format=%s\n", - audio_format_to_string(audio_format, &af_string)); + fprintf(stderr, "audio_format=%s\n", + audio_format_to_string(audio_format, &af_string)); size_t frame_size = audio_format.GetFrameSize(); @@ -145,8 +144,7 @@ run_output(struct audio_output *ao, AudioFormat audio_format) if (consumed == 0) { ao_plugin_close(ao); ao_plugin_disable(ao); - g_printerr("Failed to play: %s\n", - error.GetMessage()); + LogError(error, "Failed to play"); return false; } @@ -168,8 +166,8 @@ int main(int argc, char **argv) Error error; if (argc < 3 || argc > 4) { - g_printerr("Usage: run_output CONFIG NAME [FORMAT] <IN\n"); - return 1; + fprintf(stderr, "Usage: run_output CONFIG NAME [FORMAT] <IN\n"); + return EXIT_FAILURE; } const Path config_path = Path::FromFS(argv[1]); @@ -184,8 +182,8 @@ int main(int argc, char **argv) config_global_init(); if (!ReadConfigFile(config_path, error)) { - g_printerr("%s\n", error.GetMessage()); - return 1; + LogError(error); + return EXIT_FAILURE; } main_loop = new EventLoop(EventLoop::Default()); @@ -203,9 +201,8 @@ int main(int argc, char **argv) if (argc > 3) { if (!audio_format_parse(audio_format, argv[3], false, error)) { - g_printerr("Failed to parse audio format: %s\n", - error.GetMessage()); - return 1; + LogError(error, "Failed to parse audio format"); + return EXIT_FAILURE; } } diff --git a/test/run_resolver.cxx b/test/run_resolver.cxx index 65c55b4df..aba7238ec 100644 --- a/test/run_resolver.cxx +++ b/test/run_resolver.cxx @@ -22,8 +22,6 @@ #include "util/Error.hxx" #include "Log.hxx" -#include <glib.h> - #ifdef WIN32 #include <ws2tcpip.h> #include <winsock.h> @@ -37,7 +35,7 @@ int main(int argc, char **argv) { if (argc != 2) { - g_printerr("Usage: run_resolver HOST\n"); + fprintf(stderr, "Usage: run_resolver HOST\n"); return EXIT_FAILURE; } @@ -52,7 +50,7 @@ int main(int argc, char **argv) for (const struct addrinfo *i = ai; i != NULL; i = i->ai_next) { const auto s = sockaddr_to_string(i->ai_addr, i->ai_addrlen); - g_print("%s\n", s.c_str()); + printf("%s\n", s.c_str()); } freeaddrinfo(ai); diff --git a/test/software_volume.cxx b/test/software_volume.cxx index ae2d53a08..1a336f2df 100644 --- a/test/software_volume.cxx +++ b/test/software_volume.cxx @@ -30,8 +30,7 @@ #include "util/ConstBuffer.hxx" #include "util/Error.hxx" #include "stdbin.h" - -#include <glib.h> +#include "Log.hxx" #include <stddef.h> #include <stdlib.h> @@ -43,17 +42,16 @@ int main(int argc, char **argv) ssize_t nbytes; if (argc > 2) { - g_printerr("Usage: software_volume [FORMAT] <IN >OUT\n"); - return 1; + fprintf(stderr, "Usage: software_volume [FORMAT] <IN >OUT\n"); + return EXIT_FAILURE; } Error error; AudioFormat audio_format(48000, SampleFormat::S16, 2); if (argc > 1) { if (!audio_format_parse(audio_format, argv[1], false, error)) { - g_printerr("Failed to parse audio format: %s\n", - error.GetMessage()); - return 1; + LogError(error, "Failed to parse audio format"); + return EXIT_FAILURE; } } |