Commit 2a057ac0d4053d2306f48bc9e89b0dcb1959b9da

Authored by Jay Berkenbilt
1 parent 4f305488

Add test case for removing a page we don't have

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 += 8; 114 +$n_tests += 9;
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"},
@@ -142,6 +142,10 @@ $td->runtest("duplicate page", @@ -142,6 +142,10 @@ $td->runtest("duplicate page",
142 {$td->COMMAND => "test_driver 19 page_api_1.pdf"}, 142 {$td->COMMAND => "test_driver 19 page_api_1.pdf"},
143 {$td->FILE => "page_api_1.out", $td->EXIT_STATUS => 2}, 143 {$td->FILE => "page_api_1.out", $td->EXIT_STATUS => 2},
144 $td->NORMALIZE_NEWLINES); 144 $td->NORMALIZE_NEWLINES);
  145 +$td->runtest("remove page we don't have",
  146 + {$td->COMMAND => "test_driver 22 page_api_1.pdf"},
  147 + {$td->FILE => "page_api_1.out2", $td->EXIT_STATUS => 2},
  148 + $td->NORMALIZE_NEWLINES);
145 # ---------- 149 # ----------
146 $td->notify("--- Miscellaneous Tests ---"); 150 $td->notify("--- Miscellaneous Tests ---");
147 $n_tests += 40; 151 $n_tests += 40;
qpdf/qtest/qpdf/page_api_1.out2 0 → 100644
  1 +page_api_1.pdf (page object: object 4 0): page object not referenced in /Pages tree
qpdf/test_driver.cc
@@ -826,6 +826,15 @@ void runtest(int n, char const* filename) @@ -826,6 +826,15 @@ void runtest(int n, char const* filename)
826 contents.shallowCopy(); 826 contents.shallowCopy();
827 std::cout << "you can't see this" << std::endl; 827 std::cout << "you can't see this" << std::endl;
828 } 828 }
  829 + else if (n == 22)
  830 + {
  831 + // Try to remove a page we don't have
  832 + std::vector<QPDFObjectHandle> const& pages = pdf.getAllPages();
  833 + QPDFObjectHandle page = pages[0];
  834 + pdf.removePage(page);
  835 + pdf.removePage(page);
  836 + std::cout << "you can't see this" << std::endl;
  837 + }
829 else 838 else
830 { 839 {
831 throw std::runtime_error(std::string("invalid test ") + 840 throw std::runtime_error(std::string("invalid test ") +