1b8bc0d8aSopenharmony_ci/* test-gps.c 2b8bc0d8aSopenharmony_ci * 3b8bc0d8aSopenharmony_ci * Creates ExifEntries for the GPS ifd and initializes them. 4b8bc0d8aSopenharmony_ci * Checks for formats and component counts. 5b8bc0d8aSopenharmony_ci * 6b8bc0d8aSopenharmony_ci * Copyright 2020 Heiko Lewin <hlewin@gmx.de> 7b8bc0d8aSopenharmony_ci * 8b8bc0d8aSopenharmony_ci * This library is free software; you can redistribute it and/or 9b8bc0d8aSopenharmony_ci * modify it under the terms of the GNU Lesser General Public 10b8bc0d8aSopenharmony_ci * License as published by the Free Software Foundation; either 11b8bc0d8aSopenharmony_ci * version 2 of the License, or (at your option) any later version. 12b8bc0d8aSopenharmony_ci * 13b8bc0d8aSopenharmony_ci * This library is distributed in the hope that it will be useful, 14b8bc0d8aSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of 15b8bc0d8aSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16b8bc0d8aSopenharmony_ci * Lesser General Public License for more details. 17b8bc0d8aSopenharmony_ci * 18b8bc0d8aSopenharmony_ci * You should have received a copy of the GNU Lesser General Public 19b8bc0d8aSopenharmony_ci * License along with this library; if not, write to the 20b8bc0d8aSopenharmony_ci * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 21b8bc0d8aSopenharmony_ci * Boston, MA 02110-1301 USA. 22b8bc0d8aSopenharmony_ci */ 23b8bc0d8aSopenharmony_ci 24b8bc0d8aSopenharmony_ci#include <libexif/exif-utils.h> 25b8bc0d8aSopenharmony_ci#include <libexif/exif-data.h> 26b8bc0d8aSopenharmony_ci 27b8bc0d8aSopenharmony_ci#include <stdio.h> 28b8bc0d8aSopenharmony_ci#include <stdlib.h> 29b8bc0d8aSopenharmony_ci#include <string.h> 30b8bc0d8aSopenharmony_ci#include <stdint.h> 31b8bc0d8aSopenharmony_ci 32b8bc0d8aSopenharmony_ci/* 33b8bc0d8aSopenharmony_ci * List of tags to test, 34b8bc0d8aSopenharmony_ci */ 35b8bc0d8aSopenharmony_ciconst uint16_t test_tags [] = { 36b8bc0d8aSopenharmony_ci EXIF_TAG_GPS_VERSION_ID, 37b8bc0d8aSopenharmony_ci EXIF_TAG_GPS_LATITUDE_REF, 38b8bc0d8aSopenharmony_ci EXIF_TAG_GPS_LATITUDE, 39b8bc0d8aSopenharmony_ci EXIF_TAG_GPS_LONGITUDE_REF, 40b8bc0d8aSopenharmony_ci EXIF_TAG_GPS_LONGITUDE, 41b8bc0d8aSopenharmony_ci EXIF_TAG_GPS_ALTITUDE_REF, 42b8bc0d8aSopenharmony_ci EXIF_TAG_GPS_ALTITUDE, 43b8bc0d8aSopenharmony_ci EXIF_TAG_GPS_TIME_STAMP, 44b8bc0d8aSopenharmony_ci EXIF_TAG_GPS_SATELLITES, 45b8bc0d8aSopenharmony_ci EXIF_TAG_GPS_STATUS, 46b8bc0d8aSopenharmony_ci EXIF_TAG_GPS_MEASURE_MODE, 47b8bc0d8aSopenharmony_ci EXIF_TAG_GPS_DOP, 48b8bc0d8aSopenharmony_ci EXIF_TAG_GPS_SPEED_REF, 49b8bc0d8aSopenharmony_ci EXIF_TAG_GPS_SPEED, 50b8bc0d8aSopenharmony_ci EXIF_TAG_GPS_TRACK_REF, 51b8bc0d8aSopenharmony_ci EXIF_TAG_GPS_TRACK, 52b8bc0d8aSopenharmony_ci EXIF_TAG_GPS_IMG_DIRECTION_REF, 53b8bc0d8aSopenharmony_ci EXIF_TAG_GPS_IMG_DIRECTION, 54b8bc0d8aSopenharmony_ci EXIF_TAG_GPS_MAP_DATUM, 55b8bc0d8aSopenharmony_ci EXIF_TAG_GPS_DEST_LATITUDE_REF, 56b8bc0d8aSopenharmony_ci EXIF_TAG_GPS_DEST_LATITUDE, 57b8bc0d8aSopenharmony_ci EXIF_TAG_GPS_DEST_LONGITUDE_REF, 58b8bc0d8aSopenharmony_ci EXIF_TAG_GPS_DEST_LONGITUDE, 59b8bc0d8aSopenharmony_ci EXIF_TAG_GPS_DEST_BEARING_REF, 60b8bc0d8aSopenharmony_ci EXIF_TAG_GPS_DEST_BEARING, 61b8bc0d8aSopenharmony_ci EXIF_TAG_GPS_DEST_DISTANCE_REF, 62b8bc0d8aSopenharmony_ci EXIF_TAG_GPS_DEST_DISTANCE, 63b8bc0d8aSopenharmony_ci EXIF_TAG_GPS_PROCESSING_METHOD, 64b8bc0d8aSopenharmony_ci EXIF_TAG_GPS_AREA_INFORMATION, 65b8bc0d8aSopenharmony_ci EXIF_TAG_GPS_DATE_STAMP, 66b8bc0d8aSopenharmony_ci EXIF_TAG_GPS_DIFFERENTIAL, 67b8bc0d8aSopenharmony_ci EXIF_TAG_GPS_H_POSITIONING_ERROR, 68b8bc0d8aSopenharmony_ci 0xFFFFu 69b8bc0d8aSopenharmony_ci}; 70b8bc0d8aSopenharmony_ci 71b8bc0d8aSopenharmony_ci 72b8bc0d8aSopenharmony_ci/* 73b8bc0d8aSopenharmony_ci * Verify that the entry is properly initialized. 74b8bc0d8aSopenharmony_ci */ 75b8bc0d8aSopenharmony_cistatic int check_entry_format(ExifEntry *e) 76b8bc0d8aSopenharmony_ci{ 77b8bc0d8aSopenharmony_ci if(e->tag > EXIF_TAG_GPS_H_POSITIONING_ERROR) { 78b8bc0d8aSopenharmony_ci /* unknown tags should get EXIF_FORMAT_UNDEFINED, no size and no data */ 79b8bc0d8aSopenharmony_ci if(e->format != EXIF_FORMAT_UNDEFINED || e->size || e->components || e->data) { 80b8bc0d8aSopenharmony_ci fprintf(stderr, "check_entry_format: Unknown tag not handled correctly (tag=%x)\n", e->tag); 81b8bc0d8aSopenharmony_ci return 1; 82b8bc0d8aSopenharmony_ci } 83b8bc0d8aSopenharmony_ci return 0; 84b8bc0d8aSopenharmony_ci } 85b8bc0d8aSopenharmony_ci switch(e->format) { 86b8bc0d8aSopenharmony_ci case EXIF_FORMAT_UNDEFINED: 87b8bc0d8aSopenharmony_ci case EXIF_FORMAT_ASCII: 88b8bc0d8aSopenharmony_ci /* entries with ASCII or UNDEFINED format do not necessarily need to have the component count set. 89b8bc0d8aSopenharmony_ci only check here is, if component count is set, the size should match the count */ 90b8bc0d8aSopenharmony_ci if(e->size != e->components) { 91b8bc0d8aSopenharmony_ci fprintf (stderr, "check_entry_format: Entry has bad component count or size (tag=%x)\n", e->tag); 92b8bc0d8aSopenharmony_ci return 1; 93b8bc0d8aSopenharmony_ci } 94b8bc0d8aSopenharmony_ci break; 95b8bc0d8aSopenharmony_ci 96b8bc0d8aSopenharmony_ci default: 97b8bc0d8aSopenharmony_ci /* All other formats should have a nonzero component count. */ 98b8bc0d8aSopenharmony_ci if(!e->components) { 99b8bc0d8aSopenharmony_ci fprintf (stderr, "check_entry_format: Entry should have component count set (tag=%x)\n", e->tag); 100b8bc0d8aSopenharmony_ci return 1; 101b8bc0d8aSopenharmony_ci } 102b8bc0d8aSopenharmony_ci return 0; 103b8bc0d8aSopenharmony_ci } 104b8bc0d8aSopenharmony_ci 105b8bc0d8aSopenharmony_ci /* If a value is present the size should be set to the right value */ 106b8bc0d8aSopenharmony_ci if(e->data && e->size != e->components * exif_format_get_size(e->format)) { 107b8bc0d8aSopenharmony_ci fprintf (stderr, "check_entry_format: Entry has bad size (tag=%x)\n", e->tag); 108b8bc0d8aSopenharmony_ci return 1; 109b8bc0d8aSopenharmony_ci } 110b8bc0d8aSopenharmony_ci return 0; 111b8bc0d8aSopenharmony_ci} 112b8bc0d8aSopenharmony_ci 113b8bc0d8aSopenharmony_ciint 114b8bc0d8aSopenharmony_cimain () 115b8bc0d8aSopenharmony_ci{ 116b8bc0d8aSopenharmony_ci size_t i; 117b8bc0d8aSopenharmony_ci ExifData *data = NULL; 118b8bc0d8aSopenharmony_ci ExifEntry *e = NULL; 119b8bc0d8aSopenharmony_ci 120b8bc0d8aSopenharmony_ci data = exif_data_new (); 121b8bc0d8aSopenharmony_ci if (!data) { 122b8bc0d8aSopenharmony_ci fprintf (stderr, "Error running exif_data_new()\n"); 123b8bc0d8aSopenharmony_ci goto ERROR_EXIT; 124b8bc0d8aSopenharmony_ci } 125b8bc0d8aSopenharmony_ci 126b8bc0d8aSopenharmony_ci /* Run tests */ 127b8bc0d8aSopenharmony_ci for (i=0; i < sizeof(test_tags)/sizeof(test_tags[0]); ++i) { 128b8bc0d8aSopenharmony_ci e = exif_entry_new (); 129b8bc0d8aSopenharmony_ci if (!e) { 130b8bc0d8aSopenharmony_ci fprintf (stderr, "Error running exif_entry_new()\n"); 131b8bc0d8aSopenharmony_ci goto ERROR_EXIT; 132b8bc0d8aSopenharmony_ci } 133b8bc0d8aSopenharmony_ci exif_content_add_entry(data->ifd[EXIF_IFD_GPS], e); 134b8bc0d8aSopenharmony_ci exif_entry_initialize (e, (ExifTag)test_tags[i]); 135b8bc0d8aSopenharmony_ci if(check_entry_format(e)) goto ERROR_EXIT; 136b8bc0d8aSopenharmony_ci exif_content_remove_entry (data->ifd[EXIF_IFD_GPS], e); 137b8bc0d8aSopenharmony_ci exif_entry_unref (e); 138b8bc0d8aSopenharmony_ci } 139b8bc0d8aSopenharmony_ci exif_data_unref(data); 140b8bc0d8aSopenharmony_ci return 0; 141b8bc0d8aSopenharmony_ciERROR_EXIT: 142b8bc0d8aSopenharmony_ci exif_entry_unref (e); 143b8bc0d8aSopenharmony_ci exif_data_unref (data); 144b8bc0d8aSopenharmony_ci exit(EXIT_FAILURE); 145b8bc0d8aSopenharmony_ci} 146b8bc0d8aSopenharmony_ci 147