diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/DumpDatabase.cxx | 151 | ||||
-rw-r--r-- | test/DumpPlaylist.cxx (renamed from test/dump_playlist.c) | 14 | ||||
-rw-r--r-- | test/FakeSong.cxx | 33 | ||||
-rw-r--r-- | test/RunInotify.cxx (renamed from test/run_inotify.c) | 5 | ||||
-rw-r--r-- | test/RunInput.cxx (renamed from test/run_input.c) | 13 | ||||
-rw-r--r-- | test/TestQueuePriority.cxx (renamed from test/test_queue_priority.c) | 15 | ||||
-rw-r--r-- | test/dump_text_file.c | 3 | ||||
-rw-r--r-- | test/read_tags.c | 19 | ||||
-rw-r--r-- | test/run_decoder.c | 5 |
9 files changed, 237 insertions, 21 deletions
diff --git a/test/DumpDatabase.cxx b/test/DumpDatabase.cxx new file mode 100644 index 000000000..0678d7076 --- /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.hxx" +#include "song.h" +#include "PlaylistVector.hxx" + +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 PlaylistInfo &playlist, + const Directory &directory, GError **) +{ + cout << "P " << directory.path << "/" << playlist.name.c_str() << 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/dump_playlist.c b/test/DumpPlaylist.cxx index 84ac69045..427052b6c 100644 --- a/test/dump_playlist.c +++ b/test/DumpPlaylist.cxx @@ -18,23 +18,29 @@ */ #include "config.h" +#include "TagSave.hxx" +#include "song.h" +#include "Directory.hxx" + +extern "C" { #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" #include "decoder_api.h" #include "decoder_list.h" #include "playlist_list.h" #include "playlist_plugin.h" +} #include <glib.h> #include <unistd.h> #include <stdlib.h> +Directory::Directory() {} +Directory::~Directory() {} + static void my_log_func(const gchar *log_domain, G_GNUC_UNUSED GLogLevelFlags log_level, const gchar *message, G_GNUC_UNUSED gpointer user_data) @@ -157,7 +163,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 +254,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/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/run_inotify.c b/test/RunInotify.cxx index 3e7c70dba..2b77130d8 100644 --- a/test/run_inotify.c +++ b/test/RunInotify.cxx @@ -18,9 +18,10 @@ */ #include "config.h" -#include "inotify_source.h" +#include "InotifySource.hxx" + +#include <glib.h> -#include <stdbool.h> #include <sys/inotify.h> #include <signal.h> diff --git a/test/run_input.c b/test/RunInput.cxx index 676e4e618..52b53db5a 100644 --- a/test/run_input.c +++ b/test/RunInput.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2011 The Music Player Daemon Project + * Copyright (C) 2003-2013 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -18,17 +18,20 @@ */ #include "config.h" +#include "TagSave.hxx" +#include "stdbin.h" + +extern "C" { #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" #ifdef ENABLE_ARCHIVE #include "archive_list.h" #endif +} #include <glib.h> @@ -127,7 +130,6 @@ int main(int argc, char **argv) /* initialize MPD */ - tag_pool_init(); config_global_init(); io_thread_init(); @@ -179,7 +181,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/TestQueuePriority.cxx index 5543edbba..6d994176f 100644 --- a/test/test_queue_priority.c +++ b/test/TestQueuePriority.cxx @@ -1,5 +1,20 @@ +#include "config.h" +extern "C" { #include "queue.h" +} #include "song.h" +#include "Directory.hxx" + +Directory detached_root; + +Directory::Directory() {} +Directory::~Directory() {} + +struct song * +song_dup_detached(const struct song *src) +{ + return const_cast<song *>(src); +} void song_free(G_GNUC_UNUSED struct song *song) 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/read_tags.c b/test/read_tags.c index faf9a45c0..09032efc7 100644 --- a/test/read_tags.c +++ b/test/read_tags.c @@ -218,6 +218,25 @@ int main(int argc, char **argv) return 1; } + g_mutex_lock(mutex); + + while (!is->ready) { + g_cond_wait(cond, mutex); + input_stream_update(is); + } + + if (!input_stream_check(is, &error)) { + g_mutex_unlock(mutex); + + g_printerr("Failed to read %s: %s\n", + path, error->message); + g_error_free(error); + + return EXIT_FAILURE; + } + + g_mutex_unlock(mutex); + success = decoder_plugin_scan_stream(plugin, is, &print_handler, NULL); input_stream_close(is); 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; } |