1#!/bin/sh 2# Compares the parsed EXIF data extracted from test images with the parsed EXIF 3# data in the original images. This tests that the tag parsing and writing 4# round-trip produces an EXIF structure with the same meaning as the original. 5# 6# Copyright (C) 2019-2021 Dan Fandrich <dan@coneharvesters.com>, et. al. 7# SPDX-License-Identifier: LGPL-2.0-or-later 8 9srcdir="${srcdir:-.}" 10TMPORIGINAL="$(mktemp)" 11TMPEXTRACTED="$(mktemp)" 12TMPDATA="$(mktemp)" 13trap 'rm -f "${TMPORIGINAL}" "${TMPEXTRACTED}" "${TMPDATA}"' 0 14 15# Remove the file name, which is a harmless difference between the two outputs. 16# Also delete the size of the MakerNote. Since the MakerNote is parsed 17# internally and rewritten, it can sometimes have slightly different padding 18# and therefore slightly different size, which is a semantically meaningless 19# difference. 20# FIXME: Not all MakerNote differences are harmless. For example, 21# olympus_makernote_variant_4.jpg has a huge size difference, probably because 22# of a parsing bug in libexif. This should be investigated. Ideally, this would 23# ignore small differences in size but trigger on larger differences. 24parse_canonicalize () { 25 sed \ 26 -e '/^File /d' \ 27 -e '/MakerNote (Undefined)$/{N;N;d}' 28} 29 30. ${srcdir}/inc-comparetool.sh 31 32# Ensure that names are untranslated 33LANG= 34LANGUAGE= 35LC_ALL=C 36export LANG LANGUAGE LC_ALL 37for fn in "${srcdir}"/testdata/*.jpg ; do 38 ./test-parse$EXEEXT "${fn}" | tr -d '\015' | parse_canonicalize > "${TMPORIGINAL}" 39 ./test-extract$EXEEXT -o "${TMPDATA}" "${fn}" 40 ./test-parse$EXEEXT "${TMPDATA}" | tr -d '\015' | parse_canonicalize > "${TMPEXTRACTED}" 41 if ${comparetool} "${TMPORIGINAL}" "${TMPEXTRACTED}"; then 42 : "no differences detected" 43 else 44 echo Error parsing "$fn" 45 exit 1 46 fi 47done 48 49for fn in "${srcdir}"/testdata/*.jpg ; do 50 ./test-parse$EXEEXT "${fn}" | tr -d '\015' | parse_canonicalize > "${TMPORIGINAL}" 51 ./test-parse-from-data$EXEEXT "${fn}" | tr -d '\015' | parse_canonicalize > "${TMPEXTRACTED}" 52 if ${comparetool} "${TMPORIGINAL}" "${TMPEXTRACTED}"; then 53 echo "no differences detected" 54 else 55 echo "ERROR: Difference between test-parse and test-parse-from-data for $fn !" 56 exit 1 57 fi 58done 59