mirror of
https://github.com/eclipse-openvehicle-api/openvehicle-api.git
synced 2026-04-18 10:38:16 +00:00
53
tests/component_tests/logger/CMakeLists.txt
Normal file
53
tests/component_tests/logger/CMakeLists.txt
Normal 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)
|
||||
@@ -0,0 +1,6 @@
|
||||
[Configuration]
|
||||
Version = 100
|
||||
|
||||
[[Component]]
|
||||
Path = "ComponentTest_Logger_Module.sdv"
|
||||
Class = "LoggerTestService"
|
||||
60
tests/component_tests/logger/logger_test.cpp
Normal file
60
tests/component_tests/logger/logger_test.cpp
Normal 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
|
||||
}
|
||||
11
tests/component_tests/logger/logger_test_service.cpp
Normal file
11
tests/component_tests/logger/logger_test_service.cpp
Normal 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!");
|
||||
|
||||
}
|
||||
23
tests/component_tests/logger/logger_test_service.h
Normal file
23
tests/component_tests/logger/logger_test_service.h
Normal 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
|
||||
Reference in New Issue
Block a user