119 lines
2.6 KiB
C++
119 lines
2.6 KiB
C++
/*
|
|
* Copyright 2013 (c) Anna Schumaker.
|
|
*/
|
|
extern "C" {
|
|
#include <core/filter.h>
|
|
#include <core/idle.h>
|
|
}
|
|
#include <core/library.h>
|
|
#include <core/tags/tags.h>
|
|
#include "test.h"
|
|
|
|
static Queue *Q_NULL = NULL;
|
|
static struct library *LIB_NULL = NULL;
|
|
|
|
static void test_init()
|
|
{
|
|
Queue *q = collection :: get_queue();
|
|
|
|
test_not_equal(q, Q_NULL);
|
|
test_equal(q->has_flag(Q_ENABLED), true);
|
|
test_equal(q->has_flag(Q_REPEAT), true);
|
|
|
|
test_cp_data_dir();
|
|
filter_init();
|
|
tags :: init();
|
|
collection :: init();
|
|
|
|
test_equal(q->size(), (unsigned)24);
|
|
}
|
|
|
|
static void test_enable()
|
|
{
|
|
Queue *q = collection :: get_queue();
|
|
struct library *library = library_get(0);
|
|
|
|
collection :: set_enabled(LIB_NULL, true);
|
|
test_equal(q->size(), (unsigned)24);
|
|
|
|
collection :: set_enabled(library, false);
|
|
test_equal(q->size(), (unsigned)0);
|
|
|
|
collection :: set_enabled(library, true);
|
|
test_equal(q->size(), (unsigned)24);
|
|
|
|
collection :: set_enabled(library, true);
|
|
test_equal(q->size(), (unsigned)24);
|
|
|
|
collection :: set_enabled(library, false);
|
|
test_equal(q->size(), (unsigned)0);
|
|
|
|
collection :: set_enabled(library, true);
|
|
test_equal(q->size(), (unsigned)24);
|
|
}
|
|
|
|
static void test_remove()
|
|
{
|
|
Queue *q = collection :: get_queue();
|
|
struct library *library = library_get(0);
|
|
|
|
collection :: remove(LIB_NULL);
|
|
test_equal(q->size(), (unsigned)24);
|
|
|
|
collection :: remove(library);
|
|
test_equal(q->size(), (unsigned)0);
|
|
|
|
collection :: remove(library);
|
|
test_equal(q->size(), (unsigned)0);
|
|
}
|
|
|
|
static void test_add()
|
|
{
|
|
Queue *q = collection :: get_queue();
|
|
|
|
test_generate_library();
|
|
collection :: add("/tmp/ocarina/");
|
|
|
|
test_equal(q->size(), (unsigned)0);
|
|
test_equal(idle_run_task(), true);
|
|
test_equal(q->size(), (unsigned)0);
|
|
|
|
for (unsigned int i = 0; i < 6; i++) {
|
|
test_equal(idle_run_task(), (i < 5) ? true : false);
|
|
test_equal(q->size(), i * 7);
|
|
}
|
|
}
|
|
|
|
static void test_update()
|
|
{
|
|
Queue *q = collection :: get_queue();
|
|
test_rm_library_dirs();
|
|
|
|
collection :: update_all();
|
|
test_equal(idle_run_task(), true);
|
|
test_equal(q->size(), (unsigned)21);
|
|
|
|
for (unsigned int i = 0; i < 4; i++)
|
|
test_equal(idle_run_task(), (i < 3) ? true : false);
|
|
test_equal(q->size(), (unsigned)21);
|
|
|
|
|
|
test_generate_library();
|
|
|
|
collection :: update_all();
|
|
test_equal(idle_run_task(), true);
|
|
test_equal(q->size(), (unsigned)21);
|
|
|
|
for (unsigned int i = 0; i < 6; i++)
|
|
test_equal(idle_run_task(), (i < 5) ? true : false);
|
|
test_equal(q->size(), (unsigned)35);
|
|
}
|
|
|
|
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),
|
|
);
|