]>
git.saurik.com Git - wxWidgets.git/blob - tests/controls/datepickerctrltest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/datepickerctrltest.cpp
3 // Purpose: wxDatePickerCtrl unit test
4 // Author: Vadim Zeitlin
6 // Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
7 ///////////////////////////////////////////////////////////////////////////////
11 #if wxUSE_DATEPICKCTRL
21 #include "wx/datectrl.h"
23 #include "testableframe.h"
26 class DatePickerCtrlTestCase
: public CppUnit::TestCase
29 DatePickerCtrlTestCase() { }
35 CPPUNIT_TEST_SUITE( DatePickerCtrlTestCase
);
36 CPPUNIT_TEST( Value
);
37 CPPUNIT_TEST( Range
);
38 CPPUNIT_TEST_SUITE_END();
43 wxDatePickerCtrl
* m_datepicker
;
45 DECLARE_NO_COPY_CLASS(DatePickerCtrlTestCase
)
48 // register in the unnamed registry so that these tests are run by default
49 CPPUNIT_TEST_SUITE_REGISTRATION( DatePickerCtrlTestCase
);
51 // also include in its own registry so that these tests can be run alone
52 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( DatePickerCtrlTestCase
, "DatePickerCtrlTestCase" );
54 void DatePickerCtrlTestCase::setUp()
56 m_datepicker
= new wxDatePickerCtrl(wxTheApp
->GetTopWindow(), wxID_ANY
);
59 void DatePickerCtrlTestCase::tearDown()
64 void DatePickerCtrlTestCase::Value()
66 const wxDateTime
dt(18, wxDateTime::Jul
, 2011);
67 m_datepicker
->SetValue(dt
);
69 CPPUNIT_ASSERT_EQUAL( dt
, m_datepicker
->GetValue() );
71 // We don't use wxDP_ALLOWNONE currently, hence a value is required.
72 WX_ASSERT_FAILS_WITH_ASSERT( m_datepicker
->SetValue(wxDateTime()) );
75 void DatePickerCtrlTestCase::Range()
77 // Initially we have no valid range but MSW version still has (built in)
78 // minimum as it doesn't support dates before 1601-01-01, hence don't rely
79 // on GetRange() returning false.
80 wxDateTime dtRangeStart
, dtRangeEnd
;
81 m_datepicker
->GetRange(&dtRangeStart
, &dtRangeEnd
);
82 CPPUNIT_ASSERT( !dtRangeEnd
.IsValid() );
84 // After we set it we should be able to get it back.
86 dtStart(15, wxDateTime::Feb
, 1923),
87 dtEnd(18, wxDateTime::Jun
, 2011);
89 m_datepicker
->SetRange(dtStart
, dtEnd
);
90 CPPUNIT_ASSERT( m_datepicker
->GetRange(&dtRangeStart
, &dtRangeEnd
) );
91 CPPUNIT_ASSERT_EQUAL( dtStart
, dtRangeStart
);
92 CPPUNIT_ASSERT_EQUAL( dtEnd
, dtRangeEnd
);
94 // Setting dates inside the range should work, including the range end
96 m_datepicker
->SetValue(dtStart
);
97 CPPUNIT_ASSERT_EQUAL( dtStart
, m_datepicker
->GetValue() );
99 m_datepicker
->SetValue(dtEnd
);
100 CPPUNIT_ASSERT_EQUAL( dtEnd
, m_datepicker
->GetValue() );
103 // Setting dates outside the range should not work.
104 m_datepicker
->SetValue(dtEnd
+ wxTimeSpan::Day());
105 CPPUNIT_ASSERT_EQUAL( dtEnd
, m_datepicker
->GetValue() );
107 m_datepicker
->SetValue(dtStart
- wxTimeSpan::Day());
108 CPPUNIT_ASSERT_EQUAL( dtEnd
, m_datepicker
->GetValue() );
111 #endif // wxUSE_DATEPICKCTRL