Fix newobject3 testcase

Fixes Octave problem which has a template called product.
This commit is contained in:
William S Fulton 2017-10-10 08:05:21 +01:00
parent e7f0c6d6ad
commit 08210236ef
5 changed files with 158 additions and 11 deletions

View File

@ -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;
}
%}

View File

@ -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");

View File

@ -0,0 +1,93 @@
<?php
/* ----------------------------------------------------------------------------
* 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.
* ----------------------------------------------------------------------------- */
// Try to load our extension if it's not already loaded.
if (!extension_loaded('newobject3')) {
if (strtolower(substr(PHP_OS, 0, 3)) === 'win') {
if (!dl('php_newobject3.dll')) return;
} else {
// PHP_SHLIB_SUFFIX gives 'dylib' on MacOS X but modules are 'so'.
if (PHP_SHLIB_SUFFIX === 'dylib') {
if (!dl('newobject3.so')) return;
} else {
if (!dl('newobject3.'.PHP_SHLIB_SUFFIX)) return;
}
}
}
/* PHP Proxy Classes */
class Product {
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 __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();
}
}
?>

View File

@ -0,0 +1,18 @@
<?php
require "tests.php";
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::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");
?>

View File

@ -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 */