diff --git a/.vscode/launch.json b/.vscode/launch.json index 22b7f1f8d..244e01430 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -137,7 +137,7 @@ "request": "launch", "program": "${workspaceFolder}/out/linux/x64/tests/standalone/ten_runtime_smoke_test", "args": [ - "--gtest_filter=ExtensionTest.GraphPolygonInOneAppReturnAll" + "--gtest_filter=AudioFrameTest.FromJson" ], "cwd": "${workspaceFolder}/out/linux/x64/tests/standalone/", "env": { diff --git a/core/include/ten_runtime/binding/cpp/internal/msg/cmd_result.h b/core/include/ten_runtime/binding/cpp/internal/msg/cmd_result.h index edab0c4ce..02ee4a818 100644 --- a/core/include/ten_runtime/binding/cpp/internal/msg/cmd_result.h +++ b/core/include/ten_runtime/binding/cpp/internal/msg/cmd_result.h @@ -19,6 +19,7 @@ namespace ten { class extension_t; class ten_env_tester_t; +class cmd_result_internal_accessor_t; class cmd_result_t : public msg_t { private: @@ -74,6 +75,7 @@ class cmd_result_t : public msg_t { friend extension_t; friend ten_env_tester_t; friend ten_env_t; + friend cmd_result_internal_accessor_t; static std::unique_ptr create(ten_shared_ptr_t *cmd, error_t *err = nullptr) { diff --git a/core/include_internal/ten_runtime/binding/cpp/internal/msg/cmd/cmd_result_internal_accessor.h b/core/include_internal/ten_runtime/binding/cpp/internal/msg/cmd/cmd_result_internal_accessor.h new file mode 100644 index 000000000..49aac9959 --- /dev/null +++ b/core/include_internal/ten_runtime/binding/cpp/internal/msg/cmd/cmd_result_internal_accessor.h @@ -0,0 +1,34 @@ +// +// Copyright © 2024 Agora +// This file is part of TEN Framework, an open source project. +// Licensed under the Apache License, Version 2.0, with certain conditions. +// Refer to the "LICENSE" file in the root directory for more information. +// +#pragma once + +#include "ten_runtime/binding/cpp/internal/msg/cmd_result.h" + +namespace ten { + +class cmd_result_internal_accessor_t { + public: + explicit cmd_result_internal_accessor_t() = default; + ~cmd_result_internal_accessor_t() = default; + + // @{ + cmd_result_internal_accessor_t(const cmd_result_internal_accessor_t &) = + delete; + cmd_result_internal_accessor_t(cmd_result_internal_accessor_t &&) = delete; + cmd_result_internal_accessor_t &operator=( + const cmd_result_internal_accessor_t &) = delete; + cmd_result_internal_accessor_t &operator=(cmd_result_internal_accessor_t &&) = + delete; + // @} + + static std::unique_ptr create(ten_shared_ptr_t *cmd, + error_t *err = nullptr) { + return ten::cmd_result_t::create(cmd, err); + } +}; + +} // namespace ten diff --git a/core/include_internal/ten_runtime/common/loc.h b/core/include_internal/ten_runtime/common/loc.h index f2ea25e96..688c8e46c 100644 --- a/core/include_internal/ten_runtime/common/loc.h +++ b/core/include_internal/ten_runtime/common/loc.h @@ -75,9 +75,6 @@ TEN_RUNTIME_PRIVATE_API void ten_loc_init_from_loc(ten_loc_t *self, TEN_RUNTIME_PRIVATE_API void ten_loc_init_from_value(ten_loc_t *self, ten_value_t *value); -TEN_RUNTIME_PRIVATE_API void ten_loc_init_from_json(ten_loc_t *self, - ten_json_t *json); - TEN_RUNTIME_PRIVATE_API void ten_loc_deinit(ten_loc_t *self); TEN_RUNTIME_PRIVATE_API void ten_loc_set(ten_loc_t *self, const char *app_uri, diff --git a/core/include_internal/ten_runtime/msg/audio_frame/audio_frame.h b/core/include_internal/ten_runtime/msg/audio_frame/audio_frame.h index e14e8c37a..dbf8b6e6d 100644 --- a/core/include_internal/ten_runtime/msg/audio_frame/audio_frame.h +++ b/core/include_internal/ten_runtime/msg/audio_frame/audio_frame.h @@ -63,13 +63,6 @@ TEN_RUNTIME_PRIVATE_API void ten_raw_audio_frame_destroy( TEN_RUNTIME_PRIVATE_API ten_msg_t *ten_raw_audio_frame_as_msg_clone( ten_msg_t *self, ten_list_t *excluded_field_ids); -TEN_RUNTIME_PRIVATE_API ten_json_t *ten_raw_audio_frame_as_msg_to_json( - ten_msg_t *self, ten_error_t *err); - -TEN_RUNTIME_PRIVATE_API bool ten_raw_audio_frame_check_type_and_name( - ten_msg_t *self, const char *type_str, const char *name_str, - ten_error_t *err); - TEN_RUNTIME_PRIVATE_API int32_t ten_raw_audio_frame_get_samples_per_channel(ten_audio_frame_t *self); @@ -127,9 +120,6 @@ TEN_RUNTIME_PRIVATE_API bool ten_raw_audio_frame_set_data_fmt( TEN_RUNTIME_PRIVATE_API bool ten_raw_audio_frame_set_timestamp( ten_audio_frame_t *self, int64_t timestamp); -TEN_RUNTIME_PRIVATE_API bool ten_raw_audio_frame_as_msg_init_from_json( - ten_msg_t *self, ten_json_t *json, ten_error_t *err); - TEN_RUNTIME_PRIVATE_API ten_value_t *ten_raw_audio_frame_peek_ten_property( ten_msg_t *self, ten_list_t *paths, ten_error_t *err); diff --git a/core/include_internal/ten_runtime/msg/cmd_base/cmd/close_app/cmd.h b/core/include_internal/ten_runtime/msg/cmd_base/cmd/close_app/cmd.h index 5fb4efc2f..6e140e410 100644 --- a/core/include_internal/ten_runtime/msg/cmd_base/cmd/close_app/cmd.h +++ b/core/include_internal/ten_runtime/msg/cmd_base/cmd/close_app/cmd.h @@ -14,9 +14,6 @@ typedef struct ten_cmd_close_app_t { ten_cmd_t cmd_hdr; } ten_cmd_close_app_t; -TEN_RUNTIME_PRIVATE_API bool ten_raw_cmd_close_app_as_msg_init_from_json( - ten_msg_t *self, ten_json_t *json, ten_error_t *err); - TEN_RUNTIME_PRIVATE_API void ten_raw_cmd_close_app_as_msg_destroy( ten_msg_t *self); diff --git a/core/include_internal/ten_runtime/msg/cmd_base/cmd/custom/cmd.h b/core/include_internal/ten_runtime/msg/cmd_base/cmd/custom/cmd.h index 6683e1884..c4c042b97 100644 --- a/core/include_internal/ten_runtime/msg/cmd_base/cmd/custom/cmd.h +++ b/core/include_internal/ten_runtime/msg/cmd_base/cmd/custom/cmd.h @@ -21,13 +21,6 @@ typedef struct ten_cmd_t ten_cmd_t; TEN_RUNTIME_PRIVATE_API bool ten_raw_cmd_custom_set_ten_property( ten_msg_t *self, ten_list_t *paths, ten_value_t *value, ten_error_t *err); -TEN_RUNTIME_PRIVATE_API bool ten_raw_cmd_custom_check_type_and_name( - ten_msg_t *self, const char *type_str, const char *name_str, - ten_error_t *err); - -TEN_RUNTIME_PRIVATE_API bool ten_raw_cmd_custom_as_msg_init_from_json( - ten_msg_t *self, ten_json_t *json, ten_error_t *err); - TEN_RUNTIME_PRIVATE_API void ten_raw_cmd_custom_as_msg_destroy(ten_msg_t *self); TEN_RUNTIME_PRIVATE_API ten_msg_t *ten_raw_cmd_custom_as_msg_clone( diff --git a/core/include_internal/ten_runtime/msg/cmd_base/cmd/start_graph/cmd.h b/core/include_internal/ten_runtime/msg/cmd_base/cmd/start_graph/cmd.h index 7cf2f67e3..3573fbfcd 100644 --- a/core/include_internal/ten_runtime/msg/cmd_base/cmd/start_graph/cmd.h +++ b/core/include_internal/ten_runtime/msg/cmd_base/cmd/start_graph/cmd.h @@ -68,9 +68,6 @@ ten_cmd_start_graph_get_requested_extension_names(ten_shared_ptr_t *self); TEN_RUNTIME_PRIVATE_API void ten_cmd_start_graph_fill_loc_info( ten_shared_ptr_t *self, const char *app_uri, const char *graph_id); -TEN_RUNTIME_PRIVATE_API bool ten_raw_cmd_start_graph_as_msg_init_from_json( - ten_msg_t *self, ten_json_t *json, ten_error_t *err); - TEN_RUNTIME_PRIVATE_API bool ten_raw_cmd_start_graph_init_from_json( ten_cmd_start_graph_t *self, ten_json_t *json, ten_error_t *err); diff --git a/core/include_internal/ten_runtime/msg/cmd_base/cmd/stop_graph/cmd.h b/core/include_internal/ten_runtime/msg/cmd_base/cmd/stop_graph/cmd.h index 15142c609..ba5b96c5a 100644 --- a/core/include_internal/ten_runtime/msg/cmd_base/cmd/stop_graph/cmd.h +++ b/core/include_internal/ten_runtime/msg/cmd_base/cmd/stop_graph/cmd.h @@ -24,9 +24,6 @@ TEN_RUNTIME_PRIVATE_API ten_string_t *ten_cmd_stop_graph_get_graph_id( TEN_RUNTIME_PRIVATE_API void ten_raw_cmd_stop_graph_as_msg_destroy( ten_msg_t *self); -TEN_RUNTIME_PRIVATE_API bool ten_raw_cmd_stop_graph_as_msg_init_from_json( - ten_msg_t *self, ten_json_t *json, ten_error_t *err); - TEN_RUNTIME_PRIVATE_API ten_cmd_stop_graph_t *ten_raw_cmd_stop_graph_create( void); diff --git a/core/include_internal/ten_runtime/msg/cmd_base/cmd/timeout/cmd.h b/core/include_internal/ten_runtime/msg/cmd_base/cmd/timeout/cmd.h index 2f3f9448f..cc04b13d8 100644 --- a/core/include_internal/ten_runtime/msg/cmd_base/cmd/timeout/cmd.h +++ b/core/include_internal/ten_runtime/msg/cmd_base/cmd/timeout/cmd.h @@ -19,9 +19,6 @@ typedef struct ten_cmd_timeout_t { TEN_RUNTIME_PRIVATE_API void ten_cmd_timeout_set_timer_id( ten_shared_ptr_t *self, uint32_t timer_id); -TEN_RUNTIME_PRIVATE_API bool ten_raw_cmd_timeout_as_msg_init_from_json( - ten_msg_t *self, ten_json_t *json, ten_error_t *err); - TEN_RUNTIME_PRIVATE_API ten_shared_ptr_t *ten_cmd_timeout_create( uint32_t timer_id); @@ -34,9 +31,6 @@ TEN_RUNTIME_PRIVATE_API void ten_raw_cmd_timeout_set_timer_id( TEN_RUNTIME_PRIVATE_API uint32_t ten_raw_cmd_timeout_get_timer_id(ten_cmd_timeout_t *self); -TEN_RUNTIME_PRIVATE_API ten_json_t *ten_raw_cmd_timeout_as_msg_to_json( - ten_msg_t *self, ten_error_t *err); - TEN_RUNTIME_API uint32_t ten_cmd_timeout_get_timer_id(ten_shared_ptr_t *self); TEN_RUNTIME_PRIVATE_API bool ten_raw_cmd_timeout_loop_all_fields( diff --git a/core/include_internal/ten_runtime/msg/cmd_base/cmd/timer/cmd.h b/core/include_internal/ten_runtime/msg/cmd_base/cmd/timer/cmd.h index 21f3619d1..4d8158154 100644 --- a/core/include_internal/ten_runtime/msg/cmd_base/cmd/timer/cmd.h +++ b/core/include_internal/ten_runtime/msg/cmd_base/cmd/timer/cmd.h @@ -31,10 +31,6 @@ typedef struct ten_cmd_timer_t { TEN_RUNTIME_PRIVATE_API bool ten_raw_cmd_timer_set_ten_property( ten_msg_t *self, ten_list_t *paths, ten_value_t *value, ten_error_t *err); -TEN_RUNTIME_PRIVATE_API bool ten_raw_cmd_timer_check_type_and_name( - ten_msg_t *self, const char *type_str, const char *name_str, - ten_error_t *err); - TEN_RUNTIME_PRIVATE_API bool ten_raw_cmd_timer_set_timer_id( ten_cmd_timer_t *self, uint32_t timer_id); @@ -67,14 +63,8 @@ TEN_RUNTIME_PRIVATE_API int32_t ten_cmd_timer_get_times(ten_shared_ptr_t *self); TEN_RUNTIME_API bool ten_cmd_timer_set_times(ten_shared_ptr_t *self, int32_t times); -TEN_RUNTIME_PRIVATE_API bool ten_raw_cmd_timer_as_msg_init_from_json( - ten_msg_t *self, ten_json_t *json, ten_error_t *err); - TEN_RUNTIME_PRIVATE_API void ten_raw_cmd_timer_as_msg_destroy(ten_msg_t *self); -TEN_RUNTIME_PRIVATE_API ten_json_t *ten_raw_cmd_timer_as_msg_to_json( - ten_msg_t *self, ten_error_t *err); - TEN_RUNTIME_PRIVATE_API ten_cmd_timer_t *ten_raw_cmd_timer_create(void); TEN_RUNTIME_API ten_shared_ptr_t *ten_cmd_timer_create(void); diff --git a/core/include_internal/ten_runtime/msg/cmd_base/cmd_base.h b/core/include_internal/ten_runtime/msg/cmd_base/cmd_base.h index d73c3eb47..0730fbc7f 100644 --- a/core/include_internal/ten_runtime/msg/cmd_base/cmd_base.h +++ b/core/include_internal/ten_runtime/msg/cmd_base/cmd_base.h @@ -99,12 +99,6 @@ TEN_RUNTIME_PRIVATE_API void ten_raw_cmd_base_save_cmd_id_to_parent_cmd_id( TEN_RUNTIME_PRIVATE_API void ten_raw_cmd_base_set_seq_id(ten_cmd_base_t *self, const char *seq_id); -TEN_RUNTIME_PRIVATE_API bool ten_raw_cmd_base_get_field_from_json( - ten_msg_t *self, ten_json_t *json, ten_error_t *err); - -TEN_RUNTIME_PRIVATE_API bool ten_raw_cmd_base_put_field_to_json( - ten_msg_t *self, ten_json_t *json, ten_error_t *err); - TEN_RUNTIME_PRIVATE_API bool ten_cmd_base_cmd_id_is_empty( ten_shared_ptr_t *self); diff --git a/core/include_internal/ten_runtime/msg/cmd_base/cmd_result/cmd.h b/core/include_internal/ten_runtime/msg/cmd_base/cmd_result/cmd.h index a709a0116..bc3ee92a7 100644 --- a/core/include_internal/ten_runtime/msg/cmd_base/cmd_result/cmd.h +++ b/core/include_internal/ten_runtime/msg/cmd_base/cmd_result/cmd.h @@ -81,15 +81,9 @@ TEN_RUNTIME_PRIVATE_API void ten_cmd_result_set_original_cmd_type( TEN_RUNTIME_PRIVATE_API TEN_MSG_TYPE ten_cmd_result_get_original_cmd_type(ten_shared_ptr_t *self); -TEN_RUNTIME_PRIVATE_API bool ten_raw_cmd_result_as_msg_init_from_json( - ten_msg_t *self, ten_json_t *json, ten_error_t *err); - TEN_RUNTIME_PRIVATE_API ten_msg_t *ten_raw_cmd_result_as_msg_clone( ten_msg_t *self, TEN_UNUSED ten_list_t *excluded_field_ids); -TEN_RUNTIME_PRIVATE_API ten_json_t *ten_raw_cmd_result_as_msg_to_json( - ten_msg_t *self, ten_error_t *err); - TEN_RUNTIME_PRIVATE_API void ten_raw_cmd_result_destroy(ten_cmd_result_t *self); TEN_RUNTIME_PRIVATE_API TEN_STATUS_CODE diff --git a/core/include_internal/ten_runtime/msg/data/data.h b/core/include_internal/ten_runtime/msg/data/data.h index 3dc19b491..42ca0e026 100644 --- a/core/include_internal/ten_runtime/msg/data/data.h +++ b/core/include_internal/ten_runtime/msg/data/data.h @@ -35,18 +35,8 @@ TEN_RUNTIME_PRIVATE_API void ten_raw_data_buf_copy( TEN_RUNTIME_PRIVATE_API ten_msg_t *ten_raw_data_as_msg_clone( ten_msg_t *self, ten_list_t *excluded_field_ids); -TEN_RUNTIME_PRIVATE_API bool ten_raw_data_as_msg_init_from_json( - ten_msg_t *self, ten_json_t *json, ten_error_t *err); - -TEN_RUNTIME_PRIVATE_API ten_json_t *ten_raw_data_as_msg_to_json( - ten_msg_t *self, ten_error_t *err); - TEN_RUNTIME_PRIVATE_API bool ten_raw_data_loop_all_fields( ten_msg_t *self, ten_raw_msg_process_one_field_func_t cb, void *user_data, ten_error_t *err); TEN_RUNTIME_PRIVATE_API void ten_raw_data_destroy(ten_data_t *self); - -TEN_RUNTIME_PRIVATE_API bool ten_raw_data_check_type_and_name( - ten_msg_t *self, const char *type_str, const char *name_str, - ten_error_t *err); diff --git a/core/include_internal/ten_runtime/msg/msg.h b/core/include_internal/ten_runtime/msg/msg.h index 70b3eb61e..572c17770 100644 --- a/core/include_internal/ten_runtime/msg/msg.h +++ b/core/include_internal/ten_runtime/msg/msg.h @@ -268,10 +268,18 @@ TEN_RUNTIME_PRIVATE_API bool ten_raw_msg_get_one_field_from_json( ten_msg_t *self, ten_msg_field_process_data_t *field, void *user_data, ten_error_t *err); +TEN_RUNTIME_PRIVATE_API bool +ten_raw_msg_get_one_field_from_json_include_internal_field( + ten_msg_t *self, ten_msg_field_process_data_t *field, void *user_data, + ten_error_t *err); + TEN_RUNTIME_PRIVATE_API bool ten_raw_msg_put_one_field_to_json( ten_msg_t *self, ten_msg_field_process_data_t *field, void *user_data, ten_error_t *err); +TEN_RUNTIME_PRIVATE_API ten_json_t *ten_msg_to_json_include_internal_field( + ten_shared_ptr_t *self, ten_error_t *err); + TEN_RUNTIME_PRIVATE_API bool ten_raw_msg_process_field( ten_msg_t *self, ten_raw_msg_process_one_field_func_t cb, void *user_data, ten_error_t *err); diff --git a/core/include_internal/ten_runtime/msg/msg_info.h b/core/include_internal/ten_runtime/msg/msg_info.h index ba5a86a5f..0a254b7ea 100644 --- a/core/include_internal/ten_runtime/msg/msg_info.h +++ b/core/include_internal/ten_runtime/msg/msg_info.h @@ -30,13 +30,6 @@ typedef void (*ten_msg_engine_handler_func_t)(ten_engine_t *engine, ten_shared_ptr_t *msg, ten_error_t *err); -typedef bool (*ten_raw_msg_init_from_json_func_t)(ten_msg_t *msg, - ten_json_t *json, - ten_error_t *err); - -typedef ten_json_t *(*ten_raw_msg_to_json_func_t)(ten_msg_t *msg, - ten_error_t *err); - typedef ten_msg_t *(*ten_raw_msg_clone_func_t)(ten_msg_t *msg, ten_list_t *excluded_field_ids); @@ -59,11 +52,6 @@ typedef ten_value_t *(*ten_raw_msg_peek_ten_property_func_t)(ten_msg_t *msg, ten_list_t *paths, ten_error_t *err); -typedef bool (*ten_raw_msg_check_type_and_name_func_t)(ten_msg_t *self, - const char *type_str, - const char *name_str, - ten_error_t *err); - typedef struct ten_msg_info_t { const char *msg_type_name; const char *msg_unique_name; @@ -72,29 +60,23 @@ typedef struct ten_msg_info_t { ten_msg_engine_handler_func_t engine_handler; ten_raw_msg_clone_func_t clone; - ten_raw_msg_init_from_json_func_t init_from_json; - ten_raw_msg_to_json_func_t to_json; ten_raw_msg_loop_all_fields_func_t loop_all_fields; ten_raw_msg_validate_schema_func_t validate_schema; ten_raw_msg_set_ten_property_func_t set_ten_property; ten_raw_msg_peek_ten_property_func_t peek_ten_property; - ten_raw_msg_check_type_and_name_func_t check_type_and_name; } ten_msg_info_t; -#define TEN_MSG_INFO_INIT_VALUES \ - { \ - NULL, /* msg_type_name */ \ - NULL, /* unique_name */ \ - false, /* create_in_path */ \ - NULL, /* engine_handler */ \ - NULL, /* clone */ \ - NULL, /* init_from_json */ \ - NULL, /* to_json */ \ - NULL, /* loop_all_fields */ \ - NULL, /* validate_schema */ \ - NULL, /* set_ten_property */ \ - NULL, /* peek_ten_property */ \ - NULL, /* check_type_and_name */ \ +#define TEN_MSG_INFO_INIT_VALUES \ + { \ + NULL, /* msg_type_name */ \ + NULL, /* unique_name */ \ + false, /* create_in_path */ \ + NULL, /* engine_handler */ \ + NULL, /* clone */ \ + NULL, /* loop_all_fields */ \ + NULL, /* validate_schema */ \ + NULL, /* set_ten_property */ \ + NULL, /* peek_ten_property */ \ } TEN_UNUSED static const ten_msg_info_t ten_msg_info[] = { @@ -111,104 +93,83 @@ TEN_UNUSED static const ten_msg_info_t ten_msg_info[] = { // The engine does not need to handle general cmd. NULL, /* engine_handler */ - ten_raw_cmd_custom_as_msg_clone, /* clone */ - ten_raw_cmd_custom_as_msg_init_from_json, /* init_from_json */ - ten_raw_cmd_custom_to_json, /* to_json*/ - ten_raw_cmd_custom_loop_all_fields, /* loop_all_fields */ - ten_raw_msg_validate_schema, /* validate_schema */ - ten_raw_cmd_custom_set_ten_property, /* set_ten_property */ - NULL, /* peek_ten_property */ - ten_raw_cmd_custom_check_type_and_name, /* check_type_and_name */ + ten_raw_cmd_custom_as_msg_clone, /* clone */ + ten_raw_cmd_custom_loop_all_fields, /* loop_all_fields */ + ten_raw_msg_validate_schema, /* validate_schema */ + ten_raw_cmd_custom_set_ten_property, /* set_ten_property */ + NULL, /* peek_ten_property */ }, [TEN_MSG_TYPE_CMD_STOP_GRAPH] = { - TEN_STR_STOP_GRAPH, /* msg_type_name */ - TEN_STR_MSG_NAME_TEN_STOP_GRAPH, /* msg_unique_name */ - false, /* create_in_path */ - ten_engine_handle_cmd_stop_graph, /* engine_handler */ - NULL, /* clone */ - ten_raw_cmd_stop_graph_as_msg_init_from_json, /* init_from_json */ - ten_raw_cmd_stop_graph_to_json, /* to_json */ - ten_raw_cmd_stop_graph_loop_all_fields, /* loop_all_fields */ - NULL, /* validate_schema */ - NULL, /* set_ten_property */ - NULL, /* peek_ten_property */ - NULL, /* check_type_and_name */ + TEN_STR_STOP_GRAPH, /* msg_type_name */ + TEN_STR_MSG_NAME_TEN_STOP_GRAPH, /* msg_unique_name */ + false, /* create_in_path */ + ten_engine_handle_cmd_stop_graph, /* engine_handler */ + NULL, /* clone */ + ten_raw_cmd_stop_graph_loop_all_fields, /* loop_all_fields */ + NULL, /* validate_schema */ + NULL, /* set_ten_property */ + NULL, /* peek_ten_property */ }, [TEN_MSG_TYPE_CMD_START_GRAPH] = { - TEN_STR_START_GRAPH, /* msg_type_name */ - TEN_STR_MSG_NAME_TEN_START_GRAPH, /* msg_unique_name */ - true, /* create_in_path */ - ten_engine_handle_cmd_start_graph, /* engine_handler */ - ten_raw_cmd_start_graph_as_msg_clone, /* clone */ - ten_raw_cmd_start_graph_as_msg_init_from_json, /* init_from_json */ - ten_raw_cmd_start_graph_to_json, /* to_json */ - ten_raw_cmd_start_graph_loop_all_fields, /* loop_all_fields */ - NULL, /* validate_schema */ - NULL, /* set_ten_property */ - NULL, /* peek_ten_property */ - NULL, /* check_type_and_name */ + TEN_STR_START_GRAPH, /* msg_type_name */ + TEN_STR_MSG_NAME_TEN_START_GRAPH, /* msg_unique_name */ + true, /* create_in_path */ + ten_engine_handle_cmd_start_graph, /* engine_handler */ + ten_raw_cmd_start_graph_as_msg_clone, /* clone */ + ten_raw_cmd_start_graph_loop_all_fields, /* loop_all_fields */ + NULL, /* validate_schema */ + NULL, /* set_ten_property */ + NULL, /* peek_ten_property */ }, [TEN_MSG_TYPE_CMD_RESULT] = { - TEN_STR_RESULT, /* msg_type_name */ - TEN_STR_MSG_NAME_TEN_RESULT, /* msg_unique_name */ - false, /* create_in_path */ - ten_engine_handle_cmd_result, /* engine_handler */ - ten_raw_cmd_result_as_msg_clone, /* clone */ - ten_raw_cmd_result_as_msg_init_from_json, /* init_from_json */ - ten_raw_cmd_result_as_msg_to_json, /* to_json */ - ten_raw_cmd_result_loop_all_fields, /* loop_all_fields */ - ten_raw_cmd_result_validate_schema, /* validate_schema */ - NULL, /* set_ten_property */ - NULL, /* peek_ten_property */ - NULL, /* check_type_and_name */ + TEN_STR_RESULT, /* msg_type_name */ + TEN_STR_MSG_NAME_TEN_RESULT, /* msg_unique_name */ + false, /* create_in_path */ + ten_engine_handle_cmd_result, /* engine_handler */ + ten_raw_cmd_result_as_msg_clone, /* clone */ + ten_raw_cmd_result_loop_all_fields, /* loop_all_fields */ + ten_raw_cmd_result_validate_schema, /* validate_schema */ + NULL, /* set_ten_property */ + NULL, /* peek_ten_property */ }, [TEN_MSG_TYPE_CMD_CLOSE_APP] = { - TEN_STR_CLOSE_APP, /* msg_type_name */ - TEN_STR_MSG_NAME_TEN_CLOSE_APP, /* msg_unique_name */ - false, /* create_in_path */ - ten_engine_handle_cmd_close_app, /* engine_handler */ - NULL, /* clone */ - ten_raw_cmd_close_app_as_msg_init_from_json, /* init_from_json*/ - ten_raw_cmd_close_app_to_json, /* to_json */ - ten_raw_cmd_close_app_loop_all_fields, /* loop_all_fields */ - NULL, /* validate_schema */ - NULL, /* set_ten_property */ - NULL, /* peek_ten_property */ - NULL, /* check_type_and_name */ + TEN_STR_CLOSE_APP, /* msg_type_name */ + TEN_STR_MSG_NAME_TEN_CLOSE_APP, /* msg_unique_name */ + false, /* create_in_path */ + ten_engine_handle_cmd_close_app, /* engine_handler */ + NULL, /* clone */ + ten_raw_cmd_close_app_loop_all_fields, /* loop_all_fields */ + NULL, /* validate_schema */ + NULL, /* set_ten_property */ + NULL, /* peek_ten_property */ }, [TEN_MSG_TYPE_CMD_TIMEOUT] = { - TEN_STR_TIMEOUT, /* msg_type_name */ - TEN_STR_MSG_NAME_TEN_TIMEOUT, /* msg_unique_name */ - false, /* create_in_path */ - NULL, /* engine_handler */ - NULL, /* clone */ - ten_raw_cmd_timeout_as_msg_init_from_json, /* init_from_json */ - ten_raw_cmd_timeout_as_msg_to_json, /* to_json */ - ten_raw_cmd_timeout_loop_all_fields, /* loop_all_fields */ - NULL, /* validate_schema */ - NULL, /* set_ten_property */ - NULL, /* peek_ten_property */ - NULL, /* check_type_and_name */ + TEN_STR_TIMEOUT, /* msg_type_name */ + TEN_STR_MSG_NAME_TEN_TIMEOUT, /* msg_unique_name */ + false, /* create_in_path */ + NULL, /* engine_handler */ + NULL, /* clone */ + ten_raw_cmd_timeout_loop_all_fields, /* loop_all_fields */ + NULL, /* validate_schema */ + NULL, /* set_ten_property */ + NULL, /* peek_ten_property */ }, [TEN_MSG_TYPE_CMD_TIMER] = { - TEN_STR_TIMER, /* msg_type_name */ - TEN_STR_MSG_NAME_TEN_TIMER, /* msg_unique_name */ - true, /* create_in_path */ - ten_engine_handle_cmd_timer, /* engine_handler */ - NULL, /* clone */ - ten_raw_cmd_timer_as_msg_init_from_json, /* init_from_json */ - ten_raw_cmd_timer_as_msg_to_json, /* to_json */ - ten_raw_cmd_timer_loop_all_fields, /* loop_all_fields */ - NULL, /* validate_schema */ - ten_raw_cmd_timer_set_ten_property, /* set_ten_property */ - NULL, /* peek_ten_property */ - ten_raw_cmd_timer_check_type_and_name, /* check_type_and_name */ + TEN_STR_TIMER, /* msg_type_name */ + TEN_STR_MSG_NAME_TEN_TIMER, /* msg_unique_name */ + true, /* create_in_path */ + ten_engine_handle_cmd_timer, /* engine_handler */ + NULL, /* clone */ + ten_raw_cmd_timer_loop_all_fields, /* loop_all_fields */ + NULL, /* validate_schema */ + ten_raw_cmd_timer_set_ten_property, /* set_ten_property */ + NULL, /* peek_ten_property */ }, [TEN_MSG_TYPE_DATA] = { @@ -223,13 +184,10 @@ TEN_UNUSED static const ten_msg_info_t ten_msg_info[] = { NULL, /* engine_handler */ ten_raw_data_as_msg_clone, /* clone */ - ten_raw_data_as_msg_init_from_json, /* init_from_json */ - ten_raw_data_as_msg_to_json, /* to_json */ ten_raw_data_loop_all_fields, /* loop_all_fields */ ten_raw_msg_validate_schema, /* validate_schema */ ten_raw_data_like_set_ten_property, /* set_ten_property */ NULL, /* peek_ten_property */ - ten_raw_data_check_type_and_name, /* check_type_and_name */ }, [TEN_MSG_TYPE_AUDIO_FRAME] = { @@ -243,14 +201,11 @@ TEN_UNUSED static const ten_msg_info_t ten_msg_info[] = { // The engine does not need to handle general audio frame. NULL, /* engine_handler */ - ten_raw_audio_frame_as_msg_clone, /* clone */ - ten_raw_audio_frame_as_msg_init_from_json, /* init_from_json */ - ten_raw_audio_frame_as_msg_to_json, /* to_json */ - ten_raw_audio_frame_loop_all_fields, /* loop_all_fields */ - ten_raw_msg_validate_schema, /* validate_schema */ - ten_raw_data_like_set_ten_property, /* set_ten_property */ - ten_raw_audio_frame_peek_ten_property, /* peek_ten_property */ - ten_raw_audio_frame_check_type_and_name, /* check_type_and_name */ + ten_raw_audio_frame_as_msg_clone, /* clone */ + ten_raw_audio_frame_loop_all_fields, /* loop_all_fields */ + ten_raw_msg_validate_schema, /* validate_schema */ + ten_raw_data_like_set_ten_property, /* set_ten_property */ + ten_raw_audio_frame_peek_ten_property, /* peek_ten_property */ }, [TEN_MSG_TYPE_VIDEO_FRAME] = { @@ -264,14 +219,11 @@ TEN_UNUSED static const ten_msg_info_t ten_msg_info[] = { // The engine does not need to handle general video frame. NULL, /* engine_handler */ - ten_raw_video_frame_as_msg_clone, /* clone */ - ten_raw_video_frame_as_msg_init_from_json, /* init_from_json */ - ten_raw_video_frame_as_msg_to_json, /* to_json */ - ten_raw_video_frame_loop_all_fields, /* loop_all_fields */ - ten_raw_msg_validate_schema, /* validate_schema */ - ten_raw_video_frame_set_ten_property, /* set_ten_property */ - ten_raw_video_frame_peek_ten_property, /* peek_ten_property */ - ten_raw_video_frame_check_type_and_name, /* check_type_and_name */ + ten_raw_video_frame_as_msg_clone, /* clone */ + ten_raw_video_frame_loop_all_fields, /* loop_all_fields */ + ten_raw_msg_validate_schema, /* validate_schema */ + ten_raw_video_frame_set_ten_property, /* set_ten_property */ + ten_raw_video_frame_peek_ten_property, /* peek_ten_property */ }, [TEN_MSG_TYPE_LAST] = TEN_MSG_INFO_INIT_VALUES, }; diff --git a/core/include_internal/ten_runtime/msg/video_frame/video_frame.h b/core/include_internal/ten_runtime/msg/video_frame/video_frame.h index 2ae7b2f23..d485333b8 100644 --- a/core/include_internal/ten_runtime/msg/video_frame/video_frame.h +++ b/core/include_internal/ten_runtime/msg/video_frame/video_frame.h @@ -39,18 +39,11 @@ TEN_RUNTIME_API ten_video_frame_payload_t *ten_raw_video_frame_raw_payload( TEN_RUNTIME_PRIVATE_API ten_msg_t *ten_raw_video_frame_as_msg_clone( ten_msg_t *self, ten_list_t *excluded_field_ids); -TEN_RUNTIME_PRIVATE_API ten_json_t *ten_raw_video_frame_as_msg_to_json( - ten_msg_t *self, ten_error_t *err); - TEN_RUNTIME_PRIVATE_API void ten_raw_video_frame_init(ten_video_frame_t *self); TEN_RUNTIME_PRIVATE_API void ten_raw_video_frame_destroy( ten_video_frame_t *self); -TEN_RUNTIME_PRIVATE_API bool ten_raw_video_frame_check_type_and_name( - ten_msg_t *self, const char *type_str, const char *name_str, - ten_error_t *err); - TEN_RUNTIME_PRIVATE_API TEN_PIXEL_FMT ten_raw_video_frame_get_pixel_fmt(ten_video_frame_t *self); @@ -84,9 +77,6 @@ TEN_RUNTIME_PRIVATE_API bool ten_raw_video_frame_set_timestamp( TEN_RUNTIME_PRIVATE_API bool ten_raw_video_frame_set_eof( ten_video_frame_t *self, bool is_eof); -TEN_RUNTIME_PRIVATE_API bool ten_raw_video_frame_as_msg_init_from_json( - ten_msg_t *self, ten_json_t *json, ten_error_t *err); - TEN_RUNTIME_PRIVATE_API bool ten_raw_video_frame_set_ten_property( ten_msg_t *self, ten_list_t *paths, ten_value_t *value, ten_error_t *err); diff --git a/core/src/ten_runtime/app/graph.c b/core/src/ten_runtime/app/graph.c index 2f30137b5..26a3aa011 100644 --- a/core/src/ten_runtime/app/graph.c +++ b/core/src/ten_runtime/app/graph.c @@ -8,6 +8,7 @@ #include "include_internal/ten_runtime/app/app.h" #include "include_internal/ten_runtime/app/base_dir.h" +#include "include_internal/ten_runtime/msg/msg.h" #include "ten_runtime/app/app.h" #include "ten_utils/lib/json.h" #include "ten_utils/lib/smart_ptr.h" @@ -38,7 +39,8 @@ bool ten_app_check_start_graph_cmd(ten_app_t *self, return true; } - ten_json_t *start_graph_cmd_json = ten_msg_to_json(start_graph_cmd, err); + ten_json_t *start_graph_cmd_json = + ten_msg_to_json_include_internal_field(start_graph_cmd, err); if (!start_graph_cmd_json) { TEN_ASSERT(0, "Failed to convert start graph cmd to json, should not happen."); diff --git a/core/src/ten_runtime/binding/python/interface/ten/async_ten_env.py b/core/src/ten_runtime/binding/python/interface/ten/async_ten_env.py index 0a6083c64..906262d36 100644 --- a/core/src/ten_runtime/binding/python/interface/ten/async_ten_env.py +++ b/core/src/ten_runtime/binding/python/interface/ten/async_ten_env.py @@ -57,42 +57,42 @@ async def send_cmd_ex(self, cmd: Cmd) -> AsyncGenerator[CmdResult, None]: break yield result - def _deinit_routine(self) -> None: - # Wait for the internal thread to finish. - self._ten_thread.join() - - self._internal.on_deinit_done() - - def _on_release(self) -> None: - if hasattr(self, "_deinit_thread"): - self._deinit_thread.join() - - def _deinit(self) -> None: - # Start the deinit thread to avoid blocking the extension thread. - self._deinit_thread = threading.Thread(target=self._deinit_routine) - self._deinit_thread.start() - - def on_configure_done(self) -> None: + async def on_configure_done(self) -> None: raise NotImplementedError( "No need to call this method in async extension" ) - def on_init_done(self) -> None: + async def on_init_done(self) -> None: raise NotImplementedError( "No need to call this method in async extension" ) - def on_start_done(self) -> None: + async def on_start_done(self) -> None: raise NotImplementedError( "No need to call this method in async extension" ) - def on_stop_done(self) -> None: + async def on_stop_done(self) -> None: raise NotImplementedError( "No need to call this method in async extension" ) - def on_deinit_done(self) -> None: + async def on_deinit_done(self) -> None: raise NotImplementedError( "No need to call this method in async extension" ) + + def _deinit_routine(self) -> None: + # Wait for the internal thread to finish. + self._ten_thread.join() + + self._internal.on_deinit_done() + + def _on_release(self) -> None: + if hasattr(self, "_deinit_thread"): + self._deinit_thread.join() + + def _deinit(self) -> None: + # Start the deinit thread to avoid blocking the extension thread. + self._deinit_thread = threading.Thread(target=self._deinit_routine) + self._deinit_thread.start() diff --git a/core/src/ten_runtime/common/loc.c b/core/src/ten_runtime/common/loc.c index e6c215a9e..c41da0fe9 100644 --- a/core/src/ten_runtime/common/loc.c +++ b/core/src/ten_runtime/common/loc.c @@ -339,68 +339,6 @@ ten_value_t *ten_loc_to_value(ten_loc_t *self) { } } -void ten_loc_init_from_json(ten_loc_t *self, ten_json_t *json) { - TEN_ASSERT(self && json, "Should not happen."); - - ten_loc_init_empty(self); - - if (ten_json_object_peek(json, TEN_STR_APP)) { - ten_string_init_formatted( - &self->app_uri, "%s", - ten_json_object_peek_string(json, TEN_STR_APP) - ? ten_json_object_peek_string(json, TEN_STR_APP) - : ""); - } - - if (ten_json_object_peek(json, TEN_STR_GRAPH)) { - ten_string_init_formatted( - &self->graph_id, "%s", - ten_json_object_peek_string(json, TEN_STR_GRAPH) - ? ten_json_object_peek_string(json, TEN_STR_GRAPH) - : ""); - } - - ten_json_t *extension_group_json = - ten_json_object_peek(json, TEN_STR_EXTENSION_GROUP); - if (extension_group_json) { - if (ten_json_is_object(extension_group_json)) { - ten_json_t *extension_group_name_json = - ten_json_object_peek(extension_group_json, TEN_STR_NAME); - TEN_ASSERT(ten_json_is_string(extension_group_name_json), - "name of extension_group must be a string."); - - ten_string_init_formatted( - &self->extension_group_name, "%s", - ten_json_peek_string_value(extension_group_name_json)); - } else if (ten_json_is_string(extension_group_json)) { - ten_string_init_formatted( - &self->extension_group_name, "%s", - ten_json_peek_string_value(extension_group_json)); - } else { - TEN_ASSERT(0, "extension_group must be an object or a string."); - } - } - - ten_json_t *extension_json = ten_json_object_peek(json, TEN_STR_EXTENSION); - if (extension_json) { - if (ten_json_is_object(extension_json)) { - ten_json_t *extension_name_json = - ten_json_object_peek(extension_json, TEN_STR_NAME); - TEN_ASSERT(ten_json_is_string(extension_name_json), - "name of extension must be a string."); - - ten_string_init_formatted( - &self->extension_name, "%s", - ten_json_peek_string_value(extension_name_json)); - } else if (ten_json_is_string(extension_json)) { - ten_string_init_formatted(&self->extension_name, "%s", - ten_json_peek_string_value(extension_json)); - } else { - TEN_ASSERT(0, "extension must be an object or a string."); - } - } -} - void ten_loc_set_from_value(ten_loc_t *self, ten_value_t *value) { TEN_ASSERT(self && value, "Should not happen."); diff --git a/core/src/ten_runtime/engine/msg_interface/cmd_result.c b/core/src/ten_runtime/engine/msg_interface/cmd_result.c index f1452db9c..1d74796bc 100644 --- a/core/src/ten_runtime/engine/msg_interface/cmd_result.c +++ b/core/src/ten_runtime/engine/msg_interface/cmd_result.c @@ -162,7 +162,8 @@ static bool ten_engine_handle_cmd_result_for_cmd_start_graph( if (err_msg_value) { TEN_ASSERT(ten_value_is_string(err_msg_value), "Should not happen."); ten_engine_return_error_for_cmd_start_graph( - self, original_start_graph_cmd, ten_value_peek_raw_str(err_msg_value)); + self, original_start_graph_cmd, + ten_value_peek_raw_str(err_msg_value)); } else { ten_engine_return_error_for_cmd_start_graph( self, original_start_graph_cmd, "Failed to start engine in app [%s].", @@ -177,9 +178,6 @@ static bool ten_engine_handle_cmd_result_for_cmd_start_graph( return true; } -/** - * @return true if command is handled, false otherwise. - */ void ten_engine_handle_cmd_result(ten_engine_t *self, ten_shared_ptr_t *cmd_result, ten_error_t *err) { diff --git a/core/src/ten_runtime/msg/audio_frame/pcm_frame.c b/core/src/ten_runtime/msg/audio_frame/pcm_frame.c index 9e5131220..f59a8ab7a 100644 --- a/core/src/ten_runtime/msg/audio_frame/pcm_frame.c +++ b/core/src/ten_runtime/msg/audio_frame/pcm_frame.c @@ -14,7 +14,6 @@ #include "include_internal/ten_runtime/msg/msg.h" #include "include_internal/ten_utils/value/value_path.h" #include "include_internal/ten_utils/value/value_set.h" -#include "ten_runtime/common/errno.h" #include "ten_runtime/msg/audio_frame/audio_frame.h" #include "ten_utils/lib/alloc.h" #include "ten_utils/macro/check.h" @@ -365,78 +364,6 @@ ten_msg_t *ten_raw_audio_frame_as_msg_clone(ten_msg_t *self, return (ten_msg_t *)new_frame; } -ten_json_t *ten_raw_audio_frame_as_msg_to_json(ten_msg_t *self, - ten_error_t *err) { - TEN_ASSERT(self && ten_raw_msg_check_integrity(self) && - ten_raw_msg_get_type(self) == TEN_MSG_TYPE_AUDIO_FRAME, - "Should not happen."); - - ten_json_t *json = ten_json_create_object(); - TEN_ASSERT(json, "Should not happen."); - - bool rc = ten_raw_audio_frame_loop_all_fields( - self, ten_raw_msg_put_one_field_to_json, json, err); - if (!rc) { - ten_json_destroy(json); - return NULL; - } - - return json; -} - -bool ten_raw_audio_frame_check_type_and_name(ten_msg_t *self, - const char *type_str, - const char *name_str, - ten_error_t *err) { - TEN_ASSERT(self && ten_raw_msg_check_integrity(self), "Invalid argument."); - - if (type_str) { - if (strcmp(type_str, TEN_STR_AUDIO_FRAME) != 0) { - if (err) { - ten_error_set(err, TEN_ERRNO_GENERIC, - "Incorrect message type for audio frame: %s", type_str); - } - return false; - } - } - - if (name_str) { - if (strncmp(name_str, TEN_STR_MSG_NAME_TEN_NAMESPACE_PREFIX, - strlen(TEN_STR_MSG_NAME_TEN_NAMESPACE_PREFIX)) == 0) { - if (err) { - ten_error_set(err, TEN_ERRNO_GENERIC, - "Incorrect message name for audio frame: %s", name_str); - } - return false; - } - } - - return true; -} - -static bool ten_raw_audio_frame_init_from_json(ten_audio_frame_t *self, - ten_json_t *json, - ten_error_t *err) { - TEN_ASSERT(self && ten_raw_audio_frame_check_integrity(self), - "Should not happen."); - TEN_ASSERT(json && ten_json_check_integrity(json), "Should not happen."); - - return ten_raw_audio_frame_loop_all_fields( - (ten_msg_t *)self, ten_raw_msg_get_one_field_from_json, json, err); -} - -bool ten_raw_audio_frame_as_msg_init_from_json(ten_msg_t *self, - ten_json_t *json, - ten_error_t *err) { - TEN_ASSERT( - self && ten_raw_audio_frame_check_integrity((ten_audio_frame_t *)self), - "Should not happen."); - TEN_ASSERT(json && ten_json_check_integrity(json), "Should not happen."); - - return ten_raw_audio_frame_init_from_json((ten_audio_frame_t *)self, json, - err); -} - ten_value_t *ten_raw_audio_frame_peek_ten_property(ten_msg_t *self, ten_list_t *paths, ten_error_t *err) { diff --git a/core/src/ten_runtime/msg/cmd_base/cmd/close_app/cmd.c b/core/src/ten_runtime/msg/cmd_base/cmd/close_app/cmd.c index 200a461c8..7b9ef0b8c 100644 --- a/core/src/ten_runtime/msg/cmd_base/cmd/close_app/cmd.c +++ b/core/src/ten_runtime/msg/cmd_base/cmd/close_app/cmd.c @@ -60,28 +60,6 @@ ten_json_t *ten_raw_cmd_close_app_to_json(ten_msg_t *self, ten_error_t *err) { return json; } -static bool ten_raw_cmd_close_app_init_from_json(ten_cmd_close_app_t *self, - ten_json_t *json, - ten_error_t *err) { - TEN_ASSERT(self && ten_raw_cmd_check_integrity((ten_cmd_t *)self), - "Should not happen."); - TEN_ASSERT(json && ten_json_check_integrity(json), "Should not happen."); - - return ten_raw_cmd_close_app_loop_all_fields( - (ten_msg_t *)self, ten_raw_msg_get_one_field_from_json, json, err); -} - -bool ten_raw_cmd_close_app_as_msg_init_from_json(ten_msg_t *self, - ten_json_t *json, - ten_error_t *err) { - TEN_ASSERT(self && ten_raw_cmd_check_integrity((ten_cmd_t *)self), - "Should not happen."); - TEN_ASSERT(json && ten_json_check_integrity(json), "Should not happen."); - - return ten_raw_cmd_close_app_init_from_json((ten_cmd_close_app_t *)self, json, - err); -} - bool ten_raw_cmd_close_app_loop_all_fields( ten_msg_t *self, ten_raw_msg_process_one_field_func_t cb, void *user_data, ten_error_t *err) { diff --git a/core/src/ten_runtime/msg/cmd_base/cmd/custom/cmd.c b/core/src/ten_runtime/msg/cmd_base/cmd/custom/cmd.c index 271440e71..bc73de21e 100644 --- a/core/src/ten_runtime/msg/cmd_base/cmd/custom/cmd.c +++ b/core/src/ten_runtime/msg/cmd_base/cmd/custom/cmd.c @@ -16,7 +16,6 @@ #include "include_internal/ten_runtime/msg/msg.h" #include "include_internal/ten_utils/value/value_path.h" #include "include_internal/ten_utils/value/value_set.h" -#include "ten_runtime/common/errno.h" #include "ten_utils/container/list.h" #include "ten_utils/container/list_node.h" #include "ten_utils/lib/alloc.h" @@ -68,25 +67,6 @@ ten_cmd_t *ten_raw_cmd_custom_create(const char *cmd_name) { return cmd; } -static bool ten_raw_cmd_custom_init_from_json(ten_cmd_t *self, ten_json_t *json, - ten_error_t *err) { - TEN_ASSERT(self && ten_raw_cmd_check_integrity((ten_cmd_t *)self), - "Should not happen."); - TEN_ASSERT(json && ten_json_check_integrity(json), "Should not happen."); - - return ten_raw_cmd_custom_loop_all_fields( - (ten_msg_t *)self, ten_raw_msg_get_one_field_from_json, json, err); -} - -bool ten_raw_cmd_custom_as_msg_init_from_json(ten_msg_t *self, ten_json_t *json, - ten_error_t *err) { - TEN_ASSERT(self && ten_raw_cmd_check_integrity((ten_cmd_t *)self), - "Should not happen."); - TEN_ASSERT(json && ten_json_check_integrity(json), "Should not happen."); - - return ten_raw_cmd_custom_init_from_json((ten_cmd_t *)self, json, err); -} - // This hack is only used by msgpack when serializing/deserializing the connect // command. Eventually, we should remove this hack. static void ten_raw_cmd_custom_to_json_msgpack_serialization_hack( @@ -225,36 +205,6 @@ bool ten_raw_cmd_custom_set_ten_property(ten_msg_t *self, ten_list_t *paths, return success; } -bool ten_raw_cmd_custom_check_type_and_name(ten_msg_t *self, - const char *type_str, - const char *name_str, - ten_error_t *err) { - TEN_ASSERT(self && ten_raw_msg_check_integrity(self), "Invalid argument."); - - if (type_str) { - if (strcmp(type_str, TEN_STR_CMD) != 0) { - if (err) { - ten_error_set(err, TEN_ERRNO_GENERIC, - "Incorrect message type for cmd: %s", type_str); - } - return false; - } - } - - if (name_str) { - if (strncmp(name_str, TEN_STR_MSG_NAME_TEN_NAMESPACE_PREFIX, - strlen(TEN_STR_MSG_NAME_TEN_NAMESPACE_PREFIX)) == 0) { - if (err) { - ten_error_set(err, TEN_ERRNO_GENERIC, - "Incorrect message name for cmd: %s", name_str); - } - return false; - } - } - - return true; -} - bool ten_raw_cmd_custom_loop_all_fields(ten_msg_t *self, ten_raw_msg_process_one_field_func_t cb, void *user_data, ten_error_t *err) { diff --git a/core/src/ten_runtime/msg/cmd_base/cmd/start_graph/cmd.c b/core/src/ten_runtime/msg/cmd_base/cmd/start_graph/cmd.c index d810463c3..4d83e1789 100644 --- a/core/src/ten_runtime/msg/cmd_base/cmd/start_graph/cmd.c +++ b/core/src/ten_runtime/msg/cmd_base/cmd/start_graph/cmd.c @@ -88,19 +88,10 @@ bool ten_raw_cmd_start_graph_init_from_json(ten_cmd_start_graph_t *self, "Should not happen."); TEN_ASSERT(json && ten_json_check_integrity(json), "Should not happen."); + // =-=-= return ten_raw_cmd_start_graph_loop_all_fields( - (ten_msg_t *)self, ten_raw_msg_get_one_field_from_json, json, err); -} - -bool ten_raw_cmd_start_graph_as_msg_init_from_json(ten_msg_t *self, - ten_json_t *json, - ten_error_t *err) { - TEN_ASSERT(self && ten_raw_cmd_check_integrity((ten_cmd_t *)self), - "Should not happen."); - TEN_ASSERT(json && ten_json_check_integrity(json), "Should not happen."); - - return ten_raw_cmd_start_graph_init_from_json((ten_cmd_start_graph_t *)self, - json, err); + (ten_msg_t *)self, + ten_raw_msg_get_one_field_from_json_include_internal_field, json, err); } static bool ten_raw_cmd_start_graph_as_msg_init_from_json_str( diff --git a/core/src/ten_runtime/msg/cmd_base/cmd/stop_graph/cmd.c b/core/src/ten_runtime/msg/cmd_base/cmd/stop_graph/cmd.c index a0322c4f8..ffde17e11 100644 --- a/core/src/ten_runtime/msg/cmd_base/cmd/stop_graph/cmd.c +++ b/core/src/ten_runtime/msg/cmd_base/cmd/stop_graph/cmd.c @@ -55,28 +55,6 @@ ten_shared_ptr_t *ten_cmd_stop_graph_create(void) { ten_raw_cmd_stop_graph_destroy); } -static bool ten_raw_cmd_stop_graph_init_from_json(ten_cmd_stop_graph_t *self, - ten_json_t *json, - ten_error_t *err) { - TEN_ASSERT(self && ten_raw_cmd_check_integrity((ten_cmd_t *)self), - "Should not happen."); - TEN_ASSERT(json && ten_json_check_integrity(json), "Should not happen."); - - return ten_raw_cmd_stop_graph_loop_all_fields( - (ten_msg_t *)self, ten_raw_msg_get_one_field_from_json, json, err); -} - -bool ten_raw_cmd_stop_graph_as_msg_init_from_json(ten_msg_t *self, - ten_json_t *json, - ten_error_t *err) { - TEN_ASSERT(self && ten_raw_cmd_check_integrity((ten_cmd_t *)self), - "Should not happen."); - TEN_ASSERT(json && ten_json_check_integrity(json), "Should not happen."); - - return ten_raw_cmd_stop_graph_init_from_json((ten_cmd_stop_graph_t *)self, - json, err); -} - ten_json_t *ten_raw_cmd_stop_graph_to_json(ten_msg_t *self, ten_error_t *err) { TEN_ASSERT(self && ten_raw_msg_get_type((ten_msg_t *)self) == TEN_MSG_TYPE_CMD_STOP_GRAPH, diff --git a/core/src/ten_runtime/msg/cmd_base/cmd/timeout/cmd.c b/core/src/ten_runtime/msg/cmd_base/cmd/timeout/cmd.c index 3a160ec27..b2e8e1e50 100644 --- a/core/src/ten_runtime/msg/cmd_base/cmd/timeout/cmd.c +++ b/core/src/ten_runtime/msg/cmd_base/cmd/timeout/cmd.c @@ -13,7 +13,6 @@ #include "include_internal/ten_runtime/msg/msg.h" #include "include_internal/ten_utils/value/value_set.h" #include "ten_utils/lib/alloc.h" -#include "ten_utils/lib/json.h" #include "ten_utils/lib/smart_ptr.h" #include "ten_utils/macro/check.h" #include "ten_utils/value/value.h" @@ -63,56 +62,6 @@ ten_shared_ptr_t *ten_cmd_timeout_create(const uint32_t timer_id) { ten_raw_cmd_timeout_destroy); } -static bool ten_raw_cmd_timeout_init_from_json(ten_cmd_timeout_t *self, - ten_json_t *json, - ten_error_t *err) { - TEN_ASSERT(self && ten_raw_cmd_check_integrity((ten_cmd_t *)self), - "Should not happen."); - TEN_ASSERT(json && ten_json_check_integrity(json), "Should not happen."); - - return ten_raw_cmd_timeout_loop_all_fields( - (ten_msg_t *)self, ten_raw_msg_get_one_field_from_json, json, err); -} - -bool ten_raw_cmd_timeout_as_msg_init_from_json(ten_msg_t *self, - ten_json_t *json, - ten_error_t *err) { - TEN_ASSERT(self && ten_raw_cmd_check_integrity((ten_cmd_t *)self), - "Should not happen."); - TEN_ASSERT(json && ten_json_check_integrity(json), "Should not happen."); - - return ten_raw_cmd_timeout_init_from_json((ten_cmd_timeout_t *)self, json, - err); -} - -static ten_json_t *ten_raw_cmd_timeout_to_json(ten_cmd_timeout_t *self, - ten_error_t *err) { - TEN_ASSERT( - self && ten_raw_cmd_check_integrity((ten_cmd_t *)self) && - ten_raw_msg_get_type((ten_msg_t *)self) == TEN_MSG_TYPE_CMD_TIMEOUT, - "Should not happen."); - - ten_json_t *json = ten_json_create_object(); - TEN_ASSERT(json, "Should not happen."); - - if (!ten_raw_cmd_timeout_loop_all_fields( - (ten_msg_t *)self, ten_raw_msg_put_one_field_to_json, json, err)) { - ten_json_destroy(json); - return NULL; - } - - return json; -} - -ten_json_t *ten_raw_cmd_timeout_as_msg_to_json(ten_msg_t *self, - ten_error_t *err) { - TEN_ASSERT(self && ten_raw_cmd_check_integrity((ten_cmd_t *)self) && - ten_raw_msg_get_type(self) == TEN_MSG_TYPE_CMD_TIMEOUT, - "Should not happen."); - - return ten_raw_cmd_timeout_to_json((ten_cmd_timeout_t *)self, err); -} - uint32_t ten_raw_cmd_timeout_get_timer_id(ten_cmd_timeout_t *self) { TEN_ASSERT( self && ten_raw_cmd_check_integrity((ten_cmd_t *)self) && diff --git a/core/src/ten_runtime/msg/cmd_base/cmd/timer/cmd.c b/core/src/ten_runtime/msg/cmd_base/cmd/timer/cmd.c index 4423d0aa3..f363e7c8a 100644 --- a/core/src/ten_runtime/msg/cmd_base/cmd/timer/cmd.c +++ b/core/src/ten_runtime/msg/cmd_base/cmd/timer/cmd.c @@ -14,11 +14,9 @@ #include "include_internal/ten_runtime/msg/msg.h" #include "include_internal/ten_utils/value/value_path.h" #include "include_internal/ten_utils/value/value_set.h" -#include "ten_runtime/common/errno.h" #include "ten_utils/container/list.h" #include "ten_utils/lib/alloc.h" #include "ten_utils/lib/error.h" -#include "ten_utils/lib/json.h" #include "ten_utils/lib/smart_ptr.h" #include "ten_utils/macro/check.h" #include "ten_utils/value/value.h" @@ -65,17 +63,6 @@ void ten_raw_cmd_timer_as_msg_destroy(ten_msg_t *self) { ten_raw_cmd_timer_destroy((ten_cmd_timer_t *)self); } -static bool ten_raw_cmd_timer_init_from_json(ten_cmd_timer_t *self, - ten_json_t *json, - ten_error_t *err) { - TEN_ASSERT(self && ten_raw_cmd_check_integrity((ten_cmd_t *)self), - "Should not happen."); - TEN_ASSERT(json && ten_json_check_integrity(json), "Should not happen."); - - return ten_raw_cmd_timer_loop_all_fields( - (ten_msg_t *)self, ten_raw_msg_get_one_field_from_json, json, err); -} - bool ten_raw_cmd_timer_loop_all_fields(ten_msg_t *self, ten_raw_msg_process_one_field_func_t cb, void *user_data, ten_error_t *err) { @@ -94,15 +81,6 @@ bool ten_raw_cmd_timer_loop_all_fields(ten_msg_t *self, return true; } -bool ten_raw_cmd_timer_as_msg_init_from_json(ten_msg_t *self, ten_json_t *json, - ten_error_t *err) { - TEN_ASSERT(self && ten_raw_cmd_check_integrity((ten_cmd_t *)self), - "Should not happen."); - TEN_ASSERT(json && ten_json_check_integrity(json), "Should not happen."); - - return ten_raw_cmd_timer_init_from_json((ten_cmd_timer_t *)self, json, err); -} - ten_cmd_timer_t *ten_raw_cmd_timer_create(void) { ten_cmd_timer_t *raw_cmd = TEN_MALLOC(sizeof(ten_cmd_timer_t)); TEN_ASSERT(raw_cmd, "Failed to allocate memory."); @@ -121,32 +99,6 @@ ten_shared_ptr_t *ten_cmd_timer_create(void) { ten_raw_cmd_timer_destroy); } -static ten_json_t *ten_raw_cmd_timer_to_json(ten_cmd_timer_t *self, - ten_error_t *err) { - TEN_ASSERT( - self && ten_raw_msg_get_type((ten_msg_t *)self) == TEN_MSG_TYPE_CMD_TIMER, - "Should not happen."); - - ten_json_t *json = ten_json_create_object(); - TEN_ASSERT(json, "Should not happen."); - - if (!ten_raw_cmd_timer_loop_all_fields( - (ten_msg_t *)self, ten_raw_msg_put_one_field_to_json, json, err)) { - ten_json_destroy(json); - return NULL; - } - - return json; -} - -ten_json_t *ten_raw_cmd_timer_as_msg_to_json(ten_msg_t *self, - ten_error_t *err) { - TEN_ASSERT(self && ten_raw_msg_get_type(self) == TEN_MSG_TYPE_CMD_TIMER, - "Should not happen."); - - return ten_raw_cmd_timer_to_json((ten_cmd_timer_t *)self, err); -} - uint32_t ten_raw_cmd_timer_get_timer_id(ten_cmd_timer_t *self) { TEN_ASSERT( self && ten_raw_msg_get_type((ten_msg_t *)self) == TEN_MSG_TYPE_CMD_TIMER, @@ -268,37 +220,6 @@ bool ten_raw_cmd_timer_set_ten_property(ten_msg_t *self, ten_list_t *paths, return success; } -bool ten_raw_cmd_timer_check_type_and_name(ten_msg_t *self, - const char *type_str, - const char *name_str, - ten_error_t *err) { - TEN_ASSERT(self && ten_raw_msg_check_integrity(self), "Invalid argument."); - - if (type_str) { - if (strcmp(type_str, TEN_STR_CMD) != 0 && - strcmp(type_str, TEN_STR_TIMER) != 0) { - if (err) { - ten_error_set(err, TEN_ERRNO_GENERIC, - "Incorrect message type for timer cmd: %s", type_str); - } - return false; - } - } - - if (name_str) { - if (strcmp(name_str, TEN_STR_MSG_NAME_TEN_NAMESPACE_PREFIX TEN_STR_TIMER) != - 0) { - if (err) { - ten_error_set(err, TEN_ERRNO_GENERIC, - "Incorrect message name for timer cmd: %s", name_str); - } - return false; - } - } - - return true; -} - int32_t ten_cmd_timer_get_times(ten_shared_ptr_t *self) { TEN_ASSERT(self && ten_msg_get_type(self) == TEN_MSG_TYPE_CMD_TIMER, "Should not happen."); diff --git a/core/src/ten_runtime/msg/cmd_base/cmd_base.c b/core/src/ten_runtime/msg/cmd_base/cmd_base.c index 28d4604ca..9033cb3de 100644 --- a/core/src/ten_runtime/msg/cmd_base/cmd_base.c +++ b/core/src/ten_runtime/msg/cmd_base/cmd_base.c @@ -243,23 +243,6 @@ void ten_raw_cmd_base_set_seq_id(ten_cmd_base_t *self, const char *seq_id) { ten_string_set_formatted(ten_value_peek_string(&self->seq_id), "%s", seq_id); } -bool ten_raw_cmd_base_get_field_from_json(ten_msg_t *self, ten_json_t *json, - ten_error_t *err) { - TEN_ASSERT(self && json, "Should not happen."); - - return ten_raw_cmd_base_process_field( - self, ten_raw_msg_get_one_field_from_json, json, err); -} - -bool ten_raw_cmd_base_put_field_to_json(ten_msg_t *self, ten_json_t *json, - ten_error_t *err) { - TEN_ASSERT(self && ten_raw_msg_check_integrity(self) && json, - "Should not happen."); - - return ten_raw_cmd_base_process_field(self, ten_raw_msg_put_one_field_to_json, - json, err); -} - static bool ten_raw_cmd_base_cmd_id_is_empty(ten_cmd_base_t *self) { TEN_ASSERT(self && ten_raw_cmd_base_check_integrity(self), "Should not happen."); diff --git a/core/src/ten_runtime/msg/cmd_base/cmd_result/cmd.c b/core/src/ten_runtime/msg/cmd_base/cmd_result/cmd.c index 71c9cc94b..5a4c00324 100644 --- a/core/src/ten_runtime/msg/cmd_base/cmd_result/cmd.c +++ b/core/src/ten_runtime/msg/cmd_base/cmd_result/cmd.c @@ -266,26 +266,6 @@ void ten_cmd_result_set_status_code(ten_shared_ptr_t *self, ten_raw_cmd_result_set_status_code(cmd_result, status_code); } -static bool ten_raw_cmd_result_init_from_json(ten_cmd_result_t *self, - ten_json_t *json, - ten_error_t *err) { - TEN_ASSERT(self && ten_raw_cmd_base_check_integrity((ten_cmd_base_t *)self), - "Should not happen."); - TEN_ASSERT(json && ten_json_check_integrity(json), "Should not happen."); - - return ten_raw_cmd_result_loop_all_fields( - (ten_msg_t *)self, ten_raw_msg_get_one_field_from_json, json, err); -} - -bool ten_raw_cmd_result_as_msg_init_from_json(ten_msg_t *self, ten_json_t *json, - ten_error_t *err) { - TEN_ASSERT(self && ten_raw_cmd_base_check_integrity((ten_cmd_base_t *)self), - "Should not happen."); - TEN_ASSERT(json && ten_json_check_integrity(json), "Should not happen."); - - return ten_raw_cmd_result_init_from_json((ten_cmd_result_t *)self, json, err); -} - static ten_json_t *ten_raw_cmd_result_put_field_to_json(ten_cmd_result_t *self, ten_error_t *err) { TEN_ASSERT(self && ten_raw_msg_get_type((ten_msg_t *)self) == @@ -304,14 +284,6 @@ static ten_json_t *ten_raw_cmd_result_put_field_to_json(ten_cmd_result_t *self, return json; } -ten_json_t *ten_raw_cmd_result_as_msg_to_json(ten_msg_t *self, - ten_error_t *err) { - TEN_ASSERT(self && ten_raw_msg_get_type(self) == TEN_MSG_TYPE_CMD_RESULT, - "Should not happen."); - - return ten_raw_cmd_result_put_field_to_json((ten_cmd_result_t *)self, err); -} - ten_json_t *ten_cmd_result_to_json(ten_shared_ptr_t *self, ten_error_t *err) { TEN_ASSERT(self && ten_msg_get_type(self) == TEN_MSG_TYPE_CMD_RESULT, "Should not happen."); diff --git a/core/src/ten_runtime/msg/data/data.c b/core/src/ten_runtime/msg/data/data.c index ae9c73297..621b84c8d 100644 --- a/core/src/ten_runtime/msg/data/data.c +++ b/core/src/ten_runtime/msg/data/data.c @@ -11,10 +11,8 @@ #include "include_internal/ten_runtime/msg/locked_res.h" #include "include_internal/ten_runtime/msg/msg.h" #include "include_internal/ten_utils/value/value_path.h" -#include "ten_runtime/common/errno.h" #include "ten_utils/lib/alloc.h" #include "ten_utils/lib/buf.h" -#include "ten_utils/lib/json.h" #include "ten_utils/lib/signature.h" #include "ten_utils/lib/smart_ptr.h" #include "ten_utils/macro/check.h" @@ -135,42 +133,6 @@ ten_msg_t *ten_raw_data_as_msg_clone(ten_msg_t *self, return (ten_msg_t *)new_data; } -static bool ten_raw_data_init_from_json(ten_data_t *self, ten_json_t *json, - ten_error_t *err) { - TEN_ASSERT(self && ten_raw_data_check_integrity(self), "Should not happen."); - TEN_ASSERT(json && ten_json_check_integrity(json), "Should not happen."); - - return ten_raw_data_loop_all_fields( - (ten_msg_t *)self, ten_raw_msg_get_one_field_from_json, json, err); -} - -bool ten_raw_data_as_msg_init_from_json(ten_msg_t *self, ten_json_t *json, - ten_error_t *err) { - TEN_ASSERT(self && ten_raw_data_check_integrity((ten_data_t *)self), - "Should not happen."); - TEN_ASSERT(json && ten_json_check_integrity(json), "Should not happen."); - - return ten_raw_data_init_from_json((ten_data_t *)self, json, err); -} - -ten_json_t *ten_raw_data_as_msg_to_json(ten_msg_t *self, ten_error_t *err) { - TEN_ASSERT(self && ten_raw_msg_check_integrity(self) && - ten_raw_msg_get_type(self) == TEN_MSG_TYPE_DATA, - "Should not happen."); - - ten_json_t *json = ten_json_create_object(); - TEN_ASSERT(json, "Should not happen."); - - bool rc = ten_raw_data_loop_all_fields( - self, ten_raw_msg_put_one_field_to_json, json, err); - if (!rc) { - ten_json_destroy(json); - return NULL; - } - - return json; -} - bool ten_raw_data_loop_all_fields(ten_msg_t *self, ten_raw_msg_process_one_field_func_t cb, TEN_UNUSED void *user_data, @@ -255,31 +217,3 @@ bool ten_raw_data_like_set_ten_property(ten_msg_t *self, ten_list_t *paths, return success; } - -bool ten_raw_data_check_type_and_name(ten_msg_t *self, const char *type_str, - const char *name_str, ten_error_t *err) { - TEN_ASSERT(self && ten_raw_msg_check_integrity(self), "Invalid argument."); - - if (type_str) { - if (strcmp(type_str, TEN_STR_DATA) != 0) { - if (err) { - ten_error_set(err, TEN_ERRNO_GENERIC, - "Incorrect message type for data: %s", type_str); - } - return false; - } - } - - if (name_str) { - if (strncmp(name_str, TEN_STR_MSG_NAME_TEN_NAMESPACE_PREFIX, - strlen(TEN_STR_MSG_NAME_TEN_NAMESPACE_PREFIX)) == 0) { - if (err) { - ten_error_set(err, TEN_ERRNO_GENERIC, - "Incorrect message name for data: %s", name_str); - } - return false; - } - } - - return true; -} diff --git a/core/src/ten_runtime/msg/msg.c b/core/src/ten_runtime/msg/msg.c index 51a96d2ae..5a9976b29 100644 --- a/core/src/ten_runtime/msg/msg.c +++ b/core/src/ten_runtime/msg/msg.c @@ -582,9 +582,9 @@ const char *ten_msg_type_to_string(const TEN_MSG_TYPE type) { return ten_msg_info[type].msg_type_name; } -bool ten_raw_msg_get_one_field_from_json(ten_msg_t *self, - ten_msg_field_process_data_t *field, - void *user_data, ten_error_t *err) { +static bool ten_raw_msg_get_one_field_from_json_internal( + ten_msg_t *self, ten_msg_field_process_data_t *field, void *user_data, + bool include_internal_field, ten_error_t *err) { TEN_ASSERT(self && ten_raw_msg_check_integrity(self), "Should not happen."); TEN_ASSERT(field, "Should not happen."); TEN_ASSERT( @@ -596,25 +596,27 @@ bool ten_raw_msg_get_one_field_from_json(ten_msg_t *self, if (!field->is_user_defined_properties) { // Internal fields are uniformly stored in the "_ten" section. - json = ten_json_object_peek_object_forcibly(json, TEN_STR_UNDERLINE_TEN); - TEN_ASSERT(json, "Should not happen."); + if (include_internal_field) { + json = ten_json_object_peek_object_forcibly(json, TEN_STR_UNDERLINE_TEN); + TEN_ASSERT(json, "Should not happen."); + + json = ten_json_object_peek(json, field->field_name); + if (!json) { + // Some fields are optional, and it is allowed for the corresponding + // JSON block to be absent during deserialization. + return true; + } - json = ten_json_object_peek(json, field->field_name); - if (!json) { - // Some fields are optional, and it is allowed for the corresponding JSON - // block to be absent during deserialization. - return true; - } + if (!ten_value_set_from_json(field->field_value, json)) { + // If the field value cannot be set from the JSON, it means that the + // JSON format is incorrect. + if (err) { + ten_error_set(err, TEN_ERRNO_INVALID_JSON, + "Invalid JSON format for field %s.", field->field_name); + } - if (!ten_value_set_from_json(field->field_value, json)) { - // If the field value cannot be set from the JSON, it means that the JSON - // format is incorrect. - if (err) { - ten_error_set(err, TEN_ERRNO_INVALID_JSON, - "Invalid JSON format for field %s.", field->field_name); + return false; } - - return false; } } else { // User-defined fields are stored in the root of the JSON. The field value @@ -655,17 +657,23 @@ bool ten_raw_msg_get_one_field_from_json(ten_msg_t *self, return true; } -bool ten_raw_msg_get_field_from_json(ten_msg_t *self, ten_json_t *json, - ten_error_t *err) { - TEN_ASSERT(self && json, "Should not happen."); +bool ten_raw_msg_get_one_field_from_json(ten_msg_t *self, + ten_msg_field_process_data_t *field, + void *user_data, ten_error_t *err) { + return ten_raw_msg_get_one_field_from_json_internal(self, field, user_data, + false, err); +} - return ten_raw_msg_process_field(self, ten_raw_msg_get_one_field_from_json, - json, err); +bool ten_raw_msg_get_one_field_from_json_include_internal_field( + ten_msg_t *self, ten_msg_field_process_data_t *field, void *user_data, + ten_error_t *err) { + return ten_raw_msg_get_one_field_from_json_internal(self, field, user_data, + true, err); } -bool ten_raw_msg_put_one_field_to_json(ten_msg_t *self, - ten_msg_field_process_data_t *field, - void *user_data, ten_error_t *err) { +static bool ten_raw_msg_put_one_field_to_json_internal( + ten_msg_t *self, ten_msg_field_process_data_t *field, void *user_data, + bool include_internal_field, ten_error_t *err) { TEN_ASSERT(self && ten_raw_msg_check_integrity(self), "Should not happen."); TEN_ASSERT(field, "Should not happen."); TEN_ASSERT( @@ -677,11 +685,14 @@ bool ten_raw_msg_put_one_field_to_json(ten_msg_t *self, if (!field->is_user_defined_properties) { // Internal fields are uniformly stored in the "_ten" section. - json = ten_json_object_peek_object_forcibly(json, TEN_STR_UNDERLINE_TEN); - TEN_ASSERT(json, "Should not happen."); - ten_json_object_set_new(json, field->field_name, - ten_value_to_json(field->field_value)); + if (include_internal_field) { + json = ten_json_object_peek_object_forcibly(json, TEN_STR_UNDERLINE_TEN); + TEN_ASSERT(json, "Should not happen."); + + ten_json_object_set_new(json, field->field_name, + ten_value_to_json(field->field_value)); + } } else { TEN_ASSERT(ten_value_is_object(field->field_value), "Should not happen."); @@ -701,13 +712,30 @@ bool ten_raw_msg_put_one_field_to_json(ten_msg_t *self, return true; } -bool ten_raw_msg_put_field_to_json(ten_msg_t *self, ten_json_t *json, - ten_error_t *err) { - TEN_ASSERT(self && ten_raw_msg_check_integrity(self) && json, - "Should not happen."); +static bool ten_raw_msg_put_one_field_to_json_include_internal_field( + ten_msg_t *self, ten_msg_field_process_data_t *field, void *user_data, + ten_error_t *err) { + TEN_ASSERT(self && ten_raw_msg_check_integrity(self), "Should not happen."); + TEN_ASSERT(field, "Should not happen."); + TEN_ASSERT( + field->field_value && ten_value_check_integrity(field->field_value), + "Should not happen."); - return ten_raw_msg_process_field(self, ten_raw_msg_put_one_field_to_json, - json, err); + return ten_raw_msg_put_one_field_to_json_internal(self, field, user_data, + true, err); +} + +bool ten_raw_msg_put_one_field_to_json(ten_msg_t *self, + ten_msg_field_process_data_t *field, + void *user_data, ten_error_t *err) { + TEN_ASSERT(self && ten_raw_msg_check_integrity(self), "Should not happen."); + TEN_ASSERT(field, "Should not happen."); + TEN_ASSERT( + field->field_value && ten_value_check_integrity(field->field_value), + "Should not happen."); + + return ten_raw_msg_put_one_field_to_json_internal(self, field, user_data, + false, err); } bool ten_raw_msg_process_field(ten_msg_t *self, @@ -751,6 +779,32 @@ ten_json_t *ten_msg_to_json(ten_shared_ptr_t *self, ten_error_t *err) { return ten_raw_msg_to_json(ten_msg_get_raw_msg(self), err); } +static ten_json_t *ten_raw_msg_to_json_include_internal_field( + ten_msg_t *self, ten_error_t *err) { + TEN_ASSERT(self && ten_raw_msg_check_integrity(self), "Should not happen."); + ten_json_t *json = ten_json_create_object(); + TEN_ASSERT(json, "Should not happen."); + + bool rc = ten_raw_msg_loop_all_fields( + self, ten_raw_msg_put_one_field_to_json_include_internal_field, json, + err); + + if (!rc) { + ten_json_destroy(json); + return NULL; + } + + return json; +} + +ten_json_t *ten_msg_to_json_include_internal_field(ten_shared_ptr_t *self, + ten_error_t *err) { + TEN_ASSERT(self && ten_msg_check_integrity(self), "Should not happen."); + + return ten_raw_msg_to_json_include_internal_field(ten_msg_get_raw_msg(self), + err); +} + void ten_raw_msg_copy_field(ten_msg_t *self, ten_msg_t *src, ten_list_t *excluded_field_ids) { TEN_ASSERT(src && ten_raw_msg_check_integrity(src), "Should not happen."); @@ -784,24 +838,6 @@ static bool ten_raw_msg_init_from_json(ten_msg_t *self, ten_json_t *json, TEN_ASSERT(self && ten_raw_msg_check_integrity(self), "Should not happen."); TEN_ASSERT(json && ten_json_check_integrity(json), "Should not happen."); - const char *type_str = - ten_msg_json_get_string_field_in_ten(json, TEN_STR_TYPE); - const char *name_str = - ten_msg_json_get_string_field_in_ten(json, TEN_STR_NAME); - - ten_raw_msg_check_type_and_name_func_t check_msg_type_and_name_string = - ten_msg_info[ten_raw_msg_get_type(self)].check_type_and_name; - if (check_msg_type_and_name_string) { - if (!check_msg_type_and_name_string(self, type_str, name_str, err)) { - if (err) { - ten_error_set(err, TEN_ERRNO_INVALID_JSON, - "Failed to init a message from json, because the type " - "and name are incorrect."); - } - return false; - } - } - bool rc = ten_raw_msg_loop_all_fields( self, ten_raw_msg_get_one_field_from_json, json, err); @@ -1035,15 +1071,14 @@ static bool ten_raw_msg_dump_internal(ten_msg_t *msg, ten_error_t *err, const char *fmt, va_list ap) { TEN_ASSERT(msg && ten_raw_msg_check_integrity(msg), "Should not happen."); - ten_json_t *msg_json = ten_raw_msg_to_json(msg, err); + ten_json_t *msg_json = ten_raw_msg_to_json_include_internal_field(msg, err); + TEN_ASSERT(msg_json, "Failed to convert msg type(%s), name(%s) to JSON.", + ten_msg_type_to_string(msg->type), + ten_value_peek_raw_str(&msg->name)); if (!msg_json) { return false; } - TEN_ASSERT(msg_json, "Failed to convert msg type(%s), key(%s) to JSON.", - ten_msg_type_to_string(msg->type), - ten_value_peek_raw_str(&msg->name)); - bool must_free = false; const char *msg_json_str = ten_json_to_string(msg_json, NULL, &must_free); diff --git a/core/src/ten_runtime/msg/video_frame/video_frame.c b/core/src/ten_runtime/msg/video_frame/video_frame.c index 05cc1f4f4..9e531f7be 100644 --- a/core/src/ten_runtime/msg/video_frame/video_frame.c +++ b/core/src/ten_runtime/msg/video_frame/video_frame.c @@ -14,7 +14,6 @@ #include "include_internal/ten_runtime/msg/video_frame/field/field_info.h" #include "include_internal/ten_utils/value/value_path.h" #include "include_internal/ten_utils/value/value_set.h" -#include "ten_runtime/common/errno.h" #include "ten_runtime/msg/msg.h" #include "ten_runtime/msg/video_frame/video_frame.h" #include "ten_utils/lib/alloc.h" @@ -259,78 +258,6 @@ ten_msg_t *ten_raw_video_frame_as_msg_clone(ten_msg_t *self, return (ten_msg_t *)new_frame; } -ten_json_t *ten_raw_video_frame_as_msg_to_json(ten_msg_t *self, - ten_error_t *err) { - TEN_ASSERT(self && ten_raw_msg_check_integrity(self) && - ten_raw_msg_get_type(self) == TEN_MSG_TYPE_VIDEO_FRAME, - "Should not happen."); - - ten_json_t *json = ten_json_create_object(); - TEN_ASSERT(json, "Should not happen."); - - bool rc = ten_raw_video_frame_loop_all_fields( - self, ten_raw_msg_put_one_field_to_json, json, err); - if (!rc) { - ten_json_destroy(json); - return NULL; - } - - return json; -} - -bool ten_raw_video_frame_check_type_and_name(ten_msg_t *self, - const char *type_str, - const char *name_str, - ten_error_t *err) { - TEN_ASSERT(self && ten_raw_msg_check_integrity(self), "Invalid argument."); - - if (type_str) { - if (strcmp(type_str, TEN_STR_VIDEO_FRAME) != 0) { - if (err) { - ten_error_set(err, TEN_ERRNO_GENERIC, - "Incorrect message type for video frame: %s", type_str); - } - return false; - } - } - - if (name_str) { - if (strncmp(name_str, TEN_STR_MSG_NAME_TEN_NAMESPACE_PREFIX, - strlen(TEN_STR_MSG_NAME_TEN_NAMESPACE_PREFIX)) == 0) { - if (err) { - ten_error_set(err, TEN_ERRNO_GENERIC, - "Incorrect message name for video frame: %s", name_str); - } - return false; - } - } - - return true; -} - -static bool ten_raw_video_frame_init_from_json(ten_video_frame_t *self, - ten_json_t *json, - ten_error_t *err) { - TEN_ASSERT(self && ten_raw_video_frame_check_integrity(self), - "Should not happen."); - TEN_ASSERT(json && ten_json_check_integrity(json), "Should not happen."); - - return ten_raw_video_frame_loop_all_fields( - (ten_msg_t *)self, ten_raw_msg_get_one_field_from_json, json, err); -} - -bool ten_raw_video_frame_as_msg_init_from_json(ten_msg_t *self, - ten_json_t *json, - ten_error_t *err) { - TEN_ASSERT( - self && ten_raw_video_frame_check_integrity((ten_video_frame_t *)self), - "Should not happen."); - TEN_ASSERT(json && ten_json_check_integrity(json), "Should not happen."); - - return ten_raw_video_frame_init_from_json((ten_video_frame_t *)self, json, - err); -} - bool ten_raw_video_frame_set_ten_property(ten_msg_t *self, ten_list_t *paths, ten_value_t *value, ten_error_t *err) { diff --git a/core/src/ten_runtime/test/extension_tester.c b/core/src/ten_runtime/test/extension_tester.c index ce41b176b..689459ede 100644 --- a/core/src/ten_runtime/test/extension_tester.c +++ b/core/src/ten_runtime/test/extension_tester.c @@ -30,7 +30,6 @@ #include "ten_utils/container/list_str.h" #include "ten_utils/io/runloop.h" #include "ten_utils/lib/event.h" -#include "ten_utils/lib/json.h" #include "ten_utils/lib/signature.h" #include "ten_utils/lib/smart_ptr.h" #include "ten_utils/lib/string.h" @@ -172,14 +171,6 @@ static void ten_extension_tester_create_and_start_graph( TEN_ASSERT(first_addon_name, "Should not happen."); TEN_ASSERT(ten_string_len(first_addon_name), "No addon name is specified."); - ten_shared_ptr_t *start_graph_cmd = ten_cmd_start_graph_create(); - TEN_ASSERT(start_graph_cmd, "Should not happen."); - - // Set the destination so that the recipient is the app itself. - bool rc = ten_msg_clear_and_set_dest(start_graph_cmd, TEN_STR_LOCALHOST, NULL, - NULL, NULL, NULL); - TEN_ASSERT(rc, "Should not happen."); - ten_string_t start_graph_cmd_json_str; ten_string_init_formatted(&start_graph_cmd_json_str, "{\ @@ -281,15 +272,19 @@ static void ten_extension_tester_create_and_start_graph( ten_string_get_raw_str(first_addon_name), ten_string_get_raw_str(first_addon_name)); - ten_json_t *start_graph_cmd_json = ten_json_from_string( - ten_string_get_raw_str(&start_graph_cmd_json_str), NULL); + ten_shared_ptr_t *start_graph_cmd = ten_cmd_start_graph_create(); + TEN_ASSERT(start_graph_cmd, "Should not happen."); - ten_string_deinit(&start_graph_cmd_json_str); + // Set the destination so that the recipient is the app itself. + bool rc = ten_msg_clear_and_set_dest(start_graph_cmd, TEN_STR_LOCALHOST, NULL, + NULL, NULL, NULL); + TEN_ASSERT(rc, "Should not happen."); - rc = ten_msg_from_json(start_graph_cmd, start_graph_cmd_json, NULL); + rc = ten_cmd_start_graph_init_from_json_str( + start_graph_cmd, ten_string_get_raw_str(&start_graph_cmd_json_str), NULL); TEN_ASSERT(rc, "Should not happen."); - ten_json_destroy(start_graph_cmd_json); + ten_string_deinit(&start_graph_cmd_json_str); rc = ten_env_proxy_notify(self->test_app_ten_env_proxy, test_app_ten_env_send_cmd, start_graph_cmd, false, diff --git a/packages/example_extensions/simple_echo_cpp/src/main.cc b/packages/example_extensions/simple_echo_cpp/src/main.cc index 49ec5b22a..372662ebd 100644 --- a/packages/example_extensions/simple_echo_cpp/src/main.cc +++ b/packages/example_extensions/simple_echo_cpp/src/main.cc @@ -22,11 +22,11 @@ class simple_echo_extension_t : public ten::extension_t { // Parse the command and return a new command with the same name but with a // suffix ", too" added to it. - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - auto cmd_name = json["_ten"]["name"]; + std::string cmd_name = cmd->get_name(); auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); - cmd_result->set_property("detail", (cmd_name.get() + ", too")); + cmd_result->set_property("detail", cmd_name + ", too"); + ten_env.return_result(std::move(cmd_result), std::move(cmd)); } diff --git a/packages/example_extensions/simple_http_server_cpp/src/main.cc b/packages/example_extensions/simple_http_server_cpp/src/main.cc index ba7d7ffd8..3c7391dce 100644 --- a/packages/example_extensions/simple_http_server_cpp/src/main.cc +++ b/packages/example_extensions/simple_http_server_cpp/src/main.cc @@ -609,10 +609,7 @@ void send_ten_msg_with_req_body( cmd = ten::cmd_close_app_t::create(); // Set the destination of the command to the localhost. - cmd_json["_ten"].erase("dest"); - auto dest = nlohmann::json::array(); - dest.push_back({{"app", "localhost"}}); - cmd_json["_ten"]["dest"] = dest; + cmd->set_dest("localhost", nullptr, nullptr, nullptr); } else { assert(0 && "Handle more internal command types."); } diff --git a/tests/common/client/cpp/msgpack_tcp.h b/tests/common/client/cpp/msgpack_tcp.h index 13e5fc6b5..ff02abe35 100644 --- a/tests/common/client/cpp/msgpack_tcp.h +++ b/tests/common/client/cpp/msgpack_tcp.h @@ -11,8 +11,10 @@ #include #include +#include "include_internal/ten_runtime/binding/cpp/internal/msg/cmd/cmd_result_internal_accessor.h" #include "include_internal/ten_runtime/binding/cpp/ten.h" #include "include_internal/ten_utils/log/log.h" +#include "ten_runtime/binding/cpp/internal/msg/cmd_result.h" #include "ten_utils/lib/json.h" #include "ten_utils/lib/smart_ptr.h" #include "ten_utils/lib/string.h" @@ -49,109 +51,32 @@ class msgpack_tcp_client_t { return success; } - bool send_json(const nlohmann::json &cmd_json) { - if (cmd_json.contains("_ten")) { - if (cmd_json["_ten"].contains("type")) { - if (cmd_json["_ten"]["type"] == "start_graph") { - std::unique_ptr cmd = ten::cmd_start_graph_t::create(); - cmd->from_json(cmd_json.dump().c_str()); - return send_cmd(std::move(cmd)); - } else if (cmd_json["_ten"]["type"] == "close_app") { - std::unique_ptr cmd = ten::cmd_close_app_t::create(); - cmd->from_json(cmd_json.dump().c_str()); - return send_cmd(std::move(cmd)); - } else { - TEN_ASSERT(0, "Handle more TEN builtin command type."); - } - } else { - std::unique_ptr cmd = ten::cmd_t::create( - cmd_json["_ten"]["name"].get().c_str()); - cmd->from_json(cmd_json.dump().c_str()); - return send_cmd(std::move(cmd)); - } - } else { - TEN_ASSERT(0, "Should not happen."); - } - - return false; - } - - nlohmann::json send_cmd_and_recv_resp_in_json( + std::unique_ptr send_cmd_and_recv_result( std::unique_ptr &&cmd) { send_cmd(std::move(cmd)); ten_shared_ptr_t *c_resp = ten_test_msgpack_tcp_client_recv_msg(c_client); if (c_resp != nullptr) { - ten_json_t *c_json = ten_msg_to_json(c_resp, nullptr); - - bool must_free = false; - const char *json_str = ten_json_to_string(c_json, nullptr, &must_free); - TEN_ASSERT(json_str, "Failed to get JSON string from JSON."); - - nlohmann::json result = nlohmann::json::parse(json_str); - - ten_json_destroy(c_json); - if (must_free) { - TEN_FREE( - json_str); // NOLINT(cppcoreguidelines-no-malloc, hicpp-no-malloc) - } - - ten_shared_ptr_destroy(c_resp); - - return result; - } else { - return nlohmann::json{}; - } - } - - nlohmann::json send_json_and_recv_resp_in_json( - const nlohmann::json &cmd_json) { - if (cmd_json.contains("_ten")) { - if (cmd_json["_ten"].contains("type")) { - if (cmd_json["_ten"]["type"] == "start_graph") { - std::unique_ptr start_graph_cmd = - ten::cmd_start_graph_t::create(); - start_graph_cmd->from_json(cmd_json.dump().c_str()); - return send_cmd_and_recv_resp_in_json(std::move(start_graph_cmd)); - } else { - TEN_ASSERT(0, "Handle more TEN builtin command type."); - } - } else { - std::unique_ptr custom_cmd = ten::cmd_t::create( - cmd_json["_ten"]["name"].get().c_str()); - custom_cmd->from_json(cmd_json.dump().c_str()); - return send_cmd_and_recv_resp_in_json(std::move(custom_cmd)); - } + return ten::cmd_result_internal_accessor_t::create(c_resp); } else { - TEN_ASSERT(0, "Should not happen."); + return {}; } - return {}; } - std::vector batch_recv_resp_in_json() { + std::vector> batch_recv_cmd_results() { ten_list_t msgs = TEN_LIST_INIT_VAL; - ten_test_msgpack_tcp_client_recv_msgs_batch(c_client, &msgs); - std::vector results; + std::vector> results; ten_list_foreach (&msgs, iter) { - ten_shared_ptr_t *c_resp = ten_smart_ptr_listnode_get(iter.node); - TEN_ASSERT(c_resp, "Should not happen."); - - ten_json_t *c_json = ten_msg_to_json(c_resp, nullptr); - - bool must_free = false; - const char *json_str = ten_json_to_string(c_json, nullptr, &must_free); - TEN_ASSERT(json_str, "Failed to get JSON string from JSON."); - - results.emplace_back(nlohmann::json::parse(json_str)); + ten_shared_ptr_t *c_cmd_result = + ten_shared_ptr_clone(ten_smart_ptr_listnode_get(iter.node)); + TEN_ASSERT(c_cmd_result, "Should not happen."); - ten_json_destroy(c_json); - if (must_free) { - TEN_FREE( - json_str); // NOLINT(cppcoreguidelines-no-malloc, hicpp-no-malloc) - } + auto cmd_result = + ten::cmd_result_internal_accessor_t::create(c_cmd_result); + results.push_back(std::move(cmd_result)); } ten_list_clear(&msgs); diff --git a/tests/common/client/msgpack_tcp.c b/tests/common/client/msgpack_tcp.c index 7354135da..a7eab6b00 100644 --- a/tests/common/client/msgpack_tcp.c +++ b/tests/common/client/msgpack_tcp.c @@ -6,6 +6,8 @@ // #include "tests/common/client/msgpack_tcp.h" +#include + #include "core_protocols/msgpack/common/parser.h" #include "core_protocols/msgpack/msg/msg.h" #include "include_internal/ten_runtime/msg/msg.h" diff --git a/tests/ten_runtime/integration/cpp/graph_env_var_1/client/client.cc b/tests/ten_runtime/integration/cpp/graph_env_var_1/client/client.cc index c5a28089c..1403ed1c9 100644 --- a/tests/ten_runtime/integration/cpp/graph_env_var_1/client/client.cc +++ b/tests/ten_runtime/integration/cpp/graph_env_var_1/client/client.cc @@ -13,12 +13,9 @@ int main(int argc, char **argv) { auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension", "addon": "default_extension_cpp", @@ -29,28 +26,21 @@ int main(int argc, char **argv) { } }] } - })"_json); - TEN_ASSERT(TEN_STATUS_CODE_OK == resp["_ten"]["status_code"], + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + TEN_ASSERT(TEN_STATUS_CODE_OK == cmd_result->get_status_code(), "Should not happen."); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group", - "extension": "test_extension" - }] - } - })"_json); - TEN_ASSERT(TEN_STATUS_CODE_OK == resp["_ten"]["status_code"], - "Should not happen."); - TEN_ASSERT(static_cast("137") == resp["_ten"]["seq_id"], + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group", "test_extension"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + TEN_ASSERT(TEN_STATUS_CODE_OK == cmd_result->get_status_code(), "Should not happen."); - TEN_ASSERT(static_cast("hello world, too") == resp["detail"], + TEN_ASSERT(static_cast("hello world, too") == + cmd_result->get_property_string("detail"), "Should not happen."); delete client; diff --git a/tests/ten_runtime/integration/cpp/graph_env_var_2/client/client.cc b/tests/ten_runtime/integration/cpp/graph_env_var_2/client/client.cc index c5a28089c..1403ed1c9 100644 --- a/tests/ten_runtime/integration/cpp/graph_env_var_2/client/client.cc +++ b/tests/ten_runtime/integration/cpp/graph_env_var_2/client/client.cc @@ -13,12 +13,9 @@ int main(int argc, char **argv) { auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension", "addon": "default_extension_cpp", @@ -29,28 +26,21 @@ int main(int argc, char **argv) { } }] } - })"_json); - TEN_ASSERT(TEN_STATUS_CODE_OK == resp["_ten"]["status_code"], + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + TEN_ASSERT(TEN_STATUS_CODE_OK == cmd_result->get_status_code(), "Should not happen."); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group", - "extension": "test_extension" - }] - } - })"_json); - TEN_ASSERT(TEN_STATUS_CODE_OK == resp["_ten"]["status_code"], - "Should not happen."); - TEN_ASSERT(static_cast("137") == resp["_ten"]["seq_id"], + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group", "test_extension"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + TEN_ASSERT(TEN_STATUS_CODE_OK == cmd_result->get_status_code(), "Should not happen."); - TEN_ASSERT(static_cast("hello world, too") == resp["detail"], + TEN_ASSERT(static_cast("hello world, too") == + cmd_result->get_property_string("detail"), "Should not happen."); delete client; diff --git a/tests/ten_runtime/integration/cpp/graph_env_var_3/client/client.cc b/tests/ten_runtime/integration/cpp/graph_env_var_3/client/client.cc index 9fa8b1047..63e7a5324 100644 --- a/tests/ten_runtime/integration/cpp/graph_env_var_3/client/client.cc +++ b/tests/ten_runtime/integration/cpp/graph_env_var_3/client/client.cc @@ -13,12 +13,9 @@ int main(int argc, char **argv) { auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension", "addon": "default_extension_cpp", @@ -29,28 +26,21 @@ int main(int argc, char **argv) { } }] } - })"_json); - TEN_ASSERT(TEN_STATUS_CODE_OK == resp["_ten"]["status_code"], + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + TEN_ASSERT(TEN_STATUS_CODE_OK == cmd_result->get_status_code(), "Should not happen."); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group", - "extension": "test_extension" - }] - } - })"_json); - TEN_ASSERT(TEN_STATUS_CODE_OK == resp["_ten"]["status_code"], - "Should not happen."); - TEN_ASSERT(static_cast("137") == resp["_ten"]["seq_id"], + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group", "test_extension"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + TEN_ASSERT(TEN_STATUS_CODE_OK == cmd_result->get_status_code(), "Should not happen."); - TEN_ASSERT(static_cast("hello world, too") == resp["detail"], + TEN_ASSERT(static_cast("hello world, too") == + cmd_result->get_property_string("detail"), "Should not happen."); delete client; diff --git a/tests/ten_runtime/integration/cpp/hello_world/client/client.cc b/tests/ten_runtime/integration/cpp/hello_world/client/client.cc index d83e1af44..62eeaf175 100644 --- a/tests/ten_runtime/integration/cpp/hello_world/client/client.cc +++ b/tests/ten_runtime/integration/cpp/hello_world/client/client.cc @@ -13,12 +13,9 @@ int main(int argc, char **argv) { auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension", "addon": "default_extension_cpp", @@ -26,28 +23,21 @@ int main(int argc, char **argv) { "extension_group": "test_extension_group" }] } - })"_json); - TEN_ASSERT(TEN_STATUS_CODE_OK == resp["_ten"]["status_code"], + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + TEN_ASSERT(TEN_STATUS_CODE_OK == cmd_result->get_status_code(), "Should not happen."); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group", - "extension": "test_extension" - }] - } - })"_json); - TEN_ASSERT(TEN_STATUS_CODE_OK == resp["_ten"]["status_code"], - "Should not happen."); - TEN_ASSERT(static_cast("137") == resp["_ten"]["seq_id"], + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group", "test_extension"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + TEN_ASSERT(TEN_STATUS_CODE_OK == cmd_result->get_status_code(), "Should not happen."); - TEN_ASSERT(static_cast("hello world, too") == resp["detail"], + TEN_ASSERT(static_cast("hello world, too") == + cmd_result->get_property_string("detail"), "Should not happen."); delete client; diff --git a/tests/ten_runtime/integration/cpp/multi_apps/client/client.cc b/tests/ten_runtime/integration/cpp/multi_apps/client/client.cc index d2261fc94..d268c9e0c 100644 --- a/tests/ten_runtime/integration/cpp/multi_apps/client/client.cc +++ b/tests/ten_runtime/integration/cpp/multi_apps/client/client.cc @@ -6,6 +6,7 @@ // #include +#include "ten_runtime/binding/cpp/internal/msg/cmd/start_graph.h" #include "ten_utils/macro/check.h" #include "tests/common/client/cpp/msgpack_tcp.h" @@ -17,12 +18,9 @@ void test_extension_in_app1_not_installed() { // Send a start_graph cmd to app 8001. However, because there is no extension // addon named `ext_e` in app 8001, the `start_graph` command will fail. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "ext_a", "addon": "ext_e", @@ -36,11 +34,13 @@ void test_extension_in_app1_not_installed() { "extension_group": "test_extension_group" }] } - })"_json); - TEN_ASSERT(TEN_STATUS_CODE_ERROR == resp["_ten"]["status_code"], + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + TEN_ASSERT(TEN_STATUS_CODE_ERROR == cmd_result->get_status_code(), "Should not happen."); - auto detail = resp.value("detail", ""); + auto detail = cmd_result->get_property_string("detail"); // NOLINTNEXTLINE TEN_ASSERT(!detail.empty() && detail.find("ext_e") != std::string::npos, "Should not happen."); @@ -54,11 +54,10 @@ void test_extension_in_app2_not_installed() { // Send a start_graph cmd to app 8001. However, because there is no extension // addon named `ext_e` in app 8002, the `start_graph` command will fail. - auto resp = client->send_json_and_recv_resp_in_json( + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json( R"({ "_ten": { - "type": "start_graph", - "seq_id": "56", "nodes": [{ "type": "extension", "name": "ext_a", @@ -86,11 +85,13 @@ void test_extension_in_app2_not_installed() { }] }] } - })"_json); - TEN_ASSERT(TEN_STATUS_CODE_ERROR == resp["_ten"]["status_code"], + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + TEN_ASSERT(TEN_STATUS_CODE_ERROR == cmd_result->get_status_code(), "Should not happen."); - auto detail = resp.value("detail", ""); + auto detail = cmd_result->get_property_string("detail"); // NOLINTNEXTLINE TEN_ASSERT(!detail.empty() && detail.find("ext_e") != std::string::npos, "Should not happen."); @@ -107,11 +108,10 @@ int main(int argc, char **argv) { // Create a client and connect to the app. auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); - auto resp = client->send_json_and_recv_resp_in_json( + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json( R"({ "_ten": { - "type": "start_graph", - "seq_id": "55", "nodes": [{ "type": "extension", "name": "ext_a", @@ -120,28 +120,21 @@ int main(int argc, char **argv) { "extension_group": "test_extension_group" }] } - })"_json); - TEN_ASSERT(TEN_STATUS_CODE_OK == resp["_ten"]["status_code"], + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + TEN_ASSERT(TEN_STATUS_CODE_OK == cmd_result->get_status_code(), "Should not happen."); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group", - "extension": "ext_a" - }] - } - })"_json); - TEN_ASSERT(TEN_STATUS_CODE_OK == resp["_ten"]["status_code"], - "Should not happen."); - TEN_ASSERT(static_cast("137") == resp["_ten"]["seq_id"], + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group", "ext_a"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + TEN_ASSERT(TEN_STATUS_CODE_OK == cmd_result->get_status_code(), "Should not happen."); - TEN_ASSERT(static_cast("hello world, too") == resp["detail"], + TEN_ASSERT(static_cast("hello world, too") == + cmd_result->get_property_string("detail"), "Should not happen."); client->close_app(); diff --git a/tests/ten_runtime/integration/go/access_property_go/client/client.cc b/tests/ten_runtime/integration/go/access_property_go/client/client.cc index b4061f186..9c06f3ec5 100644 --- a/tests/ten_runtime/integration/go/access_property_go/client/client.cc +++ b/tests/ten_runtime/integration/go/access_property_go/client/client.cc @@ -13,26 +13,17 @@ int main(TEN_UNUSED int argc, TEN_UNUSED char **argv) { // Create a client and connect to the app. auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8007/"); - nlohmann::json resp = client->send_json_and_recv_resp_in_json(R"({ - "_ten": { - "name": "test", - "seq_id": "111", - "dest": [{ - "app": "msgpack://127.0.0.1:8007/", - "graph": "default", - "extension_group": "nodetest", - "extension": "A" - }] - } - })"_json); - TEN_ASSERT(TEN_STATUS_CODE_OK == resp["_ten"]["status_code"], + auto test_cmd = ten::cmd_t::create("test"); + test_cmd->set_dest("msgpack://127.0.0.1:8007/", "default", "nodetest", "A"); + auto cmd_result = client->send_cmd_and_recv_result(std::move(test_cmd)); + TEN_ASSERT(TEN_STATUS_CODE_OK == cmd_result->get_status_code(), "Should not happen."); TEN_LOGD("Got graph result."); - std::string resp_str = resp["detail"]; - TEN_LOGD("Got result: %s", resp_str.c_str()); - TEN_ASSERT(resp_str == std::string("okok"), "Should not happen."); + std::string detail_str = cmd_result->get_property_string("detail"); + TEN_LOGD("Got result: %s", detail_str.c_str()); + TEN_ASSERT(detail_str == std::string("okok"), "Should not happen."); // NOTE the order: client destroy, then connection lost, then nodejs exits. delete client; diff --git a/tests/ten_runtime/integration/go/close_app_go/client/client.cc b/tests/ten_runtime/integration/go/close_app_go/client/client.cc index b33d13d07..056d0d170 100644 --- a/tests/ten_runtime/integration/go/close_app_go/client/client.cc +++ b/tests/ten_runtime/integration/go/close_app_go/client/client.cc @@ -13,20 +13,11 @@ int main(TEN_UNUSED int argc, TEN_UNUSED char **argv) { // Create a client and connect to the app. auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8007/"); - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello", - "seq_id": "238", - "dest": [{ - "app": "msgpack://127.0.0.1:8007/", - "graph": "default", - "extension_group": "default_extension_group", - "extension": "default_extension_go" - }] - } - })"_json); - TEN_ASSERT(TEN_STATUS_CODE_OK == resp["_ten"]["status_code"], + auto hello_cmd = ten::cmd_t::create("hello"); + hello_cmd->set_dest("msgpack://127.0.0.1:8007/", "default", + "default_extension_group", "default_extension_go"); + auto cmd_result = client->send_cmd_and_recv_result(std::move(hello_cmd)); + TEN_ASSERT(TEN_STATUS_CODE_OK == cmd_result->get_status_code(), "Should not happen."); // NOTE the order: client destroy, then connection lost, then nodejs exits diff --git a/tests/ten_runtime/integration/go/expired_ten_go/client/client.cc b/tests/ten_runtime/integration/go/expired_ten_go/client/client.cc index 14bbb9fcb..106811975 100644 --- a/tests/ten_runtime/integration/go/expired_ten_go/client/client.cc +++ b/tests/ten_runtime/integration/go/expired_ten_go/client/client.cc @@ -14,25 +14,16 @@ int main(TEN_UNUSED int argc, TEN_UNUSED char **argv) { // Create a client and connect to the app. auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8007/"); - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello", - "seq_id": "238", - "dest": [{ - "app": "msgpack://127.0.0.1:8007/", - "graph": "default", - "extension_group": "default_extension_group", - "extension": "extension_a" - }] - } - })"_json); - TEN_ASSERT(TEN_STATUS_CODE_OK == resp["_ten"]["status_code"], + auto hello_cmd = ten::cmd_t::create("hello"); + hello_cmd->set_dest("msgpack://127.0.0.1:8007/", "default", + "default_extension_group", "extension_a"); + auto cmd_result = client->send_cmd_and_recv_result(std::move(hello_cmd)); + TEN_ASSERT(TEN_STATUS_CODE_OK == cmd_result->get_status_code(), "Should not happen."); - std::string resp_str = resp["detail"]; - TEN_LOGD("got result: %s", resp_str.c_str()); - TEN_ASSERT(resp_str == std::string("ten"), "Should not happen."); + std::string detail_str = cmd_result->get_property_string("detail"); + TEN_LOGD("got result: %s", detail_str.c_str()); + TEN_ASSERT(detail_str == std::string("ten"), "Should not happen."); // NOTE the order: client destroy, then connection lost, then nodejs exits delete client; diff --git a/tests/ten_runtime/integration/go/frequently_cgo_call_go/client/client.cc b/tests/ten_runtime/integration/go/frequently_cgo_call_go/client/client.cc index 319cf3654..7872d4618 100644 --- a/tests/ten_runtime/integration/go/frequently_cgo_call_go/client/client.cc +++ b/tests/ten_runtime/integration/go/frequently_cgo_call_go/client/client.cc @@ -14,25 +14,16 @@ int main(TEN_UNUSED int argc, TEN_UNUSED char **argv) { // Create a client and connect to the app. auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8007/"); - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello", - "seq_id": "238", - "dest": [{ - "app": "msgpack://127.0.0.1:8007/", - "graph": "default", - "extension_group": "default_extension_group", - "extension": "extension_a" - }] - } - })"_json); - TEN_ASSERT(TEN_STATUS_CODE_OK == resp["_ten"]["status_code"], + auto hello_cmd = ten::cmd_t::create("hello"); + hello_cmd->set_dest("msgpack://127.0.0.1:8007/", "default", + "default_extension_group", "extension_a"); + auto cmd_result = client->send_cmd_and_recv_result(std::move(hello_cmd)); + TEN_ASSERT(TEN_STATUS_CODE_OK == cmd_result->get_status_code(), "Should not happen."); - std::string resp_str = resp["detail"]; - TEN_LOGD("got result: %s", resp_str.c_str()); - TEN_ASSERT(resp_str == std::string("password"), "Should not happen."); + std::string detail_str = cmd_result->get_property_string("detail"); + TEN_LOGD("got result: %s", detail_str.c_str()); + TEN_ASSERT(detail_str == std::string("password"), "Should not happen."); // NOTE the order: client destroy, then connection lost, then nodejs exits delete client; diff --git a/tests/ten_runtime/integration/go/handle_error_go/client/client.cc b/tests/ten_runtime/integration/go/handle_error_go/client/client.cc index 1a93bc4c4..7e8f72b9e 100644 --- a/tests/ten_runtime/integration/go/handle_error_go/client/client.cc +++ b/tests/ten_runtime/integration/go/handle_error_go/client/client.cc @@ -13,24 +13,15 @@ int main(TEN_UNUSED int argc, TEN_UNUSED char **argv) { // Create a client and connect to the app. auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8007/"); - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello", - "seq_id": "238", - "dest": [{ - "app": "msgpack://127.0.0.1:8007/", - "graph": "default", - "extension_group": "default_extension_group", - "extension": "extension_a" - }] - } - })"_json); - TEN_ASSERT(TEN_STATUS_CODE_ERROR == resp["_ten"]["status_code"], + auto hello_cmd = ten::cmd_t::create("hello"); + hello_cmd->set_dest("msgpack://127.0.0.1:8007/", "default", + "default_extension_group", "extension_a"); + auto cmd_result = client->send_cmd_and_recv_result(std::move(hello_cmd)); + TEN_ASSERT(TEN_STATUS_CODE_ERROR == cmd_result->get_status_code(), "Should not happen."); - std::string resp_str = resp["detail"]; - TEN_LOGD("got result: %s", resp_str.c_str()); + std::string detail_str = cmd_result->get_property_string("detail"); + TEN_LOGD("got result: %s", detail_str.c_str()); // NOTE the order: client destroy, then connection lost, then nodejs exits delete client; diff --git a/tests/ten_runtime/integration/go/prepare_to_stop_go/client/client.cc b/tests/ten_runtime/integration/go/prepare_to_stop_go/client/client.cc index 221f61c83..caca11c8d 100644 --- a/tests/ten_runtime/integration/go/prepare_to_stop_go/client/client.cc +++ b/tests/ten_runtime/integration/go/prepare_to_stop_go/client/client.cc @@ -13,23 +13,14 @@ int main(TEN_UNUSED int argc, TEN_UNUSED char **argv) { // Create a client and connect to the app. auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8007/"); - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "start", - "seq_id": "238", - "dest": [{ - "app": "msgpack://127.0.0.1:8007/", - "graph": "default", - "extension_group": "nodetest_group", - "extension": "A" - }] - } - })"_json); - TEN_ASSERT(TEN_STATUS_CODE_OK == resp["_ten"]["status_code"], + auto start_cmd = ten::cmd_t::create("start"); + start_cmd->set_dest("msgpack://127.0.0.1:8007/", "default", "nodetest_group", + "A"); + auto cmd_result = client->send_cmd_and_recv_result(std::move(start_cmd)); + TEN_ASSERT(TEN_STATUS_CODE_OK == cmd_result->get_status_code(), "Should not happen."); - std::string resp_str = resp["detail"]; + std::string resp_str = cmd_result->get_property_string("detail"); TEN_LOGD("got result: %s", resp_str.c_str()); TEN_ASSERT(resp_str == "done", "Should not happen."); diff --git a/tests/ten_runtime/integration/go/return_result_go/client/client.cc b/tests/ten_runtime/integration/go/return_result_go/client/client.cc index 848d359cf..3923aaa3c 100644 --- a/tests/ten_runtime/integration/go/return_result_go/client/client.cc +++ b/tests/ten_runtime/integration/go/return_result_go/client/client.cc @@ -13,23 +13,14 @@ int main(TEN_UNUSED int argc, TEN_UNUSED char **argv) { // Create a client and connect to the app. auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8007/"); - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello", - "seq_id": "238", - "dest": [{ - "app": "msgpack://127.0.0.1:8007/", - "graph": "default", - "extension_group": "default_extension_group", - "extension": "extension_a" - }] - } - })"_json); - TEN_ASSERT(TEN_STATUS_CODE_OK == resp["_ten"]["status_code"], + auto hello_cmd = ten::cmd_t::create("hello"); + hello_cmd->set_dest("msgpack://127.0.0.1:8007/", "default", + "default_extension_group", "extension_a"); + auto cmd_result = client->send_cmd_and_recv_result(std::move(hello_cmd)); + TEN_ASSERT(TEN_STATUS_CODE_OK == cmd_result->get_status_code(), "Should not happen."); - std::string resp_str = resp["detail"]; + std::string resp_str = cmd_result->get_property_string("detail"); TEN_LOGD("got result: %s", resp_str.c_str()); TEN_ASSERT(resp_str == std::string("password"), "Should not happen."); diff --git a/tests/ten_runtime/integration/go/return_value_go/client/client.cc b/tests/ten_runtime/integration/go/return_value_go/client/client.cc index 14bbe444e..c5d42858e 100644 --- a/tests/ten_runtime/integration/go/return_value_go/client/client.cc +++ b/tests/ten_runtime/integration/go/return_value_go/client/client.cc @@ -13,23 +13,14 @@ int main(TEN_UNUSED int argc, TEN_UNUSED char **argv) { // Create a client and connect to the app. auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8007/"); - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello", - "seq_id": "238", - "dest": [{ - "app": "msgpack://127.0.0.1:8007/", - "graph": "default", - "extension_group": "default_extension_group", - "extension": "extension_a" - }] - } - })"_json); - TEN_ASSERT(TEN_STATUS_CODE_OK == resp["_ten"]["status_code"], + auto hello_cmd = ten::cmd_t::create("hello"); + hello_cmd->set_dest("msgpack://127.0.0.1:8007/", "default", + "default_extension_group", "extension_a"); + auto cmd_result = client->send_cmd_and_recv_result(std::move(hello_cmd)); + TEN_ASSERT(TEN_STATUS_CODE_OK == cmd_result->get_status_code(), "Should not happen."); - std::string resp_str = resp["detail"]; + std::string resp_str = cmd_result->get_property_string("detail"); TEN_LOGD("got result: %s", resp_str.c_str()); TEN_ASSERT(resp_str == std::string("ten"), "Should not happen."); diff --git a/tests/ten_runtime/integration/go/start_app_sync_go/client/client.cc b/tests/ten_runtime/integration/go/start_app_sync_go/client/client.cc index b33d13d07..056d0d170 100644 --- a/tests/ten_runtime/integration/go/start_app_sync_go/client/client.cc +++ b/tests/ten_runtime/integration/go/start_app_sync_go/client/client.cc @@ -13,20 +13,11 @@ int main(TEN_UNUSED int argc, TEN_UNUSED char **argv) { // Create a client and connect to the app. auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8007/"); - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello", - "seq_id": "238", - "dest": [{ - "app": "msgpack://127.0.0.1:8007/", - "graph": "default", - "extension_group": "default_extension_group", - "extension": "default_extension_go" - }] - } - })"_json); - TEN_ASSERT(TEN_STATUS_CODE_OK == resp["_ten"]["status_code"], + auto hello_cmd = ten::cmd_t::create("hello"); + hello_cmd->set_dest("msgpack://127.0.0.1:8007/", "default", + "default_extension_group", "default_extension_go"); + auto cmd_result = client->send_cmd_and_recv_result(std::move(hello_cmd)); + TEN_ASSERT(TEN_STATUS_CODE_OK == cmd_result->get_status_code(), "Should not happen."); // NOTE the order: client destroy, then connection lost, then nodejs exits diff --git a/tests/ten_runtime/integration/go/three_extension_cmd_go/client/client.cc b/tests/ten_runtime/integration/go/three_extension_cmd_go/client/client.cc index d3f3669bb..85c274bb4 100644 --- a/tests/ten_runtime/integration/go/three_extension_cmd_go/client/client.cc +++ b/tests/ten_runtime/integration/go/three_extension_cmd_go/client/client.cc @@ -14,11 +14,9 @@ int main(TEN_UNUSED int argc, TEN_UNUSED char **argv) { // Create a client and connect to the app. auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8007/"); - nlohmann::json resp = client->send_json_and_recv_resp_in_json(R"({ - "_ten": { - "type": "start_graph", - "seq_id": "156", - "nodes": [ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [ { "type": "extension", "app": "msgpack://127.0.0.1:8007/", @@ -70,30 +68,22 @@ int main(TEN_UNUSED int argc, TEN_UNUSED char **argv) { } ] } - })"_json); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); TEN_LOGD("client sent json"); - TEN_ASSERT(TEN_STATUS_CODE_OK == resp["_ten"]["status_code"], + TEN_ASSERT(TEN_STATUS_CODE_OK == cmd_result->get_status_code(), "Should not happen."); TEN_LOGD("got graph result"); - - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "A", - "seq_id": "238", - "dest": [{ - "app": "msgpack://127.0.0.1:8007/", - "extension_group": "nodetest_group", - "extension": "A" - }] - } - })"_json); - TEN_ASSERT(TEN_STATUS_CODE_OK == resp["_ten"]["status_code"], + auto A_cmd = ten::cmd_t::create("A"); + A_cmd->set_dest("msgpack://127.0.0.1:8007/", nullptr, "nodetest_group", "A"); + cmd_result = client->send_cmd_and_recv_result(std::move(A_cmd)); + TEN_ASSERT(TEN_STATUS_CODE_OK == cmd_result->get_status_code(), "Should not happen."); - std::string resp_str = resp["detail"]; + std::string resp_str = cmd_result->get_property_string("detail"); TEN_LOGD("got result: %s", resp_str.c_str()); ten_json_t *result = ten_json_from_string(resp_str.c_str(), NULL); TEN_ASSERT( diff --git a/tests/ten_runtime/integration/go/transfer_pointer_go/client/client.cc b/tests/ten_runtime/integration/go/transfer_pointer_go/client/client.cc index 0d2c1a815..c5d42858e 100644 --- a/tests/ten_runtime/integration/go/transfer_pointer_go/client/client.cc +++ b/tests/ten_runtime/integration/go/transfer_pointer_go/client/client.cc @@ -13,23 +13,14 @@ int main(TEN_UNUSED int argc, TEN_UNUSED char **argv) { // Create a client and connect to the app. auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8007/"); - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello", - "seq_id": "238", - "dest": [{ - "app": "msgpack://127.0.0.1:8007/", - "graph": "default", - "extension_group": "default_extension_group", - "extension": "extension_a" - }] - } - })"_json); - TEN_ASSERT(TEN_STATUS_CODE_OK == resp["_ten"]["status_code"], + auto hello_cmd = ten::cmd_t::create("hello"); + hello_cmd->set_dest("msgpack://127.0.0.1:8007/", "default", + "default_extension_group", "extension_a"); + auto cmd_result = client->send_cmd_and_recv_result(std::move(hello_cmd)); + TEN_ASSERT(TEN_STATUS_CODE_OK == cmd_result->get_status_code(), "Should not happen."); - std::string resp_str = resp["detail"]; + std::string resp_str = cmd_result->get_property_string("detail"); TEN_LOGD("got result: %s", resp_str.c_str()); TEN_ASSERT(resp_str == std::string("ten"), "Should not happen."); diff --git a/tests/ten_runtime/integration/go/two_extension_one_group_cmd_go/client/client.cc b/tests/ten_runtime/integration/go/two_extension_one_group_cmd_go/client/client.cc index a6bfcb88e..81c0ce2ba 100644 --- a/tests/ten_runtime/integration/go/two_extension_one_group_cmd_go/client/client.cc +++ b/tests/ten_runtime/integration/go/two_extension_one_group_cmd_go/client/client.cc @@ -13,11 +13,9 @@ int main(TEN_UNUSED int argc, TEN_UNUSED char **argv) { // Create a client and connect to the app. auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8007/"); - nlohmann::json resp = client->send_json_and_recv_resp_in_json(R"({ - "_ten": { - "type": "start_graph", - "seq_id": "156", - "nodes": [ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [ { "type": "extension", "app": "msgpack://127.0.0.1:8007/", @@ -49,27 +47,20 @@ int main(TEN_UNUSED int argc, TEN_UNUSED char **argv) { } ] } - })"_json); - TEN_ASSERT(TEN_STATUS_CODE_OK == resp["_ten"]["status_code"], + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + TEN_ASSERT(TEN_STATUS_CODE_OK == cmd_result->get_status_code(), "Should not happen."); TEN_LOGD("Got graph result."); - - resp = client->send_json_and_recv_resp_in_json(R"({ - "_ten": { - "name": "A", - "seq_id": "100", - "dest": [{ - "app": "msgpack://127.0.0.1:8007/", - "extension_group": "nodetest", - "extension": "A" - }] - } - })"_json); - TEN_ASSERT(TEN_STATUS_CODE_OK == resp["_ten"]["status_code"], + auto A_cmd = ten::cmd_t::create("A"); + A_cmd->set_dest("msgpack://127.0.0.1:8007/", nullptr, "nodetest", "A"); + cmd_result = client->send_cmd_and_recv_result(std::move(A_cmd)); + TEN_ASSERT(TEN_STATUS_CODE_OK == cmd_result->get_status_code(), "Should not happen."); - std::string resp_str = resp["detail"]; + std::string resp_str = cmd_result->get_property_string("detail"); TEN_LOGD("Got result: %s", resp_str.c_str()); TEN_ASSERT(resp_str == std::string("world"), "Should not happen."); diff --git a/tests/ten_runtime/smoke/audio_frame_test/basic.cc b/tests/ten_runtime/smoke/audio_frame_test/basic.cc index c88637718..cc1205819 100644 --- a/tests/ten_runtime/smoke/audio_frame_test/basic.cc +++ b/tests/ten_runtime/smoke/audio_frame_test/basic.cc @@ -94,12 +94,9 @@ TEST(AudioFrameTest, Basic) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "audio_frame_basic__test_extension_1", @@ -138,24 +135,18 @@ TEST(AudioFrameTest, Basic) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/audio_frame_test/create_from_json.cc b/tests/ten_runtime/smoke/audio_frame_test/create_from_json.cc index 84f77aa02..9feb085af 100644 --- a/tests/ten_runtime/smoke/audio_frame_test/create_from_json.cc +++ b/tests/ten_runtime/smoke/audio_frame_test/create_from_json.cc @@ -109,12 +109,9 @@ TEST(AudioFrameTest, CreateFromJson) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "audio_frame_create_from_json__test_extension_1", @@ -153,24 +150,18 @@ TEST(AudioFrameTest, CreateFromJson) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/audio_frame_test/from_json.cc b/tests/ten_runtime/smoke/audio_frame_test/from_json.cc index 85c52c798..5b31c7220 100644 --- a/tests/ten_runtime/smoke/audio_frame_test/from_json.cc +++ b/tests/ten_runtime/smoke/audio_frame_test/from_json.cc @@ -26,21 +26,14 @@ class test_extension_1 : public ten::extension_t { hello_world_cmd = std::move(cmd); auto audio_frame = ten::audio_frame_t::create("audio_frame"); - audio_frame->from_json( - // clang-format off - R"({ - "_ten": { - "data_fmt": 1, - "bytes_per_sample": 3, - "channel_layout": 2, - "line_size": 100, - "number_of_channel": 555, - "sample_rate": 543, - "timestamp": 12341234 - } - })" - // clang-format on - ); + audio_frame->set_data_fmt(TEN_AUDIO_FRAME_DATA_FMT_INTERLEAVE); + audio_frame->set_bytes_per_sample(3); + audio_frame->set_channel_layout(2); + audio_frame->set_line_size(100); + audio_frame->set_number_of_channels(555); + audio_frame->set_sample_rate(543); + audio_frame->set_timestamp(12341234); + ten_env.send_audio_frame(std::move(audio_frame)); } else if (std::string(cmd->get_name()) == "audio_frame_ack") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); @@ -61,10 +54,9 @@ class test_extension_2 : public ten::extension_t { ten::ten_env_t &ten_env, std::unique_ptr audio_frame) override { auto cmd = ten::cmd_t::create("audio_frame_ack"); - if (audio_frame->get_property_int64("_ten.bytes_per_sample") == 3 && - audio_frame->get_property_int64("_ten.number_of_channel") == 555 && - audio_frame->get_property_int64("_ten.data_fmt") == - TEN_AUDIO_FRAME_DATA_FMT_INTERLEAVE) { + if (audio_frame->get_bytes_per_sample() == 3 && + audio_frame->get_number_of_channels() == 555 && + audio_frame->get_data_fmt() == TEN_AUDIO_FRAME_DATA_FMT_INTERLEAVE) { ten_env.send_cmd(std::move(cmd)); } } @@ -114,12 +106,9 @@ TEST(AudioFrameTest, FromJson) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + bool rc = start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "audio_frame_from_json__test_extension_1", @@ -158,24 +147,19 @@ TEST(AudioFrameTest, FromJson) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + TEN_ASSERT(rc, "Should not happen."); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/audio_frame_test/multi_dest_pcm_frame.cc b/tests/ten_runtime/smoke/audio_frame_test/multi_dest_pcm_frame.cc index bf4d97d5d..f0b0f599a 100644 --- a/tests/ten_runtime/smoke/audio_frame_test/multi_dest_pcm_frame.cc +++ b/tests/ten_runtime/smoke/audio_frame_test/multi_dest_pcm_frame.cc @@ -43,8 +43,7 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "dispatch_data") { + if (std::string(cmd->get_name()) == "dispatch_data") { auto audio_frame = createEmptyAudioFrame(SAMPLE_RATE, NUM_OF_CHANNELS); audio_frame->set_property("test_prop", "test_prop_value"); @@ -75,8 +74,7 @@ class test_extension_2 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "check_received") { + if (std::string(cmd->get_name()) == "check_received") { if (received) { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "received confirmed"); @@ -111,8 +109,7 @@ class test_extension_3 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "check_received") { + if (std::string(cmd->get_name()) == "check_received") { if (received) { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "received confirmed"); @@ -175,12 +172,9 @@ TEST(AudioFrameTest, MultiDestAudioFrame) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "extension 1", "addon": "multi_dest_audio_frame__extension_1", @@ -217,55 +211,40 @@ TEST(AudioFrameTest, MultiDestAudioFrame) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'dispatch_data' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "dispatch_data", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group", - "extension": "extension 1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, "done"); - - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "check_received", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group", - "extension": "extension 2" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "received confirmed"); - - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "check_received", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group", - "extension": "extension 3" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "received confirmed"); + auto dispatch_data_cmd = ten::cmd_t::create("dispatch_data"); + dispatch_data_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group", "extension 1"); + + cmd_result = client->send_cmd_and_recv_result(std::move(dispatch_data_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "done"); + + auto check_received_cmd = ten::cmd_t::create("check_received"); + check_received_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group", "extension 2"); + + cmd_result = client->send_cmd_and_recv_result(std::move(check_received_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "received confirmed"); + + check_received_cmd = ten::cmd_t::create("check_received"); + check_received_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group", "extension 3"); + + cmd_result = client->send_cmd_and_recv_result(std::move(check_received_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "received confirmed"); delete client; ten_thread_join(app_thread, -1); -} \ No newline at end of file +} diff --git a/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_connect_cmd.cc b/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_connect_cmd.cc index 160231a87..be3d724c1 100644 --- a/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_connect_cmd.cc +++ b/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_connect_cmd.cc @@ -6,7 +6,6 @@ // #include #include -#include #include "gtest/gtest.h" #include "include_internal/ten_runtime/binding/cpp/ten.h" @@ -22,9 +21,7 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { ten_env.send_cmd(std::move(cmd)); return; } @@ -37,8 +34,7 @@ class test_extension_2 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_mapping") { + if (std::string(cmd->get_name()) == "hello_mapping") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -90,11 +86,10 @@ TEST(CmdConversionTest, CmdConversionConnectCmd) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json connect_resp = client->send_json_and_recv_resp_in_json( + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json( R"###({ "_ten": { - "type": "start_graph", - "seq_id": "55", "nodes": [{ "type": "extension", "name": "test_extension_1", @@ -130,24 +125,21 @@ TEST(CmdConversionTest, CmdConversionConnectCmd) { // NOLINT }] }] } - })###"_json); - ten_test::check_status_code_is(connect_resp, TEN_STATUS_CODE_OK); + })###"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "cmd_conversion_connect_cmd_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "cmd_conversion_connect_cmd_extension_group", + "test_extension_1"); + + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_data.cc b/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_data.cc index 5f9b3ae98..abc9a1ad3 100644 --- a/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_data.cc +++ b/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_data.cc @@ -21,9 +21,7 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - - if (json["_ten"]["name"] == "send_data") { + if (std::string(cmd->get_name()) == "send_data") { auto data = ten::data_t::create("aaa"); data->set_property("prop_bool", true); ten_env.send_data(std::move(data)); @@ -42,8 +40,7 @@ class test_extension_2 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "data_received_check") { + if (std::string(cmd->get_name()) == "data_received_check") { if (data_received) { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "data received"); @@ -182,36 +179,23 @@ TEST(CmdConversionTest, CmdConversionData) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send a user-defined 'send_data' command. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "send_data", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "cmd_mapping_data_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, "data sent"); + auto send_data_cmd = ten::cmd_t::create("send_data"); + send_data_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "cmd_mapping_data_extension_group", + "test_extension_1"); + auto cmd_result = client->send_cmd_and_recv_result(std::move(send_data_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "data sent"); // Send 'data_received_check' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "data_received_check", - "seq_id": "138", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "cmd_mapping_data_extension_group", - "extension": "test_extension_2" - }] - } - })"_json); - ten_test::check_result_is(resp, "138", TEN_STATUS_CODE_OK, "data received"); + auto data_received_check_cmd = ten::cmd_t::create("data_received_check"); + data_received_check_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "cmd_mapping_data_extension_group", + "test_extension_2"); + cmd_result = + client->send_cmd_and_recv_result(std::move(data_received_check_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "data received"); delete client; diff --git a/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_graph.cc b/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_graph.cc index 75f58a12f..fcfe3e5c6 100644 --- a/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_graph.cc +++ b/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_graph.cc @@ -21,9 +21,7 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { ten_env.send_cmd(std::move(cmd)); return; } @@ -36,8 +34,7 @@ class test_extension_2 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_mapping") { + if (std::string(cmd->get_name()) == "hello_mapping") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -139,21 +136,13 @@ TEST(CmdConversionTest, CmdConversionGraph) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send a user-defined 'hello world' command. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "default_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "default_extension_group", "test_extension_1"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_graph_default_uri.cc b/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_graph_default_uri.cc index 115cefedd..e8b57e814 100644 --- a/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_graph_default_uri.cc +++ b/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_graph_default_uri.cc @@ -6,7 +6,6 @@ // #include #include -#include #include "gtest/gtest.h" #include "include_internal/ten_runtime/binding/cpp/ten.h" @@ -22,9 +21,7 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { ten_env.send_cmd(std::move(cmd)); } } @@ -36,8 +33,7 @@ class test_extension_2 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_mapping") { + if (std::string(cmd->get_name()) == "hello_mapping") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -138,21 +134,14 @@ TEST(CmdConversionTest, CmdConversionGraphDefaultUri) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send a user-defined 'hello world' command. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "cmd_conversion_graph_default_uri_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "cmd_conversion_graph_default_uri_extension_group", + "test_extension_1"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path.cc b/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path.cc index cbf470c11..6e106be2a 100644 --- a/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path.cc +++ b/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path.cc @@ -143,22 +143,17 @@ TEST(CmdConversionTest, CmdConversionPath) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send a user-defined 'hello world' command. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "cmd_mapping_path__extension_group", - "extension": "test_extension_1" - }] - }, - "test_property": 32 - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "cmd_mapping_path__extension_group", + "test_extension_1"); + hello_world_cmd->set_property("test_property", 32); + + auto cmd_result = + client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_array_1.cc b/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_array_1.cc index 4c0f7653d..946c49f12 100644 --- a/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_array_1.cc +++ b/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_array_1.cc @@ -143,22 +143,17 @@ TEST(CmdConversionTest, CmdConversionPathArray1) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send a user-defined 'hello world' command. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "cmd_mapping_path_array_1__extension_group", - "extension": "test_extension_1" - }] - }, - "test_property": 32 - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "cmd_mapping_path_array_1__extension_group", + "test_extension_1"); + hello_world_cmd->set_property("test_property", 32); + + auto cmd_result = + client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_array_2.cc b/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_array_2.cc index c4586167f..57e449fba 100644 --- a/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_array_2.cc +++ b/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_array_2.cc @@ -149,22 +149,17 @@ TEST(CmdConversionTest, CmdConversionPathArray2) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send a user-defined 'hello world' command. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "cmd_mapping_path_array_2__extension_group", - "extension": "test_extension_1" - }] - }, - "test_property": 32 - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "cmd_mapping_path_array_2__extension_group", + "test_extension_1"); + hello_world_cmd->set_property("test_property", 32); + + auto cmd_result = + client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_array_3.cc b/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_array_3.cc index 41c4655e6..6ddb21f03 100644 --- a/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_array_3.cc +++ b/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_array_3.cc @@ -149,22 +149,17 @@ TEST(CmdConversionTest, CmdConversionPathArray3) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send a user-defined 'hello world' command. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "cmd_mapping_path_array_3__extension_group", - "extension": "test_extension_1" - }] - }, - "test_property": 32 - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "cmd_mapping_path_array_3__extension_group", + "test_extension_1"); + hello_world_cmd->set_property("test_property", 32); + + auto cmd_result = + client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_array_4.cc b/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_array_4.cc index ee23fe866..ad59bfd2b 100644 --- a/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_array_4.cc +++ b/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_array_4.cc @@ -150,22 +150,16 @@ TEST(CmdConversionTest, CmdConversionPathArray4) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send a user-defined 'hello world' command. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "cmd_mapping_path_array_4__extension_group", - "extension": "test_extension_1" - }] - }, - "test_property": 32 - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "cmd_mapping_path_array_4__extension_group", + "test_extension_1"); + hello_world_cmd->set_property("test_property", 32); + + auto cmd_result = + client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_array_5.cc b/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_array_5.cc index 7994e1bd3..66b8323e5 100644 --- a/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_array_5.cc +++ b/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_array_5.cc @@ -150,22 +150,16 @@ TEST(CmdConversionTest, CmdConversionPathArray5) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send a user-defined 'hello world' command. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "cmd_mapping_path_array_5__extension_group", - "extension": "test_extension_1" - }] - }, - "test_property": 32 - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "cmd_mapping_path_array_5__extension_group", + "test_extension_1"); + hello_world_cmd->set_property("test_property", 32); + + auto cmd_result = + client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_array_6.cc b/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_array_6.cc index 151b8b15b..2664da200 100644 --- a/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_array_6.cc +++ b/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_array_6.cc @@ -150,22 +150,16 @@ TEST(CmdConversionTest, CmdConversionPathArray6) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send a user-defined 'hello world' command. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "cmd_mapping_path_array_6__extension_group", - "extension": "test_extension_1" - }] - }, - "test_property": 32 - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "cmd_mapping_path_array_6__extension_group", + "test_extension_1"); + hello_world_cmd->set_property("test_property", 32); + + auto cmd_result = + client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_array_7.cc b/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_array_7.cc index 54f022dc4..4708e96bc 100644 --- a/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_array_7.cc +++ b/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_array_7.cc @@ -150,22 +150,17 @@ TEST(CmdConversionTest, CmdConversionPathArray7) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send a user-defined 'hello world' command. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "cmd_mapping_path_array_7__extension_group", - "extension": "test_extension_1" - }] - }, - "test_property": 32 - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "cmd_mapping_path_array_7__extension_group", + "test_extension_1"); + hello_world_cmd->set_property("test_property", 32); + + auto cmd_result = + client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_keep_original.cc b/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_keep_original.cc index 0e47af6d3..60b9f1298 100644 --- a/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_keep_original.cc +++ b/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_keep_original.cc @@ -146,24 +146,19 @@ TEST(CmdConversionTest, CmdConversionPathKeepOriginal) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send a user-defined 'hello world' command. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "cmd_mapping_path_keep_original__extension_group", - "extension": "test_extension_1" - }] - }, - "test_property": 32, - "test_original_int": 33, - "test_original_str": "abc" - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "cmd_mapping_path_keep_original__extension_group", + "test_extension_1"); + hello_world_cmd->set_property("test_property", 32); + hello_world_cmd->set_property("test_original_int", 33); + hello_world_cmd->set_property("test_original_str", "abc"); + + auto cmd_result = + client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_nested_1.cc b/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_nested_1.cc index 8bf03999f..18207089c 100644 --- a/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_nested_1.cc +++ b/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_nested_1.cc @@ -36,8 +36,8 @@ class test_extension_2 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { if (std::string(cmd->get_name()) == "hello_mapping") { - auto json_str = cmd->get_property_to_json("test_group"); - auto json = nlohmann::json::parse(json_str); + auto json = + nlohmann::json::parse(cmd->get_property_to_json("test_group")); if (json["test_property_name"] == 32) { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); @@ -145,22 +145,17 @@ TEST(CmdConversionTest, CmdConversionPathNested1) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send a user-defined 'hello world' command. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "cmd_mapping_path_nested_1__extension_group", - "extension": "test_extension_1" - }] - }, - "test_property": 32 - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "cmd_mapping_path_nested_1__extension_group", + "test_extension_1"); + hello_world_cmd->set_property("test_property", 32); + + auto cmd_result = + client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_nested_2.cc b/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_nested_2.cc index b76cfbb40..819d5ce5e 100644 --- a/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_nested_2.cc +++ b/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_nested_2.cc @@ -36,8 +36,8 @@ class test_extension_2 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { if (std::string(cmd->get_name()) == "hello_mapping") { - auto json_str = cmd->get_property_to_json("test_group"); - auto json = nlohmann::json::parse(json_str); + auto json = + nlohmann::json::parse(cmd->get_property_to_json("test_group")); if (json["test_property_name"] == 32) { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); @@ -145,24 +145,19 @@ TEST(CmdConversionTest, CmdConversionPathNested2) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send a user-defined 'hello world' command. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "cmd_mapping_path_nested_2__extension_group", - "extension": "test_extension_1" - }] - }, - "test_group": { + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "cmd_mapping_path_nested_2__extension_group", + "test_extension_1"); + hello_world_cmd->set_property_from_json("test_group", R"({ "test_property": 32 - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + })"); + + auto cmd_result = + client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_nested_3.cc b/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_nested_3.cc index becadcece..798c89c18 100644 --- a/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_nested_3.cc +++ b/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_nested_3.cc @@ -36,8 +36,8 @@ class test_extension_2 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { if (std::string(cmd->get_name()) == "hello_mapping") { - auto json_str = cmd->get_property_to_json("dest_test_group"); - auto json = nlohmann::json::parse(json_str); + auto json = + nlohmann::json::parse(cmd->get_property_to_json("dest_test_group")); if (json["test_property_name"] == 32) { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); @@ -145,24 +145,19 @@ TEST(CmdConversionTest, CmdConversionPathNested3) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send a user-defined 'hello world' command. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "cmd_mapping_path_nested_3__extension_group", - "extension": "test_extension_1" - }] - }, - "test_group": [{ + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "cmd_mapping_path_nested_3__extension_group", + "test_extension_1"); + hello_world_cmd->set_property_from_json("test_group", R"([{ "test_property": 32 - }] - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + }])"); + + auto cmd_result = + client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_nested_4.cc b/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_nested_4.cc index 7393e5824..9150f7cf6 100644 --- a/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_nested_4.cc +++ b/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_nested_4.cc @@ -36,8 +36,8 @@ class test_extension_2 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { if (std::string(cmd->get_name()) == "hello_mapping") { - auto json_str = cmd->get_property_to_json("dest_test_group"); - auto json = nlohmann::json::parse(json_str); + auto json = + nlohmann::json::parse(cmd->get_property_to_json("dest_test_group")); if (json["test_property_name"] == 32) { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); @@ -145,26 +145,21 @@ TEST(CmdConversionTest, CmdConversionPathNested4) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send a user-defined 'hello world' command. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "cmd_mapping_path_nested_4__extension_group", - "extension": "test_extension_1" - }] - }, - "test_group": [{ + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "cmd_mapping_path_nested_4__extension_group", + "test_extension_1"); + hello_world_cmd->set_property_from_json("test_group", R"([{ "aaa": { "test_property": 32 } - }] - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + }])"); + + auto cmd_result = + client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_nested_5.cc b/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_nested_5.cc index 5e3d65107..357247058 100644 --- a/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_nested_5.cc +++ b/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_nested_5.cc @@ -37,12 +37,12 @@ class test_extension_2 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { if (std::string(cmd->get_name()) == "hello_mapping") { - auto json_str = cmd->get_property_to_json("test_group"); - auto json = nlohmann::json::parse(json_str); + auto json = + nlohmann::json::parse(cmd->get_property_to_json("test_group")); if (json["test_property_name"] == 32) { - auto resp = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); - resp->set_property("detail", "hello world, too"); - ten_env.return_result(std::move(resp), std::move(cmd)); + auto result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); + result->set_property("detail", "hello world, too"); + ten_env.return_result(std::move(result), std::move(cmd)); } } } @@ -147,22 +147,17 @@ TEST(CmdConversionTest, CmdConversionPathNested5) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send a user-defined 'hello world' command. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "cmd_mapping_path_nested_5__extension_group", - "extension": "test_extension_1" - }] - }, - "test_property": 32 - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "cmd_mapping_path_nested_5__extension_group", + "test_extension_1"); + hello_world_cmd->set_property("test_property", 32); + + auto cmd_result = + client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_nested_6.cc b/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_nested_6.cc new file mode 100644 index 000000000..07fe1c30d --- /dev/null +++ b/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_nested_6.cc @@ -0,0 +1,169 @@ +// +// Copyright © 2024 Agora +// This file is part of TEN Framework, an open source project. +// Licensed under the Apache License, Version 2.0, with certain conditions. +// Refer to the "LICENSE" file in the root directory for more information. +// +#include +#include +#include + +#include "gtest/gtest.h" +#include "include_internal/ten_runtime/binding/cpp/ten.h" +#include "ten_utils/lib/thread.h" +#include "tests/common/client/cpp/msgpack_tcp.h" +#include "tests/ten_runtime/smoke/extension_test/util/binding/cpp/check.h" + +namespace { + +class test_extension_1 : public ten::extension_t { + public: + explicit test_extension_1(const std::string &name) : ten::extension_t(name) {} + + void on_cmd(ten::ten_env_t &ten_env, + std::unique_ptr cmd) override { + if (std::string(cmd->get_name()) == "hello_world") { + ten_env.send_cmd(std::move(cmd)); + return; + } + } +}; + +class test_extension_2 : public ten::extension_t { + public: + explicit test_extension_2(const std::string &name) : ten::extension_t(name) {} + + void on_cmd(ten::ten_env_t &ten_env, + std::unique_ptr cmd) override { + if (std::string(cmd->get_name()) == "hello_mapping") { + auto json = + nlohmann::json::parse(cmd->get_property_to_json("dest_test_group")); + if (json["test_property_name"] == 32) { + auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); + cmd_result->set_property("detail", "hello world, too"); + ten_env.return_result(std::move(cmd_result), std::move(cmd)); + } + } + } +}; + +class test_app : public ten::app_t { + public: + void on_configure(ten::ten_env_t &ten_env) override { + ten::ten_env_internal_accessor_t ten_env_internal_accessor(&ten_env); + bool rc = ten_env_internal_accessor.init_manifest_from_json( + // clang-format off + R"###({ + "type": "app", + "name": "test_app", + "version": "0.1.0" + })###" + // clang-format on + ); + ASSERT_EQ(rc, true); + + rc = ten_env.init_property_from_json( + // clang-format off + R"###({ + "_ten": { + "uri": "msgpack://127.0.0.1:8001/", + "log_level": 2, + "predefined_graphs": [{ + "name": "default", + "auto_start": false, + "singleton": true, + "nodes": [{ + "app": "msgpack://127.0.0.1:8001/", + "type": "extension", + "name": "test_extension_1", + "addon": "cmd_mapping_path_nested_6__test_extension_1", + "extension_group": "cmd_mapping_path_nested_6__extension_group" + },{ + "app": "msgpack://127.0.0.1:8001/", + "type": "extension", + "name": "test_extension_2", + "addon": "cmd_mapping_path_nested_6__test_extension_2", + "extension_group": "cmd_mapping_path_nested_6__extension_group" + }], + "connections": [{ + "app": "msgpack://127.0.0.1:8001/", + "extension_group": "cmd_mapping_path_nested_6__extension_group", + "extension": "test_extension_1", + "cmd": [{ + "name": "hello_world", + "dest": [{ + "app": "msgpack://127.0.0.1:8001/", + "extension_group": "cmd_mapping_path_nested_6__extension_group", + "extension": "test_extension_2", + "msg_conversion": { + "type": "per_property", + "rules": [{ + "path": "_ten.name", + "conversion_mode": "fixed_value", + "value": "hello_mapping" + },{ + "path": "dest_test_group.test_property_name", + "conversion_mode": "from_original", + "original_path": "test_group[0].aaa.test_property" + }] + } + }] + }] + }] + }] + } + })###" + // clang-format on + ); + ASSERT_EQ(rc, true); + + ten_env.on_configure_done(); + } +}; + +void *test_app_thread_main(TEN_UNUSED void *args) { + auto *app = new test_app(); + app->run(); + delete app; + + return nullptr; +} + +TEN_CPP_REGISTER_ADDON_AS_EXTENSION(cmd_mapping_path_nested_6__test_extension_1, + test_extension_1); +TEN_CPP_REGISTER_ADDON_AS_EXTENSION(cmd_mapping_path_nested_6__test_extension_2, + test_extension_2); + +} // namespace + +TEST(CmdConversionTest, CmdConversionPathNested6) { // NOLINT + // Start app. + auto *app_thread = + ten_thread_create("app thread", test_app_thread_main, nullptr); + + // Create a client and connect to the app. + auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); + + // Send a user-defined 'hello world' command. + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "cmd_mapping_path_nested_6__extension_group", + "test_extension_1"); + hello_world_cmd->from_json(R"({ + "test_group": [{ + "aaa": { + "test_property": 32 + } + }] + })"); + + auto cmd_result = + client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); + + delete client; + + ten_thread_join(app_thread, -1); +} diff --git a/tests/ten_runtime/smoke/cmd_result_test/multiple_result_1.cc b/tests/ten_runtime/smoke/cmd_result_test/multiple_result_1.cc index 961a8a281..97854ed41 100644 --- a/tests/ten_runtime/smoke/cmd_result_test/multiple_result_1.cc +++ b/tests/ten_runtime/smoke/cmd_result_test/multiple_result_1.cc @@ -106,12 +106,9 @@ TEST(CmdResultTest, MultipleResult1) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "multiple_result_1__test_extension_1", @@ -138,24 +135,18 @@ TEST(CmdResultTest, MultipleResult1) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/cmd_result_test/multiple_result_2.cc b/tests/ten_runtime/smoke/cmd_result_test/multiple_result_2.cc index 6f826ae70..a0ca49123 100644 --- a/tests/ten_runtime/smoke/cmd_result_test/multiple_result_2.cc +++ b/tests/ten_runtime/smoke/cmd_result_test/multiple_result_2.cc @@ -120,12 +120,9 @@ TEST(CmdResultTest, MultipleResult2) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "multiple_result_2__test_extension_1", @@ -162,24 +159,18 @@ TEST(CmdResultTest, MultipleResult2) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/cmd_result_test/multiple_result_3.cc b/tests/ten_runtime/smoke/cmd_result_test/multiple_result_3.cc index e200913bb..7e50a3ee9 100644 --- a/tests/ten_runtime/smoke/cmd_result_test/multiple_result_3.cc +++ b/tests/ten_runtime/smoke/cmd_result_test/multiple_result_3.cc @@ -120,12 +120,9 @@ TEST(CmdResultTest, MultipleResult3) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "multiple_result_3__test_extension_1", @@ -162,24 +159,18 @@ TEST(CmdResultTest, MultipleResult3) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/data_test/basic.cc b/tests/ten_runtime/smoke/data_test/basic.cc index 57d312050..493556c20 100644 --- a/tests/ten_runtime/smoke/data_test/basic.cc +++ b/tests/ten_runtime/smoke/data_test/basic.cc @@ -6,7 +6,6 @@ // #include #include -#include #include "gtest/gtest.h" #include "include_internal/ten_runtime/binding/cpp/ten.h" @@ -24,8 +23,7 @@ class test_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "check_received") { + if (std::string(cmd->get_name()) == "check_received") { if (received) { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "received confirmed"); @@ -91,12 +89,9 @@ TEST(DataTest, Basic) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension", "addon": "data_basic__extension", @@ -104,27 +99,20 @@ TEST(DataTest, Basic) { // NOLINT "extension_group": "default_extension_group" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); const char *str = DATA; client->send_data("", "default_extension_group", "test_extension", (void *)str, strlen(str) + 1); - - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "check_received", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "default_extension_group", - "extension": "test_extension" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "received confirmed"); + auto check_received_cmd = ten::cmd_t::create("check_received"); + check_received_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "default_extension_group", "test_extension"); + cmd_result = client->send_cmd_and_recv_result(std::move(check_received_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "received confirmed"); delete client; diff --git a/tests/ten_runtime/smoke/data_test/basic_2.cc b/tests/ten_runtime/smoke/data_test/basic_2.cc index b99083825..fdf0bb4ca 100644 --- a/tests/ten_runtime/smoke/data_test/basic_2.cc +++ b/tests/ten_runtime/smoke/data_test/basic_2.cc @@ -93,12 +93,9 @@ TEST(DataTest, Basic2) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "data_basic_2__test_extension_1", @@ -137,24 +134,18 @@ TEST(DataTest, Basic2) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/data_test/create_from_json.cc b/tests/ten_runtime/smoke/data_test/create_from_json.cc index dc4131c02..607163c25 100644 --- a/tests/ten_runtime/smoke/data_test/create_from_json.cc +++ b/tests/ten_runtime/smoke/data_test/create_from_json.cc @@ -98,12 +98,9 @@ TEST(DataTest, CreateFromJson) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "data_create_from_json__test_extension_1", @@ -142,24 +139,18 @@ TEST(DataTest, CreateFromJson) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/data_test/from_json.cc b/tests/ten_runtime/smoke/data_test/from_json.cc index a77b08de8..43c724fa6 100644 --- a/tests/ten_runtime/smoke/data_test/from_json.cc +++ b/tests/ten_runtime/smoke/data_test/from_json.cc @@ -102,12 +102,9 @@ TEST(DataTest, FromJson) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "data_from_json__test_extension_1", @@ -146,24 +143,18 @@ TEST(DataTest, FromJson) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/data_test/multi_dest_data.cc b/tests/ten_runtime/smoke/data_test/multi_dest_data.cc index bfc4915a1..4e4b5a0d6 100644 --- a/tests/ten_runtime/smoke/data_test/multi_dest_data.cc +++ b/tests/ten_runtime/smoke/data_test/multi_dest_data.cc @@ -25,8 +25,7 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "dispatch_data") { + if (std::string(cmd->get_name()) == "dispatch_data") { const char *str = DATA; auto length = strlen(str); @@ -65,8 +64,7 @@ class test_extension_2 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "check_received") { + if (std::string(cmd->get_name()) == "check_received") { if (received) { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "received confirmed"); @@ -100,8 +98,7 @@ class test_extension_3 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "check_received") { + if (std::string(cmd->get_name()) == "check_received") { if (received) { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "received confirmed"); @@ -164,12 +161,9 @@ TEST(DataTest, MultiDestData) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "extension 1", "addon": "multi_dest_data__extension_1", @@ -206,53 +200,38 @@ TEST(DataTest, MultiDestData) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'dispatch_data' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "dispatch_data", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group", - "extension": "extension 1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, "done"); - - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "check_received", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group", - "extension": "extension 2" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "received confirmed"); - - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "check_received", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group", - "extension": "extension 3" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "received confirmed"); + auto dispatch_data_cmd = ten::cmd_t::create("dispatch_data"); + dispatch_data_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group", "extension 1"); + + cmd_result = client->send_cmd_and_recv_result(std::move(dispatch_data_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "done"); + + auto check_received_cmd = ten::cmd_t::create("check_received"); + check_received_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group", "extension 2"); + + cmd_result = client->send_cmd_and_recv_result(std::move(check_received_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "received confirmed"); + + check_received_cmd = ten::cmd_t::create("check_received"); + check_received_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group", "extension 3"); + + cmd_result = client->send_cmd_and_recv_result(std::move(check_received_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "received confirmed"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/basic/basic_extensions_init_dependency.cc b/tests/ten_runtime/smoke/extension_test/basic/basic_extensions_init_dependency.cc index ed8bc30d3..868e40d83 100644 --- a/tests/ten_runtime/smoke/extension_test/basic/basic_extensions_init_dependency.cc +++ b/tests/ten_runtime/smoke/extension_test/basic/basic_extensions_init_dependency.cc @@ -30,11 +30,9 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { ten_env.send_cmd(std::move(cmd)); - } else if (json["_ten"]["name"] == "get_name") { + } else if (std::string(cmd->get_name()) == "get_name") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "test_extension_1"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -77,8 +75,7 @@ class test_extension_2 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", greeting_); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -148,8 +145,10 @@ void *test_app_thread_main(TEN_UNUSED void *args) { return nullptr; } -TEN_CPP_REGISTER_ADDON_AS_EXTENSION(basic_extensions_init_dependency__extension_1, test_extension_1); -TEN_CPP_REGISTER_ADDON_AS_EXTENSION(basic_extensions_init_dependency__extension_2, test_extension_2); +TEN_CPP_REGISTER_ADDON_AS_EXTENSION( + basic_extensions_init_dependency__extension_1, test_extension_1); +TEN_CPP_REGISTER_ADDON_AS_EXTENSION( + basic_extensions_init_dependency__extension_2, test_extension_2); } // namespace @@ -162,12 +161,9 @@ TEST(ExtensionTest, BasicExtensionsInitDependency) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "basic_extensions_init_dependency__extension_1", @@ -206,24 +202,20 @@ TEST(ExtensionTest, BasicExtensionsInitDependency) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extensions_init_dependency", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is( - resp, "137", TEN_STATUS_CODE_OK, + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extensions_init_dependency", + "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string( + cmd_result, std::string(EXTENSION_PROP_VALUE_GREETING) + "test_extension_1"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/basic/basic_hello_world_1.cc b/tests/ten_runtime/smoke/extension_test/basic/basic_hello_world_1.cc index 018a5136f..3615cd442 100644 --- a/tests/ten_runtime/smoke/extension_test/basic/basic_hello_world_1.cc +++ b/tests/ten_runtime/smoke/extension_test/basic/basic_hello_world_1.cc @@ -73,12 +73,9 @@ TEST(ExtensionTest, BasicHelloWorld1) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension", "addon": "basic_hello_world_1__test_extension", @@ -86,24 +83,18 @@ TEST(ExtensionTest, BasicHelloWorld1) { // NOLINT "app": "msgpack://127.0.0.1:8001/" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group", - "extension": "test_extension" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group", "test_extension"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/basic/basic_hello_world_2.cc b/tests/ten_runtime/smoke/extension_test/basic/basic_hello_world_2.cc index 1bec52e9d..612e5f2db 100644 --- a/tests/ten_runtime/smoke/extension_test/basic/basic_hello_world_2.cc +++ b/tests/ten_runtime/smoke/extension_test/basic/basic_hello_world_2.cc @@ -71,12 +71,9 @@ TEST(ExtensionTest, BasicHelloWorld2) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension", "addon": "basic_hello_world_2__extension", @@ -84,24 +81,20 @@ TEST(ExtensionTest, BasicHelloWorld2) { // NOLINT "app": "msgpack://127.0.0.1:8001/" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group", - "extension": "test_extension" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group", "test_extension"); + + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/basic/basic_loop.cc b/tests/ten_runtime/smoke/extension_test/basic/basic_loop.cc index 9d33d7407..ec5fa1cf5 100644 --- a/tests/ten_runtime/smoke/extension_test/basic/basic_loop.cc +++ b/tests/ten_runtime/smoke/extension_test/basic/basic_loop.cc @@ -21,8 +21,7 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { hello_world_cmd = std::move(cmd); auto hello_world_1_cmd = ten::cmd_t::create("hello_world_1"); ten_env.send_cmd(std::move(hello_world_1_cmd), @@ -37,7 +36,7 @@ class test_extension_1 : public ten::extension_t { std::move(hello_world_cmd)); }); return; - } else if (json["_ten"]["name"] == "hello_world_2") { + } else if (std::string(cmd->get_name()) == "hello_world_2") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -54,8 +53,7 @@ class test_extension_2 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world_1") { + if (std::string(cmd->get_name()) == "hello_world_1") { // waiting for result pending_request = std::move(cmd); auto hello_world_2_cmd = ten::cmd_t::create("hello_world_2"); @@ -118,12 +116,9 @@ TEST(ExtensionTest, BasicLoop) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "basic_loop__extension_1", @@ -162,24 +157,18 @@ TEST(ExtensionTest, BasicLoop) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/basic/basic_loop_cmd.cc b/tests/ten_runtime/smoke/extension_test/basic/basic_loop_cmd.cc index 53d4bc7ca..b73a79866 100644 --- a/tests/ten_runtime/smoke/extension_test/basic/basic_loop_cmd.cc +++ b/tests/ten_runtime/smoke/extension_test/basic/basic_loop_cmd.cc @@ -120,12 +120,9 @@ TEST(ExtensionTest, BasicLoopCmd) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "basic_loop_cmd__extension_1", @@ -164,24 +161,18 @@ TEST(ExtensionTest, BasicLoopCmd) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/basic/basic_loop_cmd_snap_shot.cc b/tests/ten_runtime/smoke/extension_test/basic/basic_loop_cmd_snap_shot.cc index 1b2953056..9a0232fd4 100644 --- a/tests/ten_runtime/smoke/extension_test/basic/basic_loop_cmd_snap_shot.cc +++ b/tests/ten_runtime/smoke/extension_test/basic/basic_loop_cmd_snap_shot.cc @@ -120,12 +120,9 @@ TEST(ExtensionTest, BasicLoopCmdSnapShot) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "basic_loop_cmd_snapshot__extension_1", @@ -164,24 +161,18 @@ TEST(ExtensionTest, BasicLoopCmdSnapShot) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/basic/basic_msg_property_to_prop_store.cc b/tests/ten_runtime/smoke/extension_test/basic/basic_msg_property_to_prop_store.cc index e46b35546..4a389cf52 100644 --- a/tests/ten_runtime/smoke/extension_test/basic/basic_msg_property_to_prop_store.cc +++ b/tests/ten_runtime/smoke/extension_test/basic/basic_msg_property_to_prop_store.cc @@ -94,12 +94,9 @@ TEST(ExtensionTest, BasicMsgPropertyToPropStore) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "basic_msg_property_to_property_store__test_extension_1", @@ -126,24 +123,18 @@ TEST(ExtensionTest, BasicMsgPropertyToPropStore) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/basic/basic_multi_app.cc b/tests/ten_runtime/smoke/extension_test/basic/basic_multi_app.cc index a84ae7bea..c6616bbdd 100644 --- a/tests/ten_runtime/smoke/extension_test/basic/basic_multi_app.cc +++ b/tests/ten_runtime/smoke/extension_test/basic/basic_multi_app.cc @@ -24,8 +24,7 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { ten_env.send_cmd(std::move(cmd)); return; } @@ -38,8 +37,7 @@ class test_extension_2 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -155,12 +153,9 @@ TEST(ExtensionTest, BasicMultiApp) { // NOLINT // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "basic_multi_app__extension_1", @@ -187,10 +182,12 @@ TEST(ExtensionTest, BasicMultiApp) { // NOLINT }] }] } - })"_json); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); - if (!resp.empty()) { - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + if (cmd_result) { + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); break; } else { client.reset(); @@ -203,20 +200,15 @@ TEST(ExtensionTest, BasicMultiApp) { // NOLINT TEN_ASSERT(client, "Failed to connect to the TEN app."); // Send a user-defined 'hello world' command. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group 1", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group 1", "test_extension_1"); + + auto cmd_result = + client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); // Because the closing of an engine would _not_ cause the closing of the // app, so we have to explicitly close the app. diff --git a/tests/ten_runtime/smoke/extension_test/basic/basic_multi_app_close_through_engine.cc b/tests/ten_runtime/smoke/extension_test/basic/basic_multi_app_close_through_engine.cc index 74084d830..1db855c6a 100644 --- a/tests/ten_runtime/smoke/extension_test/basic/basic_multi_app_close_through_engine.cc +++ b/tests/ten_runtime/smoke/extension_test/basic/basic_multi_app_close_through_engine.cc @@ -23,8 +23,7 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { ten_env.send_cmd(std::move(cmd)); return; } @@ -37,8 +36,7 @@ class test_extension_2 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -140,12 +138,9 @@ TEST(ExtensionTest, BasicMultiAppCloseThroughEngine) { // NOLINT client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "basic_multi_app_close_through_engine__extension_1", @@ -172,10 +167,12 @@ TEST(ExtensionTest, BasicMultiAppCloseThroughEngine) { // NOLINT }] }] } - })"_json); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); - if (!resp.empty()) { - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + if (cmd_result) { + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); break; } else { delete client; @@ -189,20 +186,13 @@ TEST(ExtensionTest, BasicMultiAppCloseThroughEngine) { // NOLINT TEN_ASSERT(client, "Failed to connect to the TEN app."); // Send a user-defined 'hello world' command. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group 1", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group 1", "test_extension_1"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); // The 'client' is actually connected the 'engine', so the following // 'close_app()' is actually to close the app through the engine. diff --git a/tests/ten_runtime/smoke/extension_test/basic/basic_multi_extension.cc b/tests/ten_runtime/smoke/extension_test/basic/basic_multi_extension.cc index be8d17c49..d443a1cdc 100644 --- a/tests/ten_runtime/smoke/extension_test/basic/basic_multi_extension.cc +++ b/tests/ten_runtime/smoke/extension_test/basic/basic_multi_extension.cc @@ -22,9 +22,7 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { ten_env.send_cmd(std::move(cmd)); return; } @@ -37,8 +35,7 @@ class test_extension_2 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -90,12 +87,9 @@ TEST(ExtensionTest, BasicMultiExtension) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "extension_group": "basic_multi_extension", @@ -122,24 +116,18 @@ TEST(ExtensionTest, BasicMultiExtension) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_multi_extension", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_multi_extension", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/basic/basic_multi_extension_group.cc b/tests/ten_runtime/smoke/extension_test/basic/basic_multi_extension_group.cc index c8f2f1230..fcd7c93a3 100644 --- a/tests/ten_runtime/smoke/extension_test/basic/basic_multi_extension_group.cc +++ b/tests/ten_runtime/smoke/extension_test/basic/basic_multi_extension_group.cc @@ -87,12 +87,9 @@ TEST(ExtensionTest, BasicMultiExtensionGroup) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "basic_multi_extension_group__extension_1", @@ -119,24 +116,19 @@ TEST(ExtensionTest, BasicMultiExtensionGroup) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_multi_extension_group__extension_group_1", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_multi_extension_group__extension_group_1", + "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/basic/basic_no_init_extension_group.cc b/tests/ten_runtime/smoke/extension_test/basic/basic_no_init_extension_group.cc index 7e39d40c7..f153c3fac 100644 --- a/tests/ten_runtime/smoke/extension_test/basic/basic_no_init_extension_group.cc +++ b/tests/ten_runtime/smoke/extension_test/basic/basic_no_init_extension_group.cc @@ -22,8 +22,7 @@ class test_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -72,12 +71,9 @@ TEST(ExtensionTest, BasicNoInitExtensionGroup) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension", "app": "msgpack://127.0.0.1:8001/", @@ -85,24 +81,18 @@ TEST(ExtensionTest, BasicNoInitExtensionGroup) { // NOLINT "addon": "basic_no_init_extension_group__extension" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_no_init_extension_group", - "extension": "test_extension" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_no_init_extension_group", "test_extension"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/basic/basic_throw_exception_in_extension.cc b/tests/ten_runtime/smoke/extension_test/basic/basic_throw_exception_in_extension.cc index 5db653696..2a22fd98d 100644 --- a/tests/ten_runtime/smoke/extension_test/basic/basic_throw_exception_in_extension.cc +++ b/tests/ten_runtime/smoke/extension_test/basic/basic_throw_exception_in_extension.cc @@ -23,8 +23,7 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { ten_env.send_cmd(std::move(cmd)); return; } @@ -37,8 +36,7 @@ class test_extension_2 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { ten_env.send_cmd(std::move(cmd)); return; } @@ -51,8 +49,7 @@ class test_extension_3 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { ten_env.send_cmd(std::move(cmd)); return; } @@ -65,8 +62,7 @@ class test_extension_4 : public ten::extension_t { void on_cmd(TEN_UNUSED ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { throw std::exception(); } } @@ -187,12 +183,9 @@ TEST(ExtensionTest, BasicThrowExceptionInExtension) { // NOLINT client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "basic_throw_exception_in_extension__extension_1", @@ -255,10 +248,11 @@ TEST(ExtensionTest, BasicThrowExceptionInExtension) { // NOLINT }] }] } - })"_json); - - if (!resp.empty()) { - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + if (cmd_result) { + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); break; } else { delete client; @@ -270,18 +264,11 @@ TEST(ExtensionTest, BasicThrowExceptionInExtension) { // NOLINT } // Send a user-defined 'hello world' command to 'extension 1'. - client->send_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_throw_exception_in_extension_1", - "extension": "test_extension_1" - }] - } - })"_json); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_throw_exception_in_extension_1", + "test_extension_1"); + client->send_cmd(std::move(hello_world_cmd)); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/basic/basic_two_extensions.cc b/tests/ten_runtime/smoke/extension_test/basic/basic_two_extensions.cc index de1d88832..bda8262a4 100644 --- a/tests/ten_runtime/smoke/extension_test/basic/basic_two_extensions.cc +++ b/tests/ten_runtime/smoke/extension_test/basic/basic_two_extensions.cc @@ -86,12 +86,9 @@ TEST(ExtensionTest, BasicTwoExtensions) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "basic_two_extensions__test_extension_1", @@ -118,24 +115,18 @@ TEST(ExtensionTest, BasicTwoExtensions) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/basic/basic_two_standalone_extension_1.cc b/tests/ten_runtime/smoke/extension_test/basic/basic_two_standalone_extension_1.cc index 08103ba8b..6a14f6692 100644 --- a/tests/ten_runtime/smoke/extension_test/basic/basic_two_standalone_extension_1.cc +++ b/tests/ten_runtime/smoke/extension_test/basic/basic_two_standalone_extension_1.cc @@ -84,12 +84,9 @@ TEST(ExtensionTest, BasicTwoStandaloneExtension1) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "basic_two_standalone_extension_1__test_extension_1", @@ -103,39 +100,29 @@ TEST(ExtensionTest, BasicTwoStandaloneExtension1) { // NOLINT "app": "msgpack://127.0.0.1:8001/" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello from test extension 1"); - - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group", - "extension": "test_extension_2" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello from test extension 2"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group", "test_extension_1"); + + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello from test extension 1"); + + hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group", "test_extension_2"); + + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello from test extension 2"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/basic/basic_two_standalone_extension_2.cc b/tests/ten_runtime/smoke/extension_test/basic/basic_two_standalone_extension_2.cc index 19481932d..b95f52ac9 100644 --- a/tests/ten_runtime/smoke/extension_test/basic/basic_two_standalone_extension_2.cc +++ b/tests/ten_runtime/smoke/extension_test/basic/basic_two_standalone_extension_2.cc @@ -84,12 +84,9 @@ TEST(ExtensionTest, BasicTwoStandaloneExtension2) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "basic_two_standalone_extension_2__test_extension_1", @@ -103,39 +100,29 @@ TEST(ExtensionTest, BasicTwoStandaloneExtension2) { // NOLINT "app": "msgpack://127.0.0.1:8001/" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group 1", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello from test extension 1"); - - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group 2", - "extension": "test_extension_2" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello from test extension 2"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group 1", "test_extension_1"); + + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello from test extension 1"); + + hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group 2", "test_extension_2"); + + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello from test extension 2"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/command/command_check_cmd_out.cc b/tests/ten_runtime/smoke/extension_test/command/command_check_cmd_out.cc index fd2be2ce9..f22b8fda8 100644 --- a/tests/ten_runtime/smoke/extension_test/command/command_check_cmd_out.cc +++ b/tests/ten_runtime/smoke/extension_test/command/command_check_cmd_out.cc @@ -6,13 +6,10 @@ // #include #include -#include #include "gtest/gtest.h" #include "include_internal/ten_runtime/binding/cpp/ten.h" -#include "ten_utils/lib/json.h" #include "ten_utils/lib/thread.h" -#include "ten_utils/lib/time.h" #include "tests/common/client/cpp/msgpack_tcp.h" #include "tests/ten_runtime/smoke/extension_test/util/binding/cpp/check.h" @@ -24,10 +21,7 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - - auto cmd_name_str = json["_ten"]["name"].get(); - const auto *cmd_name = cmd_name_str.c_str(); + const auto *cmd_name = cmd->get_name(); auto res = ten_env.is_cmd_connected(cmd_name); if (res) { ten_env.send_cmd(std::move(cmd)); @@ -45,8 +39,7 @@ class test_extension_2 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -120,10 +113,10 @@ void *test_app_thread_main(TEN_UNUSED void *args) { return nullptr; } -TEN_CPP_REGISTER_ADDON_AS_EXTENSION(command_check_cmd_out_extension_1__extension_1, - test_extension_1); -TEN_CPP_REGISTER_ADDON_AS_EXTENSION(command_check_cmd_out_extension_1__extension_2, - test_extension_2); +TEN_CPP_REGISTER_ADDON_AS_EXTENSION( + command_check_cmd_out_extension_1__extension_1, test_extension_1); +TEN_CPP_REGISTER_ADDON_AS_EXTENSION( + command_check_cmd_out_extension_1__extension_2, test_extension_2); } // namespace @@ -136,38 +129,21 @@ TEST(ExtensionTest, CommandCheckCmdOut) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send a custom command which no other extensions can deal with. - nlohmann::json resp_w = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello", - "seq_id": "136", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "command_check_cmd_out_extension_1", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp_w, "136", TEN_STATUS_CODE_OK, - "can not find a way out"); + auto hello_cmd = ten::cmd_t::create("hello"); + hello_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "command_check_cmd_out_extension_1", "test_extension_1"); + auto cmd_result = client->send_cmd_and_recv_result(std::move(hello_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "can not find a way out"); // Send a user-defined 'hello world' command. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "command_check_cmd_out_extension_1", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "command_check_cmd_out_extension_1", + "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/command/command_invalid_extension.cc b/tests/ten_runtime/smoke/extension_test/command/command_invalid_extension.cc index 31f139322..2ffcb84f9 100644 --- a/tests/ten_runtime/smoke/extension_test/command/command_invalid_extension.cc +++ b/tests/ten_runtime/smoke/extension_test/command/command_invalid_extension.cc @@ -22,8 +22,7 @@ class test_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -72,12 +71,9 @@ TEST(ExtensionTest, CommandInvalidExtension) { auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension", "addon": "command_invalid_extension__extension", @@ -85,24 +81,19 @@ TEST(ExtensionTest, CommandInvalidExtension) { "extension_group": "test_extension_group" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group", - "extension": "test" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_ERROR, - "The extension[test] is invalid."); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group", "test"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_ERROR); + ten_test::check_detail_with_string(cmd_result, + "The extension[test] is invalid."); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/command/command_invalid_extension_2.cc b/tests/ten_runtime/smoke/extension_test/command/command_invalid_extension_2.cc index c567a2054..16fbab967 100644 --- a/tests/ten_runtime/smoke/extension_test/command/command_invalid_extension_2.cc +++ b/tests/ten_runtime/smoke/extension_test/command/command_invalid_extension_2.cc @@ -22,9 +22,7 @@ class test_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { requested_cmd = std::move(cmd); // We send out a request with invalid extension, the extension thread will @@ -90,12 +88,9 @@ TEST(ExtensionTest, CommandInvalidExtension2) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension", "addon": "command_invalid_extension_2__extension", @@ -103,24 +98,19 @@ TEST(ExtensionTest, CommandInvalidExtension2) { // NOLINT "extension_group": "test_extension_group" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group", - "extension": "test_extension" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_ERROR, - "The extension[a] is invalid."); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group", "test_extension"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_ERROR); + ten_test::check_detail_with_string(cmd_result, + "The extension[a] is invalid."); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/command/command_invalid_extension_group.cc b/tests/ten_runtime/smoke/extension_test/command/command_invalid_extension_group.cc index 65b58454d..906c2fa36 100644 --- a/tests/ten_runtime/smoke/extension_test/command/command_invalid_extension_group.cc +++ b/tests/ten_runtime/smoke/extension_test/command/command_invalid_extension_group.cc @@ -22,8 +22,7 @@ class test_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -72,12 +71,9 @@ TEST(ExtensionTest, CommandInvalidExtensionGroup) { auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension", "addon": "command_invalid_extension_group__extension", @@ -85,24 +81,19 @@ TEST(ExtensionTest, CommandInvalidExtensionGroup) { "extension_group": "test_group" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test", - "extension": "test_extension" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_ERROR, - "The extension group[test] is invalid."); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, "test", + "test_extension"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_ERROR); + ten_test::check_detail_with_string(cmd_result, + "The extension group[test] is invalid."); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/command/command_send_enum.cc b/tests/ten_runtime/smoke/extension_test/command/command_send_enum.cc index 02a63facf..ec5af53bf 100644 --- a/tests/ten_runtime/smoke/extension_test/command/command_send_enum.cc +++ b/tests/ten_runtime/smoke/extension_test/command/command_send_enum.cc @@ -24,9 +24,7 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { hello_world_cmd = std::move(cmd); auto new_cmd = ten::cmd_t::create("send enum"); @@ -114,12 +112,9 @@ TEST(ExtensionTest, CommandSendEnum) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "command_send_enum__extension_1", "addon": "command_send_enum__extension_1", @@ -146,24 +141,19 @@ TEST(ExtensionTest, CommandSendEnum) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "command_send_enum__extension_group_1", - "extension": "command_send_enum__extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "command_send_enum__extension_group_1", + "command_send_enum__extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/command/command_send_ptr.cc b/tests/ten_runtime/smoke/extension_test/command/command_send_ptr.cc index 3c2a928a6..4c9609bf8 100644 --- a/tests/ten_runtime/smoke/extension_test/command/command_send_ptr.cc +++ b/tests/ten_runtime/smoke/extension_test/command/command_send_ptr.cc @@ -22,9 +22,7 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { int *test_data = reinterpret_cast(ten_malloc(sizeof(int))); *test_data = 12344321; @@ -108,12 +106,9 @@ TEST(ExtensionTest, CommandSendPtr) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "command_send_ptr__extension_1", "addon": "command_send_ptr__extension_1", @@ -140,24 +135,19 @@ TEST(ExtensionTest, CommandSendPtr) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "command_send_ptr__extension_group_1", - "extension": "command_send_ptr__extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "command_send_ptr__extension_group_1", + "command_send_ptr__extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/command/command_send_ptr_through_cmd.cc b/tests/ten_runtime/smoke/extension_test/command/command_send_ptr_through_cmd.cc index f0956c1d3..51ca9a88c 100644 --- a/tests/ten_runtime/smoke/extension_test/command/command_send_ptr_through_cmd.cc +++ b/tests/ten_runtime/smoke/extension_test/command/command_send_ptr_through_cmd.cc @@ -110,12 +110,9 @@ TEST(ExtensionTest, CommandSendPtrThroughCmd) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "command_send_ptr_through_cmd__extension_1", "addon": "command_send_ptr_through_cmd__extension_1", @@ -142,24 +139,19 @@ TEST(ExtensionTest, CommandSendPtrThroughCmd) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "command_send_ptr_through_cmd__extension_group_1", - "extension": "command_send_ptr_through_cmd__extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "command_send_ptr_through_cmd__extension_group_1", + "command_send_ptr_through_cmd__extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/command/command_stop_graph_actively.cc b/tests/ten_runtime/smoke/extension_test/command/command_stop_graph_actively.cc index 6558e8fcd..0809facd1 100644 --- a/tests/ten_runtime/smoke/extension_test/command/command_stop_graph_actively.cc +++ b/tests/ten_runtime/smoke/extension_test/command/command_stop_graph_actively.cc @@ -24,8 +24,7 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { ten_env.send_cmd(std::move(cmd)); return; } @@ -38,8 +37,7 @@ class test_extension_2 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { ten_env.send_cmd(std::move(cmd)); return; } @@ -52,8 +50,7 @@ class test_extension_3 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { ten_env.send_cmd(std::move(cmd)); return; } @@ -66,8 +63,7 @@ class test_extension_4 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "must return result before close engine"); @@ -193,12 +189,9 @@ TEST(ExtensionTest, CommandStopGraphActively) { // NOLINT client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "command_stop_graph_actively__extension_1", @@ -261,10 +254,13 @@ TEST(ExtensionTest, CommandStopGraphActively) { // NOLINT }] }] } - })"_json); + })"); - if (!resp.empty()) { - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + + if (cmd_result) { + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); break; } else { delete client; @@ -277,17 +273,11 @@ TEST(ExtensionTest, CommandStopGraphActively) { // NOLINT TEN_ASSERT(client, "Failed to connect to the TEN app."); - client->send_json( - R"({ - "_ten": { - "name": "hello_world", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "command_stop_graph_actively_1", - "extension": "test_extension_1" - }] - } - })"_json); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "command_stop_graph_actively_1", + "test_extension_1"); + client->send_cmd(std::move(hello_world_cmd)); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/command/command_stop_graph_actively_through_cmd.cc b/tests/ten_runtime/smoke/extension_test/command/command_stop_graph_actively_through_cmd.cc index 36bdb2df3..1df8dfe2a 100644 --- a/tests/ten_runtime/smoke/extension_test/command/command_stop_graph_actively_through_cmd.cc +++ b/tests/ten_runtime/smoke/extension_test/command/command_stop_graph_actively_through_cmd.cc @@ -197,12 +197,9 @@ TEST(ExtensionTest, CommandStopGraphActivelyThroughCmd) { // NOLINT client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "command_stop_graph_actively_through_cmd__extension_1", @@ -265,10 +262,13 @@ TEST(ExtensionTest, CommandStopGraphActivelyThroughCmd) { // NOLINT }] }] } - })"_json); + })"); - if (!resp.empty()) { - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + + if (cmd_result) { + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); break; } else { delete client; @@ -281,17 +281,11 @@ TEST(ExtensionTest, CommandStopGraphActivelyThroughCmd) { // NOLINT TEN_ASSERT(client, "Failed to connect to the TEN app."); - client->send_json( - R"({ - "_ten": { - "name": "hello_world", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "command_stop_graph_actively_through_cmd_1", - "extension": "test_extension_1" - }] - } - })"_json); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "command_stop_graph_actively_through_cmd_1", + "test_extension_1"); + client->send_cmd(std::move(hello_world_cmd)); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/command/command_stop_graph_actively_through_cmd_dest.cc b/tests/ten_runtime/smoke/extension_test/command/command_stop_graph_actively_through_cmd_dest.cc index 05832024e..3759a8595 100644 --- a/tests/ten_runtime/smoke/extension_test/command/command_stop_graph_actively_through_cmd_dest.cc +++ b/tests/ten_runtime/smoke/extension_test/command/command_stop_graph_actively_through_cmd_dest.cc @@ -192,12 +192,9 @@ TEST(ExtensionTest, CommandStopGraphActivelyThroughCmdDest) { // NOLINT client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "command_stop_graph_actively_through_cmd_dest__extension_1", @@ -260,10 +257,13 @@ TEST(ExtensionTest, CommandStopGraphActivelyThroughCmdDest) { // NOLINT }] }] } - })"_json); + })"); - if (!resp.empty()) { - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + + if (cmd_result) { + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); break; } else { delete client; @@ -276,17 +276,11 @@ TEST(ExtensionTest, CommandStopGraphActivelyThroughCmdDest) { // NOLINT TEN_ASSERT(client, "Failed to connect to the TEN app."); - client->send_json( - R"({ - "_ten": { - "name": "hello_world", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "command_stop_graph_actively_through_cmd_dest_1", - "extension": "test_extension_1" - }] - } - })"_json); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "command_stop_graph_actively_through_cmd_dest_1", + "test_extension_1"); + client->send_cmd(std::move(hello_world_cmd)); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/concurrent/multi_app_concurrent.cc b/tests/ten_runtime/smoke/extension_test/concurrent/multi_app_concurrent.cc index f708b3706..eec1888f9 100644 --- a/tests/ten_runtime/smoke/extension_test/concurrent/multi_app_concurrent.cc +++ b/tests/ten_runtime/smoke/extension_test/concurrent/multi_app_concurrent.cc @@ -24,8 +24,7 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { ten_env.send_cmd(std::move(cmd)); return; } @@ -38,8 +37,7 @@ class test_extension_2 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -142,12 +140,9 @@ void *client_thread_main(TEN_UNUSED void *args) { client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "multi_app_concurrent__extension_1", @@ -174,10 +169,12 @@ void *client_thread_main(TEN_UNUSED void *args) { }] }] } - })"_json); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); - if (!resp.empty()) { - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + if (cmd_result) { + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); break; } else { delete client; @@ -191,20 +188,16 @@ void *client_thread_main(TEN_UNUSED void *args) { TEN_ASSERT(client, "Failed to connect to the TEN app."); // Send a user-defined 'hello world' command. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group 1", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group 1", "test_extension_1"); + + auto cmd_result = + client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); + delete client; return nullptr; diff --git a/tests/ten_runtime/smoke/extension_test/concurrent/multi_app_sequential.cc b/tests/ten_runtime/smoke/extension_test/concurrent/multi_app_sequential.cc index 075119a3d..bb33c0223 100644 --- a/tests/ten_runtime/smoke/extension_test/concurrent/multi_app_sequential.cc +++ b/tests/ten_runtime/smoke/extension_test/concurrent/multi_app_sequential.cc @@ -23,8 +23,7 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { ten_env.send_cmd(std::move(cmd)); return; } @@ -37,8 +36,7 @@ class test_extension_2 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -150,12 +148,9 @@ TEST(ExtensionTest, MultiAppSequential) { // NOLINT client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "multi_app_sequential__extension_1", @@ -182,10 +177,12 @@ TEST(ExtensionTest, MultiAppSequential) { // NOLINT }] }] } - })"_json); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); - if (!resp.empty()) { - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + if (cmd_result) { + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); break; } else { delete client; @@ -196,20 +193,16 @@ TEST(ExtensionTest, MultiAppSequential) { // NOLINT } // Send a user-defined 'hello world' command. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group 1", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group 1", "test_extension_1"); + + auto cmd_result = + client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); + delete client; } diff --git a/tests/ten_runtime/smoke/extension_test/concurrent/one_engine_concurrent.cc b/tests/ten_runtime/smoke/extension_test/concurrent/one_engine_concurrent.cc index b2cfbb794..16337f6a3 100644 --- a/tests/ten_runtime/smoke/extension_test/concurrent/one_engine_concurrent.cc +++ b/tests/ten_runtime/smoke/extension_test/concurrent/one_engine_concurrent.cc @@ -118,22 +118,14 @@ void *client_thread_main(TEN_UNUSED void *args) { client_port); // Send a user-defined 'hello world' command. - nlohmann::json request = R"({ - "_ten": { - "name": "test", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "extension_group_A", - "extension": "A" - }] - } - })"_json; - request["_ten"]["dest"][0]["graph"] = graph_id; - request["_ten"]["seq_id"] = seq_id_str; - - nlohmann::json resp = client->send_json_and_recv_resp_in_json(request); - ten_test::check_result_is(resp, seq_id_str, TEN_STATUS_CODE_OK, - R"({"a": "b"})"); + auto test_cmd = ten::cmd_t::create("test"); + test_cmd->set_dest("msgpack://127.0.0.1:8001/", graph_id.c_str(), + "extension_group_A", "A"); + + auto cmd_result = client->send_cmd_and_recv_result(std::move(test_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_json(cmd_result, R"({"a": "b"})"); // Destroy the client. delete client; @@ -164,12 +156,11 @@ TEST(ExtensionTest, OneEngineConcurrent) { // NOLINT client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json( R"({ "_ten": { - "type": "start_graph", "long_running_mode": true, - "seq_id": "55", "nodes": [{ "type": "extension", "name": "A", @@ -197,11 +188,14 @@ TEST(ExtensionTest, OneEngineConcurrent) { // NOLINT }] }] } - })"_json); + })"); + + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); - if (!resp.empty()) { - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); - graph_id = resp.value("detail", ""); + if (cmd_result) { + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + graph_id = cmd_result->get_property_string("detail"); break; } else { diff --git a/tests/ten_runtime/smoke/extension_test/dest/no_audio_frame_dest.cc b/tests/ten_runtime/smoke/extension_test/dest/no_audio_frame_dest.cc index bd3b3aa8b..ee34b9dae 100644 --- a/tests/ten_runtime/smoke/extension_test/dest/no_audio_frame_dest.cc +++ b/tests/ten_runtime/smoke/extension_test/dest/no_audio_frame_dest.cc @@ -10,6 +10,7 @@ #include "gtest/gtest.h" #include "include_internal/ten_runtime/binding/cpp/ten.h" +#include "ten_runtime/binding/cpp/internal/msg/cmd/start_graph.h" #include "ten_runtime/binding/cpp/internal/ten_env.h" #include "ten_utils/lang/cpp/lib/error.h" #include "ten_utils/lib/thread.h" @@ -109,11 +110,10 @@ TEST(ExtensionTest, NoAudioFrameDest) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json( R"({ "_ten": { - "type": "start_graph", - "seq_id": "55", "nodes": [{ "type": "extension", "name": "test_extension_1", @@ -153,24 +153,18 @@ TEST(ExtensionTest, NoAudioFrameDest) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/dest/specify_dest.cc b/tests/ten_runtime/smoke/extension_test/dest/specify_dest.cc index 7a2d6a9de..bc84afb45 100644 --- a/tests/ten_runtime/smoke/extension_test/dest/specify_dest.cc +++ b/tests/ten_runtime/smoke/extension_test/dest/specify_dest.cc @@ -245,22 +245,15 @@ TEST(ExtensionTest, SpecifyDest) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send the "initial_request" to the "business extension". - nlohmann::json const resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "initial_request", - "seq_id": "111", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "specify_dest_group", - "extension": "business_extension" - }] - } - })"_json); + auto initial_request_cmd = ten::cmd_t::create("initial_request"); + initial_request_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "specify_dest_group", "business_extension"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(initial_request_cmd)); // Check whether the correct result has been received. - ten_test::check_result_is(resp, "111", TEN_STATUS_CODE_OK, "success"); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "success"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/engine/batch_send_msgs_in_migration.cc b/tests/ten_runtime/smoke/extension_test/engine/batch_send_msgs_in_migration.cc index 3494023f8..9152fb70b 100644 --- a/tests/ten_runtime/smoke/extension_test/engine/batch_send_msgs_in_migration.cc +++ b/tests/ten_runtime/smoke/extension_test/engine/batch_send_msgs_in_migration.cc @@ -92,28 +92,19 @@ TEST(ExtensionTest, BatchSendMsgsInMigration) { // NOLINT // transfer one message to the runtime before the connection migration is // completed. for (int i = 0; i < size; i++) { - client->send_json( - R"({ - "_ten": { - "name": "test", - "seq_id": "123", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "migration_group", - "extension": "migration" - }] - } - })"_json); + auto test_cmd = ten::cmd_t::create("test"); + test_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "migration_group", "migration"); + client->send_cmd(std::move(test_cmd)); } int count = 0; while (count < size) { - auto results = client->batch_recv_resp_in_json(); + auto cmd_results = client->batch_recv_cmd_results(); - for (auto &resp : results) { - ten_test::check_result_is(resp, "123", TEN_STATUS_CODE_OK, - R"({"id":1,"name":"a"})"); + for (auto &cmd_result : cmd_results) { + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_json(cmd_result, R"({"id":1,"name":"a"})"); count++; } } diff --git a/tests/ten_runtime/smoke/extension_test/engine/engine_long_running_mode.cc b/tests/ten_runtime/smoke/extension_test/engine/engine_long_running_mode.cc index e21295f98..fe73b2f8c 100644 --- a/tests/ten_runtime/smoke/extension_test/engine/engine_long_running_mode.cc +++ b/tests/ten_runtime/smoke/extension_test/engine/engine_long_running_mode.cc @@ -33,10 +33,11 @@ class ExtensionB : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json resp = {{"a", "b"}}; + nlohmann::json detail = {{"a", "b"}}; auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); - cmd_result->set_property_from_json("detail", resp.dump().c_str()); + cmd_result->set_property_from_json("detail", detail.dump().c_str()); + ten_env.return_result(std::move(cmd_result), std::move(cmd)); } }; @@ -125,12 +126,11 @@ TEST(ExtensionTest, EngineLongRunningMode) { // NOLINT client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json( R"({ "_ten": { - "type": "start_graph", "long_running_mode": true, - "seq_id": "55", "nodes": [{ "type": "extension", "name": "A", @@ -158,11 +158,14 @@ TEST(ExtensionTest, EngineLongRunningMode) { // NOLINT }] }] } - })"_json); + })"); + + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); - if (!resp.empty()) { - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); - graph_id = resp.value("detail", ""); + if (cmd_result) { + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + graph_id = cmd_result->get_property_string("detail"); break; } else { @@ -183,22 +186,14 @@ TEST(ExtensionTest, EngineLongRunningMode) { // NOLINT client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send a user-defined 'hello world' command. - nlohmann::json request = - R"({ - "_ten": { - "name": "test", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "engine_long_running_mode__extension_group_A", - "extension": "A" - }] - } - })"_json; - request["_ten"]["dest"][0]["graph"] = graph_id; - - nlohmann::json resp = client->send_json_and_recv_resp_in_json(request); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, R"({"a": "b"})"); + auto test_cmd = ten::cmd_t::create("test"); + test_cmd->set_dest("msgpack://127.0.0.1:8001/", graph_id.c_str(), + "engine_long_running_mode__extension_group_A", "A"); + + auto cmd_result = client->send_cmd_and_recv_result(std::move(test_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_json(cmd_result, R"({"a": "b"})"); // Destroy the client. delete client; diff --git a/tests/ten_runtime/smoke/extension_test/engine/engine_one_loop_per_engine.cc b/tests/ten_runtime/smoke/extension_test/engine/engine_one_loop_per_engine.cc index dde52b9f0..7d6513f64 100644 --- a/tests/ten_runtime/smoke/extension_test/engine/engine_one_loop_per_engine.cc +++ b/tests/ten_runtime/smoke/extension_test/engine/engine_one_loop_per_engine.cc @@ -22,8 +22,7 @@ class test_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -73,12 +72,9 @@ TEST(ExtensionTest, EngineOneLoopPerEngine) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension", "addon": "engine_one_loop_per_engine__extension", @@ -86,24 +82,20 @@ TEST(ExtensionTest, EngineOneLoopPerEngine) { // NOLINT "extension_group": "engine_one_loop_per_engine" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "engine_one_loop_per_engine", - "extension": "test_extension" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "engine_one_loop_per_engine", "test_extension"); + + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); // Destroy the client. delete client; diff --git a/tests/ten_runtime/smoke/extension_test/engine/extension_send_msg_to_incorrect_engine.cc b/tests/ten_runtime/smoke/extension_test/engine/extension_send_msg_to_incorrect_engine.cc index 10b6474cc..bf3c0a06d 100644 --- a/tests/ten_runtime/smoke/extension_test/engine/extension_send_msg_to_incorrect_engine.cc +++ b/tests/ten_runtime/smoke/extension_test/engine/extension_send_msg_to_incorrect_engine.cc @@ -22,8 +22,7 @@ class test_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_shared = std::make_shared>(std::move(cmd)); @@ -85,12 +84,9 @@ TEST(ExtensionTest, ExtensionSendMsgToIncorrectEngine) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension", "addon": "extension_send_msg_to_incorrect_engine__extension", @@ -98,24 +94,21 @@ TEST(ExtensionTest, ExtensionSendMsgToIncorrectEngine) { // NOLINT "extension_group": "extension_send_msg_to_incorrect_engine" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "extension_send_msg_to_incorrect_engine", - "extension": "test_extension" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_ERROR, - "Graph not found."); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "extension_send_msg_to_incorrect_engine", + "test_extension"); + + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_ERROR); + ten_test::check_detail_with_string(cmd_result, "Graph not found."); // Destroy the client. delete client; diff --git a/tests/ten_runtime/smoke/extension_test/engine/wrong_engine_then_correct_in_migration.cc b/tests/ten_runtime/smoke/extension_test/engine/wrong_engine_then_correct_in_migration.cc index 36db18db8..44c803fdb 100644 --- a/tests/ten_runtime/smoke/extension_test/engine/wrong_engine_then_correct_in_migration.cc +++ b/tests/ten_runtime/smoke/extension_test/engine/wrong_engine_then_correct_in_migration.cc @@ -89,58 +89,37 @@ TEST(ExtensionTest, WrongEngineThenCorrectInMigration) { // NOLINT // Send a message to the wrong engine, the connection won't be migrated as the // engine is not found. - auto resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "test", - "seq_id": "1", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "incorrect_graph_id", - "extension_group": "migration_group", - "extension": "migration" - }] - } - })"_json); - ten_test::check_result_is(resp, "1", TEN_STATUS_CODE_ERROR, - "Graph not found."); + auto test_cmd = ten::cmd_t::create("test"); + test_cmd->set_dest("msgpack://127.0.0.1:8001/", "incorrect_graph_id", + "migration_group", "migration"); + + auto cmd_result = client->send_cmd_and_recv_result(std::move(test_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_ERROR); + ten_test::check_detail_with_string(cmd_result, "Graph not found."); // Send a message to the correct engine, the connection will be migrated, and // the belonging thread of the connection should be correct. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "test", - "seq_id": "2", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "migration_group", - "extension": "migration" - }] - } - })"_json); - ten_test::check_result_is(resp, "2", TEN_STATUS_CODE_OK, - R"({"id":1,"name":"a"})"); + test_cmd = ten::cmd_t::create("test"); + test_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", "migration_group", + "migration"); + + cmd_result = client->send_cmd_and_recv_result(std::move(test_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_json(cmd_result, R"({"id":1,"name":"a"})"); // The connection attaches to the remote now as it is migrated. Then send a // message to the wrong engine again, the message should be forwarded to the // app. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "test", - "seq_id": "3", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "incorrect_graph_id", - "extension_group": "migration_group", - "extension": "migration" - }] - } - })"_json); - ten_test::check_result_is(resp, "3", TEN_STATUS_CODE_ERROR, - "Graph not found."); + test_cmd = ten::cmd_t::create("test"); + test_cmd->set_dest("msgpack://127.0.0.1:8001/", "incorrect_graph_id", + "migration_group", "migration"); + + cmd_result = client->send_cmd_and_recv_result(std::move(test_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_ERROR); + ten_test::check_detail_with_string(cmd_result, "Graph not found."); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/error/error_client_send_json.cc b/tests/ten_runtime/smoke/extension_test/error/error_client_send_json.cc index 5342ed343..58ed5238b 100644 --- a/tests/ten_runtime/smoke/extension_test/error/error_client_send_json.cc +++ b/tests/ten_runtime/smoke/extension_test/error/error_client_send_json.cc @@ -15,7 +15,6 @@ #include "ten_utils/lib/smart_ptr.h" #include "ten_utils/lib/thread.h" #include "tests/common/client/msgpack_tcp.h" -#include "tests/ten_runtime/smoke/extension_test/util/check.h" namespace { diff --git a/tests/ten_runtime/smoke/extension_test/error/failed_to_connect_to_remote.cc b/tests/ten_runtime/smoke/extension_test/error/failed_to_connect_to_remote.cc index ca62fc456..6e2237a21 100644 --- a/tests/ten_runtime/smoke/extension_test/error/failed_to_connect_to_remote.cc +++ b/tests/ten_runtime/smoke/extension_test/error/failed_to_connect_to_remote.cc @@ -39,8 +39,7 @@ class test_predefined_graph : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "test") { + if (std::string(cmd->get_name()) == "test") { nlohmann::json detail = {{"id", 1}, {"name", "a"}}; auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); @@ -149,21 +148,13 @@ TEST(ExtensionTest, FailedToConnectToRemote) { // NOLINT // Do not need to send 'start_graph' command first. // The 'graph_id' MUST be "default" if we want to send the request to // predefined graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "test", - "seq_id": "111", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "failed_to_connect_to_remote__predefined_graph_group", - "extension": "predefined_graph" - }] - } - })"_json); - ten_test::check_result_is(resp, "111", TEN_STATUS_CODE_OK, - R"({"id": 1, "name": "a"})"); + auto test_cmd = ten::cmd_t::create("test"); + test_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "failed_to_connect_to_remote__predefined_graph_group", + "predefined_graph"); + auto cmd_result = client->send_cmd_and_recv_result(std::move(test_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_json(cmd_result, R"({"id": 1, "name": "a"})"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/extension/extension_reg_extension.cc b/tests/ten_runtime/smoke/extension_test/extension/extension_reg_extension.cc index 61e880e7b..0d1d4804a 100644 --- a/tests/ten_runtime/smoke/extension_test/extension/extension_reg_extension.cc +++ b/tests/ten_runtime/smoke/extension_test/extension/extension_reg_extension.cc @@ -21,8 +21,7 @@ class test_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -72,12 +71,9 @@ TEST(ExtensionTest, ExtensionRegExtension) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "extension_reg_extension", "addon": "extension_reg_extension__extension", @@ -85,24 +81,19 @@ TEST(ExtensionTest, ExtensionRegExtension) { // NOLINT "extension_group": "extension_reg_extension" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "extension_reg_extension", - "extension": "extension_reg_extension" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "extension_reg_extension", + "extension_reg_extension"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); // Destroy the client. delete client; diff --git a/tests/ten_runtime/smoke/extension_test/extension/extension_reg_extension_and_create_group.cc b/tests/ten_runtime/smoke/extension_test/extension/extension_reg_extension_and_create_group.cc index 6a2c36d74..4ba4df531 100644 --- a/tests/ten_runtime/smoke/extension_test/extension/extension_reg_extension_and_create_group.cc +++ b/tests/ten_runtime/smoke/extension_test/extension/extension_reg_extension_and_create_group.cc @@ -26,8 +26,7 @@ class test_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -78,12 +77,9 @@ TEST(ExtensionTest, ExtensionRegExtensionAndCreateGroup) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension", "addon": "extension_reg_extension_and_create_group__extension", @@ -91,24 +87,20 @@ TEST(ExtensionTest, ExtensionRegExtensionAndCreateGroup) { // NOLINT "extension_group": "extension_reg_extension_and_create_group__extension_group" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "extension_reg_extension_and_create_group__extension_group", - "extension": "test_extension" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest( + "msgpack://127.0.0.1:8001/", nullptr, + "extension_reg_extension_and_create_group__extension_group", + "test_extension"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/extension/extension_reg_extension_group.cc b/tests/ten_runtime/smoke/extension_test/extension/extension_reg_extension_group.cc index e7d4ece8a..b75d3e2f3 100644 --- a/tests/ten_runtime/smoke/extension_test/extension/extension_reg_extension_group.cc +++ b/tests/ten_runtime/smoke/extension_test/extension/extension_reg_extension_group.cc @@ -22,8 +22,7 @@ class test_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -73,12 +72,9 @@ TEST(ExtensionTest, ExtensionRegExtensionGroup) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension", "addon": "extension_reg_extension_group__extension", @@ -86,23 +82,17 @@ TEST(ExtensionTest, ExtensionRegExtensionGroup) { // NOLINT "extension_group": "extension_reg_extension_group__extension_group" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); - - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "extension_reg_extension_group__extension_group", - "extension": "test_extension" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "extension_reg_extension_group__extension_group", + "test_extension"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/extension/extension_with_same_name.cc b/tests/ten_runtime/smoke/extension_test/extension/extension_with_same_name.cc index 238dee96b..fa54787d4 100644 --- a/tests/ten_runtime/smoke/extension_test/extension/extension_with_same_name.cc +++ b/tests/ten_runtime/smoke/extension_test/extension/extension_with_same_name.cc @@ -22,8 +22,7 @@ class test_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -115,12 +114,9 @@ TEST(ExtensionTest, ExtensionWithSameName) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "same_name", "addon": "extension_with_same_name__extension", @@ -134,24 +130,19 @@ TEST(ExtensionTest, ExtensionWithSameName) { // NOLINT "extension_group": "extension_with_same_name__extension_group_2" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "extension_with_same_name__extension_group_1", - "extension": "same_name" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "extension_with_same_name__extension_group_1", + "same_name"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/extension_group/extension_group_not_specified.cc b/tests/ten_runtime/smoke/extension_test/extension_group/extension_group_not_specified.cc index 85e31de42..3dd3f61c7 100644 --- a/tests/ten_runtime/smoke/extension_test/extension_group/extension_group_not_specified.cc +++ b/tests/ten_runtime/smoke/extension_test/extension_group/extension_group_not_specified.cc @@ -21,8 +21,7 @@ class test_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -71,12 +70,9 @@ TEST(ExtensionTest, ExtensionGroupNotSpecified) { auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "extension_group_not_specified__extension", @@ -90,24 +86,19 @@ TEST(ExtensionTest, ExtensionGroupNotSpecified) { "extension_group": "extension_group_not_specified" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "extension_group_not_specified", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "extension_group_not_specified", + "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/extension_group/extension_group_with_same_name.cc b/tests/ten_runtime/smoke/extension_test/extension_group/extension_group_with_same_name.cc index 742571902..68dd4b827 100644 --- a/tests/ten_runtime/smoke/extension_test/extension_group/extension_group_with_same_name.cc +++ b/tests/ten_runtime/smoke/extension_test/extension_group/extension_group_with_same_name.cc @@ -21,8 +21,7 @@ class test_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -71,12 +70,9 @@ TEST(ExtensionTest, ExtensionGroupWithSameName) { auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "extension_group_with_same_name__extension", @@ -90,24 +86,19 @@ TEST(ExtensionTest, ExtensionGroupWithSameName) { "extension_group": "extension_group_with_same_name" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "extension_group_with_same_name", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "extension_group_with_same_name", + "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/extension_group/extension_group_with_same_name_and_topo_info.cc b/tests/ten_runtime/smoke/extension_test/extension_group/extension_group_with_same_name_and_topo_info.cc index 0c7dabc94..cd8cd01e4 100644 --- a/tests/ten_runtime/smoke/extension_test/extension_group/extension_group_with_same_name_and_topo_info.cc +++ b/tests/ten_runtime/smoke/extension_test/extension_group/extension_group_with_same_name_and_topo_info.cc @@ -21,8 +21,7 @@ class test_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -71,12 +70,9 @@ TEST(ExtensionTest, ExtensionGroupWithSameNameAndGraphInfo) { auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "extension_group_with_same_name_and_graph_info__extension", @@ -103,24 +99,18 @@ TEST(ExtensionTest, ExtensionGroupWithSameNameAndGraphInfo) { }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "same_name_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "same_name_extension_group", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/graph/graph_lack_something_1.cc b/tests/ten_runtime/smoke/extension_test/graph/graph_lack_something_1.cc index d7992044c..19b072192 100644 --- a/tests/ten_runtime/smoke/extension_test/graph/graph_lack_something_1.cc +++ b/tests/ten_runtime/smoke/extension_test/graph/graph_lack_something_1.cc @@ -21,9 +21,7 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { ten_env.send_cmd(std::move(cmd)); return; } @@ -36,8 +34,7 @@ class test_extension_2 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -89,12 +86,9 @@ TEST(ExtensionTest, GraphLackSomething1) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "extension_group": "graph_lack_something_1", @@ -121,24 +115,20 @@ TEST(ExtensionTest, GraphLackSomething1) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "graph_lack_something_1", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "graph_lack_something_1", "test_extension_1"); + + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/graph/graph_lack_something_2.cc b/tests/ten_runtime/smoke/extension_test/graph/graph_lack_something_2.cc index 13e3de6c4..ab98d90da 100644 --- a/tests/ten_runtime/smoke/extension_test/graph/graph_lack_something_2.cc +++ b/tests/ten_runtime/smoke/extension_test/graph/graph_lack_something_2.cc @@ -21,9 +21,7 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { ten_env.send_cmd(std::move(cmd)); return; } @@ -36,8 +34,7 @@ class test_extension_2 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -89,12 +86,9 @@ TEST(ExtensionTest, GraphLackSomething2) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "graph_lack_something_2__extension_1", @@ -121,24 +115,18 @@ TEST(ExtensionTest, GraphLackSomething2) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "graph_lack_something_2", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "graph_lack_something_2", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/graph/graph_lack_something_3.cc b/tests/ten_runtime/smoke/extension_test/graph/graph_lack_something_3.cc index 7db5a044f..6c8345d44 100644 --- a/tests/ten_runtime/smoke/extension_test/graph/graph_lack_something_3.cc +++ b/tests/ten_runtime/smoke/extension_test/graph/graph_lack_something_3.cc @@ -21,9 +21,7 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { ten_env.send_cmd(std::move(cmd)); return; } @@ -36,8 +34,7 @@ class test_extension_2 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -89,12 +86,9 @@ TEST(ExtensionTest, GraphLackSomething3) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "graph_lack_something_3__extension_1", @@ -121,24 +115,18 @@ TEST(ExtensionTest, GraphLackSomething3) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "graph_lack_something_3", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "graph_lack_something_3", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/graph/graph_loop_in_multi_app.cc b/tests/ten_runtime/smoke/extension_test/graph/graph_loop_in_multi_app.cc index e41a64c8c..2ba1531b7 100644 --- a/tests/ten_runtime/smoke/extension_test/graph/graph_loop_in_multi_app.cc +++ b/tests/ten_runtime/smoke/extension_test/graph/graph_loop_in_multi_app.cc @@ -23,8 +23,7 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { ten_env.send_cmd(std::move(cmd)); return; } @@ -37,8 +36,7 @@ class test_extension_2 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -52,8 +50,7 @@ class test_extension_3 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { ten_env.send_cmd(std::move(cmd)); return; } @@ -66,8 +63,7 @@ class test_extension_4 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -189,12 +185,9 @@ TEST(ExtensionTest, GraphLoopInMultiApp) { // NOLINT client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "graph_loop_in_multi_app__extension_1", @@ -269,11 +262,13 @@ TEST(ExtensionTest, GraphLoopInMultiApp) { // NOLINT }] }] } - })"_json); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); - if (!resp.empty()) { - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); - graph_id = resp["detail"]; + if (cmd_result) { + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + graph_id = cmd_result->get_property_string("detail"); break; } else { delete client; @@ -287,42 +282,28 @@ TEST(ExtensionTest, GraphLoopInMultiApp) { // NOLINT TEN_ASSERT(client, "Failed to connect to the TEN app."); // Send a user-defined 'hello world' command to 'extension 1'. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "graph_loop_in_multi_app__extension_group_1", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "graph_loop_in_multi_app__extension_group_1", + "test_extension_1"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); // Send a user-defined 'hello world' command to 'extension 2'. // The command MUST be sent to the dest directly. auto *client2 = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8002/"); - nlohmann::json request_2 = - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "138", - "dest":[{ - "app": "msgpack://127.0.0.1:8002/", - "extension_group": "graph_loop_in_multi_app__extension_group_2", - "extension": "test_extension_2" - }] - } - })"_json; - request_2["_ten"]["dest"][0]["graph"] = graph_id; - resp = client2->send_json_and_recv_resp_in_json(request_2); - - ten_test::check_result_is(resp, "138", TEN_STATUS_CODE_OK, - "hello world, too"); + hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8002/", graph_id.c_str(), + "graph_loop_in_multi_app__extension_group_2", + "test_extension_2"); + + cmd_result = client2->send_cmd_and_recv_result(std::move(hello_world_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; delete client2; diff --git a/tests/ten_runtime/smoke/extension_test/graph/graph_loop_in_one_app.cc b/tests/ten_runtime/smoke/extension_test/graph/graph_loop_in_one_app.cc index a3021da56..12b5f2721 100644 --- a/tests/ten_runtime/smoke/extension_test/graph/graph_loop_in_one_app.cc +++ b/tests/ten_runtime/smoke/extension_test/graph/graph_loop_in_one_app.cc @@ -21,8 +21,7 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { ten_env.send_cmd(std::move(cmd)); return; } @@ -35,8 +34,7 @@ class test_extension_2 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -50,8 +48,7 @@ class test_extension_3 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { ten_env.send_cmd(std::move(cmd)); return; } @@ -64,8 +61,7 @@ class test_extension_4 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -121,12 +117,9 @@ TEST(ExtensionTest, GraphLoopInOneApp) { auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "graph_loop_in_one_app__extension_1", @@ -201,40 +194,28 @@ TEST(ExtensionTest, GraphLoopInOneApp) { }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command to 'extension 1'. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "graph_loop_in_one_app__extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "graph_loop_in_one_app__extension_group", + "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); // Send a user-defined 'hello world' command to 'extension 2'. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "138", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "graph_loop_in_one_app__extension_group", - "extension": "test_extension_2" - }] - } - })"_json); - ten_test::check_result_is(resp, "138", TEN_STATUS_CODE_OK, - "hello world, too"); + hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "graph_loop_in_one_app__extension_group", + "test_extension_2"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); // Destroy the client. delete client; diff --git a/tests/ten_runtime/smoke/extension_test/graph/graph_loop_multiple_circle.cc b/tests/ten_runtime/smoke/extension_test/graph/graph_loop_multiple_circle.cc index 0c9012de1..468e2c87d 100644 --- a/tests/ten_runtime/smoke/extension_test/graph/graph_loop_multiple_circle.cc +++ b/tests/ten_runtime/smoke/extension_test/graph/graph_loop_multiple_circle.cc @@ -36,10 +36,8 @@ class test_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - - if (json["_ten"]["name"] == "sum") { - // TEN_ENV_LOG_ERROR(ten_env, std::to_string(counter_).c_str()); + if (std::string(cmd->get_name()) == "sum") { + nlohmann::json json = nlohmann::json::parse(cmd->to_json()); if (counter_ == 2) { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); @@ -112,12 +110,9 @@ TEST(ExtensionTest, GraphLoopMultipleCircle) { // NOLINT // Create a client and connect to the app. auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "dest": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"dest": [{ "app": "msgpack://127.0.0.1:8001/" }], "nodes": [{ @@ -207,24 +202,18 @@ TEST(ExtensionTest, GraphLoopMultipleCircle) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); - - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "sum", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "graph_loop_multiple_circle__extension_group", - "extension": "A" - }] - } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); - - nlohmann::json detail = resp["detail"]; + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + auto sum_cmd = ten::cmd_t::create("sum"); + sum_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "graph_loop_multiple_circle__extension_group", "A"); + cmd_result = client->send_cmd_and_recv_result(std::move(sum_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + + nlohmann::json detail = + nlohmann::json::parse(cmd_result->get_property_to_json("detail")); EXPECT_EQ((1 + 2 + 3) * 2, std::stoi(detail["total"].get())); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/graph/graph_loop_multiple_circle_through_cmd.cc b/tests/ten_runtime/smoke/extension_test/graph/graph_loop_multiple_circle_through_cmd.cc index 6b2f8f7c0..96353d05d 100644 --- a/tests/ten_runtime/smoke/extension_test/graph/graph_loop_multiple_circle_through_cmd.cc +++ b/tests/ten_runtime/smoke/extension_test/graph/graph_loop_multiple_circle_through_cmd.cc @@ -109,12 +109,9 @@ TEST(ExtensionTest, DISABLED_GraphLoopMultipleCircleThroughCmd) { // NOLINT // Create a client and connect to the app. auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "dest": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"dest": [{ "app": "msgpack://127.0.0.1:8001/" }], "nodes": [{ @@ -204,24 +201,19 @@ TEST(ExtensionTest, DISABLED_GraphLoopMultipleCircleThroughCmd) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); - - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "sum", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "graph_loop_multiple_circle_through_cmd__extension_group", - "extension": "A" - }] - } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); - - nlohmann::json detail = resp["detail"]; + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + auto sum_cmd = ten::cmd_t::create("sum"); + sum_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "graph_loop_multiple_circle_through_cmd__extension_group", + "A"); + cmd_result = client->send_cmd_and_recv_result(std::move(sum_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + + nlohmann::json detail = + nlohmann::json::parse(cmd_result->get_property_to_json("detail")); EXPECT_EQ((1 + 2 + 3) * 2, detail["total"].get()); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/graph/graph_loop_multiple_circle_through_cmd_with_default.cc b/tests/ten_runtime/smoke/extension_test/graph/graph_loop_multiple_circle_through_cmd_with_default.cc index fa895081e..838a9f892 100644 --- a/tests/ten_runtime/smoke/extension_test/graph/graph_loop_multiple_circle_through_cmd_with_default.cc +++ b/tests/ten_runtime/smoke/extension_test/graph/graph_loop_multiple_circle_through_cmd_with_default.cc @@ -107,12 +107,9 @@ TEST(ExtensionTest, // Create a client and connect to the app. auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "dest": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"dest": [{ "app": "msgpack://127.0.0.1:8001/" }], "nodes": [{ @@ -202,24 +199,20 @@ TEST(ExtensionTest, }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); - - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "sum", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "graph_loop_multiple_circle_through_cmd_with_default__extension_group", - "extension": "A" - }] - } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); - - nlohmann::json detail = resp["detail"]; + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + auto sum_cmd = ten::cmd_t::create("sum"); + sum_cmd->set_dest( + "msgpack://127.0.0.1:8001/", nullptr, + "graph_loop_multiple_circle_through_cmd_with_default__extension_group", + "A"); + cmd_result = client->send_cmd_and_recv_result(std::move(sum_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + + nlohmann::json detail = + nlohmann::json::parse(cmd_result->get_property_to_json("detail")); EXPECT_EQ((1 + 2 + 3) * 2, detail["total"].get()); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/graph/graph_multiple_polygon.cc b/tests/ten_runtime/smoke/extension_test/graph/graph_multiple_polygon.cc index 72778b3cb..5c5c99eea 100644 --- a/tests/ten_runtime/smoke/extension_test/graph/graph_multiple_polygon.cc +++ b/tests/ten_runtime/smoke/extension_test/graph/graph_multiple_polygon.cc @@ -47,14 +47,16 @@ class test_extension : public ten::extension_t { if (is_leaf_node_) { json["return_from"] = name_; + auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property_from_json("detail", json.dump().c_str()); + ten_env.return_result(std::move(cmd_result), std::move(cmd)); return; } std::vector edges = {"B", "C", "D", "E", "F", "G"}; - if (json["_ten"]["name"] == "send") { + if (std::string(cmd->get_name()) == "send") { json["from"] = name_; if (std::find(edges.begin(), edges.end(), name_) != edges.end()) { json[name_] = name_; @@ -222,12 +224,9 @@ TEST(ExtensionTest, GraphMultiplePolygon) { // NOLINT ++i) { client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "dest": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"dest": [{ "app": "msgpack://127.0.0.1:8001/" }], "nodes": [{ @@ -401,10 +400,12 @@ TEST(ExtensionTest, GraphMultiplePolygon) { // NOLINT }] }] } - })"_json); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); - if (!resp.empty()) { - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + if (cmd_result) { + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); break; } else { delete client; @@ -417,20 +418,14 @@ TEST(ExtensionTest, GraphMultiplePolygon) { // NOLINT TEN_ASSERT(client, "Failed to connect to the TEN app."); - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "send", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "graph_multiple_polygon_1", - "extension": "A" - }] - } - })"_json); - - nlohmann::json detail = resp["detail"]; + auto send_cmd = ten::cmd_t::create("send"); + send_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "graph_multiple_polygon_1", "A"); + + auto cmd_result = client->send_cmd_and_recv_result(std::move(send_cmd)); + + nlohmann::json detail = + nlohmann::json::parse(cmd_result->get_property_to_json("detail")); EXPECT_EQ(detail["return_from"], "A"); EXPECT_EQ(detail["success"], true); EXPECT_EQ(detail["received_count"], 1); diff --git a/tests/ten_runtime/smoke/extension_test/graph/graph_multiple_polygon_one_app.cc b/tests/ten_runtime/smoke/extension_test/graph/graph_multiple_polygon_one_app.cc index c85433c44..d58ab1ad4 100644 --- a/tests/ten_runtime/smoke/extension_test/graph/graph_multiple_polygon_one_app.cc +++ b/tests/ten_runtime/smoke/extension_test/graph/graph_multiple_polygon_one_app.cc @@ -48,7 +48,7 @@ class test_extension : public ten::extension_t { } std::vector edges = {"B", "C", "D", "E", "F", "G"}; - if (json["_ten"]["name"] == "send") { + if (std::string(cmd->get_name()) == "send") { json["from"] = name_; if (std::find(edges.begin(), edges.end(), name_) != edges.end()) { json[name_] = name_; @@ -149,12 +149,9 @@ TEST(ExtensionTest, GraphMultiplePolygonOneApp) { // NOLINT // Create a client and connect to the app. auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "dest": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"dest": [{ "app": "msgpack://127.0.0.1:8001/" }], "nodes": [{ @@ -328,23 +325,17 @@ TEST(ExtensionTest, GraphMultiplePolygonOneApp) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); - - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "send", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "graph_multiple_polygon_one_app__extension_group", - "extension": "A" - }] - } - })"_json); - nlohmann::json detail = resp["detail"]; + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + auto send_cmd = ten::cmd_t::create("send"); + send_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "graph_multiple_polygon_one_app__extension_group", "A"); + cmd_result = client->send_cmd_and_recv_result(std::move(send_cmd)); + nlohmann::json detail = + nlohmann::json::parse(cmd_result->get_property_to_json("detail")); EXPECT_EQ(detail["return_from"], "A"); EXPECT_EQ(detail["success"], true); EXPECT_EQ(detail["received_count"], 1); diff --git a/tests/ten_runtime/smoke/extension_test/graph/graph_out_of_order_1.cc b/tests/ten_runtime/smoke/extension_test/graph/graph_out_of_order_1.cc index 70df37f88..f9297e1af 100644 --- a/tests/ten_runtime/smoke/extension_test/graph/graph_out_of_order_1.cc +++ b/tests/ten_runtime/smoke/extension_test/graph/graph_out_of_order_1.cc @@ -84,12 +84,9 @@ TEST(ExtensionTest, GraphOutOfOrder1) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "graph_out_of_order_1__test_extension_1", @@ -103,39 +100,29 @@ TEST(ExtensionTest, GraphOutOfOrder1) { // NOLINT "app": "msgpack://127.0.0.1:8001/" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group 1", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello from test extension 1"); - - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group 2", - "extension": "test_extension_2" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello from test extension 2"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group 1", "test_extension_1"); + + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello from test extension 1"); + + hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group 2", "test_extension_2"); + + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello from test extension 2"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/graph/graph_out_of_order_2.cc b/tests/ten_runtime/smoke/extension_test/graph/graph_out_of_order_2.cc index c35c38243..d4e447406 100644 --- a/tests/ten_runtime/smoke/extension_test/graph/graph_out_of_order_2.cc +++ b/tests/ten_runtime/smoke/extension_test/graph/graph_out_of_order_2.cc @@ -84,12 +84,9 @@ TEST(ExtensionTest, GraphOutOfOrder2) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "graph_out_of_order_2__test_extension_1", @@ -103,39 +100,29 @@ TEST(ExtensionTest, GraphOutOfOrder2) { // NOLINT "app": "msgpack://127.0.0.1:8001/" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group 1", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello from test extension 1"); - - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group 2", - "extension": "test_extension_2" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello from test extension 2"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group 1", "test_extension_1"); + + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello from test extension 1"); + + hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group 2", "test_extension_2"); + + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello from test extension 2"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/graph/graph_polygon_in_one_app_return_all_1.cc b/tests/ten_runtime/smoke/extension_test/graph/graph_polygon_in_one_app_return_all_1.cc index f1afb2969..67f7ec29a 100644 --- a/tests/ten_runtime/smoke/extension_test/graph/graph_polygon_in_one_app_return_all_1.cc +++ b/tests/ten_runtime/smoke/extension_test/graph/graph_polygon_in_one_app_return_all_1.cc @@ -44,7 +44,7 @@ class test_extension : public ten::extension_t { } std::vector edges = {"B", "C"}; - if (json["_ten"]["name"] == "send") { + if (std::string(cmd->get_name()) == "send") { json["from"] = name_; if (std::find(edges.begin(), edges.end(), name_) != edges.end()) { json["source"] = name_; @@ -126,12 +126,9 @@ TEST(ExtensionTest, GraphPolygonInOneAppReturnAll1) { // NOLINT // Create a client and connect to the app. auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "dest": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"dest": [{ "app": "msgpack://127.0.0.1:8001/" }], "nodes": [{ @@ -217,23 +214,18 @@ TEST(ExtensionTest, GraphPolygonInOneAppReturnAll1) { // NOLINT "extension": "D" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); - - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "send", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "graph_polygon_in_one_app_return_all_1__extension_group", - "extension": "A" - }] - } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); - nlohmann::json detail = resp["detail"]; + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + auto send_cmd = ten::cmd_t::create("send"); + send_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "graph_polygon_in_one_app_return_all_1__extension_group", + "A"); + cmd_result = client->send_cmd_and_recv_result(std::move(send_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + nlohmann::json detail = + nlohmann::json::parse(cmd_result->get_property_to_json("detail")); EXPECT_EQ(detail["return_from"], "A"); EXPECT_EQ(detail["success"], true); diff --git a/tests/ten_runtime/smoke/extension_test/graph/graph_polygon_in_one_app_return_all_2.cc b/tests/ten_runtime/smoke/extension_test/graph/graph_polygon_in_one_app_return_all_2.cc index 93fd6f315..c38458a76 100644 --- a/tests/ten_runtime/smoke/extension_test/graph/graph_polygon_in_one_app_return_all_2.cc +++ b/tests/ten_runtime/smoke/extension_test/graph/graph_polygon_in_one_app_return_all_2.cc @@ -44,7 +44,7 @@ class test_extension : public ten::extension_t { } std::vector edges = {"B", "C"}; - if (json["_ten"]["name"] == "send") { + if (std::string(cmd->get_name()) == "send") { json["from"] = name_; if (std::find(edges.begin(), edges.end(), name_) != edges.end()) { json["source"] = name_; @@ -126,12 +126,9 @@ TEST(ExtensionTest, GraphPolygonInOneAppReturnAll2) { // NOLINT // Create a client and connect to the app. auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "dest": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"dest": [{ "app": "msgpack://127.0.0.1:8001/" }], "nodes": [{ @@ -217,23 +214,18 @@ TEST(ExtensionTest, GraphPolygonInOneAppReturnAll2) { // NOLINT "extension": "D" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); - - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "send", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "graph_polygon_in_one_app_return_all_2__extension_group", - "extension": "A" - }] - } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); - nlohmann::json detail = resp["detail"]; + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + auto send_cmd = ten::cmd_t::create("send"); + send_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "graph_polygon_in_one_app_return_all_2__extension_group", + "A"); + cmd_result = client->send_cmd_and_recv_result(std::move(send_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + nlohmann::json detail = + nlohmann::json::parse(cmd_result->get_property_to_json("detail")); EXPECT_EQ(detail["return_from"], "A"); EXPECT_EQ(detail["success"], true); diff --git a/tests/ten_runtime/smoke/extension_test/graph/graph_y_shape_in_multi_app.cc b/tests/ten_runtime/smoke/extension_test/graph/graph_y_shape_in_multi_app.cc index fcabf8a4e..67e7814bd 100644 --- a/tests/ten_runtime/smoke/extension_test/graph/graph_y_shape_in_multi_app.cc +++ b/tests/ten_runtime/smoke/extension_test/graph/graph_y_shape_in_multi_app.cc @@ -23,8 +23,7 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { ten_env.send_cmd(std::move(cmd)); return; } @@ -37,8 +36,7 @@ class test_extension_2 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { ten_env.send_cmd(std::move(cmd)); return; } @@ -51,8 +49,7 @@ class test_extension_3 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { ten_env.send_cmd(std::move(cmd)); return; } @@ -65,8 +62,7 @@ class test_extension_4 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -188,11 +184,9 @@ TEST(ExtensionTest, GraphYShapeInMultiApp) { // NOLINT client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": { "nodes": [{ "type": "extension", "name": "test_extension_1", @@ -256,11 +250,13 @@ TEST(ExtensionTest, GraphYShapeInMultiApp) { // NOLINT }] }] } - })"_json); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); - if (!resp.empty()) { - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); - graph_id = resp["detail"]; + if (cmd_result) { + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + graph_id = cmd_result->get_property_string("detail"); break; } else { @@ -275,41 +271,27 @@ TEST(ExtensionTest, GraphYShapeInMultiApp) { // NOLINT TEN_ASSERT(client, "Failed to connect to the TEN app."); // Send a user-defined 'hello world' command to 'extension 1'. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "graph_y_shape_in_multi_app__extension_group_1", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "graph_y_shape_in_multi_app__extension_group_1", + "test_extension_1"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); // Send a user-defined 'hello world' command to 'extension 2'. auto *client2 = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8002/"); - nlohmann::json request2 = - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "138", - "dest":[{ - "app": "msgpack://127.0.0.1:8002/", - "extension_group": "graph_y_shape_in_multi_app__extension_group_2", - "extension": "test_extension_2" - }] - } - })"_json; - request2["_ten"]["dest"][0]["graph"] = graph_id; - resp = client2->send_json_and_recv_resp_in_json(request2); - - ten_test::check_result_is(resp, "138", TEN_STATUS_CODE_OK, - "hello world, too"); + hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8002/", graph_id.c_str(), + "graph_y_shape_in_multi_app__extension_group_2", + "test_extension_2"); + + cmd_result = client2->send_cmd_and_recv_result(std::move(hello_world_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; delete client2; diff --git a/tests/ten_runtime/smoke/extension_test/graph/graph_y_shape_in_one_app.cc b/tests/ten_runtime/smoke/extension_test/graph/graph_y_shape_in_one_app.cc index 4ed9be719..0ef8b8ebe 100644 --- a/tests/ten_runtime/smoke/extension_test/graph/graph_y_shape_in_one_app.cc +++ b/tests/ten_runtime/smoke/extension_test/graph/graph_y_shape_in_one_app.cc @@ -21,8 +21,7 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { ten_env.send_cmd(std::move(cmd)); return; } @@ -35,8 +34,7 @@ class test_extension_2 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { ten_env.send_cmd(std::move(cmd)); return; } @@ -49,8 +47,7 @@ class test_extension_3 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { ten_env.send_cmd(std::move(cmd)); return; } @@ -63,8 +60,7 @@ class test_extension_4 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -120,12 +116,9 @@ TEST(ExtensionTest, GraphYShapeInOneApp) { auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "graph_y_shape_in_one_app__extension_1", @@ -188,40 +181,28 @@ TEST(ExtensionTest, GraphYShapeInOneApp) { }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command to 'extension 1'. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "graph_y_shape_in_one_app__extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "graph_y_shape_in_one_app__extension_group", + "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); // Send a user-defined 'hello world' command to 'extension 2'. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "138", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "graph_y_shape_in_one_app__extension_group", - "extension": "test_extension_2" - }] - } - })"_json); - ten_test::check_result_is(resp, "138", TEN_STATUS_CODE_OK, - "hello world, too"); + hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "graph_y_shape_in_one_app__extension_group", + "test_extension_2"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/graph_name/graph_name_basic.cc b/tests/ten_runtime/smoke/extension_test/graph_name/graph_name_basic.cc index 89db8807d..24ad822aa 100644 --- a/tests/ten_runtime/smoke/extension_test/graph_name/graph_name_basic.cc +++ b/tests/ten_runtime/smoke/extension_test/graph_name/graph_name_basic.cc @@ -32,9 +32,11 @@ class test_extension : public ten::extension_t { // extension1(app1) -> extension3(app2) -> extension2(app1) -> return if (name_ == "extension2") { - const nlohmann::json resp = {{"id", 1}, {"name", "aa"}}; + const nlohmann::json detail = {{"id", 1}, {"name", "aa"}}; + auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); - cmd_result->set_property_from_json("detail", resp.dump().c_str()); + cmd_result->set_property_from_json("detail", detail.dump().c_str()); + ten_env.return_result(std::move(cmd_result), std::move(cmd)); } else { ten_env.send_cmd(std::move(cmd), @@ -132,12 +134,9 @@ TEST(ExtensionTest, GraphNameBasic) { // NOLINT ++i) { client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "dest": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"dest": [{ "app": "msgpack://127.0.0.1:8001/" }], "nodes": [{ @@ -185,11 +184,14 @@ TEST(ExtensionTest, GraphNameBasic) { // NOLINT }] }] } - })"_json); + })"); + + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); - if (!resp.empty()) { - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); - graph_id = resp["detail"].get(); + if (cmd_result) { + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + graph_id = cmd_result->get_property_string("detail"); break; } else { @@ -205,55 +207,35 @@ TEST(ExtensionTest, GraphNameBasic) { // NOLINT // Send data to extension_1, it will return from extension_2 with json // result. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "send_message", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "graph_id_basic__extension_group_1", - "extension": "extension1" - }] - } - })"_json); - ten_test::check_detail_is(resp, R"({"id": 1, "name": "aa"})"); + auto send_message_cmd = ten::cmd_t::create("send_message"); + send_message_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "graph_id_basic__extension_group_1", "extension1"); + + auto cmd_result = + client->send_cmd_and_recv_result(std::move(send_message_cmd)); + + ten_test::check_detail_with_json(cmd_result, R"({"id": 1, "name": "aa"})"); // Send data to extension_3, it will return from extension_2 with json // result. auto *client2 = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8002/"); - nlohmann::json command_2 = - R"({ - "_ten": { - "name": "send_message", - "dest": [{ - "app": "msgpack://127.0.0.1:8002/", - "extension_group": "graph_id_basic__extension_group_2", - "extension": "extension3" - }] - } - })"_json; - command_2["_ten"]["dest"][0]["graph"] = graph_id; + send_message_cmd = ten::cmd_t::create("send_message"); + send_message_cmd->set_dest("msgpack://127.0.0.1:8002/", graph_id.c_str(), + "graph_id_basic__extension_group_2", "extension3"); // It must be sent directly to 127.0.0.1:8002, not 127.0.0.1:8001 - resp = client2->send_json_and_recv_resp_in_json(command_2); - ten_test::check_detail_is(resp, R"({"id": 1, "name": "aa"})"); - - // Send data to extension_2 directly. - nlohmann::json command_3 = - R"({ - "_ten": { - "name": "send_message", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "graph_id_basic__extension_group_1", - "extension": "extension2" - }] - } - })"_json; - command_3["_ten"]["dest"][0]["graph"] = graph_id; - resp = client->send_json_and_recv_resp_in_json(command_3); - ten_test::check_detail_is(resp, R"({"id": 1, "name": "aa"})"); + cmd_result = client2->send_cmd_and_recv_result(std::move(send_message_cmd)); + + ten_test::check_detail_with_json(cmd_result, R"({"id": 1, "name": "aa"})"); + + send_message_cmd = ten::cmd_t::create("send_message"); + send_message_cmd->set_dest("msgpack://127.0.0.1:8001/", graph_id.c_str(), + "graph_id_basic__extension_group_1", "extension2"); + + cmd_result = client->send_cmd_and_recv_result(std::move(send_message_cmd)); + + ten_test::check_detail_with_json(cmd_result, R"({"id": 1, "name": "aa"})"); delete client; delete client2; diff --git a/tests/ten_runtime/smoke/extension_test/http_server_extension/http_server_extension_close_app.cc b/tests/ten_runtime/smoke/extension_test/http_server_extension/http_server_extension_close_app.cc index f6aa20d09..360ea1ef5 100644 --- a/tests/ten_runtime/smoke/extension_test/http_server_extension/http_server_extension_close_app.cc +++ b/tests/ten_runtime/smoke/extension_test/http_server_extension/http_server_extension_close_app.cc @@ -25,8 +25,7 @@ class test_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); diff --git a/tests/ten_runtime/smoke/extension_test/http_server_extension/http_server_extension_two_extensions.cc b/tests/ten_runtime/smoke/extension_test/http_server_extension/http_server_extension_two_extensions.cc index a30e3e3a0..6dc1a00e5 100644 --- a/tests/ten_runtime/smoke/extension_test/http_server_extension/http_server_extension_two_extensions.cc +++ b/tests/ten_runtime/smoke/extension_test/http_server_extension/http_server_extension_two_extensions.cc @@ -24,8 +24,7 @@ class test_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); diff --git a/tests/ten_runtime/smoke/extension_test/lock/lock_data_1.cc b/tests/ten_runtime/smoke/extension_test/lock/lock_data_1.cc index 1545c08f6..08663759f 100644 --- a/tests/ten_runtime/smoke/extension_test/lock/lock_data_1.cc +++ b/tests/ten_runtime/smoke/extension_test/lock/lock_data_1.cc @@ -25,8 +25,7 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "dispatch_data") { + if (std::string(cmd->get_name()) == "dispatch_data") { const char *str = DATA; auto length = strlen(str); @@ -70,8 +69,7 @@ class test_extension_2 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "check_received") { + if (std::string(cmd->get_name()) == "check_received") { if (received) { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "received confirmed"); @@ -105,8 +103,7 @@ class test_extension_3 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "check_received") { + if (std::string(cmd->get_name()) == "check_received") { if (received) { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "received confirmed"); @@ -166,12 +163,9 @@ TEST(ExtensionTest, LockData1) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "extension 1", "addon": "lock_data_1__extension_1", @@ -208,53 +202,38 @@ TEST(ExtensionTest, LockData1) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'dispatch_data' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "dispatch_data", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group", - "extension": "extension 1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, "done"); - - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "check_received", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group", - "extension": "extension 2" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_ERROR, - "received failed"); - - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "check_received", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group", - "extension": "extension 3" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_ERROR, - "received failed"); + auto dispatch_data_cmd = ten::cmd_t::create("dispatch_data"); + dispatch_data_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group", "extension 1"); + + cmd_result = client->send_cmd_and_recv_result(std::move(dispatch_data_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "done"); + + auto check_received_cmd = ten::cmd_t::create("check_received"); + check_received_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group", "extension 2"); + + cmd_result = client->send_cmd_and_recv_result(std::move(check_received_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_ERROR); + ten_test::check_detail_with_string(cmd_result, "received failed"); + + check_received_cmd = ten::cmd_t::create("check_received"); + check_received_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group", "extension 3"); + + cmd_result = client->send_cmd_and_recv_result(std::move(check_received_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_ERROR); + ten_test::check_detail_with_string(cmd_result, "received failed"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/msg_property/msg_property_send_c_string.cc b/tests/ten_runtime/smoke/extension_test/msg_property/msg_property_send_c_string.cc index 6d62a872a..2b5877371 100644 --- a/tests/ten_runtime/smoke/extension_test/msg_property/msg_property_send_c_string.cc +++ b/tests/ten_runtime/smoke/extension_test/msg_property/msg_property_send_c_string.cc @@ -107,12 +107,9 @@ TEST(ExtensionTest, MsgPropertySendCString) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "msg_property_send_c_string__extension_1", "addon": "msg_property_send_c_string__extension_1", @@ -139,24 +136,19 @@ TEST(ExtensionTest, MsgPropertySendCString) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "msg_property_send_c_string__extension_group_1", - "extension": "msg_property_send_c_string__extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "msg_property_send_c_string__extension_group_1", + "msg_property_send_c_string__extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/msg_property/msg_property_send_cpp_ptr.cc b/tests/ten_runtime/smoke/extension_test/msg_property/msg_property_send_cpp_ptr.cc index 9d2f2f859..48ef1a9b2 100644 --- a/tests/ten_runtime/smoke/extension_test/msg_property/msg_property_send_cpp_ptr.cc +++ b/tests/ten_runtime/smoke/extension_test/msg_property/msg_property_send_cpp_ptr.cc @@ -132,12 +132,9 @@ TEST(ExtensionTest, MsgPropertySendCppPtr) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "msg_property_send_cpp_ptr__extension_1", "addon": "msg_property_send_cpp_ptr__extension_1", @@ -164,24 +161,19 @@ TEST(ExtensionTest, MsgPropertySendCppPtr) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "msg_property_send_cpp_ptr__extension_group_1", - "extension": "msg_property_send_cpp_ptr__extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "msg_property_send_cpp_ptr__extension_group_1", + "msg_property_send_cpp_ptr__extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/msg_property/msg_property_send_cpp_string.cc b/tests/ten_runtime/smoke/extension_test/msg_property/msg_property_send_cpp_string.cc index 81af14bbc..77b44a22a 100644 --- a/tests/ten_runtime/smoke/extension_test/msg_property/msg_property_send_cpp_string.cc +++ b/tests/ten_runtime/smoke/extension_test/msg_property/msg_property_send_cpp_string.cc @@ -105,12 +105,9 @@ TEST(ExtensionTest, MsgPropertySendCppString) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "msg_property_send_cpp_string__extension_1", "addon": "msg_property_send_cpp_string__extension_1", @@ -137,24 +134,19 @@ TEST(ExtensionTest, MsgPropertySendCppString) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "msg_property_send_cpp_string__extension_group_1", - "extension": "msg_property_send_cpp_string__extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "msg_property_send_cpp_string__extension_group_1", + "msg_property_send_cpp_string__extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/msg_property/msg_property_send_float_ptr.cc b/tests/ten_runtime/smoke/extension_test/msg_property/msg_property_send_float_ptr.cc index 66e90d12e..d7b756c04 100644 --- a/tests/ten_runtime/smoke/extension_test/msg_property/msg_property_send_float_ptr.cc +++ b/tests/ten_runtime/smoke/extension_test/msg_property/msg_property_send_float_ptr.cc @@ -114,12 +114,9 @@ TEST(ExtensionTest, MsgPropertySendFloatPtr) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "msg_property_send_float_ptr__extension_1", "addon": "msg_property_send_float_ptr__extension_1", @@ -146,24 +143,19 @@ TEST(ExtensionTest, MsgPropertySendFloatPtr) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "msg_property_send_float_ptr__extension_group_1", - "extension": "msg_property_send_float_ptr__extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "msg_property_send_float_ptr__extension_group_1", + "msg_property_send_float_ptr__extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/msg_property/msg_property_send_int.cc b/tests/ten_runtime/smoke/extension_test/msg_property/msg_property_send_int.cc index d7a52d643..c24d74eba 100644 --- a/tests/ten_runtime/smoke/extension_test/msg_property/msg_property_send_int.cc +++ b/tests/ten_runtime/smoke/extension_test/msg_property/msg_property_send_int.cc @@ -106,12 +106,9 @@ TEST(ExtensionTest, MsgPropertySendInt) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "msg_property_send_int__extension_1", "addon": "msg_property_send_int__extension_1", @@ -138,24 +135,19 @@ TEST(ExtensionTest, MsgPropertySendInt) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "msg_property_send_int__extension_group_1", - "extension": "msg_property_send_int__extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "msg_property_send_int__extension_group_1", + "msg_property_send_int__extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/msg_property/msg_property_send_int32_ptr.cc b/tests/ten_runtime/smoke/extension_test/msg_property/msg_property_send_int32_ptr.cc index f5a42d631..d0ec1b92a 100644 --- a/tests/ten_runtime/smoke/extension_test/msg_property/msg_property_send_int32_ptr.cc +++ b/tests/ten_runtime/smoke/extension_test/msg_property/msg_property_send_int32_ptr.cc @@ -114,12 +114,9 @@ TEST(ExtensionTest, MsgPropertySendInt32Ptr) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "msg_property_send_int32_ptr__extension_1", "addon": "msg_property_send_int32_ptr__extension_1", @@ -146,24 +143,19 @@ TEST(ExtensionTest, MsgPropertySendInt32Ptr) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "msg_property_send_int32_ptr__extension_group_1", - "extension": "msg_property_send_int32_ptr__extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "msg_property_send_int32_ptr__extension_group_1", + "msg_property_send_int32_ptr__extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_basic.cc b/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_basic.cc index bff8fa95b..544383475 100644 --- a/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_basic.cc +++ b/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_basic.cc @@ -21,8 +21,7 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { ten_env.send_cmd(std::move(cmd)); return; } @@ -35,8 +34,7 @@ class test_extension_2 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -50,8 +48,7 @@ class test_extension_3 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -105,12 +102,9 @@ TEST(ExtensionTest, MultiDestBasic) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "extension 1", "addon": "multi_dest_basic__extension_1", @@ -147,24 +141,18 @@ TEST(ExtensionTest, MultiDestBasic) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group", - "extension": "extension 1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group", "extension 1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_in_multi_app.cc b/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_in_multi_app.cc index bca5a0ce6..a46681f80 100644 --- a/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_in_multi_app.cc +++ b/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_in_multi_app.cc @@ -27,7 +27,7 @@ void on_cmd(ten::ten_env_t &ten_env, \ std::unique_ptr cmd) override { \ nlohmann::json json = nlohmann::json::parse(cmd->to_json()); \ - if (json["_ten"]["name"] == "hello_world") { \ + if (std::string(cmd->get_name()) == "hello_world") { \ auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); \ cmd_result->set_property("detail", "hello world from extension " #N); \ ten_env.return_result(std::move(cmd_result), std::move(cmd)); \ @@ -91,8 +91,7 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { ten_env.send_cmd( std::move(cmd), [this](ten::ten_env_t &ten_env, std::unique_ptr result) { @@ -164,12 +163,9 @@ TEST(ExtensionTest, MultiDestInMultiApp) { // NOLINT client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "multi_dest_in_multi_app__extension_1", @@ -326,10 +322,12 @@ TEST(ExtensionTest, MultiDestInMultiApp) { // NOLINT }] }] } - })"_json); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); - if (!resp.empty()) { - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + if (cmd_result) { + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); break; } else { delete client; @@ -343,20 +341,14 @@ TEST(ExtensionTest, MultiDestInMultiApp) { // NOLINT TEN_ASSERT(client, "Failed to connect to the TEN app."); // Send a user-defined 'hello world' command to 'extension 1'. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "multi_dest_in_multi_app__extension_group_1", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "return from extension 1"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "multi_dest_in_multi_app__extension_group_1", + "test_extension_1"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "return from extension 1"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_in_multi_app_with_response_handler.cc b/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_in_multi_app_with_response_handler.cc index 7ddd438e7..f1abef415 100644 --- a/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_in_multi_app_with_response_handler.cc +++ b/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_in_multi_app_with_response_handler.cc @@ -27,7 +27,7 @@ void on_cmd(ten::ten_env_t &ten_env, \ std::unique_ptr cmd) override { \ nlohmann::json json = nlohmann::json::parse(cmd->to_json()); \ - if (json["_ten"]["name"] == "hello_world") { \ + if (std::string(cmd->get_name()) == "hello_world") { \ auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); \ cmd_result->set_property("detail", "hello world from extension " #N); \ ten_env.return_result(std::move(cmd_result), std::move(cmd)); \ @@ -92,8 +92,7 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { ten_env.send_cmd( std::move(cmd), [&](ten::ten_env_t &ten_env, std::unique_ptr cmd) { @@ -165,12 +164,9 @@ TEST(ExtensionTest, MultiDestInMultiAppWithResponseHandler) { // NOLINT client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "multi_dest_in_multi_app_with_result_handler__extension_1", @@ -327,10 +323,12 @@ TEST(ExtensionTest, MultiDestInMultiAppWithResponseHandler) { // NOLINT }] }] } - })"_json); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); - if (!resp.empty()) { - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + if (cmd_result) { + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); break; } else { delete client; @@ -344,20 +342,15 @@ TEST(ExtensionTest, MultiDestInMultiAppWithResponseHandler) { // NOLINT TEN_ASSERT(client, "Failed to connect to the TEN app."); // Send a user-defined 'hello world' command to 'extension 1'. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "multi_dest_in_multi_app_with_result_handler__extension_group_1", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "return from extension 1"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest( + "msgpack://127.0.0.1:8001/", nullptr, + "multi_dest_in_multi_app_with_result_handler__extension_group_1", + "test_extension_1"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "return from extension 1"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_in_multi_app_with_response_handler_lambda.cc b/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_in_multi_app_with_response_handler_lambda.cc index 3a1957034..78871370a 100644 --- a/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_in_multi_app_with_response_handler_lambda.cc +++ b/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_in_multi_app_with_response_handler_lambda.cc @@ -27,7 +27,7 @@ void on_cmd(ten::ten_env_t &ten_env, \ std::unique_ptr cmd) override { \ nlohmann::json json = nlohmann::json::parse(cmd->to_json()); \ - if (json["_ten"]["name"] == "hello_world") { \ + if (std::string(cmd->get_name()) == "hello_world") { \ auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); \ cmd_result->set_property("detail", "hello world from extension " #N); \ ten_env.return_result(std::move(cmd_result), std::move(cmd)); \ @@ -94,8 +94,7 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { ten_env.send_cmd( std::move(cmd), [this](ten::ten_env_t &ten_env, @@ -170,12 +169,9 @@ TEST(ExtensionTest, MultiDestInMultiAppWithResponseHandlerLambda) { // NOLINT client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "multi_dest_in_multi_app_with_result_handler_lambda__extension_1", @@ -332,10 +328,12 @@ TEST(ExtensionTest, MultiDestInMultiAppWithResponseHandlerLambda) { // NOLINT }] }] } - })"_json); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); - if (!resp.empty()) { - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + if (cmd_result) { + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); break; } else { delete client; @@ -349,20 +347,15 @@ TEST(ExtensionTest, MultiDestInMultiAppWithResponseHandlerLambda) { // NOLINT TEN_ASSERT(client, "Failed to connect to the TEN app."); // Send a user-defined 'hello world' command to 'extension 1'. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "multi_dest_in_multi_app_with_result_handler_lambda__extension_group_1", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "return from extension 1"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest( + "msgpack://127.0.0.1:8001/", nullptr, + "multi_dest_in_multi_app_with_result_handler_lambda__extension_group_1", + "test_extension_1"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "return from extension 1"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_in_one_app.cc b/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_in_one_app.cc index e50674131..b52b014a6 100644 --- a/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_in_one_app.cc +++ b/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_in_one_app.cc @@ -62,8 +62,7 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { ten_env.send_cmd( std::move(cmd), [this](ten::ten_env_t &ten_env, std::unique_ptr result) { @@ -90,7 +89,7 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, \ std::unique_ptr cmd) override { \ nlohmann::json json = nlohmann::json::parse(cmd->to_json()); \ - if (json["_ten"]["name"] == "hello_world") { \ + if (std::string(cmd->get_name()) == "hello_world") { \ auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); \ cmd_result->set_property("detail", "hello world from extension " #N); \ ten_env.return_result(std::move(cmd_result), std::move(cmd)); \ @@ -211,10 +210,8 @@ TEST(ExtensionTest, MultiDestInOneApp) { // NOLINT // Create a client and connect to the app. auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); - auto request = R"({ + auto start_graph_cmd_content_str = R"({ "_ten": { - "type": "start_graph", - "seq_id": "55", "nodes": [], "connections": [{ "app": "msgpack://127.0.0.1:8001/", @@ -229,7 +226,7 @@ TEST(ExtensionTest, MultiDestInOneApp) { // NOLINT })"_json; for (int i = 1; i <= DEST_EXTENSION_MAX_ID; i++) { - request["_ten"]["nodes"].push_back({ + start_graph_cmd_content_str["_ten"]["nodes"].push_back({ {"type", "extension"}, {"name", "test_extension_" + std::to_string(i)}, {"addon", "multi_dest_in_one_app__extension_" + std::to_string(i)}, @@ -239,34 +236,33 @@ TEST(ExtensionTest, MultiDestInOneApp) { // NOLINT } for (int i = DEST_EXTENSION_MIN_ID; i <= DEST_EXTENSION_MAX_ID; i++) { - request["_ten"]["connections"][0]["cmd"][0]["dest"].push_back({ - {"app", "msgpack://127.0.0.1:8001/"}, // app - {"extension_group", - "multi_dest_in_one_app__extension_group"}, // extension_group - {"extension", "test_extension_" + std::to_string(i)}, // extension - }); + start_graph_cmd_content_str["_ten"]["connections"][0]["cmd"][0]["dest"] + .push_back({ + {"app", "msgpack://127.0.0.1:8001/"}, // app + {"extension_group", + "multi_dest_in_one_app__extension_group"}, // extension_group + {"extension", "test_extension_" + std::to_string(i)}, // extension + }); } // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json(request); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json( + start_graph_cmd_content_str.dump().c_str()); + + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command to 'extension 1'. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "multi_dest_in_one_app__extension_group", - "extension": "test_extension_1" - }] - } - })"_json); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "multi_dest_in_one_app__extension_group", + "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "return from extension 1"); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "return from extension 1"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_resp_when_all.cc b/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_resp_when_all.cc index 0030c6454..30bac7d15 100644 --- a/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_resp_when_all.cc +++ b/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_resp_when_all.cc @@ -21,8 +21,7 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { ten_env.send_cmd(std::move(cmd)); return; } @@ -35,8 +34,7 @@ class test_extension_2 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -50,8 +48,7 @@ class test_extension_3 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -105,12 +102,9 @@ TEST(ExtensionTest, MultiDestRespWhenAll) { auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "extension 1", "addon": "multi_dest_resp_when_all__extension_1", @@ -147,24 +141,18 @@ TEST(ExtensionTest, MultiDestRespWhenAll) { }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group", - "extension": "extension 1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group", "extension 1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_resp_when_all_in_multi_app.cc b/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_resp_when_all_in_multi_app.cc index a6fc45f6d..3d5686d7e 100644 --- a/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_resp_when_all_in_multi_app.cc +++ b/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_resp_when_all_in_multi_app.cc @@ -23,8 +23,7 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { ten_env.send_cmd(std::move(cmd)); return; } @@ -37,8 +36,7 @@ class test_extension_2 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -52,8 +50,7 @@ class test_extension_3 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -171,12 +168,9 @@ TEST(ExtensionTest, MultiDestRespWhenAllInMultiApp) { // NOLINT client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "extension 1", "addon": "multi_dest_resp_when_all_in_multi_app__extension_1", @@ -213,10 +207,12 @@ TEST(ExtensionTest, MultiDestRespWhenAllInMultiApp) { // NOLINT }] }] } - })"_json); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); - if (!resp.empty()) { - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + if (cmd_result) { + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); break; } else { delete client; @@ -230,20 +226,15 @@ TEST(ExtensionTest, MultiDestRespWhenAllInMultiApp) { // NOLINT TEN_ASSERT(client, "Failed to connect to the TEN app."); // Send a user-defined 'hello world' command. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group", - "extension": "extension 1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group", "extension 1"); + + auto cmd_result = + client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_send_in_stop_period.cc b/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_send_in_stop_period.cc index f4f47b9e9..63888da85 100644 --- a/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_send_in_stop_period.cc +++ b/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_send_in_stop_period.cc @@ -21,8 +21,7 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { ten_env.send_cmd(std::move(cmd)); return; } @@ -42,8 +41,7 @@ class test_extension_2 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -57,8 +55,7 @@ class test_extension_3 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -112,12 +109,9 @@ TEST(ExtensionTest, MultiDestSendInStopPeriod) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "extension 1", "addon": "multi_dest_send_in_stop_period__extension_1", @@ -154,24 +148,18 @@ TEST(ExtensionTest, MultiDestSendInStopPeriod) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group1", - "extension": "extension 1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group1", "extension 1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_y_topo.cc b/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_y_topo.cc index 75c8c0acf..a59333944 100644 --- a/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_y_topo.cc +++ b/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_y_topo.cc @@ -21,9 +21,7 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { // Remember the command sent from the client, so that we can send its // result back to the client. client_cmd = std::move(cmd); @@ -56,9 +54,8 @@ class test_extension_2 : public ten::extension_t { std::unique_ptr cmd) override { // Extension 2 is just a forwarding proxy, forward all the commands it // received out. - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { ten_env.send_cmd(std::move(cmd)); return; } @@ -139,12 +136,9 @@ TEST(ExtensionTest, MultiDestYGraph) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "extension_1", "addon": "multi_dest_y_graph__extension_1", @@ -199,22 +193,16 @@ TEST(ExtensionTest, MultiDestYGraph) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); - - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "extension_group", - "extension": "extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, "OK"); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "extension_group", "extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "OK"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/outer_thread/128_threads_attempt_to_suspend_1.cc b/tests/ten_runtime/smoke/extension_test/outer_thread/128_threads_attempt_to_suspend_1.cc index 1e0f8113e..bb50d6806 100644 --- a/tests/ten_runtime/smoke/extension_test/outer_thread/128_threads_attempt_to_suspend_1.cc +++ b/tests/ten_runtime/smoke/extension_test/outer_thread/128_threads_attempt_to_suspend_1.cc @@ -1036,12 +1036,9 @@ TEST(ExtensionTest, auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "one_hundred_and_twenty_eight_threads_attempt_to_suspend_1__test_extension_1", @@ -1088,23 +1085,18 @@ TEST(ExtensionTest, }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_2" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, "ok"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_2"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "ok"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/outer_thread/16_threads_attempt_to_suspend_1.cc b/tests/ten_runtime/smoke/extension_test/outer_thread/16_threads_attempt_to_suspend_1.cc index 5d4510d5f..9cf56c288 100644 --- a/tests/ten_runtime/smoke/extension_test/outer_thread/16_threads_attempt_to_suspend_1.cc +++ b/tests/ten_runtime/smoke/extension_test/outer_thread/16_threads_attempt_to_suspend_1.cc @@ -299,12 +299,9 @@ TEST(ExtensionTest, SixteenThreadsAttemptToSuspend1) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "sixteen_threads_attempt_to_suspend_1__test_extension_1", @@ -339,23 +336,18 @@ TEST(ExtensionTest, SixteenThreadsAttemptToSuspend1) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_2" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, "ok"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_2"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "ok"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/outer_thread/2_threads_attempt_to_suspend_1.cc b/tests/ten_runtime/smoke/extension_test/outer_thread/2_threads_attempt_to_suspend_1.cc index 70b0c14c4..a836438d0 100644 --- a/tests/ten_runtime/smoke/extension_test/outer_thread/2_threads_attempt_to_suspend_1.cc +++ b/tests/ten_runtime/smoke/extension_test/outer_thread/2_threads_attempt_to_suspend_1.cc @@ -219,12 +219,9 @@ TEST(ExtensionTest, TwoThreadsAttemptToSuspend1) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "two_threads_attempt_to_suspend_1__test_extension_1", @@ -259,23 +256,18 @@ TEST(ExtensionTest, TwoThreadsAttemptToSuspend1) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_2" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, "ok"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_2"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "ok"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/outer_thread/2_threads_attempt_to_suspend_2.cc b/tests/ten_runtime/smoke/extension_test/outer_thread/2_threads_attempt_to_suspend_2.cc index e7718dcdc..122ac58b7 100644 --- a/tests/ten_runtime/smoke/extension_test/outer_thread/2_threads_attempt_to_suspend_2.cc +++ b/tests/ten_runtime/smoke/extension_test/outer_thread/2_threads_attempt_to_suspend_2.cc @@ -221,12 +221,9 @@ TEST(ExtensionTest, TwoThreadsAttemptToSuspend2) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "two_threads_attempt_to_suspend_2__test_extension_1", @@ -261,23 +258,18 @@ TEST(ExtensionTest, TwoThreadsAttemptToSuspend2) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_2" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, "ok"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_2"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "ok"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/outer_thread/2_threads_attempt_to_suspend_3.cc b/tests/ten_runtime/smoke/extension_test/outer_thread/2_threads_attempt_to_suspend_3.cc index bff45849d..60e06ffef 100644 --- a/tests/ten_runtime/smoke/extension_test/outer_thread/2_threads_attempt_to_suspend_3.cc +++ b/tests/ten_runtime/smoke/extension_test/outer_thread/2_threads_attempt_to_suspend_3.cc @@ -244,12 +244,9 @@ TEST(ExtensionTest, TwoThreadsAttemptToSuspend3) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "two_threads_attempt_to_suspend_3__test_extension_1", @@ -284,23 +281,18 @@ TEST(ExtensionTest, TwoThreadsAttemptToSuspend3) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_2" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, "ok"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_2"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "ok"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/outer_thread/2_threads_attempt_to_suspend_4.cc b/tests/ten_runtime/smoke/extension_test/outer_thread/2_threads_attempt_to_suspend_4.cc index a06cf5d0a..498d1694c 100644 --- a/tests/ten_runtime/smoke/extension_test/outer_thread/2_threads_attempt_to_suspend_4.cc +++ b/tests/ten_runtime/smoke/extension_test/outer_thread/2_threads_attempt_to_suspend_4.cc @@ -254,12 +254,9 @@ TEST(ExtensionTest, TwoThreadsAttemptToSuspend4) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "two_threads_attempt_to_suspend_4__test_extension_1", @@ -294,23 +291,18 @@ TEST(ExtensionTest, TwoThreadsAttemptToSuspend4) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_2" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, "ok"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_2"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "ok"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/outer_thread/2_threads_attempt_to_suspend_5.cc b/tests/ten_runtime/smoke/extension_test/outer_thread/2_threads_attempt_to_suspend_5.cc index d5fb4f463..0ff3bef7c 100644 --- a/tests/ten_runtime/smoke/extension_test/outer_thread/2_threads_attempt_to_suspend_5.cc +++ b/tests/ten_runtime/smoke/extension_test/outer_thread/2_threads_attempt_to_suspend_5.cc @@ -259,12 +259,9 @@ TEST(ExtensionTest, TwoThreadsAttemptToSuspend5) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "two_threads_attempt_to_suspend_5__test_extension_1", @@ -299,23 +296,18 @@ TEST(ExtensionTest, TwoThreadsAttemptToSuspend5) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_2" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, "ok"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_2"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "ok"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/outer_thread/2_threads_attempt_to_suspend_6.cc b/tests/ten_runtime/smoke/extension_test/outer_thread/2_threads_attempt_to_suspend_6.cc index 62d1ce476..24361b9a2 100644 --- a/tests/ten_runtime/smoke/extension_test/outer_thread/2_threads_attempt_to_suspend_6.cc +++ b/tests/ten_runtime/smoke/extension_test/outer_thread/2_threads_attempt_to_suspend_6.cc @@ -220,12 +220,9 @@ TEST(ExtensionTest, TwoThreadsAttemptToSuspend6) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "two_threads_attempt_to_suspend_6__test_extension_1", @@ -260,23 +257,18 @@ TEST(ExtensionTest, TwoThreadsAttemptToSuspend6) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_2" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, "ok"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_2"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "ok"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/outer_thread/2_threads_attempt_to_suspend_7.cc b/tests/ten_runtime/smoke/extension_test/outer_thread/2_threads_attempt_to_suspend_7.cc index 16fe8a5e5..5a43c3388 100644 --- a/tests/ten_runtime/smoke/extension_test/outer_thread/2_threads_attempt_to_suspend_7.cc +++ b/tests/ten_runtime/smoke/extension_test/outer_thread/2_threads_attempt_to_suspend_7.cc @@ -220,12 +220,9 @@ TEST(ExtensionTest, TwoThreadsAttemptToSuspend7) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "two_threads_attempt_to_suspend_7__test_extension_1", @@ -260,23 +257,18 @@ TEST(ExtensionTest, TwoThreadsAttemptToSuspend7) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_2" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, "ok"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_2"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "ok"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/outer_thread/32_threads_attempt_to_suspend_1.cc b/tests/ten_runtime/smoke/extension_test/outer_thread/32_threads_attempt_to_suspend_1.cc index fd7c2e140..e9186471b 100644 --- a/tests/ten_runtime/smoke/extension_test/outer_thread/32_threads_attempt_to_suspend_1.cc +++ b/tests/ten_runtime/smoke/extension_test/outer_thread/32_threads_attempt_to_suspend_1.cc @@ -419,12 +419,9 @@ TEST(ExtensionTest, ThirtyTwoThreadsAttemptToSuspend1) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "thirty_two_threads_attempt_to_suspend_1__test_extension_1", @@ -459,23 +456,18 @@ TEST(ExtensionTest, ThirtyTwoThreadsAttemptToSuspend1) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_2" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, "ok"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_2"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "ok"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/outer_thread/32_threads_attempt_to_suspend_2.cc b/tests/ten_runtime/smoke/extension_test/outer_thread/32_threads_attempt_to_suspend_2.cc index 3e3ead5c4..a4b4da242 100644 --- a/tests/ten_runtime/smoke/extension_test/outer_thread/32_threads_attempt_to_suspend_2.cc +++ b/tests/ten_runtime/smoke/extension_test/outer_thread/32_threads_attempt_to_suspend_2.cc @@ -426,12 +426,9 @@ TEST(ExtensionTest, ThirtyTwoThreadsAttemptToSuspend2) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "thirty_two_threads_attempt_to_suspend_2__test_extension_1", @@ -466,23 +463,18 @@ TEST(ExtensionTest, ThirtyTwoThreadsAttemptToSuspend2) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_2" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, "ok"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_2"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "ok"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/outer_thread/32_threads_attempt_to_suspend_3.cc b/tests/ten_runtime/smoke/extension_test/outer_thread/32_threads_attempt_to_suspend_3.cc index a019f262d..b41719757 100644 --- a/tests/ten_runtime/smoke/extension_test/outer_thread/32_threads_attempt_to_suspend_3.cc +++ b/tests/ten_runtime/smoke/extension_test/outer_thread/32_threads_attempt_to_suspend_3.cc @@ -421,12 +421,9 @@ TEST(ExtensionTest, ThirtyTwoThreadsAttemptToSuspend3) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "thirty_two_threads_attempt_to_suspend_3__test_extension_1", @@ -461,23 +458,18 @@ TEST(ExtensionTest, ThirtyTwoThreadsAttemptToSuspend3) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_2" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, "ok"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_2"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "ok"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/outer_thread/32_threads_attempt_to_suspend_4.cc b/tests/ten_runtime/smoke/extension_test/outer_thread/32_threads_attempt_to_suspend_4.cc index aca6921fb..57d5db184 100644 --- a/tests/ten_runtime/smoke/extension_test/outer_thread/32_threads_attempt_to_suspend_4.cc +++ b/tests/ten_runtime/smoke/extension_test/outer_thread/32_threads_attempt_to_suspend_4.cc @@ -431,12 +431,9 @@ TEST(ExtensionTest, ThirtyTwoThreadsAttemptToSuspend4) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "thirty_two_threads_attempt_to_suspend_4__test_extension_1", @@ -471,23 +468,18 @@ TEST(ExtensionTest, ThirtyTwoThreadsAttemptToSuspend4) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_2" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, "ok"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_2"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "ok"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/outer_thread/32_threads_attempt_to_suspend_5.cc b/tests/ten_runtime/smoke/extension_test/outer_thread/32_threads_attempt_to_suspend_5.cc index 8585339d5..486ca755c 100644 --- a/tests/ten_runtime/smoke/extension_test/outer_thread/32_threads_attempt_to_suspend_5.cc +++ b/tests/ten_runtime/smoke/extension_test/outer_thread/32_threads_attempt_to_suspend_5.cc @@ -512,12 +512,9 @@ TEST(ExtensionTest, ThirtyTwoThreadsAttemptToSuspend5) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "thirty_two_threads_attempt_to_suspend_5__test_extension_1", @@ -564,23 +561,18 @@ TEST(ExtensionTest, ThirtyTwoThreadsAttemptToSuspend5) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_2" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, "ok"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_2"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "ok"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/outer_thread/32_threads_attempt_to_suspend_6.cc b/tests/ten_runtime/smoke/extension_test/outer_thread/32_threads_attempt_to_suspend_6.cc index aa5b8c35f..ebb137f05 100644 --- a/tests/ten_runtime/smoke/extension_test/outer_thread/32_threads_attempt_to_suspend_6.cc +++ b/tests/ten_runtime/smoke/extension_test/outer_thread/32_threads_attempt_to_suspend_6.cc @@ -529,12 +529,9 @@ TEST(ExtensionTest, ThirtyTwoThreadsAttemptToSuspend6) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "thirty_two_threads_attempt_to_suspend_6__test_extension_1", @@ -581,23 +578,18 @@ TEST(ExtensionTest, ThirtyTwoThreadsAttemptToSuspend6) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_2" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, "ok"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_2"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "ok"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/outer_thread/auto_free_out_of_scope.cc b/tests/ten_runtime/smoke/extension_test/outer_thread/auto_free_out_of_scope.cc index f655bc492..cb1a35084 100644 --- a/tests/ten_runtime/smoke/extension_test/outer_thread/auto_free_out_of_scope.cc +++ b/tests/ten_runtime/smoke/extension_test/outer_thread/auto_free_out_of_scope.cc @@ -206,12 +206,9 @@ TEST(ExtensionTest, AutoFreeOutOfScope) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "auto_free_out_of_scope__test_extension_1", @@ -246,23 +243,18 @@ TEST(ExtensionTest, AutoFreeOutOfScope) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_2" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, "ok"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_2"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "ok"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/outer_thread/outer_thread_send_data.cc b/tests/ten_runtime/smoke/extension_test/outer_thread/outer_thread_send_data.cc index 1b6680176..6fece1ffe 100644 --- a/tests/ten_runtime/smoke/extension_test/outer_thread/outer_thread_send_data.cc +++ b/tests/ten_runtime/smoke/extension_test/outer_thread/outer_thread_send_data.cc @@ -172,12 +172,9 @@ TEST(ExtensionTest, OuterThreadSendData) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "outer_thread_send_data__test_extension_1", @@ -212,24 +209,18 @@ TEST(ExtensionTest, OuterThreadSendData) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/outer_thread/outer_thread_send_data_resp_handler.cc b/tests/ten_runtime/smoke/extension_test/outer_thread/outer_thread_send_data_resp_handler.cc index 0151a6e9e..0d179a7d0 100644 --- a/tests/ten_runtime/smoke/extension_test/outer_thread/outer_thread_send_data_resp_handler.cc +++ b/tests/ten_runtime/smoke/extension_test/outer_thread/outer_thread_send_data_resp_handler.cc @@ -197,12 +197,9 @@ TEST(ExtensionTest, OuterThreadSendDataRespHandler) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "outer_thread_send_data_resp_handler__test_extension_1", @@ -237,24 +234,18 @@ TEST(ExtensionTest, OuterThreadSendDataRespHandler) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/path/clean_when_stopped.cc b/tests/ten_runtime/smoke/extension_test/path/clean_when_stopped.cc index 209fa97f7..b097c0322 100644 --- a/tests/ten_runtime/smoke/extension_test/path/clean_when_stopped.cc +++ b/tests/ten_runtime/smoke/extension_test/path/clean_when_stopped.cc @@ -102,12 +102,9 @@ TEST(ExtensionTest, CleanWhenStopped) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "clean_when_stopped__test_extension_1", @@ -141,38 +138,24 @@ TEST(ExtensionTest, CleanWhenStopped) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send 'hello world' command and ignore the result. - client->send_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_1"); + client->send_cmd(std::move(hello_world_cmd)); // Send a user-defined 'hello world2' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world2", - "seq_id": "138", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "138", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world2_cmd = ten::cmd_t::create("hello_world2"); + hello_world2_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world2_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/path/path_timeout.cc b/tests/ten_runtime/smoke/extension_test/path/path_timeout.cc index 874adb933..1a32d7eff 100644 --- a/tests/ten_runtime/smoke/extension_test/path/path_timeout.cc +++ b/tests/ten_runtime/smoke/extension_test/path/path_timeout.cc @@ -114,12 +114,9 @@ TEST(ExtensionTest, PathTimeout) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "path_timeout__test_extension_1", @@ -153,38 +150,26 @@ TEST(ExtensionTest, PathTimeout) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send 'hello world' command and wait for the result. - resp = client->send_json_and_recv_resp_in_json(R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "", TEN_STATUS_CODE_ERROR, "Path timeout."); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_ERROR); + ten_test::check_detail_with_string(cmd_result, "Path timeout."); // Send a user-defined 'hello world2' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world2", - "seq_id": "138", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "138", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world2_cmd = ten::cmd_t::create("hello_world2"); + hello_world2_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world2_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/path/path_timeout_2.cc b/tests/ten_runtime/smoke/extension_test/path/path_timeout_2.cc index 62dc515d5..ded20b059 100644 --- a/tests/ten_runtime/smoke/extension_test/path/path_timeout_2.cc +++ b/tests/ten_runtime/smoke/extension_test/path/path_timeout_2.cc @@ -117,12 +117,9 @@ TEST(ExtensionTest, PathTimeout2) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "path_timeout_2__test_extension_1", @@ -156,39 +153,26 @@ TEST(ExtensionTest, PathTimeout2) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send 'hello world' command and wait for the result. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "", TEN_STATUS_CODE_ERROR, "Path timeout."); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_ERROR); + ten_test::check_detail_with_string(cmd_result, "Path timeout."); // Send a user-defined 'hello world2' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world2", - "seq_id": "138", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "138", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world2_cmd = ten::cmd_t::create("hello_world2"); + hello_world2_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world2_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_basic_1.cc b/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_basic_1.cc index 65474919b..a4dc14f36 100644 --- a/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_basic_1.cc +++ b/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_basic_1.cc @@ -76,8 +76,8 @@ void *app_thread_main(TEN_UNUSED void *args) { return nullptr; } -TEN_CPP_REGISTER_ADDON_AS_EXTENSION( - predefined_graph_basic_1__predefined_graph, test_predefined_graph); +TEN_CPP_REGISTER_ADDON_AS_EXTENSION(predefined_graph_basic_1__predefined_graph, + test_predefined_graph); } // namespace @@ -90,21 +90,12 @@ TEST(ExtensionTest, PredefinedGraphBasic1) { // NOLINT // Do not need to send 'start_graph' command first. // The 'graph_id' MUST be "default" if we want to send the request to // predefined graph. - nlohmann::json const resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "test", - "seq_id": "111", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "predefined_graph_group", - "extension": "predefined_graph" - }] - } - })"_json); - ten_test::check_result_is(resp, "111", TEN_STATUS_CODE_OK, - R"({"id": 1, "name": "a"})"); + auto test_cmd = ten::cmd_t::create("test"); + test_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "predefined_graph_group", "predefined_graph"); + auto cmd_result = client->send_cmd_and_recv_result(std::move(test_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_json(cmd_result, R"({"id": 1, "name": "a"})"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_basic_2.cc b/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_basic_2.cc index a96d5f4f0..a8c94da35 100644 --- a/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_basic_2.cc +++ b/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_basic_2.cc @@ -18,8 +18,7 @@ class test_normal_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -89,8 +88,7 @@ class test_predefined_graph : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "command_1") { + if (std::string(cmd->get_name()) == "command_1") { if (normal_extension_is_ready) { auto detail = R"({"id": 1, "name": "a"})"_json; auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); @@ -174,21 +172,12 @@ TEST(ExtensionTest, PredefinedGraphBasic2) { // NOLINT // Do not need to send 'start_graph' command first. // The 'graph_id' MUST be "default" (a special string) if we want to send the // request to predefined graph. - nlohmann::json const resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "command_1", - "seq_id": "111", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "predefined_graph_group", - "extension": "predefined_graph" - }] - } - })"_json); - ten_test::check_result_is(resp, "111", TEN_STATUS_CODE_OK, - R"({"id": 1, "name": "a"})"); + auto command_1_cmd = ten::cmd_t::create("command_1"); + command_1_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "predefined_graph_group", "predefined_graph"); + auto cmd_result = client->send_cmd_and_recv_result(std::move(command_1_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_json(cmd_result, R"({"id": 1, "name": "a"})"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_engine_own_eventloop.cc b/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_engine_own_eventloop.cc index cffddd00a..c87bb10f1 100644 --- a/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_engine_own_eventloop.cc +++ b/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_engine_own_eventloop.cc @@ -90,27 +90,16 @@ TEST(ExtensionTest, PredefinedGraphEngineOwnEventloop) { // NOLINT // Create a client and connect to the app. auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); - // TODO(Wei): client->send_json would cause thread safety issue, need to have - // a message queue in client. - // Do not need to send 'start_graph' command first. // The 'graph_id' MUST be "default" (a special string) if we want to send the // request to predefined graph. - nlohmann::json const resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "test", - "seq_id": "111", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "predefined_graph_engine_own_eventloop__extension_group", - "extension": "predefined_graph" - }] - } - })"_json); - ten_test::check_result_is(resp, "111", TEN_STATUS_CODE_OK, - R"({"id": 1, "name": "a"})"); + auto test_cmd = ten::cmd_t::create("test"); + test_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "predefined_graph_engine_own_eventloop__extension_group", + "predefined_graph"); + auto cmd_result = client->send_cmd_and_recv_result(std::move(test_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_json(cmd_result, R"({"id": 1, "name": "a"})"); delete client; ten_thread_join(app_thread, -1); diff --git a/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_multi_app.cc b/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_multi_app.cc index b3f5ca017..400fa6f8b 100644 --- a/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_multi_app.cc +++ b/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_multi_app.cc @@ -22,9 +22,7 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { ten_env.send_cmd(std::move(cmd)); return; } @@ -37,8 +35,7 @@ class test_extension_2 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -158,21 +155,13 @@ TEST(ExtensionTest, PredefinedGraphMultiApp) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send a user-defined 'hello world' command. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "predefined_graph_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "predefined_graph_group", "test_extension_1"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_multi_extension_1.cc b/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_multi_extension_1.cc index 25a2e1864..eeb8e6bc3 100644 --- a/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_multi_extension_1.cc +++ b/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_multi_extension_1.cc @@ -21,9 +21,7 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { ten_env.send_cmd(std::move(cmd)); return; } @@ -36,8 +34,7 @@ class test_extension_2 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -131,21 +128,14 @@ TEST(ExtensionTest, PredefinedGraphMultiExtension1) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send a user-defined 'hello world' command. - nlohmann::json const resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "predefined_graph_multi_extension_1", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "predefined_graph_multi_extension_1", + "test_extension_1"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_multi_extension_2.cc b/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_multi_extension_2.cc index 18474caf4..afa364b73 100644 --- a/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_multi_extension_2.cc +++ b/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_multi_extension_2.cc @@ -22,9 +22,7 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { ten_env.send_cmd(std::move(cmd)); return; } @@ -37,8 +35,7 @@ class test_extension_2 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -128,21 +125,14 @@ TEST(ExtensionTest, PredefinedGraphMultiExtension2) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send a user-defined 'hello world' command. - nlohmann::json const resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "predefined_graph_multi_extension_2", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "predefined_graph_multi_extension_2", + "test_extension_1"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_multi_extension_3.cc b/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_multi_extension_3.cc index 5e40208fc..336699cd0 100644 --- a/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_multi_extension_3.cc +++ b/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_multi_extension_3.cc @@ -21,9 +21,7 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { ten_env.send_cmd(std::move(cmd)); return; } @@ -36,8 +34,7 @@ class test_extension_2 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -127,21 +124,13 @@ TEST(ExtensionTest, PredefinedGraphMultiExtension3) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send a user-defined 'hello world' command. - nlohmann::json const resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "predefined_graph_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "predefined_graph_group", "test_extension_1"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_multi_extension_4.cc b/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_multi_extension_4.cc index cbc73e36e..5c9aefb7d 100644 --- a/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_multi_extension_4.cc +++ b/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_multi_extension_4.cc @@ -21,9 +21,7 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { ten_env.send_cmd(std::move(cmd)); return; } @@ -36,9 +34,7 @@ class test_extension_2 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { ten_env.send_cmd( std::move(cmd), [](ten::ten_env_t &ten_env, std::unique_ptr cmd) { @@ -54,8 +50,7 @@ class test_extension_3 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -169,21 +164,14 @@ TEST(ExtensionTest, PredefinedGraphMultiExtension4) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send a user-defined 'hello world' command. - nlohmann::json const resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "predefined_graph_multi_extension_4", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "predefined_graph_multi_extension_4", + "test_extension_1"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_no_auto_start.cc b/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_no_auto_start.cc index 98b4bf855..8f9982f27 100644 --- a/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_no_auto_start.cc +++ b/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_no_auto_start.cc @@ -76,8 +76,9 @@ void *app_thread_main(TEN_UNUSED void *args) { return nullptr; } -TEN_CPP_REGISTER_ADDON_AS_EXTENSION(predefined_graph_no_auto_start__predefined_graph_extension, - test_predefined_graph); +TEN_CPP_REGISTER_ADDON_AS_EXTENSION( + predefined_graph_no_auto_start__predefined_graph_extension, + test_predefined_graph); } // namespace @@ -90,21 +91,12 @@ TEST(ExtensionTest, PredefinedGraphNoAutoStart) { // NOLINT // Do not need to send 'start_graph' command first. // The 'graph_id' MUST be "default" (a special string) if we want to send the // request to predefined graph. - nlohmann::json const resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "test", - "seq_id": "111", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "predefined_graph_group", - "extension": "predefined_graph" - }] - } - })"_json); - ten_test::check_result_is(resp, "111", TEN_STATUS_CODE_OK, - R"({"id": 1, "name": "a"})"); + auto test_cmd = ten::cmd_t::create("test"); + test_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "predefined_graph_group", "predefined_graph"); + auto cmd_result = client->send_cmd_and_recv_result(std::move(test_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_json(cmd_result, R"({"id": 1, "name": "a"})"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_two_standalone_extensions_1.cc b/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_two_standalone_extensions_1.cc index 967e1161f..0b20d8f63 100644 --- a/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_two_standalone_extensions_1.cc +++ b/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_two_standalone_extensions_1.cc @@ -93,20 +93,13 @@ TEST(ExtensionTest, PredefinedGraphTwoStandaloneExtensions1) { // NOLINT // Do not need to send 'start_graph' command first. // The 'graph_id' MUST be "default" (a special string) if we want to send the // request to predefined graph. - nlohmann::json const resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "test", - "seq_id": "111", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "two_extensions_same_group", - "extension": "two_extensions_same_group_extension_2" - }] - } - })"_json); - ten_test::check_result_is(resp, "111", TEN_STATUS_CODE_OK, "success"); + auto test_cmd = ten::cmd_t::create("test"); + test_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "two_extensions_same_group", + "two_extensions_same_group_extension_2"); + auto cmd_result = client->send_cmd_and_recv_result(std::move(test_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "success"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_two_standalone_extensions_2.cc b/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_two_standalone_extensions_2.cc index 01800f3b9..8b979dbc3 100644 --- a/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_two_standalone_extensions_2.cc +++ b/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_two_standalone_extensions_2.cc @@ -93,20 +93,13 @@ TEST(ExtensionTest, PredefinedGraphTwoStandaloneExtensions2) { // NOLINT // Do not need to send 'start_graph' command first. // The 'graph_id' MUST be "default" (a special string) if we want to send the // request to predefined graph. - nlohmann::json const resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "test", - "seq_id": "111", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "two_extensions_group_2", - "extension": "two_extensions_group_extension_2" - }] - } - })"_json); - ten_test::check_result_is(resp, "111", TEN_STATUS_CODE_OK, "success"); + auto test_cmd = ten::cmd_t::create("test"); + test_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "two_extensions_group_2", + "two_extensions_group_extension_2"); + auto cmd_result = client->send_cmd_and_recv_result(std::move(test_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "success"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/prepare_to_stop/different_thread.cc b/tests/ten_runtime/smoke/extension_test/prepare_to_stop/different_thread.cc index 142768aa0..6f43452ab 100644 --- a/tests/ten_runtime/smoke/extension_test/prepare_to_stop/different_thread.cc +++ b/tests/ten_runtime/smoke/extension_test/prepare_to_stop/different_thread.cc @@ -112,12 +112,9 @@ TEST(ExtensionTest, PrepareToStopDifferentThread) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "prepare_to_stop_different_thread__test_extension_1", @@ -151,24 +148,18 @@ TEST(ExtensionTest, PrepareToStopDifferentThread) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/prepare_to_stop/same_thread.cc b/tests/ten_runtime/smoke/extension_test/prepare_to_stop/same_thread.cc index 4b655d586..7dfd83df0 100644 --- a/tests/ten_runtime/smoke/extension_test/prepare_to_stop/same_thread.cc +++ b/tests/ten_runtime/smoke/extension_test/prepare_to_stop/same_thread.cc @@ -113,12 +113,9 @@ TEST(ExtensionTest, PrepareToStopSameThread) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "prepare_to_stop_same_thread__extension_1", @@ -152,24 +149,18 @@ TEST(ExtensionTest, PrepareToStopSameThread) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "prepare_to_stop_same_thread", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "prepare_to_stop_same_thread", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/property/property_access_app_store.cc b/tests/ten_runtime/smoke/extension_test/property/property_access_app_store.cc index 825032fae..9597f6772 100644 --- a/tests/ten_runtime/smoke/extension_test/property/property_access_app_store.cc +++ b/tests/ten_runtime/smoke/extension_test/property/property_access_app_store.cc @@ -111,37 +111,24 @@ TEST(ExtensionTest, PropertyAccessAppStore) { // NOLINT // Send a request to test_property_access_app_store_1 to make sure // it has been initted. - nlohmann::json resp = client->send_json_and_recv_resp_in_json(R"({ - "_ten": { - "name": "test", - "seq_id": "110", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "default_extension_group_1", - "extension": "test_property_access_app_store_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "110", TEN_STATUS_CODE_OK, "success"); + auto test_cmd = ten::cmd_t::create("test"); + test_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "default_extension_group_1", + "test_property_access_app_store_1"); + auto cmd_result = client->send_cmd_and_recv_result(std::move(test_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "success"); // Do not need to send 'start_graph' command first. // The 'graph_id' MUST be "default" (a special string) if we want to send the // request to predefined graph. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "test", - "seq_id": "111", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "default_extension_group_2", - "extension": "test_property_access_app_store_2" - }] - } - })"_json); - ten_test::check_result_is(resp, "111", TEN_STATUS_CODE_OK, "success"); + test_cmd = ten::cmd_t::create("test"); + test_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "default_extension_group_2", + "test_property_access_app_store_2"); + cmd_result = client->send_cmd_and_recv_result(std::move(test_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "success"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/property/property_access_app_store_async.cc b/tests/ten_runtime/smoke/extension_test/property/property_access_app_store_async.cc index 3b6ea18af..d1da35500 100644 --- a/tests/ten_runtime/smoke/extension_test/property/property_access_app_store_async.cc +++ b/tests/ten_runtime/smoke/extension_test/property/property_access_app_store_async.cc @@ -111,20 +111,13 @@ TEST(ExtensionTest, PropertyAccessAppStoreAsync) { // NOLINT // Do not need to send 'start_graph' command first. // The 'graph_id' MUST be "default" (a special string) if we want to send the // request to predefined graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "test", - "seq_id": "111", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "default_extension_group_2", - "extension": "test_property_access_app_store_async_2" - }] - } - })"_json); - ten_test::check_result_is(resp, "111", TEN_STATUS_CODE_OK, "success"); + auto test_cmd = ten::cmd_t::create("test"); + test_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "default_extension_group_2", + "test_property_access_app_store_async_2"); + auto cmd_result = client->send_cmd_and_recv_result(std::move(test_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "success"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/property/property_all.cc b/tests/ten_runtime/smoke/extension_test/property/property_all.cc index fb8dd0f0b..3e01d57dc 100644 --- a/tests/ten_runtime/smoke/extension_test/property/property_all.cc +++ b/tests/ten_runtime/smoke/extension_test/property/property_all.cc @@ -6,7 +6,6 @@ // #include #include -#include #include "gtest/gtest.h" #include "include_internal/ten_runtime/binding/cpp/ten.h" @@ -72,8 +71,7 @@ class test_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto conn_property_value = ten_env.get_property_float64(CONN_PROP_NAME); auto extension_property_value_int64 = @@ -149,7 +147,7 @@ TEST(ExtensionTest, PropertyAll) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph with a property. - nlohmann::json command = + nlohmann::json start_graph_cmd_content_str = R"({ "_ten": { "type": "start_graph", @@ -164,26 +162,25 @@ TEST(ExtensionTest, PropertyAll) { // NOLINT }] } })"_json; - command["_ten"]["nodes"][0]["property"][CONN_PROP_NAME] = CONN_PROP_VAL; + start_graph_cmd_content_str["_ten"]["nodes"][0]["property"][CONN_PROP_NAME] = + CONN_PROP_VAL; - nlohmann::json resp = client->send_json_and_recv_resp_in_json(command); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json( + start_graph_cmd_content_str.dump().c_str()); + + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "property_all__extension_group", - "extension": "test_extension" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "property_all__extension_group", "test_extension"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/property/property_connect_cmd.cc b/tests/ten_runtime/smoke/extension_test/property/property_connect_cmd.cc index 670179b3c..5ed5d0197 100644 --- a/tests/ten_runtime/smoke/extension_test/property/property_connect_cmd.cc +++ b/tests/ten_runtime/smoke/extension_test/property/property_connect_cmd.cc @@ -6,7 +6,6 @@ // #include #include -#include #include "gtest/gtest.h" #include "include_internal/ten_runtime/binding/cpp/ten.h" @@ -28,8 +27,7 @@ class test_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto prop_value = ten_env.get_property_int64(PROP_NAME); if (prop_value == CONNECT_CMD_PROP_VAL) { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); @@ -82,7 +80,7 @@ void *test_app_thread_main(TEN_UNUSED void *args) { } TEN_CPP_REGISTER_ADDON_AS_EXTENSION(property_start_graph_cmd__extension, - test_extension); + test_extension); } // namespace @@ -95,11 +93,9 @@ TEST(ExtensionTest, PropertyConnectCmd) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json command = + nlohmann::json start_graph_cmd_content_str = R"({ "_ten": { - "type": "start_graph", - "seq_id": "55", "nodes": [{ "type": "extension", "name": "test_extension", @@ -110,26 +106,24 @@ TEST(ExtensionTest, PropertyConnectCmd) { // NOLINT }] } })"_json; - command["_ten"]["nodes"][0]["property"]["test_prop"] = CONNECT_CMD_PROP_VAL; + start_graph_cmd_content_str["_ten"]["nodes"][0]["property"]["test_prop"] = + CONNECT_CMD_PROP_VAL; - nlohmann::json resp = client->send_json_and_recv_resp_in_json(command); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json( + start_graph_cmd_content_str.dump().c_str()); + + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "property_start_graph_cmd", - "extension": "test_extension" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "property_start_graph_cmd", "test_extension"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/property/property_connect_cmd_override_extension_success.cc b/tests/ten_runtime/smoke/extension_test/property/property_connect_cmd_override_extension_success.cc index cffb1cbe3..696fb537c 100644 --- a/tests/ten_runtime/smoke/extension_test/property/property_connect_cmd_override_extension_success.cc +++ b/tests/ten_runtime/smoke/extension_test/property/property_connect_cmd_override_extension_success.cc @@ -6,13 +6,11 @@ // #include #include -#include #include "gtest/gtest.h" #include "include_internal/ten_runtime/binding/cpp/ten.h" #include "ten_utils/lang/cpp/lib/value.h" #include "ten_utils/lib/thread.h" -#include "ten_utils/macro/macros.h" #include "tests/common/client/cpp/msgpack_tcp.h" #include "tests/ten_runtime/smoke/extension_test/util/binding/cpp/check.h" @@ -28,8 +26,7 @@ class test_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto prop_value = ten_env.get_property_int64(PROP_NAME); if (prop_value == PROP_NEW_VAL) { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); @@ -81,11 +78,9 @@ TEST(ExtensionTest, PropertyConnectCmdOverrideExtensionSuccess) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json command = + nlohmann::json start_graph_cmd_content_str = R"({ "_ten": { - "type": "start_graph", - "seq_id": "55", "nodes": [{ "type": "extension", "name": "test_extension", @@ -96,26 +91,26 @@ TEST(ExtensionTest, PropertyConnectCmdOverrideExtensionSuccess) { // NOLINT }] } })"_json; - command["_ten"]["nodes"][0]["property"]["test_prop"] = PROP_NEW_VAL; + start_graph_cmd_content_str["_ten"]["nodes"][0]["property"]["test_prop"] = + PROP_NEW_VAL; - nlohmann::json resp = client->send_json_and_recv_resp_in_json(command); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json( + start_graph_cmd_content_str.dump().c_str()); + + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "property_start_graph_cmd_override_extension_success__extension_group", - "extension": "test_extension" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest( + "msgpack://127.0.0.1:8001/", nullptr, + "property_start_graph_cmd_override_extension_success__extension_group", + "test_extension"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/property/property_extension.cc b/tests/ten_runtime/smoke/extension_test/property/property_extension.cc index 20367f365..f7ecc045c 100644 --- a/tests/ten_runtime/smoke/extension_test/property/property_extension.cc +++ b/tests/ten_runtime/smoke/extension_test/property/property_extension.cc @@ -6,7 +6,6 @@ // #include #include -#include #include "gtest/gtest.h" #include "include_internal/ten_runtime/binding/cpp/ten.h" @@ -59,8 +58,7 @@ class test_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto app_property_value = ten_env.get_property_int32("app:" APP_PROP_NAME); auto extension_property_value = ten_env.get_property_int32(EXT_PROP_NAME); @@ -130,12 +128,9 @@ TEST(ExtensionTest, PropertyExtension) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension", "addon": "property_extension__extension", @@ -143,24 +138,19 @@ TEST(ExtensionTest, PropertyExtension) { // NOLINT "extension_group": "property_extension__extension_group" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "property_extension__extension_group", - "extension": "test_extension" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "property_extension__extension_group", + "test_extension"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); // Destroy the client. delete client; diff --git a/tests/ten_runtime/smoke/extension_test/property/property_get_float64.cc b/tests/ten_runtime/smoke/extension_test/property/property_get_float64.cc index 401b74b3e..51cd80cc9 100644 --- a/tests/ten_runtime/smoke/extension_test/property/property_get_float64.cc +++ b/tests/ten_runtime/smoke/extension_test/property/property_get_float64.cc @@ -6,7 +6,6 @@ // #include #include -#include #include "gtest/gtest.h" #include "include_internal/ten_runtime/binding/cpp/ten.h" @@ -27,8 +26,7 @@ class test_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto prop_value = ten_env.get_property_float64("app:" PROP_NAME); if (fabs(prop_value - PROP_VAL) < 0.01) { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); @@ -94,12 +92,9 @@ TEST(ExtensionTest, PropertyGetFloat64) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension", "addon": "property_get_float64__extension", @@ -107,24 +102,19 @@ TEST(ExtensionTest, PropertyGetFloat64) { // NOLINT "extension_group": "property_get_float64__extension_group" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "property_get_float64__extension_group", - "extension": "test_extension" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "property_get_float64__extension_group", + "test_extension"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/property/property_get_int32.cc b/tests/ten_runtime/smoke/extension_test/property/property_get_int32.cc index 780a81263..ea8905598 100644 --- a/tests/ten_runtime/smoke/extension_test/property/property_get_int32.cc +++ b/tests/ten_runtime/smoke/extension_test/property/property_get_int32.cc @@ -6,7 +6,6 @@ // #include #include -#include #include "gtest/gtest.h" #include "include_internal/ten_runtime/binding/cpp/ten.h" @@ -27,8 +26,7 @@ class test_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto prop_value = ten_env.get_property_int32("app:" PROP_NAME); if (prop_value == PROP_VAL) { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); @@ -94,12 +92,9 @@ TEST(ExtensionTest, PropertyGetInt32) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension", "addon": "property_get_int32__extension", @@ -107,24 +102,19 @@ TEST(ExtensionTest, PropertyGetInt32) { // NOLINT "extension_group": "property_get_int32__extension_group" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "property_get_int32__extension_group", - "extension": "test_extension" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "property_get_int32__extension_group", + "test_extension"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/property/property_in_graph_use_env_1.cc b/tests/ten_runtime/smoke/extension_test/property/property_in_graph_use_env_1.cc index 233d2083e..a4c009557 100644 --- a/tests/ten_runtime/smoke/extension_test/property/property_in_graph_use_env_1.cc +++ b/tests/ten_runtime/smoke/extension_test/property/property_in_graph_use_env_1.cc @@ -27,8 +27,7 @@ class test_extension : public ten::extension_t { mode = "default"; } - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", mode); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -108,36 +107,23 @@ TEST(ExtensionTest, PropertyInGraphUseEnv1) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send a user-defined 'hello world' command. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "property_in_graph_use_env_1", - "extension": "property_in_graph_use_env_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "Luke, I'm your father."); - - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "property_in_graph_use_env_1", - "extension": "property_in_graph_use_env_1_no_prop" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, "default"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "property_in_graph_use_env_1", + "property_in_graph_use_env_1"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "Luke, I'm your father."); + hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "property_in_graph_use_env_1", + "property_in_graph_use_env_1_no_prop"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "default"); // Destroy the client. delete client; diff --git a/tests/ten_runtime/smoke/extension_test/property/property_in_graph_use_env_2.cc b/tests/ten_runtime/smoke/extension_test/property/property_in_graph_use_env_2.cc index 2637fb212..ff2c36598 100644 --- a/tests/ten_runtime/smoke/extension_test/property/property_in_graph_use_env_2.cc +++ b/tests/ten_runtime/smoke/extension_test/property/property_in_graph_use_env_2.cc @@ -27,8 +27,7 @@ class test_extension : public ten::extension_t { mode = "default"; } - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", mode); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -108,35 +107,23 @@ TEST(ExtensionTest, PropertyInGraphUseEnv2) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send a user-defined 'hello world' command. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "property_in_graph_use_env_2", - "extension": "property_in_graph_use_env_2" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, "default"); - - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "property_in_graph_use_env_2", - "extension": "property_in_graph_use_env_2_no_prop" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, "default"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "property_in_graph_use_env_2", + "property_in_graph_use_env_2"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "default"); + hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "property_in_graph_use_env_2", + "property_in_graph_use_env_2_no_prop"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "default"); // Destroy the client. delete client; diff --git a/tests/ten_runtime/smoke/extension_test/property/property_not_exist.cc b/tests/ten_runtime/smoke/extension_test/property/property_not_exist.cc index 94b01e6ed..ffb10b142 100644 --- a/tests/ten_runtime/smoke/extension_test/property/property_not_exist.cc +++ b/tests/ten_runtime/smoke/extension_test/property/property_not_exist.cc @@ -6,7 +6,6 @@ // #include #include -#include #include "gtest/gtest.h" #include "include_internal/ten_runtime/binding/cpp/ten.h" @@ -25,8 +24,7 @@ class test_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { // The property does not exist, the app should not crash here. auto prop_value = ten_env.get_property_to_json("app:" PROP_NAME); if (prop_value.empty()) { @@ -80,12 +78,9 @@ TEST(ExtensionTest, PropertyNotExist) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension", "addon": "property_not_exist__extension", @@ -93,24 +88,19 @@ TEST(ExtensionTest, PropertyNotExist) { // NOLINT "extension_group": "property_not_exist__extension_group" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "property_not_exist__extension_group", - "extension": "test_extension" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "property_not_exist__extension_group", + "test_extension"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/property/property_prebuilt_graph.cc b/tests/ten_runtime/smoke/extension_test/property/property_prebuilt_graph.cc index bc776e8e9..28e017697 100644 --- a/tests/ten_runtime/smoke/extension_test/property/property_prebuilt_graph.cc +++ b/tests/ten_runtime/smoke/extension_test/property/property_prebuilt_graph.cc @@ -27,8 +27,7 @@ class test_extension : public ten::extension_t { mode = "default"; } - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", mode); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -108,35 +107,23 @@ TEST(ExtensionTest, PropertyPredefinedGraph) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send a user-defined 'hello world' command. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "property_predefined_graph", - "extension": "property_predefined_graph" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, "1"); - - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "property_predefined_graph", - "extension": "property_predefined_graph_no_prop" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, "default"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "property_predefined_graph", + "property_predefined_graph"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "1"); + hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "property_predefined_graph", + "property_predefined_graph_no_prop"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "default"); // Destroy the client. delete client; diff --git a/tests/ten_runtime/smoke/extension_test/property/property_set_float32.cc b/tests/ten_runtime/smoke/extension_test/property/property_set_float32.cc index 9b0e72d1a..a05e0b06f 100644 --- a/tests/ten_runtime/smoke/extension_test/property/property_set_float32.cc +++ b/tests/ten_runtime/smoke/extension_test/property/property_set_float32.cc @@ -6,7 +6,6 @@ // #include #include -#include #include "gtest/gtest.h" #include "include_internal/ten_runtime/binding/cpp/ten.h" @@ -50,8 +49,7 @@ class test_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto rc = ten_env.set_property(PROP_NAME, static_cast(PROP_NEW_VAL)); EXPECT_EQ(rc, true); @@ -99,7 +97,7 @@ void *test_app_thread_main(TEN_UNUSED void *args) { return nullptr; } TEN_CPP_REGISTER_ADDON_AS_EXTENSION(property_set_float32__extension, - test_extension); + test_extension); } // namespace @@ -112,12 +110,9 @@ TEST(ExtensionTest, PropertySetFloat32) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension", "addon": "property_set_float32__extension", @@ -125,24 +120,19 @@ TEST(ExtensionTest, PropertySetFloat32) { // NOLINT "extension_group": "property_set_float32__extension_group" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "property_set_float32__extension_group", - "extension": "test_extension" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "property_set_float32__extension_group", + "test_extension"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/property/property_set_int32.cc b/tests/ten_runtime/smoke/extension_test/property/property_set_int32.cc index cbb06fb11..6d1848ce5 100644 --- a/tests/ten_runtime/smoke/extension_test/property/property_set_int32.cc +++ b/tests/ten_runtime/smoke/extension_test/property/property_set_int32.cc @@ -6,7 +6,6 @@ // #include #include -#include #include "gtest/gtest.h" #include "include_internal/ten_runtime/binding/cpp/ten.h" @@ -50,8 +49,7 @@ class test_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { ten_env.set_property(PROP_NAME, PROP_NEW_VAL); auto prop_value = ten_env.get_property_int32(PROP_NAME); @@ -98,7 +96,7 @@ void *test_app_thread_main(TEN_UNUSED void *args) { } TEN_CPP_REGISTER_ADDON_AS_EXTENSION(property_set_int32__extension, - test_extension); + test_extension); } // namespace @@ -111,12 +109,9 @@ TEST(ExtensionTest, PropertySetInt32) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension", "addon": "property_set_int32__extension", @@ -124,24 +119,19 @@ TEST(ExtensionTest, PropertySetInt32) { // NOLINT "extension_group": "property_set_int32__extension_group" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "property_set_int32__extension_group", - "extension": "test_extension" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "property_set_int32__extension_group", + "test_extension"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/resp_handler/resp_handler_async_basic.cc b/tests/ten_runtime/smoke/extension_test/resp_handler/resp_handler_async_basic.cc index 3a3078801..295c00c39 100644 --- a/tests/ten_runtime/smoke/extension_test/resp_handler/resp_handler_async_basic.cc +++ b/tests/ten_runtime/smoke/extension_test/resp_handler/resp_handler_async_basic.cc @@ -21,8 +21,7 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world_1") { + if (std::string(cmd->get_name()) == "hello_world_1") { auto test_string = std::make_shared("test test test"); ten_env.send_cmd(std::move(cmd), @@ -36,7 +35,7 @@ class test_extension_1 : public ten::extension_t { ten_env.return_result_directly(std::move(cmd)); } }); - } else if (json["_ten"]["name"] == "hello_world_2") { + } else if (std::string(cmd->get_name()) == "hello_world_2") { ten_env.send_cmd( std::move(cmd), [](ten::ten_env_t &ten_env, std::unique_ptr cmd_result) { @@ -48,7 +47,7 @@ class test_extension_1 : public ten::extension_t { return true; }); - } else if (json["_ten"]["name"] == "hello_world_3") { + } else if (std::string(cmd->get_name()) == "hello_world_3") { ten_env.send_cmd( std::move(cmd), [](ten::ten_env_t &ten_env, std::unique_ptr cmd_result) { @@ -58,15 +57,14 @@ class test_extension_1 : public ten::extension_t { ten_env.return_result_directly(std::move(cmd_result)); } }); - } else if (json["_ten"]["name"] == "hello_world_4") { + } else if (std::string(cmd->get_name()) == "hello_world_4") { hello_world_4_cmd = std::move(cmd); auto hello_world_5_cmd = ten::cmd_t::create("hello_world_5"); ten_env.send_cmd( std::move(hello_world_5_cmd), [&](ten::ten_env_t &ten_env, std::unique_ptr cmd) { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json.value("detail", "") == "hello world, too") { + if (cmd->get_property_string("detail") == "hello world, too") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world 4, too"); ten_env.return_result(std::move(cmd_result), @@ -74,7 +72,7 @@ class test_extension_1 : public ten::extension_t { } }); return; - } else if (json["_ten"]["name"] == "hello_world_5") { + } else if (std::string(cmd->get_name()) == "hello_world_5") { auto cmd_shared = std::make_shared>(std::move(cmd)); @@ -107,12 +105,11 @@ class test_extension_2 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world_1" || - json["_ten"]["name"] == "hello_world_2" || - json["_ten"]["name"] == "hello_world_3" || - json["_ten"]["name"] == "hello_world_5" || - json["_ten"]["name"] == "hello_world_6") { + if (std::string(cmd->get_name()) == "hello_world_1" || + std::string(cmd->get_name()) == "hello_world_2" || + std::string(cmd->get_name()) == "hello_world_3" || + std::string(cmd->get_name()) == "hello_world_5" || + std::string(cmd->get_name()) == "hello_world_6") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -164,12 +161,9 @@ TEST(ExtensionTest, RespHandlerAsyncBasic) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "resp_handler_async_basic__extension_1", @@ -224,84 +218,47 @@ TEST(ExtensionTest, RespHandlerAsyncBasic) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world_1", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "resp_handler_async_basic__extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world 1, too"); - - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world_2", - "seq_id": "138", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "resp_handler_async_basic__extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "138", TEN_STATUS_CODE_OK, - "hello world 2, too"); - - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world_3", - "seq_id": "139", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "resp_handler_async_basic__extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "139", TEN_STATUS_CODE_OK, - "hello world 3, too"); - - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world_4", - "seq_id": "140", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "resp_handler_async_basic__extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "140", TEN_STATUS_CODE_OK, - "hello world 4, too"); - - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world_5", - "seq_id": "141", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "resp_handler_async_basic__extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "141", TEN_STATUS_CODE_OK, - "hello world 5, too"); + auto hello_world_1_cmd = ten::cmd_t::create("hello_world_1"); + hello_world_1_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "resp_handler_async_basic__extension_group", + "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_1_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world 1, too"); + auto hello_world_2_cmd = ten::cmd_t::create("hello_world_2"); + hello_world_2_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "resp_handler_async_basic__extension_group", + "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_2_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world 2, too"); + auto hello_world_3_cmd = ten::cmd_t::create("hello_world_3"); + hello_world_3_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "resp_handler_async_basic__extension_group", + "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_3_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world 3, too"); + auto hello_world_4_cmd = ten::cmd_t::create("hello_world_4"); + hello_world_4_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "resp_handler_async_basic__extension_group", + "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_4_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world 4, too"); + auto hello_world_5_cmd = ten::cmd_t::create("hello_world_5"); + hello_world_5_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "resp_handler_async_basic__extension_group", + "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_5_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world 5, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/resp_handler/resp_handler_basic.cc b/tests/ten_runtime/smoke/extension_test/resp_handler/resp_handler_basic.cc index 168c18b46..eaf420843 100644 --- a/tests/ten_runtime/smoke/extension_test/resp_handler/resp_handler_basic.cc +++ b/tests/ten_runtime/smoke/extension_test/resp_handler/resp_handler_basic.cc @@ -21,8 +21,7 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world_1") { + if (std::string(cmd->get_name()) == "hello_world_1") { auto test_string = std::make_shared("test test test"); ten_env.send_cmd(std::move(cmd), @@ -37,7 +36,7 @@ class test_extension_1 : public ten::extension_t { ten_env.return_result_directly(std::move(cmd)); } }); - } else if (json["_ten"]["name"] == "hello_world_2") { + } else if (std::string(cmd->get_name()) == "hello_world_2") { ten_env.send_cmd( std::move(cmd), [](ten::ten_env_t &ten_env, std::unique_ptr cmd_result) { @@ -47,7 +46,7 @@ class test_extension_1 : public ten::extension_t { ten_env.return_result_directly(std::move(cmd_result)); }; }); - } else if (json["_ten"]["name"] == "hello_world_3") { + } else if (std::string(cmd->get_name()) == "hello_world_3") { ten_env.send_cmd( std::move(cmd), [](ten::ten_env_t &ten_env, std::unique_ptr cmd_result) { @@ -57,22 +56,21 @@ class test_extension_1 : public ten::extension_t { ten_env.return_result_directly(std::move(cmd_result)); } }); - } else if (json["_ten"]["name"] == "hello_world_4") { + } else if (std::string(cmd->get_name()) == "hello_world_4") { hello_world_4_cmd = std::move(cmd); auto hello_world_5_cmd = ten::cmd_t::create("hello_world_5"); ten_env.send_cmd( std::move(hello_world_5_cmd), [&](ten::ten_env_t &ten_env, std::unique_ptr cmd) { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json.value("detail", "") == "hello world 5, too") { + if (cmd->get_property_string("detail") == "hello world 5, too") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world 4, too"); ten_env.return_result(std::move(cmd_result), std::move(hello_world_4_cmd)); } }); - } else if (json["_ten"]["name"] == "hello_world_5") { + } else if (std::string(cmd->get_name()) == "hello_world_5") { auto cmd_shared = std::make_shared>(std::move(cmd)); @@ -102,24 +100,23 @@ class test_extension_2 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world_1") { + if (std::string(cmd->get_name()) == "hello_world_1") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world 1, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); - } else if (json["_ten"]["name"] == "hello_world_2") { + } else if (std::string(cmd->get_name()) == "hello_world_2") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world 2, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); - } else if (json["_ten"]["name"] == "hello_world_3") { + } else if (std::string(cmd->get_name()) == "hello_world_3") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world 3, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); - } else if (json["_ten"]["name"] == "hello_world_5") { + } else if (std::string(cmd->get_name()) == "hello_world_5") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world 5, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); - } else if (json["_ten"]["name"] == "hello_world_6") { + } else if (std::string(cmd->get_name()) == "hello_world_6") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world 6, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -171,12 +168,9 @@ TEST(ExtensionTest, RespHandlerBasic) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "resp_handler_basic__extension_1", @@ -231,84 +225,47 @@ TEST(ExtensionTest, RespHandlerBasic) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world_1", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "resp_handler_basic__extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world 1, too"); - - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world_2", - "seq_id": "138", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "resp_handler_basic__extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "138", TEN_STATUS_CODE_OK, - "hello world 2, too"); - - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world_3", - "seq_id": "139", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "resp_handler_basic__extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "139", TEN_STATUS_CODE_OK, - "hello world 3, too"); - - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world_4", - "seq_id": "140", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "resp_handler_basic__extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "140", TEN_STATUS_CODE_OK, - "hello world 4, too"); - - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world_5", - "seq_id": "141", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "resp_handler_basic__extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "141", TEN_STATUS_CODE_OK, - "hello world 5, too"); + auto hello_world_1_cmd = ten::cmd_t::create("hello_world_1"); + hello_world_1_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "resp_handler_basic__extension_group", + "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_1_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world 1, too"); + auto hello_world_2_cmd = ten::cmd_t::create("hello_world_2"); + hello_world_2_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "resp_handler_basic__extension_group", + "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_2_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world 2, too"); + auto hello_world_3_cmd = ten::cmd_t::create("hello_world_3"); + hello_world_3_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "resp_handler_basic__extension_group", + "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_3_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world 3, too"); + auto hello_world_4_cmd = ten::cmd_t::create("hello_world_4"); + hello_world_4_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "resp_handler_basic__extension_group", + "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_4_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world 4, too"); + auto hello_world_5_cmd = ten::cmd_t::create("hello_world_5"); + hello_world_5_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "resp_handler_basic__extension_group", + "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_5_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world 5, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/resp_handler/resp_handler_basic_wait_in_on_start.cc b/tests/ten_runtime/smoke/extension_test/resp_handler/resp_handler_basic_wait_in_on_start.cc index 7d3102842..2beca7f8f 100644 --- a/tests/ten_runtime/smoke/extension_test/resp_handler/resp_handler_basic_wait_in_on_start.cc +++ b/tests/ten_runtime/smoke/extension_test/resp_handler/resp_handler_basic_wait_in_on_start.cc @@ -27,8 +27,7 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world_1") { + if (std::string(cmd->get_name()) == "hello_world_1") { auto test_string = std::make_shared("test test test"); ten_env.send_cmd(std::move(cmd), @@ -43,7 +42,7 @@ class test_extension_1 : public ten::extension_t { ten_env.return_result_directly(std::move(cmd)); } }); - } else if (json["_ten"]["name"] == "hello_world_2") { + } else if (std::string(cmd->get_name()) == "hello_world_2") { ten_env.send_cmd( std::move(cmd), [](ten::ten_env_t &ten_env, std::unique_ptr cmd_result) { @@ -53,7 +52,7 @@ class test_extension_1 : public ten::extension_t { ten_env.return_result_directly(std::move(cmd_result)); }; }); - } else if (json["_ten"]["name"] == "hello_world_3") { + } else if (std::string(cmd->get_name()) == "hello_world_3") { ten_env.send_cmd( std::move(cmd), [](ten::ten_env_t &ten_env, std::unique_ptr cmd_result) { @@ -63,22 +62,21 @@ class test_extension_1 : public ten::extension_t { ten_env.return_result_directly(std::move(cmd_result)); } }); - } else if (json["_ten"]["name"] == "hello_world_4") { + } else if (std::string(cmd->get_name()) == "hello_world_4") { hello_world_4_cmd = std::move(cmd); auto hello_world_5_cmd = ten::cmd_t::create("hello_world_5"); ten_env.send_cmd( std::move(hello_world_5_cmd), [&](ten::ten_env_t &ten_env, std::unique_ptr cmd) { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json.value("detail", "") == "hello world 5, too") { + if (cmd->get_property_string("detail") == "hello world 5, too") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world 4, too"); ten_env.return_result(std::move(cmd_result), std::move(hello_world_4_cmd)); } }); - } else if (json["_ten"]["name"] == "hello_world_5") { + } else if (std::string(cmd->get_name()) == "hello_world_5") { auto cmd_shared = std::make_shared>(std::move(cmd)); @@ -108,24 +106,23 @@ class test_extension_2 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world_1") { + if (std::string(cmd->get_name()) == "hello_world_1") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world 1, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); - } else if (json["_ten"]["name"] == "hello_world_2") { + } else if (std::string(cmd->get_name()) == "hello_world_2") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world 2, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); - } else if (json["_ten"]["name"] == "hello_world_3") { + } else if (std::string(cmd->get_name()) == "hello_world_3") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world 3, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); - } else if (json["_ten"]["name"] == "hello_world_5") { + } else if (std::string(cmd->get_name()) == "hello_world_5") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world 5, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); - } else if (json["_ten"]["name"] == "hello_world_6") { + } else if (std::string(cmd->get_name()) == "hello_world_6") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world 6, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -177,12 +174,9 @@ TEST(ExtensionTest, RespHandlerBasicWaitInOnStart) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "resp_handler_basic_wait_in_on_start__extension_1", @@ -237,84 +231,52 @@ TEST(ExtensionTest, RespHandlerBasicWaitInOnStart) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world_1", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "resp_handler_basic_wait_in_on_start__extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world 1, too"); - - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world_2", - "seq_id": "138", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "resp_handler_basic_wait_in_on_start__extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "138", TEN_STATUS_CODE_OK, - "hello world 2, too"); - - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world_3", - "seq_id": "139", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "resp_handler_basic_wait_in_on_start__extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "139", TEN_STATUS_CODE_OK, - "hello world 3, too"); - - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world_4", - "seq_id": "140", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "resp_handler_basic_wait_in_on_start__extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "140", TEN_STATUS_CODE_OK, - "hello world 4, too"); - - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world_5", - "seq_id": "141", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "resp_handler_basic_wait_in_on_start__extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "141", TEN_STATUS_CODE_OK, - "hello world 5, too"); + auto hello_world_1_cmd = ten::cmd_t::create("hello_world_1"); + hello_world_1_cmd->set_dest( + "msgpack://127.0.0.1:8001/", nullptr, + "resp_handler_basic_wait_in_on_start__extension_group", + "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_1_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world 1, too"); + auto hello_world_2_cmd = ten::cmd_t::create("hello_world_2"); + hello_world_2_cmd->set_dest( + "msgpack://127.0.0.1:8001/", nullptr, + "resp_handler_basic_wait_in_on_start__extension_group", + "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_2_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world 2, too"); + auto hello_world_3_cmd = ten::cmd_t::create("hello_world_3"); + hello_world_3_cmd->set_dest( + "msgpack://127.0.0.1:8001/", nullptr, + "resp_handler_basic_wait_in_on_start__extension_group", + "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_3_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world 3, too"); + auto hello_world_4_cmd = ten::cmd_t::create("hello_world_4"); + hello_world_4_cmd->set_dest( + "msgpack://127.0.0.1:8001/", nullptr, + "resp_handler_basic_wait_in_on_start__extension_group", + "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_4_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world 4, too"); + auto hello_world_5_cmd = ten::cmd_t::create("hello_world_5"); + hello_world_5_cmd->set_dest( + "msgpack://127.0.0.1:8001/", nullptr, + "resp_handler_basic_wait_in_on_start__extension_group", + "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_5_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world 5, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/return/return_1.cc b/tests/ten_runtime/smoke/extension_test/return/return_1.cc index 50a84503f..7f13b1882 100644 --- a/tests/ten_runtime/smoke/extension_test/return/return_1.cc +++ b/tests/ten_runtime/smoke/extension_test/return/return_1.cc @@ -110,12 +110,9 @@ TEST(ExtensionTest, Return1) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "return_1__extension_1", @@ -152,25 +149,19 @@ TEST(ExtensionTest, Return1) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command to 'extension 1'. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "return from extension 1"); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "return from extension 1"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/return/return_2.cc b/tests/ten_runtime/smoke/extension_test/return/return_2.cc index e7acf810f..0d9653f04 100644 --- a/tests/ten_runtime/smoke/extension_test/return/return_2.cc +++ b/tests/ten_runtime/smoke/extension_test/return/return_2.cc @@ -110,12 +110,9 @@ TEST(ExtensionTest, Return2) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "return_2__extension_1", @@ -152,25 +149,19 @@ TEST(ExtensionTest, Return2) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command to 'extension 1'. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group 1", - "extension": "test_extension_1" - }] - } - })"_json); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group 1", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "return from extension 1"); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "return from extension 1"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/return/return_3.cc b/tests/ten_runtime/smoke/extension_test/return/return_3.cc index 0733a6e70..6439e79ed 100644 --- a/tests/ten_runtime/smoke/extension_test/return/return_3.cc +++ b/tests/ten_runtime/smoke/extension_test/return/return_3.cc @@ -138,12 +138,9 @@ TEST(ExtensionTest, Return3) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "return_3__extension_1", @@ -180,25 +177,19 @@ TEST(ExtensionTest, Return3) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command to 'extension 1'. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group 1", - "extension": "test_extension_1" - }] - } - })"_json); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group 1", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "return from extension 1"); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "return from extension 1"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/return/return_4.cc b/tests/ten_runtime/smoke/extension_test/return/return_4.cc index 340ea1c46..4e7994524 100644 --- a/tests/ten_runtime/smoke/extension_test/return/return_4.cc +++ b/tests/ten_runtime/smoke/extension_test/return/return_4.cc @@ -138,12 +138,9 @@ TEST(ExtensionTest, Return4) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "return_4__extension_1", @@ -180,25 +177,19 @@ TEST(ExtensionTest, Return4) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command to 'extension 1'. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "return from extension 1"); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "return from extension 1"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/same_thread_ext_on_xxx/same_thread_ext_on_data.cc b/tests/ten_runtime/smoke/extension_test/same_thread_ext_on_xxx/same_thread_ext_on_data.cc index b5e1201e4..99dffef41 100644 --- a/tests/ten_runtime/smoke/extension_test/same_thread_ext_on_xxx/same_thread_ext_on_data.cc +++ b/tests/ten_runtime/smoke/extension_test/same_thread_ext_on_xxx/same_thread_ext_on_data.cc @@ -112,12 +112,9 @@ TEST(ExtensionTest, SameThreadExtOnData) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "same_thread_ext_on_data__test_extension_1", @@ -152,24 +149,18 @@ TEST(ExtensionTest, SameThreadExtOnData) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/same_thread_ext_on_xxx/same_thread_ext_on_xxx_basic.cc b/tests/ten_runtime/smoke/extension_test/same_thread_ext_on_xxx/same_thread_ext_on_xxx_basic.cc index 123fb678e..c19d83f51 100644 --- a/tests/ten_runtime/smoke/extension_test/same_thread_ext_on_xxx/same_thread_ext_on_xxx_basic.cc +++ b/tests/ten_runtime/smoke/extension_test/same_thread_ext_on_xxx/same_thread_ext_on_xxx_basic.cc @@ -120,12 +120,9 @@ TEST(ExtensionTest, SameThreadExtOnXxxBasic) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "same_thread_ext_on_xxx_basic__test_extension_1", @@ -152,24 +149,18 @@ TEST(ExtensionTest, SameThreadExtOnXxxBasic) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/start_graph/start_graph_and_communicate.cc b/tests/ten_runtime/smoke/extension_test/start_graph/start_graph_and_communicate.cc index 40df8bbc2..1768d23a6 100644 --- a/tests/ten_runtime/smoke/extension_test/start_graph/start_graph_and_communicate.cc +++ b/tests/ten_runtime/smoke/extension_test/start_graph/start_graph_and_communicate.cc @@ -18,8 +18,7 @@ class test_normal_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -83,8 +82,7 @@ class test_predefined_graph : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "test") { + if (std::string(cmd->get_name()) == "test") { if (received_hello_world_resp) { nlohmann::json detail = {{"id", 1}, {"name", "a"}}; @@ -172,21 +170,13 @@ TEST(ExtensionTest, StartGraphAndCommunication) { // NOLINT // Do not need to send 'start_graph' command first. // The 'graph_id' MUST be "default" (a special string) if we want to send the // request to predefined graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "test", - "seq_id": "111", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "start_graph_and_communication__predefined_graph_group", - "extension": "predefined_graph" - }] - } - })"_json); - ten_test::check_result_is(resp, "111", TEN_STATUS_CODE_OK, - R"({"id": 1, "name": "a"})"); + auto test_cmd = ten::cmd_t::create("test"); + test_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "start_graph_and_communication__predefined_graph_group", + "predefined_graph"); + auto cmd_result = client->send_cmd_and_recv_result(std::move(test_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_json(cmd_result, R"({"id": 1, "name": "a"})"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/start_graph/start_graph_from_extension.cc b/tests/ten_runtime/smoke/extension_test/start_graph/start_graph_from_extension.cc index be187c024..8027b79ba 100644 --- a/tests/ten_runtime/smoke/extension_test/start_graph/start_graph_from_extension.cc +++ b/tests/ten_runtime/smoke/extension_test/start_graph/start_graph_from_extension.cc @@ -61,8 +61,7 @@ class test_predefined_graph : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "test") { + if (std::string(cmd->get_name()) == "test") { if (start_graph_cmd_is_done) { nlohmann::json detail = {{"id", 1}, {"name", "a"}}; @@ -150,21 +149,13 @@ TEST(ExtensionTest, StartGraphFromExtension) { // NOLINT // Do not need to send 'start_graph' command first. // The 'graph_id' MUST be "default" (a special string) if we want to send the // request to predefined graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "test", - "seq_id": "111", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "start_graph_from_extension__predefined_graph_group", - "extension": "predefined_graph" - }] - } - })"_json); - ten_test::check_result_is(resp, "111", TEN_STATUS_CODE_OK, - R"({"id": 1, "name": "a"})"); + auto test_cmd = ten::cmd_t::create("test"); + test_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "start_graph_from_extension__predefined_graph_group", + "predefined_graph"); + auto cmd_result = client->send_cmd_and_recv_result(std::move(test_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_json(cmd_result, R"({"id": 1, "name": "a"})"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/start_graph/start_predefined_graph_cross_app.cc b/tests/ten_runtime/smoke/extension_test/start_graph/start_predefined_graph_cross_app.cc index 550ef3add..e5aaba879 100644 --- a/tests/ten_runtime/smoke/extension_test/start_graph/start_predefined_graph_cross_app.cc +++ b/tests/ten_runtime/smoke/extension_test/start_graph/start_predefined_graph_cross_app.cc @@ -31,8 +31,7 @@ class test_normal_extension_2 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -108,8 +107,7 @@ class test_predefined_graph : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "test") { + if (std::string(cmd->get_name()) == "test") { if (received_hello_world_resp) { nlohmann::json detail = {{"id", 1}, {"name", "a"}}; @@ -255,21 +253,13 @@ TEST(ExtensionTest, StartPredefinedGraphCrossApp) { // NOLINT // Do not need to send 'start_graph' command first. // The 'graph_id' MUST be "default" (a special string) if we want to send the // request to predefined graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "test", - "seq_id": "111", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "start_predefined_graph_cross_app__predefined_graph_group", - "extension": "predefined_graph" - }] - } - })"_json); - ten_test::check_result_is(resp, "111", TEN_STATUS_CODE_OK, - R"({"id": 1, "name": "a"})"); + auto test_cmd = ten::cmd_t::create("test"); + test_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "start_predefined_graph_cross_app__predefined_graph_group", + "predefined_graph"); + auto cmd_result = client->send_cmd_and_recv_result(std::move(test_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_json(cmd_result, R"({"id": 1, "name": "a"})"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/start_graph/start_predefined_graph_from_extension.cc b/tests/ten_runtime/smoke/extension_test/start_graph/start_predefined_graph_from_extension.cc index 7b6d9700d..c849105b5 100644 --- a/tests/ten_runtime/smoke/extension_test/start_graph/start_predefined_graph_from_extension.cc +++ b/tests/ten_runtime/smoke/extension_test/start_graph/start_predefined_graph_from_extension.cc @@ -18,8 +18,7 @@ class test_normal_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -76,8 +75,7 @@ class test_predefined_graph : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "test") { + if (std::string(cmd->get_name()) == "test") { if (received_hello_world_resp) { nlohmann::json detail = {{"id", 1}, {"name", "a"}}; @@ -175,21 +173,14 @@ TEST(ExtensionTest, StartPredefinedGraphFromExtension) { // NOLINT // Do not need to send 'start_graph' command first. // The 'graph_id' MUST be "default" (a special string) if we want to send the // request to predefined graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "test", - "seq_id": "111", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "start_predefined_graph_from_extension__predefined_graph_group", - "extension": "predefined_graph" - }] - } - })"_json); - ten_test::check_result_is(resp, "111", TEN_STATUS_CODE_OK, - R"({"id": 1, "name": "a"})"); + auto test_cmd = ten::cmd_t::create("test"); + test_cmd->set_dest( + "msgpack://127.0.0.1:8001/", "default", + "start_predefined_graph_from_extension__predefined_graph_group", + "predefined_graph"); + auto cmd_result = client->send_cmd_and_recv_result(std::move(test_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_json(cmd_result, R"({"id": 1, "name": "a"})"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/start_graph/start_two_predefined_graphs.cc b/tests/ten_runtime/smoke/extension_test/start_graph/start_two_predefined_graphs.cc index 878e7e34c..4fec9c509 100644 --- a/tests/ten_runtime/smoke/extension_test/start_graph/start_two_predefined_graphs.cc +++ b/tests/ten_runtime/smoke/extension_test/start_graph/start_two_predefined_graphs.cc @@ -33,8 +33,7 @@ class test_normal_extension_2 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -92,8 +91,7 @@ class test_predefined_graph : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "test") { + if (std::string(cmd->get_name()) == "test") { nlohmann::json detail = {{"id", 1}, {"name", "a"}}; auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); @@ -257,21 +255,13 @@ TEST(ExtensionTest, StartTwoPredefinedGraphs) { // NOLINT // Do not need to send 'start_graph' command first. // The 'graph_id' MUST be "default" (a special string) if we want to send the // request to predefined graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "test", - "seq_id": "111", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "start_two_predefined_graphs__predefined_graph_group", - "extension": "predefined_graph" - }] - } - })"_json); - ten_test::check_result_is(resp, "111", TEN_STATUS_CODE_OK, - R"({"id": 1, "name": "a"})"); + auto test_cmd = ten::cmd_t::create("test"); + test_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "start_two_predefined_graphs__predefined_graph_group", + "predefined_graph"); + auto cmd_result = client->send_cmd_and_recv_result(std::move(test_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_json(cmd_result, R"({"id": 1, "name": "a"})"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/suspend_resume/suspend_resume_1.cc b/tests/ten_runtime/smoke/extension_test/suspend_resume/suspend_resume_1.cc index d7ccfe894..17e7feddc 100644 --- a/tests/ten_runtime/smoke/extension_test/suspend_resume/suspend_resume_1.cc +++ b/tests/ten_runtime/smoke/extension_test/suspend_resume/suspend_resume_1.cc @@ -184,12 +184,9 @@ TEST(ExtensionTest, SuspendResume1) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "suspend_resume_1__test_extension_1", @@ -224,24 +221,18 @@ TEST(ExtensionTest, SuspendResume1) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/suspend_resume/suspend_resume_2.cc b/tests/ten_runtime/smoke/extension_test/suspend_resume/suspend_resume_2.cc index 308919c63..4241e86c8 100644 --- a/tests/ten_runtime/smoke/extension_test/suspend_resume/suspend_resume_2.cc +++ b/tests/ten_runtime/smoke/extension_test/suspend_resume/suspend_resume_2.cc @@ -192,12 +192,9 @@ TEST(ExtensionTest, SuspendResume2) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "suspend_resume_2__test_extension_1", @@ -232,24 +229,18 @@ TEST(ExtensionTest, SuspendResume2) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world 1, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world 1, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/ten_proxy/ten_proxy_1.cc b/tests/ten_runtime/smoke/extension_test/ten_proxy/ten_proxy_1.cc index e46357927..14d443703 100644 --- a/tests/ten_runtime/smoke/extension_test/ten_proxy/ten_proxy_1.cc +++ b/tests/ten_runtime/smoke/extension_test/ten_proxy/ten_proxy_1.cc @@ -137,12 +137,9 @@ TEST(ExtensionTest, TenEnvProxy1) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "ten_proxy_1__test_extension_1", @@ -150,24 +147,18 @@ TEST(ExtensionTest, TenEnvProxy1) { // NOLINT "extension_group": "basic_extension_group" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/timer/timer_one_shot.cc b/tests/ten_runtime/smoke/extension_test/timer/timer_one_shot.cc index 3500c4065..6b2810f83 100644 --- a/tests/ten_runtime/smoke/extension_test/timer/timer_one_shot.cc +++ b/tests/ten_runtime/smoke/extension_test/timer/timer_one_shot.cc @@ -10,6 +10,7 @@ #include "gtest/gtest.h" #include "include_internal/ten_runtime/binding/cpp/ten.h" +#include "ten_runtime/msg/msg.h" #include "ten_utils/lib/thread.h" #include "tests/common/client/cpp/msgpack_tcp.h" #include "tests/ten_runtime/smoke/extension_test/util/binding/cpp/check.h" @@ -24,8 +25,7 @@ class test_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { hello_world_cmd = std::move(cmd); // Start a timer. @@ -37,8 +37,10 @@ class test_extension : public ten::extension_t { ten_env.send_cmd(std::move(timer_cmd)); return; - } else if (json["_ten"]["type"] == "timeout" && - json["_ten"]["timer_id"].get() == 55) { + } else if (cmd->get_type() == TEN_MSG_TYPE_CMD_TIMEOUT && + std::unique_ptr( + static_cast(cmd.release())) + ->get_timer_id() == 55) { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(hello_world_cmd)); @@ -110,12 +112,9 @@ TEST(ExtensionTest, TimerOneShot) { auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension", "addon": "timer_one_shot__extension", @@ -123,24 +122,19 @@ TEST(ExtensionTest, TimerOneShot) { "extension_group": "timer_one_shot__extension_group" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "timer_one_shot__extension_group", - "extension": "test_extension" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "timer_one_shot__extension_group", + "test_extension"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/timer/timer_ten_shot.cc b/tests/ten_runtime/smoke/extension_test/timer/timer_ten_shot.cc index 43158f9bf..46862ded4 100644 --- a/tests/ten_runtime/smoke/extension_test/timer/timer_ten_shot.cc +++ b/tests/ten_runtime/smoke/extension_test/timer/timer_ten_shot.cc @@ -6,7 +6,6 @@ // #include #include -#include #include "gtest/gtest.h" #include "include_internal/ten_runtime/binding/cpp/ten.h" @@ -24,8 +23,7 @@ class test_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { hello_world_cmd = std::move(cmd); auto timer_cmd = ten::cmd_timer_t::create(); @@ -36,8 +34,10 @@ class test_extension : public ten::extension_t { ten_env.send_cmd(std::move(timer_cmd)); return; - } else if (json["_ten"]["type"] == "timeout" && - json["_ten"]["timer_id"].get() == 55) { + } else if (cmd->get_type() == TEN_MSG_TYPE_CMD_TIMEOUT && + std::unique_ptr( + static_cast(cmd.release())) + ->get_timer_id() == 55) { timer_shots_cnt++; if (timer_shots_cnt == TIMER_TIMES) { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); @@ -93,12 +93,9 @@ TEST(ExtensionTest, TimerTenShot) { auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension", "addon": "timer_ten_shot__extension", @@ -106,24 +103,19 @@ TEST(ExtensionTest, TimerTenShot) { "extension_group": "timer_ten_shot__extension_group" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "timer_ten_shot__extension_group", - "extension": "test_extension" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "timer_ten_shot__extension_group", + "test_extension"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/timer/timer_two_shot.cc b/tests/ten_runtime/smoke/extension_test/timer/timer_two_shot.cc index 5b6a4f660..55a641ac2 100644 --- a/tests/ten_runtime/smoke/extension_test/timer/timer_two_shot.cc +++ b/tests/ten_runtime/smoke/extension_test/timer/timer_two_shot.cc @@ -6,7 +6,6 @@ // #include #include -#include #include "gtest/gtest.h" #include "include_internal/ten_runtime/binding/cpp/ten.h" @@ -24,8 +23,7 @@ class test_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { hello_world_cmd = std::move(cmd); auto timer_cmd = ten::cmd_timer_t::create(); @@ -36,8 +34,10 @@ class test_extension : public ten::extension_t { ten_env.send_cmd(std::move(timer_cmd)); return; - } else if (json["_ten"]["type"] == "timeout" && - json["_ten"]["timer_id"].get() == 55) { + } else if (cmd->get_type() == TEN_MSG_TYPE_CMD_TIMEOUT && + std::unique_ptr( + static_cast(cmd.release())) + ->get_timer_id() == 55) { timer_shots_cnt++; if (timer_shots_cnt == TIMER_TIMES) { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); @@ -93,12 +93,9 @@ TEST(ExtensionTest, TimerTwoShot) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension", "addon": "timer_two_shot__extension", @@ -106,24 +103,19 @@ TEST(ExtensionTest, TimerTwoShot) { // NOLINT "extension_group": "timer_two_shot__extension_group" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "timer_two_shot__extension_group", - "extension": "test_extension" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "timer_two_shot__extension_group", + "test_extension"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/extension_test/util/binding/cpp/check.h b/tests/ten_runtime/smoke/extension_test/util/binding/cpp/check.h index ae1cfc204..e03d9a861 100644 --- a/tests/ten_runtime/smoke/extension_test/util/binding/cpp/check.h +++ b/tests/ten_runtime/smoke/extension_test/util/binding/cpp/check.h @@ -8,27 +8,18 @@ #include +#include #include #include "gtest/gtest.h" #include "nlohmann/json.hpp" +#include "ten_runtime/binding/cpp/internal/msg/cmd_result.h" +#include "ten_runtime/common/status_code.h" namespace ten_test { -static inline void assert_json_equals_integer(const nlohmann::json &actual, - const int64_t expected) { - bool is_equals = false; - - if (actual.is_number()) { - is_equals = (actual.get() == expected); - } - - EXPECT_EQ(true, is_equals) << "Assertion failed, expected: " << expected - << ", actual: " << actual << std::endl; -} - -static inline void assert_json_equals(const nlohmann::json &actual, - const std::string &expected) { +static inline void _assert_json_equals(const nlohmann::json &actual, + const std::string &expected) { // CAUTION: we can not use 'EXPECT_EQ(str1, str2)' here, there will be too // many useless logs if assertion failed. @@ -45,42 +36,24 @@ static inline void assert_json_equals(const nlohmann::json &actual, << ", actual: " << actual << std::endl; } -static inline void check_status_code_is(const nlohmann::json &json, - const TEN_STATUS_CODE status_code) { - assert_json_equals_integer(json["_ten"]["status_code"], status_code); -} - -static inline void check_seq_id_is(const nlohmann::json &json, - const std::string &expect) { - assert_json_equals(json["_ten"]["seq_id"], expect); +static inline void check_status_code( + const std::unique_ptr &cmd_result, + const TEN_STATUS_CODE status_code) { + EXPECT_EQ(cmd_result->get_status_code(), status_code); } -static inline void check_detail_is(const nlohmann::json &actual, - const std::string &expected) { - assert_json_equals(actual["detail"], expected); +static inline void check_detail_with_json( + const std::unique_ptr &cmd_result, + const nlohmann::json &expected) { + _assert_json_equals( + nlohmann::json::parse(cmd_result->get_property_to_json("detail")), + expected); } -static inline void check_result_is(const nlohmann::json &resp, - const std::string &seq_id, - const TEN_STATUS_CODE status_code, - const std::string &detail) { - check_seq_id_is(resp, seq_id); - check_status_code_is(resp, status_code); - check_detail_is(resp, detail); -} - -static inline void check_result_json_is(const nlohmann::json &resp, - const std::string &seq_id, - const TEN_STATUS_CODE status_code, - const std::string &detail_field, - const std::string &detail_value) { - check_seq_id_is(resp, seq_id); - check_status_code_is(resp, status_code); - - nlohmann::json detail = - nlohmann::json::parse(resp["detail"].get()); - - assert_json_equals(detail[detail_field], detail_value); +static inline void check_detail_with_string( + const std::unique_ptr &cmd_result, + const std::string &detail) { + EXPECT_EQ(cmd_result->get_property_string("detail"), detail); } } // namespace ten_test diff --git a/tests/ten_runtime/smoke/extension_test/util/check.h b/tests/ten_runtime/smoke/extension_test/util/check.h deleted file mode 100644 index e837cc3cd..000000000 --- a/tests/ten_runtime/smoke/extension_test/util/check.h +++ /dev/null @@ -1,61 +0,0 @@ -// -// Copyright © 2024 Agora -// This file is part of TEN Framework, an open source project. -// Licensed under the Apache License, Version 2.0, with certain conditions. -// Refer to the "LICENSE" file in the root directory for more information. -// -#include "ten_runtime/ten_config.h" - -#include - -#include "gtest/gtest.h" -#include "include_internal/ten_runtime/msg/msg.h" -#include "ten_runtime/common/status_code.h" -#include "ten_utils/lib/json.h" -#include "ten_utils/lib/string.h" - -static inline void check_status_code_is(ten_json_t *json, - TEN_STATUS_CODE status_code) { - TEN_ASSERT(json, "Should not happen."); - - EXPECT_EQ( - ten_msg_json_get_integer_field_in_ten(json, "status_code") == status_code, - true); -} - -static inline void check_detail_is_string(ten_json_t *json, - const char *detail) { - TEN_ASSERT(json, "Should not happen."); - EXPECT_EQ(ten_c_string_is_equal( - ten_msg_json_get_string_field_in_ten(json, "detail"), detail), - true); -} - -static inline void check_seq_id_is(ten_json_t *json, const char *expect) { - TEN_ASSERT(json, "Should not happen."); - EXPECT_EQ(ten_c_string_is_equal( - expect, ten_msg_json_get_string_field_in_ten(json, "seq_id")), - true); -} - -static inline void check_result_is(ten_json_t *resp, const char *seq_id, - TEN_STATUS_CODE status_code, - const char *detail) { - check_seq_id_is(resp, seq_id); - check_status_code_is(resp, status_code); - check_detail_is_string(resp, detail); -} - -static inline void check_result_json_is(ten_json_t *resp, const char *seq_id, - TEN_STATUS_CODE status_code, - const char *detail_field, - const char *detail_value) { - check_seq_id_is(resp, seq_id); - check_status_code_is(resp, status_code); - ten_json_t *detail = ten_json_from_string( - ten_msg_json_get_string_field_in_ten(resp, "detail"), NULL); - EXPECT_EQ(ten_c_string_is_equal(detail_value, ten_json_object_peek_string( - detail, detail_field)), - true); - ten_json_destroy(detail); -} diff --git a/tests/ten_runtime/smoke/graph_test/group_node_missing.cc b/tests/ten_runtime/smoke/graph_test/group_node_missing.cc index 527b4cf9a..ee2c9b9f2 100644 --- a/tests/ten_runtime/smoke/graph_test/group_node_missing.cc +++ b/tests/ten_runtime/smoke/graph_test/group_node_missing.cc @@ -70,12 +70,9 @@ TEST(GraphTest, GroupNodeMissing) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension", "addon": "group_node_missing__test_extension", @@ -83,24 +80,18 @@ TEST(GraphTest, GroupNodeMissing) { // NOLINT "app": "msgpack://127.0.0.1:8001/" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group", - "extension": "test_extension" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group", "test_extension"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/graph_test/group_node_missing_2_apps.cc b/tests/ten_runtime/smoke/graph_test/group_node_missing_2_apps.cc index ce98469ac..843517bef 100644 --- a/tests/ten_runtime/smoke/graph_test/group_node_missing_2_apps.cc +++ b/tests/ten_runtime/smoke/graph_test/group_node_missing_2_apps.cc @@ -24,8 +24,7 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { ten_env.send_cmd(std::move(cmd)); return; } @@ -38,8 +37,7 @@ class test_extension_2 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); @@ -153,12 +151,9 @@ TEST(GraphTest, GroupNodeMissing2Apps) { // NOLINT // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "addon": "group_node_missing_2_apps__extension_1", "name": "test_extension_1", @@ -185,10 +180,12 @@ TEST(GraphTest, GroupNodeMissing2Apps) { // NOLINT }] }] } - })"_json); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); - if (!resp.empty()) { - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + if (cmd_result) { + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); break; } else { client.reset(); @@ -201,20 +198,15 @@ TEST(GraphTest, GroupNodeMissing2Apps) { // NOLINT TEN_ASSERT(client, "Failed to connect to the TEN app."); // Send a user-defined 'hello world' command. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group 1", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group 1", "test_extension_1"); + + auto cmd_result = + client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); // Because the closing of an engine would _not_ cause the closing of the // app, so we have to explicitly close the app. diff --git a/tests/ten_runtime/smoke/interface_test/interface_out_cmd_in_schema.cc b/tests/ten_runtime/smoke/interface_test/interface_out_cmd_in_schema.cc index 727ffb218..950b387a2 100644 --- a/tests/ten_runtime/smoke/interface_test/interface_out_cmd_in_schema.cc +++ b/tests/ten_runtime/smoke/interface_test/interface_out_cmd_in_schema.cc @@ -118,12 +118,9 @@ TEST(InterfaceTest, OutCmdInSchema) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "interface_out_cmd_in_schema__test_extension_1", @@ -150,24 +147,18 @@ TEST(InterfaceTest, OutCmdInSchema) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/interface_test/interface_out_cmd_not_in_schema.cc b/tests/ten_runtime/smoke/interface_test/interface_out_cmd_not_in_schema.cc index c261c3d11..4eb786c83 100644 --- a/tests/ten_runtime/smoke/interface_test/interface_out_cmd_not_in_schema.cc +++ b/tests/ten_runtime/smoke/interface_test/interface_out_cmd_not_in_schema.cc @@ -118,12 +118,9 @@ TEST(InterfaceTest, OutCmdNotInSchema) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "interface_out_cmd_not_in_schema__test_extension_1", @@ -150,24 +147,18 @@ TEST(InterfaceTest, OutCmdNotInSchema) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/interface_test/interface_out_result_error.cc b/tests/ten_runtime/smoke/interface_test/interface_out_result_error.cc index 209756981..6dd5494b8 100644 --- a/tests/ten_runtime/smoke/interface_test/interface_out_result_error.cc +++ b/tests/ten_runtime/smoke/interface_test/interface_out_result_error.cc @@ -160,12 +160,9 @@ TEST(InterfaceTest, OutResultError) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "interface_out_result_error__test_extension_1", @@ -192,23 +189,17 @@ TEST(InterfaceTest, OutResultError) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); delete client; diff --git a/tests/ten_runtime/smoke/log_test/log_file.cc b/tests/ten_runtime/smoke/log_test/log_file.cc index e1ad15fe6..8e3a4fc28 100644 --- a/tests/ten_runtime/smoke/log_test/log_file.cc +++ b/tests/ten_runtime/smoke/log_test/log_file.cc @@ -73,12 +73,9 @@ TEST(LogTest, LogFile) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension", "addon": "log_file__test_extension", @@ -86,24 +83,18 @@ TEST(LogTest, LogFile) { // NOLINT "app": "msgpack://127.0.0.1:8001/" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group", - "extension": "test_extension" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group", "test_extension"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/log_test/log_stderr.cc b/tests/ten_runtime/smoke/log_test/log_stderr.cc index fbca65503..6eb03e3d9 100644 --- a/tests/ten_runtime/smoke/log_test/log_stderr.cc +++ b/tests/ten_runtime/smoke/log_test/log_stderr.cc @@ -72,12 +72,9 @@ TEST(LogTest, LogStderr) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension", "addon": "log_stderr__test_extension", @@ -85,24 +82,18 @@ TEST(LogTest, LogStderr) { // NOLINT "app": "msgpack://127.0.0.1:8001/" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group", - "extension": "test_extension" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group", "test_extension"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/msg_test/msg_1.cc b/tests/ten_runtime/smoke/msg_test/msg_1.cc index 447456ed0..e142a2b80 100644 --- a/tests/ten_runtime/smoke/msg_test/msg_1.cc +++ b/tests/ten_runtime/smoke/msg_test/msg_1.cc @@ -23,8 +23,7 @@ class test_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { hello_world_cmd = std::move(cmd); // Start a timer. @@ -36,8 +35,10 @@ class test_extension : public ten::extension_t { bool success = ten_env.send_cmd(std::move(timer_cmd)); EXPECT_EQ(success, true); - } else if (json["_ten"]["type"] == "timeout" && - json["_ten"]["timer_id"].get() == 55) { + } else if (cmd->get_type() == TEN_MSG_TYPE_CMD_TIMEOUT && + std::unique_ptr( + static_cast(cmd.release())) + ->get_timer_id() == 55) { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(hello_world_cmd)); @@ -88,12 +89,9 @@ TEST(MsgTest, Msg1) { auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension", "addon": "msg_1__extension", @@ -101,24 +99,18 @@ TEST(MsgTest, Msg1) { "extension_group": "msg_1__extension_group" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "msg_1__extension_group", - "extension": "test_extension" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "msg_1__extension_group", "test_extension"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/msg_test/msg_10.cc b/tests/ten_runtime/smoke/msg_test/msg_10.cc index af74ecfe8..14bdd6475 100644 --- a/tests/ten_runtime/smoke/msg_test/msg_10.cc +++ b/tests/ten_runtime/smoke/msg_test/msg_10.cc @@ -132,12 +132,9 @@ TEST(MsgTest, Msg10) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "msg_10__extension_1", "addon": "msg_10__extension_1", @@ -164,24 +161,18 @@ TEST(MsgTest, Msg10) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "msg_10__extension_group_1", - "extension": "msg_10__extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "msg_10__extension_group_1", "msg_10__extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/msg_test/msg_11.cc b/tests/ten_runtime/smoke/msg_test/msg_11.cc index eae384bff..5bda7fa13 100644 --- a/tests/ten_runtime/smoke/msg_test/msg_11.cc +++ b/tests/ten_runtime/smoke/msg_test/msg_11.cc @@ -6,7 +6,6 @@ // #include #include -#include #include "gtest/gtest.h" #include "include_internal/ten_runtime/binding/cpp/ten.h" @@ -24,29 +23,21 @@ class test_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { hello_world_cmd = std::move(cmd); - // Start a timer. - std::unique_ptr timer_cmd = ten::cmd_t::create("ten:timer"); + auto timer_cmd = ten::cmd_timer_t::create(); timer_cmd->set_dest("localhost", nullptr, nullptr, nullptr); - timer_cmd->from_json( - // clang-format off - R"({ - "_ten": { - "timer_id": 55, - "timeout_in_us": 100, - "times": 1 - } - })" - // clang-format on - ); + timer_cmd->set_timer_id(55); + timer_cmd->set_timeout_in_us(100); + timer_cmd->set_times(1); bool success = ten_env.send_cmd(std::move(timer_cmd)); EXPECT_EQ(success, true); - } else if (json["_ten"]["type"] == "timeout" && - json["_ten"]["timer_id"].get() == 55) { + } else if (cmd->get_type() == TEN_MSG_TYPE_CMD_TIMEOUT && + std::unique_ptr( + static_cast(cmd.release())) + ->get_timer_id() == 55) { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(hello_world_cmd)); @@ -91,12 +82,9 @@ TEST(MsgTest, Msg11) { auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension", "addon": "msg_11__extension", @@ -104,24 +92,18 @@ TEST(MsgTest, Msg11) { "extension_group": "msg_11__extension_group" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "msg_11__extension_group", - "extension": "test_extension" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "msg_11__extension_group", "test_extension"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/msg_test/msg_12.cc b/tests/ten_runtime/smoke/msg_test/msg_12.cc index 28dff758f..c99acd5df 100644 --- a/tests/ten_runtime/smoke/msg_test/msg_12.cc +++ b/tests/ten_runtime/smoke/msg_test/msg_12.cc @@ -133,12 +133,9 @@ TEST(MsgTest, Msg12) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "msg_12__extension_1", "addon": "msg_12__extension_1", @@ -165,24 +162,18 @@ TEST(MsgTest, Msg12) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "msg_12__extension_group_1", - "extension": "msg_12__extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "msg_12__extension_group_1", "msg_12__extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/msg_test/msg_13.cc b/tests/ten_runtime/smoke/msg_test/msg_13.cc index 1645cbc71..69c27864e 100644 --- a/tests/ten_runtime/smoke/msg_test/msg_13.cc +++ b/tests/ten_runtime/smoke/msg_test/msg_13.cc @@ -132,12 +132,9 @@ TEST(MsgTest, Msg13) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "msg_13__extension_1", "addon": "msg_13__extension_1", @@ -164,24 +161,18 @@ TEST(MsgTest, Msg13) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "msg_13__extension_group_1", - "extension": "msg_13__extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "msg_13__extension_group_1", "msg_13__extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/msg_test/msg_2.cc b/tests/ten_runtime/smoke/msg_test/msg_2.cc index cc8977157..658d3066b 100644 --- a/tests/ten_runtime/smoke/msg_test/msg_2.cc +++ b/tests/ten_runtime/smoke/msg_test/msg_2.cc @@ -6,7 +6,6 @@ // #include #include -#include #include "gtest/gtest.h" #include "include_internal/ten_runtime/binding/cpp/ten.h" @@ -24,8 +23,7 @@ class test_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { hello_world_cmd = std::move(cmd); // Start a timer. @@ -37,8 +35,10 @@ class test_extension : public ten::extension_t { bool success = ten_env.send_cmd(std::move(timer_cmd)); EXPECT_EQ(success, true); - } else if (json["_ten"]["type"] == "timeout" && - json["_ten"]["timer_id"].get() == 55) { + } else if (cmd->get_type() == TEN_MSG_TYPE_CMD_TIMEOUT && + std::unique_ptr( + static_cast(cmd.release())) + ->get_timer_id() == 55) { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(hello_world_cmd)); @@ -83,12 +83,9 @@ TEST(MsgTest, Msg2) { auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension", "addon": "msg_2__extension", @@ -96,24 +93,18 @@ TEST(MsgTest, Msg2) { "extension_group": "msg_2__extension_group" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "msg_2__extension_group", - "extension": "test_extension" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "msg_2__extension_group", "test_extension"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/msg_test/msg_3.cc b/tests/ten_runtime/smoke/msg_test/msg_3.cc index 5046100db..ce3299f15 100644 --- a/tests/ten_runtime/smoke/msg_test/msg_3.cc +++ b/tests/ten_runtime/smoke/msg_test/msg_3.cc @@ -6,7 +6,6 @@ // #include #include -#include #include "gtest/gtest.h" #include "include_internal/ten_runtime/binding/cpp/ten.h" @@ -24,8 +23,7 @@ class test_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { hello_world_cmd = std::move(cmd); // Start a timer. @@ -37,8 +35,10 @@ class test_extension : public ten::extension_t { bool success = ten_env.send_cmd(std::move(timer_cmd)); EXPECT_EQ(success, true); - } else if (json["_ten"]["type"] == "timeout" && - json["_ten"]["timer_id"].get() == 55) { + } else if (cmd->get_type() == TEN_MSG_TYPE_CMD_TIMEOUT && + std::unique_ptr( + static_cast(cmd.release())) + ->get_timer_id() == 55) { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(hello_world_cmd)); @@ -83,12 +83,9 @@ TEST(MsgTest, Msg3) { auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension", "addon": "msg_3__extension", @@ -96,24 +93,18 @@ TEST(MsgTest, Msg3) { "extension_group": "msg_3__extension_group" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "msg_3__extension_group", - "extension": "test_extension" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "msg_3__extension_group", "test_extension"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/msg_test/msg_4.cc b/tests/ten_runtime/smoke/msg_test/msg_4.cc index 54f0509d9..b2f18d846 100644 --- a/tests/ten_runtime/smoke/msg_test/msg_4.cc +++ b/tests/ten_runtime/smoke/msg_test/msg_4.cc @@ -6,7 +6,6 @@ // #include #include -#include #include "gtest/gtest.h" #include "include_internal/ten_runtime/binding/cpp/ten.h" @@ -24,29 +23,22 @@ class test_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { hello_world_cmd = std::move(cmd); // Start a timer. - std::unique_ptr timer_cmd = ten::cmd_timer_t::create(); + auto timer_cmd = ten::cmd_timer_t::create(); timer_cmd->set_dest("localhost", nullptr, nullptr, nullptr); - timer_cmd->from_json( - // clang-format off - R"({ - "_ten": { - "timer_id": 55, - "timeout_in_us": 100, - "times": 1 - } - })" - // clang-format on - ); + timer_cmd->set_timer_id(55); + timer_cmd->set_timeout_in_us(100); + timer_cmd->set_times(1); bool success = ten_env.send_cmd(std::move(timer_cmd)); EXPECT_EQ(success, true); - } else if (json["_ten"]["type"] == "timeout" && - json["_ten"]["timer_id"].get() == 55) { + } else if (cmd->get_type() == TEN_MSG_TYPE_CMD_TIMEOUT && + std::unique_ptr( + static_cast(cmd.release())) + ->get_timer_id() == 55) { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(hello_world_cmd)); @@ -91,12 +83,9 @@ TEST(MsgTest, Msg4) { auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension", "addon": "msg_4__extension", @@ -104,24 +93,18 @@ TEST(MsgTest, Msg4) { "extension_group": "msg_4__extension_group" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "msg_4__extension_group", - "extension": "test_extension" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "msg_4__extension_group", "test_extension"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/msg_test/msg_5.cc b/tests/ten_runtime/smoke/msg_test/msg_5.cc index c7d6089c7..cc620af08 100644 --- a/tests/ten_runtime/smoke/msg_test/msg_5.cc +++ b/tests/ten_runtime/smoke/msg_test/msg_5.cc @@ -6,7 +6,6 @@ // #include #include -#include #include "gtest/gtest.h" #include "include_internal/ten_runtime/binding/cpp/ten.h" @@ -24,31 +23,22 @@ class test_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { hello_world_cmd = std::move(cmd); // Start a timer. - std::unique_ptr timer_cmd = ten::cmd_timer_t::create(); - timer_cmd->from_json( - // clang-format off - R"({ - "_ten": { - "dest": [{ - "app": "localhost" - }], - "timer_id": 55, - "timeout_in_us": 100, - "times": 1 - } - })" - // clang-format on - ); + auto timer_cmd = ten::cmd_timer_t::create(); + timer_cmd->set_dest("localhost", nullptr, nullptr, nullptr); + timer_cmd->set_timer_id(55); + timer_cmd->set_timeout_in_us(100); + timer_cmd->set_times(1); bool success = ten_env.send_cmd(std::move(timer_cmd)); EXPECT_EQ(success, true); - } else if (json["_ten"]["type"] == "timeout" && - json["_ten"]["timer_id"].get() == 55) { + } else if (cmd->get_type() == TEN_MSG_TYPE_CMD_TIMEOUT && + std::unique_ptr( + static_cast(cmd.release())) + ->get_timer_id() == 55) { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(hello_world_cmd)); @@ -93,12 +83,9 @@ TEST(MsgTest, Msg5) { auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension", "addon": "msg_5__extension", @@ -106,24 +93,18 @@ TEST(MsgTest, Msg5) { "extension_group": "msg_5__extension_group" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "msg_5__extension_group", - "extension": "test_extension" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "msg_5__extension_group", "test_extension"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/msg_test/msg_6.cc b/tests/ten_runtime/smoke/msg_test/msg_6.cc index 9c75293cb..7d2ff93e5 100644 --- a/tests/ten_runtime/smoke/msg_test/msg_6.cc +++ b/tests/ten_runtime/smoke/msg_test/msg_6.cc @@ -6,7 +6,6 @@ // #include #include -#include #include "gtest/gtest.h" #include "include_internal/ten_runtime/binding/cpp/ten.h" @@ -24,8 +23,7 @@ class test_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { hello_world_cmd = std::move(cmd); // Start a timer. @@ -37,8 +35,10 @@ class test_extension : public ten::extension_t { bool success = ten_env.send_cmd(std::move(timer_cmd)); EXPECT_EQ(success, true); - } else if (json["_ten"]["type"] == "timeout" && - json["_ten"]["timer_id"].get() == 55) { + } else if (cmd->get_type() == TEN_MSG_TYPE_CMD_TIMEOUT && + std::unique_ptr( + static_cast(cmd.release())) + ->get_timer_id() == 55) { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(hello_world_cmd)); @@ -83,12 +83,9 @@ TEST(MsgTest, Msg6) { auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension", "addon": "msg_6__extension", @@ -96,24 +93,18 @@ TEST(MsgTest, Msg6) { "extension_group": "msg_6__extension_group" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "msg_6__extension_group", - "extension": "test_extension" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "msg_6__extension_group", "test_extension"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/msg_test/msg_7.cc b/tests/ten_runtime/smoke/msg_test/msg_7.cc index 9c39e4aba..117151141 100644 --- a/tests/ten_runtime/smoke/msg_test/msg_7.cc +++ b/tests/ten_runtime/smoke/msg_test/msg_7.cc @@ -6,7 +6,6 @@ // #include #include -#include #include "gtest/gtest.h" #include "include_internal/ten_runtime/binding/cpp/ten.h" @@ -24,8 +23,7 @@ class test_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { hello_world_cmd = std::move(cmd); // Start a timer. @@ -37,8 +35,10 @@ class test_extension : public ten::extension_t { bool success = ten_env.send_cmd(std::move(timer_cmd)); EXPECT_EQ(success, true); - } else if (json["_ten"]["type"] == "timeout" && - json["_ten"]["timer_id"].get() == 55) { + } else if (cmd->get_type() == TEN_MSG_TYPE_CMD_TIMEOUT && + std::unique_ptr( + static_cast(cmd.release())) + ->get_timer_id() == 55) { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(hello_world_cmd)); @@ -83,12 +83,9 @@ TEST(MsgTest, Msg7) { auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension", "addon": "msg_7__extension", @@ -96,24 +93,18 @@ TEST(MsgTest, Msg7) { "extension_group": "msg_7__extension_group" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "msg_7__extension_group", - "extension": "test_extension" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "msg_7__extension_group", "test_extension"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/msg_test/msg_8.cc b/tests/ten_runtime/smoke/msg_test/msg_8.cc index ccf3a8e04..3873b3b1a 100644 --- a/tests/ten_runtime/smoke/msg_test/msg_8.cc +++ b/tests/ten_runtime/smoke/msg_test/msg_8.cc @@ -104,12 +104,9 @@ TEST(MsgTest, Msg8) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "msg_8__extension_1", "addon": "msg_8__extension_1", @@ -136,24 +133,18 @@ TEST(MsgTest, Msg8) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "msg_8__extension_group_1", - "extension": "msg_8__extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "msg_8__extension_group_1", "msg_8__extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/msg_test/msg_9.cc b/tests/ten_runtime/smoke/msg_test/msg_9.cc index 2f5aafa7b..5d6ea3ffd 100644 --- a/tests/ten_runtime/smoke/msg_test/msg_9.cc +++ b/tests/ten_runtime/smoke/msg_test/msg_9.cc @@ -133,12 +133,9 @@ TEST(MsgTest, Msg9) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "msg_9__extension_1", "addon": "msg_9__extension_1", @@ -165,24 +162,18 @@ TEST(MsgTest, Msg9) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "msg_9__extension_group_1", - "extension": "msg_9__extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "msg_9__extension_group_1", "msg_9__extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/msg_test/msg_fail_1.cc b/tests/ten_runtime/smoke/msg_test/msg_fail_1.cc index 9863e6ad5..55eb5100d 100644 --- a/tests/ten_runtime/smoke/msg_test/msg_fail_1.cc +++ b/tests/ten_runtime/smoke/msg_test/msg_fail_1.cc @@ -6,7 +6,6 @@ // #include #include -#include #include "gtest/gtest.h" #include "include_internal/ten_runtime/binding/cpp/ten.h" @@ -24,8 +23,7 @@ class test_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { hello_world_cmd = std::move(cmd); // Start a timer. @@ -37,8 +35,10 @@ class test_extension : public ten::extension_t { bool success = ten_env.send_cmd(std::move(timer_cmd)); EXPECT_EQ(success, true); - } else if (json["_ten"]["type"] == "timeout" && - json["_ten"]["timer_id"].get() == 55) { + } else if (cmd->get_type() == TEN_MSG_TYPE_CMD_TIMEOUT && + std::unique_ptr( + static_cast(cmd.release())) + ->get_timer_id() == 55) { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(hello_world_cmd)); @@ -83,12 +83,9 @@ TEST(MsgTest, MsgFail1) { auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension", "addon": "msg_fail_1__extension", @@ -96,24 +93,18 @@ TEST(MsgTest, MsgFail1) { "extension_group": "msg_fail_1__extension_group" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "msg_fail_1__extension_group", - "extension": "test_extension" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "msg_fail_1__extension_group", "test_extension"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/msg_test/msg_fail_2.cc b/tests/ten_runtime/smoke/msg_test/msg_fail_2.cc index cbc27dbf9..3beab8d3f 100644 --- a/tests/ten_runtime/smoke/msg_test/msg_fail_2.cc +++ b/tests/ten_runtime/smoke/msg_test/msg_fail_2.cc @@ -6,7 +6,6 @@ // #include #include -#include #include "gtest/gtest.h" #include "include_internal/ten_runtime/binding/cpp/ten.h" @@ -24,45 +23,22 @@ class test_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "hello_world") { + if (std::string(cmd->get_name()) == "hello_world") { hello_world_cmd = std::move(cmd); // Start a timer. - std::unique_ptr timer_cmd = ten::cmd_timer_t::create(); + auto timer_cmd = ten::cmd_timer_t::create(); timer_cmd->set_dest("localhost", nullptr, nullptr, nullptr); - - bool success = timer_cmd->from_json( - // clang-format off - R"({ - "_ten": { - "type": "incorrect_type", - "timer_id": 55, - "timeout_in_us": 100, - "times": 1 - } - })" - // clang-format on - ); - EXPECT_EQ(success, false); - - success = timer_cmd->from_json( - // clang-format off - R"({ - "_ten": { - "timer_id": 55, - "timeout_in_us": 100, - "times": 1 - } - })" - // clang-format on - ); - EXPECT_EQ(success, true); - - success = ten_env.send_cmd(std::move(timer_cmd)); - EXPECT_EQ(success, true); - } else if (json["_ten"]["type"] == "timeout" && - json["_ten"]["timer_id"].get() == 55) { + timer_cmd->set_timer_id(55); + timer_cmd->set_timeout_in_us(100); + timer_cmd->set_times(1); + + bool rc = ten_env.send_cmd(std::move(timer_cmd)); + EXPECT_EQ(rc, true); + } else if (cmd->get_type() == TEN_MSG_TYPE_CMD_TIMEOUT && + std::unique_ptr( + static_cast(cmd.release())) + ->get_timer_id() == 55) { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(hello_world_cmd)); @@ -95,8 +71,7 @@ void *test_app_thread_main(TEN_UNUSED void *args) { return nullptr; } -TEN_CPP_REGISTER_ADDON_AS_EXTENSION(msg_fail_2__extension, - test_extension); +TEN_CPP_REGISTER_ADDON_AS_EXTENSION(msg_fail_2__extension, test_extension); } // namespace @@ -108,12 +83,9 @@ TEST(MsgTest, MsgFail2) { auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension", "addon": "msg_fail_2__extension", @@ -121,24 +93,18 @@ TEST(MsgTest, MsgFail2) { "extension_group": "msg_fail_2__extension_group" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest":[{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "msg_fail_2__extension_group", - "extension": "test_extension" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "msg_fail_2__extension_group", "test_extension"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/notify_test/member_func_in_lambda_1.cc b/tests/ten_runtime/smoke/notify_test/member_func_in_lambda_1.cc index d88f54f05..6276552f8 100644 --- a/tests/ten_runtime/smoke/notify_test/member_func_in_lambda_1.cc +++ b/tests/ten_runtime/smoke/notify_test/member_func_in_lambda_1.cc @@ -121,12 +121,9 @@ TEST(NotifyTest, MemberFuncInLambda1) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension", "addon": "notify_test_member_func_basic_in_lambda_1__test_extension", @@ -134,24 +131,18 @@ TEST(NotifyTest, MemberFuncInLambda1) { // NOLINT "extension_group": "basic_extension_group" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/notify_test/member_func_in_lambda_2.cc b/tests/ten_runtime/smoke/notify_test/member_func_in_lambda_2.cc index 36fd044c6..b23834454 100644 --- a/tests/ten_runtime/smoke/notify_test/member_func_in_lambda_2.cc +++ b/tests/ten_runtime/smoke/notify_test/member_func_in_lambda_2.cc @@ -129,12 +129,9 @@ TEST(NotifyTest, MemberFuncInLambda2) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension", "addon": "notify_test_member_func_basic_in_lambda_2__test_extension", @@ -142,24 +139,18 @@ TEST(NotifyTest, MemberFuncInLambda2) { // NOLINT "extension_group": "basic_extension_group" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/notify_test/member_func_in_lambda_3.cc b/tests/ten_runtime/smoke/notify_test/member_func_in_lambda_3.cc index a8248b3a2..37012604f 100644 --- a/tests/ten_runtime/smoke/notify_test/member_func_in_lambda_3.cc +++ b/tests/ten_runtime/smoke/notify_test/member_func_in_lambda_3.cc @@ -131,12 +131,9 @@ TEST(NotifyTest, MemberFuncInLambda3) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension", "addon": "notify_test_member_func_basic_in_lambda_3__test_extension", @@ -144,24 +141,18 @@ TEST(NotifyTest, MemberFuncInLambda3) { // NOLINT "extension_group": "basic_extension_group" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/notify_test/normal_func.cc b/tests/ten_runtime/smoke/notify_test/normal_func.cc index bda843f46..35df2a900 100644 --- a/tests/ten_runtime/smoke/notify_test/normal_func.cc +++ b/tests/ten_runtime/smoke/notify_test/normal_func.cc @@ -123,12 +123,9 @@ TEST(NotifyTest, NormalFunc) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension", "addon": "notify_test_normal_func__test_extension", @@ -136,24 +133,18 @@ TEST(NotifyTest, NormalFunc) { // NOLINT "extension_group": "basic_extension_group" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/notify_test/normal_func_in_lambda.cc b/tests/ten_runtime/smoke/notify_test/normal_func_in_lambda.cc index 038b21641..91d7b3376 100644 --- a/tests/ten_runtime/smoke/notify_test/normal_func_in_lambda.cc +++ b/tests/ten_runtime/smoke/notify_test/normal_func_in_lambda.cc @@ -127,12 +127,9 @@ TEST(NotifyTest, NormalFuncInLambda) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension", "addon": "notify_test_normal_func_in_lambda__test_extension", @@ -140,24 +137,18 @@ TEST(NotifyTest, NormalFuncInLambda) { // NOLINT "extension_group": "basic_extension_group" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/notify_test/normal_func_with_user_data.cc b/tests/ten_runtime/smoke/notify_test/normal_func_with_user_data.cc index f7ecd35d1..867c9b19e 100644 --- a/tests/ten_runtime/smoke/notify_test/normal_func_with_user_data.cc +++ b/tests/ten_runtime/smoke/notify_test/normal_func_with_user_data.cc @@ -131,12 +131,9 @@ TEST(NotifyTest, NormalFuncWithUserData) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension", "addon": "notify_test_normal_func_with_user_data__test_extension", @@ -144,24 +141,18 @@ TEST(NotifyTest, NormalFuncWithUserData) { // NOLINT "extension_group": "basic_extension_group" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/result_conversion/result_conversion_1.cc b/tests/ten_runtime/smoke/result_conversion/result_conversion_1.cc index 29f70c80a..42639bcf4 100644 --- a/tests/ten_runtime/smoke/result_conversion/result_conversion_1.cc +++ b/tests/ten_runtime/smoke/result_conversion/result_conversion_1.cc @@ -44,10 +44,12 @@ class test_extension_2 : public ten::extension_t { std::unique_ptr cmd) override { if (std::string(cmd->get_name()) == "hello_mapping") { if (cmd->get_property_int64("test_group.test_property_name") == 32) { - auto resp = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); - resp->set_property("detail", "hello world, too"); - resp->set_property("resp_property", "may the force be with you."); - ten_env.return_result(std::move(resp), std::move(cmd)); + auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); + + cmd_result->set_property("detail", "hello world, too"); + cmd_result->set_property("resp_property", "may the force be with you."); + + ten_env.return_result(std::move(cmd_result), std::move(cmd)); } } } @@ -159,22 +161,17 @@ TEST(ResultConversionTest, ResultConversion1) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send a user-defined 'hello world' command. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "graph": "default", - "extension_group": "result_mapping_1__extension_group", - "extension": "test_extension_1" - }] - }, - "test_property": 32 - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "may the force be with you."); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", + "result_mapping_1__extension_group", + "test_extension_1"); + hello_world_cmd->set_property("test_property", 32); + + auto cmd_result = + client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "may the force be with you."); delete client; diff --git a/tests/ten_runtime/smoke/schema_test/schema_cmd_property_required.cc b/tests/ten_runtime/smoke/schema_test/schema_cmd_property_required.cc index 1e9a4f0a6..5d7ba4255 100644 --- a/tests/ten_runtime/smoke/schema_test/schema_cmd_property_required.cc +++ b/tests/ten_runtime/smoke/schema_test/schema_cmd_property_required.cc @@ -202,12 +202,9 @@ TEST(SchemaTest, SendCmdPropertyRequired) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "schema_cmd_property_required__test_extension_1", @@ -234,24 +231,18 @@ TEST(SchemaTest, SendCmdPropertyRequired) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - R"({"a": "demo", "b": 1})"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_json(cmd_result, R"({"a": "demo", "b": 1})"); delete client; diff --git a/tests/ten_runtime/smoke/schema_test/schema_cmd_result.cc b/tests/ten_runtime/smoke/schema_test/schema_cmd_result.cc index 6ff263636..f4c5e2ce6 100644 --- a/tests/ten_runtime/smoke/schema_test/schema_cmd_result.cc +++ b/tests/ten_runtime/smoke/schema_test/schema_cmd_result.cc @@ -147,11 +147,10 @@ TEST(SchemaTest, CmdResult) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json( R"###({ "_ten": { - "type": "start_graph", - "seq_id": "55", "nodes": [{ "type": "extension", "name": "test_extension_1", @@ -179,23 +178,17 @@ TEST(SchemaTest, CmdResult) { // NOLINT }] }] } - })###"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })###"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); delete client; diff --git a/tests/ten_runtime/smoke/schema_test/schema_cmd_result_error.cc b/tests/ten_runtime/smoke/schema_test/schema_cmd_result_error.cc index a9d3de3cc..6f3f5b076 100644 --- a/tests/ten_runtime/smoke/schema_test/schema_cmd_result_error.cc +++ b/tests/ten_runtime/smoke/schema_test/schema_cmd_result_error.cc @@ -147,11 +147,10 @@ TEST(SchemaTest, CmdResultError) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json( R"###({ "_ten": { - "type": "start_graph", - "seq_id": "55", "nodes": [{ "type": "extension", "name": "test_extension_1", @@ -179,23 +178,17 @@ TEST(SchemaTest, CmdResultError) { // NOLINT }] }] } - })###"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })###"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_ERROR); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_ERROR); delete client; diff --git a/tests/ten_runtime/smoke/schema_test/schema_data_prop.cc b/tests/ten_runtime/smoke/schema_test/schema_data_prop.cc index 3473c667d..1ef7d7ebc 100644 --- a/tests/ten_runtime/smoke/schema_test/schema_data_prop.cc +++ b/tests/ten_runtime/smoke/schema_test/schema_data_prop.cc @@ -182,12 +182,9 @@ TEST(SchemaTest, DataProp) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "schema_data_prop__test_extension_1", @@ -214,24 +211,19 @@ TEST(SchemaTest, DataProp) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, "success"); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "success"); { std::unique_lock lock(mutex_lock); diff --git a/tests/ten_runtime/smoke/schema_test/schema_on_cmd.cc b/tests/ten_runtime/smoke/schema_test/schema_on_cmd.cc index d43087d17..a15ec1ff4 100644 --- a/tests/ten_runtime/smoke/schema_test/schema_on_cmd.cc +++ b/tests/ten_runtime/smoke/schema_test/schema_on_cmd.cc @@ -136,12 +136,9 @@ TEST(SchemaTest, OnCmd) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "schema_on_cmd__test_extension_1", @@ -168,26 +165,20 @@ TEST(SchemaTest, OnCmd) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); // The cmd does not match the schema defined in `test_extension_2`, so we will // receive an error result. - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_ERROR); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_ERROR); delete client; diff --git a/tests/ten_runtime/smoke/schema_test/schema_send_cmd.cc b/tests/ten_runtime/smoke/schema_test/schema_send_cmd.cc index 1f6657d55..b702c608d 100644 --- a/tests/ten_runtime/smoke/schema_test/schema_send_cmd.cc +++ b/tests/ten_runtime/smoke/schema_test/schema_send_cmd.cc @@ -133,12 +133,9 @@ TEST(SchemaTest, SendCmd) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "schema_send_cmd__test_extension_1", @@ -165,24 +162,18 @@ TEST(SchemaTest, SendCmd) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/schema_test/schema_set_extension_property.cc b/tests/ten_runtime/smoke/schema_test/schema_set_extension_property.cc index 7e272774e..edc25c88f 100644 --- a/tests/ten_runtime/smoke/schema_test/schema_set_extension_property.cc +++ b/tests/ten_runtime/smoke/schema_test/schema_set_extension_property.cc @@ -186,12 +186,9 @@ TEST(SchemaTest, SetExtensionProperty) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension", "addon": "schema_set_extension_prop__test_extension", @@ -199,23 +196,18 @@ TEST(SchemaTest, SetExtensionProperty) { // NOLINT "app": "msgpack://127.0.0.1:8001/" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group", - "extension": "test_extension" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, "world"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group", "test_extension"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "world"); delete client; diff --git a/tests/ten_runtime/smoke/schema_test/schema_set_property_buf.cc b/tests/ten_runtime/smoke/schema_test/schema_set_property_buf.cc index ba42108e1..add6ac55c 100644 --- a/tests/ten_runtime/smoke/schema_test/schema_set_property_buf.cc +++ b/tests/ten_runtime/smoke/schema_test/schema_set_property_buf.cc @@ -134,12 +134,9 @@ TEST(SchemaTest, SetPropertyBuf) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "schema_set_property_buf__test_extension_1", @@ -166,24 +163,18 @@ TEST(SchemaTest, SetPropertyBuf) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/schema_test/schema_set_property_ptr.cc b/tests/ten_runtime/smoke/schema_test/schema_set_property_ptr.cc index 8341cdbf6..bd39c63fe 100644 --- a/tests/ten_runtime/smoke/schema_test/schema_set_property_ptr.cc +++ b/tests/ten_runtime/smoke/schema_test/schema_set_property_ptr.cc @@ -136,12 +136,9 @@ TEST(SchemaTest, SetPropertyPtr) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "schema_set_property_ptr__test_extension_1", @@ -168,24 +165,18 @@ TEST(SchemaTest, SetPropertyPtr) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/ten_env_call_timing/on_xxx_done.cc b/tests/ten_runtime/smoke/ten_env_call_timing/on_xxx_done.cc index 70190dcf9..11705d3cb 100644 --- a/tests/ten_runtime/smoke/ten_env_call_timing/on_xxx_done.cc +++ b/tests/ten_runtime/smoke/ten_env_call_timing/on_xxx_done.cc @@ -142,12 +142,9 @@ TEST(TenEnvCallTimingTest, OnXxxDone) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension", "addon": "on_xxx_done__test_extension", @@ -155,24 +152,18 @@ TEST(TenEnvCallTimingTest, OnXxxDone) { // NOLINT "app": "msgpack://127.0.0.1:8001/" }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group", - "extension": "test_extension" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group", "test_extension"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/video_frame_test/basic.cc b/tests/ten_runtime/smoke/video_frame_test/basic.cc index 85d0f8088..f8a220ea5 100644 --- a/tests/ten_runtime/smoke/video_frame_test/basic.cc +++ b/tests/ten_runtime/smoke/video_frame_test/basic.cc @@ -94,12 +94,9 @@ TEST(VideoFrameTest, Basic) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "video_frame_basic__test_extension_1", @@ -138,24 +135,18 @@ TEST(VideoFrameTest, Basic) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/video_frame_test/create_from_json.cc b/tests/ten_runtime/smoke/video_frame_test/create_from_json.cc index e9be46795..c8e3fcbaa 100644 --- a/tests/ten_runtime/smoke/video_frame_test/create_from_json.cc +++ b/tests/ten_runtime/smoke/video_frame_test/create_from_json.cc @@ -105,12 +105,9 @@ TEST(VideoFrameTest, CreateFromJson) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "video_frame_create_from_json__test_extension_1", @@ -149,24 +146,18 @@ TEST(VideoFrameTest, CreateFromJson) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/video_frame_test/from_json.cc b/tests/ten_runtime/smoke/video_frame_test/from_json.cc index 0137b211d..d10d65abc 100644 --- a/tests/ten_runtime/smoke/video_frame_test/from_json.cc +++ b/tests/ten_runtime/smoke/video_frame_test/from_json.cc @@ -26,18 +26,11 @@ class test_extension_1 : public ten::extension_t { hello_world_cmd = std::move(cmd); auto video_frame = ten::video_frame_t::create("video_frame"); - video_frame->from_json( - // clang-format off - R"({ - "_ten": { - "width": 345, - "height": 567, - "pixel_fmt": 1, - "timestamp": 12341234 - } - })" - // clang-format on - ); + video_frame->set_width(345); + video_frame->set_height(567); + video_frame->set_pixel_fmt(TEN_PIXEL_FMT_RGB24); + video_frame->set_timestamp(12341234); + ten_env.send_video_frame(std::move(video_frame)); } else if (std::string(cmd->get_name()) == "video_frame_ack") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); @@ -110,12 +103,9 @@ TEST(VideoFrameTest, FromJson) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "test_extension_1", "addon": "video_frame_from_json__test_extension_1", @@ -154,24 +144,18 @@ TEST(VideoFrameTest, FromJson) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'hello world' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "hello_world", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "basic_extension_group", - "extension": "test_extension_1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "hello world, too"); + auto hello_world_cmd = ten::cmd_t::create("hello_world"); + hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "basic_extension_group", "test_extension_1"); + cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "hello world, too"); delete client; diff --git a/tests/ten_runtime/smoke/video_frame_test/multi_dest_video_frame.cc b/tests/ten_runtime/smoke/video_frame_test/multi_dest_video_frame.cc index 160af7d81..1a4d57a39 100644 --- a/tests/ten_runtime/smoke/video_frame_test/multi_dest_video_frame.cc +++ b/tests/ten_runtime/smoke/video_frame_test/multi_dest_video_frame.cc @@ -39,8 +39,7 @@ class test_extension_1 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "dispatch_data") { + if (std::string(cmd->get_name()) == "dispatch_data") { auto video_frame = create420Buffer(WIDTH, HEIGHT); video_frame->set_property("test_prop", "test_prop_value"); @@ -71,8 +70,7 @@ class test_extension_2 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "check_received") { + if (std::string(cmd->get_name()) == "check_received") { if (received) { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "received confirmed"); @@ -107,8 +105,7 @@ class test_extension_3 : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json["_ten"]["name"] == "check_received") { + if (std::string(cmd->get_name()) == "check_received") { if (received) { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "received confirmed"); @@ -171,12 +168,9 @@ TEST(VideoFrameTest, MultiDestVideoFrame) { // NOLINT auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/"); // Send graph. - nlohmann::json resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "type": "start_graph", - "seq_id": "55", - "nodes": [{ + auto start_graph_cmd = ten::cmd_start_graph_t::create(); + start_graph_cmd->set_nodes_and_connections_from_json(R"({ + "_ten": {"nodes": [{ "type": "extension", "name": "extension 1", "addon": "multi_dest_video_frame__extension_1", @@ -213,53 +207,32 @@ TEST(VideoFrameTest, MultiDestVideoFrame) { // NOLINT }] }] } - })"_json); - ten_test::check_status_code_is(resp, TEN_STATUS_CODE_OK); + })"); + auto cmd_result = + client->send_cmd_and_recv_result(std::move(start_graph_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); // Send a user-defined 'dispatch_data' command. - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "dispatch_data", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group", - "extension": "extension 1" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, "done"); - - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "check_received", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group", - "extension": "extension 2" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "received confirmed"); - - resp = client->send_json_and_recv_resp_in_json( - R"({ - "_ten": { - "name": "check_received", - "seq_id": "137", - "dest": [{ - "app": "msgpack://127.0.0.1:8001/", - "extension_group": "test_extension_group", - "extension": "extension 3" - }] - } - })"_json); - ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, - "received confirmed"); + auto dispatch_data_cmd = ten::cmd_t::create("dispatch_data"); + dispatch_data_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group", "extension 1"); + cmd_result = client->send_cmd_and_recv_result(std::move(dispatch_data_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "done"); + + auto check_received_cmd = ten::cmd_t::create("check_received"); + check_received_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group", "extension 2"); + cmd_result = client->send_cmd_and_recv_result(std::move(check_received_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "received confirmed"); + + check_received_cmd = ten::cmd_t::create("check_received"); + check_received_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, + "test_extension_group", "extension 3"); + cmd_result = client->send_cmd_and_recv_result(std::move(check_received_cmd)); + ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK); + ten_test::check_detail_with_string(cmd_result, "received confirmed"); delete client;