2015-12-29 09:11:51 -05:00
|
|
|
/*
|
|
|
|
* Copyright 2015 (c) Anna Schumaker.
|
|
|
|
*/
|
2016-08-25 10:05:27 -04:00
|
|
|
#include <core/core.h>
|
2016-08-26 09:25:17 -04:00
|
|
|
#include <core/idle.h>
|
2016-03-29 08:39:00 -04:00
|
|
|
#include <core/settings.h>
|
2016-08-26 09:25:17 -04:00
|
|
|
#include <gui/filter.h>
|
|
|
|
#include <gui/model.h>
|
2015-12-29 09:11:51 -05:00
|
|
|
#include <gui/sidebar.h>
|
2016-08-26 09:25:17 -04:00
|
|
|
#include <gui/treeview.h>
|
2015-12-29 09:11:51 -05:00
|
|
|
#include <tests/test.h>
|
|
|
|
|
2016-08-25 10:05:27 -04:00
|
|
|
const gchar *test_pl_names[8] = { "Collection",
|
|
|
|
"History",
|
|
|
|
"", "Playlists",
|
|
|
|
"", "Dynamic",
|
|
|
|
"", "Library" };
|
2016-08-25 14:40:45 -04:00
|
|
|
const gchar *test_dyn_names[3] = { "Least Played", "Most Played", "Unplayed" };
|
2016-08-25 10:05:27 -04:00
|
|
|
struct core_init_data init_data;
|
2016-08-25 09:30:46 -04:00
|
|
|
|
2015-12-29 09:11:51 -05:00
|
|
|
static void test_sidebar()
|
2016-08-25 07:44:02 -04:00
|
|
|
{
|
2016-08-25 11:41:40 -04:00
|
|
|
GtkTreeIter iter, child;
|
2016-08-25 09:30:46 -04:00
|
|
|
unsigned int i;
|
2016-08-25 10:58:24 -04:00
|
|
|
|
2016-08-25 07:44:02 -04:00
|
|
|
g_assert_nonnull(gui_sidebar_store());
|
|
|
|
g_assert_true(GTK_IS_TREE_STORE(gui_sidebar_store()));
|
|
|
|
|
|
|
|
g_assert_nonnull(gui_sidebar_model());
|
|
|
|
g_assert_true(GTK_IS_TREE_MODEL(gui_sidebar_model()));
|
2016-08-25 07:50:16 -04:00
|
|
|
|
|
|
|
g_assert_nonnull(gui_sidebar_filter());
|
|
|
|
g_assert_true(GTK_IS_TREE_MODEL_FILTER(gui_sidebar_filter()));
|
2016-08-25 07:56:20 -04:00
|
|
|
|
|
|
|
g_assert_nonnull(gui_sidebar_treeview());
|
|
|
|
g_assert_true(GTK_IS_TREE_VIEW(gui_sidebar_treeview()));
|
2016-08-25 10:58:24 -04:00
|
|
|
|
2016-08-26 10:00:26 -04:00
|
|
|
g_assert_nonnull(gui_random_button());
|
|
|
|
g_assert_true(GTK_IS_TOGGLE_BUTTON(gui_random_button()));
|
|
|
|
|
2016-08-25 09:30:46 -04:00
|
|
|
g_assert_true(gui_sidebar_iter_first(&iter));
|
2016-09-12 13:49:27 -04:00
|
|
|
gui_sidebar_iter_add(&iter, playlist_lookup(PL_SYSTEM, "Collection"), NULL);
|
|
|
|
gui_sidebar_iter_add(&iter, playlist_lookup(PL_SYSTEM, "History"), NULL);
|
2016-08-25 10:05:27 -04:00
|
|
|
|
|
|
|
g_assert_true(gui_sidebar_iter_first(&iter));
|
|
|
|
for (i = 0; i < 8; i++) {
|
2016-08-25 09:30:46 -04:00
|
|
|
g_assert_cmpstr_free(gui_sidebar_iter_name(&iter), ==,
|
|
|
|
test_pl_names[i]);
|
|
|
|
g_assert_cmpuint(gui_sidebar_iter_type(&iter), ==,
|
2016-08-25 10:05:27 -04:00
|
|
|
(i < 2) ? PL_SYSTEM: PL_MAX_TYPE);
|
2016-08-25 09:30:46 -04:00
|
|
|
|
2016-08-25 10:05:27 -04:00
|
|
|
if (i < 7)
|
2016-08-25 09:30:46 -04:00
|
|
|
g_assert_true(gui_sidebar_iter_next(&iter));
|
|
|
|
}
|
|
|
|
g_assert_false(gui_sidebar_iter_next(&iter));
|
2016-08-25 10:34:00 -04:00
|
|
|
|
|
|
|
gui_sidebar_iter_first(&iter);
|
|
|
|
g_assert_true(gui_sidebar_iter_find(&iter, "Playlists", PL_MAX_TYPE));
|
|
|
|
g_assert_cmpstr_free(gui_sidebar_iter_name(&iter), ==, "Playlists");
|
|
|
|
g_assert_cmpuint(gui_sidebar_iter_type(&iter), ==, PL_MAX_TYPE);
|
|
|
|
|
2016-08-25 11:41:40 -04:00
|
|
|
g_assert_false(gui_sidebar_iter_down(&iter, &child));
|
2016-09-12 13:49:27 -04:00
|
|
|
gui_sidebar_iter_append_child(&iter, playlist_lookup(PL_SYSTEM, "Favorites"),
|
2016-08-25 11:41:40 -04:00
|
|
|
NULL);
|
2016-09-12 13:49:27 -04:00
|
|
|
gui_sidebar_iter_append_child(&iter, playlist_lookup(PL_SYSTEM, "Hidden"),
|
2016-08-25 11:41:40 -04:00
|
|
|
NULL);
|
|
|
|
g_assert_true(gui_sidebar_iter_down(&iter, &child));
|
|
|
|
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
g_assert_cmpstr_free(gui_sidebar_iter_name(&child), ==,
|
|
|
|
(i == 0) ? "Favorites" : "Hidden");
|
|
|
|
g_assert_cmpuint(gui_sidebar_iter_type(&child), ==, PL_SYSTEM);
|
|
|
|
gui_sidebar_iter_next(&child);
|
|
|
|
}
|
|
|
|
|
2016-08-25 10:34:00 -04:00
|
|
|
g_assert_false(gui_sidebar_iter_find(&iter, "History", PL_SYSTEM));
|
|
|
|
gui_sidebar_iter_first(&iter);
|
|
|
|
g_assert_true(gui_sidebar_iter_find(&iter, "History", PL_SYSTEM));
|
|
|
|
g_assert_cmpstr_free(gui_sidebar_iter_name(&iter), ==, "History");
|
|
|
|
g_assert_cmpuint(gui_sidebar_iter_type(&iter), ==, PL_SYSTEM);
|
2016-09-10 14:03:11 -04:00
|
|
|
g_assert(gui_sidebar_iter_playlist(&iter) ==
|
2016-09-12 13:49:27 -04:00
|
|
|
playlist_lookup(PL_SYSTEM, "History"));
|
2016-08-25 14:40:45 -04:00
|
|
|
|
|
|
|
g_assert_true(gui_sidebar_iter_find(&iter, "Dynamic", PL_MAX_TYPE));
|
|
|
|
g_assert_false(gui_sidebar_iter_down(&iter, &child));
|
2016-09-12 13:49:27 -04:00
|
|
|
gui_sidebar_iter_sort_child(&iter, playlist_lookup(PL_SYSTEM, "Most Played"),
|
2016-08-25 14:40:45 -04:00
|
|
|
NULL);
|
2016-09-12 13:49:27 -04:00
|
|
|
gui_sidebar_iter_sort_child(&iter, playlist_lookup(PL_SYSTEM, "Least Played"),
|
2016-08-25 14:40:45 -04:00
|
|
|
NULL);
|
2016-09-12 13:49:27 -04:00
|
|
|
gui_sidebar_iter_sort_child(&iter, playlist_lookup(PL_SYSTEM, "Unplayed"),
|
2016-08-25 14:40:45 -04:00
|
|
|
NULL);
|
|
|
|
g_assert_true(gui_sidebar_iter_down(&iter, &child));
|
|
|
|
|
|
|
|
g_assert_true(gui_sidebar_iter_down(&iter, &child));
|
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
g_assert_cmpstr_free(gui_sidebar_iter_name(&child), ==,
|
|
|
|
test_dyn_names[i]);
|
|
|
|
g_assert_cmpuint(gui_sidebar_iter_type(&child), ==, PL_SYSTEM);
|
|
|
|
gui_sidebar_iter_next(&child);
|
|
|
|
}
|
2016-08-25 07:44:02 -04:00
|
|
|
}
|
|
|
|
|
2016-08-26 09:25:17 -04:00
|
|
|
static void test_sidebar_selection()
|
|
|
|
{
|
2016-09-12 08:17:41 -04:00
|
|
|
struct playlist *collection;
|
2016-08-26 09:25:17 -04:00
|
|
|
GtkTreeSelection *selection;
|
2016-08-26 10:00:26 -04:00
|
|
|
GtkToggleButton *random;
|
2016-08-26 09:25:17 -04:00
|
|
|
GtkTreeModel *filter;
|
|
|
|
GtkTreePath *path;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
unsigned int i, n;
|
|
|
|
|
2016-09-12 13:49:27 -04:00
|
|
|
collection = playlist_lookup(PL_SYSTEM, "Collection");
|
2016-09-12 08:17:41 -04:00
|
|
|
selection = gtk_tree_view_get_selection(gui_sidebar_treeview());
|
|
|
|
filter = GTK_TREE_MODEL(gui_sidebar_filter());
|
|
|
|
random = gui_random_button();
|
2016-08-26 09:25:17 -04:00
|
|
|
|
|
|
|
g_assert_cmpuint(gtk_tree_model_iter_n_children(filter, NULL), ==, 6);
|
|
|
|
playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony");
|
|
|
|
while (idle_run_task()) {}
|
2016-09-12 13:49:27 -04:00
|
|
|
playlist_add(playlist_lookup(PL_SYSTEM, "History"), track_get(0));
|
|
|
|
playlist_add(playlist_lookup(PL_SYSTEM, "Favorites"), track_get(0));
|
2016-08-26 09:25:17 -04:00
|
|
|
gtk_tree_model_filter_refilter(gui_sidebar_filter());
|
|
|
|
g_assert_cmpuint(gtk_tree_model_iter_n_children(filter, NULL), ==, 8);
|
2016-08-31 16:55:19 -04:00
|
|
|
|
2016-09-12 08:17:41 -04:00
|
|
|
playlist_set_random(collection, true);
|
2016-09-12 13:08:24 -04:00
|
|
|
g_assert_true(playlist_select(playlist_lookup(PL_SYSTEM, "Favorites")));
|
2016-09-12 16:02:46 -04:00
|
|
|
g_assert(playlist_current() == playlist_lookup(PL_SYSTEM, "Favorites"));
|
2016-08-26 09:25:17 -04:00
|
|
|
|
|
|
|
g_assert_true(gui_sidebar_iter_first(&iter));
|
|
|
|
path = gtk_tree_model_get_path(gui_sidebar_model(), &iter);
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
gtk_tree_selection_select_path(selection, path);
|
|
|
|
n = gtk_tree_selection_count_selected_rows(selection);
|
|
|
|
g_assert_cmpuint(n, ==, (i < 2) ? 1 : 0);
|
2016-08-26 10:00:26 -04:00
|
|
|
if (i == 0) {
|
2016-09-12 08:17:41 -04:00
|
|
|
g_assert(gui_model_get_playlist() == collection);
|
2016-08-26 10:00:26 -04:00
|
|
|
g_assert_true(gtk_toggle_button_get_active(random));
|
|
|
|
g_assert_true(gtk_widget_get_sensitive(
|
|
|
|
GTK_WIDGET(random)));
|
|
|
|
|
|
|
|
gtk_toggle_button_set_active(random, false);
|
2016-09-19 10:55:29 -04:00
|
|
|
g_assert_false(collection->pl_random);
|
2016-08-26 10:00:26 -04:00
|
|
|
gtk_toggle_button_set_active(random, true);
|
2016-09-19 10:55:29 -04:00
|
|
|
g_assert_true(collection->pl_random);
|
2016-08-26 10:00:26 -04:00
|
|
|
} else if (i == 1) {
|
2016-08-26 09:25:17 -04:00
|
|
|
g_assert(gui_model_get_playlist() ==
|
2016-09-12 13:49:27 -04:00
|
|
|
playlist_lookup(PL_SYSTEM, "History"));
|
2016-08-26 10:00:26 -04:00
|
|
|
g_assert_false(gtk_toggle_button_get_active(random));
|
|
|
|
g_assert_false(gtk_widget_get_sensitive(
|
|
|
|
GTK_WIDGET(random)));
|
|
|
|
} else {
|
2016-08-26 09:25:17 -04:00
|
|
|
g_assert_null(gui_model_get_playlist());
|
2016-08-26 10:00:26 -04:00
|
|
|
g_assert_false(gtk_toggle_button_get_active(random));
|
|
|
|
g_assert_false(gtk_widget_get_sensitive(
|
|
|
|
GTK_WIDGET(random)));
|
|
|
|
}
|
2016-08-31 16:55:19 -04:00
|
|
|
|
|
|
|
gui_sidebar_filter_path_select(path);
|
2016-09-12 16:02:46 -04:00
|
|
|
g_assert(playlist_current() == playlist_lookup(PL_SYSTEM, "Collection"));
|
2016-08-31 16:55:19 -04:00
|
|
|
|
2016-08-26 09:25:17 -04:00
|
|
|
gtk_tree_selection_unselect_all(selection);
|
2016-08-31 16:55:19 -04:00
|
|
|
gui_sidebar_iter_next(&iter);
|
2016-08-26 09:25:17 -04:00
|
|
|
gtk_tree_path_next(path);
|
|
|
|
}
|
|
|
|
gtk_tree_path_free(path);
|
|
|
|
}
|
|
|
|
|
2016-08-25 07:44:02 -04:00
|
|
|
static void test_sidebar_pos()
|
2015-12-29 09:11:51 -05:00
|
|
|
{
|
2016-03-29 08:39:00 -04:00
|
|
|
g_assert_false(settings_has("gui.sidebar.pos"));
|
|
|
|
|
2016-08-21 13:34:05 -04:00
|
|
|
gtk_paned_set_position(gui_sidebar(), 300);
|
2016-03-29 08:39:00 -04:00
|
|
|
g_assert_true(settings_has("gui.sidebar.pos"));
|
|
|
|
g_assert_cmpuint(settings_get("gui.sidebar.pos"), ==, 300);
|
2016-03-25 08:16:12 -04:00
|
|
|
|
2016-03-29 08:39:00 -04:00
|
|
|
settings_set("gui.sidebar.pos", 250);
|
2016-03-25 08:16:12 -04:00
|
|
|
gui_sidebar_init();
|
2016-03-29 08:39:00 -04:00
|
|
|
g_assert_cmpuint(settings_get("gui.sidebar.pos"), ==, 250);
|
2016-08-21 13:34:05 -04:00
|
|
|
g_assert_cmpuint(gtk_paned_get_position(gui_sidebar()), ==, 250);
|
2016-03-25 08:16:12 -04:00
|
|
|
}
|
|
|
|
|
2017-04-04 09:46:15 -04:00
|
|
|
static void test_sidebar_expand()
|
|
|
|
{
|
|
|
|
GtkTreeModel *model = GTK_TREE_MODEL(gui_sidebar_filter());
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
g_assert_true(gtk_tree_model_get_iter_first(model, &iter));
|
|
|
|
|
|
|
|
g_assert_false( settings_has("gui.sidebar.expand.Collection"));
|
|
|
|
gui_sidebar_filter_row_expanded(&iter, true);
|
|
|
|
g_assert_cmpuint(settings_get("gui.sidebar.expand.Collection"), ==, 1);
|
|
|
|
g_assert_true( settings_has("gui.sidebar.expand.Collection"));
|
|
|
|
gui_sidebar_filter_row_expanded(&iter, false);
|
|
|
|
g_assert_cmpuint(settings_get("gui.sidebar.expand.Collection"), ==, 0);
|
|
|
|
|
|
|
|
gtk_tree_model_iter_next(model, &iter);
|
|
|
|
gtk_tree_model_iter_next(model, &iter);
|
|
|
|
gtk_tree_model_iter_next(model, &iter);
|
|
|
|
|
|
|
|
g_assert_false( settings_has("gui.sidebar.expand.Playlists"));
|
|
|
|
gui_sidebar_filter_row_expanded(&iter, true);
|
|
|
|
g_assert_cmpuint(settings_get("gui.sidebar.expand.Playlists"), ==, 1);
|
|
|
|
g_assert_true( settings_has("gui.sidebar.expand.Playlists"));
|
|
|
|
gui_sidebar_filter_row_expanded(&iter, false);
|
|
|
|
g_assert_cmpuint(settings_get("gui.sidebar.expand.Playlists"), ==, 0);
|
|
|
|
|
|
|
|
gtk_tree_model_iter_next(model, &iter);
|
|
|
|
gtk_tree_model_iter_next(model, &iter);
|
|
|
|
|
|
|
|
g_assert_false( settings_has("gui.sidebar.expand.Dynamic"));
|
|
|
|
gui_sidebar_filter_row_expanded(&iter, true);
|
|
|
|
g_assert_cmpuint(settings_get("gui.sidebar.expand.Dynamic"), ==, 1);
|
|
|
|
g_assert_true( settings_has("gui.sidebar.expand.Dynamic"));
|
|
|
|
gui_sidebar_filter_row_expanded(&iter, false);
|
|
|
|
g_assert_cmpuint(settings_get("gui.sidebar.expand.Dynamic"), ==, 0);
|
|
|
|
|
|
|
|
gtk_tree_model_iter_next(model, &iter);
|
|
|
|
gtk_tree_model_iter_next(model, &iter);
|
|
|
|
|
|
|
|
g_assert_false( settings_has("gui.sidebar.expand.Library"));
|
|
|
|
gui_sidebar_filter_row_expanded(&iter, true);
|
|
|
|
g_assert_cmpuint(settings_get("gui.sidebar.expand.Library"), ==, 1);
|
|
|
|
g_assert_true( settings_has("gui.sidebar.expand.Library"));
|
|
|
|
gui_sidebar_filter_row_expanded(&iter, false);
|
|
|
|
g_assert_cmpuint(settings_get("gui.sidebar.expand.Library"), ==, 0);
|
|
|
|
}
|
|
|
|
|
2016-03-25 08:16:12 -04:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int ret;
|
2015-12-29 09:11:51 -05:00
|
|
|
|
|
|
|
gtk_init(&argc, NULL);
|
2016-08-25 10:05:27 -04:00
|
|
|
core_init(&argc, &argv, &init_data);
|
2016-08-18 14:07:28 -04:00
|
|
|
gui_builder_init("share/ocarina/ocarina.ui");
|
2016-08-26 09:25:17 -04:00
|
|
|
gui_model_init();
|
|
|
|
gui_filter_init();
|
|
|
|
gui_treeview_init();
|
2015-12-29 09:11:51 -05:00
|
|
|
gui_sidebar_init();
|
|
|
|
|
2016-03-25 08:16:12 -04:00
|
|
|
g_test_init(&argc, &argv, NULL);
|
|
|
|
g_test_add_func("/Gui/Sidebar", test_sidebar);
|
2016-08-26 09:25:17 -04:00
|
|
|
g_test_add_func("/Gui/Sidebar/Selection", test_sidebar_selection);
|
2016-08-25 07:44:02 -04:00
|
|
|
g_test_add_func("/Gui/Sidebar/Pos", test_sidebar_pos);
|
2017-04-04 09:46:15 -04:00
|
|
|
g_test_add_func("/Gui/Sidebar/Expand", test_sidebar_expand);
|
2016-03-25 08:16:12 -04:00
|
|
|
ret = g_test_run();
|
2015-12-29 09:11:51 -05:00
|
|
|
|
2016-08-25 10:05:27 -04:00
|
|
|
core_deinit();
|
2016-08-26 09:25:17 -04:00
|
|
|
gui_treeview_deinit();
|
|
|
|
gui_filter_deinit();
|
|
|
|
gui_model_deinit();
|
2015-12-29 09:11:51 -05:00
|
|
|
gui_builder_deinit();
|
2016-03-25 08:16:12 -04:00
|
|
|
return ret;
|
2015-12-29 09:11:51 -05:00
|
|
|
}
|