use more mocking in unit tests - #9383
Open
neheb wants to merge 2 commits into
Open
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.