]>
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
7 // Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
8 ///////////////////////////////////////////////////////////////////////////////
12 #if wxUSE_DATEPICKCTRL
22 #include "wx/datectrl.h"
24 #include "testableframe.h"
27 class DatePickerCtrlTestCase
: public CppUnit::TestCase
30 DatePickerCtrlTestCase() { }
36 CPPUNIT_TEST_SUITE( DatePickerCtrlTestCase
);
37 CPPUNIT_TEST( Value
);
38 CPPUNIT_TEST( Range
);
39 CPPUNIT_TEST_SUITE_END();
44 wxDatePickerCtrl
* m_datepicker
;
46 DECLARE_NO_COPY_CLASS(DatePickerCtrlTestCase
)
49 // register in the unnamed registry so that these tests are run by default
50 CPPUNIT_TEST_SUITE_REGISTRATION( DatePickerCtrlTestCase
);
52 // also include in its own registry so that these tests can be run alone
53 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( DatePickerCtrlTestCase
, "DatePickerCtrlTestCase" );
55 void DatePickerCtrlTestCase::setUp()
57 m_datepicker
= new wxDatePickerCtrl(wxTheApp
->GetTopWindow(), wxID_ANY
);
60 void DatePickerCtrlTestCase::tearDown()
65 void DatePickerCtrlTestCase::Value()
67 const wxDateTime
dt(18, wxDateTime::Jul
, 2011);
68 m_datepicker
->SetValue(dt
);
70 CPPUNIT_ASSERT_EQUAL( dt
, m_datepicker
->GetValue() );
72 // We don't use wxDP_ALLOWNONE currently, hence a value is required.
73 WX_ASSERT_FAILS_WITH_ASSERT( m_datepicker
->SetValue(wxDateTime()) );
76 void DatePickerCtrlTestCase::Range()
78 // Initially we have no valid range but MSW version still has (built in)
79 // minimum as it doesn't support dates before 1601-01-01, hence don't rely
80 // on GetRange() returning false.
81 wxDateTime dtRangeStart
, dtRangeEnd
;
82 m_datepicker
->GetRange(&dtRangeStart
, &dtRangeEnd
);
83 CPPUNIT_ASSERT( !dtRangeEnd
.IsValid() );
85 // After we set it we should be able to get it back.
87 dtStart(15, wxDateTime::Feb
, 1923),
88 dtEnd(18, wxDateTime::Jun
, 2011);
90 m_datepicker
->SetRange(dtStart
, dtEnd
);
91 CPPUNIT_ASSERT( m_datepicker
->GetRange(&dtRangeStart
, &dtRangeEnd
) );
92 CPPUNIT_ASSERT_EQUAL( dtStart
, dtRangeStart
);
93 CPPUNIT_ASSERT_EQUAL( dtEnd
, dtRangeEnd
);
95 // Setting dates inside the range should work, including the range end
97 m_datepicker
->SetValue(dtStart
);
98 CPPUNIT_ASSERT_EQUAL( dtStart
, m_datepicker
->GetValue() );
100 m_datepicker
->SetValue(dtEnd
);
101 CPPUNIT_ASSERT_EQUAL( dtEnd
, m_datepicker
->GetValue() );
104 // Setting dates outside the range should not work.
105 m_datepicker
->SetValue(dtEnd
+ wxTimeSpan::Day());
106 CPPUNIT_ASSERT_EQUAL( dtEnd
, m_datepicker
->GetValue() );
108 m_datepicker
->SetValue(dtStart
- wxTimeSpan::Day());
109 CPPUNIT_ASSERT_EQUAL( dtEnd
, m_datepicker
->GetValue() );
112 #endif // wxUSE_DATEPICKCTRL