From b13d5045e2867c127a2977de8f0a6d0cb917214f Mon Sep 17 00:00:00 2001 From: "Meredith L. Patterson" <mlp@thesmartpolitenerd.com> Date: Sun, 24 Nov 2013 20:40:48 -0600 Subject: [PATCH] there's all the signed-int parsers working --- src/bindings/php/Tests/Int16Test.php | 30 +++++++++++++++++++++++++++ src/bindings/php/Tests/Int32Test.php | 31 ++++++++++++++++++++++++++++ src/bindings/php/Tests/Int64Test.php | 24 +++++++++++++++++++++ src/bindings/php/Tests/Int8Test.php | 24 +++++++++++++++++++++ 4 files changed, 109 insertions(+) create mode 100644 src/bindings/php/Tests/Int16Test.php create mode 100644 src/bindings/php/Tests/Int32Test.php create mode 100644 src/bindings/php/Tests/Int64Test.php create mode 100644 src/bindings/php/Tests/Int8Test.php diff --git a/src/bindings/php/Tests/Int16Test.php b/src/bindings/php/Tests/Int16Test.php new file mode 100644 index 00000000..4b170cc3 --- /dev/null +++ b/src/bindings/php/Tests/Int16Test.php @@ -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); + } +} +?> \ No newline at end of file diff --git a/src/bindings/php/Tests/Int32Test.php b/src/bindings/php/Tests/Int32Test.php new file mode 100644 index 00000000..c538aa25 --- /dev/null +++ b/src/bindings/php/Tests/Int32Test.php @@ -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); + } +} +?> \ No newline at end of file diff --git a/src/bindings/php/Tests/Int64Test.php b/src/bindings/php/Tests/Int64Test.php new file mode 100644 index 00000000..4c0faa22 --- /dev/null +++ b/src/bindings/php/Tests/Int64Test.php @@ -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); + } +} +?> \ No newline at end of file diff --git a/src/bindings/php/Tests/Int8Test.php b/src/bindings/php/Tests/Int8Test.php new file mode 100644 index 00000000..164d7737 --- /dev/null +++ b/src/bindings/php/Tests/Int8Test.php @@ -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); + } +} +?> \ No newline at end of file -- GitLab