File: datepickerctrltest.cpp

package info (click to toggle)
wxwidgets3.0 3.0.5.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 120,464 kB
  • sloc: cpp: 896,633; makefile: 52,303; ansic: 21,971; sh: 5,713; python: 2,940; xml: 1,534; perl: 264; javascript: 33
file content (111 lines) | stat: -rw-r--r-- 3,223 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
///////////////////////////////////////////////////////////////////////////////
// Name:        tests/controls/datepickerctrltest.cpp
// Purpose:     wxDatePickerCtrl unit test
// Author:      Vadim Zeitlin
// Created:     2011-06-18
// 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