Add unit tests for FileIO: canSeekBeyondEOF fails
This commit is contained in:
parent
c905bd7a13
commit
2732c10a86
@ -19,23 +19,28 @@ endforeach()
|
||||
|
||||
add_executable(unit_tests mainTestRunner.cpp
|
||||
gtestwrapper.h
|
||||
test_basicio.cpp
|
||||
test_types.cpp
|
||||
test_tiffheader.cpp
|
||||
test_futils.cpp
|
||||
test_enforce.cpp
|
||||
test_safe_op.cpp
|
||||
test_XmpKey.cpp
|
||||
test_DateValue.cpp
|
||||
test_TimeValue.cpp
|
||||
test_XmpKey.cpp
|
||||
test_basicio.cpp
|
||||
test_cr2header_int.cpp
|
||||
test_enforce.cpp
|
||||
test_FileIo.cpp
|
||||
test_futils.cpp
|
||||
test_helper_functions.cpp
|
||||
test_slice.cpp
|
||||
test_image_int.cpp
|
||||
test_safe_op.cpp
|
||||
test_slice.cpp
|
||||
test_tiffheader.cpp
|
||||
test_types.cpp
|
||||
${unit_tests_exiv2lib_SOURCES}
|
||||
)
|
||||
|
||||
target_compile_definitions(unit_tests PRIVATE exiv2lib_STATIC)
|
||||
target_compile_definitions(unit_tests
|
||||
PRIVATE
|
||||
exiv2lib_STATIC
|
||||
TESTDATA_PATH="${PROJECT_SOURCE_DIR}/test/data"
|
||||
)
|
||||
|
||||
if (exiv2lib_COMPILE_DEFINITIONS)
|
||||
target_compile_definitions(unit_tests PRIVATE ${exiv2lib_COMPILE_DEFINITIONS})
|
||||
|
||||
74
unitTests/test_FileIo.cpp
Normal file
74
unitTests/test_FileIo.cpp
Normal file
@ -0,0 +1,74 @@
|
||||
#include "basicio.hpp"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
using namespace Exiv2;
|
||||
|
||||
namespace
|
||||
{
|
||||
const std::string testData(TESTDATA_PATH);
|
||||
const std::string imagePath(testData + "/DSC_3079.jpg");
|
||||
} // namespace
|
||||
|
||||
TEST(AFileIO, canBeInstantiatedWithFilePath)
|
||||
{
|
||||
ASSERT_NO_THROW(FileIo file(imagePath));
|
||||
}
|
||||
|
||||
TEST(AFileIO, canBeOpenInReadBinaryMode)
|
||||
{
|
||||
FileIo file(imagePath);
|
||||
ASSERT_EQ(0, file.open());
|
||||
}
|
||||
|
||||
TEST(AFileIO, isOpenDoItsJob)
|
||||
{
|
||||
FileIo file(imagePath);
|
||||
ASSERT_FALSE(file.isopen());
|
||||
file.open();
|
||||
ASSERT_TRUE(file.isopen());
|
||||
}
|
||||
|
||||
TEST(AFileIO, returnsFileSizeIfItsOpened)
|
||||
{
|
||||
FileIo file(imagePath);
|
||||
file.open();
|
||||
ASSERT_EQ(118685, file.size());
|
||||
}
|
||||
|
||||
TEST(AFileIO, returnsFileSizeEvenWhenFileItIsNotOpened)
|
||||
{
|
||||
FileIo file(imagePath);
|
||||
ASSERT_EQ(118685, file.size());
|
||||
}
|
||||
|
||||
TEST(AFileIO, isOpenedAtPosition0)
|
||||
{
|
||||
FileIo file(imagePath);
|
||||
file.open();
|
||||
ASSERT_EQ(0, file.tell());
|
||||
}
|
||||
|
||||
TEST(AFileIO, canSeekToExistingPositions)
|
||||
{
|
||||
FileIo file(imagePath);
|
||||
file.open();
|
||||
|
||||
ASSERT_EQ(0, file.seek(100, BasicIo::beg));
|
||||
ASSERT_EQ(0, file.seek(-50, BasicIo::cur));
|
||||
ASSERT_EQ(0, file.seek(-50, BasicIo::end));
|
||||
|
||||
ASSERT_FALSE(file.error());
|
||||
ASSERT_FALSE(file.eof());
|
||||
}
|
||||
|
||||
TEST(AFileIO, canSeekBeyondEOF)
|
||||
{
|
||||
FileIo file(imagePath);
|
||||
file.open();
|
||||
|
||||
// POSIX allows seeking beyond the existing end of file.
|
||||
ASSERT_EQ(0, file.seek(200000, BasicIo::beg));
|
||||
ASSERT_FALSE(file.error());
|
||||
ASSERT_FALSE(file.eof());
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user