|
|
|
|
@ -0,0 +1,102 @@
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
#include "app.hpp"
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <chrono>
|
|
|
|
|
|
|
|
|
|
// Mock classes to support testing if needed, or use direct access if public
|
|
|
|
|
// Since CmsEngine is likely in a namespace or header, we assume app.hpp provides the interface
|
|
|
|
|
|
|
|
|
|
class CmsEngineTest : public ::testing::Test {
|
|
|
|
|
protected:
|
|
|
|
|
void SetUp() override {
|
|
|
|
|
engine_ = std::make_unique<CmsEngine>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TearDown() override {
|
|
|
|
|
engine_.reset();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<CmsEngine> engine_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TEST_F(CmsEngineTest, TestPushNotification_Normal) {
|
|
|
|
|
NotificationMessage msg;
|
|
|
|
|
msg.id = "NOTIF-001";
|
|
|
|
|
msg.summary = "Test notification";
|
|
|
|
|
msg.isRead = false;
|
|
|
|
|
|
|
|
|
|
EXPECT_NO_THROW(engine_->pushNotification(msg));
|
|
|
|
|
|
|
|
|
|
auto unread = engine_->getUnreadNotifications();
|
|
|
|
|
EXPECT_EQ(unread.size(), 1);
|
|
|
|
|
EXPECT_EQ(unread[0].id, "NOTIF-001");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CmsEngineTest, TestGetUnreadNotifications_Empty) {
|
|
|
|
|
auto unread = engine_->getUnreadNotifications();
|
|
|
|
|
EXPECT_TRUE(unread.empty());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CmsEngineTest, TestGetUnreadNotifications_Mixed) {
|
|
|
|
|
NotificationMessage readMsg;
|
|
|
|
|
readMsg.id = "READ-001";
|
|
|
|
|
readMsg.summary = "Read message";
|
|
|
|
|
readMsg.isRead = true;
|
|
|
|
|
|
|
|
|
|
NotificationMessage unreadMsg;
|
|
|
|
|
unreadMsg.id = "UNREAD-001";
|
|
|
|
|
unreadMsg.summary = "Unread message";
|
|
|
|
|
unreadMsg.isRead = false;
|
|
|
|
|
|
|
|
|
|
engine_->pushNotification(readMsg);
|
|
|
|
|
engine_->pushNotification(unreadMsg);
|
|
|
|
|
|
|
|
|
|
auto unread = engine_->getUnreadNotifications();
|
|
|
|
|
EXPECT_EQ(unread.size(), 1);
|
|
|
|
|
EXPECT_EQ(unread[0].id, "UNREAD-001");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CmsEngineTest, TestSwitchMode_Success) {
|
|
|
|
|
EXPECT_TRUE(engine_->switchMode(RunMode::AutoExec));
|
|
|
|
|
|
|
|
|
|
auto context = engine_->getSystemContext();
|
|
|
|
|
EXPECT_EQ(context.currentMode, RunMode::AutoExec);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CmsEngineTest, TestSwitchMode_DegradedRestriction) {
|
|
|
|
|
engine_->switchMode(RunMode::Degraded);
|
|
|
|
|
|
|
|
|
|
// Should fail to switch out of degraded mode
|
|
|
|
|
EXPECT_FALSE(engine_->switchMode(RunMode::Idle));
|
|
|
|
|
|
|
|
|
|
auto context = engine_->getSystemContext();
|
|
|
|
|
EXPECT_EQ(context.currentMode, RunMode::Degraded);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CmsEngineTest, TestGetSystemContext_Valid) {
|
|
|
|
|
engine_->switchMode(RunMode::HumanLoop);
|
|
|
|
|
|
|
|
|
|
auto context = engine_->getSystemContext();
|
|
|
|
|
EXPECT_EQ(context.currentMode, RunMode::HumanLoop);
|
|
|
|
|
EXPECT_NE(context.switchTime.time_since_epoch(), std::chrono::seconds(0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CmsEngineTest, TestGetSummary_Format) {
|
|
|
|
|
engine_->switchMode(RunMode::AutoExec);
|
|
|
|
|
|
|
|
|
|
std::string summary = engine_->getSummary();
|
|
|
|
|
|
|
|
|
|
EXPECT_NE(summary.find("Events"), std::string::npos);
|
|
|
|
|
EXPECT_NE(summary.find("Plans"), std::string::npos);
|
|
|
|
|
EXPECT_NE(summary.find("Templates"), std::string::npos);
|
|
|
|
|
EXPECT_NE(summary.find("Monitor Nodes"), std::string::npos);
|
|
|
|
|
EXPECT_NE(summary.find("Active Sessions"), std::string::npos);
|
|
|
|
|
EXPECT_NE(summary.find("Notifications"), std::string::npos);
|
|
|
|
|
EXPECT_NE(summary.find("AutoExec"), std::string::npos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
|
::testing::InitGoogleTest(&argc, argv);
|
|
|
|
|
return RUN_ALL_TESTS();
|
|
|
|
|
}
|