From 789ba56c77fe5bfdcde6156dbc4245b435db7935 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 25 Apr 2019 02:38:46 +0200 Subject: [PATCH 01/14] Rename class used as the test skeleton Use a better name than the absolutely meaningless EventHandler. Also add a brief comment describing this class. No real changes. --- tests/fswatcher/fswatchertest.cpp | 35 +++++++++++++++++-------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/tests/fswatcher/fswatchertest.cpp b/tests/fswatcher/fswatchertest.cpp index 95a9482301..b1be80207b 100644 --- a/tests/fswatcher/fswatchertest.cpp +++ b/tests/fswatcher/fswatchertest.cpp @@ -193,13 +193,16 @@ protected: EventGenerator* EventGenerator::ms_instance = 0; -// custom event handler -class EventHandler : public wxEvtHandler +// Abstract base class from which concrete event tests inherit. +// +// This class provides the common test skeleton which various virtual hooks +// that should or can be reimplemented by the derived classes. +class FSWTesterBase : public wxEvtHandler { public: enum { WAIT_DURATION = 3 }; - EventHandler(int types = wxFSW_EVENT_ALL) : + FSWTesterBase(int types = wxFSW_EVENT_ALL) : eg(EventGenerator::Get()), m_loop(0), #ifdef OSX_EVENT_LOOP_WORKAROUND m_loopActivator(NULL), @@ -210,12 +213,12 @@ public: #ifdef OSX_EVENT_LOOP_WORKAROUND m_loopActivator = new wxEventLoopActivator(m_loop); #endif - Connect(wxEVT_IDLE, wxIdleEventHandler(EventHandler::OnIdle)); + Connect(wxEVT_IDLE, wxIdleEventHandler(FSWTesterBase::OnIdle)); Connect(wxEVT_FSWATCHER, wxFileSystemWatcherEventHandler( - EventHandler::OnFileSystemEvent)); + FSWTesterBase::OnFileSystemEvent)); } - virtual ~EventHandler() + virtual ~FSWTesterBase() { delete m_watcher; #ifdef OSX_EVENT_LOOP_WORKAROUND @@ -521,7 +524,7 @@ void FileSystemWatcherTestCase::TestEventCreate() { wxLogDebug("TestEventCreate()"); - class EventTester : public EventHandler + class EventTester : public FSWTesterBase { public: virtual void GenerateEvent() wxOVERRIDE @@ -552,7 +555,7 @@ void FileSystemWatcherTestCase::TestEventDelete() { wxLogDebug("TestEventDelete()"); - class EventTester : public EventHandler + class EventTester : public FSWTesterBase { public: virtual void GenerateEvent() wxOVERRIDE @@ -585,7 +588,7 @@ void FileSystemWatcherTestCase::TestEventRename() { wxLogDebug("TestEventRename()"); - class EventTester : public EventHandler + class EventTester : public FSWTesterBase { public: virtual void GenerateEvent() wxOVERRIDE @@ -616,7 +619,7 @@ void FileSystemWatcherTestCase::TestEventModify() { wxLogDebug("TestEventModify()"); - class EventTester : public EventHandler + class EventTester : public FSWTesterBase { public: virtual void GenerateEvent() wxOVERRIDE @@ -647,7 +650,7 @@ void FileSystemWatcherTestCase::TestEventAccess() { wxLogDebug("TestEventAccess()"); - class EventTester : public EventHandler + class EventTester : public FSWTesterBase { public: virtual void GenerateEvent() wxOVERRIDE @@ -680,7 +683,7 @@ void FileSystemWatcherTestCase::TestEventAttribute() { wxLogDebug("TestEventAttribute()"); - class EventTester : public EventHandler + class EventTester : public FSWTesterBase { public: virtual void GenerateEvent() wxOVERRIDE @@ -711,12 +714,12 @@ void FileSystemWatcherTestCase::TestSingleWatchtypeEvent() { wxLogDebug("TestSingleWatchtypeEvent()"); - class EventTester : public EventHandler + class EventTester : public FSWTesterBase { public: // We could pass wxFSW_EVENT_CREATE or MODIFY instead, but not RENAME or // DELETE as the event path fields would be wrong in CheckResult() - EventTester() : EventHandler(wxFSW_EVENT_ACCESS) {} + EventTester() : FSWTesterBase(wxFSW_EVENT_ACCESS) {} virtual void GenerateEvent() wxOVERRIDE { @@ -747,7 +750,7 @@ void FileSystemWatcherTestCase::TestSingleWatchtypeEvent() void FileSystemWatcherTestCase::TestTrees() { - class TreeTester : public EventHandler + class TreeTester : public FSWTesterBase { const size_t subdirs; const size_t files; @@ -1003,7 +1006,7 @@ namespace // can't be a weak_definition // // So define this class outside the function instead. -class NoEventsAfterRemoveEventTester : public EventHandler, +class NoEventsAfterRemoveEventTester : public FSWTesterBase, public wxTimer { public: From a83ffbe320a7f928ca94f3227c71ffaae71be693 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 25 Apr 2019 02:43:24 +0200 Subject: [PATCH 02/14] Reduce use of raw pointers Use objects instead of pointers whenever possible and wxScopedPtr instead of raw pointers when we really need to allocate objects on the heap. --- tests/fswatcher/fswatchertest.cpp | 38 ++++++++++++------------------- 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/tests/fswatcher/fswatchertest.cpp b/tests/fswatcher/fswatchertest.cpp index b1be80207b..5251d824a9 100644 --- a/tests/fswatcher/fswatchertest.cpp +++ b/tests/fswatcher/fswatchertest.cpp @@ -25,6 +25,7 @@ #include "wx/evtloop.h" #include "wx/filename.h" #include "wx/filefn.h" +#include "wx/scopedptr.h" #include "wx/stdpaths.h" #include "wx/fswatcher.h" @@ -203,16 +204,12 @@ public: enum { WAIT_DURATION = 3 }; FSWTesterBase(int types = wxFSW_EVENT_ALL) : - eg(EventGenerator::Get()), m_loop(0), + eg(EventGenerator::Get()), + m_count(0), m_eventTypes(types) #ifdef OSX_EVENT_LOOP_WORKAROUND - m_loopActivator(NULL), + , m_loopActivator(&m_loop) #endif - m_count(0), m_watcher(0), m_eventTypes(types) { - m_loop = new wxEventLoop(); -#ifdef OSX_EVENT_LOOP_WORKAROUND - m_loopActivator = new wxEventLoopActivator(m_loop); -#endif Connect(wxEVT_IDLE, wxIdleEventHandler(FSWTesterBase::OnIdle)); Connect(wxEVT_FSWATCHER, wxFileSystemWatcherEventHandler( FSWTesterBase::OnFileSystemEvent)); @@ -220,21 +217,13 @@ public: virtual ~FSWTesterBase() { - delete m_watcher; -#ifdef OSX_EVENT_LOOP_WORKAROUND - delete m_loopActivator; -#endif - if (m_loop) - { - if (m_loop->IsRunning()) - m_loop->Exit(); - delete m_loop; - } + if (m_loop.IsRunning()) + m_loop.Exit(); } void Exit() { - m_loop->Exit(); + m_loop.Exit(); } // sends idle event, so we get called in a moment @@ -247,14 +236,14 @@ public: // The fs watcher test cases will hang on OS X if Yield() is not called. // It seems that the OS X event loop and / or queueing behaves // differently than on MSW and Linux. - m_loop->Yield(true); + m_loop.Yield(true); #endif } void Run() { SendIdle(); - m_loop->Run(); + m_loop.Run(); } void OnIdle(wxIdleEvent& /*evt*/) @@ -313,7 +302,7 @@ public: // XXX only now can we construct Watcher, because we need // active loop here - m_watcher = new wxFileSystemWatcher(); + m_watcher.reset(new wxFileSystemWatcher()); m_watcher->SetOwner(this); // add dir to be watched @@ -415,13 +404,14 @@ public: protected: EventGenerator& eg; - wxEventLoopBase* m_loop; // loop reference + wxEventLoop m_loop; // loop reference #ifdef OSX_EVENT_LOOP_WORKAROUND - wxEventLoopActivator* m_loopActivator; + wxEventLoopActivator m_loopActivator; #endif int m_count; // idle events count - wxFileSystemWatcher* m_watcher; + wxScopedPtr m_watcher; + int m_eventTypes; // Which event-types to watch. Normally all of them bool tested; // indicates, whether we have already passed the test From cd8bbcb8df3cc2c6a3ff85971507a076338c95fe Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 25 Apr 2019 02:44:23 +0200 Subject: [PATCH 03/14] Remove unused variable FileSystemWatcherTestCase::m_loop was never used, so just remove it. --- tests/fswatcher/fswatchertest.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/fswatcher/fswatchertest.cpp b/tests/fswatcher/fswatchertest.cpp index 5251d824a9..3a13a0996c 100644 --- a/tests/fswatcher/fswatchertest.cpp +++ b/tests/fswatcher/fswatchertest.cpp @@ -434,9 +434,6 @@ public: virtual void setUp() wxOVERRIDE; virtual void tearDown() wxOVERRIDE; -protected: - wxEventLoopBase* m_loop; - private: CPPUNIT_TEST_SUITE( FileSystemWatcherTestCase ); CPPUNIT_TEST( TestEventCreate ); From cfb194e55fc27927387b22ba7d4bb58bd0d31d6e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 25 Apr 2019 02:46:32 +0200 Subject: [PATCH 04/14] Use wxVector<> instead of macro-based wxArray Also remove the never used m_lastEvent member variable. No real changes. --- tests/fswatcher/fswatchertest.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/tests/fswatcher/fswatchertest.cpp b/tests/fswatcher/fswatchertest.cpp index 3a13a0996c..60bc5b221c 100644 --- a/tests/fswatcher/fswatchertest.cpp +++ b/tests/fswatcher/fswatchertest.cpp @@ -25,9 +25,10 @@ #include "wx/evtloop.h" #include "wx/filename.h" #include "wx/filefn.h" +#include "wx/fswatcher.h" #include "wx/scopedptr.h" #include "wx/stdpaths.h" -#include "wx/fswatcher.h" +#include "wx/vector.h" #include "testfile.h" @@ -339,8 +340,7 @@ public: virtual void OnFileSystemEvent(wxFileSystemWatcherEvent& evt) { wxLogDebug("--- %s ---", evt.ToString()); - m_lastEvent = wxDynamicCast(evt.Clone(), wxFileSystemWatcherEvent); - m_events.Add(m_lastEvent); + m_events.push_back(wxDynamicCast(evt.Clone(), wxFileSystemWatcherEvent)); // test finished SendIdle(); @@ -415,10 +415,7 @@ protected: int m_eventTypes; // Which event-types to watch. Normally all of them bool tested; // indicates, whether we have already passed the test - #include "wx/arrimpl.cpp" - WX_DEFINE_ARRAY_PTR(wxFileSystemWatcherEvent*, wxArrayEvent); - wxArrayEvent m_events; - wxFileSystemWatcherEvent* m_lastEvent; + wxVector m_events; }; From db0d288f605d8949405f3d17c61882dbfac73f0f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 25 Apr 2019 02:48:25 +0200 Subject: [PATCH 05/14] Use Bind() instead of Connect() Just another modernization, no real changes. --- tests/fswatcher/fswatchertest.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/fswatcher/fswatchertest.cpp b/tests/fswatcher/fswatchertest.cpp index 60bc5b221c..91e53a7bef 100644 --- a/tests/fswatcher/fswatchertest.cpp +++ b/tests/fswatcher/fswatchertest.cpp @@ -211,9 +211,8 @@ public: , m_loopActivator(&m_loop) #endif { - Connect(wxEVT_IDLE, wxIdleEventHandler(FSWTesterBase::OnIdle)); - Connect(wxEVT_FSWATCHER, wxFileSystemWatcherEventHandler( - FSWTesterBase::OnFileSystemEvent)); + Bind(wxEVT_IDLE, &FSWTesterBase::OnIdle, this); + Bind(wxEVT_FSWATCHER, &FSWTesterBase::OnFileSystemEvent, this); } virtual ~FSWTesterBase() From 9c956ea9621b51d6818ce62262d330b5a2e3101e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 25 Apr 2019 02:55:11 +0200 Subject: [PATCH 06/14] Remove strange counter-based idle handling code Just bind the idle events we want to execute dynamically instead. This is already more clear and robust than the old version, but will be simplified event further in the next commit. --- tests/fswatcher/fswatchertest.cpp | 63 ++++++++++--------------------- 1 file changed, 19 insertions(+), 44 deletions(-) diff --git a/tests/fswatcher/fswatchertest.cpp b/tests/fswatcher/fswatchertest.cpp index 91e53a7bef..9785585454 100644 --- a/tests/fswatcher/fswatchertest.cpp +++ b/tests/fswatcher/fswatchertest.cpp @@ -206,12 +206,16 @@ public: FSWTesterBase(int types = wxFSW_EVENT_ALL) : eg(EventGenerator::Get()), - m_count(0), m_eventTypes(types) + m_eventTypes(types) #ifdef OSX_EVENT_LOOP_WORKAROUND , m_loopActivator(&m_loop) #endif { - Bind(wxEVT_IDLE, &FSWTesterBase::OnIdle, this); + // wxFileSystemWatcher can be created only once the event loop is + // running, so we can't do it from here and will do it from inside the + // loop when this event handler is invoked. + Bind(wxEVT_IDLE, &FSWTesterBase::OnIdleInit, this); + Bind(wxEVT_FSWATCHER, &FSWTesterBase::OnFileSystemEvent, this); } @@ -246,53 +250,25 @@ public: m_loop.Run(); } - void OnIdle(wxIdleEvent& /*evt*/) + void OnIdleInit(wxIdleEvent& WXUNUSED(event)) { - bool more = Action(); - m_count++; + // We shouldn't be called again. + Unbind(wxEVT_IDLE, &FSWTesterBase::OnIdleInit, this); - if (more) - { - SendIdle(); - } + CPPUNIT_ASSERT(Init()); + + GenerateEvent(); + + // Check the result when the next idle event comes. + Bind(wxEVT_IDLE, &FSWTesterBase::OnIdleCheckResult, this); } - // returns whether we should produce more idle events - virtual bool Action() + void OnIdleCheckResult(wxIdleEvent& WXUNUSED(event)) { - switch (m_count) - { - case 0: - CPPUNIT_ASSERT(Init()); - break; - case 1: - GenerateEvent(); - break; - case 2: - // actual test - CheckResult(); - Exit(); - break; + Unbind(wxEVT_IDLE, &FSWTesterBase::OnIdleCheckResult, this); - // TODO a mechanism that will break the loop in case we - // don't receive a file system event - // this below doesn't quite work, so all tests must pass :-) -#if 0 - case 2: - m_loop.Yield(); - m_loop.WakeUp(); - CPPUNIT_ASSERT(KeepWaiting()); - m_loop.Yield(); - break; - case 3: - break; - case 4: - CPPUNIT_ASSERT(AfterWait()); - break; -#endif - } // switch (m_count) - - return m_count <= 0; + CheckResult(); + Exit(); } virtual bool Init() @@ -407,7 +383,6 @@ protected: #ifdef OSX_EVENT_LOOP_WORKAROUND wxEventLoopActivator m_loopActivator; #endif - int m_count; // idle events count wxScopedPtr m_watcher; From 4783262238d8902e5bbd56e149f413eeb5c7edcc Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 25 Apr 2019 02:58:53 +0200 Subject: [PATCH 07/14] Simplify the code by using CallAfter() Use CallAfter() to perform idle-time initialization, this is shorter and simpler than dealing with the idle events explicitly. Unfortunately the remaining use of idle events can't be avoided, explain the reasons for this in a comment. --- tests/fswatcher/fswatchertest.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/tests/fswatcher/fswatchertest.cpp b/tests/fswatcher/fswatchertest.cpp index 9785585454..4363dd2517 100644 --- a/tests/fswatcher/fswatchertest.cpp +++ b/tests/fswatcher/fswatchertest.cpp @@ -211,12 +211,12 @@ public: , m_loopActivator(&m_loop) #endif { + Bind(wxEVT_FSWATCHER, &FSWTesterBase::OnFileSystemEvent, this); + // wxFileSystemWatcher can be created only once the event loop is // running, so we can't do it from here and will do it from inside the // loop when this event handler is invoked. - Bind(wxEVT_IDLE, &FSWTesterBase::OnIdleInit, this); - - Bind(wxEVT_FSWATCHER, &FSWTesterBase::OnFileSystemEvent, this); + CallAfter(&FSWTesterBase::OnIdleInit); } virtual ~FSWTesterBase() @@ -246,20 +246,23 @@ public: void Run() { - SendIdle(); m_loop.Run(); } - void OnIdleInit(wxIdleEvent& WXUNUSED(event)) + void OnIdleInit() { - // We shouldn't be called again. - Unbind(wxEVT_IDLE, &FSWTesterBase::OnIdleInit, this); - CPPUNIT_ASSERT(Init()); GenerateEvent(); - // Check the result when the next idle event comes. + // Check the result when the next idle event comes: note that we can't + // use CallAfter() here, unfortunately, because OnIdleCheckResult() + // would then be called immediately, from the same event loop iteration + // as we're called from, because the idle/pending events are processed + // for as long as there any. Instead, we need to return to the event + // loop itself to give it a chance to dispatch wxFileSystemWatcherEvent + // and wait until our handler for it calls SendIdle() which will then + // end up calling OnIdleCheckResult() afterwards. Bind(wxEVT_IDLE, &FSWTesterBase::OnIdleCheckResult, this); } From 194fa8b4ca6d3d13a6b92e34aae6b114f54cb207 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 25 Apr 2019 03:00:07 +0200 Subject: [PATCH 08/14] Remove unneeded KeepWaiting() and AfterWait() functions These functions were never used anywhere and their meaning was not clear, so just drop them. Also remove the now unused "tested" member and "WAIT_DURATION" constant. --- tests/fswatcher/fswatchertest.cpp | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/tests/fswatcher/fswatchertest.cpp b/tests/fswatcher/fswatchertest.cpp index 4363dd2517..e6c5f01265 100644 --- a/tests/fswatcher/fswatchertest.cpp +++ b/tests/fswatcher/fswatchertest.cpp @@ -202,8 +202,6 @@ EventGenerator* EventGenerator::ms_instance = 0; class FSWTesterBase : public wxEvtHandler { public: - enum { WAIT_DURATION = 3 }; - FSWTesterBase(int types = wxFSW_EVENT_ALL) : eg(EventGenerator::Get()), m_eventTypes(types) @@ -291,30 +289,6 @@ public: return true; } - virtual bool KeepWaiting() - { - // did we receive event already? - if (!tested) - { - // well, let's wait a bit more - wxSleep(WAIT_DURATION); - } - - return true; - } - - virtual bool AfterWait() - { - // fail if still no events - WX_ASSERT_MESSAGE - ( - ("No events during %d seconds!", static_cast(WAIT_DURATION)), - tested - ); - - return true; - } - virtual void OnFileSystemEvent(wxFileSystemWatcherEvent& evt) { wxLogDebug("--- %s ---", evt.ToString()); @@ -322,7 +296,6 @@ public: // test finished SendIdle(); - tested = true; } virtual void CheckResult() @@ -390,7 +363,6 @@ protected: wxScopedPtr m_watcher; int m_eventTypes; // Which event-types to watch. Normally all of them - bool tested; // indicates, whether we have already passed the test wxVector m_events; }; From 9adcae898febba86d17e4def522b4104a348b846 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 25 Apr 2019 03:01:53 +0200 Subject: [PATCH 09/14] Make wxFileSystemWatcherEvent handler non-virtual and private There is no reason for it to be neither virtual nor public. --- tests/fswatcher/fswatchertest.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/tests/fswatcher/fswatchertest.cpp b/tests/fswatcher/fswatchertest.cpp index e6c5f01265..71a493f67c 100644 --- a/tests/fswatcher/fswatchertest.cpp +++ b/tests/fswatcher/fswatchertest.cpp @@ -289,15 +289,6 @@ public: return true; } - virtual void OnFileSystemEvent(wxFileSystemWatcherEvent& evt) - { - wxLogDebug("--- %s ---", evt.ToString()); - m_events.push_back(wxDynamicCast(evt.Clone(), wxFileSystemWatcherEvent)); - - // test finished - SendIdle(); - } - virtual void CheckResult() { CPPUNIT_ASSERT_MESSAGE( "No events received", !m_events.empty() ); @@ -365,6 +356,16 @@ protected: int m_eventTypes; // Which event-types to watch. Normally all of them wxVector m_events; + +private: + void OnFileSystemEvent(wxFileSystemWatcherEvent& evt) + { + wxLogDebug("--- %s ---", evt.ToString()); + m_events.push_back(wxDynamicCast(evt.Clone(), wxFileSystemWatcherEvent)); + + // test finished + SendIdle(); + } }; From 12e2f9c0ccf0b19f24d2bb0af92d1f0534458fd5 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 26 Apr 2019 03:25:36 +0200 Subject: [PATCH 10/14] Get rid of CppUnit::TestCase subclass Use a test fixture instead. This gets rid of some boilerplate and allows to avoid repeating preprocessor checks. --- tests/fswatcher/fswatchertest.cpp | 138 ++++++++++++------------------ 1 file changed, 56 insertions(+), 82 deletions(-) diff --git a/tests/fswatcher/fswatchertest.cpp b/tests/fswatcher/fswatchertest.cpp index 71a493f67c..9b86da0875 100644 --- a/tests/fswatcher/fswatchertest.cpp +++ b/tests/fswatcher/fswatchertest.cpp @@ -370,91 +370,38 @@ private: // ---------------------------------------------------------------------------- -// test class +// test fixture // ---------------------------------------------------------------------------- -class FileSystemWatcherTestCase : public CppUnit::TestCase +class FileSystemWatcherTestCase { public: - FileSystemWatcherTestCase() { } + FileSystemWatcherTestCase() + { + wxLog::AddTraceMask(wxTRACE_FSWATCHER); - virtual void setUp() wxOVERRIDE; - virtual void tearDown() wxOVERRIDE; + // Before each test, remove the dir if it exists. + // It would exist if the previous test run was aborted. + wxString tmp = wxStandardPaths::Get().GetTempDir(); + wxFileName dir; + dir.AssignDir(tmp); + dir.AppendDir("fswatcher_test"); + dir.Rmdir(wxPATH_RMDIR_RECURSIVE); + EventGenerator::Get().GetWatchDir(); + } -private: - CPPUNIT_TEST_SUITE( FileSystemWatcherTestCase ); - CPPUNIT_TEST( TestEventCreate ); - CPPUNIT_TEST( TestEventDelete ); - CPPUNIT_TEST( TestTrees ); - - // kqueue-based implementation doesn't collapse create/delete pairs in - // renames and doesn't detect neither modifications nor access to the - // files reliably currently so disable these tests - // - // FIXME: fix the code and reenable them -#ifndef wxHAS_KQUEUE - CPPUNIT_TEST( TestEventRename ); - CPPUNIT_TEST( TestEventModify ); - - // MSW implementation doesn't detect file access events currently -#ifndef __WINDOWS__ - CPPUNIT_TEST( TestEventAccess ); -#endif // __WINDOWS__ -#endif // !wxHAS_KQUEUE - -#ifdef wxHAS_INOTIFY - CPPUNIT_TEST( TestEventAttribute ); - CPPUNIT_TEST( TestSingleWatchtypeEvent ); -#endif // wxHAS_INOTIFY - - CPPUNIT_TEST( TestNoEventsAfterRemove ); - CPPUNIT_TEST_SUITE_END(); - - void TestEventCreate(); - void TestEventDelete(); - void TestEventRename(); - void TestEventModify(); - void TestEventAccess(); -#ifdef wxHAS_INOTIFY - void TestEventAttribute(); - void TestSingleWatchtypeEvent(); -#endif // wxHAS_INOTIFY - void TestTrees(); - void TestNoEventsAfterRemove(); - - wxDECLARE_NO_COPY_CLASS(FileSystemWatcherTestCase); + ~FileSystemWatcherTestCase() + { + EventGenerator::Get().RemoveWatchDir(); + } }; -// register in the unnamed registry so that these tests are run by default -CPPUNIT_TEST_SUITE_REGISTRATION( FileSystemWatcherTestCase ); - -// also include in its own registry so that these tests can be run alone -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( FileSystemWatcherTestCase, - "FileSystemWatcherTestCase" ); - -void FileSystemWatcherTestCase::setUp() -{ - wxLog::AddTraceMask(wxTRACE_FSWATCHER); - - // Before each test, remove the dir if it exists. - // It would exist if the previous test run was aborted. - wxString tmp = wxStandardPaths::Get().GetTempDir(); - wxFileName dir; - dir.AssignDir(tmp); - dir.AppendDir("fswatcher_test"); - dir.Rmdir(wxPATH_RMDIR_RECURSIVE); - EventGenerator::Get().GetWatchDir(); -} - -void FileSystemWatcherTestCase::tearDown() -{ - EventGenerator::Get().RemoveWatchDir(); -} - // ---------------------------------------------------------------------------- // TestEventCreate // ---------------------------------------------------------------------------- -void FileSystemWatcherTestCase::TestEventCreate() + +TEST_CASE_METHOD(FileSystemWatcherTestCase, + "wxFileSystemWatcher::EventCreate", "[fsw]") { wxLogDebug("TestEventCreate()"); @@ -485,7 +432,9 @@ void FileSystemWatcherTestCase::TestEventCreate() // ---------------------------------------------------------------------------- // TestEventDelete // ---------------------------------------------------------------------------- -void FileSystemWatcherTestCase::TestEventDelete() + +TEST_CASE_METHOD(FileSystemWatcherTestCase, + "wxFileSystemWatcher::EventDelete", "[fsw]") { wxLogDebug("TestEventDelete()"); @@ -515,10 +464,19 @@ void FileSystemWatcherTestCase::TestEventDelete() tester.Run(); } +// kqueue-based implementation doesn't collapse create/delete pairs in +// renames and doesn't detect neither modifications nor access to the +// files reliably currently so disable these tests +// +// FIXME: fix the code and reenable them +#ifndef wxHAS_KQUEUE + // ---------------------------------------------------------------------------- // TestEventRename // ---------------------------------------------------------------------------- -void FileSystemWatcherTestCase::TestEventRename() + +TEST_CASE_METHOD(FileSystemWatcherTestCase, + "wxFileSystemWatcher::EventRename", "[fsw]") { wxLogDebug("TestEventRename()"); @@ -549,7 +507,9 @@ void FileSystemWatcherTestCase::TestEventRename() // ---------------------------------------------------------------------------- // TestEventModify // ---------------------------------------------------------------------------- -void FileSystemWatcherTestCase::TestEventModify() + +TEST_CASE_METHOD(FileSystemWatcherTestCase, + "wxFileSystemWatcher::EventModify", "[fsw]") { wxLogDebug("TestEventModify()"); @@ -577,10 +537,15 @@ void FileSystemWatcherTestCase::TestEventModify() tester.Run(); } +// MSW implementation doesn't detect file access events currently +#ifndef __WINDOWS__ + // ---------------------------------------------------------------------------- // TestEventAccess // ---------------------------------------------------------------------------- -void FileSystemWatcherTestCase::TestEventAccess() + +TEST_CASE_METHOD(FileSystemWatcherTestCase, + "wxFileSystemWatcher::EventAccess", "[fsw]") { wxLogDebug("TestEventAccess()"); @@ -609,11 +574,16 @@ void FileSystemWatcherTestCase::TestEventAccess() tester.Run(); } +#endif // __WINDOWS__ + +#endif // !wxHAS_KQUEUE + #ifdef wxHAS_INOTIFY // ---------------------------------------------------------------------------- // TestEventAttribute // ---------------------------------------------------------------------------- -void FileSystemWatcherTestCase::TestEventAttribute() +TEST_CASE_METHOD(FileSystemWatcherTestCase, + "wxFileSystemWatcher::EventAttribute", "[fsw]") { wxLogDebug("TestEventAttribute()"); @@ -644,7 +614,9 @@ void FileSystemWatcherTestCase::TestEventAttribute() // ---------------------------------------------------------------------------- // TestSingleWatchtypeEvent: Watch only wxFSW_EVENT_ACCESS // ---------------------------------------------------------------------------- -void FileSystemWatcherTestCase::TestSingleWatchtypeEvent() + +TEST_CASE_METHOD(FileSystemWatcherTestCase, + "wxFileSystemWatcher::SingleWatchtypeEvent", "[fsw]") { wxLogDebug("TestSingleWatchtypeEvent()"); @@ -682,7 +654,8 @@ void FileSystemWatcherTestCase::TestSingleWatchtypeEvent() // TestTrees // ---------------------------------------------------------------------------- -void FileSystemWatcherTestCase::TestTrees() +TEST_CASE_METHOD(FileSystemWatcherTestCase, + "wxFileSystemWatcher::Trees", "[fsw]") { class TreeTester : public FSWTesterBase { @@ -979,7 +952,8 @@ public: } // anonymous namespace -void FileSystemWatcherTestCase::TestNoEventsAfterRemove() +TEST_CASE_METHOD(FileSystemWatcherTestCase, + "wxFileSystemWatcher::NoEventsAfterRemove", "[fsw]") { NoEventsAfterRemoveEventTester tester; tester.Run(); From ba8a594bb3426055b4bccb3372921a97d11c9be3 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 26 Apr 2019 03:31:38 +0200 Subject: [PATCH 11/14] Remove unnecessary wxLogDebug() from the test cases Tests can be traced using CATCH command line options already, so these log statements were useless. --- tests/fswatcher/fswatchertest.cpp | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/tests/fswatcher/fswatchertest.cpp b/tests/fswatcher/fswatchertest.cpp index 9b86da0875..034a055f07 100644 --- a/tests/fswatcher/fswatchertest.cpp +++ b/tests/fswatcher/fswatchertest.cpp @@ -403,8 +403,6 @@ public: TEST_CASE_METHOD(FileSystemWatcherTestCase, "wxFileSystemWatcher::EventCreate", "[fsw]") { - wxLogDebug("TestEventCreate()"); - class EventTester : public FSWTesterBase { public: @@ -436,8 +434,6 @@ TEST_CASE_METHOD(FileSystemWatcherTestCase, TEST_CASE_METHOD(FileSystemWatcherTestCase, "wxFileSystemWatcher::EventDelete", "[fsw]") { - wxLogDebug("TestEventDelete()"); - class EventTester : public FSWTesterBase { public: @@ -478,8 +474,6 @@ TEST_CASE_METHOD(FileSystemWatcherTestCase, TEST_CASE_METHOD(FileSystemWatcherTestCase, "wxFileSystemWatcher::EventRename", "[fsw]") { - wxLogDebug("TestEventRename()"); - class EventTester : public FSWTesterBase { public: @@ -511,8 +505,6 @@ TEST_CASE_METHOD(FileSystemWatcherTestCase, TEST_CASE_METHOD(FileSystemWatcherTestCase, "wxFileSystemWatcher::EventModify", "[fsw]") { - wxLogDebug("TestEventModify()"); - class EventTester : public FSWTesterBase { public: @@ -547,8 +539,6 @@ TEST_CASE_METHOD(FileSystemWatcherTestCase, TEST_CASE_METHOD(FileSystemWatcherTestCase, "wxFileSystemWatcher::EventAccess", "[fsw]") { - wxLogDebug("TestEventAccess()"); - class EventTester : public FSWTesterBase { public: @@ -585,8 +575,6 @@ TEST_CASE_METHOD(FileSystemWatcherTestCase, TEST_CASE_METHOD(FileSystemWatcherTestCase, "wxFileSystemWatcher::EventAttribute", "[fsw]") { - wxLogDebug("TestEventAttribute()"); - class EventTester : public FSWTesterBase { public: @@ -618,8 +606,6 @@ TEST_CASE_METHOD(FileSystemWatcherTestCase, TEST_CASE_METHOD(FileSystemWatcherTestCase, "wxFileSystemWatcher::SingleWatchtypeEvent", "[fsw]") { - wxLogDebug("TestSingleWatchtypeEvent()"); - class EventTester : public FSWTesterBase { public: From 77645a1aad598152762c66c82a3223cf57e87e07 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 26 Apr 2019 03:39:14 +0200 Subject: [PATCH 12/14] Replace legacy CppUnit macros with CATCH ones No real changes. --- tests/fswatcher/fswatchertest.cpp | 140 +++++++++++++++--------------- 1 file changed, 71 insertions(+), 69 deletions(-) diff --git a/tests/fswatcher/fswatchertest.cpp b/tests/fswatcher/fswatchertest.cpp index 034a055f07..54b1423566 100644 --- a/tests/fswatcher/fswatchertest.cpp +++ b/tests/fswatcher/fswatchertest.cpp @@ -73,7 +73,7 @@ public: bool RenameFile() { - CPPUNIT_ASSERT(m_file.FileExists()); + REQUIRE(m_file.FileExists()); wxLogDebug("Renaming %s=>%s", m_file.GetFullPath(), m_new.GetFullPath()); @@ -90,7 +90,7 @@ public: bool DeleteFile() { - CPPUNIT_ASSERT(m_file.FileExists()); + REQUIRE(m_file.FileExists()); bool ret = wxRemoveFile(m_file.GetFullPath()); if (ret) @@ -111,23 +111,23 @@ public: bool ReadFile() { wxFile f(m_file.GetFullPath()); - CPPUNIT_ASSERT(f.IsOpened()); + REQUIRE(f.IsOpened()); char buf[1]; ssize_t count = f.Read(buf, sizeof(buf)); - CPPUNIT_ASSERT(count > 0); + CHECK(count > 0); return true; } bool ModifyFile() { - CPPUNIT_ASSERT(m_file.FileExists()); + REQUIRE(m_file.FileExists()); wxFile file(m_file.GetFullPath(), wxFile::write_append); - CPPUNIT_ASSERT(file.IsOpened()); + REQUIRE(file.IsOpened()); - CPPUNIT_ASSERT(file.Write("Words of Wisdom, Lloyd. Words of wisdom\n")); + CHECK(file.Write("Words of Wisdom, Lloyd. Words of wisdom\n")); return file.Close(); } @@ -151,8 +151,8 @@ public: // XXX look for more unique name? there is no function to generate // unique filename, the file always get created... dir.AppendDir("fswatcher_test"); - CPPUNIT_ASSERT(!dir.DirExists()); - CPPUNIT_ASSERT(dir.Mkdir()); + REQUIRE(!dir.DirExists()); + REQUIRE(dir.Mkdir()); return dir; } @@ -160,12 +160,12 @@ public: static void RemoveWatchDir() { wxFileName dir = GetWatchDir(); - CPPUNIT_ASSERT(dir.DirExists()); + REQUIRE(dir.DirExists()); // just to be really sure we know what we remove - CPPUNIT_ASSERT_EQUAL( "fswatcher_test", dir.GetDirs().Last() ); + REQUIRE( dir.GetDirs().Last() == "fswatcher_test" ); - CPPUNIT_ASSERT( dir.Rmdir(wxPATH_RMDIR_RECURSIVE) ); + CHECK( dir.Rmdir(wxPATH_RMDIR_RECURSIVE) ); } static wxFileName RandomName(const wxFileName& base, int length = 10) @@ -249,7 +249,7 @@ public: void OnIdleInit() { - CPPUNIT_ASSERT(Init()); + REQUIRE(Init()); GenerateEvent(); @@ -275,7 +275,7 @@ public: virtual bool Init() { // test we're good to go - CPPUNIT_ASSERT(wxEventLoopBase::GetActive()); + CHECK(wxEventLoopBase::GetActive()); // XXX only now can we construct Watcher, because we need // active loop here @@ -284,29 +284,29 @@ public: // add dir to be watched wxFileName dir = EventGenerator::GetWatchDir(); - CPPUNIT_ASSERT(m_watcher->Add(dir, m_eventTypes)); + CHECK(m_watcher->Add(dir, m_eventTypes)); return true; } virtual void CheckResult() { - CPPUNIT_ASSERT_MESSAGE( "No events received", !m_events.empty() ); + REQUIRE( !m_events.empty() ); const wxFileSystemWatcherEvent * const e = m_events.front(); // this is our "reference event" const wxFileSystemWatcherEvent expected = ExpectedEvent(); - CPPUNIT_ASSERT_EQUAL( expected.GetChangeType(), e->GetChangeType() ); + CHECK( e->GetChangeType() == expected.GetChangeType() ); - CPPUNIT_ASSERT_EQUAL((int)wxEVT_FSWATCHER, e->GetEventType()); + CHECK( e->GetEventType() == wxEVT_FSWATCHER ); // XXX this needs change - CPPUNIT_ASSERT_EQUAL(wxEVT_CATEGORY_UNKNOWN, e->GetEventCategory()); + CHECK( e->GetEventCategory() == wxEVT_CATEGORY_UNKNOWN ); - CPPUNIT_ASSERT_EQUAL(expected.GetPath(), e->GetPath()); - CPPUNIT_ASSERT_EQUAL(expected.GetNewPath(), e->GetNewPath()); + CHECK( e->GetPath() == expected.GetPath() ); + CHECK( e->GetNewPath() == expected.GetNewPath() ); // Under MSW extra modification events are sometimes reported after a // rename and we just can't get rid of them, so ignore them in this @@ -408,7 +408,7 @@ TEST_CASE_METHOD(FileSystemWatcherTestCase, public: virtual void GenerateEvent() wxOVERRIDE { - CPPUNIT_ASSERT(eg.CreateFile()); + CHECK(eg.CreateFile()); } virtual wxFileSystemWatcherEvent ExpectedEvent() wxOVERRIDE @@ -439,7 +439,7 @@ TEST_CASE_METHOD(FileSystemWatcherTestCase, public: virtual void GenerateEvent() wxOVERRIDE { - CPPUNIT_ASSERT(eg.DeleteFile()); + CHECK(eg.DeleteFile()); } virtual wxFileSystemWatcherEvent ExpectedEvent() wxOVERRIDE @@ -479,7 +479,7 @@ TEST_CASE_METHOD(FileSystemWatcherTestCase, public: virtual void GenerateEvent() wxOVERRIDE { - CPPUNIT_ASSERT(eg.RenameFile()); + CHECK(eg.RenameFile()); } virtual wxFileSystemWatcherEvent ExpectedEvent() wxOVERRIDE @@ -510,7 +510,7 @@ TEST_CASE_METHOD(FileSystemWatcherTestCase, public: virtual void GenerateEvent() wxOVERRIDE { - CPPUNIT_ASSERT(eg.ModifyFile()); + CHECK(eg.ModifyFile()); } virtual wxFileSystemWatcherEvent ExpectedEvent() wxOVERRIDE @@ -544,7 +544,7 @@ TEST_CASE_METHOD(FileSystemWatcherTestCase, public: virtual void GenerateEvent() wxOVERRIDE { - CPPUNIT_ASSERT(eg.ReadFile()); + CHECK(eg.ReadFile()); } virtual wxFileSystemWatcherEvent ExpectedEvent() wxOVERRIDE @@ -580,7 +580,7 @@ TEST_CASE_METHOD(FileSystemWatcherTestCase, public: virtual void GenerateEvent() wxOVERRIDE { - CPPUNIT_ASSERT(eg.TouchFile()); + CHECK(eg.TouchFile()); } virtual wxFileSystemWatcherEvent ExpectedEvent() wxOVERRIDE @@ -617,9 +617,9 @@ TEST_CASE_METHOD(FileSystemWatcherTestCase, { // As wxFSW_EVENT_ACCESS is passed to the ctor only ReadFile() will // generate an event. Without it they all will, and the test fails - CPPUNIT_ASSERT(eg.CreateFile()); - CPPUNIT_ASSERT(eg.ModifyFile()); - CPPUNIT_ASSERT(eg.ReadFile()); + CHECK(eg.CreateFile()); + CHECK(eg.ModifyFile()); + CHECK(eg.ReadFile()); } virtual wxFileSystemWatcherEvent ExpectedEvent() wxOVERRIDE @@ -657,10 +657,10 @@ TEST_CASE_METHOD(FileSystemWatcherTestCase, #endif ) { - CPPUNIT_ASSERT(dir.Mkdir()); + REQUIRE(dir.Mkdir()); // Now add a subdir with an easy name to remember in WatchTree() dir.AppendDir("child"); - CPPUNIT_ASSERT(dir.Mkdir()); + REQUIRE(dir.Mkdir()); wxFileName child(dir); // Create a copy to which to symlink // Create a branch of 5 numbered subdirs, each containing 3 @@ -668,7 +668,7 @@ TEST_CASE_METHOD(FileSystemWatcherTestCase, for ( unsigned d = 0; d < subdirs; ++d ) { dir.AppendDir(wxString::Format("subdir%u", d+1)); - CPPUNIT_ASSERT(dir.Mkdir()); + REQUIRE(dir.Mkdir()); const wxString prefix = dir.GetPathWithSep(); const wxString ext[] = { ".txt", ".log", "" }; @@ -682,12 +682,17 @@ TEST_CASE_METHOD(FileSystemWatcherTestCase, if ( withSymlinks ) { // Create a symlink to a files, and another to 'child' - CPPUNIT_ASSERT_EQUAL(0, + CHECK + ( symlink(wxString(prefix + "file1").c_str(), - wxString(prefix + "file.lnk").c_str())); - CPPUNIT_ASSERT_EQUAL(0, + wxString(prefix + "file.lnk").c_str()) == 0 + ); + + CHECK + ( symlink(child.GetFullPath().c_str(), - wxString(prefix + "dir.lnk").c_str())); + wxString(prefix + "dir.lnk").c_str()) == 0 + ); } #endif // __UNIX__ } @@ -695,37 +700,35 @@ TEST_CASE_METHOD(FileSystemWatcherTestCase, void RmDir(wxFileName dir) { - CPPUNIT_ASSERT(dir.DirExists()); + REQUIRE(dir.DirExists()); - CPPUNIT_ASSERT(dir.Rmdir(wxPATH_RMDIR_RECURSIVE)); + CHECK(dir.Rmdir(wxPATH_RMDIR_RECURSIVE)); } void WatchDir(wxFileName dir) { - CPPUNIT_ASSERT(m_watcher); + REQUIRE(m_watcher); // Store the initial count; there may already be some watches const int initial = m_watcher->GetWatchedPathsCount(); m_watcher->Add(dir); - CPPUNIT_ASSERT_EQUAL(initial + 1, - m_watcher->GetWatchedPathsCount()); + CHECK( m_watcher->GetWatchedPathsCount() == initial + 1 ); } void RemoveSingleWatch(wxFileName dir) { - CPPUNIT_ASSERT(m_watcher); + REQUIRE(m_watcher); const int initial = m_watcher->GetWatchedPathsCount(); m_watcher->Remove(dir); - CPPUNIT_ASSERT_EQUAL(initial - 1, - m_watcher->GetWatchedPathsCount()); + CHECK( m_watcher->GetWatchedPathsCount() == initial - 1 ); } void WatchTree(const wxFileName& dir) { - CPPUNIT_ASSERT(m_watcher); + REQUIRE(m_watcher); int treeitems = 1; // the trunk #if !defined(__WINDOWS__) && !defined(wxHAVE_FSEVENTS_FILE_NOTIFICATIONS) @@ -743,17 +746,17 @@ TEST_CASE_METHOD(FileSystemWatcherTestCase, m_watcher->AddTree(dir); const int plustree = m_watcher->GetWatchedPathsCount(); - CPPUNIT_ASSERT_EQUAL(initial + treeitems, plustree); + CHECK( plustree == initial + treeitems ); m_watcher->RemoveTree(dir); - CPPUNIT_ASSERT_EQUAL(initial, m_watcher->GetWatchedPathsCount()); + CHECK( m_watcher->GetWatchedPathsCount() == initial ); // Now test the refcount mechanism by watching items more than once wxFileName child(dir); child.AppendDir("child"); m_watcher->AddTree(child); // Check some watches were added; we don't care about the number - CPPUNIT_ASSERT(initial < m_watcher->GetWatchedPathsCount()); + CHECK(initial < m_watcher->GetWatchedPathsCount()); // Now watch the whole tree and check that the count is the same // as it was the first time, despite also adding 'child' separately // Except that in wxMSW this isn't true: each watch will be a @@ -763,11 +766,11 @@ TEST_CASE_METHOD(FileSystemWatcherTestCase, fudge = 1; #endif // __WINDOWS__ || wxHAVE_FSEVENTS_FILE_NOTIFICATIONS m_watcher->AddTree(dir); - CPPUNIT_ASSERT_EQUAL(plustree + fudge, m_watcher->GetWatchedPathsCount()); + CHECK( m_watcher->GetWatchedPathsCount() == plustree + fudge ); m_watcher->RemoveTree(child); - CPPUNIT_ASSERT(initial < m_watcher->GetWatchedPathsCount()); + CHECK(initial < m_watcher->GetWatchedPathsCount()); m_watcher->RemoveTree(dir); - CPPUNIT_ASSERT_EQUAL(initial, m_watcher->GetWatchedPathsCount()); + CHECK( m_watcher->GetWatchedPathsCount() == initial ); #if defined(__UNIX__) // Finally, test a tree containing internal symlinks RmDir(dir); @@ -777,8 +780,8 @@ TEST_CASE_METHOD(FileSystemWatcherTestCase, // (and without the assert, it would infinitely loop) wxFileName fn = dir; fn.DontFollowLink(); - CPPUNIT_ASSERT(m_watcher->AddTree(fn)); - CPPUNIT_ASSERT(m_watcher->RemoveTree(fn)); + CHECK(m_watcher->AddTree(fn)); + CHECK(m_watcher->RemoveTree(fn)); // Regrow the tree without symlinks, ready for the next test RmDir(dir); @@ -788,8 +791,8 @@ TEST_CASE_METHOD(FileSystemWatcherTestCase, void WatchTreeWithFilespec(const wxFileName& dir) { - CPPUNIT_ASSERT(m_watcher); - CPPUNIT_ASSERT(dir.DirExists()); // Was built in WatchTree() + REQUIRE(m_watcher); + REQUIRE(dir.DirExists()); // Was built in WatchTree() // Store the initial count; there may already be some watches const int initial = m_watcher->GetWatchedPathsCount(); @@ -805,20 +808,19 @@ TEST_CASE_METHOD(FileSystemWatcherTestCase, #endif m_watcher->AddTree(dir, wxFSW_EVENT_ALL, "*.txt"); - const int plustree = m_watcher->GetWatchedPathsCount(); - CPPUNIT_ASSERT_EQUAL(initial + treeitems, plustree); + CHECK( m_watcher->GetWatchedPathsCount() == initial + treeitems ); // RemoveTree should try to remove only those files that were added m_watcher->RemoveTree(dir); - CPPUNIT_ASSERT_EQUAL(initial, m_watcher->GetWatchedPathsCount()); + CHECK( m_watcher->GetWatchedPathsCount() == initial ); } void RemoveAllWatches() { - CPPUNIT_ASSERT(m_watcher); + REQUIRE(m_watcher); m_watcher->RemoveAll(); - CPPUNIT_ASSERT_EQUAL(0, m_watcher->GetWatchedPathsCount()); + CHECK( m_watcher->GetWatchedPathsCount() == 0 ); } virtual void GenerateEvent() wxOVERRIDE @@ -826,16 +828,16 @@ TEST_CASE_METHOD(FileSystemWatcherTestCase, // We don't use this function for events. Just run the tests wxFileName watchdir = EventGenerator::GetWatchDir(); - CPPUNIT_ASSERT(watchdir.DirExists()); + REQUIRE(watchdir.DirExists()); wxFileName treedir(watchdir); treedir.AppendDir("treetrunk"); - CPPUNIT_ASSERT(!treedir.DirExists()); + CHECK(!treedir.DirExists()); wxFileName singledir(watchdir); singledir.AppendDir("single"); - CPPUNIT_ASSERT(!singledir.DirExists()); - CPPUNIT_ASSERT(singledir.Mkdir()); + CHECK(!singledir.DirExists()); + CHECK(singledir.Mkdir()); WatchDir(singledir); WatchTree(treedir); @@ -861,7 +863,7 @@ TEST_CASE_METHOD(FileSystemWatcherTestCase, virtual wxFileSystemWatcherEvent ExpectedEvent() wxOVERRIDE { - CPPUNIT_FAIL("Shouldn't be called"); + FAIL("Shouldn't be called"); return wxFileSystemWatcherEvent(wxFSW_EVENT_ERROR); } @@ -915,17 +917,17 @@ public: virtual void GenerateEvent() wxOVERRIDE { m_watcher->Remove(EventGenerator::GetWatchDir()); - CPPUNIT_ASSERT(eg.CreateFile()); + CHECK(eg.CreateFile()); } virtual void CheckResult() wxOVERRIDE { - CPPUNIT_ASSERT( m_events.empty() ); + REQUIRE( m_events.empty() ); } virtual wxFileSystemWatcherEvent ExpectedEvent() wxOVERRIDE { - CPPUNIT_FAIL( "Shouldn't be called" ); + FAIL( "Shouldn't be called" ); return wxFileSystemWatcherEvent(wxFSW_EVENT_ERROR); } From 1b7b79e1c2c9f550e98c34d762f46497efdd1373 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 26 Apr 2019 13:15:35 +0200 Subject: [PATCH 13/14] Remove wxLog::AddTraceMask() call This shouldn't be done unconditionally, trace mask can always be enabled using WXTRACE environment variable from outside the test. Also remove a useless tracing message. --- tests/fswatcher/fswatchertest.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/fswatcher/fswatchertest.cpp b/tests/fswatcher/fswatchertest.cpp index 54b1423566..3f9ad29696 100644 --- a/tests/fswatcher/fswatchertest.cpp +++ b/tests/fswatcher/fswatchertest.cpp @@ -378,8 +378,6 @@ class FileSystemWatcherTestCase public: FileSystemWatcherTestCase() { - wxLog::AddTraceMask(wxTRACE_FSWATCHER); - // Before each test, remove the dir if it exists. // It would exist if the previous test run was aborted. wxString tmp = wxStandardPaths::Get().GetTempDir(); @@ -422,8 +420,6 @@ TEST_CASE_METHOD(FileSystemWatcherTestCase, EventTester tester; - wxLogTrace(wxTRACE_FSWATCHER, "TestEventCreate tester created()"); - tester.Run(); } From 0b9041dd29e9de0ff0047da206eb375ff93c38c6 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 26 Apr 2019 13:32:51 +0200 Subject: [PATCH 14/14] Remove macOS workaround unnecessary any longer The workaround introduced by f0e098fa060d30122669ef53baa0de6bf873d69a doesn't seem to be needed any more, the test passes just fine without it, so remove it. See #16969. --- tests/fswatcher/fswatchertest.cpp | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/tests/fswatcher/fswatchertest.cpp b/tests/fswatcher/fswatchertest.cpp index 3f9ad29696..75decc1cf0 100644 --- a/tests/fswatcher/fswatchertest.cpp +++ b/tests/fswatcher/fswatchertest.cpp @@ -32,15 +32,6 @@ #include "testfile.h" -/* -This test used to be disabled on OS X as it hung. Work around the apparent -wxOSX differences between a non-GUI event loop and a GUI event loop (where -the tests do run fine) until this gets resolved. -*/ -#ifdef __WXOSX__ - #define OSX_EVENT_LOOP_WORKAROUND -#endif - // ---------------------------------------------------------------------------- // local functions // ---------------------------------------------------------------------------- @@ -205,9 +196,6 @@ public: FSWTesterBase(int types = wxFSW_EVENT_ALL) : eg(EventGenerator::Get()), m_eventTypes(types) -#ifdef OSX_EVENT_LOOP_WORKAROUND - , m_loopActivator(&m_loop) -#endif { Bind(wxEVT_FSWATCHER, &FSWTesterBase::OnFileSystemEvent, this); @@ -233,13 +221,6 @@ public: { wxIdleEvent* e = new wxIdleEvent(); QueueEvent(e); - -#ifdef OSX_EVENT_LOOP_WORKAROUND - // The fs watcher test cases will hang on OS X if Yield() is not called. - // It seems that the OS X event loop and / or queueing behaves - // differently than on MSW and Linux. - m_loop.Yield(true); -#endif } void Run() @@ -347,9 +328,6 @@ public: protected: EventGenerator& eg; wxEventLoop m_loop; // loop reference -#ifdef OSX_EVENT_LOOP_WORKAROUND - wxEventLoopActivator m_loopActivator; -#endif wxScopedPtr m_watcher; @@ -873,15 +851,7 @@ TEST_CASE_METHOD(FileSystemWatcherTestCase, TreeTester tester; -// The fs watcher test cases will hang on OS X if we call Run(). -// This is likely due to differences between the event loop -// between OS X and the other ports. -#ifdef OSX_EVENT_LOOP_WORKAROUND - tester.Init(); - tester.GenerateEvent(); -#else tester.Run(); -#endif }