Commit 072623d6e80129fe6a716a60bb85200f7300acd5
Merge pull request #1151 from m-holger/sat
Add additional sparse QPDF_Array tests
Showing
1 changed file
with
33 additions
and
0 deletions
libtests/sparse_array.cc
| 1 | 1 | #include <qpdf/assert_test.h> |
| 2 | 2 | |
| 3 | +#include <qpdf/QPDF.hh> | |
| 3 | 4 | #include <qpdf/QPDFObjectHandle.hh> |
| 4 | 5 | #include <qpdf/QPDFObject_private.hh> |
| 5 | 6 | #include <qpdf/QPDF_Array.hh> |
| 7 | + | |
| 6 | 8 | #include <iostream> |
| 7 | 9 | |
| 8 | 10 | int |
| ... | ... | @@ -83,6 +85,37 @@ main() |
| 83 | 85 | assert(a.at(1).isInteger() && (a.at(1).getIntValue() == 1)); |
| 84 | 86 | assert(a.at(2).isString() && (a.at(2).getStringValue() == "potato")); |
| 85 | 87 | |
| 88 | + QPDF pdf; | |
| 89 | + pdf.emptyPDF(); | |
| 90 | + | |
| 91 | + obj = QPDF_Array::create({10, "null"_qpdf.getObj()}, true); | |
| 92 | + QPDF_Array& b = *obj->as<QPDF_Array>(); | |
| 93 | + b.setAt(5, pdf.getObject(5, 0)); | |
| 94 | + b.setAt(7, "[0 1 2 3]"_qpdf); | |
| 95 | + assert(b.at(3).isNull()); | |
| 96 | + assert(b.at(8).isNull()); | |
| 97 | + assert(b.at(5).isIndirect()); | |
| 98 | + assert(b.unparse() == "[ null null null null null 5 0 R null [ 0 1 2 3 ] null null ]"); | |
| 99 | + auto c = b.copy(true); | |
| 100 | + auto d = b.copy(false); | |
| 101 | + b.at(7).setArrayItem(2, "42"_qpdf); | |
| 102 | + assert(c->unparse() == "[ null null null null null 5 0 R null [ 0 1 42 3 ] null null ]"); | |
| 103 | + assert(d->unparse() == "[ null null null null null 5 0 R null [ 0 1 2 3 ] null null ]"); | |
| 104 | + | |
| 105 | + try { | |
| 106 | + b.setAt(3, {}); | |
| 107 | + std::cout << "inserted uninitialized object\n"; | |
| 108 | + } catch (std::logic_error&) { | |
| 109 | + } | |
| 110 | + QPDF pdf2; | |
| 111 | + pdf2.emptyPDF(); | |
| 112 | + try { | |
| 113 | + pdf.makeIndirectObject(obj); | |
| 114 | + b.setAt(3, pdf2.getObject(1, 0)); | |
| 115 | + std::cout << "inserted uninitialized object\n"; | |
| 116 | + } catch (std::logic_error&) { | |
| 117 | + } | |
| 118 | + | |
| 86 | 119 | std::cout << "sparse array tests done" << std::endl; |
| 87 | 120 | return 0; |
| 88 | 121 | } | ... | ... |