test-tagtable.c

Go to the documentation of this file.
00001 /* test-tagtable.c
00002  *
00003  * Test various functions that involve the tag table.
00004  *
00005  * Copyright (c) 2009 Dan Fandrich <dan@coneharvesters.com>
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2 of the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful, 
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of 
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details. 
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the
00019  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020  * Boston, MA  02110-1301  USA.
00021  */
00022 
00023 #include "config.h"
00024 #include <libexif/exif-tag.h>
00025 #include <stdio.h>
00026 #include <string.h>
00027 
00028 #define VALIDATE(s) if (!(s)) {printf("Test %s FAILED\n", #s); fail=1;}
00029 
00030 #define TESTBLOCK(t) {int rc = (t); fail |= rc; \
00031                       if (rc) printf("%s tests FAILED\n", #t);}
00032 
00033 /* Test exif_tag_get_support_level_in_ifd */
00034 static int support_level(void)
00035 {
00036     int fail = 0;
00037 
00038     /*
00039      * The tag EXIF_TAG_PLANAR_CONFIGURATION support varies greatly between
00040      * data types.
00041      */
00042     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_PLANAR_CONFIGURATION,
00043                EXIF_IFD_0, EXIF_DATA_TYPE_UNCOMPRESSED_CHUNKY) == 
00044              EXIF_SUPPORT_LEVEL_OPTIONAL)
00045 
00046     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_PLANAR_CONFIGURATION,
00047                EXIF_IFD_0, EXIF_DATA_TYPE_UNCOMPRESSED_PLANAR) == 
00048              EXIF_SUPPORT_LEVEL_MANDATORY)
00049 
00050     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_PLANAR_CONFIGURATION,
00051                EXIF_IFD_0, EXIF_DATA_TYPE_UNCOMPRESSED_YCC) == 
00052              EXIF_SUPPORT_LEVEL_OPTIONAL)
00053 
00054     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_PLANAR_CONFIGURATION,
00055                EXIF_IFD_0, EXIF_DATA_TYPE_COMPRESSED) == 
00056              EXIF_SUPPORT_LEVEL_NOT_RECORDED)
00057 
00058     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_PLANAR_CONFIGURATION,
00059                EXIF_IFD_0, EXIF_DATA_TYPE_UNKNOWN) == 
00060              EXIF_SUPPORT_LEVEL_UNKNOWN)
00061 
00062     /*
00063      * The tag EXIF_TAG_YCBCR_POSITIONING support varies greatly between
00064      * IFDs
00065      */
00066     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_YCBCR_POSITIONING,
00067                EXIF_IFD_0, EXIF_DATA_TYPE_COMPRESSED) == 
00068              EXIF_SUPPORT_LEVEL_MANDATORY)
00069 
00070     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_YCBCR_POSITIONING,
00071                EXIF_IFD_1, EXIF_DATA_TYPE_COMPRESSED) == 
00072              EXIF_SUPPORT_LEVEL_OPTIONAL)
00073 
00074     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_YCBCR_POSITIONING,
00075                EXIF_IFD_EXIF, EXIF_DATA_TYPE_COMPRESSED) == 
00076              EXIF_SUPPORT_LEVEL_NOT_RECORDED)
00077 
00078     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_YCBCR_POSITIONING,
00079                EXIF_IFD_GPS, EXIF_DATA_TYPE_COMPRESSED) == 
00080              EXIF_SUPPORT_LEVEL_NOT_RECORDED)
00081 
00082     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_YCBCR_POSITIONING,
00083                EXIF_IFD_INTEROPERABILITY, EXIF_DATA_TYPE_COMPRESSED) == 
00084              EXIF_SUPPORT_LEVEL_NOT_RECORDED)
00085 
00086 
00087     /*
00088      * The tag EXIF_TAG_GPS_VERSION_ID has value 0 which should NOT be
00089      * treated specially
00090      */
00091     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_GPS_VERSION_ID,
00092                EXIF_IFD_GPS, EXIF_DATA_TYPE_COMPRESSED) == 
00093              EXIF_SUPPORT_LEVEL_OPTIONAL)
00094 
00095     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_GPS_VERSION_ID,
00096                EXIF_IFD_GPS, EXIF_DATA_TYPE_UNKNOWN) == 
00097              EXIF_SUPPORT_LEVEL_OPTIONAL)
00098 
00099     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_GPS_VERSION_ID,
00100                EXIF_IFD_0, EXIF_DATA_TYPE_COMPRESSED) == 
00101              EXIF_SUPPORT_LEVEL_NOT_RECORDED)
00102 
00103     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_GPS_VERSION_ID,
00104                EXIF_IFD_0, EXIF_DATA_TYPE_UNKNOWN) == 
00105              EXIF_SUPPORT_LEVEL_UNKNOWN)
00106 
00107     /* The unused tag 0xffff should NOT be treated specially */
00108     VALIDATE(exif_tag_get_support_level_in_ifd(0xffff,
00109                EXIF_IFD_0, EXIF_DATA_TYPE_UNKNOWN) == 
00110              EXIF_SUPPORT_LEVEL_UNKNOWN)
00111 
00112     VALIDATE(exif_tag_get_support_level_in_ifd(0xffff,
00113                EXIF_IFD_0, EXIF_DATA_TYPE_COMPRESSED) == 
00114              EXIF_SUPPORT_LEVEL_NOT_RECORDED)
00115 
00116     /*
00117      * The tag EXIF_TAG_DOCUMENT_NAME isn't in the EXIF 2.2 standard but
00118      * it exists in the tag table, which causes it to show up as unknown
00119      * instead of not recorded.
00120      */
00121     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_DOCUMENT_NAME,
00122                EXIF_IFD_0, EXIF_DATA_TYPE_UNKNOWN) == 
00123              EXIF_SUPPORT_LEVEL_UNKNOWN)
00124 
00125     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_DOCUMENT_NAME,
00126                EXIF_IFD_1, EXIF_DATA_TYPE_UNCOMPRESSED_CHUNKY) == 
00127              EXIF_SUPPORT_LEVEL_UNKNOWN)
00128 
00129 
00130     /*
00131      * The tag number for EXIF_TAG_INTEROPERABILITY_INDEX (1) exists in both
00132      * IFD Interoperability and IFD GPS (as EXIF_TAG_GPS_LATITUDE_REF) so
00133      * there are two entries in the table.
00134      */
00135     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_INTEROPERABILITY_INDEX,
00136                EXIF_IFD_INTEROPERABILITY, EXIF_DATA_TYPE_COMPRESSED) == 
00137              EXIF_SUPPORT_LEVEL_OPTIONAL)
00138 
00139     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_INTEROPERABILITY_INDEX,
00140                EXIF_IFD_INTEROPERABILITY, EXIF_DATA_TYPE_UNKNOWN) == 
00141              EXIF_SUPPORT_LEVEL_OPTIONAL)
00142 
00143     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_INTEROPERABILITY_INDEX,
00144                EXIF_IFD_0, EXIF_DATA_TYPE_COMPRESSED) == 
00145              EXIF_SUPPORT_LEVEL_NOT_RECORDED)
00146 
00147     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_INTEROPERABILITY_INDEX,
00148                EXIF_IFD_0, EXIF_DATA_TYPE_UNKNOWN) == 
00149              EXIF_SUPPORT_LEVEL_UNKNOWN)
00150 
00151     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_GPS_LATITUDE_REF,
00152                EXIF_IFD_GPS, EXIF_DATA_TYPE_COMPRESSED) == 
00153              EXIF_SUPPORT_LEVEL_OPTIONAL)
00154 
00155     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_GPS_LATITUDE_REF,
00156                EXIF_IFD_GPS, EXIF_DATA_TYPE_UNKNOWN) == 
00157              EXIF_SUPPORT_LEVEL_OPTIONAL)
00158 
00159     /* The result of an unknown IFD should always be unknown */
00160     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_EXIF_VERSION,
00161                EXIF_IFD_COUNT, EXIF_DATA_TYPE_UNKNOWN) == 
00162              EXIF_SUPPORT_LEVEL_UNKNOWN)
00163 
00164     VALIDATE(exif_tag_get_support_level_in_ifd(EXIF_TAG_EXIF_VERSION,
00165                EXIF_IFD_COUNT, EXIF_DATA_TYPE_COMPRESSED) == 
00166              EXIF_SUPPORT_LEVEL_UNKNOWN)
00167 
00168     return fail;
00169 }
00170 
00171 /* Test exif_tag_get_name_in_ifd  */
00172 static int name(void)
00173 {
00174     int fail = 0;
00175 
00176     /*
00177      * The tag EXIF_TAG_GPS_VERSION_ID has value 0 which should NOT be
00178      * treated specially
00179      */
00180     VALIDATE(!strcmp(exif_tag_get_name_in_ifd(
00181                         EXIF_TAG_GPS_VERSION_ID, EXIF_IFD_GPS), 
00182                      "GPSVersionID"))
00183 
00184     VALIDATE(exif_tag_get_name_in_ifd(
00185                         EXIF_TAG_GPS_VERSION_ID, EXIF_IFD_0) == NULL)
00186 
00187     /*
00188      * The tag number for EXIF_TAG_INTEROPERABILITY_INDEX (1) exists in both
00189      * IFD Interoperability and IFD GPS (as EXIF_TAG_GPS_LATITUDE_REF) so
00190      * there are two entries in the table.
00191      */
00192     VALIDATE(!strcmp(exif_tag_get_name_in_ifd(
00193                 EXIF_TAG_INTEROPERABILITY_INDEX, EXIF_IFD_INTEROPERABILITY), 
00194                      "InteroperabilityIndex"))
00195 
00196     VALIDATE(!strcmp(exif_tag_get_name_in_ifd(
00197                         EXIF_TAG_GPS_LATITUDE_REF, EXIF_IFD_GPS), 
00198                      "GPSLatitudeRef"))
00199 
00200     /* Tag that doesn't appear in an IFD produces a NULL */
00201     VALIDATE(exif_tag_get_name_in_ifd(
00202                         EXIF_TAG_EXIF_VERSION, EXIF_IFD_0) == NULL)
00203 
00204     /* Invalid IFD produces a NULL */
00205     VALIDATE(exif_tag_get_name_in_ifd(
00206                         EXIF_TAG_EXIF_VERSION, EXIF_IFD_COUNT) == NULL)
00207 
00208     return fail;
00209 }
00210 
00211 int
00212 main ()
00213 {
00214     int fail = 0;
00215 
00216     TESTBLOCK(support_level())
00217     TESTBLOCK(name())
00218 
00219     return fail;
00220 }

SourceForge.net Logo Generated by doxygen