swig/Examples/test-suite/php/exception_memory_leak_runme.php
Olly Betts 3dd7e93c77 Fix issues with exception_memory_leak testcase
The out typemap uses a function name which doesn't match the name of the
function we want it to apply to, so this testcase wasn't actually
triggering an exception so wasn't actually testing anything!

With that fixed, the testcase fails to compile for PHP due to use of
SWIG_exception_fail() (which not all target languages implement), and
with that fixed, the _runme.php needs a try ... catch adding to handle
the raised exception.
2022-10-14 12:12:21 +13:00

27 lines
882 B
PHP

<?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.
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");