Precommit (#1)

* first commit

* cleanup
This commit is contained in:
tompzf
2025-11-04 13:28:06 +01:00
committed by GitHub
parent dba45dc636
commit 6ed4b1534e
898 changed files with 256340 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
# Define project
project(PathMatchTestTests VERSION 1.0 LANGUAGES CXX)
# Define target
add_executable(UnitTest_PathMatchTest
path_match_test_suite.cpp
path_match_test_suite.h
wildcard_match.cpp
"regex_match.cpp")
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_link_libraries(UnitTest_PathMatchTest GTest::GTest)
if (WIN32)
target_link_libraries(UnitTest_PathMatchTest Ws2_32 Winmm Rpcrt4.lib)
else()
target_link_libraries(UnitTest_PathMatchTest ${CMAKE_DL_LIBS} rt)
endif()
else()
target_link_libraries(UnitTest_PathMatchTest GTest::GTest Rpcrt4.lib)
endif()
# Add the test
add_test(NAME UnitTest_PathMatchTest COMMAND UnitTest_PathMatchTest WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
# Execute the test
add_custom_command(TARGET UnitTest_PathMatchTest POST_BUILD
COMMAND ${CMAKE_COMMAND} -E env TEST_EXECUTION_MODE=CMake "$<TARGET_FILE:UnitTest_PathMatchTest>" --gtest_output=xml:${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/UnitTest_PathMatchTest.xml
VERBATIM
)

View File

@@ -0,0 +1,111 @@
#include "path_match_test_suite.h"
#include "../../../global/exec_dir_helper.h"
#include "../../../global/process_watchdog.h"
#include <filesystem>
#include <fstream>
#include <cstdlib>
#include <string>
#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();
}
void CPathMatchTest::SetUp()
{
}
void CPathMatchTest::TearDown()
{
}
void CPathMatchTest::SetUpTestCase()
{
// Clean up, just in case...
TearDownTestSuite();
// Make rand random
std::srand(static_cast<unsigned int>(std::time({})));
// Create test data
try
{
// Create a dummy file with at the given path.
auto fnCreateDummyFile = [](const std::filesystem::path& rpathFile)
{
std::ofstream stream(rpathFile.native().c_str());
if (!stream.is_open())
{
std::cerr << "Could not open file '" << rpathFile.generic_u8string() << "'" << std::endl;
ASSERT_TRUE(false);
}
uint32_t uiSize = std::rand() & 0x1ffff;
for (uint32_t uiVal = 0; uiVal < uiSize; uiVal++)
stream << uiVal;
stream.close();
};
// The source directory
std::filesystem::path pathSrc = GetExecDirectory() / "path_match_test";
std::filesystem::create_directories(pathSrc);
// Create the following dummy packages:
// subdir1/file10.bin
// subdir1/file11.bin
// subdir2/file20.bin
// subdir2/file21.bin
// subdir2/file22.bia
// subdir3_xyz/file30.bin
// subdir3_xyz/file31.bin
// subdir3_xyz/file32a.bia
// subdir3_xyz/subdir4/file40a.bin
// subdir3_xyz/subdir4/subdir5/file50a.bin
std::filesystem::path pathSrcSubDir1 = pathSrc / "subdir1";
std::filesystem::create_directories(pathSrcSubDir1);
fnCreateDummyFile(pathSrcSubDir1 / "file10.bin");
fnCreateDummyFile(pathSrcSubDir1 / "file11.bin");
std::filesystem::path pathSrcSubDir2 = pathSrc / "subdir2";
std::filesystem::create_directories(pathSrcSubDir2);
fnCreateDummyFile(pathSrcSubDir2 / "file20.bin");
fnCreateDummyFile(pathSrcSubDir2 / "file21.bin");
fnCreateDummyFile(pathSrcSubDir2 / "file22.bia");
std::filesystem::path pathSrcSubDir3 = pathSrc / "subdir3_xyz";
std::filesystem::create_directories(pathSrcSubDir3);
fnCreateDummyFile(pathSrcSubDir3 / "file30.bin");
fnCreateDummyFile(pathSrcSubDir3 / "file31.bin");
fnCreateDummyFile(pathSrcSubDir3 / "file32a.bia");
std::filesystem::path pathSrcSubDir4 = pathSrcSubDir3 / "subdir4";
std::filesystem::create_directories(pathSrcSubDir4);
fnCreateDummyFile(pathSrcSubDir4 / "file40a.bin");
std::filesystem::path pathSrcSubDir5 = pathSrcSubDir4 / "subdir5";
std::filesystem::create_directories(pathSrcSubDir5);
fnCreateDummyFile(pathSrcSubDir5 / "file50a.bin");
}
catch (const std::filesystem::filesystem_error& rexception)
{
// Exception occurred.
std::cerr << "Filesystem exception occurred (create test data): " << rexception.what() << std::endl;
ASSERT_TRUE(false);
}
}
void CPathMatchTest::TearDownTestSuite()
{
try
{
std::filesystem::remove_all(GetExecDirectory() / "path_match_test");
}
catch (const std::filesystem::filesystem_error& rexception)
{
// Exception occurred.
std::cerr << "Filesystem exception occurred (delete target test directories): " << rexception.what() << std::endl;
ASSERT_TRUE(false);
}
}

View File

@@ -0,0 +1,36 @@
#ifndef COMPOSER_TEST_SUITE_H
#define COMPOSER_TEST_SUITE_H
#include <gtest/gtest.h>
#include <filesystem>
#include <regex>
#include <string>
/**
* @brief Install package composer test suite class.
*/
class CPathMatchTest : public ::testing::Test
{
public:
/**
* @brief Setup test test
*/
virtual void SetUp();
/**
* @brief Tear down test
*/
virtual void TearDown();
/**
* @brief Setup test case
*/
static void SetUpTestCase();
/**
* @brief Tear down test case
*/
static void TearDownTestSuite();
};
#endif // !defined COMPOSER_TEST_SUITE_H

View File

@@ -0,0 +1,114 @@
#include "path_match_test_suite.h"
#include "../../../global/path_match.h"
#include "../../../global/exec_dir_helper.h"
using CRegexPathMatchTest = CPathMatchTest;
TEST_F(CRegexPathMatchTest, DirectFile)
{
std::filesystem::path rpathBase = GetExecDirectory() / "path_match_test";
EXPECT_EQ(CollectWildcardPath(rpathBase, "subdir1/file10\\.bin", EPathMatchAlgorithm::regex).size(), 1); // Match exactly "subdir1/file10.bin"
EXPECT_EQ(CollectWildcardPath(rpathBase, "subdir3_xyz/subdir4/subdir5/file50a\\.bin", EPathMatchAlgorithm::regex).size(), 1); // Match exactly "subdir3_xyz/subdir4/subdir5/file50a.bin"
}
TEST_F(CRegexPathMatchTest, DirectDir)
{
std::filesystem::path rpathBase = GetExecDirectory() / "path_match_test";
EXPECT_EQ(CollectWildcardPath(rpathBase, "subdir2/[^/]+", EPathMatchAlgorithm::regex).size(), 3); // Match all files of the "subdir2" directory
}
TEST_F(CRegexPathMatchTest, DoubleAsterisk_Wildcard)
{
std::filesystem::path rpathBase = GetExecDirectory() / "path_match_test";
EXPECT_EQ(CollectWildcardPath(rpathBase, ".*", EPathMatchAlgorithm::regex).size(), 10); // Match all files of all directories
EXPECT_EQ(CollectWildcardPath(rpathBase, ".*/file50a\\.bin", EPathMatchAlgorithm::regex).size(), 1); // Match "file50a.bin" in any directory
EXPECT_EQ(CollectWildcardPath(rpathBase, "subdir3_xyz/.*", EPathMatchAlgorithm::regex).size(), 5); // Match all files in subdir3_xyz directory and any directory underneath
EXPECT_EQ(CollectWildcardPath(rpathBase, "subdir3_xyz/.*/file50a\\.bin", EPathMatchAlgorithm::regex).size(), 1); // Match "file50a.bin" in subdir3_xyz directory and any directory underneath
EXPECT_EQ(CollectWildcardPath(rpathBase, "(.*/)?subdir1/[^/]+", EPathMatchAlgorithm::regex).size(), 2); // Match all files in any directory with the name "subdir1"
EXPECT_EQ(CollectWildcardPath(rpathBase, "(.*/)?subdir4/[^/]+", EPathMatchAlgorithm::regex).size(), 1); // Match all files in any directory with the name "subdir4"
EXPECT_EQ(CollectWildcardPath(rpathBase, "(.*/)?subdir3_xyz/.*/subdir5/[^/]+", EPathMatchAlgorithm::regex).size(), 1); // Match all files in any directory with the name "subdir5" underneath any directory with the name "subdir3_xyz"
EXPECT_EQ(CollectWildcardPath(rpathBase, "subdir3_xyz/(.*/)?subdir4/(.*/)?subdir5/[^/]+", EPathMatchAlgorithm::regex).size(), 1); // Match all files in the directory with the name "subdir5" underneath any directory with the name "subdir4" underneath the directory with the name "subdir3_xyz"
EXPECT_EQ(CollectWildcardPath(rpathBase, "subdir[^/]*/.*", EPathMatchAlgorithm::regex).size(), 10); // Match all files in any directory (as well as subdirectories) starting with the name "subdir"
EXPECT_EQ(CollectWildcardPath(rpathBase, ".*/subdir5/[^/]+", EPathMatchAlgorithm::regex).size(), 1); // Match all files in any directory or subdirectory with the name "subdir5"
}
TEST_F(CRegexPathMatchTest, File_Asterisk_Wildcard)
{
std::filesystem::path rpathBase = GetExecDirectory() / "path_match_test";
EXPECT_EQ(CollectWildcardPath(rpathBase, "subdir1/[^/]+", EPathMatchAlgorithm::regex).size(), 2); // Match all files in the "subdir1" directory
EXPECT_EQ(CollectWildcardPath(rpathBase, "subdir1/[^/]+", EPathMatchAlgorithm::regex).size(), 2); // Match all files with any filename and any extension in the "subdir1" directory
EXPECT_EQ(CollectWildcardPath(rpathBase, "subdir2/[^/]*2[^/]*", EPathMatchAlgorithm::regex).size(), 3); // Match all files with any filename having "2" in the name and any extension in the "subdir2" directory
EXPECT_EQ(CollectWildcardPath(rpathBase, "subdir3_xyz/file[^/]*", EPathMatchAlgorithm::regex).size(), 3); // Match all files in the "subdir3_xyz" directory (but not subdirectory) starting with "file" in its filename
EXPECT_EQ(CollectWildcardPath(rpathBase, "[^/]+/[^/]+", EPathMatchAlgorithm::regex).size(), 8); // Match all files in any top directory (but not from the subdirectories)
EXPECT_EQ(CollectWildcardPath(rpathBase, "subdir3_xyz/[^/]+", EPathMatchAlgorithm::regex).size(), 3); // Match all files in "subdir3_xyz" (but not from the subdirectories)
}
TEST_F(CRegexPathMatchTest, Dir_Asterisk_Wildcard)
{
std::filesystem::path rpathBase = GetExecDirectory() / "path_match_test";
EXPECT_EQ(CollectWildcardPath(rpathBase, "subdir[^/]*/[^/]+", EPathMatchAlgorithm::regex).size(), 8); // Match all files in the top directory starting with "subdir" (but not from the subdirectories)
}
TEST_F(CRegexPathMatchTest, File_QuestionMark_Wildcard)
{
std::filesystem::path rpathBase = GetExecDirectory() / "path_match_test";
EXPECT_EQ(CollectWildcardPath(rpathBase, "subdir2/file2\\w\\.bin", EPathMatchAlgorithm::regex).size(), 2); // Match all files in "subdir2" starting with the filename "file2" followed by an alpha-numerical character and ending with the extension "bin"
EXPECT_EQ(CollectWildcardPath(rpathBase, "subdir1/file1[^1]\\.bin", EPathMatchAlgorithm::regex).size(), 1); // Match all files in "subdir1" starting with the filename "file1" followed by an alpha-numerical character except the the character "1" and ending with the extension "bin"
EXPECT_EQ(CollectWildcardPath(rpathBase, "subdir2/file2\\w\\.b\\w\\w", EPathMatchAlgorithm::regex).size(), 3); // Match all files in "subdir2" starting with the filename "file2" followed by an alpha-numerical character and an extension starting with "b" followed by two alpha-numerical characters
}
TEST_F(CRegexPathMatchTest, Dir_QuestionMark_Wildcard)
{
std::filesystem::path rpathBase = GetExecDirectory() / "path_match_test";
EXPECT_EQ(CollectWildcardPath(rpathBase, "subdir\\w/[^/]+", EPathMatchAlgorithm::regex).size(), 5); // Match all files from the directory starting with "subdir" followed by an alpha-numerical character (but not from the sub-directories)
}
TEST_F(CRegexPathMatchTest, Combination_Wildcards)
{
std::filesystem::path rpathBase = GetExecDirectory() / "path_match_test";
EXPECT_EQ(CollectWildcardPath(rpathBase, "subdir\\w+_xyz/[^/]+", EPathMatchAlgorithm::regex).size(), 3); // Match all files with any name from the directory starting with "subdir" followed by an alpha-numerical character and followed by "*xyz"
EXPECT_EQ(CollectWildcardPath(rpathBase, ".*/file\\w{2}a\\..*", EPathMatchAlgorithm::regex).size(), 3); // Match all files in any of the directories starting with "file" followed by two alpha-numerical characters followed by "a" with any extension
EXPECT_EQ(CollectWildcardPath(rpathBase, "subdir3_.*/[^/]*50[^/]*", EPathMatchAlgorithm::regex).size(), 1); // Match all files having "50" in its file name with any extension in the directory starting with "subdir3*" followed by any text or in any of its subdirectories
EXPECT_EQ(CollectWildcardPath(rpathBase, "subdir\\w/[^/]+", EPathMatchAlgorithm::regex).size(), 5); // Match all files having any name in the directory starting with "subdir" followed by an alpha-numerical character (but not from the sub-directories)
}
TEST_F(CRegexPathMatchTest, Extension_Wildcards)
{
std::filesystem::path rpathBase = GetExecDirectory() / "path_match_test";
EXPECT_EQ(CollectWildcardPath(rpathBase, ".*/[^/]+\\.bin", EPathMatchAlgorithm::regex).size(), 8); // Match all files in any directory with any name having the extension "bin"
EXPECT_EQ(CollectWildcardPath(rpathBase, ".*/[^/]+\\.(?!bin$)[^/]+", EPathMatchAlgorithm::regex).size(), 2); // Match all files in any directory with any name not having the extension "bin"
EXPECT_EQ(CollectWildcardPath(rpathBase, "subdir[^/]*/[^/]+\\.bin", EPathMatchAlgorithm::regex).size(), 6); // Match all files in the directory starting with "subdir" followed by any text (but not from the subdirectories) having the extension "bin"
}
TEST_F(CRegexPathMatchTest, NoMatch)
{
std::filesystem::path rpathBase = GetExecDirectory() / "path_match_test";
EXPECT_EQ(CollectWildcardPath(rpathBase, "subdir1/file1", EPathMatchAlgorithm::regex).size(), 0); // Match exactly "subdir1/file1" (which doesn't exist)
EXPECT_EQ(CollectWildcardPath(rpathBase, "nonexistent/[^/]+", EPathMatchAlgorithm::regex).size(), 0); // Match all files with any name in the directory "nonexistent" (which do not exist)
EXPECT_EQ(CollectWildcardPath(rpathBase, "[^/]+", EPathMatchAlgorithm::regex).size(), 0); // Match all files with any name in the root directory (which do not exist)
EXPECT_EQ(CollectWildcardPath(rpathBase, "subdir1/[^/]+\\.(?!bin$).*", EPathMatchAlgorithm::regex).size(), 0); // Match all files in "subdir1" not having the extension "bin" (which do not exist)
}
TEST_F(CRegexPathMatchTest, Navigation_Pattern)
{
std::filesystem::path rpathBase = GetExecDirectory() / "path_match_test";
// Current and higher directory in pattern
EXPECT_EQ(CollectWildcardPath(rpathBase, "\\./.*file50a\\.bin", EPathMatchAlgorithm::regex).size(), 1); // Match "file50a.bin" in the "." directory or any of its sub-directories
EXPECT_EQ(CollectWildcardPath(rpathBase, "\\.\\./.*file50a\\.bin", EPathMatchAlgorithm::regex).size(), 1); // Match "file50a.bin" in the ".." directory or any of its sub-directories
EXPECT_EQ(CollectWildcardPath(rpathBase, "\\.\\./.*/subdir1/file10\\.bin", EPathMatchAlgorithm::regex).size(), 1); // Match "subdir1/file10.bin" in any directory following the ".." directory (but not from the subdirectories)
EXPECT_EQ(CollectWildcardPath(rpathBase, "[^/]+/\\.\\./subdir1/file10\\.bin", EPathMatchAlgorithm::regex).size(), 1); // Match "subdir1/file10.bin" in the parent directory ".." of any top directory (but not from the subdirectories)
EXPECT_EQ(CollectWildcardPath(rpathBase, ".*/\\.\\./subdir5/file50a\\.bin", EPathMatchAlgorithm::regex).size(), 1); // Match "subdir5/file50a.bin" in the parent directory ".." of any diretory or subdirectory
EXPECT_EQ(CollectWildcardPath(rpathBase, ".*/\\.\\./\\.\\./subdir5/file50a\\.bin", EPathMatchAlgorithm::regex).size(), 1); // Match "subdir5/file50a.bin" in the parent directory ".." of the parent directory ".." of any directory or subdirectory
EXPECT_EQ(CollectWildcardPath(rpathBase, ".*/\\.\\./\\.\\./subdir1/file10\\.bin", EPathMatchAlgorithm::regex).size(), 0); // Match "subdir1/file10.bin" in the parent directory ".." of the parent directory ".." of any directory or subdirectory (which do not exist)
}

View File

@@ -0,0 +1,117 @@
#include "path_match_test_suite.h"
#include "../../../global/path_match.h"
#include "../../../global/exec_dir_helper.h"
using CWildcardPathMatchTest = CPathMatchTest;
TEST_F(CWildcardPathMatchTest, DirectFile)
{
std::filesystem::path rpathBase = GetExecDirectory() / "path_match_test";
EXPECT_EQ(CollectWildcardPath(rpathBase, "subdir1/file10.bin").size(), 1); // Match exactly "subdir1/file10.bin"
EXPECT_EQ(CollectWildcardPath(rpathBase, "subdir3_xyz/subdir4/subdir5/file50a.bin").size(), 1); // Match exactly "subdir3_xyz/subdir4/subdir5/file50a.bin"
}
TEST_F(CWildcardPathMatchTest, DirectDir)
{
std::filesystem::path rpathBase = GetExecDirectory() / "path_match_test";
EXPECT_EQ(CollectWildcardPath(rpathBase, "subdir2").size(), 3); // Match all files of the "subdir2" directory
}
TEST_F(CWildcardPathMatchTest, DoubleAsterisk_Wildcard)
{
std::filesystem::path rpathBase = GetExecDirectory() / "path_match_test";
EXPECT_EQ(CollectWildcardPath(rpathBase, "**").size(), 10); // Match all files of all directories
EXPECT_EQ(CollectWildcardPath(rpathBase, "**/file50a.bin").size(), 1); // Match "file50a.bin" in any directory
EXPECT_EQ(CollectWildcardPath(rpathBase, "subdir3_xyz/**").size(), 5); // Match all files in subdir3_xyz directory and any directory underneath
EXPECT_EQ(CollectWildcardPath(rpathBase, "subdir3_xyz/**/file50a.bin").size(), 1); // Match "file50a.bin" in subdir3_xyz directory and any directory underneath
EXPECT_EQ(CollectWildcardPath(rpathBase, "**/subdir1").size(), 2); // Match all files in any directory with the name "subdir1"
EXPECT_EQ(CollectWildcardPath(rpathBase, "**/subdir4/*").size(), 1); // match all files in any directory with the name "subdir5" underneath any directory with the name "subdir3_xyz"
EXPECT_EQ(CollectWildcardPath(rpathBase, "**/subdir3_xyz/**/subdir5/*").size(), 1); // Match all files in any directory with the name "subdir5" underneath any directory with the name "subdir3_xyz"
EXPECT_EQ(CollectWildcardPath(rpathBase, "subdir3_xyz/**/subdir4/**/subdir5/*").size(), 1); // Match all files in the directory with the name "subdir5" underneath any directory with the name "subdir4" underneath the directory with the name "subdir3_xyz"
EXPECT_EQ(CollectWildcardPath(rpathBase, "**/subdir*").size(), 10); // Match all files in any directory (as well as subdirectories) starting with the name "subdir"
EXPECT_EQ(CollectWildcardPath(rpathBase, "**/subdir5").size(), 1); // Match all files in any directory or subdirectory with the name "subdir5"
EXPECT_EQ(CollectWildcardPath(rpathBase, "**/subdir4*").size(), 1); // Match all files in any directory (as well as subdirectories) starting with the name "subdir4"
EXPECT_EQ(CollectWildcardPath(rpathBase, "**/file4*").size(), 1); // Match all files starting with the name "file4" in any directory (as well as subdirectories)
}
TEST_F(CWildcardPathMatchTest, File_Asterisk_Wildcard)
{
std::filesystem::path rpathBase = GetExecDirectory() / "path_match_test";
EXPECT_EQ(CollectWildcardPath(rpathBase, "subdir1/*").size(), 2); // Match all files in the "subdir1" directory
EXPECT_EQ(CollectWildcardPath(rpathBase, "subdir1/*.*").size(), 2); // Match all files with any filename and any extension in the "subdir1" directory
EXPECT_EQ(CollectWildcardPath(rpathBase, "subdir2/*2*.*").size(), 3); // Match all files with any filename having "2" in the name and any extension in the "subdir2" directory
EXPECT_EQ(CollectWildcardPath(rpathBase, "subdir3_xyz/file*").size(), 3); // Match all files in the "subdir3_xyz" directory (but not subdirectory) starting with "file" in its filename
EXPECT_EQ(CollectWildcardPath(rpathBase, "*/*").size(), 8); // Match all files in any top directory (but not from the subdirectories)
EXPECT_EQ(CollectWildcardPath(rpathBase, "subdir3_xyz/*").size(), 3); // Match all files in "subdir3_xyz" (but not from the subdirectories)
}
TEST_F(CWildcardPathMatchTest, Dir_Asterisk_Wildcard)
{
std::filesystem::path rpathBase = GetExecDirectory() / "path_match_test";
EXPECT_EQ(CollectWildcardPath(rpathBase, "subdir*").size(), 8); // Match all files in the top directory starting with "subdir" (but not from the subdirectories)
}
TEST_F(CWildcardPathMatchTest, File_QuestionMark_Wildcard)
{
std::filesystem::path rpathBase = GetExecDirectory() / "path_match_test";
EXPECT_EQ(CollectWildcardPath(rpathBase, "subdir2/file2?.bin").size(), 2); // Match all files in "subdir2" starting with the filename "file2" followed by an alpha-numerical character and ending with the extension "bin"
EXPECT_EQ(CollectWildcardPath(rpathBase, "subdir1/file1?.bin").size(), 2); // Match all files in "subdir1" starting with the filename "file1" followed by an alpha-numerical character and ending with the extension "bin"
EXPECT_EQ(CollectWildcardPath(rpathBase, "subdir2/file2?.b??").size(), 3); // Match all files in "subdir2" starting with the filename "file2" followed by an alpha-numerical character and an extension starting with "b" followed by two alpha-numerical characters
}
TEST_F(CWildcardPathMatchTest, Dir_QuestionMark_Wildcard)
{
std::filesystem::path rpathBase = GetExecDirectory() / "path_match_test";
EXPECT_EQ(CollectWildcardPath(rpathBase, "subdir?").size(), 5); // Match all files from the directory starting with "subdir" followed by an alpha-numerical character (but not from the sub-directories)
}
TEST_F(CWildcardPathMatchTest, Combination_Wildcards)
{
std::filesystem::path rpathBase = GetExecDirectory() / "path_match_test";
EXPECT_EQ(CollectWildcardPath(rpathBase, "subdir?_xyz/*").size(), 3); // Match all files with any name from the directory starting with "subdir" followed by an alpha-numerical character and followed by "*xyz"
EXPECT_EQ(CollectWildcardPath(rpathBase, "**/file??a.*").size(), 3); // Match all files in any of the directories starting with "file" followed by two alpha-numerical characters followed by "a" with any extension
EXPECT_EQ(CollectWildcardPath(rpathBase, "subdir3_*/**/*50*.*").size(), 1); // Match all files having "50" in its file name with any extension in the directory starting with "subdir3*" followed by any text or in any of its subdirectories
EXPECT_EQ(CollectWildcardPath(rpathBase, "subdir?/*").size(), 5); // Match all files having any name in the directory starting with "subdir" followed by an alpha-numerical character (but not from the sub-directories)
}
TEST_F(CWildcardPathMatchTest, Extension_Wildcards)
{
std::filesystem::path rpathBase = GetExecDirectory() / "path_match_test";
EXPECT_EQ(CollectWildcardPath(rpathBase, "**/*.bin").size(), 8); // Match all files in any directory with any name having the extension "bin"
EXPECT_EQ(CollectWildcardPath(rpathBase, "**/*.bia").size(), 2); // Match all files in any directory with any name having the extension "bia"
EXPECT_EQ(CollectWildcardPath(rpathBase, "subdir*/*.bin").size(), 6); // Match all files in the directory starting with "subdir" followed by any text (but not from the subdirectories) having the extension "bin"
}
TEST_F(CWildcardPathMatchTest, NoMatch)
{
std::filesystem::path rpathBase = GetExecDirectory() / "path_match_test";
EXPECT_EQ(CollectWildcardPath(rpathBase, "subdir1/file1").size(), 0); // Match exactly "subdir1/file1" (which doesn't exist)
EXPECT_EQ(CollectWildcardPath(rpathBase, "nonexistent/*").size(), 0); // Match all files with any name in the directory "nonexistent" (which do not exist)
EXPECT_EQ(CollectWildcardPath(rpathBase, "*").size(), 0); // Match all files with any name in the root directory (which do not exist)
EXPECT_EQ(CollectWildcardPath(rpathBase, "subdir1/file10.bia").size(), 0); // Match exactly "subdir1/file10.bia" (which do not exist)
}
TEST_F(CWildcardPathMatchTest, Navigation_Pattern)
{
std::filesystem::path rpathBase = GetExecDirectory() / "path_match_test";
// Current and higher directory in pattern
EXPECT_EQ(CollectWildcardPath(rpathBase, "./**/file50a.bin").size(), 1); // Match "file50a.bin" in the "." directory or any of its sub-directories
EXPECT_EQ(CollectWildcardPath(rpathBase, "../**/file50a.bin").size(), 1); // Match "file50a.bin" in the ".." directory or any of its sub-directories
EXPECT_EQ(CollectWildcardPath(rpathBase, "../*/subdir1/file10.bin").size(), 1); // Match "subdir1/file10.bin" in any directory following the ".." directory (but not from the subdirectories)
EXPECT_EQ(CollectWildcardPath(rpathBase, "*/../subdir1/file10.bin").size(), 1); // Match "subdir1/file10.bin" in the parent directory ".." of any top directory (but not from the subdirectories)
EXPECT_EQ(CollectWildcardPath(rpathBase, "**/../subdir5/file50a.bin").size(), 1); // Match "subdir5/file50a.bin" in the parent directory ".." of any diretory or subdirectory
EXPECT_EQ(CollectWildcardPath(rpathBase, "**/../../subdir5/file50a.bin").size(), 1); // Match "subdir5/file50a.bin" in the parent directory ".." of the parent directory ".." of any directory or subdirectory
EXPECT_EQ(CollectWildcardPath(rpathBase, "**/../../subdir1/file10.bin").size(), 0); // Match "subdir1/file10.bin" in the parent directory ".." of the parent directory ".." of any directory or subdirectory (which do not exist)
}