From 6ebee4ef16cf7367e5cf23013e73841270d19e85 Mon Sep 17 00:00:00 2001 From: Parvathi Date: Tue, 19 Nov 2024 15:25:25 +0530 Subject: [PATCH] edit --- Tests/unittest/test_connectivity.cpp | 34 ++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/Tests/unittest/test_connectivity.cpp b/Tests/unittest/test_connectivity.cpp index d6c28d6b..f0878301 100644 --- a/Tests/unittest/test_connectivity.cpp +++ b/Tests/unittest/test_connectivity.cpp @@ -45,19 +45,33 @@ TEST_F(ConnectivityMonitorTest, StartContinuousMonitor_FailureNegativeTimeout) { bool result = cm.startContinuousConnectivityMonitor(timeout); EXPECT_TRUE(result); } -TEST_F(ConnectivityMonitorTest, StartContinuousMonitor_LowTimeout) { - int timeout = NMCONNECTIVITY_MONITOR_MIN_INTERVAL - 1; // Below the minimum threshold - bool result = cm.startContinuousConnectivityMonitor(timeout); - EXPECT_TRUE(result); // The function should succeed - EXPECT_EQ(cm.getTimeout(), NMCONNECTIVITY_MONITOR_DEFAULT_INTERVAL); // Timeout should be set to the default -} -TEST_F(ConnectivityMonitorTest, StartContinuousMonitor_LargeTimeout) { - int timeout = 1000000; // Very large timeout value +TEST_F(ConnectivityMonitorTest, StartMonitorWithTimeoutLessThanMinimum) { + // Set a timeout less than the minimum allowed (assuming minimum is 5 seconds) + int timeout = 3; // Example timeout that is less than the minimum allowed + + // Start the monitor with the invalid timeout bool result = cm.startContinuousConnectivityMonitor(timeout); - EXPECT_TRUE(result); // The function should succeed - EXPECT_EQ(cm.getTimeout(), timeout); // Timeout should be set to the input value + + // Assert that the monitor started successfully + EXPECT_TRUE(result); + + // Ensure that the monitor thread is running + EXPECT_TRUE(cm.continuousMonitorThrd.joinable()); + + // Optionally, capture and check logs + testing::internal::CaptureStdout(); + + // Sleep to allow the log to be captured + std::this_thread::sleep_for(std::chrono::seconds(1)); + + // Get the captured output + std::string output = testing::internal::GetCapturedStdout(); + + // Check if the log mentions the default timeout (e.g., 5 seconds) + EXPECT_TRUE(output.find("continuous monitor restarted with 5 Sec") != std::string::npos); } + TEST_F(ConnectivityMonitorTest, StopContinuousMonitor_WhenStarted) { int timeout = 30; cm.startContinuousConnectivityMonitor(timeout);