Skip to content

Commit cbe7f11

Browse files
committed
fixup! feat: Singleton class mock test support for all modules
1 parent 87683e9 commit cbe7f11

File tree

7 files changed

+53
-416
lines changed

7 files changed

+53
-416
lines changed

languages/cpp/src/shared/src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ endif ()
4040
add_library(${TARGET} ${FIREBOLT_LIBRARY_TYPE} ${SOURCES})
4141

4242
if(ENABLE_UNIT_TESTS)
43+
add_compile_definitions(MOCK_TEST)
4344
target_compile_definitions(FireboltSDK PRIVATE UNIT_TEST)
4445
endif()
4546

@@ -61,6 +62,7 @@ target_link_libraries(${TARGET}
6162
target_include_directories(${TARGET}
6263
PRIVATE
6364
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>
65+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../test/include>
6466
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>
6567
)
6668

languages/cpp/src/shared/src/Gateway/unidi/gateway_impl.h

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,30 @@
2525

2626
#include "../common.h"
2727

28+
#ifndef MOCK_TEST
29+
#include "Transport/Transport.h"
30+
#else
31+
#include "IGatewayMock.h"
32+
#endif
33+
2834
#include <string>
2935
#include <stdio.h>
3036

31-
#include "mockGateway.h"
32-
3337
namespace FireboltSDK
3438
{
3539

3640
using EventCallback = std::function<void(const std::string & /* eventName */, const JsonObject & /* parameters */, Firebolt::Error /* error */)>;
3741

42+
#ifndef MOCK_TEST
43+
class GatewayImpl
44+
{
45+
46+
Transport<WPEFramework::Core::JSON::IElement> *transport;
47+
#else
3848
class GatewayImpl : public IGatewayMock
3949
{
50+
#endif
51+
4052
public:
4153
GatewayImpl()
4254
{
@@ -48,6 +60,17 @@ namespace FireboltSDK
4860
this->transport = transport;
4961
}
5062

63+
#ifndef MOCK_TEST
64+
template <typename RESPONSE>
65+
Firebolt::Error Request(const std::string &method, const JsonObject &parameters, RESPONSE &response)
66+
{
67+
if (transport == nullptr)
68+
{
69+
return Firebolt::Error::NotConnected;
70+
}
71+
return transport->Invoke(method, parameters, response);
72+
}
73+
#endif
5174

5275
Firebolt::Error Response(unsigned id, const std::string &method, const JsonObject &response)
5376
{

languages/cpp/src/shared/src/Gateway/unidi/mockGateway.h

Lines changed: 0 additions & 144 deletions
This file was deleted.

languages/cpp/src/shared/src/IGateway.h

Lines changed: 0 additions & 137 deletions
This file was deleted.

0 commit comments

Comments
 (0)