This commit is contained in:
2026-08-10 22:26:10 +07:00
parent 4a6b541773
commit ec11dc42ed
9 changed files with 724 additions and 9 deletions

View File

@@ -79,19 +79,70 @@ protected:
// ── Đường nạp bình thường ────────────────────────────────────────────────────────────────────────
TEST_F(PluginRegistryTest, LoadsBothSourcesFromConfig)
TEST_F(PluginRegistryTest, LoadsEverySourceFromConfig)
{
PluginRegistry registry;
ASSERT_TRUE(registry.loadFromConfig(nh))
<< "could not load the plugin — check PNKX_NAV_CORE_CONFIG_DIR and devel/lib";
EXPECT_EQ(registry.size(), 2u);
EXPECT_EQ(registry.size(), 3u);
EXPECT_NE(registry.find(schema::kPoseStamped), nullptr);
EXPECT_NE(registry.find(schema::kVda5050Order), nullptr);
EXPECT_NE(registry.find(schema::kInstantAction), nullptr);
EXPECT_EQ(registry.find("does.not.exist"), nullptr);
}
TEST_F(PluginRegistryTest, TwoAliasesInOneLibraryLoadAsTwoAdapters)
{
// VDA5050SourceAdapter và InstantActionSourceAdapter là hai BOOST_DLL_ALIAS trong CÙNG một
// libmission_adapters_vda5050_source.so — cố ý, để hai adapter dùng chung một bản bộ nở compound
// action thay vì có hai bản trôi lệch nhau.
//
// Test này khoá chính cơ chế đó: `library_path` giống hệt nhau ở hai entry phải cho ra hai
// adapter riêng biệt với hai schema riêng biệt. Nếu loader gộp theo library thay vì theo symbol,
// một trong hai schema sẽ biến mất và đường vào tương ứng chết lặng.
PluginRegistry registry;
ASSERT_TRUE(registry.loadFromConfig(nh));
auto* order_adapter = registry.find(schema::kVda5050Order);
auto* instant_adapter = registry.find(schema::kInstantAction);
ASSERT_NE(order_adapter, nullptr);
ASSERT_NE(instant_adapter, nullptr);
EXPECT_NE(order_adapter, instant_adapter) << "hai alias phải là hai instance, không phải một";
EXPECT_EQ(order_adapter->schema(), std::string(schema::kVda5050Order));
EXPECT_EQ(instant_adapter->schema(), std::string(schema::kInstantAction));
}
TEST_F(PluginRegistryTest, TheInstantAdapterLoadedFromDiskExpandsCompoundActions)
{
// Không chỉ nạp được: adapter nạp qua Boost.DLL phải thật sự thấy bảng compound của nguồn order.
// `compound_actions_from` được đọc trong configure(), và configure() chạy bên trong
// loadFromConfig() — nên đây là chỗ duy nhất kiểm được cả chuỗi nạp + cấu hình + dùng chung bảng.
PluginRegistry registry;
ASSERT_TRUE(registry.loadFromConfig(nh));
auto* adapter = registry.find(schema::kInstantAction);
ASSERT_NE(adapter, nullptr);
robot_protocol_msgs::Action action;
action.actionType = "UnDockFromStation";
action.actionId = "undock_1";
action.blockingType = "HARD";
const auto request = MissionRequest::fromInstantAction(action);
std::string reason;
ASSERT_TRUE(adapter->validate(request, reason)) << reason;
const auto result = adapter->convert(request);
ASSERT_EQ(result.missions.size(), 1u);
EXPECT_EQ(result.missions.front()->motion_hint, "go_straight")
<< "nở được nghĩa là bảng compound của vda5050_src đã tới được adapter này";
EXPECT_DOUBLE_EQ(result.missions.front()->relative_distance, -1.0);
}
TEST_F(PluginRegistryTest, LoadedAdapterConvertsRealPayload)
{
PluginRegistry registry;