aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-08-10 18:02:44 +0200
committerMax Kellermann <max@duempel.org>2013-09-04 18:14:22 +0200
commit29030b54c98b0aee65fbc10ebf7ba36bed98c02c (patch)
tree79766830b55ebca38ddbce84d8d548227eedb69e /test
parentc9fcc7f14860777458153eb2d13c773ccfa1daa2 (diff)
downloadmpd-29030b54c98b0aee65fbc10ebf7ba36bed98c02c.tar.gz
mpd-29030b54c98b0aee65fbc10ebf7ba36bed98c02c.tar.xz
mpd-29030b54c98b0aee65fbc10ebf7ba36bed98c02c.zip
util/Error: new error passing library
Replaces GLib's GError.
Diffstat (limited to '')
-rw-r--r--test/DumpDatabase.cxx30
-rw-r--r--test/dump_playlist.cxx26
-rw-r--r--test/dump_rva2.cxx13
-rw-r--r--test/dump_text_file.cxx31
-rw-r--r--test/read_conf.cxx8
-rw-r--r--test/read_mixer.cxx24
-rw-r--r--test/read_tags.cxx22
-rw-r--r--test/run_convert.cxx15
-rw-r--r--test/run_decoder.cxx20
-rw-r--r--test/run_encoder.cxx33
-rw-r--r--test/run_filter.cxx40
-rw-r--r--test/run_inotify.cxx13
-rw-r--r--test/run_input.cxx37
-rw-r--r--test/run_normalize.cxx10
-rw-r--r--test/run_output.cxx60
-rw-r--r--test/run_resolver.cxx15
-rw-r--r--test/software_volume.cxx10
-rw-r--r--test/test_vorbis_encoder.cxx17
-rw-r--r--test/visit_archive.cxx13
19 files changed, 187 insertions, 250 deletions
diff --git a/test/DumpDatabase.cxx b/test/DumpDatabase.cxx
index e788d625a..cf86d91ff 100644
--- a/test/DumpDatabase.cxx
+++ b/test/DumpDatabase.cxx
@@ -27,6 +27,7 @@
#include "conf.h"
#include "Tag.hxx"
#include "fs/Path.hxx"
+#include "util/Error.hxx"
#include <iostream>
using std::cout;
@@ -46,14 +47,14 @@ my_log_func(const gchar *log_domain, gcc_unused GLogLevelFlags log_level,
}
static bool
-DumpDirectory(const Directory &directory, GError **)
+DumpDirectory(const Directory &directory, Error &)
{
cout << "D " << directory.path << endl;
return true;
}
static bool
-DumpSong(Song &song, GError **)
+DumpSong(Song &song, Error &)
{
cout << "S " << song.parent->path << "/" << song.uri << endl;
return true;
@@ -61,7 +62,7 @@ DumpSong(Song &song, GError **)
static bool
DumpPlaylist(const PlaylistInfo &playlist,
- const Directory &directory, GError **)
+ const Directory &directory, Error &)
{
cout << "P " << directory.path << "/" << playlist.name.c_str() << endl;
return true;
@@ -70,8 +71,6 @@ DumpPlaylist(const PlaylistInfo &playlist,
int
main(int argc, char **argv)
{
- GError *error = nullptr;
-
if (argc != 3) {
cerr << "Usage: DumpDatabase CONFIG PLUGIN" << endl;
return 1;
@@ -98,9 +97,9 @@ main(int argc, char **argv)
config_global_init();
- if (!ReadConfigFile(config_path, &error)) {
- cerr << error->message << endl;
- g_error_free(error);
+ Error error;
+ if (!ReadConfigFile(config_path, error)) {
+ cerr << error.GetMessage() << endl;
return EXIT_FAILURE;
}
@@ -113,29 +112,26 @@ main(int argc, char **argv)
if (path != nullptr)
param.AddBlockParam("path", path->value, path->line);
- Database *db = plugin->create(param, &error);
+ Database *db = plugin->create(param, error);
if (db == nullptr) {
- cerr << error->message << endl;
- g_error_free(error);
+ cerr << error.GetMessage() << endl;
return EXIT_FAILURE;
}
- if (!db->Open(&error)) {
+ if (!db->Open(error)) {
delete db;
- cerr << error->message << endl;
- g_error_free(error);
+ cerr << error.GetMessage() << endl;
return EXIT_FAILURE;
}
const DatabaseSelection selection("", true);
if (!db->Visit(selection, DumpDirectory, DumpSong, DumpPlaylist,
- &error)) {
+ error)) {
db->Close();
delete db;
- cerr << error->message << endl;
- g_error_free(error);
+ cerr << error.GetMessage() << endl;
return EXIT_FAILURE;
}
diff --git a/test/dump_playlist.cxx b/test/dump_playlist.cxx
index 768eee367..c3cdf638f 100644
--- a/test/dump_playlist.cxx
+++ b/test/dump_playlist.cxx
@@ -30,6 +30,7 @@
#include "PlaylistRegistry.hxx"
#include "PlaylistPlugin.hxx"
#include "fs/Path.hxx"
+#include "util/Error.hxx"
#include <glib.h>
@@ -84,7 +85,8 @@ decoder_read(gcc_unused struct decoder *decoder,
struct input_stream *is,
void *buffer, size_t length)
{
- return input_stream_lock_read(is, buffer, length, NULL);
+ Error error;
+ return input_stream_lock_read(is, buffer, length, error);
}
void
@@ -139,7 +141,6 @@ int main(int argc, char **argv)
{
const char *uri;
struct input_stream *is = NULL;
- GError *error = NULL;
struct playlist_provider *playlist;
Song *song;
@@ -162,18 +163,18 @@ int main(int argc, char **argv)
/* initialize MPD */
config_global_init();
- if (!ReadConfigFile(config_path, &error)) {
- g_printerr("%s\n", error->message);
- g_error_free(error);
+
+ Error error;
+ if (!ReadConfigFile(config_path, error)) {
+ g_printerr("%s\n", error.GetMessage());
return 1;
}
io_thread_init();
io_thread_start();
- if (!input_stream_global_init(&error)) {
- g_warning("%s", error->message);
- g_error_free(error);
+ if (!input_stream_global_init(error)) {
+ g_warning("%s", error.GetMessage());
return 2;
}
@@ -189,12 +190,11 @@ int main(int argc, char **argv)
if (playlist == NULL) {
/* open the stream and wait until it becomes ready */
- is = input_stream_open(uri, mutex, cond, &error);
+ is = input_stream_open(uri, mutex, cond, error);
if (is == NULL) {
- if (error != NULL) {
- g_warning("%s", error->message);
- g_error_free(error);
- } else
+ if (error.IsDefined())
+ g_warning("%s", error.GetMessage());
+ else
g_printerr("input_stream_open() failed\n");
return 2;
}
diff --git a/test/dump_rva2.cxx b/test/dump_rva2.cxx
index 9dbb018d6..95a55eb43 100644
--- a/test/dump_rva2.cxx
+++ b/test/dump_rva2.cxx
@@ -23,6 +23,7 @@
#include "replay_gain_info.h"
#include "conf.h"
#include "Tag.hxx"
+#include "util/Error.hxx"
#include <id3tag.h>
@@ -51,8 +52,6 @@ Tag::~Tag() {}
int main(int argc, char **argv)
{
- GError *error = NULL;
-
#ifdef HAVE_LOCALE_H
/* initialize locale */
setlocale(LC_CTYPE,"");
@@ -65,12 +64,12 @@ int main(int argc, char **argv)
const char *path = argv[1];
- struct id3_tag *tag = tag_id3_load(path, &error);
+ Error error;
+ struct id3_tag *tag = tag_id3_load(path, error);
if (tag == NULL) {
- if (error != NULL) {
- g_printerr("%s\n", error->message);
- g_error_free(error);
- } else
+ if (error.IsDefined())
+ g_printerr("%s\n", error.GetMessage());
+ else
g_printerr("No ID3 tag found\n");
return EXIT_FAILURE;
diff --git a/test/dump_text_file.cxx b/test/dump_text_file.cxx
index 165a6493c..a9f8c95a2 100644
--- a/test/dump_text_file.cxx
+++ b/test/dump_text_file.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2011 The Music Player Daemon Project
+ * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -24,6 +24,7 @@
#include "conf.h"
#include "stdbin.h"
#include "TextInputStream.hxx"
+#include "util/Error.hxx"
#ifdef ENABLE_ARCHIVE
#include "ArchiveList.hxx"
@@ -56,7 +57,7 @@ dump_text_file(TextInputStream &is)
static int
dump_input_stream(struct input_stream *is)
{
- GError *error = NULL;
+ Error error;
input_stream_lock(is);
@@ -64,9 +65,8 @@ dump_input_stream(struct input_stream *is)
input_stream_wait_ready(is);
- if (!input_stream_check(is, &error)) {
- g_warning("%s", error->message);
- g_error_free(error);
+ if (!input_stream_check(is, error)) {
+ g_warning("%s", error.GetMessage());
input_stream_unlock(is);
return EXIT_FAILURE;
}
@@ -80,9 +80,8 @@ dump_input_stream(struct input_stream *is)
}
input_stream_lock(is);
- if (!input_stream_check(is, &error)) {
- g_warning("%s", error->message);
- g_error_free(error);
+ if (!input_stream_check(is, error)) {
+ g_warning("%s", error.GetMessage());
input_stream_unlock(is);
return EXIT_FAILURE;
}
@@ -94,7 +93,6 @@ dump_input_stream(struct input_stream *is)
int main(int argc, char **argv)
{
- GError *error = NULL;
struct input_stream *is;
int ret;
@@ -122,9 +120,9 @@ int main(int argc, char **argv)
archive_plugin_init_all();
#endif
- if (!input_stream_global_init(&error)) {
- g_warning("%s", error->message);
- g_error_free(error);
+ Error error;
+ if (!input_stream_global_init(error)) {
+ g_warning("%s", error.GetMessage());
return 2;
}
@@ -133,15 +131,14 @@ int main(int argc, char **argv)
Mutex mutex;
Cond cond;
- is = input_stream_open(argv[1], mutex, cond, &error);
+ is = input_stream_open(argv[1], mutex, cond, error);
if (is != NULL) {
ret = dump_input_stream(is);
input_stream_close(is);
} else {
- if (error != NULL) {
- g_warning("%s", error->message);
- g_error_free(error);
- } else
+ if (error.IsDefined())
+ g_warning("%s", error.GetMessage());
+ else
g_printerr("input_stream_open() failed\n");
ret = 2;
}
diff --git a/test/read_conf.cxx b/test/read_conf.cxx
index 79f3eca54..55ff8c068 100644
--- a/test/read_conf.cxx
+++ b/test/read_conf.cxx
@@ -20,6 +20,7 @@
#include "config.h"
#include "conf.h"
#include "fs/Path.hxx"
+#include "util/Error.hxx"
#include <glib.h>
@@ -50,10 +51,9 @@ int main(int argc, char **argv)
config_global_init();
- GError *error = NULL;
- if (!ReadConfigFile(config_path, &error)) {
- g_printerr("%s:", error->message);
- g_error_free(error);
+ Error error;
+ if (!ReadConfigFile(config_path, error)) {
+ g_printerr("%s:", error.GetMessage());
return 1;
}
diff --git a/test/read_mixer.cxx b/test/read_mixer.cxx
index 0cc84c9b9..8426443ae 100644
--- a/test/read_mixer.cxx
+++ b/test/read_mixer.cxx
@@ -26,6 +26,7 @@
#include "Main.hxx"
#include "event/Loop.hxx"
#include "ConfigData.hxx"
+#include "util/Error.hxx"
#include <glib.h>
@@ -63,7 +64,7 @@ pulse_output_clear_mixer(gcc_unused PulseOutput *po,
bool
pulse_output_set_volume(gcc_unused PulseOutput *po,
gcc_unused const struct pa_cvolume *volume,
- gcc_unused GError **error_r)
+ gcc_unused Error &error)
{
return false;
}
@@ -111,8 +112,6 @@ pcm_volume(gcc_unused void *buffer, gcc_unused size_t length,
int main(int argc, gcc_unused char **argv)
{
- GError *error = NULL;
- bool success;
int volume;
if (argc != 2) {
@@ -126,23 +125,21 @@ int main(int argc, gcc_unused char **argv)
main_loop = new EventLoop(EventLoop::Default());
+ Error error;
Mixer *mixer = mixer_new(&alsa_mixer_plugin, nullptr,
- config_param(), &error);
+ config_param(), error);
if (mixer == NULL) {
- g_printerr("mixer_new() failed: %s\n", error->message);
- g_error_free(error);
+ g_printerr("mixer_new() failed: %s\n", error.GetMessage());
return 2;
}
- success = mixer_open(mixer, &error);
- if (!success) {
+ if (!mixer_open(mixer, error)) {
mixer_free(mixer);
- g_printerr("failed to open the mixer: %s\n", error->message);
- g_error_free(error);
+ g_printerr("failed to open the mixer: %s\n", error.GetMessage());
return 2;
}
- volume = mixer_get_volume(mixer, &error);
+ volume = mixer_get_volume(mixer, error);
mixer_close(mixer);
mixer_free(mixer);
@@ -151,10 +148,9 @@ int main(int argc, gcc_unused char **argv)
assert(volume >= -1 && volume <= 100);
if (volume < 0) {
- if (error != NULL) {
+ if (error.IsDefined()) {
g_printerr("failed to read volume: %s\n",
- error->message);
- g_error_free(error);
+ error.GetMessage());
} else
g_printerr("failed to read volume\n");
return 2;
diff --git a/test/read_tags.cxx b/test/read_tags.cxx
index d72721324..8e45be930 100644
--- a/test/read_tags.cxx
+++ b/test/read_tags.cxx
@@ -27,6 +27,7 @@
#include "TagHandler.hxx"
#include "TagId3.hxx"
#include "ApeTag.hxx"
+#include "util/Error.hxx"
#include <glib.h>
@@ -70,7 +71,8 @@ decoder_read(gcc_unused struct decoder *decoder,
struct input_stream *is,
void *buffer, size_t length)
{
- return input_stream_lock_read(is, buffer, length, NULL);
+ Error error;
+ return input_stream_lock_read(is, buffer, length, error);
}
void
@@ -140,7 +142,6 @@ static const struct tag_handler print_handler = {
int main(int argc, char **argv)
{
- GError *error = NULL;
const char *decoder_name, *path;
const struct decoder_plugin *plugin;
@@ -164,9 +165,9 @@ int main(int argc, char **argv)
io_thread_init();
io_thread_start();
- if (!input_stream_global_init(&error)) {
- g_warning("%s", error->message);
- g_error_free(error);
+ Error error;
+ if (!input_stream_global_init(error)) {
+ g_warning("%s", error.GetMessage());
return 2;
}
@@ -185,12 +186,11 @@ int main(int argc, char **argv)
Cond cond;
struct input_stream *is =
- input_stream_open(path, mutex, cond, &error);
+ input_stream_open(path, mutex, cond, error);
if (is == NULL) {
g_printerr("Failed to open %s: %s\n",
- path, error->message);
- g_error_free(error);
+ path, error.GetMessage());
return 1;
}
@@ -201,13 +201,11 @@ int main(int argc, char **argv)
input_stream_update(is);
}
- if (!input_stream_check(is, &error)) {
+ if (!input_stream_check(is, error)) {
mutex.unlock();
g_printerr("Failed to read %s: %s\n",
- path, error->message);
- g_error_free(error);
-
+ path, error.GetMessage());
return EXIT_FAILURE;
}
diff --git a/test/run_convert.cxx b/test/run_convert.cxx
index 37e2c8734..72e457338 100644
--- a/test/run_convert.cxx
+++ b/test/run_convert.cxx
@@ -29,6 +29,7 @@
#include "pcm/PcmConvert.hxx"
#include "conf.h"
#include "util/fifo_buffer.h"
+#include "util/Error.hxx"
#include "stdbin.h"
#include <glib.h>
@@ -56,7 +57,6 @@ config_get_string(gcc_unused enum ConfigOption option,
int main(int argc, char **argv)
{
- GError *error = NULL;
AudioFormat in_audio_format, out_audio_format;
const void *output;
ssize_t nbytes;
@@ -69,18 +69,19 @@ int main(int argc, char **argv)
g_log_set_default_handler(my_log_func, NULL);
+ Error error;
if (!audio_format_parse(in_audio_format, argv[1],
- false, &error)) {
+ false, error)) {
g_printerr("Failed to parse audio format: %s\n",
- error->message);
+ error.GetMessage());
return 1;
}
AudioFormat out_audio_format_mask;
if (!audio_format_parse(out_audio_format_mask, argv[2],
- true, &error)) {
+ true, error)) {
g_printerr("Failed to parse audio format: %s\n",
- error->message);
+ error.GetMessage());
return 1;
}
@@ -113,9 +114,9 @@ int main(int argc, char **argv)
fifo_buffer_consume(buffer, length);
output = state.Convert(in_audio_format, src, length,
- out_audio_format, &length, &error);
+ out_audio_format, &length, error);
if (output == NULL) {
- g_printerr("Failed to convert: %s\n", error->message);
+ g_printerr("Failed to convert: %s\n", error.GetMessage());
return 2;
}
diff --git a/test/run_decoder.cxx b/test/run_decoder.cxx
index c7ef92cf8..fb06c637a 100644
--- a/test/run_decoder.cxx
+++ b/test/run_decoder.cxx
@@ -24,6 +24,7 @@
#include "InputInit.hxx"
#include "InputLegacy.hxx"
#include "AudioFormat.hxx"
+#include "util/Error.hxx"
#include "stdbin.h"
#include <glib.h>
@@ -91,7 +92,8 @@ decoder_read(gcc_unused struct decoder *decoder,
struct input_stream *is,
void *buffer, size_t length)
{
- return input_stream_lock_read(is, buffer, length, NULL);
+ Error error;
+ return input_stream_lock_read(is, buffer, length, error);
}
void
@@ -144,7 +146,6 @@ decoder_mixramp(gcc_unused struct decoder *decoder,
int main(int argc, char **argv)
{
- GError *error = NULL;
const char *decoder_name;
struct decoder decoder;
@@ -165,9 +166,9 @@ int main(int argc, char **argv)
io_thread_init();
io_thread_start();
- if (!input_stream_global_init(&error)) {
- g_warning("%s", error->message);
- g_error_free(error);
+ Error error;
+ if (!input_stream_global_init(error)) {
+ g_warning("%s", error.GetMessage());
return 2;
}
@@ -189,12 +190,11 @@ int main(int argc, char **argv)
Cond cond;
struct input_stream *is =
- input_stream_open(decoder.uri, mutex, cond, &error);
+ input_stream_open(decoder.uri, mutex, cond, error);
if (is == NULL) {
- if (error != NULL) {
- g_warning("%s", error->message);
- g_error_free(error);
- } else
+ if (error.IsDefined())
+ g_warning("%s", error.GetMessage());
+ else
g_printerr("input_stream_open() failed\n");
return 1;
diff --git a/test/run_encoder.cxx b/test/run_encoder.cxx
index b7d64e40a..46edc9618 100644
--- a/test/run_encoder.cxx
+++ b/test/run_encoder.cxx
@@ -23,6 +23,7 @@
#include "AudioFormat.hxx"
#include "AudioParser.hxx"
#include "conf.h"
+#include "util/Error.hxx"
#include "stdbin.h"
#include <glib.h>
@@ -43,8 +44,6 @@ encoder_to_stdout(Encoder &encoder)
int main(int argc, char **argv)
{
- GError *error = NULL;
- bool ret;
const char *encoder_name;
static char buffer[32768];
@@ -71,11 +70,11 @@ int main(int argc, char **argv)
config_param param;
param.AddBlockParam("quality", "5.0", -1);
- const auto encoder = encoder_init(*plugin, param, &error);
+ Error error;
+ const auto encoder = encoder_init(*plugin, param, error);
if (encoder == NULL) {
g_printerr("Failed to initialize encoder: %s\n",
- error->message);
- g_error_free(error);
+ error.GetMessage());
return 1;
}
@@ -83,20 +82,16 @@ int main(int argc, char **argv)
AudioFormat audio_format(44100, SampleFormat::S16, 2);
if (argc > 2) {
- ret = audio_format_parse(audio_format, argv[2],
- false, &error);
- if (!ret) {
+ if (!audio_format_parse(audio_format, argv[2], false, error)) {
g_printerr("Failed to parse audio format: %s\n",
- error->message);
- g_error_free(error);
+ error.GetMessage());
return 1;
}
}
- if (!encoder_open(encoder, audio_format, &error)) {
+ if (!encoder_open(encoder, audio_format, error)) {
g_printerr("Failed to open encoder: %s\n",
- error->message);
- g_error_free(error);
+ error.GetMessage());
return 1;
}
@@ -106,22 +101,18 @@ int main(int argc, char **argv)
ssize_t nbytes;
while ((nbytes = read(0, buffer, sizeof(buffer))) > 0) {
- ret = encoder_write(encoder, buffer, nbytes, &error);
- if (!ret) {
+ if (!encoder_write(encoder, buffer, nbytes, error)) {
g_printerr("encoder_write() failed: %s\n",
- error->message);
- g_error_free(error);
+ error.GetMessage());
return 1;
}
encoder_to_stdout(*encoder);
}
- ret = encoder_end(encoder, &error);
- if (!ret) {
+ if (!encoder_end(encoder, error)) {
g_printerr("encoder_flush() failed: %s\n",
- error->message);
- g_error_free(error);
+ error.GetMessage());
return 1;
}
diff --git a/test/run_filter.cxx b/test/run_filter.cxx
index e39626ea5..62f8dde31 100644
--- a/test/run_filter.cxx
+++ b/test/run_filter.cxx
@@ -27,6 +27,8 @@
#include "pcm/PcmVolume.hxx"
#include "MixerControl.hxx"
#include "stdbin.h"
+#include "util/Error.hxx"
+#include "system/FatalError.hxx"
#include <glib.h>
@@ -37,7 +39,7 @@
bool
mixer_set_volume(gcc_unused Mixer *mixer,
- gcc_unused unsigned volume, gcc_unused GError **error_r)
+ gcc_unused unsigned volume, gcc_unused Error &error)
{
return true;
}
@@ -70,7 +72,6 @@ static Filter *
load_filter(const char *name)
{
const struct config_param *param;
- GError *error = NULL;
param = find_named_config_block(CONF_AUDIO_FILTER, name);
if (param == NULL) {
@@ -78,10 +79,10 @@ load_filter(const char *name)
return nullptr;
}
- Filter *filter = filter_configured_new(*param, &error);
+ Error error;
+ Filter *filter = filter_configured_new(*param, error);
if (filter == NULL) {
- g_printerr("Failed to load filter: %s\n", error->message);
- g_error_free(error);
+ g_printerr("Failed to load filter: %s\n", error.GetMessage());
return NULL;
}
@@ -91,8 +92,7 @@ load_filter(const char *name)
int main(int argc, char **argv)
{
struct audio_format_string af_string;
- bool success;
- GError *error = NULL;
+ Error error2;
char buffer[4096];
if (argc < 3 || argc > 4) {
@@ -115,21 +115,16 @@ int main(int argc, char **argv)
/* read configuration file (mpd.conf) */
config_global_init();
- if (!ReadConfigFile(config_path, &error)) {
- g_printerr("%s:", error->message);
- g_error_free(error);
- return 1;
- }
+ if (!ReadConfigFile(config_path, error2))
+ FatalError(error2);
/* parse the audio format */
if (argc > 3) {
- success = audio_format_parse(audio_format, argv[3],
- false, &error);
- if (!success) {
+ Error error;
+ if (!audio_format_parse(audio_format, argv[3], false, error)) {
g_printerr("Failed to parse audio format: %s\n",
- error->message);
- g_error_free(error);
+ error.GetMessage());
return 1;
}
}
@@ -142,11 +137,10 @@ int main(int argc, char **argv)
/* open the filter */
- const AudioFormat out_audio_format =
- filter->Open(audio_format, &error);
+ 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->message);
- g_error_free(error);
+ g_printerr("Failed to open filter: %s\n", error.GetMessage());
delete filter;
return 1;
}
@@ -166,9 +160,9 @@ int main(int argc, char **argv)
break;
dest = filter->FilterPCM(buffer, (size_t)nbytes,
- &length, &error);
+ &length, error);
if (dest == NULL) {
- g_printerr("Filter failed: %s\n", error->message);
+ g_printerr("Filter failed: %s\n", error.GetMessage());
filter->Close();
delete filter;
return 1;
diff --git a/test/run_inotify.cxx b/test/run_inotify.cxx
index e8ca4c8bd..459d0c504 100644
--- a/test/run_inotify.cxx
+++ b/test/run_inotify.cxx
@@ -20,6 +20,7 @@
#include "config.h"
#include "InotifySource.hxx"
#include "event/Loop.hxx"
+#include "util/Error.hxx"
#include <glib.h>
@@ -51,7 +52,6 @@ my_inotify_callback(gcc_unused int wd, unsigned mask,
int main(int argc, char **argv)
{
- GError *error = NULL;
const char *path;
if (argc != 2) {
@@ -63,20 +63,19 @@ int main(int argc, char **argv)
event_loop = new EventLoop(EventLoop::Default());
+ Error error;
InotifySource *source = InotifySource::Create(*event_loop,
my_inotify_callback,
- nullptr, &error);
+ nullptr, error);
if (source == NULL) {
- g_warning("%s", error->message);
- g_error_free(error);
+ g_warning("%s", error.GetMessage());
return 2;
}
- int descriptor = source->Add(path, IN_MASK, &error);
+ int descriptor = source->Add(path, IN_MASK, error);
if (descriptor < 0) {
delete source;
- g_warning("%s", error->message);
- g_error_free(error);
+ g_warning("%s", error.GetMessage());
return 2;
}
diff --git a/test/run_input.cxx b/test/run_input.cxx
index 494bcd823..3c74ab509 100644
--- a/test/run_input.cxx
+++ b/test/run_input.cxx
@@ -26,6 +26,7 @@
#include "InputStream.hxx"
#include "InputInit.hxx"
#include "IOThread.hxx"
+#include "util/Error.hxx"
#ifdef ENABLE_ARCHIVE
#include "ArchiveList.hxx"
@@ -49,7 +50,7 @@ my_log_func(const gchar *log_domain, gcc_unused GLogLevelFlags log_level,
static int
dump_input_stream(struct input_stream *is)
{
- GError *error = NULL;
+ Error error;
char buffer[4096];
size_t num_read;
ssize_t num_written;
@@ -60,9 +61,8 @@ dump_input_stream(struct input_stream *is)
input_stream_wait_ready(is);
- if (!input_stream_check(is, &error)) {
- g_warning("%s", error->message);
- g_error_free(error);
+ if (!input_stream_check(is, error)) {
+ g_warning("%s", error.GetMessage());
input_stream_unlock(is);
return EXIT_FAILURE;
}
@@ -83,12 +83,10 @@ dump_input_stream(struct input_stream *is)
}
num_read = input_stream_read(is, buffer, sizeof(buffer),
- &error);
+ error);
if (num_read == 0) {
- if (error != NULL) {
- g_warning("%s", error->message);
- g_error_free(error);
- }
+ if (error.IsDefined())
+ g_warning("%s", error.GetMessage());
break;
}
@@ -98,9 +96,8 @@ dump_input_stream(struct input_stream *is)
break;
}
- if (!input_stream_check(is, &error)) {
- g_warning("%s", error->message);
- g_error_free(error);
+ if (!input_stream_check(is, error)) {
+ g_warning("%s", error.GetMessage());
input_stream_unlock(is);
return EXIT_FAILURE;
}
@@ -112,7 +109,7 @@ dump_input_stream(struct input_stream *is)
int main(int argc, char **argv)
{
- GError *error = NULL;
+ Error error;
struct input_stream *is;
int ret;
@@ -140,9 +137,8 @@ int main(int argc, char **argv)
archive_plugin_init_all();
#endif
- if (!input_stream_global_init(&error)) {
- g_warning("%s", error->message);
- g_error_free(error);
+ if (!input_stream_global_init(error)) {
+ g_warning("%s", error.GetMessage());
return 2;
}
@@ -151,15 +147,14 @@ int main(int argc, char **argv)
Mutex mutex;
Cond cond;
- is = input_stream_open(argv[1], mutex, cond, &error);
+ is = input_stream_open(argv[1], mutex, cond, error);
if (is != NULL) {
ret = dump_input_stream(is);
input_stream_close(is);
} else {
- if (error != NULL) {
- g_warning("%s", error->message);
- g_error_free(error);
- } else
+ if (error.IsDefined())
+ g_warning("%s", error.GetMessage());
+ else
g_printerr("input_stream_open() failed\n");
ret = 2;
}
diff --git a/test/run_normalize.cxx b/test/run_normalize.cxx
index 5b51f4631..3193fefd2 100644
--- a/test/run_normalize.cxx
+++ b/test/run_normalize.cxx
@@ -27,6 +27,7 @@
#include "AudioCompress/compress.h"
#include "AudioParser.hxx"
#include "AudioFormat.hxx"
+#include "util/Error.hxx"
#include "stdbin.h"
#include <glib.h>
@@ -37,8 +38,6 @@
int main(int argc, char **argv)
{
- GError *error = NULL;
- bool ret;
struct Compressor *compressor;
static char buffer[4096];
ssize_t nbytes;
@@ -50,11 +49,10 @@ int main(int argc, char **argv)
AudioFormat audio_format(48000, SampleFormat::S16, 2);
if (argc > 1) {
- ret = audio_format_parse(audio_format, argv[1],
- false, &error);
- if (!ret) {
+ Error error;
+ if (!audio_format_parse(audio_format, argv[1], false, error)) {
g_printerr("Failed to parse audio format: %s\n",
- error->message);
+ error.GetMessage());
return 1;
}
}
diff --git a/test/run_output.cxx b/test/run_output.cxx
index 6bf4ebced..59c1a543e 100644
--- a/test/run_output.cxx
+++ b/test/run_output.cxx
@@ -33,6 +33,7 @@
#include "FilterRegistry.hxx"
#include "PlayerControl.hxx"
#include "stdbin.h"
+#include "util/Error.hxx"
#include <glib.h>
@@ -48,21 +49,6 @@ GlobalEvents::Emit(gcc_unused Event event)
{
}
-PcmConvert::PcmConvert() {}
-PcmConvert::~PcmConvert() {}
-
-const void *
-PcmConvert::Convert(gcc_unused const AudioFormat src_format,
- gcc_unused const void *src, gcc_unused size_t src_size,
- gcc_unused const AudioFormat dest_format,
- gcc_unused size_t *dest_size_r,
- gcc_unused GError **error_r)
-{
- g_set_error(error_r, pcm_convert_quark(), 0,
- "Not implemented");
- return NULL;
-}
-
const struct filter_plugin *
filter_plugin_by_name(gcc_unused const char *name)
{
@@ -92,7 +78,6 @@ static struct audio_output *
load_audio_output(const char *name)
{
const struct config_param *param;
- GError *error = NULL;
param = find_named_config_block(CONF_AUDIO_OUTPUT, name);
if (param == NULL) {
@@ -102,12 +87,11 @@ load_audio_output(const char *name)
static struct player_control dummy_player_control(32, 4);
+ Error error;
struct audio_output *ao =
- audio_output_new(*param, &dummy_player_control, &error);
- if (ao == NULL) {
- g_printerr("%s\n", error->message);
- g_error_free(error);
- }
+ audio_output_new(*param, &dummy_player_control, error);
+ if (ao == nullptr)
+ g_printerr("%s\n", error.GetMessage());
return ao;
}
@@ -117,19 +101,17 @@ run_output(struct audio_output *ao, AudioFormat audio_format)
{
/* open the audio output */
- GError *error = NULL;
- if (!ao_plugin_enable(ao, &error)) {
+ Error error;
+ if (!ao_plugin_enable(ao, error)) {
g_printerr("Failed to enable audio output: %s\n",
- error->message);
- g_error_free(error);
+ error.GetMessage());
return false;
}
- if (!ao_plugin_open(ao, audio_format, &error)) {
+ if (!ao_plugin_open(ao, audio_format, error)) {
ao_plugin_disable(ao);
g_printerr("Failed to open audio output: %s\n",
- error->message);
- g_error_free(error);
+ error.GetMessage());
return false;
}
@@ -157,13 +139,12 @@ run_output(struct audio_output *ao, AudioFormat audio_format)
if (play_length > 0) {
size_t consumed = ao_plugin_play(ao,
buffer, play_length,
- &error);
+ error);
if (consumed == 0) {
ao_plugin_close(ao);
ao_plugin_disable(ao);
g_printerr("Failed to play: %s\n",
- error->message);
- g_error_free(error);
+ error.GetMessage());
return false;
}
@@ -182,8 +163,7 @@ run_output(struct audio_output *ao, AudioFormat audio_format)
int main(int argc, char **argv)
{
- bool success;
- GError *error = NULL;
+ Error error;
if (argc < 3 || argc > 4) {
g_printerr("Usage: run_output CONFIG NAME [FORMAT] <IN\n");
@@ -201,9 +181,8 @@ int main(int argc, char **argv)
/* read configuration file (mpd.conf) */
config_global_init();
- if (!ReadConfigFile(config_path, &error)) {
- g_printerr("%s:", error->message);
- g_error_free(error);
+ if (!ReadConfigFile(config_path, error)) {
+ g_printerr("%s\n", error.GetMessage());
return 1;
}
@@ -221,19 +200,16 @@ int main(int argc, char **argv)
/* parse the audio format */
if (argc > 3) {
- success = audio_format_parse(audio_format, argv[3],
- false, &error);
- if (!success) {
+ if (!audio_format_parse(audio_format, argv[3], false, error)) {
g_printerr("Failed to parse audio format: %s\n",
- error->message);
- g_error_free(error);
+ error.GetMessage());
return 1;
}
}
/* do it */
- success = run_output(ao, audio_format);
+ bool success = run_output(ao, audio_format);
/* cleanup and exit */
diff --git a/test/run_resolver.cxx b/test/run_resolver.cxx
index bb7f6deaa..559e12934 100644
--- a/test/run_resolver.cxx
+++ b/test/run_resolver.cxx
@@ -19,6 +19,9 @@
#include "config.h"
#include "system/Resolver.hxx"
+#include "util/Error.hxx"
+
+#include <glib.h>
#ifdef WIN32
#include <ws2tcpip.h>
@@ -37,23 +40,21 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}
- GError *error = NULL;
+ Error error;
struct addrinfo *ai =
resolve_host_port(argv[1], 80, AI_PASSIVE, SOCK_STREAM,
- &error);
+ error);
if (ai == NULL) {
- g_printerr("%s\n", error->message);
- g_error_free(error);
+ g_warning("%s", error.GetMessage());
return EXIT_FAILURE;
}
for (const struct addrinfo *i = ai; i != NULL; i = i->ai_next) {
char *p = sockaddr_to_string(i->ai_addr, i->ai_addrlen,
- &error);
+ error);
if (p == NULL) {
freeaddrinfo(ai);
- g_printerr("%s\n", error->message);
- g_error_free(error);
+ g_warning("%s", error.GetMessage());
return EXIT_FAILURE;
}
diff --git a/test/software_volume.cxx b/test/software_volume.cxx
index d3b47d74a..19a0be88c 100644
--- a/test/software_volume.cxx
+++ b/test/software_volume.cxx
@@ -27,6 +27,7 @@
#include "pcm/PcmVolume.hxx"
#include "AudioParser.hxx"
#include "AudioFormat.hxx"
+#include "util/Error.hxx"
#include "stdbin.h"
#include <glib.h>
@@ -36,8 +37,6 @@
int main(int argc, char **argv)
{
- GError *error = NULL;
- bool ret;
static char buffer[4096];
ssize_t nbytes;
@@ -46,13 +45,12 @@ int main(int argc, char **argv)
return 1;
}
+ Error error;
AudioFormat audio_format(48000, SampleFormat::S16, 2);
if (argc > 1) {
- ret = audio_format_parse(audio_format, argv[1],
- false, &error);
- if (!ret) {
+ if (!audio_format_parse(audio_format, argv[1], false, error)) {
g_printerr("Failed to parse audio format: %s\n",
- error->message);
+ error.GetMessage());
return 1;
}
}
diff --git a/test/test_vorbis_encoder.cxx b/test/test_vorbis_encoder.cxx
index 12e17a785..3d1ac535b 100644
--- a/test/test_vorbis_encoder.cxx
+++ b/test/test_vorbis_encoder.cxx
@@ -24,8 +24,7 @@
#include "conf.h"
#include "stdbin.h"
#include "Tag.hxx"
-
-#include <glib.h>
+#include "util/Error.hxx"
#include <stddef.h>
#include <unistd.h>
@@ -56,27 +55,27 @@ main(gcc_unused int argc, gcc_unused char **argv)
config_param param;
param.AddBlockParam("quality", "5.0", -1);
- const auto encoder = encoder_init(*plugin, param, NULL);
+ const auto encoder = encoder_init(*plugin, param, IgnoreError());
assert(encoder != NULL);
/* open the encoder */
AudioFormat audio_format(44100, SampleFormat::S16, 2);
- success = encoder_open(encoder, audio_format, NULL);
+ success = encoder_open(encoder, audio_format, IgnoreError());
assert(success);
encoder_to_stdout(*encoder);
/* write a block of data */
- success = encoder_write(encoder, zero, sizeof(zero), NULL);
+ success = encoder_write(encoder, zero, sizeof(zero), IgnoreError());
assert(success);
encoder_to_stdout(*encoder);
/* write a tag */
- success = encoder_pre_tag(encoder, NULL);
+ success = encoder_pre_tag(encoder, IgnoreError());
assert(success);
encoder_to_stdout(*encoder);
@@ -85,19 +84,19 @@ main(gcc_unused int argc, gcc_unused char **argv)
tag.AddItem(TAG_ARTIST, "Foo");
tag.AddItem(TAG_TITLE, "Bar");
- success = encoder_tag(encoder, &tag, NULL);
+ success = encoder_tag(encoder, &tag, IgnoreError());
assert(success);
encoder_to_stdout(*encoder);
/* write another block of data */
- success = encoder_write(encoder, zero, sizeof(zero), NULL);
+ success = encoder_write(encoder, zero, sizeof(zero), IgnoreError());
assert(success);
/* finish */
- success = encoder_end(encoder, NULL);
+ success = encoder_end(encoder, IgnoreError());
assert(success);
encoder_to_stdout(*encoder);
diff --git a/test/visit_archive.cxx b/test/visit_archive.cxx
index 047ef4d6d..b059f16f9 100644
--- a/test/visit_archive.cxx
+++ b/test/visit_archive.cxx
@@ -28,6 +28,7 @@
#include "ArchiveFile.hxx"
#include "ArchiveVisitor.hxx"
#include "fs/Path.hxx"
+#include "util/Error.hxx"
#include <glib.h>
@@ -54,7 +55,7 @@ class MyArchiveVisitor final : public ArchiveVisitor {
int
main(int argc, char **argv)
{
- GError *error = nullptr;
+ Error error;
if (argc != 3) {
fprintf(stderr, "Usage: visit_archive PLUGIN PATH\n");
@@ -81,9 +82,8 @@ main(int argc, char **argv)
archive_plugin_init_all();
- if (!input_stream_global_init(&error)) {
- g_warning("%s", error->message);
- g_error_free(error);
+ if (!input_stream_global_init(error)) {
+ fprintf(stderr, "%s", error.GetMessage());
return 2;
}
@@ -97,14 +97,13 @@ main(int argc, char **argv)
int result = EXIT_SUCCESS;
- ArchiveFile *file = archive_file_open(plugin, path.c_str(), &error);
+ ArchiveFile *file = archive_file_open(plugin, path.c_str(), error);
if (file != nullptr) {
MyArchiveVisitor visitor;
file->Visit(visitor);
file->Close();
} else {
- fprintf(stderr, "%s\n", error->message);
- g_error_free(error);
+ fprintf(stderr, "%s", error.GetMessage());
result = EXIT_FAILURE;
}