-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add codes to address this issue. (#272)
- Loading branch information
Showing
3 changed files
with
227 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
178 changes: 178 additions & 0 deletions
178
tests/ten_runtime/smoke/extension_test/dest/no_audio_frame_dest.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
// | ||
// 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 <memory> | ||
#include <nlohmann/json.hpp> | ||
#include <string> | ||
|
||
#include "gtest/gtest.h" | ||
#include "include_internal/ten_runtime/binding/cpp/ten.h" | ||
#include "ten_runtime/binding/cpp/internal/ten_env.h" | ||
#include "ten_utils/lang/cpp/lib/error.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<ten::cmd_t> cmd) override { | ||
if (std::string(cmd->get_name()) == "hello_world") { | ||
hello_world_cmd = std::move(cmd); | ||
|
||
ten::error_t err; | ||
|
||
auto audio_frame_no_dest = | ||
ten::audio_frame_t::create("audio_frame_no_dest"); | ||
bool rc = ten_env.send_audio_frame(std::move(audio_frame_no_dest), &err); | ||
ASSERT_EQ(rc, false); | ||
ASSERT_EQ(err.is_success(), false); | ||
|
||
TEN_ENV_LOG_ERROR(ten_env, err.errmsg()); | ||
|
||
auto audio_frame = ten::audio_frame_t::create("audio_frame"); | ||
rc = ten_env.send_audio_frame(std::move(audio_frame)); | ||
ASSERT_EQ(rc, true); | ||
} else if (std::string(cmd->get_name()) == "audio_frame_ack") { | ||
auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); | ||
cmd_result->set_property("detail", "hello world, too"); | ||
bool rc = ten_env.return_result(std::move(cmd_result), | ||
std::move(hello_world_cmd)); | ||
ASSERT_EQ(rc, true); | ||
} | ||
} | ||
|
||
private: | ||
std::unique_ptr<ten::cmd_t> hello_world_cmd; | ||
}; | ||
|
||
class test_extension_2 : public ten::extension_t { | ||
public: | ||
explicit test_extension_2(const std::string &name) : ten::extension_t(name) {} | ||
|
||
void on_audio_frame( | ||
ten::ten_env_t &ten_env, | ||
std::unique_ptr<ten::audio_frame_t> audio_frame) override { | ||
auto cmd = ten::cmd_t::create("audio_frame_ack"); | ||
ten_env.send_cmd(std::move(cmd)); | ||
} | ||
}; | ||
|
||
class test_app : public ten::app_t { | ||
public: | ||
void on_configure(ten::ten_env_t &ten_env) override { | ||
bool rc = ten_env.init_property_from_json( | ||
// clang-format off | ||
R"({ | ||
"_ten": { | ||
"uri": "msgpack://127.0.0.1:8001/", | ||
"log_level": 2 | ||
} | ||
})" | ||
// clang-format on | ||
, | ||
nullptr); | ||
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(no_audio_frame_dest__test_extension_1, | ||
test_extension_1); | ||
TEN_CPP_REGISTER_ADDON_AS_EXTENSION(no_audio_frame_dest__test_extension_2, | ||
test_extension_2); | ||
|
||
} // namespace | ||
|
||
TEST(ExtensionTest, NoAudioFrameDest) { // 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 graph. | ||
nlohmann::json resp = client->send_json_and_recv_resp_in_json( | ||
R"({ | ||
"_ten": { | ||
"type": "start_graph", | ||
"seq_id": "55", | ||
"nodes": [{ | ||
"type": "extension", | ||
"name": "test_extension_1", | ||
"addon": "no_audio_frame_dest__test_extension_1", | ||
"extension_group": "basic_extension_group", | ||
"app": "msgpack://127.0.0.1:8001/" | ||
},{ | ||
"type": "extension", | ||
"name": "test_extension_2", | ||
"addon": "no_audio_frame_dest__test_extension_2", | ||
"extension_group": "basic_extension_group", | ||
"app": "msgpack://127.0.0.1:8001/" | ||
}], | ||
"connections": [{ | ||
"app": "msgpack://127.0.0.1:8001/", | ||
"extension_group": "basic_extension_group", | ||
"extension": "test_extension_1", | ||
"audio_frame": [{ | ||
"name": "audio_frame", | ||
"dest": [{ | ||
"app": "msgpack://127.0.0.1:8001/", | ||
"extension_group": "basic_extension_group", | ||
"extension": "test_extension_2" | ||
}] | ||
}] | ||
},{ | ||
"app": "msgpack://127.0.0.1:8001/", | ||
"extension_group": "basic_extension_group", | ||
"extension": "test_extension_2", | ||
"cmd": [{ | ||
"name": "audio_frame_ack", | ||
"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); | ||
|
||
// 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"); | ||
|
||
delete client; | ||
|
||
ten_thread_join(app_thread, -1); | ||
} |