Commit f6893242148460170253ef0ae51a6cd4b5ec8f95

Authored by Jay Berkenbilt
1 parent 9c00874e

Restore coverage case

Previous commit lost coverage case for buffer-based replaceStreamData.
ChangeLog
  1 +2012-07-25 Jay Berkenbilt <ejb@ql.org>
  2 +
  3 + * From Tobias: add QPDFObjectHandle::replaceStreamData that takes
  4 + a std::string analogous to the QPDFObjectHandle::newStream that
  5 + takes a string that was added earlier.
  6 +
1 2012-07-21 Jay Berkenbilt <ejb@ql.org> 7 2012-07-21 Jay Berkenbilt <ejb@ql.org>
2 8
3 * Change configure to have image comparison tests disabled by 9 * Change configure to have image comparison tests disabled by
examples/pdf-double-page-size.cc
@@ -61,12 +61,7 @@ int main(int argc, char* argv[]) @@ -61,12 +61,7 @@ int main(int argc, char* argv[])
61 char const* password = (argc == 4) ? argv[3] : ""; 61 char const* password = (argc == 4) ? argv[3] : "";
62 62
63 // Text to prepend to each page's contents 63 // Text to prepend to each page's contents
64 - char const* content = "2 0 0 2 0 0 cm\n";  
65 -  
66 - // Copy text into a buffer without the null terminator  
67 - PointerHolder<Buffer> b = new Buffer(strlen(content));  
68 - unsigned char* bp = b->getBuffer();  
69 - memcpy(bp, (unsigned char*)content, strlen(content)); 64 + std::string content = "2 0 0 2 0 0 cm\n";
70 65
71 try 66 try
72 { 67 {
@@ -80,7 +75,8 @@ int main(int argc, char* argv[]) @@ -80,7 +75,8 @@ int main(int argc, char* argv[])
80 QPDFObjectHandle& page = *iter; 75 QPDFObjectHandle& page = *iter;
81 76
82 // Prepend the buffer to the page's contents 77 // Prepend the buffer to the page's contents
83 - page.addPageContents(QPDFObjectHandle::newStream(&qpdf, b), true); 78 + page.addPageContents(
  79 + QPDFObjectHandle::newStream(&qpdf, content), true);
84 80
85 // Double the size of each of the content boxes 81 // Double the size of each of the content boxes
86 doubleBoxSize(page, "/MediaBox"); 82 doubleBoxSize(page, "/MediaBox");
qpdf/test_driver.cc
@@ -455,11 +455,9 @@ void runtest(int n, char const* filename1, char const* filename2) @@ -455,11 +455,9 @@ void runtest(int n, char const* filename1, char const* filename2)
455 { 455 {
456 throw std::logic_error("test 7 run on file with no QStream"); 456 throw std::logic_error("test 7 run on file with no QStream");
457 } 457 }
458 - PointerHolder<Buffer> b = new Buffer(20);  
459 - unsigned char* bp = b->getBuffer();  
460 - memcpy(bp, (char*)"new data for stream\n", 20); // no null!  
461 qstream.replaceStreamData( 458 qstream.replaceStreamData(
462 - b, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull()); 459 + "new data for stream\n",
  460 + QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull());
463 QPDFWriter w(pdf, "a.pdf"); 461 QPDFWriter w(pdf, "a.pdf");
464 w.setStaticID(true); 462 w.setStaticID(true);
465 w.setStreamDataMode(qpdf_s_preserve); 463 w.setStreamDataMode(qpdf_s_preserve);
@@ -509,8 +507,12 @@ void runtest(int n, char const* filename1, char const* filename2) @@ -509,8 +507,12 @@ void runtest(int n, char const* filename1, char const* filename2)
509 else if (n == 9) 507 else if (n == 9)
510 { 508 {
511 QPDFObjectHandle root = pdf.getRoot(); 509 QPDFObjectHandle root = pdf.getRoot();
  510 + // Explicitly exercise the Buffer version of newStream
  511 + PointerHolder<Buffer> buf = new Buffer(20);
  512 + unsigned char* bp = buf->getBuffer();
  513 + memcpy(bp, (char*)"data for new stream\n", 20); // no null!
512 QPDFObjectHandle qstream = QPDFObjectHandle::newStream( 514 QPDFObjectHandle qstream = QPDFObjectHandle::newStream(
513 - &pdf, "data for new stream\n"); 515 + &pdf, buf);
514 QPDFObjectHandle rstream = QPDFObjectHandle::newStream(&pdf); 516 QPDFObjectHandle rstream = QPDFObjectHandle::newStream(&pdf);
515 try 517 try
516 { 518 {
@@ -521,11 +523,9 @@ void runtest(int n, char const* filename1, char const* filename2) @@ -521,11 +523,9 @@ void runtest(int n, char const* filename1, char const* filename2)
521 { 523 {
522 std::cout << "exception: " << e.what() << std::endl; 524 std::cout << "exception: " << e.what() << std::endl;
523 } 525 }
524 - PointerHolder<Buffer> buf = new Buffer(22);  
525 - unsigned char* bp = buf->getBuffer();  
526 - memcpy(bp, (char*)"data for other stream\n", 22); // no null!  
527 rstream.replaceStreamData( 526 rstream.replaceStreamData(
528 - buf, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull()); 527 + "data for other stream\n",
  528 + QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull());
529 root.replaceKey("/QStream", qstream); 529 root.replaceKey("/QStream", qstream);
530 root.replaceKey("/RStream", rstream); 530 root.replaceKey("/RStream", rstream);
531 QPDFWriter w(pdf, "a.pdf"); 531 QPDFWriter w(pdf, "a.pdf");