Skip to content

Commit

Permalink
same code
Browse files Browse the repository at this point in the history
  • Loading branch information
cmuhammedrafi committed Dec 30, 2024
1 parent c5d87a0 commit d85070d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 97 deletions.
2 changes: 1 addition & 1 deletion LegacyPlugin_WiFiManagerAPIs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ namespace WPEFramework
Core::SystemInfo::SetEnvironment(_T("THUNDER_ACCESS"), (_T("127.0.0.1:9998")));
m_networkmanager = make_shared<WPEFramework::JSONRPC::SmartLinkType<WPEFramework::Core::JSON::IElement> >(_T(NETWORK_MANAGER_CALLSIGN), _T("org.rdk.Wifi"), query);

//subscribeToEvents();
subscribeToEvents();
return string();
}

Expand Down
2 changes: 1 addition & 1 deletion LegacyPlugin_WiFiManagerAPIs.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ namespace WPEFramework {
void activatePrimaryPlugin();

private:
PluginHost::IShell* m_service;
std::shared_ptr<WPEFramework::JSONRPC::SmartLinkType<WPEFramework::Core::JSON::IElement>> m_networkmanager;
PluginHost::IShell* m_service;
NetworkManagerTimer m_timer;
bool m_subsWiFiStateChange;
bool m_subsAvailableSSIDs;
Expand Down
107 changes: 12 additions & 95 deletions Tests/unit_test/test_LegacyPlugin_WiFiManagerAPIs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class WiFiManagerTest : public ::testing::Test {
}
};


TEST_F(WiFiManagerTest, TestedAPIsShouldExist)
{
EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("startScan")));
Expand All @@ -51,112 +50,30 @@ TEST_F(WiFiManagerTest, TestedAPIsShouldExist)
EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getSupportedSecurityModes")));
}

namespace WPEFramework
{
namespace Exchange
{
class MockINetworkManager : public INetworkManager {
public:
MOCK_METHOD(uint32_t, GetAvailableInterfaces, (IInterfaceDetailsIterator*& interfaces), (override));
MOCK_METHOD(uint32_t, GetPrimaryInterface, (std::string& interface), (override));
MOCK_METHOD(uint32_t, SetPrimaryInterface, (const std::string& interface), (override));
MOCK_METHOD(uint32_t, SetInterfaceState, (const std::string& interface, const bool enabled), (override));
MOCK_METHOD(uint32_t, GetInterfaceState, (const std::string& interface, bool& enabled), (override));
MOCK_METHOD(uint32_t, GetIPSettings, (std::string& interface, const std::string& ipversion, IPAddress& address), (override));
MOCK_METHOD(uint32_t, SetIPSettings, (const std::string& interface, const IPAddress& address), (override));
MOCK_METHOD(uint32_t, GetStunEndpoint, (std::string& endpoint, uint32_t& port, uint32_t& timeout, uint32_t& cacheLifetime), (const, override));
MOCK_METHOD(uint32_t, SetStunEndpoint, (const std::string& endpoint, const uint32_t port, const uint32_t timeout, const uint32_t cacheLifetime), (override));
MOCK_METHOD(uint32_t, GetConnectivityTestEndpoints, (IStringIterator*& endpoints), (const, override));
MOCK_METHOD(uint32_t, SetConnectivityTestEndpoints, (IStringIterator* const endpoints), (override));
MOCK_METHOD(uint32_t, IsConnectedToInternet, (std::string& ipversion, InternetStatus& status), (override));
MOCK_METHOD(uint32_t, GetCaptivePortalURI, (std::string& uri), (const, override));
MOCK_METHOD(uint32_t, StartConnectivityMonitoring, (const uint32_t interval), (override));
MOCK_METHOD(uint32_t, StopConnectivityMonitoring, (), (const, override));
MOCK_METHOD(uint32_t, GetPublicIP, (std::string& ipversion, std::string& ipaddress), (override));
MOCK_METHOD(uint32_t, Ping, (const std::string& ipversion, const std::string& endpoint, const uint32_t count, const uint16_t timeout, const std::string& guid, std::string& response), (override));
MOCK_METHOD(uint32_t, Trace, (const std::string& ipversion, const std::string& endpoint, const uint32_t nqueries, const std::string& guid, std::string& response), (override));

// WiFi Specific Methods
MOCK_METHOD(uint32_t, StartWiFiScan, (const std::string& frequency, IStringIterator* const ssids), (override));
MOCK_METHOD(uint32_t, StopWiFiScan, (), (override));
MOCK_METHOD(uint32_t, GetKnownSSIDs, (IStringIterator*& ssids), (override));
MOCK_METHOD(uint32_t, AddToKnownSSIDs, (const WiFiConnectTo& ssid), (override));
MOCK_METHOD(uint32_t, RemoveKnownSSID, (const std::string& ssid), (override));
MOCK_METHOD(uint32_t, WiFiConnect, (const WiFiConnectTo& ssid), (override));
MOCK_METHOD(uint32_t, WiFiDisconnect, (), (override));
MOCK_METHOD(uint32_t, GetConnectedSSID, (WiFiSSIDInfo& ssidInfo), (override));
MOCK_METHOD(uint32_t, StartWPS, (const WiFiWPS& method, const std::string& pin), (override));
MOCK_METHOD(uint32_t, StopWPS, (), (override));
MOCK_METHOD(uint32_t, GetWifiState, (WiFiState& state), (override));
MOCK_METHOD(uint32_t, GetWiFiSignalStrength, (std::string& ssid, std::string& strength, WiFiSignalQuality& quality), (override));
MOCK_METHOD(uint32_t, GetSupportedSecurityModes, (ISecurityModeIterator*& modes), (const, override));

// Logging Methods
MOCK_METHOD(uint32_t, SetLogLevel, (const Logging& level), (override));
MOCK_METHOD(uint32_t, GetLogLevel, (Logging& level), (override));

// Configuration Method
MOCK_METHOD(uint32_t, Configure, (const std::string& configLine), (override));

// Notification Methods
MOCK_METHOD(uint32_t, Register, (INetworkManager::INotification* notification), (override));
MOCK_METHOD(uint32_t, Unregister, (INetworkManager::INotification* notification), (override));

// Notification Event Methods
MOCK_METHOD(void, onInterfaceStateChange, (const InterfaceState state, const std::string interface), (override));
MOCK_METHOD(void, onActiveInterfaceChange, (const std::string prevActiveInterface, const std::string currentActiveInterface), (override));
MOCK_METHOD(void, onIPAddressChange, (const std::string interface, const std::string ipversion, const std::string ipaddress, const IPStatus status), (override));
MOCK_METHOD(void, onInternetStatusChange, (const InternetStatus prevState, const InternetStatus currState), (override));
MOCK_METHOD(void, onAvailableSSIDs, (const std::string jsonOfScanResults), (override));
MOCK_METHOD(void, onWiFiStateChange, (const WiFiState state), (override));
MOCK_METHOD(void, onWiFiSignalStrengthChange, (const std::string ssid, const std::string strength, const WiFiSignalQuality quality), (override));
};
}
}

TEST_F(WiFiManagerTest, connect)
{
NiceMock<ServiceMock> service;
WPEFramework::Exchange::MockINetworkManager NetworkManagerService;

EXPECT_CALL(service, QueryInterfaceByCallsign(::testing::_, ::testing::_))
.Times(1)
.Times(2)
.WillOnce(::testing::Invoke(
[&](const uint32_t, const string& name) -> void* {
EXPECT_EQ(name, string(_T("org.rdk.NetworkManager.1")));
return nullptr;
}));
[&](const uint32_t, const std::string& name) -> void* {
EXPECT_EQ(name, std::string(_T("SecurityAgent")));
return nullptr; // First call
}
))
.WillOnce(::testing::Invoke(
[&](const uint32_t, const std::string& name) -> void* {
EXPECT_EQ(name, std::string(_T("org.rdk.NetworkManager.1"))); // Different value
return nullptr; // Second call
}
));

EXPECT_EQ(string(""), plugin->Initialize(&service));

EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("connect"), _T("{}"), response));
EXPECT_EQ(response, string(""));

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;
}));

EXPECT_EQ(Core::ERROR_UNAVAILABLE, handler.Invoke(connection, _T("connect"), _T("{\"ssid\":\"testssid\"}"), response));
EXPECT_EQ(response, string(""));

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 &NetworkManagerService;
}));

ON_CALL(NetworkManagerService, WiFiConnect(::testing::_))
.WillByDefault(::testing::Return(Core::ERROR_NONE));

EXPECT_EQ(Core::ERROR_UNAVAILABLE, handler.Invoke(connection, _T("connect"), _T("{\"ssid\":\"testssid\"}"), response));
EXPECT_EQ(response, string(""));

plugin->Deinitialize(&service);
}

Expand Down

0 comments on commit d85070d

Please sign in to comment.