X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Flsolesen%2Fpel%2Fscripts%2Fmake-image-test.php;fp=vendor%2Flsolesen%2Fpel%2Fscripts%2Fmake-image-test.php;h=96e784b9b080ed6e0ba9c8127264971e8913f1e0;hp=0000000000000000000000000000000000000000;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hpb=74df008bdbb3a11eeea356744f39b802369bda3c diff --git a/vendor/lsolesen/pel/scripts/make-image-test.php b/vendor/lsolesen/pel/scripts/make-image-test.php new file mode 100644 index 000000000..96e784b9b --- /dev/null +++ b/vendor/lsolesen/pel/scripts/make-image-test.php @@ -0,0 +1,250 @@ +#!/usr/bin/php +\n"); +} + +$basename = substr($argv[1], 0, - strlen(strrchr($argv[1], '.'))); +$image_filename = $argv[1]; +$thumb_filename = $basename . '-thumb.jpg'; +$test_filename = $basename . '.php'; +$test_name = str_replace('-', '_', $basename); + +$indent = 0; + +function println($args) +{ + global $indent; + $args = func_get_args(); + $str = array_shift($args); + vprintf(str_repeat(' ', $indent) . $str . "\n", $args); +} + +function quote($str) +{ + return str_replace(array( + '\\', + '\'' + ), array( + '\\\\', + '\\\'' + ), $str); +} + +function entryToTest($name, PelEntry $entry) +{ + println('$this->assertInstanceOf(\'%s\', %s);', $name, get_class($entry)); + + println('$this->assertEquals(%s->getValue(), %s);', $name, var_export($entry->getValue(), true)); + + println('$this->assertEquals(%s->getText(), \'%s\');', $name, quote($entry->getText())); +} + +function ifdToTest($name, $number, PelIfd $ifd) +{ + println(); + println('/* Start of IDF %s%d. */', $name, $number); + + $entries = $ifd->getEntries(); + println('$this->assertEquals(count(%s%d->getEntries()), %d);', $name, $number, count($entries)); + + foreach ($entries as $tag => $entry) { + println(); + println('$entry = %s%d->getEntry(%d); // %s', $name, $number, $tag, PelTag::getName($ifd->getType(), $tag)); + entryToTest('$entry', $entry); + } + + println(); + println('/* Sub IFDs of %s%d. */', $name, $number); + + $sub_ifds = $ifd->getSubIfds(); + println('$this->assertEquals(count(%s%d->getSubIfds()), %d);', $name, $number, count($sub_ifds)); + + $n = 0; + $sub_name = $name . $number . '_'; + foreach ($sub_ifds as $type => $sub_ifd) { + println('%s%d = %s%d->getSubIfd(%d); // IFD %s', $sub_name, $n, $name, $number, $type, $sub_ifd->getName()); + println('$this->assertInstanceOf(\'PelIfd\', %s%d);', $sub_name, $n); + ifdToTest($sub_name, $n, $sub_ifd); + $n ++; + } + + println(); + + if (strlen($ifd->getThumbnailData()) > 0) { + println('$thumb_data = file_get_contents(dirname(__FILE__) .'); + println(' \'/%s\');', $GLOBALS['thumb_filename']); + println('$this->assertEquals(%s%d->getThumbnailData(), $thumb_data);', $name, $number); + } else { + println('$this->assertEquals(%s%d->getThumbnailData(), \'\');', $name, $number); + } + + println(); + println('/* Next IFD. */'); + + $next = $ifd->getNextIfd(); + println('%s%d = %s%d->getNextIfd();', $name, $number + 1, $name, $number); + + if ($next instanceof PelIfd) { + println('$this->assertInstanceOf(\'PelIfd\', %s%d);', $name, $number + 1); + println('/* End of IFD %s%d. */', $name, $number); + + ifdToTest($name, $number + 1, $next); + } else { + println('$this->assertNull(%s%d);', $name, $number + 1); + println('/* End of IFD %s%d. */', $name, $number); + } +} + +function tiffToTest($name, PelTiff $tiff) +{ + println(); + println('/* The first IFD. */'); + println('$ifd0 = %s->getIfd();', $name); + $ifd = $tiff->getIfd(); + if ($ifd instanceof PelIfd) { + println('$this->assertInstanceOf(\'PelIfd\', $ifd0);'); + ifdToTest('$ifd', 0, $ifd); + } else { + println('$this->assertNull($ifd0);'); + } +} + +function jpegContentToTest($name, PelJpegContent $content) +{ + if ($content instanceof PelExif) { + println('$this->assertInstanceOf(\'PelExif\', %s);', $name); + $tiff = $content->getTiff(); + println(); + println('$tiff = %s->getTiff();', $name); + if ($tiff instanceof PelTiff) { + println('$this->assertInstanceOf(\'PelTiff\', $tiff);'); + tiffToTest('$tiff', $tiff); + } + } +} + +function jpegToTest($name, PelJpeg $jpeg) +{ + $exif = $jpeg->getExif(); + println('$exif = %s->getExif();', $name); + if ($exif == null) { + println('$this->assertNull($exif);'); + } else { + jpegContentToTest('$exif', $exif); + } +} + +/** + * convert a binary string to a sequence of hexadecimals + */ +function binstrencode($field) +{ + $field = bin2hex($field); + $field = chunk_split($field, 2, "\\x"); + return str_replace('\x00', '\0', "\\x" . substr($field, 0, - 2)); +} + +/* + * All output is buffered so that we can dump it in $test_filename at + * the end. + */ +ob_start(); + +println('assertTrue(count(Pel::getExceptions()) == 0);'); +} else { + println('$exceptions = Pel::getExceptions();'); + for ($i = 0; $i < count($exceptions); $i ++) { + println('$this->assertInstanceOf(\'%s\', $exceptions[%d]);', $i, get_class($exceptions[$i])); + + println('$this->assertEquals($exceptions[%d]->getMessage(),', $i); + println(' \'%s\');', quote($exceptions[$i]->getMessage())); + } +} + +println(' + } +} +'); + +/* The test case is finished -- now dump the output as a PHP file. */ +file_put_contents($test_filename, ob_get_clean());