Merge branch 'msw-fnmatch-all'

Fix using *.* and similar patterns in wxDir under MSW: they're supposed
to match all files and not only files with extensions.

See #23910.
This commit is contained in:
Vadim Zeitlin 2023-10-02 19:29:31 +02:00
commit a4d2e36cec
2 changed files with 77 additions and 31 deletions

View file

@ -20,6 +20,16 @@
#define DIRTEST_FOLDER wxString("dirTest_folder")
#define SEP wxFileName::GetPathSeparator()
// We can't use wxFileSelectorDefaultWildcardStr from wxCore here, so define
// our own.
const wxString WILDCARD_ALL =
#if defined(__WXMSW__)
"*.*"
#else // Unix/Mac
"*"
#endif
;
// ----------------------------------------------------------------------------
// test fixture
// ----------------------------------------------------------------------------
@ -145,6 +155,21 @@ TEST_CASE_METHOD(DirTestCase, "Dir::Traverse", "[dir]")
wxArrayString files;
CHECK( wxDir::GetAllFiles(DIRTEST_FOLDER, &files) == 4 );
// enum all files using an explicit wildcard
CHECK(wxDir::GetAllFiles(DIRTEST_FOLDER, &files, WILDCARD_ALL) == 4);
// enum all files using an explicit wildcard different from WILDCARD_ALL
//
// broken under Wine, see https://bugs.winehq.org/show_bug.cgi?id=55677
if ( !wxIsRunningUnderWine() )
{
CHECK(wxDir::GetAllFiles(DIRTEST_FOLDER, &files, "d" + WILDCARD_ALL) == 4);
}
else if (wxDir::GetAllFiles(DIRTEST_FOLDER, &files, "d" + WILDCARD_ALL) == 4)
{
WARN("PathMatchSpec() seems to work under Wine now");
}
// enum all files according to the filter
CHECK( wxDir::GetAllFiles(DIRTEST_FOLDER, &files, "*.foo") == 1 );
@ -232,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 <shlwapi.h>
#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", "PathMatchSpec");
for ( const auto& fn : filenames )
{
wxPrintf("%-15s %20d %20d %20d\n",
fn,
fn.Matches(filter),
wxMatchWild(filter, fn),
PathMatchSpec(fn.wc_str(), filter.wc_str()) == TRUE);
}
}
#endif // __WXMSW__