/* * Copyright 2015 (c) Anna Schumaker. */ #define TEST_NEED_AUDIO #include #include #include #include #include #include #include GMainLoop *main_loop; struct core_init_data init_data; static int test_on_idle(gpointer data) { g_main_loop_quit(main_loop); return G_SOURCE_CONTINUE; } static void test_collection_sidebar() { GtkTreeSelection *selection; GtkProgressBar *progress; GtkFileChooser *chooser; GtkTreeIter iter, child; GtkTreeView *treeview; GtkTreeModel *model; GtkTreePath *path; GtkWindow *window; struct library *library; int argc = 0; gtk_init(&argc, NULL); gui_builder_init("share/ocarina/ocarina6.glade"); core_init(&argc, NULL, &init_data); gui_view_init(); gui_collection_init(); while (idle_run_task()) {} main_loop = g_main_loop_new(NULL, FALSE); window = GTK_WINDOW(gui_builder_widget("o_window")); g_idle_add(test_on_idle, window); progress = GTK_PROGRESS_BAR(gui_builder_widget("o_idle_progress")); chooser = GTK_FILE_CHOOSER(gui_builder_widget("o_collection_chooser")); treeview = GTK_TREE_VIEW(gui_builder_widget("o_collection_view")); selection = gtk_tree_view_get_selection(treeview); model = GTK_TREE_MODEL(gui_builder_object("o_collection_store")); test_equal(gtk_tree_model_get_iter_first(model, &iter), true); path = gtk_tree_model_get_path(model, &iter); gtk_tree_view_set_cursor(treeview, path, NULL, false); gtk_tree_path_free(path); test_equal(gtk_tree_selection_count_selected_rows(selection), 0); gtk_tree_model_iter_nth_child(model, &child, &iter, 0); path = gtk_tree_model_get_path(model, &child); gtk_tree_view_set_cursor(treeview, path, NULL, false); gtk_tree_path_free(path); test_equal(gtk_tree_selection_count_selected_rows(selection), 1); gtk_file_chooser_set_filename(chooser, "tests/Music/Hyrule Symphony"); g_main_loop_run(main_loop); gtk_button_clicked(GTK_BUTTON(gui_builder_widget("o_collection_add"))); gtk_tree_model_get_iter_first(model, &iter); test_equal(gtk_tree_model_iter_n_children(model, &iter), 2); gtk_tree_model_iter_nth_child(model, &child, &iter, 0); gtk_tree_model_get(model, &child, 2, &library, -1); test_equal((void *)library, (void *)library_get(0)); /* Run two idle events to scan the added path. */ test_equal(gtk_widget_is_visible(GTK_WIDGET(progress)), true); g_main_loop_run(main_loop); test_equal((float)gtk_progress_bar_get_fraction(progress), (float)0.5); while (idle_run_task()) {} g_main_loop_run(main_loop); test_equal(gtk_widget_is_visible(GTK_WIDGET(progress)), false); gtk_tree_store_clear(GTK_TREE_STORE(model)); gui_collection_init(); while (idle_run_task()) {} gtk_tree_model_get_iter_first(model, &iter); test_equal(gtk_tree_model_iter_n_children(model, &iter), 2); gtk_tree_model_iter_nth_child(model, &child, &iter, 0); gtk_tree_model_get(model, &child, 2, &library, -1); test_equal((void *)library, (void *)library_get(0)); path = gtk_tree_model_get_path(model, &child); gtk_tree_view_row_activated(treeview, path, NULL); gtk_tree_path_free(path); /* Again, run two idle events to update the selected path. */ test_equal(gtk_widget_is_visible(GTK_WIDGET(progress)), true); g_main_loop_run(main_loop); test_equal((float)gtk_progress_bar_get_fraction(progress), (float)0.5); g_main_loop_run(main_loop); test_equal(gtk_widget_is_visible(GTK_WIDGET(progress)), false); gui_builder_deinit(); } DECLARE_UNIT_TESTS( UNIT_TEST("Collection Sidebar", test_collection_sidebar), );