• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
5srcdir="${srcdir:-.}"
6TMPORIGINAL="$(mktemp)"
7TMPEXTRACTED="$(mktemp)"
8TMPDATA="$(mktemp)"
9trap 'rm -f "${TMPORIGINAL}" "${TMPEXTRACTED}" "${TMPDATA}"' 0
10
11# Remove the file name, which is a harmless difference between the two outputs.
12# Also delete the size of the MakerNote. Since the MakerNote is parsed
13# internally and rewritten, it can sometimes have slightly different padding
14# and therefore slightly different size, which is a semantically meaningless
15# difference.
16# FIXME: Not all MakerNote differences are harmless. For example,
17# olympus_makernote_variant_4.jpg has a huge size difference, probably because
18# of a parsing bug in libexif. This should be investigated. Ideally, this would
19# ignore small differences in size but trigger on larger differences.
20parse_canonicalize () {
21    sed \
22        -e '/^File /d' \
23        -e '/MakerNote (Undefined)$/{N;N;d}'
24}
25
26. ${srcdir}/inc-comparetool.sh
27
28# Ensure that names are untranslated
29LANG=
30LANGUAGE=
31LC_ALL=C
32export LANG LANGUAGE LC_ALL
33for fn in "${srcdir}"/testdata/*.jpg ; do
34    ./test-parse$EXEEXT "${fn}" | tr -d '\015' | parse_canonicalize > "${TMPORIGINAL}"
35    ./test-extract$EXEEXT -o "${TMPDATA}" "${fn}"
36    ./test-parse$EXEEXT "${TMPDATA}" | tr -d '\015' | parse_canonicalize > "${TMPEXTRACTED}"
37    if ${comparetool} "${TMPORIGINAL}" "${TMPEXTRACTED}"; then
38	: "no differences detected"
39    else
40        echo Error parsing "$fn"
41        exit 1
42    fi
43done
44
45for fn in "${srcdir}"/testdata/*.jpg ; do
46    ./test-parse$EXEEXT           "${fn}" | tr -d '\015' | parse_canonicalize > "${TMPORIGINAL}"
47    ./test-parse-from-data$EXEEXT "${fn}" | tr -d '\015' | parse_canonicalize > "${TMPEXTRACTED}"
48    if ${comparetool} "${TMPORIGINAL}" "${TMPEXTRACTED}"; then
49	echo "no differences detected"
50    else
51        echo "ERROR: Difference between test-parse and test-parse-from-data for $fn !"
52        exit 1
53    fi
54done
55