Work in progress

Added test for temp files, getter for filename, and wrappers for fwrite, fprintf, and fgets
This commit is contained in:
Michael Tryby
2019-04-01 18:05:02 -04:00
parent a0b08921fc
commit 2c6d4ca74d
4 changed files with 75 additions and 8 deletions

View File

@@ -7,17 +7,11 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set (test_source
./test_errormanager.cpp
../../src/util/errormanager.c
)
add_executable(test_errormanager ${test_source})
add_executable(test_errormanager ./test_errormanager.cpp ../../src/util/errormanager.c)
target_include_directories(test_errormanager PUBLIC ../../src/)
target_link_libraries(test_errormanager ${Boost_LIBRARIES})
add_executable(test_filemanager ./test_filemanager.cpp ../../src/util/filemanager.c)
target_include_directories(test_filemanager PUBLIC ../../src/)
target_link_libraries(test_filemanager ${Boost_LIBRARIES})

View File

@@ -14,6 +14,7 @@
#define BOOST_TEST_MODULE filemanager
#include <boost/test/unit_test.hpp>
#include <boost/filesystem.hpp>
#include "util/filemanager.h"
@@ -21,6 +22,15 @@
#define DATA_PATH_OUTPUT "./example1.out"
boost::test_tools::predicate_result check_string(std::string test, std::string ref)
{
if (ref.compare(test) == 0)
return true;
else
return false;
}
BOOST_AUTO_TEST_SUITE(test_filemanager)
@@ -57,7 +67,7 @@ struct Fixture{
file_handle = NULL;
file_handle = create_file_manager();
open_file(file_handle, DATA_PATH_OUTPUT, "rb");
open_file(file_handle, NULL, "wt");
}
~Fixture() {
close_file(file_handle);
@@ -67,5 +77,18 @@ struct Fixture{
file_handle_t *file_handle;
};
BOOST_FIXTURE_TEST_CASE(test_temp_file, Fixture)
{
char *filename;
printf_file(file_handle, "%s", "This is a test.");
get_filename(file_handle, &filename);
//BOOST_CHECK(check_string(filename, "./test_file.txt"));
BOOST_CHECK(boost::filesystem::exists(filename) == true);
free(filename);
}
BOOST_AUTO_TEST_SUITE_END()