1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the test suite of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21 ** included in the packaging of this file. Please review the following
22 ** information to ensure the GNU General Public License requirements will
23 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24 **
25 ** $QT_END_LICENSE$
26 **
27 ****************************************************************************/
28
29 #include <QtCore/QString>
30 #include <QtTest/QtTest>
31
32 #include <qplaceperiod.h>
33
34 QT_USE_NAMESPACE
35
36 class tst_QPlacePeriod : public QObject
37 {
38 Q_OBJECT
39
40 public:
41 tst_QPlacePeriod();
42
43 private Q_SLOTS:
44 void constructorTest();
45 void startDateTest();
46 void startTimeTest();
47 void endDateTest();
48 void endTimeTest();
49 void operatorsTest();
50 };
51
tst_QPlacePeriod()52 tst_QPlacePeriod::tst_QPlacePeriod()
53 {
54 }
55
constructorTest()56 void tst_QPlacePeriod::constructorTest()
57 {
58 QPlacePeriod testObj;
59 testObj.setStartTime(QTime::currentTime());
60 QPlacePeriod *testObjPtr = new QPlacePeriod(testObj);
61 QVERIFY2(testObjPtr != NULL, "Copy constructor - null");
62 QVERIFY2(testObjPtr->startTime() == testObj.startTime(), "Copy constructor - start time");
63 delete testObjPtr;
64 }
65
startDateTest()66 void tst_QPlacePeriod::startDateTest()
67 {
68 QPlacePeriod testObj;
69 QVERIFY2(testObj.startDate().isNull() == true, "Wrong default value");
70 QDate date = QDate::currentDate();
71 testObj.setStartDate(date);
72 QVERIFY2(testObj.startDate() == date, "Wrong value returned");
73 }
74
startTimeTest()75 void tst_QPlacePeriod::startTimeTest()
76 {
77 QPlacePeriod testObj;
78 QVERIFY2(testObj.startTime().isNull() == true, "Wrong default value");
79 QTime time = QTime::currentTime();
80 testObj.setStartTime(time);
81 QVERIFY2(testObj.startTime() == time, "Wrong value returned");
82 }
83
endDateTest()84 void tst_QPlacePeriod::endDateTest()
85 {
86 QPlacePeriod testObj;
87 QVERIFY2(testObj.endDate().isNull() == true, "Wrong default value");
88 QDate date = QDate::currentDate();
89 testObj.setEndDate(date);
90 QVERIFY2(testObj.endDate() == date, "Wrong value returned");
91 }
92
endTimeTest()93 void tst_QPlacePeriod::endTimeTest()
94 {
95 QPlacePeriod testObj;
96 QVERIFY2(testObj.endTime().isNull() == true, "Wrong default value");
97 QTime time = QTime::currentTime();
98 testObj.setEndTime(time);
99 QVERIFY2(testObj.endTime() == time, "Wrong value returned");
100 }
101
operatorsTest()102 void tst_QPlacePeriod::operatorsTest()
103 {
104 QPlacePeriod testObj;
105 QTime time = QTime::currentTime();
106 testObj.setEndTime(time);
107 QPlacePeriod testObj2;
108 testObj2 = testObj;
109 QVERIFY2(testObj == testObj2, "Not copied correctly");
110 testObj.setEndTime(QTime::currentTime().addSecs(102021));
111 QVERIFY2(testObj != testObj2, "Object should be different");
112 }
113
114 QTEST_APPLESS_MAIN(tst_QPlacePeriod);
115
116 #include "tst_qplaceperiod.moc"
117