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();