Added tests for short tags with pairs of values.

This commit is contained in:
Andrey Kiselev 2008-04-15 14:20:30 +00:00
parent 924a2d8827
commit 73865f3af5

View File

@ -1,4 +1,4 @@
/* $Id: short_tag.c,v 1.7 2008-03-28 01:42:06 bfriesen Exp $ */
/* $Id: short_tag.c,v 1.8 2008-04-15 14:20:30 dron Exp $ */
/*
* Copyright (c) 2004, Andrey Kiselev <dron@ak4719.spb.edu>
@ -38,11 +38,9 @@
#endif
#include "tiffio.h"
#include "tifftest.h"
extern int CheckShortField(TIFF *tif, ttag_t field, uint16 value);
extern int CheckLongField(TIFF *tif, ttag_t field, uint32 value);
const char *filename = "short_test.tiff";
static const char filename[] = "short_test.tiff";
#define SPP 3 /* Samples per pixel */
const uint16 width = 1;
@ -52,32 +50,39 @@ const uint16 photometric = PHOTOMETRIC_RGB;
const uint16 rows_per_strip = 1;
const uint16 planarconfig = PLANARCONFIG_CONTIG;
static struct SingleTags {
ttag_t tag;
uint16 value;
static const struct {
const ttag_t tag;
const uint16 value;
} short_single_tags[] = {
{ TIFFTAG_COMPRESSION, COMPRESSION_NONE },
{ TIFFTAG_FILLORDER, FILLORDER_MSB2LSB },
{ TIFFTAG_ORIENTATION, ORIENTATION_BOTRIGHT },
{ TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH },
{ TIFFTAG_INKSET, INKSET_MULTIINK },
{ TIFFTAG_MINSAMPLEVALUE, 23 },
{ TIFFTAG_MAXSAMPLEVALUE, 241 },
{ TIFFTAG_INKSET, INKSET_MULTIINK },
{ TIFFTAG_NUMBEROFINKS, SPP },
{ TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT }
/*{ TIFFTAG_IMAGEDEPTH, 1 },
{ TIFFTAG_TILEDEPTH, 1 }*/
};
#define NSINGLETAGS (sizeof(short_single_tags) / sizeof(short_single_tags[0]))
static const struct {
const ttag_t tag;
const uint16 values[2];
} short_paired_tags[] = {
{ TIFFTAG_PAGENUMBER, {1, 1} },
{ TIFFTAG_HALFTONEHINTS, {0, 255} },
{ TIFFTAG_DOTRANGE, {8, 16} },
{ TIFFTAG_YCBCRSUBSAMPLING, {2, 1} }
};
#define NPAIREDTAGS (sizeof(short_paired_tags) / sizeof(short_paired_tags[0]))
int
main(int argc, char **argv)
main()
{
TIFF *tif;
unsigned int i;
unsigned char buf[3] = { 0, 127, 255 };
(void) argc;
(void) argv;
size_t i;
unsigned char buf[SPP] = { 0, 127, 255 };
/* Test whether we can write tags. */
tif = TIFFOpen(filename, "w");
@ -118,8 +123,18 @@ main(int argc, char **argv)
for (i = 0; i < NSINGLETAGS; i++) {
if (!TIFFSetField(tif, short_single_tags[i].tag,
short_single_tags[i].value)) {
fprintf(stderr, "Can't set tag %d.\n",
(int)short_single_tags[i].tag);
fprintf(stderr, "Can't set tag %lu.\n",
(unsigned long)short_single_tags[i].tag);
goto failure;
}
}
for (i = 0; i < NPAIREDTAGS; i++) {
if (!TIFFSetField(tif, short_paired_tags[i].tag,
short_paired_tags[i].values[0],
short_paired_tags[i].values[1])) {
fprintf(stderr, "Can't set tag %lu.\n",
(unsigned long)short_paired_tags[i].tag);
goto failure;
}
}
@ -166,6 +181,12 @@ main(int argc, char **argv)
goto failure;
}
for (i = 0; i < NPAIREDTAGS; i++) {
if (CheckShortPairedField(tif, short_paired_tags[i].tag,
short_paired_tags[i].values) < 0)
goto failure;
}
TIFFClose(tif);
/* All tests passed; delete file and exit with success status. */
@ -173,9 +194,11 @@ main(int argc, char **argv)
return 0;
failure:
/* Something goes wrong; close file and return unsuccessful status. */
/*
* Something goes wrong; close file and return unsuccessful status.
* Do not remove the file for further manual investigation.
*/
TIFFClose(tif);
unlink(filename);
return 1;
}