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-10 14:18:11 -05:00
|
|
|
}
|
2014-06-05 10:19:22 -04:00
|
|
|
#include <core/library.h>
|
2014-12-02 08:16:22 -05:00
|
|
|
#include <core/tags/tags.h>
|
2015-08-31 08:11:24 -04:00
|
|
|
#include "test.h"
|
2014-05-24 12:47:33 -04: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-10-23 10:21:12 -04:00
|
|
|
Queue *q = collection :: get_queue();
|
2014-05-24 12:47:33 -04:00
|
|
|
|
|
|
|
test_not_equal(q, Q_NULL);
|
|
|
|
test_equal(q->has_flag(Q_ENABLED), true);
|
|
|
|
test_equal(q->has_flag(Q_REPEAT), true);
|
|
|
|
|
2015-08-31 08:11:24 -04:00
|
|
|
test_cp_data_dir();
|
2015-09-29 16:25:16 -04:00
|
|
|
filter_init();
|
2014-12-02 08:16:22 -05:00
|
|
|
tags :: init();
|
2015-10-23 10:21:12 -04:00
|
|
|
collection :: init();
|
2014-05-24 12:47:33 -04:00
|
|
|
|
|
|
|
test_equal(q->size(), (unsigned)24);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_enable()
|
|
|
|
{
|
2015-10-23 10:21:12 -04: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);
|
2014-05-24 12:47:33 -04:00
|
|
|
test_equal(q->size(), (unsigned)24);
|
|
|
|
|
2015-10-23 10:21:12 -04:00
|
|
|
collection :: set_enabled(library, false);
|
2014-05-24 12:47:33 -04:00
|
|
|
test_equal(q->size(), (unsigned)0);
|
|
|
|
|
2015-10-23 10:21:12 -04:00
|
|
|
collection :: set_enabled(library, true);
|
2014-05-24 12:47:33 -04:00
|
|
|
test_equal(q->size(), (unsigned)24);
|
|
|
|
|
2015-10-23 10:21:12 -04:00
|
|
|
collection :: set_enabled(library, true);
|
2014-05-24 12:47:33 -04:00
|
|
|
test_equal(q->size(), (unsigned)24);
|
|
|
|
|
2015-10-23 10:21:12 -04:00
|
|
|
collection :: set_enabled(library, false);
|
2014-05-24 12:47:33 -04:00
|
|
|
test_equal(q->size(), (unsigned)0);
|
|
|
|
|
2015-10-23 10:21:12 -04:00
|
|
|
collection :: set_enabled(library, true);
|
2014-05-24 12:47:33 -04:00
|
|
|
test_equal(q->size(), (unsigned)24);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_remove()
|
|
|
|
{
|
2015-10-23 10:21:12 -04: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);
|
2014-05-24 12:47:33 -04:00
|
|
|
test_equal(q->size(), (unsigned)24);
|
|
|
|
|
2015-10-23 10:21:12 -04:00
|
|
|
collection :: remove(library);
|
2014-05-24 12:47:33 -04:00
|
|
|
test_equal(q->size(), (unsigned)0);
|
|
|
|
|
2015-10-23 10:21:12 -04:00
|
|
|
collection :: remove(library);
|
2014-05-24 12:47:33 -04:00
|
|
|
test_equal(q->size(), (unsigned)0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_add()
|
|
|
|
{
|
2015-10-23 10:21:12 -04: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
|
|
|
|
|
|
|
test_equal(q->size(), (unsigned)0);
|
2015-11-10 13:56:54 -05:00
|
|
|
test_equal(idle_run_task(), true);
|
2014-05-24 12:47:33 -04:00
|
|
|
test_equal(q->size(), (unsigned)0);
|
|
|
|
|
|
|
|
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);
|
2014-05-24 12:47:33 -04:00
|
|
|
test_equal(q->size(), i * 7);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_update()
|
|
|
|
{
|
2015-10-23 10:21:12 -04: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);
|
2014-05-24 12:47:33 -04:00
|
|
|
test_equal(q->size(), (unsigned)21);
|
|
|
|
|
|
|
|
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);
|
2014-05-24 12:47:33 -04:00
|
|
|
test_equal(q->size(), (unsigned)21);
|
|
|
|
|
|
|
|
|
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);
|
2014-05-24 12:47:33 -04:00
|
|
|
test_equal(q->size(), (unsigned)21);
|
|
|
|
|
|
|
|
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);
|
2014-05-24 12:47:33 -04:00
|
|
|
test_equal(q->size(), (unsigned)35);
|
|
|
|
}
|
|
|
|
|
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),
|
|
|
|
);
|