6560423fa97d82d41aba8578c1968fda08ecc69e
[yaffs-website] / test / PelEntryUndefinedTest.php
1 <?php
2
3 /**
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.
7  *
8  * Copyright (C) 2004, 2006 Martin Geisler.
9  * Copyright (C) 2017 Johannes Weberhofer
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program in the file COPYING; if not, write to the
23  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
24  * Boston, MA 02110-1301 USA
25  */
26 use lsolesen\pel\PelEntryUndefined;
27 use lsolesen\pel\PelEntryUserComment;
28 use lsolesen\pel\PelEntryVersion;
29 use lsolesen\pel\PelConvert;
30 use PHPUnit\Framework\TestCase;
31
32 class PelEntryUndefinedTest extends TestCase
33 {
34
35     function testReturnValues()
36     {
37         new PelEntryUndefined(42);
38
39         $entry = new PelEntryUndefined(42, 'foo bar baz');
40         $this->assertEquals($entry->getComponents(), 11);
41         $this->assertEquals($entry->getValue(), 'foo bar baz');
42     }
43
44     function testUsercomment()
45     {
46         $entry = new PelEntryUserComment();
47         $this->assertEquals($entry->getComponents(), 8);
48         $this->assertEquals($entry->getValue(), '');
49         $this->assertEquals($entry->getEncoding(), 'ASCII');
50
51         $entry->setValue('Hello!');
52         $this->assertEquals($entry->getComponents(), 14);
53         $this->assertEquals($entry->getValue(), 'Hello!');
54         $this->assertEquals($entry->getEncoding(), 'ASCII');
55     }
56
57     function testVersion()
58     {
59         $entry = new PelEntryVersion(42);
60
61         $this->assertEquals($entry->getValue(), 0.0);
62
63         $entry->setValue(2.0);
64         $this->assertEquals($entry->getValue(), 2.0);
65         $this->assertEquals($entry->getText(false), 'Version 2.0');
66         $this->assertEquals($entry->getText(true), '2.0');
67         $this->assertEquals($entry->getBytes(PelConvert::LITTLE_ENDIAN), '0200');
68
69         $entry->setValue(2.1);
70         $this->assertEquals($entry->getValue(), 2.1);
71         $this->assertEquals($entry->getText(false), 'Version 2.1');
72         $this->assertEquals($entry->getText(true), '2.1');
73         $this->assertEquals($entry->getBytes(PelConvert::LITTLE_ENDIAN), '0210');
74
75         $entry->setValue(2.01);
76         $this->assertEquals($entry->getValue(), 2.01);
77         $this->assertEquals($entry->getText(false), 'Version 2.01');
78         $this->assertEquals($entry->getText(true), '2.01');
79         $this->assertEquals($entry->getBytes(PelConvert::LITTLE_ENDIAN), '0201');
80     }
81 }