aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorm-holger <m-holger@kubitscheck.org>2024-02-17 17:01:48 +0100
committerm-holger <m-holger@kubitscheck.org>2024-02-17 18:14:07 +0100
commit703e798330aec4a410a0088ed3b7157c60acab50 (patch)
tree1002244cb68ef29edb838cbbb60dc71547ae0a58
parentb1b789df4203296a848fec6a3513f30efceb1a45 (diff)
downloadqpdf-703e798330aec4a410a0088ed3b7157c60acab50.tar.zst
Add additional sparse QPDF_Array tests
-rw-r--r--libtests/sparse_array.cc33
1 files changed, 33 insertions, 0 deletions
diff --git a/libtests/sparse_array.cc b/libtests/sparse_array.cc
index 9f31c96f..47fe8c26 100644
--- a/libtests/sparse_array.cc
+++ b/libtests/sparse_array.cc
@@ -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;
}