aboutsummaryrefslogtreecommitdiff
path: root/Examples/test-suite/php
diff options
context:
space:
mode:
Diffstat (limited to 'Examples/test-suite/php')
-rw-r--r--Examples/test-suite/php/Makefile.in49
-rw-r--r--Examples/test-suite/php/abstract_inherit_ok_runme.php19
-rw-r--r--Examples/test-suite/php/abstract_inherit_runme.php17
-rw-r--r--Examples/test-suite/php/add_link_runme.php6
-rw-r--r--Examples/test-suite/php/argcargvtest_runme.php44
-rw-r--r--Examples/test-suite/php/argout_runme.php21
-rw-r--r--Examples/test-suite/php/arrayptr_runme.php14
-rw-r--r--Examples/test-suite/php/arrays_global_runme.php7
-rw-r--r--Examples/test-suite/php/arrays_global_twodim_runme.php7
-rw-r--r--Examples/test-suite/php/arrays_runme.php5
-rw-r--r--Examples/test-suite/php/arrays_scope_runme.php14
-rw-r--r--Examples/test-suite/php/callback_runme.php7
-rw-r--r--Examples/test-suite/php/casts_runme.php8
-rw-r--r--Examples/test-suite/php/catches_strings_runme.php23
-rw-r--r--Examples/test-suite/php/char_binary_runme.php39
-rw-r--r--Examples/test-suite/php/char_strings_runme.php2
-rw-r--r--Examples/test-suite/php/class_ignore_runme.php4
-rw-r--r--Examples/test-suite/php/constant_expr_c_runme.php15
-rw-r--r--Examples/test-suite/php/conversion_namespace_runme.php2
-rw-r--r--Examples/test-suite/php/conversion_ns_template_runme.php2
-rw-r--r--Examples/test-suite/php/conversion_runme.php2
-rw-r--r--Examples/test-suite/php/cpp11_attribute_specifiers_runme.php14
-rw-r--r--Examples/test-suite/php/cpp11_auto_variable_runme.php40
-rw-r--r--Examples/test-suite/php/cpp11_decltype_runme.php62
-rw-r--r--Examples/test-suite/php/cpp11_final_directors_runme.php16
-rw-r--r--Examples/test-suite/php/cpp11_move_typemaps_runme.php32
-rw-r--r--Examples/test-suite/php/cpp11_rvalue_reference_move_runme.php80
-rw-r--r--Examples/test-suite/php/cpp11_std_unique_ptr_runme.php108
-rw-r--r--Examples/test-suite/php/cpp11_strongly_typed_enumerations_runme.php3
-rw-r--r--Examples/test-suite/php/cpp14_auto_return_type_runme.php14
-rw-r--r--Examples/test-suite/php/cpp17_director_string_view_runme.php42
-rw-r--r--Examples/test-suite/php/cpp17_string_view_runme.php51
-rw-r--r--Examples/test-suite/php/cpp20_spaceship_operator_runme.php23
-rw-r--r--Examples/test-suite/php/cpp_basic_runme.php24
-rw-r--r--Examples/test-suite/php/cpp_enum_runme.php43
-rw-r--r--Examples/test-suite/php/cpp_static_runme.php10
-rw-r--r--Examples/test-suite/php/default_args_runme.php142
-rw-r--r--Examples/test-suite/php/director_abstract_runme.php16
-rw-r--r--Examples/test-suite/php/director_alternating_runme.php11
-rw-r--r--Examples/test-suite/php/director_basic_runme.php11
-rw-r--r--Examples/test-suite/php/director_classes_runme.php79
-rw-r--r--Examples/test-suite/php/director_classic_runme.php14
-rw-r--r--Examples/test-suite/php/director_default_runme.php8
-rw-r--r--Examples/test-suite/php/director_detect_runme.php10
-rw-r--r--Examples/test-suite/php/director_enum_runme.php8
-rw-r--r--Examples/test-suite/php/director_exception_catches_runme.php26
-rw-r--r--Examples/test-suite/php/director_exception_nothrow_runme.php23
-rw-r--r--Examples/test-suite/php/director_exception_runme.php16
-rw-r--r--Examples/test-suite/php/director_extend_runme.php10
-rw-r--r--Examples/test-suite/php/director_finalizer_runme.php31
-rw-r--r--Examples/test-suite/php/director_frob_runme.php10
-rw-r--r--Examples/test-suite/php/director_ignore_runme.php24
-rw-r--r--Examples/test-suite/php/director_nested_runme.php13
-rw-r--r--Examples/test-suite/php/director_overload_runme.php14
-rw-r--r--Examples/test-suite/php/director_ownership_runme.php28
-rw-r--r--Examples/test-suite/php/director_pass_by_value_runme.php5
-rw-r--r--Examples/test-suite/php/director_profile_runme.php8
-rw-r--r--Examples/test-suite/php/director_protected_runme.php8
-rw-r--r--Examples/test-suite/php/director_stl_runme.php10
-rw-r--r--Examples/test-suite/php/director_string_runme.php19
-rw-r--r--Examples/test-suite/php/director_thread_runme.php12
-rw-r--r--Examples/test-suite/php/director_unroll_runme.php16
-rw-r--r--Examples/test-suite/php/director_wombat_runme.php52
-rw-r--r--Examples/test-suite/php/enum_scope_template_runme.php19
-rw-r--r--Examples/test-suite/php/evil_diamond_ns_runme.php2
-rw-r--r--Examples/test-suite/php/evil_diamond_prop_runme.php4
-rw-r--r--Examples/test-suite/php/evil_diamond_runme.php2
-rw-r--r--Examples/test-suite/php/exception_memory_leak_runme.php35
-rw-r--r--Examples/test-suite/php/exception_order_runme.php10
-rw-r--r--Examples/test-suite/php/extend_template_ns_runme.php2
-rw-r--r--Examples/test-suite/php/extend_template_runme.php2
-rw-r--r--Examples/test-suite/php/friends_runme.php51
-rw-r--r--Examples/test-suite/php/global_vars_runme.php27
-rw-r--r--Examples/test-suite/php/grouping_runme.php4
-rw-r--r--Examples/test-suite/php/ignore_parameter_runme.php8
-rw-r--r--Examples/test-suite/php/import_nomodule_runme.php14
-rw-r--r--Examples/test-suite/php/li_carrays_cpp_runme.php7
-rw-r--r--Examples/test-suite/php/li_carrays_runme.php7
-rw-r--r--Examples/test-suite/php/li_constraints_runme.php68
-rw-r--r--Examples/test-suite/php/li_factory_runme.php11
-rw-r--r--Examples/test-suite/php/li_std_auto_ptr_runme.php108
-rw-r--r--Examples/test-suite/php/li_std_string_runme.php86
-rw-r--r--Examples/test-suite/php/li_std_vector_member_var_runme.php2
-rw-r--r--Examples/test-suite/php/long_long_runme.php65
-rw-r--r--Examples/test-suite/php/member_pointer_const_runme.php61
-rw-r--r--Examples/test-suite/php/mod_runme.php9
-rw-r--r--Examples/test-suite/php/multivalue_runme.php24
-rw-r--r--Examples/test-suite/php/newobject1_runme.php15
-rw-r--r--Examples/test-suite/php/newobject2_runme.php17
-rw-r--r--Examples/test-suite/php/newobject3_runme.php3
-rw-r--r--Examples/test-suite/php/overload_bool_runme.php42
-rw-r--r--Examples/test-suite/php/overload_complicated_runme.php39
-rw-r--r--Examples/test-suite/php/overload_copy_runme.php13
-rw-r--r--Examples/test-suite/php/overload_extend2_runme.php16
-rw-r--r--Examples/test-suite/php/overload_extend_c_runme.php11
-rw-r--r--Examples/test-suite/php/overload_extend_runme.php11
-rw-r--r--Examples/test-suite/php/overload_null_runme.php16
-rw-r--r--Examples/test-suite/php/overload_numeric_runme.php40
-rw-r--r--Examples/test-suite/php/overload_polymorphic_runme.php12
-rw-r--r--Examples/test-suite/php/overload_rename_runme.php6
-rw-r--r--Examples/test-suite/php/overload_return_type_runme.php3
-rw-r--r--Examples/test-suite/php/overload_simple_runme.php195
-rw-r--r--Examples/test-suite/php/overload_subtype_runme.php11
-rw-r--r--Examples/test-suite/php/overload_template_fast_runme.php110
-rw-r--r--Examples/test-suite/php/overload_template_runme.php110
-rw-r--r--Examples/test-suite/php/php_iterator_runme.php5
-rw-r--r--Examples/test-suite/php/php_pragma_runme.php9
-rw-r--r--Examples/test-suite/php/pointer_reference_runme.php2
-rw-r--r--Examples/test-suite/php/prefix_runme.php14
-rw-r--r--Examples/test-suite/php/preproc_constants_c_runme.php11
-rw-r--r--Examples/test-suite/php/preproc_constants_runme.php11
-rw-r--r--Examples/test-suite/php/primitive_ref_runme.php2
-rw-r--r--Examples/test-suite/php/rename_camel_runme.php13
-rw-r--r--Examples/test-suite/php/rename_scope_runme.php2
-rw-r--r--Examples/test-suite/php/skel.php4
-rw-r--r--Examples/test-suite/php/smart_pointer_rename_runme.php2
-rw-r--r--Examples/test-suite/php/smart_pointer_static_runme.php18
-rw-r--r--Examples/test-suite/php/swig_exception_runme.php3
-rw-r--r--Examples/test-suite/php/sym_runme.php8
-rw-r--r--Examples/test-suite/php/template_arg_typename_runme.php2
-rw-r--r--Examples/test-suite/php/template_construct_runme.php4
-rw-r--r--Examples/test-suite/php/tests.php180
-rw-r--r--Examples/test-suite/php/threads_exception_runme.php11
-rw-r--r--Examples/test-suite/php/typedef_reference_runme.php2
-rw-r--r--Examples/test-suite/php/typemap_ns_using_runme.php3
-rw-r--r--Examples/test-suite/php/using1_runme.php3
-rw-r--r--Examples/test-suite/php/using2_runme.php3
-rw-r--r--Examples/test-suite/php/valuewrapper_base_runme.php4
-rw-r--r--Examples/test-suite/php/virtual_vs_nonvirtual_base_runme.php5
-rw-r--r--Examples/test-suite/php/wrapmacro_runme.php4
130 files changed, 2634 insertions, 482 deletions
diff --git a/Examples/test-suite/php/Makefile.in b/Examples/test-suite/php/Makefile.in
index 64f0d1f9d..3811bd024 100644
--- a/Examples/test-suite/php/Makefile.in
+++ b/Examples/test-suite/php/Makefile.in
@@ -5,16 +5,29 @@
LANGUAGE = php
SCRIPTSUFFIX = _runme.php
+HAVE_CXX11 = @HAVE_CXX11@
+HAVE_CXX14 = @HAVE_CXX14@
+HAVE_CXX17 = @HAVE_CXX17@
+HAVE_CXX20 = @HAVE_CXX20@
srcdir = @srcdir@
top_srcdir = @top_srcdir@
top_builddir = @top_builddir@
CPP_TEST_CASES += \
callback \
+ director_stl \
+ exception_partial_info \
+ inout \
+ li_cdata_carrays_cpp \
li_factory \
php_iterator \
php_namewarn_rename \
php_pragma \
+ prefix \
+
+C_TEST_CASES += \
+ li_cdata_carrays \
+ multivalue \
include $(srcdir)/../common.mk
@@ -44,10 +57,18 @@ missingtests: missingcpptests missingctests
+$(swig_and_compile_c)
+$(run_testcase)
+# Trying to load the modules for imports.multicpptest fails with:
+#
+# Warning: Function registration failed - duplicate name - global_test in Unknown on line 0
+# Segmentation fault
+#
+# This was previously hidden because we didn't even try to load the modules for
+# .multicpptest testcases, so for now just do the parts of the test we did
+# before. FIXME: Fix this!
%.multicpptest:
$(setup)
+$(swig_and_compile_multi_cpp)
- +$(run_testcase)
+ +[ "$*" = "imports" ] || $(run_multi_testcase)
# Smart target
%.test:
@@ -58,18 +79,27 @@ missingtests: missingcpptests missingctests
@echo ' $(MULTI_CPP_TEST_CASES) '|grep -F -v ' $* ' >/dev/null ||\
$(MAKE) $*.multicpptest
-# Runs the testcase. Tries to run testcase_runme.php, and if that's not
-# found, runs testcase.php, except for multicpptests.
+# Runs the testcase. Tries to run testcase_runme.php, and if that's not found,
+# at least test that the module loads without errors.
run_testcase = \
if [ -f $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \
- $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile PHP_SCRIPT=$(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) RUNTOOL='$(RUNTOOL)' php_run; \
- elif [ -f $(SCRIPTDIR)/$(SCRIPTPREFIX)$*.php -a ! -f $(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)/$*.list ]; then \
- $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile PHP_SCRIPT=$(SCRIPTDIR)/$(SCRIPTPREFIX)$*.php RUNTOOL='$(RUNTOOL)' php_run; \
+ $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile PHP_EXTENSION=$(TARGETPREFIX)$*@PHP_SO@ PHP_SCRIPT=$(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) RUNTOOL='$(RUNTOOL)' php_run; \
+ else \
+ $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile PHP_EXTENSION=$(TARGETPREFIX)$*@PHP_SO@ PHP_SCRIPT= RUNTOOL='$(RUNTOOL)' php_run; \
+ fi
+
+# Runs a multicpptest testcase. Tries to run testcase_runme.php, and if that's
+# not found, at least test that the modules load without errors.
+run_multi_testcase = \
+ if [ -f $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \
+ $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile PHP_EXTENSION_LIST=$(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)/$*.list PHP_SCRIPT=$(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) RUNTOOL='$(RUNTOOL)' php_run_multi; \
+ else \
+ $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile PHP_EXTENSION_LIST=$(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)/$*.list PHP_SCRIPT= RUNTOOL='$(RUNTOOL)' php_run_multi; \
fi
-# Clean: remove the generated .php file
+# Clean: remove the generated PHP-specific files
%.clean:
- @rm -f $*.php php_$*.h
+ @rm -f php_$*.h
clean:
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' php_clean
@@ -77,5 +107,6 @@ clean:
rm -f import_stl_a.php import_stl_b.php php_import_stl_a.h php_import_stl_b.h
rm -f imports_a.php imports_b.php php_imports_a.h php_imports_b.h
rm -f mod_a.php mod_b.php php_mod_a.h php_mod_b.h
- rm -f multi_import_a.php multi_import_b.php php_multi_import_a.h php_multi_import_b.h
+ rm -f multi_import_a.php multi_import_b.php multi_import_d.php php_multi_import_a.h php_multi_import_b.h php_multi_import_d.h
rm -f packageoption_a.php packageoption_b.php packageoption_c.php php_packageoption_a.h php_packageoption_b.h php_packageoption_c.h
+ rm -f template_typedef_cplx2.php php_template_typedef_cplx2.h
diff --git a/Examples/test-suite/php/abstract_inherit_ok_runme.php b/Examples/test-suite/php/abstract_inherit_ok_runme.php
index c2c343dac..add4191c2 100644
--- a/Examples/test-suite/php/abstract_inherit_ok_runme.php
+++ b/Examples/test-suite/php/abstract_inherit_ok_runme.php
@@ -1,12 +1,25 @@
<?php
require "tests.php";
-require "abstract_inherit_ok.php";
+
+// No new functions
+check::functions(array());
check::classes(array('Foo','Spam'));
-$spam=new Spam();
+// No new vars
+check::globals(array());
+
+// We shouldn't be able to instantiate abstract class Foo.
+$class = 'Foo';
+try {
+ $obj = eval("new $class();");
+ check::fail("Should not be able to instantiate abstract class $class");
+} catch (Error $e) {
+ check::equal($e->getMessage(), "Cannot instantiate abstract class $class", "Unexpected exception: {$e->getMessage()}");
+}
+
+$spam=new Spam();
check::equal(0,$spam->blah(),"spam object method");
check::done();
-?>
diff --git a/Examples/test-suite/php/abstract_inherit_runme.php b/Examples/test-suite/php/abstract_inherit_runme.php
index 514bbc3b0..376a2adaa 100644
--- a/Examples/test-suite/php/abstract_inherit_runme.php
+++ b/Examples/test-suite/php/abstract_inherit_runme.php
@@ -1,14 +1,19 @@
<?php
require "tests.php";
-require "abstract_inherit.php";
check::classes(array('Foo','Bar','Spam','NRFilter_i','NRRCFilter_i','NRRCFilterpro_i','NRRCFilterpri_i'));
-// This constructor attempt should fail as there isn't one
-//$spam=new Spam();
-//check::equal(0,$spam->blah(),"spam object method");
-//check::equal(0,Spam::blah($spam),"spam class method");
+// We shouldn't be able to instantiate any of these classes since they are all
+// abstract (in each case there's a pure virtual function in the base class
+// which isn't implemented).
+foreach (array('Foo','Bar','Spam','NRFilter_i','NRRCFilter_i','NRRCFilterpro_i','NRRCFilterpri_i')as $class) {
+ try {
+ $obj = eval("new $class();");
+ check::fail("Should not be able to instantiate abstract class $class");
+ } catch (Error $e) {
+ check::equal($e->getMessage(), "Cannot instantiate abstract class $class", "Unexpected exception: {$e->getMessage()}");
+ }
+}
check::done();
-?>
diff --git a/Examples/test-suite/php/add_link_runme.php b/Examples/test-suite/php/add_link_runme.php
index 3e16fa1df..073dee36d 100644
--- a/Examples/test-suite/php/add_link_runme.php
+++ b/Examples/test-suite/php/add_link_runme.php
@@ -1,10 +1,9 @@
<?php
require "tests.php";
-require "add_link.php";
-// No new functions, except the flat functions
-check::functions(array('new_foo','foo_blah'));
+// No new functions
+check::functions(array());
check::classes(array('Foo'));
@@ -19,4 +18,3 @@ check::is_a($foo_blah,'foo');
//check::is_a($class_foo_blah,foo);
check::done();
-?>
diff --git a/Examples/test-suite/php/argcargvtest_runme.php b/Examples/test-suite/php/argcargvtest_runme.php
new file mode 100644
index 000000000..dac427098
--- /dev/null
+++ b/Examples/test-suite/php/argcargvtest_runme.php
@@ -0,0 +1,44 @@
+<?php
+
+require "tests.php";
+
+// New functions
+check::functions(array('mainc', 'mainv', 'initializeapp'));
+// New classes
+check::classes(array('argcargvtest'));
+// No new vars
+check::globals(array());
+
+$largs = array('hi', 'hola', 'hello');
+check::equal(mainc($largs), 3, 'Test main typemap 1');
+
+$targs = array('hi', 'hola');
+check::equal(mainv($targs, 0), 'hi', 'Test main typemap 2a');
+check::equal(mainv($targs, 1), 'hola', 'Test main typemap 2b');
+check::equal(mainv($targs, 2), '<<NULL>>', 'Test main typemap 2c');
+
+$error = 0;
+try {
+ mainv('hello', 1);
+ $error = 1;
+}
+catch (exception $e) {
+}
+check::equal($error, 0, 'Test main typemap 3');
+
+initializeApp($largs);
+
+# Check that an empty array works.
+$empty_args = [];
+check::equal(mainc($empty_args), 0, "test main typemap 4");
+check::equal(mainv($empty_args, 0), '<<NULL>>', 'Test main typemap 4a');
+
+# Check that empty strings are handled.
+$empty_string = ["hello", "", "world"];
+check::equal(mainc($empty_string), 3, "test main typemap 5");
+check::equal(mainv($empty_string, 0), "hello", "test main typemap 6a");
+check::equal(mainv($empty_string, 1), "", "test main typemap 6b");
+check::equal(mainv($empty_string, 2), "world", "test main typemap 6c");
+check::equal(mainv($empty_string, 3), "<<NULL>>", "test main typemap 6d");
+
+check::done();
diff --git a/Examples/test-suite/php/argout_runme.php b/Examples/test-suite/php/argout_runme.php
index 8b66613fd..554d07756 100644
--- a/Examples/test-suite/php/argout_runme.php
+++ b/Examples/test-suite/php/argout_runme.php
@@ -1,7 +1,6 @@
<?php
require "tests.php";
-require "argout.php";
check::functions(array('incp','incr','inctr','new_intp','copy_intp','delete_intp','intp_assign','intp_value','voidhandle','handle'));
@@ -21,18 +20,14 @@ $tr=copy_intp(4);
check::equal(4,inctr($tr),"4==incr($tr)");
check::equal(5,intp_value($tr),"5==$tr");
-# Check the voidhandle call, first with null
-unset($handle);
-# FIXME: Call-time pass-by-reference has been deprecated for ages, and was
-# removed in PHP 5.4. We need to rework
-#voidhandle(&$handle);
-#check::resource($handle,"_p_void",'$handle is not _p_void');
-#$handledata=handle($handle);
-#check::equal($handledata,"Here it is","\$handledata != \"Here it is\"");
-
+# Check the voidhandle call, first with NULL and then with the SWIG\p_void we
+# get from the first call.
$handle=NULL;
-voidhandle($handle);
-check::isnull($handle,'$handle not null');
+for ($i=0; $i != 1; $i++) {
+ voidhandle($handle);
+ check::equal(get_class($handle),"SWIG\\_p_void",'$handle is not _p_void');
+ $handledata=handle($handle);
+ check::equal($handledata,"Here it is","\$handledata != \"Here it is\"");
+}
check::done();
-?>
diff --git a/Examples/test-suite/php/arrayptr_runme.php b/Examples/test-suite/php/arrayptr_runme.php
deleted file mode 100644
index 86b7f8628..000000000
--- a/Examples/test-suite/php/arrayptr_runme.php
+++ /dev/null
@@ -1,14 +0,0 @@
-<?php
-
-require "tests.php";
-require "arrayptr.php";
-
-// No new functions
-check::functions(array('foo'));
-// No new classes
-check::classes(array());
-// now new vars
-check::globals(array());
-
-check::done();
-?>
diff --git a/Examples/test-suite/php/arrays_global_runme.php b/Examples/test-suite/php/arrays_global_runme.php
index 95a300775..6a97db91e 100644
--- a/Examples/test-suite/php/arrays_global_runme.php
+++ b/Examples/test-suite/php/arrays_global_runme.php
@@ -1,11 +1,11 @@
<?php
require "tests.php";
-require "arrays_global.php";
-check::functions(array('test_a','test_b','new_simplestruct','new_material'));
+check::functions(array('test_a','test_b'));
check::classes(array('arrays_global','SimpleStruct','Material'));
-check::globals(array('array_c','array_sc','array_uc','array_s','array_us','array_i','array_ui','array_l','array_ul','array_ll','array_f','array_d','array_struct','array_structpointers','array_ipointers','array_enum','array_enumpointers','array_const_i','beginstring_fix44a','beginstring_fix44b','beginstring_fix44c','beginstring_fix44d','beginstring_fix44e','beginstring_fix44f','chitmat','hitmat_val','hitmat','simplestruct_double_field'));
+check::globals(array('array_c','array_sc','array_uc','array_s','array_us','array_i','array_ui','array_l','array_ul','array_ll','array_f','array_d','array_struct','array_structpointers','array_ipointers','array_enum','array_enumpointers','array_const_i','BeginString_FIX44a','BeginString_FIX44b','BeginString_FIX44c','BeginString_FIX44d','BeginString_FIX44e','BeginString_FIX44f','chitMat','hitMat_val','hitMat'));
+
// The size of array_c is 2, but the last byte is \0, so we can only store a
// single byte string in it.
check::set("array_c","Z");
@@ -16,4 +16,3 @@ check::set("array_c","h");
check::equal("h",check::get("array_c"),"set array_c");
check::done();
-?>
diff --git a/Examples/test-suite/php/arrays_global_twodim_runme.php b/Examples/test-suite/php/arrays_global_twodim_runme.php
index d9f50a6de..e6fbf52d9 100644
--- a/Examples/test-suite/php/arrays_global_twodim_runme.php
+++ b/Examples/test-suite/php/arrays_global_twodim_runme.php
@@ -1,11 +1,11 @@
<?php
require "tests.php";
-require "arrays_global_twodim.php";
-check::functions(array('fn_taking_arrays','get_2d_array','new_simplestruct','new_material'));
+check::functions(array('fn_taking_arrays','get_2d_array',));
check::classes(array('arrays_global_twodim','SimpleStruct','Material'));
-check::globals(array('array_c','array_sc','array_uc','array_s','array_us','array_i','array_ui','array_l','array_ul','array_ll','array_f','array_d','array_struct','array_structpointers','array_ipointers','array_enum','array_enumpointers','array_const_i','chitmat','hitmat_val','hitmat','simplestruct_double_field'));
+check::globals(array('array_c','array_sc','array_uc','array_s','array_us','array_i','array_ui','array_l','array_ul','array_ll','array_f','array_d','array_struct','array_structpointers','array_ipointers','array_enum','array_enumpointers','array_const_i','chitMat','hitMat_val','hitMat'));
+
$a1=array(10,11,12,13);
$a2=array(14,15,16,17);
$a=array($a1,$a2);
@@ -19,4 +19,3 @@ for($x=0;$x<count($a1);$x++) {
}
check::done();
-?>
diff --git a/Examples/test-suite/php/arrays_runme.php b/Examples/test-suite/php/arrays_runme.php
index c6e9e8f70..1d9e44d76 100644
--- a/Examples/test-suite/php/arrays_runme.php
+++ b/Examples/test-suite/php/arrays_runme.php
@@ -1,10 +1,10 @@
<?php
+
require "tests.php";
-require "arrays.php";
check::functions(array('fn_taking_arrays','newintpointer','setintfrompointer','getintfrompointer','array_pointer_func'));
check::classes(array('arrays','SimpleStruct','ArrayStruct','CartPoseData_t'));
-check::globals(array('simplestruct_double_field','arraystruct_array_c','arraystruct_array_sc','arraystruct_array_uc','arraystruct_array_s','arraystruct_array_us','arraystruct_array_i','arraystruct_array_ui','arraystruct_array_l','arraystruct_array_ul','arraystruct_array_ll','arraystruct_array_f','arraystruct_array_d','arraystruct_array_struct','arraystruct_array_structpointers','arraystruct_array_ipointers','arraystruct_array_enum','arraystruct_array_enumpointers','arraystruct_array_const_i','cartposedata_t_p'));
+check::globals(array('array_shifted_size'));
$ss=new simplestruct();
check::classname('simplestruct',$ss);
@@ -15,4 +15,3 @@ check::equal($as->array_c,"a",'$as->array_c=="a"');
check::equal(isset($as->array_const_i),TRUE,'isset($as->array_const_i)');
check::done();
-?>
diff --git a/Examples/test-suite/php/arrays_scope_runme.php b/Examples/test-suite/php/arrays_scope_runme.php
index 11c180870..8455b837c 100644
--- a/Examples/test-suite/php/arrays_scope_runme.php
+++ b/Examples/test-suite/php/arrays_scope_runme.php
@@ -1,16 +1,18 @@
<?php
require "tests.php";
-require "arrays_scope.php";
-// New functions
-check::functions(array('new_bar','bar_blah'));
+// No new functions
+check::functions(array());
// New classes
check::classes(array('arrays_scope','Bar'));
-// New vars
-check::globals(array('bar_adata','bar_bdata','bar_cdata'));
+// No new globals
+check::globals(array());
$bar=new bar();
+$bar->blah($bar->adata, $bar->bdata, $bar->cdata);
+// Like C/C++, SWIG treats `int asize[ASIZE]` as `int*` so there's no checking
+// of the passed array size.
+$bar->blah($bar->bdata, $bar->cdata, $bar->adata);
check::done();
-?>
diff --git a/Examples/test-suite/php/callback_runme.php b/Examples/test-suite/php/callback_runme.php
index fefa32502..717185649 100644
--- a/Examples/test-suite/php/callback_runme.php
+++ b/Examples/test-suite/php/callback_runme.php
@@ -1,9 +1,10 @@
<?php
require "tests.php";
-require "callback.php";
+
// In 2.0.6 and earlier, the constant was misnamed.
-if (gettype(callback::FOO_I_Cb_Ptr) !== 'resource') die("callback::FOO_I_Cb_Ptr not a resource\n");
+check::equal(gettype(callback::FOO_I_Cb_Ptr), 'object', "callback::FOO_I_Cb_Ptr not an object");
+
+check::equal(get_class(callback::FOO_I_Cb_Ptr), 'SWIG\_p_f_int__int', "callback::FOO_I_Cb_Ptr not expected class");
check::done();
-?>
diff --git a/Examples/test-suite/php/casts_runme.php b/Examples/test-suite/php/casts_runme.php
index a9623a328..6234f0fab 100644
--- a/Examples/test-suite/php/casts_runme.php
+++ b/Examples/test-suite/php/casts_runme.php
@@ -1,13 +1,12 @@
<?php
require "tests.php";
-require "casts.php";
// No new functions
-check::functions(array('new_a','a_hello','new_b'));
-// No new classes
+check::functions(array());
+// New classes
check::classes(array('A','B'));
-// now new vars
+// No new vars
check::globals(array());
# Make sure $b inherits hello() from class A
@@ -15,4 +14,3 @@ $b=new B();
$b->hello();
check::done();
-?>
diff --git a/Examples/test-suite/php/catches_strings_runme.php b/Examples/test-suite/php/catches_strings_runme.php
new file mode 100644
index 000000000..758c3f618
--- /dev/null
+++ b/Examples/test-suite/php/catches_strings_runme.php
@@ -0,0 +1,23 @@
+<?php
+
+require "tests.php";
+
+$exception_thrown = false;
+try {
+ StringsThrower::charstring();
+} catch (Exception $e) {
+ check::equal($e->getMessage(), "charstring message", "incorrect exception message: {$e->getMessage()}");
+ $exception_thrown = true;
+}
+check::equal($exception_thrown, true, "Should have thrown an exception");
+
+$exception_thrown = false;
+try {
+ StringsThrower::stdstring();
+} catch (Exception $e) {
+ check::equal($e->getMessage(), "stdstring message", "incorrect exception message: {$e->getMessage()}");
+ $exception_thrown = true;
+}
+check::equal($exception_thrown, true, "Should have thrown an exception");
+
+check::done();
diff --git a/Examples/test-suite/php/char_binary_runme.php b/Examples/test-suite/php/char_binary_runme.php
new file mode 100644
index 000000000..87c3fd40a
--- /dev/null
+++ b/Examples/test-suite/php/char_binary_runme.php
@@ -0,0 +1,39 @@
+<?php
+
+require "tests.php";
+
+check::functions(array('new_pchar', 'delete_pchar', 'pchar_getitem', 'pchar_setitem'));
+
+check::classes(array('Test', 'char_binary'));
+
+$t = new Test();
+$str = 'hile';
+check::equal(4, $t->strlen($str), "bad multi-arg typemap");
+check::equal(4, $t->ustrlen($str), "bad multi-arg typemap");
+check::equal(4, $t->strlen("hil\000"), "bad multi-arg typemap");
+check::equal(4, $t->ustrlen("hil\000"), "bad multi-arg typemap");
+
+// creating a raw char*
+$pc = new_pchar(5);
+pchar_setitem($pc, 0, 'h');
+pchar_setitem($pc, 1, 'o');
+pchar_setitem($pc, 2, 'l');
+pchar_setitem($pc, 3, 'a');
+pchar_setitem($pc, 4, 0);
+
+// FIXME: These don't work as we get the stringified pointer object, e.g.
+// "SWIGPointer(0x55dafc88c0a0,owned=0"
+if (0) {
+ check::equal($t->strlen($pc), 4, "bad multi-arg typemap");
+ check::equal($t->ustrlen($pc), 4, "bad multi-arg typemap");
+
+ var_pchar_set($pc);
+ check::equal(var_pchar_get(), "hola", "bad pointer case");
+
+ var_namet_set($pc);
+ check::equal(var_namet_get(), "hola", "bad pointer case");
+}
+
+delete_pchar($pc);
+
+check::done();
diff --git a/Examples/test-suite/php/char_strings_runme.php b/Examples/test-suite/php/char_strings_runme.php
index e06ee9d2b..7dc8fe74d 100644
--- a/Examples/test-suite/php/char_strings_runme.php
+++ b/Examples/test-suite/php/char_strings_runme.php
@@ -1,7 +1,6 @@
<?php
require "tests.php";
-require "char_strings.php";
$CPLUSPLUS_MSG = "A message from the deep dark world of C++, where anything is possible.";
$OTHERLAND_MSG_10 = "Little message from the safe world.10";
@@ -40,4 +39,3 @@ check::equal(GetConstCharPointerRef(), $CPLUSPLUS_MSG, "failed GetConstCharPoint
check::equal(SetConstCharPointerRef($OTHERLAND_MSG_10, 10), true, "failed SetConstCharPointerRef");
check::done();
-?>
diff --git a/Examples/test-suite/php/class_ignore_runme.php b/Examples/test-suite/php/class_ignore_runme.php
index ae4881f27..f52bc1a13 100644
--- a/Examples/test-suite/php/class_ignore_runme.php
+++ b/Examples/test-suite/php/class_ignore_runme.php
@@ -1,9 +1,8 @@
<?php
require "tests.php";
-require "class_ignore.php";
-check::functions(array('do_blah','new_bar','bar_blah','new_boo','boo_away','new_far','new_hoo'));
+check::functions(array('do_blah'));
check::classes(array('class_ignore','Bar','Boo','Far','Hoo'));
// No new vars
check::globals(array());
@@ -13,4 +12,3 @@ do_blah($bar);
check::classparent($bar,"");
check::done();
-?>
diff --git a/Examples/test-suite/php/constant_expr_c_runme.php b/Examples/test-suite/php/constant_expr_c_runme.php
new file mode 100644
index 000000000..877d13b49
--- /dev/null
+++ b/Examples/test-suite/php/constant_expr_c_runme.php
@@ -0,0 +1,15 @@
+<?php
+
+require "tests.php";
+
+// New functions
+check::functions(array('xx', 'yy'));
+// New classes
+check::classes(array('constant_expr_c'));
+// New vars
+check::globals(array('X','d_array','s1a','s2a','s2b','s3a','s3b','s4a','s4b','s5a','s5b','s6a','s6b','s7a','s7b','s8a','s8b'));
+
+check::equal(XX, xx());
+check::equal(YY, yy());
+
+check::done();
diff --git a/Examples/test-suite/php/conversion_namespace_runme.php b/Examples/test-suite/php/conversion_namespace_runme.php
index e21ff7438..858bf89d9 100644
--- a/Examples/test-suite/php/conversion_namespace_runme.php
+++ b/Examples/test-suite/php/conversion_namespace_runme.php
@@ -1,7 +1,6 @@
<?php
require "tests.php";
-require "conversion_namespace.php";
check::classes(array("Foo","Bar"));
$bar=new Bar;
@@ -10,4 +9,3 @@ $foo=$bar->toFoo();
check::classname("foo",$foo);
check::done();
-?>
diff --git a/Examples/test-suite/php/conversion_ns_template_runme.php b/Examples/test-suite/php/conversion_ns_template_runme.php
index 9702eedb7..4157b106a 100644
--- a/Examples/test-suite/php/conversion_ns_template_runme.php
+++ b/Examples/test-suite/php/conversion_ns_template_runme.php
@@ -1,10 +1,8 @@
<?php
require "tests.php";
-require "conversion_ns_template.php";
check::classes(array("conversion_ns_template","Foo_One","Bar_One","Hi"));
// this is too hard, I'm not sure what to test for,
check::done();
-?>
diff --git a/Examples/test-suite/php/conversion_runme.php b/Examples/test-suite/php/conversion_runme.php
index 1a10ff4f4..858bf89d9 100644
--- a/Examples/test-suite/php/conversion_runme.php
+++ b/Examples/test-suite/php/conversion_runme.php
@@ -1,7 +1,6 @@
<?php
require "tests.php";
-require "conversion.php";
check::classes(array("Foo","Bar"));
$bar=new Bar;
@@ -10,4 +9,3 @@ $foo=$bar->toFoo();
check::classname("foo",$foo);
check::done();
-?>
diff --git a/Examples/test-suite/php/cpp11_attribute_specifiers_runme.php b/Examples/test-suite/php/cpp11_attribute_specifiers_runme.php
new file mode 100644
index 000000000..2336b319a
--- /dev/null
+++ b/Examples/test-suite/php/cpp11_attribute_specifiers_runme.php
@@ -0,0 +1,14 @@
+<?php
+
+require "tests.php";
+
+// New functions
+check::functions(array('noReturn','noDiscard','noDiscardDeprecated','maybeUnused1','maybeUnused2','likely','test_string_literal'));
+// New classes
+check::classes(array('cpp11_attribute_specifiers','S'));
+// No new vars
+check::globals(array());
+
+check::equal(test_string_literal(), 'Test [[ and ]] in string literal', "test_string_literal() wrong");
+
+check::done();
diff --git a/Examples/test-suite/php/cpp11_auto_variable_runme.php b/Examples/test-suite/php/cpp11_auto_variable_runme.php
new file mode 100644
index 000000000..4e2d489ea
--- /dev/null
+++ b/Examples/test-suite/php/cpp11_auto_variable_runme.php
@@ -0,0 +1,40 @@
+<?php
+
+require "tests.php";
+
+// No new functions
+check::functions(array());
+check::classes(array('cpp11_auto_variable'));
+check::globals(array('f', 't', 'zero', 'one', 'la', 'da', 'fa', 'lc', 'dc', 'fc', 'pi_approx', 'Bar', 'Bar2', 'Bar3', 'Foo', 'Foo2', 'Foo3'));
+
+check::equal(f_get(), false);
+check::equal(gettype(f_get()), "boolean");
+check::equal(t_get(), true);
+check::equal(gettype(t_get()), "boolean");
+
+t_set(false);
+check::equal(t_get(), false);
+
+check::equal(function_exists('f_set'), false, "f should be constant but f_set() exists");
+
+check::equal(zero_get(), 0);
+check::equal(gettype(zero_get()), "integer");
+check::equal(one_get(), 1);
+check::equal(gettype(one_get()), "integer");
+
+zero_set(42);
+check::equal(zero_get(), 42);
+
+check::equal(function_exists('one_set'), false, "one should be constant but one_set() exists");
+
+check::equal(fa_get(), 1.0);
+check::equal(da_get(), 1.0);
+// PHP doesn't have a native "long double" type, so SWIG/PHP doesn't have
+// typemaps for it and so it should get wrapped as an opaque type.
+check::str_contains(la_get(), "SWIGPointer(");
+
+check::equal(fc_get(), 1.0);
+check::equal(dc_get(), 1.0);
+// PHP doesn't have a native "long double" type, so SWIG/PHP doesn't have
+// typemaps for it and so it should get wrapped as an opaque type.
+check::str_contains(lc_get(), "SWIGPointer(");
diff --git a/Examples/test-suite/php/cpp11_decltype_runme.php b/Examples/test-suite/php/cpp11_decltype_runme.php
new file mode 100644
index 000000000..6c19f0651
--- /dev/null
+++ b/Examples/test-suite/php/cpp11_decltype_runme.php
@@ -0,0 +1,62 @@
+<?php
+
+require "tests.php";
+
+// No new functions
+check::functions(array());
+check::classes(array('A', 'B'));
+// No new vars
+check::globals(array());
+
+$a = new A();
+
+$a->i = 5;
+check::equal($a->i, 5, 'Assignment to $a->i failed.');
+
+$a->j = 10;
+check::equal($a->j, 10, 'Assignment to $a->j failed.');
+
+$n = $a->get_number(5);
+check::equal($n, 10, 'get_number(5) should return 10.');
+
+$n = $a->get_number(6);
+check::equal($n, 0, 'get_number(6) should return 0.');
+
+$b = new B();
+
+check::equal($b->a, false);
+
+check::equal($b->b, true);
+
+$b->ij = 42;
+check::equal($b->ij, 42, 'Assignment to $b->ij failed.');
+
+$b->i = 7;
+$b->j = 17;
+$n = $b->get_number_sum(0);
+check::equal($n, 24, '$b->get_number_sum(0) should return 24.');
+
+check::equal($b->negate(true), false);
+
+check::equal($b->negate(false), true);
+
+check::equal(gettype($b->should_be_int), "integer");
+check::equal(gettype($b->should_be_int2), "integer");
+check::equal(gettype($b->should_be_int3), "integer");
+check::equal(gettype($b->should_be_int4), "integer");
+check::equal(gettype($b->should_be_int5), "integer");
+check::equal(gettype($b->should_be_int6), "integer");
+check::equal(gettype($b->should_be_int7), "integer");
+check::equal(gettype($b->should_be_int8), "integer");
+check::equal(gettype($b->should_be_int9), "integer");
+check::equal(gettype($b->should_be_int10), "integer");
+
+check::equal(gettype($b->should_be_bool), "boolean");
+
+check::equal(gettype($b::should_be_char), "string");
+check::equal($b::should_be_char, "\0");
+
+check::equal(gettype($b::should_be_string), "string");
+check::equal($b::should_be_string, "xyzzy");
+
+check::equal(gettype($b->should_be_enum), "integer");
diff --git a/Examples/test-suite/php/cpp11_final_directors_runme.php b/Examples/test-suite/php/cpp11_final_directors_runme.php
new file mode 100644
index 000000000..07e04b15f
--- /dev/null
+++ b/Examples/test-suite/php/cpp11_final_directors_runme.php
@@ -0,0 +1,16 @@
+<?php
+
+require "tests.php";
+
+// No new functions
+check::functions(array());
+check::classes(array('Base','BaseFinalDestructor','BaseFinalDestructor2','Derived'));
+// No new vars
+check::globals(array());
+
+class Derived2 extends Derived {
+ function meth() { return 3; }
+}
+
+$b = new Derived2();
+check::equal($b->meth(), 3, "Wrong return value");
diff --git a/Examples/test-suite/php/cpp11_move_typemaps_runme.php b/Examples/test-suite/php/cpp11_move_typemaps_runme.php
new file mode 100644
index 000000000..2d4b5e090
--- /dev/null
+++ b/Examples/test-suite/php/cpp11_move_typemaps_runme.php
@@ -0,0 +1,32 @@
+<?php
+
+require "tests.php";
+
+Counter::reset_counts();
+$mo = new MoveOnly(111);
+Counter::check_counts(1, 0, 0, 0, 0, 0);
+MoveOnly::take($mo);
+Counter::check_counts(1, 0, 0, 1, 0, 2);
+$mo = NULL;
+Counter::check_counts(1, 0, 0, 1, 0, 2);
+
+Counter::reset_counts();
+$mo = new MovableCopyable(111);
+Counter::check_counts(1, 0, 0, 0, 0, 0);
+MovableCopyable::take($mo);
+Counter::check_counts(1, 0, 0, 1, 0, 2);
+$mo = NULL;
+Counter::check_counts(1, 0, 0, 1, 0, 2);
+
+$mo = new MoveOnly(222);
+MoveOnly::take($mo);
+$exception_thrown = false;
+try {
+ MoveOnly::take($mo);
+} catch (TypeError $e) {
+ check::str_contains($e->getMessage(), "Cannot release ownership as memory is not owned", "incorrect exception message: {$e->getMessage()}");
+ $exception_thrown = true;
+}
+check::equal($exception_thrown, true, "double usage of takeKlassUniquePtr should have been an error");
+
+check::done();
diff --git a/Examples/test-suite/php/cpp11_rvalue_reference_move_runme.php b/Examples/test-suite/php/cpp11_rvalue_reference_move_runme.php
new file mode 100644
index 000000000..38bb758ed
--- /dev/null
+++ b/Examples/test-suite/php/cpp11_rvalue_reference_move_runme.php
@@ -0,0 +1,80 @@
+<?php
+
+require "tests.php";
+
+# Function containing rvalue reference parameter
+Counter::reset_counts();
+$mo = new MovableCopyable(222);
+Counter::check_counts(1, 0, 0, 0, 0, 0);
+MovableCopyable::movein($mo);
+Counter::check_counts(1, 0, 0, 1, 0, 2);
+try {
+ MovableCopyable::is_nullptr($mo);
+ check::fail("is_nullptr check");
+} catch (TypeError $e) {
+}
+$mo = NULL;
+Counter::check_counts(1, 0, 0, 1, 0, 2);
+
+# Move constructor test
+Counter::reset_counts();
+$mo = new MovableCopyable(222);
+Counter::check_counts(1, 0, 0, 0, 0, 0);
+$mo_moved = new MovableCopyable($mo);
+Counter::check_counts(1, 0, 0, 1, 0, 1);
+try {
+ MovableCopyable::is_nullptr($mo);
+ check::fail("is_nullptr check");
+} catch (TypeError $e) {
+}
+$mo = NULL;
+Counter::check_counts(1, 0, 0, 1, 0, 1);
+$mo_moved = NULL;
+Counter::check_counts(1, 0, 0, 1, 0, 2);
+
+# Move assignment operator test
+Counter::reset_counts();
+$mo111 = new MovableCopyable(111);
+$mo222 = new MovableCopyable(222);
+Counter::check_counts(2, 0, 0, 0, 0, 0);
+$mo111->MoveAssign($mo222);
+Counter::check_counts(2, 0, 0, 0, 1, 1);
+try {
+ MovableCopyable::is_nullptr($mo222);
+ check::fail("is_nullptr check");
+} catch (TypeError $e) {
+}
+$mo222 = NULL;
+Counter::check_counts(2, 0, 0, 0, 1, 1);
+$mo111 = NULL;
+Counter::check_counts(2, 0, 0, 0, 1, 2);
+
+# null check
+Counter::reset_counts();
+$exception_thrown = false;
+try {
+ MovableCopyable::movein(NULL);
+} catch (TypeError $e) {
+ check::str_contains($e->getMessage(), "Invalid null reference", "incorrect exception message: {$e->getMessage()}");
+ $exception_thrown = true;
+}
+check::equal($exception_thrown, true, "Should have thrown null error");
+Counter::check_counts(0, 0, 0, 0, 0, 0);
+
+# output
+Counter::reset_counts();
+$mc = MovableCopyable::moveout(1234);
+Counter::check_counts(2, 0, 0, 0, 1, 1);
+MovableCopyable::check_numbers_match($mc, 1234);
+
+$exception_thrown = false;
+try {
+ MovableCopyable::movein($mc);
+} catch (TypeError $e) {
+ check::str_contains($e->getMessage(), "Cannot release ownership as memory is not owned", "incorrect exception message: {$e->getMessage()}");
+ $exception_thrown = true;
+}
+check::equal($exception_thrown, true, "Should have thrown 'Cannot release ownership as memory is not owned' error");
+Counter::check_counts(2, 0, 0, 0, 1, 1);
+
+check::done();
diff --git a/Examples/test-suite/php/cpp11_std_unique_ptr_runme.php b/Examples/test-suite/php/cpp11_std_unique_ptr_runme.php
new file mode 100644
index 000000000..425f6535f
--- /dev/null
+++ b/Examples/test-suite/php/cpp11_std_unique_ptr_runme.php
@@ -0,0 +1,108 @@
+<?php
+
+require "tests.php";
+
+function checkCount($expected_count) {
+ $actual_count = Klass::getTotal_count();
+ check::equal($actual_count, $expected_count, "Counts incorrect");
+}
+
+# Test raw pointer handling involving virtual inheritance
+$kini = new KlassInheritance("KlassInheritanceInput");
+checkCount(1);
+$s = useKlassRawPtr($kini);
+check::equal($s, "KlassInheritanceInput", "Incorrect string: $s");
+$kini = NULL;
+checkCount(0);
+
+
+# unique_ptr as input
+$kin = new Klass("KlassInput");
+checkCount(1);
+$s = takeKlassUniquePtr($kin);
+checkCount(0);
+check::equal($s, "KlassInput", "Incorrect string: $s");
+try {
+ is_nullptr($kin);
+ check::fail("is_nullptr check");
+} catch (TypeError $e) {
+}
+$kin = NULL; # Should not fail, even though already deleted
+checkCount(0);
+
+$kin = new Klass("KlassInput");
+checkCount(1);
+$s = takeKlassUniquePtr($kin);
+checkCount(0);
+check::equal($s, "KlassInput", "Incorrect string: $s");
+try {
+ is_nullptr($kin);
+ check::fail("is_nullptr check");
+} catch (TypeError $e) {
+}
+$exception_thrown = false;
+try {
+ takeKlassUniquePtr($kin);
+} catch (TypeError $e) {
+ check::equal($e->getMessage(), "Cannot release ownership as memory is not owned for argument 1 of SWIGTYPE_p_Klass of takeKlassUniquePtr", "Unexpected exception: {$e->getMessage()}");
+ $exception_thrown = true;
+}
+check::equal($exception_thrown, true, "double usage of takeKlassUniquePtr should have been an error");
+$kin = NULL; # Should not fail, even though already deleted
+checkCount(0);
+
+$kin = new Klass("KlassInput");
+$exception_thrown = false;
+$notowned = get_not_owned_ptr($kin);
+try {
+ takeKlassUniquePtr($notowned);
+} catch (TypeError $e) {
+ check::equal($e->getMessage(), "Cannot release ownership as memory is not owned for argument 1 of SWIGTYPE_p_Klass of takeKlassUniquePtr", "Unexpected exception: {$e->getMessage()}");
+ $exception_thrown = true;
+}
+check::equal($exception_thrown, true, "double usage of takeKlassUniquePtr should have been an error");
+checkCount(1);
+$kin = NULL;
+checkCount(0);
+
+$kini = new KlassInheritance("KlassInheritanceInput");
+checkCount(1);
+$s = takeKlassUniquePtr($kini);
+checkCount(0);
+check::equal($s, "KlassInheritanceInput", "Incorrect string: $s");
+try {
+ is_nullptr($kini);
+ check::fail("is_nullptr check");
+} catch (TypeError $e) {
+}
+
+$kini = NULL; # Should not fail, even though already deleted
+checkCount(0);
+
+takeKlassUniquePtr(NULL);
+takeKlassUniquePtr(make_null());
+checkCount(0);
+
+# overloaded parameters
+check::equal(overloadTest(), 0, "overloadTest failed");
+check::equal(overloadTest(NULL), 1, "overloadTest failed");
+check::equal(overloadTest(new Klass("over")), 1, "overloadTest failed");
+checkCount(0);
+
+
+# unique_ptr as output
+$k1 = makeKlassUniquePtr("first");
+$k2 = makeKlassUniquePtr("second");
+checkCount(2);
+
+$k1 = NULL;
+checkCount(1);
+
+check::equal($k2->getLabel(), "second", "proper label");
+
+$k2 = NULL;
+checkCount(0);
+
+check::equal(makeNullUniquePtr(), NULL);
+
+check::done();
diff --git a/Examples/test-suite/php/cpp11_strongly_typed_enumerations_runme.php b/Examples/test-suite/php/cpp11_strongly_typed_enumerations_runme.php
index bee59b209..ca327d502 100644
--- a/Examples/test-suite/php/cpp11_strongly_typed_enumerations_runme.php
+++ b/Examples/test-suite/php/cpp11_strongly_typed_enumerations_runme.php
@@ -1,7 +1,6 @@
<?php
require "tests.php";
-require "cpp11_strongly_typed_enumerations.php";
function enumCheck($actual, $expected) {
check::equal($actual, $expected, "Enum value mismatch");
@@ -166,4 +165,4 @@ enumCheck(globalTest1(Enum1_Val5a), 13);
enumCheck(globalTest2(Class1::Enum12_Val5c), 1121);
#enumCheck(globalTest3(Class1::Struct1.Enum12_Val5f), 3121);
-?>
+check::done();
diff --git a/Examples/test-suite/php/cpp14_auto_return_type_runme.php b/Examples/test-suite/php/cpp14_auto_return_type_runme.php
new file mode 100644
index 000000000..41d9ed80c
--- /dev/null
+++ b/Examples/test-suite/php/cpp14_auto_return_type_runme.php
@@ -0,0 +1,14 @@
+<?php
+
+require "tests.php";
+
+check::functions(array('va_static_cast'));
+check::classes(array('cpp14_auto_return_type', 'X'));
+check::classmethods("X",array("__construct","__set","__isset","__get","a"));
+
+// No new vars
+check::globals(array());
+
+check::equal(va_static_cast(), 42);
+$x = new X();
+check::equal($x->a(), "a string");
diff --git a/Examples/test-suite/php/cpp17_director_string_view_runme.php b/Examples/test-suite/php/cpp17_director_string_view_runme.php
new file mode 100644
index 000000000..44a4b7b69
--- /dev/null
+++ b/Examples/test-suite/php/cpp17_director_string_view_runme.php
@@ -0,0 +1,42 @@
+<?php
+
+require "tests.php";
+
+// No new functions
+check::functions(array());
+// New classes
+check::classes(array('A'));
+// No new vars
+check::globals(array());
+
+class B extends A {
+ public $smem;
+
+ private $cached_string;
+
+ function get_first() {
+ // Since std::string_view contains a pointer into a string, the string
+ // cannot be a temporary in order to avoid undefined behaviour.
+ $this->cached_string = parent::get_first() . " world!";
+ return $this->cached_string;
+ }
+
+ function process_text($string) {
+ parent::process_text($string);
+ $this->smem = "hello";
+ }
+}
+
+$b = new B("hello");
+
+check::equal($b->get(0), "hello", "get(0) failed");
+
+check::equal($b->get_first(), "hello world!", "get_first failed");
+
+check::equal($b->call_get_first(), "hello world!", "call_get_first failed");
+
+$b->call_process_func();
+
+check::equal($b->smem, "hello", "smem failed");
+
+check::done();
diff --git a/Examples/test-suite/php/cpp17_string_view_runme.php b/Examples/test-suite/php/cpp17_string_view_runme.php
new file mode 100644
index 000000000..ff9b4d2fb
--- /dev/null
+++ b/Examples/test-suite/php/cpp17_string_view_runme.php
@@ -0,0 +1,51 @@
+<?php
+
+require "tests.php";
+
+# Checking expected use of %typemap(in) std::string_view {}
+cpp17_string_view::test_value("Fee");
+
+# Checking expected result of %typemap(out) std::string_view {}
+check::equal(cpp17_string_view::test_value("Fi"), "Fi", "Test 1");
+
+# Checking expected use of %typemap(in) const std::string_view & {}
+cpp17_string_view::test_const_reference("Fo");
+
+# Checking expected result of %typemap(out) const std::string_view& {}
+check::equal(cpp17_string_view::test_const_reference("Fum"), "Fum", "Test 3");
+
+# Input and output typemaps for pointers and non-const references to
+# std::string_view are *not* supported; the following tests confirm
+# that none of these cases are slipping through.
+
+$stringPtr = cpp17_string_view::test_pointer_out();
+
+cpp17_string_view::test_pointer($stringPtr);
+
+$stringPtr = cpp17_string_view::test_const_pointer_out();
+
+cpp17_string_view::test_const_pointer($stringPtr);
+
+$stringPtr = cpp17_string_view::test_reference_out();
+
+cpp17_string_view::test_reference($stringPtr);
+
+// Global variables
+check::equal(ConstGlobalString_get(), "const global string", "ConstGlobalString test");
+
+// Member variables
+$myStructure = new Structure();
+check::equal($myStructure->ConstMemberString, "const member string", "ConstMemberString test");
+
+check::equal(Structure::ConstStaticMemberString(), "const static member string", "ConstStaticMemberString test");
+
+cpp17_string_view::test_const_reference_returning_void("foo");
+
+check::equal(cpp17_string_view::stdstringview_empty(), "", "stdstringview_empty test");
+check::equal(cpp17_string_view::c_empty(), "", "c_empty test");
+check::isnull(cpp17_string_view::c_null(), "c_null test");
+check::isnull(cpp17_string_view::get_null(cpp17_string_view::c_null()), "get_null c_null test");
+check::equal(cpp17_string_view::get_null(cpp17_string_view::c_empty()), "non-null", "get_null c_empty test");
+check::equal(cpp17_string_view::get_null(cpp17_string_view::stdstringview_empty()), "non-null", "get_null stdstringview_empty test");
+
+check::done();
diff --git a/Examples/test-suite/php/cpp20_spaceship_operator_runme.php b/Examples/test-suite/php/cpp20_spaceship_operator_runme.php
new file mode 100644
index 000000000..00484f742
--- /dev/null
+++ b/Examples/test-suite/php/cpp20_spaceship_operator_runme.php
@@ -0,0 +1,23 @@
+<?php
+
+require "tests.php";
+
+check::functions(array('f', 'spaceship'));
+check::classes(array('cpp20_spaceship_operator','A'));
+check::globals(array('v', 'SPACE'));
+
+//check::equal(ALIEN, true);
+check::equal(SPACE_get(), 1);
+check::equal(COMET, 1);
+check::equal(v_get(), 42);
+
+$x = new A(1);
+$y = new A(2);
+
+check::equal(spaceship($x, $y) < 0, true);
+check::equal(spaceship($x, $x), 0);
+check::equal(spaceship($y, $x) > 0, true);
+
+check::equal(f(), 42);
+
+check::done();
diff --git a/Examples/test-suite/php/cpp_basic_runme.php b/Examples/test-suite/php/cpp_basic_runme.php
index b24cf7000..548767ce9 100644
--- a/Examples/test-suite/php/cpp_basic_runme.php
+++ b/Examples/test-suite/php/cpp_basic_runme.php
@@ -1,14 +1,13 @@
<?php
require "tests.php";
-require "cpp_basic.php";
// New functions
-check::functions(array('foo_func1','foo_func2','foo___str__','foosubsub___str__','bar_test','bar_testfoo','get_func1_ptr','get_func2_ptr','test_func_ptr','fl_window_show'));
+check::functions(array('get_func1_ptr','get_func2_ptr','get_const_reference','get_reference','test_func_ptr'));
// New classes
-check::classes(array('cpp_basic','Foo','FooSub','FooSubSub','Bar','Fl_Window'));
-// New vars
-check::globals(array('foo_num','foo_func_ptr','bar_fptr','bar_fref','bar_fval','bar_cint','bar_global_fptr','bar_global_fref','bar_global_fval'));
+check::classes(array('cpp_basic','Foo','FooSub','FooSubSub','Bar','Fl_Window','JustConst'));
+// No new vars
+check::globals(array());
$f = new Foo(3);
$f->func_ptr = get_func1_ptr();
@@ -16,5 +15,18 @@ check::equal(test_func_ptr($f, 7), 2*7*3, "get_func1_ptr() didn't work");
$f->func_ptr = get_func2_ptr();
check::equal(test_func_ptr($f, 7), -7*3, "get_func2_ptr() didn't work");
+// Test that custom properties work when enabled with
+// %feature(php:allowdynamicproperties, 1).
+check::equal($f->custom_prop, NULL, "Test unset custom property");
+$f->custom_prop = "test";
+check::equal($f->custom_prop, "test", "Test custom property setting");
+$f->custom_prop = 42;
+check::equal($f->custom_prop, 42, "Test custom property setting");
+
+// Test that %feature(php:allowdynamicproperties, 0) doesn't enable them
+// (regression test for bug fixed in 4.2.0).
+$b = new Bar();
+$b->custom_prop = 42;
+check::equal($b->custom_prop === 42, false, "Managed to set custom property with %feature(php:allowdynamicproperties, 0)");
+
check::done();
-?>
diff --git a/Examples/test-suite/php/cpp_enum_runme.php b/Examples/test-suite/php/cpp_enum_runme.php
new file mode 100644
index 000000000..5028f6894
--- /dev/null
+++ b/Examples/test-suite/php/cpp_enum_runme.php
@@ -0,0 +1,43 @@
+<?php
+
+require "tests.php";
+
+// New functions
+check::functions(array());
+// New classes
+check::classes(array('cpp_enum', 'StructWithEnums', 'Foo'));
+// New vars
+check::globals(array('hi'));
+
+
+$f = new Foo();
+
+check::equal($f->hola, Foo::Hello);
+
+$f->hola = Foo::Hi;
+check::equal($f->hola, Foo::Hi);
+
+$f->hola = Foo::Hello;
+check::equal($f->hola, Foo::Hello);
+
+$hi = Hello;
+check::equal($hi, Hello);
+
+check::equal(CASE0A, 10);
+check::equal(CASE0B, 10);
+check::equal(CASE0C, 10);
+check::equal(CASE1A, 10);
+check::equal(CASE1B, 10);
+check::equal(CASE1C, 10);
+check::equal(CASE2A, 10);
+check::equal(CASE2B, 10);
+check::equal(CASE2C, 10);
+check::equal(CASE3A, 10);
+check::equal(CASE3B, 10);
+check::equal(CASE3C, 10);
+check::equal(CASE4A, 10);
+check::equal(CASE4B, 10);
+check::equal(CASE4C, 10);
+check::equal(CASE4D, 10);
+
+check::done();
diff --git a/Examples/test-suite/php/cpp_static_runme.php b/Examples/test-suite/php/cpp_static_runme.php
index 20b50dd9e..2687333b0 100644
--- a/Examples/test-suite/php/cpp_static_runme.php
+++ b/Examples/test-suite/php/cpp_static_runme.php
@@ -1,14 +1,12 @@
<?php
require "tests.php";
-require "cpp_static.php";
-// New functions
-check::functions(array('staticfunctiontest_static_func','staticfunctiontest_static_func_2','staticfunctiontest_static_func_3','is_python_builtin','staticmembertest_grab_int','staticbase_grab_statty_base','staticderived_grab_statty_derived'));
+// No new functions
+check::functions(array());
// New classes
check::classes(array('StaticMemberTest','StaticFunctionTest','cpp_static','StaticBase','StaticDerived'));
-// New vars
-check::globals(array('staticmembertest_static_int','staticbase_statty','staticderived_statty'));
+// No new vars
+check::globals(array());
check::done();
-?>
diff --git a/Examples/test-suite/php/default_args_runme.php b/Examples/test-suite/php/default_args_runme.php
new file mode 100644
index 000000000..cf4932209
--- /dev/null
+++ b/Examples/test-suite/php/default_args_runme.php
@@ -0,0 +1,142 @@
+<?php
+require "tests.php";
+
+// New functions
+check::functions(array('doublevalue1','doublevalue2','seek','seek2','seek3','seek4','seek5','seek6','seek7','seek8','seek9','seeka','seekb','anonymous','booltest','casts1','casts2','chartest1','chartest2','chartest3','chartest4','chartest5','chartest6','dummy','afunction','reftest1','reftest2','chops','exceptionspec','constructorcall','cfunc1','cfunc2','cfunc3','slightly_off_square'));
+// New classes
+check::classes(array('TrickyInPython','default_args','EnumClass','DerivedEnumClass','Tree','Foo','MyClass1','MyClass2','Except','Statics','Tricky','Klass','ConstMethods','Pointf','CDA'));
+// New vars
+check::globals(array('CONST_NUM'));
+
+$ec = new EnumClass();
+check::equal($ec->blah(), true, "EnumClass::blah() default arguments don't work");
+
+$de = new DerivedEnumClass();
+$de->accelerate();
+$de->accelerate(EnumClass::SLOW);
+
+check::equal(Statics::staticMethod(), 60, "Statics::staticMethod()");
+
+check::equal(cfunc1(1), 2.0, "cfunc1(1)");
+
+check::equal(cfunc2(1), 3.0, "cfunc2(1)");
+
+check::equal(cfunc3(1), 4.0, "cfunc3(1)");
+
+$f = new Foo();
+
+$f->newname();
+$f->newname(1);
+$f->defaulted1();
+$f->defaulted2();
+
+check::equal($f->double_if_void_ptr_is_null(2, Null), 4, "\$f->double_if_void_ptr_is_null(2, Null)");
+
+check::equal($f->double_if_void_ptr_is_null(3), 6, "\$f->double_if_void_ptr_is_null(3)");
+
+check::equal($f->double_if_void_ptr_is_null(4, Null), 8, "\$f->double_if_void_ptr_is_null(4, Null)");
+
+check::equal($f->double_if_void_ptr_is_null(5, Null), 10, "\$f->double_if_void_ptr_is_null(5, Null)");
+
+check::equal($f->double_if_void_ptr_is_null(6, Null), 12, "\$f->double_if_void_ptr_is_null(6, Null)");
+
+check::equal($f->double_if_void_ptr_is_null(7), 14, "\$f->double_if_void_ptr_is_null(7)");
+
+try {
+ $f = new Foo(1);
+ check::fail("Foo::Foo ignore is not working");
+} catch (ArgumentCountError $e) {
+}
+
+try {
+ $f = new Foo(1, 2);
+ check::fail("Foo::Foo ignore is not working");
+} catch (ArgumentCountError $e) {
+}
+
+try {
+ $f = new Foo(1, 2, 3);
+ check::fail("Foo::Foo ignore is not working");
+} catch (ArgumentCountError $e) {
+}
+
+try {
+ $m = $f->meth(1);
+ check::fail("Foo::meth ignore is not working");
+} catch (Error $e) {
+}
+
+try {
+ $m = $f->meth(1, 2);
+ check::fail("Foo::meth ignore is not working");
+} catch (Error $e) {
+}
+
+try {
+ $m = $f->meth(1, 2, 3);
+ check::fail("Foo::meth ignore is not working");
+} catch (Error $e) {
+}
+
+check::equal(Klass::inc(100, new Klass(22))->val, 122, "Klass::inc failed");
+
+check::equal(klass::inc(100)->val, 99, "klass::inc failed");
+
+check::equal(klass::inc()->val, 0, "klass::inc failed");
+
+$tricky = new TrickyInPython();
+check::equal($tricky->value_m1(10), -1, "trickyvalue_m1 failed");
+check::equal($tricky->value_m1(10, 10), 10, "trickyvalue_m1 failed");
+check::equal($tricky->value_0xabcdef(10), 0xabcdef, "trickyvalue_0xabcdef failed");
+check::equal($tricky->value_0644(10), 420, "trickyvalue_0644 failed");
+check::equal($tricky->value_perm(10), 420, "trickyvalue_perm failed");
+check::equal($tricky->value_m01(10), -1, "trickyvalue_m01 failed");
+check::equal($tricky->booltest2(), True, "booltest2 failed");
+
+check::equal($tricky->max_32bit_int1(), 0x7FFFFFFF, "max_32bit_int1 failed");
+// On 32-bit platforms -2147483648 is a PHP float (rather than
+// PHP int on 64-bit platforms) so only check equivalence rather
+// than strict equality.
+check::equivalent($tricky->min_32bit_int1(), -2147483648, "min_32bit_int1 failed");
+check::equal($tricky->max_32bit_int2(), 0x7FFFFFFF, "max_32bit_int2 failed");
+
+$tricky->too_big_32bit_int1();
+$tricky->too_small_32bit_int1();
+$tricky->too_big_32bit_int2();
+$tricky->too_small_32bit_int2();
+
+seek();
+seek(10);
+
+check::equal(booltest(), True, "booltest failed");
+
+check::equal(slightly_off_square(10), 102, "slightly_off_square(10)");
+
+check::equal(slightly_off_square(), 291, "slightly_off_square()");
+
+check::equal(chartest1(), "x", "chartest1()");
+
+check::equal(chartest2(), "\0", "chartest2()");
+
+check::equal(chartest3(), "\1", "chartest3()");
+
+check::equal(chartest4(), "\n", "chartest4()");
+
+check::equal(chartest5(), "B", "chartest5()");
+
+check::equal(chartest6(), "C", "chartest6()");
+
+// Regression test for bug in initial implementation of PHP type declarations.
+$p = (new ReflectionMethod('TrickyInPython', 'value_m1'))->getParameters();
+// empty array in buggy version
+check::equal(count($p), 2, "Expected 2 parameters");
+check::equal((string)$p[0]->getType(), 'int', "Expected int parameter");
+check::equal((string)$p[1]->getType(), 'int', "Expected int parameter");
+
+$p = (new ReflectionMethod('EnumClass', 'blah'))->getParameters();
+// empty array in buggy version
+check::equal(count($p), 2, "Expected 2 parameters");
+check::equal((string)$p[0]->getType(), 'int', "Expected int parameter");
+check::equal((string)$p[1]->getType(), 'int', "Expected int parameter");
+
+check::done();
diff --git a/Examples/test-suite/php/director_abstract_runme.php b/Examples/test-suite/php/director_abstract_runme.php
index 1a119cfd5..2d9799f2f 100644
--- a/Examples/test-suite/php/director_abstract_runme.php
+++ b/Examples/test-suite/php/director_abstract_runme.php
@@ -1,13 +1,12 @@
<?php
require "tests.php";
-require "director_abstract.php";
-// No new functions
-check::functions(array('foo_ping','foo_pong','example0_getxsize','example0_color','example0_get_color','example1_getxsize','example1_color','example1_get_color','example2_getxsize','example2_color','example2_get_color','example4_getxsize','example4_color','example4_get_color','example3_i_color','example3_i_get_color','g','a_f'));
-// No new classes
+// New functions
+check::functions(array('g'));
+// New classes
check::classes(array('director_abstract','Foo','Example0','Example1','Example2','Example4','Example3_i','A'));
-// now new vars
+// No new vars
check::globals(array());
class MyFoo extends Foo {
@@ -23,19 +22,19 @@ check::equal($a->ping(), "MyFoo::ping()", "MyFoo::ping failed");
check::equal($a->pong(), "Foo::pong();MyFoo::ping()", "MyFoo::pong failed");
class MyExample1 extends Example1 {
- function Color($r, $g, $b) {
+ function Color($r, $g = NULL, $b = NULL) {
return $r;
}
}
class MyExample2 extends Example1 {
- function Color($r, $g, $b) {
+ function Color($r, $g = NULL, $b = NULL) {
return $g;
}
}
class MyExample3 extends Example1 {
- function Color($r, $g, $b) {
+ function Color($r, $g = NULL, $b = NULL) {
return $b;
}
}
@@ -59,4 +58,3 @@ $class = new ReflectionClass('Example3_i');
check::equal($class->isAbstract(), true, "Example3_i abstractness failed");
check::done();
-?>
diff --git a/Examples/test-suite/php/director_alternating_runme.php b/Examples/test-suite/php/director_alternating_runme.php
new file mode 100644
index 000000000..de33038be
--- /dev/null
+++ b/Examples/test-suite/php/director_alternating_runme.php
@@ -0,0 +1,11 @@
+<?php
+
+require "tests.php";
+
+check::functions(array('getBar','idFromGetBar'));
+check::classes(array('Foo','Bar','Baz','director_alternating'));
+// No new vars
+check::globals(array());
+
+$id = director_alternating::getBar()->id();
+check::equal($id, director_alternating::idFromGetBar(), "idFromGetBar() failed");
diff --git a/Examples/test-suite/php/director_basic_runme.php b/Examples/test-suite/php/director_basic_runme.php
index 478a36f80..db7adefc1 100644
--- a/Examples/test-suite/php/director_basic_runme.php
+++ b/Examples/test-suite/php/director_basic_runme.php
@@ -1,14 +1,12 @@
<?php
require "tests.php";
-require "director_basic.php";
// No new functions
-check::functions(array('foo_ping','foo_pong','foo_get_self','a_f','a_rg','a1_ff','myclass_method','myclass_vmethod','myclass_pmethod','myclass_cmethod','myclass_get_self','myclass_call_pmethod','myclasst_i_method','myclass_nonvirtual','myclass_nonoverride','myclass_call_nonvirtual','myclass_call_nonoverride','myclass_connect'));
-// No new classes
-check::classes(array('Foo','A','A1','Bar','MyClass','MyClassT_i'));
-// now new vars
-check::globals(array('bar_x'));
+check::functions(array());
+check::classes(array('Foo','A','A1','Bar','MyClass','MyClassT_i','ConstPtrClass'));
+// No new vars
+check::globals(array());
class PhpFoo extends Foo {
function ping() {
@@ -55,4 +53,3 @@ check::equal($bc->x, 34, "bc failed");
check::equal($bd->x, 16, "bd failed");
check::done();
-?>
diff --git a/Examples/test-suite/php/director_classes_runme.php b/Examples/test-suite/php/director_classes_runme.php
new file mode 100644
index 000000000..c25d85d17
--- /dev/null
+++ b/Examples/test-suite/php/director_classes_runme.php
@@ -0,0 +1,79 @@
+<?php
+require "tests.php";
+
+// No new functions
+check::functions(array());
+// New classes
+check::classes(array('director_classes', 'Base', 'BaseClass', 'Caller', 'Derived', 'DerivedClass', 'DoubleHolder'));
+// New vars
+check::globals(array('PrintDebug'));
+
+class PHPDerived extends Base {
+ function Val(DoubleHolder $x) { return $x; }
+ function Ref(DoubleHolder $x) { return $x; }
+ function Ptr(?DoubleHolder $x) { return $x; }
+ function ConstPtrRef(?DoubleHolder $x) { return $x; }
+ function FullyOverloaded($x) {
+ $rv = parent::FullyOverloaded($x);
+ $rv = preg_replace('/Base/', 'PHPDerived', $rv);
+ return $rv;
+ }
+ function SemiOverloaded($x) {
+ # this is going to be awkward because we can't really
+ # semi-overload in PHP, but we can sort of fake it.
+ if (!is_int($x)) {
+ return parent::SemiOverloaded($x);
+ }
+ $rv = parent::SemiOverloaded($x);
+ $rv = preg_replace('/Base/', 'PHPDerived', $rv);
+ return $rv;
+ }
+ function DefaultParms(int $x, float $y = 1.125) {
+ $rv = parent::DefaultParms($x, $y);
+ $rv = preg_replace('/Base/', 'PHPDerived', $rv);
+ return $rv;
+ }
+}
+
+{
+ $c = new Caller();
+ makeCalls($c, new Base(100.0));
+ makeCalls($c, new Derived(200.0));
+ makeCalls($c, new PHPDerived(300.0));
+}
+
+function makeCalls($caller, $base) {
+ $bname = get_class($base);
+ if ($bname == 'PHPDerived') {
+ // TODO: Debug and make this work:
+ return;
+ }
+ $caller->set($base);
+ $dh = new DoubleHolder(444.555);
+ check::equal($caller->ValCall($dh)->val, $dh->val, "$bname.Val");
+ check::equal($caller->RefCall($dh)->val, $dh->val, "$bname.Ref");
+ check::equal($caller->PtrCall($dh)->val, $dh->val, "$bname.Ptr");
+ check::equal($caller->ConstPtrRefCall($dh)->val, $dh->val, "$bname.ConstPtrRef");
+ check::equal($caller->FullyOverloadedCall(1),
+ "{$bname}::FullyOverloaded(int)",
+ "$bname.FullyOverloaded(int)");
+ check::equal($caller->FullyOverloadedCall(false),
+ "{$bname}::FullyOverloaded(bool)",
+ "$bname.FullyOverloaded(bool)");
+ // This next one is TODO for Perl with PerlDerived.
+ check::equal($caller->SemiOverloadedCall(-678),
+ "{$bname}::SemiOverloaded(int)",
+ "$bname.SemiOverloaded(int)");
+ check::equal($caller->SemiOverloadedCall(false),
+ "Base::SemiOverloaded(bool)",
+ "$bname.SemiOverloaded(bool)");
+ check::equal($caller->DefaultParmsCall(10, 2.2),
+ "{$bname}::DefaultParms(int, double)",
+ "$bname.DefaultParms(int, double)");
+ check::equal($caller->DefaultParmsCall(10),
+ "{$bname}::DefaultParms(int)",
+ "$bname.DefaultParms(int)");
+ $caller->reset();
+}
+
+check::done();
diff --git a/Examples/test-suite/php/director_classic_runme.php b/Examples/test-suite/php/director_classic_runme.php
index a44881e04..e2ac1f7a7 100644
--- a/Examples/test-suite/php/director_classic_runme.php
+++ b/Examples/test-suite/php/director_classic_runme.php
@@ -1,13 +1,12 @@
<?php
require "tests.php";
-require "director_classic.php";
// No new functions
-check::functions(array('being_id','person_id','child_id','grandchild_id','caller_delcallback','caller_setcallback','caller_resetcallback','caller_call','caller_baseclass'));
-// No new classes
+check::functions(array());
+// New classes
check::classes(array('Being','Person','Child','GrandChild','OrphanPerson','OrphanChild','Caller'));
-// now new vars
+// No new vars
check::globals(array());
class TargetLangPerson extends Person {
@@ -81,11 +80,7 @@ function mycheck($person, $expected) {
$ret = $baseclass->id();
if ($debug)
print $ret . "\n";
- # TODO: Currently we do not track the dynamic type of returned
- # objects, so in case it's possible that the dynamic type is not equal
- # to the static type, we skip this check.
- if (get_parent_class($person) === false)
- check::equal($ret, $expected, "#3 failed");
+ check::equal($ret, $expected, "#3 failed");
$caller->resetCallback();
if ($debug)
@@ -147,4 +142,3 @@ mycheck($person, "TargetLangOrphanChild");
unset($person);
check::done();
-?>
diff --git a/Examples/test-suite/php/director_default_runme.php b/Examples/test-suite/php/director_default_runme.php
index c459ce3ec..92e415041 100644
--- a/Examples/test-suite/php/director_default_runme.php
+++ b/Examples/test-suite/php/director_default_runme.php
@@ -1,13 +1,12 @@
<?php
require "tests.php";
-require "director_default.php";
// No new functions
-check::functions(array('foo_msg','foo_getmsg','bar_msg','bar_getmsg','defaultsbase_defaultargs','defaultsderived_defaultargs'));
-// No new classes
+check::functions(array());
+// New classes
check::classes(array('Foo','Bar','DefaultsBase','DefaultsDerived'));
-// now new vars
+// No new vars
check::globals(array());
$f = new Foo();
@@ -17,4 +16,3 @@ $f = new Bar();
$f = new Bar(1);
check::done();
-?>
diff --git a/Examples/test-suite/php/director_detect_runme.php b/Examples/test-suite/php/director_detect_runme.php
index a6d3aebd6..b9d0a6e0a 100644
--- a/Examples/test-suite/php/director_detect_runme.php
+++ b/Examples/test-suite/php/director_detect_runme.php
@@ -1,16 +1,17 @@
<?php
require "tests.php";
-require "director_detect.php";
// No new functions
-check::functions(array('foo_cloner','foo_get_value','foo_get_class','foo_just_do_it','bar_baseclass','bar_cloner','bar_get_value','bar_get_class','bar_just_do_it'));
-// No new classes
+check::functions(array());
+// New classes
check::classes(array('A','Foo','Bar'));
-// now new vars
+// No new vars
check::globals(array());
class MyBar extends Bar {
+ public $val;
+
function __construct($val = 2) {
parent::__construct();
$this->val = $val;
@@ -52,4 +53,3 @@ check::equal($b->val, 5, "b: Bad virtual detection");
check::equal($vc, 6, "c: Bad virtual detection");
check::done();
-?>
diff --git a/Examples/test-suite/php/director_enum_runme.php b/Examples/test-suite/php/director_enum_runme.php
index 0571ec0da..21e07a57b 100644
--- a/Examples/test-suite/php/director_enum_runme.php
+++ b/Examples/test-suite/php/director_enum_runme.php
@@ -1,13 +1,12 @@
<?php
require "tests.php";
-require "director_enum.php";
// No new functions
-check::functions(array('foo_say_hello','foo_say_hi','foo_say_bye','foo_say_hi_ref','foo_ping','foo_ping_ref','foo_ping_member_enum','a_f','a2_f'));
-// No new classes
+check::functions(array());
+// New classes
check::classes(array('director_enum','Foo','A','B','A2','B2'));
-// now new vars
+// No new vars
check::globals(array());
class MyFoo extends Foo {
@@ -22,4 +21,3 @@ $a = new MyFoo();
check::equal($a->say_hi(director_enum::hello), $b->say_hello(director_enum::hi), "say failed");
check::done();
-?>
diff --git a/Examples/test-suite/php/director_exception_catches_runme.php b/Examples/test-suite/php/director_exception_catches_runme.php
new file mode 100644
index 000000000..51c5663d5
--- /dev/null
+++ b/Examples/test-suite/php/director_exception_catches_runme.php
@@ -0,0 +1,26 @@
+<?php
+
+require "tests.php";
+
+// No new functions
+check::functions(array());
+// New classes
+check::classes(array('BaseClass'));
+// No new vars
+check::globals(array());
+
+class MyClass extends BaseClass {
+ function description() {
+ throw new Exception("Testing exception thrown in description()");
+ }
+}
+
+$b = new MyClass();
+try {
+ BaseClass::call_description($b);
+ check::fail("No exception thrown by BaseClass::call_description(\$b)");
+} catch (Exception $e) {
+ check::equal($e->getMessage(), "Testing exception thrown in description()", "Unexpected exception message: ".$e->getMessage());
+}
+
+check::done();
diff --git a/Examples/test-suite/php/director_exception_nothrow_runme.php b/Examples/test-suite/php/director_exception_nothrow_runme.php
new file mode 100644
index 000000000..2bc4a0c4a
--- /dev/null
+++ b/Examples/test-suite/php/director_exception_nothrow_runme.php
@@ -0,0 +1,23 @@
+<?php
+
+require "tests.php";
+
+// No new functions
+check::functions(array());
+// New classes
+check::classes(array('Bar', 'Base'));
+// No new vars
+check::globals(array());
+
+class MyBar extends Bar {
+ function pang() {
+ return "MyBar::pang()";
+ }
+}
+
+$a = new MyBar();
+check::equal($a->pang(), "MyBar::pang()", "MyBar::pang() not called as expected");
+$b = new Bar();
+check::equal($b->pang(), "Bar::pang()", "Bar::pang() not called as expected");
+
+check::done();
diff --git a/Examples/test-suite/php/director_exception_runme.php b/Examples/test-suite/php/director_exception_runme.php
index dd2d04e8a..6f33df028 100644
--- a/Examples/test-suite/php/director_exception_runme.php
+++ b/Examples/test-suite/php/director_exception_runme.php
@@ -1,16 +1,17 @@
<?php
require "tests.php";
-require "director_exception.php";
-// No new functions
-check::functions(array('foo_ping','foo_pong','launder','bar_ping','bar_pong','returnalltypes_return_int','returnalltypes_return_double','returnalltypes_return_const_char_star','returnalltypes_return_std_string','returnalltypes_return_bar','returnalltypes_call_int','returnalltypes_call_double','returnalltypes_call_const_char_star','returnalltypes_call_std_string','returnalltypes_call_bar','is_python_builtin'));
-// No new classes
+// New functions
+check::functions(array('launder'));
+// New classes
check::classes(array('director_exception','Foo','Exception1','Exception2','Base','Bar','ReturnAllTypes'));
-// now new vars
+// No new vars
check::globals(array());
class MyException extends Exception {
+ public $msg;
+
function __construct($a, $b) {
$this->msg = $a . $b;
}
@@ -38,9 +39,7 @@ class MyFoo3 extends Foo {
# MyFoo.pong().
$ok = 0;
$a = new MyFoo();
-# TODO: Currently we do not track the dynamic type of returned
-# objects, so we skip the launder() call.
-#$b = director_exception::launder($a);
+$b = director_exception::launder($a);
$b = $a;
try {
$b->pong();
@@ -124,4 +123,3 @@ try {
}
check::done();
-?>
diff --git a/Examples/test-suite/php/director_extend_runme.php b/Examples/test-suite/php/director_extend_runme.php
index 7aa2e0f78..3c6dd6b1d 100644
--- a/Examples/test-suite/php/director_extend_runme.php
+++ b/Examples/test-suite/php/director_extend_runme.php
@@ -1,13 +1,12 @@
<?php
require "tests.php";
-require "director_extend.php";
// No new functions
-check::functions(array('spobject_getfoobar','spobject_dummy','spobject_exceptionmethod'));
-// No new classes
+check::functions(array());
+// New classes
check::classes(array('SpObject'));
-// now new vars
+// No new vars
check::globals(array());
class MyObject extends SpObject{
@@ -18,7 +17,6 @@ class MyObject extends SpObject{
$m = new MyObject();
check::equal($m->dummy(), 666, "1st call");
-check::equal($m->dummy(), 666, "2st call"); // Locked system
+check::equal($m->dummy(), 666, "2nd call"); // Locked system
check::done();
-?>
diff --git a/Examples/test-suite/php/director_finalizer_runme.php b/Examples/test-suite/php/director_finalizer_runme.php
index 96bb5c179..689f445d2 100644
--- a/Examples/test-suite/php/director_finalizer_runme.php
+++ b/Examples/test-suite/php/director_finalizer_runme.php
@@ -1,19 +1,23 @@
<?php
require "tests.php";
-require "director_finalizer.php";
-// No new functions
-check::functions(array('foo_orstatus','deletefoo','getstatus','launder','resetstatus'));
-// No new classes
+// New functions
+check::functions(array('deleteFoo','getStatus','launder','resetStatus'));
+// New classes
check::classes(array('director_finalizer','Foo'));
-// now new vars
+// No new vars
check::globals(array());
class MyFoo extends Foo {
function __destruct() {
- $this->orStatus(2);
- if (method_exists(get_parent_class(), "__destruct")) {
+ # It's not safe to call methods on the C++ object from the PHP destructor
+ # if the object has been disowned, since the C++ object will already have
+ # been destroyed by the time the PHP destructor runs.
+ if ($this->thisown) {
+ $this->orStatus(2);
+ }
+ if (method_exists(parent::class, "__destruct")) {
parent::__destruct();
}
}
@@ -41,21 +45,24 @@ resetStatus();
$a = new MyFoo();
$a->thisown = 0;
+check::equal(getStatus(), 0, "shadow release does not fire destructor of disowned object");
+
deleteFoo($a);
unset($a);
-check::equal(getStatus(), 3, "getStatus() failed #4");
+# getStatus() would ideally return 3 here.
+check::equal(getStatus(), 1, "getStatus() failed #4");
resetStatus();
$a = new MyFoo();
$a->thisown = 0;
-deleteFoo(launder($a));
+$g = launder($a);
unset($a);
-
-check::equal(getStatus(), 3, "getStatus() failed #5");
+deleteFoo($g);
+# getStatus() would ideally return 3 here.
+check::equal(getStatus(), 1, "getStatus() failed #5");
resetStatus();
check::done();
-?>
diff --git a/Examples/test-suite/php/director_frob_runme.php b/Examples/test-suite/php/director_frob_runme.php
index 450a1234b..732b9d500 100644
--- a/Examples/test-suite/php/director_frob_runme.php
+++ b/Examples/test-suite/php/director_frob_runme.php
@@ -1,14 +1,13 @@
<?php
require "tests.php";
-require "director_frob.php";
// No new functions
-check::functions(array('alpha_abs_method','bravo_abs_method','charlie_abs_method','ops_opint','ops_opintstarstarconst','ops_opintamp','ops_opintstar','ops_opconstintintstar','prims_ull','prims_callull','corecallbacks_on3dengineredrawn','corecallbacks_on3dengineredrawn2'));
-// No new classes
+check::functions(array());
+// New classes
check::classes(array('Alpha','Bravo','Charlie','Delta','Ops','Prims','corePoint3d','coreCallbacks_On3dEngineRedrawnData','coreCallbacksOn3dEngineRedrawnData','coreCallbacks'));
-// now new vars
-check::globals(array('corecallbacks_on3dengineredrawndata__eye','corecallbacks_on3dengineredrawndata__at','corecallbackson3dengineredrawndata__eye','corecallbackson3dengineredrawndata__at'));
+// No new vars
+check::globals(array());
$foo = new Bravo();
$s = $foo->abs_method();
@@ -16,4 +15,3 @@ $s = $foo->abs_method();
check::equal($s, "Bravo::abs_method()", "s failed");
check::done();
-?>
diff --git a/Examples/test-suite/php/director_ignore_runme.php b/Examples/test-suite/php/director_ignore_runme.php
new file mode 100644
index 000000000..87bc4757d
--- /dev/null
+++ b/Examples/test-suite/php/director_ignore_runme.php
@@ -0,0 +1,24 @@
+<?php
+
+require "tests.php";
+
+// No new functions
+check::functions(array());
+check::classes(array('DAbstractIgnores','DIgnores','DTemplateAbstractIgnoresInt','DIgnoreConstructor','DIgnoreOnlyConstructor','DIgnoreDestructor'));
+// No new vars
+check::globals(array());
+
+class DIgnoresDerived extends DIgnores {
+ function PublicMethod1() {
+ return 18.75;
+ }
+}
+
+class DAbstractIgnoresDerived extends DAbstractIgnores {
+}
+
+$a = new DIgnoresDerived();
+check::equal($a->Triple(5), 15, "Wrong return value");
+
+$b = new DAbstractIgnoresDerived();
+check::equal($b->Quadruple(5), 20, "Wrong return value");
diff --git a/Examples/test-suite/php/director_nested_runme.php b/Examples/test-suite/php/director_nested_runme.php
index 9a094a182..adf9f6206 100644
--- a/Examples/test-suite/php/director_nested_runme.php
+++ b/Examples/test-suite/php/director_nested_runme.php
@@ -1,13 +1,12 @@
<?php
require "tests.php";
-require "director_nested.php";
// No new functions
-check::functions(array('foo_int_advance','foo_int_do_advance','bar_step','bar_do_advance','bar_do_step','foobar_int_get_value','foobar_int_get_name','foobar_int_name','foobar_int_get_self','foobar_int_do_advance','foobar_int_do_step'));
-// No new classes
+check::functions(array());
+// New classes
check::classes(array('Foo_int','Bar','FooBar_int'));
-// now new vars
+// No new vars
check::globals(array());
class A extends FooBar_int {
@@ -60,10 +59,7 @@ class C extends FooBar_int {
}
$cc = new C();
-# TODO: Currently we do not track the dynamic type of returned
-# objects, so we skip the get_self() call.
-#$c = Foobar_int::get_self($cc);
-$c = $cc;
+$c = Foobar_int::get_self($cc);
$c->advance();
check::equal($c->get_name(), "FooBar::get_name hello", "get_name failed");
@@ -71,4 +67,3 @@ check::equal($c->get_name(), "FooBar::get_name hello", "get_name failed");
check::equal($c->name(), "FooBar::get_name hello", "name failed");
check::done();
-?>
diff --git a/Examples/test-suite/php/director_overload_runme.php b/Examples/test-suite/php/director_overload_runme.php
new file mode 100644
index 000000000..07b485d95
--- /dev/null
+++ b/Examples/test-suite/php/director_overload_runme.php
@@ -0,0 +1,14 @@
+<?php
+
+require "tests.php";
+
+check::functions(array());
+check::classes(array('OverloadedClass','OverloadedPointers','OverloadedGetSet'));
+check::globals(array());
+
+$o = new OverloadedGetSet;
+check::equal($o->rw(), 42, "get_set() initial value not 42");
+check::equal($o->rw(7), null, "get_set() failed to set");
+check::equal($o->rw(), 7, "get_set() didn't return back set value");
+
+check::done();
diff --git a/Examples/test-suite/php/director_ownership_runme.php b/Examples/test-suite/php/director_ownership_runme.php
new file mode 100644
index 000000000..a78fb9c03
--- /dev/null
+++ b/Examples/test-suite/php/director_ownership_runme.php
@@ -0,0 +1,28 @@
+<?php
+require "tests.php";
+
+check::functions(array('make_content'));
+check::classes(array('ContentBase','ContentDerived','Container','director_ownership'));
+// No new vars
+check::globals(array());
+
+function set_content_and_release(Container $container, ContentBase $content) {
+ $content->thisown = false;
+ $container->set_content($content);
+}
+
+$container = new Container();
+
+// make a content in PHP (newobject is 1)
+$content_php = new ContentDerived();
+
+// make a content in C++ (newobject is 1)
+$content_cpp = make_content();
+
+set_content_and_release($container, $content_php);
+check::equal($container->get_content()->get_name(), "ContentDerived", "get_content() not ContentDerived");
+
+set_content_and_release($container, $content_cpp);
+check::equal($container->get_content()->get_name(), "ContentDerived", "get_content() not ContentDerived");
+
+check::done();
diff --git a/Examples/test-suite/php/director_pass_by_value_runme.php b/Examples/test-suite/php/director_pass_by_value_runme.php
index 8a8b84d67..b8f1bb9f9 100644
--- a/Examples/test-suite/php/director_pass_by_value_runme.php
+++ b/Examples/test-suite/php/director_pass_by_value_runme.php
@@ -1,7 +1,6 @@
<?php
require "tests.php";
-require "director_pass_by_value.php";
$passByVal = null;
@@ -15,10 +14,12 @@ class director_pass_by_value_Derived extends DirectorPassByValueAbstractBase {
# bug was the passByVal global object was destroyed after the call to virtualMethod had finished.
$caller = new Caller();
$caller->call_virtualMethod(new director_pass_by_value_Derived());
+if (has_cplusplus11()) {
+ Counter::check_counts(1, 0, 0, 1, 0, 1); # check move constructor called and just one destructor
+}
$ret = $passByVal->getVal();
if ($ret != 0x12345678) {
check::fail("Bad return value, got " . dechex($ret));
}
check::done();
-?>
diff --git a/Examples/test-suite/php/director_profile_runme.php b/Examples/test-suite/php/director_profile_runme.php
index c6f4c3c94..219ec815a 100644
--- a/Examples/test-suite/php/director_profile_runme.php
+++ b/Examples/test-suite/php/director_profile_runme.php
@@ -1,13 +1,12 @@
<?php
require "tests.php";
-require "director_profile.php";
// No new functions
-check::functions(array('b_fn','b_vfi','b_fi','b_fj','b_fk','b_fl','b_get_self','b_vfs','b_fs'));
-// No new classes
+check::functions(array());
+// New classes
check::classes(array('A','B'));
-// now new vars
+// No new vars
check::globals(array());
class MyB extends B {
@@ -50,4 +49,3 @@ while ($i) {
print $a . "\n";
check::done();
-?>
diff --git a/Examples/test-suite/php/director_protected_runme.php b/Examples/test-suite/php/director_protected_runme.php
index e759fed25..b73c8f872 100644
--- a/Examples/test-suite/php/director_protected_runme.php
+++ b/Examples/test-suite/php/director_protected_runme.php
@@ -1,11 +1,12 @@
<?php
require "tests.php";
-require "director_protected.php";
-check::functions(array('foo_pong','foo_s','foo_q','foo_ping','foo_pang','foo_used','foo_cheer','bar_create','bar_callping','bar_callcheer','bar_cheer','bar_pong','bar_used','bar_ping','bar_pang','a_draw','b_draw'));
+// No new functions
+check::functions(array());
check::classes(array('Foo','Bar','PrivateFoo','A','B','AA','BB'));
-check::globals(array('bar_a'));
+// No new vars
+check::globals(array());
class FooBar extends Bar {
protected function ping() {
@@ -67,4 +68,3 @@ check::equal($fb3->callping(), "Bar::ping();", "bad fb3::callping");
check::equal($fb3->callcheer(), "FooBar3::cheer();", "bad fb3::callcheer");
check::done();
-?>
diff --git a/Examples/test-suite/php/director_stl_runme.php b/Examples/test-suite/php/director_stl_runme.php
index f7a5c0aa0..031a87ae7 100644
--- a/Examples/test-suite/php/director_stl_runme.php
+++ b/Examples/test-suite/php/director_stl_runme.php
@@ -1,13 +1,12 @@
<?php
require "tests.php";
-require "director_stl.php";
// No new functions
-check::functions(array('foo_bar','foo_ping','foo_pong','foo_tping','foo_tpong','foo_pident','foo_vident','foo_vsecond','foo_tpident','foo_tvident','foo_tvsecond','foo_vidents','foo_tvidents'));
-// No new classes
+check::functions(array());
+// New classes
check::classes(array('Foo'));
-// now new vars
+// No new vars
check::globals(array());
class MyFoo extends Foo {
@@ -27,7 +26,7 @@ class MyFoo extends Foo {
return $v;
}
- function vsecond($v1, $v2) {
+ function vsecond($v1, $v2 = NULL) {
return $v2;
}
}
@@ -57,4 +56,3 @@ $vs;
$a->tvidents($vs);*/
check::done();
-?>
diff --git a/Examples/test-suite/php/director_string_runme.php b/Examples/test-suite/php/director_string_runme.php
index 77e84c9bf..47121e7b0 100644
--- a/Examples/test-suite/php/director_string_runme.php
+++ b/Examples/test-suite/php/director_string_runme.php
@@ -1,16 +1,17 @@
<?php
require "tests.php";
-require "director_string.php";
// No new functions
-check::functions(array('a_get_first','a_call_get_first','a_string_length','a_process_text','a_call_process_func','stringvector_size','stringvector_is_empty','stringvector_clear','stringvector_push','stringvector_pop','stringvector_capacity','stringvector_reserve'));
-// No new classes
+check::functions(array());
+// New classes
check::classes(array('A','StringVector'));
-// now new vars
-check::globals(array('a','a_call','a_m_strings','stringvector'));
+// No new vars
+check::globals(array());
class B extends A {
+ public $smem;
+
function get_first() {
return parent::get_first() . " world!";
}
@@ -23,12 +24,14 @@ class B extends A {
$b = new B("hello");
-$b->get(0);
-check::equal($b->get_first(),"hello world!", "get_first failed");
+check::equal($b->get(0), "hello", "get(0) failed");
+
+check::equal($b->get_first(), "hello world!", "get_first failed");
+
+check::equal($b->call_get_first(), "hello world!", "call_get_first failed");
$b->call_process_func();
check::equal($b->smem, "hello", "smem failed");
check::done();
-?>
diff --git a/Examples/test-suite/php/director_thread_runme.php b/Examples/test-suite/php/director_thread_runme.php
index 2a640a022..e4eb3684a 100644
--- a/Examples/test-suite/php/director_thread_runme.php
+++ b/Examples/test-suite/php/director_thread_runme.php
@@ -1,18 +1,17 @@
<?php
require "tests.php";
-require "director_thread.php";
# Fails in a ZTS-build of PHP5 - see: https://github.com/swig/swig/pull/155
-# FIXME: Does this still fail in a threaded build of PHP7?
+# FIXME: Does this still fail in a threaded build of PHP8?
exit(0);
-// No new functions
+// New functions
check::functions(array('millisecondsleep','foo_stop','foo_run','foo_do_foo'));
-// No new classes
+// New classes
check::classes(array('director_thread','Foo'));
-// now new vars
-check::globals(array('foo_val'));
+// No new vars
+check::globals(array());
class Derived extends Foo {
function do_foo() {
@@ -30,4 +29,3 @@ if ($d->val >= 0) {
$d->stop();
check::done();
-?>
diff --git a/Examples/test-suite/php/director_unroll_runme.php b/Examples/test-suite/php/director_unroll_runme.php
index e3101887d..7f94753f5 100644
--- a/Examples/test-suite/php/director_unroll_runme.php
+++ b/Examples/test-suite/php/director_unroll_runme.php
@@ -1,14 +1,13 @@
<?php
require "tests.php";
-require "director_unroll.php";
// No new functions
-check::functions(array('foo_ping','foo_pong'));
-// No new classes
+check::functions(array());
+// New classes
check::classes(array('Foo','Bar'));
-// now new vars
-check::globals(array('bar'));
+// No new vars
+check::globals(array());
class MyFoo extends Foo {
function ping() {
@@ -23,10 +22,7 @@ $b = new Bar();
$b->set($a);
$c = $b->get();
-// FIXME: This doesn't work for checking that they wrap the same C++ object
-// because the two objects have different PHP resources, and we can't easily
-// look inside those resources to see which C++ objects they refer to.
-//check::equal($a->_cPtr, $c->_cPtr, "_cPtr check failed");
+// FIXME: The python version checks that a.this == c.this, but we don't seem
+// to have a way to check this with the PHP bindings we generate.
check::done();
-?>
diff --git a/Examples/test-suite/php/director_wombat_runme.php b/Examples/test-suite/php/director_wombat_runme.php
new file mode 100644
index 000000000..3e308044f
--- /dev/null
+++ b/Examples/test-suite/php/director_wombat_runme.php
@@ -0,0 +1,52 @@
+<?php
+
+require "tests.php";
+
+// No new functions
+check::functions(array());
+check::classes(array('Bar', 'Foo_integers'));
+// No new vars
+check::globals(array());
+
+// Test base class functionality
+$barObj = new Bar();
+
+// Bar::meth should return a Foo_integers instance
+$fooIntsObj = $barObj->meth();
+check::equal(get_class($fooIntsObj), "Foo_integers", "wrong class");
+
+check::equal($fooIntsObj->meth(42) , 42, "Foo_integers::meth(n) should return n");
+
+//
+// Now subclass Foo_integers, but override its virtual method
+// meth(n) so that it returns the number plus one.
+//
+class MyFooInts extends Foo_integers {
+ function meth($n) {
+ return $n + 1;
+ }
+}
+
+//
+// Subclass Bar and override its virtual method meth()
+// so that it returns a new MyFooInts instance instead of
+// a Foo_integers instance.
+//
+class MyBar extends Bar {
+ function meth() {
+ return new MyFooInts();
+ }
+}
+
+//
+// Now repeat previous tests:
+//
+// Create a MyBar instance...
+//
+$barObj = new MyBar();
+
+// MyBar::meth should return a MyFooInts instance
+$fooIntsObj = $barObj->meth();
+check::equal(get_class($fooIntsObj), "MyFooInts", "wrong class");
+
+check::equal($fooIntsObj->meth(42) , 43, "MyFooInts::meth(n) should return n + 1");
diff --git a/Examples/test-suite/php/enum_scope_template_runme.php b/Examples/test-suite/php/enum_scope_template_runme.php
index 85ba467b7..d5aed62f7 100644
--- a/Examples/test-suite/php/enum_scope_template_runme.php
+++ b/Examples/test-suite/php/enum_scope_template_runme.php
@@ -1,15 +1,16 @@
<?php
require "tests.php";
-require "enum_scope_template.php";
+check::functions(array("chops"));
check::classes(array("enum_scope_template", "TreeInt"));
-check::functions(array("chops","treeint_chops"));
-check::equal(0,TreeInt_Oak,"0==TreeInt_Oak");
-check::equal(1,TreeInt_Fir,"1==TreeInt_Fir");
-check::equal(2,TreeInt_Cedar,"2==TreeInt_Cedar");
-check::equal(TreeInt_Oak,chops(TreeInt_Oak),"TreeInt_Oak==chops(TreeInt_Oak)");
-check::equal(TreeInt_Fir,chops(TreeInt_Fir),"TreeInt_Fir==chops(TreeInt_Fir)");
-check::equal(TreeInt_Cedar,chops(TreeInt_Cedar),"TreeInt_Cedar==chops(TreeInt_Cedar)");
+// No new vars
+check::globals(array());
+
+check::equal(0,TreeInt::Oak,"0==TreeInt_Oak");
+check::equal(1,TreeInt::Fir,"1==TreeInt_Fir");
+check::equal(2,TreeInt::Cedar,"2==TreeInt_Cedar");
+check::equal(TreeInt::Oak,chops(TreeInt::Oak),"TreeInt_Oak==chops(TreeInt_Oak)");
+check::equal(TreeInt::Fir,chops(TreeInt::Fir),"TreeInt_Fir==chops(TreeInt_Fir)");
+check::equal(TreeInt::Cedar,chops(TreeInt::Cedar),"TreeInt_Cedar==chops(TreeInt_Cedar)");
check::done();
-?>
diff --git a/Examples/test-suite/php/evil_diamond_ns_runme.php b/Examples/test-suite/php/evil_diamond_ns_runme.php
index fcce0f767..f2115bf36 100644
--- a/Examples/test-suite/php/evil_diamond_ns_runme.php
+++ b/Examples/test-suite/php/evil_diamond_ns_runme.php
@@ -1,7 +1,6 @@
<?php
require "tests.php";
-require "evil_diamond_ns.php";
check::classes(array("evil_diamond_ns","foo","bar","baz","spam"));
check::functions("test");
@@ -15,4 +14,3 @@ $spam=new spam();
$_spam=test($spam);
check::done();
-?>
diff --git a/Examples/test-suite/php/evil_diamond_prop_runme.php b/Examples/test-suite/php/evil_diamond_prop_runme.php
index 9bdb7435f..611f17d6a 100644
--- a/Examples/test-suite/php/evil_diamond_prop_runme.php
+++ b/Examples/test-suite/php/evil_diamond_prop_runme.php
@@ -1,7 +1,6 @@
<?php
require "tests.php";
-require "evil_diamond_prop.php";
check::classes(array("evil_diamond_prop","foo","bar","baz","spam"));
check::functions("test");
@@ -31,10 +30,7 @@ check::is_a($spam,"spam");
check::equal(1,$spam->_foo,"1==spam->_foo");
check::equal(2,$spam->_bar,"2==spam->_bar");
// multiple inheritance not supported in PHP
-set_error_handler(NULL, 0); // Don't complain that _baz is unknown.
check::equal(null,$spam->_baz,"null==spam->_baz");
-restore_error_handler();
check::equal(4,$spam->_spam,"4==spam->_spam");
check::done();
-?>
diff --git a/Examples/test-suite/php/evil_diamond_runme.php b/Examples/test-suite/php/evil_diamond_runme.php
index a587ca359..7d01c98ec 100644
--- a/Examples/test-suite/php/evil_diamond_runme.php
+++ b/Examples/test-suite/php/evil_diamond_runme.php
@@ -1,7 +1,6 @@
<?php
require "tests.php";
-require "evil_diamond.php";
check::classes(array("evil_diamond","foo","bar","baz","spam"));
check::functions("test");
@@ -13,4 +12,3 @@ check::is_a("spam","bar");
//check::is_a("spam","baz");
check::done();
-?>
diff --git a/Examples/test-suite/php/exception_memory_leak_runme.php b/Examples/test-suite/php/exception_memory_leak_runme.php
new file mode 100644
index 000000000..116ab2f0e
--- /dev/null
+++ b/Examples/test-suite/php/exception_memory_leak_runme.php
@@ -0,0 +1,35 @@
+<?php
+
+require "tests.php";
+
+check::functions(array('trigger_internal_swig_exception'));
+check::classes(array('Foo', 'exception_memory_leak'));
+// No new vars
+check::globals(array());
+
+$a = new Foo();
+check::equal(Foo::get_count(), 1, "Should have 1 Foo objects");
+$b = new Foo();
+check::equal(Foo::get_count(), 2, "Should have 2 Foo objects");
+
+// Normal behaviour
+trigger_internal_swig_exception("no problem", $a);
+check::equal(Foo::get_count(), 2, "Should have 2 Foo objects");
+check::equal(Foo::get_freearg_count(), 1, "freearg should have been used once");
+
+// SWIG exception triggered and handled (return new object case).
+try {
+ trigger_internal_swig_exception("null", $b);
+ check::fail("Expected exception not thrown");
+} catch (Exception $e) {
+}
+check::equal(Foo::get_count(), 2, "Should have 2 Foo objects");
+check::equal(Foo::get_freearg_count(), 2, "freearg should have been used twice");
+
+// SWIG exception triggered and handled (return by value case).
+try {
+ trigger_internal_swig_exception("null");
+ check::fail("Expected exception not thrown");
+} catch (Exception $e) {
+}
+check::equal(Foo::get_count(), 2, "Should have 2 Foo objects");
diff --git a/Examples/test-suite/php/exception_order_runme.php b/Examples/test-suite/php/exception_order_runme.php
index 77f115fa1..835a83ca3 100644
--- a/Examples/test-suite/php/exception_order_runme.php
+++ b/Examples/test-suite/php/exception_order_runme.php
@@ -1,10 +1,9 @@
-<?
+<?php
require "tests.php";
-require "exception_order.php";
-check::functions(array('a_foo','a_bar','a_foobar','a_barfoo','is_python_builtin'));
+check::functions(array());
check::classes(array('A','E1','E2','E3','exception_order','ET_i','ET_d'));
-check::globals(array('efoovar','foovar','cfoovar','a_sfoovar','a_foovar','a_efoovar'));
+check::globals(array('efoovar','foovar','cfoovar'));
$a = new A();
try {
@@ -36,4 +35,5 @@ try {
} catch (Exception $e) {
check::equal($e->getMessage(), 'C++ E2 * exception thrown', '');
}
-?>
+
+check::done();
diff --git a/Examples/test-suite/php/extend_template_ns_runme.php b/Examples/test-suite/php/extend_template_ns_runme.php
index e6d3e9f73..46158672b 100644
--- a/Examples/test-suite/php/extend_template_ns_runme.php
+++ b/Examples/test-suite/php/extend_template_ns_runme.php
@@ -1,7 +1,6 @@
<?php
require "tests.php";
-require "extend_template_ns.php";
check::classes(array("extend_template_ns","Foo_One"));
$foo=new Foo_One();
@@ -9,4 +8,3 @@ check::equal(2,$foo->test1(2),"test1");
check::equal(3,$foo->test2(3),"test2");
check::done();
-?>
diff --git a/Examples/test-suite/php/extend_template_runme.php b/Examples/test-suite/php/extend_template_runme.php
index 41bde4458..a6579dce9 100644
--- a/Examples/test-suite/php/extend_template_runme.php
+++ b/Examples/test-suite/php/extend_template_runme.php
@@ -1,7 +1,6 @@
<?php
require "tests.php";
-require "extend_template.php";
check::classes(array("Foo_0"));
$foo=new Foo_0();
@@ -9,4 +8,3 @@ check::equal(2,$foo->test1(2),"test1");
check::equal(3,$foo->test2(3),"test2");
check::done();
-?>
diff --git a/Examples/test-suite/php/friends_runme.php b/Examples/test-suite/php/friends_runme.php
new file mode 100644
index 000000000..4107817f7
--- /dev/null
+++ b/Examples/test-suite/php/friends_runme.php
@@ -0,0 +1,51 @@
+<?php
+
+require "tests.php";
+
+check::functions(array('globalscope','mix','get_val2','get_val3','bas','baz','get_val1','set','chum_blah','mate_blah','friend_definition','friend_declaration','friend_args_definition','friend_args_declaration','friend_definition_compiler','friend_declaration_compiler','friend_args_definition_compiler','friend_args_declaration_compiler'));
+check::classes(array('friends','Foe','A','B','D_i','D_d','CModelParameterCompartment','CModelParameterSpecies','Chum','Mate'));
+// No new vars
+check::globals(array());
+
+$a = new A(2);
+
+check::equal(get_val1($a), 2);
+check::equal(get_val2($a), 4);
+check::equal(get_val3($a), 6);
+
+# nice overload working fine
+check::equal(get_val1(1, 2, 3), 1);
+
+$b = new B(3);
+
+# David's case
+check::equal(mix($a, $b), 5);
+
+$di = new D_i(2);
+$dd = new D_d(3.3);
+
+# incredible template overloading working just fine
+check::equal(get_val1($di), 2);
+check::equal(get_val1($dd), 3.3);
+
+set($di, 4);
+set($dd, 1.3);
+
+check::equal(get_val1($di), 4);
+check::equal(get_val1($dd), 1.3);
+
+check::equal(chum_blah(), 1234);
+check::equal(mate_blah(), 4321);
+
+$foe = new Foe(111);
+check::equal(friend_definition(), 10);
+check::equal(friend_declaration(), 11);
+check::equal(friend_args_definition($foe), 111);
+check::equal(friend_args_declaration($foe), 111);
+
+check::equal(friend_definition_compiler(), 20);
+check::equal(friend_declaration_compiler(), 21);
+check::equal(friend_args_definition_compiler($foe), 111);
+check::equal(friend_args_declaration_compiler($foe), 111);
+
+check::done();
diff --git a/Examples/test-suite/php/global_vars_runme.php b/Examples/test-suite/php/global_vars_runme.php
new file mode 100644
index 000000000..c3fe7d8aa
--- /dev/null
+++ b/Examples/test-suite/php/global_vars_runme.php
@@ -0,0 +1,27 @@
+<?php
+
+require "tests.php";
+
+check::functions(array('init','read_b','read_x'));
+check::classes(array('A','global_vars'));
+check::globals(array('b','a','ap','cap','ar','x','xp','c_member','vp','h','hp','hr'));
+
+$an = new A();
+check::classname('A', $an);
+ap_set($an);
+check::classname('A', ap_get());
+check::equivalent(ap_get(), $an, "global var assignment");
+
+x_set(17);
+check::equal(x_get(), 17, "global var assignment");
+check::equal(read_x(), 17, "PHP global var change visible in C++");
+init();
+check::equal(x_get(), 1234, "C++ global var change visible in PHP");
+
+b_set('test');
+check::equal(b_get(), 'test', "global var assignment");
+check::equal(read_b(), 'test', "PHP global var change visible in C++");
+init();
+check::equal(b_get(), 'string b', "C++ global var change visible in PHP");
+
+check::done();
diff --git a/Examples/test-suite/php/grouping_runme.php b/Examples/test-suite/php/grouping_runme.php
index 8bad7cd4c..d2b849d1c 100644
--- a/Examples/test-suite/php/grouping_runme.php
+++ b/Examples/test-suite/php/grouping_runme.php
@@ -1,11 +1,10 @@
<?php
require "tests.php";
-require "grouping.php";
check::functions(array("test1","test2","do_unary","negate"));
check::equal(5,test1(5),"5==test1(5)");
-check::resource(test2(7),"_p_int","_p_int==test2(7)");
+check::equal(get_class(test2(7)),"SWIG\\_p_int","test2(7) is _p_int");
check::globals(array('test3'));
//check::equal(37,test3_get(),'37==test3_get()');
@@ -19,4 +18,3 @@ check::equal(-5,negate(5),"-5==negate(5)");
check::equal(7,do_unary(-7,NEGATE),"7=do_unary(-7,NEGATE)");
check::done();
-?>
diff --git a/Examples/test-suite/php/ignore_parameter_runme.php b/Examples/test-suite/php/ignore_parameter_runme.php
index b9c2b777d..90b82d7da 100644
--- a/Examples/test-suite/php/ignore_parameter_runme.php
+++ b/Examples/test-suite/php/ignore_parameter_runme.php
@@ -1,14 +1,13 @@
<?php
require "tests.php";
-require "ignore_parameter.php";
// New functions
-check::functions(array('jaguar','lotus','tvr','ferrari','fiat','sportscars_daimler','sportscars_astonmartin','sportscars_bugatti','sportscars_lamborghini','sportscars_maseratti'));
+check::functions(array('jaguar','lotus','tvr','ferrari','fiat'));
// New classes
check::classes(array('ignore_parameter','SportsCars','MiniCooper','MorrisMinor','FordAnglia','AustinAllegro'));
// No new vars
-check::globals(array());
+check::globals(array('called_argout'));
check::equal(jaguar(2,3.4),"hello",'jaguar(2,3.4)=="hello"');
check::equal(lotus("eek",3.4),101,'lotus("eek",3.4)==101');
@@ -18,7 +17,7 @@ check::equal(ferrari(),101,'ferrari(2)==101');
$sc=new sportscars();
check::classname("sportscars",$sc);
check::equal($sc->daimler(2,3.4),"hello",'$sc->daimler(2,3.4)=="hello"');
-check::equal($sc->astonmartin("eek",3.4),101,'$sc->mastonmartin("eek",3.4)==101');
+check::equal($sc->astonmartin("eek",3.4),101,'$sc->astonmartin("eek",3.4)==101');
check::equal($sc->bugatti("eek",2),8.8,'$sc->bugatti("eek",2)==8.8');
check::equal($sc->lamborghini(),101,'$sc->lamborghini(2)==101');
@@ -35,4 +34,3 @@ $aa=new austinallegro();
check::classname("austinallegro",$aa);
check::done();
-?>
diff --git a/Examples/test-suite/php/import_nomodule_runme.php b/Examples/test-suite/php/import_nomodule_runme.php
index e5ea761f7..3dda18b0d 100644
--- a/Examples/test-suite/php/import_nomodule_runme.php
+++ b/Examples/test-suite/php/import_nomodule_runme.php
@@ -1,14 +1,17 @@
<?php
+
require "tests.php";
-require "import_nomodule.php";
// No new functions
-check::functions(array('create_foo','delete_foo','test1','is_python_builtin'));
-// No new classes
-check::classes(array('import_nomodule','Bar'));
-// now new vars
+check::functions(array());
+check::classes(array('import_nomodule'));
+// No new globals
check::globals(array());
+// SWIGPHP doesn't currently support the "violation of the type system" which
+// is tested by this testcase.
+exit(0);
+
$f = import_nomodule::create_Foo();
import_nomodule::test1($f,42);
import_nomodule::delete_Foo($f);
@@ -17,4 +20,3 @@ $b = new Bar();
import_nomodule::test1($b,37);
check::done();
-?>
diff --git a/Examples/test-suite/php/li_carrays_cpp_runme.php b/Examples/test-suite/php/li_carrays_cpp_runme.php
index 3e8a443f6..ccbcf7dde 100644
--- a/Examples/test-suite/php/li_carrays_cpp_runme.php
+++ b/Examples/test-suite/php/li_carrays_cpp_runme.php
@@ -1,16 +1,16 @@
<?php
+
require "tests.php";
-require "li_carrays_cpp.php";
// Check functions.
-check::functions(array('new_intarray','delete_intarray','intarray_getitem','intarray_setitem','doublearray_getitem','doublearray_setitem','doublearray_cast','doublearray_frompointer','xyarray_getitem','xyarray_setitem','xyarray_cast','xyarray_frompointer','delete_abarray','abarray_getitem','abarray_setitem','shortarray_getitem','shortarray_setitem','shortarray_cast','shortarray_frompointer','sum_array'));
+check::functions(array('new_intArray','delete_intArray','intArray_getitem','intArray_setitem','new_ABArray','delete_ABArray','ABArray_getitem','ABArray_setitem','sum_array'));
// Check classes.
// NB An "li_carrays_cpp" class is created as a mock namespace.
check::classes(array('li_carrays_cpp','doubleArray','AB','XY','XYArray','shortArray'));
// Check global variables.
-check::globals(array('xy_x','xy_y','globalxyarray','ab_a','ab_b','globalabarray'));
+check::globals(array('globalXYArray','globalABArray'));
$d = new doubleArray(10);
@@ -19,4 +19,3 @@ $d->setitem(5, $d->getitem(0) + 3);
check::equal($d->getitem(0) + $d->getitem(5), 17., "7+10==17");
check::done();
-?>
diff --git a/Examples/test-suite/php/li_carrays_runme.php b/Examples/test-suite/php/li_carrays_runme.php
index abe358101..df54e04f5 100644
--- a/Examples/test-suite/php/li_carrays_runme.php
+++ b/Examples/test-suite/php/li_carrays_runme.php
@@ -1,16 +1,16 @@
<?php
+
require "tests.php";
-require "li_carrays.php";
// Check functions.
-check::functions(array('new_intarray','delete_intarray','intarray_getitem','intarray_setitem','doublearray_getitem','doublearray_setitem','doublearray_cast','doublearray_frompointer','xyarray_getitem','xyarray_setitem','xyarray_cast','xyarray_frompointer','delete_abarray','abarray_getitem','abarray_setitem','shortarray_getitem','shortarray_setitem','shortarray_cast','shortarray_frompointer','sum_array'));
+check::functions(array('new_intArray','delete_intArray','intArray_getitem','intArray_setitem','new_ABArray','delete_ABArray','ABArray_getitem','ABArray_setitem','sum_array'));
// Check classes.
// NB An "li_carrays" class is created as a mock namespace.
check::classes(array('li_carrays','doubleArray','AB','XY','XYArray','shortArray'));
// Check global variables.
-check::globals(array('xy_x','xy_y','globalxyarray','ab_a','ab_b','globalabarray'));
+check::globals(array('globalXYArray','globalABArray'));
$d = new doubleArray(10);
@@ -19,4 +19,3 @@ $d->setitem(5, $d->getitem(0) + 3);
check::equal($d->getitem(0) + $d->getitem(5), 17., "7+10==17");
check::done();
-?>
diff --git a/Examples/test-suite/php/li_constraints_runme.php b/Examples/test-suite/php/li_constraints_runme.php
new file mode 100644
index 000000000..35d523b9f
--- /dev/null
+++ b/Examples/test-suite/php/li_constraints_runme.php
@@ -0,0 +1,68 @@
+<?php
+
+require "tests.php";
+
+// New functions
+check::functions(array('test_nonnegative', 'test_nonpositive', 'test_positive',
+ 'test_negative', 'test_nonzero', 'test_nonnull', 'get_nonnull'));
+// New classes
+check::classes(array('li_constraints'));
+// No new vars
+check::globals(array());
+
+function check_double(bool $except, $fn, string $f, $val) {
+ $actual = true;
+ $d = doubleval($val);
+ try {
+ $fn($d);
+ } catch(ValueError $e) {
+ $actual = false;
+ $msg = $e->getMessage();
+ }
+ $name = "test_" . str_replace("-", "", $f);
+ if($actual) {
+ check::equal($actual, $except, "Test '$name' with $val pass");
+ } else {
+ check::equal($actual, $except, "Test '$name' throw exception with $val");
+ check::equal($msg, "Expected a " . $f . " value.", "'$name' throw proper exception");
+ }
+}
+
+$nonnegative = function ($val) { test_nonnegative($val); };
+check_double(true, $nonnegative, "non-negative", 10);
+check_double(true, $nonnegative, "non-negative", 0);
+check_double(false, $nonnegative, "non-negative", -10);
+
+$nonpositive = function ($val) { test_nonpositive($val); };
+check_double(false, $nonpositive, "non-positive", 10);
+check_double(true, $nonpositive, "non-positive", 0);
+check_double(true, $nonpositive, "non-positive", -10);
+
+$positive = function ($val) { test_positive($val); };
+check_double(true, $positive, "positive", 10);
+check_double(false, $positive, "positive", 0);
+check_double(false, $positive, "positive", -10);
+
+$negative = function ($val) { test_negative($val); };
+check_double(false, $negative, "negative", 10);
+check_double(false, $negative, "negative", 0);
+check_double(true, $negative, "negative", -10);
+
+$nonzero = function ($val) { test_nonzero($val); };
+check_double(true, $nonzero, "nonzero", 10);
+check_double(false, $nonzero, "nonzero", 0);
+check_double(true, $nonzero, "nonzero", -10);
+
+$have_exception = false;
+try {
+ test_nonnull(null);
+} catch(ValueError $e) {
+ $msg = $e->getMessage();
+ $have_exception = strcmp($msg, "Received a NULL pointer.") === 0;
+}
+if (!$have_exception) {
+ throw new Exception("test_nonnull should perform a proper exception with 'null' value");
+}
+
+$non_null = get_nonnull();
+test_nonnull($non_null);
diff --git a/Examples/test-suite/php/li_factory_runme.php b/Examples/test-suite/php/li_factory_runme.php
index 982d7b1fd..18545fec7 100644
--- a/Examples/test-suite/php/li_factory_runme.php
+++ b/Examples/test-suite/php/li_factory_runme.php
@@ -1,13 +1,12 @@
<?php
require "tests.php";
-require "li_factory.php";
// No new functions
-check::functions(array('geometry_draw','geometry_create','geometry_clone_','point_draw','point_width','point_clone_','circle_draw','circle_radius','circle_clone_'));
-// No new classes
+check::functions(array());
+// New classes
check::classes(array('Geometry','Point','Circle'));
-// now new vars
+// No new vars
check::globals(array());
$circle = Geometry::create(Geometry::CIRCLE);
@@ -18,5 +17,7 @@ $point = Geometry::create(Geometry::POINT);
$w = $point->width();
check::equal($w, 1.0, "w failed");
+$point = Geometry::create(Geometry::SHAPELESS);
+check::equal($point, NULL, "NULL failed");
+
check::done();
-?>
diff --git a/Examples/test-suite/php/li_std_auto_ptr_runme.php b/Examples/test-suite/php/li_std_auto_ptr_runme.php
new file mode 100644
index 000000000..7ebcf97b1
--- /dev/null
+++ b/Examples/test-suite/php/li_std_auto_ptr_runme.php
@@ -0,0 +1,108 @@
+<?php
+
+require "tests.php";
+
+function checkCount($expected_count) {
+ $actual_count = Klass::getTotal_count();
+ check::equal($actual_count, $expected_count, "Counts incorrect");
+}
+
+# Test raw pointer handling involving virtual inheritance
+$kini = new KlassInheritance("KlassInheritanceInput");
+checkCount(1);
+$s = useKlassRawPtr($kini);
+check::equal($s, "KlassInheritanceInput", "Incorrect string: $s");
+$kini = NULL;
+checkCount(0);
+
+
+# auto_ptr as input
+$kin = new Klass("KlassInput");
+checkCount(1);
+$s = takeKlassAutoPtr($kin);
+checkCount(0);
+check::equal($s, "KlassInput", "Incorrect string: $s");
+try {
+ is_nullptr($kin);
+ check::fail("is_nullptr check");
+} catch (TypeError $e) {
+}
+$kin = NULL; # Should not fail, even though already deleted
+checkCount(0);
+
+$kin = new Klass("KlassInput");
+checkCount(1);
+$s = takeKlassAutoPtr($kin);
+checkCount(0);
+check::equal($s, "KlassInput", "Incorrect string: $s");
+try {
+ is_nullptr($kin);
+ check::fail("is_nullptr check");
+} catch (TypeError $e) {
+}
+$exception_thrown = false;
+try {
+ takeKlassAutoPtr($kin);
+} catch (TypeError $e) {
+ check::equal($e->getMessage(), "Cannot release ownership as memory is not owned for argument 1 of SWIGTYPE_p_Klass of takeKlassAutoPtr", "Unexpected exception: {$e->getMessage()}");
+ $exception_thrown = true;
+}
+check::equal($exception_thrown, true, "double usage of takeKlassAutoPtr should have been an error");
+$kin = NULL; # Should not fail, even though already deleted
+checkCount(0);
+
+$kin = new Klass("KlassInput");
+$exception_thrown = false;
+$notowned = get_not_owned_ptr($kin);
+try {
+ takeKlassAutoPtr($notowned);
+} catch (TypeError $e) {
+ check::equal($e->getMessage(), "Cannot release ownership as memory is not owned for argument 1 of SWIGTYPE_p_Klass of takeKlassAutoPtr", "Unexpected exception: {$e->getMessage()}");
+ $exception_thrown = true;
+}
+check::equal($exception_thrown, true, "double usage of takeKlassAutoPtr should have been an error");
+checkCount(1);
+$kin = NULL;
+checkCount(0);
+
+$kini = new KlassInheritance("KlassInheritanceInput");
+checkCount(1);
+$s = takeKlassAutoPtr($kini);
+checkCount(0);
+check::equal($s, "KlassInheritanceInput", "Incorrect string: $s");
+try {
+ is_nullptr($kini);
+ check::fail("is_nullptr check");
+} catch (TypeError $e) {
+}
+
+$kini = NULL; # Should not fail, even though already deleted
+checkCount(0);
+
+takeKlassAutoPtr(NULL);
+takeKlassAutoPtr(make_null());
+checkCount(0);
+
+# overloaded parameters
+check::equal(overloadTest(), 0, "overloadTest failed");
+check::equal(overloadTest(NULL), 1, "overloadTest failed");
+check::equal(overloadTest(new Klass("over")), 1, "overloadTest failed");
+checkCount(0);
+
+
+# auto_ptr as output
+$k1 = makeKlassAutoPtr("first");
+$k2 = makeKlassAutoPtr("second");
+checkCount(2);
+
+$k1 = NULL;
+checkCount(1);
+
+check::equal($k2->getLabel(), "second", "proper label");
+
+$k2 = NULL;
+checkCount(0);
+
+check::equal(makeNullAutoPtr(), NULL);
+
+check::done();
diff --git a/Examples/test-suite/php/li_std_string_runme.php b/Examples/test-suite/php/li_std_string_runme.php
index 04ee3fc86..cd0431254 100644
--- a/Examples/test-suite/php/li_std_string_runme.php
+++ b/Examples/test-suite/php/li_std_string_runme.php
@@ -1,11 +1,34 @@
<?php
require "tests.php";
-require "li_std_string.php";
-// Global variables
-//$s="initial string";
-//check::equal(GlobalString2_get() ,"global string 2", "GlobalString2 test 1");
+# Checking expected use of %typemap(in) std::string {}
+li_std_string::test_value("Fee");
+
+# Checking expected result of %typemap(out) std::string {}
+check::equal(li_std_string::test_value("Fi"), "Fi", "Test 1");
+
+# Checking expected use of %typemap(in) const std::string & {}
+li_std_string::test_const_reference("Fo");
+
+# Checking expected result of %typemap(out) const std::string& {}
+check::equal(li_std_string::test_const_reference("Fum"), "Fum", "Test 3");
+
+# Input and output typemaps for pointers and non-const references to
+# std::string are *not* supported; the following tests confirm
+# that none of these cases are slipping through.
+
+$stringPtr = li_std_string::test_pointer_out();
+
+li_std_string::test_pointer($stringPtr);
+
+$stringPtr = li_std_string::test_const_pointer_out();
+
+li_std_string::test_const_pointer($stringPtr);
+
+$stringPtr = li_std_string::test_reference_out();
+
+li_std_string::test_reference($stringPtr);
// Global variables
$s = "initial string";
@@ -24,11 +47,60 @@ check::equal($myStructure->ConstMemberString, "const member string", "ConstMembe
check::equal(Structure::StaticMemberString2(), "static member string 2", "StaticMemberString2 test 1");
Structure::StaticMemberString2($s);
check::equal(Structure::StaticMemberString2(), $s, "StaticMemberString2 test 2");
-// below broken ?
-//check::equal(Structure::ConstStaticMemberString(), "const static member string", "ConstStaticMemberString test");
+check::equal(Structure::ConstStaticMemberString(), "const static member string", "ConstStaticMemberString test");
+
+// Test INPUT, INOUT and OUTPUT string& typemaps:
+$input = "hello";
+check::equal(li_std_string::test_reference_input($input), "hello");
+// $input should be unchanged - this check is to catch if we incorrectly used
+// the default string& typemap:
+check::equal($input, "hello");
+$s = li_std_string::test_reference_inout($input);
+check::equal($s, "hellohello");
+// $input should be unchanged - this check is to catch if we incorrectly used
+// the default string& typemap:
+check::equal($input, "hello");
+check::equal(li_std_string::test_reference_output(), "output");
+
+// Test default PHP wrapping of std::string& as a by-ref PHP string parameter:
+$s = "byref";
+check::equal(li_std_string::test_reference_php($s), null);
+check::equal($s, "byref.php");
+
+// Test throwing strings:
+try {
+ test_throw();
+ check::fail("test_throw() didn't throw");
+} catch (Exception $s) {
+ check::equal($s->getMessage(), "test_throw message");
+}
+try {
+ test_const_reference_throw();
+ check::fail("test_const_reference_throw() didn't throw");
+} catch (Exception $s) {
+ check::equal($s->getMessage(), "test_const_reference_throw message");
+}
+try {
+ test_pointer_throw();
+ check::fail("test_pointer_throw() didn't throw");
+} catch (Exception $s) {
+ check::equal($s->getMessage(), "foo");
+}
+try {
+ test_const_pointer_throw();
+ check::fail("test_const_pointer_throw() didn't throw");
+} catch (Exception $s) {
+ check::equal($s->getMessage(), "foo");
+}
+
+check::equal(li_std_string::stdstring_empty(), "", "stdstring_empty test");
+check::equal(li_std_string::c_empty(), "", "c_empty test");
+check::isnull(li_std_string::c_null(), "c_null test");
+check::isnull(li_std_string::get_null(li_std_string::c_null()), "get_null c_null test");
+check::equal(li_std_string::get_null(li_std_string::c_empty()), "non-null", "get_null c_empty test");
+check::equal(li_std_string::get_null(li_std_string::stdstring_empty()), "non-null", "get_null stdstring_empty test");
// This used to give "Undefined variable: r"
li_std_string::test_const_reference_returning_void("foo");
check::done();
-?>
diff --git a/Examples/test-suite/php/li_std_vector_member_var_runme.php b/Examples/test-suite/php/li_std_vector_member_var_runme.php
index 238350352..32ce484fc 100644
--- a/Examples/test-suite/php/li_std_vector_member_var_runme.php
+++ b/Examples/test-suite/php/li_std_vector_member_var_runme.php
@@ -1,7 +1,6 @@
<?php
require "tests.php";
-require "li_std_vector_member_var.php";
$t = new Test();
@@ -27,4 +26,3 @@ check::equal($T->start_t->x, 4, "S::x != 4");
check::equal($T->length, 7, "T::length != 7");
check::done();
-?>
diff --git a/Examples/test-suite/php/long_long_runme.php b/Examples/test-suite/php/long_long_runme.php
new file mode 100644
index 000000000..544a59c18
--- /dev/null
+++ b/Examples/test-suite/php/long_long_runme.php
@@ -0,0 +1,65 @@
+<?php
+// This is the long_long runtime testcase. It checks that the long long and
+// unsigned long long types map correctly to PHP int or string (for values
+// which don't fit in a PHP int).
+
+require "tests.php";
+
+check::functions(array("foo1","foo2","foo3","foo4","foo5","foo6","bar1","bar2","bar3","bar4","bar5","bar6","UnsignedToSigned"));
+check::classes(array("long_long"));
+check::globals(array("ll","ull"));
+
+function check_ll($ll) {
+ long_long::ll_set($ll);
+ check::equivalent($ll, long_long::ll_get(), "Round tripping of long long failed");
+}
+
+function check_ull($ull) {
+ long_long::ull_set($ull);
+ check::equivalent($ull, long_long::ull_get(), "Round tripping of unsigned long long failed");
+}
+
+check_ll("0");
+check_ll(0);
+check_ll("9223372036854775807"); // 0x7FFFFFFFFFFFFFFF
+if ((int)0x100000000 !== 0) {
+ // This check doesn't work if PHP int is 32 bits.
+ check_ll(0x7FFFFFFFFFFFFFFF);
+}
+check_ll(-10);
+
+$testNumber = 0;
+const COUNT = 1025;
+
+for ($i=0; $i<COUNT; $i++) {
+ check_ull($testNumber);
+ $testNumber += 1;
+}
+
+$testNumber = 256*256/2-COUNT;
+for ($i=0; $i<COUNT*2; $i++) {
+ check_ull($testNumber);
+ $testNumber += 1;
+}
+
+$testNumber = 256*256-COUNT;
+for ($i=0; $i<COUNT*2; $i++) {
+ check_ull($testNumber);
+ $testNumber += 1;
+}
+
+$testNumber = 0x7FFFFFFFFFFFFFFF-COUNT;
+for ($i=0; $i<COUNT*2; $i++) {
+ check_ull($testNumber);
+ $testNumber += 1;
+}
+
+// Check that conversion from unsigned long long to long long gives expected
+// value (including negative numbers)
+
+check::equal(long_long::UnsignedToSigned(0), 0, "UnsignedToSigned test failed");
+check::equal(long_long::UnsignedToSigned(0xff), 0xff, "UnsignedToSigned test failed");
+check::equal(long_long::UnsignedToSigned(-0xff), -0xff, "UnsignedToSigned test failed");
+check::equal(long_long::UnsignedToSigned(-1), -1, "UnsignedToSigned test failed");
+
+check::done();
diff --git a/Examples/test-suite/php/member_pointer_const_runme.php b/Examples/test-suite/php/member_pointer_const_runme.php
new file mode 100644
index 000000000..bd8eaa87c
--- /dev/null
+++ b/Examples/test-suite/php/member_pointer_const_runme.php
@@ -0,0 +1,61 @@
+<?php
+
+require "tests.php";
+
+// Check functions.
+check::functions(array('do_op','do_op_td','areapt','perimeterpt','perimeterpt_td','call1'));
+
+// Check classes.
+check::classes(array('member_pointer_const','Circle','Funktions','Shape','Square'));
+
+// Check global variables.
+check::globals(array('areavar','perimetervar','perimetervar_td'));
+
+# Get the pointers
+
+$area_pt = member_pointer_const::areapt();
+$perim_pt = member_pointer_const::perimeterpt();
+
+# Create some objects
+
+$s = new Square(10);
+
+# Do some calculations
+
+check::equal(100.0, member_pointer_const::do_op($s, $area_pt), "Square area");
+check::equal(40.0, member_pointer_const::do_op($s, $perim_pt), "Square perim");
+
+
+$memberPtr = member_pointer_const::areavar_get();
+$memberPtr = member_pointer_const::perimetervar_get();
+
+# Try the variables
+check::equal(100.0, member_pointer_const::do_op($s, member_pointer_const::areavar_get()), "Square area");
+check::equal(40.0, member_pointer_const::do_op($s, member_pointer_const::perimetervar_get()), "Square perim");
+
+# Modify one of the variables
+member_pointer_const::areavar_set($perim_pt);
+
+check::equal(40.0, member_pointer_const::do_op($s, member_pointer_const::areavar_get()), "Square perimeter");
+
+# Try the constants
+
+/*
+$memberPtr = member_pointer_const::AREAPT;
+$memberPtr = member_pointer_const::PERIMPT;
+$memberPtr = member_pointer_const::NULLPT;
+
+check::equal(100.0, member_pointer_const::do_op($s, member_pointer_const::AREAPT), "Square area");
+check::equal(40.0, member_pointer_const::do_op($s, member_pointer_const::PERIMPT), "Square perim");
+*/
+
+# Typedefs
+check::equal(40.0, member_pointer_const::do_op_td($s, $perim_pt), "Square perim");
+
+/*
+check::equal(3, member_pointer_const::call1(member_pointer_const::ADD_BY_VALUE, 1, 2), "Add by value");
+check::equal(7, member_pointer_const::call2(member_pointer_const::ADD_BY_VALUE, 3, 4), "Add by pointer");
+check::equal(11, member_pointer_const::call3(member_pointer_const::ADD_BY_VALUE, 5, 6), "Add by reference");
+ */
+
+check::done();
diff --git a/Examples/test-suite/php/mod_runme.php b/Examples/test-suite/php/mod_runme.php
new file mode 100644
index 000000000..6e485ce80
--- /dev/null
+++ b/Examples/test-suite/php/mod_runme.php
@@ -0,0 +1,9 @@
+<?php
+
+require "tests.php";
+
+$c = new C();
+$d = new D();
+$d->DoSomething($c);
+
+check::done();
diff --git a/Examples/test-suite/php/multivalue_runme.php b/Examples/test-suite/php/multivalue_runme.php
new file mode 100644
index 000000000..77e1e1a82
--- /dev/null
+++ b/Examples/test-suite/php/multivalue_runme.php
@@ -0,0 +1,24 @@
+<?php
+
+require "tests.php";
+
+// New functions
+check::functions(array('divide_l','divide_v','divide_mv'));
+// New classes
+check::classes(array('multivalue'));
+// No new vars
+check::globals(array());
+
+$r = multivalue::divide_l(37, 5);
+check::equal($r[0], 7, "Test divide_l quotient");
+check::equal($r[1], 2, "Test divide_l remainder");
+
+$r = multivalue::divide_v(41, 7);
+check::equal($r[0], 5, "Test divide_v quotient");
+check::equal($r[1], 6, "Test divide_v remainder");
+
+$r = multivalue::divide_mv(91, 13);
+check::equal($r[0], 7, "Test divide_mv quotient");
+check::equal($r[1], 0, "Test divide_mv remainder");
+
+check::done();
diff --git a/Examples/test-suite/php/newobject1_runme.php b/Examples/test-suite/php/newobject1_runme.php
index 863e3e423..464f09b0b 100644
--- a/Examples/test-suite/php/newobject1_runme.php
+++ b/Examples/test-suite/php/newobject1_runme.php
@@ -1,19 +1,24 @@
<?php
require "tests.php";
-require "newobject1.php";
// No new functions
-check::functions(array('foo_makefoo','foo_makemore','foo_foocount'));
-// No new classes
+check::functions(array());
+// New classes
check::classes(array('Foo'));
-// now new vars
+// No new vars
check::globals(array());
+check::equal(Foo::fooCount(), 0, "no Foo objects expected");
$foo = Foo::makeFoo();
check::equal(get_class($foo), "Foo", "static failed");
+check::equal(Foo::fooCount(), 1, "1 Foo object expected");
$bar = $foo->makeMore();
check::equal(get_class($bar), "Foo", "regular failed");
+check::equal(Foo::fooCount(), 2, "2 Foo objects expected");
+$foo = null;
+check::equal(Foo::fooCount(), 1, "1 Foo object expected");
+$bar = null;
+check::equal(Foo::fooCount(), 0, "no Foo objects expected");
check::done();
-?>
diff --git a/Examples/test-suite/php/newobject2_runme.php b/Examples/test-suite/php/newobject2_runme.php
new file mode 100644
index 000000000..f20a6a4f9
--- /dev/null
+++ b/Examples/test-suite/php/newobject2_runme.php
@@ -0,0 +1,17 @@
+<?php
+
+require "tests.php";
+
+check::equal(fooCount(), 0, "no Foo objects expected");
+$foo = makeFoo();
+check::equal(get_class($foo), "Foo", "static failed");
+check::equal(fooCount(), 1, "1 Foo object expected");
+$bar = makeFoo();
+check::equal(get_class($bar), "Foo", "regular failed");
+check::equal(fooCount(), 2, "2 Foo objects expected");
+$foo = null;
+check::equal(fooCount(), 1, "1 Foo object expected");
+$bar = null;
+check::equal(fooCount(), 0, "no Foo objects expected");
+
+check::done();
diff --git a/Examples/test-suite/php/newobject3_runme.php b/Examples/test-suite/php/newobject3_runme.php
index edd5d8608..29e16be61 100644
--- a/Examples/test-suite/php/newobject3_runme.php
+++ b/Examples/test-suite/php/newobject3_runme.php
@@ -1,7 +1,6 @@
<?php
require "tests.php";
-require "newobject3.php";
$factory = new factory();
@@ -15,4 +14,4 @@ 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");
-?>
+check::done();
diff --git a/Examples/test-suite/php/overload_bool_runme.php b/Examples/test-suite/php/overload_bool_runme.php
new file mode 100644
index 000000000..e477330ef
--- /dev/null
+++ b/Examples/test-suite/php/overload_bool_runme.php
@@ -0,0 +1,42 @@
+<?php
+require "tests.php";
+
+# Overloading bool, int, string
+check::equal(overloaded(true), "bool", "wrong!");
+check::equal(overloaded(false), "bool", "wrong!");
+
+check::equal(overloaded(0), "int", "wrong!");
+check::equal(overloaded(1), "int", "wrong!");
+check::equal(overloaded(2), "int", "wrong!");
+
+check::equal(overloaded("1234"), "string", "wrong!");
+
+# Test bool masquerading as int
+check::equal(intfunction(true), "int", "wrong!");
+check::equal(intfunction(false), "int", "wrong!");
+
+# Test int masquerading as bool
+check::equal(boolfunction(1), "true", "wrong!");
+check::equal(boolfunction(0), "false", "wrong!");
+
+#############################################
+
+# Overloading bool, int, string
+check::equal(overloaded_ref(true), "bool", "wrong!");
+check::equal(overloaded_ref(false), "bool", "wrong!");
+
+check::equal(overloaded_ref(0), "int", "wrong!");
+check::equal(overloaded_ref(1), "int", "wrong!");
+check::equal(overloaded_ref(2), "int", "wrong!");
+
+check::equal(overloaded_ref("1234"), "string", "wrong!");
+
+# Test bool masquerading as int
+check::equal(intfunction_ref(true), "int", "wrong!");
+check::equal(intfunction_ref(false), "int", "wrong!");
+
+# Test int masquerading as bool
+check::equal(boolfunction(1), "true", "wrong!");
+check::equal(boolfunction(0), "false", "wrong!");
+
+check::done();
diff --git a/Examples/test-suite/php/overload_complicated_runme.php b/Examples/test-suite/php/overload_complicated_runme.php
new file mode 100644
index 000000000..6a5f8b480
--- /dev/null
+++ b/Examples/test-suite/php/overload_complicated_runme.php
@@ -0,0 +1,39 @@
+<?php
+require "tests.php";
+
+$pInt = NULL;
+
+# Check the correct constructors are available
+$p = new Pop($pInt);
+
+$p = new Pop($pInt, false);
+
+# Check overloaded in const only and pointers/references which target
+# languages cannot disambiguate
+check::equal($p->hip(false), 701, "Test 1 failed");
+
+check::equal($p->hip($pInt), 702, "Test 2 failed");
+
+# Reverse the order for the above
+check::equal($p->hop($pInt), 805, "Test 3 failed");
+
+check::equal($p->hop(false), 801, "Test 4 failed");
+
+# Few more variations and order shuffled
+check::equal($p->pop(false), 901, "Test 5 failed");
+
+check::equal($p->pop($pInt), 904, "Test 6 failed");
+
+check::equal($p->pop(), 905, "Test 7 failed");
+
+# Overload on const only
+check::equal($p->bop($pInt), 1001, "Test 8 failed");
+
+check::equal($p->bip($pInt), 2002, "Test 9 failed");
+
+# Globals
+check::equal(muzak(false), 3001, "Test 10 failed");
+
+check::equal(muzak($pInt), 3002, "Test 11 failed");
+
+check::done();
diff --git a/Examples/test-suite/php/overload_copy_runme.php b/Examples/test-suite/php/overload_copy_runme.php
new file mode 100644
index 000000000..893a715c5
--- /dev/null
+++ b/Examples/test-suite/php/overload_copy_runme.php
@@ -0,0 +1,13 @@
+<?php
+require "tests.php";
+
+// No new functions
+check::functions(array());
+check::classes(array('Foo'));
+// No new vars
+check::globals(array());
+
+$f = new Foo();
+$g = new Foo($f);
+
+check::done();
diff --git a/Examples/test-suite/php/overload_extend2_runme.php b/Examples/test-suite/php/overload_extend2_runme.php
new file mode 100644
index 000000000..6964a0d7a
--- /dev/null
+++ b/Examples/test-suite/php/overload_extend2_runme.php
@@ -0,0 +1,16 @@
+<?php
+require "tests.php";
+
+$f = new Foo();
+check::equal($f->test(3), 1, '$f->test(3)');
+check::equal($f->test("hello"), 2, '$f->test("hello")');
+check::equal($f->test(3.5, 2.5), 3, '$f->test(3.5, 2.5)');
+check::equal($f->test("hello", 20), 1020, '$f->test("hello", 20)');
+check::equal($f->test("hello", 20, 100), 120, '$f->test("hello", 20, 100)');
+
+// C default args
+check::equal($f->test($f), 30, '$f->test(f)');
+check::equal($f->test($f, 100), 120, '$f->test(f, 100)');
+check::equal($f->test($f, 100, 200), 300, '$f->test(f, 100, 200)');
+
+check::done();
diff --git a/Examples/test-suite/php/overload_extend_c_runme.php b/Examples/test-suite/php/overload_extend_c_runme.php
new file mode 100644
index 000000000..55f426c13
--- /dev/null
+++ b/Examples/test-suite/php/overload_extend_c_runme.php
@@ -0,0 +1,11 @@
+<?php
+require "tests.php";
+
+$f = new Foo();
+check::equal($f->test(), 0, '$f->test()');
+check::equal($f->test(3), 1, '$f->test(3)');
+check::equal($f->test("hello"), 2, '$f->test("hello")');
+check::equal($f->test(3.0, 2.0), 5.0, '$f->test(3, 2)');
+check::equal($f->test(3.0), 1003.0, '$f->test(3.0)');
+
+check::done();
diff --git a/Examples/test-suite/php/overload_extend_runme.php b/Examples/test-suite/php/overload_extend_runme.php
new file mode 100644
index 000000000..89c0499eb
--- /dev/null
+++ b/Examples/test-suite/php/overload_extend_runme.php
@@ -0,0 +1,11 @@
+<?php
+require "tests.php";
+
+$f = new Foo();
+check::equal($f->test(), 0, '$f->test()');
+check::equal($f->test(3), 1, '$f->test(3)');
+check::equal($f->test("hello"), 2, '$f->test("hello")');
+check::equal($f->test(3.0, 2.0), 5.0, '$f->test(3.0, 2.0)');
+check::equal($f->test(3.0), 1003.0, '$f->test(3.0)');
+
+check::done();
diff --git a/Examples/test-suite/php/overload_null_runme.php b/Examples/test-suite/php/overload_null_runme.php
index 22824d4fb..7afafeacd 100644
--- a/Examples/test-suite/php/overload_null_runme.php
+++ b/Examples/test-suite/php/overload_null_runme.php
@@ -1,7 +1,6 @@
<?php
require "tests.php";
-require "overload_null.php";
$o = new Overload();
$x = new X();
@@ -31,16 +30,15 @@ check::equal(14, $o->byval1cpr(null), "test 14");
check::equal(15, $o->byval2cpr(null), "test 15");
check::equal(16, $o->byval2cpr($x), "test 16");
-# forward class declaration
-check::equal(17, $o->byval1forwardptr($x), "test 17");
-check::equal(18, $o->byval1forwardptr(null), "test 18");
+# fwd class declaration
+check::equal(17, $o->byval1fwdptr($x), "test 17");
+check::equal(18, $o->byval1fwdptr(null), "test 18");
-check::equal(19, $o->byval2forwardptr(null), "test 19");
-check::equal(20, $o->byval2forwardptr($x), "test 20");
+check::equal(19, $o->byval2fwdptr(null), "test 19");
+check::equal(20, $o->byval2fwdptr($x), "test 20");
-check::equal(21, $o->byval1forwardref($x), "test 21");
+check::equal(21, $o->byval1fwdref($x), "test 21");
-check::equal(22, $o->byval2forwardref($x), "test 22");
+check::equal(22, $o->byval2fwdref($x), "test 22");
check::done();
-?>
diff --git a/Examples/test-suite/php/overload_numeric_runme.php b/Examples/test-suite/php/overload_numeric_runme.php
new file mode 100644
index 000000000..a346c0d16
--- /dev/null
+++ b/Examples/test-suite/php/overload_numeric_runme.php
@@ -0,0 +1,40 @@
+<?php
+require "tests.php";
+
+$nums = new Nums();
+$limits = new Limits();
+
+check::equal($nums->over(0), "signed char", '$nums->over(0)');
+check::equal($nums->over(0.0), "float", '$nums->over(0.0)');
+
+check::equal($nums->over($limits->schar_min()), "signed char", '$nums->over($limits->schar_min())');
+check::equal($nums->over($limits->schar_max()), "signed char", '$nums->over($limits->schar_max())');
+
+check::equal($nums->over($limits->schar_min() - 1), "short", '$nums->over($limits->schar_min() - 1)');
+check::equal($nums->over($limits->schar_max() + 1), "short", '$nums->over($limits->schar_max() + 1)');
+check::equal($nums->over($limits->shrt_min()), "short", '$nums->over($limits->shrt_min())');
+check::equal($nums->over($limits->shrt_max()), "short", '$nums->over($limits->shrt_max())');
+
+check::equal($nums->over($limits->shrt_min() - 1), "int", '$nums->over($limits->shrt_min() - 1)');
+check::equal($nums->over($limits->shrt_max() + 1), "int", '$nums->over($limits->shrt_max() + 1)');
+check::equal($nums->over($limits->int_min()), "int", '$nums->over($limits->int_min())');
+check::equal($nums->over($limits->int_max()), "int", '$nums->over($limits->int_max())');
+
+check::equal($nums->over($limits->flt_min()), "float", '$nums->over($limits->flt_min())');
+check::equal($nums->over($limits->flt_max()), "float", '$nums->over($limits->flt_max())');
+
+check::equal($nums->over($limits->flt_max() * 10), "double", '$nums->over($limits->flt_max() * 10)');
+check::equal($nums->over(-$limits->flt_max() * 10), "double", '$nums->over(-$limits->flt_max() * 10)');
+check::equal($nums->over($limits->dbl_max()), "double", '$nums->over($limits->dbl_max())');
+check::equal($nums->over(-$limits->dbl_max()), "double", '$nums->over(-$limits->dbl_max())');
+
+check::equal($nums->over(INF), "float", '$nums->over(INF)');
+check::equal($nums->over(-INF), "float", '$nums->over(-INF)');
+check::equal($nums->over(NAN), "float", '$nums->over(NAN)');
+
+// Just check if the following are accepted without exceptions being thrown
+$nums->doublebounce(INF);
+$nums->doublebounce(-INF);
+$nums->doublebounce(NAN);
+
+check::done();
diff --git a/Examples/test-suite/php/overload_polymorphic_runme.php b/Examples/test-suite/php/overload_polymorphic_runme.php
new file mode 100644
index 000000000..908988291
--- /dev/null
+++ b/Examples/test-suite/php/overload_polymorphic_runme.php
@@ -0,0 +1,12 @@
+<?php
+
+require "tests.php";
+
+$t = new Derived();
+
+check::equal(overload_polymorphic::test($t), 0, "test(Derived)");
+check::equal(overload_polymorphic::test(1), 1, "test(1)");
+check::equal(overload_polymorphic::test2($t), 1, "test2(Derived)");
+check::equal(overload_polymorphic::test3($t, null, $t), 1, "test3(Derived, null, Derived)");
+
+check::done();
diff --git a/Examples/test-suite/php/overload_rename_runme.php b/Examples/test-suite/php/overload_rename_runme.php
index 0357f91a6..c2df99034 100644
--- a/Examples/test-suite/php/overload_rename_runme.php
+++ b/Examples/test-suite/php/overload_rename_runme.php
@@ -1,13 +1,12 @@
<?php
require "tests.php";
-require "overload_rename.php";
// No new functions
check::functions(array());
-// No new classes
+// New classes
check::classes(array('Foo'));
-// now new vars
+// No new vars
check::globals(array());
$f = new Foo(1.0);
@@ -16,4 +15,3 @@ $f = Foo::Foo_int(1.0,1);
$f = Foo::Foo_int(1.0,1,1.0);
check::done();
-?>
diff --git a/Examples/test-suite/php/overload_return_type_runme.php b/Examples/test-suite/php/overload_return_type_runme.php
index 4fa19d22a..f03a85d7f 100644
--- a/Examples/test-suite/php/overload_return_type_runme.php
+++ b/Examples/test-suite/php/overload_return_type_runme.php
@@ -1,7 +1,6 @@
<?php
require "tests.php";
-require "overload_return_type.php";
$b = new B;
check::equal($b->foo(1), 0, "");
@@ -10,4 +9,4 @@ check::classname("A", $b->foo("test"));
check::equal(overload_return_type::foo(), 1, "overload_return_type::foo() should be 1");
check::equal(overload_return_type::bar(), 1, "overload_return_type::bar() should be 1");
-?>
+check::done();
diff --git a/Examples/test-suite/php/overload_simple_runme.php b/Examples/test-suite/php/overload_simple_runme.php
new file mode 100644
index 000000000..60cd7798d
--- /dev/null
+++ b/Examples/test-suite/php/overload_simple_runme.php
@@ -0,0 +1,195 @@
+<?php
+require "tests.php";
+
+check::functions(array('foo','blah','fbool','fint','fdouble','num','fid','as_l','as_ll','as_ul','as_ull','malloc_void','free_void','int_object','sizeof_long'));
+check::classes(array('Foo','Bar','overload_simple','Spam','ClassA'));
+// No new vars
+check::globals(array());
+
+$f = new Foo();
+check::classname("Foo", $f);
+$b = new Bar();
+check::classname("Bar", $b);
+$v = overload_simple::malloc_void(32);
+check::classname("SWIG\_p_void", $v);
+
+#
+# 'simple' dispatch (no overload) of int and double arguments
+#
+
+check::equal(overload_simple::fint(3), "fint:int", "fint(int) - int");
+
+check::equal(overload_simple::fint("1"), "fint:int", "fint(int) - string int");
+
+check::equal(overload_simple::fint(3.0), "fint:int", "fint(int) - double");
+
+check::equal(overload_simple::fint("3.0"), "fint:int", "fint(int) - string double");
+
+# Test handling of cases which aren't simple numbers.
+
+check::equal(overload_simple::fint("l"), "fint:int", "fint(int) - int");
+
+check::equal(overload_simple::fdouble("l"), "fdouble:double", "fint(double) - int");
+
+check::equal(overload_simple::fdouble("1.5/2.0"), "fdouble:double", "fint(double) - double");
+
+# adapted from Perl regression testcase
+$n = 3;
+$n = $n + 1;
+check::equal(overload_simple::fint($n), "fint:int", "fint(int) - int var");
+
+check::equal(overload_simple::fint(4/2), "fint:int", "fint(int) - divide int denom");
+
+check::equal(overload_simple::fint(4/2.0), "fint:int", "fint(int) - divide double denom");
+
+check::equal(overload_simple::fdouble(3), "fdouble:double", "fdouble(double) - int");
+
+check::equal(overload_simple::fdouble("3"), "fdouble:double", "fdouble(double) - string int");
+
+check::equal(overload_simple::fdouble(3.0), "fdouble:double", "fdouble(double) - double");
+
+check::equal(overload_simple::fdouble("3.0"), "fdouble:double", "fdouble(double) - string doubl");
+
+#
+# Overload between int and double
+#
+check::equal(overload_simple::num(3), "num:int", "num(int) - int");
+
+check::equal(overload_simple::num(3.0), "num:double", "num(int) - double");
+
+#
+# Overload between int, double, char * and many types.
+#
+check::equal(overload_simple::foo(3), "foo:int", "foo:int - int");
+
+check::equal(overload_simple::foo(3.0), "foo:double", "foo:double - double");
+
+check::equal(overload_simple::foo("3"), "foo:char *", "foo:char * - string int");
+
+check::equal(overload_simple::foo("3.0"), "foo:char *", "foo:char * - string double");
+
+check::equal(overload_simple::foo("hello"), "foo:char *", "foo:char * string");
+
+check::equal(overload_simple::foo($f), "foo:Foo *", "foo:Foo *");
+
+check::equal(overload_simple::foo($b), "foo:Bar *", "foo:Bar *");
+
+check::equal(overload_simple::foo($v), "foo:void *", "foo:void *");
+
+check::equal(overload_simple::blah("hello"), "blah:char *", "blah:char *");
+
+$s = new Spam();
+
+check::equal($s->foo(3), "foo:int", "Spam::foo:int");
+
+check::equal($s->foo(3.0), "foo:double", "Spam::foo(double)");
+
+check::equal($s->foo("hello"), "foo:char *", "Spam::foo:char *");
+
+check::equal($s->foo($f), "foo:Foo *", "Spam::foo(Foo *)");
+
+check::equal($s->foo($b), "foo:Bar *", "Spam::foo(Bar *)");
+
+check::equal($s->foo($v), "foo:void *", "Spam::foo(void *)");
+
+check::equal(Spam::bar(3), "bar:int", "Spam::bar(int)");
+
+check::equal(Spam::bar(3.0), "bar:double", "Spam::bar(double)");
+
+check::equal(Spam::bar("hello"), "bar:char *", "Spam::bar(char *)");
+
+check::equal(Spam::bar($f), "bar:Foo *", "Spam::bar(Foo *)");
+
+check::equal(Spam::bar($b), "bar:Bar *", "Spam::bar(Bar *)");
+
+check::equal(Spam::bar($v), "bar:void *", "Spam::bar(void *)");
+
+# Test constructors
+
+$s = new Spam();
+check::is_a($s, "spam");
+
+check::equal($s->type, "none", "Spam()");
+
+$s = new Spam(3);
+check::is_a($s, "spam");
+
+check::equal($s->type, "int", "Spam(int)");
+
+$s = new Spam(3.0);
+check::is_a($s, "spam");
+check::equal($s->type, "double", "Spam(double)");
+
+$s = new Spam("hello");
+check::is_a($s, "spam");
+check::equal($s->type, "char *", "Spam(char *)");
+
+$s = new Spam($f);
+check::is_a($s, "spam");
+check::equal($s->type, "Foo *", "Spam(Foo *)");
+
+$s = new Spam($b);
+check::is_a($s, "spam");
+check::equal($s->type, "Bar *", "Spam(Bar *)");
+
+$s = new Spam($v);
+check::is_a($s, "spam");
+check::equal($s->type, "void *", "Spam(void *)");
+
+#
+# Combine dispatch
+#
+
+check::equal(overload_simple::fid(3, 3.0), "fid:intdouble", "fid(int,double)");
+
+check::equal(overload_simple::fid(3.0, 3), "fid:doubleint", "fid(double,int)");
+
+check::equal(overload_simple::fid(3.0, 3.0), "fid:doubledouble", "fid(double,double)");
+
+check::equal(overload_simple::fid(3, 3), "fid:intint", "fid(int,int)");
+
+check::equal(false, overload_simple::fbool(false), "fbool(bool)");
+check::equal(true, overload_simple::fbool(true), "fbool(bool)");
+check::equal(2, overload_simple::fbool(2), "fbool(int)");
+
+# int and object overload
+
+check::equal(overload_simple::int_object(1), 1, "int_object(1)");
+check::equal(overload_simple::int_object(0), 0, "int_object(0)");
+check::equal(overload_simple::int_object(NULL), 999, "int_object(Spam*)");
+check::equal(overload_simple::int_object($s), 999, "int_object(Spam*)");
+
+function check($args, $want) {
+ if ($want === NULL) {
+ try {
+ eval("return Spam::bar($args);");
+ check::fail("Expected exception");
+ } catch (TypeError $e) {
+ check::equal(substr($e->getMessage(), 0, 35), "No matching function for overloaded", "Not the expected I expected");
+ }
+ return;
+ }
+ check::equal(eval("return Spam::bar($args);"), "bar:$want", "bar($args) => $want");
+}
+
+# normal use patterns
+check("11", 'int');
+check("11.0", 'double');
+check("'11'", 'char *');
+check("'11.0'", 'char *');
+check("-13", 'int');
+check("-13.0", 'double');
+check("'-13'", 'char *');
+check("'-13.0'", 'char *');
+
+check("' '", 'char *');
+check("' 11 '", 'char *');
+
+# Check TypeError is thrown when the wrong type is passed.
+check("array()", NULL);
+check("function(){}", NULL);
+check("new stdClass()", NULL);
+class NotASwigWrappedClass { };
+check("new NotASwigWrappedClass()", NULL);
+
+check::done();
diff --git a/Examples/test-suite/php/overload_subtype_runme.php b/Examples/test-suite/php/overload_subtype_runme.php
new file mode 100644
index 000000000..f12025cf8
--- /dev/null
+++ b/Examples/test-suite/php/overload_subtype_runme.php
@@ -0,0 +1,11 @@
+<?php
+require "tests.php";
+
+$f = new Foo();
+$b = new Bar();
+
+check::equal(spam($f), 1, "foo");
+
+check::equal(spam($b), 2, "bar");
+
+check::done();
diff --git a/Examples/test-suite/php/overload_template_fast_runme.php b/Examples/test-suite/php/overload_template_fast_runme.php
new file mode 100644
index 000000000..7aa19f693
--- /dev/null
+++ b/Examples/test-suite/php/overload_template_fast_runme.php
@@ -0,0 +1,110 @@
+<?php
+
+require "tests.php";
+
+$f = foo();
+
+$a = maximum(3, 4);
+$b = maximum(3.4, 5.2);
+
+# mix 1
+check::equal(mix1("hi"), 101, "mix1(const char*)");
+
+check::equal(mix1(1.0, 1.0), 102, "mix1(double, const double &)");
+
+check::equal(mix1(1.0), 103, "mix1(double)");
+
+# mix 2
+check::equal(mix2("hi"), 101, "mix2(const char*)");
+
+check::equal(mix2(1.0, 1.0), 102, "mix2(double, const double &)");
+
+check::equal(mix2(1.0), 103, "mix2(double)");
+
+# mix 3
+check::equal(mix3("hi"), 101, "mix3(const char*)");
+
+check::equal(mix3(1.0, 1.0), 102, "mix3(double, const double &)");
+
+check::equal(mix3(1.0), 103, "mix3(double)");
+
+# Combination 1
+check::equal(overtparams1(100), 10, "overtparams1(int)");
+
+check::equal(overtparams1(100.0, 100), 20, "overtparams1(double, int)");
+
+# Combination 2
+check::equal(overtparams2(100.0, 100), 40, "overtparams2(double, int)");
+
+# Combination 3
+check::equal(overloaded(), 60, "overloaded()");
+
+check::equal(overloaded(100.0, 100), 70, "overloaded(double, int)");
+
+# Combination 4
+check::equal(overloadedagain("hello"), 80, "overloadedagain(const char *)");
+
+check::equal(overloadedagain(), 90, "overloadedagain(double)");
+
+# specializations
+check::equal(specialization(10), 202, "specialization(int)");
+
+check::equal(specialization(10.0), 203, "specialization(double)");
+
+check::equal(specialization(10, 10), 204, "specialization(int, int)");
+
+check::equal(specialization(10.0, 10.0), 205, "specialization(double, double)");
+
+check::equal(specialization("hi", "hi"), 201, "specialization(const char *, const char *)");
+
+# simple specialization
+xyz();
+xyz_int();
+xyz_double();
+
+# a bit of everything
+check::equal(overload("hi"), 0, "overload()");
+
+check::equal(overload(1), 10, "overload(int t)");
+
+check::equal(overload(1, 1), 20, "overload(int t, const int &)");
+
+check::equal(overload(1, "hello"), 30, "overload(int t, const char *)");
+
+$k = new Klass();
+check::equal(overload($k), 10, "overload(Klass t)");
+
+check::equal(overload($k, $k), 20, "overload(Klass t, const Klass &)");
+
+check::equal(overload($k, "hello"), 30, "overload(Klass t, const char *)");
+
+check::equal(overload(10.0, "hi"), 40, "overload(double t, const char *)");
+
+check::equal(overload(), 50, "overload(const char *)");
+
+# everything put in a namespace
+check::equal(nsoverload("hi"), 1000, "nsoverload()");
+
+check::equal(nsoverload(1), 1010, "nsoverload(int t)");
+
+check::equal(nsoverload(1, 1), 1020, "nsoverload(int t, const int &)");
+
+check::equal(nsoverload(1, "hello"), 1030, "nsoverload(int t, const char *)");
+
+check::equal(nsoverload($k), 1010, "nsoverload(Klass t)");
+
+check::equal(nsoverload($k, $k), 1020, "nsoverload(Klass t, const Klass &)");
+
+check::equal(nsoverload($k, "hello"), 1030, "nsoverload(Klass t, const char *)");
+
+check::equal(nsoverload(10.0, "hi"), 1040, "nsoverload(double t, const char *)");
+
+check::equal(nsoverload(), 1050, "nsoverload(const char *)");
+
+
+A::foo(1);
+$b = new B();
+$b->foo(1);
+
+
+check::done();
diff --git a/Examples/test-suite/php/overload_template_runme.php b/Examples/test-suite/php/overload_template_runme.php
new file mode 100644
index 000000000..7aa19f693
--- /dev/null
+++ b/Examples/test-suite/php/overload_template_runme.php
@@ -0,0 +1,110 @@
+<?php
+
+require "tests.php";
+
+$f = foo();
+
+$a = maximum(3, 4);
+$b = maximum(3.4, 5.2);
+
+# mix 1
+check::equal(mix1("hi"), 101, "mix1(const char*)");
+
+check::equal(mix1(1.0, 1.0), 102, "mix1(double, const double &)");
+
+check::equal(mix1(1.0), 103, "mix1(double)");
+
+# mix 2
+check::equal(mix2("hi"), 101, "mix2(const char*)");
+
+check::equal(mix2(1.0, 1.0), 102, "mix2(double, const double &)");
+
+check::equal(mix2(1.0), 103, "mix2(double)");
+
+# mix 3
+check::equal(mix3("hi"), 101, "mix3(const char*)");
+
+check::equal(mix3(1.0, 1.0), 102, "mix3(double, const double &)");
+
+check::equal(mix3(1.0), 103, "mix3(double)");
+
+# Combination 1
+check::equal(overtparams1(100), 10, "overtparams1(int)");
+
+check::equal(overtparams1(100.0, 100), 20, "overtparams1(double, int)");
+
+# Combination 2
+check::equal(overtparams2(100.0, 100), 40, "overtparams2(double, int)");
+
+# Combination 3
+check::equal(overloaded(), 60, "overloaded()");
+
+check::equal(overloaded(100.0, 100), 70, "overloaded(double, int)");
+
+# Combination 4
+check::equal(overloadedagain("hello"), 80, "overloadedagain(const char *)");
+
+check::equal(overloadedagain(), 90, "overloadedagain(double)");
+
+# specializations
+check::equal(specialization(10), 202, "specialization(int)");
+
+check::equal(specialization(10.0), 203, "specialization(double)");
+
+check::equal(specialization(10, 10), 204, "specialization(int, int)");
+
+check::equal(specialization(10.0, 10.0), 205, "specialization(double, double)");
+
+check::equal(specialization("hi", "hi"), 201, "specialization(const char *, const char *)");
+
+# simple specialization
+xyz();
+xyz_int();
+xyz_double();
+
+# a bit of everything
+check::equal(overload("hi"), 0, "overload()");
+
+check::equal(overload(1), 10, "overload(int t)");
+
+check::equal(overload(1, 1), 20, "overload(int t, const int &)");
+
+check::equal(overload(1, "hello"), 30, "overload(int t, const char *)");
+
+$k = new Klass();
+check::equal(overload($k), 10, "overload(Klass t)");
+
+check::equal(overload($k, $k), 20, "overload(Klass t, const Klass &)");
+
+check::equal(overload($k, "hello"), 30, "overload(Klass t, const char *)");
+
+check::equal(overload(10.0, "hi"), 40, "overload(double t, const char *)");
+
+check::equal(overload(), 50, "overload(const char *)");
+
+# everything put in a namespace
+check::equal(nsoverload("hi"), 1000, "nsoverload()");
+
+check::equal(nsoverload(1), 1010, "nsoverload(int t)");
+
+check::equal(nsoverload(1, 1), 1020, "nsoverload(int t, const int &)");
+
+check::equal(nsoverload(1, "hello"), 1030, "nsoverload(int t, const char *)");
+
+check::equal(nsoverload($k), 1010, "nsoverload(Klass t)");
+
+check::equal(nsoverload($k, $k), 1020, "nsoverload(Klass t, const Klass &)");
+
+check::equal(nsoverload($k, "hello"), 1030, "nsoverload(Klass t, const char *)");
+
+check::equal(nsoverload(10.0, "hi"), 1040, "nsoverload(double t, const char *)");
+
+check::equal(nsoverload(), 1050, "nsoverload(const char *)");
+
+
+A::foo(1);
+$b = new B();
+$b->foo(1);
+
+
+check::done();
diff --git a/Examples/test-suite/php/php_iterator_runme.php b/Examples/test-suite/php/php_iterator_runme.php
index fd645ccb2..76b4757fc 100644
--- a/Examples/test-suite/php/php_iterator_runme.php
+++ b/Examples/test-suite/php/php_iterator_runme.php
@@ -1,9 +1,9 @@
<?php
require "tests.php";
-require "php_iterator.php";
-check::functions(array('myiterator_rewind','myiterator_key','myiterator_current','myiterator_next','myiterator_valid'));
+// No new functions.
+check::functions(array());
check::classes(array('MyIterator'));
// No new global variables.
check::globals(array());
@@ -21,4 +21,3 @@ foreach (new MyIterator(2, 5) as $k => $v) {
check::equal($s, '(0=>2)(1=>3)(2=>4)', 'Simple iteration failed');
check::done();
-?>
diff --git a/Examples/test-suite/php/php_pragma_runme.php b/Examples/test-suite/php/php_pragma_runme.php
index c76cfc9b5..cf297701d 100644
--- a/Examples/test-suite/php/php_pragma_runme.php
+++ b/Examples/test-suite/php/php_pragma_runme.php
@@ -1,11 +1,14 @@
<?php
require "tests.php";
-require "php_pragma.php";
+// No new functions
+check::functions(array());
+// No new classes
+check::classes(array());
+// No new vars
+check::globals(array());
check::equal('1.5',(new ReflectionExtension('php_pragma'))->getVersion(),"1.5==version(php_pragma)");
check::done();
-
-?>
diff --git a/Examples/test-suite/php/pointer_reference_runme.php b/Examples/test-suite/php/pointer_reference_runme.php
index 52946177e..a8a511271 100644
--- a/Examples/test-suite/php/pointer_reference_runme.php
+++ b/Examples/test-suite/php/pointer_reference_runme.php
@@ -1,7 +1,6 @@
<?php
require "tests.php";
-require "pointer_reference.php";
$s = pointer_reference::get();
check::equal($s->value, 10, "pointer_reference::get() failed");
@@ -15,4 +14,3 @@ check::equal(pointer_reference::overloading(1), 111, "overload test 1 failed");
check::equal(pointer_reference::overloading($ss), 222, "overload test 2 failed");
check::done();
-?>
diff --git a/Examples/test-suite/php/prefix_runme.php b/Examples/test-suite/php/prefix_runme.php
index fcf7c66f6..9f83df1e1 100644
--- a/Examples/test-suite/php/prefix_runme.php
+++ b/Examples/test-suite/php/prefix_runme.php
@@ -1,18 +1,18 @@
<?php
require "tests.php";
-require "prefix.php";
-// No new functions
-check::functions(array('foo_get_self'));
-// No new classes
-check::classes(array('ProjectFoo'));
-// now new vars
+// New functions
+check::functions(array('self'));
+// New classes
+check::classes(array('Project','ProjectBar','ProjectFoo'));
+// No new vars
check::globals(array());
$f = new ProjectFoo();
// This resulted in "Fatal error: Class 'Foo' not found"
$f->get_self();
+Project::self(new ProjectBar());
+
check::done();
-?>
diff --git a/Examples/test-suite/php/preproc_constants_c_runme.php b/Examples/test-suite/php/preproc_constants_c_runme.php
index 20868dcc0..b48409c24 100644
--- a/Examples/test-suite/php/preproc_constants_c_runme.php
+++ b/Examples/test-suite/php/preproc_constants_c_runme.php
@@ -1,7 +1,6 @@
<?php
require "tests.php";
-require "preproc_constants_c.php";
// Same as preproc_constants.i testcase, but bool types are int instead
check::equal(gettype(preproc_constants_c::CONST_INT1), "integer", "preproc_constants.CONST_INT1 has unexpected type");
@@ -27,8 +26,10 @@ check::equal(gettype(preproc_constants_c::CONST_DOUBLE1), "double", "preproc_con
check::equal(gettype(preproc_constants_c::CONST_DOUBLE2), "double", "preproc_constants.CONST_DOUBLE2 has unexpected type");
check::equal(gettype(preproc_constants_c::CONST_DOUBLE3), "double", "preproc_constants.CONST_DOUBLE3 has unexpected type");
check::equal(gettype(preproc_constants_c::CONST_DOUBLE4), "double", "preproc_constants.CONST_DOUBLE4 has unexpected type");
-check::equal(gettype(preproc_constants_c::CONST_DOUBLE5), "double", "preproc_constants.CONST_DOUBLE5 has unexpected type");
-check::equal(gettype(preproc_constants_c::CONST_DOUBLE6), "double", "preproc_constants.CONST_DOUBLE6 has unexpected type");
+# C/C++ `float` constants are wrapped as PHP `double` as PHP doesn't have a
+# `float` type.
+check::equal(gettype(preproc_constants_c::CONST_FLOAT1), "double", "preproc_constants.CONST_FLOAT1 has unexpected type");
+check::equal(gettype(preproc_constants_c::CONST_FLOAT2), "double", "preproc_constants.CONST_FLOAT2 has unexpected type");
check::equal(gettype(preproc_constants_c::CONST_BOOL1), "integer", "preproc_constants.CONST_BOOL1 has unexpected type");
check::equal(gettype(preproc_constants_c::CONST_BOOL2), "integer", "preproc_constants.CONST_BOOL2 has unexpected type");
check::equal(gettype(preproc_constants_c::CONST_CHAR), "string", "preproc_constants.CONST_CHAR has unexpected type");
@@ -52,6 +53,8 @@ check::equal(gettype(preproc_constants_c::EXPR_PLUS), "integer", "preproc_consta
check::equal(gettype(preproc_constants_c::EXPR_MINUS), "integer", "preproc_constants.EXPR_MINUS has unexpected type");
check::equal(gettype(preproc_constants_c::EXPR_LSHIFT), "integer", "preproc_constants.EXPR_LSHIFT has unexpected type");
check::equal(gettype(preproc_constants_c::EXPR_RSHIFT), "integer", "preproc_constants.EXPR_RSHIFT has unexpected type");
+check::equal(gettype(preproc_constants_c::EXPR_LT), "integer", "preproc_constants.EXPR_LT has unexpected type");
+check::equal(gettype(preproc_constants_c::EXPR_GT), "integer", "preproc_constants.EXPR_GT has unexpected type");
check::equal(gettype(preproc_constants_c::EXPR_LTE), "integer", "preproc_constants.EXPR_LTE has unexpected type");
check::equal(gettype(preproc_constants_c::EXPR_GTE), "integer", "preproc_constants.EXPR_GTE has unexpected type");
check::equal(gettype(preproc_constants_c::EXPR_INEQUALITY), "integer", "preproc_constants.EXPR_INEQUALITY has unexpected type");
@@ -66,4 +69,4 @@ check::equal(gettype(preproc_constants_c::EXPR_MIXED1), "double", "preproc_const
check::equal(gettype(preproc_constants_c::EXPR_WCHAR_MAX), "integer", "preproc_constants.EXPR_WCHAR_MAX has unexpected type");
check::equal(gettype(preproc_constants_c::EXPR_WCHAR_MIN), "integer", "preproc_constants.EXPR_WCHAR_MIN has unexpected type");
-?>
+check::done();
diff --git a/Examples/test-suite/php/preproc_constants_runme.php b/Examples/test-suite/php/preproc_constants_runme.php
index bd216c269..3d550e115 100644
--- a/Examples/test-suite/php/preproc_constants_runme.php
+++ b/Examples/test-suite/php/preproc_constants_runme.php
@@ -1,7 +1,6 @@
<?php
require "tests.php";
-require "preproc_constants.php";
check::equal(gettype(preproc_constants::CONST_INT1), "integer", "preproc_constants.CONST_INT1 has unexpected type");
check::equal(gettype(preproc_constants::CONST_INT2), "integer", "preproc_constants.CONST_INT2 has unexpected type");
@@ -26,8 +25,10 @@ check::equal(gettype(preproc_constants::CONST_DOUBLE1), "double", "preproc_const
check::equal(gettype(preproc_constants::CONST_DOUBLE2), "double", "preproc_constants.CONST_DOUBLE2 has unexpected type");
check::equal(gettype(preproc_constants::CONST_DOUBLE3), "double", "preproc_constants.CONST_DOUBLE3 has unexpected type");
check::equal(gettype(preproc_constants::CONST_DOUBLE4), "double", "preproc_constants.CONST_DOUBLE4 has unexpected type");
-check::equal(gettype(preproc_constants::CONST_DOUBLE5), "double", "preproc_constants.CONST_DOUBLE5 has unexpected type");
-check::equal(gettype(preproc_constants::CONST_DOUBLE6), "double", "preproc_constants.CONST_DOUBLE6 has unexpected type");
+# C/C++ `float` constants are wrapped as PHP `double` as PHP doesn't have a
+# `float` type.
+check::equal(gettype(preproc_constants::CONST_FLOAT1), "double", "preproc_constants.CONST_FLOAT1 has unexpected type");
+check::equal(gettype(preproc_constants::CONST_FLOAT2), "double", "preproc_constants.CONST_FLOAT2 has unexpected type");
check::equal(gettype(preproc_constants::CONST_BOOL1), "boolean", "preproc_constants.CONST_BOOL1 has unexpected type");
check::equal(gettype(preproc_constants::CONST_BOOL2), "boolean", "preproc_constants.CONST_BOOL2 has unexpected type");
check::equal(gettype(preproc_constants::CONST_CHAR), "string", "preproc_constants.CONST_CHAR has unexpected type");
@@ -51,6 +52,8 @@ check::equal(gettype(preproc_constants::EXPR_PLUS), "integer", "preproc_constant
check::equal(gettype(preproc_constants::EXPR_MINUS), "integer", "preproc_constants.EXPR_MINUS has unexpected type");
check::equal(gettype(preproc_constants::EXPR_LSHIFT), "integer", "preproc_constants.EXPR_LSHIFT has unexpected type");
check::equal(gettype(preproc_constants::EXPR_RSHIFT), "integer", "preproc_constants.EXPR_RSHIFT has unexpected type");
+check::equal(gettype(preproc_constants::EXPR_LT), "boolean", "preproc_constants.EXPR_LT has unexpected type");
+check::equal(gettype(preproc_constants::EXPR_GT), "boolean", "preproc_constants.EXPR_GT has unexpected type");
check::equal(gettype(preproc_constants::EXPR_LTE), "boolean", "preproc_constants.EXPR_LTE has unexpected type");
check::equal(gettype(preproc_constants::EXPR_GTE), "boolean", "preproc_constants.EXPR_GTE has unexpected type");
check::equal(gettype(preproc_constants::EXPR_INEQUALITY), "boolean", "preproc_constants.EXPR_INEQUALITY has unexpected type");
@@ -65,4 +68,4 @@ check::equal(gettype(preproc_constants::EXPR_MIXED1), "double", "preproc_constan
check::equal(gettype(preproc_constants::EXPR_WCHAR_MAX), "integer", "preproc_constants.EXPR_WCHAR_MAX has unexpected type");
check::equal(gettype(preproc_constants::EXPR_WCHAR_MIN), "integer", "preproc_constants.EXPR_WCHAR_MIN has unexpected type");
-?>
+check::done();
diff --git a/Examples/test-suite/php/primitive_ref_runme.php b/Examples/test-suite/php/primitive_ref_runme.php
index 263a28074..9b281cf50 100644
--- a/Examples/test-suite/php/primitive_ref_runme.php
+++ b/Examples/test-suite/php/primitive_ref_runme.php
@@ -1,7 +1,6 @@
<?php
require "tests.php";
-require "primitive_ref.php";
# A large long long number is too big, so PHP makes treats it as a double, but SWIG opts to return it as a string.
# The conversion to double can lose precision so this isn't an exact comparison.
@@ -31,4 +30,3 @@ long_long_equal(ref_longlong(0x123456789ABCDEF0), 0x123456789ABCDEF0, "ref_longl
long_long_equal(ref_ulonglong(0xF23456789ABCDEF0), 0xF23456789ABCDEF0, "ref_ulonglong failed");
check::done();
-?>
diff --git a/Examples/test-suite/php/rename_camel_runme.php b/Examples/test-suite/php/rename_camel_runme.php
new file mode 100644
index 000000000..9aaeda01d
--- /dev/null
+++ b/Examples/test-suite/php/rename_camel_runme.php
@@ -0,0 +1,13 @@
+<?php
+
+require "tests.php";
+
+// We want to fail if any extra classes/function/constants are defined.
+check::werror(true);
+
+check::classes(array("rename_camel","GeometryFactory","ByteOrderValues"));
+check::functions(array("CamelCase","CamelCase1","CamelCase2","CamelCase3","lowerCamelCase","lowerCamelCase1","lowerCamelCase2","lowerCamelCase3","under_case","under_case1","under_case2","under_case3","Import","foo","hello"));
+check::constants(array("HELLO","HI_THERE","BYE","SEE_YOU"));
+
+
+check::done();
diff --git a/Examples/test-suite/php/rename_scope_runme.php b/Examples/test-suite/php/rename_scope_runme.php
index df620d796..e1db4f59c 100644
--- a/Examples/test-suite/php/rename_scope_runme.php
+++ b/Examples/test-suite/php/rename_scope_runme.php
@@ -1,7 +1,6 @@
<?php
require "tests.php";
-require "rename_scope.php";
check::classes(array("rename_scope","Interface_UP","Interface_BP","Natural_UP","Natural_BP","Bucket"));
@@ -13,4 +12,3 @@ check::classparent("Natural_UP","Interface_UP");
check::classparent("Natural_BP","Interface_BP");
check::done();
-?>
diff --git a/Examples/test-suite/php/skel.php b/Examples/test-suite/php/skel.php
index 780a999ed..7fdebc7d6 100644
--- a/Examples/test-suite/php/skel.php
+++ b/Examples/test-suite/php/skel.php
@@ -2,14 +2,12 @@
// Sample test file
require "tests.php";
-require "____.php";
// No new functions
check::functions(array());
// No new classes
check::classes(array());
-// now new vars
+// No new vars
check::globals(array());
check::done();
-?>
diff --git a/Examples/test-suite/php/smart_pointer_rename_runme.php b/Examples/test-suite/php/smart_pointer_rename_runme.php
index 26692dde5..094860386 100644
--- a/Examples/test-suite/php/smart_pointer_rename_runme.php
+++ b/Examples/test-suite/php/smart_pointer_rename_runme.php
@@ -1,7 +1,6 @@
<?php
require "tests.php";
-require "smart_pointer_rename.php";
check::classes(array("Foo","Bar"));
check::classmethods("foo",array("ftest1","ftest2","__set","__isset","__get","__construct"));
@@ -24,4 +23,3 @@ check::equal(3,$bar->test(),"bar->test");
check::classname("foo",$bar->__deref__());
check::done();
-?>
diff --git a/Examples/test-suite/php/smart_pointer_static_runme.php b/Examples/test-suite/php/smart_pointer_static_runme.php
new file mode 100644
index 000000000..71f7a74ee
--- /dev/null
+++ b/Examples/test-suite/php/smart_pointer_static_runme.php
@@ -0,0 +1,18 @@
+<?php
+
+require "tests.php";
+
+check::classes(array("Foo2","MyHandle_Foo2"));
+
+// This doesn't actually test any smart pointer stuff, just that static
+// vs non-static overloading is wrapped suitable (fixed in SWIG 4.2.0).
+//
+// We can't make the same wrapped method both static and non-static in PHP
+// so we make it non-static, and that at least allows the static version
+// to be called via an object.
+$foo2=new Foo2();
+check::classname("foo2",$foo2);
+check::equal($foo2->sum(1,2), 3);
+check::equal($foo2->sum(1,2,3), 6);
+
+check::done();
diff --git a/Examples/test-suite/php/swig_exception_runme.php b/Examples/test-suite/php/swig_exception_runme.php
index 76641996e..c218890e4 100644
--- a/Examples/test-suite/php/swig_exception_runme.php
+++ b/Examples/test-suite/php/swig_exception_runme.php
@@ -1,6 +1,5 @@
<?php
-require("swig_exception.php");
require("tests.php");
$c = new Circle(10);
@@ -30,4 +29,4 @@ if (Shape::nshapes() != 0) {
check::fail("Shape::nshapes() should be 0, actually ".Shape::nshapes());
}
-?>
+check::done();
diff --git a/Examples/test-suite/php/sym_runme.php b/Examples/test-suite/php/sym_runme.php
index 127d28fd9..7e8f914c1 100644
--- a/Examples/test-suite/php/sym_runme.php
+++ b/Examples/test-suite/php/sym_runme.php
@@ -1,13 +1,12 @@
<?php
require "tests.php";
-require "sym.php";
// No new functions
check::functions(array());
-// No new classes
-check::classes(array('flim','flam'));
-// now new vars
+// New classes
+check::classes(array('Flim','Flam'));
+// No new vars
check::globals(array());
$flim=new flim();
@@ -19,4 +18,3 @@ check::equal($flam->jam(),"flam-jam","flam()->jam==flam-jam");
check::equal($flam->jar(),"flam-jar","flam()->jar==flam-jar");
check::done();
-?>
diff --git a/Examples/test-suite/php/template_arg_typename_runme.php b/Examples/test-suite/php/template_arg_typename_runme.php
index e609240e7..c7fcbbd9d 100644
--- a/Examples/test-suite/php/template_arg_typename_runme.php
+++ b/Examples/test-suite/php/template_arg_typename_runme.php
@@ -1,7 +1,6 @@
<?php
require "tests.php";
-require "template_arg_typename.php";
// No new functions
check::functions(array());
@@ -15,4 +14,3 @@ $bufb=new boolunaryfunction_bool($whatisthis);
check::is_a($bufb,"boolunaryfunction_bool");
check::done();
-?>
diff --git a/Examples/test-suite/php/template_construct_runme.php b/Examples/test-suite/php/template_construct_runme.php
index b227d9fec..84d6abf45 100644
--- a/Examples/test-suite/php/template_construct_runme.php
+++ b/Examples/test-suite/php/template_construct_runme.php
@@ -1,11 +1,9 @@
<?php
require "tests.php";
-require "template_construct.php";
-check::classes(array('Foo_int'));
+check::classes(array('Foo_int','Foo_short'));
$foo_int=new foo_int(3);
check::is_a($foo_int,"foo_int","Made a foo_int");
check::done();
-?>
diff --git a/Examples/test-suite/php/tests.php b/Examples/test-suite/php/tests.php
index 20fa1ed98..1136d7a37 100644
--- a/Examples/test-suite/php/tests.php
+++ b/Examples/test-suite/php/tests.php
@@ -1,86 +1,31 @@
<?php
-function die_on_error($errno, $errstr, $file, $line) {
- if ($file !== Null) {
- print $file;
- if ($line !== Null) print ":$line";
- print ": ";
- }
- print "$errstr\n";
- exit(1);
-}
-set_error_handler("die_on_error", -1);
-
-$_original_functions=get_defined_functions();
-$_original_globals=1;
-$_original_classes=get_declared_classes();
-$_original_globals=array_keys($GLOBALS);
-
class check {
// do we have true global vars or just GETSET functions?
// Used to filter out get/set global functions to fake vars...
const GETSET = 1;
- static function get_extra_classes($ref=FALSE) {
- static $extra;
- global $_original_classes;
- if ($ref===FALSE) $f=$_original_classes;
- if (! is_array($extra)) {
- $df=array_flip(get_declared_classes());
- foreach($_original_classes as $class) unset($df[$class]);
- $extra=array_keys($df);
- }
- return $extra;
- }
-
- static function get_extra_functions($ref=FALSE,$gs=false) {
- static $extra;
- static $extrags; // for get/setters
- global $_original_functions;
- if ($ref===FALSE) $f=$_original_functions;
- if (! is_array($extra) || $gs) {
- $extra=array();
- $extrags=array();
- $df=get_defined_functions();
- $df=array_flip($df['internal']);
- foreach($_original_functions['internal'] as $func) unset($df[$func]);
- // Now chop out any get/set accessors
- foreach(array_keys($df) as $func)
- if ((self::GETSET && preg_match('/_[gs]et$/', $func)) ||
- preg_match('/^new_/', $func) ||
- preg_match('/_(alter|get)_newobject$/', $func))
- $extrags[]=$func;
- else $extra[]=$func;
-// $extra=array_keys($df);
- }
- if ($gs) return $extrags;
- return $extra;
- }
-
- static function get_extra_globals($ref=FALSE) {
- static $extra;
- global $_original_globals;
- if (! is_array($extra)) {
- if (self::GETSET) {
- $_extra=array();
- foreach(check::get_extra_functions(false,1) as $global) {
- if (preg_match('/^(.*)_[sg]et$/', $global, $match))
- $_extra[$match[1]] = 1;
- }
- $extra=array_keys($_extra);
- } else {
- if ($ref===FALSE) $ref=$_original_globals;
- if (! is_array($extra)) {
- $df=array_flip(array_keys($GLOBALS));
- foreach($_original_globals as $func) unset($df[$func]);
- // MASK xxxx_LOADED__ variables
- foreach(array_keys($df) as $func)
- if (preg_match('/_LOADED__$/', $func)) unset($df[$func]);
- $extra=array_keys($df);
- }
+ private static $_extension = null;
+
+ private static $_werror = false;
+
+ static function get_extension() {
+ if (self::$_extension === null) {
+ foreach(get_included_files() as $f) {
+ $module_name = preg_filter('/.*\/([^\/]+)_runme\.php$/', '\1', $f);
+ if ($module_name !== null) break;
}
+ if ($module_name === null) {
+ print("Failed to determine module name from get_included_files()\n");
+ exit(1);
+ }
+ self::$_extension = new ReflectionExtension($module_name);
}
- return $extra;
+ return self::$_extension;
+ }
+
+ static function werror($v) {
+ self::$_werror = $v;
}
static function classname($string,$object) {
@@ -148,7 +93,8 @@ class check {
if (! is_array($classes)) $classes=array($classes);
$message=array();
$missing=array();
- $extra=array_flip(check::get_extra_classes());
+ $extra = array_flip(array_filter(self::get_extension()->getClassNames(),
+ function ($e) { return !preg_match('/^SWIG\\\\/', $e); }));
foreach($classes as $class) {
if (! class_exists($class)) $missing[]=$class;
else unset($extra[$class]);
@@ -164,15 +110,16 @@ class check {
if (! is_array($functions)) $functions=array($functions);
$message=array();
$missing=array();
- $extra=array_flip(check::get_extra_functions());
-
+ $extra = self::get_extension()->getFunctions();
foreach ($functions as $func) {
if (! function_exists($func)) $missing[]=$func;
else unset($extra[$func]);
}
+ $extra = array_filter(array_keys($extra),
+ function ($e) { return !preg_match('/_[gs]et$|^is_python_/', $e); });
if ($missing) $message[]=sprintf("Functions missing: %s",join(",",$missing));
if ($message) return check::fail(join("\n ",$message));
- if ($extra) $message[]=sprintf("These extra functions are defined: %s",join(",",array_keys($extra)));
+ if ($extra) $message[]=sprintf("These extra functions are defined: %s",join(",",$extra));
if ($message) return check::warn(join("\n ",$message));
return TRUE;
}
@@ -181,64 +128,82 @@ class check {
if (! is_array($globals)) $globals=array($globals);
$message=array();
$missing=array();
- $extra=array_flip(check::get_extra_globals());
+ $extra = self::get_extension()->getFunctions();
foreach ($globals as $glob) {
- if (self::GETSET) {
- if (! isset($extra[$glob])) $missing[]=$glob;
- else unset($extra[$glob]);
- } else {
- if (! isset($GLOBALS[$glob])) $missing[]=$glob;
- else unset($extra[$glob]);
+ if (! function_exists($glob . "_get") && ! function_exists($glob . "_set")) $missing[]=$glob;
+ else {
+ unset($extra[$glob . "_get"]);
+ unset($extra[$glob . "_set"]);
}
}
+ $extra = array_filter(array_keys($extra),
+ function ($e) { return preg_match('/_[gs]et$/', $e); });
if ($missing) $message[]=sprintf("Globals missing: %s",join(",",$missing));
if ($message) return check::fail(join("\n ",$message));
- if ($extra) $message[]=sprintf("These extra globals are defined: %s",join(",",array_keys($extra)));
+ if ($extra) $message[]=sprintf("These extra globals are defined: %s",join(",",$extra));
if ($message) return check::warn(join("\n ",$message));
return TRUE;
}
+ static function constants($constants) {
+ if (! is_array($constants)) $constants=array($constants);
+ $message=array();
+ $missing=array();
+ $extra = self::get_extension()->getConstants();
+ unset($extra['swig_runtime_data_type_pointer']);
+ foreach($constants as $constant) {
+ if (! defined($constant)) $missing[]=$constant;
+ else unset($extra[$constant]);
+ }
+ if ($missing) $message[]=sprintf("Constants missing: %s",join(",",$missing));
+ if ($message) return check::fail(join("\n ",$message));
+ if ($extra) $message[]=sprintf("These extra constants are defined: %s",join(",",array_keys($extra)));
+ if ($message) return check::warn(join("\n ",$message));
+ return TRUE;
+ }
+
static function functionref($a,$type,$message) {
if (! preg_match("/^_[a-f0-9]+$type$/i", $a))
return check::fail($message);
return TRUE;
}
- static function equal($a,$b,$message) {
- if (! ($a===$b)) return check::fail($message . ": '$a'!=='$b'");
+ static function equal($a,$b,$message=null) {
+ if (! ($a===$b)) return check::fail_($message, "'$a'!=='$b'");
return TRUE;
}
- static function resource($a,$b,$message) {
- $resource=trim(check::var_dump($a));
- if (! preg_match("/^resource\([0-9]+\) of type \($b\)/i", $resource))
- return check::fail($message);
+ static function equivalent($a,$b,$message=null) {
+ if (! ($a==$b)) return check::fail_($message, "'$a'!='$b'");
return TRUE;
}
- static function isnull($a,$message) {
- $value=trim(check::var_dump($a));
- return check::equal($value,"NULL",$message);
+ static function str_contains($a,$b,$message=null) {
+ # Use strpos as PHP function str_contains requires PHP 8
+ return check::equal(strpos($a,$b)!==false,true,$message);
}
- static function var_dump($arg) {
- ob_start();
- var_dump($arg);
- $result=ob_get_contents();
- ob_end_clean();
- return $result;
+ static function isnull($a,$message=null) {
+ return check::equal($a,NULL,$message);
}
- static function fail($pattern) {
- $args=func_get_args();
- print("Failed on: ".call_user_func_array("sprintf",$args)."\n");
+ private static function fail_($message, $pattern, ...$args) {
+ $bt = debug_backtrace(0);
+ $bt = $bt[array_key_last($bt)-1];
+ print("{$bt['file']}:{$bt['line']}: Failed on: ");
+ if ($message !== NULL) print("$message: ");
+ print(sprintf($pattern, ...$args) . "\n");
exit(1);
}
- static function warn($pattern) {
- $args=func_get_args();
- print("Warning on: ".call_user_func_array("sprintf",$args)."\n");
+ static function fail(...$args) {
+ check::fail_(null, ...$args);
+ }
+
+ static function warn($pattern, ...$args) {
+ if (self::$_werror) self::fail($pattern, ...$args);
+ print("Warning on: " . sprintf($pattern, ...$args) . "\n");
return FALSE;
}
@@ -246,4 +211,3 @@ class check {
# print $_SERVER[argv][0]." ok\n";
}
}
-?>
diff --git a/Examples/test-suite/php/threads_exception_runme.php b/Examples/test-suite/php/threads_exception_runme.php
index 80717eb88..e9103f018 100644
--- a/Examples/test-suite/php/threads_exception_runme.php
+++ b/Examples/test-suite/php/threads_exception_runme.php
@@ -1,14 +1,13 @@
<?php
require "tests.php";
-require "threads_exception.php";
-// Check functions
-check::functions(array('test_simple','test_message','test_hosed','test_unknown','test_multi','is_python_builtin'));
+// No new functions
+check::functions(array());
// Check classes.
check::classes(array('Exc','Test','threads_exception'));
-// Check globals.
-check::globals(array('exc_code','exc_msg'));
+// No new vars
+check::globals(array());
$t = new Test();
try {
@@ -41,3 +40,5 @@ foreach (Array(1,2,3,4) as $i) {
} catch (Exception $e) {
}
}
+
+check::done();
diff --git a/Examples/test-suite/php/typedef_reference_runme.php b/Examples/test-suite/php/typedef_reference_runme.php
index 83e75fb66..8309c3c6f 100644
--- a/Examples/test-suite/php/typedef_reference_runme.php
+++ b/Examples/test-suite/php/typedef_reference_runme.php
@@ -1,7 +1,6 @@
<?php
require "tests.php";
-require "typedef_reference.php";
check::functions(array('somefunc','otherfunc','new_intp','copy_intp','delete_intp','intp_assign','intp_value'));
$int2=copy_intp(2);
@@ -10,4 +9,3 @@ $int3=copy_intp(3);
check::equal(3,otherfunc($int3)," test passing intp to otherfunc");
check::done();
-?>
diff --git a/Examples/test-suite/php/typemap_ns_using_runme.php b/Examples/test-suite/php/typemap_ns_using_runme.php
index 6a599f008..e15427856 100644
--- a/Examples/test-suite/php/typemap_ns_using_runme.php
+++ b/Examples/test-suite/php/typemap_ns_using_runme.php
@@ -1,9 +1,8 @@
<?php
require "tests.php";
-require "typemap_ns_using.php";
+
if (! class_exists("_fooimpl")) die("_fooimpl class not found\n");
if (! 3==spam(3)) die("spam function not working right\n");
check::done();
-?>
diff --git a/Examples/test-suite/php/using1_runme.php b/Examples/test-suite/php/using1_runme.php
index 51841bc78..e15427856 100644
--- a/Examples/test-suite/php/using1_runme.php
+++ b/Examples/test-suite/php/using1_runme.php
@@ -1,9 +1,8 @@
<?php
require "tests.php";
-require "using1.php";
+
if (! class_exists("_fooimpl")) die("_fooimpl class not found\n");
if (! 3==spam(3)) die("spam function not working right\n");
check::done();
-?>
diff --git a/Examples/test-suite/php/using2_runme.php b/Examples/test-suite/php/using2_runme.php
index 391a98f52..e15427856 100644
--- a/Examples/test-suite/php/using2_runme.php
+++ b/Examples/test-suite/php/using2_runme.php
@@ -1,9 +1,8 @@
<?php
require "tests.php";
-require "using2.php";
+
if (! class_exists("_fooimpl")) die("_fooimpl class not found\n");
if (! 3==spam(3)) die("spam function not working right\n");
check::done();
-?>
diff --git a/Examples/test-suite/php/valuewrapper_base_runme.php b/Examples/test-suite/php/valuewrapper_base_runme.php
index 6a1abdbd2..3f4c38e5b 100644
--- a/Examples/test-suite/php/valuewrapper_base_runme.php
+++ b/Examples/test-suite/php/valuewrapper_base_runme.php
@@ -1,13 +1,11 @@
<?php
require "tests.php";
-require "valuewrapper_base.php";
check::classes(array("valuewrapper_base","Base","Interface_BP"));
-check::functions("make_interface_bp");
+check::functions("make_Interface_BP");
$ibp=valuewrapper_base::make_interface_bp();
check::classname("interface_bp",$ibp);
check::done();
-?>
diff --git a/Examples/test-suite/php/virtual_vs_nonvirtual_base_runme.php b/Examples/test-suite/php/virtual_vs_nonvirtual_base_runme.php
index 0d4aa3d5f..8d8d40560 100644
--- a/Examples/test-suite/php/virtual_vs_nonvirtual_base_runme.php
+++ b/Examples/test-suite/php/virtual_vs_nonvirtual_base_runme.php
@@ -1,11 +1,10 @@
-<?
+<?php
require "tests.php";
-require "virtual_vs_nonvirtual_base.php";
$fail = new SimpleClassFail();
$work = new SimpleClassWork();
check::equal($work->getInner()->get(), $fail->getInner()->get(), "should both be 10");
-?>
+check::done();
diff --git a/Examples/test-suite/php/wrapmacro_runme.php b/Examples/test-suite/php/wrapmacro_runme.php
index f32da990e..18b2ef1e1 100644
--- a/Examples/test-suite/php/wrapmacro_runme.php
+++ b/Examples/test-suite/php/wrapmacro_runme.php
@@ -1,12 +1,10 @@
<?php
require "tests.php";
-require "wrapmacro.php";
-check::functions(array('guint16_swap_le_be_constant', 'maximum'));
+check::functions(array('GUINT16_SWAP_LE_BE_CONSTANT', 'maximum'));
check::equal(maximum(2.3, 2.4), 2.4, "maximum() doesn't work");
check::equal(guint16_swap_le_be_constant(0x1234), 0x3412, "GUINT16_SWAP_LE_BE_CONSTANT() doesn't work");
check::done();
-?>