1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @file |
5
|
|
|
* Grafizzi\Graph\Tests\IG19Test: a component of the Grafizzi library. |
6
|
|
|
* |
7
|
|
|
* (c) 2012 Frédéric G. MARAND <[email protected]> |
8
|
|
|
* |
9
|
|
|
* Grafizzi is free software: you can redistribute it and/or modify it under the |
10
|
|
|
* terms of the GNU Lesser General Public License as published by the Free |
11
|
|
|
* Software Foundation, either version 3 of the License, or (at your option) any |
12
|
|
|
* later version. |
13
|
|
|
* |
14
|
|
|
* Grafizzi is distributed in the hope that it will be useful, but WITHOUT ANY |
15
|
|
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
16
|
|
|
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
17
|
|
|
* details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
20
|
|
|
* along with Grafizzi, in the COPYING.LESSER.txt file. If not, see |
21
|
|
|
* <http://www.gnu.org/licenses/> |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
namespace Grafizzi\Graph\Tests; |
25
|
|
|
|
26
|
|
|
use Grafizzi\Graph\Attribute; |
27
|
|
|
use Grafizzi\Graph\Cluster; |
28
|
|
|
use Grafizzi\Graph\Edge; |
29
|
|
|
use Grafizzi\Graph\Node; |
30
|
|
|
|
31
|
|
|
require 'vendor/autoload.php'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* A recreation of Image_GraphViz test19.phpt |
35
|
|
|
* |
36
|
|
|
* Image_GraphViz version author: Philippe Jausions <[email protected]> |
37
|
|
|
* |
38
|
|
|
* Test 19: "Call graph with labeled clusters" |
39
|
|
|
* |
40
|
|
|
* "Graph definition taken from GraphViz documentation" |
41
|
|
|
* |
42
|
|
|
* Note: ordering of insertions differs from Image_GraphViz, since Grafizzi |
43
|
|
|
* orders output by insertion order to allow customizing output order. |
44
|
|
|
*/ |
45
|
|
|
class IG19Test extends BaseGraphTest { |
46
|
|
|
|
47
|
|
|
public function setUp() : void { |
48
|
|
|
// not strict by default. |
49
|
|
|
parent::setUpExtended(); |
|
|
|
|
50
|
|
|
$g = $this->Graph; |
51
|
|
|
$dic = $this->dic; |
52
|
|
|
$g->setDirected(true); |
53
|
|
|
$g->setAttributes(array( |
54
|
|
|
new Attribute($dic, 'size', 8.6), |
55
|
|
|
new Attribute($dic, 'ratio', 'fill'), |
56
|
|
|
)); |
57
|
|
|
|
58
|
|
|
$nullTitle = array(new Attribute($dic, 'title', NULL)); |
59
|
|
|
|
60
|
|
|
$g->addChild($nFan = new Node($dic, 'fan', array('implicit' => TRUE))); |
61
|
|
|
|
62
|
|
|
$g->addChild($error = new Cluster($dic, 'error.h', array( |
63
|
|
|
new Attribute($dic, 'label', 'error.h'), |
64
|
|
|
))); |
65
|
|
|
$error->addChild($nInterp_err = new Node($dic, 'interp_err', $nullTitle)); |
66
|
|
|
|
67
|
|
|
$g->addChild($sfio = new Cluster($dic, 'sfio.h', array( |
68
|
|
|
new Attribute($dic, 'label', 'sfio.h') |
69
|
|
|
))); |
70
|
|
|
$sfio->addChild($nSfprintf = new Node($dic, 'sfprintf', $nullTitle)); |
71
|
|
|
|
72
|
|
|
$g->addChild($ciafan = new Cluster($dic, 'ciafan.c', array( |
73
|
|
|
new Attribute($dic, 'label', 'ciafan.c'), |
74
|
|
|
))); |
75
|
|
|
$ciafan->addChild($nCiafan = new Node($dic, 'ciafan', $nullTitle)); |
76
|
|
|
$ciafan->addChild($nComputefan = new Node($dic, 'computefan', $nullTitle)); |
77
|
|
|
$ciafan->addChild($nIncrement = new Node($dic, 'increment', $nullTitle)); |
78
|
|
|
|
79
|
|
|
$g->addChild($util = new Cluster($dic, 'util.c', array( |
80
|
|
|
new Attribute($dic, 'label', 'util.c'), |
81
|
|
|
))); |
82
|
|
|
$util->addChild($nStringdup = new Node($dic, 'stringdup', $nullTitle)); |
83
|
|
|
$util->addChild($nFatal = new Node($dic, 'fatal', $nullTitle)); |
84
|
|
|
$util->addChild($nDebug = new Node($dic, 'debug', $nullTitle)); |
85
|
|
|
|
86
|
|
|
$g->addChild($query = new Cluster($dic, 'query.h', array( |
87
|
|
|
new Attribute($dic, 'label', 'query.h'), |
88
|
|
|
))); |
89
|
|
|
$query->addChild($nRef = new Node($dic, 'ref', $nullTitle)); |
90
|
|
|
$query->addChild($nDef = new Node($dic, 'def', $nullTitle)); |
91
|
|
|
|
92
|
|
|
// No label on this cluster. |
93
|
|
|
$g->addChild($field = new Cluster($dic, 'field.h')); |
94
|
|
|
$field->addChild($nGet_sym_fields = new Node($dic, 'get_sym_fields', $nullTitle)); |
95
|
|
|
|
96
|
|
|
$g->addChild($stdio = new Cluster($dic, 'stdio.h', array( |
97
|
|
|
new Attribute($dic, 'label', 'stdio.h'), |
98
|
|
|
))); |
99
|
|
|
$stdio->addChild($nStdprintf = new Node($dic, 'stdprintf', $nullTitle)); |
100
|
|
|
$stdio->addChild($nStdsprintf = new Node($dic, 'stdsprintf', $nullTitle)); |
101
|
|
|
|
102
|
|
|
$g->addChild($libc = new Cluster($dic, '<libc.a>')); |
103
|
|
|
$libc->addChild($nGetopt = new Node($dic, 'getopt', $nullTitle)); |
104
|
|
|
|
105
|
|
|
$g->addChild($stdlib = new Cluster($dic,'stdlib.h', array( |
106
|
|
|
new Attribute($dic, 'label', 'stdlib.h'), |
107
|
|
|
))); |
108
|
|
|
$stdlib->addChild($nExit = new Node($dic, 'exit', $nullTitle)); |
109
|
|
|
$stdlib->addChild($nMalloc = new Node($dic, 'malloc', $nullTitle)); |
110
|
|
|
$stdlib->addChild($nFree = new Node($dic, 'free', $nullTitle)); |
111
|
|
|
$stdlib->addChild($nRealloc = new Node($dic, 'realloc', $nullTitle)); |
112
|
|
|
|
113
|
|
|
$g->addChild($main = new Cluster($dic, 'main.c')); |
114
|
|
|
$main->addChild($nMain = new Node($dic, 'main', $nullTitle)); |
115
|
|
|
|
116
|
|
|
$g->addChild($index = new Cluster($dic, 'index.h')); |
117
|
|
|
$index->addChild($nInit_index = new Node($dic, 'init_index', $nullTitle)); |
118
|
|
|
|
119
|
|
|
$g->addChild($string = new Cluster($dic, 'string.h', array( |
120
|
|
|
new Attribute($dic, 'label', 'string.h'), |
121
|
|
|
))); |
122
|
|
|
$string->addChild($nStrcpy = new Node($dic, 'strcpy', $nullTitle)); |
123
|
|
|
$string->addChild($nStrlen = new Node($dic, 'strlen', $nullTitle)); |
124
|
|
|
$string->addChild($nStrcmp = new Node($dic, 'strcmp', $nullTitle)); |
125
|
|
|
$string->addChild($nStrcat = new Node($dic, 'strcat', $nullTitle)); |
126
|
|
|
|
127
|
|
|
$g->addChild(new Edge($dic, $nCiafan, $nComputefan)); |
128
|
|
|
$g->addChild(new Edge($dic, $nCiafan, $nDef)); |
129
|
|
|
|
130
|
|
|
$g->addChild(new Edge($dic, $nFan, $nIncrement)); |
131
|
|
|
$g->addChild(new Edge($dic, $nFan, $nFatal)); |
132
|
|
|
$g->addChild(new Edge($dic, $nFan, $nRef)); |
133
|
|
|
$g->addChild(new Edge($dic, $nFan, $nInterp_err)); |
134
|
|
|
$g->addChild(new Edge($dic, $nFan, $nFree)); |
135
|
|
|
$g->addChild(new Edge($dic, $nFan, $nExit)); |
136
|
|
|
$g->addChild(new Edge($dic, $nFan, $nMalloc)); |
137
|
|
|
$g->addChild(new Edge($dic, $nFan, $nStdsprintf)); |
138
|
|
|
$g->addChild(new Edge($dic, $nFan, $nStrlen)); |
139
|
|
|
|
140
|
|
|
$g->addChild(new Edge($dic, $nComputefan, $nFan)); |
141
|
|
|
$g->addChild(new Edge($dic, $nComputefan, $nStdprintf)); |
142
|
|
|
$g->addChild(new Edge($dic, $nComputefan, $nGet_sym_fields)); |
143
|
|
|
$g->addChild(new Edge($dic, $nComputefan, $nMalloc)); |
144
|
|
|
$g->addChild(new Edge($dic, $nComputefan, $nStrcmp)); |
145
|
|
|
$g->addChild(new Edge($dic, $nComputefan, $nRealloc)); |
146
|
|
|
$g->addChild(new Edge($dic, $nComputefan, $nStrlen)); |
147
|
|
|
|
148
|
|
|
$g->addChild(new Edge($dic, $nStringdup, $nFatal)); |
149
|
|
|
$g->addChild(new Edge($dic, $nStringdup, $nMalloc)); |
150
|
|
|
$g->addChild(new Edge($dic, $nStringdup, $nStrcpy)); |
151
|
|
|
$g->addChild(new Edge($dic, $nStringdup, $nStrlen)); |
152
|
|
|
|
153
|
|
|
$g->addChild(new Edge($dic, $nMain, $nExit)); |
154
|
|
|
$g->addChild(new Edge($dic, $nMain, $nInterp_err)); |
155
|
|
|
$g->addChild(new Edge($dic, $nMain, $nCiafan)); |
156
|
|
|
$g->addChild(new Edge($dic, $nMain, $nFatal)); |
157
|
|
|
$g->addChild(new Edge($dic, $nMain, $nMalloc)); |
158
|
|
|
$g->addChild(new Edge($dic, $nMain, $nStrcpy)); |
159
|
|
|
$g->addChild(new Edge($dic, $nMain, $nGetopt)); |
160
|
|
|
$g->addChild(new Edge($dic, $nMain, $nInit_index)); |
161
|
|
|
$g->addChild(new Edge($dic, $nMain, $nStrlen)); |
162
|
|
|
$g->addChild(new Edge($dic, $nIncrement, $nStrcmp)); |
163
|
|
|
$g->addChild(new Edge($dic, $nDebug, $nSfprintf)); |
164
|
|
|
$g->addChild(new Edge($dic, $nDebug, $nStrcat)); |
165
|
|
|
$g->addChild(new Edge($dic, $nFatal, $nSfprintf)); |
166
|
|
|
$g->addChild(new Edge($dic, $nFatal, $nExit)); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* Tests g->build() |
171
|
|
|
*/ |
172
|
|
|
public function testBuild() { |
173
|
|
|
$expected = <<<'EOT' |
174
|
|
|
digraph G { |
175
|
|
|
size=8.6; |
176
|
|
|
ratio=fill; |
177
|
|
|
|
178
|
|
|
subgraph "cluster_error.h" { |
179
|
|
|
label="error.h"; |
180
|
|
|
|
181
|
|
|
interp_err; |
182
|
|
|
} /* /subgraph "cluster_error.h" */ |
183
|
|
|
subgraph "cluster_sfio.h" { |
184
|
|
|
label="sfio.h"; |
185
|
|
|
|
186
|
|
|
sfprintf; |
187
|
|
|
} /* /subgraph "cluster_sfio.h" */ |
188
|
|
|
subgraph "cluster_ciafan.c" { |
189
|
|
|
label="ciafan.c"; |
190
|
|
|
|
191
|
|
|
ciafan; |
192
|
|
|
computefan; |
193
|
|
|
increment; |
194
|
|
|
} /* /subgraph "cluster_ciafan.c" */ |
195
|
|
|
subgraph "cluster_util.c" { |
196
|
|
|
label="util.c"; |
197
|
|
|
|
198
|
|
|
stringdup; |
199
|
|
|
fatal; |
200
|
|
|
debug; |
201
|
|
|
} /* /subgraph "cluster_util.c" */ |
202
|
|
|
subgraph "cluster_query.h" { |
203
|
|
|
label="query.h"; |
204
|
|
|
|
205
|
|
|
ref; |
206
|
|
|
def; |
207
|
|
|
} /* /subgraph "cluster_query.h" */ |
208
|
|
|
subgraph "cluster_field.h" { |
209
|
|
|
get_sym_fields; |
210
|
|
|
} /* /subgraph "cluster_field.h" */ |
211
|
|
|
subgraph "cluster_stdio.h" { |
212
|
|
|
label="stdio.h"; |
213
|
|
|
|
214
|
|
|
stdprintf; |
215
|
|
|
stdsprintf; |
216
|
|
|
} /* /subgraph "cluster_stdio.h" */ |
217
|
|
|
subgraph "cluster_<libc.a>" { |
218
|
|
|
getopt; |
219
|
|
|
} /* /subgraph "cluster_<libc.a>" */ |
220
|
|
|
subgraph "cluster_stdlib.h" { |
221
|
|
|
label="stdlib.h"; |
222
|
|
|
|
223
|
|
|
exit; |
224
|
|
|
malloc; |
225
|
|
|
free; |
226
|
|
|
realloc; |
227
|
|
|
} /* /subgraph "cluster_stdlib.h" */ |
228
|
|
|
subgraph "cluster_main.c" { |
229
|
|
|
main; |
230
|
|
|
} /* /subgraph "cluster_main.c" */ |
231
|
|
|
subgraph "cluster_index.h" { |
232
|
|
|
init_index; |
233
|
|
|
} /* /subgraph "cluster_index.h" */ |
234
|
|
|
subgraph "cluster_string.h" { |
235
|
|
|
label="string.h"; |
236
|
|
|
|
237
|
|
|
strcpy; |
238
|
|
|
strlen; |
239
|
|
|
strcmp; |
240
|
|
|
strcat; |
241
|
|
|
} /* /subgraph "cluster_string.h" */ |
242
|
|
|
ciafan -> computefan; |
243
|
|
|
ciafan -> def; |
244
|
|
|
fan -> increment; |
245
|
|
|
fan -> fatal; |
246
|
|
|
fan -> ref; |
247
|
|
|
fan -> interp_err; |
248
|
|
|
fan -> free; |
249
|
|
|
fan -> exit; |
250
|
|
|
fan -> malloc; |
251
|
|
|
fan -> stdsprintf; |
252
|
|
|
fan -> strlen; |
253
|
|
|
computefan -> fan; |
254
|
|
|
computefan -> stdprintf; |
255
|
|
|
computefan -> get_sym_fields; |
256
|
|
|
computefan -> malloc; |
257
|
|
|
computefan -> strcmp; |
258
|
|
|
computefan -> realloc; |
259
|
|
|
computefan -> strlen; |
260
|
|
|
stringdup -> fatal; |
261
|
|
|
stringdup -> malloc; |
262
|
|
|
stringdup -> strcpy; |
263
|
|
|
stringdup -> strlen; |
264
|
|
|
main -> exit; |
265
|
|
|
main -> interp_err; |
266
|
|
|
main -> ciafan; |
267
|
|
|
main -> fatal; |
268
|
|
|
main -> malloc; |
269
|
|
|
main -> strcpy; |
270
|
|
|
main -> getopt; |
271
|
|
|
main -> init_index; |
272
|
|
|
main -> strlen; |
273
|
|
|
increment -> strcmp; |
274
|
|
|
debug -> sfprintf; |
275
|
|
|
debug -> strcat; |
276
|
|
|
fatal -> sfprintf; |
277
|
|
|
fatal -> exit; |
278
|
|
|
} /* /digraph G */ |
279
|
|
|
|
280
|
|
|
EOT; |
281
|
|
|
$this->check($expected, "Image_graphViz test 19 passed."); |
282
|
|
|
} |
283
|
|
|
} |
284
|
|
|
|
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.