mirror of
https://github.com/eclipse-openvehicle-api/openvehicle-api.git
synced 2026-08-30 12:15:12 +00:00
69
tests/component_tests/config_install/CMakeLists.txt
Normal file
69
tests/component_tests/config_install/CMakeLists.txt
Normal file
@@ -0,0 +1,69 @@
|
||||
# Define project
|
||||
project (ModuleControlTests VERSION 1.0 LANGUAGES CXX)
|
||||
|
||||
# Get CRC++ from github
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
CRCpp
|
||||
GIT_REPOSITORY https://github.com/d-bahr/CRCpp
|
||||
GIT_TAG release-1.2.0.0
|
||||
)
|
||||
FetchContent_MakeAvailable(CRCpp)
|
||||
|
||||
# Add include directories
|
||||
include_directories(../export ${CRCpp_SOURCE_DIR})
|
||||
|
||||
# build module example for the test
|
||||
add_library(ComponentTest_ConfigInstall_Module SHARED
|
||||
"test_component.cpp"
|
||||
)
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
target_link_options(ComponentTest_ConfigInstall_Module PUBLIC -fPIC)
|
||||
target_link_libraries(ComponentTest_ConfigInstall_Module GTest::GTest)
|
||||
if (WIN32)
|
||||
target_link_libraries(ComponentTest_ConfigInstall_Module Ws2_32 Winmm Rpcrt4.lib)
|
||||
else()
|
||||
target_link_libraries(ComponentTest_ConfigInstall_Module ${CMAKE_DL_LIBS} rt)
|
||||
endif()
|
||||
else()
|
||||
target_link_libraries(ComponentTest_ConfigInstall_Module GTest::GTest Rpcrt4.lib)
|
||||
endif()
|
||||
|
||||
set_target_properties(ComponentTest_ConfigInstall_Module PROPERTIES PREFIX "")
|
||||
set_target_properties(ComponentTest_ConfigInstall_Module PROPERTIES SUFFIX ".sdv")
|
||||
|
||||
# Execute the sdv_packager utility to install the component in instance #2006.
|
||||
add_custom_target(ComponentTest_ConfigInstall_install_manifest
|
||||
# TODO EVE
|
||||
# COMMAND "$<TARGET_FILE:sdv_packager>" -O. --instance2006 -NComponentTest_ConfigInstall "$<TARGET_FILE:ComponentTest_ConfigInstall_Module>" "-I$<TARGET_FILE_DIR:ComponentTest_ConfigInstall_Module>" --settings --create_configtest.toml
|
||||
COMMAND "$<TARGET_FILE:sdv_packager>" DIRECT_INSTALL ComponentTest_ConfigInstall --instance2006 "$<TARGET_FILE:ComponentTest_ConfigInstall_Module>" "-I$<TARGET_FILE_DIR:ComponentTest_ConfigInstall_Module>" --overwrite --user_config
|
||||
DEPENDS ComponentTest_ConfigInstall_Module
|
||||
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
|
||||
)
|
||||
|
||||
# Module control test executable
|
||||
add_executable(ComponentTest_ConfigInstall
|
||||
"main.cpp"
|
||||
"module_install_test.cpp"
|
||||
"manifest_helper_util_test.cpp"
|
||||
)
|
||||
|
||||
target_link_libraries(ComponentTest_ConfigInstall ${CMAKE_DL_LIBS} GTest::GTest)
|
||||
|
||||
# Add the Data Dispatch Service unittest
|
||||
add_test(NAME ComponentTest_ConfigInstall COMMAND ComponentTest_ConfigInstall WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
|
||||
|
||||
# Execute the test
|
||||
add_custom_command(TARGET ComponentTest_ConfigInstall POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E env TEST_EXECUTION_MODE=CMake "$<TARGET_FILE:ComponentTest_ConfigInstall>" --gtest_output=xml:${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ComponentTest_ConfigInstall.xml
|
||||
VERBATIM
|
||||
)
|
||||
|
||||
# Build dependencies
|
||||
add_dependencies(ComponentTest_ConfigInstall_Module sdv_packager)
|
||||
add_dependencies(ComponentTest_ConfigInstall_Module dependency_sdv_components)
|
||||
add_dependencies(ComponentTest_ConfigInstall dependency_sdv_components)
|
||||
add_dependencies(ComponentTest_ConfigInstall ComponentTest_ConfigInstall_Module)
|
||||
add_dependencies(ComponentTest_ConfigInstall ComponentTest_ConfigInstall_install_manifest)
|
||||
|
||||
14
tests/component_tests/config_install/main.cpp
Normal file
14
tests/component_tests/config_install/main.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#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();
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <support/sdv_core.h>
|
||||
#include <interfaces/app.h>
|
||||
#include <support/mem_access.h>
|
||||
#include <support/app_control.h>
|
||||
#include <filesystem>
|
||||
#include "../../../global/exec_dir_helper.h"
|
||||
|
||||
TEST(ManifestHelperUtil, Instantiate)
|
||||
{
|
||||
sdv::app::CAppControl control;
|
||||
bool bResult = control.Startup("");
|
||||
EXPECT_TRUE(bResult);
|
||||
|
||||
auto pModuleControl = sdv::core::GetObject<sdv::core::IModuleControl>("ModuleControlService");
|
||||
ASSERT_TRUE(pModuleControl);
|
||||
sdv::core::TModuleID tManifestModule = pModuleControl->Load("manifest_util.sdv");
|
||||
ASSERT_NE(tManifestModule, 0);
|
||||
|
||||
sdv::TObjectPtr ptrManifestUtil = sdv::core::CreateUtility("ManifestHelperUtility");
|
||||
EXPECT_TRUE(ptrManifestUtil);
|
||||
sdv::helper::IModuleManifestHelper* pManifestHelper = ptrManifestUtil.GetInterface<sdv::helper::IModuleManifestHelper>();
|
||||
EXPECT_NE(pManifestHelper, nullptr);
|
||||
ptrManifestUtil.Clear();
|
||||
|
||||
pModuleControl->Unload(tManifestModule);
|
||||
|
||||
control.Shutdown();
|
||||
}
|
||||
|
||||
TEST(ManifestHelperUtil, NonExistingComponent)
|
||||
{
|
||||
sdv::app::CAppControl control;
|
||||
bool bResult = control.Startup("");
|
||||
EXPECT_TRUE(bResult);
|
||||
|
||||
auto pModuleControl = sdv::core::GetObject<sdv::core::IModuleControl>("ModuleControlService");
|
||||
ASSERT_TRUE(pModuleControl);
|
||||
sdv::core::TModuleID tManifestModule = pModuleControl->Load("manifest_util.sdv");
|
||||
ASSERT_NE(tManifestModule, 0);
|
||||
|
||||
sdv::TObjectPtr ptrManifestUtil = sdv::core::CreateUtility("ManifestHelperUtility");
|
||||
EXPECT_TRUE(ptrManifestUtil);
|
||||
sdv::helper::IModuleManifestHelper* pManifestHelper = ptrManifestUtil.GetInterface<sdv::helper::IModuleManifestHelper>();
|
||||
EXPECT_NE(pManifestHelper, nullptr);
|
||||
|
||||
sdv::u8string ssManifest = pManifestHelper->ReadModuleManifest("non_existing_component");
|
||||
EXPECT_TRUE(ssManifest.empty());
|
||||
|
||||
ptrManifestUtil.Clear();
|
||||
pModuleControl->Unload(tManifestModule);
|
||||
|
||||
control.Shutdown();
|
||||
}
|
||||
|
||||
TEST(ManifestHelperUtil, ExistingComponent)
|
||||
{
|
||||
sdv::app::CAppControl control;
|
||||
bool bResult = control.Startup("");
|
||||
EXPECT_TRUE(bResult);
|
||||
|
||||
auto pModuleControl = sdv::core::GetObject<sdv::core::IModuleControl>("ModuleControlService");
|
||||
ASSERT_TRUE(pModuleControl);
|
||||
sdv::core::TModuleID tManifestModule = pModuleControl->Load("manifest_util.sdv");
|
||||
ASSERT_NE(tManifestModule, 0);
|
||||
|
||||
sdv::TObjectPtr ptrManifestUtil = sdv::core::CreateUtility("ManifestHelperUtility");
|
||||
EXPECT_TRUE(ptrManifestUtil);
|
||||
sdv::helper::IModuleManifestHelper* pManifestHelper = ptrManifestUtil.GetInterface<sdv::helper::IModuleManifestHelper>();
|
||||
EXPECT_NE(pManifestHelper, nullptr);
|
||||
|
||||
sdv::u8string ssManifest = pManifestHelper->ReadModuleManifest((GetExecDirectory() /
|
||||
"ComponentTest_ConfigInstall_Module.sdv").generic_u8string());
|
||||
EXPECT_FALSE(ssManifest.empty());
|
||||
|
||||
ptrManifestUtil.Clear();
|
||||
pModuleControl->Unload(tManifestModule);
|
||||
|
||||
control.Shutdown();
|
||||
}
|
||||
|
||||
277
tests/component_tests/config_install/module_install_test.cpp
Normal file
277
tests/component_tests/config_install/module_install_test.cpp
Normal file
@@ -0,0 +1,277 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <support/sdv_core.h>
|
||||
#include <interfaces/app.h>
|
||||
#include <support/mem_access.h>
|
||||
#include <support/app_control.h>
|
||||
#include <filesystem>
|
||||
#include "../../../global/exec_dir_helper.h"
|
||||
#include "../../../global/base64.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <Shlobj.h>
|
||||
#endif
|
||||
|
||||
class CModuleControl_Install : public ::testing::Test
|
||||
{
|
||||
public:
|
||||
virtual void SetUp()
|
||||
{
|
||||
DeleteTestDirs();
|
||||
}
|
||||
|
||||
virtual void TearDown()
|
||||
{
|
||||
DeleteTestDirs();
|
||||
}
|
||||
|
||||
static void SetUpTestCase() {}
|
||||
static void TearDownTestSuite() {}
|
||||
|
||||
void DeleteTestDirs()
|
||||
{
|
||||
try
|
||||
{
|
||||
std::filesystem::remove_all(GetExecDirectory() / "module_test1");
|
||||
}
|
||||
catch (const std::filesystem::filesystem_error&)
|
||||
{}
|
||||
try
|
||||
{
|
||||
std::filesystem::remove_all(GetExecDirectory() / "module_test2");
|
||||
}
|
||||
catch (const std::filesystem::filesystem_error&)
|
||||
{}
|
||||
try
|
||||
{
|
||||
std::filesystem::remove_all(GetDefaultInstallDir());
|
||||
}
|
||||
catch (const std::filesystem::filesystem_error&)
|
||||
{}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Default installation directory.
|
||||
* @return The default installation directory.
|
||||
*/
|
||||
std::filesystem::path GetDefaultInstallDir();
|
||||
};
|
||||
|
||||
inline std::filesystem::path CModuleControl_Install::GetDefaultInstallDir()
|
||||
{
|
||||
// // The default directory for Windows is located at $ProgramData/ and for Posix at the executable.
|
||||
std::filesystem::path pathInstallDir;
|
||||
//#ifdef _WIN32
|
||||
// wchar_t* szPath = nullptr;
|
||||
// HRESULT hr = SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_DEFAULT, 0, &szPath);
|
||||
// if (SUCCEEDED(hr) && szPath)
|
||||
// pathInstallDir = szPath;
|
||||
// if (szPath) CoTaskMemFree(szPath);
|
||||
//#elif defined __unix__
|
||||
pathInstallDir = GetExecDirectory();
|
||||
//#else
|
||||
//#error OS is not supported!
|
||||
//#endif
|
||||
// Append the installation directory with /<instance_ID>/.
|
||||
pathInstallDir /= "2006";
|
||||
|
||||
return pathInstallDir;
|
||||
}
|
||||
|
||||
TEST_F(CModuleControl_Install, MainApp_DefaultInstallDir)
|
||||
{
|
||||
sdv::app::CAppControl control;
|
||||
bool bResult = control.Startup("[Application]\nMode=\"Main\"\nInstance=2006");
|
||||
EXPECT_TRUE(bResult);
|
||||
|
||||
// The default installation directory should be created.
|
||||
EXPECT_TRUE(std::filesystem::exists(GetDefaultInstallDir()));
|
||||
|
||||
control.Shutdown();
|
||||
}
|
||||
|
||||
TEST_F(CModuleControl_Install, IsolatedApp_DefaultInstallDir)
|
||||
{
|
||||
sdv::app::CAppControl control;
|
||||
std::string ssConnectionString = Base64EncodePlainText("");
|
||||
std::string ssConfig = R"code([Application]
|
||||
Mode = "Isolated"
|
||||
Instance = 2006
|
||||
Connection = ")code";
|
||||
ssConfig += Base64EncodePlainText("test") + "\"";
|
||||
bool bResult = control.Startup(ssConfig);
|
||||
EXPECT_TRUE(bResult);
|
||||
|
||||
// The default installation directory should be created.
|
||||
EXPECT_TRUE(std::filesystem::exists(GetDefaultInstallDir()));
|
||||
|
||||
control.Shutdown();
|
||||
}
|
||||
|
||||
TEST_F(CModuleControl_Install, OtherApp_DefaultInstallDir)
|
||||
{
|
||||
sdv::app::CAppControl control;
|
||||
bool bResult = control.Startup("");
|
||||
EXPECT_TRUE(bResult);
|
||||
|
||||
// The default installation directory should be created.
|
||||
EXPECT_FALSE(std::filesystem::exists(GetDefaultInstallDir()));
|
||||
|
||||
control.Shutdown();
|
||||
}
|
||||
|
||||
TEST_F(CModuleControl_Install, MainApp_BlockDefaultInstallDir)
|
||||
{
|
||||
// Prevent error reporting on std::cerr - they will influence test outcome.
|
||||
auto* pCErr = std::cerr.rdbuf();
|
||||
std::ostringstream sstreamCErr;
|
||||
std::cerr.rdbuf(sstreamCErr.rdbuf());
|
||||
|
||||
// Create a blocking file... cannot create directory!
|
||||
std::ofstream fstream(GetDefaultInstallDir());
|
||||
ASSERT_TRUE(fstream.is_open());
|
||||
fstream << "Dummy string...";
|
||||
fstream.close();
|
||||
|
||||
sdv::app::CAppControl control;
|
||||
bool bResult = control.Startup("[Application]\nMode=\"Main\"\nInstance=2006");
|
||||
EXPECT_FALSE(bResult);
|
||||
|
||||
// The default installation directory should be created.
|
||||
EXPECT_TRUE(std::filesystem::exists(GetDefaultInstallDir()));
|
||||
|
||||
std::cerr.rdbuf(pCErr);
|
||||
}
|
||||
|
||||
TEST_F(CModuleControl_Install, IsolatedApp_BlockDefaultInstallDir)
|
||||
{
|
||||
// Prevent error reporting on std::cerr - they will influence test outcome.
|
||||
auto* pCErr = std::cerr.rdbuf();
|
||||
std::ostringstream sstreamCErr;
|
||||
std::cerr.rdbuf(sstreamCErr.rdbuf());
|
||||
|
||||
std::ofstream fstream(GetDefaultInstallDir());
|
||||
ASSERT_TRUE(fstream.is_open());
|
||||
fstream << "Dummy string...";
|
||||
fstream.close();
|
||||
|
||||
sdv::app::CAppControl control;
|
||||
bool bResult = control.Startup("[Application]\nMode=\"Isolated\"\nInstance=2006");
|
||||
EXPECT_FALSE(bResult);
|
||||
|
||||
// The default installation directory should be created.
|
||||
EXPECT_TRUE(std::filesystem::exists(GetDefaultInstallDir()));
|
||||
|
||||
std::cerr.rdbuf(pCErr);
|
||||
}
|
||||
|
||||
TEST_F(CModuleControl_Install, OtherApp_BlockDefaultInstallDir)
|
||||
{
|
||||
std::ofstream fstream(GetDefaultInstallDir());
|
||||
ASSERT_TRUE(fstream.is_open());
|
||||
fstream << "Dummy string...";
|
||||
fstream.close();
|
||||
|
||||
sdv::app::CAppControl control;
|
||||
bool bResult = control.Startup("");
|
||||
EXPECT_TRUE(bResult);
|
||||
|
||||
// The default installation directory should be created.
|
||||
EXPECT_TRUE(std::filesystem::exists(GetDefaultInstallDir()));
|
||||
|
||||
control.Shutdown();
|
||||
}
|
||||
|
||||
TEST_F(CModuleControl_Install, MainApp_CustomInstallDirRelative)
|
||||
{
|
||||
sdv::app::CAppControl control;
|
||||
bool bResult = control.Startup(R"code(
|
||||
[Application]
|
||||
Mode="Main"
|
||||
Instance=2006
|
||||
InstallDir = "module_test1"
|
||||
)code");
|
||||
EXPECT_TRUE(bResult);
|
||||
|
||||
// The default installation directory should be created.
|
||||
EXPECT_TRUE(std::filesystem::exists(GetExecDirectory() / "module_test1"));
|
||||
|
||||
control.Shutdown();
|
||||
}
|
||||
|
||||
TEST_F(CModuleControl_Install, IsolatedApp_CustomInstallDirRelative)
|
||||
{
|
||||
sdv::app::CAppControl control;
|
||||
bool bResult = control.Startup(std::string(R"code(
|
||||
[Application]
|
||||
Mode="Isolated"
|
||||
Instance=2006
|
||||
InstallDir = "module_test1"
|
||||
Connection = ")code") + Base64EncodePlainText("test") + "\"");
|
||||
EXPECT_TRUE(bResult);
|
||||
|
||||
// The default installation directory should be created.
|
||||
EXPECT_TRUE(std::filesystem::exists(GetExecDirectory() / "module_test1"));
|
||||
|
||||
control.Shutdown();
|
||||
}
|
||||
|
||||
TEST_F(CModuleControl_Install, OtherApp_CustomInstallDirRelative)
|
||||
{
|
||||
sdv::app::CAppControl control;
|
||||
bool bResult = control.Startup(R"code([Application]
|
||||
Install.Dir = "module_test1"
|
||||
)code");
|
||||
EXPECT_TRUE(bResult);
|
||||
|
||||
// The default installation directory should be created.
|
||||
EXPECT_FALSE(std::filesystem::exists(GetExecDirectory() / "module_test1"));
|
||||
|
||||
control.Shutdown();
|
||||
}
|
||||
|
||||
TEST_F(CModuleControl_Install, MainApp_CustomInstallDirAbsolute)
|
||||
{
|
||||
sdv::app::CAppControl control;
|
||||
bool bResult = control.Startup(std::string(R"code(
|
||||
[Application]
|
||||
Mode="Main"
|
||||
Instance=2006
|
||||
InstallDir = ")code") + (GetExecDirectory() / "module_test2").generic_u8string() + "\"");
|
||||
EXPECT_TRUE(bResult);
|
||||
|
||||
// The default installation directory should be created.
|
||||
EXPECT_TRUE(std::filesystem::exists(GetExecDirectory() / "module_test2"));
|
||||
|
||||
control.Shutdown();
|
||||
}
|
||||
|
||||
TEST_F(CModuleControl_Install, IsolatedApp_CustomInstallDirAbsolute)
|
||||
{
|
||||
sdv::app::CAppControl control;
|
||||
bool bResult = control.Startup(std::string(R"code(
|
||||
[Application]
|
||||
Mode="Isolated"
|
||||
Instance=2006
|
||||
InstallDir = ")code") + (GetExecDirectory() / "module_test2").generic_u8string() + "\"" + R"code(
|
||||
Connection = ")code" + Base64EncodePlainText("test") + "\"");
|
||||
EXPECT_TRUE(bResult);
|
||||
|
||||
// The default installation directory should be created.
|
||||
EXPECT_TRUE(std::filesystem::exists(GetExecDirectory() / "module_test2"));
|
||||
|
||||
control.Shutdown();
|
||||
}
|
||||
|
||||
TEST_F(CModuleControl_Install, OtherApp_CustomInstallDirAbsolute)
|
||||
{
|
||||
sdv::app::CAppControl control;
|
||||
bool bResult = control.Startup(std::string(R"code([Application]
|
||||
InstallDir = ")code") + (GetExecDirectory() / "module_test2").generic_u8string() + "\"");
|
||||
EXPECT_TRUE(bResult);
|
||||
|
||||
// The default installation directory should be created.
|
||||
EXPECT_FALSE(std::filesystem::exists(GetExecDirectory() / "module_test2"));
|
||||
|
||||
control.Shutdown();
|
||||
}
|
||||
|
||||
28
tests/component_tests/config_install/test_component.cpp
Normal file
28
tests/component_tests/config_install/test_component.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#include <support/component_impl.h>
|
||||
|
||||
class CModuleTestComponent1 : public sdv::CSdvObject
|
||||
{
|
||||
public:
|
||||
|
||||
BEGIN_SDV_INTERFACE_MAP()
|
||||
END_SDV_INTERFACE_MAP()
|
||||
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::Utility)
|
||||
DECLARE_OBJECT_CLASS_NAME("ModuleTestComponent1")
|
||||
private:
|
||||
};
|
||||
DEFINE_SDV_OBJECT(CModuleTestComponent1)
|
||||
|
||||
class CModuleTestComponent2 : public sdv::CSdvObject
|
||||
{
|
||||
public:
|
||||
|
||||
BEGIN_SDV_INTERFACE_MAP()
|
||||
END_SDV_INTERFACE_MAP()
|
||||
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::Utility)
|
||||
DECLARE_OBJECT_CLASS_NAME("ModuleTestComponent2")
|
||||
private:
|
||||
};
|
||||
DEFINE_SDV_OBJECT(CModuleTestComponent2)
|
||||
|
||||
Reference in New Issue
Block a user