mirror of
https://github.com/eclipse-openvehicle-api/openvehicle-api.git
synced 2026-08-30 12:15:12 +00:00
connection between 2 systems and bug fixes (#14)
This commit is contained in:
36
tests/component_tests/param_utils/CMakeLists.txt
Normal file
36
tests/component_tests/param_utils/CMakeLists.txt
Normal file
@@ -0,0 +1,36 @@
|
||||
#*******************************************************************************
|
||||
# Copyright (c) 2025-2026 ZF Friedrichshafen AG
|
||||
#
|
||||
# This program and the accompanying materials are made available under the
|
||||
# terms of the Apache License Version 2.0 which is available at
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# Contributors:
|
||||
# Erik Verhoeven - initial API and implementation
|
||||
#*******************************************************************************
|
||||
|
||||
# Define project
|
||||
project (ComponentTest_ParamUtils VERSION 1.0 LANGUAGES CXX)
|
||||
|
||||
# Data maneger executable
|
||||
add_executable(ComponentTest_ParamUtils
|
||||
"main.cpp"
|
||||
"get_parameter.cpp"
|
||||
"resolve_text.cpp"
|
||||
)
|
||||
|
||||
target_link_libraries(ComponentTest_ParamUtils ${CMAKE_DL_LIBS} GTest::GTest)
|
||||
|
||||
# Add the ParamUtils component test
|
||||
add_test(NAME ComponentTest_ParamUtils COMMAND ComponentTest_ParamUtils WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
|
||||
|
||||
# Execute the test
|
||||
add_custom_command(TARGET ComponentTest_ParamUtils POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E env TEST_EXECUTION_MODE=CMake "$<TARGET_FILE:ComponentTest_ParamUtils>" --gtest_output=xml:${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ComponentTest_ParamUtils.xml
|
||||
VERBATIM
|
||||
)
|
||||
|
||||
# Build dependencies
|
||||
add_dependencies(ComponentTest_ParamUtils dependency_sdv_components)
|
||||
213
tests/component_tests/param_utils/get_parameter.cpp
Normal file
213
tests/component_tests/param_utils/get_parameter.cpp
Normal file
@@ -0,0 +1,213 @@
|
||||
/********************************************************************************
|
||||
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* Erik Verhoeven - initial API and implementation
|
||||
********************************************************************************/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <support/app_control.h>
|
||||
#include <support/local_service_access.h>
|
||||
|
||||
TEST(ParamUtils, GetParameter_FailParamInterface)
|
||||
{
|
||||
sdv::app::CAppControl control;
|
||||
bool bResult = control.Startup("[Application]\nMode=\"Main\"\nInstance=2010");
|
||||
ASSERT_TRUE(bResult);
|
||||
|
||||
// Get the app settings service
|
||||
sdv::TInterfaceAccessPtr ptrSystemSettings = sdv::core::GetObject("AppSettingsService");
|
||||
ASSERT_TRUE(ptrSystemSettings);
|
||||
|
||||
// Request the IParameters interface
|
||||
sdv::IParameters* pParameters = ptrSystemSettings.GetInterface<sdv::IParameters>();
|
||||
ASSERT_NE(pParameters, nullptr);
|
||||
|
||||
// Invalid parameters interface
|
||||
sdv::any_t anyFail = sdv::core::GetParameter(nullptr, "Application.InstallDir");
|
||||
EXPECT_TRUE(anyFail.empty());
|
||||
bool bExcept = false;
|
||||
try
|
||||
{
|
||||
sdv::core::GetParameter(nullptr, "Application.InstallDir", false);
|
||||
}
|
||||
catch (const std::runtime_error&)
|
||||
{
|
||||
bExcept = true;
|
||||
}
|
||||
EXPECT_TRUE(bExcept);
|
||||
|
||||
// Invalid parameters name
|
||||
anyFail = sdv::core::GetParameter(pParameters, "ParamDoesNotExist");
|
||||
EXPECT_TRUE(anyFail.empty());
|
||||
bExcept = false;
|
||||
try
|
||||
{
|
||||
sdv::core::GetParameter(pParameters, "ParamDoesNotExist", false);
|
||||
}
|
||||
catch (const std::runtime_error&)
|
||||
{
|
||||
bExcept = true;
|
||||
}
|
||||
EXPECT_TRUE(bExcept);
|
||||
|
||||
control.Shutdown();
|
||||
}
|
||||
|
||||
TEST(ParamUtils, GetParameter_FailObjectInterface)
|
||||
{
|
||||
sdv::app::CAppControl control;
|
||||
bool bResult = control.Startup("[Application]\nMode=\"Main\"\nInstance=2010");
|
||||
ASSERT_TRUE(bResult);
|
||||
|
||||
// Get the app settings service
|
||||
sdv::TInterfaceAccessPtr ptrSystemSettings = sdv::core::GetObject("AppSettingsService");
|
||||
ASSERT_TRUE(ptrSystemSettings);
|
||||
|
||||
// Invalid object interface
|
||||
sdv::any_t anyFail = sdv::core::GetParameter(sdv::TInterfaceAccessPtr(), "Application.InstallDir");
|
||||
EXPECT_TRUE(anyFail.empty());
|
||||
bool bExcept = false;
|
||||
try
|
||||
{
|
||||
sdv::core::GetParameter(sdv::TInterfaceAccessPtr(), "Application.InstallDir", false);
|
||||
}
|
||||
catch (const std::runtime_error&)
|
||||
{
|
||||
bExcept = true;
|
||||
}
|
||||
EXPECT_TRUE(bExcept);
|
||||
|
||||
// Invalid parameters name
|
||||
anyFail = sdv::core::GetParameter(ptrSystemSettings, "ParamDoesNotExist");
|
||||
EXPECT_TRUE(anyFail.empty());
|
||||
bExcept = false;
|
||||
try
|
||||
{
|
||||
sdv::core::GetParameter(ptrSystemSettings, "ParamDoesNotExist", false);
|
||||
}
|
||||
catch (const std::runtime_error&)
|
||||
{
|
||||
bExcept = true;
|
||||
}
|
||||
EXPECT_TRUE(bExcept);
|
||||
|
||||
control.Shutdown();
|
||||
}
|
||||
|
||||
TEST(ParamUtils, GetParameter_FailObjectName)
|
||||
{
|
||||
sdv::app::CAppControl control;
|
||||
bool bResult = control.Startup("[Application]\nMode=\"Main\"\nInstance=2010");
|
||||
ASSERT_TRUE(bResult);
|
||||
|
||||
// Invalid object name
|
||||
sdv::any_t anyFail = sdv::core::GetParameter("InvalidObject", "Application.InstallDir");
|
||||
EXPECT_TRUE(anyFail.empty());
|
||||
bool bExcept = false;
|
||||
try
|
||||
{
|
||||
sdv::core::GetParameter("InvalidObject", "Application.InstallDir", false);
|
||||
}
|
||||
catch (const std::runtime_error&)
|
||||
{
|
||||
bExcept = true;
|
||||
}
|
||||
EXPECT_TRUE(bExcept);
|
||||
|
||||
// Invalid parameters name
|
||||
anyFail = sdv::core::GetParameter("AppSettingsService", "ParamDoesNotExist");
|
||||
EXPECT_TRUE(anyFail.empty());
|
||||
bExcept = false;
|
||||
try
|
||||
{
|
||||
sdv::core::GetParameter("AppSettingsService", "ParamDoesNotExist", false);
|
||||
}
|
||||
catch (const std::runtime_error&)
|
||||
{
|
||||
bExcept = true;
|
||||
}
|
||||
EXPECT_TRUE(bExcept);
|
||||
|
||||
control.Shutdown();
|
||||
}
|
||||
|
||||
TEST(ParamUtils, GetParameter_ParamInterface)
|
||||
{
|
||||
sdv::app::CAppControl control;
|
||||
bool bResult = control.Startup("[Application]\nMode=\"Main\"\nInstance=2010");
|
||||
ASSERT_TRUE(bResult);
|
||||
|
||||
// Get the app settings service
|
||||
sdv::TInterfaceAccessPtr ptrSystemSettings = sdv::core::GetObject("AppSettingsService");
|
||||
ASSERT_TRUE(ptrSystemSettings);
|
||||
|
||||
// Request the IParameters interface
|
||||
sdv::IParameters* pParameters = ptrSystemSettings.GetInterface<sdv::IParameters>();
|
||||
ASSERT_NE(pParameters, nullptr);
|
||||
|
||||
// Request the install directory through parameters
|
||||
sdv::any_t anyInstall = sdv::core::GetParameter(pParameters, "Application.InstallDir");
|
||||
EXPECT_FALSE(anyInstall.empty());
|
||||
EXPECT_EQ(std::filesystem::relative(anyInstall.get<std::string>(), control.GetAppDirectory()), "../../bin/2010");
|
||||
|
||||
control.Shutdown();
|
||||
}
|
||||
|
||||
TEST(ParamUtils, GetParameter_ObjectInterface)
|
||||
{
|
||||
sdv::app::CAppControl control;
|
||||
bool bResult = control.Startup("[Application]\nMode=\"Main\"\nInstance=2010");
|
||||
ASSERT_TRUE(bResult);
|
||||
|
||||
// Get the app settings service
|
||||
sdv::TInterfaceAccessPtr ptrSystemSettings = sdv::core::GetObject("AppSettingsService");
|
||||
ASSERT_TRUE(ptrSystemSettings);
|
||||
|
||||
// Request the install directory through parameters
|
||||
sdv::any_t anyInstall = sdv::core::GetParameter(ptrSystemSettings, "Application.InstallDir");
|
||||
EXPECT_FALSE(anyInstall.empty());
|
||||
EXPECT_EQ(std::filesystem::relative(anyInstall.get<std::string>(), control.GetAppDirectory()), "../../bin/2010");
|
||||
|
||||
control.Shutdown();
|
||||
}
|
||||
|
||||
TEST(ParamUtils, GetParameter_ObjectName)
|
||||
{
|
||||
sdv::app::CAppControl control;
|
||||
bool bResult = control.Startup("[Application]\nMode=\"Main\"\nInstance=2010");
|
||||
ASSERT_TRUE(bResult);
|
||||
|
||||
// Request the install directory through parameters
|
||||
sdv::any_t anyInstall = sdv::core::GetParameter("AppSettingsService", "Application.InstallDir");
|
||||
EXPECT_FALSE(anyInstall.empty());
|
||||
EXPECT_EQ(std::filesystem::relative(anyInstall.get<std::string>(), control.GetAppDirectory()), "../../bin/2010");
|
||||
|
||||
control.Shutdown();
|
||||
}
|
||||
|
||||
TEST(ParamUtils, GetParameter_EnumExpand)
|
||||
{
|
||||
sdv::app::CAppControl control;
|
||||
bool bResult = control.Startup("[Application]\nMode=\"Main\"\nInstance=2010");
|
||||
ASSERT_TRUE(bResult);
|
||||
|
||||
// Request the mode through parameters
|
||||
sdv::any_t anyMode = sdv::core::GetParameter("AppSettingsService", "Application.Mode");
|
||||
EXPECT_FALSE(anyMode.empty());
|
||||
EXPECT_EQ(static_cast<uint64_t>(anyMode), static_cast<uint64_t>(sdv::app::EAppContext::main));
|
||||
|
||||
// Request the expanded mode through parameters
|
||||
std::string ssMode = sdv::core::GetParameterExpand("AppSettingsService", "Application.Mode");
|
||||
EXPECT_FALSE(ssMode.empty());
|
||||
EXPECT_EQ(ssMode, "Main");
|
||||
|
||||
control.Shutdown();
|
||||
}
|
||||
|
||||
27
tests/component_tests/param_utils/main.cpp
Normal file
27
tests/component_tests/param_utils/main.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
/********************************************************************************
|
||||
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* Erik Verhoeven - initial API and implementation
|
||||
********************************************************************************/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "../../../global/process_watchdog.h"
|
||||
|
||||
#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();
|
||||
}
|
||||
168
tests/component_tests/param_utils/resolve_text.cpp
Normal file
168
tests/component_tests/param_utils/resolve_text.cpp
Normal file
@@ -0,0 +1,168 @@
|
||||
/********************************************************************************
|
||||
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* Erik Verhoeven - initial API and implementation
|
||||
********************************************************************************/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <support/app_control.h>
|
||||
#include <support/local_service_access.h>
|
||||
|
||||
TEST(ParamUtils, ResolveText_FailObjectName)
|
||||
{
|
||||
sdv::app::CAppControl control;
|
||||
bool bResult = control.Startup("[Application]\nMode=\"Main\"\nInstance=2010");
|
||||
ASSERT_TRUE(bResult);
|
||||
|
||||
// Invalid parameters interface
|
||||
std::string ssText = sdv::core::ResolveText("$(InvalidObject:Application.InstallDir)");
|
||||
EXPECT_TRUE(ssText.empty());
|
||||
bool bExcept = false;
|
||||
try
|
||||
{
|
||||
sdv::core::ResolveText("$(InvalidObject:Application.InstallDir)", true, false);
|
||||
}
|
||||
catch (const std::runtime_error&)
|
||||
{
|
||||
bExcept = true;
|
||||
}
|
||||
EXPECT_TRUE(bExcept);
|
||||
|
||||
// Invalid parameter name
|
||||
ssText = sdv::core::ResolveText("$(AppSettingsService:ParamDoesNotExist)");
|
||||
EXPECT_TRUE(ssText.empty());
|
||||
bExcept = false;
|
||||
try
|
||||
{
|
||||
sdv::core::ResolveText("$(AppSettingsService:ParamDoesNotExist)", true, false);
|
||||
}
|
||||
catch (const std::runtime_error&)
|
||||
{
|
||||
bExcept = true;
|
||||
}
|
||||
EXPECT_TRUE(bExcept);
|
||||
|
||||
control.Shutdown();
|
||||
}
|
||||
|
||||
TEST(ParamUtils, ResolveText_EscapingDollarCharacter)
|
||||
{
|
||||
sdv::app::CAppControl control;
|
||||
bool bResult = control.Startup("[Application]\nMode=\"Main\"\nInstance=2010");
|
||||
ASSERT_TRUE(bResult);
|
||||
|
||||
// Not escaping $ - this is allowed!
|
||||
std::string ssText = sdv::core::ResolveText("There is a $ in this text.");
|
||||
EXPECT_FALSE(ssText.empty());
|
||||
EXPECT_EQ(ssText, "There is a $ in this text.");
|
||||
bool bExcept = false;
|
||||
ssText.clear();
|
||||
try
|
||||
{
|
||||
ssText = sdv::core::ResolveText("There is a $ in this text.", true, false);
|
||||
}
|
||||
catch (const std::runtime_error&)
|
||||
{
|
||||
bExcept = true;
|
||||
}
|
||||
EXPECT_FALSE(bExcept);
|
||||
EXPECT_EQ(ssText, "There is a $ in this text.");
|
||||
|
||||
// Missing (-character - this is the same as not escaping $
|
||||
ssText = sdv::core::ResolveText("$AppSettingsService:Application.InstallDir)");
|
||||
EXPECT_FALSE(ssText.empty());
|
||||
EXPECT_EQ(ssText, "$AppSettingsService:Application.InstallDir)");
|
||||
bExcept = false;
|
||||
ssText.clear();
|
||||
try
|
||||
{
|
||||
ssText = sdv::core::ResolveText("$AppSettingsService:Application.InstallDir)", true, false);
|
||||
}
|
||||
catch (const std::runtime_error&)
|
||||
{
|
||||
bExcept = true;
|
||||
}
|
||||
EXPECT_FALSE(bExcept);
|
||||
EXPECT_EQ(ssText, "$AppSettingsService:Application.InstallDir)");
|
||||
|
||||
// Missing )-character - this is an error
|
||||
ssText = sdv::core::ResolveText("$(AppSettingsService:Application.InstallDir");
|
||||
EXPECT_TRUE(ssText.empty());
|
||||
bExcept = false;
|
||||
try
|
||||
{
|
||||
sdv::core::ResolveText("$(AppSettingsService:Application.InstallDir", true, false);
|
||||
}
|
||||
catch (const std::runtime_error&)
|
||||
{
|
||||
bExcept = true;
|
||||
}
|
||||
EXPECT_TRUE(bExcept);
|
||||
|
||||
// Invalid object-param pair
|
||||
ssText = sdv::core::ResolveText("$(Application.InstallDir)");
|
||||
EXPECT_TRUE(ssText.empty());
|
||||
bExcept = false;
|
||||
try
|
||||
{
|
||||
sdv::core::ResolveText("$(Application.InstallDir)", true, false);
|
||||
}
|
||||
catch (const std::runtime_error&)
|
||||
{
|
||||
bExcept = true;
|
||||
}
|
||||
EXPECT_TRUE(bExcept);
|
||||
|
||||
// Resolvinf during first iteration
|
||||
ssText = sdv::core::ResolveText("$(AppSettingsService:Application.Mode)");
|
||||
EXPECT_EQ(ssText, "Main");
|
||||
|
||||
// Resolving during second iteration
|
||||
ssText = sdv::core::ResolveText("\\$(AppSettingsService:Application.Mode)");
|
||||
EXPECT_EQ(ssText, "Main");
|
||||
|
||||
// No further iteration
|
||||
ssText = sdv::core::ResolveText("\\$(AppSettingsService:Application.Mode)", false);
|
||||
EXPECT_EQ(ssText, "$(AppSettingsService:Application.Mode)");
|
||||
|
||||
control.Shutdown();
|
||||
}
|
||||
|
||||
TEST(ParamUtils, ResolveText_Object)
|
||||
{
|
||||
sdv::app::CAppControl control;
|
||||
bool bResult = control.Startup("[Application]\nMode=\"Main\"\nInstance=2010");
|
||||
ASSERT_TRUE(bResult);
|
||||
|
||||
// Request the install directory through parameters
|
||||
std::string ssText = sdv::core::ResolveText("$(AppSettingsService:Application.InstallDir)/MyPackage");
|
||||
EXPECT_FALSE(ssText.empty());
|
||||
EXPECT_EQ(std::filesystem::relative(ssText, control.GetAppDirectory()), "../../bin/2010/MyPackage");
|
||||
|
||||
// Request the install directory through parameters
|
||||
ssText = sdv::core::ResolveText("The application mode is \"$( AppSettingsService : Application.Mode )\" and the instance numbver is $(AppSettingsService:Application.Instance).");
|
||||
EXPECT_FALSE(ssText.empty());
|
||||
EXPECT_EQ(ssText, "The application mode is \"Main\" and the instance numbver is 2010.");
|
||||
|
||||
ssText = sdv::core::ResolveText("The application mode is \"$(AppSettingsService:Application.Mode)\" and the instance number "
|
||||
"is $(AppSettingsService:Application.Instance).");
|
||||
EXPECT_FALSE(ssText.empty());
|
||||
EXPECT_EQ(ssText, "The application mode is \"Main\" and the instance number is 2010.");
|
||||
|
||||
// Request the install directory through parameters
|
||||
ssText = sdv::core::ResolveText("Valid text with a \\$ in the text...");
|
||||
EXPECT_FALSE(ssText.empty());
|
||||
EXPECT_EQ(ssText, "Valid text with a $ in the text...");
|
||||
|
||||
control.Shutdown();
|
||||
}
|
||||
|
||||
// TODO: Recursive test
|
||||
// e.g. \$($(MyObject1:Name):$(MyObject2:ParamName))
|
||||
Reference in New Issue
Block a user