From ef495c0b8fd0691d6571de8a5f72a23529d30a24 Mon Sep 17 00:00:00 2001 From: Danack Date: Sun, 7 Jul 2024 17:05:19 +0200 Subject: [PATCH] Alter test to not use unreasonable values, and to give easier to understand error messages on failure. --- tests/014-setresourcelimit.phpt | 42 ++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/tests/014-setresourcelimit.phpt b/tests/014-setresourcelimit.phpt index 14ea263f..83fc1f61 100644 --- a/tests/014-setresourcelimit.phpt +++ b/tests/014-setresourcelimit.phpt @@ -9,55 +9,65 @@ require_once(dirname(__FILE__) . '/skipif.inc'); 100000000, - + // Set maximum amount of disk space in bytes permitted for use by the pixel cache. When this limit is exceeded, the pixel cache is not be created and an error message is returned. Imagick::RESOURCETYPE_DISK => 100, - - + //Set maximum number of open pixel cache files. When this limit is exceeded, any subsequent pixels cached to disk are closed and reopened on demand. This behavior permits a large number of images to be accessed simultaneously on disk, but with a speed penalty due to repeated open/close calls. Imagick::RESOURCETYPE_FILE => 100, - + // Set maximum amount of memory map in bytes to allocate for the pixel cache. When this limit is exceeded, the image pixels are cached to disk - Imagick::RESOURCETYPE_MAP => 10 * $g, - + Imagick::RESOURCETYPE_MAP => 123 * $m, + // Set maximum amount of memory in bytes to allocate for the pixel cache from the heap. When this limit is exceeded, the image pixels are cached to memory-mapped disk - Imagick::RESOURCETYPE_MEMORY => 10 * $g, + Imagick::RESOURCETYPE_MEMORY => 234 * $m, ); if (defined('Imagick::RESOURCETYPE_TIME')) { - $tests[Imagick::RESOURCETYPE_TIME] = 30; + $tests[Imagick::RESOURCETYPE_TIME] = 30; } if (defined('Imagick::RESOURCETYPE_THROTTLE')) { - $tests[Imagick::RESOURCETYPE_THROTTLE] = 1; + $tests[Imagick::RESOURCETYPE_THROTTLE] = 1; } if (defined('Imagick::RESOURCETYPE_THREAD')) { - $tests[Imagick::RESOURCETYPE_THREAD] = 1; + $tests[Imagick::RESOURCETYPE_THREAD] = 1; } if (defined('Imagick::RESOURCETYPE_WIDTH')) { - $tests[Imagick::RESOURCETYPE_WIDTH] = $g; + $tests[Imagick::RESOURCETYPE_WIDTH] = 15 * $k; } if (defined('Imagick::RESOURCETYPE_HEIGHT')) { - $tests[Imagick::RESOURCETYPE_HEIGHT] = $g; + $tests[Imagick::RESOURCETYPE_HEIGHT] = 15 * $k; +} + +$reflection_class = new ReflectionClass(Imagick::class); +$constants = $reflection_class->getConstants(); +$resource_constants = []; +foreach ($constants as $name => $value) { + if (strpos($name, "RESOURCETYPE") === 0) { + $resource_constants[$value] = $name; + } } + foreach ($tests as $resourceType => $value) { Imagick::setResourceLimit($resourceType, $value); $actualValue = Imagick::getResourceLimit($resourceType); if ($actualValue != $value) { - echo "Error testing $resourceType, value returned $actualValue is not $value \n"; + $resourceTypeString = $resource_constants[$resourceType]; + echo "Error testing $resourceTypeString, value returned $actualValue is not $value \n"; } }