+ // In console applications we run the tests directly from the overridden
+ // OnRun(), but in the GUI ones we run them when we get the first call to
+ // our EVT_IDLE handler to ensure that we do everything from inside the
+ // main event loop. This is especially important under wxOSX/Cocoa where
+ // the main event loop is different from the others but it's also safer to
+ // do it like this in the other ports as we test the GUI code in the same
+ // context as it's used usually, in normal programs, and it might behave
+ // differently without the event loop.
+#if wxUSE_GUI
+ void OnIdle(wxIdleEvent& event)
+ {
+ if ( m_runTests )
+ {
+ m_runTests = false;
+
+#ifdef __WXOSX__
+ // we need to wait until the window is activated and fully ready
+ // otherwise no events can be posted
+ wxEventLoopBase* const loop = wxEventLoop::GetActive();
+ if ( loop )
+ {
+ loop->DispatchTimeout(1000);
+ loop->Yield();
+ }
+#endif // __WXOSX__
+
+ m_exitcode = RunTests();
+ ExitMainLoop();
+ }
+
+ event.Skip();
+ }
+#else // !wxUSE_GUI
+ virtual int OnRun()
+ {
+ m_exitcode = RunTests();
+ return m_exitcode;
+ }
+#endif // wxUSE_GUI/!wxUSE_GUI
+