Skip to content

Commit dee0207

Browse files
pre-commit run by Even Rouaultrouault
pre-commit run by Even Rouault
authored andcommitted
Reformatting in test/ using 'pre-commit run'
1 parent b0ae5d7 commit dee0207

21 files changed

+6177
-5007
lines changed

test/ascii_tag.c

+143-134
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
/*
22
* Copyright (c) 2004, Andrey Kiselev <[email protected]>
33
*
4-
* Permission to use, copy, modify, distribute, and sell this software and
4+
* Permission to use, copy, modify, distribute, and sell this software and
55
* its documentation for any purpose is hereby granted without fee, provided
66
* that (i) the above copyright notices and this permission notice appear in
77
* all copies of the software and related documentation, and (ii) the names of
88
* Sam Leffler and Silicon Graphics may not be used in any advertising or
99
* publicity relating to the software without the specific, prior written
1010
* permission of Sam Leffler and Silicon Graphics.
11-
*
12-
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
13-
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
14-
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
15-
*
11+
*
12+
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
13+
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
14+
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
15+
*
1616
* IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
1717
* ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
1818
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
19-
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
20-
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
19+
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
20+
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
2121
* OF THIS SOFTWARE.
2222
*/
2323

@@ -32,142 +32,151 @@
3232
#include <stdio.h>
3333
#include <string.h>
3434

35-
#ifdef HAVE_UNISTD_H
36-
# include <unistd.h>
37-
#endif
35+
#ifdef HAVE_UNISTD_H
36+
#include <unistd.h>
37+
#endif
3838

3939
#include "tiffio.h"
4040

4141
static const char filename[] = "ascii_test.tiff";
4242

43-
static const struct {
44-
ttag_t tag;
45-
const char *value;
46-
} ascii_tags[] = {
47-
{ TIFFTAG_DOCUMENTNAME, "Test TIFF image" },
48-
{ TIFFTAG_IMAGEDESCRIPTION, "Temporary test image" },
49-
{ TIFFTAG_MAKE, "This is not scanned image" },
50-
{ TIFFTAG_MODEL, "No scanner" },
51-
{ TIFFTAG_PAGENAME, "Test page" },
52-
{ TIFFTAG_SOFTWARE, "Libtiff library" },
53-
{ TIFFTAG_DATETIME, "2004:09:10 16:09:00" },
54-
{ TIFFTAG_ARTIST, "Andrey V. Kiselev" },
55-
{ TIFFTAG_HOSTCOMPUTER, "Debian GNU/Linux (Sarge)" },
56-
{ TIFFTAG_TARGETPRINTER, "No printer" },
57-
{ TIFFTAG_COPYRIGHT, "Copyright (c) 2004, Andrey Kiselev" },
58-
{ TIFFTAG_FAXSUBADDRESS, "Fax subaddress" },
59-
/* DGN tags */
60-
{ TIFFTAG_UNIQUECAMERAMODEL, "No camera" },
61-
{ TIFFTAG_CAMERASERIALNUMBER, "1234567890" }
62-
};
63-
#define NTAGS (sizeof (ascii_tags) / sizeof (ascii_tags[0]))
43+
static const struct
44+
{
45+
ttag_t tag;
46+
const char *value;
47+
} ascii_tags[] = {{TIFFTAG_DOCUMENTNAME, "Test TIFF image"},
48+
{TIFFTAG_IMAGEDESCRIPTION, "Temporary test image"},
49+
{TIFFTAG_MAKE, "This is not scanned image"},
50+
{TIFFTAG_MODEL, "No scanner"},
51+
{TIFFTAG_PAGENAME, "Test page"},
52+
{TIFFTAG_SOFTWARE, "Libtiff library"},
53+
{TIFFTAG_DATETIME, "2004:09:10 16:09:00"},
54+
{TIFFTAG_ARTIST, "Andrey V. Kiselev"},
55+
{TIFFTAG_HOSTCOMPUTER, "Debian GNU/Linux (Sarge)"},
56+
{TIFFTAG_TARGETPRINTER, "No printer"},
57+
{TIFFTAG_COPYRIGHT, "Copyright (c) 2004, Andrey Kiselev"},
58+
{TIFFTAG_FAXSUBADDRESS, "Fax subaddress"},
59+
/* DGN tags */
60+
{TIFFTAG_UNIQUECAMERAMODEL, "No camera"},
61+
{TIFFTAG_CAMERASERIALNUMBER, "1234567890"}};
62+
#define NTAGS (sizeof(ascii_tags) / sizeof(ascii_tags[0]))
6463

6564
static const char ink_names[] = "Red\0Green\0Blue";
6665
const int ink_names_size = 15;
6766

68-
int
69-
main()
67+
int main()
7068
{
71-
TIFF *tif;
72-
size_t i;
73-
unsigned char buf[] = { 0, 127, 255 };
74-
char *value;
75-
76-
/* Test whether we can write tags. */
77-
tif = TIFFOpen(filename, "w");
78-
if (!tif) {
79-
fprintf (stderr, "Can't create test TIFF file %s.\n", filename);
80-
return 1;
81-
}
82-
83-
if (!TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, 1)) {
84-
fprintf (stderr, "Can't set ImageWidth tag.\n");
85-
goto failure;
86-
}
87-
if (!TIFFSetField(tif, TIFFTAG_IMAGELENGTH, 1)) {
88-
fprintf (stderr, "Can't set ImageLength tag.\n");
89-
goto failure;
90-
}
91-
if (!TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8)) {
92-
fprintf (stderr, "Can't set BitsPerSample tag.\n");
93-
goto failure;
94-
}
95-
if (!TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, sizeof(buf))) {
96-
fprintf (stderr, "Can't set SamplesPerPixel tag.\n");
97-
goto failure;
98-
}
99-
if (!TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG)) {
100-
fprintf (stderr, "Can't set PlanarConfiguration tag.\n");
101-
goto failure;
102-
}
103-
if (!TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB)) {
104-
fprintf (stderr, "Can't set PhotometricInterpretation tag.\n");
105-
goto failure;
106-
}
107-
108-
for (i = 0; i < NTAGS; i++) {
109-
if (!TIFFSetField(tif, ascii_tags[i].tag,
110-
ascii_tags[i].value)) {
111-
fprintf(stderr, "Can't set tag %"PRIu32".\n",
112-
ascii_tags[i].tag);
113-
goto failure;
114-
}
115-
}
116-
117-
/* InkNames tag has special form, so we handle it separately. */
118-
if (!TIFFSetField(tif, TIFFTAG_NUMBEROFINKS, 3)) {
119-
fprintf (stderr, "Can't set tag %d (NUMBEROFINKS).\n",
120-
TIFFTAG_NUMBEROFINKS);
121-
goto failure;
122-
}
123-
if (!TIFFSetField(tif, TIFFTAG_INKNAMES, ink_names_size, ink_names)) {
124-
fprintf (stderr, "Can't set tag %d (INKNAMES).\n",
125-
TIFFTAG_INKNAMES);
126-
goto failure;
127-
}
128-
129-
/* Write dummy pixel data. */
130-
if (TIFFWriteScanline(tif, buf, 0, 0) == -1) {
131-
fprintf (stderr, "Can't write image data.\n");
132-
goto failure;
133-
}
134-
135-
TIFFClose(tif);
136-
137-
/* Ok, now test whether we can read written values. */
138-
tif = TIFFOpen(filename, "r");
139-
if (!tif) {
140-
fprintf (stderr, "Can't open test TIFF file %s.\n", filename);
141-
return 1;
142-
}
143-
144-
for (i = 0; i < NTAGS; i++) {
145-
if (!TIFFGetField(tif, ascii_tags[i].tag, &value)
146-
|| strcmp(value, ascii_tags[i].value)) {
147-
fprintf(stderr, "Can't get tag %"PRIu32".\n",
148-
ascii_tags[i].tag);
149-
goto failure;
150-
}
151-
}
152-
153-
if (!TIFFGetField(tif, TIFFTAG_INKNAMES, &value)
154-
|| memcmp(value, ink_names, ink_names_size)) {
155-
fprintf (stderr, "Can't get tag %d (INKNAMES).\n",
156-
TIFFTAG_INKNAMES);
157-
goto failure;
158-
}
159-
160-
TIFFClose(tif);
161-
162-
/* All tests passed; delete file and exit with success status. */
163-
unlink(filename);
164-
return 0;
69+
TIFF *tif;
70+
size_t i;
71+
unsigned char buf[] = {0, 127, 255};
72+
char *value;
73+
74+
/* Test whether we can write tags. */
75+
tif = TIFFOpen(filename, "w");
76+
if (!tif)
77+
{
78+
fprintf(stderr, "Can't create test TIFF file %s.\n", filename);
79+
return 1;
80+
}
81+
82+
if (!TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, 1))
83+
{
84+
fprintf(stderr, "Can't set ImageWidth tag.\n");
85+
goto failure;
86+
}
87+
if (!TIFFSetField(tif, TIFFTAG_IMAGELENGTH, 1))
88+
{
89+
fprintf(stderr, "Can't set ImageLength tag.\n");
90+
goto failure;
91+
}
92+
if (!TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8))
93+
{
94+
fprintf(stderr, "Can't set BitsPerSample tag.\n");
95+
goto failure;
96+
}
97+
if (!TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, sizeof(buf)))
98+
{
99+
fprintf(stderr, "Can't set SamplesPerPixel tag.\n");
100+
goto failure;
101+
}
102+
if (!TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG))
103+
{
104+
fprintf(stderr, "Can't set PlanarConfiguration tag.\n");
105+
goto failure;
106+
}
107+
if (!TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB))
108+
{
109+
fprintf(stderr, "Can't set PhotometricInterpretation tag.\n");
110+
goto failure;
111+
}
112+
113+
for (i = 0; i < NTAGS; i++)
114+
{
115+
if (!TIFFSetField(tif, ascii_tags[i].tag, ascii_tags[i].value))
116+
{
117+
fprintf(stderr, "Can't set tag %" PRIu32 ".\n", ascii_tags[i].tag);
118+
goto failure;
119+
}
120+
}
121+
122+
/* InkNames tag has special form, so we handle it separately. */
123+
if (!TIFFSetField(tif, TIFFTAG_NUMBEROFINKS, 3))
124+
{
125+
fprintf(stderr, "Can't set tag %d (NUMBEROFINKS).\n",
126+
TIFFTAG_NUMBEROFINKS);
127+
goto failure;
128+
}
129+
if (!TIFFSetField(tif, TIFFTAG_INKNAMES, ink_names_size, ink_names))
130+
{
131+
fprintf(stderr, "Can't set tag %d (INKNAMES).\n", TIFFTAG_INKNAMES);
132+
goto failure;
133+
}
134+
135+
/* Write dummy pixel data. */
136+
if (TIFFWriteScanline(tif, buf, 0, 0) == -1)
137+
{
138+
fprintf(stderr, "Can't write image data.\n");
139+
goto failure;
140+
}
141+
142+
TIFFClose(tif);
143+
144+
/* Ok, now test whether we can read written values. */
145+
tif = TIFFOpen(filename, "r");
146+
if (!tif)
147+
{
148+
fprintf(stderr, "Can't open test TIFF file %s.\n", filename);
149+
return 1;
150+
}
151+
152+
for (i = 0; i < NTAGS; i++)
153+
{
154+
if (!TIFFGetField(tif, ascii_tags[i].tag, &value) ||
155+
strcmp(value, ascii_tags[i].value))
156+
{
157+
fprintf(stderr, "Can't get tag %" PRIu32 ".\n", ascii_tags[i].tag);
158+
goto failure;
159+
}
160+
}
161+
162+
if (!TIFFGetField(tif, TIFFTAG_INKNAMES, &value) ||
163+
memcmp(value, ink_names, ink_names_size))
164+
{
165+
fprintf(stderr, "Can't get tag %d (INKNAMES).\n", TIFFTAG_INKNAMES);
166+
goto failure;
167+
}
168+
169+
TIFFClose(tif);
170+
171+
/* All tests passed; delete file and exit with success status. */
172+
unlink(filename);
173+
return 0;
165174

166175
failure:
167-
/*
168-
* Something goes wrong; close file and return unsuccessful status.
169-
* Do not remove the file for further manual investigation.
170-
*/
171-
TIFFClose(tif);
172-
return 1;
176+
/*
177+
* Something goes wrong; close file and return unsuccessful status.
178+
* Do not remove the file for further manual investigation.
179+
*/
180+
TIFFClose(tif);
181+
return 1;
173182
}

0 commit comments

Comments
 (0)