diff options
-rw-r--r-- | qpdf/qtest/qpdf.test | 10 | ||||
-rw-r--r-- | qpdf/qtest/qpdf/exceptions.out | 5 | ||||
-rw-r--r-- | qpdf/test_driver.cc | 44 |
3 files changed, 59 insertions, 0 deletions
diff --git a/qpdf/qtest/qpdf.test b/qpdf/qtest/qpdf.test index af103201..b6b33977 100644 --- a/qpdf/qtest/qpdf.test +++ b/qpdf/qtest/qpdf.test @@ -180,6 +180,16 @@ $td->runtest("check final version", show_ntests(); # ---------- +$td->notify("--- Exceptions ---"); +$n_tests += 1; + +$td->runtest("check exception handling", + {$td->COMMAND => "test_driver 61 -"}, + {$td->FILE => "exceptions.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +show_ntests(); +# ---------- $td->notify("--- Dangling Refs ---"); my @dangling = (qw(minimal dangling-refs)); $n_tests += 2 * scalar(@dangling); diff --git a/qpdf/qtest/qpdf/exceptions.out b/qpdf/qtest/qpdf/exceptions.out new file mode 100644 index 00000000..ab69668e --- /dev/null +++ b/qpdf/qtest/qpdf/exceptions.out @@ -0,0 +1,5 @@ +Caught QPDFExc as expected +Caught QPDFSystemError as expected +Caught logic_error as expected +Caught runtime_error as expected +test 61 done diff --git a/qpdf/test_driver.cc b/qpdf/test_driver.cc index e83f84aa..462a8a23 100644 --- a/qpdf/test_driver.cc +++ b/qpdf/test_driver.cc @@ -16,6 +16,7 @@ #include <qpdf/Pl_Buffer.hh> #include <qpdf/Pl_Flate.hh> #include <qpdf/QPDFWriter.hh> +#include <qpdf/QPDFSystemError.hh> #include <iostream> #include <sstream> #include <algorithm> @@ -269,6 +270,10 @@ void runtest(int n, char const* filename1, char const* arg2) pdf.processMemoryFile((std::string(filename1) + ".pdf").c_str(), p, size); } + else if (n == 61) + { + // Ignore filename argument entirely + } else if (n % 2 == 0) { if (n % 4 == 0) @@ -2046,6 +2051,45 @@ void runtest(int n, char const* filename1, char const* arg2) w.setStaticID(true); w.write(); } + else if (n == 61) + { + // Test to make sure exceptions can be caught properly across + // shared library boundaries. + pdf.setAttemptRecovery(false); + pdf.setSuppressWarnings(true); + try + { + pdf.processMemoryFile("empty", "", 0); + } + catch (QPDFExc& e) + { + std::cout << "Caught QPDFExc as expected" << std::endl; + } + try + { + QUtil::safe_fopen("/does/not/exist", "r"); + } + catch (QPDFSystemError& e) + { + std::cout << "Caught QPDFSystemError as expected" << std::endl; + } + try + { + QUtil::int_to_string_base(0, 12); + } + catch (std::logic_error& e) + { + std::cout << "Caught logic_error as expected" << std::endl; + } + try + { + QUtil::toUTF8(0xffffffff); + } + catch (std::runtime_error& e) + { + std::cout << "Caught runtime_error as expected" << std::endl; + } + } else { throw std::runtime_error(std::string("invalid test ") + |