mirror of
https://github.com/qpdf/qpdf.git
synced 2024-12-23 03:18:59 +00:00
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.
This commit is contained in:
parent
ae65cdcce2
commit
fc2e491f74
@ -178,6 +178,16 @@ $td->runtest("check final version",
|
||||
{$td->STRING => "test 54 done\n", $td->EXIT_STATUS => 0},
|
||||
$td->NORMALIZE_NEWLINES);
|
||||
|
||||
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 ---");
|
||||
|
5
qpdf/qtest/qpdf/exceptions.out
Normal file
5
qpdf/qtest/qpdf/exceptions.out
Normal file
@ -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
|
@ -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 ") +
|
||||
|
Loading…
Reference in New Issue
Block a user