ocarina/tests/gui/filter.c

99 lines
2.8 KiB
C

/*
* Copyright 2016 (c) Anna Schumaker.
*/
#include <core/audio.h>
#include <core/core.h>
#include <core/idle.h>
#include <gui/filter.h>
#include <gui/model.h>
#include <gui/window.h>
static struct core_init_data init_data;
void test_filter()
{
struct track *track;
GtkEntry *entry;
GtkTreeModel *model;
GtkTreePath *path;
GtkTreeIter iter;
unsigned int i;
g_assert_nonnull(gui_filter_get());
g_assert_true(GTK_IS_TREE_MODEL_FILTER(gui_filter_get()));
g_assert(gtk_tree_model_filter_get_model(gui_filter_get()) ==
GTK_TREE_MODEL(gui_model_get()));
entry = GTK_ENTRY(gui_filter_search());
model = GTK_TREE_MODEL(gui_filter_get());
g_assert_false(gtk_tree_model_get_iter_first(model, &iter));
gui_filter_set_playlist(playlist_lookup(PL_SYSTEM, "Collection"));
g_assert_false(gtk_tree_model_get_iter_first(model, &iter));
playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony");
while (idle_run_task()) {};
g_assert_cmpuint(gtk_tree_model_iter_n_children(model, NULL), ==, 13);
for (i = 0; i < 13; i++) {
path = gui_filter_path_from_index(i);
g_assert_nonnull(path);
g_assert_cmpuint(gui_filter_path_get_index(path), ==, i);
track = gui_filter_path_get_track(path);
g_assert_nonnull(track);
g_assert_cmpuint(track->tr_track, ==, i + 1);
gui_filter_path_load_track(path);
g_assert(audio_cur_track() == track);
gtk_tree_path_free(path);
}
path = gui_filter_path_from_index(i);
g_assert_null(path);
path = gui_filter_path_from_index(12);
gtk_tree_path_next(path);
g_assert_null(gui_filter_path_get_track(path));
gtk_tree_path_free(path);
gtk_entry_set_text(entry, "Hyrule");
g_assert_cmpuint(gtk_tree_model_iter_n_children(model, NULL), ==, 13);
gtk_combo_box_set_active(gui_filter_how(), GUI_FILTER_TITLE);
g_assert_cmpuint(gtk_tree_model_iter_n_children(model, NULL), ==, 2);
gui_filter_set_playlist(playlist_lookup(PL_SYSTEM, "Unplayed"));
g_assert_cmpuint(gtk_tree_model_iter_n_children(model, NULL), ==, 13);
g_assert_cmpstr(gtk_entry_get_text(entry), ==, "");
gui_filter_set_playlist(playlist_lookup(PL_SYSTEM, "Collection"));
g_assert_cmpuint(gtk_tree_model_iter_n_children(model, NULL), ==, 2);
g_assert_cmpstr(gtk_entry_get_text(entry), ==, "hyrule");
gtk_combo_box_set_active(gui_filter_how(), GUI_FILTER_DEFAULT);
g_assert_cmpuint(gtk_tree_model_iter_n_children(model, NULL), ==, 13);
}
int main(int argc, char **argv)
{
int ret;
gtk_init(&argc, NULL);
core_init(&argc, NULL, &init_data);
gui_builder_init("share/ocarina/ocarina.ui");
gui_window_init("share/ocarina/ocarina.png");
gui_model_init();
gui_filter_init();
g_test_init(&argc, &argv, NULL);
g_test_add_func("/Gui/Filter", test_filter);
ret = g_test_run();
gui_filter_deinit();
gui_model_deinit();
gui_window_deinit();
gui_builder_deinit();
core_deinit();
return ret;
}