Add support for i8
[plcapi.git] / tests / 1ParsingBugsTest.php
index 6a6a3f9..343fcb0 100644 (file)
@@ -5,6 +5,11 @@
 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();
@@ -40,8 +45,8 @@ class ParsingBugsTests extends PHPUnit_Framework_TestCase
         $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());
     }
 
     /**
@@ -49,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());
     }
 
@@ -63,7 +68,7 @@ class ParsingBugsTests extends PHPUnit_Framework_TestCase
         $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()
@@ -111,14 +116,18 @@ class ParsingBugsTests extends PHPUnit_Framework_TestCase
 <value><int>01</int></value>
 </member>
 <member>
-<name>float1</name>
-<value><double>01.10</double></value>
-</member>
-<member>
 <name>integer2</name>
 <value><int>+1</int></value>
 </member>
 <member>
+<name>integer3</name>
+<value><i4>1</i4></value>
+</member>
+<member>
+<name>float1</name>
+<value><double>01.10</double></value>
+</member>
+<member>
 <name>float2</name>
 <value><double>+1.10</double></value>
 </member>
@@ -134,15 +143,49 @@ 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 =
+            '<?xml version="1.0"?>
+<methodResponse>
+<params>
+<param>
+<value>
+<struct>
+<member>
+<name>integer1</name>
+<value><i8>1</i8></value>
+</member>
+</member>
+</struct>
+</value>
+</param>
+</params>
+</methodResponse>';
+        $r = $m->parseResponse($fp);
+        $v = $r->value();
+        $s = $v->structmem('integer1');
+        $this->assertEquals(1, $s->scalarval());
     }
 
     public function testAddScalarToStruct()
@@ -549,7 +592,7 @@ and there they were.</value></member><member><name>postid</name><value>7414222</
         $this->assertequals(2, $r->faultCode());
     }
 
-    public function TestLocale()
+    public function testLocale()
     {
         $locale = setlocale(LC_NUMERIC, 0);
         /// @todo on php 5.3/win setting locale to german does not seem to set decimal separator to comma...
@@ -567,4 +610,31 @@ and there they were.</value></member><member><name>postid</name><value>7414222</
             $this->markTestSkipped('did not find a locale which sets decimal separator to comma');
         }
     }
+
+    public function testArrayAccess()
+    {
+        $v1 = new xmlrpcval(array(new xmlrpcval('one'), new xmlrpcval('two')), 'array');
+        $this->assertequals(1, count($v1));
+        $out = array('me' => array(), 'mytype' => 2, '_php_class' => null);
+        foreach($v1 as $key => $val)
+        {
+            $expected = each($out);
+            $this->assertequals($expected['key'], $key);
+            if (gettype($expected['value']) == 'array') {
+                $this->assertequals('array', gettype($val));
+            } else {
+                $this->assertequals($expected['value'], $val);
+            }
+        }
+
+        $v2 = new \PhpXmlRpc\Value(array(new \PhpXmlRpc\Value('one'), new \PhpXmlRpc\Value('two')), 'array');
+        $this->assertequals(2, count($v2));
+        $out = array(0 => 'object', 1 => 'object');
+        foreach($v2 as $key => $val)
+        {
+            $expected = each($out);
+            $this->assertequals($expected['key'], $key);
+            $this->assertequals($expected['value'], gettype($val));
+        }
+    }
 }