Esempio n. 1
0
/*
 * Check that logging works correctly.
 */
void LoggingTest::testLogging() {
  MockLogDestination *destination = new MockLogDestination();
  InitLogging(ola::OLA_LOG_DEBUG, destination);
  destination->AddExpected(ola::OLA_LOG_DEBUG, " debug\n");
  OLA_DEBUG << "debug";
  destination->AddExpected(ola::OLA_LOG_INFO, " info\n");
  OLA_INFO << "info";
  destination->AddExpected(ola::OLA_LOG_WARN, " warn\n");
  OLA_WARN << "warn";
  destination->AddExpected(ola::OLA_LOG_FATAL, " fatal\n");
  OLA_FATAL << "fatal";

  // Now make sure nothing below WARN is logged
  ola::SetLogLevel(ola::OLA_LOG_WARN);
  OLA_DEBUG << "debug";
  OLA_INFO << "info";
  destination->AddExpected(ola::OLA_LOG_WARN, " warn\n");
  OLA_WARN << "warn";
  destination->AddExpected(ola::OLA_LOG_FATAL, " fatal\n");
  OLA_FATAL << "fatal";
  OLA_ASSERT_EQ(destination->LinesRemaining(), 0);

  // set the log level to INFO
  IncrementLogLevel();
  OLA_DEBUG << "debug";
  destination->AddExpected(ola::OLA_LOG_INFO, " info\n");
  OLA_INFO << "info";
  destination->AddExpected(ola::OLA_LOG_WARN, " warn\n");
  OLA_WARN << "warn";
  destination->AddExpected(ola::OLA_LOG_FATAL, " fatal\n");
  OLA_FATAL << "fatal";
  OLA_ASSERT_EQ(destination->LinesRemaining(), 0);

  IncrementLogLevel();
  // this should wrap to NONE
  IncrementLogLevel();
  OLA_DEBUG << "debug";
  OLA_INFO << "info";
  OLA_WARN << "warn";
  OLA_FATAL << "fatal";
  OLA_ASSERT_EQ(destination->LinesRemaining(), 0);
}