[geos-commits] r3069 - in trunk/php: . test

svn_geos at osgeo.org svn_geos at osgeo.org
Thu Jun 24 05:07:10 EDT 2010


Author: strk
Date: 2010-06-24 09:07:10 +0000 (Thu, 24 Jun 2010)
New Revision: 3069

Modified:
   trunk/php/geos.c
   trunk/php/test/test.php
Log:
WKBWriter::{get,set}ByteOrder, improve tests for writeHEX


Modified: trunk/php/geos.c
===================================================================
--- trunk/php/geos.c	2010-06-24 09:01:54 UTC (rev 3068)
+++ trunk/php/geos.c	2010-06-24 09:07:10 UTC (rev 3069)
@@ -1817,12 +1817,16 @@
 PHP_METHOD(WKBWriter, __construct);
 PHP_METHOD(WKBWriter, getOutputDimension);
 PHP_METHOD(WKBWriter, setOutputDimension);
+PHP_METHOD(WKBWriter, getByteOrder);
+PHP_METHOD(WKBWriter, setByteOrder);
 PHP_METHOD(WKBWriter, writeHEX);
 
 static function_entry WKBWriter_methods[] = {
     PHP_ME(WKBWriter, __construct, NULL, 0)
     PHP_ME(WKBWriter, getOutputDimension, NULL, 0)
     PHP_ME(WKBWriter, setOutputDimension, NULL, 0)
+    PHP_ME(WKBWriter, getByteOrder, NULL, 0)
+    PHP_ME(WKBWriter, setByteOrder, NULL, 0)
     PHP_ME(WKBWriter, writeHEX, NULL, 0)
     {NULL, NULL, NULL}
 };
@@ -1933,8 +1937,43 @@
     RETURN_STRING(retstr, 0);
 }
 
+/**
+ * long GEOSWKBWriter::getByteOrder();
+ */
+PHP_METHOD(WKBWriter, getByteOrder)
+{
+    GEOSWKBWriter *writer;
+    long int ret;
 
+    writer = (GEOSWKBWriter*)getRelay(getThis(), WKBWriter_ce_ptr);
 
+    ret = GEOSWKBWriter_getByteOrder(writer);
+
+    RETURN_LONG(ret);
+}
+
+/**
+ * void GEOSWKBWriter::setByteOrder(dims);
+ */
+PHP_METHOD(WKBWriter, setByteOrder)
+{
+    GEOSWKBWriter *writer;
+    long int dim;
+
+    writer = (GEOSWKBWriter*)getRelay(getThis(), WKBWriter_ce_ptr);
+
+    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &dim)
+        == FAILURE)
+    {
+        RETURN_NULL();
+    }
+
+    GEOSWKBWriter_setByteOrder(writer, dim);
+
+}
+
+
+
 /* -- Free functions ------------------------- */
 
 /**

Modified: trunk/php/test/test.php
===================================================================
--- trunk/php/test/test.php	2010-06-24 09:01:54 UTC (rev 3068)
+++ trunk/php/test/test.php	2010-06-24 09:07:10 UTC (rev 3069)
@@ -1734,7 +1734,7 @@
         $writer->setOutputDimension(2);
         $this->assertEquals(2, $writer->getOutputDimension());
 
-	# 1 is invalid
+        # 1 is invalid
         try {
             $writer->setOutputDimension(1);
             $this->assertTrue(FALSE);
@@ -1742,7 +1742,7 @@
             $this->assertContains('must be 2 or 3', $e->getMessage());
         }
 
-	# 4 is invalid
+        # 4 is invalid
         try {
             $writer->setOutputDimension(4);
             $this->assertTrue(FALSE);
@@ -1751,6 +1751,28 @@
         }
     }
 
+    public function testWKBWriter_getsetByteOrder()
+    {
+        $writer = new GEOSWKBWriter();
+
+        /* Machine-dependent */
+        $bo = $writer->getByteOrder();
+
+        $obo = $bo ? 0 : 1;
+        $writer->setByteOrder($obo);
+        $this->assertEquals($obo, $writer->getByteOrder());
+
+        # Anything different from 0 (BIG_ENDIAN) or 1 (LITTLE_ENDIAN)
+        # is invalid
+        try {
+            $writer->setByteOrder(5);
+            $this->assertTrue(FALSE);
+        } catch (Exception $e) {
+            $this->assertContains('LITTLE (1) or BIG (0)', $e->getMessage());
+        }
+
+    }
+
     public function testWKBWriter_writeHEX()
     {
         $writer = new GEOSWKBWriter();
@@ -1765,11 +1787,44 @@
 
         $g = $reader->read('POINT(6 7)');
 
+        $writer->setOutputDimension(2); // 2D
+
+        $writer->setByteOrder(1); // LITTLE endian
         $this->assertEquals('010100000000000000000018400000000000001C40',
             $writer->writeHEX($g));
+        $writer->setByteOrder(0); // BIG endian
+        $this->assertEquals('00000000014018000000000000401C000000000000',
+            $writer->writeHEX($g));
 
+        $writer->setOutputDimension(3); // 3D
+
+        $writer->setByteOrder(1); // LITTLE endian
+        $this->assertEquals('010100000000000000000018400000000000001C40',
+            $writer->writeHEX($g));
+        $writer->setByteOrder(0); // BIG endian
+        $this->assertEquals('00000000014018000000000000401C000000000000',
+            $writer->writeHEX($g));
+
         $g = $reader->read('POINT(6 7 8)');
+
+        $writer->setOutputDimension(2); // 2D
+
+        $writer->setByteOrder(1); // LITTLE endian
         $this->assertEquals('010100000000000000000018400000000000001C40',
             $writer->writeHEX($g));
+        $writer->setByteOrder(0); // BIG endian
+        $this->assertEquals('00000000014018000000000000401C000000000000',
+            $writer->writeHEX($g));
+
+        $writer->setOutputDimension(3); // 3D
+
+        $writer->setByteOrder(1); // LITTLE endian, 2d
+        $this->assertEquals(
+            '010100008000000000000018400000000000001C400000000000002040',
+            $writer->writeHEX($g));
+        $writer->setByteOrder(0); // BIG endian, 3d
+        $this->assertEquals(
+            '00800000014018000000000000401C0000000000004020000000000000',
+            $writer->writeHEX($g));
     }
 }



More information about the geos-commits mailing list