+static void test_action_list()
+{
+ int ret, action_idx;
+ struct lttng_action *list_action = nullptr, *list_action_from_buffer = nullptr,
+ *stop_session_action = nullptr, *notify_action = nullptr,
+ *start_session_action = nullptr;
+ struct lttng_payload payload;
+
+ lttng_payload_init(&payload);
+
+ list_action = lttng_action_list_create();
+ ok(list_action, "Create list action");
+ ok(lttng_action_get_type(list_action) == LTTNG_ACTION_TYPE_LIST,
+ "Action has type LTTNG_ACTION_TYPE_LIST");
+
+ start_session_action = lttng_action_start_session_create();
+ (void) lttng_action_start_session_set_session_name(start_session_action, "une-session");
+
+ stop_session_action = lttng_action_stop_session_create();
+ (void) lttng_action_stop_session_set_session_name(stop_session_action, "une-autre-session");
+ notify_action = lttng_action_notify_create();
+
+ lttng_action_list_add_action(list_action, start_session_action);
+ lttng_action_list_add_action(list_action, stop_session_action);
+ lttng_action_list_add_action(list_action, notify_action);
+
+ ret = lttng_action_serialize(list_action, &payload);
+ ok(ret == 0, "Action list serialized");
+
+ {
+ struct lttng_payload_view view = lttng_payload_view_from_payload(&payload, 0, -1);
+ (void) lttng_action_create_from_payload(&view, &list_action_from_buffer);
+ }
+ ok(list_action_from_buffer, "Notify action created from payload is non-null");
+
+ ok(lttng_action_is_equal(list_action, list_action_from_buffer),
+ "Serialized and de-serialized list action are equal");
+
+ action_idx = 0;
+ for (auto action : lttng::ctl::const_action_list_view(list_action)) {
+ const lttng_action_type inner_action_type = lttng_action_get_type(action);
+ switch (action_idx) {
+ case 0:
+ ok(inner_action_type == LTTNG_ACTION_TYPE_START_SESSION,
+ "First inner action of action list is `start-session` action");
+ break;
+ case 1:
+ ok(inner_action_type == LTTNG_ACTION_TYPE_STOP_SESSION,
+ "Second inner action of action list is `stop-session` action");
+ break;
+ case 2:
+ ok(inner_action_type == LTTNG_ACTION_TYPE_NOTIFY,
+ "Third inner action of action list is `notify` action");
+ break;
+ }
+ action_idx++;
+ }
+
+ action_idx = 0;
+ for (auto action : lttng::ctl::action_list_view(list_action)) {
+ const lttng_action_type inner_action_type = lttng_action_get_type(action);
+ switch (action_idx) {
+ case 0:
+ ok(inner_action_type == LTTNG_ACTION_TYPE_START_SESSION,
+ "First inner action of action list is `start-session` action");
+ break;
+ case 1:
+ ok(inner_action_type == LTTNG_ACTION_TYPE_STOP_SESSION,
+ "Second inner action of action list is `stop-session` action");
+ break;
+ case 2:
+ ok(inner_action_type == LTTNG_ACTION_TYPE_NOTIFY,
+ "Third inner action of action list is `notify` action");
+ break;
+ }
+ action_idx++;
+ }
+
+ lttng_action_destroy(list_action);
+ lttng_action_destroy(list_action_from_buffer);
+ lttng_action_destroy(start_session_action);
+ lttng_action_destroy(stop_session_action);
+ lttng_action_destroy(notify_action);
+ lttng_payload_reset(&payload);
+}
+