EXIF library (libexif) Internals  0.6.24
test-gps.c
Go to the documentation of this file.
1 /* test-gps.c
2  *
3  * Creates ExifEntries for the GPS ifd and initializes them.
4  * Checks for formats and component counts.
5  *
6  * Copyright 2020 Heiko Lewin <hlewin@gmx.de>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301 USA.
22  */
23 
24 #include <libexif/exif-utils.h>
25 #include <libexif/exif-data.h>
26 
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <stdint.h>
31 
32 /*
33  * List of tags to test,
34  */
35 const uint16_t test_tags [] = {
68  0xFFFFu
69 };
70 
71 
72 /*
73  * Verify that the entry is properly initialized.
74  */
76 {
78  /* unknown tags should get EXIF_FORMAT_UNDEFINED, no size and no data */
79  if(e->format != EXIF_FORMAT_UNDEFINED || e->size || e->components || e->data) {
80  fprintf(stderr, "check_entry_format: Unknown tag not handled correctly (tag=%x)\n", e->tag);
81  return 1;
82  }
83  return 0;
84  }
85  switch(e->format) {
87  case EXIF_FORMAT_ASCII:
88  /* entries with ASCII or UNDEFINED format do not necessarily need to have the component count set.
89  only check here is, if component count is set, the size should match the count */
90  if(e->size != e->components) {
91  fprintf (stderr, "check_entry_format: Entry has bad component count or size (tag=%x)\n", e->tag);
92  return 1;
93  }
94  break;
95 
96  default:
97  /* All other formats should have a nonzero component count. */
98  if(!e->components) {
99  fprintf (stderr, "check_entry_format: Entry should have component count set (tag=%x)\n", e->tag);
100  return 1;
101  }
102  return 0;
103  }
104 
105  /* If a value is present the size should be set to the right value */
106  if(e->data && e->size != e->components * exif_format_get_size(e->format)) {
107  fprintf (stderr, "check_entry_format: Entry has bad size (tag=%x)\n", e->tag);
108  return 1;
109  }
110  return 0;
111 }
112 
113 int
115 {
116  size_t i;
117  ExifData *data = NULL;
118  ExifEntry *e = NULL;
119 
120  data = exif_data_new ();
121  if (!data) {
122  fprintf (stderr, "Error running exif_data_new()\n");
123  goto ERROR_EXIT;
124  }
125 
126  /* Run tests */
127  for (i=0; i < sizeof(test_tags)/sizeof(test_tags[0]); ++i) {
128  e = exif_entry_new ();
129  if (!e) {
130  fprintf (stderr, "Error running exif_entry_new()\n");
131  goto ERROR_EXIT;
132  }
135  if(check_entry_format(e)) goto ERROR_EXIT;
137  exif_entry_unref (e);
138  }
139  exif_data_unref(data);
140  return 0;
141 ERROR_EXIT:
142  exif_entry_unref (e);
143  exif_data_unref (data);
144  exit(EXIT_FAILURE);
145 }
146 
void exif_content_remove_entry(ExifContent *c, ExifEntry *e)
Remove an EXIF tag from an IFD.
Definition: exif-content.c:163
void exif_content_add_entry(ExifContent *c, ExifEntry *entry)
Add an EXIF tag to an IFD.
Definition: exif-content.c:139
ExifData * exif_data_new(void)
Allocate a new ExifData.
Definition: exif-data.c:96
void exif_data_unref(ExifData *data)
Definition: exif-data.c:1098
Defines the ExifData type and the associated functions.
ExifEntry * exif_entry_new(void)
Reserve memory for and initialize a new ExifEntry.
Definition: exif-entry.c:111
void exif_entry_unref(ExifEntry *e)
Decrease reference counter for ExifEntry.
Definition: exif-entry.c:147
void exif_entry_initialize(ExifEntry *e, ExifTag tag)
Initialize an empty ExifEntry with default data in the correct format for the given tag.
Definition: exif-entry.c:1459
unsigned char exif_format_get_size(ExifFormat format)
Return the raw size of the given EXIF data type.
Definition: exif-format.c:66
@ EXIF_FORMAT_UNDEFINED
Definition: exif-format.h:39
@ EXIF_FORMAT_ASCII
Definition: exif-format.h:34
@ EXIF_IFD_GPS
Definition: exif-ifd.h:33
#define EXIF_TAG_GPS_LONGITUDE
Definition: exif-tag.h:178
#define EXIF_TAG_GPS_DEST_LATITUDE
Definition: exif-tag.h:194
#define EXIF_TAG_GPS_PROCESSING_METHOD
Definition: exif-tag.h:201
ExifTag
EXIF tags.
Definition: exif-tag.h:34
#define EXIF_TAG_GPS_TRACK_REF
Definition: exif-tag.h:188
#define EXIF_TAG_GPS_DEST_DISTANCE_REF
Definition: exif-tag.h:199
#define EXIF_TAG_GPS_MAP_DATUM
Definition: exif-tag.h:192
#define EXIF_TAG_GPS_TIME_STAMP
Definition: exif-tag.h:181
#define EXIF_TAG_GPS_LONGITUDE_REF
Definition: exif-tag.h:177
#define EXIF_TAG_GPS_SPEED_REF
Definition: exif-tag.h:186
#define EXIF_TAG_GPS_VERSION_ID
Definition: exif-tag.h:174
#define EXIF_TAG_GPS_IMG_DIRECTION
Definition: exif-tag.h:191
#define EXIF_TAG_GPS_DEST_LONGITUDE
Definition: exif-tag.h:196
#define EXIF_TAG_GPS_DOP
Definition: exif-tag.h:185
#define EXIF_TAG_GPS_AREA_INFORMATION
Definition: exif-tag.h:202
#define EXIF_TAG_GPS_DATE_STAMP
Definition: exif-tag.h:203
#define EXIF_TAG_GPS_H_POSITIONING_ERROR
Definition: exif-tag.h:205
#define EXIF_TAG_GPS_ALTITUDE
Definition: exif-tag.h:180
#define EXIF_TAG_GPS_DEST_BEARING
Definition: exif-tag.h:198
#define EXIF_TAG_GPS_DEST_BEARING_REF
Definition: exif-tag.h:197
#define EXIF_TAG_GPS_DIFFERENTIAL
Definition: exif-tag.h:204
#define EXIF_TAG_GPS_DEST_DISTANCE
Definition: exif-tag.h:200
#define EXIF_TAG_GPS_DEST_LATITUDE_REF
Definition: exif-tag.h:193
#define EXIF_TAG_GPS_LATITUDE_REF
Definition: exif-tag.h:175
#define EXIF_TAG_GPS_LATITUDE
Definition: exif-tag.h:176
#define EXIF_TAG_GPS_IMG_DIRECTION_REF
Definition: exif-tag.h:190
#define EXIF_TAG_GPS_TRACK
Definition: exif-tag.h:189
#define EXIF_TAG_GPS_MEASURE_MODE
Definition: exif-tag.h:184
#define EXIF_TAG_GPS_SPEED
Definition: exif-tag.h:187
#define EXIF_TAG_GPS_ALTITUDE_REF
Definition: exif-tag.h:179
#define EXIF_TAG_GPS_DEST_LONGITUDE_REF
Definition: exif-tag.h:195
#define EXIF_TAG_GPS_SATELLITES
Definition: exif-tag.h:182
#define EXIF_TAG_GPS_STATUS
Definition: exif-tag.h:183
EXIF data manipulation functions and types.
Represents the entire EXIF data found in an image.
Definition: exif-data.h:47
ExifContent * ifd[EXIF_IFD_COUNT]
Data for each IFD.
Definition: exif-data.h:49
Data found in one EXIF tag.
Definition: exif-entry.h:43
unsigned long components
Number of elements in the array, if this is an array entry.
Definition: exif-entry.h:52
ExifFormat format
Type of data in this entry.
Definition: exif-entry.h:48
unsigned char * data
Pointer to the raw EXIF data for this entry.
Definition: exif-entry.h:57
ExifTag tag
EXIF tag for this entry.
Definition: exif-entry.h:45
unsigned int size
Number of bytes in the buffer at data.
Definition: exif-entry.h:61
static int check_entry_format(ExifEntry *e)
Definition: test-gps.c:75
const uint16_t test_tags[]
Definition: test-gps.c:35
int main()
Definition: test-gps.c:114

libexif Generated by doxygen