From 5885b2f142b2e8be75b42ee1f1d8722930a0cd85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C4=83t=C4=83lin=20R=C4=83ceanu?= Date: Wed, 26 Dec 2018 22:12:01 +0200 Subject: [PATCH] Test that selecting 'single' radio button does not reset others Add a unit test for the expected behaviour. Closes https://github.com/wxWidgets/wxWidgets/pull/1102 --- tests/controls/radiobuttontest.cpp | 34 ++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/controls/radiobuttontest.cpp b/tests/controls/radiobuttontest.cpp index 0d687a7918..649775b294 100644 --- a/tests/controls/radiobuttontest.cpp +++ b/tests/controls/radiobuttontest.cpp @@ -35,11 +35,13 @@ private: WXUISIM_TEST( Click ); CPPUNIT_TEST( Value ); CPPUNIT_TEST( Group ); + CPPUNIT_TEST( Single ); CPPUNIT_TEST_SUITE_END(); void Click(); void Value(); void Group(); + void Single(); wxRadioButton* m_radio; @@ -150,4 +152,36 @@ void RadioButtonTestCase::Group() wxDELETE(g2radio1); } +void RadioButtonTestCase::Single() +{ + //Create a group of 2 buttons, having second button selected + wxScopedPtr gradio0(new wxRadioButton(wxTheApp->GetTopWindow(), + wxID_ANY, "wxRadioButton", + wxDefaultPosition, + wxDefaultSize, wxRB_GROUP)); + + wxScopedPtr gradio1(new wxRadioButton(wxTheApp->GetTopWindow(), + wxID_ANY, "wxRadioButton")); + + gradio1->SetValue(true); + + //Create a "single" button (by default it will not be selected) + wxScopedPtr sradio(new wxRadioButton(wxTheApp->GetTopWindow(), + wxID_ANY, "wxRadioButton", + wxDefaultPosition, + wxDefaultSize, wxRB_SINGLE)); + + //Create a non-grouped button and select it + wxScopedPtr ngradio(new wxRadioButton(wxTheApp->GetTopWindow(), + wxID_ANY, "wxRadioButton")); + + ngradio->SetValue(true); + + //Select the "single" button + sradio->SetValue(true); + + CHECK(gradio1->GetValue()); + CHECK(ngradio->GetValue()); +} + #endif //wxUSE_RADIOBTN