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