-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: read float type property, but int value from json (#350)
- Loading branch information
Showing
21 changed files
with
151 additions
and
29 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
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
File renamed without changes.
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
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
122 changes: 122 additions & 0 deletions
122
tests/ten_runtime/smoke/property/property_get_float64_type_but_int_value.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,122 @@ | ||
// | ||
// 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/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" | ||
|
||
#define PROP_NAME "test_prop" | ||
#define PROP_VAL 123 | ||
|
||
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 { | ||
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); | ||
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 | ||
"{\ | ||
\"type\": \"app\",\ | ||
\"name\": \"test_app\",\ | ||
\"version\": \"1.0.0\",\ | ||
\"api\": {\ | ||
\"property\": {\ | ||
\"" PROP_NAME "\": {\ | ||
\"type\": \"float64\"\ | ||
}\ | ||
}\ | ||
}\ | ||
}" | ||
// clang-format on | ||
); | ||
ASSERT_EQ(rc, true); | ||
|
||
rc = ten_env.init_property_from_json( | ||
"{\ | ||
\"_ten\": {\ | ||
\"uri\": \"msgpack://127.0.0.1:8001/\"},\ | ||
\"" PROP_NAME "\":" TEN_XSTR(PROP_VAL) "}"); | ||
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( | ||
property_get_float64_type_but_int_value__extension, test_extension); | ||
|
||
} // namespace | ||
|
||
TEST(PropertyTest, GetFloat64TypeButIntValue) { // 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. | ||
auto start_graph_cmd = ten::cmd_start_graph_t::create(); | ||
start_graph_cmd->set_graph_from_json(R"({ | ||
"nodes": [{ | ||
"type": "extension", | ||
"name": "test_extension", | ||
"addon": "property_get_float64_type_but_int_value__extension", | ||
"app": "msgpack://127.0.0.1:8001/", | ||
"extension_group": "property_get_float64_type_but_int_value__extension_group" | ||
}] | ||
})"); | ||
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. | ||
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_type_but_int_value__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; | ||
|
||
ten_thread_join(app_thread, -1); | ||
} |
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
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