forked from rdkcentral/networkmanager
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'rdkcentral:develop' into develop
- Loading branch information
Showing
3 changed files
with
204 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters