From 235087af4ef2d583fded0eaaebf83f061214c66e Mon Sep 17 00:00:00 2001 From: Luis Diaz Mas Date: Fri, 24 Apr 2020 07:25:56 +0200 Subject: [PATCH] Do not call tell() in File::eof() - Fix tests & performance --- src/basicio.cpp | 3 +-- tests/bugfixes/github/test_issue_428.py | 7 +++++-- tests/suite.conf | 1 + unitTests/test_FileIo.cpp | 4 ++-- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/basicio.cpp b/src/basicio.cpp index faf7fe9a..f4223f74 100644 --- a/src/basicio.cpp +++ b/src/basicio.cpp @@ -1022,8 +1022,7 @@ namespace Exiv2 { bool FileIo::eof() const { - assert(p_->fp_ != 0); - return feof(p_->fp_) != 0 || tell() >= (long) size() ; + return std::feof(p_->fp_) != 0; } std::string FileIo::path() const diff --git a/tests/bugfixes/github/test_issue_428.py b/tests/bugfixes/github/test_issue_428.py index 9e72c72a..24cddd2c 100644 --- a/tests/bugfixes/github/test_issue_428.py +++ b/tests/bugfixes/github/test_issue_428.py @@ -13,19 +13,22 @@ class PngReadRawProfile(metaclass=system_tests.CaseMeta): filenames = [ system_tests.path("$data_path/issue_428_poc1.png"), - system_tests.path("$data_path/issue_428_poc2.png"), system_tests.path("$data_path/issue_428_poc3.png"), system_tests.path("$data_path/issue_428_poc4.png"), system_tests.path("$data_path/issue_428_poc5.png"), system_tests.path("$data_path/issue_428_poc8.png"), + system_tests.path("$data_path/issue_428_poc2.png"), system_tests.path("$data_path/issue_428_poc6.png"), system_tests.path("$data_path/issue_428_poc7.png"), ] commands = ["$exiv2 " + fname for fname in filenames] stdout = [""] * len(filenames) - stderr = [ stderr_exception(fname) for fname in filenames[0:6] ] + stderr = [ stderr_exception(fname) for fname in filenames[0:5] ] + stderr.append("""$exiv2_exception_message """ + filenames[5] + """: +$kerInputDataReadFailed +""") stderr.append("""Error: XMP Toolkit error 201: XML parsing failure Warning: Failed to decode XMP metadata. """ + stderr_exception(filenames[6])) diff --git a/tests/suite.conf b/tests/suite.conf index a3211945..a6006d12 100644 --- a/tests/suite.conf +++ b/tests/suite.conf @@ -22,6 +22,7 @@ taglist: ${ENV:exiv2_path}/taglist${ENV:binary_extension} [variables] kerOffsetOutOfRange: Offset out of range kerFailedToReadImageData: Failed to read image data +kerInputDataReadFailed: Failed to read input data kerCorruptedMetadata: corrupted image metadata kerInvalidMalloc: invalid memory allocation request kerInvalidTypeValue: invalid type in tiff structure diff --git a/unitTests/test_FileIo.cpp b/unitTests/test_FileIo.cpp index 1cfbda11..363f66a1 100644 --- a/unitTests/test_FileIo.cpp +++ b/unitTests/test_FileIo.cpp @@ -33,13 +33,13 @@ TEST(AFileIO, returnsFileSizeIfItsOpened) { FileIo file(imagePath); file.open(); - ASSERT_EQ(118685, file.size()); + ASSERT_EQ(118685ul, file.size()); } TEST(AFileIO, returnsFileSizeEvenWhenFileItIsNotOpened) { FileIo file(imagePath); - ASSERT_EQ(118685, file.size()); + ASSERT_EQ(118685ul, file.size()); } TEST(AFileIO, isOpenedAtPosition0)