Replace a single function with a class in Enter processing tests

No real changes yet, this is a pure refactoring before the upcoming
changes.
This commit is contained in:
Vadim Zeitlin
2019-09-08 18:47:13 +02:00
parent ba2ea837de
commit e85b5e5261
4 changed files with 44 additions and 18 deletions

View File

@@ -233,9 +233,10 @@ void ComboBoxTestCase::IsEmpty()
TEST_CASE("wxComboBox::ProcessEnter", "[wxComboBox][enter]") TEST_CASE("wxComboBox::ProcessEnter", "[wxComboBox][enter]")
{ {
struct ComboBoxCreator class ComboBoxCreator : public TextLikeControlCreator
{ {
static wxControl* Do(wxWindow* parent, int style) public:
virtual wxControl* Create(wxWindow* parent, int style) const wxOVERRIDE
{ {
const wxString choices[] = { "foo", "bar", "baz" }; const wxString choices[] = { "foo", "bar", "baz" };
@@ -246,7 +247,7 @@ TEST_CASE("wxComboBox::ProcessEnter", "[wxComboBox][enter]")
} }
}; };
TestProcessEnter(&ComboBoxCreator::Do); TestProcessEnter(ComboBoxCreator());
} }
#endif //wxUSE_COMBOBOX #endif //wxUSE_COMBOBOX

View File

@@ -1271,9 +1271,14 @@ void TextCtrlTestCase::XYToPositionSingleLine()
TEST_CASE("wxTextCtrl::ProcessEnter", "[wxTextCtrl][enter]") TEST_CASE("wxTextCtrl::ProcessEnter", "[wxTextCtrl][enter]")
{ {
struct TextCtrlCreator class TextCtrlCreator : public TextLikeControlCreator
{ {
static wxControl* Do(wxWindow* parent, int style) public:
explicit TextCtrlCreator()
{
}
virtual wxControl* Create(wxWindow* parent, int style) const wxOVERRIDE
{ {
return new wxTextCtrl(parent, wxID_ANY, wxString(), return new wxTextCtrl(parent, wxID_ANY, wxString(),
wxDefaultPosition, wxDefaultSize, wxDefaultPosition, wxDefaultSize,
@@ -1281,7 +1286,7 @@ TEST_CASE("wxTextCtrl::ProcessEnter", "[wxTextCtrl][enter]")
} }
}; };
TestProcessEnter(&TextCtrlCreator::Do); TestProcessEnter(TextCtrlCreator());
} }
#endif //wxUSE_TEXTCTRL #endif //wxUSE_TEXTCTRL

View File

@@ -384,13 +384,17 @@ enum ProcessEnter
class TestDialog : public wxDialog class TestDialog : public wxDialog
{ {
public: public:
explicit TestDialog(TextLikeControlCreator controlCreator, explicit TestDialog(const TextLikeControlCreator& controlCreator,
ProcessEnter processEnter) ProcessEnter processEnter)
: wxDialog(wxTheApp->GetTopWindow(), wxID_ANY, "Test dialog"), : wxDialog(wxTheApp->GetTopWindow(), wxID_ANY, "Test dialog"),
m_control((*controlCreator)(this, m_control
processEnter == ProcessEnter_No (
? 0 controlCreator.Create
: wxTE_PROCESS_ENTER)), (
this,
processEnter == ProcessEnter_No ? 0 : wxTE_PROCESS_ENTER
)
),
m_processEnter(processEnter), m_processEnter(processEnter),
m_gotEnter(false) m_gotEnter(false)
{ {
@@ -455,7 +459,7 @@ private:
} // anonymous namespace } // anonymous namespace
void TestProcessEnter(TextLikeControlCreator controlCreator) void TestProcessEnter(const TextLikeControlCreator& controlCreator)
{ {
if ( !EnableUITests() ) if ( !EnableUITests() )
{ {
@@ -487,7 +491,7 @@ void TestProcessEnter(TextLikeControlCreator controlCreator)
#else // !wxUSE_UIACTIONSIMULATOR #else // !wxUSE_UIACTIONSIMULATOR
void TestProcessEnter(TextLikeControlCreator WXUNUSED(controlCreator)) void TestProcessEnter(const TextLikeControlCreator& WXUNUSED(controlCreator))
{ {
WARN("Skipping wxTE_PROCESS_ENTER tests: wxUIActionSimulator not available"); WARN("Skipping wxTE_PROCESS_ENTER tests: wxUIActionSimulator not available");
} }

View File

@@ -75,11 +75,27 @@ private:
wxDECLARE_NO_COPY_CLASS(TextEntryTestCase); wxDECLARE_NO_COPY_CLASS(TextEntryTestCase);
}; };
// Function to call to test that wxTE_PROCESS_ENTER is handled correctly for // Helper used for creating the control of the specific type (currently either
// the controls of the type created by the given creator function when they're // wxTextCtrl or wxComboBox) with the given flag.
// placed in a dialog with a default button. class TextLikeControlCreator
typedef wxControl* (*TextLikeControlCreator)(wxWindow* parent, int style); {
public:
TextLikeControlCreator() {}
void TestProcessEnter(TextLikeControlCreator controlCreator); // Create the control of the right type using the given parent and style.
virtual wxControl* Create(wxWindow* parent, int style) const = 0;
// Give it a virtual dtor to avoid warnings even though this class is not
// supposed to be used polymorphically.
virtual ~TextLikeControlCreator() {}
private:
wxDECLARE_NO_COPY_CLASS(TextLikeControlCreator);
};
// Use the given control creator to check that various combinations of
// specifying and not specifying wxTE_PROCESS_ENTER and handling or not
// handling the resulting event work as expected.
void TestProcessEnter(const TextLikeControlCreator& controlCreator);
#endif // _WX_TESTS_CONTROLS_TEXTENTRYTEST_H_ #endif // _WX_TESTS_CONTROLS_TEXTENTRYTEST_H_