Merge branch 'gtk-gui-app-console-mode'

Add a test for running wxGTK GUI apps in console mode.

See #23981, #23990.
This commit is contained in:
Vadim Zeitlin 2023-10-25 23:48:00 +02:00
commit 72b4658d5a
4 changed files with 61 additions and 5 deletions

View file

@ -344,6 +344,11 @@ jobs:
exit $rc
fi
- name: Testing launching GUI test
working-directory: tests
run: |
WX_TEST_DISABLE_GUI=1 ./test_gui
- name: Testing GUI using Xvfb
if: matrix.use_xvfb
working-directory: tests

View file

@ -186,16 +186,24 @@ static void notify_gtk_font_name(GObject*, GParamSpec*, void*)
static bool UpdatePreferDark(GVariant* value)
{
GtkSettings* const settings = gtk_settings_get_default();
// This shouldn't happen, but don't bother doing anything else if it does.
if (!settings)
return false;
// 0: No preference, 1: Prefer dark appearance, 2: Prefer light appearance
gboolean preferDark = g_variant_get_uint32(value) == 1;
GtkSettings* settings = gtk_settings_get_default();
char* themeName;
gboolean preferDarkPrev;
char* themeName = nullptr;
gboolean preferDarkPrev = false;
g_object_get(settings,
"gtk-theme-name", &themeName,
"gtk-application-prefer-dark-theme", &preferDarkPrev, nullptr);
// This is not supposed to happen neither, but don't crash if it does.
if (!themeName)
return false;
// We don't need to enable prefer-dark if the theme is already dark
if (strstr(themeName, "-dark") || strstr(themeName, "-Dark"))
preferDark = false;

View file

@ -1767,6 +1767,6 @@ bool wxWinModule::OnInit()
void wxWinModule::OnExit()
{
Display *xdisplay = wxGlobalDisplay();
XFreeGC( xdisplay, g_eraseGC );
if (Display *xdisplay = wxGlobalDisplay())
XFreeGC( xdisplay, g_eraseGC );
}

View file

@ -340,6 +340,9 @@ public:
virtual int OnRun() override
{
if ( !IsGUIEnabled() )
return 0;
if ( TestAppBase::OnRun() != 0 )
m_exitcode = EXIT_FAILURE;
@ -352,6 +355,35 @@ public:
}
#endif // wxUSE_GUI/!wxUSE_GUI
// Hack to test that GUI applications not using GUI at all work: this was
// broken in the past (see #23981), so now the test suite checks that
// running this test with WX_TEST_DISABLE_GUI works.
#if wxUSE_GUI
bool IsGUIEnabled() const
{
return !wxGetEnv(wxASCII_STR("WX_TEST_DISABLE_GUI"), nullptr);
}
virtual bool Initialize(int& argc, wxChar **argv) override
{
return IsGUIEnabled() ? wxApp::Initialize(argc, argv)
: wxAppConsole::Initialize(argc, argv);
}
virtual bool OnInitGui() override
{
return !IsGUIEnabled() || wxApp::OnInitGui();
}
virtual void CleanUp() override
{
if ( IsGUIEnabled() )
wxApp::CleanUp();
else
wxAppConsole::CleanUp();
}
#endif // wxUSE_GUI
private:
int RunTests();
@ -592,6 +624,14 @@ TestApp::TestApp()
//
bool TestApp::OnInit()
{
#if wxUSE_GUI
if ( !IsGUIEnabled() )
{
wxFputs(wxASCII_STR("Not running tests because GUI is disabled.\n"), stderr);
return true;
}
#endif // wxUSE_GUI
// Hack: don't call TestAppBase::OnInit() to let CATCH handle command line.
// Output some important information about the test environment.
@ -688,6 +728,9 @@ int TestApp::RunTests()
int TestApp::OnExit()
{
#if wxUSE_GUI
if ( !IsGUIEnabled() )
return wxAppConsole::OnExit();
delete GetTopWindow();
#endif // wxUSE_GUI