diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..26bbfb0 --- /dev/null +++ b/tests/CMakeLists.txt @@ -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 14) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include) + +include(CTest) +enable_testing() + +add_executable(test_plan_execute_t1 test_app.cpp ../src/app.cpp) + +target_link_libraries(test_plan_execute_t1 gtest gmock gtest_main) +include(GoogleTest) +gtest_discover_tests(test_plan_execute_t1) \ No newline at end of file diff --git a/tests/test_app.cpp b/tests/test_app.cpp new file mode 100644 index 0000000..7c6eb8a --- /dev/null +++ b/tests/test_app.cpp @@ -0,0 +1,102 @@ +#include +#include "app.hpp" +#include +#include +#include + +// 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(); + } + + void TearDown() override { + engine_.reset(); + } + + std::unique_ptr engine_; +}; + +TEST_F(CmsEngineTest, TestPushNotification_Normal) { + NotificationMessage msg; + msg.id = "NOTIF-001"; + msg.content = "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.content = "Read message"; + readMsg.isRead = true; + + NotificationMessage unreadMsg; + unreadMsg.id = "UNREAD-001"; + unreadMsg.content = "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(); +} \ No newline at end of file