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.
This commit is contained in:
Vadim Zeitlin
2019-04-25 02:55:11 +02:00
parent db0d288f60
commit 9c956ea962

View File

@@ -206,12 +206,16 @@ public:
FSWTesterBase(int types = wxFSW_EVENT_ALL) : FSWTesterBase(int types = wxFSW_EVENT_ALL) :
eg(EventGenerator::Get()), eg(EventGenerator::Get()),
m_count(0), m_eventTypes(types) m_eventTypes(types)
#ifdef OSX_EVENT_LOOP_WORKAROUND #ifdef OSX_EVENT_LOOP_WORKAROUND
, m_loopActivator(&m_loop) , m_loopActivator(&m_loop)
#endif #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); Bind(wxEVT_FSWATCHER, &FSWTesterBase::OnFileSystemEvent, this);
} }
@@ -246,53 +250,25 @@ public:
m_loop.Run(); m_loop.Run();
} }
void OnIdle(wxIdleEvent& /*evt*/) void OnIdleInit(wxIdleEvent& WXUNUSED(event))
{ {
bool more = Action(); // We shouldn't be called again.
m_count++; Unbind(wxEVT_IDLE, &FSWTesterBase::OnIdleInit, this);
if (more) CPPUNIT_ASSERT(Init());
{
SendIdle(); GenerateEvent();
}
// Check the result when the next idle event comes.
Bind(wxEVT_IDLE, &FSWTesterBase::OnIdleCheckResult, this);
} }
// returns whether we should produce more idle events void OnIdleCheckResult(wxIdleEvent& WXUNUSED(event))
virtual bool Action()
{ {
switch (m_count) Unbind(wxEVT_IDLE, &FSWTesterBase::OnIdleCheckResult, this);
{
case 0:
CPPUNIT_ASSERT(Init());
break;
case 1:
GenerateEvent();
break;
case 2:
// actual test
CheckResult();
Exit();
break;
// TODO a mechanism that will break the loop in case we CheckResult();
// don't receive a file system event Exit();
// 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;
} }
virtual bool Init() virtual bool Init()
@@ -407,7 +383,6 @@ protected:
#ifdef OSX_EVENT_LOOP_WORKAROUND #ifdef OSX_EVENT_LOOP_WORKAROUND
wxEventLoopActivator m_loopActivator; wxEventLoopActivator m_loopActivator;
#endif #endif
int m_count; // idle events count
wxScopedPtr<wxFileSystemWatcher> m_watcher; wxScopedPtr<wxFileSystemWatcher> m_watcher;