2016-01-19 10:16:26 -05:00
|
|
|
/*
|
|
|
|
* Copyright 2016 (c) Anna Schumaker.
|
|
|
|
*/
|
2016-01-20 09:16:01 -05:00
|
|
|
#include <core/audio.h>
|
2016-01-21 15:18:37 -05:00
|
|
|
#include <core/core.h>
|
|
|
|
#include <core/idle.h>
|
2016-05-02 10:18:17 -04:00
|
|
|
#include <core/playlist.h>
|
2016-03-29 08:39:00 -04:00
|
|
|
#include <core/settings.h>
|
2016-01-19 10:16:26 -05:00
|
|
|
#include <gui/builder.h>
|
2016-08-21 10:27:52 -04:00
|
|
|
#include <gui/filter.h>
|
2016-01-19 10:16:26 -05:00
|
|
|
#include <gui/model.h>
|
|
|
|
#include <gui/view.h>
|
|
|
|
#include <tests/test.h>
|
2016-08-19 08:53:37 -04:00
|
|
|
#include <tests/gui.h>
|
2016-01-19 10:16:26 -05:00
|
|
|
|
2016-08-20 10:08:36 -04:00
|
|
|
const gchar *QUEUE_SETTINGS[GUI_MODEL_N_COLUMNS] = {
|
|
|
|
[GUI_MODEL_TRACK_NR] = "gui.queue.track",
|
|
|
|
[GUI_MODEL_TITLE] = "gui.queue.title",
|
|
|
|
[GUI_MODEL_LENGTH] = "gui.queue.length",
|
|
|
|
[GUI_MODEL_ARTIST] = "gui.queue.artist",
|
|
|
|
[GUI_MODEL_ALBUM] = "gui.queue.album",
|
|
|
|
[GUI_MODEL_YEAR] = "gui.queue.year",
|
|
|
|
[GUI_MODEL_GENRE] = "gui.queue.genre",
|
|
|
|
[GUI_MODEL_COUNT] = "gui.queue.count",
|
|
|
|
[GUI_MODEL_LAST_PLAY] = "gui.queue.played",
|
|
|
|
[GUI_MODEL_FILE_PATH] = "gui.queue.filepath",
|
|
|
|
[GUI_MODEL_FONT] = "gui.queue.font",
|
2016-01-19 10:16:26 -05:00
|
|
|
};
|
|
|
|
|
2016-01-20 09:16:01 -05:00
|
|
|
unsigned int load_count = 0;
|
|
|
|
|
|
|
|
static void test_load(struct track *track) { load_count++; }
|
|
|
|
static void test_state_change(GstState state) {}
|
|
|
|
static void test_config_pause(int count) {}
|
|
|
|
|
2016-03-24 08:06:40 -04:00
|
|
|
struct audio_ops test_audio_ops = {
|
2016-01-20 09:16:01 -05:00
|
|
|
.on_load = test_load,
|
|
|
|
.on_state_change = test_state_change,
|
|
|
|
.on_config_pause = test_config_pause,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct core_init_data init_data = {
|
2016-03-24 08:06:40 -04:00
|
|
|
.audio_ops = &test_audio_ops,
|
2016-01-20 09:16:01 -05:00
|
|
|
};
|
2016-01-19 10:16:26 -05:00
|
|
|
|
|
|
|
static void test_treeview()
|
|
|
|
{
|
|
|
|
GtkTreeViewColumn *col;
|
|
|
|
GtkTreeView *treeview;
|
2016-08-02 11:46:42 -04:00
|
|
|
GtkTreeModel *filter;
|
2016-01-20 09:16:01 -05:00
|
|
|
GtkTreePath *path;
|
|
|
|
GtkTreeIter iter;
|
2016-01-19 10:16:26 -05:00
|
|
|
unsigned int i;
|
|
|
|
|
2016-05-11 11:13:42 -04:00
|
|
|
playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony");
|
2016-01-21 15:18:37 -05:00
|
|
|
while (idle_run_task() == true) {}
|
2016-08-22 10:15:09 -04:00
|
|
|
gui_filter_set_playlist(playlist_get(PL_SYSTEM, "Collection"));
|
2016-08-21 10:27:52 -04:00
|
|
|
filter = GTK_TREE_MODEL(gui_filter_get());
|
2016-01-21 15:18:37 -05:00
|
|
|
|
2016-01-19 10:16:26 -05:00
|
|
|
treeview = GTK_TREE_VIEW(gui_builder_widget("o_treeview"));
|
|
|
|
|
2016-08-20 10:08:36 -04:00
|
|
|
for (i = 0; i < GUI_MODEL_N_COLUMNS; i++)
|
2016-03-29 08:39:00 -04:00
|
|
|
g_assert_false(settings_has(QUEUE_SETTINGS[i]));
|
2016-01-19 10:16:26 -05:00
|
|
|
|
2016-08-20 10:08:36 -04:00
|
|
|
for (i = 0; i < GUI_MODEL_N_COLUMNS; i++) {
|
|
|
|
if (i == GUI_MODEL_FILE_PATH || i == GUI_MODEL_FONT)
|
2016-06-04 17:39:11 -04:00
|
|
|
continue;
|
2016-01-19 10:16:26 -05:00
|
|
|
col = gtk_tree_view_get_column(treeview, i);
|
2016-08-29 07:59:11 -04:00
|
|
|
gtk_tree_view_column_set_fixed_width(col, (i + 2) * 10);
|
2016-01-19 10:16:26 -05:00
|
|
|
}
|
|
|
|
|
2016-08-19 08:53:37 -04:00
|
|
|
gui_test_main_loop();
|
2016-08-20 10:08:36 -04:00
|
|
|
for (i = 0; i < GUI_MODEL_N_COLUMNS; i++) {
|
|
|
|
bool has = (i < GUI_MODEL_LAST_PLAY);
|
2016-03-29 08:39:00 -04:00
|
|
|
g_assert(settings_has(QUEUE_SETTINGS[i]) == has);
|
2016-01-19 10:16:26 -05:00
|
|
|
/* The "Played" column gets any remaining space. */
|
2016-09-26 10:52:44 -04:00
|
|
|
if (has)
|
2016-03-29 08:39:00 -04:00
|
|
|
g_assert_cmpuint(settings_get(QUEUE_SETTINGS[i]),
|
2016-03-24 08:06:40 -04:00
|
|
|
==, (i + 2) * 10);
|
|
|
|
}
|
2016-03-29 08:39:00 -04:00
|
|
|
g_assert_false(settings_has("gui.queue.filepath"));
|
|
|
|
g_assert_cmpuint(settings_get("gui.queue.filepath"), ==, 0);
|
2016-01-19 10:16:26 -05:00
|
|
|
|
2016-08-20 10:08:36 -04:00
|
|
|
for (i = 0; i < GUI_MODEL_LAST_PLAY; i++)
|
2016-03-29 08:39:00 -04:00
|
|
|
settings_set(QUEUE_SETTINGS[i], 42);
|
2016-01-19 10:16:26 -05:00
|
|
|
|
|
|
|
gui_view_init();
|
2016-08-20 10:08:36 -04:00
|
|
|
for (i = 0; i < GUI_MODEL_LAST_PLAY; i++) {
|
2016-01-19 10:16:26 -05:00
|
|
|
col = gtk_tree_view_get_column(treeview, i);
|
2016-03-24 08:06:40 -04:00
|
|
|
g_assert_cmpuint(gtk_tree_view_column_get_fixed_width(col), ==, 42);
|
|
|
|
}
|
2016-01-21 15:18:37 -05:00
|
|
|
|
2016-03-24 08:06:40 -04:00
|
|
|
g_assert((void *)gtk_tree_view_get_model(treeview) ==
|
2016-08-21 10:27:52 -04:00
|
|
|
(void *)gui_filter_get());
|
2016-01-21 15:18:37 -05:00
|
|
|
|
2016-01-20 09:16:01 -05:00
|
|
|
gtk_tree_model_iter_nth_child(filter, &iter, NULL, 3);
|
|
|
|
path = gtk_tree_model_get_path(filter, &iter);
|
|
|
|
gtk_tree_view_row_activated(treeview, path, NULL);
|
2016-03-24 08:06:40 -04:00
|
|
|
g_assert_cmpuint(load_count, ==, 1);
|
2016-01-20 09:16:01 -05:00
|
|
|
gtk_tree_path_free(path);
|
|
|
|
|
2016-08-20 21:01:19 -04:00
|
|
|
gui_view_set_playlist(NULL);
|
2016-08-19 08:53:37 -04:00
|
|
|
gui_test_deinit();
|
2016-01-19 10:16:26 -05:00
|
|
|
}
|
|
|
|
|
2016-03-24 08:06:40 -04:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2016-10-19 08:22:18 -04:00
|
|
|
gtk_init(&argc, NULL);
|
|
|
|
core_init(&argc, NULL, &init_data);
|
|
|
|
gui_builder_init("share/ocarina/ocarina.ui");
|
2016-08-20 10:08:36 -04:00
|
|
|
gui_model_init();
|
2016-10-19 08:22:18 -04:00
|
|
|
gui_view_init();
|
2016-08-19 08:53:37 -04:00
|
|
|
gui_test_init();
|
2016-10-19 08:22:18 -04:00
|
|
|
while (idle_run_task()) {};
|
|
|
|
|
2016-03-24 08:06:40 -04:00
|
|
|
g_test_init(&argc, &argv, NULL);
|
|
|
|
g_test_add_func("/Gui/Treeview", test_treeview);
|
|
|
|
return g_test_run();
|
|
|
|
}
|