From c0e419ce5e847fc5adc4a4e336a54f69d535ac93 Mon Sep 17 00:00:00 2001 From: Brian Wolff Date: Thu, 18 Aug 2011 05:45:04 +0000 Subject: [PATCH] follow-up r86169: unit tests for extraction of JPEG comment (COM) segments. --- tests/phpunit/data/media/README | 3 +- .../data/media/jpeg-comment-binary.jpg | Bin 0 -> 448 bytes .../data/media/jpeg-comment-iso8859-1.jpg | Bin 0 -> 447 bytes .../data/media/jpeg-comment-multiple.jpg | Bin 0 -> 431 bytes tests/phpunit/data/media/jpeg-comment-utf.jpg | Bin 0 -> 445 bytes .../media/BitmapMetadataHandlerTest.php | 15 ++++++++ .../media/JpegMetadataExtractorTest.php | 32 ++++++++++++++++++ 7 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 tests/phpunit/data/media/jpeg-comment-binary.jpg create mode 100644 tests/phpunit/data/media/jpeg-comment-iso8859-1.jpg create mode 100644 tests/phpunit/data/media/jpeg-comment-multiple.jpg create mode 100644 tests/phpunit/data/media/jpeg-comment-utf.jpg create mode 100644 tests/phpunit/includes/media/JpegMetadataExtractorTest.php 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 0000000000000000000000000000000000000000..b467fe43c6d5b0c701870edc1b1001d0505deb7c GIT binary patch literal 448 zcmex=8lgi%9V+tSFgz|OAV&D_?xZ%79J4=@OFFmN$w zFf%GKFbOg;3o`yc!XUxGzzp;YGGJt3Wd_P93otM-F)^|rq#2o*1sQ}CS%eK8l>#TS z8UYoFpy>sg0}>TPH4!9wi-Cuk5oj;a2z!Q0|C-)knzHNWg@~`8B-Q@96z@!M+0?=# z(!Bon$C@hnoy$TDmN9hiD>TXYzDYYr)mBR*7vA^8arF0H}$z A*8l(j literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..d9ffbac1db64318688249264190b569420e7b498 GIT binary patch literal 447 zcmex=jKe5@ci+Wc+`GL4tvS8R!*cz{tYN43tq8U|?cmVq`%`Gcqv?G6*TM2pc*o1x{o& z0xA+g(+e~QBr1q%B1rTW0}nGJ&|aVs_6(Q)HNC$yW!KFM5nn$^s{M5--kIRCsf91*w`%k#G{dKtR5@Mq_O)~2>jjzFg?1$G;(65Ax?|K9`vWALAHDqg~+=Mht*V`K~+Eso(CY$offv@jPa)0un&(BZVm%i41yF7pU gqL-m-3x9SlXl-iiz{+1fl~_3d3V7M)+x+`8}o z!Sjz^e*N)v%J%>N|G)cx`@`2aAVU~6w6!gbEDP-H3f|0Zo%@Dl@c#gVAO`~%g9bCB z5(ASUBeNjm|04_%3=GUbk01j^7FK4UjIsa&6B8373qqQaiCK_ANRdU@&`~LHBC8Ql zkqDYzpgAB>K~xh#qPG}$m>Gfg0*$a|xb&~-{iP|pZeED^`bkpluS@aH1eZ-MJR;5O ze}Am0lHa*3#9$di_r5}tjPIMYb2M)3mJmF9ck<%id2Vh(8m8;*4H)ezzaNuL`Q*UY x_a?bN`OxR*C+$mLYrkEdzkSim(6xm>I~TMzwRLg?I$bHS+hCR0CL#a-CIGfmwhI6N literal 0 HcmV?d00001 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'] ); + } +} -- 2.20.1