xref: /openbmc/telemetry/tests/src/mocks/sensor_mock.hpp (revision 405c1e4bf8b993cb3800adead546e91b030ecb9b)
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:
11     explicit SensorMock()
12     {
13         initialize();
14     }
15 
16     explicit SensorMock(Id sensorId) : mockSensorId(sensorId)
17     {
18         initialize();
19     }
20 
21     static Id makeId(std::string_view service, std::string_view path)
22     {
23         return Id("SensorMock", service, path);
24     }
25 
26     MOCK_METHOD(Id, id, (), (const, override));
27     MOCK_METHOD(void, registerForUpdates,
28                 (const std::weak_ptr<interfaces::SensorListener>&), (override));
29 
30     const uint64_t mockId = generateUniqueMockId();
31 
32     Id mockSensorId = Id("SensorMock", "", "");
33 
34   private:
35     void initialize()
36     {
37         ON_CALL(*this, id()).WillByDefault(testing::Invoke([this] {
38             return this->mockSensorId;
39         }));
40     }
41 };
42