Skip to content

Commit

Permalink
iox-eclipse-iceoryx#1755 Test platform logging integration into hoofs…
Browse files Browse the repository at this point in the history
… logger
  • Loading branch information
elBoberido committed Mar 12, 2024
1 parent 93ff01e commit 9a62ad5
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions iceoryx_hoofs/test/moduletests/test_reporting_logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@
//
// SPDX-License-Identifier: Apache-2.0

#include "iceoryx_platform/logging.hpp"
#include "iox/logging.hpp"

#include "iceoryx_hoofs/testing/mocks/logger_mock.hpp"
#include "iceoryx_hoofs/testing/testing_logger.hpp"
#include "test.hpp"

namespace
{
using namespace ::testing;

void testLogLevelThreshold(const iox::log::LogLevel loggerLogLevel)
void testLogLevelThreshold(const iox::log::LogLevel loggerLogLevel,
const std::function<void(iox::log::LogLevel)>& loggerCall)
{
iox::log::Logger::setLogLevel(loggerLogLevel);

Expand All @@ -47,7 +48,6 @@ void testLogLevelThreshold(const iox::log::LogLevel loggerLogLevel)
{iox::log::LogLevel::DEBUG, "Debug"},
{iox::log::LogLevel::TRACE, "Trace"}};

iox::testing::Logger_Mock loggerMock;
for (const auto& logEntryLogLevel : logEntryLogLevels)
{
if (!iox::testing::TestingLogger::doesLoggerSupportLogLevel(logEntryLogLevel.value))
Expand All @@ -56,7 +56,7 @@ void testLogLevelThreshold(const iox::log::LogLevel loggerLogLevel)
}

dynamic_cast<iox::testing::TestingLogger&>(iox::log::Logger::get()).clearLogBuffer();
IOX_LOG_INTERNAL("", 0, "", logEntryLogLevel.value, "");
loggerCall(logEntryLogLevel.value);

if (logEntryLogLevel.value <= loggerLogLevel)
{
Expand Down Expand Up @@ -87,7 +87,26 @@ TEST(LoggingLogLevelThreshold_test, LogLevel)
{
SCOPED_TRACE(std::string("Logger LogLevel: ") + iox::log::asStringLiteral(loggerLogLevel));

testLogLevelThreshold(loggerLogLevel);
testLogLevelThreshold(loggerLogLevel, [](auto logLevel) { IOX_LOG_INTERNAL("", 0, "", logLevel, ""); });
}
}

TEST(LoggingLogLevelThreshold_test, LogLevelForPlatform)
{
::testing::Test::RecordProperty("TEST_ID", "574007ac-62ed-4cd1-95e8-e18a9f20e1e1");
for (const auto loggerLogLevel : {iox::log::LogLevel::OFF,
iox::log::LogLevel::FATAL,
iox::log::LogLevel::ERROR,
iox::log::LogLevel::WARN,
iox::log::LogLevel::INFO,
iox::log::LogLevel::DEBUG,
iox::log::LogLevel::TRACE})
{
SCOPED_TRACE(std::string("Logger LogLevel: ") + iox::log::asStringLiteral(loggerLogLevel));

testLogLevelThreshold(loggerLogLevel, [](auto logLevel) {
iox_platform_detail_log("", 0, "", static_cast<IceoryxPlatformLogLevel>(logLevel), "");
});
}
}

Expand Down

0 comments on commit 9a62ad5

Please sign in to comment.