Imported from libpng-0.98.tar

This commit is contained in:
Glenn Randers-Pehrson
1998-01-16 22:06:18 -06:00
parent 2687fcc7b5
commit c4a2ae6cac
26 changed files with 687 additions and 240 deletions

View File

@@ -1,12 +1,12 @@
/* pngtest.c - a simple test program to test libpng
*
* libpng 0.97
* libpng 0.98
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson
* January 7, 1998
* January 16, 1998
*
* This program reads in a PNG image, writes it out again, and then
* compares the two files. If the files are identical, this shows that
@@ -37,6 +37,8 @@
#include "png.h"
int test_one_file(PNG_CONST char *inname, PNG_CONST char *outname);
#ifdef __TURBOC__
#include <mem.h>
#endif
@@ -45,10 +47,10 @@
/* #define STDERR stderr */
#define STDERR stdout /* for DOS */
#if defined(PNG_NO_STDIO)
/* START of code to validate stdio-free compilation */
/* These copies of the default read/write functions come from pngrio.c and */
/* pngwio.c. They allow "don't include stdio" testing of the library. */
#if defined(PNG_NO_STDIO)
/* This is the function which does the actual reading of data. If you are
not reading from a standard C stream, you should create a replacement
read_data function and use it at run time with png_set_read_fn(), rather
@@ -118,7 +120,7 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
png_error(png_ptr, "read Error");
}
}
#endif
#endif /* USE_FAR_KEYWORD */
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
static void
@@ -196,7 +198,7 @@ png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
}
}
#endif
#endif /* USE_FAR_KEYWORD */
/* This function is called when there is a warning, but the library thinks
* it can continue anyway. Replacement functions don't have to do anything
@@ -224,13 +226,13 @@ png_default_error(png_structp png_ptr, png_const_charp message)
/* We can return because png_error calls the default handler which is
* actually ok in this case. */
}
#endif
#endif /* PNG_NO_STDIO */
/* END of code to validate stdio-free compilation */
/* Test one file */
int test(PNG_CONST char *inname, PNG_CONST char *outname)
int test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
{
FILE *fpin, *fpout;
static FILE *fpin, *fpout; /* "static" prevents setjmp corruption */
png_structp read_ptr, write_ptr;
png_infop read_info_ptr, write_info_ptr, end_info_ptr;
png_bytep row_buf;
@@ -263,16 +265,18 @@ int test(PNG_CONST char *inname, PNG_CONST char *outname)
read_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL,
(png_error_ptr)NULL, (png_error_ptr)NULL);
#if defined(PNG_NO_STDIO)
png_set_error_fn(read_ptr, (png_voidp)inname, png_default_error, png_default_warning);
png_set_error_fn(read_ptr, (png_voidp)inname, png_default_error,
png_default_warning);
#endif
write_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL,
(png_error_ptr)NULL, (png_error_ptr)NULL);
#if defined(PNG_NO_STDIO)
png_set_error_fn(write_ptr, (png_voidp)inname, png_default_error, png_default_warning);
png_set_error_fn(write_ptr, (png_voidp)inname, png_default_error,
png_default_warning);
#endif
png_debug(0, "Allocating read_info, write_info and end_info structures\n");
read_info_ptr = png_create_info_struct(read_ptr);
write_info_ptr = png_create_info_struct(read_ptr);
write_info_ptr = png_create_info_struct(write_ptr);
end_info_ptr = png_create_info_struct(read_ptr);
png_debug(0, "Setting jmpbuf for read struct\n");
@@ -371,7 +375,7 @@ int test(PNG_CONST char *inname, PNG_CONST char *outname)
#endif
#if defined(PNG_READ_sRGB_SUPPORTED) && defined(PNG_WRITE_sRGB_SUPPORTED)
{
png_byte intent;
int intent;
if (png_get_sRGB(read_ptr, read_info_ptr, &intent))
{
@@ -515,14 +519,13 @@ int test(PNG_CONST char *inname, PNG_CONST char *outname)
png_write_end(write_ptr, end_info_ptr);
png_debug(0, "Destroying data structs\n");
png_free(read_ptr, row_buf);
png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
png_destroy_write_struct(&write_ptr, &write_info_ptr);
fclose(fpin);
fclose(fpout);
png_free(read_ptr, row_buf);
png_debug(0, "Opening files for comparison\n");
if ((fpin = fopen(inname, "rb")) == NULL)
{
@@ -576,8 +579,8 @@ int test(PNG_CONST char *inname, PNG_CONST char *outname)
PNG_CONST char *inname = "pngtest_png";
PNG_CONST char *outname = "pngout_png";
#else
PNG_CONST char *inname = "pngtest.png";
PNG_CONST char *outname = "pngout.png";
static char *inname = "pngtest.png";
static char *outname = "pngout.png";
#endif
int
@@ -608,12 +611,15 @@ main(int argc, char *argv[])
if (!multiple && argc == 3)
outname = argv[2];
if (!multiple && argc > 3 || multiple && argc < 2)
if ((!multiple && argc > 3) || (multiple && argc < 2))
{
fprintf(STDERR, "usage: %s [infile.png] [outfile.png]\n\t%s -m {infile.png}\n",
fprintf(STDERR,
"usage: %s [infile.png] [outfile.png]\n\t%s -m {infile.png}\n",
argv[0], argv[0]);
fprintf(STDERR, " reads/writes one PNG file (without -m) or multiple files (-m)\n");
fprintf(STDERR, " with -m %s is used as a temporary file\n", outname);
fprintf(STDERR,
" reads/writes one PNG file (without -m) or multiple files (-m)\n");
fprintf(STDERR,
" with -m %s is used as a temporary file\n", outname);
exit(1);
}
@@ -622,13 +628,29 @@ main(int argc, char *argv[])
int i;
for (i=2; i<argc; ++i)
{
fprintf(STDERR, "Testing %s:\n",argv[i]);
ierror += test(argv[i], outname);
int kerror;
fprintf(STDERR, "Testing %s:",argv[i]);
kerror = test_one_file(argv[i], outname);
if (kerror == 0) fprintf(STDERR, " PASS\n");
else {
fprintf(STDERR, " FAIL\n");
ierror += kerror;
}
}
}
else
{
ierror += test(inname, outname);
int i;
for (i=0; i<3; ++i) {
int kerror;
fprintf(STDERR, "Testing %s:",inname);
kerror = test_one_file(inname, outname);
if (kerror == 0) fprintf(STDERR, " PASS\n");
else {
fprintf(STDERR, " FAIL\n");
ierror += kerror;
}
}
}
if (ierror == 0)