1b8bc0d8aSopenharmony_ci/* test-value.c 2b8bc0d8aSopenharmony_ci * 3b8bc0d8aSopenharmony_ci * Creates all the types of tags supported in exif_entry_initialize() and 4b8bc0d8aSopenharmony_ci * ensures that exif_entry_get_value() properly truncates the output of each 5b8bc0d8aSopenharmony_ci * one according to the buffer size available. 6b8bc0d8aSopenharmony_ci * 7b8bc0d8aSopenharmony_ci * Copyright 2002 Lutz Mueller <lutz@users.sourceforge.net> 8b8bc0d8aSopenharmony_ci * 9b8bc0d8aSopenharmony_ci * This library is free software; you can redistribute it and/or 10b8bc0d8aSopenharmony_ci * modify it under the terms of the GNU Lesser General Public 11b8bc0d8aSopenharmony_ci * License as published by the Free Software Foundation; either 12b8bc0d8aSopenharmony_ci * version 2 of the License, or (at your option) any later version. 13b8bc0d8aSopenharmony_ci * 14b8bc0d8aSopenharmony_ci * This library is distributed in the hope that it will be useful, 15b8bc0d8aSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of 16b8bc0d8aSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17b8bc0d8aSopenharmony_ci * Lesser General Public License for more details. 18b8bc0d8aSopenharmony_ci * 19b8bc0d8aSopenharmony_ci * You should have received a copy of the GNU Lesser General Public 20b8bc0d8aSopenharmony_ci * License along with this library; if not, write to the 21b8bc0d8aSopenharmony_ci * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22b8bc0d8aSopenharmony_ci * Boston, MA 02110-1301 USA. 23b8bc0d8aSopenharmony_ci */ 24b8bc0d8aSopenharmony_ci 25b8bc0d8aSopenharmony_ci#include <libexif/exif-utils.h> 26b8bc0d8aSopenharmony_ci#include <libexif/exif-data.h> 27b8bc0d8aSopenharmony_ci 28b8bc0d8aSopenharmony_ci#include <stdio.h> 29b8bc0d8aSopenharmony_ci#include <stdlib.h> 30b8bc0d8aSopenharmony_ci#include <string.h> 31b8bc0d8aSopenharmony_ci 32b8bc0d8aSopenharmony_ci/* 33b8bc0d8aSopenharmony_ci * List of tags to test, one per default initialized type. 34b8bc0d8aSopenharmony_ci * There should be one for every block in exif_entry_initialize() and 35b8bc0d8aSopenharmony_ci * exif_entry_get_value(). 36b8bc0d8aSopenharmony_ci */ 37b8bc0d8aSopenharmony_ciExifTag trunc_test_tags[] = { 38b8bc0d8aSopenharmony_ci EXIF_TAG_PIXEL_X_DIMENSION, 39b8bc0d8aSopenharmony_ci EXIF_TAG_SUBJECT_LOCATION, 40b8bc0d8aSopenharmony_ci EXIF_TAG_IMAGE_WIDTH, 41b8bc0d8aSopenharmony_ci EXIF_TAG_ORIENTATION, 42b8bc0d8aSopenharmony_ci EXIF_TAG_SAMPLES_PER_PIXEL, 43b8bc0d8aSopenharmony_ci EXIF_TAG_BITS_PER_SAMPLE, 44b8bc0d8aSopenharmony_ci EXIF_TAG_X_RESOLUTION, 45b8bc0d8aSopenharmony_ci EXIF_TAG_WHITE_POINT, 46b8bc0d8aSopenharmony_ci EXIF_TAG_REFERENCE_BLACK_WHITE, 47b8bc0d8aSopenharmony_ci EXIF_TAG_DATE_TIME, 48b8bc0d8aSopenharmony_ci EXIF_TAG_IMAGE_DESCRIPTION, 49b8bc0d8aSopenharmony_ci EXIF_TAG_EXIF_VERSION, 50b8bc0d8aSopenharmony_ci EXIF_TAG_FLASH_PIX_VERSION, 51b8bc0d8aSopenharmony_ci EXIF_TAG_COPYRIGHT, 52b8bc0d8aSopenharmony_ci EXIF_TAG_FILE_SOURCE, 53b8bc0d8aSopenharmony_ci EXIF_TAG_COMPONENTS_CONFIGURATION, 54b8bc0d8aSopenharmony_ci EXIF_TAG_SCENE_TYPE, 55b8bc0d8aSopenharmony_ci EXIF_TAG_YCBCR_SUB_SAMPLING, 56b8bc0d8aSopenharmony_ci EXIF_TAG_PLANAR_CONFIGURATION, 57b8bc0d8aSopenharmony_ci}; 58b8bc0d8aSopenharmony_ci 59b8bc0d8aSopenharmony_ci/* 60b8bc0d8aSopenharmony_ci * These tags produce different outputs depending on the amount of buffer space 61b8bc0d8aSopenharmony_ci * available. 62b8bc0d8aSopenharmony_ci */ 63b8bc0d8aSopenharmony_ciExifTag nonuniform_test_tags[] = { 64b8bc0d8aSopenharmony_ci EXIF_TAG_RESOLUTION_UNIT, 65b8bc0d8aSopenharmony_ci EXIF_TAG_COLOR_SPACE, 66b8bc0d8aSopenharmony_ci EXIF_TAG_METERING_MODE, 67b8bc0d8aSopenharmony_ci}; 68b8bc0d8aSopenharmony_ci 69b8bc0d8aSopenharmony_ci/* 70b8bc0d8aSopenharmony_ci * These tags need a nonzero rational number to be interesting. 71b8bc0d8aSopenharmony_ci * They must have space for a rational or srational created automatically by 72b8bc0d8aSopenharmony_ci * exif_entry_initialize(). 73b8bc0d8aSopenharmony_ci */ 74b8bc0d8aSopenharmony_ciExifTag rational_test_tags[] = { 75b8bc0d8aSopenharmony_ci EXIF_TAG_FNUMBER, 76b8bc0d8aSopenharmony_ci EXIF_TAG_APERTURE_VALUE, 77b8bc0d8aSopenharmony_ci EXIF_TAG_MAX_APERTURE_VALUE, 78b8bc0d8aSopenharmony_ci EXIF_TAG_FOCAL_LENGTH, 79b8bc0d8aSopenharmony_ci EXIF_TAG_SUBJECT_DISTANCE, 80b8bc0d8aSopenharmony_ci EXIF_TAG_EXPOSURE_TIME, 81b8bc0d8aSopenharmony_ci EXIF_TAG_SHUTTER_SPEED_VALUE, 82b8bc0d8aSopenharmony_ci EXIF_TAG_BRIGHTNESS_VALUE, 83b8bc0d8aSopenharmony_ci EXIF_TAG_EXPOSURE_BIAS_VALUE, 84b8bc0d8aSopenharmony_ci}; 85b8bc0d8aSopenharmony_ci 86b8bc0d8aSopenharmony_ci/* 87b8bc0d8aSopenharmony_ci * Verify that the entry is properly truncated to the buffer length within 88b8bc0d8aSopenharmony_ci * exif_entry_get_value(). If uniform is zero, then only check that the 89b8bc0d8aSopenharmony_ci * resulting string fits within the buffer and don't check its content. 90b8bc0d8aSopenharmony_ci */ 91b8bc0d8aSopenharmony_cistatic void check_entry_trunc(ExifEntry *e, int uniform) 92b8bc0d8aSopenharmony_ci{ 93b8bc0d8aSopenharmony_ci unsigned int i; 94b8bc0d8aSopenharmony_ci char v[1024], full[1024]; /* Large enough to never truncate output */ 95b8bc0d8aSopenharmony_ci 96b8bc0d8aSopenharmony_ci printf ("Tag 0x%x\n", (int) e->tag); 97b8bc0d8aSopenharmony_ci 98b8bc0d8aSopenharmony_ci /* Get the full, untruncated string to use as the expected value */ 99b8bc0d8aSopenharmony_ci exif_entry_get_value (e, full, sizeof(full)); 100b8bc0d8aSopenharmony_ci printf ("Full: '%s'\n", full); 101b8bc0d8aSopenharmony_ci 102b8bc0d8aSopenharmony_ci for (i = strlen(full); i > 0; i--) { 103b8bc0d8aSopenharmony_ci /* Make sure the buffer isn't NUL-terminated to begin with */ 104b8bc0d8aSopenharmony_ci memset(v, '*', sizeof(v)); 105b8bc0d8aSopenharmony_ci exif_entry_get_value (e, v, i); 106b8bc0d8aSopenharmony_ci /* Truncate the full string by one on each iteration */ 107b8bc0d8aSopenharmony_ci full[i-1] = '\0'; 108b8bc0d8aSopenharmony_ci if ((strlen(v) >= i) || (uniform && strcmp(full, v))) { 109b8bc0d8aSopenharmony_ci printf("Bad truncation!\n"); 110b8bc0d8aSopenharmony_ci printf("Length %2i: '%s'\n", i, v); 111b8bc0d8aSopenharmony_ci exit(1); 112b8bc0d8aSopenharmony_ci } 113b8bc0d8aSopenharmony_ci } 114b8bc0d8aSopenharmony_ci} 115b8bc0d8aSopenharmony_ci 116b8bc0d8aSopenharmony_ciint 117b8bc0d8aSopenharmony_cimain () 118b8bc0d8aSopenharmony_ci{ 119b8bc0d8aSopenharmony_ci ExifData *data; 120b8bc0d8aSopenharmony_ci ExifEntry *e; 121b8bc0d8aSopenharmony_ci ExifMem *mem; 122b8bc0d8aSopenharmony_ci unsigned i; 123b8bc0d8aSopenharmony_ci static const ExifSRational r = {1., 20.}; /* a nonzero number */ 124b8bc0d8aSopenharmony_ci static const char user_comment[] = "ASCII\0\0\0A Long User Comment"; 125b8bc0d8aSopenharmony_ci static const char xp_comment[] = "U\0C\0S\0-\0002\0 \0C\0o\0m\0m\0e\0n\0t\0"; 126b8bc0d8aSopenharmony_ci static const char interop[] = "R98"; 127b8bc0d8aSopenharmony_ci static const char subsec[] = "130 "; 128b8bc0d8aSopenharmony_ci static const ExifRational gpsh = {12., 1.}; 129b8bc0d8aSopenharmony_ci static const ExifRational gpsm = {34., 1.}; 130b8bc0d8aSopenharmony_ci static const ExifRational gpss = {56780., 1000.}; 131b8bc0d8aSopenharmony_ci 132b8bc0d8aSopenharmony_ci data = exif_data_new (); 133b8bc0d8aSopenharmony_ci if (!data) { 134b8bc0d8aSopenharmony_ci fprintf (stderr, "Error running exif_data_new()\n"); 135b8bc0d8aSopenharmony_ci exit(13); 136b8bc0d8aSopenharmony_ci } 137b8bc0d8aSopenharmony_ci 138b8bc0d8aSopenharmony_ci /* Full initialization/truncation tests */ 139b8bc0d8aSopenharmony_ci for (i=0; i < sizeof(trunc_test_tags)/sizeof(trunc_test_tags[0]); ++i) { 140b8bc0d8aSopenharmony_ci e = exif_entry_new (); 141b8bc0d8aSopenharmony_ci if (!e) { 142b8bc0d8aSopenharmony_ci fprintf (stderr, "Error running exif_entry_new()\n"); 143b8bc0d8aSopenharmony_ci exit(13); 144b8bc0d8aSopenharmony_ci } 145b8bc0d8aSopenharmony_ci exif_content_add_entry (data->ifd[EXIF_IFD_0], e); 146b8bc0d8aSopenharmony_ci exif_entry_initialize (e, trunc_test_tags[i]); 147b8bc0d8aSopenharmony_ci check_entry_trunc(e, 1); 148b8bc0d8aSopenharmony_ci exif_content_remove_entry (data->ifd[EXIF_IFD_0], e); 149b8bc0d8aSopenharmony_ci exif_entry_unref (e); 150b8bc0d8aSopenharmony_ci } 151b8bc0d8aSopenharmony_ci 152b8bc0d8aSopenharmony_ci /* Nonuniform initialization/truncation tests */ 153b8bc0d8aSopenharmony_ci for (i=0; i < sizeof(nonuniform_test_tags)/sizeof(nonuniform_test_tags[0]); 154b8bc0d8aSopenharmony_ci ++i) { 155b8bc0d8aSopenharmony_ci e = exif_entry_new (); 156b8bc0d8aSopenharmony_ci if (!e) { 157b8bc0d8aSopenharmony_ci fprintf (stderr, "Error running exif_entry_new()\n"); 158b8bc0d8aSopenharmony_ci exit(13); 159b8bc0d8aSopenharmony_ci } 160b8bc0d8aSopenharmony_ci exif_content_add_entry (data->ifd[EXIF_IFD_0], e); 161b8bc0d8aSopenharmony_ci exif_entry_initialize (e, nonuniform_test_tags[i]); 162b8bc0d8aSopenharmony_ci check_entry_trunc(e, 0); 163b8bc0d8aSopenharmony_ci exif_content_remove_entry (data->ifd[EXIF_IFD_0], e); 164b8bc0d8aSopenharmony_ci exif_entry_unref (e); 165b8bc0d8aSopenharmony_ci } 166b8bc0d8aSopenharmony_ci 167b8bc0d8aSopenharmony_ci /* Rational number initialization/truncation tests */ 168b8bc0d8aSopenharmony_ci for (i=0; i < sizeof(rational_test_tags)/sizeof(rational_test_tags[0]); 169b8bc0d8aSopenharmony_ci ++i) { 170b8bc0d8aSopenharmony_ci e = exif_entry_new (); 171b8bc0d8aSopenharmony_ci if (!e) { 172b8bc0d8aSopenharmony_ci fprintf (stderr, "Error running exif_entry_new()\n"); 173b8bc0d8aSopenharmony_ci exit(13); 174b8bc0d8aSopenharmony_ci } 175b8bc0d8aSopenharmony_ci exif_content_add_entry (data->ifd[EXIF_IFD_0], e); 176b8bc0d8aSopenharmony_ci exif_entry_initialize (e, rational_test_tags[i]); 177b8bc0d8aSopenharmony_ci exif_set_srational (e->data, exif_data_get_byte_order (data), r); 178b8bc0d8aSopenharmony_ci /* In case this tag needs an unsigned rational instead, 179b8bc0d8aSopenharmony_ci * fix the type automatically */ 180b8bc0d8aSopenharmony_ci exif_entry_fix (e); 181b8bc0d8aSopenharmony_ci check_entry_trunc(e, 1); 182b8bc0d8aSopenharmony_ci exif_content_remove_entry (data->ifd[EXIF_IFD_0], e); 183b8bc0d8aSopenharmony_ci exif_entry_unref (e); 184b8bc0d8aSopenharmony_ci } 185b8bc0d8aSopenharmony_ci 186b8bc0d8aSopenharmony_ci /* Create a memory allocator to manage the remaining ExifEntry structs */ 187b8bc0d8aSopenharmony_ci mem = exif_mem_new_default(); 188b8bc0d8aSopenharmony_ci if (!mem) { 189b8bc0d8aSopenharmony_ci fprintf (stderr, "Out of memory\n"); 190b8bc0d8aSopenharmony_ci exit(13); 191b8bc0d8aSopenharmony_ci } 192b8bc0d8aSopenharmony_ci 193b8bc0d8aSopenharmony_ci /* EXIF_TAG_SUB_SEC_TIME initialization/truncation tests */ 194b8bc0d8aSopenharmony_ci e = exif_entry_new_mem (mem); 195b8bc0d8aSopenharmony_ci if (!e) { 196b8bc0d8aSopenharmony_ci fprintf (stderr, "Out of memory\n"); 197b8bc0d8aSopenharmony_ci exit(13); 198b8bc0d8aSopenharmony_ci } 199b8bc0d8aSopenharmony_ci exif_content_add_entry (data->ifd[EXIF_IFD_0], e); 200b8bc0d8aSopenharmony_ci exif_entry_initialize (e, EXIF_TAG_SUB_SEC_TIME); 201b8bc0d8aSopenharmony_ci e->size = sizeof(subsec); /* include NUL */ 202b8bc0d8aSopenharmony_ci e->components = e->size; 203b8bc0d8aSopenharmony_ci /* Allocate memory to use for holding the tag data */ 204b8bc0d8aSopenharmony_ci e->data = exif_mem_alloc(mem, e->size); 205b8bc0d8aSopenharmony_ci if (!e->data) { 206b8bc0d8aSopenharmony_ci fprintf (stderr, "Out of memory\n"); 207b8bc0d8aSopenharmony_ci exit(13); 208b8bc0d8aSopenharmony_ci } 209b8bc0d8aSopenharmony_ci memcpy(e->data, subsec, e->size); 210b8bc0d8aSopenharmony_ci check_entry_trunc(e, 1); 211b8bc0d8aSopenharmony_ci exif_content_remove_entry (data->ifd[EXIF_IFD_0], e); 212b8bc0d8aSopenharmony_ci exif_entry_unref (e); 213b8bc0d8aSopenharmony_ci 214b8bc0d8aSopenharmony_ci /* EXIF_TAG_USER_COMMENT initialization/truncation tests */ 215b8bc0d8aSopenharmony_ci e = exif_entry_new_mem (mem); 216b8bc0d8aSopenharmony_ci if (!e) { 217b8bc0d8aSopenharmony_ci fprintf (stderr, "Out of memory\n"); 218b8bc0d8aSopenharmony_ci exit(13); 219b8bc0d8aSopenharmony_ci } 220b8bc0d8aSopenharmony_ci exif_content_add_entry (data->ifd[EXIF_IFD_0], e); 221b8bc0d8aSopenharmony_ci exif_entry_initialize (e, EXIF_TAG_USER_COMMENT); 222b8bc0d8aSopenharmony_ci e->size = sizeof(user_comment) - 1; 223b8bc0d8aSopenharmony_ci e->components = e->size; 224b8bc0d8aSopenharmony_ci /* Allocate memory to use for holding the tag data */ 225b8bc0d8aSopenharmony_ci e->data = exif_mem_alloc(mem, e->size); 226b8bc0d8aSopenharmony_ci if (!e->data) { 227b8bc0d8aSopenharmony_ci fprintf (stderr, "Out of memory\n"); 228b8bc0d8aSopenharmony_ci exit(13); 229b8bc0d8aSopenharmony_ci } 230b8bc0d8aSopenharmony_ci memcpy(e->data, user_comment, e->size); 231b8bc0d8aSopenharmony_ci check_entry_trunc(e, 1); 232b8bc0d8aSopenharmony_ci exif_content_remove_entry (data->ifd[EXIF_IFD_0], e); 233b8bc0d8aSopenharmony_ci exif_entry_unref (e); 234b8bc0d8aSopenharmony_ci 235b8bc0d8aSopenharmony_ci /* EXIF_TAG_XP_COMMENT truncation tests */ 236b8bc0d8aSopenharmony_ci e = exif_entry_new_mem (mem); 237b8bc0d8aSopenharmony_ci if (!e) { 238b8bc0d8aSopenharmony_ci fprintf (stderr, "Out of memory\n"); 239b8bc0d8aSopenharmony_ci exit(13); 240b8bc0d8aSopenharmony_ci } 241b8bc0d8aSopenharmony_ci exif_content_add_entry (data->ifd[EXIF_IFD_0], e); 242b8bc0d8aSopenharmony_ci exif_entry_initialize (e, EXIF_TAG_XP_COMMENT); 243b8bc0d8aSopenharmony_ci e->format = EXIF_FORMAT_BYTE; 244b8bc0d8aSopenharmony_ci e->size = sizeof(xp_comment) - 1; 245b8bc0d8aSopenharmony_ci e->components = e->size; 246b8bc0d8aSopenharmony_ci /* Allocate memory to use for holding the tag data */ 247b8bc0d8aSopenharmony_ci e->data = exif_mem_alloc(mem, e->size); 248b8bc0d8aSopenharmony_ci if (!e->data) { 249b8bc0d8aSopenharmony_ci fprintf (stderr, "Out of memory\n"); 250b8bc0d8aSopenharmony_ci exit(13); 251b8bc0d8aSopenharmony_ci } 252b8bc0d8aSopenharmony_ci memcpy(e->data, xp_comment, e->size); 253b8bc0d8aSopenharmony_ci check_entry_trunc(e, 1); 254b8bc0d8aSopenharmony_ci exif_content_remove_entry (data->ifd[EXIF_IFD_0], e); 255b8bc0d8aSopenharmony_ci exif_entry_unref (e); 256b8bc0d8aSopenharmony_ci 257b8bc0d8aSopenharmony_ci /* EXIF_TAG_INTEROPERABILITY_VERSION truncation tests */ 258b8bc0d8aSopenharmony_ci e = exif_entry_new_mem (mem); 259b8bc0d8aSopenharmony_ci if (!e) { 260b8bc0d8aSopenharmony_ci fprintf (stderr, "Out of memory\n"); 261b8bc0d8aSopenharmony_ci exit(13); 262b8bc0d8aSopenharmony_ci } 263b8bc0d8aSopenharmony_ci exif_content_add_entry (data->ifd[EXIF_IFD_INTEROPERABILITY], e); 264b8bc0d8aSopenharmony_ci exif_entry_initialize (e, EXIF_TAG_INTEROPERABILITY_VERSION); 265b8bc0d8aSopenharmony_ci e->format = EXIF_FORMAT_UNDEFINED; /* The spec says ASCII, but libexif 266b8bc0d8aSopenharmony_ci allows UNDEFINED */ 267b8bc0d8aSopenharmony_ci e->size = sizeof(interop); /* include NUL */ 268b8bc0d8aSopenharmony_ci e->components = e->size; 269b8bc0d8aSopenharmony_ci /* Allocate memory to use for holding the tag data */ 270b8bc0d8aSopenharmony_ci e->data = exif_mem_alloc(mem, e->size); 271b8bc0d8aSopenharmony_ci if (!e->data) { 272b8bc0d8aSopenharmony_ci fprintf (stderr, "Out of memory\n"); 273b8bc0d8aSopenharmony_ci exit(13); 274b8bc0d8aSopenharmony_ci } 275b8bc0d8aSopenharmony_ci memcpy(e->data, interop, e->size); 276b8bc0d8aSopenharmony_ci check_entry_trunc(e, 1); 277b8bc0d8aSopenharmony_ci exif_content_remove_entry (data->ifd[EXIF_IFD_INTEROPERABILITY], e); 278b8bc0d8aSopenharmony_ci exif_entry_unref (e); 279b8bc0d8aSopenharmony_ci 280b8bc0d8aSopenharmony_ci /* EXIF_TAG_GPS_VERSION_ID truncation tests */ 281b8bc0d8aSopenharmony_ci e = exif_entry_new_mem (mem); 282b8bc0d8aSopenharmony_ci if (!e) { 283b8bc0d8aSopenharmony_ci fprintf (stderr, "Out of memory\n"); 284b8bc0d8aSopenharmony_ci exit(13); 285b8bc0d8aSopenharmony_ci } 286b8bc0d8aSopenharmony_ci exif_content_add_entry (data->ifd[EXIF_IFD_GPS], e); 287b8bc0d8aSopenharmony_ci exif_entry_initialize (e, EXIF_TAG_GPS_VERSION_ID); 288b8bc0d8aSopenharmony_ci e->format = EXIF_FORMAT_BYTE; 289b8bc0d8aSopenharmony_ci e->size = 4; 290b8bc0d8aSopenharmony_ci e->components = e->size; 291b8bc0d8aSopenharmony_ci /* Allocate memory to use for holding the tag data */ 292b8bc0d8aSopenharmony_ci e->data = exif_mem_alloc(mem, e->size); 293b8bc0d8aSopenharmony_ci if (!e->data) { 294b8bc0d8aSopenharmony_ci fprintf (stderr, "Out of memory\n"); 295b8bc0d8aSopenharmony_ci exit(13); 296b8bc0d8aSopenharmony_ci } 297b8bc0d8aSopenharmony_ci e->data[0] = 2; 298b8bc0d8aSopenharmony_ci e->data[1] = 2; 299b8bc0d8aSopenharmony_ci e->data[2] = 0; 300b8bc0d8aSopenharmony_ci e->data[3] = 0; 301b8bc0d8aSopenharmony_ci check_entry_trunc(e, 1); 302b8bc0d8aSopenharmony_ci exif_content_remove_entry (data->ifd[EXIF_IFD_GPS], e); 303b8bc0d8aSopenharmony_ci exif_entry_unref (e); 304b8bc0d8aSopenharmony_ci 305b8bc0d8aSopenharmony_ci /* EXIF_TAG_GPS_ALTITUDE_REF truncation tests */ 306b8bc0d8aSopenharmony_ci e = exif_entry_new_mem (mem); 307b8bc0d8aSopenharmony_ci if (!e) { 308b8bc0d8aSopenharmony_ci fprintf (stderr, "Out of memory\n"); 309b8bc0d8aSopenharmony_ci exit(13); 310b8bc0d8aSopenharmony_ci } 311b8bc0d8aSopenharmony_ci exif_content_add_entry (data->ifd[EXIF_IFD_GPS], e); 312b8bc0d8aSopenharmony_ci exif_entry_initialize (e, EXIF_TAG_GPS_ALTITUDE_REF); 313b8bc0d8aSopenharmony_ci e->format = EXIF_FORMAT_BYTE; 314b8bc0d8aSopenharmony_ci e->size = 1; 315b8bc0d8aSopenharmony_ci e->components = e->size; 316b8bc0d8aSopenharmony_ci /* Allocate memory to use for holding the tag data */ 317b8bc0d8aSopenharmony_ci e->data = exif_mem_alloc(mem, e->size); 318b8bc0d8aSopenharmony_ci if (!e->data) { 319b8bc0d8aSopenharmony_ci fprintf (stderr, "Out of memory\n"); 320b8bc0d8aSopenharmony_ci exit(13); 321b8bc0d8aSopenharmony_ci } 322b8bc0d8aSopenharmony_ci e->data[0] = 1; 323b8bc0d8aSopenharmony_ci check_entry_trunc(e, 1); 324b8bc0d8aSopenharmony_ci exif_content_remove_entry (data->ifd[EXIF_IFD_GPS], e); 325b8bc0d8aSopenharmony_ci exif_entry_unref (e); 326b8bc0d8aSopenharmony_ci 327b8bc0d8aSopenharmony_ci /* EXIF_TAG_GPS_TIME_STAMP truncation tests */ 328b8bc0d8aSopenharmony_ci e = exif_entry_new_mem (mem); 329b8bc0d8aSopenharmony_ci if (!e) { 330b8bc0d8aSopenharmony_ci fprintf (stderr, "Out of memory\n"); 331b8bc0d8aSopenharmony_ci exit(13); 332b8bc0d8aSopenharmony_ci } 333b8bc0d8aSopenharmony_ci exif_content_add_entry (data->ifd[EXIF_IFD_GPS], e); 334b8bc0d8aSopenharmony_ci exif_entry_initialize (e, EXIF_TAG_GPS_TIME_STAMP); 335b8bc0d8aSopenharmony_ci e->format = EXIF_FORMAT_RATIONAL; 336b8bc0d8aSopenharmony_ci e->components = 3; 337b8bc0d8aSopenharmony_ci e->size = e->components * exif_format_get_size(EXIF_FORMAT_RATIONAL); 338b8bc0d8aSopenharmony_ci /* Allocate memory to use for holding the tag data */ 339b8bc0d8aSopenharmony_ci e->data = exif_mem_alloc(mem, e->size); 340b8bc0d8aSopenharmony_ci if (!e->data) { 341b8bc0d8aSopenharmony_ci fprintf (stderr, "Out of memory\n"); 342b8bc0d8aSopenharmony_ci exit(13); 343b8bc0d8aSopenharmony_ci } 344b8bc0d8aSopenharmony_ci exif_set_rational(e->data, exif_data_get_byte_order (data), gpsh); 345b8bc0d8aSopenharmony_ci exif_set_rational(e->data+8, exif_data_get_byte_order (data), gpsm); 346b8bc0d8aSopenharmony_ci exif_set_rational(e->data+16, exif_data_get_byte_order (data), gpss); 347b8bc0d8aSopenharmony_ci check_entry_trunc(e, 1); 348b8bc0d8aSopenharmony_ci exif_content_remove_entry (data->ifd[EXIF_IFD_GPS], e); 349b8bc0d8aSopenharmony_ci exif_entry_unref (e); 350b8bc0d8aSopenharmony_ci 351b8bc0d8aSopenharmony_ci /* EXIF_TAG_SUBJECT_AREA truncation tests */ 352b8bc0d8aSopenharmony_ci e = exif_entry_new_mem (mem); 353b8bc0d8aSopenharmony_ci if (!e) { 354b8bc0d8aSopenharmony_ci fprintf (stderr, "Out of memory\n"); 355b8bc0d8aSopenharmony_ci exit(13); 356b8bc0d8aSopenharmony_ci } 357b8bc0d8aSopenharmony_ci exif_content_add_entry (data->ifd[EXIF_IFD_0], e); 358b8bc0d8aSopenharmony_ci exif_entry_initialize (e, EXIF_TAG_SUBJECT_AREA); 359b8bc0d8aSopenharmony_ci e->format = EXIF_FORMAT_SHORT; 360b8bc0d8aSopenharmony_ci /* This tags is interpreted differently depending on # components */ 361b8bc0d8aSopenharmony_ci /* Rectangle */ 362b8bc0d8aSopenharmony_ci e->components = 4; 363b8bc0d8aSopenharmony_ci e->size = e->components * exif_format_get_size(EXIF_FORMAT_SHORT); 364b8bc0d8aSopenharmony_ci /* Allocate memory to use for holding the tag data */ 365b8bc0d8aSopenharmony_ci e->data = exif_mem_alloc(mem, e->size); 366b8bc0d8aSopenharmony_ci if (!e->data) { 367b8bc0d8aSopenharmony_ci fprintf (stderr, "Out of memory\n"); 368b8bc0d8aSopenharmony_ci exit(13); 369b8bc0d8aSopenharmony_ci } 370b8bc0d8aSopenharmony_ci exif_set_short(e->data, exif_data_get_byte_order (data), 123); 371b8bc0d8aSopenharmony_ci exif_set_short(e->data+2, exif_data_get_byte_order (data), 456); 372b8bc0d8aSopenharmony_ci exif_set_short(e->data+4, exif_data_get_byte_order (data), 78); 373b8bc0d8aSopenharmony_ci exif_set_short(e->data+6, exif_data_get_byte_order (data), 90); 374b8bc0d8aSopenharmony_ci check_entry_trunc(e, 1); 375b8bc0d8aSopenharmony_ci /* Circle */ 376b8bc0d8aSopenharmony_ci e->components = 3; 377b8bc0d8aSopenharmony_ci e->size = e->components * exif_format_get_size(EXIF_FORMAT_SHORT); 378b8bc0d8aSopenharmony_ci check_entry_trunc(e, 1); 379b8bc0d8aSopenharmony_ci /* Centre */ 380b8bc0d8aSopenharmony_ci e->components = 2; 381b8bc0d8aSopenharmony_ci e->size = e->components * exif_format_get_size(EXIF_FORMAT_SHORT); 382b8bc0d8aSopenharmony_ci check_entry_trunc(e, 1); 383b8bc0d8aSopenharmony_ci /* Invalid */ 384b8bc0d8aSopenharmony_ci e->components = 1; 385b8bc0d8aSopenharmony_ci e->size = e->components * exif_format_get_size(EXIF_FORMAT_SHORT); 386b8bc0d8aSopenharmony_ci check_entry_trunc(e, 1); 387b8bc0d8aSopenharmony_ci exif_content_remove_entry (data->ifd[EXIF_IFD_0], e); 388b8bc0d8aSopenharmony_ci exif_entry_unref (e); 389b8bc0d8aSopenharmony_ci 390b8bc0d8aSopenharmony_ci exif_mem_unref(mem); 391b8bc0d8aSopenharmony_ci exif_data_unref (data); 392b8bc0d8aSopenharmony_ci 393b8bc0d8aSopenharmony_ci return 0; 394b8bc0d8aSopenharmony_ci} 395