Commit c2ae35540e78d4edfbc57d42bfa2fc166c38b8a5
1 parent
2d1db060
Add boundary condition test for getUniqueResourceName
Showing
3 changed files
with
25 additions
and
1 deletions
qpdf/qtest/qpdf.test
| @@ -1032,12 +1032,19 @@ $td->runtest("detect foreign object in write", | @@ -1032,12 +1032,19 @@ $td->runtest("detect foreign object in write", | ||
| 1032 | show_ntests(); | 1032 | show_ntests(); |
| 1033 | # ---------- | 1033 | # ---------- |
| 1034 | $td->notify("--- Merge Dictionary ---"); | 1034 | $td->notify("--- Merge Dictionary ---"); |
| 1035 | -$n_tests += 1; | 1035 | +$n_tests += 3; |
| 1036 | 1036 | ||
| 1037 | $td->runtest("merge dictionary", | 1037 | $td->runtest("merge dictionary", |
| 1038 | {$td->COMMAND => "test_driver 50 merge-dict.pdf"}, | 1038 | {$td->COMMAND => "test_driver 50 merge-dict.pdf"}, |
| 1039 | {$td->FILE => "merge-dict.out", $td->EXIT_STATUS => 0}, | 1039 | {$td->FILE => "merge-dict.out", $td->EXIT_STATUS => 0}, |
| 1040 | $td->NORMALIZE_NEWLINES); | 1040 | $td->NORMALIZE_NEWLINES); |
| 1041 | +$td->runtest("unique resource name", | ||
| 1042 | + {$td->COMMAND => "test_driver 60 minimal.pdf"}, | ||
| 1043 | + {$td->STRING => "test 60 done\n", $td->EXIT_STATUS => 0}, | ||
| 1044 | + $td->NORMALIZE_NEWLINES); | ||
| 1045 | +$td->runtest("check output", | ||
| 1046 | + {$td->FILE => "a.pdf"}, | ||
| 1047 | + {$td->FILE => "unique-resources.pdf"}); | ||
| 1041 | 1048 | ||
| 1042 | show_ntests(); | 1049 | show_ntests(); |
| 1043 | # ---------- | 1050 | # ---------- |
qpdf/qtest/qpdf/unique-resources.pdf
0 → 100644
No preview for this file type
qpdf/test_driver.cc
| @@ -2016,6 +2016,23 @@ void runtest(int n, char const* filename1, char const* arg2) | @@ -2016,6 +2016,23 @@ void runtest(int n, char const* filename1, char const* arg2) | ||
| 2016 | w.setStaticID(true); | 2016 | w.setStaticID(true); |
| 2017 | w.write(); | 2017 | w.write(); |
| 2018 | } | 2018 | } |
| 2019 | + else if (n == 60) | ||
| 2020 | + { | ||
| 2021 | + // Boundary condition testing for getUniqueResourceName | ||
| 2022 | + QPDFObjectHandle r1 = QPDFObjectHandle::newDictionary(); | ||
| 2023 | + int min_suffix = 1; | ||
| 2024 | + for (int i = 1; i < 3; ++i) | ||
| 2025 | + { | ||
| 2026 | + std::string name = r1.getUniqueResourceName("/Quack", min_suffix); | ||
| 2027 | + r1.mergeResources(QPDFObjectHandle::parse("<< /Z << >> >>")); | ||
| 2028 | + r1.getKey("/Z").replaceKey( | ||
| 2029 | + name, QPDFObjectHandle::newString("moo")); | ||
| 2030 | + } | ||
| 2031 | + pdf.getTrailer().replaceKey("/QTest", r1); | ||
| 2032 | + QPDFWriter w(pdf, "a.pdf"); | ||
| 2033 | + w.setStaticID(true); | ||
| 2034 | + w.write(); | ||
| 2035 | + } | ||
| 2019 | else | 2036 | else |
| 2020 | { | 2037 | { |
| 2021 | throw std::runtime_error(std::string("invalid test ") + | 2038 | throw std::runtime_error(std::string("invalid test ") + |