File: kdatecomboboxtest.cpp

package info (click to toggle)
kwidgetsaddons 5.28.0-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 62,388 kB
  • ctags: 3,611
  • sloc: cpp: 26,647; python: 682; sh: 23; makefile: 6
file content (163 lines) | stat: -rw-r--r-- 5,821 bytes parent folder | download
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
    Copyright 2011 John Layt <john@layt.net>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/

#include "kdatecomboboxtest.h"

#include <QtCore/QDate>

#include <QtTest/QtTest>
#include <QLineEdit>
#include "kdatecombobox.h"

QTEST_MAIN(KDateComboBoxTest)

void KDateComboBoxTest::testDefaults()
{
    m_combo = new KDateComboBox(0);
    QCOMPARE(m_combo->date(), QDate::currentDate());
    // Missing support in QLocale;
    //QCOMPARE(m_combo->minimumDate(), KLocale::global()->calendar()->earliestValidDate());
    //QCOMPARE(m_combo->maximumDate(), KLocale::global()->calendar()->latestValidDate());
    QCOMPARE(m_combo->isValid(), true);
    QCOMPARE(m_combo->isNull(), false);
    QCOMPARE(m_combo->options(), KDateComboBox::EditDate | KDateComboBox::SelectDate | KDateComboBox::DatePicker | KDateComboBox::DateKeywords);
    QCOMPARE(m_combo->displayFormat(), QLocale::ShortFormat);
    delete m_combo;
}

void KDateComboBoxTest::testValidNull()
{
    m_combo = new KDateComboBox(0);
    QCOMPARE(m_combo->isValid(), true);
    QCOMPARE(m_combo->isNull(), false);
    m_combo->setDate(QDate());
    QCOMPARE(m_combo->isValid(), false);
    QCOMPARE(m_combo->isNull(), true);
    m_combo->setDate(QDate(2000, 1, 1));
    m_combo->lineEdit()->setText(QStringLiteral("invalid"));
    QCOMPARE(m_combo->isValid(), false);
    QCOMPARE(m_combo->isNull(), false);
    delete m_combo;
}

void KDateComboBoxTest::testDateRange()
{
    m_combo = new KDateComboBox(0);
    m_combo->setDate(QDate(2000, 1, 1));
    // Missing support in QLocale;
    //QCOMPARE(m_combo->minimumDate(), KLocale::global()->calendar()->earliestValidDate());
    //QCOMPARE(m_combo->maximumDate(), KLocale::global()->calendar()->latestValidDate());
    QCOMPARE(m_combo->isValid(), true);

    m_combo->setDateRange(QDate(2001, 1, 1), QDate(2002, 1, 1));
    QCOMPARE(m_combo->minimumDate(), QDate(2001, 1, 1));
    QCOMPARE(m_combo->maximumDate(), QDate(2002, 1, 1));
    QCOMPARE(m_combo->isValid(), false);

    m_combo->setDate(QDate(2003, 1, 1));
    QCOMPARE(m_combo->isValid(), false);
    m_combo->setDate(QDate(2001, 6, 1));
    QCOMPARE(m_combo->isValid(), true);
    m_combo->setDate(QDate(2001, 1, 1));
    QCOMPARE(m_combo->isValid(), true);
    m_combo->setDate(QDate(2002, 1, 1));
    QCOMPARE(m_combo->isValid(), true);
    m_combo->setDate(QDate(2000, 12, 31));
    QCOMPARE(m_combo->isValid(), false);
    m_combo->setDate(QDate(2002, 1, 2));
    QCOMPARE(m_combo->isValid(), false);

    m_combo->setDateRange(QDate(1995, 1, 1), QDate(1990, 1, 1));
    QCOMPARE(m_combo->minimumDate(), QDate(2001, 1, 1));
    QCOMPARE(m_combo->maximumDate(), QDate(2002, 1, 1));

    m_combo->setMinimumDate(QDate(2000, 1, 1));
    QCOMPARE(m_combo->minimumDate(), QDate(2000, 1, 1));
    QCOMPARE(m_combo->maximumDate(), QDate(2002, 1, 1));

    m_combo->setMaximumDate(QDate(2003, 1, 1));
    QCOMPARE(m_combo->minimumDate(), QDate(2000, 1, 1));
    QCOMPARE(m_combo->maximumDate(), QDate(2003, 1, 1));

    m_combo->resetDateRange();
    QVERIFY(!m_combo->minimumDate().isValid());
    QVERIFY(!m_combo->maximumDate().isValid());

    // Check functioning when the minimum or maximum date is not already set

    m_combo->setMinimumDate(QDate(2000, 1, 1));
    QCOMPARE(m_combo->minimumDate(), QDate(2000, 1, 1));
    QVERIFY(!m_combo->maximumDate().isValid());

    m_combo->resetMinimumDate();
    QVERIFY(!m_combo->minimumDate().isValid());
    QVERIFY(!m_combo->maximumDate().isValid());

    m_combo->setMaximumDate(QDate(2003, 1, 1));
    QVERIFY(!m_combo->minimumDate().isValid());
    QCOMPARE(m_combo->maximumDate(), QDate(2003, 1, 1));

    m_combo->resetMaximumDate();
    QVERIFY(!m_combo->minimumDate().isValid());
    QVERIFY(!m_combo->maximumDate().isValid());

    delete m_combo;
}

void KDateComboBoxTest::testDateList()
{
    m_combo = new KDateComboBox(0);
    QMap<QDate, QString> map;

    // Test default map
    QCOMPARE(m_combo->dateMap(), map);

    // Test basic map
    map.clear();
    map.insert(QDate(2000, 1, 1), QStringLiteral("New Years Day"));
    map.insert(QDate(2000, 1, 2), QString());
    map.insert(QDate(2000, 1, 3), QStringLiteral("separator"));
    map.insert(QDate(), QStringLiteral("No Date"));
    m_combo->setDateMap(map);
    QCOMPARE(m_combo->dateMap(), map);

    delete m_combo;
}

void KDateComboBoxTest::testOptions()
{
    m_combo = new KDateComboBox(0);
    KDateComboBox::Options options = KDateComboBox::EditDate | KDateComboBox::SelectDate | KDateComboBox::DatePicker | KDateComboBox::DateKeywords;
    QCOMPARE(m_combo->options(), options);
    options = KDateComboBox::EditDate | KDateComboBox::WarnOnInvalid;
    m_combo->setOptions(options);
    QCOMPARE(m_combo->options(), options);
    delete m_combo;
}

void KDateComboBoxTest::testDisplayFormat()
{
    m_combo = new KDateComboBox(0);
    QLocale::FormatType format = QLocale::ShortFormat;
    QCOMPARE(m_combo->displayFormat(), format);
    format = QLocale::NarrowFormat;
    m_combo->setDisplayFormat(format);
    QCOMPARE(m_combo->displayFormat(), format);
    delete m_combo;
}