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
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 \
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
--- /dev/null
+///////////////////////////////////////////////////////////////////////////////
+// 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
$(OBJS)\test_gui_choicebooktest.obj \\r
$(OBJS)\test_gui_choicetest.obj \\r
$(OBJS)\test_gui_comboboxtest.obj \\r
+ $(OBJS)\test_gui_datepickerctrltest.obj \
$(OBJS)\test_gui_frametest.obj \\r
$(OBJS)\test_gui_gaugetest.obj \\r
$(OBJS)\test_gui_gridtest.obj \\r
$(OBJS)\test_gui_comboboxtest.obj: .\controls\comboboxtest.cpp\r
$(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\controls\comboboxtest.cpp\r
\r
+$(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\r
$(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\controls\frametest.cpp\r
\r
$(OBJS)\test_gui_choicebooktest.o \\r
$(OBJS)\test_gui_choicetest.o \\r
$(OBJS)\test_gui_comboboxtest.o \\r
+ $(OBJS)\test_gui_datepickerctrltest.o \
$(OBJS)\test_gui_frametest.o \\r
$(OBJS)\test_gui_gaugetest.o \\r
$(OBJS)\test_gui_gridtest.o \\r
$(OBJS)\test_gui_comboboxtest.o: ./controls/comboboxtest.cpp\r
$(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<\r
\r
+$(OBJS)\test_gui_datepickerctrltest.o: ./controls/datepickerctrltest.cpp
+ $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<
+
$(OBJS)\test_gui_frametest.o: ./controls/frametest.cpp\r
$(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<\r
\r
$(OBJS)\test_gui_choicebooktest.obj \\r
$(OBJS)\test_gui_choicetest.obj \\r
$(OBJS)\test_gui_comboboxtest.obj \\r
+ $(OBJS)\test_gui_datepickerctrltest.obj \
$(OBJS)\test_gui_frametest.obj \\r
$(OBJS)\test_gui_gaugetest.obj \\r
$(OBJS)\test_gui_gridtest.obj \\r
$(OBJS)\test_gui_comboboxtest.obj: .\controls\comboboxtest.cpp\r
$(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\controls\comboboxtest.cpp\r
\r
+$(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\r
$(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\controls\frametest.cpp\r
\r
$(OBJS)\test_gui_choicebooktest.obj &\r
$(OBJS)\test_gui_choicetest.obj &\r
$(OBJS)\test_gui_comboboxtest.obj &\r
+ $(OBJS)\test_gui_datepickerctrltest.obj &
$(OBJS)\test_gui_frametest.obj &\r
$(OBJS)\test_gui_gaugetest.obj &\r
$(OBJS)\test_gui_gridtest.obj &\r
$(OBJS)\test_gui_comboboxtest.obj : .AUTODEPEND .\controls\comboboxtest.cpp\r
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $<\r
\r
+$(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\r
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $<\r
\r
controls/choicebooktest.cpp
controls/choicetest.cpp
controls/comboboxtest.cpp
+ controls/datepickerctrltest.cpp
controls/frametest.cpp
controls/gaugetest.cpp
controls/gridtest.cpp
# End Source File\r
# Begin Source File\r
\r
+SOURCE=.\controls\datepickerctrltest.cpp
+# End Source File
+# Begin Source File
+
SOURCE=.\dummy.cpp\r
# ADD BASE CPP /Yc"testprec.h"\r
# ADD CPP /Yc"testprec.h"\r
RelativePath=".\config\config.cpp">\r
</File>\r
<File\r
+ RelativePath=".\controls\datepickerctrltest.cpp">
+ </File>
+ <File
RelativePath=".\dummy.cpp">\r
<FileConfiguration\r
Name="Debug|Win32">\r
>\r
</File>\r
<File\r
+ RelativePath=".\controls\datepickerctrltest.cpp"
+ >
+ </File>
+ <File
RelativePath=".\dummy.cpp"\r
>\r
<FileConfiguration\r
>\r
</File>\r
<File\r
+ RelativePath=".\controls\datepickerctrltest.cpp"
+ >
+ </File>
+ <File
RelativePath=".\dummy.cpp"\r
>\r
<FileConfiguration\r