2014-11-12 08:16:53 -05:00
|
|
|
/**
|
|
|
|
* Copyright 2014 (c) Anna Schumaker.
|
|
|
|
*/
|
|
|
|
#include <core/tags/library.h>
|
2015-08-27 11:03:31 -04:00
|
|
|
#include "../test.h"
|
2014-11-12 08:16:53 -05:00
|
|
|
|
2015-10-23 10:21:12 -04:00
|
|
|
static void test_verify_empty(struct library *library)
|
2014-11-12 08:16:53 -05:00
|
|
|
{
|
2015-10-23 10:01:03 -04:00
|
|
|
test_equal(library->primary_key(), "");
|
|
|
|
test_equal(library->enabled(), false);
|
|
|
|
test_equal(library->size(), 0);
|
|
|
|
}
|
2014-11-12 08:16:53 -05:00
|
|
|
|
2015-10-23 10:21:12 -04:00
|
|
|
static void test_verify_zelda(struct library *library)
|
2015-10-23 10:01:03 -04:00
|
|
|
{
|
|
|
|
test_equal(library->primary_key(), "/home/Zelda/Music");
|
|
|
|
test_equal(library->enabled(), true);
|
|
|
|
test_equal(library->size(), 0);
|
|
|
|
}
|
2014-11-12 08:16:53 -05:00
|
|
|
|
2015-10-23 10:21:12 -04:00
|
|
|
static void test_verify_link(struct library *library)
|
2015-10-23 10:01:03 -04:00
|
|
|
{
|
|
|
|
test_equal(library->primary_key(), "/home/Link/Music");
|
|
|
|
test_equal(library->enabled(), false);
|
|
|
|
test_equal(library->size(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_library()
|
|
|
|
{
|
2015-10-23 10:21:12 -04:00
|
|
|
struct library *link = new struct library("/home/Link/Music");
|
|
|
|
struct library *zelda = new struct library("/home/Zelda/Music");
|
|
|
|
struct library *library = new struct library();
|
2015-10-23 10:01:03 -04:00
|
|
|
file f;
|
|
|
|
|
|
|
|
link->set_enabled(false);
|
|
|
|
test_verify_link(link);
|
|
|
|
test_verify_zelda(zelda);
|
|
|
|
test_verify_empty(library);
|
2014-11-13 08:31:47 -05:00
|
|
|
|
|
|
|
for (unsigned int i = 0; i < 42; i++)
|
2015-10-23 10:01:03 -04:00
|
|
|
zelda->inc_size();
|
|
|
|
test_equal(zelda->size(), 42);
|
2014-11-13 08:31:47 -05:00
|
|
|
|
|
|
|
for (unsigned int i = 0; i < 21; i++)
|
2015-10-23 10:01:03 -04:00
|
|
|
zelda->dec_size();
|
|
|
|
test_equal(zelda->size(), 21);
|
2014-11-13 08:31:47 -05:00
|
|
|
|
2014-11-12 08:16:53 -05:00
|
|
|
|
2015-09-10 10:33:24 -04:00
|
|
|
file_init(&f, "library_tag", 0);
|
2015-09-10 09:46:33 -04:00
|
|
|
file_open(&f, OPEN_WRITE);
|
2015-10-23 10:01:03 -04:00
|
|
|
link->write(f);
|
|
|
|
file_writef(&f, "\n");
|
|
|
|
zelda->write(f);
|
2015-09-10 09:12:48 -04:00
|
|
|
file_close(&f);
|
2014-11-12 08:16:53 -05:00
|
|
|
|
2015-09-10 09:46:33 -04:00
|
|
|
file_open(&f, OPEN_READ);
|
2015-10-23 10:01:03 -04:00
|
|
|
library->read(f);
|
|
|
|
test_verify_link(library);
|
|
|
|
|
|
|
|
library->read(f);
|
2015-09-10 09:12:48 -04:00
|
|
|
file_close(&f);
|
2015-10-23 10:01:03 -04:00
|
|
|
test_verify_zelda(library);
|
2014-11-12 08:16:53 -05:00
|
|
|
|
2015-10-23 10:01:03 -04:00
|
|
|
delete library;
|
|
|
|
delete zelda;
|
|
|
|
delete link;
|
2014-11-12 08:16:53 -05:00
|
|
|
}
|
|
|
|
|
2015-10-23 10:01:03 -04:00
|
|
|
static void test_library_db()
|
2014-11-17 08:30:54 -05:00
|
|
|
{
|
2015-10-23 10:21:12 -04:00
|
|
|
database<struct library> library_db;
|
|
|
|
struct library *library, *library2;
|
2014-11-17 08:30:54 -05:00
|
|
|
|
2015-10-23 10:01:03 -04:00
|
|
|
test_equal(tags :: library_size(), 0);
|
2014-11-17 08:30:54 -05:00
|
|
|
|
2015-09-28 09:45:50 -04:00
|
|
|
library_db_init();
|
2015-09-28 10:00:06 -04:00
|
|
|
library = library_find("/home/Zelda/Music");
|
2015-10-23 10:01:03 -04:00
|
|
|
test_verify_zelda(library);
|
2014-11-17 08:30:54 -05:00
|
|
|
|
2015-10-23 10:01:03 -04:00
|
|
|
test_equal(tags :: library_size(), 1);
|
2015-09-28 10:00:06 -04:00
|
|
|
test_equal(library_find("/home/Zelda/Music"), library);
|
2015-09-28 10:08:11 -04:00
|
|
|
test_equal(library_get(0), library);
|
|
|
|
test_equal(library_get(1), (struct library *)NULL);
|
2014-11-17 08:30:54 -05:00
|
|
|
|
2015-09-21 09:02:13 -04:00
|
|
|
db_init(&library_db, "library.db", false);
|
2015-09-17 08:12:25 -04:00
|
|
|
db_load(&library_db);
|
2015-10-23 10:01:03 -04:00
|
|
|
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);
|
2014-11-17 08:30:54 -05:00
|
|
|
|
2015-09-28 09:55:29 -04:00
|
|
|
library_remove(library);
|
2015-09-28 10:08:11 -04:00
|
|
|
test_equal(library_get(0), (struct library *)NULL);
|
2015-10-23 10:01:03 -04:00
|
|
|
test_equal(tags :: library_size(), 1);
|
|
|
|
|
2015-09-28 09:45:50 -04:00
|
|
|
library_db_deinit();
|
2015-10-23 10:01:03 -04:00
|
|
|
db_deinit(&library_db);
|
|
|
|
db_load(&library_db);
|
|
|
|
test_equal(library_db.db_size, 0);
|
2014-11-17 08:30:54 -05:00
|
|
|
}
|
|
|
|
|
2015-08-27 11:03:31 -04:00
|
|
|
DECLARE_UNIT_TESTS(
|
2015-10-23 10:01:03 -04:00
|
|
|
UNIT_TEST("Library Tag", test_library),
|
|
|
|
UNIT_TEST("Library Database", test_library_db),
|
2015-08-27 11:03:31 -04:00
|
|
|
);
|