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:
@@ -233,9 +233,10 @@ void ComboBoxTestCase::IsEmpty()
|
||||
|
||||
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" };
|
||||
|
||||
@@ -246,7 +247,7 @@ TEST_CASE("wxComboBox::ProcessEnter", "[wxComboBox][enter]")
|
||||
}
|
||||
};
|
||||
|
||||
TestProcessEnter(&ComboBoxCreator::Do);
|
||||
TestProcessEnter(ComboBoxCreator());
|
||||
}
|
||||
|
||||
#endif //wxUSE_COMBOBOX
|
||||
|
@@ -1271,9 +1271,14 @@ void TextCtrlTestCase::XYToPositionSingleLine()
|
||||
|
||||
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(),
|
||||
wxDefaultPosition, wxDefaultSize,
|
||||
@@ -1281,7 +1286,7 @@ TEST_CASE("wxTextCtrl::ProcessEnter", "[wxTextCtrl][enter]")
|
||||
}
|
||||
};
|
||||
|
||||
TestProcessEnter(&TextCtrlCreator::Do);
|
||||
TestProcessEnter(TextCtrlCreator());
|
||||
}
|
||||
|
||||
#endif //wxUSE_TEXTCTRL
|
||||
|
@@ -384,13 +384,17 @@ enum ProcessEnter
|
||||
class TestDialog : public wxDialog
|
||||
{
|
||||
public:
|
||||
explicit TestDialog(TextLikeControlCreator controlCreator,
|
||||
explicit TestDialog(const TextLikeControlCreator& controlCreator,
|
||||
ProcessEnter processEnter)
|
||||
: wxDialog(wxTheApp->GetTopWindow(), wxID_ANY, "Test dialog"),
|
||||
m_control((*controlCreator)(this,
|
||||
processEnter == ProcessEnter_No
|
||||
? 0
|
||||
: wxTE_PROCESS_ENTER)),
|
||||
m_control
|
||||
(
|
||||
controlCreator.Create
|
||||
(
|
||||
this,
|
||||
processEnter == ProcessEnter_No ? 0 : wxTE_PROCESS_ENTER
|
||||
)
|
||||
),
|
||||
m_processEnter(processEnter),
|
||||
m_gotEnter(false)
|
||||
{
|
||||
@@ -455,7 +459,7 @@ private:
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
void TestProcessEnter(TextLikeControlCreator controlCreator)
|
||||
void TestProcessEnter(const TextLikeControlCreator& controlCreator)
|
||||
{
|
||||
if ( !EnableUITests() )
|
||||
{
|
||||
@@ -487,7 +491,7 @@ void TestProcessEnter(TextLikeControlCreator controlCreator)
|
||||
|
||||
#else // !wxUSE_UIACTIONSIMULATOR
|
||||
|
||||
void TestProcessEnter(TextLikeControlCreator WXUNUSED(controlCreator))
|
||||
void TestProcessEnter(const TextLikeControlCreator& WXUNUSED(controlCreator))
|
||||
{
|
||||
WARN("Skipping wxTE_PROCESS_ENTER tests: wxUIActionSimulator not available");
|
||||
}
|
||||
|
@@ -75,11 +75,27 @@ private:
|
||||
wxDECLARE_NO_COPY_CLASS(TextEntryTestCase);
|
||||
};
|
||||
|
||||
// Function to call to test that wxTE_PROCESS_ENTER is handled correctly for
|
||||
// the controls of the type created by the given creator function when they're
|
||||
// placed in a dialog with a default button.
|
||||
typedef wxControl* (*TextLikeControlCreator)(wxWindow* parent, int style);
|
||||
// Helper used for creating the control of the specific type (currently either
|
||||
// wxTextCtrl or wxComboBox) with the given flag.
|
||||
class TextLikeControlCreator
|
||||
{
|
||||
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_
|
||||
|
Reference in New Issue
Block a user