mock_appender.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021 Pilz GmbH & Co. KG
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef MOCK_APPENDER_H
18 #define MOCK_APPENDER_H
19 
20 #include <gmock/gmock.h>
21 
22 #include "ros/console_impl.h"
23 #include <ros/console.h>
24 
25 #include "log4cxx/appenderskeleton.h"
26 #include "log4cxx/level.h"
27 
28 namespace pilz_testutils
29 {
38 class MockAppender : public log4cxx::AppenderSkeleton
39 {
40 public:
42  {
43  close();
44  }
45 
46 public:
47  // Indirection via "internal_append" needed to avoid "override" warning
48  // message from compiler
49  void append(const log4cxx::spi::LoggingEventPtr& a, log4cxx::helpers::Pool& b) override
50  {
51  internal_append(a, b);
52  }
53 
54  MOCK_METHOD2(internal_append, void(const log4cxx::spi::LoggingEventPtr&, log4cxx::helpers::Pool&));
55 
56  log4cxx::LogString getName() const override
57  {
58  return "MockAppender";
59  }
60 
61  void close() override
62  {
63  }
64 
65  // LCOV_EXCL_START required by Base class
66  bool requiresLayout() const override
67  {
68  return false;
69  }
70  // LCOV_EXCL_STOP
71 };
72 
73 #define GENERATE_LOGMESSAGE_MATCHER_P(level) \
74  MATCHER_P(Is##level, msg, std::string(#level " \"") + msg + "\"") \
75  { \
76  return arg->getLevel()->toInt() == log4cxx::Level::level##_INT && std::string(msg) == arg->getMessage(); \
77  }
78 
84 
85 #define EXPECT_LOG(logger, level, msg) \
86  EXPECT_EQ((logger).getName(), "MockAppender"); \
87  EXPECT_CALL(logger, internal_append(Is##level(msg), ::testing::_))
88 
89 } // namespace pilz_testutils
90 
91 namespace log4cxx
92 {
93 namespace spi
94 {
95 // LCOV_EXCL_START
96 void PrintTo(const LoggingEventPtr& logging_event, std::ostream* os)
97 {
98  *os << logging_event->getLevel()->toString() << " \"" << logging_event->getMessage() << "\"";
99 }
100 // LCOV_EXCL_STOP
101 } // namespace spi
102 } // namespace log4cxx
103 
104 #endif // MOCK_APPENDER_H
bool requiresLayout() const override
Definition: mock_appender.h:66
Mocked version of a log4cxx::Appender to be used by gtest.
Definition: mock_appender.h:38
#define GENERATE_LOGMESSAGE_MATCHER_P(level)
Definition: mock_appender.h:73
MOCK_METHOD2(internal_append, void(const log4cxx::spi::LoggingEventPtr &, log4cxx::helpers::Pool &))
void PrintTo(const XmlRpcClientForTest::ClientConnectionState &state, ::std::ostream *os)
log4cxx::LogString getName() const override
Definition: mock_appender.h:56
void append(const log4cxx::spi::LoggingEventPtr &a, log4cxx::helpers::Pool &b) override
Definition: mock_appender.h:49


pilz_testutils
Author(s):
autogenerated on Mon Feb 28 2022 23:13:41