Krzysztof Grobelny | 7f06f61 | 2020-09-24 13:42:10 +0200 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "interfaces/sensor.hpp" |
| 4 | #include "utils/generate_unique_mock_id.hpp" |
| 5 | |
| 6 | #include <gmock/gmock.h> |
| 7 | |
| 8 | class SensorMock : public interfaces::Sensor |
| 9 | { |
| 10 | public: |
Krzysztof Grobelny | 6ccfcbf | 2020-11-04 09:31:36 +0100 | [diff] [blame] | 11 | explicit SensorMock() |
| 12 | { |
| 13 | initialize(); |
| 14 | } |
| 15 | |
Krzysztof Grobelny | 7f06f61 | 2020-09-24 13:42:10 +0200 | [diff] [blame] | 16 | explicit SensorMock(Id sensorId) : mockSensorId(sensorId) |
| 17 | { |
Krzysztof Grobelny | 6ccfcbf | 2020-11-04 09:31:36 +0100 | [diff] [blame] | 18 | initialize(); |
Krzysztof Grobelny | 7f06f61 | 2020-09-24 13:42:10 +0200 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | static Id makeId(std::string_view service, std::string_view path) |
| 22 | { |
| 23 | return Id("SensorMock", service, path); |
| 24 | } |
| 25 | |
Krzysztof Grobelny | b564594 | 2020-09-29 11:52:45 +0200 | [diff] [blame] | 26 | MOCK_METHOD(Id, id, (), (const, override)); |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 27 | MOCK_METHOD(std::string, metadata, (), (const, override)); |
Krzysztof Grobelny | b564594 | 2020-09-29 11:52:45 +0200 | [diff] [blame] | 28 | MOCK_METHOD(void, registerForUpdates, |
| 29 | (const std::weak_ptr<interfaces::SensorListener>&), (override)); |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 30 | MOCK_METHOD(void, unregisterFromUpdates, |
| 31 | (const std::weak_ptr<interfaces::SensorListener>&), (override)); |
Krzysztof Grobelny | 7f06f61 | 2020-09-24 13:42:10 +0200 | [diff] [blame] | 32 | |
| 33 | const uint64_t mockId = generateUniqueMockId(); |
| 34 | |
| 35 | Id mockSensorId = Id("SensorMock", "", ""); |
Krzysztof Grobelny | 6ccfcbf | 2020-11-04 09:31:36 +0100 | [diff] [blame] | 36 | |
| 37 | private: |
| 38 | void initialize() |
| 39 | { |
| 40 | ON_CALL(*this, id()).WillByDefault(testing::Invoke([this] { |
| 41 | return this->mockSensorId; |
| 42 | })); |
| 43 | } |
Krzysztof Grobelny | 7f06f61 | 2020-09-24 13:42:10 +0200 | [diff] [blame] | 44 | }; |