X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=tests%2F1ParsingBugsTest.php;h=ce463f7a1283e009e69719cd04b5fcb9118b5a3b;hb=238968291ce5627e94dbc3928d377d09f6e9eeda;hp=949130f234d0126858db58a636dde2cc222d3ca6;hpb=8e7f7c3cd2daa0c63b3b54b83caad271e1feb31c;p=plcapi.git diff --git a/tests/1ParsingBugsTest.php b/tests/1ParsingBugsTest.php index 949130f..ce463f7 100644 --- a/tests/1ParsingBugsTest.php +++ b/tests/1ParsingBugsTest.php @@ -5,15 +5,48 @@ include_once __DIR__ . '/../lib/xmlrpc.inc'; include_once __DIR__ . '/../lib/xmlrpcs.inc'; +include_once __DIR__ . '/parse_args.php'; + +/** + * Tests involving parsing of xml and handling of xmlrpc values + */ class ParsingBugsTests extends PHPUnit_Framework_TestCase { + public $args = array(); + + protected function setUp() + { + $this->args = argParser::getArgs(); + if ($this->args['DEBUG'] == 1) + ob_start(); + } + + protected function tearDown() + { + if ($this->args['DEBUG'] != 1) + return; + $out = ob_get_clean(); + $status = $this->getStatus(); + if ($status == PHPUnit_Runner_BaseTestRunner::STATUS_ERROR + || $status == PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE) { + echo $out; + } + } + + protected function newMsg($methodName, $params = array()) + { + $msg = new xmlrpcmsg($methodName, $params); + $msg->setDebug($this->args['DEBUG']); + return $msg; + } + public function testMinusOneString() { $v = new xmlrpcval('-1'); $u = new xmlrpcval('-1', 'string'); $t = new xmlrpcval(-1, 'string'); - $this->assertEquals($u->scalarval(), $v->scalarval()); - $this->assertEquals($t->scalarval(), $v->scalarval()); + $this->assertEquals($v->scalarval(), $u->scalarval()); + $this->assertEquals($v->scalarval(), $t->scalarval()); } /** @@ -21,8 +54,8 @@ class ParsingBugsTests extends PHPUnit_Framework_TestCase */ public function testMinusOneInt() { - $v = new xmlrpcval(-1); $u = new xmlrpcval(); + $v = new xmlrpcval(-1); $this->assertEquals($u->scalarval(), $v->scalarval()); } @@ -32,10 +65,10 @@ class ParsingBugsTests extends PHPUnit_Framework_TestCase $v = array($str => new xmlrpcval(1)); $r = new xmlrpcresp(new xmlrpcval($v, 'struct')); $r = $r->serialize(); - $m = new xmlrpcmsg('dummy'); + $m = $this->newMsg('dummy'); $r = $m->parseResponse($r); $v = $r->value(); - $this->assertEquals($v->structmemexists($str), true); + $this->assertEquals(true, $v->structmemexists($str)); } public function testUnicodeInErrorString() @@ -62,7 +95,7 @@ class ParsingBugsTests extends PHPUnit_Framework_TestCase '); - $m = new xmlrpcmsg('dummy'); + $m = $this->newMsg('dummy'); $r = $m->parseResponse($response); $v = $r->faultString(); $this->assertEquals(chr(224) . chr(252) . chr(232) . chr(224) . chr(252) . chr(232), $v); @@ -70,7 +103,7 @@ class ParsingBugsTests extends PHPUnit_Framework_TestCase public function testValidNumbers() { - $m = new xmlrpcmsg('dummy'); + $m = $this->newMsg('dummy'); $fp = ' @@ -83,14 +116,18 @@ class ParsingBugsTests extends PHPUnit_Framework_TestCase 01 -float1 -01.10 - - integer2 +1 +integer3 +1 + + +float1 +01.10 + + float2 +1.10 @@ -106,15 +143,48 @@ class ParsingBugsTests extends PHPUnit_Framework_TestCase $r = $m->parseResponse($fp); $v = $r->value(); $s = $v->structmem('integer1'); - $t = $v->structmem('float1'); - $u = $v->structmem('integer2'); - $w = $v->structmem('float2'); - $x = $v->structmem('float3'); + $t = $v->structmem('integer2'); + $u = $v->structmem('integer3'); + $x = $v->structmem('float1'); + $y = $v->structmem('float2'); + $z = $v->structmem('float3'); $this->assertEquals(1, $s->scalarval()); - $this->assertEquals(1.1, $t->scalarval()); + $this->assertEquals(1, $t->scalarval()); $this->assertEquals(1, $u->scalarval()); - $this->assertEquals(1.1, $w->scalarval()); - $this->assertEquals(-110.0, $x->scalarval()); + + $this->assertEquals(1.1, $x->scalarval()); + $this->assertEquals(1.1, $y->scalarval()); + $this->assertEquals(-110.0, $z->scalarval()); + } + + public function testI8() + { + if (PHP_INT_SIZE == 4 ) { + $this->markTestSkipped('did not find a locale which sets decimal separator to comma'); + return; + } + + $m = $this->newMsg('dummy'); + $fp = + ' + + + + + + +integer1 +1 + + + + + +'; + $r = $m->parseResponse($fp); + $v = $r->value(); + $s = $v->structmem('integer1'); + $this->assertEquals(1, $s->scalarval()); } public function testAddScalarToStruct() @@ -193,8 +263,7 @@ class ParsingBugsTests extends PHPUnit_Framework_TestCase public function testBrokenResponses() { - $m = new xmlrpcmsg('dummy'); - //$m->debug = 1; + $m = $this->newMsg('dummy'); // omitting the 'params' tag: no more tolerated by the lib... $f = ' @@ -226,7 +295,7 @@ class ParsingBugsTests extends PHPUnit_Framework_TestCase public function testBuggyHttp() { - $s = new xmlrpcmsg('dummy'); + $s = $this->newMsg('dummy'); $f = 'HTTP/1.1 100 Welcome to the jungle HTTP/1.0 200 OK @@ -253,7 +322,7 @@ and there they were.postid7414222newMsg('dummy'); $f = '