4 * PEL: PHP Exif Library.
5 * A library with support for reading and
6 * writing all Exif headers in JPEG and TIFF images using PHP.
8 * Copyright (C) 2004, 2005, 2006 Martin Geisler.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program in the file COPYING; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
26 use \lsolesen\pel\PelEntryByte;
27 use \lsolesen\pel\Pel;
28 use \lsolesen\pel\PelEntrySByte;
29 use \lsolesen\pel\PelEntryShort;
30 use \lsolesen\pel\PelEntrySShort;
31 use \lsolesen\pel\PelEntryLong;
32 use \lsolesen\pel\PelEntrySLong;
33 use \lsolesen\pel\PelEntryRational;
34 use \lsolesen\pel\PelEntrySRational;
35 use \lsolesen\pel\PelOverflowException;
37 abstract class NumberTest extends \PHPUnit_Framework_TestCase
43 public function __construct($min, $max)
45 Pel::setStrictParsing(true);
48 parent::__construct('PEL Exif Number Tests');
51 public function testOverflow()
53 $this->num->setValue(0);
54 $this->assertEquals($this->num->getValue(), 0);
58 $this->num->setValue($this->min - 1);
59 } catch (PelOverflowException $e) {
62 $this->assertTrue($caught);
63 $this->assertEquals($this->num->getValue(), 0);
67 $this->num->setValue($this->max + 1);
68 } catch (PelOverflowException $e) {
71 $this->assertTrue($caught);
72 $this->assertEquals($this->num->getValue(), 0);
76 $this->num->setValue(0, $this->max + 1);
77 } catch (PelOverflowException $e) {
80 $this->assertTrue($caught);
81 $this->assertEquals($this->num->getValue(), 0);
85 $this->num->setValue(0, $this->min - 1);
86 } catch (PelOverflowException $e) {
89 $this->assertTrue($caught);
90 $this->assertEquals($this->num->getValue(), 0);
94 * @expectedException PHPUnit_Framework_Error
95 * @expectedExceptionMessageRegExp /Missing argument 1 for lsolesen.pel.PelEntryNumber::setValue()/
97 public function testSetValueWithNoArgument()
99 $this->num->setValue();
102 public function testReturnValues()
104 $this->num->setValue(1, 2, 3);
105 $this->assertEquals($this->num->getValue(), array(
110 $this->assertEquals($this->num->getText(), '1, 2, 3');
112 $this->num->setValue(1);
113 $this->assertEquals($this->num->getValue(), 1);
114 $this->assertEquals($this->num->getText(), '1');
116 $this->num->setValue($this->max);
117 $this->assertEquals($this->num->getValue(), $this->max);
118 $this->assertEquals($this->num->getText(), $this->max);
120 $this->num->setValue($this->min);
121 $this->assertEquals($this->num->getValue(), $this->min);
122 $this->assertEquals($this->num->getText(), $this->min);
126 class ByteTestCase extends NumberTest
129 public function __construct()
131 $this->num = new PelEntryByte(42);
132 parent::__construct(0, 255);
136 class SByteTestCase extends NumberTest
139 public function __construct()
141 $this->num = new PelEntrySByte(42);
142 parent::__construct(- 128, 127);
146 class ShortTestCase extends NumberTest
149 public function __construct()
151 $this->num = new PelEntryShort(42);
152 parent::__construct(0, 65535);
156 class SShortTestCase extends NumberTest
159 public function __construct()
162 $this->num = new PelEntrySShort(42);
163 parent::__construct(- 32768, 32767);
167 class LongTestCase extends NumberTest
170 public function __construct()
173 $this->num = new PelEntryLong(42);
174 parent::__construct(0, 4294967295);
178 class SLongTestCase extends NumberTest
181 public function __construct()
184 $this->num = new PelEntrySLong(42);
185 parent::__construct(- 2147483648, 2147483647);
189 class RationalTestCase extends \PHPUnit_Framework_TestCase
191 public function testOverflow()
193 $entry = new PelEntryRational(42, array(
197 $this->assertEquals($entry->getValue(), array(
204 $entry->setValue(array(
214 } catch (PelOverflowException $e) {
217 $this->assertTrue($caught);
218 $this->assertEquals($entry->getValue(), array(
225 $entry->setValue(array(
232 } catch (PelOverflowException $e) {
235 $this->assertTrue($caught);
236 $this->assertEquals($entry->getValue(), array(
243 $entry->setValue(array(
250 } catch (PelOverflowException $e) {
253 $this->assertTrue($caught);
254 $this->assertEquals($entry->getValue(), array(
261 * @expectedException PHPUnit_Framework_Error
262 * @expectedMessage Undefined variable: tag
263 * @expectedExceptionMessageRegExp /Missing argument 1 for lsolesen.pel.PelEntryRational::__construct()/
265 public function testPelEntryWithoutArguments()
267 $entry = new PelEntryRational();
270 public function testReturnValues()
272 $entry = new PelEntryRational(42);
273 $this->assertEquals($entry->getValue(), array());
274 $this->assertEquals($entry->getText(), '');
276 $entry->setValue(array(
286 $this->assertEquals($entry->getValue(), array(
300 $this->assertEquals($entry->getText(), '1/2, 3/4, 5/6');
302 $entry->setValue(array(
306 $this->assertEquals($entry->getValue(), array(
310 $this->assertEquals($entry->getText(), '7/8');
312 $pattern = new PatternExpectation('/Missing argument 1 for lsolesen.pel.PelEntryNumber::setValue()/');
313 $this->expectError($pattern);
316 $entry->setValue(array(
320 $this->assertEquals($entry->getValue(), array(
324 $this->assertEquals($entry->getText(), '0/4294967295');
328 class SRationalTestCase extends \PHPUnit_Framework_TestCase
331 public function __construct()
334 parent::__construct('PEL Exif SRational Tests');
337 public function testOverflow()
339 $entry = new PelEntrySRational(42, array(
343 $this->assertEquals($entry->getValue(), array(
350 $entry->setValue(array(
357 } catch (PelOverflowException $e) {
360 $this->assertTrue($caught);
361 $this->assertEquals($entry->getValue(), array(
368 $entry->setValue(array(
375 } catch (PelOverflowException $e) {
378 $this->assertTrue($caught);
379 $this->assertEquals($entry->getValue(), array(
386 $entry->setValue(array(
393 } catch (PelOverflowException $e) {
396 $this->assertTrue($caught);
397 $this->assertEquals($entry->getValue(), array(
403 public function testReturnValues()
405 $pattern = new PatternExpectation('/Missing argument 1 for lsolesen.pel.PelEntrySRational::__construct()/');
406 $this->expectError($pattern);
407 $pattern = new PatternExpectation('/Undefined variable: tag/');
408 $this->expectError($pattern);
409 $entry = new PelEntrySRational();
411 $entry = new PelEntrySRational(42);
412 $this->assertEquals($entry->getValue(), array());
414 $entry->setValue(array(
424 $this->assertEquals($entry->getValue(), array(
438 $this->assertEquals($entry->getText(), '-1/2, 3/4, -5/6');
440 $entry->setValue(array(
444 $this->assertEquals($entry->getValue(), array(
448 $this->assertEquals($entry->getText(), '7/8');
450 $pattern = new PatternExpectation('/Missing argument 1 for lsolesen.pel.PelEntryNumber::setValue()/');
451 $this->expectError($pattern);
454 $entry->setValue(array(
458 $this->assertEquals($entry->getValue(), array(
462 $this->assertEquals($entry->getText(), '0/2147483647');