diff options
author | Max Kellermann <max@duempel.org> | 2013-12-15 17:12:43 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-12-15 18:52:13 +0100 |
commit | 66d90dd412cd102879a1ceff83df5aad9f08a21c (patch) | |
tree | 84f314c59cb64b3a1dcb8210e9f5ceac08c519eb | |
parent | d5dfe7d457b559bd9c53d65d0315c55611cc6a79 (diff) |
test/*: use fprintf(stderr,...) and Log() instead of g_printerr()
Avoid GLib.
-rw-r--r-- | test/read_conf.cxx | 32 | ||||
-rw-r--r-- | test/run_convert.cxx | 35 | ||||
-rw-r--r-- | test/run_decoder.cxx | 49 | ||||
-rw-r--r-- | test/run_encoder.cxx | 37 | ||||
-rw-r--r-- | test/run_input.cxx | 24 | ||||
-rw-r--r-- | test/run_normalize.cxx | 5 |
6 files changed, 63 insertions, 119 deletions
diff --git a/test/read_conf.cxx b/test/read_conf.cxx index d5eacec67..1f137e9a2 100644 --- a/test/read_conf.cxx +++ b/test/read_conf.cxx @@ -21,40 +21,26 @@ #include "ConfigGlobal.hxx" #include "fs/Path.hxx" #include "util/Error.hxx" - -#include <glib.h> +#include "Log.hxx" #include <assert.h> -static void -my_log_func(gcc_unused const gchar *log_domain, - GLogLevelFlags log_level, - const gchar *message, gcc_unused gpointer user_data) -{ - if (log_level > G_LOG_LEVEL_WARNING) - return; - - g_printerr("%s\n", message); -} - int main(int argc, char **argv) { if (argc != 3) { - g_printerr("Usage: read_conf FILE SETTING\n"); - return 1; + fprintf(stderr, "Usage: read_conf FILE SETTING\n"); + return EXIT_FAILURE; } const Path config_path = Path::FromFS(argv[1]); const char *name = argv[2]; - g_log_set_default_handler(my_log_func, NULL); - config_global_init(); Error error; if (!ReadConfigFile(config_path, error)) { - g_printerr("%s:", error.GetMessage()); - return 1; + LogError(error); + return EXIT_FAILURE; } ConfigOption option = ParseConfigOptionName(name); @@ -63,11 +49,11 @@ int main(int argc, char **argv) : nullptr; int ret; if (value != NULL) { - g_print("%s\n", value); - ret = 0; + printf("%s\n", value); + ret = EXIT_SUCCESS; } else { - g_printerr("No such setting: %s\n", name); - ret = 2; + fprintf(stderr, "No such setting: %s\n", name); + ret = EXIT_FAILURE; } config_global_finish(); diff --git a/test/run_convert.cxx b/test/run_convert.cxx index d9a1b7f08..67783592c 100644 --- a/test/run_convert.cxx +++ b/test/run_convert.cxx @@ -30,25 +30,14 @@ #include "ConfigGlobal.hxx" #include "util/FifoBuffer.hxx" #include "util/Error.hxx" +#include "Log.hxx" #include "stdbin.h" -#include <glib.h> - #include <assert.h> #include <stddef.h> #include <stdlib.h> #include <unistd.h> -static void -my_log_func(const gchar *log_domain, gcc_unused GLogLevelFlags log_level, - const gchar *message, gcc_unused gpointer user_data) -{ - if (log_domain != NULL) - g_printerr("%s: %s\n", log_domain, message); - else - g_printerr("%s\n", message); -} - const char * config_get_string(gcc_unused enum ConfigOption option, const char *default_value) @@ -62,26 +51,23 @@ int main(int argc, char **argv) const void *output; if (argc != 3) { - g_printerr("Usage: run_convert IN_FORMAT OUT_FORMAT <IN >OUT\n"); + fprintf(stderr, + "Usage: run_convert IN_FORMAT OUT_FORMAT <IN >OUT\n"); return 1; } - g_log_set_default_handler(my_log_func, NULL); - Error error; if (!audio_format_parse(in_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; } AudioFormat out_audio_format_mask; if (!audio_format_parse(out_audio_format_mask, argv[2], true, error)) { - g_printerr("Failed to parse audio format: %s\n", - error.GetMessage()); - return 1; + LogError(error, "Failed to parse audio format"); + return EXIT_FAILURE; } out_audio_format = in_audio_format; @@ -91,8 +77,7 @@ int main(int argc, char **argv) PcmConvert state; if (!state.Open(in_audio_format, out_audio_format_mask, error)) { - g_printerr("Failed to open PcmConvert: %s\n", - error.GetMessage()); + LogError(error, "Failed to open PcmConvert"); return EXIT_FAILURE; } @@ -124,8 +109,8 @@ int main(int argc, char **argv) &length, error); if (output == NULL) { state.Close(); - g_printerr("Failed to convert: %s\n", error.GetMessage()); - return 2; + LogError(error, "Failed to convert"); + return EXIT_FAILURE; } gcc_unused ssize_t ignored = write(1, output, length); diff --git a/test/run_decoder.cxx b/test/run_decoder.cxx index 56ef2068d..fb29bd3b3 100644 --- a/test/run_decoder.cxx +++ b/test/run_decoder.cxx @@ -36,16 +36,7 @@ #include <assert.h> #include <unistd.h> #include <stdlib.h> - -static void -my_log_func(const gchar *log_domain, gcc_unused GLogLevelFlags log_level, - const gchar *message, gcc_unused gpointer user_data) -{ - if (log_domain != NULL) - g_printerr("%s: %s\n", log_domain, message); - else - g_printerr("%s\n", message); -} +#include <stdio.h> struct Decoder { const char *uri; @@ -66,9 +57,9 @@ decoder_initialized(Decoder &decoder, assert(!decoder.initialized); assert(audio_format.IsValid()); - g_printerr("audio_format=%s duration=%f\n", - audio_format_to_string(audio_format, &af_string), - duration); + fprintf(stderr, "audio_format=%s duration=%f\n", + audio_format_to_string(audio_format, &af_string), + duration); decoder.initialized = true; } @@ -167,13 +158,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 @@ -186,8 +177,8 @@ int main(int argc, char **argv) const char *decoder_name; if (argc != 3) { - g_printerr("Usage: run_decoder DECODER URI >OUT\n"); - return 1; + fprintf(stderr, "Usage: run_decoder DECODER URI >OUT\n"); + return EXIT_FAILURE; } Decoder decoder; @@ -200,23 +191,21 @@ int main(int argc, char **argv) #endif #endif - g_log_set_default_handler(my_log_func, NULL); - io_thread_init(); io_thread_start(); Error error; if (!input_stream_global_init(error)) { LogError(error); - return 2; + return EXIT_FAILURE; } decoder_plugin_init_all(); decoder.plugin = decoder_plugin_from_name(decoder_name); if (decoder.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; } decoder.initialized = false; @@ -233,17 +222,17 @@ 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 1; + return EXIT_FAILURE; } decoder.plugin->StreamDecode(decoder, *is); is->Close(); } else { - g_printerr("Decoder plugin is not usable\n"); - return 1; + fprintf(stderr, "Decoder plugin is not usable\n"); + return EXIT_FAILURE; } decoder_plugin_deinit_all(); @@ -251,8 +240,8 @@ int main(int argc, char **argv) io_thread_deinit(); if (!decoder.initialized) { - g_printerr("Decoding failed\n"); - return 1; + fprintf(stderr, "Decoding failed\n"); + return EXIT_FAILURE; } return 0; diff --git a/test/run_encoder.cxx b/test/run_encoder.cxx index 0eba87d64..166af08ef 100644 --- a/test/run_encoder.cxx +++ b/test/run_encoder.cxx @@ -24,10 +24,9 @@ #include "AudioParser.hxx" #include "ConfigData.hxx" #include "util/Error.hxx" +#include "Log.hxx" #include "stdbin.h" -#include <glib.h> - #include <stddef.h> #include <unistd.h> @@ -50,8 +49,9 @@ int main(int argc, char **argv) /* parse command line */ if (argc > 3) { - g_printerr("Usage: run_encoder [ENCODER] [FORMAT] <IN >OUT\n"); - return 1; + fprintf(stderr, + "Usage: run_encoder [ENCODER] [FORMAT] <IN >OUT\n"); + return EXIT_FAILURE; } if (argc > 1) @@ -63,8 +63,8 @@ int main(int argc, char **argv) const auto plugin = encoder_plugin_get(encoder_name); if (plugin == NULL) { - g_printerr("No such encoder: %s\n", encoder_name); - return 1; + fprintf(stderr, "No such encoder: %s\n", encoder_name); + return EXIT_FAILURE; } config_param param; @@ -73,9 +73,8 @@ int main(int argc, char **argv) Error error; const auto encoder = encoder_init(*plugin, param, error); if (encoder == NULL) { - g_printerr("Failed to initialize encoder: %s\n", - error.GetMessage()); - return 1; + LogError(error, "Failed to initialize encoder"); + return EXIT_FAILURE; } /* open the encoder */ @@ -83,16 +82,14 @@ int main(int argc, char **argv) AudioFormat audio_format(44100, SampleFormat::S16, 2); if (argc > 2) { if (!audio_format_parse(audio_format, argv[2], 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; } } if (!encoder_open(encoder, audio_format, error)) { - g_printerr("Failed to open encoder: %s\n", - error.GetMessage()); - return 1; + LogError(error, "Failed to open encoder"); + return EXIT_FAILURE; } encoder_to_stdout(*encoder); @@ -102,18 +99,16 @@ int main(int argc, char **argv) ssize_t nbytes; while ((nbytes = read(0, buffer, sizeof(buffer))) > 0) { if (!encoder_write(encoder, buffer, nbytes, error)) { - g_printerr("encoder_write() failed: %s\n", - error.GetMessage()); - return 1; + LogError(error, "encoder_write() failed"); + return EXIT_FAILURE; } encoder_to_stdout(*encoder); } if (!encoder_end(encoder, error)) { - g_printerr("encoder_flush() failed: %s\n", - error.GetMessage()); - return 1; + LogError(error, "encoder_flush() failed"); + return EXIT_FAILURE; } encoder_to_stdout(*encoder); diff --git a/test/run_input.cxx b/test/run_input.cxx index 23316b7c6..fcf4107c4 100644 --- a/test/run_input.cxx +++ b/test/run_input.cxx @@ -40,16 +40,6 @@ #include <unistd.h> #include <stdlib.h> -static void -my_log_func(const gchar *log_domain, gcc_unused GLogLevelFlags log_level, - const gchar *message, gcc_unused gpointer user_data) -{ - if (log_domain != NULL) - g_printerr("%s: %s\n", log_domain, message); - else - g_printerr("%s\n", message); -} - static int dump_input_stream(InputStream *is) { @@ -73,14 +63,14 @@ dump_input_stream(InputStream *is) /* print meta data */ if (!is->mime.empty()) - g_printerr("MIME type: %s\n", is->mime.c_str()); + fprintf(stderr, "MIME type: %s\n", is->mime.c_str()); /* read data and tags from the stream */ while (!is->IsEOF()) { Tag *tag = is->ReadTag(); if (tag != NULL) { - g_printerr("Received a tag:\n"); + fprintf(stderr, "Received a tag:\n"); tag_save(stderr, *tag); delete tag; } @@ -116,8 +106,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 */ @@ -128,8 +118,6 @@ int main(int argc, char **argv) #endif #endif - g_log_set_default_handler(my_log_func, NULL); - /* initialize MPD */ config_global_init(); @@ -159,8 +147,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/run_normalize.cxx b/test/run_normalize.cxx index 3193fefd2..091c3d61a 100644 --- a/test/run_normalize.cxx +++ b/test/run_normalize.cxx @@ -33,6 +33,7 @@ #include <glib.h> #include <stddef.h> +#include <stdio.h> #include <unistd.h> #include <string.h> @@ -43,7 +44,7 @@ int main(int argc, char **argv) ssize_t nbytes; if (argc > 2) { - g_printerr("Usage: run_normalize [FORMAT] <IN >OUT\n"); + fprintf(stderr, "Usage: run_normalize [FORMAT] <IN >OUT\n"); return 1; } @@ -51,7 +52,7 @@ int main(int argc, char **argv) if (argc > 1) { Error error; if (!audio_format_parse(audio_format, argv[1], false, error)) { - g_printerr("Failed to parse audio format: %s\n", + fprintf(stderr, "Failed to parse audio format: %s\n", error.GetMessage()); return 1; } |