243 lines
6.9 KiB
C
243 lines
6.9 KiB
C
/*
|
|
* Copyright 2016 (c) Anna Schumaker.
|
|
*/
|
|
#include <core/core.h>
|
|
#include <gui/filter.h>
|
|
#include <gui/model.h>
|
|
#include <gui/treeview.h>
|
|
#include <tests/test.h>
|
|
#include <tests/loop.h>
|
|
|
|
const gchar *GUI_COL_SETTINGS[GUI_MODEL_N_COLUMNS] = {
|
|
[GUI_MODEL_TRACK_NR] = "gui.queue.track",
|
|
[GUI_MODEL_TITLE] = "gui.queue.title",
|
|
[GUI_MODEL_LENGTH] = "gui.queue.length",
|
|
[GUI_MODEL_ARTIST] = "gui.queue.artist",
|
|
[GUI_MODEL_ALBUM] = "gui.queue.album",
|
|
[GUI_MODEL_YEAR] = "gui.queue.year",
|
|
[GUI_MODEL_GENRE] = "gui.queue.genre",
|
|
[GUI_MODEL_COUNT] = "gui.queue.count",
|
|
[GUI_MODEL_LAST_PLAY] = "gui.queue.played",
|
|
[GUI_MODEL_FILE_PATH] = "gui.queue.filepath",
|
|
[GUI_MODEL_FONT] = "gui.queue.font",
|
|
};
|
|
|
|
void test_treeview_init()
|
|
{
|
|
GtkTreePath *path;
|
|
|
|
g_assert_nonnull(gui_treeview());
|
|
g_assert_true(GTK_IS_TREE_VIEW(gui_treeview()));
|
|
g_assert(gtk_tree_view_get_model(gui_treeview()) ==
|
|
GTK_TREE_MODEL(gui_filter_get()));
|
|
|
|
/* No scrolling without a playlist. */
|
|
gui_treeview_scroll();
|
|
gtk_tree_view_get_cursor(gui_treeview(), &path, NULL);
|
|
g_assert_null(path);
|
|
|
|
gui_treeview_set_playlist(playlist_lookup(PL_SYSTEM, "Collection"));
|
|
g_assert(gui_model_get_playlist() ==
|
|
playlist_lookup(PL_SYSTEM, "Collection"));
|
|
|
|
/* No scrolling when playlist index is -1. */
|
|
gui_treeview_scroll();
|
|
gtk_tree_view_get_cursor(gui_treeview(), &path, NULL);
|
|
g_assert_null(path);
|
|
|
|
/* Okay, NOW we can scroll! */
|
|
playlist_current_set(playlist_lookup(PL_SYSTEM, "Collection"), 4);
|
|
gui_treeview_scroll();
|
|
gtk_tree_view_get_cursor(gui_treeview(), &path, NULL);
|
|
g_assert_nonnull(path);
|
|
g_assert_cmpuint(gui_filter_path_get_track(path)->tr_track, ==, 5);
|
|
|
|
gtk_tree_view_row_activated(gui_treeview(), path, NULL);
|
|
g_assert_cmpuint(audio_cur_track()->tr_track, ==, 5);
|
|
gtk_tree_path_free(path);
|
|
}
|
|
|
|
void test_treeview_select()
|
|
{
|
|
GtkTreeSelection *selection;
|
|
struct track *track;
|
|
GtkTreePath *path;
|
|
GList *list;
|
|
unsigned int i;
|
|
|
|
selection = gtk_tree_view_get_selection(gui_treeview());
|
|
|
|
gui_treeview_set_playlist(playlist_lookup(PL_SYSTEM, "Collection"));
|
|
g_assert(gui_model_get_playlist() ==
|
|
playlist_lookup(PL_SYSTEM, "Collection"));
|
|
|
|
g_assert_cmpuint(audio_cur_track()->tr_track, !=, 2);
|
|
path = gui_filter_path_from_index(1);
|
|
g_assert_nonnull(path);
|
|
gtk_tree_view_row_activated(gui_treeview(), path, NULL);
|
|
g_assert_cmpuint(audio_cur_track()->tr_track, ==, 2);
|
|
gtk_tree_path_free(path);
|
|
|
|
gtk_tree_selection_unselect_all(selection);
|
|
g_assert_null(gui_treeview_list_selected_tracks());
|
|
|
|
gtk_tree_selection_select_all(selection);
|
|
list = gui_treeview_list_selected_tracks();
|
|
g_assert_cmpuint(g_list_length(list), ==, 13);
|
|
for (i = 0; i < 13; i++) {
|
|
track = (struct track *)g_list_nth_data(list, i);
|
|
g_assert_nonnull(track);
|
|
g_assert_cmpuint(track->tr_track, ==, i + 1);
|
|
}
|
|
g_list_free(list);
|
|
g_assert_cmpuint(gtk_tree_selection_count_selected_rows(selection), ==, 0);
|
|
}
|
|
|
|
void test_treeview_sort()
|
|
{
|
|
GtkTreeViewColumn *col;
|
|
unsigned int i, sort;
|
|
|
|
/* Switch to collection playlist and check sort arrows. */
|
|
gui_treeview_set_playlist(playlist_lookup(PL_SYSTEM, "Collection"));
|
|
g_assert(gui_model_get_playlist() ==
|
|
playlist_lookup(PL_SYSTEM, "Collection"));
|
|
|
|
for (i = 0; i < GUI_MODEL_N_COLUMNS; i++) {
|
|
col = gtk_tree_view_get_column(gui_treeview(), i);
|
|
switch (i) {
|
|
case GUI_MODEL_FILE_PATH:
|
|
case GUI_MODEL_FONT:
|
|
g_assert_null(col);
|
|
break;
|
|
case GUI_MODEL_ARTIST:
|
|
case GUI_MODEL_YEAR:
|
|
case GUI_MODEL_TRACK_NR:
|
|
g_assert_true(
|
|
gtk_tree_view_column_get_sort_indicator(col));
|
|
g_assert_cmpuint(
|
|
gtk_tree_view_column_get_sort_order(col), ==,
|
|
GTK_SORT_ASCENDING);
|
|
break;
|
|
default:
|
|
g_assert_false(
|
|
gtk_tree_view_column_get_sort_indicator(col));
|
|
}
|
|
}
|
|
|
|
/* Click some columns and check that indicators change. */
|
|
col = gtk_tree_view_get_column(gui_treeview(), GUI_MODEL_YEAR);
|
|
gtk_tree_view_column_clicked(col);
|
|
g_assert_cmpstr(gtk_label_get_text(gui_sorting()), ==,
|
|
"Sorting: {Year}");
|
|
|
|
col = gtk_tree_view_get_column(gui_treeview(), GUI_MODEL_LENGTH);
|
|
gtk_tree_view_column_clicked(col);
|
|
g_assert_cmpstr(gtk_label_get_text(gui_sorting()), ==,
|
|
"Sorting: {Year, Length}");
|
|
|
|
col = gtk_tree_view_get_column(gui_treeview(), GUI_MODEL_TRACK_NR);
|
|
gtk_tree_view_column_clicked(col);
|
|
g_assert_cmpstr(gtk_label_get_text(gui_sorting()), ==,
|
|
"Sorting: {Year, Length, #}");
|
|
|
|
col = gtk_tree_view_get_column(gui_treeview(), GUI_MODEL_LENGTH);
|
|
gtk_tree_view_column_clicked(col);
|
|
g_assert_cmpstr(gtk_label_get_text(gui_sorting()), ==,
|
|
"Sorting: {Year, -Length, #}");
|
|
|
|
for (i = 0; i < GUI_MODEL_N_COLUMNS; i++) {
|
|
sort = GTK_SORT_ASCENDING;
|
|
col = gtk_tree_view_get_column(gui_treeview(), i);
|
|
switch (i) {
|
|
case GUI_MODEL_FILE_PATH:
|
|
case GUI_MODEL_FONT:
|
|
g_assert_null(col);
|
|
break;
|
|
case GUI_MODEL_LENGTH:
|
|
sort = GTK_SORT_DESCENDING;
|
|
case GUI_MODEL_YEAR:
|
|
case GUI_MODEL_TRACK_NR:
|
|
g_assert_true(
|
|
gtk_tree_view_column_get_sort_indicator(col));
|
|
g_assert_cmpuint(
|
|
gtk_tree_view_column_get_sort_order(col), ==,
|
|
sort);
|
|
break;
|
|
default:
|
|
g_assert_false(
|
|
gtk_tree_view_column_get_sort_indicator(col));
|
|
}
|
|
}
|
|
|
|
/* History playlist should not have any sort arrows. */
|
|
gui_treeview_set_playlist(playlist_lookup(PL_SYSTEM, "History"));
|
|
g_assert(gui_model_get_playlist() ==
|
|
playlist_lookup(PL_SYSTEM, "History"));
|
|
g_assert_cmpstr(gtk_label_get_text(gui_sorting()), ==, "");
|
|
|
|
for (i = 0; i < GUI_MODEL_N_COLUMNS; i++) {
|
|
col = gtk_tree_view_get_column(gui_treeview(), i);
|
|
if (!col)
|
|
break;
|
|
g_assert_false(gtk_tree_view_column_get_sort_indicator(col));
|
|
}
|
|
}
|
|
|
|
void test_treeview_columns()
|
|
{
|
|
GtkTreeViewColumn *col;
|
|
unsigned int i;
|
|
const gchar *setting;
|
|
|
|
for (i = 0; i < GUI_MODEL_N_COLUMNS; i++) {
|
|
col = gtk_tree_view_get_column(gui_treeview(), i);
|
|
if (!col)
|
|
continue;
|
|
|
|
g_assert_false(settings_has(GUI_COL_SETTINGS[i]));
|
|
gtk_tree_view_column_set_fixed_width(col, (i + 2) * 10);
|
|
}
|
|
|
|
test_main_loop();
|
|
for (i = 0; i < GUI_MODEL_N_COLUMNS; i++) {
|
|
col = gtk_tree_view_get_column(gui_treeview(), i);
|
|
if (!col || (i == GUI_MODEL_LAST_PLAY))
|
|
continue;
|
|
|
|
setting = GUI_COL_SETTINGS[i];
|
|
g_assert_true(setting);
|
|
g_assert_cmpuint(settings_get(setting), ==, (i + 2) * 10);
|
|
}
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
int ret;
|
|
|
|
gtk_init(&argc, NULL);
|
|
core_init(&argc, NULL, NULL, NULL, IDLE_SYNC);
|
|
gui_builder_init("share/ocarina/ocarina.ui");
|
|
gui_model_init();
|
|
gui_filter_init();
|
|
gui_treeview_init();
|
|
test_loop_init();
|
|
|
|
playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony");
|
|
while (idle_run_task()) {}
|
|
|
|
g_test_init(&argc, &argv, NULL);
|
|
g_test_add_func("/Gui/Treeview/Init", test_treeview_init);
|
|
g_test_add_func("/Gui/Treeview/Select", test_treeview_select);
|
|
g_test_add_func("/Gui/Treeview/Sort", test_treeview_sort);
|
|
g_test_add_func("/Gui/Treeview/Columns", test_treeview_columns);
|
|
ret = g_test_run();
|
|
|
|
core_deinit();
|
|
test_loop_deinit();
|
|
gui_treeview_deinit();
|
|
gui_filter_deinit();
|
|
gui_model_deinit();
|
|
return ret;
|
|
}
|