2013-10-27 17:25:26 -04:00
|
|
|
/*
|
|
|
|
* Copyright 2013 (c) Anna Schumaker.
|
|
|
|
*/
|
2015-11-10 10:19:45 -05:00
|
|
|
extern "C" {
|
2015-09-29 16:25:16 -04:00
|
|
|
#include <core/filter.h>
|
2014-06-05 10:19:22 -04:00
|
|
|
#include <core/idle.h>
|
2015-11-12 10:42:21 -05:00
|
|
|
#include <core/tags/tags.h>
|
2015-11-10 14:18:11 -05:00
|
|
|
}
|
2014-06-05 10:19:22 -04:00
|
|
|
#include <core/library.h>
|
2015-08-31 08:11:24 -04:00
|
|
|
#include "test.h"
|
2014-05-24 12:47:33 -04:00
|
|
|
|
2015-10-23 10:21:12 -04:00
|
|
|
static struct library *LIB_NULL = NULL;
|
2014-05-24 12:47:33 -04:00
|
|
|
|
|
|
|
static void test_init()
|
|
|
|
{
|
2015-12-05 08:55:24 -05:00
|
|
|
struct queue *q = collection :: get_queue();
|
|
|
|
GSList *list;
|
2014-05-24 12:47:33 -04:00
|
|
|
|
2015-09-29 16:25:16 -04:00
|
|
|
filter_init();
|
2015-11-12 10:24:27 -05:00
|
|
|
tags_init();
|
2015-12-05 08:55:24 -05:00
|
|
|
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);
|
2014-05-24 12:47:33 -04:00
|
|
|
}
|
|
|
|
|
2015-12-05 09:36:14 -05:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2015-12-05 10:21:24 -05:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2015-12-05 09:36:14 -05:00
|
|
|
|
2014-05-24 12:47:33 -04:00
|
|
|
static void test_enable()
|
|
|
|
{
|
2015-12-05 08:55:24 -05:00
|
|
|
test_cp_data_dir();
|
|
|
|
filter_init();
|
|
|
|
tags_init();
|
|
|
|
collection_init(NULL);
|
|
|
|
|
2015-11-16 09:12:15 -05:00
|
|
|
queue *q = collection :: get_queue();
|
2015-09-28 10:08:11 -04:00
|
|
|
struct library *library = library_get(0);
|
2014-05-24 12:47:33 -04:00
|
|
|
|
2015-10-23 10:21:12 -04:00
|
|
|
collection :: set_enabled(LIB_NULL, true);
|
2015-11-19 13:48:59 -05:00
|
|
|
test_equal(queue_size(q), (unsigned)24);
|
2014-05-24 12:47:33 -04:00
|
|
|
|
2015-10-23 10:21:12 -04:00
|
|
|
collection :: set_enabled(library, false);
|
2015-11-19 13:48:59 -05:00
|
|
|
test_equal(queue_size(q), (unsigned)0);
|
2014-05-24 12:47:33 -04:00
|
|
|
|
2015-10-23 10:21:12 -04:00
|
|
|
collection :: set_enabled(library, true);
|
2015-11-19 13:48:59 -05:00
|
|
|
test_equal(queue_size(q), (unsigned)24);
|
2014-05-24 12:47:33 -04:00
|
|
|
|
2015-10-23 10:21:12 -04:00
|
|
|
collection :: set_enabled(library, true);
|
2015-11-19 13:48:59 -05:00
|
|
|
test_equal(queue_size(q), (unsigned)24);
|
2014-05-24 12:47:33 -04:00
|
|
|
|
2015-10-23 10:21:12 -04:00
|
|
|
collection :: set_enabled(library, false);
|
2015-11-19 13:48:59 -05:00
|
|
|
test_equal(queue_size(q), (unsigned)0);
|
2014-05-24 12:47:33 -04:00
|
|
|
|
2015-10-23 10:21:12 -04:00
|
|
|
collection :: set_enabled(library, true);
|
2015-11-19 13:48:59 -05:00
|
|
|
test_equal(queue_size(q), (unsigned)24);
|
2014-05-24 12:47:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_update()
|
|
|
|
{
|
2015-11-16 09:12:15 -05:00
|
|
|
queue *q = collection :: get_queue();
|
2015-08-31 08:11:24 -04:00
|
|
|
test_rm_library_dirs();
|
2014-05-24 12:47:33 -04:00
|
|
|
|
2015-10-23 10:21:12 -04:00
|
|
|
collection :: update_all();
|
2015-11-10 13:56:54 -05:00
|
|
|
test_equal(idle_run_task(), true);
|
2015-11-19 13:48:59 -05:00
|
|
|
test_equal(queue_size(q), (unsigned)21);
|
2014-05-24 12:47:33 -04:00
|
|
|
|
|
|
|
for (unsigned int i = 0; i < 4; i++)
|
2015-11-10 13:56:54 -05:00
|
|
|
test_equal(idle_run_task(), (i < 3) ? true : false);
|
2015-11-19 13:48:59 -05:00
|
|
|
test_equal(queue_size(q), (unsigned)21);
|
2014-05-24 12:47:33 -04:00
|
|
|
|
|
|
|
|
2015-08-31 08:11:24 -04:00
|
|
|
test_generate_library();
|
2014-05-24 12:47:33 -04:00
|
|
|
|
2015-10-23 10:21:12 -04:00
|
|
|
collection :: update_all();
|
2015-11-10 13:56:54 -05:00
|
|
|
test_equal(idle_run_task(), true);
|
2015-11-19 13:48:59 -05:00
|
|
|
test_equal(queue_size(q), (unsigned)21);
|
2014-05-24 12:47:33 -04:00
|
|
|
|
|
|
|
for (unsigned int i = 0; i < 6; i++)
|
2015-11-10 13:56:54 -05:00
|
|
|
test_equal(idle_run_task(), (i < 5) ? true : false);
|
2015-11-19 13:48:59 -05:00
|
|
|
test_equal(queue_size(q), (unsigned)35);
|
2014-05-24 12:47:33 -04:00
|
|
|
}
|
|
|
|
|
2015-08-31 08:11:24 -04:00
|
|
|
DECLARE_UNIT_TESTS(
|
2015-12-05 08:55:24 -05:00
|
|
|
UNIT_TEST("Collection Initialization", test_init),
|
2015-12-05 09:36:14 -05:00
|
|
|
UNIT_TEST("Collection Add Path", test_add),
|
2015-12-05 10:21:24 -05:00
|
|
|
UNIT_TEST("Collection Remove Path", test_remove),
|
2015-08-31 08:11:24 -04:00
|
|
|
UNIT_TEST("Library Enable and Disable", test_enable),
|
|
|
|
UNIT_TEST("Library Update Path", test_update),
|
|
|
|
);
|