Changeset View
Changeset View
Standalone View
Standalone View
autotests/DateTimeTest.cpp
- This file was added.
1 | /* This file is part of the KDE project | ||||
---|---|---|---|---|---|
2 | Copyright (C) 2018 Jarosław Staniek <staniek@kde.org> | ||||
3 | | ||||
4 | This library is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU Library General Public | ||||
6 | License as published by the Free Software Foundation; either | ||||
7 | version 2 of the License, or (at your option) any later version. | ||||
8 | | ||||
9 | This library is distributed in the hope that it will be useful, | ||||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
12 | Library General Public License for more details. | ||||
13 | | ||||
14 | You should have received a copy of the GNU Library General Public License | ||||
15 | along with this library; see the file COPYING.LIB. If not, write to | ||||
16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
17 | * Boston, MA 02110-1301, USA. | ||||
18 | */ | ||||
19 | | ||||
20 | #include "DateTimeTest.h" | ||||
21 | | ||||
22 | #include <QtTest> | ||||
23 | | ||||
24 | #include <KDbDateTime> | ||||
25 | #include <KDbExpression> | ||||
26 | #include "parser/generated/sqlparser.h" | ||||
27 | #include "parser/KDbParser_p.h" | ||||
28 | | ||||
29 | QTEST_GUILESS_MAIN(DateTimeTest) | ||||
30 | | ||||
31 | void DateTimeTest::initTestCase() | ||||
32 | { | ||||
33 | } | ||||
34 | | ||||
35 | void DateTimeTest::testYear() | ||||
36 | { | ||||
37 | KDbYear year("2020"); | ||||
38 | QVERIFY(year.isValid()); | ||||
39 | QCOMPARE(year.toString(), "2020"); | ||||
40 | QCOMPARE(year.toQDateValue(), 2020); | ||||
41 | QCOMPARE(year.toIsoValue(), 2020); | ||||
42 | QVariant yearVariant = QVariant::fromValue(year); | ||||
43 | QVERIFY(yearVariant.isValid()); | ||||
44 | QCOMPARE(yearVariant.toInt(), 2020); | ||||
45 | QCOMPARE(yearVariant.toString(), "2020"); | ||||
46 | } | ||||
47 | | ||||
48 | void DateTimeTest::testDate() | ||||
49 | { | ||||
50 | KDbYear year("2020"); | ||||
51 | KDbDate date(year, "2", "29"); | ||||
52 | QVERIFY(date.isValid()); | ||||
53 | QCOMPARE(date.toString(), "2020-2-29"); | ||||
54 | QDate qtDate(2020, 2, 29); | ||||
55 | QCOMPARE(date.toQDate(), qtDate); | ||||
56 | QVariant dateVariant = QVariant::fromValue(date); | ||||
57 | QVERIFY(dateVariant.isValid()); | ||||
58 | QCOMPARE(dateVariant.toDate(), qtDate); | ||||
59 | //! @todo more cases | ||||
60 | } | ||||
61 | | ||||
62 | void DateTimeTest::testTime() | ||||
63 | { | ||||
64 | KDbTime time("1", "15", "20", "789", KDbTime::Period::Pm); | ||||
65 | QVERIFY(time.isValid()); | ||||
66 | QCOMPARE(time.toString(), "1:15:20.789 PM"); | ||||
67 | QTime qtTime(13, 15, 20, 789); | ||||
68 | QCOMPARE(time.toQTime(), qtTime); | ||||
69 | QVariant timeVariant = QVariant::fromValue(time); | ||||
70 | QVERIFY(timeVariant.isValid()); | ||||
71 | QCOMPARE(timeVariant.toTime(), qtTime); | ||||
72 | //! @todo more cases | ||||
73 | } | ||||
74 | | ||||
75 | void DateTimeTest::testDateTime() | ||||
76 | { | ||||
77 | KDbYear year("2020"); | ||||
78 | KDbTime time("1", "15", "20", "789", KDbTime::Period::Pm); | ||||
79 | KDbDate date(year, "2", "29"); | ||||
80 | | ||||
81 | KDbDateTime dateTime(date, time); | ||||
82 | QVERIFY(dateTime.isValid()); | ||||
83 | QCOMPARE(dateTime.toString(), "2020-2-29 1:15:20.789 PM"); | ||||
84 | QTime qtTime(13, 15, 20, 789); | ||||
85 | QDate qtDate(2020, 2, 29); | ||||
86 | QDateTime qtDateTime(qtDate, qtTime); | ||||
87 | QCOMPARE(dateTime.toQDateTime(), qtDateTime); | ||||
88 | QVariant dateTimeVariant = QVariant::fromValue(dateTime); | ||||
89 | QVERIFY(dateTimeVariant.isValid()); | ||||
90 | QCOMPARE(dateTimeVariant.toDateTime(), qtDateTime); | ||||
91 | //! @todo more cases | ||||
92 | } | ||||
93 | | ||||
94 | void DateTimeTest::cleanupTestCase() | ||||
95 | { | ||||
96 | } |