2026-04-20 03:19:33 +00:00
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
#include "alert_manager.hpp"
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
2026-04-28 08:58:57 +00:00
|
|
|
|
// Mock time function for deterministic testing
|
|
|
|
|
|
uint32_t mock_timestamp = 1640995200; // 2022-01-01 00:00:00 UTC
|
2026-04-20 03:19:33 +00:00
|
|
|
|
|
2026-04-28 08:58:57 +00:00
|
|
|
|
// Mock the time function
|
|
|
|
|
|
uint32_t get_mock_timestamp() {
|
|
|
|
|
|
return mock_timestamp;
|
|
|
|
|
|
}
|
2026-04-20 03:19:33 +00:00
|
|
|
|
|
2026-04-28 08:58:57 +00:00
|
|
|
|
// Override the global time function in alert_manager.cpp
|
|
|
|
|
|
extern "C" uint32_t std_time(nullptr) {
|
|
|
|
|
|
return mock_timestamp;
|
2026-04-20 03:19:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-28 08:58:57 +00:00
|
|
|
|
// Test fixture for AlertManager
|
2026-04-20 03:19:33 +00:00
|
|
|
|
class AlertManagerTest : public ::testing::Test {
|
|
|
|
|
|
protected:
|
2026-04-28 08:58:57 +00:00
|
|
|
|
AlertManager alert_manager;
|
2026-04-20 03:19:33 +00:00
|
|
|
|
|
|
|
|
|
|
void SetUp() override {
|
|
|
|
|
|
mock_timestamp = 1640995200;
|
2026-04-28 08:58:57 +00:00
|
|
|
|
alert_manager.initialize();
|
2026-04-20 03:19:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TearDown() override {
|
2026-04-28 08:58:57 +00:00
|
|
|
|
alert_manager.resetAllAlerts();
|
2026-04-20 03:19:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2026-04-28 08:58:57 +00:00
|
|
|
|
// Test case: AlertManager 构造函数初始化默认阈值
|
|
|
|
|
|
TEST_F(AlertManagerTest, testAlertManagerConstructorDefaultThresholds) {
|
|
|
|
|
|
EXPECT_FLOAT_EQ(alert_manager.getAltitudeThresholds().first, 100.0f);
|
|
|
|
|
|
EXPECT_FLOAT_EQ(alert_manager.getAltitudeThresholds().second, -50.0f);
|
|
|
|
|
|
EXPECT_TRUE(alert_manager.getActiveAlerts().empty());
|
|
|
|
|
|
EXPECT_TRUE(alert_manager.getAlertHistory(10).empty());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Test case: AlertManager 析构函数无副作用
|
|
|
|
|
|
TEST_F(AlertManagerTest, testAlertManagerDestructorNoSideEffects) {
|
|
|
|
|
|
// Destructor should not throw or cause undefined behavior
|
|
|
|
|
|
// Simply verify it can be called without issues
|
|
|
|
|
|
AlertManager temp_manager;
|
|
|
|
|
|
// No assertion needed as destructor is trivial
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Test case: initialize 输出初始化信息
|
|
|
|
|
|
TEST_F(AlertManagerTest, testInitializeOutputInfo) {
|
|
|
|
|
|
// Capture output
|
|
|
|
|
|
testing::internal::CaptureStdout();
|
|
|
|
|
|
alert_manager.initialize();
|
|
|
|
|
|
std::string output = testing::internal::GetCapturedStdout();
|
|
|
|
|
|
EXPECT_NE(output.find("预警管理器初始化完成。"), std::string::npos);
|
|
|
|
|
|
EXPECT_NE(output.find("默认预警阈值:上限=100米,下限=-50米"), std::string::npos);
|
2026-04-20 03:19:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-28 08:58:57 +00:00
|
|
|
|
// Test case: checkAltitudeAlert 高度正常时无预警
|
|
|
|
|
|
TEST_F(AlertManagerTest, testCheckAltitudeAlertNormalHeight) {
|
|
|
|
|
|
alert_manager.checkAltitudeAlert(50.0f, get_mock_timestamp());
|
|
|
|
|
|
EXPECT_FALSE(alert_manager.hasActiveAlerts());
|
2026-04-20 03:19:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-28 08:58:57 +00:00
|
|
|
|
// Test case: checkAltitudeAlert 超过上限触发预警
|
|
|
|
|
|
TEST_F(AlertManagerTest, testCheckAltitudeAlertUpperThresholdTrigger) {
|
|
|
|
|
|
alert_manager.checkAltitudeAlert(101.0f, get_mock_timestamp());
|
|
|
|
|
|
auto active_alerts = alert_manager.getActiveAlerts();
|
|
|
|
|
|
EXPECT_EQ(active_alerts.size(), 1);
|
|
|
|
|
|
EXPECT_EQ(active_alerts[0].type, AlertType::ALTITUDE_UPPER);
|
|
|
|
|
|
EXPECT_EQ(active_alerts[0].status, AlertStatus::ACTIVE);
|
2026-04-20 03:19:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-28 08:58:57 +00:00
|
|
|
|
// Test case: checkAltitudeAlert 低于下限触发预警
|
|
|
|
|
|
TEST_F(AlertManagerTest, testCheckAltitudeAlertLowerThresholdTrigger) {
|
|
|
|
|
|
alert_manager.checkAltitudeAlert(-51.0f, get_mock_timestamp());
|
|
|
|
|
|
auto active_alerts = alert_manager.getActiveAlerts();
|
|
|
|
|
|
EXPECT_EQ(active_alerts.size(), 1);
|
|
|
|
|
|
EXPECT_EQ(active_alerts[0].type, AlertType::ALTITUDE_LOWER);
|
|
|
|
|
|
EXPECT_EQ(active_alerts[0].status, AlertStatus::ACTIVE);
|
2026-04-20 03:19:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-28 08:58:57 +00:00
|
|
|
|
// Test case: checkAltitudeAlert 上限恢复正常解除预警
|
|
|
|
|
|
TEST_F(AlertManagerTest, testCheckAltitudeAlertUpperThresholdResolve) {
|
|
|
|
|
|
alert_manager.checkAltitudeAlert(101.0f, get_mock_timestamp());
|
|
|
|
|
|
alert_manager.checkAltitudeAlert(99.0f, get_mock_timestamp());
|
|
|
|
|
|
EXPECT_FALSE(alert_manager.hasActiveAlerts());
|
2026-04-20 03:19:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-28 08:58:57 +00:00
|
|
|
|
// Test case: checkAltitudeAlert 下限恢复正常解除预警
|
|
|
|
|
|
TEST_F(AlertManagerTest, testCheckAltitudeAlertLowerThresholdResolve) {
|
|
|
|
|
|
alert_manager.checkAltitudeAlert(-51.0f, get_mock_timestamp());
|
|
|
|
|
|
alert_manager.checkAltitudeAlert(-49.0f, get_mock_timestamp());
|
|
|
|
|
|
EXPECT_FALSE(alert_manager.hasActiveAlerts());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Test case: setAltitudeThresholds 合法输入更新阈值
|
|
|
|
|
|
TEST_F(AlertManagerTest, testSetAltitudeThresholdsValidInput) {
|
|
|
|
|
|
alert_manager.setAltitudeThresholds(200.0f, -100.0f);
|
|
|
|
|
|
auto thresholds = alert_manager.getAltitudeThresholds();
|
2026-04-20 03:19:33 +00:00
|
|
|
|
EXPECT_FLOAT_EQ(thresholds.first, 200.0f);
|
|
|
|
|
|
EXPECT_FLOAT_EQ(thresholds.second, -100.0f);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-28 08:58:57 +00:00
|
|
|
|
// Test case: setAltitudeThresholds 非法输入(上限 <= 下限)
|
|
|
|
|
|
TEST_F(AlertManagerTest, testSetAltitudeThresholdsInvalidInput) {
|
|
|
|
|
|
// Capture stderr
|
|
|
|
|
|
testing::internal::CaptureStderr();
|
|
|
|
|
|
alert_manager.setAltitudeThresholds(50.0f, 100.0f);
|
|
|
|
|
|
std::string error_output = testing::internal::GetCapturedStderr();
|
|
|
|
|
|
EXPECT_NE(error_output.find("错误:上限阈值必须大于下限阈值。"), std::string::npos);
|
2026-04-20 03:19:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-28 08:58:57 +00:00
|
|
|
|
// Test case: triggerSensorFailure 触发传感器故障预警
|
2026-04-20 03:19:33 +00:00
|
|
|
|
TEST_F(AlertManagerTest, testTriggerSensorFailure) {
|
2026-04-28 08:58:57 +00:00
|
|
|
|
alert_manager.triggerSensorFailure(get_mock_timestamp());
|
|
|
|
|
|
auto active_alerts = alert_manager.getActiveAlerts();
|
|
|
|
|
|
EXPECT_EQ(active_alerts.size(), 1);
|
|
|
|
|
|
EXPECT_EQ(active_alerts[0].type, AlertType::SENSOR_FAILURE);
|
|
|
|
|
|
EXPECT_EQ(active_alerts[0].description, "传感器故障");
|
2026-04-20 03:19:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-28 08:58:57 +00:00
|
|
|
|
// Test case: triggerLowBattery 触发低电量预警
|
2026-04-20 03:19:33 +00:00
|
|
|
|
TEST_F(AlertManagerTest, testTriggerLowBattery) {
|
2026-04-28 08:58:57 +00:00
|
|
|
|
alert_manager.triggerLowBattery(get_mock_timestamp(), 15.5f);
|
|
|
|
|
|
auto active_alerts = alert_manager.getActiveAlerts();
|
|
|
|
|
|
EXPECT_EQ(active_alerts.size(), 1);
|
|
|
|
|
|
EXPECT_EQ(active_alerts[0].type, AlertType::LOW_BATTERY);
|
|
|
|
|
|
EXPECT_NE(active_alerts[0].description.find("低电量警告:当前电量15.5%"), std::string::npos);
|
2026-04-20 03:19:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-28 08:58:57 +00:00
|
|
|
|
// Test case: triggerCommunicationError 触发通信错误预警
|
2026-04-20 03:19:33 +00:00
|
|
|
|
TEST_F(AlertManagerTest, testTriggerCommunicationError) {
|
2026-04-28 08:58:57 +00:00
|
|
|
|
alert_manager.triggerCommunicationError(get_mock_timestamp());
|
|
|
|
|
|
auto active_alerts = alert_manager.getActiveAlerts();
|
|
|
|
|
|
EXPECT_EQ(active_alerts.size(), 1);
|
|
|
|
|
|
EXPECT_EQ(active_alerts[0].type, AlertType::COMMUNICATION_ERROR);
|
|
|
|
|
|
EXPECT_EQ(active_alerts[0].description, "通信错误");
|
2026-04-20 03:19:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-28 08:58:57 +00:00
|
|
|
|
// Test case: acknowledgeAllAlerts 确认所有活动预警
|
2026-04-20 03:19:33 +00:00
|
|
|
|
TEST_F(AlertManagerTest, testAcknowledgeAllAlerts) {
|
2026-04-28 08:58:57 +00:00
|
|
|
|
alert_manager.triggerSensorFailure(get_mock_timestamp());
|
|
|
|
|
|
alert_manager.triggerLowBattery(get_mock_timestamp(), 10.0f);
|
|
|
|
|
|
alert_manager.acknowledgeAllAlerts(get_mock_timestamp());
|
|
|
|
|
|
auto active_alerts = alert_manager.getActiveAlerts();
|
|
|
|
|
|
EXPECT_TRUE(active_alerts.empty());
|
|
|
|
|
|
EXPECT_TRUE(alert_manager.hasUnacknowledgedAlerts());
|
2026-04-20 03:19:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-28 08:58:57 +00:00
|
|
|
|
// Test case: acknowledgeAlert 确认指定类型预警
|
|
|
|
|
|
TEST_F(AlertManagerTest, testAcknowledgeAlertSpecificType) {
|
|
|
|
|
|
alert_manager.triggerSensorFailure(get_mock_timestamp());
|
|
|
|
|
|
alert_manager.acknowledgeAlert(AlertType::SENSOR_FAILURE, get_mock_timestamp());
|
|
|
|
|
|
auto active_alerts = alert_manager.getActiveAlerts();
|
|
|
|
|
|
EXPECT_TRUE(active_alerts.empty());
|
2026-04-20 03:19:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-28 08:58:57 +00:00
|
|
|
|
// Test case: resetAlert 重置指定类型预警
|
2026-04-20 03:19:33 +00:00
|
|
|
|
TEST_F(AlertManagerTest, testResetAlert) {
|
2026-04-28 08:58:57 +00:00
|
|
|
|
alert_manager.triggerSensorFailure(get_mock_timestamp());
|
|
|
|
|
|
alert_manager.resetAlert(AlertType::SENSOR_FAILURE);
|
|
|
|
|
|
EXPECT_FALSE(alert_manager.hasActiveAlerts());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Test case: resetAllAlerts 清除所有活动预警
|
|
|
|
|
|
TEST_F(AlertManagerTest, testResetAllAlertsClearAll) {
|
|
|
|
|
|
alert_manager.triggerSensorFailure(get_mock_timestamp());
|
|
|
|
|
|
alert_manager.triggerLowBattery(get_mock_timestamp(), 10.0f);
|
|
|
|
|
|
alert_manager.resetAllAlerts();
|
|
|
|
|
|
EXPECT_FALSE(alert_manager.hasActiveAlerts());
|
|
|
|
|
|
EXPECT_TRUE(alert_manager.getAlertHistory(10).size() >= 2);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Test case: hasActiveAlerts 检查是否存在活动预警
|
|
|
|
|
|
TEST_F(AlertManagerTest, testHasActiveAlertsWhenNoAlerts) {
|
|
|
|
|
|
EXPECT_FALSE(alert_manager.hasActiveAlerts());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Test case: hasActiveAlerts 检查存在活动预警
|
|
|
|
|
|
TEST_F(AlertManagerTest, testHasActiveAlertsWhenAlertsExist) {
|
|
|
|
|
|
alert_manager.triggerSensorFailure(get_mock_timestamp());
|
|
|
|
|
|
EXPECT_TRUE(alert_manager.hasActiveAlerts());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Test case: hasUnacknowledgedAlerts 检查未确认预警
|
|
|
|
|
|
TEST_F(AlertManagerTest, testHasUnacknowledgedAlertsWhenActive) {
|
|
|
|
|
|
alert_manager.triggerSensorFailure(get_mock_timestamp());
|
|
|
|
|
|
EXPECT_TRUE(alert_manager.hasUnacknowledgedAlerts());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Test case: hasUnacknowledgedAlerts 检查已确认预警
|
|
|
|
|
|
TEST_F(AlertManagerTest, testHasUnacknowledgedAlertsWhenAcknowledged) {
|
|
|
|
|
|
alert_manager.triggerSensorFailure(get_mock_timestamp());
|
|
|
|
|
|
alert_manager.acknowledgeAlert(AlertType::SENSOR_FAILURE, get_mock_timestamp());
|
|
|
|
|
|
EXPECT_FALSE(alert_manager.hasUnacknowledgedAlerts());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Test case: getActiveAlerts 返回活动预警列表
|
|
|
|
|
|
TEST_F(AlertManagerTest, testGetActiveAlertsReturnsCorrectList) {
|
|
|
|
|
|
alert_manager.triggerSensorFailure(get_mock_timestamp());
|
|
|
|
|
|
alert_manager.triggerLowBattery(get_mock_timestamp(), 10.0f);
|
|
|
|
|
|
auto alerts = alert_manager.getActiveAlerts();
|
|
|
|
|
|
EXPECT_EQ(alerts.size(), 2);
|
2026-04-20 03:19:33 +00:00
|
|
|
|
EXPECT_EQ(alerts[0].type, AlertType::SENSOR_FAILURE);
|
2026-04-28 08:58:57 +00:00
|
|
|
|
EXPECT_EQ(alerts[1].type, AlertType::LOW_BATTERY);
|
2026-04-20 03:19:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-28 08:58:57 +00:00
|
|
|
|
// Test case: getAlertHistory 获取最近历史记录
|
2026-04-20 03:19:33 +00:00
|
|
|
|
TEST_F(AlertManagerTest, testGetAlertHistoryMaxCount) {
|
2026-04-28 08:58:57 +00:00
|
|
|
|
// Add multiple alerts
|
|
|
|
|
|
for (int i = 0; i < 5; ++i) {
|
|
|
|
|
|
alert_manager.triggerSensorFailure(get_mock_timestamp() + i);
|
2026-04-20 03:19:33 +00:00
|
|
|
|
}
|
2026-04-28 08:58:57 +00:00
|
|
|
|
auto history = alert_manager.getAlertHistory(3);
|
|
|
|
|
|
EXPECT_EQ(history.size(), 3);
|
|
|
|
|
|
EXPECT_EQ(history[0].trigger_time, get_mock_timestamp() + 4);
|
2026-04-20 03:19:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-28 08:58:57 +00:00
|
|
|
|
// Test case: getStatusDescription 生成系统状态描述
|
|
|
|
|
|
TEST_F(AlertManagerTest, testGetStatusDescriptionWithActiveAlerts) {
|
|
|
|
|
|
alert_manager.triggerSensorFailure(get_mock_timestamp());
|
|
|
|
|
|
std::string status = alert_manager.getStatusDescription();
|
|
|
|
|
|
EXPECT_NE(status.find("有1个活动预警"), std::string::npos);
|
|
|
|
|
|
EXPECT_NE(status.find("传感器故障"), std::string::npos);
|
2026-04-20 03:19:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-28 08:58:57 +00:00
|
|
|
|
// Test case: getStatusDescription 生成系统正常状态描述
|
|
|
|
|
|
TEST_F(AlertManagerTest, testGetStatusDescriptionNormalState) {
|
|
|
|
|
|
std::string status = alert_manager.getStatusDescription();
|
|
|
|
|
|
EXPECT_EQ(status, "系统状态:正常");
|
2026-04-20 03:19:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-28 08:58:57 +00:00
|
|
|
|
// Test case: clearHistory 清空历史记录
|
|
|
|
|
|
TEST_F(AlertManagerTest, testClearHistoryClearsAll) {
|
|
|
|
|
|
alert_manager.triggerSensorFailure(get_mock_timestamp());
|
|
|
|
|
|
alert_manager.clearHistory();
|
|
|
|
|
|
EXPECT_TRUE(alert_manager.getAlertHistory(10).empty());
|
2026-04-20 03:19:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-28 08:58:57 +00:00
|
|
|
|
// Test case: addToHistory 添加预警到历史记录并限制数量
|
|
|
|
|
|
TEST_F(AlertManagerTest, testAddToHistoryLimitSize) {
|
|
|
|
|
|
const size_t max_history = 5;
|
|
|
|
|
|
// Simulate adding more than max_history entries
|
|
|
|
|
|
for (int i = 0; i < max_history + 2; ++i) {
|
|
|
|
|
|
AlertInfo alert;
|
|
|
|
|
|
alert.type = AlertType::SENSOR_FAILURE;
|
|
|
|
|
|
alert.status = AlertStatus::ACTIVE;
|
|
|
|
|
|
alert.trigger_time = get_mock_timestamp() + i;
|
|
|
|
|
|
alert.description = "Test alert";
|
|
|
|
|
|
alert_manager.addToHistory(alert);
|
2026-04-20 03:19:33 +00:00
|
|
|
|
}
|
2026-04-28 08:58:57 +00:00
|
|
|
|
auto history = alert_manager.getAlertHistory(max_history);
|
|
|
|
|
|
EXPECT_EQ(history.size(), max_history);
|
|
|
|
|
|
EXPECT_EQ(history[0].trigger_time, get_mock_timestamp() + max_history + 1);
|
2026-04-20 03:19:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-28 08:58:57 +00:00
|
|
|
|
// Test case: triggerAlert 内部方法触发新预警
|
|
|
|
|
|
TEST_F(AlertManagerTest, testTriggerAlertInternalMethod) {
|
|
|
|
|
|
alert_manager.triggerAlert(AlertType::ALTITUDE_UPPER, get_mock_timestamp(), "Test description");
|
|
|
|
|
|
auto active_alerts = alert_manager.getActiveAlerts();
|
|
|
|
|
|
EXPECT_EQ(active_alerts.size(), 1);
|
|
|
|
|
|
EXPECT_EQ(active_alerts[0].type, AlertType::ALTITUDE_UPPER);
|
|
|
|
|
|
EXPECT_EQ(active_alerts[0].description, "Test description");
|
2026-04-20 03:19:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-28 08:58:57 +00:00
|
|
|
|
// Test case: updateAlertStatus 更新预警状态为已确认
|
|
|
|
|
|
TEST_F(AlertManagerTest, testUpdateAlertStatusAcknowledge) {
|
|
|
|
|
|
alert_manager.triggerSensorFailure(get_mock_timestamp());
|
|
|
|
|
|
alert_manager.updateAlertStatus(AlertType::SENSOR_FAILURE, AlertStatus::ACKNOWLEDGED, get_mock_timestamp());
|
|
|
|
|
|
auto active_alerts = alert_manager.getActiveAlerts();
|
|
|
|
|
|
EXPECT_TRUE(active_alerts.empty());
|
2026-04-20 03:19:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-28 08:58:57 +00:00
|
|
|
|
// Test case: updateAlertStatus 更新预警状态为已解决
|
|
|
|
|
|
TEST_F(AlertManagerTest, testUpdateAlertStatusResolve) {
|
|
|
|
|
|
alert_manager.triggerSensorFailure(get_mock_timestamp());
|
|
|
|
|
|
alert_manager.updateAlertStatus(AlertType::SENSOR_FAILURE, AlertStatus::RESOLVED, get_mock_timestamp());
|
|
|
|
|
|
auto active_alerts = alert_manager.getActiveAlerts();
|
|
|
|
|
|
EXPECT_TRUE(active_alerts.empty());
|
2026-04-20 03:19:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-28 08:58:57 +00:00
|
|
|
|
// Test case: getAlertTypeName 返回正确名称
|
2026-04-20 03:19:33 +00:00
|
|
|
|
TEST_F(AlertManagerTest, testGetAlertTypeName) {
|
2026-04-28 08:58:57 +00:00
|
|
|
|
EXPECT_EQ(AlertManager::getAlertTypeName(AlertType::ALTITUDE_UPPER), "高度上限预警");
|
|
|
|
|
|
EXPECT_EQ(AlertManager::getAlertTypeName(AlertType::UNKNOWN), "未知预警");
|
2026-04-20 03:19:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-28 08:58:57 +00:00
|
|
|
|
// Test case: getAlertStatusName 返回正确状态名
|
2026-04-20 03:19:33 +00:00
|
|
|
|
TEST_F(AlertManagerTest, testGetAlertStatusName) {
|
2026-04-28 08:58:57 +00:00
|
|
|
|
EXPECT_EQ(AlertManager::getAlertStatusName(AlertStatus::ACTIVE), "预警中");
|
|
|
|
|
|
EXPECT_EQ(AlertManager::getAlertStatusName(AlertStatus::UNKNOWN), "未知状态");
|
2026-04-20 03:19:33 +00:00
|
|
|
|
}
|