gui/playlist: Clean up file and rewrite unit test
The unit test now checks how we respond to the row-activated signal. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
e7d2fa5c4d
commit
39bc7492d4
|
@ -27,29 +27,7 @@ static inline void __gui_playlist_update_size(struct playlist *playlist)
|
|||
update_size[playlist->pl_type](playlist);
|
||||
}
|
||||
|
||||
void __playlist_row_activated(GtkTreeView *treeview, GtkTreePath *path,
|
||||
GtkTreeViewColumn *col, gpointer data)
|
||||
{
|
||||
struct playlist *prev = playlist_cur();
|
||||
|
||||
gui_sidebar_filter_path_select(path);
|
||||
__gui_playlist_update_size(prev);
|
||||
__gui_playlist_update_size(playlist_cur());
|
||||
}
|
||||
|
||||
void __playlist_row_collapsed(GtkTreeView *treeview, GtkTreeIter *iter,
|
||||
GtkTreePath *path, gpointer data)
|
||||
{
|
||||
gui_sidebar_filter_row_expanded(iter, false);
|
||||
}
|
||||
|
||||
void __playlist_row_expanded(GtkTreeView *treeview, GtkTreeIter *iter,
|
||||
GtkTreePath *path, gpointer data)
|
||||
{
|
||||
gui_sidebar_filter_row_expanded(iter, true);
|
||||
}
|
||||
|
||||
static void *__playlist_init(struct queue *queue, void *data)
|
||||
static void *__gui_playlist_init(struct queue *queue, void *data)
|
||||
{
|
||||
struct playlist *playlist = (struct playlist *)data;
|
||||
|
||||
|
@ -58,35 +36,35 @@ static void *__playlist_init(struct queue *queue, void *data)
|
|||
return playlist;
|
||||
}
|
||||
|
||||
static void __playlist_deinit(struct queue *queue)
|
||||
static void __gui_playlist_deinit(struct queue *queue)
|
||||
{
|
||||
gui_filter_clear_search(queue->q_private);
|
||||
}
|
||||
|
||||
static void __playlist_added(struct queue *queue, unsigned int row)
|
||||
static void __gui_playlist_added(struct queue *queue, unsigned int row)
|
||||
{
|
||||
gui_model_add(queue->q_private, row);
|
||||
__gui_playlist_update_size(queue->q_private);
|
||||
}
|
||||
|
||||
static void __playlist_removed(struct queue *queue, unsigned int row)
|
||||
static void __gui_playlist_removed(struct queue *queue, unsigned int row)
|
||||
{
|
||||
gui_model_remove(queue->q_private, row);
|
||||
__gui_playlist_update_size(queue->q_private);
|
||||
}
|
||||
|
||||
static void __playlist_cleared(struct queue *queue, unsigned int n)
|
||||
static void __gui_playlist_cleared(struct queue *queue, unsigned int n)
|
||||
{
|
||||
gui_model_clear(queue->q_private, n);
|
||||
__gui_playlist_update_size(queue->q_private);
|
||||
}
|
||||
|
||||
static void __playlist_updated(struct queue *queue, unsigned int n)
|
||||
static void __gui_playlist_updated(struct queue *queue, unsigned int n)
|
||||
{
|
||||
gui_model_update(queue->q_private, n);
|
||||
}
|
||||
|
||||
static bool __playlist_erase(struct queue *queue, struct track *track)
|
||||
static bool __gui_playlist_erase(struct queue *queue, struct track *track)
|
||||
{
|
||||
struct playlist *playlist = queue->q_private;
|
||||
enum playlist_type_t type = playlist->pl_type;
|
||||
|
@ -109,6 +87,40 @@ static bool __playlist_erase(struct queue *queue, struct track *track)
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
struct queue_ops playlist_ops = {
|
||||
.qop_init = __gui_playlist_init,
|
||||
.qop_deinit = __gui_playlist_deinit,
|
||||
.qop_added = __gui_playlist_added,
|
||||
.qop_erase = __gui_playlist_erase,
|
||||
.qop_removed = __gui_playlist_removed,
|
||||
.qop_cleared = __gui_playlist_cleared,
|
||||
.qop_updated = __gui_playlist_updated,
|
||||
};
|
||||
|
||||
|
||||
void __gui_playlist_row_activated(GtkTreeView *treeview, GtkTreePath *path,
|
||||
GtkTreeViewColumn *col, gpointer data)
|
||||
{
|
||||
struct playlist *prev = playlist_cur();
|
||||
|
||||
gui_sidebar_filter_path_select(path);
|
||||
__gui_playlist_update_size(prev);
|
||||
__gui_playlist_update_size(playlist_cur());
|
||||
}
|
||||
|
||||
void __gui_playlist_row_collapsed(GtkTreeView *treeview, GtkTreeIter *iter,
|
||||
GtkTreePath *path, gpointer data)
|
||||
{
|
||||
gui_sidebar_filter_row_expanded(iter, false);
|
||||
}
|
||||
|
||||
void __gui_playlist_row_expanded(GtkTreeView *treeview, GtkTreeIter *iter,
|
||||
GtkTreePath *path, gpointer data)
|
||||
{
|
||||
gui_sidebar_filter_row_expanded(iter, true);
|
||||
}
|
||||
|
||||
bool __gui_playlist_init_idle()
|
||||
{
|
||||
struct playlist *playlist = playlist_cur();
|
||||
|
@ -133,20 +145,3 @@ void gui_playlist_init()
|
|||
|
||||
idle_schedule(IDLE_SYNC, __gui_playlist_init_idle, NULL);
|
||||
}
|
||||
|
||||
const gchar *gui_playlist_cur()
|
||||
{
|
||||
if (gui_model_get_playlist())
|
||||
return gui_model_get_playlist()->pl_name;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct queue_ops playlist_ops = {
|
||||
.qop_init = __playlist_init,
|
||||
.qop_deinit = __playlist_deinit,
|
||||
.qop_added = __playlist_added,
|
||||
.qop_erase = __playlist_erase,
|
||||
.qop_removed = __playlist_removed,
|
||||
.qop_cleared = __playlist_cleared,
|
||||
.qop_updated = __playlist_updated,
|
||||
};
|
||||
|
|
|
@ -12,9 +12,6 @@
|
|||
/* Called to initialize the GUI playlist code. */
|
||||
void gui_playlist_init();
|
||||
|
||||
/* Called to get the currently selected playlist. */
|
||||
const gchar *gui_playlist_cur();
|
||||
|
||||
/* Playlist operations passed to core_init() */
|
||||
extern struct queue_ops playlist_ops;
|
||||
|
||||
|
|
|
@ -748,9 +748,9 @@ audio-volume-medium</property>
|
|||
<property name="search_column">1</property>
|
||||
<property name="enable_tree_lines">True</property>
|
||||
<signal name="key-press-event" handler="__gui_sidebar_keypress" swapped="no"/>
|
||||
<signal name="row-activated" handler="__playlist_row_activated" swapped="no"/>
|
||||
<signal name="row-collapsed" handler="__playlist_row_collapsed" swapped="no"/>
|
||||
<signal name="row-expanded" handler="__playlist_row_expanded" swapped="no"/>
|
||||
<signal name="row-activated" handler="__gui_playlist_row_activated" swapped="no"/>
|
||||
<signal name="row-collapsed" handler="__gui_playlist_row_collapsed" swapped="no"/>
|
||||
<signal name="row-expanded" handler="__gui_playlist_row_expanded" swapped="no"/>
|
||||
<child internal-child="selection">
|
||||
<object class="GtkTreeSelection" id="treeview-selection3">
|
||||
<signal name="changed" handler="__gui_sidebar_selection_changed" swapped="no"/>
|
||||
|
|
|
@ -3,104 +3,56 @@
|
|||
*/
|
||||
#include <core/core.h>
|
||||
#include <core/idle.h>
|
||||
#include <gui/builder.h>
|
||||
#include <core/settings.h>
|
||||
#include <gui/filter.h>
|
||||
#include <gui/model.h>
|
||||
#include <gui/playlist.h>
|
||||
#include <gui/sidebar.h>
|
||||
#include <gui/treeview.h>
|
||||
#include <gui/view.h>
|
||||
#include <gui/window.h>
|
||||
#include <tests/test.h>
|
||||
|
||||
struct core_init_data init_data = {
|
||||
.playlist_ops = &playlist_ops,
|
||||
};
|
||||
|
||||
static void test_playlist_sidebar()
|
||||
static void test_playlist()
|
||||
{
|
||||
GtkTreeSelection *selection;
|
||||
GtkTreeView *treeview;
|
||||
GtkTreeModel *model;
|
||||
GtkTreeIter iter, child;
|
||||
GtkTreePath *path;
|
||||
GtkTreeIter iter;
|
||||
|
||||
g_assert_true(GTK_IS_TREE_VIEW(gui_sidebar_treeview()));
|
||||
|
||||
treeview = gui_sidebar_treeview();
|
||||
selection = gtk_tree_view_get_selection(treeview);
|
||||
model = gui_sidebar_model();
|
||||
|
||||
playlist_add(PL_SYSTEM, "Queued Tracks", track_get(0));
|
||||
playlist_add(PL_SYSTEM, "History", track_get(0));
|
||||
gui_pl_library_add("tests/Music/Hyrule Symphony");
|
||||
while (idle_run_task()) {}
|
||||
playlist_add(PL_SYSTEM, "Favorites", track_get(0));
|
||||
playlist_add(PL_SYSTEM, "Hidden", track_get(1));
|
||||
|
||||
gui_pl_user_add("Test");
|
||||
playlist_add(PL_USER, "Test", track_get(0));
|
||||
gtk_tree_model_filter_refilter(gui_sidebar_filter());
|
||||
gtk_tree_view_expand_all(treeview);
|
||||
|
||||
g_assert_true(gtk_tree_model_get_iter_first(model, &iter));
|
||||
path = gtk_tree_model_get_path(model, &iter);
|
||||
gtk_tree_selection_select_path(selection, path);
|
||||
g_assert_cmpuint(gtk_tree_selection_count_selected_rows(selection), ==, 1);
|
||||
g_assert_cmpstr(gui_playlist_cur(), ==, "Queued Tracks");
|
||||
g_assert_true(gui_sidebar_iter_first(&iter));
|
||||
path = gtk_tree_model_get_path(gui_sidebar_model(), &iter);
|
||||
gtk_tree_view_row_activated(gui_sidebar_treeview(), path, NULL);
|
||||
g_assert_true(playlist_cur() == playlist_get(PL_SYSTEM, "Collection"));
|
||||
gtk_tree_path_free(path);
|
||||
|
||||
gtk_tree_path_next(path);
|
||||
gtk_tree_selection_select_path(selection, path);
|
||||
g_assert_cmpuint(gtk_tree_selection_count_selected_rows(selection), ==, 1);
|
||||
g_assert_cmpstr(gui_playlist_cur(), ==, "Collection");
|
||||
|
||||
gtk_tree_path_next(path);
|
||||
gtk_tree_selection_select_path(selection, path);
|
||||
g_assert_cmpuint(gtk_tree_selection_count_selected_rows(selection), ==, 1);
|
||||
g_assert_cmpstr(gui_playlist_cur(), ==, "History");
|
||||
|
||||
gtk_tree_path_next(path);
|
||||
gtk_tree_selection_unselect_all(selection);
|
||||
gtk_tree_selection_select_path(selection, path);
|
||||
g_assert_cmpuint(gtk_tree_selection_count_selected_rows(selection), ==, 0);
|
||||
g_assert_null(gui_playlist_cur());
|
||||
|
||||
gtk_tree_path_next(path);
|
||||
gtk_tree_selection_select_path(selection, path);
|
||||
g_assert_cmpuint(gtk_tree_selection_count_selected_rows(selection), ==, 0);
|
||||
g_assert_null(gui_playlist_cur());
|
||||
|
||||
gtk_tree_path_down(path);
|
||||
gtk_tree_selection_select_path(selection, path);
|
||||
g_assert_cmpuint(gtk_tree_selection_count_selected_rows(selection), ==, 1);
|
||||
g_assert_cmpstr(gui_playlist_cur(), ==, "Favorites");
|
||||
|
||||
gtk_tree_path_next(path);
|
||||
gtk_tree_selection_select_path(selection, path);
|
||||
g_assert_cmpuint(gtk_tree_selection_count_selected_rows(selection), ==, 1);
|
||||
g_assert_cmpstr(gui_playlist_cur(), ==, "Hidden");
|
||||
|
||||
gtk_tree_path_next(path);
|
||||
gtk_tree_selection_select_path(selection, path);
|
||||
g_assert_cmpuint(gtk_tree_selection_count_selected_rows(selection), ==, 1);
|
||||
g_assert_cmpstr(gui_playlist_cur(), ==, "Test");
|
||||
|
||||
gtk_tree_path_up(path);
|
||||
gtk_tree_path_next(path);
|
||||
gtk_tree_selection_unselect_all(selection);
|
||||
gtk_tree_selection_select_path(selection, path);
|
||||
g_assert_cmpuint(gtk_tree_selection_count_selected_rows(selection), ==, 0);
|
||||
g_assert_null(gui_playlist_cur());
|
||||
|
||||
gtk_tree_path_next(path);
|
||||
gtk_tree_selection_select_path(selection, path);
|
||||
g_assert_cmpuint(gtk_tree_selection_count_selected_rows(selection), ==, 0);
|
||||
g_assert_null(gui_playlist_cur());
|
||||
|
||||
/* Most played and least played are both filtered out */
|
||||
gtk_tree_path_down(path);
|
||||
gtk_tree_selection_select_path(selection, path);
|
||||
g_assert_cmpuint(gtk_tree_selection_count_selected_rows(selection), ==, 1);
|
||||
g_assert_cmpstr(gui_playlist_cur(), ==, "Unplayed");
|
||||
g_assert_false(settings_has("gui.sidebar.expand.Playlists"));
|
||||
g_assert_true(gui_sidebar_iter_find(&iter, "Playlists", PL_MAX_TYPE));
|
||||
g_assert_true(gtk_tree_model_filter_convert_child_iter_to_iter(
|
||||
gui_sidebar_filter(), &child, &iter));
|
||||
path = gtk_tree_model_get_path(GTK_TREE_MODEL(gui_sidebar_filter()),
|
||||
&child);
|
||||
g_assert_nonnull(path);
|
||||
g_assert_true(gtk_tree_view_expand_row(gui_sidebar_treeview(), path, false));
|
||||
g_assert_true(settings_has("gui.sidebar.expand.Playlists"));
|
||||
g_assert_cmpuint(settings_get("gui.sidebar.expand.Playlists"), ==, 1);
|
||||
g_assert_true(gtk_tree_view_collapse_row(gui_sidebar_treeview(), path));
|
||||
g_assert_cmpuint(settings_get("gui.sidebar.expand.Playlists"), ==, 0);
|
||||
gtk_tree_path_free(path);
|
||||
|
||||
g_assert_true(gui_sidebar_iter_down(&iter, &child));
|
||||
g_assert_true(gtk_tree_model_filter_convert_child_iter_to_iter(
|
||||
gui_sidebar_filter(), &iter, &child));
|
||||
path = gtk_tree_model_get_path(GTK_TREE_MODEL(gui_sidebar_filter()),
|
||||
&iter);
|
||||
g_assert_nonnull(path);
|
||||
gtk_tree_view_row_activated(gui_sidebar_treeview(), path, NULL);
|
||||
g_assert_true(playlist_cur() == playlist_get(PL_SYSTEM, "Favorites"));
|
||||
gtk_tree_path_free(path);
|
||||
}
|
||||
|
||||
|
@ -109,23 +61,23 @@ int main(int argc, char **argv)
|
|||
int ret;
|
||||
|
||||
gtk_init(&argc, NULL);
|
||||
gui_builder_init("share/ocarina/ocarina.ui");
|
||||
core_init(&argc, NULL, &init_data);
|
||||
gui_builder_init("share/ocarina/ocarina.ui");
|
||||
gui_model_init();
|
||||
gui_filter_init();
|
||||
gui_treeview_init();
|
||||
gui_sidebar_init();
|
||||
gui_view_init();
|
||||
gui_playlist_init();
|
||||
playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony");
|
||||
while (idle_run_task()) {}
|
||||
|
||||
g_test_init(&argc, &argv, NULL);
|
||||
g_test_add_func("/Gui/Playlist/Sidebar", test_playlist_sidebar);
|
||||
g_test_add_func("/Gui/Playlist", test_playlist);
|
||||
ret = g_test_run();
|
||||
|
||||
core_deinit();
|
||||
gui_treeview_deinit();
|
||||
gui_filter_deinit();
|
||||
gui_model_deinit();
|
||||
gui_builder_deinit();
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user