From 78d09e2e90fb5bea9f67bf63e78bc91774e0a4c3 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 17 Jul 2015 15:23:13 +0200 Subject: [PATCH] Document and test wxDatePickerCtrl::SetRange() date-clamping behaviour. Document that the current value of the control is adjusted if it doesn't lie in the newly set range and add a unit test to check for this, now that it actually passes under all platforms, after the previous commits. --- interface/wx/datectrl.h | 4 ++++ tests/controls/datepickerctrltest.cpp | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/interface/wx/datectrl.h b/interface/wx/datectrl.h index c817154997..3d516acee6 100644 --- a/interface/wx/datectrl.h +++ b/interface/wx/datectrl.h @@ -173,6 +173,10 @@ public: becomes the earliest date (inclusive) accepted by the control. If @a dt2 is valid, it becomes the latest possible date. + Notice that if the current value is not inside the new range, it will + be adjusted to lie inside it, i.e. calling this method can change the + control value, however no events are generated by it. + @remarks If the current value of the control is outside of the newly set range bounds, the behaviour is undefined. */ diff --git a/tests/controls/datepickerctrltest.cpp b/tests/controls/datepickerctrltest.cpp index 5d80e6c339..abef3925f8 100644 --- a/tests/controls/datepickerctrltest.cpp +++ b/tests/controls/datepickerctrltest.cpp @@ -106,6 +106,13 @@ void DatePickerCtrlTestCase::Range() m_datepicker->SetValue(dtStart - wxTimeSpan::Day()); CPPUNIT_ASSERT_EQUAL( dtEnd, m_datepicker->GetValue() ); + + + // Changing the range should clamp the current value to it if necessary. + const wxDateTime + dtBeforeEnd = dtEnd - wxDateSpan::Day(); + m_datepicker->SetRange(dtStart, dtBeforeEnd); + CPPUNIT_ASSERT_EQUAL( dtBeforeEnd, m_datepicker->GetValue() ); } #endif // wxUSE_DATEPICKCTRL