gui/playlists/library: Write unit test for adding file paths
This functionality needs to be tested better. I can't really test the dialog, since it runs in the main thread, but I can test adding library paths with the selected directory. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
3e17b7bc1f
commit
e550638823
|
@ -9,7 +9,6 @@
|
||||||
#include <gui/idle.h>
|
#include <gui/idle.h>
|
||||||
#include <gui/model.h>
|
#include <gui/model.h>
|
||||||
#include <gui/playlist.h>
|
#include <gui/playlist.h>
|
||||||
#include <gui/playlists/library.h>
|
|
||||||
#include <gui/sidebar.h>
|
#include <gui/sidebar.h>
|
||||||
#include <gui/treeview.h>
|
#include <gui/treeview.h>
|
||||||
#include <gui/view.h>
|
#include <gui/view.h>
|
||||||
|
@ -108,7 +107,6 @@ static void __ocarina_startup(GApplication *application, gpointer data)
|
||||||
gui_treeview_init();
|
gui_treeview_init();
|
||||||
gui_sidebar_init();
|
gui_sidebar_init();
|
||||||
gui_view_init();
|
gui_view_init();
|
||||||
gui_pl_library_init();
|
|
||||||
gui_playlist_init();
|
gui_playlist_init();
|
||||||
gui_audio_init();
|
gui_audio_init();
|
||||||
|
|
||||||
|
|
|
@ -182,6 +182,8 @@ void gui_playlist_init()
|
||||||
"audio-x-generic");
|
"audio-x-generic");
|
||||||
|
|
||||||
idle_schedule(IDLE_SYNC, __gui_playlist_init_idle, NULL);
|
idle_schedule(IDLE_SYNC, __gui_playlist_init_idle, NULL);
|
||||||
|
|
||||||
|
gui_pl_library_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
const gchar *gui_playlist_cur()
|
const gchar *gui_playlist_cur()
|
||||||
|
|
|
@ -8,27 +8,12 @@
|
||||||
#include <gui/window.h>
|
#include <gui/window.h>
|
||||||
#include <glib/gi18n.h>
|
#include <glib/gi18n.h>
|
||||||
|
|
||||||
static void __gui_pl_library_add(GtkFileChooser *chooser)
|
|
||||||
{
|
|
||||||
gchar *filename = gtk_file_chooser_get_filename(chooser);
|
|
||||||
struct playlist *playlist;
|
|
||||||
struct library *library;
|
|
||||||
|
|
||||||
if (playlist_new(PL_LIBRARY, filename)) {
|
|
||||||
library = library_lookup(filename);
|
|
||||||
playlist = playlist_get(PL_LIBRARY, library->li_path);
|
|
||||||
gui_playlist_add_library(playlist);
|
|
||||||
}
|
|
||||||
|
|
||||||
gui_idle_enable();
|
|
||||||
g_free(filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
void __gui_pl_library_choose(GtkButton *button, gpointer data)
|
void __gui_pl_library_choose(GtkButton *button, gpointer data)
|
||||||
{
|
{
|
||||||
GtkFileFilter *filter;
|
GtkFileFilter *filter;
|
||||||
|
const gchar *music;
|
||||||
GtkWidget *dialog;
|
GtkWidget *dialog;
|
||||||
const gchar *path;
|
gchar *path;
|
||||||
gint res;
|
gint res;
|
||||||
|
|
||||||
filter = gtk_file_filter_new();
|
filter = gtk_file_filter_new();
|
||||||
|
@ -42,14 +27,17 @@ void __gui_pl_library_choose(GtkButton *button, gpointer data)
|
||||||
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
|
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
|
||||||
gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter);
|
gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter);
|
||||||
|
|
||||||
path = g_get_user_special_dir(G_USER_DIRECTORY_MUSIC);
|
music = g_get_user_special_dir(G_USER_DIRECTORY_MUSIC);
|
||||||
if (path)
|
if (music)
|
||||||
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog),
|
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog),
|
||||||
path);
|
music);
|
||||||
|
|
||||||
res = gtk_dialog_run(GTK_DIALOG(dialog));
|
res = gtk_dialog_run(GTK_DIALOG(dialog));
|
||||||
if (res == GTK_RESPONSE_ACCEPT)
|
if (res == GTK_RESPONSE_ACCEPT) {
|
||||||
__gui_pl_library_add(GTK_FILE_CHOOSER(dialog));
|
path = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
|
||||||
|
gui_pl_library_add(path);
|
||||||
|
g_free(path);
|
||||||
|
}
|
||||||
|
|
||||||
gtk_widget_destroy(dialog);
|
gtk_widget_destroy(dialog);
|
||||||
}
|
}
|
||||||
|
@ -64,8 +52,10 @@ static bool __gui_pl_library_init_idle()
|
||||||
gui_playlist_add_library(playlist);
|
gui_playlist_add_library(playlist);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef CONFIG_TESTING
|
||||||
if (library_db_get()->db_size == 0)
|
if (library_db_get()->db_size == 0)
|
||||||
__gui_pl_library_choose(NULL, NULL);
|
__gui_pl_library_choose(NULL, NULL);
|
||||||
|
#endif /* CONFIG_TESTING */
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -74,3 +64,18 @@ void gui_pl_library_init()
|
||||||
{
|
{
|
||||||
idle_schedule(IDLE_SYNC, __gui_pl_library_init_idle, NULL);
|
idle_schedule(IDLE_SYNC, __gui_pl_library_init_idle, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool gui_pl_library_add(const gchar *filename)
|
||||||
|
{
|
||||||
|
struct playlist *playlist;
|
||||||
|
struct library *library;
|
||||||
|
|
||||||
|
if (playlist_new(PL_LIBRARY, filename)) {
|
||||||
|
library = library_lookup(filename);
|
||||||
|
playlist = playlist_get(PL_LIBRARY, library->li_path);
|
||||||
|
gui_playlist_add_library(playlist);
|
||||||
|
gui_idle_enable();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
*/
|
*/
|
||||||
#ifndef OCARINA_GUI_PLAYLIST_H
|
#ifndef OCARINA_GUI_PLAYLIST_H
|
||||||
#define OCARINA_GUI_PLAYLIST_H
|
#define OCARINA_GUI_PLAYLIST_H
|
||||||
|
|
||||||
#include <core/playlist.h>
|
#include <core/playlist.h>
|
||||||
|
#include <gui/playlists/library.h>
|
||||||
|
|
||||||
/* Called to initialize the GUI playlist code. */
|
/* Called to initialize the GUI playlist code. */
|
||||||
void gui_playlist_init();
|
void gui_playlist_init();
|
||||||
|
|
|
@ -7,4 +7,7 @@
|
||||||
/* Called to initialize GUI library playlists. */
|
/* Called to initialize GUI library playlists. */
|
||||||
void gui_pl_library_init();
|
void gui_pl_library_init();
|
||||||
|
|
||||||
|
/* Called to add a library path. */
|
||||||
|
bool gui_pl_library_add(const gchar *);
|
||||||
|
|
||||||
#endif /* OCARINA_GUI_PLAYLISTS_LIBRARY_H */
|
#endif /* OCARINA_GUI_PLAYLISTS_LIBRARY_H */
|
||||||
|
|
|
@ -11,6 +11,8 @@ gui_unit_test(Model)
|
||||||
gui_unit_test(Filter)
|
gui_unit_test(Filter)
|
||||||
gui_unit_test(Treeview)
|
gui_unit_test(Treeview)
|
||||||
gui_unit_test(Sidebar)
|
gui_unit_test(Sidebar)
|
||||||
|
|
||||||
|
add_subdirectory(playlists/)
|
||||||
gui_unit_test(View)
|
gui_unit_test(View)
|
||||||
gui_unit_test(Playlist)
|
gui_unit_test(Playlist)
|
||||||
gui_unit_test(Audio)
|
gui_unit_test(Audio)
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
library
|
|
@ -0,0 +1,7 @@
|
||||||
|
Include(../../UnitTest.cmake)
|
||||||
|
|
||||||
|
function(gui_playlist_unit_test name)
|
||||||
|
unit_test(Gui/Playlists ${name} guilib ${corefiles})
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
gui_playlist_unit_test(Library)
|
|
@ -0,0 +1,70 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2016 (c) Anna Schumaker.
|
||||||
|
*/
|
||||||
|
#include <core/core.h>
|
||||||
|
#include <core/idle.h>
|
||||||
|
#include <gui/builder.h>
|
||||||
|
#include <gui/filter.h>
|
||||||
|
#include <gui/model.h>
|
||||||
|
#include <gui/playlist.h>
|
||||||
|
#include <gui/sidebar.h>
|
||||||
|
#include <gui/treeview.h>
|
||||||
|
|
||||||
|
struct core_init_data init_data = {
|
||||||
|
.playlist_ops = &playlist_ops,
|
||||||
|
};
|
||||||
|
|
||||||
|
static void test_library()
|
||||||
|
{
|
||||||
|
GtkTreeModel *model = gui_sidebar_model();
|
||||||
|
struct playlist *playlist;
|
||||||
|
GtkTreeIter iter;
|
||||||
|
|
||||||
|
gui_sidebar_iter_first(&iter);
|
||||||
|
gui_sidebar_iter_find(&iter, "Library", PL_MAX_TYPE);
|
||||||
|
g_assert_false(gtk_tree_model_iter_has_child(model, &iter));
|
||||||
|
|
||||||
|
g_assert_cmpuint(library_db_get()->db_size, ==, 0);
|
||||||
|
g_assert_null(playlist_get(PL_LIBRARY, "tests/Music/Hyrule Symphony"));
|
||||||
|
|
||||||
|
g_assert_true(gui_pl_library_add("tests/Music/Hyrule Symphony"));
|
||||||
|
playlist = playlist_get(PL_LIBRARY, "tests/Music/Hyrule Symphony");
|
||||||
|
g_assert_cmpuint(library_db_get()->db_size, ==, 1);
|
||||||
|
g_assert_cmpuint(playlist_size(playlist->pl_type,
|
||||||
|
playlist->pl_name), ==, 0);
|
||||||
|
g_assert_true(gtk_tree_model_iter_has_child(model, &iter));
|
||||||
|
g_assert_cmpuint(gtk_tree_model_iter_n_children(model, &iter), ==, 1);
|
||||||
|
|
||||||
|
while (idle_run_task()) {}
|
||||||
|
g_assert_cmpuint(library_db_get()->db_size, ==, 1);
|
||||||
|
g_assert_cmpuint(playlist_size(playlist->pl_type,
|
||||||
|
playlist->pl_name), ==, 13);
|
||||||
|
g_assert_true(gtk_tree_model_iter_has_child(model, &iter));
|
||||||
|
g_assert_cmpuint(gtk_tree_model_iter_n_children(model, &iter), ==, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
gtk_init(&argc, NULL);
|
||||||
|
core_init(&argc, &argv, &init_data);
|
||||||
|
gui_builder_init("share/ocarina/ocarina.ui");
|
||||||
|
gui_model_init();
|
||||||
|
gui_filter_init();
|
||||||
|
gui_treeview_init();
|
||||||
|
gui_sidebar_init();
|
||||||
|
gui_playlist_init();
|
||||||
|
while (idle_run_task()) {}
|
||||||
|
|
||||||
|
g_test_init(&argc, &argv, NULL);
|
||||||
|
g_test_add_func("/Gui/Playlists/Library", test_library);
|
||||||
|
ret = g_test_run();
|
||||||
|
|
||||||
|
core_deinit();
|
||||||
|
gui_treeview_deinit();
|
||||||
|
gui_filter_deinit();
|
||||||
|
gui_model_deinit();
|
||||||
|
gui_builder_deinit();
|
||||||
|
return ret;
|
||||||
|
}
|
Loading…
Reference in New Issue