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.
unit test file for LegacyPlugin_WiFiAPIs
- Loading branch information
1 parent
24312a3
commit ac24650
Showing
18 changed files
with
532 additions
and
55 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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,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 |
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
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
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,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_ | ||
|
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,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 | ||
|
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,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; | ||
}; | ||
|
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,3 @@ | ||
#include "Module.h" | ||
|
||
MODULE_NAME_DECLARATION(BUILD_REFERENCE) |
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,8 @@ | ||
#pragma once | ||
|
||
#ifndef MODULE_NAME | ||
#define MODULE_NAME tests | ||
#endif | ||
|
||
#include <core/core.h> | ||
#include <plugins/plugins.h> |
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,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 | ||
|
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,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; | ||
}; | ||
|
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,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 | ||
|
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,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; | ||
}; | ||
|
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,39 @@ | ||
#include <gtest/gtest.h> | ||
#include <gmock/gmock.h> | ||
#include <fstream> | ||
#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::Network> plugin; | ||
Core::JSONRPC::Handler& handler; | ||
DECL_CORE_JSONRPC_CONX connection; | ||
Core::JSONRPC::Message message; | ||
string response; | ||
ServiceMock services; | ||
|
||
NetworkTest() | ||
: plugin(Core::ProxyType<Plugin::Network>::Create()) | ||
, handler(*(plugin)) | ||
, INIT_CONX(1, 0) | ||
{ | ||
|
||
} | ||
virtual ~NetworkTest() override | ||
{ | ||
} | ||
}; | ||
|
||
|
||
|
||
|
||
|
Oops, something went wrong.