/* * Copyright 2013 (c) Anna Schumaker. */ extern "C" { #include #include #include } #include #include "test.h" static struct library *LIB_NULL = NULL; static void test_init() { struct queue *q = collection :: get_queue(); GSList *list; filter_init(); tags_init(); collection_init(NULL); test_not_equal(q, NULL); test_equal(queue_has_flag(q, Q_ENABLED), true); test_equal(queue_has_flag(q, Q_REPEAT), true); test_equal(queue_has_flag(q, Q_SAVE_SORT), true); test_equal(queue_has_flag(q, Q_SAVE_FLAGS), true); test_equal(queue_has_flag(q, Q_ADD_FRONT), false); test_equal(queue_size(q), 0); list = q->q_sort; test_equal(g_slist_length(q->q_sort), 3); test_equal(GPOINTER_TO_INT(list->data), COMPARE_ARTIST); list = g_slist_next(list); test_equal(GPOINTER_TO_INT(list->data), COMPARE_YEAR); list = g_slist_next(list); test_equal(GPOINTER_TO_INT(list->data), COMPARE_TRACK); } static void test_add() { struct queue *q = collection :: get_queue(); struct library *lib; test_equal(collection_add("tests/Invalid"), NULL); lib = collection_add("tests/Music"); test_not_equal(lib, NULL); test_equal(lib->li_size, 0); test_equal(lib->li_enabled, true); test_equal(lib->li_path, "tests/Music"); test_equal(queue_size(q), 0); test_equal(idle_run_task(), true); /* collection validation */ test_equal(idle_run_task(), true); /* tests/Music/ */ test_equal(idle_run_task(), true); /* tests/Music/Hyrule Symphony/ */ test_equal(idle_run_task(), false); /* tests/Music/Ocarina of Time/ */ test_equal(track_db_get()->db_size, 48); test_equal(lib->li_size, 48); test_equal(queue_size(q), 48); } static void test_enable() { test_cp_data_dir(); filter_init(); tags_init(); collection_init(NULL); queue *q = collection :: get_queue(); struct library *library = library_get(0); collection :: set_enabled(LIB_NULL, true); test_equal(queue_size(q), (unsigned)24); collection :: set_enabled(library, false); test_equal(queue_size(q), (unsigned)0); collection :: set_enabled(library, true); test_equal(queue_size(q), (unsigned)24); collection :: set_enabled(library, true); test_equal(queue_size(q), (unsigned)24); collection :: set_enabled(library, false); test_equal(queue_size(q), (unsigned)0); collection :: set_enabled(library, true); test_equal(queue_size(q), (unsigned)24); } static void test_remove() { queue *q = collection :: get_queue(); struct library *library = library_get(0); collection :: remove(LIB_NULL); test_equal(queue_size(q), (unsigned)24); collection :: remove(library); test_equal(queue_size(q), (unsigned)0); collection :: remove(library); test_equal(queue_size(q), (unsigned)0); } static void test_update() { queue *q = collection :: get_queue(); test_rm_library_dirs(); collection :: update_all(); test_equal(idle_run_task(), true); test_equal(queue_size(q), (unsigned)21); for (unsigned int i = 0; i < 4; i++) test_equal(idle_run_task(), (i < 3) ? true : false); test_equal(queue_size(q), (unsigned)21); test_generate_library(); collection :: update_all(); test_equal(idle_run_task(), true); test_equal(queue_size(q), (unsigned)21); for (unsigned int i = 0; i < 6; i++) test_equal(idle_run_task(), (i < 5) ? true : false); test_equal(queue_size(q), (unsigned)35); } DECLARE_UNIT_TESTS( UNIT_TEST("Collection Initialization", test_init), UNIT_TEST("Collection Add Path", test_add), UNIT_TEST("Library Enable and Disable", test_enable), UNIT_TEST("Library Delete Path", test_remove), UNIT_TEST("Library Update Path", test_update), );