From 18b34a564906c7ef36daefab081b44ebfd9ee64b Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Fri, 16 Oct 2020 14:35:18 -0400 Subject: [PATCH] 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. --- TODO | 6 ++++++ include/qpdf/InputSource.hh | 3 +++ libtests/closed_file_input_source.cc | 4 ++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/TODO b/TODO index 05d497e4..cbd317e8 100644 --- a/TODO +++ b/TODO @@ -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 diff --git a/include/qpdf/InputSource.hh b/include/qpdf/InputSource.hh index 896a2559..8850828d 100644 --- a/include/qpdf/InputSource.hh +++ b/include/qpdf/InputSource.hh @@ -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: diff --git a/libtests/closed_file_input_source.cc b/libtests/closed_file_input_source.cc index 7309ca31..f3e4f2ac 100644 --- a/libtests/closed_file_input_source.cc +++ b/libtests/closed_file_input_source.cc @@ -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);