aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/DumpDatabase.cxx37
-rw-r--r--test/FakeDecoderAPI.cxx144
-rw-r--r--test/dump_playlist.cxx158
-rw-r--r--test/dump_rva2.cxx22
-rw-r--r--test/dump_text_file.cxx40
-rw-r--r--test/read_conf.cxx34
-rw-r--r--test/read_mixer.cxx33
-rw-r--r--test/read_tags.cxx115
-rw-r--r--test/run_convert.cxx43
-rw-r--r--test/run_decoder.cxx87
-rw-r--r--test/run_encoder.cxx42
-rw-r--r--test/run_filter.cxx47
-rw-r--r--test/run_inotify.cxx13
-rw-r--r--test/run_input.cxx40
-rw-r--r--test/run_normalize.cxx5
-rw-r--r--test/run_output.cxx32
-rw-r--r--test/run_resolver.cxx17
-rw-r--r--test/software_volume.cxx35
-rw-r--r--test/test_pcm_channels.cxx49
-rw-r--r--test/test_pcm_dither.cxx2
-rw-r--r--test/test_pcm_format.cxx56
-rw-r--r--test/test_pcm_mix.cxx16
-rw-r--r--test/test_pcm_util.hxx10
-rw-r--r--test/test_pcm_volume.cxx188
-rw-r--r--test/test_queue_priority.cxx41
-rw-r--r--test/test_vorbis_encoder.cxx10
-rw-r--r--test/visit_archive.cxx12
27 files changed, 583 insertions, 745 deletions
diff --git a/test/DumpDatabase.cxx b/test/DumpDatabase.cxx
index 21a12d294..ff3464099 100644
--- a/test/DumpDatabase.cxx
+++ b/test/DumpDatabase.cxx
@@ -21,6 +21,7 @@
#include "DatabaseRegistry.hxx"
#include "DatabasePlugin.hxx"
#include "DatabaseSelection.hxx"
+#include "DatabaseListener.hxx"
#include "Directory.hxx"
#include "Song.hxx"
#include "PlaylistVector.hxx"
@@ -28,6 +29,7 @@
#include "ConfigData.hxx"
#include "tag/TagConfig.hxx"
#include "fs/Path.hxx"
+#include "event/Loop.hxx"
#include "util/Error.hxx"
#include <glib.h>
@@ -39,15 +41,21 @@ 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)
+#ifdef HAVE_LIBUPNP
+#include "InputStream.hxx"
+size_t
+InputStream::LockRead(void *, size_t, Error &)
{
- if (log_domain != NULL)
- g_printerr("%s: %s\n", log_domain, message);
- else
- g_printerr("%s\n", message);
+ return 0;
}
+#endif
+
+class MyDatabaseListener final : public DatabaseListener {
+public:
+ virtual void OnDatabaseModified() override {
+ cout << "DatabaseModified" << endl;
+ }
+};
static bool
DumpDirectory(const Directory &directory, Error &)
@@ -59,7 +67,10 @@ DumpDirectory(const Directory &directory, Error &)
static bool
DumpSong(Song &song, Error &)
{
- cout << "S " << song.parent->path << "/" << song.uri << endl;
+ cout << "S ";
+ if (song.parent != nullptr && !song.parent->IsRoot())
+ cout << song.parent->path << "/";
+ cout << song.uri << endl;
return true;
}
@@ -94,8 +105,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();
@@ -108,14 +117,18 @@ main(int argc, char **argv)
TagLoadConfig();
+ EventLoop event_loop;
+ MyDatabaseListener database_listener;
+
/* do it */
const struct config_param *path = config_get_param(CONF_DB_FILE);
- config_param param("database", path->line);
+ config_param param("database", path != nullptr ? path->line : -1);
if (path != nullptr)
param.AddBlockParam("path", path->value.c_str(), path->line);
- Database *db = plugin->create(param, error);
+ Database *db = plugin->create(event_loop, database_listener,
+ param, error);
if (db == nullptr) {
cerr << error.GetMessage() << endl;
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..b0702d3be 100644
--- a/test/dump_playlist.cxx
+++ b/test/dump_playlist.cxx
@@ -19,12 +19,10 @@
#include "config.h"
#include "TagSave.hxx"
-#include "Song.hxx"
+#include "DetachedSong.hxx"
#include "SongEnumerator.hxx"
-#include "Directory.hxx"
#include "InputStream.hxx"
#include "ConfigGlobal.hxx"
-#include "DecoderAPI.hxx"
#include "DecoderList.hxx"
#include "InputInit.hxx"
#include "IOThread.hxx"
@@ -40,110 +38,14 @@
#include <unistd.h>
#include <stdlib.h>
-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;
InputStream *is = NULL;
- 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 +57,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 +72,7 @@ int main(int argc, char **argv)
if (!input_stream_global_init(error)) {
LogError(error);
- return 2;
+ return EXIT_FAILURE;
}
playlist_list_global_init();
@@ -187,47 +87,49 @@ int main(int argc, char **argv)
if (playlist == NULL) {
/* open the stream and wait until it becomes ready */
- is = InputStream::Open(uri, mutex, cond, error);
+ is = InputStream::OpenReady(uri, mutex, cond, error);
if (is == NULL) {
if (error.IsDefined())
LogError(error);
else
- g_printerr("InputStream::Open() failed\n");
+ fprintf(stderr,
+ "InputStream::Open() failed\n");
return 2;
}
- is->LockWaitReady();
-
/* open the playlist */
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;
}
}
/* dump the playlist */
+ DetachedSong *song;
while ((song = playlist->NextSong()) != NULL) {
- g_print("%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);
- else if (song->start_ms > 0)
- g_print("range: %u:%02u..\n",
- song->start_ms / 60000,
- (song->start_ms / 1000) % 60);
-
- if (song->tag != NULL)
- tag_save(stdout, *song->tag);
-
- song->Free();
+ printf("%s\n", song->GetURI());
+
+ const unsigned start_ms = song->GetStartMS();
+ const unsigned end_ms = song->GetEndMS();
+
+ if (end_ms > 0)
+ printf("range: %u:%02u..%u:%02u\n",
+ start_ms / 60000,
+ (start_ms / 1000) % 60,
+ end_ms / 60000,
+ (end_ms / 1000) % 60);
+ else if (start_ms > 0)
+ printf("range: %u:%02u..\n",
+ start_ms / 60000,
+ (start_ms / 1000) % 60);
+
+ tag_save(stdout, song->GetTag());
+
+ delete song;
}
/* deinitialize everything */
diff --git a/test/dump_rva2.cxx b/test/dump_rva2.cxx
index e1ba5336a..e79703e50 100644
--- a/test/dump_rva2.cxx
+++ b/test/dump_rva2.cxx
@@ -24,16 +24,16 @@
#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
#include <stdlib.h>
+#include <stdio.h>
const char *
config_get_string(gcc_unused enum ConfigOption option,
@@ -50,8 +50,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 +60,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 +74,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..764d3f24b 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;
@@ -59,23 +49,6 @@ dump_text_file(TextInputStream &is)
static int
dump_input_stream(InputStream &is)
{
- Error error;
-
- is.Lock();
-
- /* wait until the stream becomes ready */
-
- is.WaitReady();
-
- if (!is.Check(error)) {
- LogError(error);
- is.Unlock();
- return EXIT_FAILURE;
- }
-
- /* read data and tags from the stream */
-
- is.Unlock();
{
TextInputStream tis(is);
dump_text_file(tis);
@@ -83,6 +56,7 @@ dump_input_stream(InputStream &is)
is.Lock();
+ Error error;
if (!is.Check(error)) {
LogError(error);
is.Unlock();
@@ -99,8 +73,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 +83,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();
@@ -133,7 +105,7 @@ int main(int argc, char **argv)
Mutex mutex;
Cond cond;
- InputStream *is = InputStream::Open(argv[1], mutex, cond, error);
+ InputStream *is = InputStream::OpenReady(argv[1], mutex, cond, error);
if (is != NULL) {
ret = dump_input_stream(*is);
is->Close();
@@ -141,8 +113,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..b27c70497 100644
--- a/test/read_conf.cxx
+++ b/test/read_conf.cxx
@@ -21,40 +21,28 @@
#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);
-}
+#include <stdio.h>
+#include <stdlib.h>
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 +51,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..49d40befb 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"
@@ -37,103 +37,31 @@
#include <assert.h>
#include <unistd.h>
#include <stdlib.h>
+#include <stdio.h>
#ifdef HAVE_LOCALE_H
#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 +81,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 +105,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);
@@ -186,28 +114,13 @@ int main(int argc, char **argv)
Mutex mutex;
Cond cond;
- InputStream *is = InputStream::Open(path, mutex, cond,
- error);
+ InputStream *is = InputStream::OpenReady(path, mutex, cond,
+ error);
if (is == NULL) {
- g_printerr("Failed to open %s: %s\n",
- path, error.GetMessage());
- return 1;
- }
-
- mutex.lock();
-
- is->WaitReady();
-
- if (!is->Check(error)) {
- mutex.unlock();
-
- g_printerr("Failed to read %s: %s\n",
- path, error.GetMessage());
+ FormatError(error, "Failed to open %s", path);
return EXIT_FAILURE;
}
- mutex.unlock();
-
success = plugin->ScanStream(*is, print_handler, nullptr);
is->Close();
}
@@ -217,8 +130,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..a71b815f5 100644
--- a/test/run_encoder.cxx
+++ b/test/run_encoder.cxx
@@ -24,10 +24,11 @@
#include "AudioParser.hxx"
#include "ConfigData.hxx"
#include "util/Error.hxx"
+#include "Log.hxx"
#include "stdbin.h"
-#include <glib.h>
-
+#include <stdio.h>
+#include <stdlib.h>
#include <stddef.h>
#include <unistd.h>
@@ -50,8 +51,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 +65,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 +75,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 +84,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 +101,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..3b5e803d7 100644
--- a/test/run_filter.cxx
+++ b/test/run_filter.cxx
@@ -25,16 +25,19 @@
#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>
#include <assert.h>
#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
#include <errno.h>
#include <unistd.h>
@@ -45,16 +48,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 +69,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 +90,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 +104,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 +115,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 +124,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 +153,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..0c1ba1d36 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)
{
@@ -58,27 +50,17 @@ dump_input_stream(InputStream *is)
is->Lock();
- /* wait until the stream becomes ready */
-
- is->WaitReady();
-
- if (!is->Check(error)) {
- LogError(error);
- is->Unlock();
- return EXIT_FAILURE;
- }
-
/* 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 +96,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 */
@@ -147,7 +129,7 @@ int main(int argc, char **argv)
Mutex mutex;
Cond cond;
- is = InputStream::Open(argv[1], mutex, cond, error);
+ is = InputStream::OpenReady(argv[1], mutex, cond, error);
if (is != NULL) {
ret = dump_input_stream(is);
is->Close();
@@ -155,8 +137,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..86c2452b9 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>
@@ -43,6 +44,7 @@
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
+#include <stdio.h>
EventLoop *main_loop;
@@ -83,7 +85,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 +95,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 +107,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 +145,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 +167,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 +183,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 +202,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..7a0ea3b64 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>
@@ -32,12 +30,13 @@
#include <netdb.h>
#endif
+#include <stdio.h>
#include <stdlib.h>
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 +50,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..b10eabeb3 100644
--- a/test/software_volume.cxx
+++ b/test/software_volume.cxx
@@ -24,15 +24,17 @@
*/
#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 "Log.hxx"
-#include <glib.h>
-
+#include <stdio.h>
#include <stddef.h>
+#include <stdlib.h>
#include <unistd.h>
int main(int argc, char **argv)
@@ -41,28 +43,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_format.cxx b/test/test_pcm_format.cxx
index 49f4ccd4b..3b0dbb8fe 100644
--- a/test/test_pcm_format.cxx
+++ b/test/test_pcm_format.cxx
@@ -29,86 +29,72 @@
void
PcmFormatTest::TestFormat8to16()
{
- constexpr unsigned N = 256;
+ constexpr size_t N = 256;
const auto src = TestDataBuffer<int8_t, N>();
PcmBuffer buffer;
- size_t d_size;
PcmDither dither;
- auto d = pcm_convert_to_16(buffer, dither, SampleFormat::S8,
- src, sizeof(src), &d_size);
- auto d_end = pcm_end_pointer(d, d_size);
- CPPUNIT_ASSERT_EQUAL(N, unsigned(d_end - d));
+ auto d = pcm_convert_to_16(buffer, dither, SampleFormat::S8, src);
+ CPPUNIT_ASSERT_EQUAL(N, d.size);
for (size_t i = 0; i < N; ++i)
- CPPUNIT_ASSERT_EQUAL(int(src[i]), d[i] >> 8);
+ CPPUNIT_ASSERT_EQUAL(int(src[i]), d.data[i] >> 8);
}
void
PcmFormatTest::TestFormat16to24()
{
- constexpr unsigned N = 256;
+ constexpr size_t N = 256;
const auto src = TestDataBuffer<int16_t, N>();
PcmBuffer buffer;
- size_t d_size;
- auto d = pcm_convert_to_24(buffer, SampleFormat::S16,
- src, sizeof(src), &d_size);
- auto d_end = pcm_end_pointer(d, d_size);
- CPPUNIT_ASSERT_EQUAL(N, unsigned(d_end - d));
+ auto d = pcm_convert_to_24(buffer, SampleFormat::S16, src);
+ CPPUNIT_ASSERT_EQUAL(N, d.size);
for (size_t i = 0; i < N; ++i)
- CPPUNIT_ASSERT_EQUAL(int(src[i]), d[i] >> 8);
+ CPPUNIT_ASSERT_EQUAL(int(src[i]), d.data[i] >> 8);
}
void
PcmFormatTest::TestFormat16to32()
{
- constexpr unsigned N = 256;
+ constexpr size_t N = 256;
const auto src = TestDataBuffer<int16_t, N>();
PcmBuffer buffer;
- size_t d_size;
- auto d = pcm_convert_to_32(buffer, SampleFormat::S16,
- src, sizeof(src), &d_size);
- auto d_end = pcm_end_pointer(d, d_size);
- CPPUNIT_ASSERT_EQUAL(N, unsigned(d_end - d));
+ auto d = pcm_convert_to_32(buffer, SampleFormat::S16, src);
+ CPPUNIT_ASSERT_EQUAL(N, d.size);
for (size_t i = 0; i < N; ++i)
- CPPUNIT_ASSERT_EQUAL(int(src[i]), d[i] >> 16);
+ CPPUNIT_ASSERT_EQUAL(int(src[i]), d.data[i] >> 16);
}
void
PcmFormatTest::TestFormatFloat()
{
- constexpr unsigned N = 256;
+ constexpr size_t N = 256;
const auto src = TestDataBuffer<int16_t, N>();
PcmBuffer buffer1, buffer2;
- size_t f_size;
- auto f = pcm_convert_to_float(buffer1, SampleFormat::S16,
- src, sizeof(src), &f_size);
- auto f_end = pcm_end_pointer(f, f_size);
- CPPUNIT_ASSERT_EQUAL(N, unsigned(f_end - f));
+ auto f = pcm_convert_to_float(buffer1, SampleFormat::S16, src);
+ CPPUNIT_ASSERT_EQUAL(N, f.size);
- for (auto i = f; i != f_end; ++i) {
- CPPUNIT_ASSERT(*i >= -1.);
- CPPUNIT_ASSERT(*i <= 1.);
+ for (size_t i = 0; i != f.size; ++i) {
+ CPPUNIT_ASSERT(f.data[i] >= -1.);
+ CPPUNIT_ASSERT(f.data[i] <= 1.);
}
PcmDither dither;
- size_t d_size;
auto d = pcm_convert_to_16(buffer2, dither,
SampleFormat::FLOAT,
- f, f_size, &d_size);
- auto d_end = pcm_end_pointer(d, d_size);
- CPPUNIT_ASSERT_EQUAL(N, unsigned(d_end - d));
+ f.ToVoid());
+ CPPUNIT_ASSERT_EQUAL(N, d.size);
for (size_t i = 0; i < N; ++i)
- CPPUNIT_ASSERT_EQUAL(src[i], d[i]);
+ CPPUNIT_ASSERT_EQUAL(src[i], d.data[i]);
}
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_util.hxx b/test/test_pcm_util.hxx
index b378c75a7..216e360ce 100644
--- a/test/test_pcm_util.hxx
+++ b/test/test_pcm_util.hxx
@@ -17,6 +17,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#include "util/ConstBuffer.hxx"
+
#include <array>
#include <random>
@@ -76,6 +78,14 @@ public:
operator typename std::array<T, N>::const_pointer() const {
return begin();
}
+
+ operator ConstBuffer<T>() const {
+ return { begin(), size() };
+ }
+
+ operator ConstBuffer<void>() const {
+ return { begin(), size() * sizeof(T) };
+ }
};
template<typename T>
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_queue_priority.cxx b/test/test_queue_priority.cxx
index a1037798c..953103f9a 100644
--- a/test/test_queue_priority.cxx
+++ b/test/test_queue_priority.cxx
@@ -1,7 +1,6 @@
#include "config.h"
#include "Queue.hxx"
-#include "Song.hxx"
-#include "Directory.hxx"
+#include "DetachedSong.hxx"
#include "util/Macros.hxx"
#include <cppunit/TestFixture.h>
@@ -9,21 +8,8 @@
#include <cppunit/ui/text/TestRunner.h>
#include <cppunit/extensions/HelperMacros.h>
-Directory detached_root;
-
-Directory::Directory() {}
-Directory::~Directory() {}
-
-Song *
-Song::DupDetached() const
-{
- return const_cast<Song *>(this);
-}
-
-void
-Song::Free()
-{
-}
+Tag::Tag(const Tag &) {}
+void Tag::Clear() {}
static void
check_descending_priority(const struct queue *queue,
@@ -53,12 +39,29 @@ public:
void
QueuePriorityTest::TestPriority()
{
- static Song songs[16];
+ DetachedSong songs[16] = {
+ DetachedSong("0.ogg"),
+ DetachedSong("1.ogg"),
+ DetachedSong("2.ogg"),
+ DetachedSong("3.ogg"),
+ DetachedSong("4.ogg"),
+ DetachedSong("5.ogg"),
+ DetachedSong("6.ogg"),
+ DetachedSong("7.ogg"),
+ DetachedSong("8.ogg"),
+ DetachedSong("9.ogg"),
+ DetachedSong("a.ogg"),
+ DetachedSong("b.ogg"),
+ DetachedSong("c.ogg"),
+ DetachedSong("d.ogg"),
+ DetachedSong("e.ogg"),
+ DetachedSong("f.ogg"),
+ };
struct queue queue(32);
for (unsigned i = 0; i < ARRAY_SIZE(songs); ++i)
- queue.Append(&songs[i], 0);
+ queue.Append(DetachedSong(songs[i]), 0);
CPPUNIT_ASSERT_EQUAL(unsigned(ARRAY_SIZE(songs)), queue.GetLength());
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();