mirror of
https://github.com/qpdf/qpdf.git
synced 2024-12-22 10:58:58 +00:00
Add additional sparse QPDF_Array tests
This commit is contained in:
parent
b1b789df42
commit
703e798330
@ -1,8 +1,10 @@
|
||||
#include <qpdf/assert_test.h>
|
||||
|
||||
#include <qpdf/QPDF.hh>
|
||||
#include <qpdf/QPDFObjectHandle.hh>
|
||||
#include <qpdf/QPDFObject_private.hh>
|
||||
#include <qpdf/QPDF_Array.hh>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
int
|
||||
@ -83,6 +85,37 @@ main()
|
||||
assert(a.at(1).isInteger() && (a.at(1).getIntValue() == 1));
|
||||
assert(a.at(2).isString() && (a.at(2).getStringValue() == "potato"));
|
||||
|
||||
QPDF pdf;
|
||||
pdf.emptyPDF();
|
||||
|
||||
obj = QPDF_Array::create({10, "null"_qpdf.getObj()}, true);
|
||||
QPDF_Array& b = *obj->as<QPDF_Array>();
|
||||
b.setAt(5, pdf.getObject(5, 0));
|
||||
b.setAt(7, "[0 1 2 3]"_qpdf);
|
||||
assert(b.at(3).isNull());
|
||||
assert(b.at(8).isNull());
|
||||
assert(b.at(5).isIndirect());
|
||||
assert(b.unparse() == "[ null null null null null 5 0 R null [ 0 1 2 3 ] null null ]");
|
||||
auto c = b.copy(true);
|
||||
auto d = b.copy(false);
|
||||
b.at(7).setArrayItem(2, "42"_qpdf);
|
||||
assert(c->unparse() == "[ null null null null null 5 0 R null [ 0 1 42 3 ] null null ]");
|
||||
assert(d->unparse() == "[ null null null null null 5 0 R null [ 0 1 2 3 ] null null ]");
|
||||
|
||||
try {
|
||||
b.setAt(3, {});
|
||||
std::cout << "inserted uninitialized object\n";
|
||||
} catch (std::logic_error&) {
|
||||
}
|
||||
QPDF pdf2;
|
||||
pdf2.emptyPDF();
|
||||
try {
|
||||
pdf.makeIndirectObject(obj);
|
||||
b.setAt(3, pdf2.getObject(1, 0));
|
||||
std::cout << "inserted uninitialized object\n";
|
||||
} catch (std::logic_error&) {
|
||||
}
|
||||
|
||||
std::cout << "sparse array tests done" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user