• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* test-tagtable.c
2  *
3  * Test various functions that involve the tag table.
4  *
5  * Copyright (c) 2009 Dan Fandrich <dan@coneharvesters.com>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  * Boston, MA  02110-1301  USA.
21  */
22 
23 #include "config.h"
24 #include <libexif/exif-tag.h>
25 #include <stdio.h>
26 #include <string.h>
27 
28 #define VALIDATE(s) if (!(s)) {printf("Test %s FAILED\n", #s); fail=1;}
29 
30 #define TESTBLOCK(t) {int rc = (t); fail |= rc; \
31                       if (rc) printf("%s tests FAILED\n", #t);}
32 
33 /* Test exif_tag_get_support_level_in_ifd */
support_level(void)34 static int support_level(void)
35 {
36     int fail = 0;
37 
38     /*
39      * The tag EXIF_TAG_PLANAR_CONFIGURATION support varies greatly between
40      * data types.
41      */
42     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_PLANAR_CONFIGURATION,
43                EXIF_IFD_0, EXIF_DATA_TYPE_UNCOMPRESSED_CHUNKY) ==
44              EXIF_SUPPORT_LEVEL_OPTIONAL)
45 
46     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_PLANAR_CONFIGURATION,
47                EXIF_IFD_0, EXIF_DATA_TYPE_UNCOMPRESSED_PLANAR) ==
48              EXIF_SUPPORT_LEVEL_MANDATORY)
49 
50     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_PLANAR_CONFIGURATION,
51                EXIF_IFD_0, EXIF_DATA_TYPE_UNCOMPRESSED_YCC) ==
52              EXIF_SUPPORT_LEVEL_OPTIONAL)
53 
54     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_PLANAR_CONFIGURATION,
55                EXIF_IFD_0, EXIF_DATA_TYPE_COMPRESSED) ==
56              EXIF_SUPPORT_LEVEL_NOT_RECORDED)
57 
58     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_PLANAR_CONFIGURATION,
59                EXIF_IFD_0, EXIF_DATA_TYPE_UNKNOWN) ==
60              EXIF_SUPPORT_LEVEL_UNKNOWN)
61 
62     /*
63      * The tag EXIF_TAG_YCBCR_POSITIONING support varies greatly between
64      * IFDs
65      */
66     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_YCBCR_POSITIONING,
67                EXIF_IFD_0, EXIF_DATA_TYPE_COMPRESSED) ==
68              EXIF_SUPPORT_LEVEL_MANDATORY)
69 
70     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_YCBCR_POSITIONING,
71                EXIF_IFD_1, EXIF_DATA_TYPE_COMPRESSED) ==
72              EXIF_SUPPORT_LEVEL_OPTIONAL)
73 
74     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_YCBCR_POSITIONING,
75                EXIF_IFD_EXIF, EXIF_DATA_TYPE_COMPRESSED) ==
76              EXIF_SUPPORT_LEVEL_NOT_RECORDED)
77 
78     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_YCBCR_POSITIONING,
79                EXIF_IFD_GPS, EXIF_DATA_TYPE_COMPRESSED) ==
80              EXIF_SUPPORT_LEVEL_NOT_RECORDED)
81 
82     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_YCBCR_POSITIONING,
83                EXIF_IFD_INTEROPERABILITY, EXIF_DATA_TYPE_COMPRESSED) ==
84              EXIF_SUPPORT_LEVEL_NOT_RECORDED)
85 
86 
87     /*
88      * The tag EXIF_TAG_GPS_VERSION_ID has value 0 which should NOT be
89      * treated specially
90      */
91     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_GPS_VERSION_ID,
92                EXIF_IFD_GPS, EXIF_DATA_TYPE_COMPRESSED) ==
93              EXIF_SUPPORT_LEVEL_OPTIONAL)
94 
95     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_GPS_VERSION_ID,
96                EXIF_IFD_GPS, EXIF_DATA_TYPE_UNKNOWN) ==
97              EXIF_SUPPORT_LEVEL_OPTIONAL)
98 
99     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_GPS_VERSION_ID,
100                EXIF_IFD_0, EXIF_DATA_TYPE_COMPRESSED) ==
101              EXIF_SUPPORT_LEVEL_NOT_RECORDED)
102 
103     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_GPS_VERSION_ID,
104                EXIF_IFD_0, EXIF_DATA_TYPE_UNKNOWN) ==
105              EXIF_SUPPORT_LEVEL_UNKNOWN)
106 
107     /* The unused tag 0xffff should NOT be treated specially */
108     VALIDATE(exif_tag_get_support_level_in_ifd(0xffff,
109                EXIF_IFD_0, EXIF_DATA_TYPE_UNKNOWN) ==
110              EXIF_SUPPORT_LEVEL_UNKNOWN)
111 
112     VALIDATE(exif_tag_get_support_level_in_ifd(0xffff,
113                EXIF_IFD_0, EXIF_DATA_TYPE_COMPRESSED) ==
114              EXIF_SUPPORT_LEVEL_NOT_RECORDED)
115 
116     /*
117      * The tag EXIF_TAG_DOCUMENT_NAME isn't in the EXIF 2.2 standard but
118      * it exists in the tag table, which causes it to show up as unknown
119      * instead of not recorded.
120      */
121     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_DOCUMENT_NAME,
122                EXIF_IFD_0, EXIF_DATA_TYPE_UNKNOWN) ==
123              EXIF_SUPPORT_LEVEL_UNKNOWN)
124 
125     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_DOCUMENT_NAME,
126                EXIF_IFD_1, EXIF_DATA_TYPE_UNCOMPRESSED_CHUNKY) ==
127              EXIF_SUPPORT_LEVEL_UNKNOWN)
128 
129 
130     /*
131      * The tag number for EXIF_TAG_INTEROPERABILITY_INDEX (1) exists in both
132      * IFD Interoperability and IFD GPS (as EXIF_TAG_GPS_LATITUDE_REF) so
133      * there are two entries in the table.
134      */
135     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_INTEROPERABILITY_INDEX,
136                EXIF_IFD_INTEROPERABILITY, EXIF_DATA_TYPE_COMPRESSED) ==
137              EXIF_SUPPORT_LEVEL_OPTIONAL)
138 
139     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_INTEROPERABILITY_INDEX,
140                EXIF_IFD_INTEROPERABILITY, EXIF_DATA_TYPE_UNKNOWN) ==
141              EXIF_SUPPORT_LEVEL_OPTIONAL)
142 
143     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_INTEROPERABILITY_INDEX,
144                EXIF_IFD_0, EXIF_DATA_TYPE_COMPRESSED) ==
145              EXIF_SUPPORT_LEVEL_NOT_RECORDED)
146 
147     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_INTEROPERABILITY_INDEX,
148                EXIF_IFD_0, EXIF_DATA_TYPE_UNKNOWN) ==
149              EXIF_SUPPORT_LEVEL_UNKNOWN)
150 
151     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_GPS_LATITUDE_REF,
152                EXIF_IFD_GPS, EXIF_DATA_TYPE_COMPRESSED) ==
153              EXIF_SUPPORT_LEVEL_OPTIONAL)
154 
155     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_GPS_LATITUDE_REF,
156                EXIF_IFD_GPS, EXIF_DATA_TYPE_UNKNOWN) ==
157              EXIF_SUPPORT_LEVEL_OPTIONAL)
158 
159     /* The result of an unknown IFD should always be unknown */
160     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_EXIF_VERSION,
161                EXIF_IFD_COUNT, EXIF_DATA_TYPE_UNKNOWN) ==
162              EXIF_SUPPORT_LEVEL_UNKNOWN)
163 
164     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_EXIF_VERSION,
165                EXIF_IFD_COUNT, EXIF_DATA_TYPE_COMPRESSED) ==
166              EXIF_SUPPORT_LEVEL_UNKNOWN)
167 
168     return fail;
169 }
170 
171 /* Test exif_tag_get_name_in_ifd  */
name(void)172 static int name(void)
173 {
174     int fail = 0;
175 
176     /*
177      * The tag EXIF_TAG_GPS_VERSION_ID has value 0 which should NOT be
178      * treated specially
179      */
180     VALIDATE(!strcmp(exif_tag_get_name_in_ifd(
181                         EXIF_TAG_GPS_VERSION_ID, EXIF_IFD_GPS),
182                      "GPSVersionID"))
183 
184     VALIDATE(exif_tag_get_name_in_ifd(
185                         EXIF_TAG_GPS_VERSION_ID, EXIF_IFD_0) == NULL)
186 
187     /*
188      * The tag number for EXIF_TAG_INTEROPERABILITY_INDEX (1) exists in both
189      * IFD Interoperability and IFD GPS (as EXIF_TAG_GPS_LATITUDE_REF) so
190      * there are two entries in the table.
191      */
192     VALIDATE(!strcmp(exif_tag_get_name_in_ifd(
193                 EXIF_TAG_INTEROPERABILITY_INDEX, EXIF_IFD_INTEROPERABILITY),
194                      "InteroperabilityIndex"))
195 
196     VALIDATE(!strcmp(exif_tag_get_name_in_ifd(
197                         EXIF_TAG_GPS_LATITUDE_REF, EXIF_IFD_GPS),
198                      "GPSLatitudeRef"))
199 
200     /* Tag that doesn't appear in an IFD produces a NULL */
201     VALIDATE(exif_tag_get_name_in_ifd(
202                         EXIF_TAG_EXIF_VERSION, EXIF_IFD_0) == NULL)
203 
204     /* Invalid IFD produces a NULL */
205     VALIDATE(exif_tag_get_name_in_ifd(
206                         EXIF_TAG_EXIF_VERSION, EXIF_IFD_COUNT) == NULL)
207 
208     return fail;
209 }
210 
211 int
main()212 main ()
213 {
214     int fail = 0;
215 
216     TESTBLOCK(support_level())
217     TESTBLOCK(name())
218 
219     return fail;
220 }
221