diff --git a/unitTests/CMakeLists.txt b/unitTests/CMakeLists.txt index 735543ed..5b62c260 100644 --- a/unitTests/CMakeLists.txt +++ b/unitTests/CMakeLists.txt @@ -2,6 +2,7 @@ add_executable(unit_tests mainTestRunner.cpp gtestwrapper.h test_types.cpp test_tiffheader.cpp + test_futils.cpp ) #TODO Use GTest::GTest once we upgrade the minimum CMake version required diff --git a/unitTests/test_futils.cpp b/unitTests/test_futils.cpp new file mode 100644 index 00000000..238b9015 --- /dev/null +++ b/unitTests/test_futils.cpp @@ -0,0 +1,32 @@ +// File under test +#include + +// Auxiliary headers +#include +#include +#include + +#include + +using namespace Exiv2; + +TEST(strError, returnSuccessAfterClosingFile) +{ + std::string tmpFile("tmp.dat"); + std::ofstream auxFile(tmpFile.c_str()); + auxFile.close(); + ASSERT_STREQ("Success (errno = 0)", strError().c_str()); + std::remove(tmpFile.c_str()); +} + +TEST(strError, returnNoSuchFileOrDirectoryWhenTryingToOpenNonExistingFile) +{ + std::ifstream auxFile("nonExistingFile"); + ASSERT_STREQ("No such file or directory (errno = 2)", strError().c_str()); +} + +TEST(strError, doNotRecognizeUnknownError) +{ + errno = 9999; + ASSERT_STREQ("Unknown error 9999 (errno = 9999)", strError().c_str()); +}