| 1 |
/* |
| 2 |
* Copyright (C) 2016 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 <QtGui/qpa/qplatformnativeinterface.h> |
| 18 |
#include <QtTest/QtTest> |
| 19 |
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) |
| 20 |
#include <LomiriToolkit-Qt6/private/ucunits_p.h> |
| 21 |
#else |
| 22 |
#include <LomiriToolkit/private/ucunits_p.h> |
| 23 |
#endif |
| 24 |
|
| 25 |
UT_USE_NAMESPACE |
| 26 |
|
| 27 |
class tst_UCUnitsScale : public QObject |
| 28 |
{ |
| 29 |
Q_OBJECT |
| 30 |
|
| 31 |
private Q_SLOTS: |
| 32 |
|
| 33 |
void dpGridUnitDefaultWithScale() { |
| 34 |
UCUnits units; |
| 35 |
|
| 36 |
QCOMPARE(units.dp(1.0), 1.0f); |
| 37 |
QCOMPARE(units.dp(1.32), 1.0f); |
| 38 |
QCOMPARE(units.dp(1.72), 2.0f); |
| 39 |
QCOMPARE(units.dp(0.23), 0.0f); |
| 40 |
QCOMPARE(units.dp(0.51), 1.0f); |
| 41 |
QCOMPARE(units.dp(0.9999), 1.0f); |
| 42 |
QCOMPARE(units.dp(1000.01), 1000.0f); |
| 43 |
|
| 44 |
QMetaObject::invokeMethod(qGuiApp->platformNativeInterface(), "changeScale", Q_ARG(float, 2.5)); |
| 45 |
QCOMPARE(units.dp(1.0), 2.0f); |
| 46 |
QCOMPARE(units.dp(1.32), 3.0f); |
| 47 |
QCOMPARE(units.dp(1.72), 3.0f); |
| 48 |
QCOMPARE(units.dp(0.23), 0.0f); |
| 49 |
QCOMPARE(units.dp(0.51), 1.0f); |
| 50 |
QCOMPARE(units.dp(0.9999), 2.0f); |
| 51 |
QCOMPARE(units.dp(1000.01), 2500.0f); |
| 52 |
} |
| 53 |
|
| 54 |
void guGridUnitDefaultWithScale() { |
| 55 |
UCUnits units; |
| 56 |
|
| 57 |
QCOMPARE(units.gu(0.5), 4.0f); |
| 58 |
QCOMPARE(units.gu(1), 8.0f); |
| 59 |
QCOMPARE(units.gu(1.5), 12.0f); |
| 60 |
QCOMPARE(units.gu(2), 16.0f); |
| 61 |
QCOMPARE(units.gu(4), 32.0f); |
| 62 |
QCOMPARE(units.gu(100000), 800000.0f); |
| 63 |
QCOMPARE(units.gu(150.51983), 1204.0f); |
| 64 |
|
| 65 |
QMetaObject::invokeMethod(qGuiApp->platformNativeInterface(), "changeScale", Q_ARG(float, 2.5)); |
| 66 |
QCOMPARE(units.gu(0.5), 10.0f); |
| 67 |
QCOMPARE(units.gu(1), 20.0f); |
| 68 |
QCOMPARE(units.gu(1.5), 30.0f); |
| 69 |
QCOMPARE(units.gu(2), 40.0f); |
| 70 |
QCOMPARE(units.gu(4), 80.0f); |
| 71 |
QCOMPARE(units.gu(100000), 2000000.0f); |
| 72 |
QCOMPARE(units.gu(150.51983), 3010.0f); |
| 73 |
} |
| 74 |
}; |
| 75 |
|
| 76 |
QTEST_MAIN(tst_UCUnitsScale) |
| 77 |
|
| 78 |
#include "tst_units_scale.moc" |