Commit ee3682f1068fa8edc6e90b911fe2dbfa6bd7733a

Authored by Jay Berkenbilt
1 parent 1c944e4c

test_driver: accept optional second file name

This way we don't have to hard-code the name of a second file in the
test driver for tests that require one.
qpdf/qtest/qpdf.test
@@ -366,7 +366,8 @@ $td->runtest("check output", @@ -366,7 +366,8 @@ $td->runtest("check output",
366 {$td->FILE => "a.pdf"}, 366 {$td->FILE => "a.pdf"},
367 {$td->FILE => "reserved-objects.pdf"}); 367 {$td->FILE => "reserved-objects.pdf"});
368 $td->runtest("detect foreign object in write", 368 $td->runtest("detect foreign object in write",
369 - {$td->COMMAND => "test_driver 29 copy-foreign-objects-in.pdf"}, 369 + {$td->COMMAND => "test_driver 29" .
  370 + " copy-foreign-objects-in.pdf minimal.pdf"},
370 {$td->FILE => "foreign-in-write.out", $td->EXIT_STATUS => 0}, 371 {$td->FILE => "foreign-in-write.out", $td->EXIT_STATUS => 0},
371 $td->NORMALIZE_NEWLINES); 372 $td->NORMALIZE_NEWLINES);
372 373
@@ -391,7 +392,7 @@ foreach my $d ([25, 1], [26, 2], [27, 3]) @@ -391,7 +392,7 @@ foreach my $d ([25, 1], [26, 2], [27, 3])
391 my ($testn, $outn) = @$d; 392 my ($testn, $outn) = @$d;
392 $td->runtest("copy objects $outn", 393 $td->runtest("copy objects $outn",
393 {$td->COMMAND => "test_driver $testn" . 394 {$td->COMMAND => "test_driver $testn" .
394 - " copy-foreign-objects-in.pdf"}, 395 + " copy-foreign-objects-in.pdf minimal.pdf"},
395 {$td->STRING => "test $testn done\n", $td->EXIT_STATUS => 0}, 396 {$td->STRING => "test $testn done\n", $td->EXIT_STATUS => 0},
396 $td->NORMALIZE_NEWLINES); 397 $td->NORMALIZE_NEWLINES);
397 $td->runtest("check output", 398 $td->runtest("check output",
@@ -399,7 +400,8 @@ foreach my $d ([25, 1], [26, 2], [27, 3]) @@ -399,7 +400,8 @@ foreach my $d ([25, 1], [26, 2], [27, 3])
399 {$td->FILE => "copy-foreign-objects-out$outn.pdf"}); 400 {$td->FILE => "copy-foreign-objects-out$outn.pdf"});
400 } 401 }
401 $td->runtest("copy objects error", 402 $td->runtest("copy objects error",
402 - {$td->COMMAND => "test_driver 28 copy-foreign-objects-in.pdf"}, 403 + {$td->COMMAND => "test_driver 28" .
  404 + " copy-foreign-objects-in.pdf minimal.pdf"},
403 {$td->FILE => "copy-foreign-objects-errors.out", 405 {$td->FILE => "copy-foreign-objects-errors.out",
404 $td->EXIT_STATUS => 0}, 406 $td->EXIT_STATUS => 0},
405 $td->NORMALIZE_NEWLINES); 407 $td->NORMALIZE_NEWLINES);
qpdf/test_driver.cc
@@ -21,7 +21,8 @@ static char const* whoami = 0; @@ -21,7 +21,8 @@ static char const* whoami = 0;
21 21
22 void usage() 22 void usage()
23 { 23 {
24 - std::cerr << "Usage: " << whoami << " n filename" << std::endl; 24 + std::cerr << "Usage: " << whoami << " n filename1 [filename2]"
  25 + << std::endl;
25 exit(2); 26 exit(2);
26 } 27 }
27 28
@@ -76,7 +77,7 @@ static QPDFObjectHandle createPageContents(QPDF&amp; pdf, std::string const&amp; text) @@ -76,7 +77,7 @@ static QPDFObjectHandle createPageContents(QPDF&amp; pdf, std::string const&amp; text)
76 return QPDFObjectHandle::newStream(&pdf, contents); 77 return QPDFObjectHandle::newStream(&pdf, contents);
77 } 78 }
78 79
79 -void runtest(int n, char const* filename) 80 +void runtest(int n, char const* filename1, char const* filename2)
80 { 81 {
81 // Most tests here are crafted to work on specific files. Look at 82 // Most tests here are crafted to work on specific files. Look at
82 // the test suite to see how the test is invoked to find the file 83 // the test suite to see how the test is invoked to find the file
@@ -94,21 +95,21 @@ void runtest(int n, char const* filename) @@ -94,21 +95,21 @@ void runtest(int n, char const* filename)
94 if (n % 4 == 0) 95 if (n % 4 == 0)
95 { 96 {
96 QTC::TC("qpdf", "exercise processFile(name)"); 97 QTC::TC("qpdf", "exercise processFile(name)");
97 - pdf.processFile(filename); 98 + pdf.processFile(filename1);
98 } 99 }
99 else 100 else
100 { 101 {
101 QTC::TC("qpdf", "exercise processFile(FILE*)"); 102 QTC::TC("qpdf", "exercise processFile(FILE*)");
102 - filep = QUtil::fopen_wrapper(std::string("open ") + filename,  
103 - fopen(filename, "rb"));  
104 - pdf.processFile(filename, filep, false); 103 + filep = QUtil::fopen_wrapper(std::string("open ") + filename1,
  104 + fopen(filename1, "rb"));
  105 + pdf.processFile(filename1, filep, false);
105 } 106 }
106 } 107 }
107 else 108 else
108 { 109 {
109 QTC::TC("qpdf", "exercise processMemoryFile"); 110 QTC::TC("qpdf", "exercise processMemoryFile");
110 - FILE* f = QUtil::fopen_wrapper(std::string("open ") + filename,  
111 - fopen(filename, "rb")); 111 + FILE* f = QUtil::fopen_wrapper(std::string("open ") + filename1,
  112 + fopen(filename1, "rb"));
112 fseek(f, 0, SEEK_END); 113 fseek(f, 0, SEEK_END);
113 size_t size = (size_t) QUtil::tell(f); 114 size_t size = (size_t) QUtil::tell(f);
114 fseek(f, 0, SEEK_SET); 115 fseek(f, 0, SEEK_SET);
@@ -125,7 +126,7 @@ void runtest(int n, char const* filename) @@ -125,7 +126,7 @@ void runtest(int n, char const* filename)
125 if (ferror(f)) 126 if (ferror(f))
126 { 127 {
127 throw std::runtime_error( 128 throw std::runtime_error(
128 - std::string("failure reading file ") + filename + 129 + std::string("failure reading file ") + filename1 +
129 " into memory: read " + 130 " into memory: read " +
130 QUtil::int_to_string(bytes_read) + "; wanted " + 131 QUtil::int_to_string(bytes_read) + "; wanted " +
131 QUtil::int_to_string(size)); 132 QUtil::int_to_string(size));
@@ -133,14 +134,14 @@ void runtest(int n, char const* filename) @@ -133,14 +134,14 @@ void runtest(int n, char const* filename)
133 else 134 else
134 { 135 {
135 throw std::logic_error( 136 throw std::logic_error(
136 - std::string("premature eof reading file ") + filename + 137 + std::string("premature eof reading file ") + filename1 +
137 " into memory: read " + 138 " into memory: read " +
138 QUtil::int_to_string(bytes_read) + "; wanted " + 139 QUtil::int_to_string(bytes_read) + "; wanted " +
139 QUtil::int_to_string(size)); 140 QUtil::int_to_string(size));
140 } 141 }
141 } 142 }
142 fclose(f); 143 fclose(f);
143 - pdf.processMemoryFile(filename, buf_p, size); 144 + pdf.processMemoryFile(filename1, buf_p, size);
144 } 145 }
145 146
146 if ((n == 0) || (n == 1)) 147 if ((n == 0) || (n == 1))
@@ -925,8 +926,9 @@ void runtest(int n, char const* filename) @@ -925,8 +926,9 @@ void runtest(int n, char const* filename)
925 // Copy qtest without crossing page boundaries. Should get O1 926 // Copy qtest without crossing page boundaries. Should get O1
926 // and O2 and their streams but not O3 or any other pages. 927 // and O2 and their streams but not O3 or any other pages.
927 928
  929 + assert(filename2 != 0);
928 QPDF newpdf; 930 QPDF newpdf;
929 - newpdf.processFile("minimal.pdf"); 931 + newpdf.processFile(filename2);
930 QPDFObjectHandle qtest = pdf.getTrailer().getKey("/QTest"); 932 QPDFObjectHandle qtest = pdf.getTrailer().getKey("/QTest");
931 newpdf.getTrailer().replaceKey( 933 newpdf.getTrailer().replaceKey(
932 "/QTest", newpdf.copyForeignObject(qtest)); 934 "/QTest", newpdf.copyForeignObject(qtest));
@@ -944,8 +946,9 @@ void runtest(int n, char const* filename) @@ -944,8 +946,9 @@ void runtest(int n, char const* filename)
944 // that O3 points to. Also, inherited object will have been 946 // that O3 points to. Also, inherited object will have been
945 // pushed down and will be preserved. 947 // pushed down and will be preserved.
946 948
  949 + assert(filename2 != 0);
947 QPDF newpdf; 950 QPDF newpdf;
948 - newpdf.processFile("minimal.pdf"); 951 + newpdf.processFile(filename2);
949 QPDFObjectHandle qtest = pdf.getTrailer().getKey("/QTest"); 952 QPDFObjectHandle qtest = pdf.getTrailer().getKey("/QTest");
950 QPDFObjectHandle O3 = qtest.getKey("/O3"); 953 QPDFObjectHandle O3 = qtest.getKey("/O3");
951 newpdf.addPage(O3, false); 954 newpdf.addPage(O3, false);
@@ -963,8 +966,9 @@ void runtest(int n, char const* filename) @@ -963,8 +966,9 @@ void runtest(int n, char const* filename)
963 // Should get qtest plus only the O3 page and the page that O3 966 // Should get qtest plus only the O3 page and the page that O3
964 // points to. Inherited objects should be preserved. 967 // points to. Inherited objects should be preserved.
965 968
  969 + assert(filename2 != 0);
966 QPDF newpdf; 970 QPDF newpdf;
967 - newpdf.processFile("minimal.pdf"); 971 + newpdf.processFile(filename2);
968 QPDFObjectHandle qtest = pdf.getTrailer().getKey("/QTest"); 972 QPDFObjectHandle qtest = pdf.getTrailer().getKey("/QTest");
969 QPDFObjectHandle O3 = qtest.getKey("/O3"); 973 QPDFObjectHandle O3 = qtest.getKey("/O3");
970 newpdf.addPage(O3.getKey("/OtherPage"), false); 974 newpdf.addPage(O3.getKey("/OtherPage"), false);
@@ -1002,8 +1006,9 @@ void runtest(int n, char const* filename) @@ -1002,8 +1006,9 @@ void runtest(int n, char const* filename)
1002 else if (n == 29) 1006 else if (n == 29)
1003 { 1007 {
1004 // Detect mixed objects in QPDFWriter 1008 // Detect mixed objects in QPDFWriter
  1009 + assert(filename2 != 0);
1005 QPDF other; 1010 QPDF other;
1006 - other.processFile("minimal.pdf"); 1011 + other.processFile(filename2);
1007 // Should use copyForeignObject instead 1012 // Should use copyForeignObject instead
1008 other.getTrailer().replaceKey( 1013 other.getTrailer().replaceKey(
1009 "/QTest", pdf.getTrailer().getKey("/QTest")); 1014 "/QTest", pdf.getTrailer().getKey("/QTest"));
@@ -1049,7 +1054,7 @@ int main(int argc, char* argv[]) @@ -1049,7 +1054,7 @@ int main(int argc, char* argv[])
1049 whoami += 3; 1054 whoami += 3;
1050 } 1055 }
1051 1056
1052 - if (argc != 3) 1057 + if ((argc < 3) || (argc > 4))
1053 { 1058 {
1054 usage(); 1059 usage();
1055 } 1060 }
@@ -1057,8 +1062,9 @@ int main(int argc, char* argv[]) @@ -1057,8 +1062,9 @@ int main(int argc, char* argv[])
1057 try 1062 try
1058 { 1063 {
1059 int n = atoi(argv[1]); 1064 int n = atoi(argv[1]);
1060 - char const* filename = argv[2];  
1061 - runtest(n, filename); 1065 + char const* filename1 = argv[2];
  1066 + char const* filename2 = argv[3];
  1067 + runtest(n, filename1, filename2);
1062 } 1068 }
1063 catch (std::exception& e) 1069 catch (std::exception& e)
1064 { 1070 {