Skip to content

Commit

Permalink
add more test cases for connectivity file
Browse files Browse the repository at this point in the history
  • Loading branch information
parvathika committed Nov 19, 2024
1 parent f852219 commit 3f6427e
Showing 1 changed file with 138 additions and 0 deletions.
138 changes: 138 additions & 0 deletions Tests/unittest/test_connectivity.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
#include "NetworkManagerImplementation.h"
#include "NetworkManagerConnectivity.h"
#include "WiFiSignalStrengthMonitor.h"
#include <cstring>
#include <atomic>
#include <vector>
#include <thread>
#include <chrono>
#include <map>
#include <curl/curl.h>
#include <condition_variable>
#include <mutex>
#include <cerrno>
#include <cstdlib>
#include <fstream>
#include <algorithm>
#include <ctime>
#include <gtest/gtest.h>
#include <gmock/gmock.h>

using namespace std;
using namespace WPEFramework;

class ConnectivityMonitorTest : public ::testing::Test {
protected:

WPEFramework::Plugin::ConnectivityMonitor cm;

void SetUp() override {

}

void TearDown() override {

}
};

TEST_F(ConnectivityMonitorTest, StartContinuousMonitor_Success) {
int timeout = 30;
bool result = cm.startContinuousConnectivityMonitor(timeout);
EXPECT_TRUE(result);
}
TEST_F(ConnectivityMonitorTest, StartContinuousMonitor_FailureNegativeTimeout) {
int timeout = -1;
bool result = cm.startContinuousConnectivityMonitor(timeout);
EXPECT_TRUE(result);
}
TEST_F(ConnectivityMonitorTest, StartMonitorWithTimeoutLessThanMinimum) {
int timeout = 3;
bool result = cm.startContinuousConnectivityMonitor(timeout);
EXPECT_TRUE(result);
}
TEST_F(ConnectivityMonitorTest, MonitorFailsToStart) {
int timeout = 0;
bool result = cm.startContinuousConnectivityMonitor(timeout);
EXPECT_TRUE(result);
}



TEST_F(ConnectivityMonitorTest, StopContinuousMonitor_WhenStarted) {
int timeout = 30;
cm.startContinuousConnectivityMonitor(timeout);
bool result = cm.stopContinuousConnectivityMonitor();
EXPECT_TRUE(result);
}
TEST_F(ConnectivityMonitorTest, StopContinuousMonitor_WhenNotStarted) {
bool result = cm.stopContinuousConnectivityMonitor();
EXPECT_TRUE(result);
}
TEST_F(ConnectivityMonitorTest, StopContinuousMonitor_AfterMultipleStartsAndStops) {
int timeout = 30;

// Start the monitor first time
cm.startContinuousConnectivityMonitor(timeout);
bool result = cm.stopContinuousConnectivityMonitor();
EXPECT_TRUE(result); // The monitor should be stopped successfully.

// Start the monitor again
cm.startContinuousConnectivityMonitor(timeout);
result = cm.stopContinuousConnectivityMonitor();
EXPECT_TRUE(result); // The monitor should be stopped again successfully.

// Start and stop multiple times to check stability
cm.startContinuousConnectivityMonitor(timeout);
result = cm.stopContinuousConnectivityMonitor();
EXPECT_TRUE(result); // The monitor should be stopped again successfully.
}
TEST_F(ConnectivityMonitorTest, StopContinuousMonitor_LongRunningMonitor) {
int timeout = 1000; // Use a large timeout value to simulate a long-running monitor.

// Start the monitor with a long timeout
cm.startContinuousConnectivityMonitor(timeout);

// Simulate some time passing, you could either add a sleep or time-based simulation
std::this_thread::sleep_for(std::chrono::seconds(2)); // Sleep for a short time to simulate long running

// Now stop the monitor
bool result = cm.stopContinuousConnectivityMonitor();
EXPECT_TRUE(result); // Monitor should stop successfully, even after running for a long time.
}


TEST_F(ConnectivityMonitorTest, StartMonitor_WithInterfaceStatusTrue) {
bool interfaceStatus = true;
bool result = cm.startConnectivityMonitor(interfaceStatus);
EXPECT_TRUE(result);
}
TEST_F(ConnectivityMonitorTest, StartMonitor_WithInterfaceStatusFalse) {
bool interfaceStatus = false;
bool result = cm.startConnectivityMonitor(interfaceStatus);
EXPECT_TRUE(result);
}

TEST_F(ConnectivityMonitorTest, SetEndpoints_Valid) {
std::vector<std::string> endpoints = {"https://github.com/rdkcentral", "https://github.com/rdkcentral/rdkservices"};
cm.setConnectivityMonitorEndpoints(endpoints);
EXPECT_EQ(cm.getConnectivityMonitorEndpoints(), endpoints);
}
TEST_F(ConnectivityMonitorTest, SetEndpoints_EmptyList) {
std::vector<std::string> endpoints;
cm.setConnectivityMonitorEndpoints(endpoints);
EXPECT_TRUE(cm.getConnectivityMonitorEndpoints().empty());
}
TEST_F(ConnectivityMonitorTest, SetEndpoints_InvalidShortEndpoints) {
std::vector<std::string> endpoints = {"ab", "htt", "xyz"};
cm.setConnectivityMonitorEndpoints(endpoints);
EXPECT_TRUE(cm.getConnectivityMonitorEndpoints().empty());
}
TEST_F(ConnectivityMonitorTest, SetEndpoints_DuplicateEndpoints) {
std::vector<std::string> endpoints = {"https://github.com", "https://github.com"};
cm.setConnectivityMonitorEndpoints(endpoints);
EXPECT_EQ(cm.getConnectivityMonitorEndpoints().size(), 2);
}




0 comments on commit 3f6427e

Please sign in to comment.