From 08210236ef09fd8d665dd77854e549d2693b469a Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 10 Oct 2017 08:05:21 +0100 Subject: [PATCH] Fix newobject3 testcase Fixes Octave problem which has a template called product. --- Examples/test-suite/newobject3.i | 14 +-- Examples/test-suite/php/newobject3_runme.php | 8 +- Examples/test-suite/php5/newobject3.php | 93 +++++++++++++++++++ Examples/test-suite/php5/newobject3_runme.php | 18 ++++ Examples/test-suite/php5/php_newobject3.h | 36 +++++++ 5 files changed, 158 insertions(+), 11 deletions(-) create mode 100644 Examples/test-suite/php5/newobject3.php create mode 100644 Examples/test-suite/php5/newobject3_runme.php create mode 100644 Examples/test-suite/php5/php_newobject3.h diff --git a/Examples/test-suite/newobject3.i b/Examples/test-suite/newobject3.i index e408fade2..ef12cd401 100644 --- a/Examples/test-suite/newobject3.i +++ b/Examples/test-suite/newobject3.i @@ -6,20 +6,20 @@ %newobject factory::create; %inline %{ -class product {}; +class Product {}; class factory { public: - product * create(short id, short type = 0); - product * create(const char * name, short type = 0); + Product * create(short id, short type = 0); + Product * create(const char * name, short type = 0); }; %} %{ -product * factory::create(short id, short type) { - return (id && type >= 0) ? new product : NULL; +Product * factory::create(short id, short type) { + return (id && type >= 0) ? new Product : NULL; } -product * factory::create(const char * name, short type) { - return (name && type >= 0) ? new product : NULL; +Product * factory::create(const char * name, short type) { + return (name && type >= 0) ? new Product : NULL; } %} diff --git a/Examples/test-suite/php/newobject3_runme.php b/Examples/test-suite/php/newobject3_runme.php index a95b777d1..edd5d8608 100644 --- a/Examples/test-suite/php/newobject3_runme.php +++ b/Examples/test-suite/php/newobject3_runme.php @@ -5,10 +5,10 @@ require "newobject3.php"; $factory = new factory(); -check::classname("product", $factory->create(7)); -check::classname("product", $factory->create(7, 6)); -check::classname("product", $factory->create("test")); -check::classname("product", $factory->create("test", 2)); +check::classname("Product", $factory->create(7)); +check::classname("Product", $factory->create(7, 6)); +check::classname("Product", $factory->create("test")); +check::classname("Product", $factory->create("test", 2)); check::isnull($factory->create(0), "create(0) should be NULL"); check::isnull($factory->create(7, -1), "create(7, -1) should be NULL"); diff --git a/Examples/test-suite/php5/newobject3.php b/Examples/test-suite/php5/newobject3.php new file mode 100644 index 000000000..21e1769d7 --- /dev/null +++ b/Examples/test-suite/php5/newobject3.php @@ -0,0 +1,93 @@ +_cPtr,$value); + $this->_pData[$var] = $value; + } + + function __get($var) { + if ($var === 'thisown') return swig_newobject3_get_newobject($this->_cPtr); + return $this->_pData[$var]; + } + + function __isset($var) { + if ($var === 'thisown') return true; + return array_key_exists($var, $this->_pData); + } + + function __construct($res=null) { + if (is_resource($res) && get_resource_type($res) === '_p_Product') { + $this->_cPtr=$res; + return; + } + $this->_cPtr=new_Product(); + } +} + +class factory { + public $_cPtr=null; + protected $_pData=array(); + + function __set($var,$value) { + if ($var === 'thisown') return swig_newobject3_alter_newobject($this->_cPtr,$value); + $this->_pData[$var] = $value; + } + + function __get($var) { + if ($var === 'thisown') return swig_newobject3_get_newobject($this->_cPtr); + return $this->_pData[$var]; + } + + function __isset($var) { + if ($var === 'thisown') return true; + return array_key_exists($var, $this->_pData); + } + + function create($id_or_name,$type=0) { + $r=factory_create($this->_cPtr,$id_or_name,$type); + if (!is_resource($r)) return $r; + return new Product($r); + } + + function __construct($res=null) { + if (is_resource($res) && get_resource_type($res) === '_p_factory') { + $this->_cPtr=$res; + return; + } + $this->_cPtr=new_factory(); + } +} + + +?> diff --git a/Examples/test-suite/php5/newobject3_runme.php b/Examples/test-suite/php5/newobject3_runme.php new file mode 100644 index 000000000..edd5d8608 --- /dev/null +++ b/Examples/test-suite/php5/newobject3_runme.php @@ -0,0 +1,18 @@ +create(7)); +check::classname("Product", $factory->create(7, 6)); +check::classname("Product", $factory->create("test")); +check::classname("Product", $factory->create("test", 2)); + +check::isnull($factory->create(0), "create(0) should be NULL"); +check::isnull($factory->create(7, -1), "create(7, -1) should be NULL"); +check::isnull($factory->create(0, -1), "create(0, -1) should be NULL"); +check::isnull($factory->create("bad", -1), "create(\"bad\", -1) should be NULL"); + +?> diff --git a/Examples/test-suite/php5/php_newobject3.h b/Examples/test-suite/php5/php_newobject3.h new file mode 100644 index 000000000..6ff30705a --- /dev/null +++ b/Examples/test-suite/php5/php_newobject3.h @@ -0,0 +1,36 @@ +/* ---------------------------------------------------------------------------- + * This file was automatically generated by SWIG (http://www.swig.org). + * Version 4.0.0 + * + * This file is not intended to be easily readable and contains a number of + * coding conventions designed to improve portability and efficiency. Do not make + * changes to this file unless you know what you are doing--modify the SWIG + * interface file instead. + * ----------------------------------------------------------------------------- */ + +#ifndef PHP_NEWOBJECT3_H +#define PHP_NEWOBJECT3_H + +extern zend_module_entry newobject3_module_entry; +#define phpext_newobject3_ptr &newobject3_module_entry + +#ifdef PHP_WIN32 +# define PHP_NEWOBJECT3_API __declspec(dllexport) +#else +# define PHP_NEWOBJECT3_API +#endif + +#ifdef ZTS +#include "TSRM.h" +#endif + +PHP_MINIT_FUNCTION(newobject3); +PHP_MSHUTDOWN_FUNCTION(newobject3); +PHP_RINIT_FUNCTION(newobject3); +PHP_RSHUTDOWN_FUNCTION(newobject3); +PHP_MINFO_FUNCTION(newobject3); + +ZEND_NAMED_FUNCTION(_wrap_new_Product); +ZEND_NAMED_FUNCTION(_wrap_factory_create); +ZEND_NAMED_FUNCTION(_wrap_new_factory); +#endif /* PHP_NEWOBJECT3_H */