From 1b364ad7b863d26e444d76501deb65f19092a832 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Thu, 21 Jun 2012 15:27:32 -0400 Subject: Add additional page API test cases --- qpdf/qtest/qpdf.test | 13 +++- qpdf/qtest/qpdf/page_api_1-out3.pdf | 135 ++++++++++++++++++++++++++++++++++++ qpdf/qtest/qpdf/page_api_1.out | 1 + qpdf/test_driver.cc | 28 ++++++++ 4 files changed, 176 insertions(+), 1 deletion(-) create mode 100644 qpdf/qtest/qpdf/page_api_1-out3.pdf create mode 100644 qpdf/qtest/qpdf/page_api_1.out diff --git a/qpdf/qtest/qpdf.test b/qpdf/qtest/qpdf.test index bc0d5643..053fb3b2 100644 --- a/qpdf/qtest/qpdf.test +++ b/qpdf/qtest/qpdf.test @@ -111,7 +111,7 @@ $td->runtest("new stream", show_ntests(); # ---------- $td->notify("--- Page API Tests ---"); -$n_tests += 5; +$n_tests += 8; $td->runtest("basic page API", {$td->COMMAND => "test_driver 15 page_api_1.pdf"}, @@ -131,6 +131,17 @@ $td->runtest("duplicate page", {$td->COMMAND => "test_driver 17 page_api_2.pdf"}, {$td->FILE => "page_api_2.out", $td->EXIT_STATUS => 2}, $td->NORMALIZE_NEWLINES); +$td->runtest("delete and re-add a page", + {$td->COMMAND => "test_driver 18 page_api_1.pdf"}, + {$td->STRING => "test 18 done\n", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "page_api_1-out3.pdf"}); +$td->runtest("duplicate page", + {$td->COMMAND => "test_driver 19 page_api_1.pdf"}, + {$td->FILE => "page_api_1.out", $td->EXIT_STATUS => 2}, + $td->NORMALIZE_NEWLINES); # ---------- $td->notify("--- Miscellaneous Tests ---"); $n_tests += 37; diff --git a/qpdf/qtest/qpdf/page_api_1-out3.pdf b/qpdf/qtest/qpdf/page_api_1-out3.pdf new file mode 100644 index 00000000..74a9cb44 --- /dev/null +++ b/qpdf/qtest/qpdf/page_api_1-out3.pdf @@ -0,0 +1,135 @@ +%PDF-1.3 +%¿÷¢þ +1 0 obj +<< /Pages 3 0 R /Type /Catalog >> +endobj +2 0 obj +<< /CreationDate (D:20120621111522) /Producer (Apex PDFWriter) >> +endobj +3 0 obj +<< /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 >> +endobj +4 0 obj +<< /Contents 14 0 R /MediaBox [ 0 0 612 792 ] /Parent 3 0 R /Resources << /Font << /F1 15 0 R >> /ProcSet [ /PDF /Text ] >> /Type /Page >> +endobj +5 0 obj +<< /Contents 16 0 R /MediaBox [ 0 0 612 792 ] /Parent 3 0 R /Resources << /Font << /F1 15 0 R >> /ProcSet [ /PDF /Text ] >> /Type /Page >> +endobj +6 0 obj +<< /Contents 17 0 R /MediaBox [ 0 0 612 792 ] /Parent 3 0 R /Resources << /Font << /F1 15 0 R >> /ProcSet [ /PDF /Text ] >> /Type /Page >> +endobj +7 0 obj +<< /Contents 18 0 R /MediaBox [ 0 0 612 792 ] /Parent 3 0 R /Resources << /Font << /F1 15 0 R >> /ProcSet [ /PDF /Text ] >> /Type /Page >> +endobj +8 0 obj +<< /Contents 19 0 R /MediaBox [ 0 0 612 792 ] /Parent 3 0 R /Resources << /Font << /F1 15 0 R >> /ProcSet [ /PDF /Text ] >> /Type /Page >> +endobj +9 0 obj +<< /Contents 20 0 R /MediaBox [ 0 0 612 792 ] /Parent 3 0 R /Resources << /Font << /F1 15 0 R >> /ProcSet [ /PDF /Text ] >> /Type /Page >> +endobj +10 0 obj +<< /Contents 21 0 R /MediaBox [ 0 0 612 792 ] /Parent 3 0 R /Resources << /Font << /F1 15 0 R >> /ProcSet [ /PDF /Text ] >> /Type /Page >> +endobj +11 0 obj +<< /Contents 22 0 R /MediaBox [ 0 0 612 792 ] /Parent 3 0 R /Resources << /Font << /F1 15 0 R >> /ProcSet [ /PDF /Text ] >> /Type /Page >> +endobj +12 0 obj +<< /Contents 23 0 R /MediaBox [ 0 0 612 792 ] /Parent 3 0 R /Resources << /Font << /F1 15 0 R >> /ProcSet [ /PDF /Text ] >> /Type /Page >> +endobj +13 0 obj +<< /Contents 24 0 R /MediaBox [ 0 0 612 792 ] /Parent 3 0 R /Resources << /Font << /F1 15 0 R >> /ProcSet [ /PDF /Text ] >> /Type /Page >> +endobj +14 0 obj +<< /Length 47 >> +stream +BT /F1 15 Tf 72 720 Td (Original page 0) Tj ET +endstream +endobj +15 0 obj +<< /BaseFont /Times-Roman /Encoding /WinAnsiEncoding /Subtype /Type1 /Type /Font >> +endobj +16 0 obj +<< /Length 47 >> +stream +BT /F1 15 Tf 72 720 Td (Original page 1) Tj ET +endstream +endobj +17 0 obj +<< /Length 47 >> +stream +BT /F1 15 Tf 72 720 Td (Original page 2) Tj ET +endstream +endobj +18 0 obj +<< /Length 47 >> +stream +BT /F1 15 Tf 72 720 Td (Original page 3) Tj ET +endstream +endobj +19 0 obj +<< /Length 47 >> +stream +BT /F1 15 Tf 72 720 Td (Original page 4) Tj ET +endstream +endobj +20 0 obj +<< /Length 47 >> +stream +BT /F1 15 Tf 72 720 Td (Original page 6) Tj ET +endstream +endobj +21 0 obj +<< /Length 47 >> +stream +BT /F1 15 Tf 72 720 Td (Original page 7) Tj ET +endstream +endobj +22 0 obj +<< /Length 47 >> +stream +BT /F1 15 Tf 72 720 Td (Original page 8) Tj ET +endstream +endobj +23 0 obj +<< /Length 47 >> +stream +BT /F1 15 Tf 72 720 Td (Original page 9) Tj ET +endstream +endobj +24 0 obj +<< /Length 47 >> +stream +BT /F1 15 Tf 72 720 Td (Original page 5) Tj ET +endstream +endobj +xref +0 25 +0000000000 65535 f +0000000015 00000 n +0000000064 00000 n +0000000145 00000 n +0000000263 00000 n +0000000417 00000 n +0000000571 00000 n +0000000725 00000 n +0000000879 00000 n +0000001033 00000 n +0000001187 00000 n +0000001342 00000 n +0000001497 00000 n +0000001652 00000 n +0000001807 00000 n +0000001904 00000 n +0000002004 00000 n +0000002101 00000 n +0000002198 00000 n +0000002295 00000 n +0000002392 00000 n +0000002489 00000 n +0000002586 00000 n +0000002683 00000 n +0000002780 00000 n +trailer << /Info 2 0 R /Root 1 0 R /Size 25 /ID [<21f7a6fb083dab8e29743918a08bfa31><31415926535897932384626433832795>] >> +startxref +2877 +%%EOF diff --git a/qpdf/qtest/qpdf/page_api_1.out b/qpdf/qtest/qpdf/page_api_1.out new file mode 100644 index 00000000..f705b886 --- /dev/null +++ b/qpdf/qtest/qpdf/page_api_1.out @@ -0,0 +1 @@ +page_api_1.pdf (page 10 (numbered from zero): object 9 0): duplicate page reference found; this would cause loss of data diff --git a/qpdf/test_driver.cc b/qpdf/test_driver.cc index 24e2f1ec..b2ceca5c 100644 --- a/qpdf/test_driver.cc +++ b/qpdf/test_driver.cc @@ -779,6 +779,34 @@ void runtest(int n, char const* filename) pdf.removePage(pages[0]); std::cout << "you can't see this" << std::endl; } + else if (n == 18) + { + // Remove a page and re-insert it in the same file. + std::vector const& pages = pdf.getAllPages(); + + // Remove pages from various places, checking to make sure + // that our pages reference is getting updated. + assert(pages.size() == 10); + QPDFObjectHandle page5 = pages[5]; + pdf.removePage(page5); + pdf.addPage(page5, false); + assert(pages.size() == 10); + assert(pages.back().getObjectID() == page5.getObjectID()); + + QPDFWriter w(pdf, "a.pdf"); + w.setStaticID(true); + w.setStreamDataMode(qpdf_s_preserve); + w.write(); + } + else if (n == 19) + { + // Remove a page and re-insert it in the same file. + std::vector const& pages = pdf.getAllPages(); + + // Try to insert a page that's already there. + pdf.addPage(pages[5], false); + std::cout << "you can't see this" << std::endl; + } else { throw std::runtime_error(std::string("invalid test ") + -- cgit v1.2.3-54-g00ecf