Commit fc4575f17f1d2bc3a286877318bc634427007d88

Authored by Jay Berkenbilt
Committed by GitHub
2 parents 9c584e7b 862feed1

Merge pull request #1158 from m-holger/cov

Add test for QPDFObjectHandle::isDirectNull
Showing 1 changed file with 40 additions and 1 deletions
qpdf/test_driver.cc
@@ -1191,6 +1191,7 @@ test_31(QPDF& pdf, char const* arg2) @@ -1191,6 +1191,7 @@ test_31(QPDF& pdf, char const* arg2)
1191 std::cout << "trailing data: " << e.what() << std::endl; 1191 std::cout << "trailing data: " << e.what() << std::endl;
1192 } 1192 }
1193 assert(QPDFObjectHandle::parse(&pdf, "[5 0 R]").getArrayItem(0).isInteger()); 1193 assert(QPDFObjectHandle::parse(&pdf, "[5 0 R]").getArrayItem(0).isInteger());
  1194 + assert(!QPDFObjectHandle::parse(&pdf, "[5 0 R]").getArrayItem(0).isDirectNull());
1194 // Make sure an indirect integer followed by "0 R" is not 1195 // Make sure an indirect integer followed by "0 R" is not
1195 // mistakenly parsed as an indirect object. 1196 // mistakenly parsed as an indirect object.
1196 assert(QPDFObjectHandle::parse(&pdf, "[5 0 R 0 R /X]").unparse() == "[ 5 0 R 0 (R) /X ]"); 1197 assert(QPDFObjectHandle::parse(&pdf, "[5 0 R 0 R /X]").unparse() == "[ 5 0 R 0 (R) /X ]");
@@ -1202,6 +1203,8 @@ test_31(QPDF&amp; pdf, char const* arg2) @@ -1202,6 +1203,8 @@ test_31(QPDF&amp; pdf, char const* arg2)
1202 assert(QPDFObjectHandle::parse(&pdf, ">>").unparse() == "null"); 1203 assert(QPDFObjectHandle::parse(&pdf, ">>").unparse() == "null");
1203 // TC:QPDFParser eof in parse 1204 // TC:QPDFParser eof in parse
1204 assert(QPDFObjectHandle::parse(&pdf, "[7 0 R]").getArrayItem(0).isNull()); 1205 assert(QPDFObjectHandle::parse(&pdf, "[7 0 R]").getArrayItem(0).isNull());
  1206 + assert(!QPDFObjectHandle::parse(&pdf, "[7 0 R]").getArrayItem(0).isDirectNull());
  1207 + assert(QPDFObjectHandle::parse(&pdf, "null").isDirectNull());
1205 // TC:QPDFParser invalid objgen 1208 // TC:QPDFParser invalid objgen
1206 assert( 1209 assert(
1207 QPDFObjectHandle::parse(&pdf, "[0 0 R -1 0 R 1 65535 R 1 100000 R 1 -1 R]").unparse() == 1210 QPDFObjectHandle::parse(&pdf, "[0 0 R -1 0 R 1 65535 R 1 100000 R 1 -1 R]").unparse() ==
@@ -1493,7 +1496,7 @@ test_42(QPDF&amp; pdf, char const* arg2) @@ -1493,7 +1496,7 @@ test_42(QPDF&amp; pdf, char const* arg2)
1493 // Stream dictionary 1496 // Stream dictionary
1494 QPDFObjectHandle page = pdf.getAllPages().at(0); 1497 QPDFObjectHandle page = pdf.getAllPages().at(0);
1495 assert("/QPDFFakeName" == page.getKey("/Contents").getDict().getKey("/Potato").getName()); 1498 assert("/QPDFFakeName" == page.getKey("/Contents").getDict().getKey("/Potato").getName());
1496 - // Rectangles 1499 + // Rectangle
1497 QPDFObjectHandle::Rectangle r0 = integer.getArrayAsRectangle(); 1500 QPDFObjectHandle::Rectangle r0 = integer.getArrayAsRectangle();
1498 assert((r0.llx == 0) && (r0.lly == 0) && (r0.urx == 0) && (r0.ury == 0)); 1501 assert((r0.llx == 0) && (r0.lly == 0) && (r0.urx == 0) && (r0.ury == 0));
1499 QPDFObjectHandle rect = 1502 QPDFObjectHandle rect =
@@ -1502,6 +1505,42 @@ test_42(QPDF&amp; pdf, char const* arg2) @@ -1502,6 +1505,42 @@ test_42(QPDF&amp; pdf, char const* arg2)
1502 assert( 1505 assert(
1503 (r1.llx > 1.19) && (r1.llx < 1.21) && (r1.lly > 3.39) && (r1.lly < 3.41) && 1506 (r1.llx > 1.19) && (r1.llx < 1.21) && (r1.lly > 3.39) && (r1.lly < 3.41) &&
1504 (r1.urx > 5.59) && (r1.urx < 5.61) && (r1.ury > 7.79) && (r1.ury < 7.81)); 1507 (r1.urx > 5.59) && (r1.urx < 5.61) && (r1.ury > 7.79) && (r1.ury < 7.81));
  1508 + assert(!"[1 2 3 4 5]"_qpdf.isRectangle());
  1509 + r1 = "[1 2 3 4 5]"_qpdf.getArrayAsRectangle();
  1510 + assert(r0.llx == 0 && r0.lly == 0 && r0.urx == 0 && r0.ury == 0);
  1511 + assert(!"[1 2 3]"_qpdf.isRectangle());
  1512 + r1 = "[1 2 3]"_qpdf.getArrayAsRectangle();
  1513 + assert(r0.llx == 0 && r0.lly == 0 && r0.urx == 0 && r0.ury == 0);
  1514 + assert(!"[1 2 false 4]"_qpdf.isRectangle());
  1515 + r1 = "[1 2 false 4]"_qpdf.getArrayAsRectangle();
  1516 + assert(r0.llx == 0 && r0.lly == 0 && r0.urx == 0 && r0.ury == 0);
  1517 + // Matrix
  1518 + auto matrix =
  1519 + QPDFObjectHandle::newFromMatrix(QPDFObjectHandle::Matrix{1.2, 3.4, 5.6, 7.8, 9.1, 2.3});
  1520 + auto m1 = matrix.getArrayAsMatrix();
  1521 + assert(
  1522 + m1.a > 1.19 && m1.a < 1.21 && m1.b > 3.39 && m1.b < 3.41 && m1.c > 5.59 && m1.c < 5.61 &&
  1523 + m1.d > 7.79 && m1.d < 7.81 && m1.e > 9.09 && m1.e < 9.11 && m1.f > 2.29 && m1.f < 2.31);
  1524 + assert(matrix.isMatrix());
  1525 + matrix = QPDFObjectHandle::newFromMatrix(QPDFMatrix{1.2, 3.4, 5.6, 7.8, 9.1, 2.3});
  1526 + m1 = matrix.getArrayAsMatrix();
  1527 + assert(
  1528 + m1.a > 1.19 && m1.a < 1.21 && m1.b > 3.39 && m1.b < 3.41 && m1.c > 5.59 && m1.c < 5.61 &&
  1529 + m1.d > 7.79 && m1.d < 7.81 && m1.e > 9.09 && m1.e < 9.11 && m1.f > 2.29 && m1.f < 2.31);
  1530 + assert(matrix.isMatrix());
  1531 + assert(!"[1 2 3 4 5]"_qpdf.isMatrix());
  1532 + m1 = "[1 2 3 4 5]"_qpdf.getArrayAsMatrix();
  1533 + assert(m1.a == 0 && m1.b == 0 && m1.c == 0 && m1.d == 0 && m1.e == 0 && m1.f == 0);
  1534 + assert(!"[1 2 3 4 5 6 7]"_qpdf.isMatrix());
  1535 + m1 = "[1 2 3 4 5 6 7]"_qpdf.getArrayAsMatrix();
  1536 + assert(m1.a == 0 && m1.b == 0 && m1.c == 0 && m1.d == 0 && m1.e == 0 && m1.f == 0);
  1537 + assert(!"[1 2 3 false 5 6 7]"_qpdf.isMatrix());
  1538 + m1 = "[1 2 3 false 5 6 7]"_qpdf.getArrayAsMatrix();
  1539 + assert(m1.a == 0 && m1.b == 0 && m1.c == 0 && m1.d == 0 && m1.e == 0 && m1.f == 0);
  1540 + assert(!"42"_qpdf.isMatrix());
  1541 + m1 = "42"_qpdf.getArrayAsMatrix();
  1542 + assert(m1.a == 0 && m1.b == 0 && m1.c == 0 && m1.d == 0 && m1.e == 0 && m1.f == 0);
  1543 + // Uninitialized
1505 QPDFObjectHandle uninitialized; 1544 QPDFObjectHandle uninitialized;
1506 assert(!uninitialized.isInitialized()); 1545 assert(!uninitialized.isInitialized());
1507 assert(!uninitialized.isInteger()); 1546 assert(!uninitialized.isInteger());