From 36ee4ecc6ee15520ef792d52f48ae7dcb7d37c30 Mon Sep 17 00:00:00 2001 From: m-holger Date: Tue, 20 Feb 2024 13:02:16 +0000 Subject: Add test for QPDFObjectHandle::isDirectNull --- qpdf/test_driver.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/qpdf/test_driver.cc b/qpdf/test_driver.cc index 45b8adf0..f863440d 100644 --- a/qpdf/test_driver.cc +++ b/qpdf/test_driver.cc @@ -1191,6 +1191,7 @@ test_31(QPDF& pdf, char const* arg2) std::cout << "trailing data: " << e.what() << std::endl; } assert(QPDFObjectHandle::parse(&pdf, "[5 0 R]").getArrayItem(0).isInteger()); + assert(!QPDFObjectHandle::parse(&pdf, "[5 0 R]").getArrayItem(0).isDirectNull()); // Make sure an indirect integer followed by "0 R" is not // mistakenly parsed as an indirect object. assert(QPDFObjectHandle::parse(&pdf, "[5 0 R 0 R /X]").unparse() == "[ 5 0 R 0 (R) /X ]"); @@ -1202,6 +1203,8 @@ test_31(QPDF& pdf, char const* arg2) assert(QPDFObjectHandle::parse(&pdf, ">>").unparse() == "null"); // TC:QPDFParser eof in parse assert(QPDFObjectHandle::parse(&pdf, "[7 0 R]").getArrayItem(0).isNull()); + assert(!QPDFObjectHandle::parse(&pdf, "[7 0 R]").getArrayItem(0).isDirectNull()); + assert(QPDFObjectHandle::parse(&pdf, "null").isDirectNull()); // TC:QPDFParser invalid objgen assert( QPDFObjectHandle::parse(&pdf, "[0 0 R -1 0 R 1 65535 R 1 100000 R 1 -1 R]").unparse() == -- cgit v1.2.3-54-g00ecf From 862feed100f9bf45c27b93c4791447f76b2486d5 Mon Sep 17 00:00:00 2001 From: m-holger Date: Tue, 20 Feb 2024 14:53:18 +0000 Subject: Add additional QPDFObjectHandle::Rectangle and Matrix tests --- qpdf/test_driver.cc | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/qpdf/test_driver.cc b/qpdf/test_driver.cc index f863440d..0f15f506 100644 --- a/qpdf/test_driver.cc +++ b/qpdf/test_driver.cc @@ -1496,7 +1496,7 @@ test_42(QPDF& pdf, char const* arg2) // Stream dictionary QPDFObjectHandle page = pdf.getAllPages().at(0); assert("/QPDFFakeName" == page.getKey("/Contents").getDict().getKey("/Potato").getName()); - // Rectangles + // Rectangle QPDFObjectHandle::Rectangle r0 = integer.getArrayAsRectangle(); assert((r0.llx == 0) && (r0.lly == 0) && (r0.urx == 0) && (r0.ury == 0)); QPDFObjectHandle rect = @@ -1505,6 +1505,42 @@ test_42(QPDF& pdf, char const* arg2) assert( (r1.llx > 1.19) && (r1.llx < 1.21) && (r1.lly > 3.39) && (r1.lly < 3.41) && (r1.urx > 5.59) && (r1.urx < 5.61) && (r1.ury > 7.79) && (r1.ury < 7.81)); + assert(!"[1 2 3 4 5]"_qpdf.isRectangle()); + r1 = "[1 2 3 4 5]"_qpdf.getArrayAsRectangle(); + assert(r0.llx == 0 && r0.lly == 0 && r0.urx == 0 && r0.ury == 0); + assert(!"[1 2 3]"_qpdf.isRectangle()); + r1 = "[1 2 3]"_qpdf.getArrayAsRectangle(); + assert(r0.llx == 0 && r0.lly == 0 && r0.urx == 0 && r0.ury == 0); + assert(!"[1 2 false 4]"_qpdf.isRectangle()); + r1 = "[1 2 false 4]"_qpdf.getArrayAsRectangle(); + assert(r0.llx == 0 && r0.lly == 0 && r0.urx == 0 && r0.ury == 0); + // Matrix + auto matrix = + QPDFObjectHandle::newFromMatrix(QPDFObjectHandle::Matrix{1.2, 3.4, 5.6, 7.8, 9.1, 2.3}); + auto m1 = matrix.getArrayAsMatrix(); + assert( + m1.a > 1.19 && m1.a < 1.21 && m1.b > 3.39 && m1.b < 3.41 && m1.c > 5.59 && m1.c < 5.61 && + m1.d > 7.79 && m1.d < 7.81 && m1.e > 9.09 && m1.e < 9.11 && m1.f > 2.29 && m1.f < 2.31); + assert(matrix.isMatrix()); + matrix = QPDFObjectHandle::newFromMatrix(QPDFMatrix{1.2, 3.4, 5.6, 7.8, 9.1, 2.3}); + m1 = matrix.getArrayAsMatrix(); + assert( + m1.a > 1.19 && m1.a < 1.21 && m1.b > 3.39 && m1.b < 3.41 && m1.c > 5.59 && m1.c < 5.61 && + m1.d > 7.79 && m1.d < 7.81 && m1.e > 9.09 && m1.e < 9.11 && m1.f > 2.29 && m1.f < 2.31); + assert(matrix.isMatrix()); + assert(!"[1 2 3 4 5]"_qpdf.isMatrix()); + m1 = "[1 2 3 4 5]"_qpdf.getArrayAsMatrix(); + assert(m1.a == 0 && m1.b == 0 && m1.c == 0 && m1.d == 0 && m1.e == 0 && m1.f == 0); + assert(!"[1 2 3 4 5 6 7]"_qpdf.isMatrix()); + m1 = "[1 2 3 4 5 6 7]"_qpdf.getArrayAsMatrix(); + assert(m1.a == 0 && m1.b == 0 && m1.c == 0 && m1.d == 0 && m1.e == 0 && m1.f == 0); + assert(!"[1 2 3 false 5 6 7]"_qpdf.isMatrix()); + m1 = "[1 2 3 false 5 6 7]"_qpdf.getArrayAsMatrix(); + assert(m1.a == 0 && m1.b == 0 && m1.c == 0 && m1.d == 0 && m1.e == 0 && m1.f == 0); + assert(!"42"_qpdf.isMatrix()); + m1 = "42"_qpdf.getArrayAsMatrix(); + assert(m1.a == 0 && m1.b == 0 && m1.c == 0 && m1.d == 0 && m1.e == 0 && m1.f == 0); + // Uninitialized QPDFObjectHandle uninitialized; assert(!uninitialized.isInitialized()); assert(!uninitialized.isInteger()); -- cgit v1.2.3-54-g00ecf