utest.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include "ros/console.h"
31 
32 #include "log4cxx/appenderskeleton.h"
33 #include "log4cxx/spi/loggingevent.h"
34 #ifdef _MSC_VER
35  // Have to be able to encode wchar LogStrings on windows.
36  #include "log4cxx/helpers/transcoder.h"
37 #endif
38 
39 #include <vector>
40 #include <stdexcept>
41 
42 #include <gtest/gtest.h>
43 
44 #include <boost/shared_array.hpp>
45 #include <boost/regex.hpp>
46 
47 class TestAppender : public log4cxx::AppenderSkeleton
48 {
49 public:
50  struct Info
51  {
52  log4cxx::LevelPtr level_;
53  std::string message_;
54  std::string logger_name_;
55  };
56 
57  typedef std::vector<Info> V_Info;
58 
59  V_Info info_;
60 
61 protected:
62  virtual void append(const log4cxx::spi::LoggingEventPtr& event, log4cxx::helpers::Pool&)
63  {
64  Info info;
65  info.level_ = event->getLevel();
66 #ifdef _MSC_VER
67  LOG4CXX_ENCODE_CHAR(msgstr, event->getMessage()); // has to handle LogString with wchar types.
68  info.message_ = msgstr; // msgstr gets instantiated inside the LOG4CXX_ENCODE_CHAR macro
69 
70  LOG4CXX_ENCODE_CHAR(loggerstr, event->getLoggerName()); // has to handle LogString with wchar types.
71  info.logger_name_ = loggerstr; // loggerstr gets instantiated inside the LOG4CXX_ENCODE_CHAR macro
72 #else
73  info.message_ = event->getMessage();
74  info.logger_name_ = event->getLoggerName();
75 #endif
76 
77  info_.push_back( info );
78  }
79 
80  virtual void close()
81  {
82  }
83  virtual bool requiresLayout() const
84  {
85  return false;
86  }
87 };
88 
89 class TestAppenderWithThrow : public log4cxx::AppenderSkeleton
90 {
91 protected:
92  virtual void append(const log4cxx::spi::LoggingEventPtr&, log4cxx::helpers::Pool&)
93  {
94  throw std::runtime_error("This should be caught");
95  }
96 
97  virtual void close()
98  {
99  }
100  virtual bool requiresLayout() const
101  {
102  return false;
103  }
104 };
105 
107 {
108  BasicFilter(bool enabled)
109  : enabled_(enabled)
110  {}
111 
112  inline virtual bool isEnabled() { return enabled_; };
113 
114  bool enabled_;
115 };
116 
117 BasicFilter g_filter(true);
118 
119 #define DEFINE_COND_TESTS(name, macro_base, level, log4cxx_level) \
120  TEST(RosConsole, name##Cond) \
121  { \
122  TestAppender* appender = new TestAppender; \
123  log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \
124  macro_base##_COND(true, "Testing %d %d %d", 1, 2, 3); \
125  macro_base##_COND(false, "Testing %d %d %d", 1, 2, 3); \
126  ASSERT_EQ((int)appender->info_.size(), 1); \
127  EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \
128  EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \
129  log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \
130  } \
131  TEST(RosConsole, name##NamedCond) \
132  { \
133  TestAppender* appender = new TestAppender; \
134  log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \
135  macro_base##_COND_NAMED(true, "test", "Testing %d %d %d", 1, 2, 3); \
136  macro_base##_COND_NAMED(false, "test", "Testing %d %d %d", 1, 2, 3); \
137  ASSERT_EQ((int)appender->info_.size(), 1); \
138  EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \
139  EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \
140  EXPECT_STREQ(appender->info_[0].logger_name_.c_str(), ROSCONSOLE_ROOT_LOGGER_NAME".rosconsole.test"); \
141  log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \
142  } \
143  TEST(RosConsole, name##StreamCond) \
144  { \
145  TestAppender* appender = new TestAppender; \
146  log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \
147  macro_base##_STREAM_COND(true, "Testing " << 1 << " " << 2 << " " << 3); \
148  macro_base##_STREAM_COND(false, "Testing " << 1 << " " << 2 << " " << 3); \
149  ASSERT_EQ((int)appender->info_.size(), 1); \
150  EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \
151  EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \
152  log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \
153  } \
154  TEST(RosConsole, name##StreamCondNamed) \
155  { \
156  TestAppender* appender = new TestAppender; \
157  log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \
158  macro_base##_STREAM_COND_NAMED(true, "test", "Testing " << 1 << " " << 2 << " " << 3); \
159  macro_base##_STREAM_COND_NAMED(false, "test", "Testing " << 1 << " " << 2 << " " << 3); \
160  ASSERT_EQ((int)appender->info_.size(), 1); \
161  EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \
162  EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \
163  EXPECT_STREQ(appender->info_[0].logger_name_.c_str(), ROSCONSOLE_ROOT_LOGGER_NAME".rosconsole.test"); \
164  log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \
165  }
166 
167 #define DEFINE_ONCE_TESTS(name, macro_base, level, log4cxx_level) \
168  TEST(RosConsole, name##Once) \
169  { \
170  TestAppender* appender = new TestAppender; \
171  log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \
172  macro_base##_ONCE("Testing %d %d %d", 1, 2, 3); \
173  ASSERT_EQ((int)appender->info_.size(), 1); \
174  EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \
175  EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \
176  log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \
177  } \
178  TEST(RosConsole, name##NamedOnce) \
179  { \
180  TestAppender* appender = new TestAppender; \
181  log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \
182  macro_base##_ONCE_NAMED("test", "Testing %d %d %d", 1, 2, 3); \
183  ASSERT_EQ((int)appender->info_.size(), 1); \
184  EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \
185  EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \
186  EXPECT_STREQ(appender->info_[0].logger_name_.c_str(), ROSCONSOLE_ROOT_LOGGER_NAME".rosconsole.test"); \
187  log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \
188  } \
189  TEST(RosConsole, name##StreamOnce) \
190  { \
191  TestAppender* appender = new TestAppender; \
192  log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \
193  macro_base##_STREAM_ONCE("Testing " << 1 << " " << 2 << " " << 3); \
194  ASSERT_EQ((int)appender->info_.size(), 1); \
195  EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \
196  EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \
197  log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \
198  } \
199  TEST(RosConsole, name##StreamOnceNamed) \
200  { \
201  TestAppender* appender = new TestAppender; \
202  log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \
203  macro_base##_STREAM_ONCE_NAMED("test", "Testing " << 1 << " " << 2 << " " << 3); \
204  ASSERT_EQ((int)appender->info_.size(), 1); \
205  EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \
206  EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \
207  EXPECT_STREQ(appender->info_[0].logger_name_.c_str(), ROSCONSOLE_ROOT_LOGGER_NAME".rosconsole.test"); \
208  log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \
209  }
210 
211 #define DEFINE_THROTTLE_TESTS(name, macro_base, level, log4cxx_level) \
212  TEST(RosConsole, name##Throttle) \
213  { \
214  TestAppender* appender = new TestAppender; \
215  log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \
216  macro_base##_THROTTLE(0.5, "Testing %d %d %d", 1, 2, 3); \
217  ASSERT_EQ((int)appender->info_.size(), 1); \
218  EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \
219  EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \
220  log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \
221  } \
222  TEST(RosConsole, name##NamedThrottle) \
223  { \
224  TestAppender* appender = new TestAppender; \
225  log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \
226  macro_base##_THROTTLE_NAMED(0.5, "test", "Testing %d %d %d", 1, 2, 3); \
227  ASSERT_EQ((int)appender->info_.size(), 1); \
228  EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \
229  EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \
230  EXPECT_STREQ(appender->info_[0].logger_name_.c_str(), ROSCONSOLE_ROOT_LOGGER_NAME".rosconsole.test"); \
231  log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \
232  } \
233  TEST(RosConsole, name##StreamThrottle) \
234  { \
235  TestAppender* appender = new TestAppender; \
236  log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \
237  macro_base##_STREAM_THROTTLE(0.5, "Testing " << 1 << " " << 2 << " " << 3); \
238  ASSERT_EQ((int)appender->info_.size(), 1); \
239  EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \
240  EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \
241  log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \
242  } \
243  TEST(RosConsole, name##StreamThrottleNamed) \
244  { \
245  TestAppender* appender = new TestAppender; \
246  log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \
247  macro_base##_STREAM_THROTTLE_NAMED(0.5, "test", "Testing " << 1 << " " << 2 << " " << 3); \
248  ASSERT_EQ((int)appender->info_.size(), 1); \
249  EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \
250  EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \
251  EXPECT_STREQ(appender->info_[0].logger_name_.c_str(), ROSCONSOLE_ROOT_LOGGER_NAME".rosconsole.test"); \
252  log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \
253  }
254 
255 #define DEFINE_FILTER_TESTS(name, macro_base, level, log4cxx_level) \
256  TEST(RosConsole, name##Filter) \
257  { \
258  TestAppender* appender = new TestAppender; \
259  log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \
260  macro_base##_FILTER(&g_filter, "Testing %d %d %d", 1, 2, 3); \
261  ASSERT_EQ((int)appender->info_.size(), 1); \
262  EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \
263  EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \
264  log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \
265  } \
266  TEST(RosConsole, name##NamedFilter) \
267  { \
268  TestAppender* appender = new TestAppender; \
269  log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \
270  macro_base##_FILTER_NAMED(&g_filter, "test", "Testing %d %d %d", 1, 2, 3); \
271  ASSERT_EQ((int)appender->info_.size(), 1); \
272  EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \
273  EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \
274  EXPECT_STREQ(appender->info_[0].logger_name_.c_str(), ROSCONSOLE_ROOT_LOGGER_NAME".rosconsole.test"); \
275  log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \
276  } \
277  TEST(RosConsole, name##StreamFilter) \
278  { \
279  TestAppender* appender = new TestAppender; \
280  log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \
281  macro_base##_STREAM_FILTER(&g_filter, "Testing " << 1 << " " << 2 << " " << 3); \
282  ASSERT_EQ((int)appender->info_.size(), 1); \
283  EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \
284  EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \
285  log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \
286  } \
287  TEST(RosConsole, name##StreamFilterNamed) \
288  { \
289  TestAppender* appender = new TestAppender; \
290  log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \
291  macro_base##_STREAM_FILTER_NAMED(&g_filter, "test", "Testing " << 1 << " " << 2 << " " << 3); \
292  ASSERT_EQ((int)appender->info_.size(), 1); \
293  EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \
294  EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \
295  EXPECT_STREQ(appender->info_[0].logger_name_.c_str(), ROSCONSOLE_ROOT_LOGGER_NAME".rosconsole.test"); \
296  log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \
297  }
298 
299 #define DEFINE_LEVEL_TESTS(name, macro_base, level, log4cxx_level) \
300  TEST(RosConsole, name) \
301  { \
302  TestAppender* appender = new TestAppender; \
303  log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \
304  macro_base("Testing %d %d %d", 1, 2, 3); \
305  ASSERT_EQ((int)appender->info_.size(), 1); \
306  EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \
307  EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \
308  log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \
309  } \
310  TEST(RosConsole, name##Named) \
311  { \
312  TestAppender* appender = new TestAppender; \
313  log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \
314  macro_base##_NAMED("test", "Testing %d %d %d", 1, 2, 3); \
315  ASSERT_EQ((int)appender->info_.size(), 1); \
316  EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \
317  EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \
318  EXPECT_STREQ(appender->info_[0].logger_name_.c_str(), ROSCONSOLE_ROOT_LOGGER_NAME".rosconsole.test"); \
319  log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \
320  } \
321  TEST(RosConsole, name##Stream) \
322  { \
323  TestAppender* appender = new TestAppender; \
324  log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \
325  macro_base##_STREAM("Testing " << 1 << " " << 2 << " " << 3); \
326  ASSERT_EQ((int)appender->info_.size(), 1); \
327  EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \
328  EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \
329  log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \
330  } \
331  TEST(RosConsole, name##StreamNamed) \
332  { \
333  TestAppender* appender = new TestAppender; \
334  log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \
335  macro_base##_STREAM_NAMED("test", "Testing " << 1 << " " << 2 << " " << 3); \
336  ASSERT_EQ((int)appender->info_.size(), 1); \
337  EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \
338  EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \
339  EXPECT_STREQ(appender->info_[0].logger_name_.c_str(), ROSCONSOLE_ROOT_LOGGER_NAME".rosconsole.test"); \
340  log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \
341  } \
342  DEFINE_COND_TESTS(name, macro_base, level, log4cxx_level) \
343  DEFINE_ONCE_TESTS(name, macro_base, level, log4cxx_level) \
344  DEFINE_THROTTLE_TESTS(name, macro_base, level, log4cxx_level) \
345  DEFINE_FILTER_TESTS(name, macro_base, level, log4cxx_level)
346 
347 DEFINE_LEVEL_TESTS(debug, ROS_DEBUG, ros::console::levels::Debug, log4cxx::Level::getDebug())
348 DEFINE_LEVEL_TESTS(info, ROS_INFO, ros::console::levels::Info, log4cxx::Level::getInfo())
349 DEFINE_LEVEL_TESTS(warn, ROS_WARN, ros::console::levels::Warn, log4cxx::Level::getWarn())
350 DEFINE_LEVEL_TESTS(error, ROS_ERROR, ros::console::levels::Error, log4cxx::Level::getError())
351 DEFINE_LEVEL_TESTS(fatal, ROS_FATAL, ros::console::levels::Fatal, log4cxx::Level::getFatal())
352 
353 TEST(RosConsole, loggingLevels)
354 {
355  log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME);
356 
357  TestAppender* appender = new TestAppender;
358  logger->addAppender( appender );
359 
360  int pre_count = 0;
361  int post_count = 0;
362 
363  {
364  logger->setLevel( log4cxx::Level::getInfo() );
365  pre_count = appender->info_.size();
366  ROS_DEBUG("test");
367  ROS_INFO("test");
368  ROS_WARN("test");
369  ROS_ERROR("test");
370  ROS_FATAL("test");
371  post_count = appender->info_.size();
372  EXPECT_EQ(post_count, pre_count + 4);
373 
374  logger->setLevel( log4cxx::Level::getWarn() );
375  pre_count = appender->info_.size();
376  ROS_DEBUG("test");
377  ROS_INFO("test");
378  ROS_WARN("test");
379  ROS_ERROR("test");
380  ROS_FATAL("test");
381  post_count = appender->info_.size();
382  EXPECT_EQ(post_count, pre_count + 3);
383 
384  logger->setLevel( log4cxx::Level::getError() );
385  pre_count = appender->info_.size();
386  ROS_DEBUG("test");
387  ROS_INFO("test");
388  ROS_WARN("test");
389  ROS_ERROR("test");
390  ROS_FATAL("test");
391  post_count = appender->info_.size();
392  EXPECT_EQ(post_count, pre_count + 2);
393 
394  logger->setLevel( log4cxx::Level::getFatal() );
395  pre_count = appender->info_.size();
396  ROS_DEBUG("test");
397  ROS_INFO("test");
398  ROS_WARN("test");
399  ROS_ERROR("test");
400  ROS_FATAL("test");
401  post_count = appender->info_.size();
402  EXPECT_EQ(post_count, pre_count + 1);
403 
404  logger->setLevel( log4cxx::Level::getOff() );
405  pre_count = appender->info_.size();
406  ROS_DEBUG("test");
407  ROS_INFO("test");
408  ROS_WARN("test");
409  ROS_ERROR("test");
410  ROS_FATAL("test");
411  post_count = appender->info_.size();
412  EXPECT_EQ(post_count, pre_count);
413  }
414 
415  {
416  logger->setLevel( log4cxx::Level::getInfo() );
417  pre_count = appender->info_.size();
418  ROS_DEBUG_STREAM("test");
419  ROS_INFO_STREAM("test");
420  ROS_WARN_STREAM("test");
421  ROS_ERROR_STREAM("test");
422  ROS_FATAL_STREAM("test");
423  post_count = appender->info_.size();
424  EXPECT_EQ(post_count, pre_count + 4);
425 
426  logger->setLevel( log4cxx::Level::getWarn() );
427  pre_count = appender->info_.size();
428  ROS_DEBUG_STREAM("test");
429  ROS_INFO_STREAM("test");
430  ROS_WARN_STREAM("test");
431  ROS_ERROR_STREAM("test");
432  ROS_FATAL_STREAM("test");
433  post_count = appender->info_.size();
434  EXPECT_EQ(post_count, pre_count + 3);
435 
436  logger->setLevel( log4cxx::Level::getError() );
437  pre_count = appender->info_.size();
438  ROS_DEBUG_STREAM("test");
439  ROS_INFO_STREAM("test");
440  ROS_WARN_STREAM("test");
441  ROS_ERROR_STREAM("test");
442  ROS_FATAL_STREAM("test");
443  post_count = appender->info_.size();
444  EXPECT_EQ(post_count, pre_count + 2);
445 
446  logger->setLevel( log4cxx::Level::getFatal() );
447  pre_count = appender->info_.size();
448  ROS_DEBUG_STREAM("test");
449  ROS_INFO_STREAM("test");
450  ROS_WARN_STREAM("test");
451  ROS_ERROR_STREAM("test");
452  ROS_FATAL_STREAM("test");
453  post_count = appender->info_.size();
454  EXPECT_EQ(post_count, pre_count + 1);
455 
456  logger->setLevel( log4cxx::Level::getOff() );
457  pre_count = appender->info_.size();
458  ROS_DEBUG_STREAM("test");
459  ROS_INFO_STREAM("test");
460  ROS_WARN_STREAM("test");
461  ROS_ERROR_STREAM("test");
462  ROS_FATAL_STREAM("test");
463  post_count = appender->info_.size();
464  EXPECT_EQ(post_count, pre_count);
465  }
466 
467  {
468  logger->setLevel( log4cxx::Level::getInfo() );
469  pre_count = appender->info_.size();
470  ROS_DEBUG_NAMED("test_name", "test");
471  ROS_INFO_NAMED("test_name", "test");
472  ROS_WARN_NAMED("test_name", "test");
473  ROS_ERROR_NAMED("test_name", "test");
474  ROS_FATAL_NAMED("test_name", "test");
475  post_count = appender->info_.size();
476  EXPECT_EQ(post_count, pre_count + 4);
477 
478  logger->setLevel( log4cxx::Level::getWarn() );
479  pre_count = appender->info_.size();
480  ROS_DEBUG_NAMED("test_name", "test");
481  ROS_INFO_NAMED("test_name", "test");
482  ROS_WARN_NAMED("test_name", "test");
483  ROS_ERROR_NAMED("test_name", "test");
484  ROS_FATAL_NAMED("test_name", "test");
485  post_count = appender->info_.size();
486  EXPECT_EQ(post_count, pre_count + 3);
487 
488  logger->setLevel( log4cxx::Level::getError() );
489  pre_count = appender->info_.size();
490  ROS_DEBUG_NAMED("test_name", "test");
491  ROS_INFO_NAMED("test_name", "test");
492  ROS_WARN_NAMED("test_name", "test");
493  ROS_ERROR_NAMED("test_name", "test");
494  ROS_FATAL_NAMED("test_name", "test");
495  post_count = appender->info_.size();
496  EXPECT_EQ(post_count, pre_count + 2);
497 
498  logger->setLevel( log4cxx::Level::getFatal() );
499  pre_count = appender->info_.size();
500  ROS_DEBUG_NAMED("test_name", "test");
501  ROS_INFO_NAMED("test_name", "test");
502  ROS_WARN_NAMED("test_name", "test");
503  ROS_ERROR_NAMED("test_name", "test");
504  ROS_FATAL_NAMED("test_name", "test");
505  post_count = appender->info_.size();
506  EXPECT_EQ(post_count, pre_count + 1);
507 
508  logger->setLevel( log4cxx::Level::getOff() );
509  pre_count = appender->info_.size();
510  ROS_DEBUG_NAMED("test_name", "test");
511  ROS_INFO_NAMED("test_name", "test");
512  ROS_WARN_NAMED("test_name", "test");
513  ROS_ERROR_NAMED("test_name", "test");
514  ROS_FATAL_NAMED("test_name", "test");
515  post_count = appender->info_.size();
516  EXPECT_EQ(post_count, pre_count);
517  }
518 
519  {
520  logger->setLevel( log4cxx::Level::getInfo() );
521  pre_count = appender->info_.size();
522  ROS_DEBUG_STREAM_NAMED("test_name", "test");
523  ROS_INFO_STREAM_NAMED("test_name", "test");
524  ROS_WARN_STREAM_NAMED("test_name", "test");
525  ROS_ERROR_STREAM_NAMED("test_name", "test");
526  ROS_FATAL_STREAM_NAMED("test_name", "test");
527  post_count = appender->info_.size();
528  EXPECT_EQ(post_count, pre_count + 4);
529 
530  logger->setLevel( log4cxx::Level::getWarn() );
531  pre_count = appender->info_.size();
532  ROS_DEBUG_STREAM_NAMED("test_name", "test");
533  ROS_INFO_STREAM_NAMED("test_name", "test");
534  ROS_WARN_STREAM_NAMED("test_name", "test");
535  ROS_ERROR_STREAM_NAMED("test_name", "test");
536  ROS_FATAL_STREAM_NAMED("test_name", "test");
537  post_count = appender->info_.size();
538  EXPECT_EQ(post_count, pre_count + 3);
539 
540  logger->setLevel( log4cxx::Level::getError() );
541  pre_count = appender->info_.size();
542  ROS_DEBUG_STREAM_NAMED("test_name", "test");
543  ROS_INFO_STREAM_NAMED("test_name", "test");
544  ROS_WARN_STREAM_NAMED("test_name", "test");
545  ROS_ERROR_STREAM_NAMED("test_name", "test");
546  ROS_FATAL_STREAM_NAMED("test_name", "test");
547  post_count = appender->info_.size();
548  EXPECT_EQ(post_count, pre_count + 2);
549 
550  logger->setLevel( log4cxx::Level::getFatal() );
551  pre_count = appender->info_.size();
552  ROS_DEBUG_STREAM_NAMED("test_name", "test");
553  ROS_INFO_STREAM_NAMED("test_name", "test");
554  ROS_WARN_STREAM_NAMED("test_name", "test");
555  ROS_ERROR_STREAM_NAMED("test_name", "test");
556  ROS_FATAL_STREAM_NAMED("test_name", "test");
557  post_count = appender->info_.size();
558  EXPECT_EQ(post_count, pre_count + 1);
559 
560  logger->setLevel( log4cxx::Level::getOff() );
561  pre_count = appender->info_.size();
562  ROS_DEBUG_STREAM_NAMED("test_name", "test");
563  ROS_INFO_STREAM_NAMED("test_name", "test");
564  ROS_WARN_STREAM_NAMED("test_name", "test");
565  ROS_ERROR_STREAM_NAMED("test_name", "test");
566  ROS_FATAL_STREAM_NAMED("test_name", "test");
567  post_count = appender->info_.size();
568  EXPECT_EQ(post_count, pre_count);
569  }
570 
571  logger->removeAppender( appender );
572 }
573 
574 TEST(RosConsole, changingLevel)
575 {
576  log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME);
577 
578  TestAppender* appender = new TestAppender;
579  logger->addAppender( appender );
580 
581  logger->setLevel( log4cxx::Level::getError() );
583  {
585  }
586 
587  EXPECT_EQ((int)appender->info_.size(), 2);
588 
589  logger->removeAppender( appender );
590 
591  logger->setLevel( log4cxx::Level::getDebug() );
592 }
593 
594 TEST(RosConsole, changingLoggerLevel)
595 {
596  log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME);
597 
598  TestAppender* appender = new TestAppender;
599  logger->addAppender( appender );
600 
601  logger->setLevel(log4cxx::Level::getDebug());
604 
605  logger->setLevel(log4cxx::Level::getInfo());
608 
609  logger->setLevel(log4cxx::Level::getWarn());
612 
613  logger->setLevel(log4cxx::Level::getError());
616 
617  logger->setLevel(log4cxx::Level::getFatal());
620 
621  EXPECT_EQ((int)appender->info_.size(), 5);
622 
623  logger->removeAppender( appender );
624 
625  logger->setLevel( log4cxx::Level::getDebug() );
626 }
627 
628 TEST(RosConsole, longPrintfStyleOutput)
629 {
630  log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME);
631 
632  TestAppender* appender = new TestAppender;
633  logger->addAppender( appender );
634 
635  std::stringstream ss;
636  for (int i = 0; i < 100000; ++i )
637  {
638  ss << 'a';
639  }
640 
641  ROS_INFO("%s", ss.str().c_str());
642 
643  ASSERT_EQ((int)appender->info_.size(), 1);
644  EXPECT_STREQ(appender->info_[0].message_.c_str(), ss.str().c_str());
645 
646  logger->removeAppender( appender );
647 
648  logger->setLevel( log4cxx::Level::getDebug() );
649 }
650 
651 TEST(RosConsole, throwingAppender)
652 {
653  log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME);
654 
656  logger->addAppender( appender );
657 
658  try
659  {
660  ROS_INFO("Hello there");
661  }
662  catch (std::exception& e)
663  {
664  FAIL();
665  }
666 
667  logger->removeAppender( appender );
668  logger->setLevel( log4cxx::Level::getDebug() );
669 }
670 
671 void onceFunc()
672 {
674 }
675 
676 TEST(RosConsole, once)
677 {
678  log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME);
679 
680  TestAppender* appender = new TestAppender;
681  logger->addAppender(appender);
682 
683  onceFunc();
684  onceFunc();
685 
686  EXPECT_EQ(appender->info_.size(), 1ULL);
687 
688  logger->removeAppender(appender);
689 }
690 
692 {
694 }
695 
696 TEST(RosConsole, throttle)
697 {
698  log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME);
699 
700  TestAppender* appender = new TestAppender;
701  logger->addAppender(appender);
702 
703  ros::Time start = ros::Time::now();
704  while (ros::Time::now() <= start + ros::Duration(0.5))
705  {
706  throttleFunc();
707  ros::Duration(0.01).sleep();
708  }
709 
710  throttleFunc();
711 
712  EXPECT_EQ(appender->info_.size(), 2ULL);
713 
714  logger->removeAppender(appender);
715 }
716 
718 {
720 }
721 
723 {
725 }
726 
727 TEST(RosConsole, delayedThrottle)
728 {
729  log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME);
730 
731  TestAppender* appender = new TestAppender;
732  logger->addAppender(appender);
733 
734  ros::Time start = ros::Time::now();
735  while (ros::Time::now() <= start + ros::Duration(0.4))
736  {
738  ros::Duration(0.01).sleep();
739  }
740 
741  EXPECT_EQ(appender->info_.size(), 0ULL);
742 
743  const int pre_count = appender->info_.size();
744  start = ros::Time::now();
745  while (ros::Time::now() <= start + ros::Duration(0.6))
746  {
748  ros::Duration(0.01).sleep();
749  }
750 
751  const int post_count = appender->info_.size();
752 
753  EXPECT_EQ(post_count, pre_count + 1);
754 
755  logger->removeAppender(appender);
756 }
757 
758 
760 {
762 }
763 
764 TEST(RosConsole, onceStream)
765 {
766  log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME);
767 
768  TestAppender* appender = new TestAppender;
769  logger->addAppender(appender);
770 
771  onceStreamFunc();
772  onceStreamFunc();
773 
774  EXPECT_EQ(appender->info_.size(), 1ULL);
775 
776  logger->removeAppender(appender);
777 }
778 
780 {
782 }
783 
784 TEST(RosConsole, throttleStream)
785 {
786  log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME);
787 
788  TestAppender* appender = new TestAppender;
789  logger->addAppender(appender);
790 
791  ros::Time start = ros::Time::now();
792  while (ros::Time::now() <= start + ros::Duration(0.5))
793  {
795  ros::Duration(0.01).sleep();
796  }
797 
799 
800  EXPECT_EQ(appender->info_.size(), 2ULL);
801 
802  logger->removeAppender(appender);
803 }
804 
806 {
808 }
809 
811 {
813 }
814 
815 TEST(RosConsole, delayedStreamThrottle)
816 {
817  log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME);
818 
819  TestAppender* appender = new TestAppender;
820  logger->addAppender(appender);
821 
822  ros::Time start = ros::Time::now();
823  while (ros::Time::now() <= start + ros::Duration(0.4))
824  {
826  ros::Duration(0.01).sleep();
827  }
828 
829  EXPECT_EQ(appender->info_.size(), 0ULL);
830 
831  const int pre_count = appender->info_.size();
832  start = ros::Time::now();
833  while (ros::Time::now() <= start + ros::Duration(0.6))
834  {
836  ros::Duration(0.01).sleep();
837  }
838 
839  const int post_count = appender->info_.size();
840 
841  EXPECT_EQ(post_count, pre_count + 1);
842 
843  logger->removeAppender(appender);
844 }
845 
846 TEST(RosConsole, basicFilter)
847 {
848  log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME);
849 
850  TestAppender* appender = new TestAppender;
851  logger->addAppender(appender);
852 
853  BasicFilter trueFilter(true), falseFilter(false);
856 
857  ASSERT_EQ(appender->info_.size(), 1ULL);
858  EXPECT_STREQ(appender->info_[0].message_.c_str(), "Hello");
859 
860  logger->removeAppender(appender);
861 }
862 
863 TEST(RosConsole, basicFilterStream)
864 {
865  log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME);
866 
867  TestAppender* appender = new TestAppender;
868  logger->addAppender(appender);
869 
870  BasicFilter trueFilter(true), falseFilter(false);
873 
874  ASSERT_EQ(appender->info_.size(), 1ULL);
875  EXPECT_STREQ(appender->info_[0].message_.c_str(), "Hello");
876 
877  logger->removeAppender(appender);
878 }
879 
881 {
882  AdvancedFilter(bool enabled)
883  : enabled_(enabled)
884  , count_(0)
885  {}
886 
888  inline virtual bool isEnabled(ros::console::FilterParams& params)
889  {
890  fprintf(stderr, "%s %s:%d:%s\n", params.message, params.file, params.line, params.function);
891  ++count_;
892  return enabled_;
893  }
894 
895  bool enabled_;
896  int count_;
897 };
898 
899 TEST(RosConsole, advancedFilter)
900 {
901  log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME);
902 
903  TestAppender* appender = new TestAppender;
904  logger->addAppender(appender);
905 
906  AdvancedFilter trueFilter(true), falseFilter(false);
909 
910  ASSERT_EQ(appender->info_.size(), 1ULL);
911  EXPECT_STREQ(appender->info_[0].message_.c_str(), "Hello");
912  EXPECT_EQ(trueFilter.count_, 1);
913  EXPECT_EQ(falseFilter.count_, 1);
914 
915  logger->removeAppender(appender);
916 }
917 
918 TEST(RosConsole, advancedFilterStream)
919 {
920  log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME);
921 
922  TestAppender* appender = new TestAppender;
923  logger->addAppender(appender);
924 
925  AdvancedFilter trueFilter(true), falseFilter(false);
928 
929  ASSERT_EQ(appender->info_.size(), 1ULL);
930  EXPECT_STREQ(appender->info_[0].message_.c_str(), "Hello");
931  EXPECT_EQ(trueFilter.count_, 1);
932  EXPECT_EQ(falseFilter.count_, 1);
933 
934  logger->removeAppender(appender);
935 }
936 
938 {
940  inline virtual bool isEnabled(ros::console::FilterParams& params)
941  {
942  params.out_message = "haha";
944  return true;
945  }
946 };
947 
948 TEST(RosConsole, changeFilter)
949 {
950  log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME);
951 
952  TestAppender* appender = new TestAppender;
953  logger->addAppender(appender);
954 
955  ChangeFilter filter;
957 
958  ASSERT_EQ(appender->info_.size(), 1ULL);
959  EXPECT_STREQ(appender->info_[0].message_.c_str(), "haha");
960  EXPECT_EQ(appender->info_[0].level_, log4cxx::Level::getError());
961 
962  logger->removeAppender(appender);
963 }
964 
965 TEST(RosConsole, changeFilterStream)
966 {
967  log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME);
968 
969  TestAppender* appender = new TestAppender;
970  logger->addAppender(appender);
971 
972  ChangeFilter filter;
974 
975  ASSERT_EQ(appender->info_.size(), 1ULL);
976  EXPECT_STREQ(appender->info_[0].message_.c_str(), "haha");
977  EXPECT_EQ(appender->info_[0].level_, log4cxx::Level::getError());
978 
979  logger->removeAppender(appender);
980 }
981 
982 TEST(RosConsole, formatToBufferInitialZero)
983 {
985  size_t size = 0;
986  ros::console::formatToBuffer(buffer, size, "Hello World %d", 5);
987  EXPECT_EQ(size, 14U);
988  EXPECT_STREQ(buffer.get(), "Hello World 5");
989 }
990 
991 TEST(RosConsole, formatToBufferInitialLargerThanFormat)
992 {
993  boost::shared_array<char> buffer(new char[30]);
994  size_t size = 30;
995  ros::console::formatToBuffer(buffer, size, "Hello World %d", 5);
996  EXPECT_EQ(size, 30U);
997  EXPECT_STREQ(buffer.get(), "Hello World 5");
998 }
999 
1000 TEST(RosConsole, formatToString)
1001 {
1002  std::string str = ros::console::formatToString("Hello World %d", 5);
1003  EXPECT_STREQ(str.c_str(), "Hello World 5");
1004 }
1005 
1006 TEST(RosConsole, formatter)
1007 {
1008  std::string format_string;
1009 
1011  char str[32];
1012  char file[32];
1013  char function[32];
1014 
1015  std::string result;
1016 
1017  // default time
1018  {
1019  std::string format_string = "${time}";
1020 
1022  ros::console::g_formatter.init(format_string.c_str());
1023 
1025  log4cxx::Logger::getLogger(ROSCONSOLE_ROOT_LOGGER_NAME), level, str,
1026  file, function, 0);
1027 
1028  boost::regex expr("([0-9]+)\\.([0-9]+)");
1029  EXPECT_TRUE(boost::regex_match(result, expr));
1030  }
1031 
1032  // time format
1033  {
1034  std::string format_string = "${time:%Y %H:%M:%S}";
1035 
1037  ros::console::g_formatter.init(format_string.c_str());
1038 
1040  log4cxx::Logger::getLogger(ROSCONSOLE_ROOT_LOGGER_NAME), level, str,
1041  file, function, 0);
1042 
1043  boost::regex expr("([0-9]{4}) ([0-9]{2}:[0-9]{2}:[0-9]{2})");
1044  EXPECT_TRUE(boost::regex_match(result, expr));
1045  }
1046 
1047  // default walltime
1048  {
1049  std::string format_string = "${walltime}";
1050 
1052  ros::console::g_formatter.init(format_string.c_str());
1053 
1055  log4cxx::Logger::getLogger(ROSCONSOLE_ROOT_LOGGER_NAME), level, str,
1056  file, function, 0);
1057 
1058  boost::regex expr("([0-9]+)\\.([0-9]+)");
1059  EXPECT_TRUE(boost::regex_match(result, expr));
1060  }
1061 
1062  // walltime format
1063  {
1064  std::string format_string = "${walltime:%Y %H:%M:%S}";
1065 
1067  ros::console::g_formatter.init(format_string.c_str());
1068 
1070  log4cxx::Logger::getLogger(ROSCONSOLE_ROOT_LOGGER_NAME), level, str,
1071  file, function, 0);
1072 
1073  boost::regex expr("([0-9]{4}) ([0-9]{2}:[0-9]{2}:[0-9]{2})");
1074  EXPECT_TRUE(boost::regex_match(result, expr));
1075  }
1076 }
1077 
1078 int main(int argc, char **argv)
1079 {
1080  testing::InitGoogleTest(&argc, argv);
1081  ros::Time::init();
1082 
1084  log4cxx::Logger::getLogger(ROSCONSOLE_ROOT_LOGGER_NAME)->removeAllAppenders();
1085  log4cxx::Logger::getRootLogger()->setLevel(log4cxx::Level::getDebug());
1086  log4cxx::Logger::getLogger(ROSCONSOLE_ROOT_LOGGER_NAME)->setLevel(log4cxx::Level::getDebug());
1087 
1088  return RUN_ALL_TESTS();
1089 }
ROS_LOG_THROTTLE
#define ROS_LOG_THROTTLE(period, level, name,...)
Log to a given named logger at a given verbosity level, limited to a specific rate of printing,...
Definition: console.h:457
main
int main(int argc, char **argv)
Definition: utest.cpp:1078
ros::console::FilterParams::file
const char * file
[input] File the message came from
Definition: console.h:197
BasicFilter::BasicFilter
BasicFilter(bool enabled)
Definition: utest.cpp:108
AdvancedFilter::AdvancedFilter
AdvancedFilter(bool enabled)
Definition: utest.cpp:882
throttleStreamFunc
void throttleStreamFunc()
Definition: utest.cpp:779
ros::console::FilterParams::function
const char * function
[input] Function the message came from
Definition: console.h:199
ros::console::levels::Error
@ Error
Definition: console_backend.h:58
ros::console::FilterParams::level
Level level
[input/output] Severity level. If changed, uses the new level
Definition: console.h:204
TestAppender::V_Info
std::vector< Info > V_Info
Definition: utest.cpp:57
ROS_ERROR_STREAM
#define ROS_ERROR_STREAM(args)
Definition: macros_generated.h:215
ros::console::FilterParams::line
int line
[input] Line the message came from
Definition: console.h:198
ROS_DEBUG_STREAM_NAMED
#define ROS_DEBUG_STREAM_NAMED(name, args)
Definition: macros_generated.h:61
ros
ROS_FATAL_STREAM
#define ROS_FATAL_STREAM(args)
Definition: macros_generated.h:267
ROS_LOG_STREAM_THROTTLE
#define ROS_LOG_STREAM_THROTTLE(period, level, name, args)
Log to a given named logger at a given verbosity level, limited to a specific rate of printing,...
Definition: console.h:478
onceStreamFunc
void onceStreamFunc()
Definition: utest.cpp:759
ChangeFilter
Definition: utest.cpp:937
BasicFilter::enabled_
bool enabled_
Definition: utest.cpp:112
BasicFilter
Definition: utest.cpp:106
AdvancedFilter::count_
int count_
Definition: utest.cpp:896
delayedThrottleStreamFunc2
void delayedThrottleStreamFunc2()
Definition: utest.cpp:810
console.h
ROS_ERROR_NAMED
#define ROS_ERROR_NAMED(name,...)
Definition: macros_generated.h:216
TestAppender::Info
Definition: thread_test.cpp:48
ROS_DEBUG_STREAM
#define ROS_DEBUG_STREAM(args)
Definition: macros_generated.h:59
ROS_FATAL_NAMED
#define ROS_FATAL_NAMED(name,...)
Definition: macros_generated.h:268
TestAppender::Info::message_
std::string message_
Definition: thread_test.cpp:51
ros::console::FilterBase
Base-class for filters. Filters allow full user-defined control over whether or not a message should ...
Definition: console.h:231
BasicFilter::isEnabled
virtual bool isEnabled()
Returns whether or not the log statement should be printed. Called before the log arguments are evalu...
Definition: utest.cpp:112
ROSCONSOLE_AUTOINIT
#define ROSCONSOLE_AUTOINIT
Initializes the rosconsole library. Usually unnecessary to call directly.
Definition: console.h:327
ros::console::Formatter::init
void init(const char *fmt)
Definition: rosconsole.cpp:356
ROSCONSOLE_ROOT_LOGGER_NAME
#define ROSCONSOLE_ROOT_LOGGER_NAME
Definition: console.h:302
AdvancedFilter::isEnabled
virtual bool isEnabled(ros::console::FilterParams &params)
Returns whether or not the log statement should be printed. Called once the message has been formatte...
Definition: utest.cpp:888
ROS_WARN_STREAM
#define ROS_WARN_STREAM(args)
Definition: macros_generated.h:163
ros::console::levels::Debug
@ Debug
Definition: console_backend.h:55
ros::console::levels::Count
@ Count
Definition: console_backend.h:61
ChangeFilter::isEnabled
virtual bool isEnabled(ros::console::FilterParams &params)
Returns whether or not the log statement should be printed. Called once the message has been formatte...
Definition: utest.cpp:940
TestAppender::append
virtual void append(const log4cxx::spi::LoggingEventPtr &event, log4cxx::helpers::Pool &)
Definition: utest.cpp:62
TestAppenderWithThrow::append
virtual void append(const log4cxx::spi::LoggingEventPtr &, log4cxx::helpers::Pool &)
Definition: utest.cpp:92
ros::console::g_formatter
ROSCONSOLE_DECL Formatter g_formatter
Only exported because the implementation need it. Do not use directly.
Definition: rosconsole.cpp:462
ROS_INFO_NAMED
#define ROS_INFO_NAMED(name,...)
Definition: macros_generated.h:112
TestAppender::Info::logger_name_
std::string logger_name_
Definition: thread_test.cpp:52
ROS_LOG_STREAM_ONCE
#define ROS_LOG_STREAM_ONCE(level, name, args)
Log to a given named logger at a given verbosity level, only the first time it is hit when enabled,...
Definition: console.h:438
ROS_FATAL_STREAM_NAMED
#define ROS_FATAL_STREAM_NAMED(name, args)
Definition: macros_generated.h:269
ROS_DEBUG
#define ROS_DEBUG(...)
Definition: macros_generated.h:58
ROS_DEBUG_NAMED
#define ROS_DEBUG_NAMED(name,...)
Definition: macros_generated.h:60
ros::console::formatToBuffer
ROSCONSOLE_DECL void formatToBuffer(boost::shared_array< char > &buffer, size_t &buffer_size, const char *fmt,...)
Definition: rosconsole.cpp:531
ROS_ERROR_STREAM_NAMED
#define ROS_ERROR_STREAM_NAMED(name, args)
Definition: macros_generated.h:217
TestAppender::requiresLayout
virtual bool requiresLayout() const
Definition: utest.cpp:83
ROS_LOG_DELAYED_THROTTLE
#define ROS_LOG_DELAYED_THROTTLE(period, level, name,...)
Log to a given named logger at a given verbosity level, limited to a specific rate of printing,...
Definition: console.h:499
boost::shared_array
Definition: console.h:73
onceFunc
void onceFunc()
Definition: utest.cpp:671
ROS_WARN
#define ROS_WARN(...)
Definition: macros_generated.h:162
TestAppenderWithThrow::close
virtual void close()
Definition: utest.cpp:97
AdvancedFilter
Definition: utest.cpp:880
TestAppender::info_
V_Info info_
Definition: thread_test.cpp:57
ROS_INFO_STREAM
#define ROS_INFO_STREAM(args)
Definition: macros_generated.h:111
ros::console::Formatter::getTokenStrings
std::string getTokenStrings(void *logger_handle, ::ros::console::Level level, const char *str, const char *file, const char *function, int line) const
Definition: rosconsole.cpp:449
TEST
TEST(RosConsole, loggingLevels)
Definition: utest.cpp:353
ROS_LOG
#define ROS_LOG(level, name,...)
Log to a given named logger at a given verbosity level, with printf-style formatting.
Definition: console.h:575
ros::console::levels::Level
Level
Definition: console_backend.h:53
ros::console::levels::Info
@ Info
Definition: console_backend.h:56
ROS_FATAL
#define ROS_FATAL(...)
Definition: macros_generated.h:266
TestAppenderWithThrow::requiresLayout
virtual bool requiresLayout() const
Definition: utest.cpp:100
ROS_WARN_STREAM_NAMED
#define ROS_WARN_STREAM_NAMED(name, args)
Definition: macros_generated.h:165
TestAppender::close
virtual void close()
Definition: utest.cpp:80
ros::console::FilterParams::out_message
std::string out_message
[output] If set, writes this message instead of the original
Definition: console.h:207
ros::Time::init
static void init()
delayedThrottleStreamFunc
void delayedThrottleStreamFunc()
Definition: utest.cpp:805
ros::console::levels::Fatal
@ Fatal
Definition: console_backend.h:59
ros::console::notifyLoggerLevelsChanged
ROSCONSOLE_DECL void notifyLoggerLevelsChanged()
Tells the system that a logger's level has changed.
Definition: rosconsole.cpp:732
ros::Time
TestAppender
Definition: thread_test.cpp:45
ros::console::FilterParams::message
const char * message
[input] The formatted message that will be output
Definition: console.h:200
delayedThrottleFunc
void delayedThrottleFunc()
Definition: utest.cpp:717
ROS_ERROR
#define ROS_ERROR(...)
Definition: macros_generated.h:214
ROS_LOG_STREAM_FILTER
#define ROS_LOG_STREAM_FILTER(filter, level, name, args)
Log to a given named logger at a given verbosity level, with user-defined filtering,...
Definition: console.h:559
ROS_LOG_STREAM_DELAYED_THROTTLE
#define ROS_LOG_STREAM_DELAYED_THROTTLE(period, level, name, args)
Log to a given named logger at a given verbosity level, limited to a specific rate of printing and po...
Definition: console.h:521
ROS_WARN_NAMED
#define ROS_WARN_NAMED(name,...)
Definition: macros_generated.h:164
TestAppender::Info::level_
log4cxx::LevelPtr level_
Definition: thread_test.cpp:50
ROS_INFO_STREAM_NAMED
#define ROS_INFO_STREAM_NAMED(name, args)
Definition: macros_generated.h:113
DEFINE_LEVEL_TESTS
#define DEFINE_LEVEL_TESTS(name, macro_base, level, log4cxx_level)
Definition: utest.cpp:299
throttleFunc
void throttleFunc()
Definition: utest.cpp:691
ros::console::levels::Warn
@ Warn
Definition: console_backend.h:57
ROS_LOG_FILTER
#define ROS_LOG_FILTER(filter, level, name,...)
Log to a given named logger at a given verbosity level, with user-defined filtering,...
Definition: console.h:542
TestAppenderWithThrow
Definition: utest.cpp:89
ros::Duration::sleep
bool sleep() const
ros::console::formatToString
ROSCONSOLE_DECL std::string formatToString(const char *fmt,...)
Definition: rosconsole.cpp:541
ros::console::Formatter::tokens_
V_Token tokens_
Definition: console.h:137
ROSCONSOLE_DEFAULT_NAME
#define ROSCONSOLE_DEFAULT_NAME
Definition: console.h:304
g_filter
BasicFilter g_filter(true)
ROS_INFO
#define ROS_INFO(...)
Definition: macros_generated.h:110
ros::console::FilterParams
Parameter structure passed to FilterBase::isEnabled(...);. Includes both input and output parameters.
Definition: console.h:194
ROS_LOG_ONCE
#define ROS_LOG_ONCE(level, name,...)
Log to a given named logger at a given verbosity level, only the first time it is hit when enabled,...
Definition: console.h:419
AdvancedFilter::enabled_
bool enabled_
Definition: utest.cpp:895
ros::Duration
delayedThrottleFunc2
void delayedThrottleFunc2()
Definition: utest.cpp:722
ros::Time::now
static Time now()
ros::console::FilterBase::isEnabled
virtual bool isEnabled()
Returns whether or not the log statement should be printed. Called before the log arguments are evalu...
Definition: console.h:239


rosconsole
Author(s): Josh Faust
autogenerated on Wed Mar 2 2022 00:53:52