Debian Codegraph @

tests/unit/units/dpr3/tst_units_dpr3.cpp

raw
1 /*
2 * Copyright (C) 2015 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License version 3, as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 #include <QtTest/QtTest>
18 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
19 #include <LomiriToolkit-Qt6/private/ucunits_p.h>
20 #else
21 #include <LomiriToolkit/private/ucunits_p.h>
22 #endif
23
24 UT_USE_NAMESPACE
25
26 class tst_UCUnitsDPR3: public QObject
27 {
28 Q_OBJECT
29
30 private Q_SLOTS:
31
32 void dpGridUnitDefaultWithDPR3() {
33 UCUnits units;
34
35 QCOMPARE(units.dp(1.0), 1.0f);
36 QCOMPARE(units.dp(1.32), 1.33333f);
37 QCOMPARE(units.dp(1.72), 1.66666f);
38 QCOMPARE(units.dp(0.23), 0.333333f);
39 QCOMPARE(units.dp(0.51), 0.666666f);
40 QCOMPARE(units.dp(0.9999), 1.0f);
41 QCOMPARE(units.dp(1000.01), 1000.0f);
42 }
43
44 void guGridUnitDefaultWithDPR3() {
45 UCUnits units;
46
47 QCOMPARE(units.gu(0.5), 4.0f);
48 QCOMPARE(units.gu(1), 8.0f);
49 QCOMPARE(units.gu(1.5), 12.0f);
50 QCOMPARE(units.gu(2), 16.0f);
51 QCOMPARE(units.gu(4), 32.0f);
52 QCOMPARE(units.gu(100000), 800000.0f);
53 QCOMPARE(units.gu(150.51983), 1204.0f);
54 }
55
56 void dpGridUnitSixteenWithDPR3() {
57 UCUnits units;
58 units.setGridUnit(16);
59
60 QCOMPARE(units.dp(1.0), 0.666666f);
61 QCOMPARE(units.dp(1.32), 1.0f);
62 QCOMPARE(units.dp(1.72), 1.0f);
63 QCOMPARE(units.dp(0.23), 0.0f);
64 QCOMPARE(units.dp(0.51), 0.333333f);
65 QCOMPARE(units.dp(0.9999), 0.666666f);
66 QCOMPARE(units.dp(1000.01), 666.666666f);
67 }
68
69 void guGridUnitSixteenWithDPR3() {
70 UCUnits units;
71 units.setGridUnit(16);
72
73 QCOMPARE(units.gu(0.5), 2.666666f);
74 QCOMPARE(units.gu(1), 5.333333f);
75 QCOMPARE(units.gu(1.5), 8.0f);
76 QCOMPARE(units.gu(2), 10.666666f);
77 QCOMPARE(units.gu(4), 21.333333f);
78 QCOMPARE(units.gu(100000), 533333.333333f);
79 QCOMPARE(units.gu(150.51983), 802.666666f);
80 }
81 };
82
83 //QTEST_MAIN(tst_UCUnitsDPR3) - want to set custom env var, so need to use actual code:
84 int main(int argc, char *argv[])
85 {
86 qputenv("QT_SCALE_FACTOR", "3");
87 qunsetenv("GRID_UNIT_PX");
88
89 QGuiApplication app(argc, argv);
90 app.setAttribute(Qt::AA_Use96Dpi, true);
91 tst_UCUnitsDPR3 tc;
92 return QTest::qExec(&tc, argc, argv);
93 }
94
95 #include "tst_units_dpr3.moc"