Skip to content

Commit

Permalink
edit
Browse files Browse the repository at this point in the history
  • Loading branch information
parvathika committed Nov 19, 2024
1 parent db78080 commit 6ebee4e
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions Tests/unittest/test_connectivity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 6ebee4e

Please sign in to comment.