加上实时数据和历史数据目标到私有类里

This commit is contained in:
2026-08-11 18:11:28 +08:00
parent 0327d71536
commit c89a678245
15 changed files with 323 additions and 268 deletions
+23 -32
View File
@@ -259,8 +259,8 @@ TEST(RenderiveWebGallery, BackendMenuMapsRetainedControlApis) {
for (const auto mode : modes) {
const auto contract = parse_json(Gallery_Protocol::case_json(
case_id, Gallery_Protocol::default_state(case_id, mode), "{}", {}, mode));
for (const auto& control : contract.at("controls").at("data"))
api_text += control.at("api").get<std::string>() + '\n';
for (const auto& control : contract.at("controls").at("descriptor").at("fields"))
api_text += control.at("presentation").at("description").get<std::string>() + '\n';
for (const auto& action : contract.at("actions").at("data"))
api_text += action.at("api").get<std::string>() + '\n';
}
@@ -497,57 +497,53 @@ TEST(RenderiveWebGallery, EveryPublishedControlAppliesToTheLiveCore2Scene) {
auto state = response_json(session.handle(gallery_request(
Gallery_Request_Kind::Open, open_message(case_id, mode))));
ASSERT_EQ(state.at("type"), "case_state");
const auto published_controls = state.at("controls").at("data");
const auto published_controls = state.at("controls").at("descriptor").at("fields");
for (const auto& published : published_controls) {
++applied_control_instances;
const std::string id = published.at("id");
const std::string id = published.at("name");
SCOPED_TRACE(std::string(case_id) + "/" + std::string(mode) + "/" + id);
const std::string input = published.at("input");
const std::string input = published.at("presentation").at("control");
const auto& current_value = state.at("controls").at("data").at(id);
nlohmann::json alternative;
if (input == "boolean") {
alternative = !published.at("value").get<bool>();
alternative = !current_value.get<bool>();
} else if (input == "number") {
const double minimum = published.at("minimum");
const double maximum = published.at("maximum");
const double current = published.at("value");
const double step = std::max(published.at("step").get<double>(), 1e-9);
const double current = current_value;
const double step = std::max(published.at("multiple_of").get<double>(), 1e-9);
double value = current + step;
if (value > maximum)
value = current - step;
if (value < minimum || value == current)
value = current == minimum ? maximum : minimum;
if (published.at("integer").get<bool>())
const bool integer = published.at("value_type") == "integer";
if (integer)
value = std::round(value);
alternative = value;
alternative = integer ? nlohmann::json(static_cast<std::int64_t>(std::llround(value))) : nlohmann::json(value);
} else if (input == "select") {
const auto& options = published.at("options");
const std::string current = published.at("value");
const auto& options = published.at("presentation").at("options");
const std::string current = current_value;
const auto selected = std::find_if(
options.begin(), options.end(), [&current](const auto& option) {
return option.template get<std::string>() != current;
return option.at("value").template get<std::string>() != current;
});
ASSERT_NE(selected, options.end());
alternative = *selected;
alternative = selected->at("value");
} else if (input == "color") {
alternative = published.at("value") == "#123456" ? "#654321" : "#123456";
alternative = current_value == "#123456" ? "#654321" : "#123456";
} else {
ASSERT_EQ(input, "text");
alternative = published.at("value").get<std::string>() + "_live";
alternative = current_value.get<std::string>() + "_live";
}
nlohmann::json request{{"category", "event"}, {"type", "gallery_patch"},
{"patch", {{id, alternative}}}};
state = response_json(session.handle(gallery_request(
Gallery_Request_Kind::Patch, request.dump())));
ASSERT_EQ(state.at("type"), "case_state");
ASSERT_EQ(state.at("type"), "case_state") << state.dump();
EXPECT_EQ(state.at("frame_mode").at("id").get<std::string>(), mode);
const auto& returned = state.at("controls").at("data");
const auto found = std::find_if(returned.begin(), returned.end(),
[&id](const auto& item) {
return item.at("id") == id;
});
ASSERT_NE(found, returned.end());
EXPECT_EQ(found->at("value"), alternative);
EXPECT_EQ(state.at("controls").at("data").at(id), alternative);
EXPECT_TRUE(state.at("telemetry").contains("kernel_observer"));
}
}
@@ -648,7 +644,7 @@ TEST(RenderiveWebGallery, CommonControlsAndViewLifecycleProduceObservableEffects
"case_state");
const auto background_state = patch_controls(session, {{"background_color", "#123456"}});
EXPECT_EQ(background_state.at("controls").at("data").at(0).at("value"), "#123456");
EXPECT_EQ(background_state.at("controls").at("data").at("background_color"), "#123456");
ASSERT_EQ(invoke_action(session, "mode_cycle").at("type"), "case_state");
const auto background_frame = session.handle(Frame_Request{});
ASSERT_TRUE(background_frame.has_value());
@@ -1443,7 +1439,7 @@ TEST(RenderiveWebGallery, ConstellationLowLatencyPixelsChange) {
expect_low_latency_canvas_to_change("constellation");
}
TEST(RenderiveWebGallery, BuilderOnlyControlsRebuildAndAllImageModesRender) {
TEST(RenderiveWebGallery, PropertyChangesRebuildAndAllImageModesRender) {
Gallery_Plot_Session constellation;
ASSERT_TRUE(constellation.handle(gallery_request(
Gallery_Request_Kind::Open,
@@ -1453,12 +1449,7 @@ TEST(RenderiveWebGallery, BuilderOnlyControlsRebuildAndAllImageModesRender) {
R"({"category":"event","type":"gallery_patch","patch":{"constellation_type":"PSK16","phase_offset":0.75}})"));
ASSERT_TRUE(rebuilt.has_value());
const auto rebuilt_json = parse_json(rebuilt->payload);
const auto& rebuilt_controls = rebuilt_json.at("controls").at("data");
const auto type = std::find_if(rebuilt_controls.begin(), rebuilt_controls.end(), [](const auto& item) {
return item.at("id") == "constellation_type";
});
ASSERT_NE(type, rebuilt_controls.end());
EXPECT_EQ(type->at("value"), "PSK16");
EXPECT_EQ(rebuilt_json.at("controls").at("data").at("constellation_type"), "PSK16");
ASSERT_TRUE(constellation.handle(Frame_Request{}).has_value());
Gallery_Plot_Session waterfall;