3
* Gallery - a web based photo album viewer and editor
4
* Copyright (C) 2000-2007 Bharat Mediratta
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or (at
9
* your option) any later version.
11
* This program is distributed in the hope that it will be useful, but
12
* WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
21
GalleryCoreApi::requireOnce('modules/dcraw/classes/DcrawToolkit.class');
27
* @author Bharat Mediratta <bharat@menalto.com>
28
* @version $Revision: 15513 $
30
class DcrawToolkitTest extends GalleryTestCase {
32
function DcrawToolkitTest($methodName) {
33
$this->GalleryTestCase($methodName);
34
$this->_toolkit = new DcrawToolkit();
42
$ret = $this->_markPluginParametersForCleanup('module', 'dcraw');
44
print $ret->getAsHtml();
45
return $this->failWithStatus($ret);
47
$this->_setParam('path', '/usr/bin/dcraw');
50
* Simulate a version after the most recent API change we know/care about, which is
51
* currently 7.73 when they added a numeric argument to the -q flag.
53
$this->_setParam('version', '7.73');
55
$this->_platform = new UnitTestPlatform();
56
$gallery->setPlatform($this->_platform);
60
$this->assert($this->_platform->isComplete(), $this->_platform->getRemaining());
64
function _setParam($key, $value) {
65
$ret = GalleryCoreApi::setPluginParameter('module', 'dcraw', $key, $value);
67
$this->failWithStatus($ret);
71
function testConvertDcrawToPpmPre773() {
74
$this->_setParam('version', '6.52');
76
$this->_platform->setReply(
77
'tempnam', array($gallery->getConfig('data.gallery.tmp'), 'dcraw_'), 'TEMPFILE');
78
$this->_platform->setReply('exec', array(array(
79
array('/usr/bin/dcraw', '-c', '-a', '-q', 'INPUTFILE', '>', 'TEMPFILE'))),
81
$this->_platform->setReply('rename', array('TEMPFILE', 'OUTPUTFILE'), 1);
82
$this->_platform->setReply('chmod', array('OUTPUTFILE', null), 1);
84
list ($ret, $outputMimeType, $context) = $this->_toolkit->performOperation(
85
'image/x-dcraw', 'convert-to-image/x-portable-pixmap',
86
'INPUTFILE', 'OUTPUTFILE', array(), array());
88
$this->failWithStatus($ret);
92
function testConvertDcrawToPpm() {
95
$this->_platform->setReply(
96
'tempnam', array($gallery->getConfig('data.gallery.tmp'), 'dcraw_'), 'TEMPFILE');
97
$this->_platform->setReply('exec', array(array(
98
array('/usr/bin/dcraw', '-c', '-a', '-q', '0', 'INPUTFILE', '>', 'TEMPFILE'))),
100
$this->_platform->setReply('rename', array('TEMPFILE', 'OUTPUTFILE'), 1);
101
$this->_platform->setReply('chmod', array('OUTPUTFILE', null), 1);
103
list ($ret, $outputMimeType, $context) = $this->_toolkit->performOperation(
104
'image/x-dcraw', 'convert-to-image/x-portable-pixmap',
105
'INPUTFILE', 'OUTPUTFILE', array(), array());
107
$this->failWithStatus($ret);
111
function testConvertDcrawToPpmBadInputFile() {
114
$this->_platform->setReply(
115
'tempnam', array($gallery->getConfig('data.gallery.tmp'), 'dcraw_'), 'TEMPFILE');
116
$this->_platform->setReply('exec', array(array(
117
array('/usr/bin/dcraw', '-c', '-a', '-q', '0', 'INPUTFILE', '>', 'TEMPFILE'))),
118
array(0, '', 'INPUTFILE: unsupported file format.'));
119
$this->_platform->setReply('unlink', array('TEMPFILE'), 1);
121
list ($ret, $outputMimeType, $context) = $this->_toolkit->performOperation(
122
'image/x-dcraw', 'convert-to-image/x-portable-pixmap',
123
'INPUTFILE', 'OUTPUTFILE', array(), array());
124
$this->assert($ret && $ret->getErrorCode() & ERROR_TOOLKIT_FAILURE);
127
function testConvertDcrawToPpmBadMimetype() {
130
list ($ret, $outputMimeType, $context) = $this->_toolkit->performOperation(
131
'bogus/bogus', 'convert-to-image/x-portable-pixmap',
132
'INPUTFILE', 'OUTPUTFILE', array(), array());
133
$this->assert($ret && $ret->getErrorCode() & ERROR_UNSUPPORTED_OPERATION);
136
function testConvertDcrawToPpmBadTempFile() {
138
$this->_platform->setReply(
139
'tempnam', array($gallery->getConfig('data.gallery.tmp'), 'dcraw_'), null);
141
list ($ret, $outputMimeType, $context) = $this->_toolkit->performOperation(
142
'image/x-dcraw', 'convert-to-image/x-portable-pixmap',
143
'INPUTFILE', 'OUTPUTFILE', array(), array());
144
$this->assert($ret && $ret->getErrorCode() & ERROR_BAD_PATH);
147
function testConvertDcrawToPpmFailedExec() {
150
$this->_platform->setReply(
151
'tempnam', array($gallery->getConfig('data.gallery.tmp'), 'dcraw_'), 'TEMPFILE');
152
$this->_platform->setReply('exec', array(array(
153
array('/usr/bin/dcraw', '-c', '-a', '-q', '0', 'INPUTFILE', '>', 'TEMPFILE'))),
155
$this->_platform->setReply('unlink', array('TEMPFILE'), 1);
157
list ($ret, $outputMimeType, $context) = $this->_toolkit->performOperation(
158
'image/x-dcraw', 'convert-to-image/x-portable-pixmap',
159
'INPUTFILE', 'OUTPUTFILE', array(), array());
160
$this->assert($ret && $ret->getErrorCode() & ERROR_TOOLKIT_FAILURE);
163
function testConvertDcrawToPpmFailedRename() {
166
$this->_platform->setReply(
167
'tempnam', array($gallery->getConfig('data.gallery.tmp'), 'dcraw_'), 'TEMPFILE');
168
$this->_platform->setReply('exec', array(array(
169
array('/usr/bin/dcraw', '-c', '-a', '-q', '0', 'INPUTFILE', '>', 'TEMPFILE'))),
171
$this->_platform->setReply('rename', array('TEMPFILE', 'OUTPUTFILE'), 0);
172
$this->_platform->setReply('unlink', array('TEMPFILE'), 1);
174
list ($ret, $outputMimeType, $context) = $this->_toolkit->performOperation(
175
'image/x-dcraw', 'convert-to-image/x-portable-pixmap',
176
'INPUTFILE', 'OUTPUTFILE', array(), array());
177
$this->assert($ret && $ret->getErrorCode() & ERROR_PLATFORM_FAILURE);
180
function testBadOperationName() {
181
list ($ret, $outputMimeType, $context) = $this->_toolkit->performOperation(
182
'image/x-dcraw', 'BOGUS OPERATION',
183
'INPUTFILE', 'OUTPUTFILE', array(), array());
184
$this->assert($ret && $ret->getErrorCode() & ERROR_UNSUPPORTED_OPERATION);
188
* This test is commented out for now because it's not possible to make sure that
189
* our dummy toolkit is called instead of a real toolkit because right now
190
* toolkit properties don't have priorities. If/when we resolve that, we can
193
function testGetDimensions() {
194
/* Move this registration back into setup when we uncomment this test * /
195
$ret = GalleryCoreApi::registerFactoryImplementation(
196
'GalleryToolkit', 'DcrawTestToolkit', 'DcrawTestToolkit',
197
'modules/dcraw/test/phpunit/DcrawToolkitTest.class', 'dcrawTest', null);
199
print $ret->getAsHtml();
200
return $this->failWithStatus($ret);
202
$this->_markToolkitForCleanup('DcrawTestToolkit');
204
$ret = GalleryCoreApi::registerToolkitProperty(
205
'DcrawTestToolkit', array('image/x-portable-pixmap'),
206
'dimensions', 'int,int', 'test-description');
208
return $this->failWithStatus($ret);
211
list ($ret, $results) = $this->_toolkit->getProperty(
212
'image/x-dcraw', 'dimensions', 'INPUTFILE');
214
$this->failWithStatus($ret);
216
$this->assertEquals(array(1, 2), $results);
220
function testGetDimensionsBadMimeType() {
221
list ($ret, $outputMimeType) = $this->_toolkit->getProperty(
222
'BAD/MIMETYPE', 'dimensions', 'INPUTFILE');
223
$this->assert($ret && $ret->getErrorCode() & ERROR_UNSUPPORTED_OPERATION);
226
function testGetBadPropertyName() {
227
list ($ret, $results) = $this->_toolkit->getProperty(
228
'image/x-dcraw', 'BAD PROPERTY', 'INPUTFILE');
229
$this->assert($ret && $ret->getErrorCode() & ERROR_UNSUPPORTED_OPERATION);