/* * Copyright 2014 (c) Anna Schumaker. */ #include #include "test.h" static void test_filepath() { gchar *filepath = test_data_file("file.txt"); 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(), filepath); test_equal(a.exists(), false); test_equal(b.exists(), false); test_equal(test_data_file_exists(NULL), false); g_free(filepath); } 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"); } DECLARE_UNIT_TESTS( UNIT_TEST("File Constructor", test_filepath), UNIT_TEST("File Opening", test_open), UNIT_TEST("File I/O", test_io), );