Document domain parameter of wxTranslations::GetTranslatedString().
[wxWidgets.git] / src / tiff / test / ascii_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 ASCII tags read/write functions.
29 */
30
31 #include "tif_config.h"
32
33 #include <stdio.h>
34 #include <string.h>
35
36 #ifdef HAVE_UNISTD_H
37 # include <unistd.h>
38 #endif
39
40 #include "tiffio.h"
41
42 static const char filename[] = "ascii_test.tiff";
43
44 static const struct {
45 ttag_t tag;
46 const char *value;
47 } ascii_tags[] = {
48 { TIFFTAG_DOCUMENTNAME, "Test TIFF image" },
49 { TIFFTAG_IMAGEDESCRIPTION, "Temporary test image" },
50 { TIFFTAG_MAKE, "This is not scanned image" },
51 { TIFFTAG_MODEL, "No scanner" },
52 { TIFFTAG_PAGENAME, "Test page" },
53 { TIFFTAG_SOFTWARE, "Libtiff library" },
54 { TIFFTAG_DATETIME, "2004:09:10 16:09:00" },
55 { TIFFTAG_ARTIST, "Andrey V. Kiselev" },
56 { TIFFTAG_HOSTCOMPUTER, "Debian GNU/Linux (Sarge)" },
57 { TIFFTAG_TARGETPRINTER, "No printer" },
58 { TIFFTAG_COPYRIGHT, "Copyright (c) 2004, Andrey Kiselev" },
59 { TIFFTAG_FAXSUBADDRESS, "Fax subaddress" },
60 /* DGN tags */
61 { TIFFTAG_UNIQUECAMERAMODEL, "No camera" },
62 { TIFFTAG_CAMERASERIALNUMBER, "1234567890" }
63 };
64 #define NTAGS (sizeof (ascii_tags) / sizeof (ascii_tags[0]))
65
66 static const char ink_names[] = "Red\0Green\0Blue";
67 const int ink_names_size = 15;
68
69 int
70 main()
71 {
72 TIFF *tif;
73 size_t i;
74 unsigned char buf[] = { 0, 127, 255 };
75 char *value;
76
77 /* Test whether we can write tags. */
78 tif = TIFFOpen(filename, "w");
79 if (!tif) {
80 fprintf (stderr, "Can't create test TIFF file %s.\n", filename);
81 return 1;
82 }
83
84 if (!TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, 1)) {
85 fprintf (stderr, "Can't set ImageWidth tag.\n");
86 goto failure;
87 }
88 if (!TIFFSetField(tif, TIFFTAG_IMAGELENGTH, 1)) {
89 fprintf (stderr, "Can't set ImageLength tag.\n");
90 goto failure;
91 }
92 if (!TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8)) {
93 fprintf (stderr, "Can't set BitsPerSample tag.\n");
94 goto failure;
95 }
96 if (!TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, sizeof(buf))) {
97 fprintf (stderr, "Can't set SamplesPerPixel tag.\n");
98 goto failure;
99 }
100 if (!TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG)) {
101 fprintf (stderr, "Can't set PlanarConfiguration tag.\n");
102 goto failure;
103 }
104 if (!TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB)) {
105 fprintf (stderr, "Can't set PhotometricInterpretation tag.\n");
106 goto failure;
107 }
108
109 for (i = 0; i < NTAGS; i++) {
110 if (!TIFFSetField(tif, ascii_tags[i].tag,
111 ascii_tags[i].value)) {
112 fprintf(stderr, "Can't set tag %lu.\n",
113 (unsigned long)ascii_tags[i].tag);
114 goto failure;
115 }
116 }
117
118 /* InkNames tag has special form, so we handle it separately. */
119 if (!TIFFSetField(tif, TIFFTAG_NUMBEROFINKS, 3)) {
120 fprintf (stderr, "Can't set tag %d (NUMBEROFINKS).\n",
121 TIFFTAG_NUMBEROFINKS);
122 goto failure;
123 }
124 if (!TIFFSetField(tif, TIFFTAG_INKNAMES, ink_names_size, ink_names)) {
125 fprintf (stderr, "Can't set tag %d (INKNAMES).\n",
126 TIFFTAG_INKNAMES);
127 goto failure;
128 }
129
130 /* Write dummy pixel data. */
131 if (!TIFFWriteScanline(tif, buf, 0, 0) < 0) {
132 fprintf (stderr, "Can't write image data.\n");
133 goto failure;
134 }
135
136 TIFFClose(tif);
137
138 /* Ok, now test whether we can read written values. */
139 tif = TIFFOpen(filename, "r");
140 if (!tif) {
141 fprintf (stderr, "Can't open test TIFF file %s.\n", filename);
142 return 1;
143 }
144
145 for (i = 0; i < NTAGS; i++) {
146 if (!TIFFGetField(tif, ascii_tags[i].tag, &value)
147 || strcmp(value, ascii_tags[i].value)) {
148 fprintf(stderr, "Can't get tag %lu.\n",
149 (unsigned long)ascii_tags[i].tag);
150 goto failure;
151 }
152 }
153
154 if (!TIFFGetField(tif, TIFFTAG_INKNAMES, &value)
155 || memcmp(value, ink_names, ink_names_size)) {
156 fprintf (stderr, "Can't get tag %d (INKNAMES).\n",
157 TIFFTAG_INKNAMES);
158 goto failure;
159 }
160
161 TIFFClose(tif);
162
163 /* All tests passed; delete file and exit with success status. */
164 unlink(filename);
165 return 0;
166
167 failure:
168 /*
169 * Something goes wrong; close file and return unsuccessful status.
170 * Do not remove the file for further manual investigation.
171 */
172 TIFFClose(tif);
173 return 1;
174 }
175
176 /* vim: set ts=8 sts=8 sw=8 noet: */