aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/DumpDatabase.cxx12
-rw-r--r--test/FakeDecoderAPI.cxx144
-rw-r--r--test/dump_playlist.cxx128
-rw-r--r--test/dump_rva2.cxx21
-rw-r--r--test/dump_text_file.cxx20
-rw-r--r--test/read_conf.cxx32
-rw-r--r--test/read_mixer.cxx33
-rw-r--r--test/read_tags.cxx101
-rw-r--r--test/run_convert.cxx43
-rw-r--r--test/run_decoder.cxx87
-rw-r--r--test/run_encoder.cxx40
-rw-r--r--test/run_filter.cxx45
-rw-r--r--test/run_inotify.cxx13
-rw-r--r--test/run_input.cxx28
-rw-r--r--test/run_normalize.cxx5
-rw-r--r--test/run_output.cxx31
-rw-r--r--test/run_resolver.cxx16
-rw-r--r--test/software_volume.cxx34
-rw-r--r--test/test_pcm_channels.cxx49
-rw-r--r--test/test_pcm_dither.cxx2
-rw-r--r--test/test_pcm_mix.cxx16
-rw-r--r--test/test_pcm_volume.cxx188
-rw-r--r--test/test_vorbis_encoder.cxx10
-rw-r--r--test/visit_archive.cxx12
24 files changed, 478 insertions, 632 deletions
diff --git a/test/DumpDatabase.cxx b/test/DumpDatabase.cxx
index 21a12d294..ec7de7e45 100644
--- a/test/DumpDatabase.cxx
+++ b/test/DumpDatabase.cxx
@@ -39,16 +39,6 @@ using std::endl;
#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 bool
DumpDirectory(const Directory &directory, Error &)
{
@@ -94,8 +84,6 @@ main(int argc, char **argv)
g_thread_init(nullptr);
#endif
- g_log_set_default_handler(my_log_func, nullptr);
-
/* initialize MPD */
config_global_init();
diff --git a/test/FakeDecoderAPI.cxx b/test/FakeDecoderAPI.cxx
new file mode 100644
index 000000000..3045722cf
--- /dev/null
+++ b/test/FakeDecoderAPI.cxx
@@ -0,0 +1,144 @@
+/*
+ * Copyright (C) 2003-2012 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.
+ */
+
+#include "config.h"
+#include "DecoderAPI.hxx"
+#include "InputStream.hxx"
+#include "util/Error.hxx"
+#include "Compiler.h"
+
+#include <glib.h>
+
+#include <unistd.h>
+
+void
+decoder_initialized(gcc_unused Decoder &decoder,
+ gcc_unused const AudioFormat audio_format,
+ gcc_unused bool seekable,
+ gcc_unused float total_time)
+{
+}
+
+DecoderCommand
+decoder_get_command(gcc_unused Decoder &decoder)
+{
+ return DecoderCommand::NONE;
+}
+
+void
+decoder_command_finished(gcc_unused Decoder &decoder)
+{
+}
+
+double
+decoder_seek_where(gcc_unused Decoder &decoder)
+{
+ return 1.0;
+}
+
+void
+decoder_seek_error(gcc_unused Decoder &decoder)
+{
+}
+
+size_t
+decoder_read(gcc_unused Decoder *decoder,
+ InputStream &is,
+ void *buffer, size_t length)
+{
+ return is.LockRead(buffer, length, IgnoreError());
+}
+
+bool
+decoder_read_full(Decoder *decoder, InputStream &is,
+ void *_buffer, size_t size)
+{
+ uint8_t *buffer = (uint8_t *)_buffer;
+
+ while (size > 0) {
+ size_t nbytes = decoder_read(decoder, is, buffer, size);
+ if (nbytes == 0)
+ return false;
+
+ buffer += nbytes;
+ size -= nbytes;
+ }
+
+ return true;
+}
+
+bool
+decoder_skip(Decoder *decoder, InputStream &is, size_t size)
+{
+ while (size > 0) {
+ char buffer[1024];
+ size_t nbytes = decoder_read(decoder, is, buffer,
+ std::min(sizeof(buffer), size));
+ if (nbytes == 0)
+ return false;
+
+ size -= nbytes;
+ }
+
+ return true;
+}
+
+void
+decoder_timestamp(gcc_unused Decoder &decoder,
+ gcc_unused double t)
+{
+}
+
+DecoderCommand
+decoder_data(gcc_unused Decoder &decoder,
+ gcc_unused InputStream *is,
+ const void *data, size_t datalen,
+ gcc_unused uint16_t kbit_rate)
+{
+ gcc_unused ssize_t nbytes = write(1, data, datalen);
+ return DecoderCommand::NONE;
+}
+
+DecoderCommand
+decoder_tag(gcc_unused Decoder &decoder,
+ gcc_unused InputStream *is,
+ gcc_unused Tag &&tag)
+{
+ return DecoderCommand::NONE;
+}
+
+void
+decoder_replay_gain(gcc_unused Decoder &decoder,
+ const ReplayGainInfo *rgi)
+{
+ const ReplayGainTuple *tuple = &rgi->tuples[REPLAY_GAIN_ALBUM];
+ if (tuple->IsDefined())
+ fprintf(stderr, "replay_gain[album]: gain=%f peak=%f\n",
+ tuple->gain, tuple->peak);
+
+ tuple = &rgi->tuples[REPLAY_GAIN_TRACK];
+ if (tuple->IsDefined())
+ fprintf(stderr, "replay_gain[track]: gain=%f peak=%f\n",
+ tuple->gain, tuple->peak);
+}
+
+void
+decoder_mixramp(gcc_unused Decoder &decoder, gcc_unused MixRampInfo &&mix_ramp)
+{
+}
diff --git a/test/dump_playlist.cxx b/test/dump_playlist.cxx
index d11562930..f0401249e 100644
--- a/test/dump_playlist.cxx
+++ b/test/dump_playlist.cxx
@@ -24,7 +24,6 @@
#include "Directory.hxx"
#include "InputStream.hxx"
#include "ConfigGlobal.hxx"
-#include "DecoderAPI.hxx"
#include "DecoderList.hxx"
#include "InputInit.hxx"
#include "IOThread.hxx"
@@ -43,98 +42,6 @@
Directory::Directory() {}
Directory::~Directory() {}
-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);
-}
-
-void
-decoder_initialized(gcc_unused Decoder &decoder,
- gcc_unused const AudioFormat audio_format,
- gcc_unused bool seekable,
- gcc_unused float total_time)
-{
-}
-
-DecoderCommand
-decoder_get_command(gcc_unused Decoder &decoder)
-{
- return DecoderCommand::NONE;
-}
-
-void
-decoder_command_finished(gcc_unused Decoder &decoder)
-{
-}
-
-double
-decoder_seek_where(gcc_unused Decoder &decoder)
-{
- return 1.0;
-}
-
-void
-decoder_seek_error(gcc_unused Decoder &decoder)
-{
-}
-
-size_t
-decoder_read(gcc_unused Decoder *decoder,
- InputStream &is,
- void *buffer, size_t length)
-{
- return is.LockRead(buffer, length, IgnoreError());
-}
-
-void
-decoder_timestamp(gcc_unused Decoder &decoder,
- gcc_unused double t)
-{
-}
-
-DecoderCommand
-decoder_data(gcc_unused Decoder &decoder,
- gcc_unused InputStream *is,
- const void *data, size_t datalen,
- gcc_unused uint16_t kbit_rate)
-{
- gcc_unused ssize_t nbytes = write(1, data, datalen);
- return DecoderCommand::NONE;
-}
-
-DecoderCommand
-decoder_tag(gcc_unused Decoder &decoder,
- gcc_unused InputStream *is,
- gcc_unused Tag &&tag)
-{
- return DecoderCommand::NONE;
-}
-
-void
-decoder_replay_gain(gcc_unused Decoder &decoder,
- const ReplayGainInfo *rgi)
-{
- 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);
-
- tuple = &rgi->tuples[REPLAY_GAIN_TRACK];
- if (tuple->IsDefined())
- g_printerr("replay_gain[track]: gain=%f peak=%f\n",
- tuple->gain, tuple->peak);
-}
-
-void
-decoder_mixramp(gcc_unused Decoder &decoder, gcc_unused MixRampInfo &&mix_ramp)
-{
-}
-
int main(int argc, char **argv)
{
const char *uri;
@@ -142,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]);
@@ -155,16 +62,14 @@ int main(int argc, char **argv)
g_thread_init(NULL);
#endif
- g_log_set_default_handler(my_log_func, NULL);
-
/* initialize MPD */
config_global_init();
Error error;
if (!ReadConfigFile(config_path, error)) {
- g_printerr("%s\n", error.GetMessage());
- return 1;
+ LogError(error);
+ return EXIT_FAILURE;
}
io_thread_init();
@@ -172,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();
@@ -192,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;
}
@@ -203,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;
}
}
@@ -211,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 bb84f5cce..3da965f03 100644
--- a/test/dump_text_file.cxx
+++ b/test/dump_text_file.cxx
@@ -39,16 +39,6 @@
#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 void
dump_text_file(TextInputStream &is)
{
std::string line;
@@ -99,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 */
@@ -109,8 +99,6 @@ int main(int argc, char **argv)
g_thread_init(NULL);
#endif
- g_log_set_default_handler(my_log_func, NULL);
-
/* initialize MPD */
config_global_init();
@@ -141,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_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/read_mixer.cxx b/test/read_mixer.cxx
index 8426443ae..95aacf6db 100644
--- a/test/read_mixer.cxx
+++ b/test/read_mixer.cxx
@@ -21,12 +21,13 @@
#include "MixerControl.hxx"
#include "MixerList.hxx"
#include "FilterRegistry.hxx"
-#include "pcm/PcmVolume.hxx"
+#include "pcm/Volume.hxx"
#include "GlobalEvents.hxx"
#include "Main.hxx"
#include "event/Loop.hxx"
#include "ConfigData.hxx"
#include "util/Error.hxx"
+#include "Log.hxx"
#include <glib.h>
@@ -101,22 +102,13 @@ filter_plugin_by_name(gcc_unused const char *name)
return NULL;
}
-bool
-pcm_volume(gcc_unused void *buffer, gcc_unused size_t length,
- gcc_unused SampleFormat format,
- gcc_unused int volume)
-{
- assert(false);
- return false;
-}
-
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)
@@ -129,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);
@@ -149,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 90f1424d9..dac9aba00 100644
--- a/test/read_tags.cxx
+++ b/test/read_tags.cxx
@@ -20,7 +20,7 @@
#include "config.h"
#include "IOThread.hxx"
#include "DecoderList.hxx"
-#include "DecoderAPI.hxx"
+#include "DecoderPlugin.hxx"
#include "InputInit.hxx"
#include "InputStream.hxx"
#include "AudioFormat.hxx"
@@ -42,98 +42,25 @@
#include <locale.h>
#endif
-void
-decoder_initialized(gcc_unused Decoder &decoder,
- gcc_unused const AudioFormat audio_format,
- gcc_unused bool seekable,
- gcc_unused float total_time)
-{
-}
-
-DecoderCommand
-decoder_get_command(gcc_unused Decoder &decoder)
-{
- return DecoderCommand::NONE;
-}
-
-void
-decoder_command_finished(gcc_unused Decoder &decoder)
-{
-}
-
-double
-decoder_seek_where(gcc_unused Decoder &decoder)
-{
- return 1.0;
-}
-
-void
-decoder_seek_error(gcc_unused Decoder &decoder)
-{
-}
-
-size_t
-decoder_read(gcc_unused Decoder *decoder,
- InputStream &is,
- void *buffer, size_t length)
-{
- return is.LockRead(buffer, length, IgnoreError());
-}
-
-void
-decoder_timestamp(gcc_unused Decoder &decoder,
- gcc_unused double t)
-{
-}
-
-DecoderCommand
-decoder_data(gcc_unused Decoder &decoder,
- gcc_unused InputStream *is,
- const void *data, size_t datalen,
- gcc_unused uint16_t kbit_rate)
-{
- gcc_unused ssize_t nbytes = write(1, data, datalen);
- return DecoderCommand::NONE;
-}
-
-DecoderCommand
-decoder_tag(gcc_unused Decoder &decoder,
- gcc_unused InputStream *is,
- gcc_unused Tag &&tag)
-{
- return DecoderCommand::NONE;
-}
-
-void
-decoder_replay_gain(gcc_unused Decoder &decoder,
- gcc_unused const ReplayGainInfo *replay_gain_info)
-{
-}
-
-void
-decoder_mixramp(gcc_unused Decoder &decoder, gcc_unused MixRampInfo &&mix_ramp)
-{
-}
-
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 = {
@@ -153,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];
@@ -177,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);
@@ -189,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();
@@ -201,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;
}
@@ -217,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_convert.cxx b/test/run_convert.cxx
index 0e873a3b3..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;
@@ -90,6 +76,10 @@ int main(int argc, char **argv)
const size_t in_frame_size = in_audio_format.GetFrameSize();
PcmConvert state;
+ if (!state.Open(in_audio_format, out_audio_format_mask, error)) {
+ LogError(error, "Failed to open PcmConvert");
+ return EXIT_FAILURE;
+ }
FifoBuffer<uint8_t, 4096> buffer;
@@ -115,15 +105,18 @@ int main(int argc, char **argv)
buffer.Consume(src.size);
size_t length;
- output = state.Convert(in_audio_format, src.data, src.size,
- out_audio_format, &length, error);
+ output = state.Convert(src.data, src.size,
+ &length, error);
if (output == NULL) {
- g_printerr("Failed to convert: %s\n", error.GetMessage());
- return 2;
+ state.Close();
+ LogError(error, "Failed to convert");
+ return EXIT_FAILURE;
}
gcc_unused ssize_t ignored = write(1, output, length);
}
+ state.Close();
+
return EXIT_SUCCESS;
}
diff --git a/test/run_decoder.cxx b/test/run_decoder.cxx
index 2f7330a1d..fb29bd3b3 100644
--- a/test/run_decoder.cxx
+++ b/test/run_decoder.cxx
@@ -29,21 +29,14 @@
#include "Log.hxx"
#include "stdbin.h"
+#ifdef HAVE_GLIB
#include <glib.h>
+#endif
#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;
@@ -64,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;
}
@@ -101,6 +94,40 @@ decoder_read(gcc_unused Decoder *decoder,
return is.LockRead(buffer, length, IgnoreError());
}
+bool
+decoder_read_full(Decoder *decoder, InputStream &is,
+ void *_buffer, size_t size)
+{
+ uint8_t *buffer = (uint8_t *)_buffer;
+
+ while (size > 0) {
+ size_t nbytes = decoder_read(decoder, is, buffer, size);
+ if (nbytes == 0)
+ return false;
+
+ buffer += nbytes;
+ size -= nbytes;
+ }
+
+ return true;
+}
+
+bool
+decoder_skip(Decoder *decoder, InputStream &is, size_t size)
+{
+ while (size > 0) {
+ char buffer[1024];
+ size_t nbytes = decoder_read(decoder, is, buffer,
+ std::min(sizeof(buffer), size));
+ if (nbytes == 0)
+ return false;
+
+ size -= nbytes;
+ }
+
+ return true;
+}
+
void
decoder_timestamp(gcc_unused Decoder &decoder,
gcc_unused double t)
@@ -131,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
@@ -150,19 +177,19 @@ 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;
decoder_name = argv[1];
decoder.uri = argv[2];
+#ifdef HAVE_GLIB
#if !GLIB_CHECK_VERSION(2,32,0)
g_thread_init(NULL);
#endif
-
- g_log_set_default_handler(my_log_func, NULL);
+#endif
io_thread_init();
io_thread_start();
@@ -170,15 +197,15 @@ int main(int argc, char **argv)
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;
@@ -195,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();
@@ -213,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 838ee708e..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,19 +99,20 @@ 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);
+
+ encoder_close(encoder);
+ encoder_finish(encoder);
}
diff --git a/test/run_filter.cxx b/test/run_filter.cxx
index 085fc256b..6781700d8 100644
--- a/test/run_filter.cxx
+++ b/test/run_filter.cxx
@@ -25,11 +25,12 @@
#include "AudioFormat.hxx"
#include "FilterPlugin.hxx"
#include "FilterInternal.hxx"
-#include "pcm/PcmVolume.hxx"
+#include "pcm/Volume.hxx"
#include "MixerControl.hxx"
#include "stdbin.h"
#include "util/Error.hxx"
#include "system/FatalError.hxx"
+#include "Log.hxx"
#include <glib.h>
@@ -45,16 +46,6 @@ mixer_set_volume(gcc_unused Mixer *mixer,
return true;
}
-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 const struct config_param *
find_named_config_block(ConfigOption option, const char *name)
{
@@ -76,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;
}
@@ -97,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]);
@@ -111,8 +102,6 @@ int main(int argc, char **argv)
g_thread_init(NULL);
#endif
- g_log_set_default_handler(my_log_func, NULL);
-
/* read configuration file (mpd.conf) */
config_global_init();
@@ -124,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;
}
}
@@ -134,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 */
@@ -163,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_input.cxx b/test/run_input.cxx
index 3817ed418..fcf4107c4 100644
--- a/test/run_input.cxx
+++ b/test/run_input.cxx
@@ -33,21 +33,13 @@
#include "ArchiveList.hxx"
#endif
+#ifdef HAVE_GLIB
#include <glib.h>
+#endif
#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)
{
@@ -71,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;
}
@@ -114,17 +106,17 @@ 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 */
+#ifdef HAVE_GLIB
#if !GLIB_CHECK_VERSION(2,32,0)
g_thread_init(NULL);
#endif
-
- g_log_set_default_handler(my_log_func, NULL);
+#endif
/* initialize MPD */
@@ -155,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;
}
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 7da2fd5b2..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;
}
@@ -51,16 +49,8 @@ int main(int argc, char **argv)
}
for (const struct addrinfo *i = ai; i != NULL; i = i->ai_next) {
- char *p = sockaddr_to_string(i->ai_addr, i->ai_addrlen,
- error);
- if (p == NULL) {
- freeaddrinfo(ai);
- LogError(error);
- return EXIT_FAILURE;
- }
-
- g_print("%s\n", p);
- g_free(p);
+ const auto s = sockaddr_to_string(i->ai_addr, i->ai_addrlen);
+ printf("%s\n", s.c_str());
}
freeaddrinfo(ai);
diff --git a/test/software_volume.cxx b/test/software_volume.cxx
index 19a0be88c..1a336f2df 100644
--- a/test/software_volume.cxx
+++ b/test/software_volume.cxx
@@ -24,15 +24,16 @@
*/
#include "config.h"
-#include "pcm/PcmVolume.hxx"
+#include "pcm/Volume.hxx"
#include "AudioParser.hxx"
#include "AudioFormat.hxx"
+#include "util/ConstBuffer.hxx"
#include "util/Error.hxx"
#include "stdbin.h"
-
-#include <glib.h>
+#include "Log.hxx"
#include <stddef.h>
+#include <stdlib.h>
#include <unistd.h>
int main(int argc, char **argv)
@@ -41,28 +42,29 @@ 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;
}
}
- while ((nbytes = read(0, buffer, sizeof(buffer))) > 0) {
- if (!pcm_volume(buffer, nbytes,
- audio_format.format,
- PCM_VOLUME_1 / 2)) {
- g_printerr("pcm_volume() has failed\n");
- return 2;
- }
+ PcmVolume pv;
+ if (!pv.Open(audio_format.format, error)) {
+ fprintf(stderr, "%s\n", error.GetMessage());
+ return EXIT_FAILURE;
+ }
- gcc_unused ssize_t ignored = write(1, buffer, nbytes);
+ while ((nbytes = read(0, buffer, sizeof(buffer))) > 0) {
+ auto dest = pv.Apply({buffer, size_t(nbytes)});
+ gcc_unused ssize_t ignored = write(1, dest.data, dest.size);
}
+
+ pv.Close();
}
diff --git a/test/test_pcm_channels.cxx b/test/test_pcm_channels.cxx
index 85c872674..355553687 100644
--- a/test/test_pcm_channels.cxx
+++ b/test/test_pcm_channels.cxx
@@ -22,67 +22,60 @@
#include "test_pcm_util.hxx"
#include "pcm/PcmChannels.hxx"
#include "pcm/PcmBuffer.hxx"
+#include "util/ConstBuffer.hxx"
void
PcmChannelsTest::TestChannels16()
{
- constexpr unsigned N = 256;
+ constexpr size_t N = 256;
const auto src = TestDataBuffer<int16_t, N * 2>();
PcmBuffer buffer;
/* stereo to mono */
- size_t dest_size;
- const int16_t *dest =
- pcm_convert_channels_16(buffer, 1, 2, src, sizeof(src),
- &dest_size);
- CPPUNIT_ASSERT(dest != NULL);
- CPPUNIT_ASSERT_EQUAL(sizeof(src) / 2, dest_size);
+ auto dest = pcm_convert_channels_16(buffer, 1, 2, { src, N * 2 });
+ CPPUNIT_ASSERT(!dest.IsNull());
+ CPPUNIT_ASSERT_EQUAL(N, dest.size);
for (unsigned i = 0; i < N; ++i)
CPPUNIT_ASSERT_EQUAL(int16_t((src[i * 2] + src[i * 2 + 1]) / 2),
- dest[i]);
+ dest.data[i]);
/* mono to stereo */
- dest = pcm_convert_channels_16(buffer, 2, 1, src, sizeof(src),
- &dest_size);
- CPPUNIT_ASSERT(dest != NULL);
- CPPUNIT_ASSERT_EQUAL(sizeof(src) * 2, dest_size);
+ dest = pcm_convert_channels_16(buffer, 2, 1, { src, N * 2 });
+ CPPUNIT_ASSERT(!dest.IsNull());
+ CPPUNIT_ASSERT_EQUAL(N * 4, dest.size);
for (unsigned i = 0; i < N; ++i) {
- CPPUNIT_ASSERT_EQUAL(src[i], dest[i * 2]);
- CPPUNIT_ASSERT_EQUAL(src[i], dest[i * 2 + 1]);
+ CPPUNIT_ASSERT_EQUAL(src[i], dest.data[i * 2]);
+ CPPUNIT_ASSERT_EQUAL(src[i], dest.data[i * 2 + 1]);
}
}
void
PcmChannelsTest::TestChannels32()
{
- constexpr unsigned N = 256;
+ constexpr size_t N = 256;
const auto src = TestDataBuffer<int32_t, N * 2>();
PcmBuffer buffer;
/* stereo to mono */
- size_t dest_size;
- const int32_t *dest =
- pcm_convert_channels_32(buffer, 1, 2, src, sizeof(src),
- &dest_size);
- CPPUNIT_ASSERT(dest != NULL);
- CPPUNIT_ASSERT_EQUAL(sizeof(src) / 2, dest_size);
+ auto dest = pcm_convert_channels_32(buffer, 1, 2, { src, N * 2 });
+ CPPUNIT_ASSERT(!dest.IsNull());
+ CPPUNIT_ASSERT_EQUAL(N, dest.size);
for (unsigned i = 0; i < N; ++i)
CPPUNIT_ASSERT_EQUAL(int32_t(((int64_t)src[i * 2] + (int64_t)src[i * 2 + 1]) / 2),
- dest[i]);
+ dest.data[i]);
/* mono to stereo */
- dest = pcm_convert_channels_32(buffer, 2, 1, src, sizeof(src),
- &dest_size);
- CPPUNIT_ASSERT(dest != NULL);
- CPPUNIT_ASSERT_EQUAL(sizeof(src) * 2, dest_size);
+ dest = pcm_convert_channels_32(buffer, 2, 1, { src, N * 2 });
+ CPPUNIT_ASSERT(!dest.IsNull());
+ CPPUNIT_ASSERT_EQUAL(N * 4, dest.size);
for (unsigned i = 0; i < N; ++i) {
- CPPUNIT_ASSERT_EQUAL(src[i], dest[i * 2]);
- CPPUNIT_ASSERT_EQUAL(src[i], dest[i * 2 + 1]);
+ CPPUNIT_ASSERT_EQUAL(src[i], dest.data[i * 2]);
+ CPPUNIT_ASSERT_EQUAL(src[i], dest.data[i * 2 + 1]);
}
}
diff --git a/test/test_pcm_dither.cxx b/test/test_pcm_dither.cxx
index 710deffcc..bf7484885 100644
--- a/test/test_pcm_dither.cxx
+++ b/test/test_pcm_dither.cxx
@@ -19,7 +19,7 @@
#include "test_pcm_all.hxx"
#include "test_pcm_util.hxx"
-#include "pcm/PcmDither.hxx"
+#include "pcm/PcmDither.cxx"
void
PcmDitherTest::TestDither24()
diff --git a/test/test_pcm_mix.cxx b/test/test_pcm_mix.cxx
index 2a8a11388..542c4de80 100644
--- a/test/test_pcm_mix.cxx
+++ b/test/test_pcm_mix.cxx
@@ -21,6 +21,7 @@
#include "test_pcm_all.hxx"
#include "test_pcm_util.hxx"
#include "pcm/PcmMix.hxx"
+#include "pcm/PcmDither.hxx"
template<typename T, SampleFormat format, typename G=RandomInt<T>>
static void
@@ -30,23 +31,26 @@ TestPcmMix(G g=G())
const auto src1 = TestDataBuffer<T, N>(g);
const auto src2 = TestDataBuffer<T, N>(g);
+ PcmDither dither;
+
/* portion1=1.0: result must be equal to src1 */
auto result = src1;
- bool success = pcm_mix(result.begin(), src2.begin(), sizeof(result),
+ bool success = pcm_mix(dither,
+ result.begin(), src2.begin(), sizeof(result),
format, 1.0);
CPPUNIT_ASSERT(success);
- AssertEqualWithTolerance(result, src1, 1);
+ AssertEqualWithTolerance(result, src1, 3);
/* portion1=0.0: result must be equal to src2 */
result = src1;
- success = pcm_mix(result.begin(), src2.begin(), sizeof(result),
+ success = pcm_mix(dither, result.begin(), src2.begin(), sizeof(result),
format, 0.0);
CPPUNIT_ASSERT(success);
- AssertEqualWithTolerance(result, src2, 1);
+ AssertEqualWithTolerance(result, src2, 3);
/* portion1=0.5 */
result = src1;
- success = pcm_mix(result.begin(), src2.begin(), sizeof(result),
+ success = pcm_mix(dither, result.begin(), src2.begin(), sizeof(result),
format, 0.5);
CPPUNIT_ASSERT(success);
@@ -54,7 +58,7 @@ TestPcmMix(G g=G())
for (unsigned i = 0; i < N; ++i)
expected[i] = (int64_t(src1[i]) + int64_t(src2[i])) / 2;
- AssertEqualWithTolerance(result, expected, 1);
+ AssertEqualWithTolerance(result, expected, 3);
}
void
diff --git a/test/test_pcm_volume.cxx b/test/test_pcm_volume.cxx
index 764d8b127..c3a261f7a 100644
--- a/test/test_pcm_volume.cxx
+++ b/test/test_pcm_volume.cxx
@@ -17,169 +17,109 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#include "config.h"
#include "test_pcm_all.hxx"
-#include "pcm/PcmVolume.hxx"
+#include "pcm/Volume.hxx"
+#include "pcm/Traits.hxx"
+#include "util/ConstBuffer.hxx"
+#include "util/Error.hxx"
#include "test_pcm_util.hxx"
#include <algorithm>
#include <string.h>
-void
-PcmVolumeTest::TestVolume8()
+template<SampleFormat F, class Traits=SampleTraits<F>,
+ typename G=RandomInt<typename Traits::value_type>>
+static void
+TestVolume(G g=G())
{
- constexpr unsigned N = 256;
- static int8_t zero[N];
- const auto src = TestDataBuffer<int8_t, N>();
+ typedef typename Traits::value_type value_type;
+
+ PcmVolume pv;
+ CPPUNIT_ASSERT(pv.Open(F, IgnoreError()));
- int8_t dest[N];
+ constexpr size_t N = 256;
+ static value_type zero[N];
+ const auto _src = TestDataBuffer<value_type, N>(g);
+ const ConstBuffer<void> src(_src, sizeof(_src));
- std::copy(src.begin(), src.end(), dest);
- CPPUNIT_ASSERT_EQUAL(true,
- pcm_volume(dest, sizeof(dest),
- SampleFormat::S8, 0));
- CPPUNIT_ASSERT_EQUAL(0, memcmp(dest, zero, sizeof(zero)));
+ pv.SetVolume(0);
+ auto dest = pv.Apply(src);
+ CPPUNIT_ASSERT_EQUAL(src.size, dest.size);
+ CPPUNIT_ASSERT_EQUAL(0, memcmp(dest.data, zero, sizeof(zero)));
- std::copy(src.begin(), src.end(), dest);
- CPPUNIT_ASSERT_EQUAL(true,
- pcm_volume(dest, sizeof(dest),
- SampleFormat::S8, PCM_VOLUME_1));
- CPPUNIT_ASSERT_EQUAL(0, memcmp(dest, src, sizeof(src)));
+ pv.SetVolume(PCM_VOLUME_1);
+ dest = pv.Apply(src);
+ CPPUNIT_ASSERT_EQUAL(src.size, dest.size);
+ CPPUNIT_ASSERT_EQUAL(0, memcmp(dest.data, src.data, src.size));
- std::copy(src.begin(), src.end(), dest);
- CPPUNIT_ASSERT_EQUAL(true,
- pcm_volume(dest, sizeof(dest),
- SampleFormat::S8, PCM_VOLUME_1 / 2));
+ pv.SetVolume(PCM_VOLUME_1 / 2);
+ dest = pv.Apply(src);
+ CPPUNIT_ASSERT_EQUAL(src.size, dest.size);
+ const auto _dest = ConstBuffer<value_type>::FromVoid(dest);
for (unsigned i = 0; i < N; ++i) {
- CPPUNIT_ASSERT(dest[i] >= (src[i] - 1) / 2);
- CPPUNIT_ASSERT(dest[i] <= src[i] / 2 + 1);
+ const auto expected = (_src[i] + 1) / 2;
+ CPPUNIT_ASSERT(_dest.data[i] >= expected - 4);
+ CPPUNIT_ASSERT(_dest.data[i] <= expected + 4);
}
+
+ pv.Close();
}
void
-PcmVolumeTest::TestVolume16()
+PcmVolumeTest::TestVolume8()
{
- constexpr unsigned N = 256;
- static int16_t zero[N];
- const auto src = TestDataBuffer<int16_t, N>();
-
- int16_t dest[N];
-
- std::copy(src.begin(), src.end(), dest);
- CPPUNIT_ASSERT_EQUAL(true,
- pcm_volume(dest, sizeof(dest),
- SampleFormat::S16, 0));
- CPPUNIT_ASSERT_EQUAL(0, memcmp(dest, zero, sizeof(zero)));
-
- std::copy(src.begin(), src.end(), dest);
- CPPUNIT_ASSERT_EQUAL(true,
- pcm_volume(dest, sizeof(dest),
- SampleFormat::S16, PCM_VOLUME_1));
- CPPUNIT_ASSERT_EQUAL(0, memcmp(dest, src, sizeof(src)));
-
- std::copy(src.begin(), src.end(), dest);
- CPPUNIT_ASSERT_EQUAL(true,
- pcm_volume(dest, sizeof(dest),
- SampleFormat::S16, PCM_VOLUME_1 / 2));
+ TestVolume<SampleFormat::S8>();
+}
- for (unsigned i = 0; i < N; ++i) {
- CPPUNIT_ASSERT(dest[i] >= (src[i] - 1) / 2);
- CPPUNIT_ASSERT(dest[i] <= src[i] / 2 + 1);
- }
+void
+PcmVolumeTest::TestVolume16()
+{
+ TestVolume<SampleFormat::S16>();
}
void
PcmVolumeTest::TestVolume24()
{
- constexpr unsigned N = 256;
- static int32_t zero[N];
- const auto src = TestDataBuffer<int32_t, N>(RandomInt24());
-
- int32_t dest[N];
-
- std::copy(src.begin(), src.end(), dest);
- CPPUNIT_ASSERT_EQUAL(true,
- pcm_volume(dest, sizeof(dest),
- SampleFormat::S24_P32, 0));
- CPPUNIT_ASSERT_EQUAL(0, memcmp(dest, zero, sizeof(zero)));
-
- std::copy(src.begin(), src.end(), dest);
- CPPUNIT_ASSERT_EQUAL(true,
- pcm_volume(dest, sizeof(dest),
- SampleFormat::S24_P32, PCM_VOLUME_1));
- CPPUNIT_ASSERT_EQUAL(0, memcmp(dest, src, sizeof(src)));
-
- std::copy(src.begin(), src.end(), dest);
- CPPUNIT_ASSERT_EQUAL(true,
- pcm_volume(dest, sizeof(dest),
- SampleFormat::S24_P32, PCM_VOLUME_1 / 2));
-
- for (unsigned i = 0; i < N; ++i) {
- CPPUNIT_ASSERT(dest[i] >= (src[i] - 1) / 2);
- CPPUNIT_ASSERT(dest[i] <= src[i] / 2 + 1);
- }
+ TestVolume<SampleFormat::S24_P32>(RandomInt24());
}
void
PcmVolumeTest::TestVolume32()
{
- constexpr unsigned N = 256;
- static int32_t zero[N];
- const auto src = TestDataBuffer<int32_t, N>();
-
- int32_t dest[N];
-
- std::copy(src.begin(), src.end(), dest);
- CPPUNIT_ASSERT_EQUAL(true,
- pcm_volume(dest, sizeof(dest),
- SampleFormat::S32, 0));
- CPPUNIT_ASSERT_EQUAL(0, memcmp(dest, zero, sizeof(zero)));
-
- std::copy(src.begin(), src.end(), dest);
- CPPUNIT_ASSERT_EQUAL(true,
- pcm_volume(dest, sizeof(dest),
- SampleFormat::S32, PCM_VOLUME_1));
- CPPUNIT_ASSERT_EQUAL(0, memcmp(dest, src, sizeof(src)));
-
- std::copy(src.begin(), src.end(), dest);
- CPPUNIT_ASSERT_EQUAL(true,
- pcm_volume(dest, sizeof(dest),
- SampleFormat::S32, PCM_VOLUME_1 / 2));
-
- for (unsigned i = 0; i < N; ++i) {
- CPPUNIT_ASSERT(dest[i] >= (src[i] - 1) / 2);
- CPPUNIT_ASSERT(dest[i] <= src[i] / 2 + 1);
- }
+ TestVolume<SampleFormat::S32>();
}
void
PcmVolumeTest::TestVolumeFloat()
{
- constexpr unsigned N = 256;
- static float zero[N];
- const auto src = TestDataBuffer<float, N>(RandomFloat());
+ PcmVolume pv;
+ CPPUNIT_ASSERT(pv.Open(SampleFormat::FLOAT, IgnoreError()));
- float dest[N];
+ constexpr size_t N = 256;
+ static float zero[N];
+ const auto _src = TestDataBuffer<float, N>(RandomFloat());
+ const ConstBuffer<void> src(_src, sizeof(_src));
- std::copy(src.begin(), src.end(), dest);
- CPPUNIT_ASSERT_EQUAL(true,
- pcm_volume(dest, sizeof(dest),
- SampleFormat::FLOAT, 0));
- CPPUNIT_ASSERT_EQUAL(0, memcmp(dest, zero, sizeof(zero)));
+ pv.SetVolume(0);
+ auto dest = pv.Apply(src);
+ CPPUNIT_ASSERT_EQUAL(src.size, dest.size);
+ CPPUNIT_ASSERT_EQUAL(0, memcmp(dest.data, zero, sizeof(zero)));
- std::copy(src.begin(), src.end(), dest);
- CPPUNIT_ASSERT_EQUAL(true,
- pcm_volume(dest, sizeof(dest),
- SampleFormat::FLOAT, PCM_VOLUME_1));
- CPPUNIT_ASSERT_EQUAL(0, memcmp(dest, src, sizeof(src)));
+ pv.SetVolume(PCM_VOLUME_1);
+ dest = pv.Apply(src);
+ CPPUNIT_ASSERT_EQUAL(src.size, dest.size);
+ CPPUNIT_ASSERT_EQUAL(0, memcmp(dest.data, src.data, src.size));
- std::copy(src.begin(), src.end(), dest);
- CPPUNIT_ASSERT_EQUAL(true,
- pcm_volume(dest, sizeof(dest),
- SampleFormat::FLOAT,
- PCM_VOLUME_1 / 2));
+ pv.SetVolume(PCM_VOLUME_1 / 2);
+ dest = pv.Apply(src);
+ CPPUNIT_ASSERT_EQUAL(src.size, dest.size);
+ const auto _dest = ConstBuffer<float>::FromVoid(dest);
for (unsigned i = 0; i < N; ++i)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(src[i] / 2, dest[i], 1);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(_src[i] / 2, _dest.data[i], 1);
+
+ pv.Close();
}
diff --git a/test/test_vorbis_encoder.cxx b/test/test_vorbis_encoder.cxx
index 1d95f6deb..bb8731c2f 100644
--- a/test/test_vorbis_encoder.cxx
+++ b/test/test_vorbis_encoder.cxx
@@ -24,6 +24,7 @@
#include "ConfigData.hxx"
#include "stdbin.h"
#include "tag/Tag.hxx"
+#include "tag/TagBuilder.hxx"
#include "util/Error.hxx"
#include <stddef.h>
@@ -81,8 +82,13 @@ main(gcc_unused int argc, gcc_unused char **argv)
encoder_to_stdout(*encoder);
Tag tag;
- tag.AddItem(TAG_ARTIST, "Foo");
- tag.AddItem(TAG_TITLE, "Bar");
+
+ {
+ TagBuilder tag_builder;
+ tag_builder.AddItem(TAG_ARTIST, "Foo");
+ tag_builder.AddItem(TAG_TITLE, "Bar");
+ tag_builder.Commit(tag);
+ }
success = encoder_tag(encoder, &tag, IgnoreError());
assert(success);
diff --git a/test/visit_archive.cxx b/test/visit_archive.cxx
index 6e66c4696..bd890de4f 100644
--- a/test/visit_archive.cxx
+++ b/test/visit_archive.cxx
@@ -35,16 +35,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);
-}
-
class MyArchiveVisitor final : public ArchiveVisitor {
public:
virtual void VisitArchiveEntry(const char *path_utf8) override {
@@ -71,8 +61,6 @@ main(int argc, char **argv)
g_thread_init(NULL);
#endif
- g_log_set_default_handler(my_log_func, NULL);
-
/* initialize MPD */
config_global_init();