aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--test/DumpDatabase.cxx151
-rw-r--r--test/FakeSong.cxx33
-rw-r--r--test/dump_playlist.c3
-rw-r--r--test/dump_text_file.c3
-rw-r--r--test/run_decoder.c5
-rw-r--r--test/run_inotify.c2
-rw-r--r--test/run_input.c4
-rw-r--r--test/test_queue_priority.c15
8 files changed, 202 insertions, 14 deletions
diff --git a/test/DumpDatabase.cxx b/test/DumpDatabase.cxx
new file mode 100644
index 000000000..7aa8f06f5
--- /dev/null
+++ b/test/DumpDatabase.cxx
@@ -0,0 +1,151 @@
+/*
+ * 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 "DatabaseRegistry.hxx"
+#include "DatabasePlugin.hxx"
+#include "DatabaseSelection.hxx"
+#include "directory.h"
+#include "song.h"
+#include "playlist_vector.h"
+
+extern "C" {
+#include "conf.h"
+#include "tag.h"
+}
+
+#include <iostream>
+using std::cout;
+using std::cerr;
+using std::endl;
+
+#include <stdlib.h>
+
+static void
+my_log_func(const gchar *log_domain, G_GNUC_UNUSED GLogLevelFlags log_level,
+ const gchar *message, G_GNUC_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, GError **)
+{
+ cout << "D " << directory.path << endl;
+ return true;
+}
+
+static bool
+DumpSong(song &song, GError **)
+{
+ cout << "S " << song.parent->path << "/" << song.uri << endl;
+ return true;
+}
+
+static bool
+DumpPlaylist(const playlist_metadata &playlist,
+ const directory &directory, GError **)
+{
+ cout << "P " << directory.path << "/" << playlist.name << endl;
+ return true;
+}
+
+int
+main(int argc, char **argv)
+{
+ GError *error = nullptr;
+
+ if (argc != 3) {
+ cerr << "Usage: DumpDatabase CONFIG PLUGIN" << endl;
+ return 1;
+ }
+
+ const char *const config_path = argv[1];
+ const char *const plugin_name = argv[2];
+
+ const DatabasePlugin *plugin = GetDatabasePluginByName(plugin_name);
+ if (plugin == NULL) {
+ cerr << "No such database plugin: " << plugin_name << endl;
+ return EXIT_FAILURE;
+ }
+
+ /* initialize GLib */
+
+ g_thread_init(nullptr);
+ g_log_set_default_handler(my_log_func, nullptr);
+
+ /* initialize MPD */
+
+ config_global_init();
+
+ if (!config_read_file(config_path, &error)) {
+ cerr << error->message << endl;
+ g_error_free(error);
+ return EXIT_FAILURE;
+ }
+
+ tag_lib_init();
+
+ /* do it */
+
+ const struct config_param *path = config_get_param(CONF_DB_FILE);
+ struct config_param *param = config_new_param("database", path->line);
+ if (path != nullptr)
+ config_add_block_param(param, "path", path->value, path->line);
+
+ Database *db = plugin->create(param, &error);
+
+ config_param_free(param);
+
+ if (db == nullptr) {
+ cerr << error->message << endl;
+ g_error_free(error);
+ return EXIT_FAILURE;
+ }
+
+ if (!db->Open(&error)) {
+ delete db;
+ cerr << error->message << endl;
+ g_error_free(error);
+ return EXIT_FAILURE;
+ }
+
+ const DatabaseSelection selection("", true);
+
+ if (!db->Visit(selection, DumpDirectory, DumpSong, DumpPlaylist,
+ &error)) {
+ db->Close();
+ delete db;
+ cerr << error->message << endl;
+ g_error_free(error);
+ return EXIT_FAILURE;
+ }
+
+ db->Close();
+ delete db;
+
+ /* deinitialize everything */
+
+ config_global_finish();
+
+ return EXIT_SUCCESS;
+}
diff --git a/test/FakeSong.cxx b/test/FakeSong.cxx
new file mode 100644
index 000000000..927a07652
--- /dev/null
+++ b/test/FakeSong.cxx
@@ -0,0 +1,33 @@
+/*
+ * 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 "song.h"
+#include "directory.h"
+#include "gcc.h"
+
+#include <stdlib.h>
+
+struct directory detached_root;
+
+struct song *
+song_dup_detached(gcc_unused const struct song *src)
+{
+ abort();
+}
diff --git a/test/dump_playlist.c b/test/dump_playlist.c
index 0570f6e49..28237a799 100644
--- a/test/dump_playlist.c
+++ b/test/dump_playlist.c
@@ -21,7 +21,6 @@
#include "io_thread.h"
#include "input_init.h"
#include "input_stream.h"
-#include "tag_pool.h"
#include "tag_save.h"
#include "conf.h"
#include "song.h"
@@ -157,7 +156,6 @@ int main(int argc, char **argv)
/* initialize MPD */
- tag_pool_init();
config_global_init();
success = config_read_file(argv[1], &error);
if (!success) {
@@ -249,7 +247,6 @@ int main(int argc, char **argv)
input_stream_global_finish();
io_thread_deinit();
config_global_finish();
- tag_pool_deinit();
return 0;
}
diff --git a/test/dump_text_file.c b/test/dump_text_file.c
index f14371441..f13e648b2 100644
--- a/test/dump_text_file.c
+++ b/test/dump_text_file.c
@@ -22,7 +22,6 @@
#include "input_init.h"
#include "input_stream.h"
#include "text_input_stream.h"
-#include "tag_pool.h"
#include "conf.h"
#include "stdbin.h"
@@ -112,7 +111,6 @@ int main(int argc, char **argv)
/* initialize MPD */
- tag_pool_init();
config_global_init();
io_thread_init();
@@ -164,7 +162,6 @@ int main(int argc, char **argv)
io_thread_deinit();
config_global_finish();
- tag_pool_deinit();
return ret;
}
diff --git a/test/run_decoder.c b/test/run_decoder.c
index e6712c75b..c25e727ba 100644
--- a/test/run_decoder.c
+++ b/test/run_decoder.c
@@ -21,7 +21,6 @@
#include "io_thread.h"
#include "decoder_list.h"
#include "decoder_api.h"
-#include "tag_pool.h"
#include "input_init.h"
#include "input_stream.h"
#include "audio_format.h"
@@ -191,8 +190,6 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}
- tag_pool_init();
-
if (!input_stream_global_init(&error)) {
g_warning("%s", error->message);
g_error_free(error);
@@ -248,7 +245,5 @@ int main(int argc, char **argv)
return 1;
}
- tag_pool_deinit();
-
return 0;
}
diff --git a/test/run_inotify.c b/test/run_inotify.c
index 3e7c70dba..4ceb60229 100644
--- a/test/run_inotify.c
+++ b/test/run_inotify.c
@@ -20,6 +20,8 @@
#include "config.h"
#include "inotify_source.h"
+#include <glib.h>
+
#include <stdbool.h>
#include <sys/inotify.h>
#include <signal.h>
diff --git a/test/run_input.c b/test/run_input.c
index 676e4e618..acf25a283 100644
--- a/test/run_input.c
+++ b/test/run_input.c
@@ -21,8 +21,8 @@
#include "io_thread.h"
#include "input_init.h"
#include "input_stream.h"
-#include "tag_pool.h"
#include "tag_save.h"
+#include "tag.h"
#include "conf.h"
#include "stdbin.h"
@@ -127,7 +127,6 @@ int main(int argc, char **argv)
/* initialize MPD */
- tag_pool_init();
config_global_init();
io_thread_init();
@@ -179,7 +178,6 @@ int main(int argc, char **argv)
io_thread_deinit();
config_global_finish();
- tag_pool_deinit();
return ret;
}
diff --git a/test/test_queue_priority.c b/test/test_queue_priority.c
index 5543edbba..b4a7366e9 100644
--- a/test/test_queue_priority.c
+++ b/test/test_queue_priority.c
@@ -1,5 +1,20 @@
+#include "config.h"
#include "queue.h"
#include "song.h"
+#include "directory.h"
+
+struct directory detached_root;
+
+struct song *
+song_dup_detached(const struct song *src)
+{
+ union {
+ const struct song *in;
+ struct song *out;
+ } u = { .in = src };
+
+ return u.out;
+}
void
song_free(G_GNUC_UNUSED struct song *song)