blob: 9b7f28ba6a545936fdf3f36adda091b63fbad608 [file] [log] [blame]
Krzysztof Grobelny7f06f612020-09-24 13:42:10 +02001#pragma once
2
3#include "interfaces/sensor.hpp"
Szymon Dompke94f71c52021-12-10 07:16:33 +01004#include "utils/conv_container.hpp"
Krzysztof Grobelny7f06f612020-09-24 13:42:10 +02005#include "utils/generate_unique_mock_id.hpp"
6
7#include <gmock/gmock.h>
8
9class SensorMock : public interfaces::Sensor
10{
11 public:
Krzysztof Grobelny6ccfcbf2020-11-04 09:31:36 +010012 explicit SensorMock()
13 {
14 initialize();
15 }
16
Krzysztof Grobelny7f06f612020-09-24 13:42:10 +020017 explicit SensorMock(Id sensorId) : mockSensorId(sensorId)
18 {
Krzysztof Grobelny6ccfcbf2020-11-04 09:31:36 +010019 initialize();
Krzysztof Grobelny7f06f612020-09-24 13:42:10 +020020 }
21
22 static Id makeId(std::string_view service, std::string_view path)
23 {
24 return Id("SensorMock", service, path);
25 }
26
Szymon Dompke94f71c52021-12-10 07:16:33 +010027 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 Grobelnyb5645942020-09-29 11:52:45 +020043 MOCK_METHOD(Id, id, (), (const, override));
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010044 MOCK_METHOD(std::string, metadata, (), (const, override));
Szymon Dompke94f71c52021-12-10 07:16:33 +010045 MOCK_METHOD(std::string, getName, (), (const, override));
Krzysztof Grobelnyb5645942020-09-29 11:52:45 +020046 MOCK_METHOD(void, registerForUpdates,
47 (const std::weak_ptr<interfaces::SensorListener>&), (override));
Lukasz Kazmierczak7e098e92021-09-16 15:59:56 +020048 MOCK_METHOD(void, unregisterFromUpdates,
49 (const std::weak_ptr<interfaces::SensorListener>&), (override));
Szymon Dompke94f71c52021-12-10 07:16:33 +010050 MOCK_METHOD(LabeledSensorInfo, getLabeledSensorInfo, (), (const, override));
Krzysztof Grobelny7f06f612020-09-24 13:42:10 +020051
52 const uint64_t mockId = generateUniqueMockId();
53
54 Id mockSensorId = Id("SensorMock", "", "");
Krzysztof Grobelny6ccfcbf2020-11-04 09:31:36 +010055
56 private:
57 void initialize()
58 {
59 ON_CALL(*this, id()).WillByDefault(testing::Invoke([this] {
60 return this->mockSensorId;
61 }));
62 }
Krzysztof Grobelny7f06f612020-09-24 13:42:10 +020063};