2016-01-12 08:19:05 -05:00
|
|
|
/*
|
|
|
|
* Copyright 2016 (c) Anna Schumaker.
|
|
|
|
*/
|
2016-01-14 08:59:26 -05:00
|
|
|
#define TEST_NEED_AUDIO
|
|
|
|
#define TEST_NEED_COLLECTION
|
|
|
|
#define TEST_NEED_PLAYLIST
|
|
|
|
#define TEST_NEED_SIDEBAR
|
|
|
|
#define TEST_NEED_WINDOW
|
2016-01-20 08:33:24 -05:00
|
|
|
#include <core/core.h>
|
|
|
|
#include <core/idle.h>
|
2016-05-02 09:49:52 -04:00
|
|
|
#include <core/playlist.h>
|
2016-01-14 08:59:26 -05:00
|
|
|
#include <gui/builder.h>
|
2016-01-12 08:19:05 -05:00
|
|
|
#include <gui/queue.h>
|
2016-01-21 15:18:37 -05:00
|
|
|
#include <gui/view.h>
|
2016-01-14 08:59:26 -05:00
|
|
|
#include <tests/gui.h>
|
2016-01-12 08:19:05 -05:00
|
|
|
#include <tests/test.h>
|
|
|
|
|
2016-05-02 07:52:18 -04:00
|
|
|
static void *test_queue_init(struct queue *queue, void *data)
|
2016-01-13 16:48:43 -05:00
|
|
|
{
|
2016-05-15 11:04:13 -04:00
|
|
|
return gui_queue_alloc(NULL, queue, "Test Queue",
|
2016-01-15 12:12:12 -05:00
|
|
|
GQ_CAN_RANDOM | GQ_CAN_REPEAT | GQ_CAN_DISABLE);
|
2016-01-13 16:48:43 -05:00
|
|
|
}
|
|
|
|
|
2016-01-18 09:07:00 -05:00
|
|
|
static void test_queue_save(struct queue *queue, unsigned int row) {}
|
2016-01-12 08:19:05 -05:00
|
|
|
|
2016-01-20 08:33:24 -05:00
|
|
|
static struct queue_ops test_ops = {
|
2016-01-13 16:48:43 -05:00
|
|
|
.qop_init = test_queue_init,
|
2016-01-12 08:19:05 -05:00
|
|
|
.qop_deinit = gui_queue_free,
|
2016-01-18 09:07:00 -05:00
|
|
|
.qop_cleared = gui_queue_cleared,
|
|
|
|
.qop_added = gui_queue_added,
|
|
|
|
.qop_removed = gui_queue_removed,
|
|
|
|
.qop_save = test_queue_save,
|
|
|
|
.qop_updated = gui_queue_updated,
|
2016-01-12 08:19:05 -05:00
|
|
|
};
|
|
|
|
|
2016-01-20 08:33:24 -05:00
|
|
|
struct core_init_data init_data = {
|
2016-05-02 09:49:52 -04:00
|
|
|
.playlist_ops = &test_ops,
|
2016-01-20 08:33:24 -05:00
|
|
|
};
|
|
|
|
|
2016-01-12 08:19:05 -05:00
|
|
|
static void test_queue()
|
|
|
|
{
|
2016-01-14 08:59:26 -05:00
|
|
|
GtkToggleButton *random, *repeat;
|
|
|
|
GtkWidget *random_img, *repeat_img;
|
2016-01-19 08:39:44 -05:00
|
|
|
GtkTreeView *treeview;
|
2016-01-12 08:19:05 -05:00
|
|
|
struct gui_queue *gq;
|
2016-01-15 12:12:12 -05:00
|
|
|
GtkSwitch *enable;
|
2016-01-15 09:35:25 -05:00
|
|
|
GtkEntry *search;
|
2016-01-12 08:19:05 -05:00
|
|
|
struct queue q;
|
2016-01-14 08:59:26 -05:00
|
|
|
int argc = 0;
|
2016-01-12 08:19:05 -05:00
|
|
|
|
2016-01-14 08:59:26 -05:00
|
|
|
gtk_init(&argc, NULL);
|
|
|
|
gui_builder_init("share/ocarina/ocarina6.glade");
|
2016-01-21 15:18:37 -05:00
|
|
|
gui_view_init();
|
2016-04-29 11:10:48 -04:00
|
|
|
while (idle_run_task()) {};
|
|
|
|
|
2016-01-15 09:35:25 -05:00
|
|
|
search = GTK_ENTRY(gui_builder_widget("o_search"));
|
2016-01-15 12:12:12 -05:00
|
|
|
enable = GTK_SWITCH(gui_builder_widget("o_enable"));
|
2016-01-14 08:59:26 -05:00
|
|
|
random = GTK_TOGGLE_BUTTON(gui_builder_widget("o_random"));
|
|
|
|
repeat = GTK_TOGGLE_BUTTON(gui_builder_widget("o_repeat"));
|
|
|
|
random_img = gtk_button_get_image(GTK_BUTTON(random));
|
|
|
|
repeat_img = gtk_button_get_image(GTK_BUTTON(repeat));
|
2016-01-19 08:39:44 -05:00
|
|
|
treeview = GTK_TREE_VIEW(gui_builder_widget("o_treeview"));
|
2016-01-14 08:00:04 -05:00
|
|
|
|
2016-01-14 08:59:26 -05:00
|
|
|
/* Test initialization */
|
2016-05-02 07:52:18 -04:00
|
|
|
queue_init(&q, 0, &test_ops, NULL);
|
2016-01-12 08:19:05 -05:00
|
|
|
gq = gui_queue(&q);
|
2016-01-18 08:54:24 -05:00
|
|
|
test_equal((void *)gq->gq_queue, (void *)&q);
|
|
|
|
test_not_equal((void *)gq->gq_model, NULL);
|
|
|
|
|
2016-01-15 12:12:12 -05:00
|
|
|
test_equal(gui_queue_can_random(gq), (bool)true);
|
|
|
|
test_equal(gui_queue_can_repeat(gq), (bool)true);
|
|
|
|
test_equal(gui_queue_can_disable(gq), (bool)true);
|
2016-01-14 08:00:04 -05:00
|
|
|
|
|
|
|
gq->gq_flags = 0;
|
2016-01-15 12:12:12 -05:00
|
|
|
test_equal(gui_queue_can_random(gq), (bool)false);
|
|
|
|
test_equal(gui_queue_can_repeat(gq), (bool)false);
|
|
|
|
test_equal(gui_queue_can_disable(gq), (bool)false);
|
2016-01-14 08:59:26 -05:00
|
|
|
|
2016-01-15 09:35:25 -05:00
|
|
|
gtk_entry_set_text(search, "Test text");
|
|
|
|
|
2016-01-15 12:12:12 -05:00
|
|
|
/* Show a queue where random, repeat, and switch are disabled */
|
2016-01-14 08:59:26 -05:00
|
|
|
gui_queue_show(gq);
|
2016-01-19 08:39:44 -05:00
|
|
|
test_equal(gtk_widget_get_sensitive(GTK_WIDGET(random)), false);
|
|
|
|
test_equal(gtk_widget_get_sensitive(GTK_WIDGET(repeat)), false);
|
|
|
|
test_equal(gtk_widget_get_sensitive(GTK_WIDGET(enable)), false);
|
|
|
|
test_equal(gtk_widget_get_sensitive(GTK_WIDGET(treeview)), false);
|
2016-01-14 08:59:26 -05:00
|
|
|
test_equal(gtk_toggle_button_get_active(random), false);
|
|
|
|
test_equal(gtk_toggle_button_get_active(repeat), false);
|
2016-01-15 12:12:12 -05:00
|
|
|
test_equal(gtk_switch_get_active(enable), false);
|
2016-01-14 08:59:26 -05:00
|
|
|
test_equal(gtk_widget_get_sensitive(random_img), false);
|
|
|
|
test_equal(gtk_widget_get_sensitive(repeat_img), false);
|
2016-01-15 09:35:25 -05:00
|
|
|
test_equal(gtk_entry_get_text(search), "");
|
2016-01-14 08:59:26 -05:00
|
|
|
|
2016-01-14 10:24:10 -05:00
|
|
|
/* Test clicking random button. */
|
|
|
|
gtk_toggle_button_set_active(random, true);
|
|
|
|
test_equal(gtk_widget_get_sensitive(random_img), true);
|
|
|
|
test_equal(queue_has_flag(&q, Q_RANDOM), (bool)true);
|
|
|
|
|
|
|
|
gtk_toggle_button_set_active(random, false);
|
|
|
|
test_equal(gtk_widget_get_sensitive(random_img), false);
|
|
|
|
test_equal(queue_has_flag(&q, Q_RANDOM), (bool)false);
|
|
|
|
|
|
|
|
/* Test clicking repeat button. */
|
|
|
|
gtk_toggle_button_set_active(repeat, true);
|
|
|
|
test_equal(gtk_widget_get_sensitive(repeat_img), true);
|
|
|
|
test_equal(queue_has_flag(&q, Q_REPEAT), (bool)true);
|
|
|
|
|
|
|
|
gtk_toggle_button_set_active(repeat, false);
|
|
|
|
test_equal(gtk_widget_get_sensitive(repeat_img), false);
|
|
|
|
test_equal(queue_has_flag(&q, Q_REPEAT), (bool)false);
|
|
|
|
|
2016-01-15 12:12:12 -05:00
|
|
|
/* Test clicking enabled switch. */
|
|
|
|
gtk_switch_set_active(enable, true);
|
2016-01-19 08:39:44 -05:00
|
|
|
test_equal(gtk_widget_get_sensitive(GTK_WIDGET(treeview)), true);
|
2016-01-15 12:12:12 -05:00
|
|
|
test_equal(queue_has_flag(&q, Q_ENABLED), (bool)true);
|
|
|
|
|
|
|
|
gtk_switch_set_active(enable, false);
|
2016-01-19 08:39:44 -05:00
|
|
|
test_equal(gtk_widget_get_sensitive(GTK_WIDGET(treeview)), false);
|
2016-01-15 12:12:12 -05:00
|
|
|
test_equal(queue_has_flag(&q, Q_ENABLED), (bool)false);
|
|
|
|
|
2016-01-19 08:39:44 -05:00
|
|
|
/* Show a queue where random, repeat, and switch are enabled */
|
2016-01-15 12:12:12 -05:00
|
|
|
gq->gq_flags = GQ_CAN_RANDOM | GQ_CAN_REPEAT | GQ_CAN_DISABLE;
|
2016-01-19 08:39:44 -05:00
|
|
|
q.q_flags = Q_RANDOM | Q_REPEAT | Q_ENABLED;
|
2016-01-14 08:59:26 -05:00
|
|
|
gui_queue_show(gq);
|
2016-01-19 08:39:44 -05:00
|
|
|
test_equal(gtk_widget_get_sensitive(GTK_WIDGET(random)), true);
|
|
|
|
test_equal(gtk_widget_get_sensitive(GTK_WIDGET(repeat)), true);
|
|
|
|
test_equal(gtk_widget_get_sensitive(GTK_WIDGET(enable)), true);
|
|
|
|
test_equal(gtk_widget_get_sensitive(GTK_WIDGET(treeview)), true);
|
2016-01-14 08:59:26 -05:00
|
|
|
test_equal(gtk_toggle_button_get_active(random), true);
|
|
|
|
test_equal(gtk_toggle_button_get_active(repeat), true);
|
2016-01-19 08:39:44 -05:00
|
|
|
test_equal(gtk_switch_get_active(enable), true);
|
2016-01-14 08:59:26 -05:00
|
|
|
test_equal(gtk_widget_get_sensitive(random_img), true);
|
|
|
|
test_equal(gtk_widget_get_sensitive(repeat_img), true);
|
|
|
|
|
|
|
|
/* Attempt to show a NULL pointer */
|
|
|
|
gui_queue_show(NULL);
|
2016-01-19 08:39:44 -05:00
|
|
|
test_equal(gtk_widget_get_sensitive(GTK_WIDGET(search)), false);
|
|
|
|
test_equal(gtk_widget_get_sensitive(GTK_WIDGET(random)), false);
|
|
|
|
test_equal(gtk_widget_get_sensitive(GTK_WIDGET(repeat)), false);
|
|
|
|
test_equal(gtk_widget_get_sensitive(GTK_WIDGET(enable)), false);
|
|
|
|
test_equal(gtk_widget_get_sensitive(GTK_WIDGET(treeview)), false);
|
2016-01-14 08:59:26 -05:00
|
|
|
test_equal(gtk_toggle_button_get_active(random), false);
|
|
|
|
test_equal(gtk_toggle_button_get_active(repeat), false);
|
2016-01-15 12:12:12 -05:00
|
|
|
test_equal(gtk_switch_get_active(enable), false);
|
2016-01-14 08:59:26 -05:00
|
|
|
test_equal(gtk_widget_get_sensitive(random_img), false);
|
|
|
|
test_equal(gtk_widget_get_sensitive(repeat_img), false);
|
2016-01-12 08:19:05 -05:00
|
|
|
|
|
|
|
queue_deinit(&q);
|
|
|
|
test_equal((void *)gui_queue(&q), NULL);
|
|
|
|
}
|
|
|
|
|
2016-01-20 16:49:37 -05:00
|
|
|
static void test_tracks()
|
2016-01-20 08:33:24 -05:00
|
|
|
{
|
2016-05-02 09:49:52 -04:00
|
|
|
struct db_entry *dbe, *next;
|
2016-01-20 08:33:24 -05:00
|
|
|
struct gui_queue *gq;
|
2016-01-20 16:49:37 -05:00
|
|
|
GtkLabel *runtime;
|
2016-01-20 08:33:24 -05:00
|
|
|
GtkEntry *search;
|
|
|
|
int argc = 0;
|
|
|
|
|
2016-01-20 16:49:37 -05:00
|
|
|
runtime = GTK_LABEL(gui_builder_widget("o_runtime"));
|
|
|
|
search = GTK_ENTRY(gui_builder_widget("o_search"));
|
2016-01-20 08:33:24 -05:00
|
|
|
|
|
|
|
core_init(&argc, NULL, &init_data);
|
2016-05-06 08:05:21 -04:00
|
|
|
gq = gui_queue(playlist_get_queue(PL_SYSTEM, "Collection"));
|
2016-01-20 08:33:24 -05:00
|
|
|
|
|
|
|
gui_queue_show(gq);
|
2016-01-20 16:49:37 -05:00
|
|
|
test_equal(gtk_label_get_text(runtime), "");
|
|
|
|
|
2016-05-11 11:13:42 -04:00
|
|
|
playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony");
|
2016-01-20 16:49:37 -05:00
|
|
|
while (idle_run_task() == true) {}
|
|
|
|
test_equal(gtk_label_get_text(runtime), "42 minutes, 45 seconds");
|
2016-01-20 08:33:24 -05:00
|
|
|
|
|
|
|
test_not_equal((void *)gq, NULL);
|
|
|
|
test_not_equal((void *)gq->gq_filter, NULL);
|
|
|
|
test_equal(gtk_tree_model_iter_n_children(gq->gq_filter, NULL), 13);
|
|
|
|
|
|
|
|
gtk_entry_set_text(search, "zelda");
|
|
|
|
g_signal_emit_by_name(search, "search-changed");
|
|
|
|
test_equal(gtk_tree_model_iter_n_children(gq->gq_filter, NULL), 2);
|
|
|
|
|
|
|
|
gtk_entry_set_text(search, "");
|
|
|
|
g_signal_emit_by_name(search, "search-changed");
|
|
|
|
test_equal(gtk_tree_model_iter_n_children(gq->gq_filter, NULL), 13);
|
|
|
|
|
2016-05-02 09:49:52 -04:00
|
|
|
db_for_each(dbe, next, track_db_get()) {
|
|
|
|
if (TRACK(dbe)->tr_track == 4) {
|
2016-05-06 08:05:21 -04:00
|
|
|
playlist_remove(PL_SYSTEM, "Collection", TRACK(dbe));
|
2016-05-02 09:49:52 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-20 16:49:37 -05:00
|
|
|
test_equal(gtk_tree_model_iter_n_children(gq->gq_filter, NULL), 12);
|
|
|
|
test_equal(gtk_label_get_text(runtime), "40 minutes, 35 seconds");
|
|
|
|
|
|
|
|
gui_queue_show(NULL);
|
|
|
|
test_equal(gtk_label_get_text(runtime), "");
|
|
|
|
|
2016-01-20 08:33:24 -05:00
|
|
|
core_deinit();
|
2016-04-29 10:46:16 -04:00
|
|
|
gui_builder_deinit();
|
2016-01-20 08:33:24 -05:00
|
|
|
}
|
|
|
|
|
2016-01-12 08:19:05 -05:00
|
|
|
DECLARE_UNIT_TESTS(
|
|
|
|
UNIT_TEST("Queue", test_queue),
|
2016-01-20 16:49:37 -05:00
|
|
|
UNIT_TEST("Queue Tracks", test_tracks),
|
2016-01-12 08:19:05 -05:00
|
|
|
);
|