Compare commits
1 Commits
main
...
test_20260
| Author | SHA1 | Date |
|---|---|---|
|
|
acb6db3931 |
114
src/app.cpp
114
src/app.cpp
|
|
@ -9,10 +9,6 @@
|
|||
// ══════════════════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* @requirement(name="核心引擎初始化", id="REQ-ENGINE-INIT-001")
|
||||
* 构造函数需初始化系统状态上下文,设置默认运行模式为空闲模式,
|
||||
* 并重置自增计数器,为后续业务操作提供初始状态。
|
||||
*
|
||||
* @brief 构造函数,初始化系统状态上下文与自增计数器
|
||||
*/
|
||||
CmsEngine::CmsEngine()
|
||||
|
|
@ -25,11 +21,8 @@ CmsEngine::CmsEngine()
|
|||
}
|
||||
|
||||
/**
|
||||
* @requirement(name="唯一标识生成", id="REQ-UTIL-IDGEN-001")
|
||||
* 系统需支持生成格式为 "ID-xxxxx" 的自增唯一标识,
|
||||
* 用于任务方案、事件等实体的 ID 分配。
|
||||
*
|
||||
* @brief 生成自增唯一标识
|
||||
*
|
||||
* @return std::string 格式如 "ID-00001"
|
||||
*/
|
||||
std::string CmsEngine::generateNextId()
|
||||
|
|
@ -44,11 +37,10 @@ std::string CmsEngine::generateNextId()
|
|||
// ══════════════════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* @requirement(name="战场事件接入", id="REQ-EVENT-INGEST-001")
|
||||
* 系统需支持从外部事件总线接入原始战场事件,执行基本合法性校验
|
||||
* (ID 不能为空、优先级范围检查),通过后存入事件库。
|
||||
*
|
||||
* @brief 接入原始战场事件
|
||||
*
|
||||
* 执行基本合法性校验(ID 不能为空、优先级范围检查),通过后存入事件库。
|
||||
*
|
||||
* @param event 战场事件
|
||||
* @return true 接入成功
|
||||
* @return false 接入失败
|
||||
|
|
@ -66,11 +58,11 @@ bool CmsEngine::ingestEvent(const EventRecord& event)
|
|||
}
|
||||
|
||||
/**
|
||||
* @requirement(name="待处理事件处理", id="REQ-EVENT-PROC-001")
|
||||
* 系统需遍历事件库中所有 Pending 状态的事件,自动将其状态标记为 Generated,
|
||||
* 并据此生成一个对应的 TaskPlan 草案,实现事件到方案的自动转化。
|
||||
*
|
||||
* @brief 处理待处理事件队列
|
||||
*
|
||||
* 遍历事件库中所有 Pending 状态的事件,自动将其状态标记为 Generated,
|
||||
* 并据此生成一个对应的 TaskPlan 草案。
|
||||
*
|
||||
* @return size_t 处理的事件数量
|
||||
*/
|
||||
size_t CmsEngine::processPendingEvents()
|
||||
|
|
@ -98,11 +90,8 @@ size_t CmsEngine::processPendingEvents()
|
|||
}
|
||||
|
||||
/**
|
||||
* @requirement(name="事件查询", id="REQ-EVENT-QUERY-001")
|
||||
* 系统需支持根据事件 ID 在事件库中查找对应的事件记录,
|
||||
* 找到则返回事件指针,未找到返回 nullptr。
|
||||
*
|
||||
* @brief 根据事件 ID 查找事件
|
||||
*
|
||||
* @param eventId 事件标识
|
||||
* @return const EventRecord* 事件指针,未找到返回 nullptr
|
||||
*/
|
||||
|
|
@ -121,11 +110,10 @@ const EventRecord* CmsEngine::findEventById(const std::string& eventId) const
|
|||
// ══════════════════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* @requirement(name="任务方案创建", id="REQ-PLAN-CREATE-001")
|
||||
* 系统需校验方案名称非空后,为其分配系统 ID 并存入方案库,
|
||||
* 确保方案数据的完整性和可追溯性。
|
||||
*
|
||||
* @brief 创建任务方案
|
||||
*
|
||||
* 校验方案名称非空后,为其分配系统 ID 并存入方案库。
|
||||
*
|
||||
* @param plan 待创建方案(id 由系统填充)
|
||||
* @return true 创建成功
|
||||
* @return false 名称不合法
|
||||
|
|
@ -142,10 +130,8 @@ bool CmsEngine::createTaskPlan(TaskPlan& plan)
|
|||
}
|
||||
|
||||
/**
|
||||
* @requirement(name="任务方案列表查询", id="REQ-PLAN-LIST-001")
|
||||
* 系统需返回全部任务方案列表的引用,以支撑方案全局视图展示。
|
||||
*
|
||||
* @brief 获取所有任务方案列表
|
||||
*
|
||||
* @return const std::vector<TaskPlan>& 方案列表
|
||||
*/
|
||||
const std::vector<TaskPlan>& CmsEngine::getAllPlans() const
|
||||
|
|
@ -154,11 +140,8 @@ const std::vector<TaskPlan>& CmsEngine::getAllPlans() const
|
|||
}
|
||||
|
||||
/**
|
||||
* @requirement(name="任务方案查找", id="REQ-PLAN-FIND-001")
|
||||
* 系统需支持根据任务 ID 在方案库中遍历查找对应方案,
|
||||
* 找到返回方案指针,未找到返回 nullptr。
|
||||
*
|
||||
* @brief 根据 ID 查找任务方案
|
||||
*
|
||||
* @param planId 任务标识
|
||||
* @return const TaskPlan* 方案指针,未找到返回 nullptr
|
||||
*/
|
||||
|
|
@ -173,11 +156,8 @@ const TaskPlan* CmsEngine::findPlanById(const std::string& planId) const
|
|||
}
|
||||
|
||||
/**
|
||||
* @requirement(name="任务方案状态更新", id="REQ-PLAN-UPDATE-001")
|
||||
* 系统需支持根据任务 ID 查找方案并更新其状态,返回是否更新成功,
|
||||
* 以驱动方案从草稿到完成的生命周期流转。
|
||||
*
|
||||
* @brief 更新任务方案状态
|
||||
*
|
||||
* @param planId 任务标识
|
||||
* @param newStatus 新状态
|
||||
* @return true 更新成功
|
||||
|
|
@ -199,10 +179,8 @@ bool CmsEngine::updatePlanStatus(const std::string& planId, PlanStatus newStatus
|
|||
// ══════════════════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* @requirement(name="模板注册", id="REQ-TMPL-REG-001")
|
||||
* 系统需支持将模板实例添加到模板库中,为后续场景匹配提供候选模板。
|
||||
*
|
||||
* @brief 注册模板实例
|
||||
*
|
||||
* @param tmpl 模板实例
|
||||
*/
|
||||
void CmsEngine::registerTemplate(const TemplateInstance& tmpl)
|
||||
|
|
@ -211,11 +189,10 @@ void CmsEngine::registerTemplate(const TemplateInstance& tmpl)
|
|||
}
|
||||
|
||||
/**
|
||||
* @requirement(name="模板匹配", id="REQ-TMPL-MATCH-001")
|
||||
* 系统需遍历模板库,返回置信度最高的模板(简单策略:置信度最大者),
|
||||
* 空库时返回 nullptr。
|
||||
*
|
||||
* @brief 根据场景匹配最佳模板
|
||||
*
|
||||
* 遍历模板库,返回置信度最高的模板(简单策略:置信度最大者)。
|
||||
*
|
||||
* @param scenario 场景描述(当前未用于精确匹配,仅做演示)
|
||||
* @return const TemplateInstance* 最佳模板,无匹配返回 nullptr
|
||||
*/
|
||||
|
|
@ -239,11 +216,10 @@ const TemplateInstance* CmsEngine::matchTemplate(const std::string& scenario) co
|
|||
// ══════════════════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* @requirement(name="执行状态上报", id="REQ-MON-REPORT-001")
|
||||
* 系统需将节点遥测数据写入内部状态表,按 nodeId 覆盖更新,
|
||||
* 以维护各节点最新的执行状态。
|
||||
*
|
||||
* @brief 上报节点执行状态
|
||||
*
|
||||
* 将节点遥测数据写入内部状态表,按 nodeId 覆盖更新。
|
||||
*
|
||||
* @param status 执行状态
|
||||
*/
|
||||
void CmsEngine::reportExecutionStatus(const ExecutionStatus& status)
|
||||
|
|
@ -252,11 +228,10 @@ void CmsEngine::reportExecutionStatus(const ExecutionStatus& status)
|
|||
}
|
||||
|
||||
/**
|
||||
* @requirement(name="节点健康检查", id="REQ-MON-HEALTH-001")
|
||||
* 系统需遍历所有节点状态,依据健康指数 < 0.5、异常码 != 0 或
|
||||
* 距最后上报超过 30 秒的判据筛选异常节点,返回异常节点状态列表。
|
||||
*
|
||||
* @brief 检查所有节点健康状态
|
||||
*
|
||||
* 异常判据:健康指数 < 0.5 或异常码 != 0 或心跳超时(距最后上报 > 30秒)。
|
||||
*
|
||||
* @return std::vector<ExecutionStatus> 异常节点列表
|
||||
*/
|
||||
std::vector<ExecutionStatus> CmsEngine::checkHealth() const
|
||||
|
|
@ -293,10 +268,10 @@ std::vector<ExecutionStatus> CmsEngine::checkHealth() const
|
|||
// ══════════════════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* @requirement(name="用户会话创建", id="REQ-SESS-CREATE-001")
|
||||
* 系统需校验 userId 非空且不重复后存入会话表,确保用户会话的唯一性。
|
||||
*
|
||||
* @brief 创建用户会话
|
||||
*
|
||||
* 校验 userId 非空且不重复后存入会话表。
|
||||
*
|
||||
* @param session 用户会话
|
||||
* @return true 创建成功
|
||||
* @return false 用户已存在或 ID 为空
|
||||
|
|
@ -314,11 +289,10 @@ bool CmsEngine::createSession(const UserSession& session)
|
|||
}
|
||||
|
||||
/**
|
||||
* @requirement(name="权限校验", id="REQ-SESS-PERM-001")
|
||||
* 系统需检查用户会话的权限位图是否包含所需的权限掩码,
|
||||
* 通过按位与运算进行判定,以保障系统操作安全。
|
||||
*
|
||||
* @brief 校验用户权限
|
||||
*
|
||||
* 检查用户会话的权限位图是否包含所需的权限掩码。
|
||||
*
|
||||
* @param userId 用户 ID
|
||||
* @param permissionMask 所需权限位掩码
|
||||
* @return true 有权限
|
||||
|
|
@ -339,10 +313,8 @@ bool CmsEngine::checkPermission(const std::string& userId,
|
|||
// ══════════════════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* @requirement(name="通知推送", id="REQ-NOTIF-PUSH-001")
|
||||
* 系统需支持将通知消息添加到消息队列尾部,以支撑系统内实时信息传达。
|
||||
*
|
||||
* @brief 推送通知消息
|
||||
*
|
||||
* @param msg 通知消息
|
||||
*/
|
||||
void CmsEngine::pushNotification(const NotificationMessage& msg)
|
||||
|
|
@ -351,11 +323,8 @@ void CmsEngine::pushNotification(const NotificationMessage& msg)
|
|||
}
|
||||
|
||||
/**
|
||||
* @requirement(name="未读通知查询", id="REQ-NOTIF-UNREAD-001")
|
||||
* 系统需遍历通知队列,筛选出所有未读通知并返回列表,
|
||||
* 以支撑用户快速查看待处理信息。
|
||||
*
|
||||
* @brief 获取所有未读通知
|
||||
*
|
||||
* @return std::vector<NotificationMessage> 未读通知列表
|
||||
*/
|
||||
std::vector<NotificationMessage> CmsEngine::getUnreadNotifications() const
|
||||
|
|
@ -374,11 +343,10 @@ std::vector<NotificationMessage> CmsEngine::getUnreadNotifications() const
|
|||
// ══════════════════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* @requirement(name="运行模式切换", id="REQ-MODE-SWITCH-001")
|
||||
* 系统需支持运行模式切换,降级模式下不允许切换到其他模式(模拟故障隔离策略),
|
||||
* 切换成功后更新时间戳和一致性标记。
|
||||
*
|
||||
* @brief 切换系统运行模式
|
||||
*
|
||||
* 降级模式下不允许切换到其他模式(模拟故障隔离策略),其余模式可自由切换。
|
||||
*
|
||||
* @param newMode 目标模式
|
||||
* @return true 切换成功
|
||||
* @return false 切换被拒绝
|
||||
|
|
@ -396,11 +364,8 @@ bool CmsEngine::switchMode(RunMode newMode)
|
|||
}
|
||||
|
||||
/**
|
||||
* @requirement(name="系统状态查询", id="REQ-MODE-QUERY-001")
|
||||
* 系统需返回当前系统状态上下文的常量引用,包括运行模式、上下文快照、
|
||||
* 一致性标记和切换时间,以支撑状态监控与审计。
|
||||
*
|
||||
* @brief 获取当前系统状态上下文
|
||||
*
|
||||
* @return const SystemStateContext& 状态上下文
|
||||
*/
|
||||
const SystemStateContext& CmsEngine::getSystemContext() const
|
||||
|
|
@ -409,11 +374,8 @@ const SystemStateContext& CmsEngine::getSystemContext() const
|
|||
}
|
||||
|
||||
/**
|
||||
* @requirement(name="引擎摘要生成", id="REQ-SUMM-GEN-001")
|
||||
* 系统需汇总事件数、方案数、模板数、监控节点数、活跃会话数、
|
||||
* 未读通知数和当前运行模式,生成格式化的引擎运行摘要字符串。
|
||||
*
|
||||
* @brief 获取引擎摘要信息
|
||||
*
|
||||
* @return std::string 包含事件数、方案数、节点数、未读通知数等
|
||||
*/
|
||||
std::string CmsEngine::getSummary() const
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
cmake_minimum_required(VERSION 3.10.0)
|
||||
project(test_plan_execute_t1)
|
||||
include(FetchContent)
|
||||
if (MSVC)
|
||||
add_compile_options(/utf-8)
|
||||
endif()
|
||||
FetchContent_Declare(
|
||||
googletest
|
||||
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
|
||||
)
|
||||
# For Windows: Prevent overriding the parent project's compiler/linker settings
|
||||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
||||
FetchContent_MakeAvailable(googletest)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include)
|
||||
|
||||
include(CTest)
|
||||
enable_testing()
|
||||
|
||||
add_executable(test_plan_execute_t1 test_cms_engine.cpp ../src/app.cpp)
|
||||
|
||||
target_link_libraries(test_plan_execute_t1 gtest gmock gtest_main)
|
||||
include(GoogleTest)
|
||||
gtest_discover_tests(test_plan_execute_t1)
|
||||
|
|
@ -0,0 +1,316 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "app.hpp"
|
||||
|
||||
// ============================================================================
|
||||
// Test Fixture for CmsEngine
|
||||
// ============================================================================
|
||||
class CmsEngineTest : public ::testing::Test {
|
||||
protected:
|
||||
CmsEngine engine;
|
||||
|
||||
void SetUp() override {
|
||||
// Initialize with some plans for findPlanById and updatePlanStatus tests
|
||||
TaskPlan plan1;
|
||||
plan1.name = "Plan1";
|
||||
engine.createTaskPlan(plan1);
|
||||
|
||||
TaskPlan plan2;
|
||||
plan2.name = "Plan2";
|
||||
engine.createTaskPlan(plan2);
|
||||
|
||||
// Register a template for registerTemplate tests
|
||||
TemplateInstance tmpl;
|
||||
tmpl.templateId = "TMPL-001";
|
||||
tmpl.confidence = 0.8;
|
||||
engine.registerTemplate(tmpl);
|
||||
}
|
||||
|
||||
// Helper to get the first plan's ID
|
||||
std::string getFirstPlanId() const {
|
||||
const auto& plans = engine.getAllPlans();
|
||||
if (!plans.empty()) {
|
||||
return plans[0].id;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
// Helper to get the second plan's ID
|
||||
std::string getSecondPlanId() const {
|
||||
const auto& plans = engine.getAllPlans();
|
||||
if (plans.size() > 1) {
|
||||
return plans[1].id;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Tests for findPlanById
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* @test 正常输入测试 - 查找存在的方案
|
||||
* @description 使用有效的 planId 查找已存在的方案,应返回正确的方案指针
|
||||
*/
|
||||
TEST_F(CmsEngineTest, testFindPlanByIdExistingPlan) {
|
||||
std::string planId = getFirstPlanId();
|
||||
ASSERT_FALSE(planId.empty()) << "Plan ID should not be empty";
|
||||
|
||||
const TaskPlan* result = engine.findPlanById(planId);
|
||||
ASSERT_NE(result, nullptr) << "Should find the existing plan";
|
||||
EXPECT_EQ(result->id, planId) << "Plan ID should match";
|
||||
EXPECT_EQ(result->name, "Plan1") << "Plan name should match";
|
||||
}
|
||||
|
||||
/**
|
||||
* @test 边界值测试 - 查找不存在的方案
|
||||
* @description 使用不存在的 planId 查找方案,应返回 nullptr
|
||||
*/
|
||||
TEST_F(CmsEngineTest, testFindPlanByIdNonExistingPlan) {
|
||||
const std::string nonExistingId = "ID-99999";
|
||||
const TaskPlan* result = engine.findPlanById(nonExistingId);
|
||||
EXPECT_EQ(result, nullptr) << "Should return nullptr for non-existing plan";
|
||||
}
|
||||
|
||||
/**
|
||||
* @test 边界值测试 - 查找空字符串 ID
|
||||
* @description 使用空字符串作为 planId 查找方案,应返回 nullptr
|
||||
*/
|
||||
TEST_F(CmsEngineTest, testFindPlanByIdEmptyId) {
|
||||
const std::string emptyId = "";
|
||||
const TaskPlan* result = engine.findPlanById(emptyId);
|
||||
EXPECT_EQ(result, nullptr) << "Should return nullptr for empty ID";
|
||||
}
|
||||
|
||||
/**
|
||||
* @test 特殊场景测试 - 查找多个方案中的特定方案
|
||||
* @description 在多个方案中查找第二个方案,应返回正确的方案
|
||||
*/
|
||||
TEST_F(CmsEngineTest, testFindPlanByIdSecondPlan) {
|
||||
std::string planId = getSecondPlanId();
|
||||
ASSERT_FALSE(planId.empty()) << "Second plan ID should not be empty";
|
||||
|
||||
const TaskPlan* result = engine.findPlanById(planId);
|
||||
ASSERT_NE(result, nullptr) << "Should find the second plan";
|
||||
EXPECT_EQ(result->id, planId) << "Plan ID should match";
|
||||
EXPECT_EQ(result->name, "Plan2") << "Plan name should match";
|
||||
}
|
||||
|
||||
/**
|
||||
* @test 异常输入测试 - 查找特殊字符 ID
|
||||
* @description 使用包含特殊字符的 planId 查找方案,应返回 nullptr
|
||||
*/
|
||||
TEST_F(CmsEngineTest, testFindPlanByIdSpecialChars) {
|
||||
const std::string specialId = "!@#$%^&*()";
|
||||
const TaskPlan* result = engine.findPlanById(specialId);
|
||||
EXPECT_EQ(result, nullptr) << "Should return nullptr for special character ID";
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Tests for updatePlanStatus
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* @test 正常输入测试 - 更新方案状态
|
||||
* @description 使用有效的 planId 更新方案状态,应返回 true 并更新状态
|
||||
*/
|
||||
TEST_F(CmsEngineTest, testUpdatePlanStatusSuccess) {
|
||||
std::string planId = getFirstPlanId();
|
||||
ASSERT_FALSE(planId.empty()) << "Plan ID should not be empty";
|
||||
|
||||
PlanStatus newStatus = PlanStatus::Approved;
|
||||
bool result = engine.updatePlanStatus(planId, newStatus);
|
||||
EXPECT_TRUE(result) << "Should return true for successful update";
|
||||
|
||||
// Verify the status was updated
|
||||
const TaskPlan* updatedPlan = engine.findPlanById(planId);
|
||||
ASSERT_NE(updatedPlan, nullptr) << "Plan should still exist";
|
||||
EXPECT_EQ(updatedPlan->status, newStatus) << "Plan status should be updated";
|
||||
}
|
||||
|
||||
/**
|
||||
* @test 边界值测试 - 更新不存在的方案状态
|
||||
* @description 使用不存在的 planId 更新方案状态,应返回 false
|
||||
*/
|
||||
TEST_F(CmsEngineTest, testUpdatePlanStatusNonExistingPlan) {
|
||||
const std::string nonExistingId = "ID-99999";
|
||||
bool result = engine.updatePlanStatus(nonExistingId, PlanStatus::Approved);
|
||||
EXPECT_FALSE(result) << "Should return false for non-existing plan";
|
||||
}
|
||||
|
||||
/**
|
||||
* @test 边界值测试 - 更新空字符串 ID 的方案状态
|
||||
* @description 使用空字符串作为 planId 更新方案状态,应返回 false
|
||||
*/
|
||||
TEST_F(CmsEngineTest, testUpdatePlanStatusEmptyId) {
|
||||
const std::string emptyId = "";
|
||||
bool result = engine.updatePlanStatus(emptyId, PlanStatus::Approved);
|
||||
EXPECT_FALSE(result) << "Should return false for empty ID";
|
||||
}
|
||||
|
||||
/**
|
||||
* @test 特殊场景测试 - 更新方案状态为 Drafting
|
||||
* @description 更新方案状态为 Drafting,应返回 true 并更新状态
|
||||
*/
|
||||
TEST_F(CmsEngineTest, testUpdatePlanStatusToDrafting) {
|
||||
std::string planId = getFirstPlanId();
|
||||
ASSERT_FALSE(planId.empty()) << "Plan ID should not be empty";
|
||||
|
||||
bool result = engine.updatePlanStatus(planId, PlanStatus::Drafting);
|
||||
EXPECT_TRUE(result) << "Should return true for successful update";
|
||||
|
||||
const TaskPlan* updatedPlan = engine.findPlanById(planId);
|
||||
ASSERT_NE(updatedPlan, nullptr) << "Plan should still exist";
|
||||
EXPECT_EQ(updatedPlan->status, PlanStatus::Drafting) << "Plan status should be Drafting";
|
||||
}
|
||||
|
||||
/**
|
||||
* @test 特殊场景测试 - 多次更新方案状态
|
||||
* @description 连续多次更新同一方案的状态,应每次返回 true 并更新状态
|
||||
*/
|
||||
TEST_F(CmsEngineTest, testUpdatePlanStatusMultipleTimes) {
|
||||
std::string planId = getFirstPlanId();
|
||||
ASSERT_FALSE(planId.empty()) << "Plan ID should not be empty";
|
||||
|
||||
// First update
|
||||
bool result1 = engine.updatePlanStatus(planId, PlanStatus::Approved);
|
||||
EXPECT_TRUE(result1) << "First update should succeed";
|
||||
|
||||
// Second update
|
||||
bool result2 = engine.updatePlanStatus(planId, PlanStatus::Executing);
|
||||
EXPECT_TRUE(result2) << "Second update should succeed";
|
||||
|
||||
// Third update
|
||||
bool result3 = engine.updatePlanStatus(planId, PlanStatus::Completed);
|
||||
EXPECT_TRUE(result3) << "Third update should succeed";
|
||||
|
||||
// Verify final status
|
||||
const TaskPlan* updatedPlan = engine.findPlanById(planId);
|
||||
ASSERT_NE(updatedPlan, nullptr) << "Plan should still exist";
|
||||
EXPECT_EQ(updatedPlan->status, PlanStatus::Completed) << "Plan status should be Completed";
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Tests for registerTemplate
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* @test 正常输入测试 - 注册模板
|
||||
* @description 注册一个有效的模板实例,应成功添加
|
||||
*/
|
||||
TEST_F(CmsEngineTest, testRegisterTemplateSuccess) {
|
||||
TemplateInstance tmpl;
|
||||
tmpl.templateId = "TMPL-002";
|
||||
tmpl.confidence = 0.9;
|
||||
|
||||
engine.registerTemplate(tmpl);
|
||||
|
||||
// Verify the template was registered by matching
|
||||
const TemplateInstance* matched = engine.matchTemplate("test_scenario");
|
||||
ASSERT_NE(matched, nullptr) << "Should find a template after registration";
|
||||
EXPECT_EQ(matched->templateId, "TMPL-002") << "Should match the newly registered template";
|
||||
EXPECT_EQ(matched->confidence, 0.9) << "Confidence should match";
|
||||
}
|
||||
|
||||
/**
|
||||
* @test 边界值测试 - 注册空 ID 模板
|
||||
* @description 注册一个 templateId 为空的模板实例,应成功添加(允许空 ID)
|
||||
*/
|
||||
TEST_F(CmsEngineTest, testRegisterTemplateEmptyId) {
|
||||
TemplateInstance tmpl;
|
||||
tmpl.templateId = "";
|
||||
tmpl.confidence = 0.5;
|
||||
|
||||
engine.registerTemplate(tmpl);
|
||||
|
||||
// Verify the template was registered
|
||||
const TemplateInstance* matched = engine.matchTemplate("test_scenario");
|
||||
ASSERT_NE(matched, nullptr) << "Should find a template after registration";
|
||||
EXPECT_EQ(matched->templateId, "") << "Template ID should be empty";
|
||||
}
|
||||
|
||||
/**
|
||||
* @test 边界值测试 - 注册零置信度模板
|
||||
* @description 注册一个置信度为 0 的模板实例,应成功添加
|
||||
*/
|
||||
TEST_F(CmsEngineTest, testRegisterTemplateZeroConfidence) {
|
||||
TemplateInstance tmpl;
|
||||
tmpl.templateId = "TMPL-003";
|
||||
tmpl.confidence = 0.0;
|
||||
|
||||
engine.registerTemplate(tmpl);
|
||||
|
||||
// Verify the template was registered
|
||||
const TemplateInstance* matched = engine.matchTemplate("test_scenario");
|
||||
ASSERT_NE(matched, nullptr) << "Should find a template after registration";
|
||||
EXPECT_EQ(matched->confidence, 0.0) << "Confidence should be 0.0";
|
||||
}
|
||||
|
||||
/**
|
||||
* @test 特殊场景测试 - 注册多个模板
|
||||
* @description 注册多个模板实例,应全部成功添加
|
||||
*/
|
||||
TEST_F(CmsEngineTest, testRegisterTemplateMultiple) {
|
||||
TemplateInstance tmpl1;
|
||||
tmpl1.templateId = "TMPL-004";
|
||||
tmpl1.confidence = 0.7;
|
||||
|
||||
TemplateInstance tmpl2;
|
||||
tmpl2.templateId = "TMPL-005";
|
||||
tmpl2.confidence = 0.9;
|
||||
|
||||
TemplateInstance tmpl3;
|
||||
tmpl3.templateId = "TMPL-006";
|
||||
tmpl3.confidence = 0.5;
|
||||
|
||||
engine.registerTemplate(tmpl1);
|
||||
engine.registerTemplate(tmpl2);
|
||||
engine.registerTemplate(tmpl3);
|
||||
|
||||
// Verify the best template is the one with highest confidence
|
||||
const TemplateInstance* matched = engine.matchTemplate("test_scenario");
|
||||
ASSERT_NE(matched, nullptr) << "Should find a template after registration";
|
||||
EXPECT_EQ(matched->templateId, "TMPL-005") << "Should match the template with highest confidence";
|
||||
EXPECT_EQ(matched->confidence, 0.9) << "Confidence should be 0.9";
|
||||
}
|
||||
|
||||
/**
|
||||
* @test 特殊场景测试 - 注册相同 ID 的模板
|
||||
* @description 注册两个 templateId 相同的模板实例,应都成功添加
|
||||
*/
|
||||
TEST_F(CmsEngineTest, testRegisterTemplateDuplicateId) {
|
||||
TemplateInstance tmpl1;
|
||||
tmpl1.templateId = "TMPL-007";
|
||||
tmpl1.confidence = 0.6;
|
||||
|
||||
TemplateInstance tmpl2;
|
||||
tmpl2.templateId = "TMPL-007";
|
||||
tmpl2.confidence = 0.8;
|
||||
|
||||
engine.registerTemplate(tmpl1);
|
||||
engine.registerTemplate(tmpl2);
|
||||
|
||||
// Verify both templates are registered and the one with higher confidence is matched
|
||||
const TemplateInstance* matched = engine.matchTemplate("test_scenario");
|
||||
ASSERT_NE(matched, nullptr) << "Should find a template after registration";
|
||||
EXPECT_EQ(matched->confidence, 0.8) << "Should match the template with higher confidence";
|
||||
}
|
||||
|
||||
/**
|
||||
* @test 异常输入测试 - 注册后立即匹配
|
||||
* @description 注册一个模板后立即匹配,应返回刚注册的模板
|
||||
*/
|
||||
TEST_F(CmsEngineTest, testRegisterTemplateAndMatchImmediately) {
|
||||
TemplateInstance tmpl;
|
||||
tmpl.templateId = "TMPL-008";
|
||||
tmpl.confidence = 1.0;
|
||||
|
||||
engine.registerTemplate(tmpl);
|
||||
|
||||
const TemplateInstance* matched = engine.matchTemplate("any_scenario");
|
||||
ASSERT_NE(matched, nullptr) << "Should find a template immediately after registration";
|
||||
EXPECT_EQ(matched->templateId, "TMPL-008") << "Should match the just registered template";
|
||||
EXPECT_EQ(matched->confidence, 1.0) << "Confidence should be 1.0";
|
||||
}
|
||||
Loading…
Reference in New Issue