aboutsummaryrefslogtreecommitdiffstats
path: root/qpdf
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-09-07 00:30:31 +0200
committerJay Berkenbilt <ejb@ql.org>2022-09-07 00:34:23 +0200
commitc1def4ead4c578862ad6fcda35a9ca65be407893 (patch)
tree5695a6a6d782c0dfd4fa91e952a1d777ab8f067d /qpdf
parentd12734d76fb599c64a9b7fd6cc5a92dd1a90e0ee (diff)
downloadqpdf-c1def4ead4c578862ad6fcda35a9ca65be407893.tar.zst
Implement QPDFObjectHandle equality
Diffstat (limited to 'qpdf')
-rw-r--r--qpdf/qtest/object-handle-api.test8
-rw-r--r--qpdf/test_driver.cc29
2 files changed, 33 insertions, 4 deletions
diff --git a/qpdf/qtest/object-handle-api.test b/qpdf/qtest/object-handle-api.test
index 3de5f909..0d233bcc 100644
--- a/qpdf/qtest/object-handle-api.test
+++ b/qpdf/qtest/object-handle-api.test
@@ -14,8 +14,6 @@ cleanup();
my $td = new TestDriver('object-handle-api');
-my $n_tests = 2;
-
$td->runtest("dictionary keys",
{$td->COMMAND => "test_driver 87 - -"},
{$td->STRING => "test 87 done\n", $td->EXIT_STATUS => 0},
@@ -24,6 +22,10 @@ $td->runtest("fluent interfaces",
{$td->COMMAND => "test_driver 88 minimal.pdf -"},
{$td->FILE => "test88.out", $td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
+$td->runtest("equality",
+ {$td->COMMAND => "test_driver 93 minimal.pdf -"},
+ {$td->STRING => "test 93 done\n", $td->EXIT_STATUS => 0},
+ $td->NORMALIZE_NEWLINES);
cleanup();
-$td->report($n_tests);
+$td->report(3);
diff --git a/qpdf/test_driver.cc b/qpdf/test_driver.cc
index 16b65d8d..812d6c07 100644
--- a/qpdf/test_driver.cc
+++ b/qpdf/test_driver.cc
@@ -3275,6 +3275,33 @@ test_92(QPDF& pdf, char const* arg2)
assert(!root.isIndirect());
}
+static void
+test_93(QPDF& pdf, char const* arg2)
+{
+ // Test QPDFObjectHandle equality. Two QPDFObjectHandle objects
+ // are equal if they point to the same underlying object.
+
+ auto trailer = pdf.getTrailer();
+ auto root1 = trailer.getKey("/Root");
+ auto root2 = pdf.getRoot();
+ assert(root1 == root2);
+ auto oh1 = "<< /One /Two >>"_qpdf;
+ auto oh2 = oh1;
+ assert(oh1 == oh2);
+ auto oh3 = "<< /One /Two >>"_qpdf;
+ assert(oh1 != oh3);
+ oh2.replaceKey("/One", "/Three"_qpdf);
+ assert(oh1 == oh2);
+ assert(oh2.unparse() == "<< /One /Three >>");
+ assert(!oh1.isIndirect());
+ auto oh4 = pdf.makeIndirectObject(oh1);
+ assert(oh1 == oh4);
+ assert(oh1.isIndirect());
+ assert(oh4.isIndirect());
+ trailer.replaceKey("/Potato", oh1);
+ assert(trailer.getKey("/Potato") == oh2);
+}
+
void
runtest(int n, char const* filename1, char const* arg2)
{
@@ -3384,7 +3411,7 @@ runtest(int n, char const* filename1, char const* arg2)
{80, test_80}, {81, test_81}, {82, test_82}, {83, test_83},
{84, test_84}, {85, test_85}, {86, test_86}, {87, test_87},
{88, test_88}, {89, test_89}, {90, test_90}, {91, test_91},
- {92, test_92}};
+ {92, test_92}, {93, test_93}};
auto fn = test_functions.find(n);
if (fn == test_functions.end()) {