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 <qplaceratings.h> |
33 | |
34 | QT_USE_NAMESPACE |
35 | |
36 | class tst_QPlaceRatings : public QObject |
37 | { |
38 | Q_OBJECT |
39 | |
40 | public: |
41 | tst_QPlaceRatings(); |
42 | |
43 | private Q_SLOTS: |
44 | void constructorTest(); |
45 | void averageTest(); |
46 | void countTest(); |
47 | void operatorsTest(); |
48 | void isEmptyTest(); |
49 | }; |
50 | |
51 | tst_QPlaceRatings::tst_QPlaceRatings() |
52 | { |
53 | } |
54 | |
55 | void tst_QPlaceRatings::constructorTest() |
56 | { |
57 | QPlaceRatings testObj; |
58 | Q_UNUSED(testObj); |
59 | |
60 | QPlaceRatings *testObjPtr = new QPlaceRatings(testObj); |
61 | QVERIFY2(testObjPtr != NULL, "Copy constructor - null" ); |
62 | QVERIFY2(testObjPtr->count() == 0, "Copy constructor - wrong count" ); |
63 | QVERIFY2(testObjPtr->average() == 0, "Copy constructor - wrong average" ); |
64 | QVERIFY2(*testObjPtr == testObj, "Copy constructor - compare" ); |
65 | delete testObjPtr; |
66 | } |
67 | |
68 | void tst_QPlaceRatings::averageTest() |
69 | { |
70 | QPlaceRatings testObj; |
71 | QVERIFY2(qFuzzyCompare(testObj.average(), 0) , "Wrong default average" ); |
72 | testObj.setAverage(-10.23); |
73 | QCOMPARE(testObj.average(), -10.23); |
74 | } |
75 | |
76 | void tst_QPlaceRatings::countTest() |
77 | { |
78 | QPlaceRatings testObj; |
79 | QVERIFY2(testObj.count() == 0, "Wrong default value" ); |
80 | testObj.setCount(-1002); |
81 | QVERIFY2(testObj.count() == -1002, "Wrong value returned" ); |
82 | } |
83 | |
84 | void tst_QPlaceRatings::operatorsTest() |
85 | { |
86 | QPlaceRatings testObj; |
87 | testObj.setAverage(0.123); |
88 | QPlaceRatings testObj2; |
89 | testObj2 = testObj; |
90 | QVERIFY2(testObj == testObj2, "Not copied correctly" ); |
91 | testObj2.setCount(-10); |
92 | QVERIFY2(testObj != testObj2, "Object should be different" ); |
93 | } |
94 | |
95 | void tst_QPlaceRatings::isEmptyTest() |
96 | { |
97 | QPlaceRatings ratings; |
98 | |
99 | QVERIFY(ratings.isEmpty()); |
100 | |
101 | ratings.setCount(1); |
102 | QVERIFY(!ratings.isEmpty()); |
103 | ratings.setCount(0); |
104 | QVERIFY(ratings.isEmpty()); |
105 | |
106 | ratings.setMaximum(1); |
107 | QVERIFY(!ratings.isEmpty()); |
108 | ratings.setMaximum(0); |
109 | QVERIFY(ratings.isEmpty()); |
110 | |
111 | ratings.setAverage(1); |
112 | QVERIFY(!ratings.isEmpty()); |
113 | ratings.setAverage(0); |
114 | QVERIFY(ratings.isEmpty()); |
115 | } |
116 | |
117 | QTEST_APPLESS_MAIN(tst_QPlaceRatings); |
118 | |
119 | #include "tst_qplaceratings.moc" |
120 | |