19 #include <gtest/gtest.h> 20 #include <gmock/gmock.h> 26 using namespace ::testing;
32 MOCK_METHOD0(clear,
void (
void));
33 MOCK_CONST_METHOD0(size,
size_t (
void));
34 MOCK_CONST_METHOD0(empty,
bool (
void));
35 MOCK_METHOD2(dequeue,
bool (std::string& data,
36 const std::chrono::microseconds& duration));
37 MOCK_METHOD1(enqueue,
bool (std::string& data));
38 MOCK_METHOD2(tryEnqueue,
39 bool (std::string& data,
40 const std::chrono::microseconds &duration));
41 inline bool enqueue(std::string&&)
override {
47 const std::chrono::microseconds&)
override 49 return enqueue(value);
58 status_monitor_ = status_monitor;
70 const std::chrono::microseconds&)
72 data = std::move(actual);
76 using std::placeholders::_1;
77 using std::placeholders::_2;
79 TEST(queue_demux_test, Sanity) {
83 TEST(queue_demux_test, single_source_test)
85 auto observed_queue = std::make_shared<MockObservedQueue>();
86 std::shared_ptr<StatusMonitor> monitor;
87 std::string actual =
"test_string";
88 EXPECT_CALL(*observed_queue, dequeue(_, _))
89 .WillOnce(Invoke([=](
auto && arg1,
auto && arg2) {
return dequeueFunc(arg1, actual, arg2); }));
93 EXPECT_TRUE(queue_monitor.
dequeue(data, std::chrono::microseconds(0)));
94 EXPECT_EQ(actual, data);
97 TEST(queue_demux_test, multi_source_test)
100 auto low_priority_queue = std::make_shared<StrictMock<MockObservedQueue>>();
101 EXPECT_CALL(*low_priority_queue, dequeue(_, _))
102 .WillOnce(Invoke([=](
auto && arg1,
auto && arg2) {
return dequeueFunc(arg1,
"low_priority", arg2); }))
103 .WillRepeatedly(Return(
false));
106 auto high_priority_observed_queue = std::make_shared<StrictMock<MockObservedQueue>>();
107 std::shared_ptr<StatusMonitor> monitor;
108 EXPECT_CALL(*high_priority_observed_queue, dequeue(_, _))
109 .WillOnce(Invoke([=](
auto && arg1,
auto && arg2) {
return dequeueFunc(arg1,
"high_priority", arg2); }))
110 .WillRepeatedly(Return(
false));;
113 EXPECT_TRUE(queue_monitor.
dequeue(data, std::chrono::microseconds(0)));
114 EXPECT_EQ(
"high_priority", data);
115 EXPECT_TRUE(queue_monitor.
dequeue(data, std::chrono::microseconds(0)));
116 EXPECT_EQ(
"low_priority", data);
117 EXPECT_FALSE(queue_monitor.
dequeue(data, std::chrono::microseconds(0)));
120 int main(
int argc,
char ** argv)
122 testing::InitGoogleMock(&argc, argv);
123 return RUN_ALL_TESTS();
bool dequeueFunc(std::string &data, std::string actual, const std::chrono::microseconds &)
bool enqueue(std::string &&) override
bool tryEnqueue(std::string &&value, const std::chrono::microseconds &) override
void setStatusMonitor(std::shared_ptr< StatusMonitor > status_monitor) override
void addSource(std::shared_ptr< IObservedQueue< T >>observed_queue, PriorityOptions priority_options) override
TEST(queue_demux_test, Sanity)
int main(int argc, char **argv)
bool dequeue(T &data, const std::chrono::microseconds &duration) override
std::shared_ptr< StatusMonitor > status_monitor_