diff --git a/libqpdf/Pipeline.cc b/libqpdf/Pipeline.cc index 9e02131..bc951a1 100644 --- a/libqpdf/Pipeline.cc +++ b/libqpdf/Pipeline.cc @@ -1,8 +1,12 @@ #include +#include + #include #include +using namespace qpdf; + Pipeline::Pipeline(char const* identifier, Pipeline* next) : identifier(identifier), next_(next) @@ -12,10 +16,8 @@ Pipeline::Pipeline(char const* identifier, Pipeline* next) : Pipeline* Pipeline::getNext(bool allow_null) { - if (!next_ && !allow_null) { - throw std::logic_error( - identifier + ": Pipeline::getNext() called on pipeline with no next"); - } + util::assertion( + next_ || allow_null, identifier + ": Pipeline::getNext() called on pipeline with no next"); return next_; } diff --git a/libqpdf/QPDFXRefEntry.cc b/libqpdf/QPDFXRefEntry.cc index 731ad40..e8ad48a 100644 --- a/libqpdf/QPDFXRefEntry.cc +++ b/libqpdf/QPDFXRefEntry.cc @@ -2,50 +2,43 @@ #include #include +#include -QPDFXRefEntry::QPDFXRefEntry() // NOLINT (modernize-use-equals-default) -{ -} +using namespace qpdf; + +QPDFXRefEntry::QPDFXRefEntry() = default; QPDFXRefEntry::QPDFXRefEntry(int type, qpdf_offset_t field1, int field2) : type(type), field1(field1), field2(field2) { - if ((type < 1) || (type > 2)) { - throw std::logic_error("invalid xref type " + std::to_string(type)); - } + util::assertion(type == 1 || type == 2, "invalid xref type " + std::to_string(type)); } int QPDFXRefEntry::getType() const { - return this->type; + return type; } qpdf_offset_t QPDFXRefEntry::getOffset() const { - if (this->type != 1) { - throw std::logic_error("getOffset called for xref entry of type != 1"); - } + util::assertion(type == 1, "getOffset called for xref entry of type != 1"); return this->field1; } int QPDFXRefEntry::getObjStreamNumber() const { - if (this->type != 2) { - throw std::logic_error("getObjStreamNumber called for xref entry of type != 2"); - } - return QIntC::to_int(this->field1); + util::assertion(type == 2, "getObjStreamNumber called for xref entry of type != 2"); + return QIntC::to_int(field1); } int QPDFXRefEntry::getObjStreamIndex() const { - if (this->type != 2) { - throw std::logic_error("getObjStreamIndex called for xref entry of type != 2"); - } - return this->field2; + util::assertion(type == 2, "getObjStreamIndex called for xref entry of type != 2"); + return field2; } diff --git a/qpdf/qtest/misc.test b/qpdf/qtest/misc.test new file mode 100644 index 0000000..b0ceff7 --- /dev/null +++ b/qpdf/qtest/misc.test @@ -0,0 +1,27 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +my $dev_null = File::Spec->devnull(); +cleanup(); + +my $td = new TestDriver('misc'); + +my $n_tests = 1; + +$td->runtest("pipeline", + {$td->COMMAND => "test_driver 62 -"}, + {$td->STRING => "test 62 done\n", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/test_driver.cc b/qpdf/test_driver.cc index 834cbc4..4933031 100644 --- a/qpdf/test_driver.cc +++ b/qpdf/test_driver.cc @@ -2279,8 +2279,17 @@ test_61(QPDF& pdf, char const* arg2) static void test_62(QPDF& pdf, char const* arg2) { - // Test int size checks. This test will fail if int and long long are the same size. - // Moved to libtests/objects + // Was test int size checks - Moved to libtests/objects. + // Test Pipeline methods + std::string out; + Pl_String pl("", nullptr, out); + unsigned short us = 1; + unsigned int ui = 2; + unsigned long long ull = 3; + long l = 4; + short s = 5; + pl << us << ui << ull << l << s; + assert(out == "12345"); } static void @@ -3548,7 +3557,7 @@ runtest(int n, char const* filename1, char const* arg2) // the test suite to see how the test is invoked to find the file // that the test is supposed to operate on. - std::set ignore_filename = {61, 81, 83, 84, 85, 86, 87, 92, 95, 96}; + std::set ignore_filename = {61, 62, 81, 83, 84, 85, 86, 87, 92, 95, 96}; if (n == 0) { // Throw in some random test cases that don't fit anywhere