aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorm-holger <m-holger@kubitscheck.org>2024-02-20 15:53:18 +0100
committerm-holger <m-holger@kubitscheck.org>2024-02-20 15:53:18 +0100
commit862feed100f9bf45c27b93c4791447f76b2486d5 (patch)
treeaf0d86e46167fabeb8d50f77e4ad4492f025bd30
parent36ee4ecc6ee15520ef792d52f48ae7dcb7d37c30 (diff)
downloadqpdf-862feed100f9bf45c27b93c4791447f76b2486d5.tar.zst
Add additional QPDFObjectHandle::Rectangle and Matrix tests
-rw-r--r--qpdf/test_driver.cc38
1 files changed, 37 insertions, 1 deletions
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());