ocarina/tests/library.cpp

116 lines
2.6 KiB
C++

/*
* Copyright 2013 (c) Anna Schumaker.
*/
#include <core/idle.h>
#include <core/library.h>
#include "test.h"
static Queue *Q_NULL = NULL;
static Library *LIB_NULL = NULL;
static void test_init()
{
Queue *q = library :: get_queue();
test_not_equal(q, Q_NULL);
test_equal(q->has_flag(Q_ENABLED), true);
test_equal(q->has_flag(Q_REPEAT), true);
tagdb :: init();
library :: init();
test_equal(q->size(), (unsigned)24);
}
static void test_enable()
{
Queue *q = library :: get_queue();
Library *library = tagdb :: lookup_library(0);
library :: set_enabled(LIB_NULL, true);
test_equal(q->size(), (unsigned)24);
library :: set_enabled(library, false);
test_equal(q->size(), (unsigned)0);
library :: set_enabled(library, true);
test_equal(q->size(), (unsigned)24);
library :: set_enabled(library, true);
test_equal(q->size(), (unsigned)24);
library :: set_enabled(library, false);
test_equal(q->size(), (unsigned)0);
library :: set_enabled(library, true);
test_equal(q->size(), (unsigned)24);
}
static void test_remove()
{
Queue *q = library :: get_queue();
Library *library = tagdb :: lookup_library(0);
library :: remove(LIB_NULL);
test_equal(q->size(), (unsigned)24);
library :: remove(library);
test_equal(q->size(), (unsigned)0);
library :: remove(library);
test_equal(q->size(), (unsigned)0);
}
static void test_add()
{
Queue *q = library :: get_queue();
test :: gen_library();
library :: 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 = library :: get_queue();
test :: rm_library_dirs();
library :: 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 :: gen_library();
library :: 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);
}
int main(int argc, char **argv)
{
test :: cp_data_dir();
run_test("Library Init Test", test_init);
run_test("Library Enable and Disable Test", test_enable);
run_test("Library Delete Path Test", test_remove);
run_test("Library Add Path Test", test_add);
run_test("Library Update Path Test", test_update);
}