126 lines
3.7 KiB
C
126 lines
3.7 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/playlist.h>
|
|
#include <gui/sidebar.h>
|
|
#include <gui/treeview.h>
|
|
#include <tests/test.h>
|
|
|
|
static void test_audio_load(struct track *track)
|
|
{ gui_pl_system_track_loaded(track); }
|
|
static void test_change_state(GstState state) { }
|
|
static void test_config_pause(int n) { }
|
|
|
|
static struct audio_ops test_audio_ops = {
|
|
.on_load = test_audio_load,
|
|
.on_state_change = test_change_state,
|
|
.on_config_pause = test_config_pause,
|
|
};
|
|
|
|
struct core_init_data init_data = {
|
|
.playlist_cb = &playlist_cb,
|
|
.audio_ops = &test_audio_ops,
|
|
};
|
|
|
|
static const gchar *toplevel[3] = { "Queued Tracks", "Collection", "History" };
|
|
static const gchar *playlists[2] = {"Favorites", "Hidden" };
|
|
static const gchar *dynamic[3] = {"Most Played", "Least Played", "Unplayed" };
|
|
|
|
static void test_system()
|
|
{
|
|
GtkTreeIter iter, child;
|
|
unsigned int i;
|
|
|
|
gui_sidebar_iter_first(&iter);
|
|
for (i = 0; i < 3; i++) {
|
|
g_assert_cmpstr_free(gui_sidebar_iter_name(&iter), ==,
|
|
toplevel[i]);
|
|
g_assert_cmpuint(gui_sidebar_iter_type(&iter), ==, PL_SYSTEM);
|
|
gui_sidebar_iter_next(&iter);
|
|
}
|
|
|
|
gui_sidebar_iter_find(&iter, "Playlists", PL_MAX_TYPE);
|
|
gui_sidebar_iter_down(&iter, &child);
|
|
for (i = 0; i < 2; i++) {
|
|
g_assert_cmpstr_free(gui_sidebar_iter_name(&child), ==,
|
|
playlists[i]);
|
|
g_assert_cmpuint(gui_sidebar_iter_type(&child), ==, PL_SYSTEM);
|
|
gui_sidebar_iter_next(&child);
|
|
}
|
|
|
|
gui_sidebar_iter_find(&iter, "Dynamic", PL_MAX_TYPE);
|
|
gui_sidebar_iter_down(&iter, &child);
|
|
for (i = 0; i < 2; i++) {
|
|
g_assert_cmpstr_free(gui_sidebar_iter_name(&child), ==,
|
|
dynamic[i]);
|
|
g_assert_cmpuint(gui_sidebar_iter_type(&child), ==, PL_SYSTEM);
|
|
gui_sidebar_iter_next(&child);
|
|
}
|
|
}
|
|
|
|
static void test_buttons()
|
|
{
|
|
struct playlist *favorites = playlist_lookup(PL_SYSTEM, "Favorites");
|
|
struct playlist *hidden = playlist_lookup(PL_SYSTEM, "Hidden");
|
|
|
|
g_assert_nonnull(gui_pl_library_add("tests/Music/Hyrule Symphony"));
|
|
while (idle_run_task()) {}
|
|
|
|
g_assert_false(gtk_toggle_button_get_active(gui_favorite_button()));
|
|
g_assert_false(gtk_toggle_button_get_active(gui_hide_button()));
|
|
|
|
playlist_add(favorites, track_get(0));
|
|
audio_load(track_get(0));
|
|
g_assert_true( gtk_toggle_button_get_active(gui_favorite_button()));
|
|
g_assert_false(gtk_toggle_button_get_active(gui_hide_button()));
|
|
|
|
gtk_toggle_button_set_active(gui_favorite_button(), false);
|
|
g_assert_false(playlist_has(favorites, track_get(0)));
|
|
gtk_toggle_button_set_active(gui_favorite_button(), true);
|
|
g_assert_true(playlist_has(favorites, track_get(0)));
|
|
|
|
playlist_add(hidden, track_get(1));
|
|
audio_load(track_get(1));
|
|
g_assert_false(gtk_toggle_button_get_active(gui_favorite_button()));
|
|
g_assert_true(gtk_toggle_button_get_active(gui_hide_button()));
|
|
|
|
gtk_toggle_button_set_active(gui_hide_button(), false);
|
|
g_assert_false(playlist_has(hidden, track_get(1)));
|
|
g_assert(audio_cur_track() == track_get(1));
|
|
gtk_toggle_button_set_active(gui_hide_button(), true);
|
|
g_assert_true(playlist_has(hidden, track_get(1)));
|
|
g_assert(audio_cur_track() != track_get(1));
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
int ret;
|
|
|
|
gtk_init(&argc, NULL);
|
|
core_init(&argc, &argv, &init_data);
|
|
gui_builder_init("share/ocarina/ocarina.ui");
|
|
gui_model_init();
|
|
gui_filter_init();
|
|
gui_treeview_init();
|
|
gui_sidebar_init();
|
|
gui_playlist_init();
|
|
while (idle_run_task()) {}
|
|
|
|
g_test_init(&argc, &argv, NULL);
|
|
g_test_add_func("/Gui/Playlists/System", test_system);
|
|
g_test_add_func("/Gui/Playlists/System/Buttons", test_buttons);
|
|
ret = g_test_run();
|
|
|
|
core_deinit();
|
|
gui_treeview_deinit();
|
|
gui_filter_deinit();
|
|
gui_model_deinit();
|
|
gui_builder_deinit();
|
|
return ret;
|
|
}
|