From cb49eb516203d0d8a3490ca689c8bf49760620b9 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 24 Feb 2016 19:38:10 +0100 Subject: [PATCH 01/11] Fix harmless deprecation warning for g_type_init() in drawing test Same as 3dde6ec2feb2bb34a5ee95bcac44c91c2525a54a. --- tests/drawing/fonttest.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/drawing/fonttest.cpp b/tests/drawing/fonttest.cpp index c7c0a0457d..c439dfca3d 100644 --- a/tests/drawing/fonttest.cpp +++ b/tests/drawing/fonttest.cpp @@ -36,7 +36,9 @@ GraphicsContextDrawingTestCase::ms_drawingFontTc = { void GraphicsContextDrawingTestCase::DoFontDrawings (wxGraphicsContext *gc) { #ifdef __WXGTK__ + wxGCC_WARNING_SUPPRESS(deprecated-declarations) g_type_init(); + wxGCC_WARNING_RESTORE() #endif // This test is expected to treat about fonts/texts. Fonts are a bit special From b58c87db287407f5a47477a3f9a00e18e756718e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 26 Feb 2016 14:36:01 +0100 Subject: [PATCH 02/11] Avoid gcc deprecation warnings for wxNORMAL in the tests We use wxNORMAL intentionally to test for its support, so we're not interested in deprecation warnings about it. --- tests/font/fonttest.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/font/fonttest.cpp b/tests/font/fonttest.cpp index 51078680a1..cd5f908ac4 100644 --- a/tests/font/fonttest.cpp +++ b/tests/font/fonttest.cpp @@ -114,10 +114,14 @@ void FontTestCase::Construct() #pragma warning(disable:4996) #endif + wxGCC_WARNING_SUPPRESS(deprecated-declarations) + // Tests relying on the soon-to-be-deprecated ctor taking ints and not // wxFontXXX enum elements. CPPUNIT_ASSERT( wxFont(10, wxDEFAULT, wxNORMAL, wxNORMAL).IsOk() ); + wxGCC_WARNING_RESTORE() + #ifdef __VISUALC__ #pragma warning(pop) #endif From fde8f93a4982ece4015627d677011e54f8ee8d24 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 26 Feb 2016 15:09:39 +0100 Subject: [PATCH 03/11] Fix ellipsization unit test when using pixel scaling When pixel doubling is in use, e.g. when using GTK+ 2 on high DPI displays, the width of a single TAB can be greater than the hardcoded 50 width in the test, which resulted in test failures. Base the widths on the average character width to make sure we can always ellipsize. --- tests/graphics/ellipsization.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/graphics/ellipsization.cpp b/tests/graphics/ellipsization.cpp index 1b6a20cb04..2a584762f2 100644 --- a/tests/graphics/ellipsization.cpp +++ b/tests/graphics/ellipsization.cpp @@ -86,7 +86,8 @@ void EllipsizationTestCase::NormalCase() wxELLIPSIZE_END }; - int widthsToTest[] = { 50, 100, 150 }; + const int charWidth = dc.GetCharWidth(); + int widthsToTest[] = { 6*charWidth, 10*charWidth, 15*charWidth }; for ( unsigned int s = 0; s < WXSIZEOF(stringsToTest); s++ ) { @@ -110,8 +111,10 @@ void EllipsizationTestCase::NormalCase() WX_ASSERT_MESSAGE ( ( - "invalid ellipsization for \"%s\" (%dpx, should be <=%dpx)", + "Test #(%u,%u.%u): \"%s\" -> \"%s\"; width=%dpx > %dpx", + s, f, m, str, + ret, dc.GetMultiLineTextExtent(ret).GetWidth(), widthsToTest[w] ), From ea489e1a7dd234f5c473acb6853efa649ad8a556 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 26 Feb 2016 20:11:55 +0100 Subject: [PATCH 04/11] Fix assertion in the HtmlParser unit test case Use wxHtmlWinParser instead of wxHtmlParser which can't be actually used without being initialized with the tag handlers (it's not clear whether this is really intentional...). --- tests/html/htmlparser.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/html/htmlparser.cpp b/tests/html/htmlparser.cpp index 57687ffe40..29c3cb5c1f 100644 --- a/tests/html/htmlparser.cpp +++ b/tests/html/htmlparser.cpp @@ -19,9 +19,10 @@ #endif #ifndef WX_PRECOMP + #include "wx/dcmemory.h" #endif // WX_PRECOMP -#include "wx/html/htmlpars.h" +#include "wx/html/winpars.h" // ---------------------------------------------------------------------------- // test class @@ -55,7 +56,7 @@ CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( HtmlParserTestCase, "HtmlParserTestCase" // Test that parsing invalid HTML simply fails but doesn't crash for example. void HtmlParserTestCase::Invalid() { - class NullParser : public wxHtmlParser + class NullParser : public wxHtmlWinParser { public: virtual wxObject *GetProduct() { return NULL; } @@ -65,6 +66,9 @@ void HtmlParserTestCase::Invalid() }; NullParser p; + wxMemoryDC dc; + p.SetDC(&dc); + p.Parse("<"); p.Parse(" Date: Fri, 26 Feb 2016 20:28:05 +0100 Subject: [PATCH 05/11] dd a hack to make wxBitmapComboBox Editable() unit test pass Sleep for a little while before sending text to this control as the test often (although not always) fails without it under wxGTK. --- tests/controls/textentrytest.cpp | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/tests/controls/textentrytest.cpp b/tests/controls/textentrytest.cpp index 19b41ff406..b5c4fddfe9 100644 --- a/tests/controls/textentrytest.cpp +++ b/tests/controls/textentrytest.cpp @@ -211,21 +211,6 @@ private: void TextEntryTestCase::Editable() { - -#ifdef __WXGTK__ - // FIXME: For some reason this test regularly (although not always) fails - // in wxGTK build bot builds when testing wxBitmapComboBox, but I - // can't reproduce the failure locally. For now, disable this check - // to let the entire test suite pass in automatic tests instead of - // failing sporadically. - if ( wxStrcmp(GetTestWindow()->GetClassInfo()->GetClassName(), - "wxBitmapComboBox") == 0 && - IsAutomaticTest() ) - { - return; - } -#endif // __WGTK__ - wxTextEntry * const entry = GetTestEntry(); wxWindow * const window = GetTestWindow(); @@ -234,6 +219,13 @@ void TextEntryTestCase::Editable() window->SetFocus(); wxYield(); +#ifdef __WXGTK__ + // For some reason, wxBitmapComboBox doesn't appear on the screen without + // this (due to wxTLW size hacks perhaps?). It would be nice to avoid doing + // this, but without this hack the test often (although not always) fails. + wxMilliSleep(50); +#endif // __WGTK__ + // Check that we get the expected number of events. wxUIActionSimulator sim; sim.Text("abcdef"); From 6c2e702357a72a2ae3115f42f672676a54464e46 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 26 Feb 2016 20:40:30 +0100 Subject: [PATCH 06/11] Add another sleep to make menu unit test pass under wxGTK At least when using GNOME, the frame containing the menu doesn't appear on screen in time for wxUIActionSimulator to use it without this. --- tests/menu/menu.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/menu/menu.cpp b/tests/menu/menu.cpp index 4d921cec3f..454baac66c 100644 --- a/tests/menu/menu.cpp +++ b/tests/menu/menu.cpp @@ -499,6 +499,12 @@ void MenuTestCase::Events() m_frame->SetFocus(); wxYield(); +#ifdef __WXGTK__ + // This is another test which fails with wxGTK without this delay because + // the frame doesn't appear on screen in time. + wxMilliSleep(50); +#endif // __WXGTK__ + wxUIActionSimulator sim; sim.KeyDown(WXK_F1); sim.KeyUp(WXK_F1); From e29bfda8d81babc3263b14a48349a798d1ba7731 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 27 Feb 2016 02:41:11 +0100 Subject: [PATCH 07/11] Fix wxComboBox unit test under wxGTK after recent changes wxEVT_COMBOBOX_CLOSEUP is sent during idle time after the changes of a216806c996ab6e42f73a821857542774a9c1f79, so add wxYield() to make sure that the unit test gets it. See #17223. --- tests/controls/comboboxtest.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/controls/comboboxtest.cpp b/tests/controls/comboboxtest.cpp index 1fe0d004e0..705f406318 100644 --- a/tests/controls/comboboxtest.cpp +++ b/tests/controls/comboboxtest.cpp @@ -145,10 +145,16 @@ void ComboBoxTestCase::PopDismiss() EventCounter close(m_combo, wxEVT_COMBOBOX_CLOSEUP); m_combo->Popup(); + CPPUNIT_ASSERT_EQUAL(1, drop.GetCount()); + m_combo->Dismiss(); - CPPUNIT_ASSERT_EQUAL(1, drop.GetCount()); +#if defined(__WXGTK__) && !defined(__WXGTK3__) + // Under wxGTK2, the event is sent only during idle time and not + // immediately, so we need this yield to get it. + wxYield(); CPPUNIT_ASSERT_EQUAL(1, close.GetCount()); +#endif // wxGTK2 #endif } From de491dd67fa3ded88ce713b346d561c2da3394dd Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 27 Feb 2016 01:56:23 +0100 Subject: [PATCH 08/11] Show wxTestableFrame from its ctor No real changes, just always show the frame as we need it to be shown for the tests to run anyhow. Also update the nonsensical comment about creating a hidden window just before showing it. --- tests/test.cpp | 5 ++--- tests/testableframe.cpp | 2 ++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/test.cpp b/tests/test.cpp index 55f741af62..85060d3cd4 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -559,9 +559,8 @@ bool TestApp::OnInit() cout << std::endl; #if wxUSE_GUI - // create a hidden parent window to be used as parent for the GUI controls - wxTestableFrame* frame = new wxTestableFrame(); - frame->Show(); + // create a parent window to be used as parent for the GUI controls + new wxTestableFrame(); Connect(wxEVT_IDLE, wxIdleEventHandler(TestApp::OnIdle)); #endif // wxUSE_GUI diff --git a/tests/testableframe.cpp b/tests/testableframe.cpp index 1b63defb88..dc535a1f43 100644 --- a/tests/testableframe.cpp +++ b/tests/testableframe.cpp @@ -20,6 +20,8 @@ wxTestableFrame::wxTestableFrame() : wxFrame(NULL, wxID_ANY, "Test Frame") { // Use fixed position to facilitate debugging. Move(200, 200); + + Show(); } void wxTestableFrame::OnEvent(wxEvent& evt) From 9fee931d6d303924c050d78740c3c9cc40ce4cd8 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 27 Feb 2016 02:22:25 +0100 Subject: [PATCH 09/11] Work around a crash in wxGTK3 GUI test suite The tests crashed after running ModalDialogsTestCase::FileDialog() because the next call to wxYield() resulted in the completion of an async operation launched by the native file dialog which tried to dereference the already destroyed dialog. --- tests/controls/dialogtest.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/controls/dialogtest.cpp b/tests/controls/dialogtest.cpp index bc65c2f0ac..3c2decde87 100644 --- a/tests/controls/dialogtest.cpp +++ b/tests/controls/dialogtest.cpp @@ -79,6 +79,13 @@ void ModalDialogsTestCase::FileDialog() CPPUNIT_ASSERT_EQUAL((int)wxID_OK, rc); CPPUNIT_ASSERT_EQUAL("test.txt", dlg.GetFilename()); + +#ifdef __WXGTK3__ + // The native file dialog in GTK+ 3 launches an async operation which tries + // to dereference the already deleted dialog object if we don't let it to + // complete before leaving this function. + wxYield(); +#endif } From 6a7420e454982f3a079b93ce7bd869216b4f29e1 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 27 Feb 2016 02:32:25 +0100 Subject: [PATCH 10/11] Don't try to redraw empty areas in wxGTK wxDataViewCtrl This just results in warnings from pixman_region32_init_rect() and doesn't seem to have any useful effects. --- src/gtk/dataview.cpp | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index e5c4feba52..346100f609 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -1670,20 +1670,27 @@ bool wxGtkDataViewModelNotifier::ValueChanged( const wxDataViewItem &item, unsig GTK_TREE_MODEL(wxgtk_model), &iter )); GdkRectangle cell_area; gtk_tree_view_get_cell_area( widget, path, gcolumn, &cell_area ); -#ifdef __WXGTK3__ - GtkAdjustment* hadjust = gtk_scrollable_get_hadjustment(GTK_SCROLLABLE(widget)); -#else - GtkAdjustment* hadjust = gtk_tree_view_get_hadjustment( widget ); -#endif - double d = gtk_adjustment_get_value( hadjust ); - int xdiff = (int) d; - GtkAllocation a; - gtk_widget_get_allocation(GTK_WIDGET(gtk_tree_view_column_get_button(gcolumn)), &a); - int ydiff = a.height; - // Redraw - gtk_widget_queue_draw_area( GTK_WIDGET(widget), - cell_area.x - xdiff, ydiff + cell_area.y, cell_area.width, cell_area.height ); + // Don't try to redraw the column if it's invisible, this just + // results in "BUG" messages from pixman_region32_init_rect() + // and would be useful even if it didn't anyhow. + if ( cell_area.width > 0 && cell_area.height > 0 ) + { +#ifdef __WXGTK3__ + GtkAdjustment* hadjust = gtk_scrollable_get_hadjustment(GTK_SCROLLABLE(widget)); +#else + GtkAdjustment* hadjust = gtk_tree_view_get_hadjustment( widget ); +#endif + double d = gtk_adjustment_get_value( hadjust ); + int xdiff = (int) d; + + GtkAllocation a; + gtk_widget_get_allocation(GTK_WIDGET(gtk_tree_view_column_get_button(gcolumn)), &a); + int ydiff = a.height; + // Redraw + gtk_widget_queue_draw_area( GTK_WIDGET(widget), + cell_area.x - xdiff, ydiff + cell_area.y, cell_area.width, cell_area.height ); + } } m_internal->ValueChanged( item, model_column ); From 01ed444267dd52e94c7f74f6bdbb757b1b61421d Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 27 Feb 2016 02:34:41 +0100 Subject: [PATCH 11/11] Avoid allocating empty size for wxGTK widgets This suppresses warning messages from GTK+ (pixman to be more precise) if there is really no space left for a widget and doesn't seem to have any ill effects. Closes #16996. --- src/gtk/win_gtk.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/gtk/win_gtk.cpp b/src/gtk/win_gtk.cpp index b0f7721f36..ab6ddd363f 100644 --- a/src/gtk/win_gtk.cpp +++ b/src/gtk/win_gtk.cpp @@ -115,7 +115,14 @@ static void pizza_size_allocate(GtkWidget* widget, GtkAllocation* alloc) child_alloc.height = child->height; if (gtk_widget_get_direction(widget) == GTK_TEXT_DIR_RTL) child_alloc.x = w - child_alloc.x - child_alloc.width; - gtk_widget_size_allocate(child->widget, &child_alloc); + + // GTK+3 doesn't like allocating 0 size, so don't do it. +#ifdef __WXGTK3__ + if (child_alloc.width && child_alloc.height) +#endif + { + gtk_widget_size_allocate(child->widget, &child_alloc); + } } } }