there's all the signed-int parsers working
This commit is contained in:
parent
282c42139d
commit
b13d5045e2
4 changed files with 109 additions and 0 deletions
30
src/bindings/php/Tests/Int16Test.php
Normal file
30
src/bindings/php/Tests/Int16Test.php
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
include_once 'hammer.php';
|
||||
|
||||
class Int16Test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $parser;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->parser = h_int16();
|
||||
}
|
||||
public function testNegative()
|
||||
{
|
||||
$result = h_parse($this->parser, "\xfe\x00");
|
||||
$this->assertEquals(-0x200, $result);
|
||||
}
|
||||
public function testPositive() {
|
||||
$result = h_parse($this->parser, "\x02\x00");
|
||||
$this->assertEquals(0x200, $result);
|
||||
}
|
||||
public function testFailure()
|
||||
{
|
||||
$result = h_parse($this->parser, "\xfe");
|
||||
$this->assertEquals(NULL, $result);
|
||||
$result = h_parse($this->parser, "\x02");
|
||||
$this->assertEquals(NULL, $result);
|
||||
}
|
||||
}
|
||||
?>
|
||||
31
src/bindings/php/Tests/Int32Test.php
Normal file
31
src/bindings/php/Tests/Int32Test.php
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
include_once 'hammer.php';
|
||||
|
||||
class Int32Test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $parser;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->parser = h_int32();
|
||||
}
|
||||
public function testNegative()
|
||||
{
|
||||
$result = h_parse($this->parser, "\xff\xfe\x00\x00");
|
||||
$this->assertEquals(-0x20000, $result);
|
||||
}
|
||||
public function testPositive()
|
||||
{
|
||||
$result = h_parse($this->parser, "\x00\x02\x00\x00");
|
||||
$this->assertEquals(0x20000, $result);
|
||||
}
|
||||
public function testFailure()
|
||||
{
|
||||
$result = h_parse($this->parser, "\xff\xfe\x00");
|
||||
$this->assertEquals(NULL, $result);
|
||||
$result = h_parse($this->parser, "\x00\x02\x00");
|
||||
$this->assertEquals(NULL, $result);
|
||||
}
|
||||
}
|
||||
?>
|
||||
24
src/bindings/php/Tests/Int64Test.php
Normal file
24
src/bindings/php/Tests/Int64Test.php
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
include_once 'hammer.php';
|
||||
|
||||
class Int64Test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $parser;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->parser = h_int64();
|
||||
}
|
||||
public function testSuccess()
|
||||
{
|
||||
$result = h_parse($this->parser, "\xff\xff\xff\xfe\x00\x00\x00\x00");
|
||||
$this->assertEquals(-0x200000000, $result);
|
||||
}
|
||||
public function testFailure()
|
||||
{
|
||||
$result = h_parse($this->parser, "\xff\xff\xff\xfe\x00\x00\x00");
|
||||
$this->assertEquals(NULL, $result);
|
||||
}
|
||||
}
|
||||
?>
|
||||
24
src/bindings/php/Tests/Int8Test.php
Normal file
24
src/bindings/php/Tests/Int8Test.php
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
include_once 'hammer.php';
|
||||
|
||||
class Int8Test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $parser;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->parser = h_int8();
|
||||
}
|
||||
public function testSuccess()
|
||||
{
|
||||
$result = h_parse($this->parser, "\x88");
|
||||
$this->assertEquals(-0x78, $result);
|
||||
}
|
||||
public function testFailure()
|
||||
{
|
||||
$result = h_parse($this->parser, "");
|
||||
$this->assertEquals(NULL, $result);
|
||||
}
|
||||
}
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue