Commit | Line | Data |
---|---|---|
fb9935cc PP |
1 | /* |
2 | * test_graph_topo.c | |
3 | * | |
4 | * Copyright 2017 - Philippe Proulx <pproulx@efficios.com> | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; under version 2 of the License. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License along | |
16 | * with this program; if not, write to the Free Software Foundation, Inc., | |
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 | */ | |
19 | ||
3fadfbc0 | 20 | #include <babeltrace2/babeltrace.h> |
578e048b | 21 | #include "common/assert.h" |
fb9935cc PP |
22 | #include <stdlib.h> |
23 | #include <string.h> | |
24 | #include <stdbool.h> | |
fb9935cc PP |
25 | #include <glib.h> |
26 | ||
27 | #include "tap/tap.h" | |
28 | ||
4725a201 | 29 | #define NR_TESTS 48 |
fb9935cc PP |
30 | |
31 | enum event_type { | |
d94d92ac PP |
32 | SRC_COMP_ACCEPT_OUTPUT_PORT_CONNECTION, |
33 | SINK_COMP_ACCEPT_INPUT_PORT_CONNECTION, | |
34 | SRC_COMP_OUTPUT_PORT_CONNECTED, | |
35 | SINK_COMP_INPUT_PORT_CONNECTED, | |
d94d92ac PP |
36 | GRAPH_SRC_OUTPUT_PORT_ADDED, |
37 | GRAPH_SINK_INPUT_PORT_ADDED, | |
d94d92ac | 38 | GRAPH_SRC_SINK_PORTS_CONNECTED, |
fb9935cc PP |
39 | }; |
40 | ||
41 | enum test { | |
42 | TEST_EMPTY_GRAPH, | |
43 | TEST_SIMPLE, | |
bf55043c PP |
44 | TEST_SRC_PORT_CONNECTED_ERROR, |
45 | TEST_SINK_PORT_CONNECTED_ERROR, | |
c14181ff | 46 | TEST_SRC_ADDS_PORT_IN_PORT_CONNECTED, |
fb9935cc PP |
47 | }; |
48 | ||
49 | struct event { | |
50 | enum event_type type; | |
51 | ||
52 | union { | |
53 | struct { | |
b19ff26f PP |
54 | const bt_component *comp; |
55 | const bt_port *self_port; | |
56 | const bt_port *other_port; | |
d94d92ac PP |
57 | } src_comp_accept_output_port_connection; |
58 | ||
59 | struct { | |
b19ff26f PP |
60 | const bt_component *comp; |
61 | const bt_port *self_port; | |
62 | const bt_port *other_port; | |
d94d92ac PP |
63 | } sink_comp_accept_input_port_connection; |
64 | ||
65 | struct { | |
b19ff26f PP |
66 | const bt_component *comp; |
67 | const bt_port *self_port; | |
68 | const bt_port *other_port; | |
d94d92ac | 69 | } src_comp_output_port_connected; |
fb9935cc | 70 | |
c14181ff | 71 | struct { |
b19ff26f PP |
72 | const bt_component *comp; |
73 | const bt_port *self_port; | |
74 | const bt_port *other_port; | |
d94d92ac PP |
75 | } sink_comp_input_port_connected; |
76 | ||
fb9935cc | 77 | struct { |
b19ff26f PP |
78 | const bt_component *comp; |
79 | const bt_port *port; | |
d94d92ac | 80 | } graph_src_output_port_added; |
fb9935cc PP |
81 | |
82 | struct { | |
b19ff26f PP |
83 | const bt_component *comp; |
84 | const bt_port *port; | |
d94d92ac | 85 | } graph_sink_input_port_added; |
fb9935cc | 86 | |
fb9935cc | 87 | struct { |
b19ff26f PP |
88 | const bt_component *upstream_comp; |
89 | const bt_component *downstream_comp; | |
90 | const bt_port *upstream_port; | |
91 | const bt_port *downstream_port; | |
d94d92ac | 92 | } graph_src_sink_ports_connected; |
fb9935cc PP |
93 | } data; |
94 | }; | |
95 | ||
96 | static GArray *events; | |
b19ff26f PP |
97 | static bt_component_class_source *src_comp_class; |
98 | static bt_component_class_sink *sink_comp_class; | |
fb9935cc PP |
99 | static enum test current_test; |
100 | ||
101 | static | |
102 | void clear_events(void) | |
103 | { | |
104 | g_array_set_size(events, 0); | |
105 | } | |
106 | ||
107 | static | |
108 | void append_event(struct event *event) | |
109 | { | |
110 | g_array_append_val(events, *event); | |
111 | } | |
112 | ||
113 | static | |
114 | bool compare_events(struct event *ev_a, struct event *ev_b) | |
115 | { | |
116 | if (ev_a->type != ev_b->type) { | |
117 | return false; | |
118 | } | |
119 | ||
120 | switch (ev_a->type) { | |
d94d92ac PP |
121 | case SRC_COMP_ACCEPT_OUTPUT_PORT_CONNECTION: |
122 | if (ev_a->data.src_comp_accept_output_port_connection.comp != | |
123 | ev_b->data.src_comp_accept_output_port_connection.comp) { | |
fb9935cc PP |
124 | return false; |
125 | } | |
126 | ||
d94d92ac PP |
127 | if (ev_a->data.src_comp_accept_output_port_connection.self_port != |
128 | ev_b->data.src_comp_accept_output_port_connection.self_port) { | |
fb9935cc PP |
129 | return false; |
130 | } | |
131 | ||
d94d92ac PP |
132 | if (ev_a->data.src_comp_accept_output_port_connection.other_port != |
133 | ev_b->data.src_comp_accept_output_port_connection.other_port) { | |
fb9935cc PP |
134 | return false; |
135 | } | |
136 | break; | |
d94d92ac PP |
137 | case SINK_COMP_ACCEPT_INPUT_PORT_CONNECTION: |
138 | if (ev_a->data.sink_comp_accept_input_port_connection.comp != | |
139 | ev_b->data.sink_comp_accept_input_port_connection.comp) { | |
c14181ff PP |
140 | return false; |
141 | } | |
142 | ||
d94d92ac PP |
143 | if (ev_a->data.sink_comp_accept_input_port_connection.self_port != |
144 | ev_b->data.sink_comp_accept_input_port_connection.self_port) { | |
c14181ff PP |
145 | return false; |
146 | } | |
147 | ||
d94d92ac PP |
148 | if (ev_a->data.sink_comp_accept_input_port_connection.other_port != |
149 | ev_b->data.sink_comp_accept_input_port_connection.other_port) { | |
c14181ff PP |
150 | return false; |
151 | } | |
152 | break; | |
d94d92ac PP |
153 | case SRC_COMP_OUTPUT_PORT_CONNECTED: |
154 | if (ev_a->data.src_comp_output_port_connected.comp != | |
155 | ev_b->data.src_comp_output_port_connected.comp) { | |
156 | return false; | |
157 | } | |
158 | ||
159 | if (ev_a->data.src_comp_output_port_connected.self_port != | |
160 | ev_b->data.src_comp_output_port_connected.self_port) { | |
fb9935cc PP |
161 | return false; |
162 | } | |
163 | ||
d94d92ac PP |
164 | if (ev_a->data.src_comp_output_port_connected.other_port != |
165 | ev_b->data.src_comp_output_port_connected.other_port) { | |
fb9935cc PP |
166 | return false; |
167 | } | |
168 | break; | |
d94d92ac PP |
169 | case SINK_COMP_INPUT_PORT_CONNECTED: |
170 | if (ev_a->data.sink_comp_input_port_connected.comp != | |
171 | ev_b->data.sink_comp_input_port_connected.comp) { | |
fb9935cc PP |
172 | return false; |
173 | } | |
174 | ||
d94d92ac PP |
175 | if (ev_a->data.sink_comp_input_port_connected.self_port != |
176 | ev_b->data.sink_comp_input_port_connected.self_port) { | |
177 | return false; | |
178 | } | |
179 | ||
180 | if (ev_a->data.sink_comp_input_port_connected.other_port != | |
181 | ev_b->data.sink_comp_input_port_connected.other_port) { | |
fb9935cc PP |
182 | return false; |
183 | } | |
184 | break; | |
d94d92ac PP |
185 | case GRAPH_SRC_OUTPUT_PORT_ADDED: |
186 | if (ev_a->data.graph_src_output_port_added.comp != | |
187 | ev_b->data.graph_src_output_port_added.comp) { | |
fb9935cc PP |
188 | return false; |
189 | } | |
190 | ||
d94d92ac PP |
191 | if (ev_a->data.graph_src_output_port_added.port != |
192 | ev_b->data.graph_src_output_port_added.port) { | |
193 | return false; | |
194 | } | |
195 | break; | |
196 | case GRAPH_SINK_INPUT_PORT_ADDED: | |
197 | if (ev_a->data.graph_sink_input_port_added.comp != | |
198 | ev_b->data.graph_sink_input_port_added.comp) { | |
199 | return false; | |
200 | } | |
201 | ||
202 | if (ev_a->data.graph_sink_input_port_added.port != | |
203 | ev_b->data.graph_sink_input_port_added.port) { | |
204 | return false; | |
205 | } | |
206 | break; | |
d94d92ac PP |
207 | case GRAPH_SRC_SINK_PORTS_CONNECTED: |
208 | if (ev_a->data.graph_src_sink_ports_connected.upstream_comp != | |
209 | ev_b->data.graph_src_sink_ports_connected.upstream_comp) { | |
210 | return false; | |
211 | } | |
212 | ||
213 | if (ev_a->data.graph_src_sink_ports_connected.downstream_comp != | |
214 | ev_b->data.graph_src_sink_ports_connected.downstream_comp) { | |
fb9935cc PP |
215 | return false; |
216 | } | |
217 | ||
d94d92ac PP |
218 | if (ev_a->data.graph_src_sink_ports_connected.upstream_port != |
219 | ev_b->data.graph_src_sink_ports_connected.upstream_port) { | |
fb9935cc PP |
220 | return false; |
221 | } | |
222 | ||
d94d92ac PP |
223 | if (ev_a->data.graph_src_sink_ports_connected.downstream_port != |
224 | ev_b->data.graph_src_sink_ports_connected.downstream_port) { | |
fb9935cc PP |
225 | return false; |
226 | } | |
227 | break; | |
fb9935cc | 228 | default: |
0fbb9a9f | 229 | abort(); |
fb9935cc PP |
230 | } |
231 | ||
232 | return true; | |
233 | } | |
234 | ||
235 | static | |
236 | bool has_event(struct event *event) | |
237 | { | |
238 | size_t i; | |
239 | ||
240 | for (i = 0; i < events->len; i++) { | |
241 | struct event *ev = &g_array_index(events, struct event, i); | |
242 | ||
243 | if (compare_events(event, ev)) { | |
244 | return true; | |
245 | } | |
246 | } | |
247 | ||
248 | return false; | |
249 | } | |
250 | ||
251 | static | |
252 | size_t event_pos(struct event *event) | |
253 | { | |
254 | size_t i; | |
255 | ||
256 | for (i = 0; i < events->len; i++) { | |
257 | struct event *ev = &g_array_index(events, struct event, i); | |
258 | ||
259 | if (compare_events(event, ev)) { | |
260 | return i; | |
261 | } | |
262 | } | |
263 | ||
1974687e | 264 | return SIZE_MAX; |
fb9935cc PP |
265 | } |
266 | ||
267 | static | |
4cdfc5e8 | 268 | bt_self_message_iterator_status src_iter_next( |
d6e69534 PP |
269 | bt_self_message_iterator *self_iterator, |
270 | bt_message_array_const msgs, uint64_t capacity, | |
d4393e08 | 271 | uint64_t *count) |
fb9935cc | 272 | { |
d6e69534 | 273 | return BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR; |
fb9935cc PP |
274 | } |
275 | ||
276 | static | |
4cdfc5e8 | 277 | bt_self_component_status src_accept_output_port_connection( |
b19ff26f PP |
278 | bt_self_component_source *self_comp, |
279 | bt_self_component_port_output *self_comp_port, | |
280 | const bt_port_input *other_port) | |
fb9935cc | 281 | { |
fb9935cc | 282 | struct event event = { |
d94d92ac PP |
283 | .type = SRC_COMP_ACCEPT_OUTPUT_PORT_CONNECTION, |
284 | .data.src_comp_accept_output_port_connection = { | |
707b7d35 PP |
285 | .comp = bt_self_component_as_component( |
286 | bt_self_component_source_as_self_component( | |
d94d92ac | 287 | self_comp)), |
707b7d35 PP |
288 | .self_port = bt_self_component_port_as_port( |
289 | bt_self_component_port_output_as_self_component_port( | |
d94d92ac | 290 | self_comp_port)), |
0d72b8c3 | 291 | .other_port = bt_port_input_as_port_const(other_port), |
fb9935cc PP |
292 | }, |
293 | }; | |
294 | ||
fb9935cc | 295 | append_event(&event); |
d94d92ac | 296 | return BT_SELF_COMPONENT_STATUS_OK; |
c14181ff PP |
297 | } |
298 | ||
299 | static | |
4cdfc5e8 | 300 | bt_self_component_status sink_accept_input_port_connection( |
b19ff26f PP |
301 | bt_self_component_sink *self_comp, |
302 | bt_self_component_port_input *self_comp_port, | |
303 | const bt_port_output *other_port) | |
c14181ff | 304 | { |
d94d92ac PP |
305 | struct event event = { |
306 | .type = SINK_COMP_ACCEPT_INPUT_PORT_CONNECTION, | |
307 | .data.sink_comp_accept_input_port_connection = { | |
707b7d35 PP |
308 | .comp = bt_self_component_as_component( |
309 | bt_self_component_sink_as_self_component( | |
d94d92ac | 310 | self_comp)), |
707b7d35 PP |
311 | .self_port = bt_self_component_port_as_port( |
312 | bt_self_component_port_input_as_self_component_port( | |
d94d92ac | 313 | self_comp_port)), |
0d72b8c3 | 314 | .other_port = bt_port_output_as_port_const(other_port), |
d94d92ac PP |
315 | }, |
316 | }; | |
c14181ff | 317 | |
d94d92ac PP |
318 | append_event(&event); |
319 | return BT_SELF_COMPONENT_STATUS_OK; | |
320 | } | |
321 | ||
322 | static | |
4cdfc5e8 | 323 | bt_self_component_status src_output_port_connected( |
b19ff26f PP |
324 | bt_self_component_source *self_comp, |
325 | bt_self_component_port_output *self_comp_port, | |
326 | const bt_port_input *other_port) | |
d94d92ac PP |
327 | { |
328 | int ret; | |
c14181ff | 329 | struct event event = { |
d94d92ac PP |
330 | .type = SRC_COMP_OUTPUT_PORT_CONNECTED, |
331 | .data.src_comp_output_port_connected = { | |
707b7d35 PP |
332 | .comp = bt_self_component_as_component( |
333 | bt_self_component_source_as_self_component( | |
d94d92ac | 334 | self_comp)), |
707b7d35 PP |
335 | .self_port = bt_self_component_port_as_port( |
336 | bt_self_component_port_output_as_self_component_port( | |
d94d92ac | 337 | self_comp_port)), |
0d72b8c3 | 338 | .other_port = bt_port_input_as_port_const(other_port), |
c14181ff PP |
339 | }, |
340 | }; | |
341 | ||
c14181ff | 342 | append_event(&event); |
fb9935cc PP |
343 | |
344 | switch (current_test) { | |
c14181ff | 345 | case TEST_SRC_ADDS_PORT_IN_PORT_CONNECTED: |
d94d92ac PP |
346 | ret = bt_self_component_source_add_output_port( |
347 | self_comp, "hello", NULL, NULL); | |
25583cd0 | 348 | BT_ASSERT(ret == 0); |
fb9935cc | 349 | break; |
bf55043c | 350 | case TEST_SRC_PORT_CONNECTED_ERROR: |
d94d92ac | 351 | return BT_SELF_COMPONENT_STATUS_ERROR; |
fb9935cc PP |
352 | default: |
353 | break; | |
354 | } | |
bf55043c | 355 | |
d94d92ac | 356 | return BT_SELF_COMPONENT_STATUS_OK; |
fb9935cc PP |
357 | } |
358 | ||
359 | static | |
4cdfc5e8 | 360 | bt_self_component_status sink_input_port_connected( |
b19ff26f PP |
361 | bt_self_component_sink *self_comp, |
362 | bt_self_component_port_input *self_comp_port, | |
363 | const bt_port_output *other_port) | |
d94d92ac PP |
364 | { |
365 | struct event event = { | |
366 | .type = SINK_COMP_INPUT_PORT_CONNECTED, | |
367 | .data.sink_comp_input_port_connected = { | |
707b7d35 PP |
368 | .comp = bt_self_component_as_component( |
369 | bt_self_component_sink_as_self_component( | |
d94d92ac | 370 | self_comp)), |
707b7d35 PP |
371 | .self_port = bt_self_component_port_as_port( |
372 | bt_self_component_port_input_as_self_component_port( | |
d94d92ac | 373 | self_comp_port)), |
0d72b8c3 | 374 | .other_port = bt_port_output_as_port_const(other_port), |
d94d92ac PP |
375 | }, |
376 | }; | |
377 | ||
378 | append_event(&event); | |
379 | ||
380 | if (current_test == TEST_SINK_PORT_CONNECTED_ERROR) { | |
381 | return BT_SELF_COMPONENT_STATUS_ERROR; | |
382 | } else { | |
383 | return BT_SELF_COMPONENT_STATUS_OK; | |
384 | } | |
385 | } | |
386 | ||
d94d92ac | 387 | static |
4cdfc5e8 | 388 | bt_self_component_status src_init( |
b19ff26f PP |
389 | bt_self_component_source *self_comp, |
390 | const bt_value *params, void *init_method_data) | |
b9d103be | 391 | { |
147337a3 | 392 | int ret; |
b9d103be | 393 | |
d94d92ac PP |
394 | ret = bt_self_component_source_add_output_port( |
395 | self_comp, "out", NULL, NULL); | |
25583cd0 | 396 | BT_ASSERT(ret == 0); |
d94d92ac | 397 | return BT_SELF_COMPONENT_STATUS_OK; |
b9d103be PP |
398 | } |
399 | ||
fb9935cc | 400 | static |
4cdfc5e8 | 401 | bt_self_component_status sink_init( |
b19ff26f PP |
402 | bt_self_component_sink *self_comp, |
403 | const bt_value *params, void *init_method_data) | |
fb9935cc | 404 | { |
d94d92ac PP |
405 | int ret; |
406 | ||
407 | ret = bt_self_component_sink_add_input_port(self_comp, | |
408 | "in", NULL, NULL); | |
409 | BT_ASSERT(ret == 0); | |
410 | return BT_SELF_COMPONENT_STATUS_OK; | |
411 | } | |
412 | ||
413 | static | |
4cdfc5e8 | 414 | bt_self_component_status sink_consume( |
b19ff26f | 415 | bt_self_component_sink *self_comp) |
d94d92ac | 416 | { |
d94d92ac | 417 | return BT_SELF_COMPONENT_STATUS_OK; |
fb9935cc PP |
418 | } |
419 | ||
420 | static | |
8cc56726 SM |
421 | bt_graph_listener_status graph_src_output_port_added( |
422 | const bt_component_source *comp, const bt_port_output *port, | |
423 | void *data) | |
fb9935cc PP |
424 | { |
425 | struct event event = { | |
d94d92ac PP |
426 | .type = GRAPH_SRC_OUTPUT_PORT_ADDED, |
427 | .data.graph_src_output_port_added = { | |
0d72b8c3 PP |
428 | .comp = bt_component_source_as_component_const(comp), |
429 | .port = bt_port_output_as_port_const(port), | |
fb9935cc PP |
430 | }, |
431 | }; | |
432 | ||
fb9935cc | 433 | append_event(&event); |
8cc56726 SM |
434 | |
435 | return BT_GRAPH_LISTENER_STATUS_OK; | |
fb9935cc PP |
436 | } |
437 | ||
438 | static | |
8cc56726 SM |
439 | bt_graph_listener_status graph_sink_input_port_added( |
440 | const bt_component_sink *comp, const bt_port_input *port, | |
441 | void *data) | |
fb9935cc PP |
442 | { |
443 | struct event event = { | |
d94d92ac PP |
444 | .type = GRAPH_SINK_INPUT_PORT_ADDED, |
445 | .data.graph_sink_input_port_added = { | |
0d72b8c3 PP |
446 | .comp = bt_component_sink_as_component_const(comp), |
447 | .port = bt_port_input_as_port_const(port), | |
fb9935cc PP |
448 | }, |
449 | }; | |
450 | ||
fb9935cc | 451 | append_event(&event); |
8cc56726 SM |
452 | |
453 | return BT_GRAPH_LISTENER_STATUS_OK; | |
fb9935cc PP |
454 | } |
455 | ||
fb9935cc | 456 | static |
8cc56726 SM |
457 | bt_graph_listener_status graph_src_sink_ports_connected( |
458 | const bt_component_source *upstream_comp, | |
b19ff26f PP |
459 | const bt_component_sink *downstream_comp, |
460 | const bt_port_output *upstream_port, | |
461 | const bt_port_input *downstream_port, void *data) | |
fb9935cc | 462 | { |
fb9935cc | 463 | struct event event = { |
d94d92ac PP |
464 | .type = GRAPH_SRC_SINK_PORTS_CONNECTED, |
465 | .data.graph_src_sink_ports_connected = { | |
466 | .upstream_comp = | |
0d72b8c3 PP |
467 | bt_component_source_as_component_const(upstream_comp), |
468 | .downstream_comp = | |
469 | bt_component_sink_as_component_const(downstream_comp), | |
470 | .upstream_port = | |
471 | bt_port_output_as_port_const(upstream_port), | |
472 | .downstream_port = | |
473 | bt_port_input_as_port_const(downstream_port), | |
fb9935cc PP |
474 | }, |
475 | }; | |
476 | ||
477 | append_event(&event); | |
8cc56726 SM |
478 | |
479 | return BT_GRAPH_LISTENER_STATUS_OK; | |
fb9935cc PP |
480 | } |
481 | ||
fb9935cc PP |
482 | static |
483 | void init_test(void) | |
484 | { | |
485 | int ret; | |
486 | ||
0d72b8c3 | 487 | src_comp_class = bt_component_class_source_create( |
d94d92ac | 488 | "src", src_iter_next); |
25583cd0 | 489 | BT_ASSERT(src_comp_class); |
0d72b8c3 | 490 | ret = bt_component_class_source_set_init_method( |
d94d92ac | 491 | src_comp_class, src_init); |
25583cd0 | 492 | BT_ASSERT(ret == 0); |
0d72b8c3 | 493 | ret = bt_component_class_source_set_accept_output_port_connection_method( |
d94d92ac | 494 | src_comp_class, src_accept_output_port_connection); |
25583cd0 | 495 | BT_ASSERT(ret == 0); |
0d72b8c3 | 496 | ret = bt_component_class_source_set_output_port_connected_method( |
d94d92ac | 497 | src_comp_class, src_output_port_connected); |
25583cd0 | 498 | BT_ASSERT(ret == 0); |
0d72b8c3 | 499 | sink_comp_class = bt_component_class_sink_create("sink", |
d94d92ac | 500 | sink_consume); |
25583cd0 | 501 | BT_ASSERT(sink_comp_class); |
0d72b8c3 | 502 | ret = bt_component_class_sink_set_init_method(sink_comp_class, |
d94d92ac | 503 | sink_init); |
25583cd0 | 504 | BT_ASSERT(ret == 0); |
0d72b8c3 | 505 | ret = bt_component_class_sink_set_accept_input_port_connection_method( |
d94d92ac | 506 | sink_comp_class, sink_accept_input_port_connection); |
25583cd0 | 507 | BT_ASSERT(ret == 0); |
0d72b8c3 | 508 | ret = bt_component_class_sink_set_input_port_connected_method( |
d94d92ac | 509 | sink_comp_class, sink_input_port_connected); |
25583cd0 | 510 | BT_ASSERT(ret == 0); |
fb9935cc | 511 | events = g_array_new(FALSE, TRUE, sizeof(struct event)); |
25583cd0 | 512 | BT_ASSERT(events); |
fb9935cc PP |
513 | } |
514 | ||
515 | static | |
516 | void fini_test(void) | |
517 | { | |
c5b9b441 PP |
518 | bt_component_class_source_put_ref(src_comp_class); |
519 | bt_component_class_sink_put_ref(sink_comp_class); | |
fb9935cc PP |
520 | g_array_free(events, TRUE); |
521 | } | |
522 | ||
523 | static | |
b19ff26f | 524 | const bt_component_source *create_src(bt_graph *graph) |
fb9935cc | 525 | { |
b19ff26f | 526 | const bt_component_source *comp; |
36712f1d | 527 | int ret; |
fb9935cc | 528 | |
0d72b8c3 | 529 | ret = bt_graph_add_source_component(graph, src_comp_class, |
d94d92ac | 530 | "src-comp", NULL, &comp); |
25583cd0 | 531 | BT_ASSERT(ret == 0); |
fb9935cc PP |
532 | return comp; |
533 | } | |
534 | ||
535 | static | |
b19ff26f | 536 | const bt_component_sink *create_sink(bt_graph *graph) |
fb9935cc | 537 | { |
b19ff26f | 538 | const bt_component_sink *comp; |
36712f1d | 539 | int ret; |
fb9935cc | 540 | |
0d72b8c3 | 541 | ret = bt_graph_add_sink_component(graph, sink_comp_class, |
d94d92ac | 542 | "sink-comp", NULL, &comp); |
25583cd0 | 543 | BT_ASSERT(ret == 0); |
fb9935cc PP |
544 | return comp; |
545 | } | |
546 | ||
547 | static | |
b19ff26f | 548 | bt_graph *create_graph(void) |
fb9935cc | 549 | { |
b19ff26f | 550 | bt_graph *graph = bt_graph_create(); |
fb9935cc PP |
551 | int ret; |
552 | ||
25583cd0 | 553 | BT_ASSERT(graph); |
0d72b8c3 | 554 | ret = bt_graph_add_source_component_output_port_added_listener( |
d94d92ac PP |
555 | graph, graph_src_output_port_added, NULL, NULL, NULL); |
556 | BT_ASSERT(ret >= 0); | |
0d72b8c3 | 557 | ret = bt_graph_add_sink_component_input_port_added_listener( |
d94d92ac | 558 | graph, graph_sink_input_port_added, NULL, NULL, NULL); |
25583cd0 | 559 | BT_ASSERT(ret >= 0); |
0d72b8c3 | 560 | ret = bt_graph_add_source_sink_component_ports_connected_listener( |
d94d92ac PP |
561 | graph, graph_src_sink_ports_connected, NULL, NULL, NULL); |
562 | BT_ASSERT(ret >= 0); | |
fb9935cc PP |
563 | return graph; |
564 | } | |
565 | ||
566 | static | |
567 | void prepare_test(enum test test, const char *name) | |
568 | { | |
569 | clear_events(); | |
570 | current_test = test; | |
571 | diag("test: %s", name); | |
572 | } | |
573 | ||
fb9935cc | 574 | static |
c14181ff | 575 | void test_src_adds_port_in_port_connected(void) |
fb9935cc | 576 | { |
b19ff26f PP |
577 | const bt_component_source *src; |
578 | const bt_component_sink *sink; | |
579 | const bt_component *gsrc; | |
580 | const bt_component *gsink; | |
581 | bt_graph *graph; | |
582 | const bt_port_output *src_def_port; | |
583 | const bt_port_output *src_hello_port; | |
584 | const bt_port_input *sink_def_port; | |
585 | const bt_port *gsrc_def_port; | |
586 | const bt_port *gsrc_hello_port; | |
587 | const bt_port *gsink_def_port; | |
fb9935cc | 588 | struct event event; |
4cdfc5e8 | 589 | bt_graph_status status; |
c14181ff PP |
590 | size_t src_accept_port_connection_pos; |
591 | size_t sink_accept_port_connection_pos; | |
592 | size_t src_port_connected_pos; | |
593 | size_t sink_port_connected_pos; | |
fb9935cc PP |
594 | size_t graph_ports_connected_pos; |
595 | size_t graph_port_added_src_pos; | |
596 | ||
c14181ff PP |
597 | prepare_test(TEST_SRC_ADDS_PORT_IN_PORT_CONNECTED, |
598 | "source adds port in port connected"); | |
fb9935cc | 599 | graph = create_graph(); |
25583cd0 | 600 | BT_ASSERT(graph); |
36712f1d PP |
601 | src = create_src(graph); |
602 | sink = create_sink(graph); | |
0d72b8c3 PP |
603 | src_def_port = bt_component_source_borrow_output_port_by_name_const(src, |
604 | "out"); | |
25583cd0 | 605 | BT_ASSERT(src_def_port); |
0d72b8c3 PP |
606 | sink_def_port = bt_component_sink_borrow_input_port_by_name_const(sink, |
607 | "in"); | |
25583cd0 | 608 | BT_ASSERT(sink_def_port); |
0d72b8c3 | 609 | status = bt_graph_connect_ports(graph, src_def_port, |
d94d92ac | 610 | sink_def_port, NULL); |
25583cd0 | 611 | BT_ASSERT(status == 0); |
0d72b8c3 PP |
612 | src_hello_port = bt_component_source_borrow_output_port_by_name_const(src, |
613 | "hello"); | |
25583cd0 | 614 | BT_ASSERT(src_hello_port); |
0d72b8c3 PP |
615 | gsrc = bt_component_source_as_component_const(src); |
616 | gsink = bt_component_sink_as_component_const(sink); | |
617 | gsrc_def_port = bt_port_output_as_port_const(src_def_port); | |
618 | gsrc_hello_port = bt_port_output_as_port_const(src_hello_port); | |
619 | gsink_def_port = bt_port_input_as_port_const(sink_def_port); | |
fb9935cc | 620 | |
36712f1d PP |
621 | /* We're supposed to have 8 events */ |
622 | ok(events->len == 8, "we have the expected number of events"); | |
623 | ||
624 | /* Source's port added */ | |
d94d92ac PP |
625 | event.type = GRAPH_SRC_OUTPUT_PORT_ADDED; |
626 | event.data.graph_src_output_port_added.comp = gsrc; | |
627 | event.data.graph_src_output_port_added.port = gsrc_def_port; | |
36712f1d PP |
628 | ok(has_event(&event), "got the expected graph's port added event (for source, initial)"); |
629 | ||
630 | /* Sink's port added */ | |
d94d92ac PP |
631 | event.type = GRAPH_SINK_INPUT_PORT_ADDED; |
632 | event.data.graph_sink_input_port_added.comp = gsink; | |
633 | event.data.graph_sink_input_port_added.port = gsink_def_port; | |
36712f1d | 634 | ok(has_event(&event), "got the expected graph's port added event (for sink, initial)"); |
fb9935cc PP |
635 | |
636 | /* Source's accept port connection */ | |
d94d92ac PP |
637 | event.type = SRC_COMP_ACCEPT_OUTPUT_PORT_CONNECTION; |
638 | event.data.src_comp_accept_output_port_connection.comp = gsrc; | |
639 | event.data.src_comp_accept_output_port_connection.self_port = gsrc_def_port; | |
640 | event.data.src_comp_accept_output_port_connection.other_port = gsink_def_port; | |
fb9935cc | 641 | ok(has_event(&event), "got the expected source's accept port connection event"); |
c14181ff PP |
642 | src_accept_port_connection_pos = event_pos(&event); |
643 | ||
644 | /* Sink's accept port connection */ | |
d94d92ac PP |
645 | event.type = SINK_COMP_ACCEPT_INPUT_PORT_CONNECTION; |
646 | event.data.sink_comp_accept_input_port_connection.comp = gsink; | |
647 | event.data.sink_comp_accept_input_port_connection.self_port = gsink_def_port; | |
648 | event.data.sink_comp_accept_input_port_connection.other_port = gsrc_def_port; | |
c14181ff PP |
649 | ok(has_event(&event), "got the expected sink's accept port connection event"); |
650 | sink_accept_port_connection_pos = event_pos(&event); | |
651 | ||
652 | /* Source's port connected */ | |
d94d92ac PP |
653 | event.type = SRC_COMP_OUTPUT_PORT_CONNECTED; |
654 | event.data.src_comp_output_port_connected.comp = gsrc; | |
655 | event.data.src_comp_output_port_connected.self_port = gsrc_def_port; | |
656 | event.data.src_comp_output_port_connected.other_port = gsink_def_port; | |
c14181ff PP |
657 | ok(has_event(&event), "got the expected source's port connected event"); |
658 | src_port_connected_pos = event_pos(&event); | |
fb9935cc PP |
659 | |
660 | /* Graph's port added (source) */ | |
d94d92ac PP |
661 | event.type = GRAPH_SRC_OUTPUT_PORT_ADDED; |
662 | event.data.graph_src_output_port_added.comp = gsrc; | |
663 | event.data.graph_src_output_port_added.port = gsrc_hello_port; | |
fb9935cc PP |
664 | ok(has_event(&event), "got the expected graph's port added event (for source)"); |
665 | graph_port_added_src_pos = event_pos(&event); | |
666 | ||
c14181ff | 667 | /* Sink's port connected */ |
d94d92ac PP |
668 | event.type = SINK_COMP_INPUT_PORT_CONNECTED; |
669 | event.data.sink_comp_input_port_connected.comp = gsink; | |
670 | event.data.sink_comp_input_port_connected.self_port = gsink_def_port; | |
671 | event.data.sink_comp_input_port_connected.other_port = gsrc_def_port; | |
c14181ff PP |
672 | ok(has_event(&event), "got the expected sink's port connected event"); |
673 | sink_port_connected_pos = event_pos(&event); | |
fb9935cc PP |
674 | |
675 | /* Graph's ports connected */ | |
d94d92ac PP |
676 | event.type = GRAPH_SRC_SINK_PORTS_CONNECTED; |
677 | event.data.graph_src_sink_ports_connected.upstream_comp = gsrc; | |
678 | event.data.graph_src_sink_ports_connected.downstream_comp = gsink; | |
679 | event.data.graph_src_sink_ports_connected.upstream_port = gsrc_def_port; | |
680 | event.data.graph_src_sink_ports_connected.downstream_port = gsink_def_port; | |
681 | ok(has_event(&event), "got the expected graph's ports connected event"); | |
fb9935cc PP |
682 | graph_ports_connected_pos = event_pos(&event); |
683 | ||
684 | /* Order of events */ | |
c14181ff | 685 | ok(src_port_connected_pos < graph_ports_connected_pos, |
fb9935cc | 686 | "event order is good (1)"); |
c14181ff | 687 | ok(sink_port_connected_pos < graph_ports_connected_pos, |
fb9935cc | 688 | "event order is good (2)"); |
c14181ff | 689 | ok(src_accept_port_connection_pos < src_port_connected_pos, |
fb9935cc | 690 | "event order is good (3)"); |
c14181ff | 691 | ok(sink_accept_port_connection_pos < sink_port_connected_pos, |
fb9935cc | 692 | "event order is good (4)"); |
c14181ff PP |
693 | ok(src_port_connected_pos < graph_port_added_src_pos, |
694 | "event order is good (5)"); | |
695 | ok(graph_port_added_src_pos < graph_ports_connected_pos, | |
696 | "event order is good (6)"); | |
fb9935cc | 697 | |
c5b9b441 PP |
698 | bt_component_source_put_ref(src); |
699 | bt_component_sink_put_ref(sink); | |
700 | bt_graph_put_ref(graph); | |
fb9935cc PP |
701 | } |
702 | ||
703 | static | |
704 | void test_simple(void) | |
705 | { | |
b19ff26f PP |
706 | const bt_component_source *src; |
707 | const bt_component_sink *sink; | |
708 | const bt_component *gsrc; | |
709 | const bt_component *gsink; | |
710 | bt_graph *graph; | |
711 | const bt_port_output *src_def_port; | |
712 | const bt_port_input *sink_def_port; | |
713 | const bt_port *gsrc_def_port; | |
714 | const bt_port *gsink_def_port; | |
fb9935cc | 715 | struct event event; |
4cdfc5e8 | 716 | bt_graph_status status; |
c14181ff PP |
717 | size_t src_accept_port_connection_pos; |
718 | size_t sink_accept_port_connection_pos; | |
719 | size_t src_port_connected_pos; | |
720 | size_t sink_port_connected_pos; | |
fb9935cc PP |
721 | size_t graph_ports_connected_pos; |
722 | ||
723 | prepare_test(TEST_SIMPLE, "simple"); | |
fb9935cc | 724 | graph = create_graph(); |
25583cd0 | 725 | BT_ASSERT(graph); |
36712f1d PP |
726 | src = create_src(graph); |
727 | sink = create_sink(graph); | |
0d72b8c3 PP |
728 | src_def_port = bt_component_source_borrow_output_port_by_name_const(src, |
729 | "out"); | |
25583cd0 | 730 | BT_ASSERT(src_def_port); |
0d72b8c3 PP |
731 | sink_def_port = bt_component_sink_borrow_input_port_by_name_const(sink, |
732 | "in"); | |
25583cd0 | 733 | BT_ASSERT(sink_def_port); |
0d72b8c3 | 734 | status = bt_graph_connect_ports(graph, src_def_port, |
d94d92ac | 735 | sink_def_port, NULL); |
25583cd0 | 736 | BT_ASSERT(status == 0); |
0d72b8c3 PP |
737 | gsrc = bt_component_source_as_component_const(src); |
738 | gsink = bt_component_sink_as_component_const(sink); | |
739 | gsrc_def_port = bt_port_output_as_port_const(src_def_port); | |
740 | gsink_def_port = bt_port_input_as_port_const(sink_def_port); | |
fb9935cc | 741 | |
36712f1d PP |
742 | /* We're supposed to have 7 events */ |
743 | ok(events->len == 7, "we have the expected number of events"); | |
744 | ||
745 | /* Source's port added */ | |
d94d92ac PP |
746 | event.type = GRAPH_SRC_OUTPUT_PORT_ADDED; |
747 | event.data.graph_src_output_port_added.comp = gsrc; | |
748 | event.data.graph_src_output_port_added.port = gsrc_def_port; | |
36712f1d PP |
749 | ok(has_event(&event), "got the expected graph's port added event (for source, initial)"); |
750 | ||
751 | /* Sink's port added */ | |
d94d92ac PP |
752 | event.type = GRAPH_SINK_INPUT_PORT_ADDED; |
753 | event.data.graph_sink_input_port_added.comp = gsink; | |
754 | event.data.graph_sink_input_port_added.port = gsink_def_port; | |
36712f1d | 755 | ok(has_event(&event), "got the expected graph's port added event (for sink, initial)"); |
fb9935cc PP |
756 | |
757 | /* Source's accept port connection */ | |
d94d92ac PP |
758 | event.type = SRC_COMP_ACCEPT_OUTPUT_PORT_CONNECTION; |
759 | event.data.src_comp_accept_output_port_connection.comp = gsrc; | |
760 | event.data.src_comp_accept_output_port_connection.self_port = gsrc_def_port; | |
761 | event.data.src_comp_accept_output_port_connection.other_port = gsink_def_port; | |
fb9935cc | 762 | ok(has_event(&event), "got the expected source's accept port connection event"); |
c14181ff | 763 | src_accept_port_connection_pos = event_pos(&event); |
fb9935cc PP |
764 | |
765 | /* Sink's accept port connection */ | |
d94d92ac PP |
766 | event.type = SINK_COMP_ACCEPT_INPUT_PORT_CONNECTION; |
767 | event.data.sink_comp_accept_input_port_connection.comp = gsink; | |
768 | event.data.sink_comp_accept_input_port_connection.self_port = gsink_def_port; | |
769 | event.data.sink_comp_accept_input_port_connection.other_port = gsrc_def_port; | |
fb9935cc | 770 | ok(has_event(&event), "got the expected sink's accept port connection event"); |
c14181ff PP |
771 | sink_accept_port_connection_pos = event_pos(&event); |
772 | ||
773 | /* Source's port connected */ | |
d94d92ac PP |
774 | event.type = SRC_COMP_OUTPUT_PORT_CONNECTED; |
775 | event.data.src_comp_output_port_connected.comp = gsrc; | |
776 | event.data.src_comp_output_port_connected.self_port = gsrc_def_port; | |
777 | event.data.src_comp_output_port_connected.other_port = gsink_def_port; | |
c14181ff PP |
778 | ok(has_event(&event), "got the expected source's port connected event"); |
779 | src_port_connected_pos = event_pos(&event); | |
780 | ||
781 | /* Sink's port connected */ | |
d94d92ac PP |
782 | event.type = SINK_COMP_INPUT_PORT_CONNECTED; |
783 | event.data.sink_comp_input_port_connected.comp = gsink; | |
784 | event.data.sink_comp_input_port_connected.self_port = gsink_def_port; | |
785 | event.data.sink_comp_input_port_connected.other_port = gsrc_def_port; | |
c14181ff PP |
786 | ok(has_event(&event), "got the expected sink's port connected event"); |
787 | sink_port_connected_pos = event_pos(&event); | |
fb9935cc | 788 | |
d94d92ac PP |
789 | /* Graph's ports connected */ |
790 | event.type = GRAPH_SRC_SINK_PORTS_CONNECTED; | |
791 | event.data.graph_src_sink_ports_connected.upstream_comp = gsrc; | |
792 | event.data.graph_src_sink_ports_connected.downstream_comp = gsink; | |
793 | event.data.graph_src_sink_ports_connected.upstream_port = gsrc_def_port; | |
794 | event.data.graph_src_sink_ports_connected.downstream_port = gsink_def_port; | |
fb9935cc PP |
795 | ok(has_event(&event), "got the expected graph's ports connected event"); |
796 | graph_ports_connected_pos = event_pos(&event); | |
797 | ||
798 | /* Order of events */ | |
c14181ff | 799 | ok(src_port_connected_pos < graph_ports_connected_pos, |
fb9935cc | 800 | "event order is good (1)"); |
c14181ff | 801 | ok(sink_port_connected_pos < graph_ports_connected_pos, |
fb9935cc | 802 | "event order is good (2)"); |
c14181ff PP |
803 | ok(src_accept_port_connection_pos < src_port_connected_pos, |
804 | "event order is good (3)"); | |
805 | ok(sink_accept_port_connection_pos < sink_port_connected_pos, | |
806 | "event order is good (4)"); | |
fb9935cc | 807 | |
c5b9b441 PP |
808 | bt_component_sink_put_ref(sink); |
809 | bt_graph_put_ref(graph); | |
810 | bt_component_source_put_ref(src); | |
fb9935cc PP |
811 | } |
812 | ||
bf55043c PP |
813 | static |
814 | void test_src_port_connected_error(void) | |
815 | { | |
b19ff26f PP |
816 | const bt_component_source *src; |
817 | const bt_component_sink *sink; | |
818 | const bt_component *gsrc; | |
819 | const bt_component *gsink; | |
820 | bt_graph *graph; | |
821 | const bt_port_output *src_def_port; | |
822 | const bt_port_input *sink_def_port; | |
823 | const bt_port *gsrc_def_port; | |
824 | const bt_port *gsink_def_port; | |
825 | const bt_connection *conn = NULL; | |
bf55043c | 826 | struct event event; |
4cdfc5e8 | 827 | bt_graph_status status; |
bf55043c PP |
828 | size_t src_accept_port_connection_pos; |
829 | size_t src_port_connected_pos; | |
830 | ||
831 | prepare_test(TEST_SRC_PORT_CONNECTED_ERROR, "port connected error: source"); | |
832 | graph = create_graph(); | |
833 | BT_ASSERT(graph); | |
834 | src = create_src(graph); | |
835 | sink = create_sink(graph); | |
0d72b8c3 PP |
836 | src_def_port = bt_component_source_borrow_output_port_by_name_const(src, |
837 | "out"); | |
bf55043c | 838 | BT_ASSERT(src_def_port); |
0d72b8c3 PP |
839 | sink_def_port = bt_component_sink_borrow_input_port_by_name_const(sink, |
840 | "in"); | |
bf55043c | 841 | BT_ASSERT(sink_def_port); |
0d72b8c3 | 842 | status = bt_graph_connect_ports(graph, src_def_port, |
d94d92ac | 843 | sink_def_port, &conn); |
bf55043c | 844 | ok(status != BT_GRAPH_STATUS_OK, |
0d72b8c3 | 845 | "bt_graph_connect_ports() returns an error"); |
d94d92ac | 846 | ok(!conn, "returned connection is still NULL"); |
0d72b8c3 PP |
847 | gsrc = bt_component_source_as_component_const(src); |
848 | gsink = bt_component_sink_as_component_const(sink); | |
849 | gsrc_def_port = bt_port_output_as_port_const(src_def_port); | |
850 | gsink_def_port = bt_port_input_as_port_const(sink_def_port); | |
bf55043c PP |
851 | |
852 | /* We're supposed to have 5 events */ | |
853 | ok(events->len == 5, "we have the expected number of events"); | |
854 | ||
855 | /* Source's port added */ | |
d94d92ac PP |
856 | event.type = GRAPH_SRC_OUTPUT_PORT_ADDED; |
857 | event.data.graph_src_output_port_added.comp = gsrc; | |
858 | event.data.graph_src_output_port_added.port = gsrc_def_port; | |
bf55043c PP |
859 | ok(has_event(&event), "got the expected graph's port added event (for source, initial)"); |
860 | ||
861 | /* Sink's port added */ | |
d94d92ac PP |
862 | event.type = GRAPH_SINK_INPUT_PORT_ADDED; |
863 | event.data.graph_sink_input_port_added.comp = gsink; | |
864 | event.data.graph_sink_input_port_added.port = gsink_def_port; | |
bf55043c PP |
865 | ok(has_event(&event), "got the expected graph's port added event (for sink, initial)"); |
866 | ||
867 | /* Source's accept port connection */ | |
d94d92ac PP |
868 | event.type = SRC_COMP_ACCEPT_OUTPUT_PORT_CONNECTION; |
869 | event.data.src_comp_accept_output_port_connection.comp = gsrc; | |
870 | event.data.src_comp_accept_output_port_connection.self_port = gsrc_def_port; | |
871 | event.data.src_comp_accept_output_port_connection.other_port = gsink_def_port; | |
bf55043c PP |
872 | ok(has_event(&event), "got the expected source's accept port connection event"); |
873 | src_accept_port_connection_pos = event_pos(&event); | |
874 | ||
875 | /* Sink's accept port connection */ | |
d94d92ac PP |
876 | event.type = SINK_COMP_ACCEPT_INPUT_PORT_CONNECTION; |
877 | event.data.sink_comp_accept_input_port_connection.comp = gsink; | |
878 | event.data.sink_comp_accept_input_port_connection.self_port = gsink_def_port; | |
879 | event.data.sink_comp_accept_input_port_connection.other_port = gsrc_def_port; | |
bf55043c PP |
880 | ok(has_event(&event), "got the expected sink's accept port connection event"); |
881 | ||
882 | /* Source's port connected */ | |
d94d92ac PP |
883 | event.type = SRC_COMP_OUTPUT_PORT_CONNECTED; |
884 | event.data.src_comp_output_port_connected.comp = gsrc; | |
885 | event.data.src_comp_output_port_connected.self_port = gsrc_def_port; | |
886 | event.data.src_comp_output_port_connected.other_port = gsink_def_port; | |
bf55043c PP |
887 | ok(has_event(&event), "got the expected source's port connected event"); |
888 | src_port_connected_pos = event_pos(&event); | |
889 | ||
890 | /* Order of events */ | |
891 | ok(src_accept_port_connection_pos < src_port_connected_pos, | |
892 | "event order is good (1)"); | |
893 | ||
c5b9b441 PP |
894 | bt_graph_put_ref(graph); |
895 | bt_component_sink_put_ref(sink); | |
896 | bt_component_source_put_ref(src); | |
897 | bt_connection_put_ref(conn); | |
bf55043c PP |
898 | } |
899 | ||
900 | static | |
901 | void test_sink_port_connected_error(void) | |
902 | { | |
b19ff26f PP |
903 | const bt_component_source *src; |
904 | const bt_component_sink *sink; | |
905 | const bt_component *gsrc; | |
906 | const bt_component *gsink; | |
907 | bt_graph *graph; | |
908 | const bt_port_output *src_def_port; | |
909 | const bt_port_input *sink_def_port; | |
910 | const bt_port *gsrc_def_port; | |
911 | const bt_port *gsink_def_port; | |
912 | const bt_connection *conn = NULL; | |
bf55043c | 913 | struct event event; |
4cdfc5e8 | 914 | bt_graph_status status; |
bf55043c PP |
915 | size_t src_accept_port_connection_pos; |
916 | size_t sink_accept_port_connection_pos; | |
917 | size_t src_port_connected_pos; | |
bf55043c PP |
918 | size_t sink_port_connected_pos; |
919 | ||
920 | prepare_test(TEST_SINK_PORT_CONNECTED_ERROR, "port connected error: sink"); | |
921 | graph = create_graph(); | |
922 | BT_ASSERT(graph); | |
923 | src = create_src(graph); | |
924 | sink = create_sink(graph); | |
0d72b8c3 PP |
925 | src_def_port = bt_component_source_borrow_output_port_by_name_const(src, |
926 | "out"); | |
bf55043c | 927 | BT_ASSERT(src_def_port); |
0d72b8c3 PP |
928 | sink_def_port = bt_component_sink_borrow_input_port_by_name_const(sink, |
929 | "in"); | |
bf55043c | 930 | BT_ASSERT(sink_def_port); |
0d72b8c3 | 931 | status = bt_graph_connect_ports(graph, src_def_port, |
d94d92ac | 932 | sink_def_port, &conn); |
bf55043c | 933 | ok(status != BT_GRAPH_STATUS_OK, |
0d72b8c3 | 934 | "bt_graph_connect_ports() returns an error"); |
d94d92ac | 935 | ok(!conn, "returned connection is still NULL"); |
0d72b8c3 PP |
936 | gsrc = bt_component_source_as_component_const(src); |
937 | gsink = bt_component_sink_as_component_const(sink); | |
938 | gsrc_def_port = bt_port_output_as_port_const(src_def_port); | |
939 | gsink_def_port = bt_port_input_as_port_const(sink_def_port); | |
bf55043c | 940 | |
4725a201 PP |
941 | /* We're supposed to have 6 events */ |
942 | ok(events->len == 6, "we have the expected number of events"); | |
bf55043c PP |
943 | |
944 | /* Source's port added */ | |
d94d92ac PP |
945 | event.type = GRAPH_SRC_OUTPUT_PORT_ADDED; |
946 | event.data.graph_src_output_port_added.comp = gsrc; | |
947 | event.data.graph_src_output_port_added.port = gsrc_def_port; | |
bf55043c PP |
948 | ok(has_event(&event), "got the expected graph's port added event (for source, initial)"); |
949 | ||
950 | /* Sink's port added */ | |
d94d92ac PP |
951 | event.type = GRAPH_SINK_INPUT_PORT_ADDED; |
952 | event.data.graph_sink_input_port_added.comp = gsink; | |
953 | event.data.graph_sink_input_port_added.port = gsink_def_port; | |
bf55043c PP |
954 | ok(has_event(&event), "got the expected graph's port added event (for sink, initial)"); |
955 | ||
956 | /* Source's accept port connection */ | |
d94d92ac PP |
957 | event.type = SRC_COMP_ACCEPT_OUTPUT_PORT_CONNECTION; |
958 | event.data.src_comp_accept_output_port_connection.comp = gsrc; | |
959 | event.data.src_comp_accept_output_port_connection.self_port = gsrc_def_port; | |
960 | event.data.src_comp_accept_output_port_connection.other_port = gsink_def_port; | |
bf55043c PP |
961 | ok(has_event(&event), "got the expected source's accept port connection event"); |
962 | src_accept_port_connection_pos = event_pos(&event); | |
963 | ||
964 | /* Sink's accept port connection */ | |
d94d92ac PP |
965 | event.type = SINK_COMP_ACCEPT_INPUT_PORT_CONNECTION; |
966 | event.data.sink_comp_accept_input_port_connection.comp = gsink; | |
967 | event.data.sink_comp_accept_input_port_connection.self_port = gsink_def_port; | |
968 | event.data.sink_comp_accept_input_port_connection.other_port = gsrc_def_port; | |
bf55043c PP |
969 | ok(has_event(&event), "got the expected sink's accept port connection event"); |
970 | sink_accept_port_connection_pos = event_pos(&event); | |
971 | ||
972 | /* Source's port connected */ | |
d94d92ac PP |
973 | event.type = SRC_COMP_OUTPUT_PORT_CONNECTED; |
974 | event.data.src_comp_output_port_connected.comp = gsrc; | |
975 | event.data.src_comp_output_port_connected.self_port = gsrc_def_port; | |
976 | event.data.src_comp_output_port_connected.other_port = gsink_def_port; | |
bf55043c PP |
977 | ok(has_event(&event), "got the expected source's port connected event"); |
978 | src_port_connected_pos = event_pos(&event); | |
979 | ||
980 | /* Sink's port connected */ | |
d94d92ac PP |
981 | event.type = SINK_COMP_INPUT_PORT_CONNECTED; |
982 | event.data.sink_comp_input_port_connected.comp = gsink; | |
983 | event.data.sink_comp_input_port_connected.self_port = gsink_def_port; | |
984 | event.data.sink_comp_input_port_connected.other_port = gsrc_def_port; | |
bf55043c PP |
985 | ok(has_event(&event), "got the expected sink's port connected event"); |
986 | sink_port_connected_pos = event_pos(&event); | |
987 | ||
bf55043c PP |
988 | /* Order of events */ |
989 | ok(src_accept_port_connection_pos < src_port_connected_pos, | |
990 | "event order is good (1)"); | |
991 | ok(sink_accept_port_connection_pos < sink_port_connected_pos, | |
992 | "event order is good (2)"); | |
bf55043c | 993 | |
c5b9b441 PP |
994 | bt_connection_put_ref(conn); |
995 | bt_graph_put_ref(graph); | |
996 | bt_component_sink_put_ref(sink); | |
997 | bt_component_source_put_ref(src); | |
bf55043c PP |
998 | } |
999 | ||
fb9935cc PP |
1000 | static |
1001 | void test_empty_graph(void) | |
1002 | { | |
b19ff26f | 1003 | bt_graph *graph; |
fb9935cc PP |
1004 | |
1005 | prepare_test(TEST_EMPTY_GRAPH, "empty graph"); | |
1006 | graph = create_graph(); | |
1007 | ok(events->len == 0, "empty graph generates no events"); | |
c5b9b441 | 1008 | bt_graph_put_ref(graph); |
fb9935cc PP |
1009 | } |
1010 | ||
1011 | int main(int argc, char **argv) | |
1012 | { | |
1013 | plan_tests(NR_TESTS); | |
1014 | init_test(); | |
1015 | test_empty_graph(); | |
1016 | test_simple(); | |
bf55043c PP |
1017 | test_src_port_connected_error(); |
1018 | test_sink_port_connected_error(); | |
c14181ff | 1019 | test_src_adds_port_in_port_connected(); |
fb9935cc PP |
1020 | fini_test(); |
1021 | return exit_status(); | |
1022 | } |