Precommit (#1)

* first commit

* cleanup
This commit is contained in:
tompzf
2025-11-04 13:28:06 +01:00
committed by GitHub
parent dba45dc636
commit 6ed4b1534e
898 changed files with 256340 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
project(LoggerTests)
set(CMAKE_CXX_STANDARD 17)
# Define target
add_library(ComponentTest_Logger_Module SHARED "logger_test_service.h" "logger_test_service.cpp")
target_link_options(ComponentTest_Logger_Module PRIVATE)
target_include_directories(ComponentTest_Logger_Module PRIVATE ./include)
if (WIN32)
target_link_libraries(ComponentTest_Logger_Module Ws2_32 Winmm)
else()
target_link_libraries(ComponentTest_Logger_Module)
endif()
set_target_properties(ComponentTest_Logger_Module PROPERTIES PREFIX "")
set_target_properties(ComponentTest_Logger_Module PROPERTIES SUFFIX ".sdv")
# Logger
add_executable(ComponentTest_Logger
"logger_test.cpp"
)
target_include_directories(ComponentTest_Logger PRIVATE
${GTEST_INCLUDE_DIRS}
)
target_link_libraries(ComponentTest_Logger
GTest::GTest
#pthread
#stdc++fs
${CMAKE_DL_LIBS}
)
add_test(NAME ComponentTest_Logger COMMAND ComponentTest_Logger)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if (WIN32)
target_link_libraries(ComponentTest_Logger Ws2_32 Winmm Rpcrt4.lib)
else()
target_link_libraries(ComponentTest_Logger rt)
endif()
else()
target_link_libraries(ComponentTest_Logger Rpcrt4.lib)
endif()
add_custom_command(TARGET ComponentTest_Logger POST_BUILD
COMMAND ${CMAKE_COMMAND} -E env TEST_EXECUTION_MODE=CMake "$<TARGET_FILE:ComponentTest_Logger>" ${GTEST_ARGUMENTS}ComponentTest_Logger.xml
VERBATIM
)
file (COPY ${PROJECT_SOURCE_DIR}/config/test_logger_userconfig.toml DESTINATION ${CMAKE_BINARY_DIR}/tests/bin/config/)
add_dependencies(ComponentTest_Logger_Module dependency_sdv_components)
add_dependencies(ComponentTest_Logger ComponentTest_Logger_Module)

View File

@@ -0,0 +1,6 @@
[Configuration]
Version = 100
[[Component]]
Path = "ComponentTest_Logger_Module.sdv"
Class = "LoggerTestService"

View File

@@ -0,0 +1,60 @@
#include <gtest/gtest.h>
#include <iostream>
#include <support/sdv_core.h>
#include <support/local_service_access.h>
#include <support/app_control.h>
#include "../../../global/process_watchdog.h"
#include "../../include/logger_test_helper.h"
#ifdef _MSC_VER
#include <process.h>
#elif defined __GNUC__
#include <unistd.h>
#endif
#if defined(_WIN32) && defined(_UNICODE)
extern "C" int wmain(int argc, wchar_t* argv[])
#else
extern "C" int main(int argc, char* argv[])
#endif
{
CProcessWatchdog watchdog;
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
TEST(AppLoggerTest, CallbackMultiThread)
{
std::string prefix = "PA_LoggerTest_";
auto startCount = GetLoggerFilesCount(prefix);
{
SDV_LOG(sdv::core::ELogSeverity::warning, "Warning: trying to log before instantiation!");
sdv::app::CAppControl appcontrol;
std::stringstream sstreamAppConfig;
sstreamAppConfig << "[LogHandler]" << std::endl << "Tag=\"" << prefix << getpid() << "\"";
bool bResult = appcontrol.Startup(sstreamAppConfig.str());
EXPECT_TRUE(bResult);
appcontrol.SetConfigMode();
SDV_LOG(sdv::core::ELogSeverity::warning, "Warning: trying to log before initialization!");
std::cout << "Logger test: Initialize Log" << std::endl;
sdv::core::EConfigProcessResult eResult = appcontrol.LoadConfig("test_logger_userconfig.toml");
EXPECT_EQ(eResult, sdv::core::EConfigProcessResult::successful);
appcontrol.SetRunningMode();
}
auto endCount = GetLoggerFilesCount(prefix);
#if defined(_WIN32)
EXPECT_TRUE(endCount > startCount);
#else
// just avoid unused variable warning
std::cout << "start:" << std::to_string(startCount) << " end:" << std::to_string(endCount) << std::endl;
#endif
}

View File

@@ -0,0 +1,11 @@
#include "logger_test_service.h"
CLoggerTestService::CLoggerTestService()
{
// auto test = sdv::core::GetObject("DataDispatchService");
// auto foo = test.GetInterface<sdv::core::IDataDispatchService>();
// foo->HasSignal(0);
SDV_LOG(sdv::core::ELogSeverity::info, "Info: Logging from Dummy test service via macro!");
}

View File

@@ -0,0 +1,23 @@
#ifndef VAPI_DUMMY_TEST_SERVICE_H
#define VAPI_DUMMY_TEST_SERVICE_H
#include <support/component_impl.h>
/**
* @brief Class to create a dummy test service.
*/
class CLoggerTestService
: public sdv::CSdvObject
{
public:
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::BasicService)
DECLARE_OBJECT_CLASS_NAME("LoggerTestService")
CLoggerTestService();
};
DEFINE_SDV_OBJECT(CLoggerTestService)
#endif // !define VAPI_DUMMY_TEST_SERVICE_H