74 lines
1.9 KiB
C++
74 lines
1.9 KiB
C++
/**
|
|
* Copyright 2014 (c) Anna Schumaker.
|
|
*/
|
|
#include <core/tags/library.h>
|
|
#include <tests/test.h>
|
|
|
|
static void test_library_tag()
|
|
{
|
|
Library library("/home/Zelda/Music");
|
|
File f("library_tag", 0);
|
|
|
|
test_equal(library.primary_key(), (std::string)"/home/Zelda/Music");
|
|
test_equal(library.size(), (unsigned)0);
|
|
test_equal(library.enabled(), true);
|
|
|
|
|
|
for (unsigned int i = 0; i < 42; i++)
|
|
library.inc_size();
|
|
test_equal(library.size(), (unsigned)42);
|
|
|
|
for (unsigned int i = 0; i < 21; i++)
|
|
library.dec_size();
|
|
test_equal(library.size(), (unsigned)21);
|
|
|
|
|
|
f.open(OPEN_WRITE);
|
|
library.write(f);
|
|
f.close();
|
|
|
|
library = Library();
|
|
test_equal(library.primary_key(), (std::string)"");
|
|
test_equal(library.size(), (unsigned)0);
|
|
test_equal(library.enabled(), false);
|
|
|
|
f.open(OPEN_READ);
|
|
library.read(f);
|
|
f.close();
|
|
|
|
test_equal(library.primary_key(), (std::string)"/home/Zelda/Music");
|
|
test_equal(library.size(), (unsigned)0); /* _size is not saved to disk. */
|
|
test_equal(library.enabled(), true);
|
|
}
|
|
|
|
static void test_library_tag_lookup()
|
|
{
|
|
Database<Library> library_db("library.db", false);
|
|
Library *library;
|
|
|
|
test_equal(tags :: library_size(), (unsigned)0);
|
|
|
|
library = tags :: get_library("/home/Zelda/Music");
|
|
test_equal(library->primary_key(), (std::string)"/home/Zelda/Music");
|
|
test_equal(library->size(), (unsigned)0);
|
|
test_equal(library->enabled(), true);
|
|
|
|
test_equal(tags :: get_library("/home/Zelda/Music"), library);
|
|
test_equal(tags :: get_library(0), library);
|
|
test_equal(tags :: get_library(1), (Library *)NULL);
|
|
|
|
library_db.load();
|
|
test_equal(library_db.actual_size(), (unsigned)tags :: library_size());
|
|
|
|
tags :: remove_library(library);
|
|
test_equal(tags :: get_library(0), (Library *)NULL);
|
|
test_equal(tags :: library_size(), (unsigned)1);
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
test :: run("Library Tag Test", test_library_tag);
|
|
test :: run("Library Tag Lookup Test", test_library_tag_lookup);
|
|
return 0;
|
|
}
|