From d18a16c401c0508389f236467e98ddf1bb80ec3b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 30 Sep 2023 16:30:33 +0200 Subject: [PATCH] Add an interactive test for PathMatchSpecEx() This test allows to compare the results of wxString::Matches(), wxMatchWild() and MSW native function for the same filter. --- tests/file/dir.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/file/dir.cpp b/tests/file/dir.cpp index 28967b5fdd..17d715b108 100644 --- a/tests/file/dir.cpp +++ b/tests/file/dir.cpp @@ -257,3 +257,45 @@ TEST_CASE_METHOD(DirTestCase, "Dir::GetName", "[dir]") CHECK( d.GetNameWithSep() == "/" ); #endif } + +// Disabled by default test allowing to check the result of matching against +// the given filter. +#ifdef __WXMSW__ + +#include "wx/msw/wrapwin.h" +#include +#ifdef __VISUALC__ + #pragma comment(lib, "shlwapi") +#endif + +#include "wx/crt.h" +#include "wx/filefn.h" + +TEST_CASE("Dir::Match", "[.]") +{ + wxString filter; + REQUIRE( wxGetEnv("WX_TEST_DIR_FILTER", &filter) ); + + static const wxString filenames[] = + { + "foo", + "foo.bar", + "foo.bar.baz", + ".hidden", + ".hidden.ext", + }; + + // Show the results of matching the pattern using various functions. + wxPrintf("%-15s %20s %20s %20s\n", + "File", "wxString::Matches", "wxMatchWild", "PathMatchSpecEx"); + for ( const auto& fn : filenames ) + { + wxPrintf("%-15s %20d %20d %20d\n", + fn, + fn.Matches(filter), + wxMatchWild(filter, fn), + PathMatchSpecEx(fn.wc_str(), filter.wc_str(), PMSF_NORMAL) == S_OK); + } +} + +#endif // __WXMSW__