From: Brian Wolff Date: Thu, 18 Aug 2011 05:45:04 +0000 (+0000) Subject: follow-up r86169: unit tests for extraction of JPEG comment (COM) segments. X-Git-Tag: 1.31.0-rc.0~28192 X-Git-Url: http://git.cyclocoop.org/%24self?a=commitdiff_plain;h=c0e419ce5e847fc5adc4a4e336a54f69d535ac93;p=lhc%2Fweb%2Fwiklou.git follow-up r86169: unit tests for extraction of JPEG comment (COM) segments. --- diff --git a/tests/phpunit/data/media/README b/tests/phpunit/data/media/README index 224db9acc4..864e9ff48b 100644 --- a/tests/phpunit/data/media/README +++ b/tests/phpunit/data/media/README @@ -21,7 +21,8 @@ TastyCakes on English Wikipedia greyscale-na-png.png, rgb-png.png, Xmp-exif-multilingual_test.jpg greyscale-png.png, 1bit-png.png, Png-native-test.png, rgb-na-png.png, -test.tiff, test.jpg +test.tiff, test.jpg, jpeg-comment-multiple.jpg, jpeg-comment-utf.jpg, +jpeg-comment-iso8859-1.jpg, jpeg-comment-binary.jpg Are all by Bawolff. I don't think they contain enough originality to claim copyright, but on the off chance they do, feel free to use them however you feel fit, without restriction. diff --git a/tests/phpunit/data/media/jpeg-comment-binary.jpg b/tests/phpunit/data/media/jpeg-comment-binary.jpg new file mode 100644 index 0000000000..b467fe43c6 Binary files /dev/null and b/tests/phpunit/data/media/jpeg-comment-binary.jpg differ diff --git a/tests/phpunit/data/media/jpeg-comment-iso8859-1.jpg b/tests/phpunit/data/media/jpeg-comment-iso8859-1.jpg new file mode 100644 index 0000000000..d9ffbac1db Binary files /dev/null and b/tests/phpunit/data/media/jpeg-comment-iso8859-1.jpg differ diff --git a/tests/phpunit/data/media/jpeg-comment-multiple.jpg b/tests/phpunit/data/media/jpeg-comment-multiple.jpg new file mode 100644 index 0000000000..363c738513 Binary files /dev/null and b/tests/phpunit/data/media/jpeg-comment-multiple.jpg differ diff --git a/tests/phpunit/data/media/jpeg-comment-utf.jpg b/tests/phpunit/data/media/jpeg-comment-utf.jpg new file mode 100644 index 0000000000..d6d35b4bee Binary files /dev/null and b/tests/phpunit/data/media/jpeg-comment-utf.jpg differ diff --git a/tests/phpunit/includes/media/BitmapMetadataHandlerTest.php b/tests/phpunit/includes/media/BitmapMetadataHandlerTest.php index a587bbe54b..148b90ac09 100644 --- a/tests/phpunit/includes/media/BitmapMetadataHandlerTest.php +++ b/tests/phpunit/includes/media/BitmapMetadataHandlerTest.php @@ -32,4 +32,19 @@ class BitmapMetadataHandlerTest extends MediaWikiTestCase { $this->assertEquals( $expected, $meta['ImageDescription'] ); } + + /** + * Test for jpeg comments are being handled by + * BitmapMetadataHandler correctly. + * + * There's more extensive tests of comment extraction in + * JpegMetadataExtractorTests.php + */ + public function testJpegComment() { + $meta = BitmapMetadataHandler::Jpeg( $this->filePath . + 'jpeg-comment-utf.jpg' ); + + $this->assertEquals( 'UTF-8 JPEG Comment — ¼', + $meta['JPEGFileComment'][0] ); + } } diff --git a/tests/phpunit/includes/media/JpegMetadataExtractorTest.php b/tests/phpunit/includes/media/JpegMetadataExtractorTest.php new file mode 100644 index 0000000000..cc57925622 --- /dev/null +++ b/tests/phpunit/includes/media/JpegMetadataExtractorTest.php @@ -0,0 +1,32 @@ +filePath = dirname( __FILE__ ) . '/../../data/media/'; + } + + public function testUtf8Comment() { + $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-comment-utf.jpg' ); + $this->assertEquals( array( 'UTF-8 JPEG Comment — ¼' ), $res['COM'] ); + } + /** The file is iso-8859-1, but it should get auto converted */ + public function testIso88591Comment() { + $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-comment-iso8859-1.jpg' ); + $this->assertEquals( array( 'ISO-8859-1 JPEG Comment - ¼' ), $res['COM'] ); + } + /** Comment values that are non-textual (random binary junk) should not be shown. + * The example test file has a comment with a 0x5 byte in it which is a control character + * and considered binary junk for our purposes. + */ + public function testBinaryCommentStripped() { + $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-comment-binary.jpg' ); + $this->assertEmpty( $res['COM'] ); + } + /* Very rarely a file can have multiple comments. + * Order of comments is based on order inside the file. + */ + public function testMultipleComment() { + $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-comment-multiple.jpg' ); + $this->assertEquals( array( 'foo', 'bar' ), $res['COM'] ); + } +}