1 #pragma once
2 
3 #include "interfaces/sensor.hpp"
4 #include "utils/conv_container.hpp"
5 #include "utils/generate_unique_mock_id.hpp"
6 
7 #include <gmock/gmock.h>
8 
9 class SensorMock : public interfaces::Sensor
10 {
11   public:
12     explicit SensorMock()
13     {
14         initialize();
15     }
16 
17     explicit SensorMock(Id sensorId) : mockSensorId(sensorId)
18     {
19         initialize();
20     }
21 
22     static Id makeId(std::string_view service, std::string_view path)
23     {
24         return Id("SensorMock", service, path);
25     }
26 
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 
43     MOCK_METHOD(Id, id, (), (const, override));
44     MOCK_METHOD(std::string, metadata, (), (const, override));
45     MOCK_METHOD(std::string, getName, (), (const, override));
46     MOCK_METHOD(void, registerForUpdates,
47                 (const std::weak_ptr<interfaces::SensorListener>&), (override));
48     MOCK_METHOD(void, unregisterFromUpdates,
49                 (const std::weak_ptr<interfaces::SensorListener>&), (override));
50     MOCK_METHOD(LabeledSensorInfo, getLabeledSensorInfo, (), (const, override));
51 
52     const uint64_t mockId = generateUniqueMockId();
53 
54     Id mockSensorId = Id("SensorMock", "", "");
55 
56   private:
57     void initialize()
58     {
59         ON_CALL(*this, id()).WillByDefault(testing::Invoke([this] {
60             return this->mockSensorId;
61         }));
62     }
63 };
64