-
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.
- Loading branch information
Showing
5 changed files
with
257 additions
and
3 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# | ||
# 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. | ||
# | ||
import("//build/ten_runtime/glob.gni") | ||
import("//build/ten_runtime/ten.gni") | ||
|
||
glob("log") { | ||
file_list = all_native_files | ||
deps = [ | ||
"//third_party/msgpack:msgpackc", | ||
"//third_party/nlohmann_json", | ||
] | ||
include_dirs = [ | ||
"//packages", | ||
"//tests/ten_runtime", | ||
] | ||
public_deps = [ | ||
"//third_party/googlemock", | ||
"//third_party/googletest", | ||
] | ||
} |
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,111 @@ | ||
// | ||
// 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 <nlohmann/json.hpp> | ||
#include <string> | ||
|
||
#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 : public ten::extension_t { | ||
public: | ||
explicit test_extension(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 { | ||
TEN_ENV_LOG_DEBUG(ten_env, | ||
(std::string("on_cmd ") + cmd->get_name()).c_str()); | ||
|
||
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)); | ||
} | ||
} | ||
}; | ||
|
||
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, | ||
"log_file": "aaa/log_file.log" | ||
} | ||
})" | ||
// 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(log_file__test_extension, test_extension); | ||
|
||
} // namespace | ||
|
||
TEST(LogTest, LogFile) { // NOLINT | ||
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", | ||
"addon": "log_file__test_extension", | ||
"extension_group": "test_extension_group", | ||
"app": "msgpack://127.0.0.1:8001/" | ||
}] | ||
} | ||
})"_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": "test_extension_group", | ||
"extension": "test_extension" | ||
}] | ||
} | ||
})"_json); | ||
ten_test::check_result_is(resp, "137", TEN_STATUS_CODE_OK, | ||
"hello world, too"); | ||
|
||
delete client; | ||
|
||
ten_thread_join(app_thread, -1); | ||
} |