Author: Tobias Schlitt Date: 2007-02-21 13:04:07 +0100 (Wed, 21 Feb 2007) New Revision: 4675
Log: - Added missing value checks for filters. - Switched deletion of test directories on again. Modified: trunk/ImageConversion/src/handlers/imagemagick.php trunk/ImageConversion/tests/filtersshell_test.php trunk/ImageConversion/tests/test_case.php Modified: trunk/ImageConversion/src/handlers/imagemagick.php =================================================================== --- trunk/ImageConversion/src/handlers/imagemagick.php 2007-02-21 11:31:45 UTC (rev 4674) +++ trunk/ImageConversion/src/handlers/imagemagick.php 2007-02-21 12:04:07 UTC (rev 4675) @@ -464,6 +464,10 @@ { break; } + if ( !is_int( $colorVal ) || $colorVal < 0 || $colorVal > 255 ) + { + throw new ezcBaseValueException( "color[$id]", $color[$id], 'int > 0 and < 256' ); + } $colorString .= sprintf( '%02x', $colorVal ); } $this->addFilterOption( @@ -612,6 +616,14 @@ */ public function croppedThumbnail( $width, $height ) { + if ( !is_int( $width ) || $width < 1 ) + { + throw new ezcBaseValueException( 'width', $width, 'int > 0' ); + } + if ( !is_int( $height ) || $height < 1 ) + { + throw new ezcBaseValueException( 'height', $height, 'int > 0' ); + } $data = getimagesize( $this->getReferenceData( $this->getActiveReference(), "resource" ) ); $scaleRatio = max( $width / $data[0], $height / $data[1] ); @@ -657,6 +669,14 @@ */ public function filledThumbnail( $width, $height, $color = array() ) { + if ( !is_int( $width ) || $width < 1 ) + { + throw new ezcBaseValueException( 'width', $width, 'int > 0' ); + } + if ( !is_int( $height ) || $height < 1 ) + { + throw new ezcBaseValueException( 'height', $height, 'int > 0' ); + } $data = getimagesize( $this->getReferenceData( $this->getActiveReference(), "resource" ) ); $scaleRatio = min( $width / $data[0], $height / $data[1] ); @@ -674,6 +694,10 @@ { break; } + if ( !is_int( $colorVal ) || $colorVal < 0 || $colorVal > 255 ) + { + throw new ezcBaseValueException( "color[$id]", $color[$id], 'int > 0 and < 256' ); + } $colorString .= sprintf( '%02x', $colorVal ); } Modified: trunk/ImageConversion/tests/filtersshell_test.php =================================================================== --- trunk/ImageConversion/tests/filtersshell_test.php 2007-02-21 11:31:45 UTC (rev 4674) +++ trunk/ImageConversion/tests/filtersshell_test.php 2007-02-21 12:04:07 UTC (rev 4675) @@ -540,6 +540,24 @@ ezcImageConversionTestCase::DEFAULT_SIMILARITY_GAP ); } + + public function testBorderFailures() + { + try + { + $this->handler->border( false, array( 255, 0, 0 ) ); + $this->fail( "Border filter accepted incorrect value." ); + } + catch ( ezcBaseValueException $e ) + {} + try + { + $this->handler->border( 10, array( 255, false, 0 ) ); + $this->fail( "Border filter accepted incorrect value." ); + } + catch ( ezcBaseValueException $e ) + {} + } public function testWatermarkAbsoluteNoScale() { @@ -613,6 +631,38 @@ ); } + public function testCroppedThumbnailFailures() + { + try + { + $this->handler->croppedThumbnail( -10, 50 ); + $this->fail( "CroppedThumbnail filter accepted incorrect value." ); + } + catch ( ezcBaseValueException $e ) + {} + try + { + $this->handler->croppedThumbnail( "foo", 50 ); + $this->fail( "CroppedThumbnail filter accepted incorrect value." ); + } + catch ( ezcBaseValueException $e ) + {} + try + { + $this->handler->croppedThumbnail( 50, -10 ); + $this->fail( "CroppedThumbnail filter accepted incorrect value." ); + } + catch ( ezcBaseValueException $e ) + {} + try + { + $this->handler->croppedThumbnail( 50, false ); + $this->fail( "CroppedThumbnail filter accepted incorrect value." ); + } + catch ( ezcBaseValueException $e ) + {} + } + public function testFillThumbnailVertical() { $this->handler->filledThumbnail( 50, 50, array( 255, 0, 0 ) ); @@ -636,5 +686,51 @@ ezcImageConversionTestCase::DEFAULT_SIMILARITY_GAP ); } + + public function testFilledThumbnailFailures() + { + try + { + $this->handler->filledThumbnail( -10, 50, array( 255, 0, 0 ) ); + $this->fail( "FilledThumbnail filter accepted incorrect value." ); + } + catch ( ezcBaseValueException $e ) + {} + try + { + $this->handler->filledThumbnail( "foo", 50, array( 255, 0, 0 ) ); + $this->fail( "FilledThumbnail filter accepted incorrect value." ); + } + catch ( ezcBaseValueException $e ) + {} + try + { + $this->handler->filledThumbnail( 50, -10, array( 255, 0, 0 ) ); + $this->fail( "FilledThumbnail filter accepted incorrect value." ); + } + catch ( ezcBaseValueException $e ) + {} + try + { + $this->handler->filledThumbnail( 50, false, array( 255, 0, 0 ) ); + $this->fail( "FilledThumbnail filter accepted incorrect value." ); + } + catch ( ezcBaseValueException $e ) + {} + try + { + $this->handler->filledThumbnail( 50, 50, array( 255, false, 0 ) ); + $this->fail( "FilledThumbnail filter accepted incorrect value." ); + } + catch ( ezcBaseValueException $e ) + {} + try + { + $this->handler->filledThumbnail( 50, 50, array( "bar", 0, 0 ) ); + $this->fail( "FilledThumbnail filter accepted incorrect value." ); + } + catch ( ezcBaseValueException $e ) + {} + } } ?> Modified: trunk/ImageConversion/tests/test_case.php =================================================================== --- trunk/ImageConversion/tests/test_case.php 2007-02-21 11:31:45 UTC (rev 4674) +++ trunk/ImageConversion/tests/test_case.php 2007-02-21 12:04:07 UTC (rev 4675) @@ -10,7 +10,7 @@ const REGENERATION_MODE = false; // Set this to false to keep the temporary test dirs - const REMOVE_TEMP_DIRS = false; + const REMOVE_TEMP_DIRS = true; const DEFAULT_SIMILARITY_GAP = 10; -- svn-components mailing list svn-components@lists.ez.no http://lists.ez.no/mailman/listinfo/svn-components