446f1228cf
To help with finding the full path of files that are located in the library's directory. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
105 lines
2.5 KiB
C++
105 lines
2.5 KiB
C++
/**
|
|
* Copyright 2014 (c) Anna Schumaker.
|
|
*/
|
|
#include <core/tags/library.h>
|
|
#include "../test.h"
|
|
|
|
static void test_verify_empty(struct library *library)
|
|
{
|
|
test_equal(library->primary_key(), "");
|
|
test_equal(library->li_enabled, false);
|
|
test_equal(library->li_size, 0);
|
|
}
|
|
|
|
static void test_verify_zelda(struct library *library)
|
|
{
|
|
test_equal(library->primary_key(), "/home/Zelda/Music");
|
|
test_equal(library->li_enabled, true);
|
|
test_equal(library->li_size, 0);
|
|
}
|
|
|
|
static void test_verify_link(struct library *library)
|
|
{
|
|
test_equal(library->primary_key(), "/home/Link/Music");
|
|
test_equal(library->li_enabled, false);
|
|
test_equal(library->li_size, 0);
|
|
}
|
|
|
|
static void test_library()
|
|
{
|
|
struct library *link = new struct library("/home/Link/Music");
|
|
struct library *zelda = new struct library("/home/Zelda/Music");
|
|
struct library *library = new struct library();
|
|
file f;
|
|
|
|
library_set_enabled(link, false);
|
|
test_verify_link(link);
|
|
test_verify_zelda(zelda);
|
|
test_verify_empty(library);
|
|
|
|
link->li_size = 21;
|
|
zelda->li_size = 42;
|
|
|
|
file_init(&f, "library_tag", 0);
|
|
file_open(&f, OPEN_WRITE);
|
|
link->write(f);
|
|
file_writef(&f, "\n");
|
|
zelda->write(f);
|
|
file_close(&f);
|
|
|
|
file_open(&f, OPEN_READ);
|
|
library->read(f);
|
|
test_verify_link(library);
|
|
test_equal(library_file(library, "navi.mp3"), "/home/Link/Music/navi.mp3");
|
|
|
|
library->read(f);
|
|
file_close(&f);
|
|
test_verify_zelda(library);
|
|
test_equal(library_file(library, "impa.ogg"), "/home/Zelda/Music/impa.ogg");
|
|
|
|
delete library;
|
|
delete zelda;
|
|
delete link;
|
|
}
|
|
|
|
static void test_library_db()
|
|
{
|
|
database<struct library> library_db;
|
|
struct library *library, *library2;
|
|
|
|
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);
|
|
db_load(&library_db);
|
|
test_equal(library_db.db_size, 1);
|
|
test_equal(db_actual_size(&library_db), 1);
|
|
|
|
library2 = 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),
|
|
);
|