2
1
mirror of https://github.com/qpdf/qpdf.git synced 2025-01-03 15:17:29 +00:00

Refactor arg parsing in qpdf.cc to use QPDFArgParser

This commit is contained in:
Jay Berkenbilt 2021-12-30 20:02:15 -05:00
parent 52817f0a45
commit c60b4ea55a
3 changed files with 390 additions and 1013 deletions

File diff suppressed because it is too large Load Diff

View File

@ -255,7 +255,7 @@ QPDF not caching overridden objstm object 0
QPDFWriter original obj non-zero gen 0 QPDFWriter original obj non-zero gen 0
QPDF_optimization indirect outlines 0 QPDF_optimization indirect outlines 0
QPDF xref space 2 QPDF xref space 2
qpdf pages range omitted at end 0 qpdf pages range omitted at end 1
qpdf pages range omitted in middle 0 qpdf pages range omitted in middle 0
qpdf npages 0 qpdf npages 0
QPDF already reserved object 0 QPDF already reserved object 0
@ -273,8 +273,6 @@ QPDF resolve failure to null 0
QPDFWriter preserve unreferenced standard 0 QPDFWriter preserve unreferenced standard 0
QPDFObjectHandle errors in parsecontent 0 QPDFObjectHandle errors in parsecontent 0
qpdf same file error 0 qpdf same file error 0
qpdf read args from stdin 0
qpdf read args from file 0
qpdf split-pages %d 0 qpdf split-pages %d 0
qpdf split-pages .pdf 0 qpdf split-pages .pdf 0
qpdf split-pages other 0 qpdf split-pages other 0
@ -362,8 +360,6 @@ QPDFOutlineObjectHelper named dest 0
QPDFOutlineDocumentHelper name named dest 0 QPDFOutlineDocumentHelper name named dest 0
QPDFOutlineDocumentHelper string named dest 0 QPDFOutlineDocumentHelper string named dest 0
QPDFOutlineObjectHelper loop 0 QPDFOutlineObjectHelper loop 0
qpdf required parameter 0
qpdf required choices 0
QPDFObjectHandle merge top type mismatch 0 QPDFObjectHandle merge top type mismatch 0
QPDFObjectHandle merge shallow copy 0 QPDFObjectHandle merge shallow copy 0
QPDFObjectHandle merge array 0 QPDFObjectHandle merge array 0
@ -599,7 +595,6 @@ qpdf copy fields non-first from orig 0
QPDF resolve duplicated page in insert 0 QPDF resolve duplicated page in insert 0
QPDFWriter preserve object streams 1 QPDFWriter preserve object streams 1
QPDFWriter exclude from object stream 0 QPDFWriter exclude from object stream 0
check unclosed --pages 1
QPDF_pages findPage not found 0 QPDF_pages findPage not found 0
qpdf overlay page with no resources 0 qpdf overlay page with no resources 0
QPDFObjectHandle check ownership 0 QPDFObjectHandle check ownership 0
@ -629,3 +624,5 @@ qpdf-c called qpdf_oh_replace_stream_data 0
qpdf-c silence oh errors 0 qpdf-c silence oh errors 0
qpdf-c called qpdf_oh_get_binary_string_value 0 qpdf-c called qpdf_oh_get_binary_string_value 0
qpdf-c called qpdf_oh_new_binary_string 0 qpdf-c called qpdf_oh_new_binary_string 0
qpdf duplicated pages password 0
qpdf misplaced pages password 0

View File

@ -149,7 +149,7 @@ foreach my $c (@completion_tests)
show_ntests(); show_ntests();
# ---------- # ----------
$td->notify("--- Argument Parsing ---"); $td->notify("--- Argument Parsing ---");
$n_tests += 9; $n_tests += 12;
$td->runtest("required argument", $td->runtest("required argument",
{$td->COMMAND => "qpdf --password minimal.pdf"}, {$td->COMMAND => "qpdf --password minimal.pdf"},
@ -182,18 +182,33 @@ $td->runtest("extra overlay filename",
$td->EXIT_STATUS => 2}, $td->EXIT_STATUS => 2},
$td->NORMALIZE_NEWLINES); $td->NORMALIZE_NEWLINES);
$td->runtest("multiple pages options", $td->runtest("multiple pages options",
{$td->COMMAND => "qpdf --pages . -- --pages . --"}, {$td->COMMAND => "qpdf --pages . --password=x -- --pages . --"},
{$td->REGEXP => ".*--pages may only be specified one time.*", {$td->REGEXP => ".*--pages may only be specified one time.*",
$td->EXIT_STATUS => 2}, $td->EXIT_STATUS => 2},
$td->NORMALIZE_NEWLINES); $td->NORMALIZE_NEWLINES);
$td->runtest("bad numeric range detects unclosed --pages", $td->runtest("bad numeric range detects unclosed --pages",
{$td->COMMAND => "qpdf --pages . --pages . --"}, {$td->COMMAND => "qpdf --pages . --pages . --"},
{$td->REGEXP => ".*--pages option must be terminated with --.*", {$td->REGEXP => ".*pages options must be terminated with --.*",
$td->EXIT_STATUS => 2}, $td->EXIT_STATUS => 2},
$td->NORMALIZE_NEWLINES); $td->NORMALIZE_NEWLINES);
$td->runtest("bad file detected as unclosed --pages", $td->runtest("bad file detected as unclosed --pages",
{$td->COMMAND => "qpdf --pages . 1 --xyz out"}, {$td->COMMAND => "qpdf --pages . 1 --xyz out"},
{$td->REGEXP => ".*--pages option must be terminated with --.*", {$td->REGEXP => ".*pages options must be terminated with --.*",
$td->EXIT_STATUS => 2},
$td->NORMALIZE_NEWLINES);
$td->runtest("misplaced pages password 1",
{$td->COMMAND => "qpdf --pages . 1 --password=z --"},
{$td->REGEXP => ".*password must immediately follow a file name.*",
$td->EXIT_STATUS => 2},
$td->NORMALIZE_NEWLINES);
$td->runtest("misplaced pages password 2",
{$td->COMMAND => "qpdf --pages --password=z . 1 --"},
{$td->REGEXP => ".*password must immediately follow a file name.*",
$td->EXIT_STATUS => 2},
$td->NORMALIZE_NEWLINES);
$td->runtest("duplicated pages password",
{$td->COMMAND => "qpdf --pages . --password=z --password=z --"},
{$td->REGEXP => ".*password already specified.*",
$td->EXIT_STATUS => 2}, $td->EXIT_STATUS => 2},
$td->NORMALIZE_NEWLINES); $td->NORMALIZE_NEWLINES);