4 * Copyright 2017 - Philippe Proulx <pproulx@efficios.com>
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.
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.
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.
20 #include <babeltrace2/babeltrace.h>
21 #include "common/assert.h"
32 SRC_COMP_OUTPUT_PORT_CONNECTED
,
33 SINK_COMP_INPUT_PORT_CONNECTED
,
34 GRAPH_SRC_OUTPUT_PORT_ADDED
,
35 GRAPH_SINK_INPUT_PORT_ADDED
,
36 GRAPH_SRC_SINK_PORTS_CONNECTED
,
42 TEST_SRC_PORT_CONNECTED_ERROR
,
43 TEST_SINK_PORT_CONNECTED_ERROR
,
44 TEST_SRC_ADDS_PORT_IN_PORT_CONNECTED
,
52 const bt_component
*comp
;
53 const bt_port
*self_port
;
54 const bt_port
*other_port
;
55 } src_comp_output_port_connected
;
58 const bt_component
*comp
;
59 const bt_port
*self_port
;
60 const bt_port
*other_port
;
61 } sink_comp_input_port_connected
;
64 const bt_component
*comp
;
66 } graph_src_output_port_added
;
69 const bt_component
*comp
;
71 } graph_sink_input_port_added
;
74 const bt_component
*upstream_comp
;
75 const bt_component
*downstream_comp
;
76 const bt_port
*upstream_port
;
77 const bt_port
*downstream_port
;
78 } graph_src_sink_ports_connected
;
82 static GArray
*events
;
83 static bt_component_class_source
*src_comp_class
;
84 static bt_component_class_sink
*sink_comp_class
;
85 static enum test current_test
;
88 void clear_events(void)
90 g_array_set_size(events
, 0);
94 void append_event(struct event
*event
)
96 g_array_append_val(events
, *event
);
100 bool compare_events(struct event
*ev_a
, struct event
*ev_b
)
102 if (ev_a
->type
!= ev_b
->type
) {
106 switch (ev_a
->type
) {
107 case SRC_COMP_OUTPUT_PORT_CONNECTED
:
108 if (ev_a
->data
.src_comp_output_port_connected
.comp
!=
109 ev_b
->data
.src_comp_output_port_connected
.comp
) {
113 if (ev_a
->data
.src_comp_output_port_connected
.self_port
!=
114 ev_b
->data
.src_comp_output_port_connected
.self_port
) {
118 if (ev_a
->data
.src_comp_output_port_connected
.other_port
!=
119 ev_b
->data
.src_comp_output_port_connected
.other_port
) {
123 case SINK_COMP_INPUT_PORT_CONNECTED
:
124 if (ev_a
->data
.sink_comp_input_port_connected
.comp
!=
125 ev_b
->data
.sink_comp_input_port_connected
.comp
) {
129 if (ev_a
->data
.sink_comp_input_port_connected
.self_port
!=
130 ev_b
->data
.sink_comp_input_port_connected
.self_port
) {
134 if (ev_a
->data
.sink_comp_input_port_connected
.other_port
!=
135 ev_b
->data
.sink_comp_input_port_connected
.other_port
) {
139 case GRAPH_SRC_OUTPUT_PORT_ADDED
:
140 if (ev_a
->data
.graph_src_output_port_added
.comp
!=
141 ev_b
->data
.graph_src_output_port_added
.comp
) {
145 if (ev_a
->data
.graph_src_output_port_added
.port
!=
146 ev_b
->data
.graph_src_output_port_added
.port
) {
150 case GRAPH_SINK_INPUT_PORT_ADDED
:
151 if (ev_a
->data
.graph_sink_input_port_added
.comp
!=
152 ev_b
->data
.graph_sink_input_port_added
.comp
) {
156 if (ev_a
->data
.graph_sink_input_port_added
.port
!=
157 ev_b
->data
.graph_sink_input_port_added
.port
) {
161 case GRAPH_SRC_SINK_PORTS_CONNECTED
:
162 if (ev_a
->data
.graph_src_sink_ports_connected
.upstream_comp
!=
163 ev_b
->data
.graph_src_sink_ports_connected
.upstream_comp
) {
167 if (ev_a
->data
.graph_src_sink_ports_connected
.downstream_comp
!=
168 ev_b
->data
.graph_src_sink_ports_connected
.downstream_comp
) {
172 if (ev_a
->data
.graph_src_sink_ports_connected
.upstream_port
!=
173 ev_b
->data
.graph_src_sink_ports_connected
.upstream_port
) {
177 if (ev_a
->data
.graph_src_sink_ports_connected
.downstream_port
!=
178 ev_b
->data
.graph_src_sink_ports_connected
.downstream_port
) {
190 bool has_event(struct event
*event
)
194 for (i
= 0; i
< events
->len
; i
++) {
195 struct event
*ev
= &g_array_index(events
, struct event
, i
);
197 if (compare_events(event
, ev
)) {
206 size_t event_pos(struct event
*event
)
210 for (i
= 0; i
< events
->len
; i
++) {
211 struct event
*ev
= &g_array_index(events
, struct event
, i
);
213 if (compare_events(event
, ev
)) {
222 bt_component_class_message_iterator_next_method_status
src_iter_next(
223 bt_self_message_iterator
*self_iterator
,
224 bt_message_array_const msgs
, uint64_t capacity
,
227 return BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_ERROR
;
231 bt_component_class_port_connected_method_status
src_output_port_connected(
232 bt_self_component_source
*self_comp
,
233 bt_self_component_port_output
*self_comp_port
,
234 const bt_port_input
*other_port
)
237 struct event event
= {
238 .type
= SRC_COMP_OUTPUT_PORT_CONNECTED
,
239 .data
.src_comp_output_port_connected
= {
240 .comp
= bt_self_component_as_component(
241 bt_self_component_source_as_self_component(
243 .self_port
= bt_self_component_port_as_port(
244 bt_self_component_port_output_as_self_component_port(
246 .other_port
= bt_port_input_as_port_const(other_port
),
250 append_event(&event
);
252 switch (current_test
) {
253 case TEST_SRC_ADDS_PORT_IN_PORT_CONNECTED
:
254 ret
= bt_self_component_source_add_output_port(
255 self_comp
, "hello", NULL
, NULL
);
258 case TEST_SRC_PORT_CONNECTED_ERROR
:
259 return BT_COMPONENT_CLASS_PORT_CONNECTED_METHOD_STATUS_ERROR
;
264 return BT_COMPONENT_CLASS_PORT_CONNECTED_METHOD_STATUS_OK
;
268 bt_component_class_port_connected_method_status
sink_input_port_connected(
269 bt_self_component_sink
*self_comp
,
270 bt_self_component_port_input
*self_comp_port
,
271 const bt_port_output
*other_port
)
273 struct event event
= {
274 .type
= SINK_COMP_INPUT_PORT_CONNECTED
,
275 .data
.sink_comp_input_port_connected
= {
276 .comp
= bt_self_component_as_component(
277 bt_self_component_sink_as_self_component(
279 .self_port
= bt_self_component_port_as_port(
280 bt_self_component_port_input_as_self_component_port(
282 .other_port
= bt_port_output_as_port_const(other_port
),
286 append_event(&event
);
288 if (current_test
== TEST_SINK_PORT_CONNECTED_ERROR
) {
289 return BT_COMPONENT_CLASS_PORT_CONNECTED_METHOD_STATUS_ERROR
;
291 return BT_COMPONENT_CLASS_PORT_CONNECTED_METHOD_STATUS_OK
;
296 bt_component_class_init_method_status
src_init(
297 bt_self_component_source
*self_comp
,
298 const bt_value
*params
, void *init_method_data
)
302 ret
= bt_self_component_source_add_output_port(
303 self_comp
, "out", NULL
, NULL
);
305 return BT_COMPONENT_CLASS_INIT_METHOD_STATUS_OK
;
309 bt_component_class_init_method_status
sink_init(
310 bt_self_component_sink
*self_comp
,
311 const bt_value
*params
, void *init_method_data
)
315 ret
= bt_self_component_sink_add_input_port(self_comp
,
318 return BT_COMPONENT_CLASS_INIT_METHOD_STATUS_OK
;
322 bt_component_class_sink_consume_method_status
sink_consume(
323 bt_self_component_sink
*self_comp
)
325 return BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK
;
329 bt_graph_listener_func_status
graph_src_output_port_added(
330 const bt_component_source
*comp
, const bt_port_output
*port
,
333 struct event event
= {
334 .type
= GRAPH_SRC_OUTPUT_PORT_ADDED
,
335 .data
.graph_src_output_port_added
= {
336 .comp
= bt_component_source_as_component_const(comp
),
337 .port
= bt_port_output_as_port_const(port
),
341 append_event(&event
);
343 return BT_GRAPH_LISTENER_FUNC_STATUS_OK
;
347 bt_graph_listener_func_status
graph_sink_input_port_added(
348 const bt_component_sink
*comp
, const bt_port_input
*port
,
351 struct event event
= {
352 .type
= GRAPH_SINK_INPUT_PORT_ADDED
,
353 .data
.graph_sink_input_port_added
= {
354 .comp
= bt_component_sink_as_component_const(comp
),
355 .port
= bt_port_input_as_port_const(port
),
359 append_event(&event
);
361 return BT_GRAPH_LISTENER_FUNC_STATUS_OK
;
365 bt_graph_listener_func_status
graph_src_sink_ports_connected(
366 const bt_component_source
*upstream_comp
,
367 const bt_component_sink
*downstream_comp
,
368 const bt_port_output
*upstream_port
,
369 const bt_port_input
*downstream_port
, void *data
)
371 struct event event
= {
372 .type
= GRAPH_SRC_SINK_PORTS_CONNECTED
,
373 .data
.graph_src_sink_ports_connected
= {
375 bt_component_source_as_component_const(upstream_comp
),
377 bt_component_sink_as_component_const(downstream_comp
),
379 bt_port_output_as_port_const(upstream_port
),
381 bt_port_input_as_port_const(downstream_port
),
385 append_event(&event
);
387 return BT_GRAPH_LISTENER_FUNC_STATUS_OK
;
395 src_comp_class
= bt_component_class_source_create(
396 "src", src_iter_next
);
397 BT_ASSERT(src_comp_class
);
398 ret
= bt_component_class_source_set_init_method(
399 src_comp_class
, src_init
);
401 ret
= bt_component_class_source_set_output_port_connected_method(
402 src_comp_class
, src_output_port_connected
);
404 sink_comp_class
= bt_component_class_sink_create("sink",
406 BT_ASSERT(sink_comp_class
);
407 ret
= bt_component_class_sink_set_init_method(sink_comp_class
,
410 ret
= bt_component_class_sink_set_input_port_connected_method(
411 sink_comp_class
, sink_input_port_connected
);
413 events
= g_array_new(FALSE
, TRUE
, sizeof(struct event
));
420 bt_component_class_source_put_ref(src_comp_class
);
421 bt_component_class_sink_put_ref(sink_comp_class
);
422 g_array_free(events
, TRUE
);
426 const bt_component_source
*create_src(bt_graph
*graph
)
428 const bt_component_source
*comp
;
431 ret
= bt_graph_add_source_component(graph
, src_comp_class
,
432 "src-comp", NULL
, BT_LOGGING_LEVEL_NONE
, &comp
);
438 const bt_component_sink
*create_sink(bt_graph
*graph
)
440 const bt_component_sink
*comp
;
443 ret
= bt_graph_add_sink_component(graph
, sink_comp_class
,
444 "sink-comp", NULL
, BT_LOGGING_LEVEL_NONE
, &comp
);
450 bt_graph
*create_graph(void)
452 bt_graph
*graph
= bt_graph_create(0);
456 ret
= bt_graph_add_source_component_output_port_added_listener(
457 graph
, graph_src_output_port_added
, NULL
, NULL
, NULL
);
459 ret
= bt_graph_add_sink_component_input_port_added_listener(
460 graph
, graph_sink_input_port_added
, NULL
, NULL
, NULL
);
462 ret
= bt_graph_add_source_sink_component_ports_connected_listener(
463 graph
, graph_src_sink_ports_connected
, NULL
, NULL
, NULL
);
469 void prepare_test(enum test test
, const char *name
)
473 diag("test: %s", name
);
477 void test_src_adds_port_in_port_connected(void)
479 const bt_component_source
*src
;
480 const bt_component_sink
*sink
;
481 const bt_component
*gsrc
;
482 const bt_component
*gsink
;
484 const bt_port_output
*src_def_port
;
485 const bt_port_output
*src_hello_port
;
486 const bt_port_input
*sink_def_port
;
487 const bt_port
*gsrc_def_port
;
488 const bt_port
*gsrc_hello_port
;
489 const bt_port
*gsink_def_port
;
491 bt_graph_connect_ports_status status
;
492 size_t src_port_connected_pos
;
493 size_t sink_port_connected_pos
;
494 size_t graph_ports_connected_pos
;
495 size_t graph_port_added_src_pos
;
497 prepare_test(TEST_SRC_ADDS_PORT_IN_PORT_CONNECTED
,
498 "source adds port in port connected");
499 graph
= create_graph();
501 src
= create_src(graph
);
502 sink
= create_sink(graph
);
503 src_def_port
= bt_component_source_borrow_output_port_by_name_const(src
,
505 BT_ASSERT(src_def_port
);
506 sink_def_port
= bt_component_sink_borrow_input_port_by_name_const(sink
,
508 BT_ASSERT(sink_def_port
);
509 status
= bt_graph_connect_ports(graph
, src_def_port
,
510 sink_def_port
, NULL
);
511 BT_ASSERT(status
== 0);
512 src_hello_port
= bt_component_source_borrow_output_port_by_name_const(src
,
514 BT_ASSERT(src_hello_port
);
515 gsrc
= bt_component_source_as_component_const(src
);
516 gsink
= bt_component_sink_as_component_const(sink
);
517 gsrc_def_port
= bt_port_output_as_port_const(src_def_port
);
518 gsrc_hello_port
= bt_port_output_as_port_const(src_hello_port
);
519 gsink_def_port
= bt_port_input_as_port_const(sink_def_port
);
521 /* We're supposed to have 6 events */
522 ok(events
->len
== 6, "we have the expected number of events");
524 /* Source's port added */
525 event
.type
= GRAPH_SRC_OUTPUT_PORT_ADDED
;
526 event
.data
.graph_src_output_port_added
.comp
= gsrc
;
527 event
.data
.graph_src_output_port_added
.port
= gsrc_def_port
;
528 ok(has_event(&event
), "got the expected graph's port added event (for source, initial)");
530 /* Sink's port added */
531 event
.type
= GRAPH_SINK_INPUT_PORT_ADDED
;
532 event
.data
.graph_sink_input_port_added
.comp
= gsink
;
533 event
.data
.graph_sink_input_port_added
.port
= gsink_def_port
;
534 ok(has_event(&event
), "got the expected graph's port added event (for sink, initial)");
536 /* Source's port connected */
537 event
.type
= SRC_COMP_OUTPUT_PORT_CONNECTED
;
538 event
.data
.src_comp_output_port_connected
.comp
= gsrc
;
539 event
.data
.src_comp_output_port_connected
.self_port
= gsrc_def_port
;
540 event
.data
.src_comp_output_port_connected
.other_port
= gsink_def_port
;
541 ok(has_event(&event
), "got the expected source's port connected event");
542 src_port_connected_pos
= event_pos(&event
);
544 /* Graph's port added (source) */
545 event
.type
= GRAPH_SRC_OUTPUT_PORT_ADDED
;
546 event
.data
.graph_src_output_port_added
.comp
= gsrc
;
547 event
.data
.graph_src_output_port_added
.port
= gsrc_hello_port
;
548 ok(has_event(&event
), "got the expected graph's port added event (for source)");
549 graph_port_added_src_pos
= event_pos(&event
);
551 /* Sink's port connected */
552 event
.type
= SINK_COMP_INPUT_PORT_CONNECTED
;
553 event
.data
.sink_comp_input_port_connected
.comp
= gsink
;
554 event
.data
.sink_comp_input_port_connected
.self_port
= gsink_def_port
;
555 event
.data
.sink_comp_input_port_connected
.other_port
= gsrc_def_port
;
556 ok(has_event(&event
), "got the expected sink's port connected event");
557 sink_port_connected_pos
= event_pos(&event
);
559 /* Graph's ports connected */
560 event
.type
= GRAPH_SRC_SINK_PORTS_CONNECTED
;
561 event
.data
.graph_src_sink_ports_connected
.upstream_comp
= gsrc
;
562 event
.data
.graph_src_sink_ports_connected
.downstream_comp
= gsink
;
563 event
.data
.graph_src_sink_ports_connected
.upstream_port
= gsrc_def_port
;
564 event
.data
.graph_src_sink_ports_connected
.downstream_port
= gsink_def_port
;
565 ok(has_event(&event
), "got the expected graph's ports connected event");
566 graph_ports_connected_pos
= event_pos(&event
);
568 /* Order of events */
569 ok(src_port_connected_pos
< graph_ports_connected_pos
,
570 "event order is good (1)");
571 ok(sink_port_connected_pos
< graph_ports_connected_pos
,
572 "event order is good (2)");
573 ok(src_port_connected_pos
< graph_port_added_src_pos
,
574 "event order is good (3)");
575 ok(graph_port_added_src_pos
< graph_ports_connected_pos
,
576 "event order is good (4)");
578 bt_component_source_put_ref(src
);
579 bt_component_sink_put_ref(sink
);
580 bt_graph_put_ref(graph
);
584 void test_simple(void)
586 const bt_component_source
*src
;
587 const bt_component_sink
*sink
;
588 const bt_component
*gsrc
;
589 const bt_component
*gsink
;
591 const bt_port_output
*src_def_port
;
592 const bt_port_input
*sink_def_port
;
593 const bt_port
*gsrc_def_port
;
594 const bt_port
*gsink_def_port
;
596 bt_graph_connect_ports_status status
;
597 size_t src_port_connected_pos
;
598 size_t sink_port_connected_pos
;
599 size_t graph_ports_connected_pos
;
601 prepare_test(TEST_SIMPLE
, "simple");
602 graph
= create_graph();
604 src
= create_src(graph
);
605 sink
= create_sink(graph
);
606 src_def_port
= bt_component_source_borrow_output_port_by_name_const(src
,
608 BT_ASSERT(src_def_port
);
609 sink_def_port
= bt_component_sink_borrow_input_port_by_name_const(sink
,
611 BT_ASSERT(sink_def_port
);
612 status
= bt_graph_connect_ports(graph
, src_def_port
,
613 sink_def_port
, NULL
);
614 BT_ASSERT(status
== 0);
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 gsink_def_port
= bt_port_input_as_port_const(sink_def_port
);
620 /* We're supposed to have 5 events */
621 ok(events
->len
== 5, "we have the expected number of events");
623 /* Source's port added */
624 event
.type
= GRAPH_SRC_OUTPUT_PORT_ADDED
;
625 event
.data
.graph_src_output_port_added
.comp
= gsrc
;
626 event
.data
.graph_src_output_port_added
.port
= gsrc_def_port
;
627 ok(has_event(&event
), "got the expected graph's port added event (for source, initial)");
629 /* Sink's port added */
630 event
.type
= GRAPH_SINK_INPUT_PORT_ADDED
;
631 event
.data
.graph_sink_input_port_added
.comp
= gsink
;
632 event
.data
.graph_sink_input_port_added
.port
= gsink_def_port
;
633 ok(has_event(&event
), "got the expected graph's port added event (for sink, initial)");
635 /* Source's port connected */
636 event
.type
= SRC_COMP_OUTPUT_PORT_CONNECTED
;
637 event
.data
.src_comp_output_port_connected
.comp
= gsrc
;
638 event
.data
.src_comp_output_port_connected
.self_port
= gsrc_def_port
;
639 event
.data
.src_comp_output_port_connected
.other_port
= gsink_def_port
;
640 ok(has_event(&event
), "got the expected source's port connected event");
641 src_port_connected_pos
= event_pos(&event
);
643 /* Sink's port connected */
644 event
.type
= SINK_COMP_INPUT_PORT_CONNECTED
;
645 event
.data
.sink_comp_input_port_connected
.comp
= gsink
;
646 event
.data
.sink_comp_input_port_connected
.self_port
= gsink_def_port
;
647 event
.data
.sink_comp_input_port_connected
.other_port
= gsrc_def_port
;
648 ok(has_event(&event
), "got the expected sink's port connected event");
649 sink_port_connected_pos
= event_pos(&event
);
651 /* Graph's ports connected */
652 event
.type
= GRAPH_SRC_SINK_PORTS_CONNECTED
;
653 event
.data
.graph_src_sink_ports_connected
.upstream_comp
= gsrc
;
654 event
.data
.graph_src_sink_ports_connected
.downstream_comp
= gsink
;
655 event
.data
.graph_src_sink_ports_connected
.upstream_port
= gsrc_def_port
;
656 event
.data
.graph_src_sink_ports_connected
.downstream_port
= gsink_def_port
;
657 ok(has_event(&event
), "got the expected graph's ports connected event");
658 graph_ports_connected_pos
= event_pos(&event
);
660 /* Order of events */
661 ok(src_port_connected_pos
< graph_ports_connected_pos
,
662 "event order is good (1)");
663 ok(sink_port_connected_pos
< graph_ports_connected_pos
,
664 "event order is good (2)");
666 bt_component_sink_put_ref(sink
);
667 bt_graph_put_ref(graph
);
668 bt_component_source_put_ref(src
);
672 void test_src_port_connected_error(void)
674 const bt_component_source
*src
;
675 const bt_component_sink
*sink
;
676 const bt_component
*gsrc
;
677 const bt_component
*gsink
;
679 const bt_port_output
*src_def_port
;
680 const bt_port_input
*sink_def_port
;
681 const bt_port
*gsrc_def_port
;
682 const bt_port
*gsink_def_port
;
683 const bt_connection
*conn
= NULL
;
685 bt_graph_connect_ports_status status
;
687 prepare_test(TEST_SRC_PORT_CONNECTED_ERROR
, "port connected error: source");
688 graph
= create_graph();
690 src
= create_src(graph
);
691 sink
= create_sink(graph
);
692 src_def_port
= bt_component_source_borrow_output_port_by_name_const(src
,
694 BT_ASSERT(src_def_port
);
695 sink_def_port
= bt_component_sink_borrow_input_port_by_name_const(sink
,
697 BT_ASSERT(sink_def_port
);
698 status
= bt_graph_connect_ports(graph
, src_def_port
,
699 sink_def_port
, &conn
);
700 ok(status
!= BT_GRAPH_CONNECT_PORTS_STATUS_OK
,
701 "bt_graph_connect_ports() returns an error");
702 bt_current_thread_clear_error();
703 ok(!conn
, "returned connection is still NULL");
704 gsrc
= bt_component_source_as_component_const(src
);
705 gsink
= bt_component_sink_as_component_const(sink
);
706 gsrc_def_port
= bt_port_output_as_port_const(src_def_port
);
707 gsink_def_port
= bt_port_input_as_port_const(sink_def_port
);
709 /* We're supposed to have 3 events */
710 ok(events
->len
== 3, "we have the expected number of events");
712 /* Source's port added */
713 event
.type
= GRAPH_SRC_OUTPUT_PORT_ADDED
;
714 event
.data
.graph_src_output_port_added
.comp
= gsrc
;
715 event
.data
.graph_src_output_port_added
.port
= gsrc_def_port
;
716 ok(has_event(&event
), "got the expected graph's port added event (for source, initial)");
718 /* Sink's port added */
719 event
.type
= GRAPH_SINK_INPUT_PORT_ADDED
;
720 event
.data
.graph_sink_input_port_added
.comp
= gsink
;
721 event
.data
.graph_sink_input_port_added
.port
= gsink_def_port
;
722 ok(has_event(&event
), "got the expected graph's port added event (for sink, initial)");
724 /* Source's port connected */
725 event
.type
= SRC_COMP_OUTPUT_PORT_CONNECTED
;
726 event
.data
.src_comp_output_port_connected
.comp
= gsrc
;
727 event
.data
.src_comp_output_port_connected
.self_port
= gsrc_def_port
;
728 event
.data
.src_comp_output_port_connected
.other_port
= gsink_def_port
;
729 ok(has_event(&event
), "got the expected source's port connected event");
731 bt_graph_put_ref(graph
);
732 bt_component_sink_put_ref(sink
);
733 bt_component_source_put_ref(src
);
734 bt_connection_put_ref(conn
);
738 void test_sink_port_connected_error(void)
740 const bt_component_source
*src
;
741 const bt_component_sink
*sink
;
742 const bt_component
*gsrc
;
743 const bt_component
*gsink
;
745 const bt_port_output
*src_def_port
;
746 const bt_port_input
*sink_def_port
;
747 const bt_port
*gsrc_def_port
;
748 const bt_port
*gsink_def_port
;
749 const bt_connection
*conn
= NULL
;
751 bt_graph_connect_ports_status status
;
753 prepare_test(TEST_SINK_PORT_CONNECTED_ERROR
, "port connected error: sink");
754 graph
= create_graph();
756 src
= create_src(graph
);
757 sink
= create_sink(graph
);
758 src_def_port
= bt_component_source_borrow_output_port_by_name_const(src
,
760 BT_ASSERT(src_def_port
);
761 sink_def_port
= bt_component_sink_borrow_input_port_by_name_const(sink
,
763 BT_ASSERT(sink_def_port
);
764 status
= bt_graph_connect_ports(graph
, src_def_port
,
765 sink_def_port
, &conn
);
766 ok(status
!= BT_GRAPH_CONNECT_PORTS_STATUS_OK
,
767 "bt_graph_connect_ports() returns an error");
768 bt_current_thread_clear_error();
769 ok(!conn
, "returned connection is still NULL");
770 gsrc
= bt_component_source_as_component_const(src
);
771 gsink
= bt_component_sink_as_component_const(sink
);
772 gsrc_def_port
= bt_port_output_as_port_const(src_def_port
);
773 gsink_def_port
= bt_port_input_as_port_const(sink_def_port
);
775 /* We're supposed to have 4 events */
776 ok(events
->len
== 4, "we have the expected number of events");
778 /* Source's port added */
779 event
.type
= GRAPH_SRC_OUTPUT_PORT_ADDED
;
780 event
.data
.graph_src_output_port_added
.comp
= gsrc
;
781 event
.data
.graph_src_output_port_added
.port
= gsrc_def_port
;
782 ok(has_event(&event
), "got the expected graph's port added event (for source, initial)");
784 /* Sink's port added */
785 event
.type
= GRAPH_SINK_INPUT_PORT_ADDED
;
786 event
.data
.graph_sink_input_port_added
.comp
= gsink
;
787 event
.data
.graph_sink_input_port_added
.port
= gsink_def_port
;
788 ok(has_event(&event
), "got the expected graph's port added event (for sink, initial)");
790 /* Source's port connected */
791 event
.type
= SRC_COMP_OUTPUT_PORT_CONNECTED
;
792 event
.data
.src_comp_output_port_connected
.comp
= gsrc
;
793 event
.data
.src_comp_output_port_connected
.self_port
= gsrc_def_port
;
794 event
.data
.src_comp_output_port_connected
.other_port
= gsink_def_port
;
795 ok(has_event(&event
), "got the expected source's port connected event");
797 /* Sink's port connected */
798 event
.type
= SINK_COMP_INPUT_PORT_CONNECTED
;
799 event
.data
.sink_comp_input_port_connected
.comp
= gsink
;
800 event
.data
.sink_comp_input_port_connected
.self_port
= gsink_def_port
;
801 event
.data
.sink_comp_input_port_connected
.other_port
= gsrc_def_port
;
802 ok(has_event(&event
), "got the expected sink's port connected event");
804 bt_connection_put_ref(conn
);
805 bt_graph_put_ref(graph
);
806 bt_component_sink_put_ref(sink
);
807 bt_component_source_put_ref(src
);
811 void test_empty_graph(void)
815 prepare_test(TEST_EMPTY_GRAPH
, "empty graph");
816 graph
= create_graph();
817 ok(events
->len
== 0, "empty graph generates no events");
818 bt_graph_put_ref(graph
);
821 int main(int argc
, char **argv
)
823 plan_tests(NR_TESTS
);
827 test_src_port_connected_error();
828 test_sink_port_connected_error();
829 test_src_adds_port_in_port_connected();
831 return exit_status();