ocarina/tests/core/library.cpp

166 lines
4.5 KiB
C++
Raw Normal View History

/*
* Copyright 2013 (c) Anna Schumaker.
*/
extern "C" {
#include <core/filter.h>
#include <core/idle.h>
#include <core/tags/tags.h>
}
#include <core/library.h>
#include "test.h"
static struct library *LIB_NULL = NULL;
static void test_init()
{
struct queue *q = collection :: get_queue();
GSList *list;
filter_init();
tags_init();
collection_init(NULL);
test_not_equal(q, NULL);
test_equal(queue_has_flag(q, Q_ENABLED), true);
test_equal(queue_has_flag(q, Q_REPEAT), true);
test_equal(queue_has_flag(q, Q_SAVE_SORT), true);
test_equal(queue_has_flag(q, Q_SAVE_FLAGS), true);
test_equal(queue_has_flag(q, Q_ADD_FRONT), false);
test_equal(queue_size(q), 0);
list = q->q_sort;
test_equal(g_slist_length(q->q_sort), 3);
test_equal(GPOINTER_TO_INT(list->data), COMPARE_ARTIST);
list = g_slist_next(list);
test_equal(GPOINTER_TO_INT(list->data), COMPARE_YEAR);
list = g_slist_next(list);
test_equal(GPOINTER_TO_INT(list->data), COMPARE_TRACK);
}
static void test_add()
{
struct queue *q = collection :: get_queue();
struct library *lib;
test_equal(collection_add("tests/Invalid"), NULL);
lib = collection_add("tests/Music");
test_not_equal(lib, NULL);
test_equal(lib->li_size, 0);
test_equal(lib->li_enabled, true);
test_equal(lib->li_path, "tests/Music");
test_equal(queue_size(q), 0);
test_equal(idle_run_task(), true); /* collection validation */
test_equal(idle_run_task(), true); /* tests/Music/ */
test_equal(idle_run_task(), true); /* tests/Music/Hyrule Symphony/ */
test_equal(idle_run_task(), false); /* tests/Music/Ocarina of Time/ */
test_equal(track_db_get()->db_size, 48);
test_equal(lib->li_size, 48);
test_equal(queue_size(q), 48);
}
static void test_update()
{
struct queue *q = collection :: get_queue();
struct library *lib = library_get(0);
g_rename("tests/Music/Hyrule Symphony/", "tests/Music/symphony/");
collection_update(lib);
/* Collection validation removes tests/Music/Hyrule Symphony/ */
test_equal(idle_run_task(), true);
test_equal(track_db_get()->db_size, 35);
test_equal(lib->li_size, 35);
test_equal(queue_size(q), 35);
/* tests/Music and tests/Music/Ocarina of Time/ have not changed */
test_equal(idle_run_task(), true);
test_equal(idle_run_task(), true);
test_equal(track_db_get()->db_size, 35);
test_equal(lib->li_size, 35);
test_equal(queue_size(q), 35);
/* Scan tests/Music/symphony/ */
test_equal(idle_run_task(), false);
test_equal(track_db_get()->db_size, 48);
test_equal(lib->li_size, 48);
test_equal(queue_size(q), 48);
g_rename("tests/Music/symphony", "tests/Music/Hyrule Symphony/");
collection_update_all();
/*
* Collection validation removes tests/Music/symphony/,
* and tests/Music has not changed
*/
test_equal(idle_run_task(), true);
test_equal(idle_run_task(), true);
test_equal(track_db_get()->db_size, 35);
test_equal(lib->li_size, 35);
test_equal(queue_size(q), 35);
/* tests/Music/Hyrule Symphony exists again */
test_equal(idle_run_task(), true);
test_equal(track_db_get()->db_size, 48);
test_equal(lib->li_size, 48);
test_equal(queue_size(q), 48);
/* tests/Music/Ocarina of Time/ has not changed */
test_equal(idle_run_task(), false);
test_equal(track_db_get()->db_size, 48);
test_equal(lib->li_size, 48);
test_equal(queue_size(q), 48);
}
static void test_remove()
{
struct queue *q = collection :: get_queue();
collection_remove(NULL);
test_equal(track_db_get()->db_size, 48);
collection_remove(library_get(0));
test_equal(track_db_get()->db_size, 0);
test_equal(library_get(0), NULL);
test_equal(queue_size(q), 0);
}
static void test_enable()
{
test_cp_data_dir();
filter_init();
tags_init();
collection_init(NULL);
queue *q = collection :: get_queue();
struct library *library = library_get(0);
collection :: set_enabled(LIB_NULL, true);
test_equal(queue_size(q), (unsigned)24);
collection :: set_enabled(library, false);
test_equal(queue_size(q), (unsigned)0);
collection :: set_enabled(library, true);
test_equal(queue_size(q), (unsigned)24);
collection :: set_enabled(library, true);
test_equal(queue_size(q), (unsigned)24);
collection :: set_enabled(library, false);
test_equal(queue_size(q), (unsigned)0);
collection :: set_enabled(library, true);
test_equal(queue_size(q), (unsigned)24);
}
DECLARE_UNIT_TESTS(
UNIT_TEST("Collection Initialization", test_init),
UNIT_TEST("Collection Add Path", test_add),
UNIT_TEST("Collection Update Path", test_update),
UNIT_TEST("Collection Remove Path", test_remove),
UNIT_TEST("Library Enable and Disable", test_enable),
);