From 046f228bb21104bec8f1ece08ca19ac6825b9a7f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 10 Feb 2022 13:38:00 +0000 Subject: [PATCH] Reset watch directory in wxFileSystemWatcher unit test Share the same variable between GetWatchDir() and RemoveWatchDir() to make things more clear. Also check for GetWatchDir() postcondition (i.e. that the directory exists) in the function itself instead of doing it in the caller. --- tests/fswatcher/fswatchertest.cpp | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/tests/fswatcher/fswatchertest.cpp b/tests/fswatcher/fswatchertest.cpp index 19aea462fb..eff0df1298 100644 --- a/tests/fswatcher/fswatchertest.cpp +++ b/tests/fswatcher/fswatchertest.cpp @@ -128,32 +128,32 @@ public: // static helpers static const wxFileName& GetWatchDir() { - static wxFileName dir; - - if (dir.DirExists()) - return dir; + if (ms_watchDir.DirExists()) + return ms_watchDir; wxString tmp = wxStandardPaths::Get().GetTempDir(); - dir.AssignDir(tmp); + ms_watchDir.AssignDir(tmp); // XXX look for more unique name? there is no function to generate // unique filename, the file always get created... - dir.AppendDir("fswatcher_test"); - REQUIRE(!dir.DirExists()); - REQUIRE(dir.Mkdir()); + ms_watchDir.AppendDir("fswatcher_test"); + REQUIRE(!ms_watchDir.DirExists()); + REQUIRE(ms_watchDir.Mkdir()); + REQUIRE(ms_watchDir.DirExists()); - return dir; + return ms_watchDir; } static void RemoveWatchDir() { - wxFileName dir = GetWatchDir(); - REQUIRE(dir.DirExists()); + REQUIRE(ms_watchDir.DirExists()); // just to be really sure we know what we remove - REQUIRE( dir.GetDirs().Last() == "fswatcher_test" ); + REQUIRE( ms_watchDir.GetDirs().Last() == "fswatcher_test" ); - CHECK( dir.Rmdir(wxPATH_RMDIR_RECURSIVE) ); + CHECK( ms_watchDir.Rmdir(wxPATH_RMDIR_RECURSIVE) ); + + ms_watchDir = wxFileName(); } static wxFileName RandomName(const wxFileName& base, int length = 10) @@ -178,9 +178,13 @@ public: protected: static EventGenerator* ms_instance; + +private: + static wxFileName ms_watchDir; }; EventGenerator* EventGenerator::ms_instance = 0; +wxFileName EventGenerator::ms_watchDir; // Abstract base class from which concrete event tests inherit. @@ -799,7 +803,6 @@ TEST_CASE_METHOD(FileSystemWatcherTestCase, // We don't use this function for events. Just run the tests wxFileName watchdir = EventGenerator::GetWatchDir(); - REQUIRE(watchdir.DirExists()); wxFileName treedir(watchdir); treedir.AppendDir("treetrunk");