Skip to content

Commit ef495c0

Browse files
committed
Alter test to not use unreasonable values, and to give easier to understand error messages on failure.
1 parent a66f84a commit ef495c0

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

tests/014-setresourcelimit.phpt

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,55 +9,65 @@ require_once(dirname(__FILE__) . '/skipif.inc');
99
<?php
1010

1111

12-
1312
$k = 1024;
1413
$m = $k * $k;
15-
$g = $k * $m;
16-
$t = $k * $g;
1714

1815
// These tests are flaky as the values ImageMagick will accept
1916
// are limited by the policy.xml of the system.
17+
// Also, it appears that some versions of ImageMagick will
18+
// reject overly large values. e.g. setting RESOURCETYPE_WIDTH
19+
// to a billion fails. Which is not totally unreasonable.
2020

2121
$tests = array(
2222
Imagick::RESOURCETYPE_AREA => 100000000,
23-
23+
2424
// 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.
2525
Imagick::RESOURCETYPE_DISK => 100,
26-
27-
26+
2827
//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.
2928
Imagick::RESOURCETYPE_FILE => 100,
30-
29+
3130
// 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
32-
Imagick::RESOURCETYPE_MAP => 10 * $g,
33-
31+
Imagick::RESOURCETYPE_MAP => 123 * $m,
32+
3433
// 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
35-
Imagick::RESOURCETYPE_MEMORY => 10 * $g,
34+
Imagick::RESOURCETYPE_MEMORY => 234 * $m,
3635
);
3736

3837
if (defined('Imagick::RESOURCETYPE_TIME')) {
39-
$tests[Imagick::RESOURCETYPE_TIME] = 30;
38+
$tests[Imagick::RESOURCETYPE_TIME] = 30;
4039
}
4140

4241
if (defined('Imagick::RESOURCETYPE_THROTTLE')) {
43-
$tests[Imagick::RESOURCETYPE_THROTTLE] = 1;
42+
$tests[Imagick::RESOURCETYPE_THROTTLE] = 1;
4443
}
4544
if (defined('Imagick::RESOURCETYPE_THREAD')) {
46-
$tests[Imagick::RESOURCETYPE_THREAD] = 1;
45+
$tests[Imagick::RESOURCETYPE_THREAD] = 1;
4746
}
4847
if (defined('Imagick::RESOURCETYPE_WIDTH')) {
49-
$tests[Imagick::RESOURCETYPE_WIDTH] = $g;
48+
$tests[Imagick::RESOURCETYPE_WIDTH] = 15 * $k;
5049
}
5150
if (defined('Imagick::RESOURCETYPE_HEIGHT')) {
52-
$tests[Imagick::RESOURCETYPE_HEIGHT] = $g;
51+
$tests[Imagick::RESOURCETYPE_HEIGHT] = 15 * $k;
52+
}
53+
54+
$reflection_class = new ReflectionClass(Imagick::class);
55+
$constants = $reflection_class->getConstants();
56+
$resource_constants = [];
57+
foreach ($constants as $name => $value) {
58+
if (strpos($name, "RESOURCETYPE") === 0) {
59+
$resource_constants[$value] = $name;
60+
}
5361
}
5462

63+
5564
foreach ($tests as $resourceType => $value) {
5665
Imagick::setResourceLimit($resourceType, $value);
5766
$actualValue = Imagick::getResourceLimit($resourceType);
5867

5968
if ($actualValue != $value) {
60-
echo "Error testing $resourceType, value returned $actualValue is not $value \n";
69+
$resourceTypeString = $resource_constants[$resourceType];
70+
echo "Error testing $resourceTypeString, value returned $actualValue is not $value \n";
6171
}
6272
}
6373

0 commit comments

Comments
 (0)