InputSource::unreadCh -- only unread most recently read character

This is all that ever worked. The test suite was trying to do
something different from ClosedFileInputSource.
This commit is contained in:
Jay Berkenbilt 2020-10-16 14:35:18 -04:00
parent 9a4d3534a1
commit 18b34a5649
3 changed files with 11 additions and 2 deletions

6
TODO
View File

@ -315,6 +315,12 @@ I find it useful to make reference to them in this list
* Investigate whether there is a way to automate the memory checker
tests for Windows.
* Part of closed_file_input_source.cc is disabled on Windows because
of odd failures. It might be worth investigating so we can fully
exercise this in the test suite. That said, ClosedFileInputSource
is exercised elsewhere in qpdf's test suite, so this is not that
pressing.
* Support user-pluggable stream filters. This would enable external
code to provide interpretation for filters that are missing from
qpdf. Make it possible for user-provided filters to override

View File

@ -83,6 +83,9 @@ class QPDF_DLL_CLASS InputSource
virtual void seek(qpdf_offset_t offset, int whence) = 0;
virtual void rewind() = 0;
virtual size_t read(char* buffer, size_t length) = 0;
// Note: you can only unread the character you just read. The
// specific character is ignored by some implementations.
virtual void unreadCh(char ch) = 0;
protected:

View File

@ -38,9 +38,9 @@ void do_tests(InputSource* is)
is->seek(521, SEEK_SET);
is->read(b, 1);
#else
is->unreadCh('Q');
is->unreadCh('\n');
check("read unread character", 1 == is->read(b, 1));
check("got character", 'Q' == b[0]);
check("got character", '\n' == b[0]);
#endif
check("last offset after read unread", 521 == is->getLastOffset());
is->seek(0, SEEK_END);