4998b0867b
This function returns the average count of tracks that have been played, and not the average count of all tracks. Implements #29: Efficiently calculate average play count of tracks Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
133 lines
3.7 KiB
C
133 lines
3.7 KiB
C
/*
|
|
* Copyright 2016 (c) Anna Schumaker.
|
|
*/
|
|
#define TEST_NEED_AUDIO
|
|
#define TEST_NEED_COLLECTION
|
|
#define TEST_NEED_PLAYLIST
|
|
#define TEST_NEED_QUEUE
|
|
#define TEST_NEED_SIDEBAR
|
|
#define TEST_NEED_WINDOW
|
|
#include <core/audio.h>
|
|
#include <core/collection.h>
|
|
#include <core/core.h>
|
|
#include <core/idle.h>
|
|
#include <gui/builder.h>
|
|
#include <gui/model.h>
|
|
#include <gui/settings.h>
|
|
#include <gui/view.h>
|
|
#include <tests/gui.h>
|
|
#include <tests/test.h>
|
|
|
|
const gchar *QUEUE_SETTINGS[Q_MODEL_N_COLUMNS] = {
|
|
[Q_MODEL_TRACK_NR] = "gui.queue.track",
|
|
[Q_MODEL_TITLE] = "gui.queue.title",
|
|
[Q_MODEL_LENGTH] = "gui.queue.length",
|
|
[Q_MODEL_ARTIST] = "gui.queue.artist",
|
|
[Q_MODEL_ALBUM] = "gui.queue.album",
|
|
[Q_MODEL_YEAR] = "gui.queue.year",
|
|
[Q_MODEL_GENRE] = "gui.queue.genre",
|
|
[Q_MODEL_COUNT] = "gui.queue.count",
|
|
[Q_MODEL_LAST_PLAY] = "gui.queue.played",
|
|
[Q_MODEL_FILE_PATH] = "gui.queue.filepath",
|
|
[Q_MODEL_FONT] = "gui.queue.font",
|
|
};
|
|
|
|
GMainLoop *main_loop;
|
|
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) {}
|
|
|
|
struct audio_ops audio_ops = {
|
|
.on_load = test_load,
|
|
.on_state_change = test_state_change,
|
|
.on_config_pause = test_config_pause,
|
|
};
|
|
|
|
struct core_init_data init_data = {
|
|
.audio_ops = &audio_ops,
|
|
};
|
|
|
|
static int test_on_idle(gpointer data)
|
|
{
|
|
g_main_loop_quit(main_loop);
|
|
return G_SOURCE_CONTINUE;
|
|
}
|
|
|
|
static void test_treeview()
|
|
{
|
|
GtkTreeModel *model, *filter;
|
|
GtkTreeViewColumn *col;
|
|
GtkTreeView *treeview;
|
|
GtkTreePath *path;
|
|
GtkTreeIter iter;
|
|
unsigned int i;
|
|
int argc = 0;
|
|
|
|
gtk_init(&argc, NULL);
|
|
core_init(&argc, NULL, &init_data);
|
|
gui_builder_init("share/ocarina/ocarina6.glade");
|
|
gui_settings_init();
|
|
gui_view_init();
|
|
while (idle_run_task()) {}
|
|
|
|
collection_add("tests/Music/Hyrule Symphony");
|
|
while (idle_run_task() == true) {}
|
|
model = GTK_TREE_MODEL(gui_queue_model_new(collection_get_queue()));
|
|
filter = gtk_tree_model_filter_new(model, NULL);
|
|
|
|
treeview = GTK_TREE_VIEW(gui_builder_widget("o_treeview"));
|
|
main_loop = g_main_loop_new(NULL, FALSE);
|
|
g_idle_add(test_on_idle, NULL);
|
|
|
|
for (i = 0; i < Q_MODEL_N_COLUMNS; i++) {
|
|
test_loop_equal(gui_settings_has(QUEUE_SETTINGS[i]),
|
|
(bool)false, i);
|
|
} test_loop_passed();
|
|
|
|
for (i = 0; i < Q_MODEL_N_COLUMNS; i++) {
|
|
if (i == Q_MODEL_FILE_PATH || i == Q_MODEL_FONT)
|
|
continue;
|
|
col = gtk_tree_view_get_column(treeview, i);
|
|
gtk_tree_view_column_set_fixed_width(col, (i + 1) * 10);
|
|
}
|
|
|
|
g_main_loop_run(main_loop);
|
|
for (i = 0; i < Q_MODEL_N_COLUMNS; i++) {
|
|
bool has = (i != Q_MODEL_FILE_PATH) && (i != Q_MODEL_FONT);
|
|
test_loop_equal(gui_settings_has(QUEUE_SETTINGS[i]), has, i);
|
|
/* The "Played" column gets any remaining space. */
|
|
if (has && i != Q_MODEL_LAST_PLAY)
|
|
test_loop_equal(gui_settings_get(QUEUE_SETTINGS[i]),
|
|
(i + 1) * 10, i);
|
|
} test_loop_passed();
|
|
test_equal(gui_settings_has("gui.queue.filepath"), (bool)false);
|
|
test_equal(gui_settings_get("gui.queue.filepath"), 0);
|
|
|
|
for (i = 0; i < Q_MODEL_LAST_PLAY; i++)
|
|
gui_settings_set(QUEUE_SETTINGS[i], 42);
|
|
|
|
gui_view_init();
|
|
for (i = 0; i < Q_MODEL_LAST_PLAY; i++) {
|
|
col = gtk_tree_view_get_column(treeview, i);
|
|
test_loop_equal(gtk_tree_view_column_get_fixed_width(col), 42, i);
|
|
} test_loop_passed();
|
|
|
|
gui_view_set_model(GTK_TREE_MODEL_FILTER(filter));
|
|
test_equal((void *)gtk_tree_view_get_model(treeview), (void *)filter);
|
|
|
|
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);
|
|
test_equal(load_count, 1);
|
|
gtk_tree_path_free(path);
|
|
|
|
gui_view_set_model(NULL);
|
|
test_equal((void *)gtk_tree_view_get_model(treeview), NULL);
|
|
}
|
|
|
|
DECLARE_UNIT_TESTS(
|
|
UNIT_TEST("Treeview", test_treeview),
|
|
);
|