add many new tests to exercise C api

git-svn-id: svn+q:///qpdf/trunk@727 71b93d88-0707-0410-a8cf-f5a4172ac649
This commit is contained in:
Jay Berkenbilt 2009-09-27 16:01:45 +00:00
parent 91d8c48533
commit fe6771e0e5
255 changed files with 903 additions and 27 deletions

2
TODO
View File

@ -18,8 +18,6 @@
files...ideally we should provide the object number currently being
read
* Have --check report the version number of the PDF file
* See if it is possible to support rewriting a file in place or at
least to detect and block this

View File

@ -39,7 +39,10 @@ class QPDF
// lifetime. This method must be called before any methods that
// potentially ask for information about the PDF file are called.
// Prior to calling this, the only methods that are allowed are
// those that set parameters.
// those that set parameters. If the input file is not
// encrypted,either a null password or an empty password can be
// used. If the file is encrypted, either the user password or
// the owner password may be supplied.
DLL_EXPORT
void processFile(char const* filename, char const* password = 0);

View File

@ -83,11 +83,11 @@ QPDF_BOOL qpdf_more_warnings(qpdf_data qpdf)
DLL_EXPORT
char const* qpdf_next_error(qpdf_data qpdf)
{
QTC::TC("qpdf", "qpdf-c called qpdf_next_error");
if (qpdf_more_errors(qpdf))
{
qpdf->tmp_string = qpdf->error;
qpdf->error.clear();
QTC::TC("qpdf", "qpdf-c qpdf_next_error returned error");
return qpdf->tmp_string.c_str();
}
else
@ -99,11 +99,11 @@ char const* qpdf_next_error(qpdf_data qpdf)
DLL_EXPORT
char const* qpdf_next_warning(qpdf_data qpdf)
{
QTC::TC("qpdf", "qpdf-c called qpdf_next_warning");
if (qpdf_more_warnings(qpdf))
{
qpdf->tmp_string = qpdf->warnings.front();
qpdf->warnings.pop_front();
QTC::TC("qpdf", "qpdf-c qpdf_next_warning returned warning");
return qpdf->tmp_string.c_str();
}
else

View File

@ -1,6 +1,84 @@
#include <qpdf/qpdf-c.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
int main()
static qpdf_data qpdf = 0;
static void report_errors()
{
while (qpdf_more_warnings(qpdf))
{
printf("warning: %s\n", qpdf_next_warning(qpdf));
}
while (qpdf_more_errors(qpdf))
{
printf("error: %s\n", qpdf_next_error(qpdf));
}
}
static void test01(char const* infile,
char const* password,
char const* outfile)
{
qpdf_read(qpdf, infile, password);
printf("version: %s\n", qpdf_get_pdf_version(qpdf));
printf("linearized: %d\n", qpdf_is_linearized(qpdf));
printf("encrypted: %d\n", qpdf_is_encrypted(qpdf));
if (qpdf_is_encrypted(qpdf))
{
printf("user password: %s\n", qpdf_get_user_password(qpdf));
}
report_errors();
}
int main(int argc, char* argv[])
{
char* whoami = 0;
char* p = 0;
int n = 0;
char const* infile;
char const* password;
char const* outfile;
void (*fn)(char const*, char const*, char const*) = 0;
if ((p = strrchr(argv[0], '/')) != NULL)
{
whoami = p + 1;
}
else if ((p = strrchr(argv[0], '\\')) != NULL)
{
whoami = p + 1;
}
else
{
whoami = argv[0];
}
if (argc != 5)
{
fprintf(stderr, "usage: %s n infile password outfile\n", whoami);
exit(2);
}
n = atoi(argv[1]);
infile = argv[2];
password = argv[3];
outfile = argv[4];
fn = ((n == 1) ? test01 :
0);
if (fn == 0)
{
fprintf(stderr, "%s: invalid test number %d\n", whoami, n);
exit(2);
}
qpdf = qpdf_init();
fn(infile, password, outfile);
qpdf_cleanup(&qpdf);
assert(qpdf == 0);
return 0;
}

View File

@ -858,6 +858,8 @@ int main(int argc, char* argv[])
std::cout << "checking " << infilename << std::endl;
try
{
std::cout << "PDF Version: " << pdf.getPDFVersion()
<< std::endl;
::show_encryption(pdf);
if (pdf.isLinearized())
{

View File

@ -122,8 +122,8 @@ qpdf-c called qpdf_init 0
qpdf-c called qpdf_cleanup 0
qpdf-c called qpdf_more_errors 0
qpdf-c called qpdf_more_warnings 0
qpdf-c called qpdf_next_error 0
qpdf-c called qpdf_next_warning 0
qpdf-c qpdf_next_error returned error 0
qpdf-c qpdf_next_warning returned warning 0
qpdf-c called qpdf_set_suppress_warnings 0
qpdf-c called qpdf_set_ignore_xref_streams 0
qpdf-c called qpdf_set_attempt_recovery 0

View File

@ -159,7 +159,7 @@ for (my $i = 1; $i <= scalar(@badfiles); ++$i)
show_ntests();
# ----------
$td->notify("--- Recovery Tests ---");
$n_tests += @badfiles + 7;
$n_tests += @badfiles + 8;
# Recovery tests. These are mostly after-the-fact -- when recovery
# was implemented, some degree of recovery was possible on many of the
@ -226,6 +226,12 @@ $td->runtest("run check on damaged file",
{$td->FILE => "append-page-content-damaged-check.out",
$td->EXIT_STATUS => 3},
$td->NORMALIZE_NEWLINES);
$td->runtest("check with C API",
{$td->COMMAND =>
"qpdf-ctest 1 append-page-content-damaged.pdf '' ''"},
{$td->FILE => "append-page-content-damaged-c-check.out",
$td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
show_ntests();
# ----------
@ -346,7 +352,7 @@ for (my $n = 16; $n <= 19; ++$n)
show_ntests();
# ----------
$td->notify("--- Specific File Tests ---");
$n_tests += 3;
$n_tests += 4;
$n_compare_pdfs += 1;
# Special PDF files that caused problems at some point
@ -356,11 +362,13 @@ $n_compare_pdfs += 1;
# happen to test boundary conditions in the LZW decoder.
$td->runtest("old and complex",
{$td->COMMAND => "qpdf --check old-and-complex.pdf"},
{$td->STRING => +("checking old-and-complex.pdf\n" .
"File is not encrypted\n" .
"File is not linearized\n" .
"No errors found\n"),
$td->EXIT_STATUS => 0},
{$td->FILE => "old-and-complex-check.out",
$td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
$td->runtest("old and complex (C API)",
{$td->COMMAND => "qpdf-ctest 1 old-and-complex.pdf '' ''"},
{$td->FILE => "old-and-complex-c-check.out",
$td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
$td->runtest("convert to qdf",
@ -534,19 +542,13 @@ check_pdf("linearized and modified",
$td->runtest("check linearized and modified",
{$td->COMMAND => "qpdf --check lin-delete-and-reuse.pdf"},
{$td->STRING => +("checking lin-delete-and-reuse.pdf\n" .
"File is not encrypted\n" .
"File is not linearized\n" .
"No errors found\n"),
$td->EXIT_STATUS => 0},
{$td->FILE => "lin-delete-and-reuse-check.out",
$td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
$td->runtest("check multiple modifications",
{$td->COMMAND => "qpdf --check multiple-mods.pdf"},
{$td->STRING => +("checking multiple-mods.pdf\n" .
"File is not encrypted\n" .
"File is not linearized\n" .
"No errors found\n"),
$td->EXIT_STATUS => 0},
{$td->FILE => "multiple-mods-check.out",
$td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
foreach my $base (@to_linearize)
@ -812,7 +814,7 @@ my @flags = (["-qdf", # 1
"no arguments"],
);
$n_tests += (@files * @flags * 2 * 2);
$n_tests += (@files * @flags * 2 * 3);
$n_compare_pdfs += (@files * @flags * 2);
$n_acroread += (@files * @flags * 2);
@ -825,6 +827,7 @@ foreach my $file (@files)
my $n = 0;
my $oflags = "--object-streams=$o";
my $odescrip = "os:" . substr($o, 0, 1);
my $osuf = ($o eq 'generate' ? "-ogen" : "");
foreach my $d (@flags)
{
my ($flags, $fdescrip) = @$d;
@ -838,7 +841,13 @@ foreach my $file (@files)
$td->runtest("check status",
{$td->COMMAND => "qpdf --check a.pdf"},
{$td->FILE => "$base.$n.check",
{$td->FILE => "$base.$n$osuf.check",
$td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
$td->runtest("check with C API",
{$td->COMMAND => [qw(qpdf-ctest 1 a.pdf), "", ""]},
{$td->FILE => "$base.$n$osuf.c-check",
$td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);

View File

@ -0,0 +1,3 @@
version: 1.5
linearized: 0
encrypted: 0

View File

@ -0,0 +1,5 @@
checking a.pdf
PDF Version: 1.5
File is not encrypted
File is not linearized
No errors found

View File

@ -0,0 +1,3 @@
version: 1.3
linearized: 0
encrypted: 0

View File

@ -1,4 +1,5 @@
checking a.pdf
PDF Version: 1.3
File is not encrypted
File is not linearized
No errors found

View File

@ -0,0 +1,4 @@
version: 1.5
linearized: 0
encrypted: 1
user password:

View File

@ -0,0 +1,6 @@
checking a.pdf
PDF Version: 1.5
P = -4
User password =
File is not linearized
No errors found

View File

@ -0,0 +1,4 @@
version: 1.4
linearized: 0
encrypted: 1
user password:

View File

@ -1,4 +1,5 @@
checking a.pdf
PDF Version: 1.4
P = -4
User password =
File is not linearized

View File

@ -0,0 +1,4 @@
version: 1.5
linearized: 1
encrypted: 1
user password:

View File

@ -0,0 +1,6 @@
checking a.pdf
PDF Version: 1.5
P = -4
User password =
File is linearized
No errors found

View File

@ -0,0 +1,4 @@
version: 1.4
linearized: 1
encrypted: 1
user password:

View File

@ -1,4 +1,5 @@
checking a.pdf
PDF Version: 1.4
P = -4
User password =
File is linearized

View File

@ -0,0 +1,4 @@
version: 1.5
linearized: 0
encrypted: 1
user password:

View File

@ -0,0 +1,6 @@
checking a.pdf
PDF Version: 1.5
P = -60
User password =
File is not linearized
No errors found

View File

@ -0,0 +1,4 @@
version: 1.3
linearized: 0
encrypted: 1
user password:

View File

@ -1,4 +1,5 @@
checking a.pdf
PDF Version: 1.3
P = -60
User password =
File is not linearized

View File

@ -0,0 +1,3 @@
version: 1.5
linearized: 0
encrypted: 0

View File

@ -0,0 +1,5 @@
checking a.pdf
PDF Version: 1.5
File is not encrypted
File is not linearized
No errors found

View File

@ -0,0 +1,3 @@
version: 1.3
linearized: 0
encrypted: 0

View File

@ -1,4 +1,5 @@
checking a.pdf
PDF Version: 1.3
File is not encrypted
File is not linearized
No errors found

View File

@ -0,0 +1,3 @@
version: 1.5
linearized: 0
encrypted: 0

View File

@ -0,0 +1,5 @@
checking a.pdf
PDF Version: 1.5
File is not encrypted
File is not linearized
No errors found

View File

@ -0,0 +1,3 @@
version: 1.3
linearized: 0
encrypted: 0

View File

@ -1,4 +1,5 @@
checking a.pdf
PDF Version: 1.3
File is not encrypted
File is not linearized
No errors found

View File

@ -0,0 +1,3 @@
version: 1.5
linearized: 0
encrypted: 0

View File

@ -0,0 +1,5 @@
checking a.pdf
PDF Version: 1.5
File is not encrypted
File is not linearized
No errors found

View File

@ -0,0 +1,3 @@
version: 1.3
linearized: 0
encrypted: 0

View File

@ -1,4 +1,5 @@
checking a.pdf
PDF Version: 1.3
File is not encrypted
File is not linearized
No errors found

View File

@ -0,0 +1,3 @@
version: 1.5
linearized: 0
encrypted: 0

View File

@ -0,0 +1,5 @@
checking a.pdf
PDF Version: 1.5
File is not encrypted
File is not linearized
No errors found

View File

@ -0,0 +1,3 @@
version: 1.3
linearized: 0
encrypted: 0

View File

@ -1,4 +1,5 @@
checking a.pdf
PDF Version: 1.3
File is not encrypted
File is not linearized
No errors found

View File

@ -0,0 +1,3 @@
version: 1.5
linearized: 0
encrypted: 0

View File

@ -0,0 +1,5 @@
checking a.pdf
PDF Version: 1.5
File is not encrypted
File is not linearized
No errors found

View File

@ -0,0 +1,3 @@
version: 1.3
linearized: 0
encrypted: 0

View File

@ -1,4 +1,5 @@
checking a.pdf
PDF Version: 1.3
File is not encrypted
File is not linearized
No errors found

View File

@ -0,0 +1,3 @@
version: 1.5
linearized: 0
encrypted: 0

View File

@ -0,0 +1,5 @@
checking a.pdf
PDF Version: 1.5
File is not encrypted
File is not linearized
No errors found

View File

@ -0,0 +1,3 @@
version: 1.3
linearized: 0
encrypted: 0

View File

@ -1,4 +1,5 @@
checking a.pdf
PDF Version: 1.3
File is not encrypted
File is not linearized
No errors found

View File

@ -0,0 +1,3 @@
version: 1.5
linearized: 0
encrypted: 0

View File

@ -0,0 +1,5 @@
checking a.pdf
PDF Version: 1.5
File is not encrypted
File is not linearized
No errors found

View File

@ -0,0 +1,3 @@
version: 1.3
linearized: 0
encrypted: 0

View File

@ -1,4 +1,5 @@
checking a.pdf
PDF Version: 1.3
File is not encrypted
File is not linearized
No errors found

View File

@ -0,0 +1,4 @@
version: 1.5
linearized: 1
encrypted: 1
user password:

View File

@ -0,0 +1,6 @@
checking a.pdf
PDF Version: 1.5
P = -60
User password =
File is linearized
No errors found

View File

@ -0,0 +1,4 @@
version: 1.3
linearized: 1
encrypted: 1
user password:

View File

@ -1,4 +1,5 @@
checking a.pdf
PDF Version: 1.3
P = -60
User password =
File is linearized

View File

@ -0,0 +1,9 @@
WARNING: append-page-content-damaged.pdf: offset 0: file is damaged
WARNING: append-page-content-damaged.pdf: can't find startxref
WARNING: Attempting to reconstruct cross-reference table
version: 1.3
linearized: 0
encrypted: 0
warning: append-page-content-damaged.pdf: offset 0: file is damaged
warning: append-page-content-damaged.pdf: can't find startxref
warning: Attempting to reconstruct cross-reference table

View File

@ -2,5 +2,6 @@ WARNING: append-page-content-damaged.pdf: offset 0: file is damaged
WARNING: append-page-content-damaged.pdf: can't find startxref
WARNING: Attempting to reconstruct cross-reference table
checking append-page-content-damaged.pdf
PDF Version: 1.3
File is not encrypted
File is not linearized

View File

@ -1,4 +1,5 @@
checking damaged-stream.pdf
PDF Version: 1.3
File is not encrypted
File is not linearized
WARNING: damaged-stream.pdf: offset 426: error decoding stream data for object 5 0: LZWDecoder: bad code received

View File

@ -1,4 +1,5 @@
checking fax-decode-parms.pdf
PDF Version: 1.4
File is not encrypted
File is not linearized
No errors found

View File

@ -0,0 +1,3 @@
version: 1.5
linearized: 0
encrypted: 0

View File

@ -0,0 +1,5 @@
checking a.pdf
PDF Version: 1.5
File is not encrypted
File is not linearized
No errors found

View File

@ -0,0 +1,3 @@
version: 1.5
linearized: 0
encrypted: 0

View File

@ -1,4 +1,5 @@
checking a.pdf
PDF Version: 1.5
File is not encrypted
File is not linearized
No errors found

View File

@ -0,0 +1,4 @@
version: 1.5
linearized: 0
encrypted: 1
user password:

View File

@ -0,0 +1,6 @@
checking a.pdf
PDF Version: 1.5
P = -4
User password =
File is not linearized
No errors found

View File

@ -0,0 +1,4 @@
version: 1.5
linearized: 0
encrypted: 1
user password:

View File

@ -1,4 +1,5 @@
checking a.pdf
PDF Version: 1.5
P = -4
User password =
File is not linearized

View File

@ -0,0 +1,4 @@
version: 1.5
linearized: 1
encrypted: 1
user password:

View File

@ -0,0 +1,6 @@
checking a.pdf
PDF Version: 1.5
P = -4
User password =
File is linearized
No errors found

View File

@ -0,0 +1,4 @@
version: 1.5
linearized: 1
encrypted: 1
user password:

View File

@ -1,4 +1,5 @@
checking a.pdf
PDF Version: 1.5
P = -4
User password =
File is linearized

View File

@ -0,0 +1,3 @@
version: 1.5
linearized: 0
encrypted: 0

View File

@ -0,0 +1,5 @@
checking a.pdf
PDF Version: 1.5
File is not encrypted
File is not linearized
No errors found

View File

@ -0,0 +1,3 @@
version: 1.5
linearized: 0
encrypted: 0

View File

@ -1,4 +1,5 @@
checking a.pdf
PDF Version: 1.5
File is not encrypted
File is not linearized
No errors found

View File

@ -0,0 +1,3 @@
version: 1.5
linearized: 0
encrypted: 0

View File

@ -0,0 +1,5 @@
checking a.pdf
PDF Version: 1.5
File is not encrypted
File is not linearized
No errors found

View File

@ -0,0 +1,3 @@
version: 1.5
linearized: 0
encrypted: 0

View File

@ -1,4 +1,5 @@
checking a.pdf
PDF Version: 1.5
File is not encrypted
File is not linearized
No errors found

View File

@ -0,0 +1,3 @@
version: 1.5
linearized: 0
encrypted: 0

View File

@ -0,0 +1,5 @@
checking a.pdf
PDF Version: 1.5
File is not encrypted
File is not linearized
No errors found

View File

@ -0,0 +1,3 @@
version: 1.5
linearized: 0
encrypted: 0

View File

@ -1,4 +1,5 @@
checking a.pdf
PDF Version: 1.5
File is not encrypted
File is not linearized
No errors found

View File

@ -0,0 +1,3 @@
version: 1.5
linearized: 0
encrypted: 0

View File

@ -0,0 +1,5 @@
checking a.pdf
PDF Version: 1.5
File is not encrypted
File is not linearized
No errors found

View File

@ -0,0 +1,3 @@
version: 1.5
linearized: 0
encrypted: 0

View File

@ -1,4 +1,5 @@
checking a.pdf
PDF Version: 1.5
File is not encrypted
File is not linearized
No errors found

View File

@ -0,0 +1,3 @@
version: 1.5
linearized: 0
encrypted: 0

View File

@ -0,0 +1,5 @@
checking a.pdf
PDF Version: 1.5
File is not encrypted
File is not linearized
No errors found

View File

@ -0,0 +1,3 @@
version: 1.5
linearized: 0
encrypted: 0

View File

@ -1,4 +1,5 @@
checking a.pdf
PDF Version: 1.5
File is not encrypted
File is not linearized
No errors found

View File

@ -0,0 +1,3 @@
version: 1.5
linearized: 0
encrypted: 0

View File

@ -0,0 +1,5 @@
checking a.pdf
PDF Version: 1.5
File is not encrypted
File is not linearized
No errors found

View File

@ -0,0 +1,3 @@
version: 1.5
linearized: 0
encrypted: 0

View File

@ -1,4 +1,5 @@
checking a.pdf
PDF Version: 1.5
File is not encrypted
File is not linearized
No errors found

View File

@ -0,0 +1,3 @@
version: 1.5
linearized: 0
encrypted: 0

View File

@ -0,0 +1,5 @@
checking a.pdf
PDF Version: 1.5
File is not encrypted
File is not linearized
No errors found

View File

@ -0,0 +1,3 @@
version: 1.5
linearized: 0
encrypted: 0

View File

@ -1,4 +1,5 @@
checking a.pdf
PDF Version: 1.5
File is not encrypted
File is not linearized
No errors found

View File

@ -0,0 +1,3 @@
version: 1.5
linearized: 0
encrypted: 0

Some files were not shown because too many files have changed in this diff Show More