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