Skip to content

Commit

Permalink
split parser.spec.mjs into multiple tests inside test/formats/ & adde…
Browse files Browse the repository at this point in the history
…d avif test
  • Loading branch information
MikeKovarik committed May 6, 2021
1 parent fc553a9 commit e03e5a5
Show file tree
Hide file tree
Showing 7 changed files with 220 additions and 172 deletions.
37 changes: 37 additions & 0 deletions test/formats/avif.spec.mjs
Original file line number Diff line number Diff line change
@@ -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')
})

})
69 changes: 69 additions & 0 deletions test/formats/heic.spec.mjs
Original file line number Diff line number Diff line change
@@ -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
})

})
52 changes: 52 additions & 0 deletions test/formats/jpeg.spec.mjs
Original file line number Diff line number Diff line change
@@ -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)
})

})

})
53 changes: 53 additions & 0 deletions test/formats/parser.spec.mjs
Original file line number Diff line number Diff line change
@@ -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'))
})

})

})
8 changes: 4 additions & 4 deletions test/png.spec.mjs → test/formats/png.spec.mjs
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
7 changes: 5 additions & 2 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand Down
Loading

0 comments on commit e03e5a5

Please sign in to comment.