|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the test suite of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 |
|
43 #include <QtTest/QtTest> |
|
44 |
|
45 #include <qcoreapplication.h> |
|
46 #include <qdebug.h> |
|
47 #include <qpoint.h> |
|
48 |
|
49 //TESTED_CLASS= |
|
50 //TESTED_FILES= |
|
51 |
|
52 class tst_QPoint : public QObject |
|
53 { |
|
54 Q_OBJECT |
|
55 |
|
56 public: |
|
57 tst_QPoint(); |
|
58 virtual ~tst_QPoint(); |
|
59 |
|
60 private slots: |
|
61 void getSetCheck(); |
|
62 void division(); |
|
63 |
|
64 void manhattanLength(); |
|
65 }; |
|
66 |
|
67 tst_QPoint::tst_QPoint() |
|
68 { |
|
69 } |
|
70 |
|
71 tst_QPoint::~tst_QPoint() |
|
72 { |
|
73 } |
|
74 |
|
75 |
|
76 |
|
77 void tst_QPoint::manhattanLength() |
|
78 { |
|
79 { |
|
80 QPoint p(10, 20); |
|
81 QCOMPARE(p.manhattanLength(), 30); |
|
82 } |
|
83 { |
|
84 QPointF p(10., 20.); |
|
85 QCOMPARE(p.manhattanLength(), 30.); |
|
86 } |
|
87 { |
|
88 QPointF p(10.1, 20.2); |
|
89 QCOMPARE(p.manhattanLength(), 30.3); |
|
90 } |
|
91 } |
|
92 |
|
93 // Testing get/set functions |
|
94 void tst_QPoint::getSetCheck() |
|
95 { |
|
96 QPoint obj1; |
|
97 // int QPoint::x() |
|
98 // void QPoint::setX(int) |
|
99 obj1.setX(0); |
|
100 QCOMPARE(0, obj1.x()); |
|
101 obj1.setX(INT_MIN); |
|
102 QCOMPARE(INT_MIN, obj1.x()); |
|
103 obj1.setX(INT_MAX); |
|
104 QCOMPARE(INT_MAX, obj1.x()); |
|
105 |
|
106 // int QPoint::y() |
|
107 // void QPoint::setY(int) |
|
108 obj1.setY(0); |
|
109 QCOMPARE(0, obj1.y()); |
|
110 obj1.setY(INT_MIN); |
|
111 QCOMPARE(INT_MIN, obj1.y()); |
|
112 obj1.setY(INT_MAX); |
|
113 QCOMPARE(INT_MAX, obj1.y()); |
|
114 |
|
115 QPointF obj2; |
|
116 // qreal QPointF::x() |
|
117 // void QPointF::setX(qreal) |
|
118 obj2.setX(0.0); |
|
119 QCOMPARE(0.0, obj2.x()); |
|
120 obj2.setX(1.1); |
|
121 QCOMPARE(1.1, obj2.x()); |
|
122 |
|
123 // qreal QPointF::y() |
|
124 // void QPointF::setY(qreal) |
|
125 obj2.setY(0.0); |
|
126 QCOMPARE(0.0, obj2.y()); |
|
127 obj2.setY(1.1); |
|
128 QCOMPARE(1.1, obj2.y()); |
|
129 } |
|
130 |
|
131 static inline qreal dot(const QPointF &a, const QPointF &b) |
|
132 { |
|
133 return a.x() * b.x() + a.y() * b.y(); |
|
134 } |
|
135 |
|
136 void tst_QPoint::division() |
|
137 { |
|
138 { |
|
139 QPointF p(1e-14, 1e-14); |
|
140 p = p / sqrt(dot(p, p)); |
|
141 qFuzzyCompare(dot(p, p), 1); |
|
142 } |
|
143 { |
|
144 QPointF p(1e-14, 1e-14); |
|
145 p /= sqrt(dot(p, p)); |
|
146 qFuzzyCompare(dot(p, p), 1); |
|
147 } |
|
148 } |
|
149 |
|
150 QTEST_MAIN(tst_QPoint) |
|
151 #include "tst_qpoint.moc" |