From 277937b0c42955707d0136187d357ea3a985ff19 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 13 Jan 2018 15:56:46 +0100 Subject: [PATCH] Always use stderr for wxMessageOutputBest in the tests Avoid showing message boxes even if we don't have the associated console as this prevents the test from completing on its own if an unknown exception happens. --- tests/test.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/test.cpp b/tests/test.cpp index e8628ac591..09ab1e8f4b 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -46,6 +46,7 @@ std::string wxTheCurrentTestClass, wxTheCurrentTestMethod; #include "wx/wx.h" #endif +#include "wx/apptrait.h" #include "wx/cmdline.h" #include #include @@ -171,8 +172,10 @@ CATCH_TRANSLATE_EXCEPTION(TestAssertFailure& e) #if wxUSE_GUI typedef wxApp TestAppBase; + typedef wxGUIAppTraits TestAppTraitsBase; #else typedef wxAppConsole TestAppBase; + typedef wxConsoleAppTraits TestAppTraitsBase; #endif // The application class @@ -186,6 +189,36 @@ public: virtual bool OnInit(); virtual int OnExit(); +#ifdef __WIN32__ + virtual wxAppTraits *CreateTraits() + { + // Define a new class just to customize CanUseStderr() behaviour. + class TestAppTraits : public TestAppTraitsBase + { + public: + // We want to always use stderr, tests are also run unattended and + // in this case we really don't want to show any message boxes, as + // wxMessageOutputBest, used e.g. from the default implementation + // of wxApp::OnUnhandledException(), would do by default. + virtual bool CanUseStderr() { return true; } + + // Overriding CanUseStderr() is not enough, we also need to + // override this one to avoid returning false from it. + virtual bool WriteToStderr(const wxString& text) + { + wxFputs(text, stderr); + fflush(stderr); + + // Intentionally ignore any errors, we really don't want to + // show any message boxes in any case. + return true; + } + }; + + return new TestAppTraits; + } +#endif // __WIN32__ + // used by events propagation test virtual int FilterEvent(wxEvent& event); virtual bool ProcessEvent(wxEvent& event);