mirror of
https://github.com/eclipse-openvehicle-api/openvehicle-api.git
synced 2026-07-02 05:35:11 +00:00
45
tests/include/basic_test_helper.h
Normal file
45
tests/include/basic_test_helper.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#include "../../global/exec_dir_helper.h"
|
||||
#include <filesystem>
|
||||
|
||||
inline std::filesystem::path GetRootDirectory()
|
||||
{
|
||||
std::filesystem::path path = GetExecDirectory();
|
||||
std::filesystem::path root = path.root_path();
|
||||
// Check for three existing directories: sdv_services, export and tests. This is the root!
|
||||
do
|
||||
{
|
||||
if (!std::filesystem::exists(path / "sdv_services"))
|
||||
continue;
|
||||
if (!std::filesystem::exists(path / "export"))
|
||||
continue;
|
||||
if (!std::filesystem::exists(path / "tests"))
|
||||
continue;
|
||||
|
||||
// Root directory found
|
||||
break;
|
||||
} while ((path = path.parent_path()), path != root);
|
||||
;
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
inline std::filesystem::path GetConfigFilePath(const std::filesystem::path& filename)
|
||||
{
|
||||
return GetExecDirectory() / "config" / filename;
|
||||
}
|
||||
|
||||
inline std::string GetConfigFile(const std::filesystem::path& filename)
|
||||
{
|
||||
std::filesystem::path configPath = GetConfigFilePath(filename);
|
||||
|
||||
std::ifstream inputStream(configPath);
|
||||
std::string configFileContent((std::istreambuf_iterator<char>(inputStream)), std::istreambuf_iterator<char>());
|
||||
|
||||
return configFileContent;
|
||||
}
|
||||
|
||||
inline std::string GetRepositoryServiceModulePath()
|
||||
{
|
||||
std::filesystem::path currentPath = GetExecDirectory() / "../../bin/repository_service.sdv";
|
||||
return currentPath.generic_u8string();
|
||||
}
|
||||
Reference in New Issue
Block a user