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