134b40a440284d3e79c146ad68414ed9e01c34f3
[yaffs-website] / vendor / lsolesen / pel / test / AsciiTest.php
1 <?php
2
3 /*
4  * PEL: PHP Exif Library. A library with support for reading and
5  * writing all Exif headers in JPEG and TIFF images using PHP.
6  *
7  * Copyright (C) 2004, 2006, 2007 Martin Geisler.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program in the file COPYING; if not, write to the
21  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
22  * Boston, MA 02110-1301 USA
23  */
24 use lsolesen\pel\PelConvert;
25 use lsolesen\pel\PelEntryAscii;
26 use lsolesen\pel\PelEntryCopyright;
27 use lsolesen\pel\PelEntryTime;
28 use lsolesen\pel\PelTag;
29 use PHPUnit\Framework\TestCase;
30
31 class AsciiTest extends TestCase
32 {
33
34     function testConstructorWithNoValues()
35     {
36         if (version_compare(PHP_VERSION, '7.1.0') >= 0) {
37             $this->markTestSkipped('Test does not run on PHP 7.1.0+');
38         } else {
39             $this->expectException(PHPUnit_Framework_Exception::class);
40             $entry = new PelEntryAscii();
41         }
42     }
43
44     function testReturnValues()
45     {
46         $entry = new PelEntryAscii(42);
47
48         $entry = new PelEntryAscii(42, 'foo bar baz');
49         $this->assertEquals($entry->getComponents(), 12);
50         $this->assertEquals($entry->getValue(), 'foo bar baz');
51     }
52
53     function testTimeWithNoConstructorArgument()
54     {
55         if (version_compare(PHP_VERSION, '7.1.0') >= 0) {
56             $this->markTestSkipped('Test does not run on PHP 7.1.0+');
57         } else {
58             $this->expectException(PHPUnit_Framework_Exception::class);
59             $entry = new PelEntryTime();
60         }
61     }
62
63     function testTimeWithNoOneConstructorArgument()
64     {
65         if (version_compare(PHP_VERSION, '7.1.0') >= 0) {
66             $this->markTestSkipped('Test does not run on PHP 7.1.0+');
67         } else {
68             $this->expectException(PHPUnit_Framework_Exception::class);
69             $entry = new PelEntryTime(42);
70         }
71     }
72
73     function testTime()
74     {
75         $entry = new PelEntryTime(42, 10);
76
77         $this->assertEquals($entry->getComponents(), 20);
78         $this->assertEquals($entry->getValue(), 10);
79         $this->assertEquals($entry->getValue(PelEntryTime::UNIX_TIMESTAMP), 10);
80         $this->assertEquals($entry->getValue(PelEntryTime::EXIF_STRING), '1970:01:01 00:00:10');
81         $this->assertEquals($entry->getValue(PelEntryTime::JULIAN_DAY_COUNT), 2440588 + 10 / 86400);
82         $this->assertEquals($entry->getText(), '1970:01:01 00:00:10');
83
84         // Malformed Exif timestamp.
85         $entry->setValue('1970!01-01 00 00 30', PelEntryTime::EXIF_STRING);
86         $this->assertEquals($entry->getValue(), 30);
87
88         $entry->setValue(2415021.75, PelEntryTime::JULIAN_DAY_COUNT);
89         // This is Jan 1st 1900 at 18:00, outside the range of a UNIX
90         // timestamp:
91         $this->assertEquals($entry->getValue(), false);
92         $this->assertEquals($entry->getValue(PelEntryTime::EXIF_STRING), '1900:01:01 18:00:00');
93         $this->assertEquals($entry->getValue(PelEntryTime::JULIAN_DAY_COUNT), 2415021.75);
94
95         $entry->setValue('0000:00:00 00:00:00', PelEntryTime::EXIF_STRING);
96
97         $this->assertEquals($entry->getValue(), false);
98         $this->assertEquals($entry->getValue(PelEntryTime::EXIF_STRING), '0000:00:00 00:00:00');
99         $this->assertEquals($entry->getValue(PelEntryTime::JULIAN_DAY_COUNT), 0);
100
101         $entry->setValue('9999:12:31 23:59:59', PelEntryTime::EXIF_STRING);
102
103         // this test will fail on 32bit machines
104         $this->assertEquals($entry->getValue(), 253402300799);
105         $this->assertEquals($entry->getValue(PelEntryTime::EXIF_STRING), '9999:12:31 23:59:59');
106         $this->assertEquals($entry->getValue(PelEntryTime::JULIAN_DAY_COUNT), 5373484 + 86399 / 86400);
107
108         // Check day roll-over for SF bug #1699489.
109         $entry->setValue('2007:04:23 23:30:00', PelEntryTime::EXIF_STRING);
110         $t = $entry->getValue(PelEntryTime::UNIX_TIMESTAMP);
111         $entry->setValue($t + 3600);
112
113         $this->assertEquals($entry->getValue(PelEntryTime::EXIF_STRING), '2007:04:24 00:30:00');
114     }
115
116     function testCopyright()
117     {
118         $entry = new PelEntryCopyright();
119         $this->assertEquals($entry->getTag(), PelTag::COPYRIGHT);
120         $value = $entry->getValue();
121         $this->assertEquals($value[0], '');
122         $this->assertEquals($value[1], '');
123         $this->assertEquals($entry->getText(false), '');
124         $this->assertEquals($entry->getText(true), '');
125
126         $entry->setValue('A');
127         $value = $entry->getValue();
128         $this->assertEquals($value[0], 'A');
129         $this->assertEquals($value[1], '');
130         $this->assertEquals($entry->getText(false), 'A (Photographer)');
131         $this->assertEquals($entry->getText(true), 'A');
132         $this->assertEquals($entry->getBytes(PelConvert::LITTLE_ENDIAN), 'A' . chr(0));
133
134         $entry->setValue('', 'B');
135         $value = $entry->getValue();
136         $this->assertEquals($value[0], '');
137         $this->assertEquals($value[1], 'B');
138         $this->assertEquals($entry->getText(false), 'B (Editor)');
139         $this->assertEquals($entry->getText(true), 'B');
140         $this->assertEquals($entry->getBytes(PelConvert::LITTLE_ENDIAN), ' ' . chr(0) . 'B' . chr(0));
141
142         $entry->setValue('A', 'B');
143         $value = $entry->getValue();
144         $this->assertEquals($value[0], 'A');
145         $this->assertEquals($value[1], 'B');
146         $this->assertEquals($entry->getText(false), 'A (Photographer) - B (Editor)');
147         $this->assertEquals($entry->getText(true), 'A - B');
148         $this->assertEquals($entry->getBytes(PelConvert::LITTLE_ENDIAN), 'A' . chr(0) . 'B' . chr(0));
149     }
150 }