103 lines
2.8 KiB
C++
103 lines
2.8 KiB
C++
/**
|
|
* Copyright 2014 (c) Anna Schumaker.
|
|
*/
|
|
#include <core/tags/library.h>
|
|
#include "../test.h"
|
|
|
|
static void test_verify_zelda(struct library *library)
|
|
{
|
|
const struct db_ops *library_ops = test_library_ops();
|
|
test_equal(library->li_enabled, true);
|
|
test_equal(library->li_size, 0);
|
|
test_str_equal(library_ops->dbe_key(library), "/home/Zelda/Music");
|
|
}
|
|
|
|
static void test_verify_link(struct library *library)
|
|
{
|
|
const struct db_ops *library_ops = test_library_ops();
|
|
test_equal(library->li_enabled, false);
|
|
test_equal(library->li_size, 0);
|
|
test_str_equal(library_ops->dbe_key(library), "/home/Link/Music");
|
|
}
|
|
|
|
static void test_library()
|
|
{
|
|
const struct db_ops *library_ops = test_library_ops();
|
|
struct library *link, *zelda, *library;
|
|
file f;
|
|
|
|
link = (struct library *)library_ops->dbe_alloc("/home/Link/Music");
|
|
zelda = (struct library *)library_ops->dbe_alloc("/home/Zelda/Music");
|
|
|
|
library_set_enabled(link, false);
|
|
test_verify_link(link);
|
|
test_verify_zelda(zelda);
|
|
|
|
link->li_size = 21;
|
|
zelda->li_size = 42;
|
|
|
|
file_init(&f, "library_tag", 0);
|
|
file_open(&f, OPEN_WRITE);
|
|
library_ops->dbe_write(&f, link);
|
|
file_writef(&f, "\n");
|
|
library_ops->dbe_write(&f, zelda);
|
|
file_close(&f);
|
|
|
|
file_open(&f, OPEN_READ);
|
|
library = (struct library *)library_ops->dbe_read(&f);
|
|
test_verify_link(library);
|
|
test_equal(library_file(library, "navi.mp3"), "/home/Link/Music/navi.mp3");
|
|
library_ops->dbe_free(library);
|
|
|
|
library = (struct library *)library_ops->dbe_read(&f);
|
|
file_close(&f);
|
|
test_verify_zelda(library);
|
|
test_equal(library_file(library, "impa.ogg"), "/home/Zelda/Music/impa.ogg");
|
|
|
|
library_ops->dbe_free(link);
|
|
library_ops->dbe_free(zelda);
|
|
library_ops->dbe_free(library);
|
|
}
|
|
|
|
static void test_library_db()
|
|
{
|
|
const struct db_ops *library_ops = test_library_ops();
|
|
struct library *library, *library2;
|
|
struct database library_db;
|
|
|
|
test_not_equal(library_db_get(), NULL);
|
|
test_equal(library_db_get()->db_size, 0);
|
|
|
|
library_db_init();
|
|
library = library_find("/home/Zelda/Music");
|
|
test_verify_zelda(library);
|
|
|
|
test_equal(library_db_get()->db_size, 1);
|
|
test_equal(library_find("/home/Zelda/Music"), library);
|
|
test_equal(library_get(0), library);
|
|
test_equal(library_get(1), (struct library *)NULL);
|
|
|
|
db_init(&library_db, "library.db", false, library_ops);
|
|
db_load(&library_db);
|
|
test_equal(library_db.db_size, 1);
|
|
test_equal(db_actual_size(&library_db), 1);
|
|
|
|
library2 = LIBRARY(db_at(&library_db, 0));
|
|
test_not_equal(library2, NULL);
|
|
test_verify_zelda(library2);
|
|
|
|
library_remove(library);
|
|
test_equal(library_get(0), (struct library *)NULL);
|
|
test_equal(library_db_get()->db_size, 0);
|
|
|
|
library_db_deinit();
|
|
db_deinit(&library_db);
|
|
db_load(&library_db);
|
|
test_equal(library_db.db_size, 0);
|
|
}
|
|
|
|
DECLARE_UNIT_TESTS(
|
|
UNIT_TEST("Library Tag", test_library),
|
|
UNIT_TEST("Library Database", test_library_db),
|
|
);
|