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 | ||
834e9996 PP |
20 | #include <babeltrace/babeltrace.h> |
21 | #include <babeltrace/assert-internal.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 | ||
9cce94e4 | 29 | #define NR_TESTS 48 |
fb9935cc PP |
30 | |
31 | enum event_type { | |
834e9996 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, | |
834e9996 PP |
36 | GRAPH_SRC_OUTPUT_PORT_ADDED, |
37 | GRAPH_SINK_INPUT_PORT_ADDED, | |
834e9996 | 38 | GRAPH_SRC_SINK_PORTS_CONNECTED, |
fb9935cc PP |
39 | }; |
40 | ||
41 | enum test { | |
42 | TEST_EMPTY_GRAPH, | |
43 | TEST_SIMPLE, | |
634f394c 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 { | |
8eee8ea2 PP |
54 | const bt_component *comp; |
55 | const bt_port *self_port; | |
56 | const bt_port *other_port; | |
834e9996 PP |
57 | } src_comp_accept_output_port_connection; |
58 | ||
59 | struct { | |
8eee8ea2 PP |
60 | const bt_component *comp; |
61 | const bt_port *self_port; | |
62 | const bt_port *other_port; | |
834e9996 PP |
63 | } sink_comp_accept_input_port_connection; |
64 | ||
65 | struct { | |
8eee8ea2 PP |
66 | const bt_component *comp; |
67 | const bt_port *self_port; | |
68 | const bt_port *other_port; | |
834e9996 | 69 | } src_comp_output_port_connected; |
fb9935cc | 70 | |
c14181ff | 71 | struct { |
8eee8ea2 PP |
72 | const bt_component *comp; |
73 | const bt_port *self_port; | |
74 | const bt_port *other_port; | |
834e9996 PP |
75 | } sink_comp_input_port_connected; |
76 | ||
fb9935cc | 77 | struct { |
8eee8ea2 PP |
78 | const bt_component *comp; |
79 | const bt_port *port; | |
834e9996 | 80 | } graph_src_output_port_added; |
fb9935cc PP |
81 | |
82 | struct { | |
8eee8ea2 PP |
83 | const bt_component *comp; |
84 | const bt_port *port; | |
834e9996 | 85 | } graph_sink_input_port_added; |
fb9935cc | 86 | |
fb9935cc | 87 | struct { |
8eee8ea2 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; | |
834e9996 | 92 | } graph_src_sink_ports_connected; |
fb9935cc PP |
93 | } data; |
94 | }; | |
95 | ||
96 | static GArray *events; | |
8eee8ea2 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) { | |
834e9996 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 | ||
834e9996 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 | ||
834e9996 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; | |
834e9996 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 | ||
834e9996 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 | ||
834e9996 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; | |
834e9996 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 | ||
834e9996 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; | |
834e9996 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 | ||
834e9996 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; | |
834e9996 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 | ||
834e9996 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; | |
834e9996 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 | ||
834e9996 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 | ||
834e9996 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 | ||
41342c71 | 264 | return SIZE_MAX; |
fb9935cc PP |
265 | } |
266 | ||
267 | static | |
ee78f405 | 268 | bt_self_message_iterator_status src_iter_next( |
b09a5592 PP |
269 | bt_self_message_iterator *self_iterator, |
270 | bt_message_array_const msgs, uint64_t capacity, | |
3fd7b79d | 271 | uint64_t *count) |
fb9935cc | 272 | { |
b09a5592 | 273 | return BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR; |
fb9935cc PP |
274 | } |
275 | ||
276 | static | |
ee78f405 | 277 | bt_self_component_status src_accept_output_port_connection( |
8eee8ea2 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 = { |
834e9996 PP |
283 | .type = SRC_COMP_ACCEPT_OUTPUT_PORT_CONNECTION, |
284 | .data.src_comp_accept_output_port_connection = { | |
bb61965b PP |
285 | .comp = bt_self_component_as_component( |
286 | bt_self_component_source_as_self_component( | |
834e9996 | 287 | self_comp)), |
bb61965b PP |
288 | .self_port = bt_self_component_port_as_port( |
289 | bt_self_component_port_output_as_self_component_port( | |
834e9996 | 290 | self_comp_port)), |
7b53201c | 291 | .other_port = bt_port_input_as_port_const(other_port), |
fb9935cc PP |
292 | }, |
293 | }; | |
294 | ||
fb9935cc | 295 | append_event(&event); |
834e9996 | 296 | return BT_SELF_COMPONENT_STATUS_OK; |
c14181ff PP |
297 | } |
298 | ||
299 | static | |
ee78f405 | 300 | bt_self_component_status sink_accept_input_port_connection( |
8eee8ea2 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 | { |
834e9996 PP |
305 | struct event event = { |
306 | .type = SINK_COMP_ACCEPT_INPUT_PORT_CONNECTION, | |
307 | .data.sink_comp_accept_input_port_connection = { | |
bb61965b PP |
308 | .comp = bt_self_component_as_component( |
309 | bt_self_component_sink_as_self_component( | |
834e9996 | 310 | self_comp)), |
bb61965b PP |
311 | .self_port = bt_self_component_port_as_port( |
312 | bt_self_component_port_input_as_self_component_port( | |
834e9996 | 313 | self_comp_port)), |
7b53201c | 314 | .other_port = bt_port_output_as_port_const(other_port), |
834e9996 PP |
315 | }, |
316 | }; | |
c14181ff | 317 | |
834e9996 PP |
318 | append_event(&event); |
319 | return BT_SELF_COMPONENT_STATUS_OK; | |
320 | } | |
321 | ||
322 | static | |
ee78f405 | 323 | bt_self_component_status src_output_port_connected( |
8eee8ea2 PP |
324 | bt_self_component_source *self_comp, |
325 | bt_self_component_port_output *self_comp_port, | |
326 | const bt_port_input *other_port) | |
834e9996 PP |
327 | { |
328 | int ret; | |
c14181ff | 329 | struct event event = { |
834e9996 PP |
330 | .type = SRC_COMP_OUTPUT_PORT_CONNECTED, |
331 | .data.src_comp_output_port_connected = { | |
bb61965b PP |
332 | .comp = bt_self_component_as_component( |
333 | bt_self_component_source_as_self_component( | |
834e9996 | 334 | self_comp)), |
bb61965b PP |
335 | .self_port = bt_self_component_port_as_port( |
336 | bt_self_component_port_output_as_self_component_port( | |
834e9996 | 337 | self_comp_port)), |
7b53201c | 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: |
834e9996 PP |
346 | ret = bt_self_component_source_add_output_port( |
347 | self_comp, "hello", NULL, NULL); | |
b8f13b8b | 348 | BT_ASSERT(ret == 0); |
fb9935cc | 349 | break; |
634f394c | 350 | case TEST_SRC_PORT_CONNECTED_ERROR: |
834e9996 | 351 | return BT_SELF_COMPONENT_STATUS_ERROR; |
fb9935cc PP |
352 | default: |
353 | break; | |
354 | } | |
634f394c | 355 | |
834e9996 | 356 | return BT_SELF_COMPONENT_STATUS_OK; |
fb9935cc PP |
357 | } |
358 | ||
359 | static | |
ee78f405 | 360 | bt_self_component_status sink_input_port_connected( |
8eee8ea2 PP |
361 | bt_self_component_sink *self_comp, |
362 | bt_self_component_port_input *self_comp_port, | |
363 | const bt_port_output *other_port) | |
834e9996 PP |
364 | { |
365 | struct event event = { | |
366 | .type = SINK_COMP_INPUT_PORT_CONNECTED, | |
367 | .data.sink_comp_input_port_connected = { | |
bb61965b PP |
368 | .comp = bt_self_component_as_component( |
369 | bt_self_component_sink_as_self_component( | |
834e9996 | 370 | self_comp)), |
bb61965b PP |
371 | .self_port = bt_self_component_port_as_port( |
372 | bt_self_component_port_input_as_self_component_port( | |
834e9996 | 373 | self_comp_port)), |
7b53201c | 374 | .other_port = bt_port_output_as_port_const(other_port), |
834e9996 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 | ||
834e9996 | 387 | static |
ee78f405 | 388 | bt_self_component_status src_init( |
8eee8ea2 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 | |
834e9996 PP |
394 | ret = bt_self_component_source_add_output_port( |
395 | self_comp, "out", NULL, NULL); | |
b8f13b8b | 396 | BT_ASSERT(ret == 0); |
834e9996 | 397 | return BT_SELF_COMPONENT_STATUS_OK; |
b9d103be PP |
398 | } |
399 | ||
fb9935cc | 400 | static |
ee78f405 | 401 | bt_self_component_status sink_init( |
8eee8ea2 PP |
402 | bt_self_component_sink *self_comp, |
403 | const bt_value *params, void *init_method_data) | |
fb9935cc | 404 | { |
834e9996 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 | |
ee78f405 | 414 | bt_self_component_status sink_consume( |
8eee8ea2 | 415 | bt_self_component_sink *self_comp) |
834e9996 | 416 | { |
834e9996 | 417 | return BT_SELF_COMPONENT_STATUS_OK; |
fb9935cc PP |
418 | } |
419 | ||
420 | static | |
8eee8ea2 PP |
421 | void graph_src_output_port_added(const bt_component_source *comp, |
422 | const bt_port_output *port, void *data) | |
fb9935cc PP |
423 | { |
424 | struct event event = { | |
834e9996 PP |
425 | .type = GRAPH_SRC_OUTPUT_PORT_ADDED, |
426 | .data.graph_src_output_port_added = { | |
7b53201c PP |
427 | .comp = bt_component_source_as_component_const(comp), |
428 | .port = bt_port_output_as_port_const(port), | |
fb9935cc PP |
429 | }, |
430 | }; | |
431 | ||
fb9935cc | 432 | append_event(&event); |
fb9935cc PP |
433 | } |
434 | ||
435 | static | |
8eee8ea2 PP |
436 | void graph_sink_input_port_added(const bt_component_sink *comp, |
437 | const bt_port_input *port, void *data) | |
fb9935cc PP |
438 | { |
439 | struct event event = { | |
834e9996 PP |
440 | .type = GRAPH_SINK_INPUT_PORT_ADDED, |
441 | .data.graph_sink_input_port_added = { | |
7b53201c PP |
442 | .comp = bt_component_sink_as_component_const(comp), |
443 | .port = bt_port_input_as_port_const(port), | |
fb9935cc PP |
444 | }, |
445 | }; | |
446 | ||
fb9935cc PP |
447 | append_event(&event); |
448 | } | |
449 | ||
fb9935cc | 450 | static |
8eee8ea2 PP |
451 | void graph_src_sink_ports_connected(const bt_component_source *upstream_comp, |
452 | const bt_component_sink *downstream_comp, | |
453 | const bt_port_output *upstream_port, | |
454 | const bt_port_input *downstream_port, void *data) | |
fb9935cc | 455 | { |
fb9935cc | 456 | struct event event = { |
834e9996 PP |
457 | .type = GRAPH_SRC_SINK_PORTS_CONNECTED, |
458 | .data.graph_src_sink_ports_connected = { | |
459 | .upstream_comp = | |
7b53201c PP |
460 | bt_component_source_as_component_const(upstream_comp), |
461 | .downstream_comp = | |
462 | bt_component_sink_as_component_const(downstream_comp), | |
463 | .upstream_port = | |
464 | bt_port_output_as_port_const(upstream_port), | |
465 | .downstream_port = | |
466 | bt_port_input_as_port_const(downstream_port), | |
fb9935cc PP |
467 | }, |
468 | }; | |
469 | ||
470 | append_event(&event); | |
471 | } | |
472 | ||
fb9935cc PP |
473 | static |
474 | void init_test(void) | |
475 | { | |
476 | int ret; | |
477 | ||
7b53201c | 478 | src_comp_class = bt_component_class_source_create( |
834e9996 | 479 | "src", src_iter_next); |
b8f13b8b | 480 | BT_ASSERT(src_comp_class); |
7b53201c | 481 | ret = bt_component_class_source_set_init_method( |
834e9996 | 482 | src_comp_class, src_init); |
b8f13b8b | 483 | BT_ASSERT(ret == 0); |
7b53201c | 484 | ret = bt_component_class_source_set_accept_output_port_connection_method( |
834e9996 | 485 | src_comp_class, src_accept_output_port_connection); |
b8f13b8b | 486 | BT_ASSERT(ret == 0); |
7b53201c | 487 | ret = bt_component_class_source_set_output_port_connected_method( |
834e9996 | 488 | src_comp_class, src_output_port_connected); |
b8f13b8b | 489 | BT_ASSERT(ret == 0); |
7b53201c | 490 | sink_comp_class = bt_component_class_sink_create("sink", |
834e9996 | 491 | sink_consume); |
b8f13b8b | 492 | BT_ASSERT(sink_comp_class); |
7b53201c | 493 | ret = bt_component_class_sink_set_init_method(sink_comp_class, |
834e9996 | 494 | sink_init); |
b8f13b8b | 495 | BT_ASSERT(ret == 0); |
7b53201c | 496 | ret = bt_component_class_sink_set_accept_input_port_connection_method( |
834e9996 | 497 | sink_comp_class, sink_accept_input_port_connection); |
b8f13b8b | 498 | BT_ASSERT(ret == 0); |
7b53201c | 499 | ret = bt_component_class_sink_set_input_port_connected_method( |
834e9996 | 500 | sink_comp_class, sink_input_port_connected); |
b8f13b8b | 501 | BT_ASSERT(ret == 0); |
fb9935cc | 502 | events = g_array_new(FALSE, TRUE, sizeof(struct event)); |
b8f13b8b | 503 | BT_ASSERT(events); |
fb9935cc PP |
504 | } |
505 | ||
506 | static | |
507 | void fini_test(void) | |
508 | { | |
8c6884d9 PP |
509 | bt_component_class_source_put_ref(src_comp_class); |
510 | bt_component_class_sink_put_ref(sink_comp_class); | |
fb9935cc PP |
511 | g_array_free(events, TRUE); |
512 | } | |
513 | ||
514 | static | |
8eee8ea2 | 515 | const bt_component_source *create_src(bt_graph *graph) |
fb9935cc | 516 | { |
8eee8ea2 | 517 | const bt_component_source *comp; |
36712f1d | 518 | int ret; |
fb9935cc | 519 | |
7b53201c | 520 | ret = bt_graph_add_source_component(graph, src_comp_class, |
834e9996 | 521 | "src-comp", NULL, &comp); |
b8f13b8b | 522 | BT_ASSERT(ret == 0); |
fb9935cc PP |
523 | return comp; |
524 | } | |
525 | ||
526 | static | |
8eee8ea2 | 527 | const bt_component_sink *create_sink(bt_graph *graph) |
fb9935cc | 528 | { |
8eee8ea2 | 529 | const bt_component_sink *comp; |
36712f1d | 530 | int ret; |
fb9935cc | 531 | |
7b53201c | 532 | ret = bt_graph_add_sink_component(graph, sink_comp_class, |
834e9996 | 533 | "sink-comp", NULL, &comp); |
b8f13b8b | 534 | BT_ASSERT(ret == 0); |
fb9935cc PP |
535 | return comp; |
536 | } | |
537 | ||
538 | static | |
8eee8ea2 | 539 | bt_graph *create_graph(void) |
fb9935cc | 540 | { |
8eee8ea2 | 541 | bt_graph *graph = bt_graph_create(); |
fb9935cc PP |
542 | int ret; |
543 | ||
b8f13b8b | 544 | BT_ASSERT(graph); |
7b53201c | 545 | ret = bt_graph_add_source_component_output_port_added_listener( |
834e9996 PP |
546 | graph, graph_src_output_port_added, NULL, NULL, NULL); |
547 | BT_ASSERT(ret >= 0); | |
7b53201c | 548 | ret = bt_graph_add_sink_component_input_port_added_listener( |
834e9996 | 549 | graph, graph_sink_input_port_added, NULL, NULL, NULL); |
b8f13b8b | 550 | BT_ASSERT(ret >= 0); |
7b53201c | 551 | ret = bt_graph_add_source_sink_component_ports_connected_listener( |
834e9996 PP |
552 | graph, graph_src_sink_ports_connected, NULL, NULL, NULL); |
553 | BT_ASSERT(ret >= 0); | |
fb9935cc PP |
554 | return graph; |
555 | } | |
556 | ||
557 | static | |
558 | void prepare_test(enum test test, const char *name) | |
559 | { | |
560 | clear_events(); | |
561 | current_test = test; | |
562 | diag("test: %s", name); | |
563 | } | |
564 | ||
fb9935cc | 565 | static |
c14181ff | 566 | void test_src_adds_port_in_port_connected(void) |
fb9935cc | 567 | { |
8eee8ea2 PP |
568 | const bt_component_source *src; |
569 | const bt_component_sink *sink; | |
570 | const bt_component *gsrc; | |
571 | const bt_component *gsink; | |
572 | bt_graph *graph; | |
573 | const bt_port_output *src_def_port; | |
574 | const bt_port_output *src_hello_port; | |
575 | const bt_port_input *sink_def_port; | |
576 | const bt_port *gsrc_def_port; | |
577 | const bt_port *gsrc_hello_port; | |
578 | const bt_port *gsink_def_port; | |
fb9935cc | 579 | struct event event; |
ee78f405 | 580 | bt_graph_status status; |
c14181ff PP |
581 | size_t src_accept_port_connection_pos; |
582 | size_t sink_accept_port_connection_pos; | |
583 | size_t src_port_connected_pos; | |
584 | size_t sink_port_connected_pos; | |
fb9935cc PP |
585 | size_t graph_ports_connected_pos; |
586 | size_t graph_port_added_src_pos; | |
587 | ||
c14181ff PP |
588 | prepare_test(TEST_SRC_ADDS_PORT_IN_PORT_CONNECTED, |
589 | "source adds port in port connected"); | |
fb9935cc | 590 | graph = create_graph(); |
b8f13b8b | 591 | BT_ASSERT(graph); |
36712f1d PP |
592 | src = create_src(graph); |
593 | sink = create_sink(graph); | |
7b53201c PP |
594 | src_def_port = bt_component_source_borrow_output_port_by_name_const(src, |
595 | "out"); | |
b8f13b8b | 596 | BT_ASSERT(src_def_port); |
7b53201c PP |
597 | sink_def_port = bt_component_sink_borrow_input_port_by_name_const(sink, |
598 | "in"); | |
b8f13b8b | 599 | BT_ASSERT(sink_def_port); |
7b53201c | 600 | status = bt_graph_connect_ports(graph, src_def_port, |
834e9996 | 601 | sink_def_port, NULL); |
b8f13b8b | 602 | BT_ASSERT(status == 0); |
7b53201c PP |
603 | src_hello_port = bt_component_source_borrow_output_port_by_name_const(src, |
604 | "hello"); | |
b8f13b8b | 605 | BT_ASSERT(src_hello_port); |
7b53201c PP |
606 | gsrc = bt_component_source_as_component_const(src); |
607 | gsink = bt_component_sink_as_component_const(sink); | |
608 | gsrc_def_port = bt_port_output_as_port_const(src_def_port); | |
609 | gsrc_hello_port = bt_port_output_as_port_const(src_hello_port); | |
610 | gsink_def_port = bt_port_input_as_port_const(sink_def_port); | |
fb9935cc | 611 | |
36712f1d PP |
612 | /* We're supposed to have 8 events */ |
613 | ok(events->len == 8, "we have the expected number of events"); | |
614 | ||
615 | /* Source's port added */ | |
834e9996 PP |
616 | event.type = GRAPH_SRC_OUTPUT_PORT_ADDED; |
617 | event.data.graph_src_output_port_added.comp = gsrc; | |
618 | event.data.graph_src_output_port_added.port = gsrc_def_port; | |
36712f1d PP |
619 | ok(has_event(&event), "got the expected graph's port added event (for source, initial)"); |
620 | ||
621 | /* Sink's port added */ | |
834e9996 PP |
622 | event.type = GRAPH_SINK_INPUT_PORT_ADDED; |
623 | event.data.graph_sink_input_port_added.comp = gsink; | |
624 | event.data.graph_sink_input_port_added.port = gsink_def_port; | |
36712f1d | 625 | ok(has_event(&event), "got the expected graph's port added event (for sink, initial)"); |
fb9935cc PP |
626 | |
627 | /* Source's accept port connection */ | |
834e9996 PP |
628 | event.type = SRC_COMP_ACCEPT_OUTPUT_PORT_CONNECTION; |
629 | event.data.src_comp_accept_output_port_connection.comp = gsrc; | |
630 | event.data.src_comp_accept_output_port_connection.self_port = gsrc_def_port; | |
631 | event.data.src_comp_accept_output_port_connection.other_port = gsink_def_port; | |
fb9935cc | 632 | ok(has_event(&event), "got the expected source's accept port connection event"); |
c14181ff PP |
633 | src_accept_port_connection_pos = event_pos(&event); |
634 | ||
635 | /* Sink's accept port connection */ | |
834e9996 PP |
636 | event.type = SINK_COMP_ACCEPT_INPUT_PORT_CONNECTION; |
637 | event.data.sink_comp_accept_input_port_connection.comp = gsink; | |
638 | event.data.sink_comp_accept_input_port_connection.self_port = gsink_def_port; | |
639 | event.data.sink_comp_accept_input_port_connection.other_port = gsrc_def_port; | |
c14181ff PP |
640 | ok(has_event(&event), "got the expected sink's accept port connection event"); |
641 | sink_accept_port_connection_pos = event_pos(&event); | |
642 | ||
643 | /* Source's port connected */ | |
834e9996 PP |
644 | event.type = SRC_COMP_OUTPUT_PORT_CONNECTED; |
645 | event.data.src_comp_output_port_connected.comp = gsrc; | |
646 | event.data.src_comp_output_port_connected.self_port = gsrc_def_port; | |
647 | event.data.src_comp_output_port_connected.other_port = gsink_def_port; | |
c14181ff PP |
648 | ok(has_event(&event), "got the expected source's port connected event"); |
649 | src_port_connected_pos = event_pos(&event); | |
fb9935cc PP |
650 | |
651 | /* Graph's port added (source) */ | |
834e9996 PP |
652 | event.type = GRAPH_SRC_OUTPUT_PORT_ADDED; |
653 | event.data.graph_src_output_port_added.comp = gsrc; | |
654 | event.data.graph_src_output_port_added.port = gsrc_hello_port; | |
fb9935cc PP |
655 | ok(has_event(&event), "got the expected graph's port added event (for source)"); |
656 | graph_port_added_src_pos = event_pos(&event); | |
657 | ||
c14181ff | 658 | /* Sink's port connected */ |
834e9996 PP |
659 | event.type = SINK_COMP_INPUT_PORT_CONNECTED; |
660 | event.data.sink_comp_input_port_connected.comp = gsink; | |
661 | event.data.sink_comp_input_port_connected.self_port = gsink_def_port; | |
662 | event.data.sink_comp_input_port_connected.other_port = gsrc_def_port; | |
c14181ff PP |
663 | ok(has_event(&event), "got the expected sink's port connected event"); |
664 | sink_port_connected_pos = event_pos(&event); | |
fb9935cc PP |
665 | |
666 | /* Graph's ports connected */ | |
834e9996 PP |
667 | event.type = GRAPH_SRC_SINK_PORTS_CONNECTED; |
668 | event.data.graph_src_sink_ports_connected.upstream_comp = gsrc; | |
669 | event.data.graph_src_sink_ports_connected.downstream_comp = gsink; | |
670 | event.data.graph_src_sink_ports_connected.upstream_port = gsrc_def_port; | |
671 | event.data.graph_src_sink_ports_connected.downstream_port = gsink_def_port; | |
672 | ok(has_event(&event), "got the expected graph's ports connected event"); | |
fb9935cc PP |
673 | graph_ports_connected_pos = event_pos(&event); |
674 | ||
675 | /* Order of events */ | |
c14181ff | 676 | ok(src_port_connected_pos < graph_ports_connected_pos, |
fb9935cc | 677 | "event order is good (1)"); |
c14181ff | 678 | ok(sink_port_connected_pos < graph_ports_connected_pos, |
fb9935cc | 679 | "event order is good (2)"); |
c14181ff | 680 | ok(src_accept_port_connection_pos < src_port_connected_pos, |
fb9935cc | 681 | "event order is good (3)"); |
c14181ff | 682 | ok(sink_accept_port_connection_pos < sink_port_connected_pos, |
fb9935cc | 683 | "event order is good (4)"); |
c14181ff PP |
684 | ok(src_port_connected_pos < graph_port_added_src_pos, |
685 | "event order is good (5)"); | |
686 | ok(graph_port_added_src_pos < graph_ports_connected_pos, | |
687 | "event order is good (6)"); | |
fb9935cc | 688 | |
8c6884d9 PP |
689 | bt_component_source_put_ref(src); |
690 | bt_component_sink_put_ref(sink); | |
691 | bt_graph_put_ref(graph); | |
fb9935cc PP |
692 | } |
693 | ||
694 | static | |
695 | void test_simple(void) | |
696 | { | |
8eee8ea2 PP |
697 | const bt_component_source *src; |
698 | const bt_component_sink *sink; | |
699 | const bt_component *gsrc; | |
700 | const bt_component *gsink; | |
701 | bt_graph *graph; | |
702 | const bt_port_output *src_def_port; | |
703 | const bt_port_input *sink_def_port; | |
704 | const bt_port *gsrc_def_port; | |
705 | const bt_port *gsink_def_port; | |
fb9935cc | 706 | struct event event; |
ee78f405 | 707 | bt_graph_status status; |
c14181ff PP |
708 | size_t src_accept_port_connection_pos; |
709 | size_t sink_accept_port_connection_pos; | |
710 | size_t src_port_connected_pos; | |
711 | size_t sink_port_connected_pos; | |
fb9935cc PP |
712 | size_t graph_ports_connected_pos; |
713 | ||
714 | prepare_test(TEST_SIMPLE, "simple"); | |
fb9935cc | 715 | graph = create_graph(); |
b8f13b8b | 716 | BT_ASSERT(graph); |
36712f1d PP |
717 | src = create_src(graph); |
718 | sink = create_sink(graph); | |
7b53201c PP |
719 | src_def_port = bt_component_source_borrow_output_port_by_name_const(src, |
720 | "out"); | |
b8f13b8b | 721 | BT_ASSERT(src_def_port); |
7b53201c PP |
722 | sink_def_port = bt_component_sink_borrow_input_port_by_name_const(sink, |
723 | "in"); | |
b8f13b8b | 724 | BT_ASSERT(sink_def_port); |
7b53201c | 725 | status = bt_graph_connect_ports(graph, src_def_port, |
834e9996 | 726 | sink_def_port, NULL); |
b8f13b8b | 727 | BT_ASSERT(status == 0); |
7b53201c PP |
728 | gsrc = bt_component_source_as_component_const(src); |
729 | gsink = bt_component_sink_as_component_const(sink); | |
730 | gsrc_def_port = bt_port_output_as_port_const(src_def_port); | |
731 | gsink_def_port = bt_port_input_as_port_const(sink_def_port); | |
fb9935cc | 732 | |
36712f1d PP |
733 | /* We're supposed to have 7 events */ |
734 | ok(events->len == 7, "we have the expected number of events"); | |
735 | ||
736 | /* Source's port added */ | |
834e9996 PP |
737 | event.type = GRAPH_SRC_OUTPUT_PORT_ADDED; |
738 | event.data.graph_src_output_port_added.comp = gsrc; | |
739 | event.data.graph_src_output_port_added.port = gsrc_def_port; | |
36712f1d PP |
740 | ok(has_event(&event), "got the expected graph's port added event (for source, initial)"); |
741 | ||
742 | /* Sink's port added */ | |
834e9996 PP |
743 | event.type = GRAPH_SINK_INPUT_PORT_ADDED; |
744 | event.data.graph_sink_input_port_added.comp = gsink; | |
745 | event.data.graph_sink_input_port_added.port = gsink_def_port; | |
36712f1d | 746 | ok(has_event(&event), "got the expected graph's port added event (for sink, initial)"); |
fb9935cc PP |
747 | |
748 | /* Source's accept port connection */ | |
834e9996 PP |
749 | event.type = SRC_COMP_ACCEPT_OUTPUT_PORT_CONNECTION; |
750 | event.data.src_comp_accept_output_port_connection.comp = gsrc; | |
751 | event.data.src_comp_accept_output_port_connection.self_port = gsrc_def_port; | |
752 | event.data.src_comp_accept_output_port_connection.other_port = gsink_def_port; | |
fb9935cc | 753 | ok(has_event(&event), "got the expected source's accept port connection event"); |
c14181ff | 754 | src_accept_port_connection_pos = event_pos(&event); |
fb9935cc PP |
755 | |
756 | /* Sink's accept port connection */ | |
834e9996 PP |
757 | event.type = SINK_COMP_ACCEPT_INPUT_PORT_CONNECTION; |
758 | event.data.sink_comp_accept_input_port_connection.comp = gsink; | |
759 | event.data.sink_comp_accept_input_port_connection.self_port = gsink_def_port; | |
760 | event.data.sink_comp_accept_input_port_connection.other_port = gsrc_def_port; | |
fb9935cc | 761 | ok(has_event(&event), "got the expected sink's accept port connection event"); |
c14181ff PP |
762 | sink_accept_port_connection_pos = event_pos(&event); |
763 | ||
764 | /* Source's port connected */ | |
834e9996 PP |
765 | event.type = SRC_COMP_OUTPUT_PORT_CONNECTED; |
766 | event.data.src_comp_output_port_connected.comp = gsrc; | |
767 | event.data.src_comp_output_port_connected.self_port = gsrc_def_port; | |
768 | event.data.src_comp_output_port_connected.other_port = gsink_def_port; | |
c14181ff PP |
769 | ok(has_event(&event), "got the expected source's port connected event"); |
770 | src_port_connected_pos = event_pos(&event); | |
771 | ||
772 | /* Sink's port connected */ | |
834e9996 PP |
773 | event.type = SINK_COMP_INPUT_PORT_CONNECTED; |
774 | event.data.sink_comp_input_port_connected.comp = gsink; | |
775 | event.data.sink_comp_input_port_connected.self_port = gsink_def_port; | |
776 | event.data.sink_comp_input_port_connected.other_port = gsrc_def_port; | |
c14181ff PP |
777 | ok(has_event(&event), "got the expected sink's port connected event"); |
778 | sink_port_connected_pos = event_pos(&event); | |
fb9935cc | 779 | |
834e9996 PP |
780 | /* Graph's ports connected */ |
781 | event.type = GRAPH_SRC_SINK_PORTS_CONNECTED; | |
782 | event.data.graph_src_sink_ports_connected.upstream_comp = gsrc; | |
783 | event.data.graph_src_sink_ports_connected.downstream_comp = gsink; | |
784 | event.data.graph_src_sink_ports_connected.upstream_port = gsrc_def_port; | |
785 | event.data.graph_src_sink_ports_connected.downstream_port = gsink_def_port; | |
fb9935cc PP |
786 | ok(has_event(&event), "got the expected graph's ports connected event"); |
787 | graph_ports_connected_pos = event_pos(&event); | |
788 | ||
789 | /* Order of events */ | |
c14181ff | 790 | ok(src_port_connected_pos < graph_ports_connected_pos, |
fb9935cc | 791 | "event order is good (1)"); |
c14181ff | 792 | ok(sink_port_connected_pos < graph_ports_connected_pos, |
fb9935cc | 793 | "event order is good (2)"); |
c14181ff PP |
794 | ok(src_accept_port_connection_pos < src_port_connected_pos, |
795 | "event order is good (3)"); | |
796 | ok(sink_accept_port_connection_pos < sink_port_connected_pos, | |
797 | "event order is good (4)"); | |
fb9935cc | 798 | |
8c6884d9 PP |
799 | bt_component_sink_put_ref(sink); |
800 | bt_graph_put_ref(graph); | |
801 | bt_component_source_put_ref(src); | |
fb9935cc PP |
802 | } |
803 | ||
634f394c PP |
804 | static |
805 | void test_src_port_connected_error(void) | |
806 | { | |
8eee8ea2 PP |
807 | const bt_component_source *src; |
808 | const bt_component_sink *sink; | |
809 | const bt_component *gsrc; | |
810 | const bt_component *gsink; | |
811 | bt_graph *graph; | |
812 | const bt_port_output *src_def_port; | |
813 | const bt_port_input *sink_def_port; | |
814 | const bt_port *gsrc_def_port; | |
815 | const bt_port *gsink_def_port; | |
816 | const bt_connection *conn = NULL; | |
634f394c | 817 | struct event event; |
ee78f405 | 818 | bt_graph_status status; |
634f394c PP |
819 | size_t src_accept_port_connection_pos; |
820 | size_t src_port_connected_pos; | |
821 | ||
822 | prepare_test(TEST_SRC_PORT_CONNECTED_ERROR, "port connected error: source"); | |
823 | graph = create_graph(); | |
824 | BT_ASSERT(graph); | |
825 | src = create_src(graph); | |
826 | sink = create_sink(graph); | |
7b53201c PP |
827 | src_def_port = bt_component_source_borrow_output_port_by_name_const(src, |
828 | "out"); | |
634f394c | 829 | BT_ASSERT(src_def_port); |
7b53201c PP |
830 | sink_def_port = bt_component_sink_borrow_input_port_by_name_const(sink, |
831 | "in"); | |
634f394c | 832 | BT_ASSERT(sink_def_port); |
7b53201c | 833 | status = bt_graph_connect_ports(graph, src_def_port, |
834e9996 | 834 | sink_def_port, &conn); |
634f394c | 835 | ok(status != BT_GRAPH_STATUS_OK, |
7b53201c | 836 | "bt_graph_connect_ports() returns an error"); |
834e9996 | 837 | ok(!conn, "returned connection is still NULL"); |
7b53201c PP |
838 | gsrc = bt_component_source_as_component_const(src); |
839 | gsink = bt_component_sink_as_component_const(sink); | |
840 | gsrc_def_port = bt_port_output_as_port_const(src_def_port); | |
841 | gsink_def_port = bt_port_input_as_port_const(sink_def_port); | |
634f394c PP |
842 | |
843 | /* We're supposed to have 5 events */ | |
844 | ok(events->len == 5, "we have the expected number of events"); | |
845 | ||
846 | /* Source's port added */ | |
834e9996 PP |
847 | event.type = GRAPH_SRC_OUTPUT_PORT_ADDED; |
848 | event.data.graph_src_output_port_added.comp = gsrc; | |
849 | event.data.graph_src_output_port_added.port = gsrc_def_port; | |
634f394c PP |
850 | ok(has_event(&event), "got the expected graph's port added event (for source, initial)"); |
851 | ||
852 | /* Sink's port added */ | |
834e9996 PP |
853 | event.type = GRAPH_SINK_INPUT_PORT_ADDED; |
854 | event.data.graph_sink_input_port_added.comp = gsink; | |
855 | event.data.graph_sink_input_port_added.port = gsink_def_port; | |
634f394c PP |
856 | ok(has_event(&event), "got the expected graph's port added event (for sink, initial)"); |
857 | ||
858 | /* Source's accept port connection */ | |
834e9996 PP |
859 | event.type = SRC_COMP_ACCEPT_OUTPUT_PORT_CONNECTION; |
860 | event.data.src_comp_accept_output_port_connection.comp = gsrc; | |
861 | event.data.src_comp_accept_output_port_connection.self_port = gsrc_def_port; | |
862 | event.data.src_comp_accept_output_port_connection.other_port = gsink_def_port; | |
634f394c PP |
863 | ok(has_event(&event), "got the expected source's accept port connection event"); |
864 | src_accept_port_connection_pos = event_pos(&event); | |
865 | ||
866 | /* Sink's accept port connection */ | |
834e9996 PP |
867 | event.type = SINK_COMP_ACCEPT_INPUT_PORT_CONNECTION; |
868 | event.data.sink_comp_accept_input_port_connection.comp = gsink; | |
869 | event.data.sink_comp_accept_input_port_connection.self_port = gsink_def_port; | |
870 | event.data.sink_comp_accept_input_port_connection.other_port = gsrc_def_port; | |
634f394c PP |
871 | ok(has_event(&event), "got the expected sink's accept port connection event"); |
872 | ||
873 | /* Source's port connected */ | |
834e9996 PP |
874 | event.type = SRC_COMP_OUTPUT_PORT_CONNECTED; |
875 | event.data.src_comp_output_port_connected.comp = gsrc; | |
876 | event.data.src_comp_output_port_connected.self_port = gsrc_def_port; | |
877 | event.data.src_comp_output_port_connected.other_port = gsink_def_port; | |
634f394c PP |
878 | ok(has_event(&event), "got the expected source's port connected event"); |
879 | src_port_connected_pos = event_pos(&event); | |
880 | ||
881 | /* Order of events */ | |
882 | ok(src_accept_port_connection_pos < src_port_connected_pos, | |
883 | "event order is good (1)"); | |
884 | ||
8c6884d9 PP |
885 | bt_graph_put_ref(graph); |
886 | bt_component_sink_put_ref(sink); | |
887 | bt_component_source_put_ref(src); | |
888 | bt_connection_put_ref(conn); | |
634f394c PP |
889 | } |
890 | ||
891 | static | |
892 | void test_sink_port_connected_error(void) | |
893 | { | |
8eee8ea2 PP |
894 | const bt_component_source *src; |
895 | const bt_component_sink *sink; | |
896 | const bt_component *gsrc; | |
897 | const bt_component *gsink; | |
898 | bt_graph *graph; | |
899 | const bt_port_output *src_def_port; | |
900 | const bt_port_input *sink_def_port; | |
901 | const bt_port *gsrc_def_port; | |
902 | const bt_port *gsink_def_port; | |
903 | const bt_connection *conn = NULL; | |
634f394c | 904 | struct event event; |
ee78f405 | 905 | bt_graph_status status; |
634f394c PP |
906 | size_t src_accept_port_connection_pos; |
907 | size_t sink_accept_port_connection_pos; | |
908 | size_t src_port_connected_pos; | |
634f394c PP |
909 | size_t sink_port_connected_pos; |
910 | ||
911 | prepare_test(TEST_SINK_PORT_CONNECTED_ERROR, "port connected error: sink"); | |
912 | graph = create_graph(); | |
913 | BT_ASSERT(graph); | |
914 | src = create_src(graph); | |
915 | sink = create_sink(graph); | |
7b53201c PP |
916 | src_def_port = bt_component_source_borrow_output_port_by_name_const(src, |
917 | "out"); | |
634f394c | 918 | BT_ASSERT(src_def_port); |
7b53201c PP |
919 | sink_def_port = bt_component_sink_borrow_input_port_by_name_const(sink, |
920 | "in"); | |
634f394c | 921 | BT_ASSERT(sink_def_port); |
7b53201c | 922 | status = bt_graph_connect_ports(graph, src_def_port, |
834e9996 | 923 | sink_def_port, &conn); |
634f394c | 924 | ok(status != BT_GRAPH_STATUS_OK, |
7b53201c | 925 | "bt_graph_connect_ports() returns an error"); |
834e9996 | 926 | ok(!conn, "returned connection is still NULL"); |
7b53201c PP |
927 | gsrc = bt_component_source_as_component_const(src); |
928 | gsink = bt_component_sink_as_component_const(sink); | |
929 | gsrc_def_port = bt_port_output_as_port_const(src_def_port); | |
930 | gsink_def_port = bt_port_input_as_port_const(sink_def_port); | |
634f394c | 931 | |
9cce94e4 PP |
932 | /* We're supposed to have 6 events */ |
933 | ok(events->len == 6, "we have the expected number of events"); | |
634f394c PP |
934 | |
935 | /* Source's port added */ | |
834e9996 PP |
936 | event.type = GRAPH_SRC_OUTPUT_PORT_ADDED; |
937 | event.data.graph_src_output_port_added.comp = gsrc; | |
938 | event.data.graph_src_output_port_added.port = gsrc_def_port; | |
634f394c PP |
939 | ok(has_event(&event), "got the expected graph's port added event (for source, initial)"); |
940 | ||
941 | /* Sink's port added */ | |
834e9996 PP |
942 | event.type = GRAPH_SINK_INPUT_PORT_ADDED; |
943 | event.data.graph_sink_input_port_added.comp = gsink; | |
944 | event.data.graph_sink_input_port_added.port = gsink_def_port; | |
634f394c PP |
945 | ok(has_event(&event), "got the expected graph's port added event (for sink, initial)"); |
946 | ||
947 | /* Source's accept port connection */ | |
834e9996 PP |
948 | event.type = SRC_COMP_ACCEPT_OUTPUT_PORT_CONNECTION; |
949 | event.data.src_comp_accept_output_port_connection.comp = gsrc; | |
950 | event.data.src_comp_accept_output_port_connection.self_port = gsrc_def_port; | |
951 | event.data.src_comp_accept_output_port_connection.other_port = gsink_def_port; | |
634f394c PP |
952 | ok(has_event(&event), "got the expected source's accept port connection event"); |
953 | src_accept_port_connection_pos = event_pos(&event); | |
954 | ||
955 | /* Sink's accept port connection */ | |
834e9996 PP |
956 | event.type = SINK_COMP_ACCEPT_INPUT_PORT_CONNECTION; |
957 | event.data.sink_comp_accept_input_port_connection.comp = gsink; | |
958 | event.data.sink_comp_accept_input_port_connection.self_port = gsink_def_port; | |
959 | event.data.sink_comp_accept_input_port_connection.other_port = gsrc_def_port; | |
634f394c PP |
960 | ok(has_event(&event), "got the expected sink's accept port connection event"); |
961 | sink_accept_port_connection_pos = event_pos(&event); | |
962 | ||
963 | /* Source's port connected */ | |
834e9996 PP |
964 | event.type = SRC_COMP_OUTPUT_PORT_CONNECTED; |
965 | event.data.src_comp_output_port_connected.comp = gsrc; | |
966 | event.data.src_comp_output_port_connected.self_port = gsrc_def_port; | |
967 | event.data.src_comp_output_port_connected.other_port = gsink_def_port; | |
634f394c PP |
968 | ok(has_event(&event), "got the expected source's port connected event"); |
969 | src_port_connected_pos = event_pos(&event); | |
970 | ||
971 | /* Sink's port connected */ | |
834e9996 PP |
972 | event.type = SINK_COMP_INPUT_PORT_CONNECTED; |
973 | event.data.sink_comp_input_port_connected.comp = gsink; | |
974 | event.data.sink_comp_input_port_connected.self_port = gsink_def_port; | |
975 | event.data.sink_comp_input_port_connected.other_port = gsrc_def_port; | |
634f394c PP |
976 | ok(has_event(&event), "got the expected sink's port connected event"); |
977 | sink_port_connected_pos = event_pos(&event); | |
978 | ||
634f394c PP |
979 | /* Order of events */ |
980 | ok(src_accept_port_connection_pos < src_port_connected_pos, | |
981 | "event order is good (1)"); | |
982 | ok(sink_accept_port_connection_pos < sink_port_connected_pos, | |
983 | "event order is good (2)"); | |
634f394c | 984 | |
8c6884d9 PP |
985 | bt_connection_put_ref(conn); |
986 | bt_graph_put_ref(graph); | |
987 | bt_component_sink_put_ref(sink); | |
988 | bt_component_source_put_ref(src); | |
634f394c PP |
989 | } |
990 | ||
fb9935cc PP |
991 | static |
992 | void test_empty_graph(void) | |
993 | { | |
8eee8ea2 | 994 | bt_graph *graph; |
fb9935cc PP |
995 | |
996 | prepare_test(TEST_EMPTY_GRAPH, "empty graph"); | |
997 | graph = create_graph(); | |
998 | ok(events->len == 0, "empty graph generates no events"); | |
8c6884d9 | 999 | bt_graph_put_ref(graph); |
fb9935cc PP |
1000 | } |
1001 | ||
1002 | int main(int argc, char **argv) | |
1003 | { | |
1004 | plan_tests(NR_TESTS); | |
1005 | init_test(); | |
1006 | test_empty_graph(); | |
1007 | test_simple(); | |
634f394c PP |
1008 | test_src_port_connected_error(); |
1009 | test_sink_port_connected_error(); | |
c14181ff | 1010 | test_src_adds_port_in_port_connected(); |
fb9935cc PP |
1011 | fini_test(); |
1012 | return exit_status(); | |
1013 | } |