Coverage Report

Created: 2024-09-19 09:45

/proc/self/cwd/test/mocks/event/mocks.cc
Line
Count
Source (jump to first uncovered line)
1
#include "mocks.h"
2
3
#include "gmock/gmock.h"
4
#include "gtest/gtest.h"
5
6
using testing::_;
7
using testing::Assign;
8
using testing::DoAll;
9
using testing::Invoke;
10
using testing::NiceMock;
11
using testing::Return;
12
using testing::ReturnNew;
13
using testing::ReturnPointee;
14
using testing::SaveArg;
15
16
namespace Envoy {
17
namespace Event {
18
19
304k
MockDispatcher::MockDispatcher() : MockDispatcher("test_thread") {}
20
21
304k
MockDispatcher::MockDispatcher(const std::string& name) : name_(name) {
22
304k
  time_system_ = std::make_unique<GlobalTimeSystem>();
23
304k
  ON_CALL(*this, initializeStats(_, _)).WillByDefault(Return());
24
304k
  ON_CALL(*this, clearDeferredDeleteList()).WillByDefault(Invoke([this]() -> void {
25
5.74k
    to_delete_.clear();
26
5.74k
  }));
27
304k
  ON_CALL(*this, createTimer_(_)).WillByDefault(ReturnNew<NiceMock<Event::MockTimer>>());
28
304k
  ON_CALL(*this, createScaledTimer_(_, _)).WillByDefault(ReturnNew<NiceMock<Event::MockTimer>>());
29
304k
  ON_CALL(*this, createScaledTypedTimer_(_, _))
30
304k
      .WillByDefault(ReturnNew<NiceMock<Event::MockTimer>>());
31
304k
  ON_CALL(*this, post(_)).WillByDefault(Invoke([](PostCb cb) -> void { cb(); }));
32
33
304k
  ON_CALL(buffer_factory_, createBuffer_(_, _, _))
34
304k
      .WillByDefault(Invoke([](std::function<void()> below_low, std::function<void()> above_high,
35
376k
                               std::function<void()> above_overflow) -> Buffer::Instance* {
36
376k
        return new Buffer::WatermarkBuffer(below_low, above_high, above_overflow);
37
376k
      }));
38
304k
  ON_CALL(*this, isThreadSafe()).WillByDefault(Return(true));
39
304k
}
40
41
304k
MockDispatcher::~MockDispatcher() = default;
42
43
14.9k
MockTimer::MockTimer() {
44
14.9k
  ON_CALL(*this, enableTimer(_, _))
45
2.43M
      .WillByDefault(Invoke([&](const std::chrono::milliseconds&, const ScopeTrackedObject* scope) {
46
2.43M
        enabled_ = true;
47
2.43M
        scope_ = scope;
48
2.43M
      }));
49
14.9k
  ON_CALL(*this, disableTimer()).WillByDefault(Assign(&enabled_, false));
50
14.9k
  ON_CALL(*this, enabled()).WillByDefault(ReturnPointee(&enabled_));
51
14.9k
}
52
53
6.90k
MockTimer::MockTimer(MockDispatcher* dispatcher) : MockTimer() {
54
6.90k
  dispatcher_ = dispatcher;
55
6.90k
  EXPECT_CALL(*dispatcher, createTimer_(_))
56
6.90k
      .WillOnce(DoAll(SaveArg<0>(&callback_), Return(this)))
57
6.90k
      .RetiresOnSaturation();
58
6.90k
  ON_CALL(*this, enableTimer(_, _))
59
47.5k
      .WillByDefault(Invoke([&](const std::chrono::milliseconds&, const ScopeTrackedObject* scope) {
60
47.5k
        enabled_ = true;
61
47.5k
        scope_ = scope;
62
47.5k
      }));
63
6.90k
  ON_CALL(*this, disableTimer()).WillByDefault(Assign(&enabled_, false));
64
6.90k
  ON_CALL(*this, enabled()).WillByDefault(ReturnPointee(&enabled_));
65
6.90k
}
66
67
14.9k
MockTimer::~MockTimer() {
68
14.9k
  if (timer_destroyed_) {
69
0
    *timer_destroyed_ = true;
70
0
  }
71
14.9k
}
72
73
64
MockSchedulableCallback::~MockSchedulableCallback() {
74
64
  if (destroy_cb_) {
75
0
    destroy_cb_->Call();
76
0
  }
77
64
}
78
79
MockSchedulableCallback::MockSchedulableCallback(MockDispatcher* dispatcher,
80
                                                 std::function<void()> callback,
81
                                                 testing::MockFunction<void()>* destroy_cb)
82
64
    : dispatcher_(dispatcher), callback_(callback), destroy_cb_(destroy_cb) {
83
64
  ON_CALL(*this, scheduleCallbackCurrentIteration()).WillByDefault(Assign(&enabled_, true));
84
64
  ON_CALL(*this, scheduleCallbackNextIteration()).WillByDefault(Assign(&enabled_, true));
85
64
  ON_CALL(*this, cancel()).WillByDefault(Assign(&enabled_, false));
86
64
  ON_CALL(*this, enabled()).WillByDefault(ReturnPointee(&enabled_));
87
64
}
88
89
MockSchedulableCallback::MockSchedulableCallback(MockDispatcher* dispatcher,
90
                                                 testing::MockFunction<void()>* destroy_cb)
91
0
    : dispatcher_(dispatcher), destroy_cb_(destroy_cb) {
92
0
  EXPECT_CALL(*dispatcher, createSchedulableCallback_(_))
93
0
      .WillOnce(DoAll(SaveArg<0>(&callback_), Return(this)))
94
0
      .RetiresOnSaturation();
95
96
0
  ON_CALL(*this, scheduleCallbackCurrentIteration()).WillByDefault(Assign(&enabled_, true));
97
0
  ON_CALL(*this, scheduleCallbackNextIteration()).WillByDefault(Assign(&enabled_, true));
98
0
  ON_CALL(*this, cancel()).WillByDefault(Assign(&enabled_, false));
99
0
  ON_CALL(*this, enabled()).WillByDefault(ReturnPointee(&enabled_));
100
0
}
101
102
0
MockSignalEvent::MockSignalEvent(MockDispatcher* dispatcher) {
103
0
  EXPECT_CALL(*dispatcher, listenForSignal_(_, _))
104
0
      .WillOnce(DoAll(SaveArg<1>(&callback_), Return(this)))
105
0
      .RetiresOnSaturation();
106
0
}
107
108
0
MockSignalEvent::~MockSignalEvent() = default;
109
110
0
MockFileEvent::MockFileEvent() = default;
111
0
MockFileEvent::~MockFileEvent() = default;
112
113
} // namespace Event
114
} // namespace Envoy