Files
qt6-migration-pipeline/external/rti_connext_dds-7.7.0/include/rti/apputils/test/TestLogCapture.hpp
T
torstenandCopilot 342ffd3e5c Update submodule to latest BUILD_RTI fixes
- HandlerMinelayerData: BUILD_RTI Guards für RTI-Abhängigkeiten
- svcTabCommon: Export-Header-Fix via Fallback-Target
- TrainingAreaBase: Stub-Header für BUILD_RTI=OFF
- ddsfts: Include-Pfad und Dependency-Fixes
- BUILD_RTI=OFF Compilation vollständig unterstützt

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Entire-Checkpoint: 01M0JNZA586SACX1PRZ2DJAE5S
2026-08-21 19:30:20 +02:00

96 lines
3.0 KiB
C++

/*
(c) Copyright, Real-Time Innovations, 2023.
All rights reserved.
No duplications, whole or partial, manual or electronic, may be made
without express written permission. Any such copies, or
revisions thereof, must display this notice unaltered.
This code contains trade secrets of Real-Time Innovations, Inc.
*/
#ifndef HPP_APPUTILS_TEST_LOG_CAPTURE_HPP_
#define HPP_APPUTILS_TEST_LOG_CAPTURE_HPP_
// IMPORTANT: macros.hpp must be the first RTI header included in every header
// file so that symbols are exported correctly on Windows
#include <dds/core/macros.hpp>
#include <rti/apputils/ServiceException.hpp>
#include "rtitest/test_setting.h"
#include "ddsctesthelpers/test_helper.h"
namespace rti { namespace apputils { namespace test {
/**
* @brief This class is a C++ wrapper for the APPUTILSTestUtils_LoggerDevice
* type, used to capture logs and find expected messages.
*/
class TestLogCapture {
public:
TestLogCapture(const std::string& expected_message) :
expected_message_(expected_message)
{
device_data_ = DDSCTesterHelperLoggerDeviceData_INITIALIZER(NULL);
if (!DDSCTesterHelperLoggerDeviceData_initialize(&device_data_)) {
RTI_THROW_SERVICE_EXCEPTION(
&RTI_LOG_INIT_FAILURE_s,
"logger device data");
}
device_data_.expectedMessage = expected_message_.c_str();
if (!DDSCTesterHelper_cacheLoggingConfiguration()) {
RTI_THROW_SERVICE_EXCEPTION(
&RTI_LOG_ANY_FAILURE_s,
"cache logging configuration");
}
// Prepare the device logger for catching the expected message
logger_device_ = NDDS_Config_LoggerDevice_INITIALIZER;
logger_device_.device_data = &device_data_;
logger_device_.write = DDSCTesterHelper_loggerDeviceWrite;
if (!NDDS_Config_Logger_set_output_device(
NDDS_Config_Logger_get_instance(),
&logger_device_)) {
RTI_THROW_SERVICE_EXCEPTION(
&RTI_LOG_INIT_FAILURE_s,
"set output device");
}
}
~TestLogCapture()
{
DDSCTesterHelperLoggerDeviceData_finalize(&device_data_);
// Restore the logging configuration; this will restore the previous
// output device if it was changed
if (!DDSCTesterHelper_restoreLoggingConfiguration()) {
RTITestLogger_log(
RTI_LOG_BIT_EXCEPTION,
&RTI_TEST_LOG_FAILURE_TEMPLATE,
"restore logging configuration");
}
}
unsigned int found_messages() const
{
return device_data_.foundMessages;
}
private:
struct NDDS_Config_LoggerDevice logger_device_;
struct DDSCTesterHelperLoggerDeviceData device_data_;
std::string expected_message_;
};
} } } /* namespace rti::apputils::test */
#endif /* HPP_APPUTILS_TEST_LOG_CAPTURE_HPP_ */
// --------------------------------------------------------------------
/* End $Id$ */