Commit 1b364ad7b863d26e444d76501deb65f19092a832
1 parent
ba61c3ae
Add additional page API test cases
Showing
4 changed files
with
176 additions
and
1 deletions
qpdf/qtest/qpdf.test
| @@ -111,7 +111,7 @@ $td->runtest("new stream", | @@ -111,7 +111,7 @@ $td->runtest("new stream", | ||
| 111 | show_ntests(); | 111 | show_ntests(); |
| 112 | # ---------- | 112 | # ---------- |
| 113 | $td->notify("--- Page API Tests ---"); | 113 | $td->notify("--- Page API Tests ---"); |
| 114 | -$n_tests += 5; | 114 | +$n_tests += 8; |
| 115 | 115 | ||
| 116 | $td->runtest("basic page API", | 116 | $td->runtest("basic page API", |
| 117 | {$td->COMMAND => "test_driver 15 page_api_1.pdf"}, | 117 | {$td->COMMAND => "test_driver 15 page_api_1.pdf"}, |
| @@ -131,6 +131,17 @@ $td->runtest("duplicate page", | @@ -131,6 +131,17 @@ $td->runtest("duplicate page", | ||
| 131 | {$td->COMMAND => "test_driver 17 page_api_2.pdf"}, | 131 | {$td->COMMAND => "test_driver 17 page_api_2.pdf"}, |
| 132 | {$td->FILE => "page_api_2.out", $td->EXIT_STATUS => 2}, | 132 | {$td->FILE => "page_api_2.out", $td->EXIT_STATUS => 2}, |
| 133 | $td->NORMALIZE_NEWLINES); | 133 | $td->NORMALIZE_NEWLINES); |
| 134 | +$td->runtest("delete and re-add a page", | ||
| 135 | + {$td->COMMAND => "test_driver 18 page_api_1.pdf"}, | ||
| 136 | + {$td->STRING => "test 18 done\n", $td->EXIT_STATUS => 0}, | ||
| 137 | + $td->NORMALIZE_NEWLINES); | ||
| 138 | +$td->runtest("check output", | ||
| 139 | + {$td->FILE => "a.pdf"}, | ||
| 140 | + {$td->FILE => "page_api_1-out3.pdf"}); | ||
| 141 | +$td->runtest("duplicate page", | ||
| 142 | + {$td->COMMAND => "test_driver 19 page_api_1.pdf"}, | ||
| 143 | + {$td->FILE => "page_api_1.out", $td->EXIT_STATUS => 2}, | ||
| 144 | + $td->NORMALIZE_NEWLINES); | ||
| 134 | # ---------- | 145 | # ---------- |
| 135 | $td->notify("--- Miscellaneous Tests ---"); | 146 | $td->notify("--- Miscellaneous Tests ---"); |
| 136 | $n_tests += 37; | 147 | $n_tests += 37; |
qpdf/qtest/qpdf/page_api_1-out3.pdf
0 → 100644
| 1 | +%PDF-1.3 | ||
| 2 | +%¿÷¢þ | ||
| 3 | +1 0 obj | ||
| 4 | +<< /Pages 3 0 R /Type /Catalog >> | ||
| 5 | +endobj | ||
| 6 | +2 0 obj | ||
| 7 | +<< /CreationDate (D:20120621111522) /Producer (Apex PDFWriter) >> | ||
| 8 | +endobj | ||
| 9 | +3 0 obj | ||
| 10 | +<< /Count 10 /Kids [ 4 0 R 5 0 R 6 0 R 7 0 R 8 0 R 9 0 R 10 0 R 11 0 R 12 0 R 13 0 R ] /Type /Pages >> | ||
| 11 | +endobj | ||
| 12 | +4 0 obj | ||
| 13 | +<< /Contents 14 0 R /MediaBox [ 0 0 612 792 ] /Parent 3 0 R /Resources << /Font << /F1 15 0 R >> /ProcSet [ /PDF /Text ] >> /Type /Page >> | ||
| 14 | +endobj | ||
| 15 | +5 0 obj | ||
| 16 | +<< /Contents 16 0 R /MediaBox [ 0 0 612 792 ] /Parent 3 0 R /Resources << /Font << /F1 15 0 R >> /ProcSet [ /PDF /Text ] >> /Type /Page >> | ||
| 17 | +endobj | ||
| 18 | +6 0 obj | ||
| 19 | +<< /Contents 17 0 R /MediaBox [ 0 0 612 792 ] /Parent 3 0 R /Resources << /Font << /F1 15 0 R >> /ProcSet [ /PDF /Text ] >> /Type /Page >> | ||
| 20 | +endobj | ||
| 21 | +7 0 obj | ||
| 22 | +<< /Contents 18 0 R /MediaBox [ 0 0 612 792 ] /Parent 3 0 R /Resources << /Font << /F1 15 0 R >> /ProcSet [ /PDF /Text ] >> /Type /Page >> | ||
| 23 | +endobj | ||
| 24 | +8 0 obj | ||
| 25 | +<< /Contents 19 0 R /MediaBox [ 0 0 612 792 ] /Parent 3 0 R /Resources << /Font << /F1 15 0 R >> /ProcSet [ /PDF /Text ] >> /Type /Page >> | ||
| 26 | +endobj | ||
| 27 | +9 0 obj | ||
| 28 | +<< /Contents 20 0 R /MediaBox [ 0 0 612 792 ] /Parent 3 0 R /Resources << /Font << /F1 15 0 R >> /ProcSet [ /PDF /Text ] >> /Type /Page >> | ||
| 29 | +endobj | ||
| 30 | +10 0 obj | ||
| 31 | +<< /Contents 21 0 R /MediaBox [ 0 0 612 792 ] /Parent 3 0 R /Resources << /Font << /F1 15 0 R >> /ProcSet [ /PDF /Text ] >> /Type /Page >> | ||
| 32 | +endobj | ||
| 33 | +11 0 obj | ||
| 34 | +<< /Contents 22 0 R /MediaBox [ 0 0 612 792 ] /Parent 3 0 R /Resources << /Font << /F1 15 0 R >> /ProcSet [ /PDF /Text ] >> /Type /Page >> | ||
| 35 | +endobj | ||
| 36 | +12 0 obj | ||
| 37 | +<< /Contents 23 0 R /MediaBox [ 0 0 612 792 ] /Parent 3 0 R /Resources << /Font << /F1 15 0 R >> /ProcSet [ /PDF /Text ] >> /Type /Page >> | ||
| 38 | +endobj | ||
| 39 | +13 0 obj | ||
| 40 | +<< /Contents 24 0 R /MediaBox [ 0 0 612 792 ] /Parent 3 0 R /Resources << /Font << /F1 15 0 R >> /ProcSet [ /PDF /Text ] >> /Type /Page >> | ||
| 41 | +endobj | ||
| 42 | +14 0 obj | ||
| 43 | +<< /Length 47 >> | ||
| 44 | +stream | ||
| 45 | +BT /F1 15 Tf 72 720 Td (Original page 0) Tj ET | ||
| 46 | +endstream | ||
| 47 | +endobj | ||
| 48 | +15 0 obj | ||
| 49 | +<< /BaseFont /Times-Roman /Encoding /WinAnsiEncoding /Subtype /Type1 /Type /Font >> | ||
| 50 | +endobj | ||
| 51 | +16 0 obj | ||
| 52 | +<< /Length 47 >> | ||
| 53 | +stream | ||
| 54 | +BT /F1 15 Tf 72 720 Td (Original page 1) Tj ET | ||
| 55 | +endstream | ||
| 56 | +endobj | ||
| 57 | +17 0 obj | ||
| 58 | +<< /Length 47 >> | ||
| 59 | +stream | ||
| 60 | +BT /F1 15 Tf 72 720 Td (Original page 2) Tj ET | ||
| 61 | +endstream | ||
| 62 | +endobj | ||
| 63 | +18 0 obj | ||
| 64 | +<< /Length 47 >> | ||
| 65 | +stream | ||
| 66 | +BT /F1 15 Tf 72 720 Td (Original page 3) Tj ET | ||
| 67 | +endstream | ||
| 68 | +endobj | ||
| 69 | +19 0 obj | ||
| 70 | +<< /Length 47 >> | ||
| 71 | +stream | ||
| 72 | +BT /F1 15 Tf 72 720 Td (Original page 4) Tj ET | ||
| 73 | +endstream | ||
| 74 | +endobj | ||
| 75 | +20 0 obj | ||
| 76 | +<< /Length 47 >> | ||
| 77 | +stream | ||
| 78 | +BT /F1 15 Tf 72 720 Td (Original page 6) Tj ET | ||
| 79 | +endstream | ||
| 80 | +endobj | ||
| 81 | +21 0 obj | ||
| 82 | +<< /Length 47 >> | ||
| 83 | +stream | ||
| 84 | +BT /F1 15 Tf 72 720 Td (Original page 7) Tj ET | ||
| 85 | +endstream | ||
| 86 | +endobj | ||
| 87 | +22 0 obj | ||
| 88 | +<< /Length 47 >> | ||
| 89 | +stream | ||
| 90 | +BT /F1 15 Tf 72 720 Td (Original page 8) Tj ET | ||
| 91 | +endstream | ||
| 92 | +endobj | ||
| 93 | +23 0 obj | ||
| 94 | +<< /Length 47 >> | ||
| 95 | +stream | ||
| 96 | +BT /F1 15 Tf 72 720 Td (Original page 9) Tj ET | ||
| 97 | +endstream | ||
| 98 | +endobj | ||
| 99 | +24 0 obj | ||
| 100 | +<< /Length 47 >> | ||
| 101 | +stream | ||
| 102 | +BT /F1 15 Tf 72 720 Td (Original page 5) Tj ET | ||
| 103 | +endstream | ||
| 104 | +endobj | ||
| 105 | +xref | ||
| 106 | +0 25 | ||
| 107 | +0000000000 65535 f | ||
| 108 | +0000000015 00000 n | ||
| 109 | +0000000064 00000 n | ||
| 110 | +0000000145 00000 n | ||
| 111 | +0000000263 00000 n | ||
| 112 | +0000000417 00000 n | ||
| 113 | +0000000571 00000 n | ||
| 114 | +0000000725 00000 n | ||
| 115 | +0000000879 00000 n | ||
| 116 | +0000001033 00000 n | ||
| 117 | +0000001187 00000 n | ||
| 118 | +0000001342 00000 n | ||
| 119 | +0000001497 00000 n | ||
| 120 | +0000001652 00000 n | ||
| 121 | +0000001807 00000 n | ||
| 122 | +0000001904 00000 n | ||
| 123 | +0000002004 00000 n | ||
| 124 | +0000002101 00000 n | ||
| 125 | +0000002198 00000 n | ||
| 126 | +0000002295 00000 n | ||
| 127 | +0000002392 00000 n | ||
| 128 | +0000002489 00000 n | ||
| 129 | +0000002586 00000 n | ||
| 130 | +0000002683 00000 n | ||
| 131 | +0000002780 00000 n | ||
| 132 | +trailer << /Info 2 0 R /Root 1 0 R /Size 25 /ID [<21f7a6fb083dab8e29743918a08bfa31><31415926535897932384626433832795>] >> | ||
| 133 | +startxref | ||
| 134 | +2877 | ||
| 135 | +%%EOF |
qpdf/qtest/qpdf/page_api_1.out
0 → 100644
| 1 | +page_api_1.pdf (page 10 (numbered from zero): object 9 0): duplicate page reference found; this would cause loss of data |
qpdf/test_driver.cc
| @@ -779,6 +779,34 @@ void runtest(int n, char const* filename) | @@ -779,6 +779,34 @@ void runtest(int n, char const* filename) | ||
| 779 | pdf.removePage(pages[0]); | 779 | pdf.removePage(pages[0]); |
| 780 | std::cout << "you can't see this" << std::endl; | 780 | std::cout << "you can't see this" << std::endl; |
| 781 | } | 781 | } |
| 782 | + else if (n == 18) | ||
| 783 | + { | ||
| 784 | + // Remove a page and re-insert it in the same file. | ||
| 785 | + std::vector<QPDFObjectHandle> const& pages = pdf.getAllPages(); | ||
| 786 | + | ||
| 787 | + // Remove pages from various places, checking to make sure | ||
| 788 | + // that our pages reference is getting updated. | ||
| 789 | + assert(pages.size() == 10); | ||
| 790 | + QPDFObjectHandle page5 = pages[5]; | ||
| 791 | + pdf.removePage(page5); | ||
| 792 | + pdf.addPage(page5, false); | ||
| 793 | + assert(pages.size() == 10); | ||
| 794 | + assert(pages.back().getObjectID() == page5.getObjectID()); | ||
| 795 | + | ||
| 796 | + QPDFWriter w(pdf, "a.pdf"); | ||
| 797 | + w.setStaticID(true); | ||
| 798 | + w.setStreamDataMode(qpdf_s_preserve); | ||
| 799 | + w.write(); | ||
| 800 | + } | ||
| 801 | + else if (n == 19) | ||
| 802 | + { | ||
| 803 | + // Remove a page and re-insert it in the same file. | ||
| 804 | + std::vector<QPDFObjectHandle> const& pages = pdf.getAllPages(); | ||
| 805 | + | ||
| 806 | + // Try to insert a page that's already there. | ||
| 807 | + pdf.addPage(pages[5], false); | ||
| 808 | + std::cout << "you can't see this" << std::endl; | ||
| 809 | + } | ||
| 782 | else | 810 | else |
| 783 | { | 811 | { |
| 784 | throw std::runtime_error(std::string("invalid test ") + | 812 | throw std::runtime_error(std::string("invalid test ") + |