Return correct string from wxEVT_TEXT wxComboBox events.
wxCommandEvent::GetString() could return empty string for the programmatically-generated wxEVT_TEXT events from a wxComboBox. Fix this by extending the on-demand string retrieval in wxCommandEvent to wxComboBox as well (it was done only for wxTextCtrl). Also add a unit test checking that the string has the expected value in the events sent by all wxTextEntry-derived controls. Closes #3901. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@77057 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -177,9 +177,32 @@ void TextEntryTestCase::Replace()
|
||||
CPPUNIT_ASSERT_EQUAL(2, entry->GetInsertionPoint());
|
||||
}
|
||||
|
||||
#if wxUSE_UIACTIONSIMULATOR
|
||||
|
||||
class TextEventHandler
|
||||
{
|
||||
public:
|
||||
explicit TextEventHandler(wxWindow* win)
|
||||
{
|
||||
win->Bind(wxEVT_TEXT, &TextEventHandler::OnText, this);
|
||||
}
|
||||
|
||||
const wxString& GetLastString() const
|
||||
{
|
||||
return m_string;
|
||||
}
|
||||
|
||||
private:
|
||||
void OnText(wxCommandEvent& event)
|
||||
{
|
||||
m_string = event.GetString();
|
||||
}
|
||||
|
||||
wxString m_string;
|
||||
};
|
||||
|
||||
void TextEntryTestCase::Editable()
|
||||
{
|
||||
#if wxUSE_UIACTIONSIMULATOR
|
||||
|
||||
#ifdef __WXGTK__
|
||||
// FIXME: For some reason this test regularly (although not always) fails
|
||||
@@ -203,6 +226,7 @@ void TextEntryTestCase::Editable()
|
||||
window->SetFocus();
|
||||
wxYield();
|
||||
|
||||
// Check that we get the expected number of events.
|
||||
wxUIActionSimulator sim;
|
||||
sim.Text("abcdef");
|
||||
wxYield();
|
||||
@@ -210,6 +234,26 @@ void TextEntryTestCase::Editable()
|
||||
CPPUNIT_ASSERT_EQUAL("abcdef", entry->GetValue());
|
||||
CPPUNIT_ASSERT_EQUAL(6, updated.GetCount());
|
||||
|
||||
|
||||
// And that the event carries the right value.
|
||||
TextEventHandler handler(window);
|
||||
|
||||
sim.Text("g");
|
||||
wxYield();
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL("abcdefg", handler.GetLastString());
|
||||
|
||||
// ... even if we generate the event programmatically and whether it uses
|
||||
// the same value as the control has right now
|
||||
entry->SetValue("abcdefg");
|
||||
CPPUNIT_ASSERT_EQUAL("abcdefg", handler.GetLastString());
|
||||
|
||||
// ... or not
|
||||
entry->SetValue("abcdef");
|
||||
CPPUNIT_ASSERT_EQUAL("abcdef", handler.GetLastString());
|
||||
|
||||
// Check that making the control not editable does indeed prevent it from
|
||||
// being edited.
|
||||
updated.Clear();
|
||||
|
||||
entry->SetEditable(false);
|
||||
@@ -218,9 +262,10 @@ void TextEntryTestCase::Editable()
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL("abcdef", entry->GetValue());
|
||||
CPPUNIT_ASSERT_EQUAL(0, updated.GetCount());
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // wxUSE_UIACTIONSIMULATOR
|
||||
|
||||
void TextEntryTestCase::Hint()
|
||||
{
|
||||
GetTestEntry()->SetHint("This is a hint");
|
||||
|
Reference in New Issue
Block a user