]> git.saurik.com Git - wxWidgets.git/blame - tests/controls/datepickerctrltest.cpp
Add test for absence of events from wxSpinCtrlDouble ctor.
[wxWidgets.git] / tests / controls / datepickerctrltest.cpp
CommitLineData
5f899cbe
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: tests/controls/datepickerctrltest.cpp
3// Purpose: wxDatePickerCtrl unit test
4// Author: Vadim Zeitlin
5// Created: 2011-06-18
5f899cbe
VZ
6// Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
7///////////////////////////////////////////////////////////////////////////////
8
9#include "testprec.h"
10
11#if wxUSE_DATEPICKCTRL
12
13#ifdef __BORLANDC__
14 #pragma hdrstop
15#endif
16
17#ifndef WX_PRECOMP
18 #include "wx/app.h"
19#endif // WX_PRECOMP
20
21#include "wx/datectrl.h"
22
23#include "testableframe.h"
24#include "testdate.h"
25
26class DatePickerCtrlTestCase : public CppUnit::TestCase
27{
28public:
29 DatePickerCtrlTestCase() { }
30
31 void setUp();
32 void tearDown();
33
34private:
35 CPPUNIT_TEST_SUITE( DatePickerCtrlTestCase );
36 CPPUNIT_TEST( Value );
37 CPPUNIT_TEST( Range );
38 CPPUNIT_TEST_SUITE_END();
39
40 void Value();
41 void Range();
42
43 wxDatePickerCtrl* m_datepicker;
44
45 DECLARE_NO_COPY_CLASS(DatePickerCtrlTestCase)
46};
47
48// register in the unnamed registry so that these tests are run by default
49CPPUNIT_TEST_SUITE_REGISTRATION( DatePickerCtrlTestCase );
50
51// also include in its own registry so that these tests can be run alone
52CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( DatePickerCtrlTestCase, "DatePickerCtrlTestCase" );
53
54void DatePickerCtrlTestCase::setUp()
55{
56 m_datepicker = new wxDatePickerCtrl(wxTheApp->GetTopWindow(), wxID_ANY);
57}
58
59void DatePickerCtrlTestCase::tearDown()
60{
61 delete m_datepicker;
62}
63
64void DatePickerCtrlTestCase::Value()
65{
66 const wxDateTime dt(18, wxDateTime::Jul, 2011);
67 m_datepicker->SetValue(dt);
68
69 CPPUNIT_ASSERT_EQUAL( dt, m_datepicker->GetValue() );
70
71 // We don't use wxDP_ALLOWNONE currently, hence a value is required.
72 WX_ASSERT_FAILS_WITH_ASSERT( m_datepicker->SetValue(wxDateTime()) );
73}
74
75void DatePickerCtrlTestCase::Range()
76{
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() );
83
84 // After we set it we should be able to get it back.
85 const wxDateTime
86 dtStart(15, wxDateTime::Feb, 1923),
87 dtEnd(18, wxDateTime::Jun, 2011);
88
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 );
93
94 // Setting dates inside the range should work, including the range end
95 // points.
96 m_datepicker->SetValue(dtStart);
97 CPPUNIT_ASSERT_EQUAL( dtStart, m_datepicker->GetValue() );
98
99 m_datepicker->SetValue(dtEnd);
100 CPPUNIT_ASSERT_EQUAL( dtEnd, m_datepicker->GetValue() );
101
102
103 // Setting dates outside the range should not work.
104 m_datepicker->SetValue(dtEnd + wxTimeSpan::Day());
105 CPPUNIT_ASSERT_EQUAL( dtEnd, m_datepicker->GetValue() );
106
107 m_datepicker->SetValue(dtStart - wxTimeSpan::Day());
108 CPPUNIT_ASSERT_EQUAL( dtEnd, m_datepicker->GetValue() );
109}
110
111#endif // wxUSE_DATEPICKCTRL