From ac24650f22554c74d0eca0f83e79e2970c61085a Mon Sep 17 00:00:00 2001 From: Parvathi Date: Wed, 18 Dec 2024 15:48:22 +0530 Subject: [PATCH] unit test file for LegacyPlugin_WiFiAPIs --- .github/CODEOWNERS | 5 + LegacyPlugin_WiFiManagerAPIs.cpp | 2 +- NetworkManagerImplementation.cpp | 11 ++ Tests/mocks/thunder/COMLinkMock.h | 18 +++ Tests/mocks/thunder/DispatcherMock.h | 20 +++ Tests/mocks/thunder/FactoriesImplementation.h | 49 ++++++ Tests/mocks/thunder/Module.cpp | 3 + Tests/mocks/thunder/Module.h | 8 + Tests/mocks/thunder/ServiceMock.h | 60 +++++++ Tests/mocks/thunder/SystemInfo.h | 65 ++++++++ Tests/mocks/thunder/ThunderPortability.h | 13 ++ .../mocks/thunder/WorkerPoolImplementation.h | 45 ++++++ .../test_LegacyPlugin_NetworkAPIs.cpp | 39 +++++ .../test_LegacyPlugin_WiFiManagerAPIs.cpp | 146 ++++++++++++++++++ .../test_NetworkManagerConnectivity.cpp | 62 ++++---- .../test_NetworkManagerStunClient.cpp | 2 +- .../test_WiFiSignalStrengthMonitor.cpp | 12 +- Tests/unit_test/unit_tests.cmake | 27 ++-- 18 files changed, 532 insertions(+), 55 deletions(-) create mode 100644 .github/CODEOWNERS create mode 100644 Tests/mocks/thunder/COMLinkMock.h create mode 100644 Tests/mocks/thunder/DispatcherMock.h create mode 100644 Tests/mocks/thunder/FactoriesImplementation.h create mode 100644 Tests/mocks/thunder/Module.cpp create mode 100644 Tests/mocks/thunder/Module.h create mode 100644 Tests/mocks/thunder/ServiceMock.h create mode 100644 Tests/mocks/thunder/SystemInfo.h create mode 100644 Tests/mocks/thunder/ThunderPortability.h create mode 100644 Tests/mocks/thunder/WorkerPoolImplementation.h create mode 100644 Tests/unit_test/test_LegacyPlugin_NetworkAPIs.cpp create mode 100644 Tests/unit_test/test_LegacyPlugin_WiFiManagerAPIs.cpp diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 00000000..42b93c90 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,5 @@ +# These owners will be the default owners for everything in +# the repo. Unless a later match takes precedence, +# @global-owner1 and @global-owner2 will be requested for +# review when someone opens a pull request. +* @rdkcentral/networkmanager-maintainers diff --git a/LegacyPlugin_WiFiManagerAPIs.cpp b/LegacyPlugin_WiFiManagerAPIs.cpp index 33691322..8e67072c 100644 --- a/LegacyPlugin_WiFiManagerAPIs.cpp +++ b/LegacyPlugin_WiFiManagerAPIs.cpp @@ -159,7 +159,7 @@ namespace WPEFramework Core::SystemInfo::SetEnvironment(_T("THUNDER_ACCESS"), (_T("127.0.0.1:9998"))); m_networkmanager = make_shared >(_T(NETWORK_MANAGER_CALLSIGN), _T("org.rdk.Wifi"), query); - subscribeToEvents(); + //subscribeToEvents(); return string(); } diff --git a/NetworkManagerImplementation.cpp b/NetworkManagerImplementation.cpp index f08fe09c..997eaf24 100644 --- a/NetworkManagerImplementation.cpp +++ b/NetworkManagerImplementation.cpp @@ -598,6 +598,12 @@ namespace WPEFramework { _notificationLock.Lock(); NMLOG_INFO("Posting onActiveInterfaceChange %s", currentActiveinterface.c_str()); + + if(currentActiveinterface == "eth0") + m_ethConnected = true; + else if (currentActiveinterface == "wlan0") + m_wlanConnected = true; + for (const auto callback : _notificationCallbacks) { callback->onActiveInterfaceChange(prevActiveInterface, currentActiveinterface); } @@ -611,6 +617,11 @@ namespace WPEFramework // Start the connectivity monitor with 'true' to indicate the interface is up. // The monitor will conntinoue even after no internet retry completed, Exit when fully connectd. connectivityMonitor.startConnectivityMonitor(); + // if ipaddress is aquired means there should be interface connected + if(interface == "eth0") + m_ethConnected = true; + else if (interface == "wlan0") + m_wlanConnected = true; } _notificationLock.Lock(); diff --git a/Tests/mocks/thunder/COMLinkMock.h b/Tests/mocks/thunder/COMLinkMock.h new file mode 100644 index 00000000..d9c02502 --- /dev/null +++ b/Tests/mocks/thunder/COMLinkMock.h @@ -0,0 +1,18 @@ +#ifndef RDKSERVICES_TESTS_MOCKS_COMLINKMOCK_H_ +#define RDKSERVICES_TESTS_MOCKS_COMLINKMOCK_H_ + +#include +#include "Module.h" + +class COMLinkMock : public WPEFramework::PluginHost::IShell::ICOMLink { +public: + virtual ~COMLinkMock() = default; + + MOCK_METHOD(void, Register, (WPEFramework::RPC::IRemoteConnection::INotification*), (override)); + MOCK_METHOD(void, Unregister, (WPEFramework::RPC::IRemoteConnection::INotification*), (override)); + MOCK_METHOD(WPEFramework::RPC::IRemoteConnection*, RemoteConnection, (const uint32_t), (override)); + MOCK_METHOD(void*, Instantiate, (const WPEFramework::RPC::Object&, const uint32_t, uint32_t&, const string&, const string&), (override)); +}; + +#endif //RDKSERVICES_TESTS_MOCKS_COMLINKMOCK_H_ + diff --git a/Tests/mocks/thunder/DispatcherMock.h b/Tests/mocks/thunder/DispatcherMock.h new file mode 100644 index 00000000..8d6502b4 --- /dev/null +++ b/Tests/mocks/thunder/DispatcherMock.h @@ -0,0 +1,20 @@ +#ifndef DISPATCHERMOCK_H +#define DISPATCHERMOCK_H + +#include + +#include "Module.h" + + class DispatcherMock: public WPEFramework::PluginHost::IDispatcher{ + public: + virtual ~DispatcherMock() = default; + MOCK_METHOD(void, AddRef, (), (const, override)); + MOCK_METHOD(uint32_t, Release, (), (const, override)); + MOCK_METHOD(void*, QueryInterface, (const uint32_t interfaceNummer), (override)); + MOCK_METHOD(void, Activate, (WPEFramework::PluginHost::IShell* service)); + MOCK_METHOD(void, Deactivate, ()); + MOCK_METHOD(WPEFramework::Core::ProxyType, Invoke, (const string&, uint32_t, const WPEFramework::Core::JSONRPC::Message&), (override)); +}; + +#endif //DISPATCHERMOCK_H + diff --git a/Tests/mocks/thunder/FactoriesImplementation.h b/Tests/mocks/thunder/FactoriesImplementation.h new file mode 100644 index 00000000..9259cb67 --- /dev/null +++ b/Tests/mocks/thunder/FactoriesImplementation.h @@ -0,0 +1,49 @@ + +#pragma once + +#include + +#include "Module.h" + +class FactoriesImplementation : public WPEFramework::PluginHost::IFactories { +public: + FactoriesImplementation(const FactoriesImplementation&) = delete; + FactoriesImplementation& operator=(const FactoriesImplementation&) = delete; + + FactoriesImplementation() + : _requestFactory(5) + , _responseFactory(5) + , _fileBodyFactory(5) + , _jsonRPCFactory(5) + { + // Defaults: + ON_CALL(*this, Request()) + .WillByDefault(::testing::Invoke( + [&]() { return (_requestFactory.Element()); })); + ON_CALL(*this, Response()) + .WillByDefault(::testing::Invoke( + [&]() { return (_responseFactory.Element()); })); + ON_CALL(*this, FileBody()) + .WillByDefault(::testing::Invoke( + [&]() { return (_fileBodyFactory.Element()); })); + ON_CALL(*this, JSONRPC()) + .WillByDefault(::testing::Invoke( + [&]() { + return (WPEFramework::Core::ProxyType>(_jsonRPCFactory.Element())); + })); + } + + virtual ~FactoriesImplementation() = default; + + MOCK_METHOD(WPEFramework::Core::ProxyType, Request, (), (override)); + MOCK_METHOD(WPEFramework::Core::ProxyType, Response, (), (override)); + MOCK_METHOD(WPEFramework::Core::ProxyType, FileBody, (), (override)); + MOCK_METHOD(WPEFramework::Core::ProxyType>, JSONRPC, (), (override)); + +private: + WPEFramework::Core::ProxyPoolType _requestFactory; + WPEFramework::Core::ProxyPoolType _responseFactory; + WPEFramework::Core::ProxyPoolType _fileBodyFactory; + WPEFramework::Core::ProxyPoolType _jsonRPCFactory; +}; + diff --git a/Tests/mocks/thunder/Module.cpp b/Tests/mocks/thunder/Module.cpp new file mode 100644 index 00000000..2d85ed90 --- /dev/null +++ b/Tests/mocks/thunder/Module.cpp @@ -0,0 +1,3 @@ +#include "Module.h" + +MODULE_NAME_DECLARATION(BUILD_REFERENCE) diff --git a/Tests/mocks/thunder/Module.h b/Tests/mocks/thunder/Module.h new file mode 100644 index 00000000..b14a5086 --- /dev/null +++ b/Tests/mocks/thunder/Module.h @@ -0,0 +1,8 @@ +#pragma once + +#ifndef MODULE_NAME +#define MODULE_NAME tests +#endif + +#include +#include diff --git a/Tests/mocks/thunder/ServiceMock.h b/Tests/mocks/thunder/ServiceMock.h new file mode 100644 index 00000000..728c6918 --- /dev/null +++ b/Tests/mocks/thunder/ServiceMock.h @@ -0,0 +1,60 @@ +#ifndef SERVICEMOCK_H +#define SERVICEMOCK_H + +#include + +#include "Module.h" + +class ServiceMock : public WPEFramework::PluginHost::IShell { +public: + virtual ~ServiceMock() = default; + + MOCK_METHOD(void, AddRef, (), (const, override)); + MOCK_METHOD(uint32_t, Release, (), (const, override)); + MOCK_METHOD(string, Versions, (), (const, override)); + MOCK_METHOD(string, Locator, (), (const, override)); + MOCK_METHOD(string, ClassName, (), (const, override)); + MOCK_METHOD(string, Callsign, (), (const, override)); + MOCK_METHOD(string, WebPrefix, (), (const, override)); + MOCK_METHOD(string, ConfigLine, (), (const, override)); + MOCK_METHOD(string, PersistentPath, (), (const, override)); + MOCK_METHOD(string, VolatilePath, (), (const, override)); + MOCK_METHOD(string, DataPath, (), (const, override)); + MOCK_METHOD(state, State, (), (const, override)); + MOCK_METHOD(WPEFramework::Core::hresult, Activate, (const reason), (override)); + MOCK_METHOD(WPEFramework::Core::hresult, Deactivate, (const reason), (override)); + MOCK_METHOD(WPEFramework::Core::hresult, Unavailable, (const reason), (override)); + MOCK_METHOD(WPEFramework::Core::hresult, ConfigLine, (const string& config), (override)); + MOCK_METHOD(WPEFramework::Core::hresult, SystemRootPath, (const string& systemRootPath), (override)); + MOCK_METHOD(WPEFramework::Core::hresult, Hibernate, (const uint32_t timeout), (override)); + MOCK_METHOD(string, SystemPath, (), (const, override)); + MOCK_METHOD(string, PluginPath, (), (const, override)); + MOCK_METHOD(WPEFramework::PluginHost::IShell::startup, Startup, (), (const, override)); + MOCK_METHOD(WPEFramework::Core::hresult, Startup, (const startup value), (override)); + MOCK_METHOD(WPEFramework::Core::hresult, Resumed, (const bool value), (override)); + MOCK_METHOD(WPEFramework::Core::hresult, Metadata, (string& info), (const, override)); + + MOCK_METHOD(bool, Resumed, (), (const, override)); + MOCK_METHOD(bool, IsSupported, (const uint8_t), (const, override)); + MOCK_METHOD(void, EnableWebServer, (const string&, const string&), (override)); + MOCK_METHOD(void, DisableWebServer, (), (override)); + MOCK_METHOD(WPEFramework::PluginHost::ISubSystem*, SubSystems, (), (override)); + MOCK_METHOD(uint32_t, Submit, (const uint32_t, const WPEFramework::Core::ProxyType&), (override)); + MOCK_METHOD(void, Notify, (const string&), (override)); + MOCK_METHOD(void*, QueryInterface, (const uint32_t), (override)); + MOCK_METHOD(void*, QueryInterfaceByCallsign, (const uint32_t, const string&), (override)); + MOCK_METHOD(void, Register, (WPEFramework::PluginHost::IPlugin::INotification*), (override)); + MOCK_METHOD(void, Unregister, (WPEFramework::PluginHost::IPlugin::INotification*), (override)); + MOCK_METHOD(string, Model, (), (const, override)); + MOCK_METHOD(bool, Background, (), (const, override)); + MOCK_METHOD(string, Accessor, (), (const, override)); + MOCK_METHOD(string, ProxyStubPath, (), (const, override)); + MOCK_METHOD(string, HashKey, (), (const, override)); + MOCK_METHOD(string, Substitute, (const string&), (const, override)); + MOCK_METHOD(WPEFramework::PluginHost::IShell::ICOMLink*, COMLink, (), (override)); + MOCK_METHOD(reason, Reason, (), (const, override)); + MOCK_METHOD(string, SystemRootPath, (), (const, override)); +}; + +#endif //SERVICEMOCK_H + diff --git a/Tests/mocks/thunder/SystemInfo.h b/Tests/mocks/thunder/SystemInfo.h new file mode 100644 index 00000000..871b1095 --- /dev/null +++ b/Tests/mocks/thunder/SystemInfo.h @@ -0,0 +1,65 @@ +#pragma once + +#include + +#include "Module.h" + +class SystemInfo : public WPEFramework::PluginHost::ISubSystem { +private: + SystemInfo(const SystemInfo&) = delete; + SystemInfo& operator=(const SystemInfo&) = delete; + +public: + SystemInfo() + : _flags(0) + { + // Defaults: + ON_CALL(*this, Set(::testing::_, ::testing::_)) + .WillByDefault(::testing::Invoke( + [&](const subsystem type, WPEFramework::Core::IUnknown* information) { + _subsystems.emplace(type, information); + + if (type >= NEGATIVE_START) { + _flags &= ~(1 << (type - NEGATIVE_START)); + } else { + _flags |= (1 << type); + } + })); + ON_CALL(*this, Get(::testing::_)) + .WillByDefault(::testing::Invoke( + [&](const subsystem type) -> const WPEFramework::Core::IUnknown* { + const WPEFramework::Core::IUnknown* result(nullptr); + + auto it = _subsystems.find(type); + if (it != _subsystems.end()) { + result = it->second; + } + + return result; + })); + ON_CALL(*this, IsActive(::testing::_)) + .WillByDefault(::testing::Invoke( + [&](const subsystem type) -> bool { + return ((type < END_LIST) && ((_flags & (1 << type)) != 0)); + })); + } + virtual ~SystemInfo() = default; + +public: + MOCK_METHOD(void, Register, (WPEFramework::PluginHost::ISubSystem::INotification * notification), (override)); + MOCK_METHOD(void, Unregister, (WPEFramework::PluginHost::ISubSystem::INotification * notification), (override)); + MOCK_METHOD(string, BuildTreeHash, (), (const, override)); + MOCK_METHOD(void, Set, (const subsystem type, WPEFramework::Core::IUnknown* information), (override)); + MOCK_METHOD(const WPEFramework::Core::IUnknown*, Get, (const subsystem type), (const, override)); + MOCK_METHOD(bool, IsActive, (const subsystem type), (const, override)); + MOCK_METHOD(string, Version, (), (const, override)); + + BEGIN_INTERFACE_MAP(SystemInfo) + INTERFACE_ENTRY(WPEFramework::PluginHost::ISubSystem) + END_INTERFACE_MAP + +private: + std::map _subsystems; + uint32_t _flags; +}; + diff --git a/Tests/mocks/thunder/ThunderPortability.h b/Tests/mocks/thunder/ThunderPortability.h new file mode 100644 index 00000000..f0ddcf36 --- /dev/null +++ b/Tests/mocks/thunder/ThunderPortability.h @@ -0,0 +1,13 @@ +#pragma once + +#include +#include + +#define EVENT_SUBSCRIBE(__A__, __B__, __C__, __D__) { plugin->Subscribe(__A__, __B__, __C__); (void)__D__; } +#define EVENT_UNSUBSCRIBE(__A__, __B__, __C__, __D__) { plugin->Unsubscribe(__A__, __B__, __C__); (void)__D__; } + +#define DECL_CORE_JSONRPC_CONX Core::JSONRPC::Context +#define INIT_CONX(__X__, __Y__) connection(__X__, __Y__, "") +#define PLUGINHOST_DISPATCHER PluginHost::ILocalDispatcher +#define PLUGINHOST_DISPATCHER_ID PluginHost::ILocalDispatcher::ID + diff --git a/Tests/mocks/thunder/WorkerPoolImplementation.h b/Tests/mocks/thunder/WorkerPoolImplementation.h new file mode 100644 index 00000000..58bf84f1 --- /dev/null +++ b/Tests/mocks/thunder/WorkerPoolImplementation.h @@ -0,0 +1,45 @@ +#pragma once + +#include + +#include "Module.h" + +class WorkerPoolImplementation : public WPEFramework::Core::WorkerPool { +private: + class Dispatcher : public WPEFramework::Core::ThreadPool::IDispatcher { + public: + Dispatcher(const Dispatcher&) = delete; + Dispatcher& operator=(const Dispatcher&) = delete; + + Dispatcher() = default; + ~Dispatcher() override = default; + + private: + void Initialize() override {} + void Deinitialize() override {} + void Dispatch(WPEFramework::Core::IDispatch* job) override + { + job->Dispatch(); + } + }; + +public: + WorkerPoolImplementation() = delete; + WorkerPoolImplementation(const WorkerPoolImplementation&) = delete; + WorkerPoolImplementation& operator=(const WorkerPoolImplementation&) = delete; + + WorkerPoolImplementation(const uint8_t threads, const uint32_t stackSize, const uint32_t queueSize) + : WPEFramework::Core::WorkerPool(threads - 1, stackSize, queueSize, &_dispatcher) + , _dispatcher() + { + } + + virtual ~WorkerPoolImplementation() + { + WPEFramework::Core::WorkerPool::Stop(); + } + +private: + Dispatcher _dispatcher; +}; + diff --git a/Tests/unit_test/test_LegacyPlugin_NetworkAPIs.cpp b/Tests/unit_test/test_LegacyPlugin_NetworkAPIs.cpp new file mode 100644 index 00000000..ff8c803f --- /dev/null +++ b/Tests/unit_test/test_LegacyPlugin_NetworkAPIs.cpp @@ -0,0 +1,39 @@ +#include +#include +#include +#include "ServiceMock.h" +#include "FactoriesImplementation.h" +#include "NetworkManagerLogger.h" +#include "LegacyPlugin_NetworkAPIs.h" +#include "ThunderPortability.h" + +using namespace std; +using namespace WPEFramework; +using namespace WPEFramework::Plugin; + + +class NetworkTest : public ::testing::Test { +protected: + Core::ProxyType plugin; + Core::JSONRPC::Handler& handler; + DECL_CORE_JSONRPC_CONX connection; + Core::JSONRPC::Message message; + string response; + ServiceMock services; + + NetworkTest() + : plugin(Core::ProxyType::Create()) + , handler(*(plugin)) + , INIT_CONX(1, 0) + { + + } + virtual ~NetworkTest() override + { + } +}; + + + + + diff --git a/Tests/unit_test/test_LegacyPlugin_WiFiManagerAPIs.cpp b/Tests/unit_test/test_LegacyPlugin_WiFiManagerAPIs.cpp new file mode 100644 index 00000000..a7cbd7d8 --- /dev/null +++ b/Tests/unit_test/test_LegacyPlugin_WiFiManagerAPIs.cpp @@ -0,0 +1,146 @@ +#include +#include +#include +#include "ServiceMock.h" +#include "FactoriesImplementation.h" +#include "NetworkManagerLogger.h" +#include "LegacyPlugin_WiFiManagerAPIs.h" +#include "ThunderPortability.h" + +using namespace std; +using namespace WPEFramework; +using namespace WPEFramework::Plugin; +using ::testing::NiceMock; + +class WiFiManagerTest : public ::testing::Test { +protected: + Core::ProxyType plugin; + Core::JSONRPC::Handler& handler; + DECL_CORE_JSONRPC_CONX connection; + Core::JSONRPC::Message message; + string response; + ServiceMock services; + + WiFiManagerTest() + : plugin(Core::ProxyType::Create()) + , handler(*(plugin)) + , INIT_CONX(1, 0) + { + + } + + virtual ~WiFiManagerTest() override + { + } +}; + +class WiFiManagerInitializedTest : public WiFiManagerTest { +protected: + NiceMock service; + WiFiManagerInitializedTest() + { + EXPECT_EQ(string(""), plugin->Initialize(&service)); + + EXPECT_CALL(service, QueryInterfaceByCallsign(::testing::_, ::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const string& name) -> void* { + EXPECT_EQ(name, string(_T("org.rdk.NetworkManager.1"))); + return nullptr; + })); + } + + virtual ~WiFiManagerInitializedTest() override + { + plugin->Deinitialize(&service); + } + +}; + +TEST_F(WiFiManagerTest, TestedAPIsShouldExist) +{ + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("startScan"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("stopScan"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("connect"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("disconnect"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("initiateWPSPairing"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("cancelWPSPairing"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("saveSSID"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("clearSSID"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getPairedSSID"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getPairedSSIDInfo"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("isPaired"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getCurrentState"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getConnectedSSID"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getSupportedSecurityModes"))); +} + +TEST_F(WiFiManagerInitializedTest, startScan) +{ + EXPECT_EQ(Core::ERROR_UNAVAILABLE, handler.Invoke(connection, _T("startScan"), _T("{}"), response)); + EXPECT_EQ(response, string("")); +} + +TEST_F(WiFiManagerInitializedTest, stopScan) +{ + EXPECT_EQ(Core::ERROR_UNAVAILABLE, handler.Invoke(connection, _T("stopScan"), _T("{}"), response)); + EXPECT_EQ(response, string("")); +} + +TEST_F(WiFiManagerInitializedTest, isPaired) +{ + EXPECT_EQ(Core::ERROR_UNAVAILABLE, handler.Invoke(connection, _T("isPaired"), _T("{}"), response)); + EXPECT_EQ(response, string("")); +} + +TEST_F(WiFiManagerInitializedTest, disconnect) +{ + EXPECT_EQ(Core::ERROR_UNAVAILABLE, handler.Invoke(connection, _T("disconnect"), _T("{}"), response)); + EXPECT_EQ(response, string("")); +} + +TEST_F(WiFiManagerInitializedTest, initiateWPSPairing) +{ + EXPECT_EQ(Core::ERROR_UNAVAILABLE, handler.Invoke(connection, _T("initiateWPSPairing"), _T("{}"), response)); + EXPECT_EQ(response, string("")); +} + +TEST_F(WiFiManagerInitializedTest, cancelWPSPairing) +{ + EXPECT_EQ(Core::ERROR_UNAVAILABLE, handler.Invoke(connection, _T("cancelWPSPairing"), _T("{}"), response)); + EXPECT_EQ(response, string("")); +} + +TEST_F(WiFiManagerInitializedTest, clearSSID) +{ + EXPECT_EQ(Core::ERROR_UNAVAILABLE, handler.Invoke(connection, _T("clearSSID"), _T("{}"), response)); + EXPECT_EQ(response, string("")); +} +TEST_F(WiFiManagerInitializedTest, getPairedSSID) +{ + EXPECT_EQ(Core::ERROR_UNAVAILABLE, handler.Invoke(connection, _T("getPairedSSID"), _T("{}"), response)); + EXPECT_EQ(response, string("")); +} + +TEST_F(WiFiManagerInitializedTest, getPairedSSIDInfo) +{ + EXPECT_EQ(Core::ERROR_UNAVAILABLE, handler.Invoke(connection, _T("getPairedSSIDInfo"), _T("{}"), response)); + EXPECT_EQ(response, string("")); +} + +TEST_F(WiFiManagerInitializedTest, getCurrentState) +{ + EXPECT_EQ(Core::ERROR_UNAVAILABLE, handler.Invoke(connection, _T("getCurrentState"), _T("{}"), response)); + EXPECT_EQ(response, string("")); +} +TEST_F(WiFiManagerInitializedTest, getConnectedSSID) +{ + EXPECT_EQ(Core::ERROR_UNAVAILABLE, handler.Invoke(connection, _T("getConnectedSSID"), _T("{}"), response)); + EXPECT_EQ(response, string("")); +} + +TEST_F(WiFiManagerInitializedTest, getSupportedSecurityModes ) +{ + EXPECT_EQ(Core::ERROR_UNAVAILABLE, handler.Invoke(connection, _T("getSupportedSecurityModes"), _T("{}"), response)); + EXPECT_EQ(response, string("")); +} diff --git a/Tests/unit_test/test_NetworkManagerConnectivity.cpp b/Tests/unit_test/test_NetworkManagerConnectivity.cpp index a0452029..2f4cdeeb 100644 --- a/Tests/unit_test/test_NetworkManagerConnectivity.cpp +++ b/Tests/unit_test/test_NetworkManagerConnectivity.cpp @@ -1,34 +1,33 @@ #include "NetworkManagerImplementation.h" #include "NetworkManagerConnectivity.h" + #include #include using namespace std; using namespace WPEFramework; - + class ConnectivityMonitorTest : public ::testing::Test { protected: - WPEFramework::Plugin::ConnectivityMonitor cm; + + WPEFramework::Plugin::ConnectivityMonitor cm; }; - -TEST_F(ConnectivityMonitorTest, StartContinuousMonitor_Success) { - int timeout = 30; + + TEST_F(ConnectivityMonitorTest, StartContinuousMonitor_Success) { + int timeout = 30; bool result = cm.startContinuousConnectivityMonitor(timeout); - EXPECT_TRUE(result); + EXPECT_TRUE(result); } - TEST_F(ConnectivityMonitorTest, StartContinuousMonitor_FailureNegativeTimeout) { - int timeout = -1; + int timeout = -1; bool result = cm.startContinuousConnectivityMonitor(timeout); - EXPECT_TRUE(result); -} - + EXPECT_TRUE(result); +} TEST_F(ConnectivityMonitorTest, StartMonitorWithTimeoutLessThanMinimum) { - int timeout = 3; + int timeout = 3; bool result = cm.startContinuousConnectivityMonitor(timeout); EXPECT_TRUE(result); } - TEST_F(ConnectivityMonitorTest, MonitorFailsToStart) { int timeout = 0; bool result = cm.startContinuousConnectivityMonitor(timeout); @@ -39,19 +38,17 @@ TEST_F(ConnectivityMonitorTest, StopContinuousMonitor_WhenStarted) { int timeout = 30; cm.startContinuousConnectivityMonitor(timeout); bool result = cm.stopContinuousConnectivityMonitor(); - EXPECT_TRUE(result); + EXPECT_TRUE(result); } - TEST_F(ConnectivityMonitorTest, StopContinuousMonitor_WhenNotStarted) { bool result = cm.stopContinuousConnectivityMonitor(); - EXPECT_TRUE(result); + EXPECT_TRUE(result); } - TEST_F(ConnectivityMonitorTest, StopContinuousMonitor_AfterMultipleStartsAndStops) { int timeout = 30; cm.startContinuousConnectivityMonitor(timeout); bool result = cm.stopContinuousConnectivityMonitor(); - EXPECT_TRUE(result); + EXPECT_TRUE(result); cm.startContinuousConnectivityMonitor(timeout); result = cm.stopContinuousConnectivityMonitor(); @@ -59,49 +56,48 @@ TEST_F(ConnectivityMonitorTest, StopContinuousMonitor_AfterMultipleStartsAndStop cm.startContinuousConnectivityMonitor(timeout); result = cm.stopContinuousConnectivityMonitor(); - EXPECT_TRUE(result); + 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); + EXPECT_TRUE(result); } -TEST_F(ConnectivityMonitorTest, StartMonitor_WithInterfaceStatus) { + TEST_F(ConnectivityMonitorTest, StartMonitor_WithInterfaceStatusTrue) { + bool interfaceStatus = true; bool result = cm.startConnectivityMonitor(); - EXPECT_TRUE(result); + EXPECT_TRUE(result); +} +TEST_F(ConnectivityMonitorTest, StartMonitor_WithInterfaceStatusFalse) { + bool interfaceStatus = false; + bool result = cm.startConnectivityMonitor(); + EXPECT_TRUE(result); } - TEST_F(ConnectivityMonitorTest, StartMonitor_NotifyIfAlreadyMonitoring) { - bool result = false; - result = cm.startConnectivityMonitor(); - EXPECT_TRUE(result); - result = cm.startConnectivityMonitor(); - EXPECT_TRUE(result); + bool interfaceStatus = true; + bool result = cm.startConnectivityMonitor(); + EXPECT_TRUE(result); } TEST_F(ConnectivityMonitorTest, SetEndpoints_Valid) { std::vector 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 endpoints; cm.setConnectivityMonitorEndpoints(endpoints); EXPECT_TRUE(cm.getConnectivityMonitorEndpoints().empty()); } - TEST_F(ConnectivityMonitorTest, SetEndpoints_InvalidShortEndpoints) { std::vector endpoints = {"ab", "htt", "xyz"}; cm.setConnectivityMonitorEndpoints(endpoints); EXPECT_TRUE(cm.getConnectivityMonitorEndpoints().empty()); } - TEST_F(ConnectivityMonitorTest, SetEndpoints_DuplicateEndpoints) { std::vector endpoints = {"https://github.com", "https://github.com"}; cm.setConnectivityMonitorEndpoints(endpoints); diff --git a/Tests/unit_test/test_NetworkManagerStunClient.cpp b/Tests/unit_test/test_NetworkManagerStunClient.cpp index 5276344a..a061ed73 100644 --- a/Tests/unit_test/test_NetworkManagerStunClient.cpp +++ b/Tests/unit_test/test_NetworkManagerStunClient.cpp @@ -28,10 +28,10 @@ TEST_F(ClientTest, BindFailure) { EXPECT_FALSE(success); EXPECT_FALSE(result.is_valid()); } - TEST_F(ClientTest, BindWithInvalidInterface) { stun::bind_result result; bool success = _client.bind("https://github.com/", 3478, "invalid_interface", stun::protocol::af_inet, 5000, 10000, result); EXPECT_FALSE(success); EXPECT_FALSE(result.is_valid()); } + diff --git a/Tests/unit_test/test_WiFiSignalStrengthMonitor.cpp b/Tests/unit_test/test_WiFiSignalStrengthMonitor.cpp index 5618a6cb..1c30a008 100644 --- a/Tests/unit_test/test_WiFiSignalStrengthMonitor.cpp +++ b/Tests/unit_test/test_WiFiSignalStrengthMonitor.cpp @@ -17,12 +17,11 @@ namespace WPEFramework { namespace Plugin { - NetworkManagerImplementation* _instance = nullptr; + NetworkManagerImplementation* _instance = nullptr; void NetworkManagerImplementation::ReportWiFiSignalStrengthChange(const string ssid, const string strength, const WiFiSignalQuality quality) - { + { return; } - void NetworkManagerImplementation::ReportInternetStatusChange(const InternetStatus prevState, const InternetStatus currState) { return; @@ -43,10 +42,7 @@ TEST_F(WiFiSignalStrengthMonitorTest, GetSignalData_Connected) { } TEST_F(WiFiSignalStrengthMonitorTest, StartWiFiSignalStrengthMonitor) { - monitor.startWiFiSignalStrengthMonitor(1); + monitor.startWiFiSignalStrengthMonitor(1); } -int main(int argc, char **argv) { - ::testing::InitGoogleMock(&argc, argv); - return RUN_ALL_TESTS(); -} + diff --git a/Tests/unit_test/unit_tests.cmake b/Tests/unit_test/unit_tests.cmake index 9c56c242..b324092f 100644 --- a/Tests/unit_test/unit_tests.cmake +++ b/Tests/unit_test/unit_tests.cmake @@ -1,9 +1,7 @@ +cmake_minimum_required(VERSION 3.10) set(UNIT_TEST "unit_tests") find_package(PkgConfig REQUIRED) -pkg_check_modules(GLIB REQUIRED glib-2.0) -pkg_check_modules(GIO REQUIRED gio-2.0) -pkg_check_modules(LIBNM REQUIRED libnm) include(FetchContent) FetchContent_Declare( @@ -16,31 +14,36 @@ add_executable(${UNIT_TEST} Tests/unit_test/test_WiFiSignalStrengthMonitor.cpp Tests/unit_test/test_NetworkManagerConnectivity.cpp Tests/unit_test/test_NetworkManagerStunClient.cpp + Tests/unit_test/test_LegacyPlugin_WiFiManagerAPIs.cpp + Tests/mocks/thunder/Module.cpp WiFiSignalStrengthMonitor.cpp NetworkManagerLogger.cpp NetworkManagerConnectivity.cpp NetworkManagerStunClient.cpp + LegacyPlugin_WiFiManagerAPIs.cpp ) - set_target_properties(${UNIT_TEST} PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED YES ) - target_compile_options(${UNIT_TEST} PRIVATE -Wall -include ${CMAKE_SOURCE_DIR}/INetworkManager.h) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage") target_include_directories(${UNIT_TEST} PRIVATE - ${GLIB_INCLUDE_DIRS} - ${LIBNM_INCLUDE_DIRS} - ${GIO_INCLUDE_DIRS} - ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} - Tests ${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR}/../googlemock/include + Tests + Tests/mocks + Tests/mocks/thunder ) +target_link_libraries(${UNIT_TEST} PRIVATE + gmock_main + ${NAMESPACE}Core::${NAMESPACE}Core + ${NAMESPACE}Plugins::${NAMESPACE}Plugins + ${NAMESPACE}Core::${NAMESPACE}Core + ${CURL_LIBRARIES} + ) -target_link_libraries(${UNIT_TEST} PRIVATE gmock_main ${NAMESPACE}Core::${NAMESPACE}Core ${GLIB_LIBRARIES} ${GIO_LIBRARIES} ${LIBNM_LIBRARIES} ${CURL_LIBRARIES}) -target_include_directories(${UNIT_TEST} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) install(TARGETS ${UNIT_TEST} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) +