ocarina/tests/gui/playlist.c

127 lines
3.9 KiB
C

/*
* 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/treeview.h>
#include <gui/sidebar.h>
#include <gui/view.h>
#include <gui/window.h>
#include <tests/test.h>
struct core_init_data init_data = {
.playlist_ops = &playlist_ops,
};
static void test_playlist_sidebar()
{
GtkTreeSelection *selection;
GtkTreeView *treeview;
GtkTreeModel *model;
GtkTreePath *path;
GtkTreeIter iter;
g_assert_true(GTK_IS_TREE_VIEW(gui_sidebar_treeview()));
treeview = gui_sidebar_treeview();
selection = gtk_tree_view_get_selection(treeview);
model = gui_sidebar_model();
playlist_add(PL_SYSTEM, "Queued Tracks", track_get(0));
playlist_add(PL_SYSTEM, "History", track_get(0));
playlist_add(PL_SYSTEM, "Favorites", track_get(0));
playlist_add(PL_SYSTEM, "Hidden", track_get(1));
playlist_new(PL_USER, "Test");
playlist_add(PL_USER, "Test", track_get(0));
gtk_tree_model_filter_refilter(gui_sidebar_filter());
gtk_tree_view_expand_all(treeview);
g_assert_true(gtk_tree_model_get_iter_first(model, &iter));
path = gtk_tree_model_get_path(model, &iter);
gtk_tree_selection_select_path(selection, path);
g_assert_cmpuint(gtk_tree_selection_count_selected_rows(selection), ==, 1);
g_assert_cmpstr(gui_playlist_cur(), ==, "Queued Tracks");
gtk_tree_path_next(path);
gtk_tree_selection_select_path(selection, path);
g_assert_cmpuint(gtk_tree_selection_count_selected_rows(selection), ==, 1);
g_assert_cmpstr(gui_playlist_cur(), ==, "Collection");
gtk_tree_path_next(path);
gtk_tree_selection_select_path(selection, path);
g_assert_cmpuint(gtk_tree_selection_count_selected_rows(selection), ==, 1);
g_assert_cmpstr(gui_playlist_cur(), ==, "History");
gtk_tree_path_next(path);
gtk_tree_selection_unselect_all(selection);
gtk_tree_selection_select_path(selection, path);
g_assert_cmpuint(gtk_tree_selection_count_selected_rows(selection), ==, 0);
gtk_tree_path_next(path);
gtk_tree_selection_select_path(selection, path);
g_assert_cmpuint(gtk_tree_selection_count_selected_rows(selection), ==, 0);
gtk_tree_path_down(path);
gtk_tree_selection_select_path(selection, path);
g_assert_cmpuint(gtk_tree_selection_count_selected_rows(selection), ==, 1);
g_assert_cmpstr(gui_playlist_cur(), ==, "Favorites");
gtk_tree_path_next(path);
gtk_tree_selection_select_path(selection, path);
g_assert_cmpuint(gtk_tree_selection_count_selected_rows(selection), ==, 1);
g_assert_cmpstr(gui_playlist_cur(), ==, "Hidden");
gtk_tree_path_next(path);
gtk_tree_selection_select_path(selection, path);
g_assert_cmpuint(gtk_tree_selection_count_selected_rows(selection), ==, 1);
g_assert_cmpstr(gui_playlist_cur(), ==, "Test");
gtk_tree_path_up(path);
gtk_tree_path_next(path);
gtk_tree_selection_unselect_all(selection);
gtk_tree_selection_select_path(selection, path);
g_assert_cmpuint(gtk_tree_selection_count_selected_rows(selection), ==, 0);
gtk_tree_path_next(path);
gtk_tree_selection_select_path(selection, path);
g_assert_cmpuint(gtk_tree_selection_count_selected_rows(selection), ==, 0);
/* Most played and least played are both filtered out */
gtk_tree_path_down(path);
gtk_tree_selection_select_path(selection, path);
g_assert_cmpuint(gtk_tree_selection_count_selected_rows(selection), ==, 1);
g_assert_cmpstr(gui_playlist_cur(), ==, "Unplayed");
gtk_tree_path_free(path);
}
int main(int argc, char **argv)
{
int ret;
gtk_init(&argc, NULL);
gui_builder_init("share/ocarina/ocarina.ui");
core_init(&argc, NULL, &init_data);
gui_model_init();
gui_filter_init();
gui_treeview_init();
gui_view_init();
gui_playlist_init();
playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony");
while (idle_run_task()) {}
g_test_init(&argc, &argv, NULL);
g_test_add_func("/Gui/Playlist/Sidebar", test_playlist_sidebar);
ret = g_test_run();
core_deinit();
gui_filter_deinit();
gui_builder_deinit();
return ret;
}