107 lines
3.2 KiB
C
107 lines
3.2 KiB
C
/*
|
|
* Copyright 2015 (c) Anna Schumaker.
|
|
*/
|
|
#include <core/core.h>
|
|
#include <core/settings.h>
|
|
#include <gui/sidebar.h>
|
|
#include <tests/test.h>
|
|
|
|
const gchar *test_pl_names[8] = { "Collection",
|
|
"History",
|
|
"", "Playlists",
|
|
"", "Dynamic",
|
|
"", "Library" };
|
|
struct core_init_data init_data;
|
|
|
|
static void test_sidebar()
|
|
{
|
|
GtkTreeIter iter, child;
|
|
unsigned int i;
|
|
|
|
g_assert_nonnull(gui_sidebar_store());
|
|
g_assert_true(GTK_IS_TREE_STORE(gui_sidebar_store()));
|
|
|
|
g_assert_nonnull(gui_sidebar_model());
|
|
g_assert_true(GTK_IS_TREE_MODEL(gui_sidebar_model()));
|
|
|
|
g_assert_nonnull(gui_sidebar_filter());
|
|
g_assert_true(GTK_IS_TREE_MODEL_FILTER(gui_sidebar_filter()));
|
|
|
|
g_assert_nonnull(gui_sidebar_treeview());
|
|
g_assert_true(GTK_IS_TREE_VIEW(gui_sidebar_treeview()));
|
|
|
|
g_assert_true(gui_sidebar_iter_first(&iter));
|
|
gui_sidebar_iter_add(&iter, playlist_get(PL_SYSTEM, "Collection"), NULL);
|
|
gui_sidebar_iter_add(&iter, playlist_get(PL_SYSTEM, "History"), NULL);
|
|
|
|
g_assert_true(gui_sidebar_iter_first(&iter));
|
|
for (i = 0; i < 8; i++) {
|
|
g_assert_cmpstr_free(gui_sidebar_iter_name(&iter), ==,
|
|
test_pl_names[i]);
|
|
g_assert_cmpuint(gui_sidebar_iter_type(&iter), ==,
|
|
(i < 2) ? PL_SYSTEM: PL_MAX_TYPE);
|
|
|
|
if (i < 7)
|
|
g_assert_true(gui_sidebar_iter_next(&iter));
|
|
}
|
|
g_assert_false(gui_sidebar_iter_next(&iter));
|
|
|
|
gui_sidebar_iter_first(&iter);
|
|
g_assert_true(gui_sidebar_iter_find(&iter, "Playlists", PL_MAX_TYPE));
|
|
g_assert_cmpstr_free(gui_sidebar_iter_name(&iter), ==, "Playlists");
|
|
g_assert_cmpuint(gui_sidebar_iter_type(&iter), ==, PL_MAX_TYPE);
|
|
|
|
g_assert_false(gui_sidebar_iter_down(&iter, &child));
|
|
gui_sidebar_iter_append_child(&iter, playlist_get(PL_SYSTEM, "Favorites"),
|
|
NULL);
|
|
gui_sidebar_iter_append_child(&iter, playlist_get(PL_SYSTEM, "Hidden"),
|
|
NULL);
|
|
g_assert_true(gui_sidebar_iter_down(&iter, &child));
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
g_assert_cmpstr_free(gui_sidebar_iter_name(&child), ==,
|
|
(i == 0) ? "Favorites" : "Hidden");
|
|
g_assert_cmpuint(gui_sidebar_iter_type(&child), ==, PL_SYSTEM);
|
|
gui_sidebar_iter_next(&child);
|
|
}
|
|
|
|
g_assert_false(gui_sidebar_iter_find(&iter, "History", PL_SYSTEM));
|
|
gui_sidebar_iter_first(&iter);
|
|
g_assert_true(gui_sidebar_iter_find(&iter, "History", PL_SYSTEM));
|
|
g_assert_cmpstr_free(gui_sidebar_iter_name(&iter), ==, "History");
|
|
g_assert_cmpuint(gui_sidebar_iter_type(&iter), ==, PL_SYSTEM);
|
|
}
|
|
|
|
static void test_sidebar_pos()
|
|
{
|
|
g_assert_false(settings_has("gui.sidebar.pos"));
|
|
|
|
gtk_paned_set_position(gui_sidebar(), 300);
|
|
g_assert_true(settings_has("gui.sidebar.pos"));
|
|
g_assert_cmpuint(settings_get("gui.sidebar.pos"), ==, 300);
|
|
|
|
settings_set("gui.sidebar.pos", 250);
|
|
gui_sidebar_init();
|
|
g_assert_cmpuint(settings_get("gui.sidebar.pos"), ==, 250);
|
|
g_assert_cmpuint(gtk_paned_get_position(gui_sidebar()), ==, 250);
|
|
}
|
|
|
|
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_sidebar_init();
|
|
|
|
g_test_init(&argc, &argv, NULL);
|
|
g_test_add_func("/Gui/Sidebar", test_sidebar);
|
|
g_test_add_func("/Gui/Sidebar/Pos", test_sidebar_pos);
|
|
ret = g_test_run();
|
|
|
|
core_deinit();
|
|
gui_builder_deinit();
|
|
return ret;
|
|
}
|