Rename: bt_put(), bt_get() -> bt_object_put_ref(), bt_object_get_ref()
[deliverable/babeltrace.git] / tests / lib / test_bt_notification_iterator.c
index 4cecf36282cc68bf678f9fbad61141d0d7a320f8..609bb4e3244756b0e7134227cc66d47c091b8627 100644 (file)
 #include <inttypes.h>
 #include <string.h>
 #include <babeltrace/assert-internal.h>
-#include <babeltrace/ctf-ir/event-class.h>
-#include <babeltrace/ctf-ir/event.h>
-#include <babeltrace/ctf-ir/field-types.h>
-#include <babeltrace/ctf-ir/fields.h>
-#include <babeltrace/ctf-ir/packet.h>
-#include <babeltrace/ctf-ir/stream-class.h>
-#include <babeltrace/ctf-ir/stream.h>
-#include <babeltrace/ctf-ir/trace.h>
-#include <babeltrace/graph/clock-class-priority-map.h>
+#include <babeltrace/trace-ir/event-class.h>
+#include <babeltrace/trace-ir/event.h>
+#include <babeltrace/trace-ir/field-classes.h>
+#include <babeltrace/trace-ir/fields.h>
+#include <babeltrace/trace-ir/packet.h>
+#include <babeltrace/trace-ir/stream-class.h>
+#include <babeltrace/trace-ir/stream.h>
+#include <babeltrace/trace-ir/trace.h>
 #include <babeltrace/graph/component-class-filter.h>
 #include <babeltrace/graph/component-class-sink.h>
 #include <babeltrace/graph/component-class-source.h>
@@ -41,7 +40,6 @@
 #include <babeltrace/graph/connection.h>
 #include <babeltrace/graph/graph.h>
 #include <babeltrace/graph/notification-event.h>
-#include <babeltrace/graph/notification-inactivity.h>
 #include <babeltrace/graph/notification-iterator.h>
 #include <babeltrace/graph/notification-packet.h>
 #include <babeltrace/graph/notification-stream.h>
@@ -55,7 +53,7 @@
 #include <babeltrace/graph/private-connection-private-notification-iterator.h>
 #include <babeltrace/graph/private-port.h>
 #include <babeltrace/plugin/plugin.h>
-#include <babeltrace/ref.h>
+#include <babeltrace/object.h>
 #include <glib.h>
 
 #include "tap/tap.h"
@@ -70,7 +68,6 @@ enum test {
 enum test_event_type {
        TEST_EV_TYPE_NOTIF_UNEXPECTED,
        TEST_EV_TYPE_NOTIF_EVENT,
-       TEST_EV_TYPE_NOTIF_INACTIVITY,
        TEST_EV_TYPE_NOTIF_STREAM_BEGIN,
        TEST_EV_TYPE_NOTIF_PACKET_BEGIN,
        TEST_EV_TYPE_NOTIF_PACKET_END,
@@ -89,7 +86,7 @@ static bool debug = false;
 static enum test current_test;
 static GArray *test_events;
 static struct bt_graph *graph;
-static struct bt_clock_class_priority_map *src_empty_cc_prio_map;
+static struct bt_private_connection_private_notification_iterator *cur_notif_iter;
 static struct bt_stream_class *src_stream_class;
 static struct bt_event_class *src_event_class;
 static struct bt_stream *src_stream1;
@@ -117,7 +114,6 @@ enum {
        SEQ_EVENT_STREAM1_PACKET2 = -15,
        SEQ_EVENT_STREAM2_PACKET1 = -16,
        SEQ_EVENT_STREAM2_PACKET2 = -17,
-       SEQ_INACTIVITY = -18,
 };
 
 struct src_iter_user_data {
@@ -171,9 +167,6 @@ void print_test_event(FILE *fp, const struct test_event *event)
        case TEST_EV_TYPE_NOTIF_EVENT:
                fprintf(fp, "TEST_EV_TYPE_NOTIF_EVENT");
                break;
-       case TEST_EV_TYPE_NOTIF_INACTIVITY:
-               fprintf(fp, "TEST_EV_TYPE_NOTIF_INACTIVITY");
-               break;
        case TEST_EV_TYPE_NOTIF_STREAM_BEGIN:
                fprintf(fp, "TEST_EV_TYPE_NOTIF_STREAM_BEGIN");
                break;
@@ -280,49 +273,22 @@ bool compare_test_events(const struct test_event *expected_events)
 static
 void init_static_data(void)
 {
-       int ret;
        struct bt_trace *trace;
-       struct bt_field_type *empty_struct_ft;
 
        /* Test events */
        test_events = g_array_new(FALSE, TRUE, sizeof(struct test_event));
        BT_ASSERT(test_events);
 
        /* Metadata */
-       empty_struct_ft = bt_field_type_structure_create();
-       BT_ASSERT(empty_struct_ft);
        trace = bt_trace_create();
        BT_ASSERT(trace);
-       ret = bt_trace_set_packet_header_field_type(trace, empty_struct_ft);
-       BT_ASSERT(ret == 0);
-       src_empty_cc_prio_map = bt_clock_class_priority_map_create();
-       BT_ASSERT(src_empty_cc_prio_map);
-       src_stream_class = bt_stream_class_create("my-stream-class");
+       src_stream_class = bt_stream_class_create(trace);
        BT_ASSERT(src_stream_class);
-       ret = bt_stream_class_set_packet_context_field_type(src_stream_class,
-               empty_struct_ft);
-       BT_ASSERT(ret == 0);
-       ret = bt_stream_class_set_event_header_field_type(src_stream_class,
-               empty_struct_ft);
-       BT_ASSERT(ret == 0);
-       ret = bt_stream_class_set_event_context_field_type(src_stream_class,
-               empty_struct_ft);
-       BT_ASSERT(ret == 0);
-       src_event_class = bt_event_class_create("my-event-class");
-       ret = bt_event_class_set_context_field_type(src_event_class,
-               empty_struct_ft);
-       BT_ASSERT(ret == 0);
-       ret = bt_event_class_set_payload_field_type(src_event_class,
-               empty_struct_ft);
-       BT_ASSERT(ret == 0);
-       ret = bt_stream_class_add_event_class(src_stream_class,
-               src_event_class);
-       BT_ASSERT(ret == 0);
-       ret = bt_trace_add_stream_class(trace, src_stream_class);
-       BT_ASSERT(ret == 0);
-       src_stream1 = bt_stream_create(src_stream_class, "stream-1", 0);
+       src_event_class = bt_event_class_create(src_stream_class);
+       BT_ASSERT(src_event_class);
+       src_stream1 = bt_stream_create(src_stream_class);
        BT_ASSERT(src_stream1);
-       src_stream2 = bt_stream_create(src_stream_class, "stream-2", 1);
+       src_stream2 = bt_stream_create(src_stream_class);
        BT_ASSERT(src_stream2);
        src_stream1_packet1 = bt_packet_create(src_stream1);
        BT_ASSERT(src_stream1_packet1);
@@ -342,8 +308,7 @@ void init_static_data(void)
                fprintf(stderr, ":: stream 2, packet 2: %p\n", src_stream2_packet2);
        }
 
-       bt_put(trace);
-       bt_put(empty_struct_ft);
+       bt_object_put_ref(trace);
 }
 
 static
@@ -353,15 +318,14 @@ void fini_static_data(void)
        g_array_free(test_events, TRUE);
 
        /* Metadata */
-       bt_put(src_empty_cc_prio_map);
-       bt_put(src_stream_class);
-       bt_put(src_event_class);
-       bt_put(src_stream1);
-       bt_put(src_stream2);
-       bt_put(src_stream1_packet1);
-       bt_put(src_stream1_packet2);
-       bt_put(src_stream2_packet1);
-       bt_put(src_stream2_packet2);
+       bt_object_put_ref(src_stream_class);
+       bt_object_put_ref(src_event_class);
+       bt_object_put_ref(src_stream1);
+       bt_object_put_ref(src_stream2);
+       bt_object_put_ref(src_stream1_packet1);
+       bt_object_put_ref(src_stream1_packet2);
+       bt_object_put_ref(src_stream2_packet1);
+       bt_object_put_ref(src_stream2_packet2);
 }
 
 static
@@ -410,54 +374,52 @@ void src_iter_next_seq_one(struct src_iter_user_data *user_data,
        struct bt_packet *event_packet = NULL;
 
        switch (user_data->seq[user_data->at]) {
-       case SEQ_INACTIVITY:
-               *notif = bt_notification_inactivity_create(graph,
-                               src_empty_cc_prio_map);
-               break;
        case SEQ_STREAM1_BEGIN:
-               *notif = bt_notification_stream_begin_create(graph,
+               *notif = bt_notification_stream_begin_create(cur_notif_iter,
                        src_stream1);
                break;
        case SEQ_STREAM2_BEGIN:
-               *notif = bt_notification_stream_begin_create(graph,
+               *notif = bt_notification_stream_begin_create(cur_notif_iter,
                        src_stream2);
                break;
        case SEQ_STREAM1_END:
-               *notif = bt_notification_stream_end_create(graph, src_stream1);
+               *notif = bt_notification_stream_end_create(cur_notif_iter,
+                       src_stream1);
                break;
        case SEQ_STREAM2_END:
-               *notif = bt_notification_stream_end_create(graph, src_stream2);
+               *notif = bt_notification_stream_end_create(cur_notif_iter,
+                       src_stream2);
                break;
        case SEQ_STREAM1_PACKET1_BEGIN:
-               *notif = bt_notification_packet_begin_create(graph,
+               *notif = bt_notification_packet_begin_create(cur_notif_iter,
                        src_stream1_packet1);
                break;
        case SEQ_STREAM1_PACKET2_BEGIN:
-               *notif = bt_notification_packet_begin_create(graph,
+               *notif = bt_notification_packet_begin_create(cur_notif_iter,
                        src_stream1_packet2);
                break;
        case SEQ_STREAM2_PACKET1_BEGIN:
-               *notif = bt_notification_packet_begin_create(graph,
+               *notif = bt_notification_packet_begin_create(cur_notif_iter,
                        src_stream2_packet1);
                break;
        case SEQ_STREAM2_PACKET2_BEGIN:
-               *notif = bt_notification_packet_begin_create(graph,
+               *notif = bt_notification_packet_begin_create(cur_notif_iter,
                        src_stream2_packet2);
                break;
        case SEQ_STREAM1_PACKET1_END:
-               *notif = bt_notification_packet_end_create(graph,
+               *notif = bt_notification_packet_end_create(cur_notif_iter,
                        src_stream1_packet1);
                break;
        case SEQ_STREAM1_PACKET2_END:
-               *notif = bt_notification_packet_end_create(graph,
+               *notif = bt_notification_packet_end_create(cur_notif_iter,
                        src_stream1_packet2);
                break;
        case SEQ_STREAM2_PACKET1_END:
-               *notif = bt_notification_packet_end_create(graph,
+               *notif = bt_notification_packet_end_create(cur_notif_iter,
                        src_stream2_packet1);
                break;
        case SEQ_STREAM2_PACKET2_END:
-               *notif = bt_notification_packet_end_create(graph,
+               *notif = bt_notification_packet_end_create(cur_notif_iter,
                        src_stream2_packet2);
                break;
        case SEQ_EVENT_STREAM1_PACKET1:
@@ -477,8 +439,8 @@ void src_iter_next_seq_one(struct src_iter_user_data *user_data,
        }
 
        if (event_packet) {
-               *notif = bt_notification_event_create(graph, src_event_class,
-                       event_packet, src_empty_cc_prio_map);
+               *notif = bt_notification_event_create(cur_notif_iter,
+                       src_event_class, event_packet);
        }
 
        BT_ASSERT(*notif);
@@ -524,6 +486,7 @@ enum bt_notification_iterator_status src_iter_next(
                bt_private_connection_private_notification_iterator_get_user_data(priv_iterator);
 
        BT_ASSERT(user_data);
+       cur_notif_iter = priv_iterator;
        return src_iter_next_seq(user_data, notifs, capacity, count);
 }
 
@@ -562,9 +525,6 @@ void append_test_events_from_notification(struct bt_notification *notification)
                BT_ASSERT(test_event.packet);
                break;
        }
-       case BT_NOTIFICATION_TYPE_INACTIVITY:
-               test_event.type = TEST_EV_TYPE_NOTIF_INACTIVITY;
-               break;
        case BT_NOTIFICATION_TYPE_STREAM_BEGIN:
                test_event.type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN;
                test_event.stream =
@@ -643,7 +603,7 @@ enum bt_notification_iterator_status common_consume(
 
        for (i = 0; i < count; i++) {
                append_test_events_from_notification(notifications[i]);
-               bt_put(notifications[i]);
+               bt_object_put_ref(notifications[i]);
        }
 
 end:
@@ -670,7 +630,7 @@ enum bt_component_status sink_consume(
        switch (it_ret) {
        case BT_NOTIFICATION_ITERATOR_STATUS_END:
                ret = BT_COMPONENT_STATUS_END;
-               BT_PUT(user_data->notif_iter);
+               BT_OBJECT_PUT_REF_AND_RESET(user_data->notif_iter);
                goto end;
        case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN:
                abort();
@@ -683,7 +643,8 @@ end:
 }
 
 static
-void sink_port_connected(struct bt_private_component *private_component,
+enum bt_component_status sink_port_connected(
+               struct bt_private_component *private_component,
                struct bt_private_port *self_private_port,
                struct bt_port *other_port)
 {
@@ -698,7 +659,8 @@ void sink_port_connected(struct bt_private_component *private_component,
        conn_status = bt_private_connection_create_notification_iterator(
                priv_conn, &user_data->notif_iter);
        BT_ASSERT(conn_status == 0);
-       bt_put(priv_conn);
+       bt_object_put_ref(priv_conn);
+       return BT_COMPONENT_STATUS_OK;
 }
 
 static
@@ -726,7 +688,7 @@ void sink_finalize(struct bt_private_component *private_component)
                private_component);
 
        if (user_data) {
-               bt_put(user_data->notif_iter);
+               bt_object_put_ref(user_data->notif_iter);
                g_free(user_data);
        }
 }
@@ -759,7 +721,7 @@ void create_source_sink(struct bt_graph *graph, struct bt_component **source,
                ret = bt_graph_add_component(graph, src_comp_class, "source",
                        NULL, source);
                BT_ASSERT(ret == 0);
-               bt_put(src_comp_class);
+               bt_object_put_ref(src_comp_class);
        }
 
        /* Create sink component */
@@ -778,7 +740,7 @@ void create_source_sink(struct bt_graph *graph, struct bt_component **source,
                ret = bt_graph_add_component(graph, sink_comp_class, "sink",
                        NULL, sink);
                BT_ASSERT(ret == 0);
-               bt_put(sink_comp_class);
+               bt_object_put_ref(sink_comp_class);
        }
 }
 
@@ -807,8 +769,8 @@ void do_std_test(enum test test, const char *name,
        BT_ASSERT(downstream_port);
        graph_status = bt_graph_connect_ports(graph, upstream_port,
                downstream_port, NULL);
-       bt_put(upstream_port);
-       bt_put(downstream_port);
+       bt_object_put_ref(upstream_port);
+       bt_object_put_ref(downstream_port);
 
        /* Run the graph until the end */
        while (graph_status == BT_GRAPH_STATUS_OK ||
@@ -824,9 +786,9 @@ void do_std_test(enum test test, const char *name,
                        "the produced sequence of test events is the expected one");
        }
 
-       bt_put(src_comp);
-       bt_put(sink_comp);
-       BT_PUT(graph);
+       bt_object_put_ref(src_comp);
+       bt_object_put_ref(sink_comp);
+       BT_OBJECT_PUT_REF_AND_RESET(graph);
 }
 
 static
@@ -899,7 +861,7 @@ void test_output_port_notification_iterator(void)
        notif_iter = bt_output_port_notification_iterator_create(upstream_port,
                NULL);
        ok(notif_iter, "bt_output_port_notification_iterator_create() succeeds");
-       bt_put(upstream_port);
+       bt_object_put_ref(upstream_port);
 
        /* Consume the notification iterator */
        while (iter_status == BT_NOTIFICATION_ITERATOR_STATUS_OK) {
@@ -913,9 +875,9 @@ void test_output_port_notification_iterator(void)
        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);
+       bt_object_put_ref(src_comp);
+       BT_OBJECT_PUT_REF_AND_RESET(graph);
+       bt_object_put_ref(notif_iter);
 }
 
 #define DEBUG_ENV_VAR  "TEST_BT_NOTIFICATION_ITERATOR_DEBUG"
This page took 0.031656 seconds and 5 git commands to generate.