Document domain parameter of wxTranslations::GetTranslatedString().
[wxWidgets.git] / src / tiff / test / long_tag.c
1
2 /*
3 * Copyright (c) 2004, Andrey Kiselev <dron@ak4719.spb.edu>
4 *
5 * Permission to use, copy, modify, distribute, and sell this software and
6 * its documentation for any purpose is hereby granted without fee, provided
7 * that (i) the above copyright notices and this permission notice appear in
8 * all copies of the software and related documentation, and (ii) the names of
9 * Sam Leffler and Silicon Graphics may not be used in any advertising or
10 * publicity relating to the software without the specific, prior written
11 * permission of Sam Leffler and Silicon Graphics.
12 *
13 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
14 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
15 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
16 *
17 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
18 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
19 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
21 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
22 * OF THIS SOFTWARE.
23 */
24
25 /*
26 * TIFF Library
27 *
28 * Module to test LONG tags read/write functions.
29 */
30
31 #include "tif_config.h"
32
33 #include <stdio.h>
34
35 #ifdef HAVE_UNISTD_H
36 # include <unistd.h>
37 #endif
38
39 #include "tiffio.h"
40
41 extern int CheckLongField(TIFF *, ttag_t, uint32);
42
43 const char *filename = "long_test.tiff";
44
45 static struct Tags {
46 ttag_t tag;
47 short count;
48 uint32 value;
49 } long_tags[] = {
50 { TIFFTAG_SUBFILETYPE, 1, FILETYPE_REDUCEDIMAGE|FILETYPE_PAGE|FILETYPE_MASK }
51 };
52 #define NTAGS (sizeof (long_tags) / sizeof (long_tags[0]))
53
54 const uint32 width = 1;
55 const uint32 length = 1;
56 const uint32 rows_per_strip = 1;
57
58 int
59 main(int argc, char **argv)
60 {
61 TIFF *tif;
62 unsigned int i;
63 unsigned char buf[3] = { 0, 127, 255 };
64 (void) argc;
65 (void) argv;
66
67 /* Test whether we can write tags. */
68 tif = TIFFOpen(filename, "w");
69 if (!tif) {
70 fprintf (stderr, "Can't create test TIFF file %s.\n", filename);
71 return 1;
72 }
73
74 if (!TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, width)) {
75 fprintf (stderr, "Can't set ImageWidth tag.\n");
76 goto failure;
77 }
78 if (!TIFFSetField(tif, TIFFTAG_IMAGELENGTH, length)) {
79 fprintf (stderr, "Can't set ImageLength tag.\n");
80 goto failure;
81 }
82 if (!TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8)) {
83 fprintf (stderr, "Can't set BitsPerSample tag.\n");
84 goto failure;
85 }
86 if (!TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 3)) {
87 fprintf (stderr, "Can't set SamplesPerPixel tag.\n");
88 goto failure;
89 }
90 if (!TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, rows_per_strip)) {
91 fprintf (stderr, "Can't set SamplesPerPixel tag.\n");
92 goto failure;
93 }
94 if (!TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG)) {
95 fprintf (stderr, "Can't set PlanarConfiguration tag.\n");
96 goto failure;
97 }
98 if (!TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB)) {
99 fprintf (stderr, "Can't set PhotometricInterpretation tag.\n");
100 goto failure;
101 }
102
103 for (i = 0; i < NTAGS; i++) {
104 if (!TIFFSetField(tif, long_tags[i].tag,
105 long_tags[i].value)) {
106 fprintf(stderr, "Can't set tag %d.\n",
107 (int)long_tags[i].tag);
108 goto failure;
109 }
110 }
111
112 /* Write dummy pixel data. */
113 if (!TIFFWriteScanline(tif, buf, 0, 0) < 0) {
114 fprintf (stderr, "Can't write image data.\n");
115 goto failure;
116 }
117
118 TIFFClose(tif);
119
120 /* Ok, now test whether we can read written values. */
121 tif = TIFFOpen(filename, "r");
122 if (!tif) {
123 fprintf (stderr, "Can't open test TIFF file %s.\n", filename);
124 return 1;
125 }
126
127 if (CheckLongField(tif, TIFFTAG_IMAGEWIDTH, width) < 0)
128 goto failure;
129
130 if (CheckLongField(tif, TIFFTAG_IMAGELENGTH, length) < 0)
131 goto failure;
132
133 if (CheckLongField(tif, TIFFTAG_ROWSPERSTRIP, rows_per_strip) < 0)
134 goto failure;
135
136 for (i = 0; i < NTAGS; i++) {
137 if (CheckLongField(tif, long_tags[i].tag,
138 long_tags[i].value) < 0)
139 goto failure;
140 }
141
142 TIFFClose(tif);
143
144 /* All tests passed; delete file and exit with success status. */
145 unlink(filename);
146 return 0;
147
148 failure:
149 /* Something goes wrong; close file and return unsuccessful status. */
150 TIFFClose(tif);
151 unlink(filename);
152 return 1;
153 }
154
155 /* vim: set ts=8 sts=8 sw=8 noet: */