aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2019-02-08 01:21:26 +0100
committerJay Berkenbilt <ejb@ql.org>2019-02-08 01:21:26 +0100
commitfc2e491f74ef151ac121fee2db00e33073255677 (patch)
tree2a9de3c482ed1a0f7fd63e6d4a42bf90055720ce
parentae65cdcce2427f8fe106ecf4da53602210b68210 (diff)
downloadqpdf-fc2e491f74ef151ac121fee2db00e33073255677.tar.zst
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.
-rw-r--r--qpdf/qtest/qpdf.test10
-rw-r--r--qpdf/qtest/qpdf/exceptions.out5
-rw-r--r--qpdf/test_driver.cc44
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 ") +