From 10daded3e932953e441e17b547ab2ab6e811bcc3 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 8 Dec 2015 15:22:01 +0100 Subject: [PATCH] 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 99d9a81e28e93106b2a471198cbfaa474a0fa714, see #17229. --- tests/events/evthandler.cpp | 75 +++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 36 deletions(-) diff --git a/tests/events/evthandler.cpp b/tests/events/evthandler.cpp index a0dd3e604e..4fb44ccfb9 100644 --- a/tests/events/evthandler.cpp +++ b/tests/events/evthandler.cpp @@ -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);