(sort of bug 32410) Fix EXIF GPSAltitude calculation when below sea level.
[lhc/web/wiklou.git] / tests / phpunit / includes / media / JpegMetadataExtractorTest.php
index 99c4384..f48382a 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-/*
+/**
  * @todo Could use a test of extended XMP segments. Hard to find programs that
  * create example files, and creating my own in vim propbably wouldn't
  * serve as a very good "test". (Adobe photoshop probably creates such files
@@ -12,10 +12,25 @@ class JpegMetadataExtractorTest extends MediaWikiTestCase {
                $this->filePath = dirname( __FILE__ ) . '/../../data/media/';
        }
 
-       public function testUtf8Comment() {
-               $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-comment-utf.jpg' );
+       /**
+        * We also use this test to test padding bytes don't
+        * screw stuff up
+        *
+        * @param $file filename
+        *
+        * @dataProvider dataUtf8Comment
+        */
+       public function testUtf8Comment( $file ) {
+               $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . $file );
                $this->assertEquals( array( 'UTF-8 JPEG Comment — ¼' ), $res['COM'] );
        }
+       public function dataUtf8Comment() {
+               return array(
+                       array( 'jpeg-comment-utf.jpg' ),
+                       array( 'jpeg-padding-even.jpg' ),
+                       array( 'jpeg-padding-odd.jpg' ),
+               );
+       }
        /** 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' );
@@ -44,7 +59,7 @@ class JpegMetadataExtractorTest extends MediaWikiTestCase {
        public function testPSIRExtraction() {
                $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-xmp-psir.jpg' );
                $expected = '50686f746f73686f7020332e30003842494d04040000000000181c02190004746573741c02190003666f6f1c020000020004';
-               $this->assertEquals( $expected, bin2hex( $res['PSIR'] ) );
+               $this->assertEquals( $expected, bin2hex( $res['PSIR'][0] ) );
        }
        public function testXMPExtractionAltAppId() {
                $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-xmp-alt.jpg' );
@@ -55,19 +70,19 @@ class JpegMetadataExtractorTest extends MediaWikiTestCase {
 
        public function testIPTCHashComparisionNoHash() {
                $segments = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-xmp-psir.jpg' );
-               $res = JpegMetadataExtractor::doPSIR( $segments['PSIR'] );
+               $res = JpegMetadataExtractor::doPSIR( $segments['PSIR'][0] );
 
                $this->assertEquals( 'iptc-no-hash', $res );
        }
        public function testIPTCHashComparisionBadHash() {
                $segments = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-iptc-bad-hash.jpg' );
-               $res = JpegMetadataExtractor::doPSIR( $segments['PSIR'] );
+               $res = JpegMetadataExtractor::doPSIR( $segments['PSIR'][0] );
 
                $this->assertEquals( 'iptc-bad-hash', $res );
        }
        public function testIPTCHashComparisionGoodHash() {
                $segments = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-iptc-good-hash.jpg' );
-               $res = JpegMetadataExtractor::doPSIR( $segments['PSIR'] );
+               $res = JpegMetadataExtractor::doPSIR( $segments['PSIR'][0] );
 
                $this->assertEquals( 'iptc-good-hash', $res );
        }