Fix UnbindFromHandler() test compilation with C++98

Can't declare classes inside the function as they must have external linkage
to be usable with Bind().

Fixes the build after 99d9a81e28, see #17229.
This commit is contained in:
Vadim Zeitlin
2015-12-08 15:22:01 +01:00
parent 60c2b96aef
commit 10daded3e9

View File

@@ -462,46 +462,49 @@ void EvtHandlerTestCase::InvalidBind()
#endif
}
// Helpers for UnbindFromHandler() test, have to be declared outside of the
// function in C++98.
struct Handler1
{
void OnDontCall(MyEvent&)
{
// Although this handler is bound, the second one below is bound
// later and so will be called first and will disconnect this one
// before it has a chance to be called.
CPPUNIT_FAIL("shouldn't be called");
}
};
class Handler2
{
public:
Handler2(MyHandler& handler, Handler1& h1)
: m_handler(handler),
m_h1(h1)
{
}
void OnUnbind(MyEvent& e)
{
m_handler.Unbind(MyEventType, &Handler1::OnDontCall, &m_h1);
// Check that the now disconnected first handler is not executed.
e.Skip();
}
private:
MyHandler& m_handler;
Handler1& m_h1;
wxDECLARE_NO_COPY_CLASS(Handler2);
};
void EvtHandlerTestCase::UnbindFromHandler()
{
struct Handler1
{
void OnDontCall(MyEvent&)
{
// Although this handler is bound, the second one below is bound
// later and so will be called first and will disconnect this one
// before it has a chance to be called.
CPPUNIT_FAIL("shouldn't be called");
}
} h1;
Handler1 h1;
handler.Bind(MyEventType, &Handler1::OnDontCall, &h1);
class Handler2
{
public:
Handler2(MyHandler& handler, Handler1& h1)
{
m_handler = &handler;
m_h1 = &h1;
}
void OnUnbind(MyEvent& e)
{
m_handler->Unbind(MyEventType, &Handler1::OnDontCall, m_h1);
// Check that the now disconnected first handler is not executed.
e.Skip();
}
private:
// Use pointers instead of references just to avoid warnings about the
// class being non-copyable even though these pointers don't change and
// are non-NULL.
MyHandler* m_handler;
Handler1* m_h1;
} h2(handler, h1);
Handler2 h2(handler, h1);
handler.Bind(MyEventType, &Handler2::OnUnbind, &h2);
handler.ProcessEvent(e);