Skip to content

Commit

Permalink
workflow initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
cmuhammedrafi committed Dec 17, 2024
1 parent 3ee8510 commit b995164
Show file tree
Hide file tree
Showing 12 changed files with 387 additions and 18 deletions.
18 changes: 18 additions & 0 deletions Tests/mocks/thunder/COMLinkMock.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef RDKSERVICES_TESTS_MOCKS_COMLINKMOCK_H_
#define RDKSERVICES_TESTS_MOCKS_COMLINKMOCK_H_

#include <gmock/gmock.h>
#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_

20 changes: 20 additions & 0 deletions Tests/mocks/thunder/DispatcherMock.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef DISPATCHERMOCK_H
#define DISPATCHERMOCK_H

#include <gmock/gmock.h>

#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<WPEFramework::Core::JSONRPC::Message>, Invoke, (const string&, uint32_t, const WPEFramework::Core::JSONRPC::Message&), (override));
};

#endif //DISPATCHERMOCK_H

49 changes: 49 additions & 0 deletions Tests/mocks/thunder/FactoriesImplementation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

#pragma once

#include <gmock/gmock.h>

#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<WPEFramework::Web::JSONBodyType<WPEFramework::Core::JSONRPC::Message>>(_jsonRPCFactory.Element()));
}));
}

virtual ~FactoriesImplementation() = default;

MOCK_METHOD(WPEFramework::Core::ProxyType<WPEFramework::Web::Request>, Request, (), (override));
MOCK_METHOD(WPEFramework::Core::ProxyType<WPEFramework::Web::Response>, Response, (), (override));
MOCK_METHOD(WPEFramework::Core::ProxyType<WPEFramework::Web::FileBody>, FileBody, (), (override));
MOCK_METHOD(WPEFramework::Core::ProxyType<WPEFramework::Web::JSONBodyType<WPEFramework::Core::JSONRPC::Message>>, JSONRPC, (), (override));

private:
WPEFramework::Core::ProxyPoolType<WPEFramework::Web::Request> _requestFactory;
WPEFramework::Core::ProxyPoolType<WPEFramework::Web::Response> _responseFactory;
WPEFramework::Core::ProxyPoolType<WPEFramework::Web::FileBody> _fileBodyFactory;
WPEFramework::Core::ProxyPoolType<WPEFramework::PluginHost::JSONRPCMessage> _jsonRPCFactory;
};

3 changes: 3 additions & 0 deletions Tests/mocks/thunder/Module.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "Module.h"

MODULE_NAME_DECLARATION(BUILD_REFERENCE)
8 changes: 8 additions & 0 deletions Tests/mocks/thunder/Module.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

#ifndef MODULE_NAME
#define MODULE_NAME tests
#endif

#include <core/core.h>
#include <plugins/plugins.h>
60 changes: 60 additions & 0 deletions Tests/mocks/thunder/ServiceMock.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#ifndef SERVICEMOCK_H
#define SERVICEMOCK_H

#include <gmock/gmock.h>

#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<WPEFramework::Core::JSON::IElement>&), (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

65 changes: 65 additions & 0 deletions Tests/mocks/thunder/SystemInfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#pragma once

#include <gmock/gmock.h>

#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<subsystem, WPEFramework::Core::IUnknown*> _subsystems;
uint32_t _flags;
};

13 changes: 13 additions & 0 deletions Tests/mocks/thunder/ThunderPortability.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <core/core.h>
#include <plugins/plugins.h>

#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

45 changes: 45 additions & 0 deletions Tests/mocks/thunder/WorkerPoolImplementation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#pragma once

#include <gmock/gmock.h>

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

90 changes: 90 additions & 0 deletions Tests/unit_test/test_LegacyPlugin_WiFiManagerAPIs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include <fstream>
#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::WiFiManager> plugin;
Core::JSONRPC::Handler& handler;
DECL_CORE_JSONRPC_CONX connection;
Core::JSONRPC::Message message;
string response;
ServiceMock services;

WiFiManagerTest()
: plugin(Core::ProxyType<Plugin::WiFiManager>::Create())
, handler(*(plugin))
, INIT_CONX(1, 0)
{

}

virtual ~WiFiManagerTest() override
{
}
};

class WiFiManagerInitializedTest : public WiFiManagerTest {
protected:
NiceMock<ServiceMock> 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("SecurityAgent")));
return nullptr;
}));
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("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_GENERAL, handler.Invoke(connection, _T("startScan"), _T("{}"), response));
EXPECT_EQ(response, string("{\"success\":false}"));
}



7 changes: 1 addition & 6 deletions Tests/unit_test/test_WiFiSignalStrengthMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,4 @@ TEST_F(WiFiSignalStrengthMonitorTest, GetSignalData_Connected) {

TEST_F(WiFiSignalStrengthMonitorTest, StartWiFiSignalStrengthMonitor) {
monitor.startWiFiSignalStrengthMonitor(1);
}

int main(int argc, char **argv) {
::testing::InitGoogleMock(&argc, argv);
return RUN_ALL_TESTS();
}
}
Loading

0 comments on commit b995164

Please sign in to comment.