From e03e5a53ff346e5c0de8999864e11ad757cd5833 Mon Sep 17 00:00:00 2001 From: Mike Date: Thu, 6 May 2021 19:38:47 +0200 Subject: [PATCH] split parser.spec.mjs into multiple tests inside test/formats/ & added avif test --- test/formats/avif.spec.mjs | 37 +++++++ test/formats/heic.spec.mjs | 69 +++++++++++++ test/formats/jpeg.spec.mjs | 52 ++++++++++ test/formats/parser.spec.mjs | 53 ++++++++++ test/{ => formats}/png.spec.mjs | 8 +- test/index.html | 7 +- test/parser.spec.mjs | 166 -------------------------------- 7 files changed, 220 insertions(+), 172 deletions(-) create mode 100644 test/formats/avif.spec.mjs create mode 100644 test/formats/heic.spec.mjs create mode 100644 test/formats/jpeg.spec.mjs create mode 100644 test/formats/parser.spec.mjs rename test/{ => formats}/png.spec.mjs (95%) delete mode 100644 test/parser.spec.mjs diff --git a/test/formats/avif.spec.mjs b/test/formats/avif.spec.mjs new file mode 100644 index 0000000..e69a696 --- /dev/null +++ b/test/formats/avif.spec.mjs @@ -0,0 +1,37 @@ +import {assert} from '../test-util-core.mjs' +import {getFile} from '../test-util-core.mjs' +import * as exifr from '../../src/bundles/full.mjs' + + +// TODO +describe('AVIF - AvifFileParser', () => { + + const options = {tiff: true, icc: true, mergeOutput: false, translateKeys: false, translateValues: false, reviveValues: false} + + const MAKE = 271 + const MODEL = 272 + const PROFILE = 36 + + it(`should extract TIFF from fixture1`, async () => { + let input = await getFile('avif/Irvine_CA.avif') + let output = await exifr.parse(input, options) + assert.exists(output.ifd0, 'output should contain IFD0') + assert.equal(output.ifd0[MAKE], 'Apple') + assert.equal(output.ifd0[MODEL], 'iPhone 3GS') + }) + + it(`should extract EXIF from fixture1`, async () => { + let input = await getFile('avif/Irvine_CA.avif') + let output = await exifr.parse(input, options) + assert.exists(output.exif, 'output should contain EXIF') + assert.isDefined(output.exif[36867]) + }) + + it(`should extract ICC from fixture2`, async () => { + let input = await getFile('avif/IMG_20180725_163423-micro.avif') + let output = await exifr.parse(input, options) + assert.exists(output.icc, 'output should contain ICC') + assert.equal(output.icc[PROFILE], 'acsp') + }) + +}) \ No newline at end of file diff --git a/test/formats/heic.spec.mjs b/test/formats/heic.spec.mjs new file mode 100644 index 0000000..841bb5d --- /dev/null +++ b/test/formats/heic.spec.mjs @@ -0,0 +1,69 @@ +import {assert} from '../test-util-core.mjs' +import {getFile} from '../test-util-core.mjs' +import * as exifr from '../../src/bundles/full.mjs' + + +describe('HEIC - HeicFileParser', () => { + + const options = {tiff: true, icc: true, mergeOutput: false, translateKeys: false, translateValues: false, reviveValues: false} + + const MAKE = 271 + const MODEL = 272 + + it(`should not find anything in fixture1`, async () => { + let input = await getFile('heic-single.heic') + let output = await exifr.parse(input, options) + assert.isUndefined(output, 'output should be undefined') + }) + + it(`should not find anything in fixture2`, async () => { + let input = await getFile('heic-collection.heic') + let output = await exifr.parse(input, options) + assert.isUndefined(output, 'output should be undefined') + }) + + it(`should extract TIFF & ICC from fixture3`, async () => { + let input = await getFile('heic-empty.heic') + let output = await exifr.parse(input, options) + assert.exists(output.ifd0, 'output should contain IFD0') + assert.exists(output.icc, 'output should contain ICC') + assert.equal(output.icc[16], 'RGB') // ColorSpaceData + }) + + it(`should extract TIFF & ICC from fixture4`, async () => { + let input = await getFile('heic-iphone.heic') + let output = await exifr.parse(input, options) + assert.exists(output.ifd0, 'output should contain IFD0') + assert.exists(output.exif, 'output should contain EXIF') + assert.exists(output.gps, 'output should contain GPS') + assert.exists(output.icc, 'output should contain ICC') + assert.equal(output.ifd0[MAKE], 'Apple') + assert.equal(output.ifd0[MODEL], 'iPhone XS Max') + }) + + it(`should extract TIFF & ICC from fixture5`, async () => { + let input = await getFile('heic-iphone7.heic') + let output = await exifr.parse(input, options) + assert.exists(output.ifd0, 'output should contain IFD0') + assert.exists(output.exif, 'output should contain EXIF') + assert.exists(output.gps, 'output should contain GPS') + assert.exists(output.icc, 'output should contain ICC') + }) + + it(`address of TIFF/EXIF from HEIC should align properly`, async () => { + let input = await getFile('heic-iphone7.heic') + let output = await exifr.parse(input, options) + assert.equal(output.ifd0[MAKE], 'Apple') + assert.equal(output.ifd0[MODEL], 'iPhone 7') + }) + + it(`address of ICC from HEIC should align properly`, async () => { + let input = await getFile('heic-iphone7.heic') + let output = await exifr.parse(input, options) + assert.equal(output.icc[4].toLowerCase(), 'appl') // ProfileCMMType + assert.equal(output.icc[16], 'RGB') // ColorSpaceData + assert.equal(output.icc[36], 'acsp') // ProfileFileSignature + assert.equal(output.icc[40].toLowerCase(), 'appl') // PrimaryPlatform + }) + +}) \ No newline at end of file diff --git a/test/formats/jpeg.spec.mjs b/test/formats/jpeg.spec.mjs new file mode 100644 index 0000000..9804c34 --- /dev/null +++ b/test/formats/jpeg.spec.mjs @@ -0,0 +1,52 @@ +import {assert} from '../test-util-core.mjs' +import {getFile} from '../test-util-core.mjs' +import {Exifr} from '../../src/bundles/full.mjs' + + +describe('JPEG - JpegFileParser', () => { + + describe('.findAppSegments()', () => { + + it(`finds APP segments existing in jpg file`, async () => { + let input = await getFile('IMG_20180725_163423.jpg') + let exr = new Exifr({tiff: true, xmp: true, jfif: true}) + await exr.read(input) + exr.setup() + let jpegFileParser = exr.fileParser + jpegFileParser.findAppSegments() + let jfifSegment = jpegFileParser.appSegments.find(segment => segment.type === 'jfif') + assert.isDefined(jfifSegment) + assert.equal(jfifSegment.offset, 25388) + assert.equal(jfifSegment.length, 18) + assert.equal(jfifSegment.start, 25397) + assert.equal(jfifSegment.size, 9) + assert.equal(jfifSegment.end, 25406) + let tiffSegment = jpegFileParser.appSegments.find(segment => segment.type === 'tiff') + assert.isDefined(tiffSegment) + }) + + it(`doesn't find segment not present in jpg file`, async () => { + let input = await getFile('IMG_20180725_163423.jpg') + let exr = new Exifr({tiff: true, xmp: true, jfif: true}) + await exr.read(input) + exr.setup() + let jpegFileParser = exr.fileParser + jpegFileParser.findAppSegments() + let xmpSegment = jpegFileParser.appSegments.find(segment => segment.type === 'xmp') + assert.isUndefined(xmpSegment) + }) + + it(`multisegment ICC - finds all segments`, async () => { + let input = await getFile('issue-metadata-extractor-65.jpg') + let exr = new Exifr(true) + await exr.read(input) + exr.setup() + let jpegFileParser = exr.fileParser + jpegFileParser.findAppSegments() + let iccSegments = jpegFileParser.appSegments.filter(segment => segment.type === 'icc') + assert.lengthOf(iccSegments, 9) + }) + + }) + +}) \ No newline at end of file diff --git a/test/formats/parser.spec.mjs b/test/formats/parser.spec.mjs new file mode 100644 index 0000000..31b23bc --- /dev/null +++ b/test/formats/parser.spec.mjs @@ -0,0 +1,53 @@ +import {assert} from '../test-util-core.mjs' +import {isBrowser, isNode, getPath, getFile} from '../test-util-core.mjs' +import {Exifr} from '../../src/bundles/full.mjs' +import * as exifr from '../../src/bundles/full.mjs' + + +describe('parser core', () => { + + describe(`throws if the input file isn't supported`, () => { + + it(`rejects random file 1`, async () => { + let input = await getFile('D65_XYZ.icc') + try { + await exifr.parse(input) + } catch(err) { + assert.instanceOf(err, Error) + assert.equal(err.message, 'Unknown file format') + } + }) + + it(`rejects random file 2`, async () => { + let input = await getFile('cookiezen.xmp') + try { + await exifr.parse(input) + } catch(err) { + assert.instanceOf(err, Error) + assert.equal(err.message, 'Unknown file format') + } + }) + + it(`accepts JPEG`, async () => { + await exifr.parse(await getFile('img_1771.jpg')) + }) + + it(`accepts TIFF`, async () => { + await exifr.parse(await getFile('issue-exif-js-124.tiff')) + }) + + it(`accepts HEIC`, async () => { + await exifr.parse(await getFile('heic-empty.heic')) + }) + + it(`accepts PNG`, async () => { + await exifr.parse(await getFile('png/IMG_20180725_163423-1.png')) + }) + + it(`accepts AVIF`, async () => { + await exifr.parse(await getFile('avif/Irvine_CA.avif')) + }) + + }) + +}) \ No newline at end of file diff --git a/test/png.spec.mjs b/test/formats/png.spec.mjs similarity index 95% rename from test/png.spec.mjs rename to test/formats/png.spec.mjs index e8c1998..821fdb8 100644 --- a/test/png.spec.mjs +++ b/test/formats/png.spec.mjs @@ -1,7 +1,7 @@ -import {assert, isNode} from './test-util-core.mjs' -import {getFile} from './test-util-core.mjs' -import * as exifr from '../src/bundles/full.mjs' -import {testSegment, testMergeSegment, testImage, testImageFull} from './test-util-suites.mjs' +import {assert, isNode} from '../test-util-core.mjs' +import {getFile} from '../test-util-core.mjs' +import * as exifr from '../../src/bundles/full.mjs' +import {testSegment, testMergeSegment, testImage, testImageFull} from '../test-util-suites.mjs' describe('PNG File format', () => { diff --git a/test/index.html b/test/index.html index 7d068a3..632118f 100644 --- a/test/index.html +++ b/test/index.html @@ -48,7 +48,11 @@ import './DynamicBufferView.spec.mjs' import './ChunkedReader.spec.mjs' import './reader.spec.mjs' - import './parser.spec.mjs' + import './formats/parser.spec.mjs' + import './formats/jpeg.spec.mjs' + import './formats/heic.spec.mjs' + import './formats/avif.spec.mjs' + import './formats/png.spec.mjs' import './options.spec.mjs' import './output-format.spec.mjs' import './highlevel-gps.spec.mjs' @@ -58,7 +62,6 @@ import './jfif.spec.mjs' import './icc.spec.mjs' import './iptc.spec.mjs' - import './png.spec.mjs' import './xmp-segment.spec.mjs' import './xmp-parser-synthetic.spec.mjs' import './xmp-parser-fixtures.spec.mjs' diff --git a/test/parser.spec.mjs b/test/parser.spec.mjs deleted file mode 100644 index bca3da4..0000000 --- a/test/parser.spec.mjs +++ /dev/null @@ -1,166 +0,0 @@ -import {assert} from './test-util-core.mjs' -import {isBrowser, isNode, getPath, getFile} from './test-util-core.mjs' -import {Exifr} from '../src/bundles/full.mjs' -import * as exifr from '../src/bundles/full.mjs' - - -describe('parser core', () => { - - describe(`throws if the input file isn't supported`, () => { - - it(`rejects random file 1`, async () => { - let input = await getFile('D65_XYZ.icc') - try { - await exifr.parse(input) - } catch(err) { - assert.instanceOf(err, Error) - assert.equal(err.message, 'Unknown file format') - } - }) - - it(`rejects random file 2`, async () => { - let input = await getFile('cookiezen.xmp') - try { - await exifr.parse(input) - } catch(err) { - assert.instanceOf(err, Error) - assert.equal(err.message, 'Unknown file format') - } - }) - - it(`accepts JPEG`, async () => { - await exifr.parse(await getFile('img_1771.jpg')) - }) - - it(`accepts TIFF`, async () => { - await exifr.parse(await getFile('issue-exif-js-124.tiff')) - }) - - it(`accepts HEIC`, async () => { - await exifr.parse(await getFile('heic-empty.heic')) - }) - - it(`accepts PNG`, async () => { - await exifr.parse(await getFile('png/IMG_20180725_163423-1.png')) - }) - - }) - -}) - -describe('JPEG - JpegFileParser', () => { - - describe('.findAppSegments()', () => { - - it(`finds APP segments existing in jpg file`, async () => { - let input = await getFile('IMG_20180725_163423.jpg') - let exr = new Exifr({tiff: true, xmp: true, jfif: true}) - await exr.read(input) - exr.setup() - let jpegFileParser = exr.fileParser - jpegFileParser.findAppSegments() - let jfifSegment = jpegFileParser.appSegments.find(segment => segment.type === 'jfif') - assert.isDefined(jfifSegment) - assert.equal(jfifSegment.offset, 25388) - assert.equal(jfifSegment.length, 18) - assert.equal(jfifSegment.start, 25397) - assert.equal(jfifSegment.size, 9) - assert.equal(jfifSegment.end, 25406) - let tiffSegment = jpegFileParser.appSegments.find(segment => segment.type === 'tiff') - assert.isDefined(tiffSegment) - }) - - it(`doesn't find segment not present in jpg file`, async () => { - let input = await getFile('IMG_20180725_163423.jpg') - let exr = new Exifr({tiff: true, xmp: true, jfif: true}) - await exr.read(input) - exr.setup() - let jpegFileParser = exr.fileParser - jpegFileParser.findAppSegments() - let xmpSegment = jpegFileParser.appSegments.find(segment => segment.type === 'xmp') - assert.isUndefined(xmpSegment) - }) - - it(`multisegment ICC - finds all segments`, async () => { - let input = await getFile('issue-metadata-extractor-65.jpg') - let exr = new Exifr(true) - await exr.read(input) - exr.setup() - let jpegFileParser = exr.fileParser - jpegFileParser.findAppSegments() - let iccSegments = jpegFileParser.appSegments.filter(segment => segment.type === 'icc') - assert.lengthOf(iccSegments, 9) - }) - - }) - -}) -/* -describe('TIFF - TiffFileParser', () => { -}) -*/ - -describe('HEIC - HeicFileParser', () => { - - const options = {tiff: true, icc: true, mergeOutput: false, translateKeys: false, translateValues: false, reviveValues: false} - - const MAKE = 271 - const MODEL = 272 - - it(`should not find anything in fixture1`, async () => { - let input = await getFile('heic-single.heic') - let output = await exifr.parse(input, options) - assert.isUndefined(output, 'output should be undefined') - }) - - it(`should not find anything in fixture2`, async () => { - let input = await getFile('heic-collection.heic') - let output = await exifr.parse(input, options) - assert.isUndefined(output, 'output should be undefined') - }) - - it(`should extract TIFF & ICC from fixture3`, async () => { - let input = await getFile('heic-empty.heic') - let output = await exifr.parse(input, options) - assert.exists(output.ifd0, 'output should contain IFD0') - assert.exists(output.icc, 'output should contain ICC') - assert.equal(output.icc[16], 'RGB') // ColorSpaceData - }) - - it(`should extract TIFF & ICC from fixture4`, async () => { - let input = await getFile('heic-iphone.heic') - let output = await exifr.parse(input, options) - assert.exists(output.ifd0, 'output should contain IFD0') - assert.exists(output.exif, 'output should contain EXIF') - assert.exists(output.gps, 'output should contain GPS') - assert.exists(output.icc, 'output should contain ICC') - assert.equal(output.ifd0[MAKE], 'Apple') - assert.equal(output.ifd0[MODEL], 'iPhone XS Max') - }) - - it(`should extract TIFF & ICC from fixture5`, async () => { - let input = await getFile('heic-iphone7.heic') - let output = await exifr.parse(input, options) - assert.exists(output.ifd0, 'output should contain IFD0') - assert.exists(output.exif, 'output should contain EXIF') - assert.exists(output.gps, 'output should contain GPS') - assert.exists(output.icc, 'output should contain ICC') - }) - - it(`address of TIFF/EXIF from HEIC should align properly`, async () => { - let input = await getFile('heic-iphone7.heic') - let output = await exifr.parse(input, options) - assert.equal(output.ifd0[MAKE], 'Apple') - assert.equal(output.ifd0[MODEL], 'iPhone 7') - }) - - it(`address of ICC from HEIC should align properly`, async () => { - let input = await getFile('heic-iphone7.heic') - let output = await exifr.parse(input, options) - assert.equal(output.icc[4].toLowerCase(), 'appl') // ProfileCMMType - assert.equal(output.icc[16], 'RGB') // ColorSpaceData - assert.equal(output.icc[36], 'acsp') // ProfileFileSignature - assert.equal(output.icc[40].toLowerCase(), 'appl') // PrimaryPlatform - }) - -}) \ No newline at end of file