c88746d2da
I move all of the core tests into the core/ directory to keep them together. Gui unit tests will be put in new directories. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
72 lines
1.5 KiB
C++
72 lines
1.5 KiB
C++
/*
|
|
* Copyright 2014 (c) Anna Schumaker.
|
|
*/
|
|
#include <core/file.h>
|
|
#include <tests/test.h>
|
|
|
|
|
|
static void test_filepath()
|
|
{
|
|
File a("", 0);
|
|
File b("file.txt", 0);
|
|
|
|
test_equal(a.get_version(), (unsigned)0);
|
|
test_equal((std::string)a.get_filepath(), (std::string)"");
|
|
|
|
test_equal(b.get_version(), (unsigned)0);
|
|
test_equal((std::string)b.get_filepath(), test :: data_file("file.txt"));
|
|
|
|
test_equal(a.exists(), false);
|
|
test_equal(b.exists(), false);
|
|
test_equal(test :: data_dir_exists(), false);
|
|
}
|
|
|
|
static void test_open()
|
|
{
|
|
File a("", 0);
|
|
|
|
test_equal(a.open(OPEN_READ), false);
|
|
test_equal(a.open(OPEN_WRITE), false);
|
|
|
|
File b("file.txt", 0);
|
|
test_equal(b.open(NOT_OPEN), false);
|
|
test_equal(b.open(OPEN_READ), false);
|
|
test_equal(b.open(OPEN_WRITE), true);
|
|
test_equal(b.open(OPEN_WRITE), false);
|
|
b.close();
|
|
|
|
test_equal(test :: data_file_exists("file.txt"), true);
|
|
}
|
|
|
|
static void test_io()
|
|
{
|
|
File a("file.txt", 1);
|
|
|
|
test_equal(a.open(OPEN_WRITE), true);
|
|
a << "ABCDE FGHIJ KLMNO PQRST UVWXYZ" << std::endl;
|
|
a.close();
|
|
test_equal(a.exists(), true);
|
|
|
|
File b("file.txt", 0);
|
|
std::string res;
|
|
|
|
test_equal(b.open(OPEN_READ), true);
|
|
test_equal(b.get_version(), (unsigned)1);
|
|
b >> res;
|
|
test_equal(res, (std::string)"ABCDE");
|
|
b >> res;
|
|
test_equal(res, (std::string)"FGHIJ");
|
|
res = b.getline();
|
|
test_equal(res, (std::string)"KLMNO PQRST UVWXYZ");
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
test :: rm_data_dir();
|
|
|
|
run_test("File Constructor Test", test_filepath);
|
|
run_test("File Open Test", test_open);
|
|
run_test("File I/O Test", test_io);
|
|
return 0;
|
|
}
|