EXIF library (libexif) Internals 0.6.26
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 * SPDX-License-Identifier: LGPL-2.0-or-later
24 */
25
26#include <libexif/exif-utils.h>
27#include <libexif/exif-data.h>
28
29#include <stdio.h>
30#include <stdlib.h>
31#include <string.h>
32#include <stdint.h>
33
34/*
35 * List of tags to test,
36 */
37static const uint16_t test_tags [] = {
70 0xFFFFu
71};
72
73
74/*
75 * Verify that the entry is properly initialized.
76 */
78{
80 /* unknown tags should get EXIF_FORMAT_UNDEFINED, no size and no data */
81 if(e->format != EXIF_FORMAT_UNDEFINED || e->size || e->components || e->data) {
82 fprintf(stderr, "check_entry_format: Unknown tag not handled correctly (tag=%x)\n", e->tag);
83 return 1;
84 }
85 return 0;
86 }
87 switch(e->format) {
90 /* entries with ASCII or UNDEFINED format do not necessarily need to have the component count set.
91 only check here is, if component count is set, the size should match the count */
92 if(e->size != e->components) {
93 fprintf (stderr, "check_entry_format: Entry has bad component count or size (tag=%x)\n", e->tag);
94 return 1;
95 }
96 break;
97
98 default:
99 /* All other formats should have a nonzero component count. */
100 if(!e->components) {
101 fprintf (stderr, "check_entry_format: Entry should have component count set (tag=%x)\n", e->tag);
102 return 1;
103 }
104 return 0;
105 }
106
107 /* If a value is present the size should be set to the right value */
108 if(e->data && e->size != e->components * exif_format_get_size(e->format)) {
109 fprintf (stderr, "check_entry_format: Entry has bad size (tag=%x)\n", e->tag);
110 return 1;
111 }
112 return 0;
113}
114
115int
116main (void)
117{
118 size_t i;
119 ExifData *data = NULL;
120 ExifEntry *e = NULL;
121
122 data = exif_data_new ();
123 if (!data) {
124 fprintf (stderr, "Error running exif_data_new()\n");
125 goto ERROR_EXIT;
126 }
127
128 /* Run tests */
129 for (i=0; i < sizeof(test_tags)/sizeof(test_tags[0]); ++i) {
130 e = exif_entry_new ();
131 if (!e) {
132 fprintf (stderr, "Error running exif_entry_new()\n");
133 goto ERROR_EXIT;
134 }
137 if(check_entry_format(e)) goto ERROR_EXIT;
140 }
141 exif_data_unref(data);
142 return 0;
143ERROR_EXIT:
145 exif_data_unref (data);
146 exit(EXIT_FAILURE);
147}
148
void exif_content_remove_entry(ExifContent *c, ExifEntry *e)
Remove an EXIF tag from an IFD.
void exif_content_add_entry(ExifContent *c, ExifEntry *entry)
Add an EXIF tag to an IFD.
void exif_data_unref(ExifData *data)
Definition exif-data.c:1110
ExifData * exif_data_new(void)
Allocate a new ExifData.
Definition exif-data.c:98
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:113
void exif_entry_unref(ExifEntry *e)
Decrease reference counter for ExifEntry.
Definition exif-entry.c:149
void exif_entry_initialize(ExifEntry *e, ExifTag tag)
Initialize an empty ExifEntry with default data in the correct format for the given tag.
unsigned char exif_format_get_size(ExifFormat format)
Return the raw size of the given EXIF data type.
Definition exif-format.c:68
@ EXIF_FORMAT_UNDEFINED
Definition exif-format.h:41
@ EXIF_FORMAT_ASCII
Definition exif-format.h:36
@ EXIF_IFD_GPS
Definition exif-ifd.h:35
#define EXIF_TAG_GPS_LONGITUDE
Definition exif-tag.h:180
#define EXIF_TAG_GPS_DEST_LATITUDE
Definition exif-tag.h:196
#define EXIF_TAG_GPS_PROCESSING_METHOD
Definition exif-tag.h:203
ExifTag
EXIF tags.
Definition exif-tag.h:36
#define EXIF_TAG_GPS_TRACK_REF
Definition exif-tag.h:190
#define EXIF_TAG_GPS_DEST_DISTANCE_REF
Definition exif-tag.h:201
#define EXIF_TAG_GPS_MAP_DATUM
Definition exif-tag.h:194
#define EXIF_TAG_GPS_TIME_STAMP
Definition exif-tag.h:183
#define EXIF_TAG_GPS_LONGITUDE_REF
Definition exif-tag.h:179
#define EXIF_TAG_GPS_SPEED_REF
Definition exif-tag.h:188
#define EXIF_TAG_GPS_VERSION_ID
Definition exif-tag.h:176
#define EXIF_TAG_GPS_IMG_DIRECTION
Definition exif-tag.h:193
#define EXIF_TAG_GPS_DEST_LONGITUDE
Definition exif-tag.h:198
#define EXIF_TAG_GPS_DOP
Definition exif-tag.h:187
#define EXIF_TAG_GPS_AREA_INFORMATION
Definition exif-tag.h:204
#define EXIF_TAG_GPS_DATE_STAMP
Definition exif-tag.h:205
#define EXIF_TAG_GPS_H_POSITIONING_ERROR
Definition exif-tag.h:207
#define EXIF_TAG_GPS_ALTITUDE
Definition exif-tag.h:182
#define EXIF_TAG_GPS_DEST_BEARING
Definition exif-tag.h:200
#define EXIF_TAG_GPS_DEST_BEARING_REF
Definition exif-tag.h:199
#define EXIF_TAG_GPS_DIFFERENTIAL
Definition exif-tag.h:206
#define EXIF_TAG_GPS_DEST_DISTANCE
Definition exif-tag.h:202
#define EXIF_TAG_GPS_DEST_LATITUDE_REF
Definition exif-tag.h:195
#define EXIF_TAG_GPS_LATITUDE_REF
Definition exif-tag.h:177
#define EXIF_TAG_GPS_LATITUDE
Definition exif-tag.h:178
#define EXIF_TAG_GPS_IMG_DIRECTION_REF
Definition exif-tag.h:192
#define EXIF_TAG_GPS_TRACK
Definition exif-tag.h:191
#define EXIF_TAG_GPS_MEASURE_MODE
Definition exif-tag.h:186
#define EXIF_TAG_GPS_SPEED
Definition exif-tag.h:189
#define EXIF_TAG_GPS_ALTITUDE_REF
Definition exif-tag.h:181
#define EXIF_TAG_GPS_DEST_LONGITUDE_REF
Definition exif-tag.h:197
#define EXIF_TAG_GPS_SATELLITES
Definition exif-tag.h:184
#define EXIF_TAG_GPS_STATUS
Definition exif-tag.h:185
EXIF data manipulation functions and types.
Represents the entire EXIF data found in an image.
Definition exif-data.h:48
ExifContent * ifd[EXIF_IFD_COUNT]
Data for each IFD.
Definition exif-data.h:50
Data found in one EXIF tag.
Definition exif-entry.h:45
unsigned long components
Number of elements in the array, if this is an array entry.
Definition exif-entry.h:54
ExifFormat format
Type of data in this entry.
Definition exif-entry.h:50
unsigned char * data
Pointer to the raw EXIF data for this entry.
Definition exif-entry.h:59
ExifTag tag
EXIF tag for this entry.
Definition exif-entry.h:47
unsigned int size
Number of bytes in the buffer at data.
Definition exif-entry.h:63
int main(void)
Definition test-gps.c:116
static int check_entry_format(ExifEntry *e)
Definition test-gps.c:77
static const uint16_t test_tags[]
Definition test-gps.c:37

libexif Generated by doxygen