aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2024-02-17 20:59:50 +0100
committerJay Berkenbilt <ejb@ql.org>2024-02-17 20:59:50 +0100
commit072623d6e80129fe6a716a60bb85200f7300acd5 (patch)
tree1f6c398cde7c090f960872e0a4bb4365d5b4fe9d
parent93cf8156b0c356be988edf4c2d22e153be9b2792 (diff)
parent703e798330aec4a410a0088ed3b7157c60acab50 (diff)
downloadqpdf-072623d6e80129fe6a716a60bb85200f7300acd5.tar.zst
Merge pull request #1151 from m-holger/sat
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;
}