blob: 2f81b60f1b95161248c7fbf7c638f510348e24b9 [file] [log] [blame]
Szymon Dompke94f71c52021-12-10 07:16:33 +01001#pragma once
2
3#include "interfaces/sensor.hpp"
4#include "interfaces/threshold.hpp"
5#include "utils/conv_container.hpp"
6
7#include <vector>
8
9#include <gmock/gmock.h>
10
11class ThresholdMock :
12 public interfaces::Threshold,
13 public std::enable_shared_from_this<ThresholdMock>
14{
15 public:
16 MOCK_METHOD(void, initialize, (), (override));
17
18 MOCK_METHOD(LabeledThresholdParam, getThresholdParam, (),
19 (const, override));
20
21 MOCK_METHOD(void, updateSensors, (Sensors newSensors), (override));
22
23 static std::vector<std::shared_ptr<interfaces::Threshold>>
24 makeThresholds(const LabeledTriggerThresholdParams& params)
25 {
26 using namespace testing;
27 std::vector<std::shared_ptr<NiceMock<ThresholdMock>>> result;
28 if (std::holds_alternative<std::vector<numeric::LabeledThresholdParam>>(
29 params))
30 {
31 auto unpackedParams =
32 std::get<std::vector<numeric::LabeledThresholdParam>>(params);
33 for (const auto& param : unpackedParams)
34 {
35 auto& thresholdMock = result.emplace_back(
36 std::make_shared<NiceMock<ThresholdMock>>());
37 ON_CALL(*thresholdMock, getThresholdParam())
38 .WillByDefault(Return(param));
39 }
40 }
41 else
42 {
43 auto unpackedParams =
44 std::get<std::vector<discrete::LabeledThresholdParam>>(params);
45 for (const auto& param : unpackedParams)
46 {
47 auto& thresholdMock = result.emplace_back(
48 std::make_shared<NiceMock<ThresholdMock>>());
49 ON_CALL(*thresholdMock, getThresholdParam())
50 .WillByDefault(Return(param));
51 }
52 if (unpackedParams.empty())
53 {
54 auto& thresholdMock = result.emplace_back(
55 std::make_shared<NiceMock<ThresholdMock>>());
56 ON_CALL(*thresholdMock, getThresholdParam())
57 .WillByDefault(Return(std::monostate{}));
58 }
59 }
60
61 return utils::convContainer<std::shared_ptr<interfaces::Threshold>>(
62 result);
63 }
64};