Update test program to process all files on the command-line, add a --help and

--verbose option, and return the results of the unit tests.
This commit is contained in:
Michael R Sweet 2021-08-23 14:40:15 -04:00
parent 543364dfa2
commit 3f2de9c46a
No known key found for this signature in database
GPG Key ID: BE67C75EC81F3244

View File

@ -29,7 +29,7 @@
// Local functions...
//
static int do_test_file(const char *filename, int objnum);
static int do_test_file(const char *filename, int objnum, bool verbose);
static int do_unit_tests(void);
static int draw_image(pdfio_stream_t *st, const char *name, double x, double y, double w, double h, const char *label);
static bool error_cb(pdfio_file_t *pdf, const char *message, bool *error);
@ -56,22 +56,41 @@ int // O - Exit status
main(int argc, // I - Number of command-line arguments
char *argv[]) // I - Command-line arguments
{
int ret = 0; // Return value
if (argc > 1)
{
int i; // Looping var
bool verbose = false; // Be verbose?
for (i = 1; i < argc; i ++)
{
if ((i + 1) < argc && isdigit(argv[i + 1][0] & 255))
if (!strcmp(argv[i], "--help"))
{
puts("Usage: ./testpdfio [--help] [--verbose] [filename [objnum] ...]");
return (0);
}
else if (!strcmp(argv[i], "--verbose"))
{
verbose = true;
}
else if (argv[i][0] == '-')
{
printf("Unknown option '%s'.\n\n", argv[i]);
puts("Usage: ./testpdfio [--help] [--verbose] [filename [objnum] ...]");
return (1);
}
else if ((i + 1) < argc && isdigit(argv[i + 1][0] & 255))
{
// filename.pdf object-number
if (do_test_file(argv[i], atoi(argv[i + 1])))
return (1);
if (do_test_file(argv[i], atoi(argv[i + 1]), verbose))
ret = 1;
i ++;
}
else if (do_test_file(argv[i], 0))
return (1);
else if (do_test_file(argv[i], 0, verbose))
ret = 1;
}
}
else
@ -82,10 +101,10 @@ main(int argc, // I - Number of command-line arguments
_chdir("../..");
#endif // _WIN32
do_unit_tests();
ret = do_unit_tests();
}
return (0);
return (ret);
}
@ -95,7 +114,8 @@ main(int argc, // I - Number of command-line arguments
static int // O - Exit status
do_test_file(const char *filename, // I - PDF filename
int objnum) // I - Object number to dump, if any
int objnum, // I - Object number to dump, if any
bool verbose) // I - Be verbose?
{
bool error = false; // Have we shown an error yet?
pdfio_file_t *pdf; // PDF file
@ -158,6 +178,8 @@ do_test_file(const char *filename, // I - PDF filename
printf(" PDF %s, %d pages, %d objects.\n", pdfioFileGetVersion(pdf), (int)num_pages, (int)num_objs);
if (verbose)
{
// Show a summary of each page...
for (n = 0; n < num_pages; n ++)
{
@ -203,6 +225,7 @@ do_test_file(const char *filename, // I - PDF filename
}
}
}
}
// Close the file and return success...
pdfioFileClose(pdf);