~ubuntu-branches/ubuntu/trusty/tiff/trusty

« back to all changes in this revision

Viewing changes to test/ascii_tag.c

  • Committer: Package Import Robot
  • Author(s): Jay Berkenbilt
  • Date: 2012-06-24 13:45:42 UTC
  • mfrom: (15.1.14 sid)
  • Revision ID: package-import@ubuntu.com-20120624134542-u7dltcqwnb6orprf
Tags: 4.0.2-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: ascii_tag.c,v 1.5.2.1 2010-06-08 18:50:43 bfriesen Exp $ */
 
1
/* $Id: ascii_tag.c,v 1.7 2008-04-15 13:32:12 dron Exp $ */
2
2
 
3
3
/*
4
4
 * Copyright (c) 2004, Andrey Kiselev  <dron@ak4719.spb.edu>
40
40
 
41
41
#include "tiffio.h"
42
42
 
43
 
const char      *filename = "ascii_test.tiff";
 
43
static const char filename[] = "ascii_test.tiff";
44
44
 
45
 
static struct Tags {
 
45
static const struct {
46
46
        ttag_t          tag;
47
47
        const char      *value;
48
48
} ascii_tags[] = {
56
56
        { TIFFTAG_ARTIST, "Andrey V. Kiselev" },
57
57
        { TIFFTAG_HOSTCOMPUTER, "Debian GNU/Linux (Sarge)" },
58
58
        { TIFFTAG_TARGETPRINTER, "No printer" },
59
 
        { TIFFTAG_PIXAR_TEXTUREFORMAT, "No texture" },
60
 
        { TIFFTAG_PIXAR_WRAPMODES, "No wrap" },
61
 
        { TIFFTAG_COPYRIGHT, "Copyright (c) 2004, Andrey Kiselev" }
 
59
        { TIFFTAG_COPYRIGHT, "Copyright (c) 2004, Andrey Kiselev" },
 
60
        { TIFFTAG_FAXSUBADDRESS, "Fax subaddress" },
 
61
        /* DGN tags */
 
62
        { TIFFTAG_UNIQUECAMERAMODEL, "No camera" },
 
63
        { TIFFTAG_CAMERASERIALNUMBER, "1234567890" }
62
64
};
63
65
#define NTAGS   (sizeof (ascii_tags) / sizeof (ascii_tags[0]))
64
66
 
65
 
const char *ink_names = "Red\0Green\0Blue";
 
67
static const char ink_names[] = "Red\0Green\0Blue";
66
68
const int ink_names_size = 15;
67
69
 
68
70
int
69
 
main(int argc, char **argv)
 
71
main()
70
72
{
71
73
        TIFF            *tif;
72
 
        int             i;
73
 
        unsigned char   buf[3] = { 0, 127, 255 };
 
74
        size_t          i;
 
75
        unsigned char   buf[] = { 0, 127, 255 };
74
76
        char            *value;
75
77
 
76
78
        /* Test whether we can write tags. */
92
94
                fprintf (stderr, "Can't set BitsPerSample tag.\n");
93
95
                goto failure;
94
96
        }
95
 
        if (!TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 3)) {
 
97
        if (!TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, sizeof(buf))) {
96
98
                fprintf (stderr, "Can't set SamplesPerPixel tag.\n");
97
99
                goto failure;
98
100
        }
108
110
        for (i = 0; i < NTAGS; i++) {
109
111
                if (!TIFFSetField(tif, ascii_tags[i].tag,
110
112
                                  ascii_tags[i].value)) {
111
 
                        fprintf(stderr, "Can't set tag %d.\n",
112
 
                                (int)ascii_tags[i].tag);
 
113
                        fprintf(stderr, "Can't set tag %lu.\n",
 
114
                                (unsigned long)ascii_tags[i].tag);
113
115
                        goto failure;
114
116
                }
115
117
        }
116
118
 
117
119
        /* InkNames tag has special form, so we handle it separately. */
118
120
        if (!TIFFSetField(tif, TIFFTAG_NUMBEROFINKS, 3)) {
119
 
                fprintf (stderr, "Can't set tag %d.\n", TIFFTAG_NUMBEROFINKS);
 
121
                fprintf (stderr, "Can't set tag %d (NUMBEROFINKS).\n",
 
122
                         TIFFTAG_NUMBEROFINKS);
120
123
                goto failure;
121
124
        }
122
125
        if (!TIFFSetField(tif, TIFFTAG_INKNAMES, ink_names_size, ink_names)) {
123
 
                fprintf (stderr, "Can't set tag %d.\n", TIFFTAG_INKNAMES);
 
126
                fprintf (stderr, "Can't set tag %d (INKNAMES).\n",
 
127
                         TIFFTAG_INKNAMES);
124
128
                goto failure;
125
129
        }
126
130
 
142
146
        for (i = 0; i < NTAGS; i++) {
143
147
                if (!TIFFGetField(tif, ascii_tags[i].tag, &value)
144
148
                    || strcmp(value, ascii_tags[i].value)) {
145
 
                        fprintf(stderr, "Can't get tag %d.\n",
146
 
                                (int)ascii_tags[i].tag);
 
149
                        fprintf(stderr, "Can't get tag %lu.\n",
 
150
                                (unsigned long)ascii_tags[i].tag);
147
151
                        goto failure;
148
152
                }
149
153
        }
150
154
 
151
155
        if (!TIFFGetField(tif, TIFFTAG_INKNAMES, &value)
152
156
            || memcmp(value, ink_names, ink_names_size)) {
153
 
                fprintf (stderr, "Can't get tag %d.\n", TIFFTAG_INKNAMES);
 
157
                fprintf (stderr, "Can't get tag %d (INKNAMES).\n",
 
158
                         TIFFTAG_INKNAMES);
154
159
                goto failure;
155
160
        }
156
161
 
161
166
        return 0;
162
167
 
163
168
failure:
164
 
        /* Something goes wrong; close file and return unsuccessful status. */
 
169
        /* 
 
170
         * Something goes wrong; close file and return unsuccessful status.
 
171
         * Do not remove the file for further manual investigation.
 
172
         */
165
173
        TIFFClose(tif);
166
 
        unlink(filename);
167
174
        return 1;
168
175
}
169
176
 
170
177
/* vim: set ts=8 sts=8 sw=8 noet: */
171
 
/*
172
 
 * Local Variables:
173
 
 * mode: c
174
 
 * c-basic-offset: 8
175
 
 * fill-column: 78
176
 
 * End:
177
 
 */