2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 02:49:00 +00:00

Add additional QPDFObjectHandle::Rectangle and Matrix tests

This commit is contained in:
m-holger 2024-02-20 14:53:18 +00:00
parent 36ee4ecc6e
commit 862feed100

View File

@ -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());