~ubuntu-branches/ubuntu/lucid/gallery2/lucid

« back to all changes in this revision

Viewing changes to modules/dcraw/test/phpunit/DcrawToolkitTest.class

  • Committer: Bazaar Package Importer
  • Author(s): Michael C. Schultheiss
  • Date: 2007-09-10 20:22:19 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070910202219-0jsuntvqge4ade6b
Tags: 2.2.3-2
Add Slovak translation of Debconf templates.  (Thanks to 
Ivan Masá.  Closes: #441671)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
/*
3
 
 * Gallery - a web based photo album viewer and editor
4
 
 * Copyright (C) 2000-2007 Bharat Mediratta
5
 
 *
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.
10
 
 *
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.
15
 
 *
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.
19
 
 */
20
 
 
21
 
GalleryCoreApi::requireOnce('modules/dcraw/classes/DcrawToolkit.class');
22
 
 
23
 
/**
24
 
 * Dcraw toolkit tests
25
 
 * @package Dcraw
26
 
 * @subpackage PHPUnit
27
 
 * @author Bharat Mediratta <bharat@menalto.com>
28
 
 * @version $Revision: 15513 $
29
 
 */
30
 
class DcrawToolkitTest extends GalleryTestCase {
31
 
 
32
 
    function DcrawToolkitTest($methodName) {
33
 
        $this->GalleryTestCase($methodName);
34
 
        $this->_toolkit = new DcrawToolkit();
35
 
    }
36
 
 
37
 
    function setUp() {
38
 
        global $gallery;
39
 
 
40
 
        parent::setUp();
41
 
 
42
 
        $ret = $this->_markPluginParametersForCleanup('module', 'dcraw');
43
 
        if ($ret) {
44
 
            print $ret->getAsHtml();
45
 
            return $this->failWithStatus($ret);
46
 
        }
47
 
        $this->_setParam('path', '/usr/bin/dcraw');
48
 
 
49
 
        /*
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.
52
 
         */
53
 
        $this->_setParam('version', '7.73');
54
 
 
55
 
        $this->_platform = new UnitTestPlatform();
56
 
        $gallery->setPlatform($this->_platform);
57
 
    }
58
 
 
59
 
    function tearDown() {
60
 
        $this->assert($this->_platform->isComplete(), $this->_platform->getRemaining());
61
 
        parent::tearDown();
62
 
    }
63
 
 
64
 
    function _setParam($key, $value) {
65
 
        $ret = GalleryCoreApi::setPluginParameter('module', 'dcraw', $key, $value);
66
 
        if ($ret) {
67
 
            $this->failWithStatus($ret);
68
 
        }
69
 
    }
70
 
 
71
 
    function testConvertDcrawToPpmPre773() {
72
 
        global $gallery;
73
 
 
74
 
        $this->_setParam('version', '6.52');
75
 
 
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'))),
80
 
            array(1, ''));
81
 
        $this->_platform->setReply('rename', array('TEMPFILE', 'OUTPUTFILE'), 1);
82
 
        $this->_platform->setReply('chmod', array('OUTPUTFILE', null), 1);
83
 
 
84
 
        list ($ret, $outputMimeType, $context) = $this->_toolkit->performOperation(
85
 
            'image/x-dcraw', 'convert-to-image/x-portable-pixmap',
86
 
            'INPUTFILE', 'OUTPUTFILE', array(), array());
87
 
        if ($ret) {
88
 
            $this->failWithStatus($ret);
89
 
        }
90
 
    }
91
 
 
92
 
    function testConvertDcrawToPpm() {
93
 
        global $gallery;
94
 
 
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'))),
99
 
            array(1, ''));
100
 
        $this->_platform->setReply('rename', array('TEMPFILE', 'OUTPUTFILE'), 1);
101
 
        $this->_platform->setReply('chmod', array('OUTPUTFILE', null), 1);
102
 
 
103
 
        list ($ret, $outputMimeType, $context) = $this->_toolkit->performOperation(
104
 
            'image/x-dcraw', 'convert-to-image/x-portable-pixmap',
105
 
            'INPUTFILE', 'OUTPUTFILE', array(), array());
106
 
        if ($ret) {
107
 
            $this->failWithStatus($ret);
108
 
        }
109
 
    }
110
 
 
111
 
    function testConvertDcrawToPpmBadInputFile() {
112
 
        global $gallery;
113
 
 
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);
120
 
 
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);
125
 
    }
126
 
 
127
 
    function testConvertDcrawToPpmBadMimetype() {
128
 
        global $gallery;
129
 
 
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);
134
 
    }
135
 
 
136
 
    function testConvertDcrawToPpmBadTempFile() {
137
 
        global $gallery;
138
 
        $this->_platform->setReply(
139
 
            'tempnam', array($gallery->getConfig('data.gallery.tmp'), 'dcraw_'), null);
140
 
 
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);
145
 
    }
146
 
 
147
 
    function testConvertDcrawToPpmFailedExec() {
148
 
        global $gallery;
149
 
 
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'))),
154
 
            array(0, ''));
155
 
        $this->_platform->setReply('unlink', array('TEMPFILE'), 1);
156
 
 
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);
161
 
    }
162
 
 
163
 
    function testConvertDcrawToPpmFailedRename() {
164
 
        global $gallery;
165
 
 
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'))),
170
 
            array(1, ''));
171
 
        $this->_platform->setReply('rename', array('TEMPFILE', 'OUTPUTFILE'), 0);
172
 
        $this->_platform->setReply('unlink', array('TEMPFILE'), 1);
173
 
 
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);
178
 
    }
179
 
 
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);
185
 
    }
186
 
 
187
 
    /*
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
191
 
     * enable this test.
192
 
     *
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);
198
 
        if ($ret) {
199
 
            print $ret->getAsHtml();
200
 
            return $this->failWithStatus($ret);
201
 
        }
202
 
        $this->_markToolkitForCleanup('DcrawTestToolkit');
203
 
 
204
 
        $ret = GalleryCoreApi::registerToolkitProperty(
205
 
            'DcrawTestToolkit', array('image/x-portable-pixmap'),
206
 
            'dimensions', 'int,int', 'test-description');
207
 
        if ($ret) {
208
 
            return $this->failWithStatus($ret);
209
 
        }
210
 
 
211
 
        list ($ret, $results) = $this->_toolkit->getProperty(
212
 
            'image/x-dcraw', 'dimensions', 'INPUTFILE');
213
 
        if ($ret) {
214
 
            $this->failWithStatus($ret);
215
 
        }
216
 
        $this->assertEquals(array(1, 2), $results);
217
 
    }
218
 
    */
219
 
 
220
 
    function testGetDimensionsBadMimeType() {
221
 
        list ($ret, $outputMimeType) = $this->_toolkit->getProperty(
222
 
            'BAD/MIMETYPE', 'dimensions', 'INPUTFILE');
223
 
        $this->assert($ret && $ret->getErrorCode() & ERROR_UNSUPPORTED_OPERATION);
224
 
    }
225
 
 
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);
230
 
    }
231
 
}
232
 
?>