/* * Copyright 2013 (c) Anna Schumaker. */ #include #include #include #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); test_cp_data_dir(); tags :: init(); library :: init(); test_equal(q->size(), (unsigned)24); } static void test_enable() { Queue *q = library :: get_queue(); Library *library = tags :: get_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 = tags :: get_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_generate_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_generate_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); } 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), );