blob: 0730d9ecea08048ec93f343a70bea347ae3b2a90 [file] [log] [blame]
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +02001#pragma once
2
3#include "interfaces/report_factory.hpp"
4#include "mocks/report_mock.hpp"
Krzysztof Grobelnyd2238192020-12-02 09:27:28 +00005#include "params/report_params.hpp"
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +02006
7#include <gmock/gmock.h>
8
9class ReportFactoryMock : public interfaces::ReportFactory
10{
11 public:
12 ReportFactoryMock()
13 {
14 using namespace testing;
15
Krzysztof Grobelnyd2238192020-12-02 09:27:28 +000016 ON_CALL(*this,
17 make(A<boost::asio::yield_context&>(), _, _, _, _, _, _, _, _))
Wludzik, Jozefe2362792020-10-27 17:23:55 +010018 .WillByDefault(WithArgs<1>(Invoke([](const std::string& name) {
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020019 return std::make_unique<NiceMock<ReportMock>>(name);
20 })));
Krzysztof Grobelnyd2238192020-12-02 09:27:28 +000021 ON_CALL(*this, make(A<const std::string&>(), _, _, _, _, _, _, _, _))
22 .WillByDefault(WithArgs<0>(Invoke([](const std::string& name) {
23 return std::make_unique<NiceMock<ReportMock>>(name);
24 })));
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020025 }
26
Krzysztof Grobelnyd2238192020-12-02 09:27:28 +000027 MOCK_METHOD(std::unique_ptr<interfaces::Report>, make,
28 (boost::asio::yield_context&, const std::string&,
29 const std::string&, bool, bool, std::chrono::milliseconds,
30 const ReadingParameters&, interfaces::ReportManager&,
31 interfaces::JsonStorage&),
32 (const, override));
33 MOCK_METHOD(std::unique_ptr<interfaces::Report>, make,
34 (const std::string&, const std::string&, bool, bool,
35 std::chrono::milliseconds, const ReadingParameters&,
36 interfaces::ReportManager&, interfaces::JsonStorage&,
37 std::vector<LabeledMetricParameters>),
38 (const, override));
39
40 auto& expectMake(
41 const testing::Matcher<boost::asio::yield_context&>& yield,
42 std::optional<std::reference_wrapper<const ReportParams>> paramsRef,
43 const testing::Matcher<interfaces::ReportManager&>& rm,
44 const testing::Matcher<interfaces::JsonStorage&>& js)
45 {
46 if (paramsRef)
47 {
48 const ReportParams& params = *paramsRef;
49 return EXPECT_CALL(*this, make(yield, params.reportName(),
50 params.reportingType(),
51 params.emitReadingUpdate(),
52 params.logToMetricReportCollection(),
53 params.interval(),
54 params.readingParameters(), rm, js));
55 }
56 else
57 {
58 using testing::_;
59 return EXPECT_CALL(*this, make(yield, _, _, _, _, _, _, rm, js));
60 }
61 }
62
63 auto& expectMake(
64 std::optional<std::reference_wrapper<const ReportParams>> paramsRef,
65 const testing::Matcher<interfaces::ReportManager&>& rm,
66 const testing::Matcher<interfaces::JsonStorage&>& js,
67 const testing::Matcher<std::vector<LabeledMetricParameters>>& lrp)
68 {
69 if (paramsRef)
70 {
71 const ReportParams& params = *paramsRef;
72 return EXPECT_CALL(*this,
73 make(params.reportName(), params.reportingType(),
74 params.emitReadingUpdate(),
75 params.logToMetricReportCollection(),
76 params.interval(),
77 params.readingParameters(), rm, js, lrp));
78 }
79 else
80 {
81 using testing::_;
82 return EXPECT_CALL(*this, make(_, _, _, _, _, _, rm, js, lrp));
83 }
84 }
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020085};