Skip to content

Commit

Permalink
Merge branch 'rdkcentral:develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
cmuhammedrafi authored Dec 3, 2024
2 parents 35ab614 + b929692 commit d30aded
Show file tree
Hide file tree
Showing 3 changed files with 204 additions and 0 deletions.
132 changes: 132 additions & 0 deletions Tests/unit_test/test_NetworkManagerConnectivity.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
#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;
cm.startContinuousConnectivityMonitor(timeout);
bool result = cm.stopContinuousConnectivityMonitor();
EXPECT_TRUE(result);

cm.startContinuousConnectivityMonitor(timeout);
result = cm.stopContinuousConnectivityMonitor();
EXPECT_TRUE(result);

cm.startContinuousConnectivityMonitor(timeout);
result = cm.stopContinuousConnectivityMonitor();
EXPECT_TRUE(result);
}
TEST_F(ConnectivityMonitorTest, StopContinuousMonitor_LongRunningMonitor) {
int timeout = 1000;
cm.startContinuousConnectivityMonitor(timeout);
std::this_thread::sleep_for(std::chrono::seconds(2));

bool result = cm.stopContinuousConnectivityMonitor();
EXPECT_TRUE(result);
}

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, StartMonitor_NotifyIfAlreadyMonitoring) {
bool interfaceStatus = true;
cm.startConnectivityMonitor(interfaceStatus);
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);
}




69 changes: 69 additions & 0 deletions Tests/unit_test/test_NetworkManagerStunClient.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include <assert.h>
#include <arpa/inet.h>
#include <errno.h>
#include <fcntl.h>
#include <ifaddrs.h>
#include <netdb.h>
#include <net/if.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <algorithm>
#include <exception>
#include <limits>
#include <memory>
#include <random>
#include <set>
#include <sstream>
#include <thread>
#include <iostream>
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include "NetworkManagerStunClient.h"

using namespace std;
using namespace stun;

class AddressTest : public ::testing::Test {
protected:
stun::attributes::address ad;
void SetUp() override {

}
void TearDown() override {

}
};

class ClientTest : public ::testing::Test {
protected:
stun::client cl;
void SetUp() override {

}
void TearDown() override {

}
};

TEST_F(ClientTest, BindSuccess) {
stun::bind_result result;
bool success = cl.bind("https://github.com/", 3478, "eth0", stun::protocol::af_inet, 5000, 10000, result);
EXPECT_FALSE(success);
EXPECT_FALSE(result.is_valid());
}

TEST_F(ClientTest, BindFailure) {
stun::bind_result result;
bool success = cl.bind("http//tata.com", 3478, "eth0", stun::protocol::af_inet, 5000, 10000, result);
EXPECT_FALSE(success);
EXPECT_FALSE(result.is_valid());
}
TEST_F(ClientTest, BindWithInvalidInterface) {
stun::bind_result result;
bool success = cl.bind("https://github.com/", 3478, "invalid_interface", stun::protocol::af_inet, 5000, 10000, result);
EXPECT_FALSE(success);
EXPECT_FALSE(result.is_valid());
}

3 changes: 3 additions & 0 deletions Tests/unit_test/tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ FetchContent_Declare(
FetchContent_MakeAvailable(googletest)
add_executable(${UNIT_TEST}
Tests/unit_test/test_WiFiSignalStrengthMonitor.cpp
Tests/unit_test/test_NetworkManagerConnectivity.cpp
Tests/unit_test/test_NetworkManagerStunClient.cpp
WiFiSignalStrengthMonitor.cpp
NetworkManagerLogger.cpp
NetworkManagerConnectivity.cpp
NetworkManagerStunClient.cpp
)
set_target_properties(${UNIT_TEST} PROPERTIES
CXX_STANDARD 11
Expand Down

0 comments on commit d30aded

Please sign in to comment.