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-11-16 09:12:15 -05:00
|
|
|
static queue *Q_NULL = NULL;
|
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-11-16 09:12:15 -05:00
|
|
|
queue *q = collection :: get_queue();
|
2014-05-24 12:47:33 -04:00
|
|
|
|
2015-08-31 08:11:24 -04:00
|
|
|
test_cp_data_dir();
|
2015-09-29 16:25:16 -04:00
|
|
|
filter_init();
|
2015-11-12 10:24:27 -05:00
|
|
|
tags_init();
|
2015-11-24 08:18:31 -05:00
|
|
|
collection :: init(NULL);
|
2014-05-24 12:47:33 -04:00
|
|
|
|
2015-11-23 08:36:29 -05:00
|
|
|
test_not_equal(q, Q_NULL);
|
|
|
|
test_equal(queue_has_flag(q, Q_ENABLED), true);
|
|
|
|
test_equal(queue_has_flag(q, Q_REPEAT), 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_enable()
|
|
|
|
{
|
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_remove()
|
|
|
|
{
|
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 :: remove(LIB_NULL);
|
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 :: remove(library);
|
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 :: remove(library);
|
2015-11-19 13:48:59 -05:00
|
|
|
test_equal(queue_size(q), (unsigned)0);
|
2014-05-24 12:47:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_add()
|
|
|
|
{
|
2015-11-16 09:12:15 -05:00
|
|
|
queue *q = collection :: get_queue();
|
2014-05-24 12:47:33 -04:00
|
|
|
|
2015-08-31 08:11:24 -04:00
|
|
|
test_generate_library();
|
2015-10-23 10:21:12 -04:00
|
|
|
collection :: add("/tmp/ocarina/");
|
2014-05-24 12:47:33 -04:00
|
|
|
|
2015-11-19 13:48:59 -05:00
|
|
|
test_equal(queue_size(q), (unsigned)0);
|
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)0);
|
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), i * 7);
|
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(
|
|
|
|
UNIT_TEST("Library Init", test_init),
|
|
|
|
UNIT_TEST("Library Enable and Disable", test_enable),
|
|
|
|
UNIT_TEST("Library Delete Path", test_remove),
|
|
|
|
UNIT_TEST("Library Add Path", test_add),
|
|
|
|
UNIT_TEST("Library Update Path", test_update),
|
|
|
|
);
|