8
* This source file is subject to the new BSD license that is bundled
9
* with this package in the file LICENSE.txt.
10
* It is also available through the world-wide-web at this URL:
11
* http://framework.zend.com/license/new-bsd
12
* If you did not receive a copy of the license and are unable to
13
* obtain it through the world-wide-web, please send an email
14
* to license@zend.com so we can send you a copy immediately.
17
* @package Zend_Measure
18
* @subpackage UnitTests
19
* @copyright Copyright (c) 2006 Zend Technologies USA Inc. (http://www.zend.com)
20
* @license http://framework.zend.com/license/new-bsd New BSD License
21
* @version $Id: BinaryTest.php 6799 2007-11-09 22:44:42Z thomas $
28
require_once 'Zend/Measure/Binary.php';
33
require_once 'PHPUnit/Framework/TestCase.php';
37
* @package Zend_Measure
38
* @subpackage UnitTests
40
class Zend_Measure_BinaryTest extends PHPUnit_Framework_TestCase
43
* test for Binary initialisation
46
public function testBinaryInit()
48
$value = new Zend_Measure_Binary('100',Zend_Measure_Binary::STANDARD,'de');
49
$this->assertTrue($value instanceof Zend_Measure_Binary,'Zend_Measure_Binary Object not returned');
54
* test for exception unknown type
57
public function testBinaryUnknownType()
60
$value = new Zend_Measure_Binary('100','Binary::UNKNOWN','de');
61
$this->fail('Exception expected because of unknown type');
62
} catch (Zend_Measure_Exception $e) {
69
* test for exception unknown value
72
public function testBinaryUnknownValue()
75
$value = new Zend_Measure_Binary('novalue',Zend_Measure_Binary::STANDARD,'de');
76
$this->fail('Exception expected because of empty value');
77
} catch (Zend_Measure_Exception $e) {
84
* test for exception unknown locale
87
public function testBinaryUnknownLocale()
90
$value = new Zend_Measure_Binary('100',Zend_Measure_Binary::STANDARD,'nolocale');
91
$this->fail('Exception expected because of unknown locale');
92
} catch (Zend_Measure_Exception $e) {
99
* test for exception no locale
100
* expected root value
102
public function testBinaryNoLocale()
104
$value = new Zend_Measure_Binary('100',Zend_Measure_Binary::STANDARD);
105
$this->assertTrue(is_object($value),'Object expected because of standard locale');
110
* test for positive value
113
public function testBinaryValuePositive()
115
$value = new Zend_Measure_Binary('100',Zend_Measure_Binary::STANDARD,'de');
116
$this->assertEquals(100, $value->getValue(), 'Zend_Measure_Binary value expected to be a positive integer');
121
* test for negative value
124
public function testBinaryValueNegative()
126
$value = new Zend_Measure_Binary('-100',Zend_Measure_Binary::STANDARD,'de');
127
$this->assertEquals(-100, $value->getValue(), 'Zend_Measure_Binary value expected to be a negative integer');
132
* test for decimal value
135
public function testBinaryValueDecimal()
137
$value = new Zend_Measure_Binary('-100,200',Zend_Measure_Binary::STANDARD,'de');
138
$this->assertEquals(-100.200, $value->getValue(), 'Zend_Measure_Binary value expected to be a decimal value');
143
* test for decimal seperated value
146
public function testBinaryValueDecimalSeperated()
148
$value = new Zend_Measure_Binary('-100.100,200',Zend_Measure_Binary::STANDARD,'de');
149
$this->assertEquals(-100100.200, $value->getValue(),'Zend_Measure_Binary Object not returned');
154
* test for string with integrated value
157
public function testBinaryValueString()
159
$value = new Zend_Measure_Binary('string -100.100,200',Zend_Measure_Binary::STANDARD,'de');
160
$this->assertEquals(-100100.200, $value->getValue(),'Zend_Measure_Binary Object not returned');
168
public function testBinaryEquality()
170
$value = new Zend_Measure_Binary('string -100.100,200',Zend_Measure_Binary::STANDARD,'de');
171
$newvalue = new Zend_Measure_Binary('otherstring -100.100,200',Zend_Measure_Binary::STANDARD,'de');
172
$this->assertTrue($value->equals($newvalue),'Zend_Measure_Binary Object should be equal');
177
* test for no equality
180
public function testBinaryNoEquality()
182
$value = new Zend_Measure_Binary('string -100.100,200',Zend_Measure_Binary::STANDARD,'de');
183
$newvalue = new Zend_Measure_Binary('otherstring -100,200',Zend_Measure_Binary::STANDARD,'de');
184
$this->assertFalse($value->equals($newvalue),'Zend_Measure_Binary Object should be not equal');
189
* test for set positive value
192
public function testBinarySetPositive()
194
$value = new Zend_Measure_Binary('100',Zend_Measure_Binary::STANDARD,'de');
195
$value->setValue('200',Zend_Measure_Binary::STANDARD,'de');
196
$this->assertEquals(200, $value->getValue(), 'Zend_Measure_Binary value expected to be a positive integer');
201
* test for set negative value
204
public function testBinarySetNegative()
206
$value = new Zend_Measure_Binary('-100',Zend_Measure_Binary::STANDARD,'de');
207
$value->setValue('-200',Zend_Measure_Binary::STANDARD,'de');
208
$this->assertEquals(-200, $value->getValue(), 'Zend_Measure_Binary value expected to be a negative integer');
213
* test for set decimal value
216
public function testBinarySetDecimal()
218
$value = new Zend_Measure_Binary('-100,200',Zend_Measure_Binary::STANDARD,'de');
219
$value->setValue('-200,200',Zend_Measure_Binary::STANDARD,'de');
220
$this->assertEquals(-200.200, $value->getValue(), 'Zend_Measure_Binary value expected to be a decimal value');
225
* test for set decimal seperated value
228
public function testBinarySetDecimalSeperated()
230
$value = new Zend_Measure_Binary('-100.100,200',Zend_Measure_Binary::STANDARD,'de');
231
$value->setValue('-200.200,200',Zend_Measure_Binary::STANDARD,'de');
232
$this->assertEquals(-200200.200, $value->getValue(),'Zend_Measure_Binary Object not returned');
237
* test for set string with integrated value
240
public function testBinarySetString()
242
$value = new Zend_Measure_Binary('string -100.100,200',Zend_Measure_Binary::STANDARD,'de');
243
$value->setValue('otherstring -200.200,200',Zend_Measure_Binary::STANDARD,'de');
244
$this->assertEquals(-200200.200, $value->getValue(),'Zend_Measure_Binary Object not returned');
249
* test for exception unknown type
252
public function testBinarySetUnknownType()
255
$value = new Zend_Measure_Binary('100',Zend_Measure_Binary::STANDARD,'de');
256
$value->setValue('otherstring -200.200,200','Binary::UNKNOWN','de');
257
$this->fail('Exception expected because of unknown type');
258
} catch (Zend_Measure_Exception $e) {
265
* test for exception unknown value
268
public function testBinarySetUnknownValue()
271
$value = new Zend_Measure_Binary('100',Zend_Measure_Binary::STANDARD,'de');
272
$value->setValue('novalue',Zend_Measure_Binary::STANDARD,'de');
273
$this->fail('Exception expected because of empty value');
274
} catch (Zend_Measure_Exception $e) {
281
* test for exception unknown locale
284
public function testBinarySetUnknownLocale()
287
$value = new Zend_Measure_Binary('100',Zend_Measure_Binary::STANDARD,'de');
288
$value->setValue('200',Zend_Measure_Binary::STANDARD,'nolocale');
289
$this->fail('Exception expected because of unknown locale');
290
} catch (Zend_Measure_Exception $e) {
297
* test for exception unknown locale
300
public function testBinarySetWithNoLocale()
302
$value = new Zend_Measure_Binary('100', Zend_Measure_Binary::STANDARD, 'de');
303
$value->setValue('200', Zend_Measure_Binary::STANDARD);
304
$this->assertEquals(200, $value->getValue(), 'Zend_Measure_Binary value expected to be a positive integer');
312
public function testBinarySetType()
314
$value = new Zend_Measure_Binary('-100',Zend_Measure_Binary::STANDARD,'de');
315
$value->setType(Zend_Measure_Binary::GIGABYTE);
316
$this->assertEquals(Zend_Measure_Binary::GIGABYTE, $value->getType(), 'Zend_Measure_Binary type expected');
321
* test setting computed type
324
public function testBinarySetComputedType1()
326
$value = new Zend_Measure_Binary('-100',Zend_Measure_Binary::MEGABYTE,'de');
327
$value->setType(Zend_Measure_Binary::TERABYTE);
328
$this->assertEquals(Zend_Measure_Binary::TERABYTE, $value->getType(), 'Zend_Measure_Binary type expected');
333
* test setting computed type
336
public function testBinarySetComputedType2()
338
$value = new Zend_Measure_Binary('-100',Zend_Measure_Binary::TERABYTE,'de');
339
$value->setType(Zend_Measure_Binary::KILOBYTE);
340
$this->assertEquals(Zend_Measure_Binary::KILOBYTE, $value->getType(), 'Zend_Measure_Binary type expected');
345
* test setting unknown type
348
public function testBinarySetTypeFailed()
351
$value = new Zend_Measure_Binary('-100',Zend_Measure_Binary::STANDARD,'de');
352
$value->setType('Binary::UNKNOWN');
353
$this->fail('Exception expected because of unknown type');
354
} catch (Zend_Measure_Exception $e) {
364
public function testBinaryToString()
366
$value = new Zend_Measure_Binary('-100',Zend_Measure_Binary::STANDARD,'de');
367
$this->assertEquals('-100 B', $value->toString(), 'Value -100 B expected');
375
public function testBinary_ToString()
377
$value = new Zend_Measure_Binary('-100',Zend_Measure_Binary::STANDARD,'de');
378
$this->assertEquals('-100 B', $value->__toString(), 'Value -100 B expected');
383
* test getConversionList
386
public function testBinaryConversionList()
388
$value = new Zend_Measure_Binary('-100',Zend_Measure_Binary::STANDARD,'de');
389
$unit = $value->getConversionList();
390
$this->assertTrue(is_array($unit), 'Array expected');