RTC Toolkit 5.1.0
Loading...
Searching...
No Matches
helpers.hpp
Go to the documentation of this file.
1
13#pragma once
14
15#include <gmock/gmock.h>
16#include <gtest/gtest.h>
17
21
22#include <iostream>
23#include <memory>
24#include <mutex>
25
26using ::testing::_; // NOLINT(google-global-names-in-headers)
27using ::testing::InSequence; // NOLINT(google-global-names-in-headers)
28using ::testing::NiceMock; // NOLINT(google-global-names-in-headers)
29using ::testing::Return; // NOLINT(google-global-names-in-headers)
30using ::testing::Sequence; // NOLINT(google-global-names-in-headers)
31
32using namespace rtctk::componentFramework; // NOLINT(google-global-names-in-headers)
33
34struct TestTopic {
35 std::uint32_t sample_id;
36};
37
40public:
41 template <class Rep, class Period>
42 static FakeReaderBase
43 MakeReader(const char* shm_name, std::chrono::duration<Rep, Period> timeout) {
45 }
46
47 explicit FakeReaderBase(const char* shm_name) {
48 m_sample.sample_id = 0;
49 m_size = 1000;
50 m_available = 500;
51 }
52
53 template <class Operation, class Rep, class Period>
54 std::pair<std::error_code, size_t>
55 Read(Operation&& op, size_t count, std::chrono::duration<Rep, Period> timeout) {
56 size_t i = 0;
57 for (; i < count and i < max_reads; i++) {
58 m_sample.sample_id += 1;
59 op(m_sample);
60 }
61 return {{}, i};
62 }
63
64 template <class Rep, class Period>
65 std::pair<std::error_code, size_t>
66 Skip(size_t count, std::chrono::duration<Rep, Period> timeout) {
67 const auto op = [](const TopicType& sample) {};
68 return Read(op, count, timeout);
69 }
70
71 std::error_code Reset() {
72 m_size = 1000;
73 m_available = 500;
74 return {};
75 }
76
77 size_t Size() {
78 return m_size;
79 }
80
81 size_t NumAvailable() {
82 return m_available;
83 }
84
85 TopicType m_sample;
86 size_t m_size;
88};
89
90// Partially specialise the base template to have FakeReader only take one template parameter.
91template <typename T>
93
94// This is a partially specialised class that limits the FakeReader::Read and FakeReader::Skip
95template <typename T>
97
98struct FakeServices {
100 services.Add<ComponentMetricsIf>(std::make_shared<FakeComponentMetrics>());
101 }
102
104 return services;
105 }
106
108};
Definition helpers.hpp:39
std::pair< std::error_code, size_t > Read(Operation &&op, size_t count, std::chrono::duration< Rep, Period > timeout)
Definition helpers.hpp:55
TopicType m_sample
Definition helpers.hpp:85
std::pair< std::error_code, size_t > Skip(size_t count, std::chrono::duration< Rep, Period > timeout)
Definition helpers.hpp:66
std::error_code Reset()
Definition helpers.hpp:71
size_t m_available
Definition helpers.hpp:87
FakeReaderBase(const char *shm_name)
Definition helpers.hpp:47
static FakeReaderBase MakeReader(const char *shm_name, std::chrono::duration< Rep, Period > timeout)
Definition helpers.hpp:43
size_t m_size
Definition helpers.hpp:86
size_t NumAvailable()
Definition helpers.hpp:81
size_t Size()
Definition helpers.hpp:77
Component metrics interface.
Definition componentMetricsIf.hpp:85
Container class that holds services of any type.
Definition serviceContainer.hpp:39
void Add(Service &&service, const std::string &name="")
Insert new service into the container.
Definition serviceContainer.hpp:62
Header file for ComponentMetricsIf.
Declaration of helper mock class for ComponentMetricsIf.
Definition commandReplier.cpp:22
elt::mal::future< std::string > InjectReqRepEvent(StateMachineEngine &engine)
Definition malEventInjector.hpp:23
A container that can hold any type of service.
Definition helpers.hpp:133
ServiceContainer & operator*()
Definition helpers.hpp:103
FakeServices()
Definition helpers.hpp:99
ServiceContainer services
Definition helpers.hpp:151
Definition helpers.hpp:34
std::uint32_t sample_id
Definition helpers.hpp:35