Add test checking the event loop created by application traits

Check that wxConsoleAppTraits creates wxConsoleEventLoop and that
wxGUIAppTraits creates wxGUIEventLoop: as tests/events/evtlooptest.cpp
is compiled into both the console and the GUI test binaries, the same
test case covers both kinds of applications.

The console case failed in monolithic builds before the fix in the
previous commit, see #24909.
This commit is contained in:
John Paul Mattia
2026-07-09 19:49:40 -07:00
parent dd7529cd1a
commit 464153c033
+27
View File
@@ -13,8 +13,13 @@
#include "testprec.h"
#include "wx/app.h"
#include "wx/apptrait.h"
#include "wx/evtloop.h"
#include "wx/timer.h"
#include <memory>
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
@@ -49,6 +54,28 @@ CPPUNIT_TEST_SUITE_REGISTRATION( EvtloopTestCase );
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( EvtloopTestCase, "EvtloopTestCase" );
// Check that the application traits create an event loop of the appropriate
// kind: this notably would not be the case for console applications using a
// monolithic build of the library before the fix for #24909.
#if wxUSE_GUI || wxUSE_CONSOLE_EVENTLOOP
TEST_CASE("EventLoop::CreateFromTraits", "[evtloop]")
{
wxAppTraits* const traits = wxTheApp->GetTraits();
REQUIRE( traits );
std::unique_ptr<wxEventLoopBase> loop(traits->CreateEventLoop());
REQUIRE( loop );
#if wxUSE_GUI
CHECK( dynamic_cast<wxGUIEventLoop*>(loop.get()) );
#else // console application
CHECK( dynamic_cast<wxConsoleEventLoop*>(loop.get()) );
#endif
}
#endif // wxUSE_GUI || wxUSE_CONSOLE_EVENTLOOP
// Helper class to schedule exit of the given event loop after the specified
// delay.
class ScheduleLoopExitTimer : public wxTimer