25static inline bool isXmlFile(
const std::string &filename) {
26 size_t dotPos = filename.find_last_of(
'.');
27 if (dotPos == std::string::npos || dotPos == filename.length() - 1) {
30 std::string extension = filename.substr(dotPos);
31 std::transform(extension.begin(), extension.end(), extension.begin(),
32 [](
unsigned char c) { return std::tolower(c); });
33 return extension ==
".xml";
46static inline std::string
getTargetPath(
const std::string &fullPath,
const std::string &targetDir) {
47 size_t pos = fullPath.rfind(targetDir);
48 if (pos != std::string::npos) {
49 return fullPath.substr(0, pos + targetDir.length());
63static inline bool setupFileTests(std::string &targetPath, std::string &skipReason) {
64 auto getCurrentPath = []() -> std::string {
65 char buffer[PATH_MAX];
66 if (getcwd(buffer,
sizeof(buffer)) !=
nullptr) {
67 return std::string(buffer);
71 auto pathExists = [](
const std::string &path) ->
bool {
return access(path.c_str(), F_OK) == 0; };
72 std::string cwd = getCurrentPath();
74 skipReason =
"Unable to determine current working directory, skipping tests...";
78 if (targetPath.empty()) {
79 skipReason =
"Project root directory not found, skipping tests...";
82 targetPath +=
"/tests/files";
83 if (!pathExists(targetPath)) {
84 skipReason =
"Test files not found, skipping tests...";
Namespace defining utility functions for working with file paths.
Definition PathUtils.h:17
static bool setupFileTests(std::string &targetPath, std::string &skipReason)
Checks if the test file directory can be found.
Definition PathUtils.h:63
static bool isXmlFile(const std::string &filename)
Checks if a file is an XML file by verifying its extension in a case-insensitive way.
Definition PathUtils.h:25
static std::string getTargetPath(const std::string &fullPath, const std::string &targetDir)
Helper method to get the absolute path of a file or directory contained within a given path.
Definition PathUtils.h:46