ocarina/tests/gui/playlist.c

96 lines
3.0 KiB
C

/*
* Copyright 2016 (c) Anna Schumaker.
*/
#include <core/core.h>
#include <core/idle.h>
#include <gui/builder.h>
#include <gui/model.h>
#include <gui/playlist.h>
#include <gui/view.h>
#include <tests/test.h>
struct core_init_data init_data;
static void test_playlist_sidebar()
{
GtkTreeSelection *selection;
GtkTreeView *treeview;
GtkTreeModel *model;
GtkTreePath *path;
GtkTreeIter iter;
g_assert_true(GTK_IS_TREE_VIEW(GTK_TREE_VIEW(gui_builder_widget("o_playlist_view"))));
treeview = GTK_TREE_VIEW(gui_builder_widget("o_playlist_view"));
selection = gtk_tree_view_get_selection(treeview);
model = GTK_TREE_MODEL(gui_builder_object("o_playlist_store"));
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(), ==, "Collection");
gtk_tree_path_next(path);
gtk_tree_selection_select_path(selection, path);
g_assert_cmpuint(gtk_tree_selection_count_selected_rows(selection), ==, 1);
gtk_tree_selection_unselect_all(selection);
g_assert_cmpstr(gui_playlist_cur(), ==, "History");
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_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(), ==, "Most Played");
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(), ==, "Least Played");
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(), ==, "Unplayed");
gtk_tree_path_free(path);
}
int main(int argc, char **argv)
{
int ret;
gtk_init(&argc, NULL);
gui_builder_init("share/ocarina/ocarina6.glade");
gui_queue_model_init();
gui_view_init();
core_init(&argc, NULL, &init_data);
gui_playlist_init();
while (idle_run_task()) {}
g_test_init(&argc, &argv, NULL);
g_test_add_func("/Gui/Playlist/Sidebar", test_playlist_sidebar);
ret = g_test_run();
gui_builder_deinit();
core_deinit();
return ret;
}