From e8ceaabb87006ab1378e38b91cc516ca0197a1ff Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 7 Nov 2017 02:33:25 +0100 Subject: [PATCH 01/19] Avoid gcc -Wunused-function warnings in wxEvtHandler unit test The warnings are justified as the functions defined by the event table macros are indeed not used here because we only write them to test that they compile, but not useful, so suppress them. --- tests/events/evthandler.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/events/evthandler.cpp b/tests/events/evthandler.cpp index ac8b59bd0c..b25f4f65aa 100644 --- a/tests/events/evthandler.cpp +++ b/tests/events/evthandler.cpp @@ -127,6 +127,11 @@ private: wxDECLARE_EVENT_TABLE(); }; +// Avoid gcc warning about some of the functions defined by the expansion of +// the event table macros being unused: they are indeed unused, but we still +// want to have them to check that they compile. +wxGCC_WARNING_SUPPRESS(unused-function) + wxBEGIN_EVENT_TABLE(MyClassWithEventTable, wxEvtHandler) EVT_IDLE(MyClassWithEventTable::OnIdle) @@ -138,6 +143,8 @@ wxBEGIN_EVENT_TABLE(MyClassWithEventTable, wxEvtHandler) //EVT_IDLE(MyClassWithEventTable::OnAnotherEvent) wxEND_EVENT_TABLE() +wxGCC_WARNING_RESTORE(unused-function) + } // anonymous namespace From cacb49c4adecb258a140f1450c471bed44b6e96c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 7 Nov 2017 02:37:24 +0100 Subject: [PATCH 02/19] Remove "test" from the sections names in Catch unit tests It doesn't really add anything and it's more convenient to specify the section on the command line (using the "-c" option) if it's just a single word, without spaces, as it doesn't need to be quoted then. --- include/wx/catch_cppunit.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/wx/catch_cppunit.h b/include/wx/catch_cppunit.h index 6d14137de3..f9472b8446 100644 --- a/include/wx/catch_cppunit.h +++ b/include/wx/catch_cppunit.h @@ -205,7 +205,7 @@ inline std::string wxGetCurrentTestName() struct EatNextSemicolon #define CPPUNIT_TEST(testname) \ - SECTION(#testname " test") \ + SECTION(#testname) \ { \ setUp(); \ try \ From 79d35109f042c36dbfe389dc4454f9f4b619f8c3 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 7 Nov 2017 02:41:24 +0100 Subject: [PATCH 03/19] Avoid assert if there is no selection in wxListCtrl::DeleteItem() Don't try making the current item visible if there is no current item. This is another fix after 99d7b13e3f221ed622143b5420afca244bf0007d (in addition to the previous 925a1c0734eef56ec6a9c5d5f89f6c4285768f0a). --- src/generic/listctrl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index 6f90877e3d..1ea2442ffa 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -4097,7 +4097,7 @@ void wxListMainWindow::DeleteItem( long lindex ) // with many items, the vertical scroll position may change so that the new // last item is not visible any longer, which is very annoying from the // user point of view. Ensure that whatever happens, this item is visible. - if (count > 1) + if ( count > 1 && m_current != (size_t)-1 ) EnsureVisible(m_current); } From 3069167dd476f09f2454bd5e61a3fa007fc5aa1d Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 7 Nov 2017 02:52:06 +0100 Subject: [PATCH 04/19] Do set the current test name when running the tests The variables and helper TempStringAssign class were added in order to implement this, but somehow it was never done, so wxGetCurrentTestName() always returned an empty string. Fix this and so store the class/method name of the currently running test in the global variables to give more context, notably for GTK+ errors. --- include/wx/catch_cppunit.h | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/include/wx/catch_cppunit.h b/include/wx/catch_cppunit.h index f9472b8446..22ebcf12f9 100644 --- a/include/wx/catch_cppunit.h +++ b/include/wx/catch_cppunit.h @@ -202,22 +202,24 @@ inline std::string wxGetCurrentTestName() public: \ void runTest() wxOVERRIDE \ { \ - struct EatNextSemicolon + using namespace wxPrivate; \ + TempStringAssign setClass(wxTheCurrentTestClass, #testclass) -#define CPPUNIT_TEST(testname) \ - SECTION(#testname) \ - { \ - setUp(); \ - try \ - { \ - testname(); \ - } \ - catch ( ... ) \ - { \ - tearDown(); \ - throw; \ - } \ - tearDown(); \ +#define CPPUNIT_TEST(testname) \ + SECTION(#testname) \ + { \ + TempStringAssign setMethod(wxTheCurrentTestMethod, #testname); \ + setUp(); \ + try \ + { \ + testname(); \ + } \ + catch ( ... ) \ + { \ + tearDown(); \ + throw; \ + } \ + tearDown(); \ } #define CPPUNIT_TEST_SUITE_END() \ From 13163fb315ac055890f3e339a6acc02158913f57 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 7 Nov 2017 03:06:03 +0100 Subject: [PATCH 05/19] Send event when clearing wxTextCtrl in wxGTK again This was broken by 1c946a469a36006b8f262473c4e6355987bfb28b and resulted in test failures in OwnerDrawnComboBoxTestCase::TextChangeEvents() unit test because wxOwnerDrawnComboBox::Clear() used SetValue("") and didn't generate any events any more. Fix this regression by explicitly sending an event if we're returning early and add a unit test explicitly checking that SetValue("") does generate an event. --- src/gtk/textctrl.cpp | 5 +++++ tests/controls/textentrytest.cpp | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index 56f5848901..c3d56aaee2 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -1046,7 +1046,12 @@ void wxTextCtrl::WriteText( const wxString &text ) wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") ); if ( text.empty() ) + { + // We don't need to actually do anything, but we still need to generate + // an event expected from this call. + SendTextUpdatedEvent(this); return; + } // we're changing the text programmatically DontMarkDirtyOnNextChange(); diff --git a/tests/controls/textentrytest.cpp b/tests/controls/textentrytest.cpp index b5c4fddfe9..96b121de84 100644 --- a/tests/controls/textentrytest.cpp +++ b/tests/controls/textentrytest.cpp @@ -57,6 +57,10 @@ void TextEntryTestCase::TextChangeEvents() CPPUNIT_ASSERT_EQUAL( 1, updated.GetCount() ); updated.Clear(); + entry->SetValue(""); + CPPUNIT_ASSERT_EQUAL( 1, updated.GetCount() ); + updated.Clear(); + entry->ChangeValue("bar"); CPPUNIT_ASSERT_EQUAL( 0, updated.GetCount() ); From 72fe57ec182ba0bc9a51ad27adc883a945d39b81 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 7 Nov 2017 03:14:49 +0100 Subject: [PATCH 06/19] Use wxTextEntry::Clear() in wxOwnerDrawnComboBox::Clear() This seems more natural than calling SetValue(wxEmptyString). No real changes. --- src/generic/odcombo.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/generic/odcombo.cpp b/src/generic/odcombo.cpp index 1f7c923839..89ec54016b 100644 --- a/src/generic/odcombo.cpp +++ b/src/generic/odcombo.cpp @@ -991,9 +991,7 @@ void wxOwnerDrawnComboBox::DoClear() GetVListBoxComboPopup()->Clear(); - // NB: This really needs to be SetValue() instead of ChangeValue(), - // as wxTextEntry API expects an event to be sent. - SetValue(wxEmptyString); + wxTextEntry::Clear(); } void wxOwnerDrawnComboBox::Clear() From 1c4e8377b74706b877043e259c2b7cfdbe1ff29d Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 7 Nov 2017 03:42:23 +0100 Subject: [PATCH 07/19] Fix XYToPosition() for the last position in first line in wxGTK This is similar to e74fb5effe6542340af85d50970787c133a911af for wxMSW and ensures that we don't consider the last position on the first line invalid in wxGTK neither. This fixes TextCtrlTestCase::XYToPositionSingleLine() unit test failure. --- src/gtk/textctrl.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index c3d56aaee2..255544eeda 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -1192,8 +1192,7 @@ long wxTextCtrl::XYToPosition(long x, long y ) const { if ( IsSingleLine() ) { - - if ( y != 0 || x >= GTKGetEntryTextLength(GTK_ENTRY(m_text)) ) + if ( y != 0 || x > GTKGetEntryTextLength(GTK_ENTRY(m_text)) ) return -1; return x; From 6d55a533a31287546a588a6a9e9cc54bb78cec14 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 7 Nov 2017 03:44:45 +0100 Subject: [PATCH 08/19] Add overview of wxTextCtrl positions and coordinates Explain the various coordinates that can be used and which positions are considered valid and which are not. --- interface/wx/textctrl.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/interface/wx/textctrl.h b/interface/wx/textctrl.h index 150a137ec3..a2c9615d4a 100644 --- a/interface/wx/textctrl.h +++ b/interface/wx/textctrl.h @@ -1033,6 +1033,31 @@ public: correspond to the positions in the value string. + @section textctrl_positions_xy wxTextCtrl Positions and Coordinates + + It is possible to use either linear positions, i.e. roughly (but @e not + always exactly, as explained in the previous section) the index of the + character in the text contained in the control or X-Y coordinates, i.e. + column and line of the character when working with this class and it + provides the functions PositionToXY() and XYToPosition() to convert between + the two. + + Additionally, a position in the control can be converted to its coordinates + in pixels using PositionToCoords() which can be useful to e.g. show a popup + menu near the given character. And, in the other direction, HitTest() can + be used to find the character under, or near, the given pixel coordinates. + + To be more precise, positions actually refer to the gaps between characters + and not the characters themselves. Thus, position 0 is the one before the + very first character in the control and so is a valid position even when + the control is empty. And if the control contains a single character, it + has two valid positions: 0 before this character and 1 -- after it. This, + when the documentation of various functions mentions "invalid position", it + doesn't consider the position just after the last character of the line to + be invalid, only the positions beyond that one (e.g. 2 and greater in the + single character example) are actually invalid. + + @section textctrl_styles wxTextCtrl Styles. Multi-line text controls support styling, i.e. provide a possibility to set From faad429b0f3bf2824d9764072e8edc42b62fb29e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 7 Nov 2017 14:12:48 +0100 Subject: [PATCH 09/19] Fix wxTextCtrl::XYToPosition() for last position in wxGTK Change this method to consider the coordinates corresponding to the last position (i.e. the one beyond the last text character) as valid, for consistency with wxMSW and to conform to the documented behaviour. Also give more information about the failures in the corresponding unit test to make debugging problems with this function simpler. --- src/gtk/textctrl.cpp | 20 ++++++++++++++++++-- tests/controls/textctrltest.cpp | 5 +++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index 255544eeda..2495c498df 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -1198,13 +1198,29 @@ long wxTextCtrl::XYToPosition(long x, long y ) const return x; } + const gint numLines = gtk_text_buffer_get_line_count (m_buffer); + GtkTextIter iter; - if (y >= gtk_text_buffer_get_line_count (m_buffer)) + if (y >= numLines) return -1; gtk_text_buffer_get_iter_at_line(m_buffer, &iter, y); - if (x >= gtk_text_iter_get_chars_in_line (&iter)) + + const gint lineLength = gtk_text_iter_get_chars_in_line (&iter); + if (x > lineLength) + { + // This coordinate is always invalid. return -1; + } + + if (x == lineLength) + { + // In this case the coordinate is considered to be valid by wx if this + // is the last line, as it corresponds to the last position beyond the + // last character of the text, and invalid otherwise. + if (y != numLines - 1) + return -1; + } return gtk_text_iter_get_offset(&iter) + x; } diff --git a/tests/controls/textctrltest.cpp b/tests/controls/textctrltest.cpp index 175d46d011..89ff430cd3 100644 --- a/tests/controls/textctrltest.cpp +++ b/tests/controls/textctrltest.cpp @@ -935,6 +935,7 @@ void TextCtrlTestCase::DoXYToPositionMultiLine(long style) for( long x = 0; x < maxLineLength_0+1; x++ ) { long p = m_text->XYToPosition(x, y); + INFO("x=" << x << ", y=" << y); CPPUNIT_ASSERT_EQUAL( pos_0[y][x], p ); } @@ -951,6 +952,7 @@ void TextCtrlTestCase::DoXYToPositionMultiLine(long style) for( long x = 0; x < maxLineLength_1+1; x++ ) { long p = m_text->XYToPosition(x, y); + INFO("x=" << x << ", y=" << y); CPPUNIT_ASSERT_EQUAL( pos_1[y][x], p ); } @@ -985,6 +987,7 @@ void TextCtrlTestCase::DoXYToPositionMultiLine(long style) for( long x = 0; x < maxLineLength_2+1; x++ ) { long p = m_text->XYToPosition(x, y); + INFO("x=" << x << ", y=" << y); CPPUNIT_ASSERT_EQUAL( ref_pos_2[y][x], p ); } @@ -1021,6 +1024,7 @@ void TextCtrlTestCase::DoXYToPositionMultiLine(long style) for( long x = 0; x < maxLineLength_3+1; x++ ) { long p = m_text->XYToPosition(x, y); + INFO("x=" << x << ", y=" << y); CPPUNIT_ASSERT_EQUAL( ref_pos_3[y][x], p ); } @@ -1061,6 +1065,7 @@ void TextCtrlTestCase::DoXYToPositionMultiLine(long style) for( long x = 0; x < maxLineLength_4+1; x++ ) { long p = m_text->XYToPosition(x, y); + INFO("x=" << x << ", y=" << y); CPPUNIT_ASSERT_EQUAL( ref_pos_4[y][x], p ); } } From 407d38d9edfcf857298edafce216646656b7d753 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 7 Nov 2017 14:23:07 +0100 Subject: [PATCH 10/19] Always use wxTE_MULTILINE explicitly in PositionToCoords() test While it is added implicitly when running all tests in the order, this style wasn't used if just this test was ran using "-c PositionToCoords" option. Specify wxTE_MULTILINE in it explicitly to allow this to work too. --- tests/controls/textctrltest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/controls/textctrltest.cpp b/tests/controls/textctrltest.cpp index 89ff430cd3..f824d92a82 100644 --- a/tests/controls/textctrltest.cpp +++ b/tests/controls/textctrltest.cpp @@ -603,7 +603,7 @@ void TextCtrlTestCase::PositionToCoordsRich2() void TextCtrlTestCase::DoPositionToCoordsTestWithStyle(long style) { delete m_text; - CreateText(style); + CreateText(style|wxTE_MULTILINE); // Asking for invalid index should fail. WX_ASSERT_FAILS_WITH_ASSERT( m_text->PositionToCoords(1) ); From 5fb740fed823337ba1757f301c6af738edbf1edd Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 7 Nov 2017 15:02:46 +0100 Subject: [PATCH 11/19] Add a layout hack to PositionToCoords() unit test for wxGTK The text control needs a few event loop iterations in order to layout itself correctly, so give it up to 1 second to do it in order to avoid spurious test failures that occurred if just a single call to wxYield() were done (or, worse, none at all as it was the case before). Also log the value returned by PositionToCoords() in case of test failures. --- tests/controls/textctrltest.cpp | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/tests/controls/textctrltest.cpp b/tests/controls/textctrltest.cpp index f824d92a82..f7877d3b0a 100644 --- a/tests/controls/textctrltest.cpp +++ b/tests/controls/textctrltest.cpp @@ -667,11 +667,31 @@ void TextCtrlTestCase::DoPositionToCoordsTestWithStyle(long style) // last position is in its bounds. m_text->SetInsertionPointEnd(); - CPPUNIT_ASSERT( m_text->PositionToCoords(0).y < 0 ); - CPPUNIT_ASSERT - ( - m_text->PositionToCoords(m_text->GetInsertionPoint()).y <= TEXT_HEIGHT - ); + const int pos = m_text->GetInsertionPoint(); + + // wxGTK needs to yield here to update the text control. +#ifdef __WXGTK__ + wxStopWatch sw; + while ( m_text->PositionToCoords(0).y == 0 || + m_text->PositionToCoords(pos).y > TEXT_HEIGHT ) + { + if ( sw.Time() > 1000 ) + { + FAIL("Timed out waiting for wxTextCtrl update."); + break; + } + + wxYield(); + } +#endif // __WXGTK__ + + wxPoint coords = m_text->PositionToCoords(0); + INFO("First position coords = " << coords); + CPPUNIT_ASSERT( coords.y < 0 ); + + coords = m_text->PositionToCoords(pos); + INFO("Position is " << pos << ", coords = " << coords); + CPPUNIT_ASSERT( coords.y <= TEXT_HEIGHT ); } void TextCtrlTestCase::PositionToXYMultiLine() From 66324470f1b90146c8c6d96b1b07bb6e90640b3f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 7 Nov 2017 15:40:29 +0100 Subject: [PATCH 12/19] Fix wxTextCtrl::GetStyle() with GTK+ 3 The text and background colours are now stored in the rgba array instead of fg_color and bg_color as with GTK+ 2 (the latter ones seem to have been repurposed for the underline and strike-through colours!). Also make the unit test for this method more robust. --- docs/changes.txt | 1 + src/gtk/textctrl.cpp | 5 +++++ tests/controls/textctrltest.cpp | 21 +++++++++++---------- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 0f5d8fd377..7b4b32ef2d 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -171,6 +171,7 @@ wxGTK: - Make wxUIActionSimulator work with GTK+ 3 (Scott Talbert). - Make wxBORDER_NONE work for wxTextCtrl with GTK+ 3 (Adrien Tétar). - Apply wxTextCtrl::SetDefaultStyle() to user-entered text (Andreas Falkenhahn). +- Fix wxTextCtrl::GetStyle() with GTK+ 3. - Support background colour in wxDataViewCtrl attributes. - Improve wxSpinCtrl best size calculation. - Implement support for icon locations in wxMimeTypesManager (Hanmac). diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index 2495c498df..4aa72d774f 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -1777,8 +1777,13 @@ bool wxTextCtrl::GetStyle(long position, wxTextAttr& style) } else // have custom attributes { +#ifdef __WXGTK3__ + style.SetBackgroundColour(*pattr->appearance.rgba[0]); + style.SetTextColour(*pattr->appearance.rgba[1]); +#else style.SetBackgroundColour(pattr->appearance.bg_color); style.SetTextColour(pattr->appearance.fg_color); +#endif const wxGtkString pangoFontString(pango_font_description_to_string(pattr->font)); diff --git a/tests/controls/textctrltest.cpp b/tests/controls/textctrltest.cpp index f7877d3b0a..3abcbfe868 100644 --- a/tests/controls/textctrltest.cpp +++ b/tests/controls/textctrltest.cpp @@ -397,7 +397,7 @@ void TextCtrlTestCase::Style() #ifndef __WXOSX__ delete m_text; // We need wxTE_RICH under windows for style support - CreateText(wxTE_RICH); + CreateText(wxTE_MULTILINE|wxTE_RICH); // Red text on a white background m_text->SetDefaultStyle(wxTextAttr(*wxRED, *wxWHITE)); @@ -431,20 +431,21 @@ void TextCtrlTestCase::Style() wxTextAttr style; // We have to check that styles are supported - if(m_text->GetStyle(3, style)) + if ( !m_text->GetStyle(3, style) ) { - CPPUNIT_ASSERT_EQUAL(style.GetTextColour(), *wxRED); - CPPUNIT_ASSERT_EQUAL(style.GetBackgroundColour(), *wxWHITE); + WARN("Retrieving text style not supported, skipping test."); + return; } + CHECK( style.GetTextColour() == *wxRED ); + CHECK( style.GetBackgroundColour() == *wxWHITE ); + // And then setting the style - if(m_text->SetStyle(15, 18, style)) - { - m_text->GetStyle(17, style); + REQUIRE( m_text->SetStyle(15, 18, style) ); - CPPUNIT_ASSERT_EQUAL(style.GetTextColour(), *wxRED); - CPPUNIT_ASSERT_EQUAL(style.GetBackgroundColour(), *wxWHITE); - } + REQUIRE( m_text->GetStyle(17, style) ); + CHECK( style.GetTextColour() == *wxRED ); + CHECK( style.GetBackgroundColour() == *wxWHITE ); #endif } From f0a32f0e1fbb478fb4963e6844f27d94b5754d1c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 7 Nov 2017 15:44:18 +0100 Subject: [PATCH 13/19] Wait for the focus event to occur in the unit test The test failed unless we dispatched events with wxGTK (both 2 and 3). --- tests/controls/windowtest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/controls/windowtest.cpp b/tests/controls/windowtest.cpp index 9d6457c905..ffc6fdf228 100644 --- a/tests/controls/windowtest.cpp +++ b/tests/controls/windowtest.cpp @@ -142,7 +142,7 @@ void WindowTestCase::FocusEvent() m_window->SetFocus(); - CPPUNIT_ASSERT_EQUAL(1, setfocus.GetCount()); + WX_ASSERT_EVENT_OCCURS(setfocus, 1); CPPUNIT_ASSERT(m_window->HasFocus()); wxButton* button = new wxButton(wxTheApp->GetTopWindow(), wxID_ANY); From 548d7a0518e09b234963ab6f37eb7ee8d491c501 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 7 Nov 2017 16:10:19 +0100 Subject: [PATCH 14/19] Disable keyboard event unit tests for wxGTK They suffer from the same problem as all the other tests using wxUIActionSimulator: it is flaky with GTK+ 2 and doesn't work at all with GTK+ 3. --- tests/events/keyboard.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/tests/events/keyboard.cpp b/tests/events/keyboard.cpp index cb54248c35..29f849aab3 100644 --- a/tests/events/keyboard.cpp +++ b/tests/events/keyboard.cpp @@ -16,9 +16,7 @@ #pragma hdrstop #endif -// FIXME: As all the other tests involving wxUIActionSimulator, this one is -// broken under OS X, the test window siply never gets any events. -#if wxUSE_UIACTIONSIMULATOR && !defined(__WXOSX__) +#if wxUSE_UIACTIONSIMULATOR #ifndef WX_PRECOMP #include "wx/app.h" @@ -204,12 +202,12 @@ public: private: CPPUNIT_TEST_SUITE( KeyboardEventTestCase ); - CPPUNIT_TEST( NormalLetter ); - CPPUNIT_TEST( NormalSpecial ); - CPPUNIT_TEST( CtrlLetter ); - CPPUNIT_TEST( CtrlSpecial ); - CPPUNIT_TEST( ShiftLetter ); - CPPUNIT_TEST( ShiftSpecial ); + WXUISIM_TEST( NormalLetter ); + WXUISIM_TEST( NormalSpecial ); + WXUISIM_TEST( CtrlLetter ); + WXUISIM_TEST( CtrlSpecial ); + WXUISIM_TEST( ShiftLetter ); + WXUISIM_TEST( ShiftSpecial ); CPPUNIT_TEST_SUITE_END(); void NormalLetter(); From c13e28ebfb20048cf02093e209dbed7852a3bacf Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 7 Nov 2017 16:16:08 +0100 Subject: [PATCH 15/19] Disable wxTopLevelWindow::IsActive() unit test for wxGTK It just doesn't work in the test, so live without it for now. Also use CHECK() instead of CPPUNIT_ASSERT(), which expands into REQUIRE(), for independent tests to let later tests to still be done even if an earlier one fails. --- tests/toplevel/toplevel.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/tests/toplevel/toplevel.cpp b/tests/toplevel/toplevel.cpp index 61c52207ed..53ea380960 100644 --- a/tests/toplevel/toplevel.cpp +++ b/tests/toplevel/toplevel.cpp @@ -73,7 +73,7 @@ void TopLevelWindowTestCase::FrameShowTest() void TopLevelWindowTestCase::TopLevelWindowShowTest(wxTopLevelWindow* tlw) { - CPPUNIT_ASSERT(!tlw->IsShown()); + CHECK(!tlw->IsShown()); wxTextCtrl* textCtrl = new wxTextCtrl(tlw, -1, "test"); textCtrl->SetFocus(); @@ -81,19 +81,26 @@ void TopLevelWindowTestCase::TopLevelWindowShowTest(wxTopLevelWindow* tlw) // only run this test on platforms where ShowWithoutActivating is implemented. #if defined(__WXMSW__) || defined(__WXMAC__) tlw->ShowWithoutActivating(); - CPPUNIT_ASSERT(tlw->IsShown()); - CPPUNIT_ASSERT(!tlw->IsActive()); + CHECK(tlw->IsShown()); + CHECK(!tlw->IsActive()); tlw->Hide(); - CPPUNIT_ASSERT(!tlw->IsShown()); - CPPUNIT_ASSERT(!tlw->IsActive()); + CHECK(!tlw->IsShown()); + CHECK(!tlw->IsActive()); #endif tlw->Show(true); - CPPUNIT_ASSERT(tlw->IsActive()); - CPPUNIT_ASSERT(tlw->IsShown()); + + // wxGTK needs many event loop iterations before the TLW becomes active and + // this doesn't happen in this test, so avoid checking for it. +#ifndef __WXGTK__ + CHECK(tlw->IsActive()); +#endif + CHECK(tlw->IsShown()); tlw->Hide(); - CPPUNIT_ASSERT(!tlw->IsShown()); - CPPUNIT_ASSERT(tlw->IsActive()); + CHECK(!tlw->IsShown()); +#ifndef __WXGTK__ + CHECK(tlw->IsActive()); +#endif } From 643071fc77255a61af68d3fefd65ca1d925644e4 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 7 Nov 2017 16:21:38 +0100 Subject: [PATCH 16/19] Add more new lines around GTK errors in the test suite Try to make things a bit more readable. --- tests/test.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test.cpp b/tests/test.cpp index ba853d53ea..5c01d4875a 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -416,10 +416,12 @@ wxTestGLogHandler(const gchar* domain, const gchar* message, gpointer data) { - fprintf(stderr, "** GTK log message while running %s(): ", + fprintf(stderr, "\n*** GTK log message while running %s(): ", wxGetCurrentTestName().c_str()); g_log_default_handler(domain, level, message, data); + + fprintf(stderr, "\n"); } #endif // __WXGTK__ From 3b76e590d4c01c4d874acb59753eaf6cce67d021 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 7 Nov 2017 16:26:12 +0100 Subject: [PATCH 17/19] Return descent from Cairo GetTextExtent() even for empty strings This method still needs to return the correct descent in this case. Fixes MeasuringTextTestCase::LeadingAndDescent() unit test failure with GTK+ 3. --- src/generic/graphicc.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/generic/graphicc.cpp b/src/generic/graphicc.cpp index 12e858d9c9..9b526da9f1 100644 --- a/src/generic/graphicc.cpp +++ b/src/generic/graphicc.cpp @@ -2644,7 +2644,10 @@ void wxCairoContext::GetTextExtent( const wxString &str, wxDouble *width, wxDoub if ( externalLeading ) *externalLeading = 0; - if ( str.empty()) + // We can skip computing the string width and height if it is empty, but + // not its descent and/or external leading, which still needs to be + // returned even for an empty string. + if ( str.empty() && !descent && !externalLeading ) return; if ( ((wxCairoFontData*)m_font.GetRefData())->Apply((wxCairoContext*)this) ) From 80a11ae17f303a82d895975738cf7bbdc0385380 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 7 Nov 2017 16:31:47 +0100 Subject: [PATCH 18/19] Use wxGtkObject instead of g_object_unref() calls in Cairo code Make the code safer and shorter. No real changes. --- src/generic/graphicc.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/generic/graphicc.cpp b/src/generic/graphicc.cpp index 9b526da9f1..c83910def7 100644 --- a/src/generic/graphicc.cpp +++ b/src/generic/graphicc.cpp @@ -88,6 +88,7 @@ using namespace std; #ifndef __WXGTK3__ #include "wx/gtk/dc.h" #endif +#include "wx/gtk/private/object.h" #endif #ifdef __WXQT__ @@ -2605,7 +2606,7 @@ void wxCairoContext::DoDrawText(const wxString& str, wxDouble x, wxDouble y) if ( ((wxCairoFontData*)m_font.GetRefData())->Apply(this) ) { #ifdef __WXGTK__ - PangoLayout *layout = pango_cairo_create_layout (m_context); + wxGtkObject layout(pango_cairo_create_layout (m_context)); const wxFont& font = static_cast(m_font.GetRefData())->GetFont(); pango_layout_set_font_description(layout, font.GetNativeFontInfo()->description); pango_layout_set_text(layout, data, data.length()); @@ -2614,8 +2615,6 @@ void wxCairoContext::DoDrawText(const wxString& str, wxDouble x, wxDouble y) cairo_move_to(m_context, x, y); pango_cairo_show_layout (m_context, layout); - g_object_unref (layout); - // Don't use Cairo text API, we already did everything. return; #endif @@ -2655,7 +2654,7 @@ void wxCairoContext::GetTextExtent( const wxString &str, wxDouble *width, wxDoub #ifdef __WXGTK__ int w, h; - PangoLayout *layout = pango_cairo_create_layout (m_context); + wxGtkObject layout(pango_cairo_create_layout (m_context)); const wxFont& font = static_cast(m_font.GetRefData())->GetFont(); pango_layout_set_font_description(layout, font.GetNativeFontInfo()->description); const wxCharBuffer data = str.utf8_str(); @@ -2676,7 +2675,6 @@ void wxCairoContext::GetTextExtent( const wxString &str, wxDouble *width, wxDoub pango_layout_iter_free(iter); *descent = h - PANGO_PIXELS(baseline); } - g_object_unref (layout); return; #endif } @@ -2723,7 +2721,7 @@ void wxCairoContext::GetPartialTextExtents(const wxString& text, wxArrayDouble& int w = 0; if (data.length()) { - PangoLayout* layout = pango_cairo_create_layout(m_context); + wxGtkObject layout(pango_cairo_create_layout(m_context)); const wxFont& font = static_cast(m_font.GetRefData())->GetFont(); pango_layout_set_font_description(layout, font.GetNativeFontInfo()->description); pango_layout_set_text(layout, data, data.length()); @@ -2735,7 +2733,6 @@ void wxCairoContext::GetPartialTextExtents(const wxString& text, wxArrayDouble& widths.Add(PANGO_PIXELS(w)); } while (pango_layout_iter_next_cluster(iter)); pango_layout_iter_free(iter); - g_object_unref(layout); } size_t i = widths.GetCount(); const size_t len = text.length(); From 7ba933c694252caaa84ed1585ac648cbf350ffa8 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 7 Nov 2017 16:37:25 +0100 Subject: [PATCH 19/19] Disable wxPaintEvent propagation tests for wxGTK3 They're currently broken and just always fail, it's useless to continue running them until the issue described in the comment in this commit is fixed. --- tests/events/propagation.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/events/propagation.cpp b/tests/events/propagation.cpp index 3f3d1eb8d3..bf2d40e7d0 100644 --- a/tests/events/propagation.cpp +++ b/tests/events/propagation.cpp @@ -37,7 +37,12 @@ // some tests there. But this should be fixed and the tests reenabled // because wxPaintEvent propagation in wxScrolledWindow is a perfect // example of fragile code that could be broken under OS X. -#ifndef __WXOSX__ +// +// FIXME: Under GTK+ 3 the test is broken because a simple wxYield() is not +// enough to map the frame. It should be also fixed there by waiting for +// it to come up, with some timeout, but for now it always fails, so +// it's useless to run it. +#if !defined(__WXOSX__) && !defined(__WXGTK3__) #define CAN_TEST_PAINT_EVENTS #endif