Changeset View
Changeset View
Standalone View
Standalone View
libs/odf/tests/TestKoUnit.cpp
Show First 20 Lines • Show All 53 Lines • ▼ Show 20 Line(s) | 51 | { | |||
---|---|---|---|---|---|
54 | KoUnit unit(type); | 54 | KoUnit unit(type); | ||
55 | QCOMPARE(unit.type(), type); | 55 | QCOMPARE(unit.type(), type); | ||
56 | } | 56 | } | ||
57 | 57 | | |||
58 | void TestKoUnit::testPixelConstructor() | 58 | void TestKoUnit::testPixelConstructor() | ||
59 | { | 59 | { | ||
60 | KoUnit unit(KoUnit::Pixel, 0.5); | 60 | KoUnit unit(KoUnit::Pixel, 0.5); | ||
61 | QCOMPARE(unit.type(), KoUnit::Pixel); | 61 | QCOMPARE(unit.type(), KoUnit::Pixel); | ||
62 | QCOMPARE(KoUnit::ptToUnit(100, unit), (qreal)50); | 62 | QCOMPARE(unit.toUserValue(100, false), (qreal)50); | ||
63 | } | 63 | } | ||
64 | 64 | | |||
65 | void TestKoUnit::testAssignOperator_data() | 65 | void TestKoUnit::testAssignOperator_data() | ||
66 | { | 66 | { | ||
67 | QTest::addColumn<KoUnit::Type>("type"); | 67 | QTest::addColumn<KoUnit::Type>("type"); | ||
68 | QTest::addColumn<KoUnit::Type>("otherType"); | 68 | QTest::addColumn<KoUnit::Type>("otherType"); | ||
69 | 69 | | |||
70 | QTest::newRow("point-pica") << KoUnit::Point << KoUnit::Pica; | 70 | QTest::newRow("point-pica") << KoUnit::Point << KoUnit::Pica; | ||
▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Line(s) | 153 | { | |||
154 | QFETCH(KoUnit::ListOptions, listOptions); | 154 | QFETCH(KoUnit::ListOptions, listOptions); | ||
155 | QFETCH(int, index); | 155 | QFETCH(int, index); | ||
156 | 156 | | |||
157 | KoUnit unit = KoUnit::fromListForUi(index, listOptions); | 157 | KoUnit unit = KoUnit::fromListForUi(index, listOptions); | ||
158 | 158 | | |||
159 | QCOMPARE(unit.indexInListForUi(listOptions), index); | 159 | QCOMPARE(unit.indexInListForUi(listOptions), index); | ||
160 | } | 160 | } | ||
161 | 161 | | |||
162 | | ||||
163 | void TestKoUnit::testToUserValue_data() | ||||
164 | { | ||||
165 | // regression test to check whether changes in KoUnit changes the conversion output | ||||
166 | | ||||
167 | QTest::addColumn<KoUnit::Type>("type"); | ||||
168 | QTest::addColumn<qreal>("value"); | ||||
169 | QTest::addColumn<qreal>("expected"); | ||||
170 | QTest::addColumn<qreal>("expectedRounded"); | ||||
171 | | ||||
172 | | ||||
173 | // 1000.0 | ||||
174 | QTest::newRow("point 1000") << KoUnit::Point << 1000.0 << 1000.0 << 1000.0; | ||||
175 | QTest::newRow("pica 1000") << KoUnit::Pica << 1000.0 << 83.3333330000 << 83.3333300000; | ||||
176 | QTest::newRow("pixel 1000") << KoUnit::Pixel << 1000.0 << 1000.0 << 1000.0; | ||||
177 | QTest::newRow("inch 1000") << KoUnit::Inch << 1000.0 << 13.8888888889 << 13.8888800000; | ||||
178 | QTest::newRow("decimeter 1000") << KoUnit::Decimeter << 1000.0 << 3.5277716700 << 3.5277000000; | ||||
179 | | ||||
180 | // 1.37 | ||||
181 | QTest::newRow("point 1.37") << KoUnit::Point << 1.37 << 1.37 << 1.37; | ||||
182 | QTest::newRow("pica 1.37") << KoUnit::Pica << 1.37 << 0.114166666210 << 0.1141600000; | ||||
183 | QTest::newRow("pixel 1.37") << KoUnit::Pixel << 1.37 << 1.37 << 1.37; | ||||
184 | QTest::newRow("inch 1.37") << KoUnit::Inch << 1.37 << 0.019027777777779 << 0.019020000000; | ||||
185 | QTest::newRow("decimeter 1.37") << KoUnit::Decimeter << 1.37 << 0.004833047187900 << 0.004800000000; | ||||
186 | | ||||
187 | // 0.0001111 | ||||
188 | QTest::newRow("point 0.0001111") << KoUnit::Point << 0.0001111 << 0.000111100000 << 0.0 ; | ||||
189 | QTest::newRow("pica 0.0001111") << KoUnit::Pica << 0.0001111 << 0.00000925833329630 << 0.0; | ||||
190 | QTest::newRow("pixel 0.0001111") << KoUnit::Pixel << 0.0001111 << 0.000111100000 << 0.000111100000 ; | ||||
191 | QTest::newRow("inch 0.0001111") << KoUnit::Inch << 0.0001111 << 0.00000154305555555568 << 0.0; | ||||
192 | QTest::newRow("decimeter 0.0001111") << KoUnit::Decimeter << 0.0001111 << 0.00000039193543253700 << 0.0; | ||||
193 | } | ||||
194 | | ||||
195 | void TestKoUnit::testToUserValue() | ||||
196 | { | ||||
197 | QFETCH(KoUnit::Type, type); | ||||
198 | QFETCH(qreal, value); | ||||
199 | QFETCH(qreal, expected); | ||||
200 | QFETCH(qreal, expectedRounded); | ||||
201 | | ||||
202 | KoUnit unit = KoUnit(type); | ||||
203 | | ||||
204 | qreal exphere = unit.toUserValue(value, false); | ||||
205 | qreal expRound = unit.toUserValue(value, true); | ||||
206 | | ||||
207 | QCOMPARE(exphere, expected); | ||||
208 | QCOMPARE(expRound, expectedRounded); | ||||
209 | | ||||
210 | } | ||||
211 | | ||||
162 | QTEST_GUILESS_MAIN(TestKoUnit) | 212 | QTEST_GUILESS_MAIN(TestKoUnit) |