Skip to content

use more mocking in unit tests - #9383

Open
neheb wants to merge 2 commits into
Exiv2:mainfrom
neheb:mock
Open

use more mocking in unit tests#9383
neheb wants to merge 2 commits into
Exiv2:mainfrom
neheb:mock

Conversation

@neheb

@neheb neheb commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

neheb added 2 commits August 8, 2026 14:39
…error/eof

Both type checkers used during ImageFactory::getType(BasicIo&) registry
iteration would throw exceptions on EOF or read errors, while every other
type checker in the registry correctly returns false. This caused
getType() to unexpectedly throw when iterating past these entries.

- isPngType: changed throw -> return false on iIo.error()/iIo.eof()
- isWebPType: replaced readOrThrow() with read()+error/eof checks
Introduce a header-only mock class for BasicIo (all 19 pure virtuals),
enabling tests to inject controlled I/O behaviour without touching the
filesystem.

- mock_basicio.hpp: MockBasicIo with a setDefaultPath() helper plus sane
  default ON_CALLs in the constructor so it is usable without per-method
  setup. The makeMockIo()/setupRead() helpers are provided here so the
  same ~15-line boilerplate is no longer duplicated across test files.

Convert all filesystem-dependent tests to use this mock:

test_ImageFactory.cpp:
- Replace file-based open()/getType() tests with MockBasicIo
  covering: JPEG detection/opening, open-failure, read-failure,
  unknown-type -> none/nullptr
- Remove padded() MemIo helper (no longer needed)

test_asfvideo.cpp, test_matroskavideo.cpp, test_riffVideo.cpp:
- Replace MemIo empty-data tests with MockBasicIo read-failure
- Add valid-signature detection tests for each format

test_jp2image.cpp:
- Add isJp2Type tests (coverage was entirely absent)
- Replace FileIo(NonExistingPath) with MockBasicIo open-failure

test_bmpimage.cpp, test_pngimage.cpp:
- Replace FileIo(NonExistingPath) tests with MockBasicIo open-failure
- Remove FileIo #include (no more filesystem deps in type-check tests)
- Convert isPngType tests to MockBasicIo for consistency with the other
  formats
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant