-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LDEV-5284 testcase for ImageWrite metadata
- Loading branch information
Showing
1 changed file
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
component extends="org.lucee.cfml.test.LuceeTestCase" labels="image" { | ||
|
||
function beforeAll(){ | ||
variables.srcImage = expandPath( getDirectoryFromPath( getCurrentTemplatePath() ) & "images/IPTC-GoogleImgSrcPmd_testimg01.jpg"); | ||
variables.metaDataFormats = [ "jpg", "tiff", "png", "webp" ]; | ||
} | ||
|
||
function run( testResults, testBox ){ | ||
describe(title="ImageWrite Function", body=function() { | ||
it("should write an image to a file", function() { | ||
var imagePath = getTempFile( getTempDirectory(), "imageWrite", "jpg" ); | ||
var img = imageNew("",200,200,"rgb","red"); | ||
|
||
imageWrite(img, imagePath); | ||
|
||
expect(fileExists(imagePath)).toBeTrue(); | ||
|
||
var writtenImg = imageRead(imagePath); | ||
expect(imageGetWidth(writtenImg)).toBe(200); | ||
expect(imageGetHeight(writtenImg)).toBe(200); | ||
|
||
fileDelete(imagePath); | ||
}); | ||
}); | ||
|
||
describe(title="ImageWrite Function - metadata", skip=true, body=function() { | ||
it("should write an image to a file, no metadata=true EXIF", function() { | ||
checkMeta( metaType="EXIF", noMeta=true ); | ||
}); | ||
|
||
it("should write an image to a file, no metadata=true IPTC", function() { | ||
checkMeta( metaType="IPTC", noMeta=true ); | ||
}); | ||
|
||
it("should write an image to a file, no metadata=false EXIF", function() { | ||
checkMeta( metaType="EXIF", noMeta=false ); | ||
}); | ||
|
||
it("should write an image to a file, no metadata=false IPTC", function() { | ||
checkMeta( metaType="IPTC", noMeta=false ); | ||
}); | ||
}); | ||
} | ||
|
||
private function checkMeta( metaType, noMeta ) { | ||
loop array="#metaDataFormats#" item="local.format" { | ||
checkMetaByFormat(format, metaType, noMeta); | ||
} | ||
} | ||
|
||
private function checkMetaByFormat( format, metaType, noMeta ) { | ||
var imagePath = getTempFile( getTempDirectory(), "imageWrite", format ); | ||
var img = imageRead( variables.srcImage ); | ||
|
||
imageWrite(image=img, destination=imagePath, noMetaData=arguments.noMeta); | ||
expect(fileExists(imagePath)).toBeTrue(); | ||
|
||
if (metaType eq "IPTC"){ | ||
var src = ImageGetIPTCMetadata( variables.srcImage ); | ||
var dest = ImageGetIPTCMetadata( imagePath ); | ||
|
||
} else if (metaType eq "EXIF"){ | ||
var src = ImageGetEXIFMetadata( variables.srcImage ); | ||
var dest = ImageGetEXIFMetadata( imagePath ); | ||
} else { | ||
throw "unsupported metadata type [#metaType#]" | ||
} | ||
|
||
if (arguments.noMeta){ | ||
expect ( dest ).toHaveLength( 0, format & " had #len(dest)# items of metadata"); | ||
} else { | ||
expect ( len( dest ) ).toBeGTE( 0, format ); // TODO some are lost? | ||
//expect ( dest ).toHaveLength( len( src ), format ); | ||
} | ||
|
||
fileDelete(imagePath); | ||
} | ||
|
||
} |