ocarina/tests/library/library.cpp

90 lines
1.7 KiB
C++

/*
* Copyright 2013 (c) Anna Schumaker.
*/
#include <library.h>
#include <print.h>
#include <stdlib.h>
void gen_library()
{
system("tests/library/gen_library.sh");
print("\n");
}
void test_add_dir(const std::string &test, const std::string &dir, bool expected)
{
print("Test %s: ", test.c_str());
if (library :: add_path(dir.c_str()) == expected)
print("PASSED\n");
else
print("FAILED\n");
library :: print_db(library :: DB_LIBRARY);
}
void test_del_dir(const std::string &test, const unsigned int path_id)
{
print("Test %s\n", test.c_str());
library :: del_path(path_id);
library :: print_db(library :: DB_LIBRARY);
}
/* Add paths library that SHOULD fail */
void test_0()
{
test_add_dir("0a", "/tmp/library/error", false);
test_add_dir("0b", "/tmp/library/file", false);
print("\n");
}
/* Simple library path operations */
void test_1()
{
test_add_dir("1a", "/tmp/library/0", true);
library :: del_path(0);
print("\n");
}
/* Test multiple paths */
void test_2()
{
library :: reset();
test_add_dir("2a", "/tmp/library/0", true);
test_add_dir("2b", "/tmp/library/1", true);
test_add_dir("2c", "/tmp/library/2", true);
test_del_dir("2d", 1);
test_del_dir("2e", 0);
test_del_dir("2f", 2);
print("\n");
}
/* Test load and save of library db */
void test_3()
{
library :: reset();
test_add_dir("3a", "/tmp/library/0", true);
test_add_dir("3b", "/tmp/library/1", true);
test_add_dir("3c", "/tmp/library/2", true);
print("Test 3d\n");
library :: reset();
library :: print_db(library :: DB_LIBRARY);
print("Test 3e\n");
library :: init();
library :: print_db(library :: DB_LIBRARY);
print("\n");
}
int main(int argc, char **argv)
{
gen_library();
test_0();
test_1();
test_2();
test_3();
return 0;
}