import source from 1.3.40
[external/swig.git] / Examples / test-suite / php / director_exception_runme.php
1 <?php
2
3 require "tests.php";
4 require "director_exception.php";
5
6 // No new functions
7 check::functions(array(foo_ping,foo_pong,launder,bar_ping,bar_pong,bar_pang));
8 // No new classes
9 check::classes(array(director_exception,Foo,Exception1,Exception2,Base,Bar));
10 // now new vars
11 check::globals(array());
12
13 class MyException extends Exception {
14   function __construct($a, $b) {
15     $this->msg = $a . $b;
16   }
17 }
18
19 class MyFoo extends Foo {
20   function ping() {
21     throw new Exception("MyFoo::ping() EXCEPTION");
22   }
23 }
24
25 class MyFoo2 extends Foo {
26   function ping() {
27     return true;
28   }
29 }
30
31 class MyFoo3 extends Foo {
32   function ping() {
33     throw new MyException("foo", "bar");
34   }
35 }
36
37 # Check that the Exception raised by MyFoo.ping() is returned by 
38 # MyFoo.pong().
39 $ok = 0;
40 $a = new MyFoo();
41 # TODO: Currently we do not track the dynamic type of returned 
42 # objects, so we skip the launder() call.
43 #$b = director_exception::launder($a);
44 $b = $a;
45 try {
46   $b->pong();
47 } catch (Exception $e) {
48   $ok = 1;
49   check::equal($e->getMessage(), "MyFoo::ping() EXCEPTION", "Unexpected error message #1");
50 }
51 check::equal($ok, 1, "Got no exception while expected one #1");
52
53 # Check that the director can return an exception which requires two 
54 # arguments to the constructor, without mangling it.
55 $ok = 0;
56 $a = new MyFoo3();
57 #$b = director_exception::launder($a);
58 $b = $a;
59 try {
60   $b->pong();
61 } catch (Exception $e) {
62   $ok = 1;
63   check::equal($e->msg, "foobar", "Unexpected error message #2");
64 }
65 check::equal($ok, 1, "Got no exception while expected one #2");
66
67 try {
68   throw new Exception2();
69 } catch (Exception2 $e2) {
70 }
71
72 try {
73   throw new Exception1();
74 } catch (Exception1 $e1) {
75 }
76
77 check::done();
78 ?>