Fix bug when setting an out of range date in wxMSW wxDatePickerCtrl.
The internally stored date value was getting out of sync with the real date in the control itself when SetValue() was called with a date out of the currently set range. This resulted in an assert failure and other unpleasantness later. Fix the bug and add a unit test checking for it (and also with some other basic wxDatePickerCtrl checks). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67990 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
a5f226861c
commit
5f899cbe91
@ -193,7 +193,19 @@ void wxDatePickerCtrl::SetValue(const wxDateTime& dt)
|
||||
dt.IsValid() ? GDT_VALID : GDT_NONE,
|
||||
&st) )
|
||||
{
|
||||
wxLogDebug(wxT("DateTime_SetSystemtime() failed"));
|
||||
// Attempts to set the date outside of the valid range should fail so
|
||||
// there is nothing unexpected if they do but still log a message if we
|
||||
// failed for some other reason.
|
||||
wxDateTime dtStart, dtEnd;
|
||||
GetRange(&dtStart, &dtEnd);
|
||||
if ( (!dtStart.IsValid() || dt >= dtStart) &&
|
||||
(!dtEnd.IsValid() || dt <= dtEnd) )
|
||||
{
|
||||
wxLogDebug(wxT("DateTime_SetSystemtime() unexpectedly failed"));
|
||||
}
|
||||
|
||||
// In any case, skip updating m_date below.
|
||||
return;
|
||||
}
|
||||
|
||||
// we need to keep only the date part, times don't make sense for this
|
||||
|
@ -166,6 +166,7 @@ TEST_GUI_OBJECTS = \
|
||||
test_gui_choicebooktest.o \
|
||||
test_gui_choicetest.o \
|
||||
test_gui_comboboxtest.o \
|
||||
test_gui_datepickerctrltest.o \
|
||||
test_gui_frametest.o \
|
||||
test_gui_gaugetest.o \
|
||||
test_gui_gridtest.o \
|
||||
@ -731,6 +732,9 @@ test_gui_choicetest.o: $(srcdir)/controls/choicetest.cpp $(TEST_GUI_ODEP)
|
||||
test_gui_comboboxtest.o: $(srcdir)/controls/comboboxtest.cpp $(TEST_GUI_ODEP)
|
||||
$(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/controls/comboboxtest.cpp
|
||||
|
||||
test_gui_datepickerctrltest.o: $(srcdir)/controls/datepickerctrltest.cpp $(TEST_GUI_ODEP)
|
||||
$(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/controls/datepickerctrltest.cpp
|
||||
|
||||
test_gui_frametest.o: $(srcdir)/controls/frametest.cpp $(TEST_GUI_ODEP)
|
||||
$(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/controls/frametest.cpp
|
||||
|
||||
|
112
tests/controls/datepickerctrltest.cpp
Normal file
112
tests/controls/datepickerctrltest.cpp
Normal file
@ -0,0 +1,112 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: tests/controls/datepickerctrltest.cpp
|
||||
// Purpose: wxDatePickerCtrl unit test
|
||||
// Author: Vadim Zeitlin
|
||||
// Created: 2011-06-18
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "testprec.h"
|
||||
|
||||
#if wxUSE_DATEPICKCTRL
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/app.h"
|
||||
#endif // WX_PRECOMP
|
||||
|
||||
#include "wx/datectrl.h"
|
||||
|
||||
#include "testableframe.h"
|
||||
#include "testdate.h"
|
||||
|
||||
class DatePickerCtrlTestCase : public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
DatePickerCtrlTestCase() { }
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
private:
|
||||
CPPUNIT_TEST_SUITE( DatePickerCtrlTestCase );
|
||||
CPPUNIT_TEST( Value );
|
||||
CPPUNIT_TEST( Range );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
void Value();
|
||||
void Range();
|
||||
|
||||
wxDatePickerCtrl* m_datepicker;
|
||||
|
||||
DECLARE_NO_COPY_CLASS(DatePickerCtrlTestCase)
|
||||
};
|
||||
|
||||
// register in the unnamed registry so that these tests are run by default
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION( DatePickerCtrlTestCase );
|
||||
|
||||
// also include in its own registry so that these tests can be run alone
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( DatePickerCtrlTestCase, "DatePickerCtrlTestCase" );
|
||||
|
||||
void DatePickerCtrlTestCase::setUp()
|
||||
{
|
||||
m_datepicker = new wxDatePickerCtrl(wxTheApp->GetTopWindow(), wxID_ANY);
|
||||
}
|
||||
|
||||
void DatePickerCtrlTestCase::tearDown()
|
||||
{
|
||||
delete m_datepicker;
|
||||
}
|
||||
|
||||
void DatePickerCtrlTestCase::Value()
|
||||
{
|
||||
const wxDateTime dt(18, wxDateTime::Jul, 2011);
|
||||
m_datepicker->SetValue(dt);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( dt, m_datepicker->GetValue() );
|
||||
|
||||
// We don't use wxDP_ALLOWNONE currently, hence a value is required.
|
||||
WX_ASSERT_FAILS_WITH_ASSERT( m_datepicker->SetValue(wxDateTime()) );
|
||||
}
|
||||
|
||||
void DatePickerCtrlTestCase::Range()
|
||||
{
|
||||
// Initially we have no valid range but MSW version still has (built in)
|
||||
// minimum as it doesn't support dates before 1601-01-01, hence don't rely
|
||||
// on GetRange() returning false.
|
||||
wxDateTime dtRangeStart, dtRangeEnd;
|
||||
m_datepicker->GetRange(&dtRangeStart, &dtRangeEnd);
|
||||
CPPUNIT_ASSERT( !dtRangeEnd.IsValid() );
|
||||
|
||||
// After we set it we should be able to get it back.
|
||||
const wxDateTime
|
||||
dtStart(15, wxDateTime::Feb, 1923),
|
||||
dtEnd(18, wxDateTime::Jun, 2011);
|
||||
|
||||
m_datepicker->SetRange(dtStart, dtEnd);
|
||||
CPPUNIT_ASSERT( m_datepicker->GetRange(&dtRangeStart, &dtRangeEnd) );
|
||||
CPPUNIT_ASSERT_EQUAL( dtStart, dtRangeStart );
|
||||
CPPUNIT_ASSERT_EQUAL( dtEnd, dtRangeEnd );
|
||||
|
||||
// Setting dates inside the range should work, including the range end
|
||||
// points.
|
||||
m_datepicker->SetValue(dtStart);
|
||||
CPPUNIT_ASSERT_EQUAL( dtStart, m_datepicker->GetValue() );
|
||||
|
||||
m_datepicker->SetValue(dtEnd);
|
||||
CPPUNIT_ASSERT_EQUAL( dtEnd, m_datepicker->GetValue() );
|
||||
|
||||
|
||||
// Setting dates outside the range should not work.
|
||||
m_datepicker->SetValue(dtEnd + wxTimeSpan::Day());
|
||||
CPPUNIT_ASSERT_EQUAL( dtEnd, m_datepicker->GetValue() );
|
||||
|
||||
m_datepicker->SetValue(dtStart - wxTimeSpan::Day());
|
||||
CPPUNIT_ASSERT_EQUAL( dtEnd, m_datepicker->GetValue() );
|
||||
}
|
||||
|
||||
#endif // wxUSE_DATEPICKCTRL
|
@ -151,6 +151,7 @@ TEST_GUI_OBJECTS = \
|
||||
$(OBJS)\test_gui_choicebooktest.obj \
|
||||
$(OBJS)\test_gui_choicetest.obj \
|
||||
$(OBJS)\test_gui_comboboxtest.obj \
|
||||
$(OBJS)\test_gui_datepickerctrltest.obj \
|
||||
$(OBJS)\test_gui_frametest.obj \
|
||||
$(OBJS)\test_gui_gaugetest.obj \
|
||||
$(OBJS)\test_gui_gridtest.obj \
|
||||
@ -779,6 +780,9 @@ $(OBJS)\test_gui_choicetest.obj: .\controls\choicetest.cpp
|
||||
$(OBJS)\test_gui_comboboxtest.obj: .\controls\comboboxtest.cpp
|
||||
$(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\controls\comboboxtest.cpp
|
||||
|
||||
$(OBJS)\test_gui_datepickerctrltest.obj: .\controls\datepickerctrltest.cpp
|
||||
$(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\controls\datepickerctrltest.cpp
|
||||
|
||||
$(OBJS)\test_gui_frametest.obj: .\controls\frametest.cpp
|
||||
$(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\controls\frametest.cpp
|
||||
|
||||
|
@ -144,6 +144,7 @@ TEST_GUI_OBJECTS = \
|
||||
$(OBJS)\test_gui_choicebooktest.o \
|
||||
$(OBJS)\test_gui_choicetest.o \
|
||||
$(OBJS)\test_gui_comboboxtest.o \
|
||||
$(OBJS)\test_gui_datepickerctrltest.o \
|
||||
$(OBJS)\test_gui_frametest.o \
|
||||
$(OBJS)\test_gui_gaugetest.o \
|
||||
$(OBJS)\test_gui_gridtest.o \
|
||||
@ -760,6 +761,9 @@ $(OBJS)\test_gui_choicetest.o: ./controls/choicetest.cpp
|
||||
$(OBJS)\test_gui_comboboxtest.o: ./controls/comboboxtest.cpp
|
||||
$(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
||||
$(OBJS)\test_gui_datepickerctrltest.o: ./controls/datepickerctrltest.cpp
|
||||
$(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
||||
$(OBJS)\test_gui_frametest.o: ./controls/frametest.cpp
|
||||
$(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
||||
|
@ -146,6 +146,7 @@ TEST_GUI_OBJECTS = \
|
||||
$(OBJS)\test_gui_choicebooktest.obj \
|
||||
$(OBJS)\test_gui_choicetest.obj \
|
||||
$(OBJS)\test_gui_comboboxtest.obj \
|
||||
$(OBJS)\test_gui_datepickerctrltest.obj \
|
||||
$(OBJS)\test_gui_frametest.obj \
|
||||
$(OBJS)\test_gui_gaugetest.obj \
|
||||
$(OBJS)\test_gui_gridtest.obj \
|
||||
@ -905,6 +906,9 @@ $(OBJS)\test_gui_choicetest.obj: .\controls\choicetest.cpp
|
||||
$(OBJS)\test_gui_comboboxtest.obj: .\controls\comboboxtest.cpp
|
||||
$(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\controls\comboboxtest.cpp
|
||||
|
||||
$(OBJS)\test_gui_datepickerctrltest.obj: .\controls\datepickerctrltest.cpp
|
||||
$(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\controls\datepickerctrltest.cpp
|
||||
|
||||
$(OBJS)\test_gui_frametest.obj: .\controls\frametest.cpp
|
||||
$(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\controls\frametest.cpp
|
||||
|
||||
|
@ -390,6 +390,7 @@ TEST_GUI_OBJECTS = &
|
||||
$(OBJS)\test_gui_choicebooktest.obj &
|
||||
$(OBJS)\test_gui_choicetest.obj &
|
||||
$(OBJS)\test_gui_comboboxtest.obj &
|
||||
$(OBJS)\test_gui_datepickerctrltest.obj &
|
||||
$(OBJS)\test_gui_frametest.obj &
|
||||
$(OBJS)\test_gui_gaugetest.obj &
|
||||
$(OBJS)\test_gui_gridtest.obj &
|
||||
@ -819,6 +820,9 @@ $(OBJS)\test_gui_choicetest.obj : .AUTODEPEND .\controls\choicetest.cpp
|
||||
$(OBJS)\test_gui_comboboxtest.obj : .AUTODEPEND .\controls\comboboxtest.cpp
|
||||
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $<
|
||||
|
||||
$(OBJS)\test_gui_datepickerctrltest.obj : .AUTODEPEND .\controls\datepickerctrltest.cpp
|
||||
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $<
|
||||
|
||||
$(OBJS)\test_gui_frametest.obj : .AUTODEPEND .\controls\frametest.cpp
|
||||
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $<
|
||||
|
||||
|
@ -147,6 +147,7 @@
|
||||
controls/choicebooktest.cpp
|
||||
controls/choicetest.cpp
|
||||
controls/comboboxtest.cpp
|
||||
controls/datepickerctrltest.cpp
|
||||
controls/frametest.cpp
|
||||
controls/gaugetest.cpp
|
||||
controls/gridtest.cpp
|
||||
|
@ -307,6 +307,10 @@ SOURCE=.\config\config.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\controls\datepickerctrltest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\dummy.cpp
|
||||
# ADD BASE CPP /Yc"testprec.h"
|
||||
# ADD CPP /Yc"testprec.h"
|
||||
|
@ -620,6 +620,9 @@
|
||||
RelativePath=".\config\config.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\controls\datepickerctrltest.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\dummy.cpp">
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32">
|
||||
|
@ -900,6 +900,10 @@
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\controls\datepickerctrltest.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\dummy.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
|
@ -872,6 +872,10 @@
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\controls\datepickerctrltest.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\dummy.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
|
Loading…
Reference in New Issue
Block a user