Krzysztof Grobelny | 7f06f61 | 2020-09-24 13:42:10 +0200 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "interfaces/sensor.hpp" |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 4 | #include "utils/conv_container.hpp" |
Krzysztof Grobelny | 7f06f61 | 2020-09-24 13:42:10 +0200 | [diff] [blame] | 5 | #include "utils/generate_unique_mock_id.hpp" |
| 6 | |
| 7 | #include <gmock/gmock.h> |
| 8 | |
| 9 | class SensorMock : public interfaces::Sensor |
| 10 | { |
| 11 | public: |
Krzysztof Grobelny | 6ccfcbf | 2020-11-04 09:31:36 +0100 | [diff] [blame] | 12 | explicit SensorMock() |
| 13 | { |
| 14 | initialize(); |
| 15 | } |
| 16 | |
Krzysztof Grobelny | 7f06f61 | 2020-09-24 13:42:10 +0200 | [diff] [blame] | 17 | explicit SensorMock(Id sensorId) : mockSensorId(sensorId) |
| 18 | { |
Krzysztof Grobelny | 6ccfcbf | 2020-11-04 09:31:36 +0100 | [diff] [blame] | 19 | initialize(); |
Krzysztof Grobelny | 7f06f61 | 2020-09-24 13:42:10 +0200 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | static Id makeId(std::string_view service, std::string_view path) |
| 23 | { |
| 24 | return Id("SensorMock", service, path); |
| 25 | } |
| 26 | |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 27 | static std::vector<std::shared_ptr<interfaces::Sensor>> |
| 28 | makeSensorMocks(const std::vector<LabeledSensorInfo>& sensorsInfo) |
| 29 | { |
| 30 | using namespace testing; |
| 31 | std::vector<std::shared_ptr<NiceMock<SensorMock>>> result; |
| 32 | for (const auto& sensorInfo : sensorsInfo) |
| 33 | { |
| 34 | auto& sensorMock = |
| 35 | result.emplace_back(std::make_shared<NiceMock<SensorMock>>()); |
| 36 | ON_CALL(*sensorMock, getLabeledSensorInfo()) |
| 37 | .WillByDefault(Return(sensorInfo)); |
| 38 | } |
| 39 | return utils::convContainer<std::shared_ptr<interfaces::Sensor>>( |
| 40 | result); |
| 41 | } |
| 42 | |
Krzysztof Grobelny | b564594 | 2020-09-29 11:52:45 +0200 | [diff] [blame] | 43 | MOCK_METHOD(Id, id, (), (const, override)); |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 44 | MOCK_METHOD(std::string, metadata, (), (const, override)); |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 45 | MOCK_METHOD(std::string, getName, (), (const, override)); |
Krzysztof Grobelny | b564594 | 2020-09-29 11:52:45 +0200 | [diff] [blame] | 46 | MOCK_METHOD(void, registerForUpdates, |
| 47 | (const std::weak_ptr<interfaces::SensorListener>&), (override)); |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 48 | MOCK_METHOD(void, unregisterFromUpdates, |
| 49 | (const std::weak_ptr<interfaces::SensorListener>&), (override)); |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 50 | MOCK_METHOD(LabeledSensorInfo, getLabeledSensorInfo, (), (const, override)); |
Krzysztof Grobelny | 7f06f61 | 2020-09-24 13:42:10 +0200 | [diff] [blame] | 51 | |
| 52 | const uint64_t mockId = generateUniqueMockId(); |
| 53 | |
| 54 | Id mockSensorId = Id("SensorMock", "", ""); |
Krzysztof Grobelny | 6ccfcbf | 2020-11-04 09:31:36 +0100 | [diff] [blame] | 55 | |
| 56 | private: |
| 57 | void initialize() |
| 58 | { |
| 59 | ON_CALL(*this, id()).WillByDefault(testing::Invoke([this] { |
| 60 | return this->mockSensorId; |
| 61 | })); |
| 62 | } |
Krzysztof Grobelny | 7f06f61 | 2020-09-24 13:42:10 +0200 | [diff] [blame] | 63 | }; |