Commit fc2e491f74ef151ac121fee2db00e33073255677
1 parent
ae65cdcc
Add test for exception handling
There have been issues reported where exceptions are not thrown properly across shared library/DLL boundaries, so add a test specifically to ensure that exceptions are caught as thrown.
Showing
3 changed files
with
59 additions
and
0 deletions
qpdf/qtest/qpdf.test
| ... | ... | @@ -180,6 +180,16 @@ $td->runtest("check final version", |
| 180 | 180 | |
| 181 | 181 | show_ntests(); |
| 182 | 182 | # ---------- |
| 183 | +$td->notify("--- Exceptions ---"); | |
| 184 | +$n_tests += 1; | |
| 185 | + | |
| 186 | +$td->runtest("check exception handling", | |
| 187 | + {$td->COMMAND => "test_driver 61 -"}, | |
| 188 | + {$td->FILE => "exceptions.out", $td->EXIT_STATUS => 0}, | |
| 189 | + $td->NORMALIZE_NEWLINES); | |
| 190 | + | |
| 191 | +show_ntests(); | |
| 192 | +# ---------- | |
| 183 | 193 | $td->notify("--- Dangling Refs ---"); |
| 184 | 194 | my @dangling = (qw(minimal dangling-refs)); |
| 185 | 195 | $n_tests += 2 * scalar(@dangling); | ... | ... |
qpdf/qtest/qpdf/exceptions.out
0 → 100644
qpdf/test_driver.cc
| ... | ... | @@ -16,6 +16,7 @@ |
| 16 | 16 | #include <qpdf/Pl_Buffer.hh> |
| 17 | 17 | #include <qpdf/Pl_Flate.hh> |
| 18 | 18 | #include <qpdf/QPDFWriter.hh> |
| 19 | +#include <qpdf/QPDFSystemError.hh> | |
| 19 | 20 | #include <iostream> |
| 20 | 21 | #include <sstream> |
| 21 | 22 | #include <algorithm> |
| ... | ... | @@ -269,6 +270,10 @@ void runtest(int n, char const* filename1, char const* arg2) |
| 269 | 270 | pdf.processMemoryFile((std::string(filename1) + ".pdf").c_str(), |
| 270 | 271 | p, size); |
| 271 | 272 | } |
| 273 | + else if (n == 61) | |
| 274 | + { | |
| 275 | + // Ignore filename argument entirely | |
| 276 | + } | |
| 272 | 277 | else if (n % 2 == 0) |
| 273 | 278 | { |
| 274 | 279 | if (n % 4 == 0) |
| ... | ... | @@ -2046,6 +2051,45 @@ void runtest(int n, char const* filename1, char const* arg2) |
| 2046 | 2051 | w.setStaticID(true); |
| 2047 | 2052 | w.write(); |
| 2048 | 2053 | } |
| 2054 | + else if (n == 61) | |
| 2055 | + { | |
| 2056 | + // Test to make sure exceptions can be caught properly across | |
| 2057 | + // shared library boundaries. | |
| 2058 | + pdf.setAttemptRecovery(false); | |
| 2059 | + pdf.setSuppressWarnings(true); | |
| 2060 | + try | |
| 2061 | + { | |
| 2062 | + pdf.processMemoryFile("empty", "", 0); | |
| 2063 | + } | |
| 2064 | + catch (QPDFExc& e) | |
| 2065 | + { | |
| 2066 | + std::cout << "Caught QPDFExc as expected" << std::endl; | |
| 2067 | + } | |
| 2068 | + try | |
| 2069 | + { | |
| 2070 | + QUtil::safe_fopen("/does/not/exist", "r"); | |
| 2071 | + } | |
| 2072 | + catch (QPDFSystemError& e) | |
| 2073 | + { | |
| 2074 | + std::cout << "Caught QPDFSystemError as expected" << std::endl; | |
| 2075 | + } | |
| 2076 | + try | |
| 2077 | + { | |
| 2078 | + QUtil::int_to_string_base(0, 12); | |
| 2079 | + } | |
| 2080 | + catch (std::logic_error& e) | |
| 2081 | + { | |
| 2082 | + std::cout << "Caught logic_error as expected" << std::endl; | |
| 2083 | + } | |
| 2084 | + try | |
| 2085 | + { | |
| 2086 | + QUtil::toUTF8(0xffffffff); | |
| 2087 | + } | |
| 2088 | + catch (std::runtime_error& e) | |
| 2089 | + { | |
| 2090 | + std::cout << "Caught runtime_error as expected" << std::endl; | |
| 2091 | + } | |
| 2092 | + } | |
| 2049 | 2093 | else |
| 2050 | 2094 | { |
| 2051 | 2095 | throw std::runtime_error(std::string("invalid test ") + | ... | ... |