2 #include <gtest/gtest.h> 6 #include "std_srvs/Empty.h" 7 #include <log4cxx/appenderskeleton.h> 10 # include <log4cxx/helpers/transcoder.h> 18 void append(
const log4cxx::spi::LoggingEventPtr& event, log4cxx::helpers::Pool&)
20 list.push_back(event);
38 const std::list<log4cxx::spi::LoggingEventPtr>&
getList()
const 44 std::list<log4cxx::spi::LoggingEventPtr>
list;
48 static const char EXCEPTION[] =
"custom exception message";
56 static const char SERVICE[] =
"service_exception";
66 log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(
"ros.roscpp");
68 logger->addAppender(appender);
72 bool success = client.
call(srv);
73 ASSERT_FALSE(success);
75 bool found_error_output =
false;
76 const std::list<log4cxx::spi::LoggingEventPtr>&
list = appender->getList();
77 for (std::list<log4cxx::spi::LoggingEventPtr>::const_iterator it = list.begin(); it != list.end(); it++)
80 LOG4CXX_ENCODE_CHAR(tmpstr, (*it)->getMessage());
81 const std::string& msg = tmpstr;
83 const log4cxx::LogString& msg = (*it)->getMessage();
85 size_t pos_error = msg.find(
"Service call failed:");
86 size_t pos_exception = msg.find(
EXCEPTION);
87 if (pos_error != std::string::npos && pos_exception != std::string::npos)
89 found_error_output =
true;
92 ASSERT_TRUE(found_error_output);
95 int main(
int argc,
char **argv)
97 testing::InitGoogleTest(&argc, argv);
98 ros::init(argc, argv,
"service_exception");
99 return RUN_ALL_TESTS();
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
static const char EXCEPTION[]
const std::list< log4cxx::spi::LoggingEventPtr > & getList() const
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool throwingService(std_srvs::Empty::Request &, std_srvs::Empty::Request &)
bool call(MReq &req, MRes &res)
std::list< log4cxx::spi::LoggingEventPtr > list
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
bool requiresLayout() const
log4cxx::helpers::ObjectPtrT< ListAppender > ListAppenderPtr
static const char SERVICE[]
void append(const log4cxx::spi::LoggingEventPtr &event, log4cxx::helpers::Pool &)
int main(int argc, char **argv)
TEST(roscpp, ServiceThrowingException)