Anna Schumaker
828f861d9a
This makes the most sense here, and lets us remove gui/queue.c at some point in the future. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
145 lines
3.9 KiB
C
145 lines
3.9 KiB
C
/*
|
|
* Copyright 2016 (c) Anna Schumaker.
|
|
*/
|
|
#include <core/core.h>
|
|
#include <core/idle.h>
|
|
#include <core/playlist.h>
|
|
#include <gui/builder.h>
|
|
#include <gui/filter.h>
|
|
#include <gui/queue.h>
|
|
#include <gui/view.h>
|
|
#include <tests/test.h>
|
|
|
|
static void *test_queue_init(struct queue *queue, void *data)
|
|
{
|
|
return gui_queue_alloc(data, queue, "Test Queue", GQ_CAN_RANDOM);
|
|
}
|
|
|
|
void test_queue_add(struct queue *queue, unsigned int n)
|
|
{ gui_model_add(gui_queue(queue)->gq_playlist, n); }
|
|
void test_queue_remove(struct queue *queue, unsigned int n)
|
|
{ gui_model_remove(gui_queue(queue)->gq_playlist, n); }
|
|
void test_queue_clear(struct queue *queue, unsigned int n)
|
|
{ gui_model_clear(gui_queue(queue)->gq_playlist, n); }
|
|
static void test_queue_save(struct queue *queue, unsigned int row) {}
|
|
void test_queue_update(struct queue *queue, unsigned int n)
|
|
{ gui_model_update(gui_queue(queue)->gq_playlist, n); }
|
|
|
|
static struct queue_ops test_ops = {
|
|
.qop_init = test_queue_init,
|
|
.qop_deinit = gui_queue_free,
|
|
.qop_cleared = test_queue_clear,
|
|
.qop_added = test_queue_add,
|
|
.qop_removed = test_queue_remove,
|
|
.qop_save = test_queue_save,
|
|
.qop_updated = test_queue_update,
|
|
};
|
|
|
|
struct core_init_data init_data = {
|
|
.playlist_ops = &test_ops,
|
|
};
|
|
|
|
static void test_queue()
|
|
{
|
|
GtkToggleButton *random;
|
|
struct gui_queue *gq;
|
|
GtkEntry *search;
|
|
struct queue q;
|
|
|
|
search = GTK_ENTRY(gui_filter_search());
|
|
random = GTK_TOGGLE_BUTTON(gui_builder_widget("random_button"));
|
|
|
|
/* Test initialization */
|
|
queue_init(&q, Q_ENABLED, &test_ops, NULL);
|
|
gq = gui_queue(&q);
|
|
|
|
g_assert_true(gui_queue_can_random(gq));
|
|
gq->gq_flags = 0;
|
|
g_assert_false(gui_queue_can_random(gq));
|
|
|
|
gtk_entry_set_text(search, "Test text");
|
|
|
|
/* Show a queue where random and repeat are disabled */
|
|
gui_queue_show(gq);
|
|
g_assert_false(gtk_widget_get_sensitive(GTK_WIDGET(random)));
|
|
g_assert_false(gtk_toggle_button_get_active(random));
|
|
g_assert_cmpstr(gtk_entry_get_text(search), ==, "");
|
|
|
|
/* Show a queue where random and repeat are enabled */
|
|
gq->gq_flags = GQ_CAN_RANDOM;
|
|
q.q_flags = Q_RANDOM | Q_REPEAT | Q_ENABLED;
|
|
gui_queue_show(gq);
|
|
g_assert_true(gtk_widget_get_sensitive(GTK_WIDGET(random)));
|
|
g_assert_true(gtk_toggle_button_get_active(random));
|
|
|
|
/* Attempt to show a NULL pointer */
|
|
gui_queue_show(NULL);
|
|
g_assert_false(gtk_widget_get_sensitive(GTK_WIDGET(random)));
|
|
g_assert_false(gtk_toggle_button_get_active(random));
|
|
|
|
queue_deinit(&q);
|
|
g_assert_null(gui_queue(&q));
|
|
}
|
|
|
|
static void test_tracks()
|
|
{
|
|
struct db_entry *dbe, *next;
|
|
GtkTreeModel *filter;
|
|
struct gui_queue *gq;
|
|
GtkEntry *search;
|
|
|
|
search = GTK_ENTRY(gui_filter_search());
|
|
|
|
gq = gui_queue(playlist_get_queue(PL_SYSTEM, "Collection"));
|
|
|
|
gui_queue_show(gq);
|
|
playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony");
|
|
while (idle_run_task() == true) {}
|
|
|
|
filter = GTK_TREE_MODEL(gui_filter_get());
|
|
g_assert_nonnull(gq);
|
|
g_assert_nonnull(filter);
|
|
g_assert_cmpuint(gtk_tree_model_iter_n_children(filter, NULL), ==, 13);
|
|
|
|
gtk_entry_set_text(search, "zelda");
|
|
g_signal_emit_by_name(search, "search-changed");
|
|
g_assert_cmpuint(gtk_tree_model_iter_n_children(filter, NULL), ==, 2);
|
|
|
|
gtk_entry_set_text(search, "");
|
|
g_signal_emit_by_name(search, "search-changed");
|
|
g_assert_cmpuint(gtk_tree_model_iter_n_children(filter, NULL), ==, 13);
|
|
|
|
db_for_each(dbe, next, track_db_get()) {
|
|
if (TRACK(dbe)->tr_track == 4) {
|
|
playlist_remove(PL_SYSTEM, "Collection", TRACK(dbe));
|
|
break;
|
|
}
|
|
}
|
|
|
|
g_assert_cmpuint(gtk_tree_model_iter_n_children(filter, NULL), ==, 12);
|
|
gui_queue_show(NULL);
|
|
}
|
|
|
|
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_model_init();
|
|
gui_filter_init();
|
|
gui_view_init();
|
|
gui_queue_init();
|
|
while (idle_run_task()) {};
|
|
|
|
g_test_init(&argc, &argv, NULL);
|
|
g_test_add_func("/Gui/Queue", test_queue);
|
|
g_test_add_func("/Gui/Queue/Tracks", test_tracks);
|
|
ret = g_test_run();
|
|
|
|
core_deinit();
|
|
gui_builder_deinit();
|
|
return ret;
|
|
}
|