|
|
|
|
@ -0,0 +1,372 @@
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
#include "alert_manager.hpp"
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
// Mock the global functions to avoid side effects
|
|
|
|
|
namespace {
|
|
|
|
|
std::string g_output_buffer;
|
|
|
|
|
void mock_cout(const std::string& msg) {
|
|
|
|
|
g_output_buffer += msg + "\n";
|
|
|
|
|
}
|
|
|
|
|
void mock_cerr(const std::string& msg) {
|
|
|
|
|
g_output_buffer += msg + "\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Replace std::cout and std::cerr with mocks
|
|
|
|
|
#define cout g_output_buffer
|
|
|
|
|
#define cerr g_output_buffer
|
|
|
|
|
|
|
|
|
|
// Mock time function for deterministic testing
|
|
|
|
|
static uint32_t mock_time = 1000;
|
|
|
|
|
uint32_t get_mock_time() { return mock_time; }
|
|
|
|
|
|
|
|
|
|
// Override std::time to use mock_time
|
|
|
|
|
extern "C" {
|
|
|
|
|
time_t time(time_t* tloc) {
|
|
|
|
|
if (tloc) *tloc = mock_time;
|
|
|
|
|
return mock_time;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test fixture for AlertManager
|
|
|
|
|
class AlertManagerTest : public ::testing::Test {
|
|
|
|
|
protected:
|
|
|
|
|
AlertManager alert_manager;
|
|
|
|
|
|
|
|
|
|
void SetUp() override {
|
|
|
|
|
g_output_buffer.clear();
|
|
|
|
|
mock_time = 1000;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TearDown() override {
|
|
|
|
|
// Reset state
|
|
|
|
|
alert_manager.resetAllAlerts();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Test case: AlertManager constructor
|
|
|
|
|
TEST_F(AlertManagerTest, testAlertManagerConstructorNormalInput) {
|
|
|
|
|
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 destructor
|
|
|
|
|
TEST_F(AlertManagerTest, testAlertManagerDestructorNormalInput) {
|
|
|
|
|
// No specific behavior expected, just ensure no crash
|
|
|
|
|
// Destructor is tested implicitly by scope
|
|
|
|
|
EXPECT_NO_FATAL_FAILURE({});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test case: initialize
|
|
|
|
|
TEST_F(AlertManagerTest, testInitializeNormalInput) {
|
|
|
|
|
alert_manager.initialize();
|
|
|
|
|
EXPECT_NE(g_output_buffer.find("预警管理器初始化完成"), std::string::npos);
|
|
|
|
|
EXPECT_NE(g_output_buffer.find("默认预警阈值:上限=100米,下限=-50米"), std::string::npos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test case: checkAltitudeAlert - normal altitude
|
|
|
|
|
TEST_F(AlertManagerTest, testCheckAltitudeAlertNormalInput) {
|
|
|
|
|
alert_manager.checkAltitudeAlert(50.0f, 1000);
|
|
|
|
|
EXPECT_TRUE(alert_manager.getActiveAlerts().empty());
|
|
|
|
|
EXPECT_FALSE(g_output_buffer.find("高度超过上限阈值") != std::string::npos);
|
|
|
|
|
EXPECT_FALSE(g_output_buffer.find("高度低于下限阈值") != std::string::npos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test case: checkAltitudeAlert - upper threshold exceeded
|
|
|
|
|
TEST_F(AlertManagerTest, testCheckAltitudeAlertUpperThresholdExceeded) {
|
|
|
|
|
alert_manager.checkAltitudeAlert(101.0f, 1000);
|
|
|
|
|
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);
|
|
|
|
|
EXPECT_NE(g_output_buffer.find("高度超过上限阈值"), std::string::npos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test case: checkAltitudeAlert - lower threshold exceeded
|
|
|
|
|
TEST_F(AlertManagerTest, testCheckAltitudeAlertLowerThresholdExceeded) {
|
|
|
|
|
alert_manager.checkAltitudeAlert(-51.0f, 1000);
|
|
|
|
|
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);
|
|
|
|
|
EXPECT_NE(g_output_buffer.find("高度低于下限阈值"), std::string::npos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test case: checkAltitudeAlert - recovery from upper threshold
|
|
|
|
|
TEST_F(AlertManagerTest, testCheckAltitudeAlertRecoveryFromUpperThreshold) {
|
|
|
|
|
alert_manager.checkAltitudeAlert(101.0f, 1000);
|
|
|
|
|
alert_manager.checkAltitudeAlert(99.0f, 1001);
|
|
|
|
|
auto active_alerts = alert_manager.getActiveAlerts();
|
|
|
|
|
EXPECT_TRUE(active_alerts.empty());
|
|
|
|
|
EXPECT_NE(g_output_buffer.find("预警已解决: 高度上限预警"), std::string::npos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test case: checkAltitudeAlert - recovery from lower threshold
|
|
|
|
|
TEST_F(AlertManagerTest, testCheckAltitudeAlertRecoveryFromLowerThreshold) {
|
|
|
|
|
alert_manager.checkAltitudeAlert(-51.0f, 1000);
|
|
|
|
|
alert_manager.checkAltitudeAlert(-49.0f, 1001);
|
|
|
|
|
auto active_alerts = alert_manager.getActiveAlerts();
|
|
|
|
|
EXPECT_TRUE(active_alerts.empty());
|
|
|
|
|
EXPECT_NE(g_output_buffer.find("预警已解决: 高度下限预警"), std::string::npos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test case: setAltitudeThresholds - valid thresholds
|
|
|
|
|
TEST_F(AlertManagerTest, testSetAltitudeThresholdsValidInput) {
|
|
|
|
|
alert_manager.setAltitudeThresholds(200.0f, -100.0f);
|
|
|
|
|
EXPECT_FLOAT_EQ(alert_manager.getAltitudeThresholds().first, 200.0f);
|
|
|
|
|
EXPECT_FLOAT_EQ(alert_manager.getAltitudeThresholds().second, -100.0f);
|
|
|
|
|
EXPECT_NE(g_output_buffer.find("预警阈值已更新"), std::string::npos);
|
|
|
|
|
EXPECT_TRUE(alert_manager.getActiveAlerts().empty());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test case: setAltitudeThresholds - invalid thresholds
|
|
|
|
|
TEST_F(AlertManagerTest, testSetAltitudeThresholdsInvalidInput) {
|
|
|
|
|
alert_manager.setAltitudeThresholds(50.0f, 100.0f);
|
|
|
|
|
EXPECT_NE(g_output_buffer.find("错误:上限阈值必须大于下限阈值。"), std::string::npos);
|
|
|
|
|
EXPECT_FLOAT_EQ(alert_manager.getAltitudeThresholds().first, 100.0f);
|
|
|
|
|
EXPECT_FLOAT_EQ(alert_manager.getAltitudeThresholds().second, -50.0f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test case: triggerSensorFailure
|
|
|
|
|
TEST_F(AlertManagerTest, testTriggerSensorFailureNormalInput) {
|
|
|
|
|
alert_manager.triggerSensorFailure(1000);
|
|
|
|
|
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].status, AlertStatus::ACTIVE);
|
|
|
|
|
EXPECT_NE(g_output_buffer.find("传感器故障"), std::string::npos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test case: triggerLowBattery
|
|
|
|
|
TEST_F(AlertManagerTest, testTriggerLowBatteryNormalInput) {
|
|
|
|
|
alert_manager.triggerLowBattery(1000, 15.5f);
|
|
|
|
|
auto active_alerts = alert_manager.getActiveAlerts();
|
|
|
|
|
EXPECT_EQ(active_alerts.size(), 1);
|
|
|
|
|
EXPECT_EQ(active_alerts[0].type, AlertType::LOW_BATTERY);
|
|
|
|
|
EXPECT_EQ(active_alerts[0].status, AlertStatus::ACTIVE);
|
|
|
|
|
EXPECT_NE(g_output_buffer.find("低电量警告:当前电量15.5%"), std::string::npos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test case: triggerCommunicationError
|
|
|
|
|
TEST_F(AlertManagerTest, testTriggerCommunicationErrorNormalInput) {
|
|
|
|
|
alert_manager.triggerCommunicationError(1000);
|
|
|
|
|
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].status, AlertStatus::ACTIVE);
|
|
|
|
|
EXPECT_NE(g_output_buffer.find("通信错误"), std::string::npos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test case: acknowledgeAllAlerts
|
|
|
|
|
TEST_F(AlertManagerTest, testAcknowledgeAllAlertsNormalInput) {
|
|
|
|
|
alert_manager.triggerSensorFailure(1000);
|
|
|
|
|
alert_manager.triggerLowBattery(1001, 10.0f);
|
|
|
|
|
alert_manager.acknowledgeAllAlerts(1002);
|
|
|
|
|
auto active_alerts = alert_manager.getActiveAlerts();
|
|
|
|
|
EXPECT_TRUE(active_alerts.empty());
|
|
|
|
|
EXPECT_NE(g_output_buffer.find("预警已确认: 传感器故障"), std::string::npos);
|
|
|
|
|
EXPECT_NE(g_output_buffer.find("预警已确认: 低电量预警"), std::string::npos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test case: acknowledgeAlert - valid type
|
|
|
|
|
TEST_F(AlertManagerTest, testAcknowledgeAlertValidType) {
|
|
|
|
|
alert_manager.triggerSensorFailure(1000);
|
|
|
|
|
alert_manager.acknowledgeAlert(AlertType::SENSOR_FAILURE, 1001);
|
|
|
|
|
auto active_alerts = alert_manager.getActiveAlerts();
|
|
|
|
|
EXPECT_TRUE(active_alerts.empty());
|
|
|
|
|
EXPECT_NE(g_output_buffer.find("预警已确认: 传感器故障"), std::string::npos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test case: acknowledgeAlert - invalid type
|
|
|
|
|
TEST_F(AlertManagerTest, testAcknowledgeAlertInvalidType) {
|
|
|
|
|
alert_manager.acknowledgeAlert(AlertType::NONE, 1000);
|
|
|
|
|
EXPECT_TRUE(alert_manager.getActiveAlerts().empty());
|
|
|
|
|
EXPECT_TRUE(g_output_buffer.empty());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test case: resetAlert - active alert
|
|
|
|
|
TEST_F(AlertManagerTest, testResetAlertActiveAlert) {
|
|
|
|
|
alert_manager.triggerSensorFailure(1000);
|
|
|
|
|
alert_manager.resetAlert(AlertType::SENSOR_FAILURE);
|
|
|
|
|
auto active_alerts = alert_manager.getActiveAlerts();
|
|
|
|
|
EXPECT_TRUE(active_alerts.empty());
|
|
|
|
|
EXPECT_NE(g_output_buffer.find("预警已解决: 传感器故障"), std::string::npos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test case: resetAlert - inactive alert
|
|
|
|
|
TEST_F(AlertManagerTest, testResetAlertInactiveAlert) {
|
|
|
|
|
alert_manager.resetAlert(AlertType::SENSOR_FAILURE);
|
|
|
|
|
EXPECT_TRUE(alert_manager.getActiveAlerts().empty());
|
|
|
|
|
EXPECT_TRUE(g_output_buffer.empty());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test case: resetAllAlerts
|
|
|
|
|
TEST_F(AlertManagerTest, testResetAllAlertsNormalInput) {
|
|
|
|
|
alert_manager.triggerSensorFailure(1000);
|
|
|
|
|
alert_manager.triggerLowBattery(1001, 10.0f);
|
|
|
|
|
alert_manager.resetAllAlerts();
|
|
|
|
|
EXPECT_TRUE(alert_manager.getActiveAlerts().empty());
|
|
|
|
|
EXPECT_NE(g_output_buffer.find("所有预警已重置。"), std::string::npos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test case: hasActiveAlerts - no alerts
|
|
|
|
|
TEST_F(AlertManagerTest, testHasActiveAlertsNoAlerts) {
|
|
|
|
|
EXPECT_FALSE(alert_manager.hasActiveAlerts());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test case: hasActiveAlerts - with active alerts
|
|
|
|
|
TEST_F(AlertManagerTest, testHasActiveAlertsWithActiveAlerts) {
|
|
|
|
|
alert_manager.triggerSensorFailure(1000);
|
|
|
|
|
EXPECT_TRUE(alert_manager.hasActiveAlerts());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test case: hasUnacknowledgedAlerts - no unacknowledged alerts
|
|
|
|
|
TEST_F(AlertManagerTest, testHasUnacknowledgedAlertsNoUnacknowledgedAlerts) {
|
|
|
|
|
alert_manager.triggerSensorFailure(1000);
|
|
|
|
|
alert_manager.acknowledgeAllAlerts(1001);
|
|
|
|
|
EXPECT_FALSE(alert_manager.hasUnacknowledgedAlerts());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test case: hasUnacknowledgedAlerts - with unacknowledged alerts
|
|
|
|
|
TEST_F(AlertManagerTest, testHasUnacknowledgedAlertsWithUnacknowledgedAlerts) {
|
|
|
|
|
alert_manager.triggerSensorFailure(1000);
|
|
|
|
|
EXPECT_TRUE(alert_manager.hasUnacknowledgedAlerts());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test case: getActiveAlerts - empty
|
|
|
|
|
TEST_F(AlertManagerTest, testGetActiveAlertsEmpty) {
|
|
|
|
|
auto alerts = alert_manager.getActiveAlerts();
|
|
|
|
|
EXPECT_TRUE(alerts.empty());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test case: getActiveAlerts - non-empty
|
|
|
|
|
TEST_F(AlertManagerTest, testGetActiveAlertsNonEmpty) {
|
|
|
|
|
alert_manager.triggerSensorFailure(1000);
|
|
|
|
|
auto alerts = alert_manager.getActiveAlerts();
|
|
|
|
|
EXPECT_EQ(alerts.size(), 1);
|
|
|
|
|
EXPECT_EQ(alerts[0].type, AlertType::SENSOR_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test case: getAlertHistory - max_count larger than history size
|
|
|
|
|
TEST_F(AlertManagerTest, testGetAlertHistoryMaxCountLargerThanHistorySize) {
|
|
|
|
|
alert_manager.triggerSensorFailure(1000);
|
|
|
|
|
alert_manager.triggerLowBattery(1001, 10.0f);
|
|
|
|
|
auto history = alert_manager.getAlertHistory(10);
|
|
|
|
|
EXPECT_EQ(history.size(), 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test case: getAlertHistory - max_count smaller than history size
|
|
|
|
|
TEST_F(AlertManagerTest, testGetAlertHistoryMaxCountSmallerThanHistorySize) {
|
|
|
|
|
alert_manager.triggerSensorFailure(1000);
|
|
|
|
|
alert_manager.triggerLowBattery(1001, 10.0f);
|
|
|
|
|
alert_manager.triggerCommunicationError(1002);
|
|
|
|
|
auto history = alert_manager.getAlertHistory(2);
|
|
|
|
|
EXPECT_EQ(history.size(), 2);
|
|
|
|
|
EXPECT_EQ(history[0].type, AlertType::COMMUNICATION_ERROR);
|
|
|
|
|
EXPECT_EQ(history[1].type, AlertType::LOW_BATTERY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test case: getStatusDescription - no active alerts
|
|
|
|
|
TEST_F(AlertManagerTest, testGetStatusDescriptionNoActiveAlerts) {
|
|
|
|
|
std::string desc = alert_manager.getStatusDescription();
|
|
|
|
|
EXPECT_EQ(desc, "系统状态:正常");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test case: getStatusDescription - with active alerts
|
|
|
|
|
TEST_F(AlertManagerTest, testGetStatusDescriptionWithActiveAlerts) {
|
|
|
|
|
alert_manager.triggerSensorFailure(1000);
|
|
|
|
|
alert_manager.triggerLowBattery(1001, 10.0f);
|
|
|
|
|
std::string desc = alert_manager.getStatusDescription();
|
|
|
|
|
EXPECT_NE(desc.find("系统状态:有2个活动预警"), std::string::npos);
|
|
|
|
|
EXPECT_NE(desc.find("传感器故障") != std::string::npos);
|
|
|
|
|
EXPECT_NE(desc.find("低电量预警") != std::string::npos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test case: clearHistory
|
|
|
|
|
TEST_F(AlertManagerTest, testClearHistoryNormalInput) {
|
|
|
|
|
alert_manager.triggerSensorFailure(1000);
|
|
|
|
|
alert_manager.clearHistory();
|
|
|
|
|
EXPECT_TRUE(alert_manager.getAlertHistory(10).empty());
|
|
|
|
|
EXPECT_NE(g_output_buffer.find("预警历史记录已清空。"), std::string::npos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test case: addToHistory - within limit
|
|
|
|
|
TEST_F(AlertManagerTest, testAddToHistoryWithinLimit) {
|
|
|
|
|
AlertInfo alert;
|
|
|
|
|
alert.type = AlertType::SENSOR_FAILURE;
|
|
|
|
|
alert.status = AlertStatus::ACTIVE;
|
|
|
|
|
alert.trigger_time = 1000;
|
|
|
|
|
alert.description = "Test alert";
|
|
|
|
|
alert_manager.addToHistory(alert);
|
|
|
|
|
auto history = alert_manager.getAlertHistory(10);
|
|
|
|
|
EXPECT_EQ(history.size(), 1);
|
|
|
|
|
EXPECT_EQ(history[0].type, AlertType::SENSOR_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test case: addToHistory - exceeding limit
|
|
|
|
|
TEST_F(AlertManagerTest, testAddToHistoryExceedingLimit) {
|
|
|
|
|
const int MAX_HISTORY = 5;
|
|
|
|
|
for (int i = 0; i < MAX_HISTORY + 1; ++i) {
|
|
|
|
|
AlertInfo alert;
|
|
|
|
|
alert.type = AlertType::SENSOR_FAILURE;
|
|
|
|
|
alert.status = AlertStatus::ACTIVE;
|
|
|
|
|
alert.trigger_time = 1000 + i;
|
|
|
|
|
alert.description = "Test alert";
|
|
|
|
|
alert_manager.addToHistory(alert);
|
|
|
|
|
}
|
|
|
|
|
auto history = alert_manager.getAlertHistory(10);
|
|
|
|
|
EXPECT_EQ(history.size(), MAX_HISTORY);
|
|
|
|
|
EXPECT_EQ(history[0].trigger_time, 1001);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test case: triggerAlert - basic functionality
|
|
|
|
|
TEST_F(AlertManagerTest, testTriggerAlertBasicFunctionality) {
|
|
|
|
|
alert_manager.triggerAlert(AlertType::SENSOR_FAILURE, 1000, "Test alert");
|
|
|
|
|
auto active_alerts = alert_manager.getActiveAlerts();
|
|
|
|
|
EXPECT_EQ(active_alerts.size(), 1);
|
|
|
|
|
EXPECT_EQ(active_alerts[0].description, "Test alert");
|
|
|
|
|
EXPECT_NE(g_output_buffer.find("[预警] 传感器故障: Test alert"), std::string::npos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test case: updateAlertStatus - acknowledged
|
|
|
|
|
TEST_F(AlertManagerTest, testUpdateAlertStatusAcknowledged) {
|
|
|
|
|
alert_manager.triggerSensorFailure(1000);
|
|
|
|
|
alert_manager.updateAlertStatus(AlertType::SENSOR_FAILURE, AlertStatus::ACKNOWLEDGED, 1001);
|
|
|
|
|
auto active_alerts = alert_manager.getActiveAlerts();
|
|
|
|
|
EXPECT_TRUE(active_alerts.empty());
|
|
|
|
|
EXPECT_NE(g_output_buffer.find("预警已确认: 传感器故障"), std::string::npos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test case: updateAlertStatus - resolved
|
|
|
|
|
TEST_F(AlertManagerTest, testUpdateAlertStatusResolved) {
|
|
|
|
|
alert_manager.triggerSensorFailure(1000);
|
|
|
|
|
alert_manager.updateAlertStatus(AlertType::SENSOR_FAILURE, AlertStatus::RESOLVED, 1001);
|
|
|
|
|
auto active_alerts = alert_manager.getActiveAlerts();
|
|
|
|
|
EXPECT_TRUE(active_alerts.empty());
|
|
|
|
|
EXPECT_NE(g_output_buffer.find("预警已解决: 传感器故障"), std::string::npos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test case: getAlertTypeName - known types
|
|
|
|
|
TEST_F(AlertManagerTest, testGetAlertTypeNameKnownTypes) {
|
|
|
|
|
EXPECT_EQ(alert_manager.getAlertTypeName(AlertType::ALTITUDE_UPPER), "高度上限预警");
|
|
|
|
|
EXPECT_EQ(alert_manager.getAlertTypeName(AlertType::SENSOR_FAILURE), "传感器故障");
|
|
|
|
|
EXPECT_EQ(alert_manager.getAlertTypeName(AlertType::NONE), "无");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test case: getAlertStatusName - known statuses
|
|
|
|
|
TEST_F(AlertManagerTest, testGetAlertStatusNameKnownStatuses) {
|
|
|
|
|
EXPECT_EQ(alert_manager.getAlertStatusName(AlertStatus::ACTIVE), "预警中");
|
|
|
|
|
EXPECT_EQ(alert_manager.getAlertStatusName(AlertStatus::ACKNOWLEDGED), "已确认");
|
|
|
|
|
EXPECT_EQ(alert_manager.getAlertStatusName(AlertStatus::RESOLVED), "已解决");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test case: getAltitudeThresholds - getter method
|
|
|
|
|
TEST_F(AlertManagerTest, testGetAltitudeThresholdsGetterMethod) {
|
|
|
|
|
auto thresholds = alert_manager.getAltitudeThresholds();
|
|
|
|
|
EXPECT_FLOAT_EQ(thresholds.first, 100.0f);
|
|
|
|
|
EXPECT_FLOAT_EQ(thresholds.second, -50.0f);
|
|
|
|
|
}
|