+static
+void test_output_port_notification_iterator(void)
+{
+ const struct test_event expected_test_events[] = {
+ { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, .stream = src_stream1, .packet = NULL, },
+ { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream1, .packet = src_stream1_packet1, },
+ { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet1, },
+ { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet1, },
+ { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, .stream = src_stream2, .packet = NULL, },
+ { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet1, },
+ { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream2, .packet = src_stream2_packet2, },
+ { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream2, .packet = src_stream2_packet2, },
+ { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet1, },
+ { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream1, .packet = src_stream1_packet1, },
+ { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream2, .packet = src_stream2_packet2, },
+ { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream1, .packet = src_stream1_packet2, },
+ { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet2, },
+ { .type = TEST_EV_TYPE_NOTIF_STREAM_END, .stream = src_stream2, .packet = NULL, },
+ { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream1, .packet = src_stream1_packet2, },
+ { .type = TEST_EV_TYPE_NOTIF_STREAM_END, .stream = src_stream1, .packet = NULL, },
+ { .type = TEST_EV_TYPE_END, },
+ { .type = TEST_EV_TYPE_SENTINEL, },
+ };
+ struct bt_component *src_comp;
+ struct bt_notification_iterator *notif_iter;
+ enum bt_notification_iterator_status iter_status =
+ BT_NOTIFICATION_ITERATOR_STATUS_OK;
+ struct bt_port *upstream_port;
+ struct bt_graph *graph;
+
+ clear_test_events();
+ current_test = TEST_OUTPUT_PORT_NOTIFICATION_ITERATOR;
+ diag("test: output port notification iterator");
+ graph = bt_graph_create();
+ assert(graph);
+ create_source_sink(graph, &src_comp, NULL);
+
+ /* Create notification iterator on source's output port */
+ upstream_port = bt_component_source_get_output_port_by_name(src_comp, "out");
+ notif_iter = bt_output_port_notification_iterator_create(upstream_port,
+ NULL, NULL);
+ ok(notif_iter, "bt_output_port_notification_iterator_create() succeeds");
+ bt_put(upstream_port);
+
+ /* Consume the notification iterator */
+ while (iter_status == BT_NOTIFICATION_ITERATOR_STATUS_OK) {
+ iter_status = common_consume(notif_iter);
+ }
+
+ ok(iter_status == BT_NOTIFICATION_ITERATOR_STATUS_END,
+ "output port notification iterator finishes without any error");
+
+ /* Compare the resulting test events */
+ ok(compare_test_events(expected_test_events),
+ "the produced sequence of test events is the expected one");
+
+ bt_put(src_comp);
+ bt_put(graph);
+ bt_put(notif_iter);
+}
+
+static
+void test_output_port_notification_iterator_subscribe_events(void)
+{
+ const struct test_event expected_test_events[] = {
+ { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet1, },
+ { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet1, },
+ { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet1, },
+ { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream2, .packet = src_stream2_packet2, },
+ { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet1, },
+ { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet2, },
+ { .type = TEST_EV_TYPE_END, },
+ { .type = TEST_EV_TYPE_SENTINEL, },
+ };
+ const enum bt_notification_type notification_types[] = {
+ BT_NOTIFICATION_TYPE_EVENT,
+ BT_NOTIFICATION_TYPE_SENTINEL,
+ };
+ struct bt_component *src_comp;
+ struct bt_notification_iterator *notif_iter;
+ enum bt_notification_iterator_status iter_status =
+ BT_NOTIFICATION_ITERATOR_STATUS_OK;
+ struct bt_port *upstream_port;
+ struct bt_graph *graph;
+
+ clear_test_events();
+ current_test = TEST_OUTPUT_PORT_NOTIFICATION_ITERATOR;
+ diag("test: output port notification iterator with event subscription");
+ graph = bt_graph_create();
+ assert(graph);
+ create_source_sink(graph, &src_comp, NULL);
+
+ /* Create notification iterator on source's output port */
+ upstream_port = bt_component_source_get_output_port_by_name(src_comp, "out");
+ notif_iter = bt_output_port_notification_iterator_create(upstream_port,
+ NULL, notification_types);
+ ok(notif_iter, "bt_output_port_notification_iterator_create() succeeds");
+ bt_put(upstream_port);
+
+ /* Consume the notification iterator */
+ while (iter_status == BT_NOTIFICATION_ITERATOR_STATUS_OK) {
+ iter_status = common_consume(notif_iter);
+ }
+
+ ok(iter_status == BT_NOTIFICATION_ITERATOR_STATUS_END,
+ "output port notification iterator finishes without any error");
+
+ /* Compare the resulting test events */
+ ok(compare_test_events(expected_test_events),
+ "the produced sequence of test events is the expected one");
+
+ bt_put(src_comp);
+ bt_put(graph);
+ bt_put(notif_iter);
+}
+
+static
+void test_output_port_notification_iterator_cannot_consume(void)
+{
+ struct bt_component *src_comp;
+ struct bt_notification_iterator *notif_iter;
+ struct bt_port *upstream_port;
+ struct bt_graph *graph;
+
+ clear_test_events();
+ current_test = TEST_OUTPUT_PORT_NOTIFICATION_ITERATOR;
+ diag("test: cannot consume graph with existing output port notification iterator");
+ graph = bt_graph_create();
+ assert(graph);
+ create_source_sink(graph, &src_comp, NULL);
+
+ /* Create notification iterator on source's output port */
+ upstream_port = bt_component_source_get_output_port_by_name(src_comp, "out");
+ notif_iter = bt_output_port_notification_iterator_create(upstream_port,
+ NULL, NULL);
+ assert(notif_iter);
+ bt_put(upstream_port);
+
+ /*
+ * This should fail because the graph is now managed by the
+ * notification iterator.
+ */
+ ok(bt_graph_run(graph) == BT_GRAPH_STATUS_CANNOT_CONSUME,
+ "bt_graph_run() returns BT_GRAPH_STATUS_CANNOT_CONSUME when there's an output port notification iterator");
+
+ bt_put(src_comp);
+ bt_put(graph);
+ bt_put(notif_iter);
+}
+