Upstream version 1.3.40
[profile/ivi/swig.git] / Examples / test-suite / php / director_classic_runme.php
1 <?php
2
3 require "tests.php";
4 require "director_classic.php";
5
6 // No new functions
7 check::functions(array(being_id,person_id,child_id,grandchild_id,caller_delcallback,caller_setcallback,caller_resetcallback,caller_call,caller_baseclass));
8 // No new classes
9 check::classes(array(Being,Person,Child,GrandChild,OrphanPerson,OrphanChild,Caller));
10 // now new vars
11 check::globals(array());
12
13 class TargetLangPerson extends Person {
14   function id() {
15     $identifier = "TargetLangPerson";
16     return $identifier;
17   }
18 }
19
20 class TargetLangChild extends Child {
21   function id() {
22     $identifier = "TargetLangChild";
23     return $identifier;
24   }
25 }
26
27 class TargetLangGrandChild extends GrandChild {
28   function id() {
29     $identifier = "TargetLangGrandChild";
30     return $identifier;
31   }
32 }
33
34 # Semis - don't override id() in target language
35 class TargetLangSemiPerson extends Person {
36   # No id() override
37 }
38
39 class TargetLangSemiChild extends Child {
40   # No id() override
41 }
42
43 class TargetLangSemiGrandChild extends GrandChild {
44   # No id() override
45 }
46
47 # Orphans - don't override id() in C++
48 class TargetLangOrphanPerson extends OrphanPerson {
49   function id() {
50     $identifier = "TargetLangOrphanPerson";
51     return $identifier;
52   }
53 }
54
55 class TargetLangOrphanChild extends OrphanChild {
56   function id() {
57     $identifier = "TargetLangOrphanChild";
58     return $identifier;
59   }
60 }
61
62 function mycheck($person, $expected) {
63   $debug = 0;
64   # Normal target language polymorphic call
65   $ret = $person->id();
66   if ($debug)
67     print $ret . "\n";
68   check::equal($ret, $expected, "#1 failed");
69
70   # Polymorphic call from C++
71   $caller = new Caller();
72   $caller->setCallback($person);
73   $ret = $caller->call();
74   if ($debug)
75     print $ret . "\n";
76   check::equal($ret, $expected, "#2 failed");
77
78   # Polymorphic call of object created in target language and passed to 
79   # C++ and back again
80   $baseclass = $caller->baseClass();
81   $ret = $baseclass->id();
82   if ($debug)
83     print $ret . "\n";
84   # TODO: Currently we do not track the dynamic type of returned 
85   # objects, so in case it's possible that the dynamic type is not equal 
86   # to the static type, we skip this check.
87   if (get_parent_class($person) === false)
88     check::equal($ret, $expected, "#3 failed");
89
90   $caller->resetCallback();
91   if ($debug)
92     print "----------------------------------------\n";
93 }
94
95 $person = new Person();
96 mycheck($person, "Person");
97 unset($person);
98
99 $person = new Child();
100 mycheck($person, "Child");
101 unset($person);
102
103 $person = new GrandChild();
104 mycheck($person, "GrandChild");
105 unset($person);
106
107 $person = new TargetLangPerson();
108 mycheck($person, "TargetLangPerson");
109 unset($person);
110
111 $person = new TargetLangChild();
112 mycheck($person, "TargetLangChild");
113 unset($person);
114
115 $person = new TargetLangGrandChild();
116 mycheck($person, "TargetLangGrandChild");
117 unset($person);
118
119 # Semis - don't override id() in target language
120 $person = new TargetLangSemiPerson();
121 mycheck($person, "Person");
122 unset($person);
123
124 $person = new TargetLangSemiChild();
125 mycheck($person, "Child");
126 unset($person);
127
128 $person = new TargetLangSemiGrandChild();
129 mycheck($person, "GrandChild");
130 unset($person);
131
132 # Orphans - don't override id() in C++
133 $person = new OrphanPerson();
134 mycheck($person, "Person");
135 unset($person);
136
137 $person = new OrphanChild();
138 mycheck($person, "Child");
139 unset($person);
140
141 $person = new TargetLangOrphanPerson();
142 mycheck($person, "TargetLangOrphanPerson");
143 unset($person);
144
145 $person = new TargetLangOrphanChild();
146 mycheck($person, "TargetLangOrphanChild");
147 unset($person);
148
149 check::done();
150 ?>