From 2dcf45104428d1785a7a239b35de4adc784b73ce Mon Sep 17 00:00:00 2001 From: zshuang0316 Date: Mon, 1 Dec 2025 16:04:46 +0800 Subject: [PATCH] in_blob: fix glob function for win32 Signed-off-by: zshuang0316 --- plugins/in_blob/win32_glob.c | 1 + tests/internal/CMakeLists.txt | 7 ++++ tests/internal/win32_glob.c | 74 +++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 tests/internal/win32_glob.c diff --git a/plugins/in_blob/win32_glob.c b/plugins/in_blob/win32_glob.c index 9bba4ca1e1c..a4d1183269a 100644 --- a/plugins/in_blob/win32_glob.c +++ b/plugins/in_blob/win32_glob.c @@ -150,6 +150,7 @@ static int glob(const char *path, return result; } } + context->gl_pathc = entries; } return result; diff --git a/tests/internal/CMakeLists.txt b/tests/internal/CMakeLists.txt index 45d769b9c25..33dbd435d35 100644 --- a/tests/internal/CMakeLists.txt +++ b/tests/internal/CMakeLists.txt @@ -81,6 +81,13 @@ if(FLB_HAVE_LIBYAML) ) endif() +if (WIN32) + set(UNIT_TESTS_FILES + ${UNIT_TESTS_FILES} + win32_glob.c + ) +endif() + if (NOT WIN32) set(UNIT_TESTS_FILES ${UNIT_TESTS_FILES} diff --git a/tests/internal/win32_glob.c b/tests/internal/win32_glob.c new file mode 100644 index 00000000000..25709cbf358 --- /dev/null +++ b/tests/internal/win32_glob.c @@ -0,0 +1,74 @@ +#include +#include +#include +#include "flb_tests_internal.h" + +#ifdef FLB_SYSTEM_WINDOWS +#include "../../plugins/in_blob/win32_glob.c" + +void test_glob_basic() +{ + glob_t glob_data; + int ret; + FILE *fp; + + /* Create some dummy files */ + fp = fopen("test_glob_1.txt", "w"); + if (fp) fclose(fp); + fp = fopen("test_glob_2.txt", "w"); + if (fp) fclose(fp); + + ret = glob("test_glob_*.txt", 0, NULL, &glob_data); + TEST_CHECK(ret == 0); + TEST_CHECK(glob_data.gl_pathc == 2); + + globfree(&glob_data); + + /* Cleanup */ + unlink("test_glob_1.txt"); + unlink("test_glob_2.txt"); +} + +void test_glob_nomatch() +{ + glob_t glob_data = {0}; + int ret; + + ret = glob("non_existent_*.txt", 0, NULL, &glob_data); + TEST_CHECK(ret == GLOB_NOMATCH); + + globfree(&glob_data); +} + +void test_glob_wildcard() +{ + glob_t glob_data; + int ret; + FILE *fp; + + /* Create dummy file */ + fp = fopen("test_wildcard.txt", "w"); + if (fp) fclose(fp); + + ret = glob("test_wild*.txt", 0, NULL, &glob_data); + TEST_CHECK(ret == 0); + TEST_CHECK(glob_data.gl_pathc == 1); + if (glob_data.gl_pathc > 0) { + TEST_CHECK(strstr(glob_data.gl_pathv[0], "test_wildcard.txt") != NULL); + } + + globfree(&glob_data); + unlink("test_wildcard.txt"); +} + +TEST_LIST = { + { "basic", test_glob_basic }, + { "nomatch", test_glob_nomatch }, + { "wildcard", test_glob_wildcard }, + { 0 } +}; +#else +TEST_LIST = { + { 0 } +}; +#endif \ No newline at end of file