Changeset View
Changeset View
Standalone View
Standalone View
wallpapers/image/autotests/testfindpreferredimage.cpp
- This file was added.
1 | /*************************************************************************** | ||||
---|---|---|---|---|---|
2 | * Copyright 2016 Antonio Larrosa <larrosa@kde.org> * | ||||
3 | * * | ||||
4 | * This program is free software; you can redistribute it and/or modify * | ||||
5 | * it under the terms of the GNU General Public License as published by * | ||||
6 | * the Free Software Foundation; either version 2 of the License, or * | ||||
7 | * (at your option) any later version. * | ||||
8 | * * | ||||
9 | * This program is distributed in the hope that it will be useful, * | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||||
12 | * GNU General Public License for more details. * | ||||
13 | * * | ||||
14 | * You should have received a copy of the GNU General Public License * | ||||
15 | * along with this program; if not, write to the * | ||||
16 | * Free Software Foundation, Inc., * | ||||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * | ||||
18 | ***************************************************************************/ | ||||
19 | #include "image.h" | ||||
20 | #include <QtTest/QtTest> | ||||
21 | #include <QDebug> | ||||
22 | | ||||
23 | extern QSize resSize(const QString &str); | ||||
24 | | ||||
25 | QString formatResolution(const QString &str) | ||||
26 | { | ||||
27 | QSize size = resSize(str); | ||||
28 | float aspectRatio = (size.height() > 0 ) ? size.width() / (float)size.height() : 0; | ||||
29 | return QString("%1 (%2)").arg(str, 9).arg(aspectRatio, 7); | ||||
30 | } | ||||
31 | | ||||
32 | class TestResolutions: public QObject | ||||
33 | { | ||||
34 | Q_OBJECT | ||||
35 | | ||||
36 | private slots: | ||||
37 | void testResolutions_data(); | ||||
38 | void testResolutions(); | ||||
39 | | ||||
40 | protected: | ||||
41 | Image m_image; | ||||
42 | QStringList m_images; | ||||
43 | }; | ||||
44 | | ||||
45 | void TestResolutions::testResolutions_data() | ||||
46 | { | ||||
47 | // The list of available wallpaper image sizes | ||||
48 | m_images << QStringLiteral("1280x1024") | ||||
49 | << QStringLiteral("1350x1080") | ||||
50 | << QStringLiteral("1440x1080") | ||||
51 | << QStringLiteral("1600x1200") | ||||
52 | << QStringLiteral("1920x1080") | ||||
53 | << QStringLiteral("1920x1200") | ||||
54 | << QStringLiteral("3840x2400"); | ||||
55 | qDebug() << "Available images:"; | ||||
56 | foreach( auto image, m_images) { | ||||
57 | qDebug() << formatResolution(image); | ||||
58 | } | ||||
59 | | ||||
60 | // The list of possible screen resolutions to test and the appropiate images that should be chosen | ||||
61 | QTest::addColumn<QString>("resolution"); | ||||
62 | QTest::addColumn<QString>("expected"); | ||||
63 | QTest::newRow("1280x1024") << QStringLiteral("1280x1024") << QStringLiteral("1280x1024"); | ||||
64 | QTest::newRow("1350x1080") << QStringLiteral("1350x1080") << QStringLiteral("1350x1080"); | ||||
65 | QTest::newRow("1440x1080") << QStringLiteral("1440x1080") << QStringLiteral("1440x1080"); | ||||
66 | QTest::newRow("1600x1200") << QStringLiteral("1600x1200") << QStringLiteral("1600x1200"); | ||||
67 | QTest::newRow("1920x1080") << QStringLiteral("1920x1080") << QStringLiteral("1920x1080"); | ||||
68 | QTest::newRow("1920x1200") << QStringLiteral("1920x1200") << QStringLiteral("1920x1200"); | ||||
69 | QTest::newRow("3840x2400") << QStringLiteral("3840x2400") << QStringLiteral("3840x2400"); | ||||
70 | QTest::newRow("4096x2160") << QStringLiteral("4096x2160") << QStringLiteral("1920x1080"); | ||||
71 | QTest::newRow("3840x2160") << QStringLiteral("3840x2160") << QStringLiteral("1920x1080"); | ||||
72 | QTest::newRow("3200x1800") << QStringLiteral("3200x1800") << QStringLiteral("1920x1080"); | ||||
73 | QTest::newRow("2048x1080") << QStringLiteral("2048x1080") << QStringLiteral("1920x1080"); | ||||
74 | QTest::newRow("1680x1050") << QStringLiteral("1680x1050") << QStringLiteral("1920x1200"); | ||||
75 | QTest::newRow("1400x1050") << QStringLiteral("1400x1050") << QStringLiteral("1440x1080"); | ||||
76 | QTest::newRow("1440x900") << QStringLiteral("1440x900") << QStringLiteral("1920x1200"); | ||||
77 | QTest::newRow("1280x960") << QStringLiteral("1280x960") << QStringLiteral("1440x1080"); | ||||
78 | QTest::newRow("1280x854") << QStringLiteral("1280x854") << QStringLiteral("1920x1200"); | ||||
79 | QTest::newRow("1280x800") << QStringLiteral("1280x800") << QStringLiteral("1920x1200"); | ||||
80 | QTest::newRow("1280x720") << QStringLiteral("1280x720") << QStringLiteral("1920x1080"); | ||||
81 | QTest::newRow("1152x768") << QStringLiteral("1152x768") << QStringLiteral("1920x1200"); | ||||
82 | QTest::newRow("1024x768") << QStringLiteral("1024x768") << QStringLiteral("1440x1080"); | ||||
83 | QTest::newRow("800x600") << QStringLiteral("800x600") << QStringLiteral("1440x1080"); | ||||
84 | QTest::newRow("848x480") << QStringLiteral("848x480") << QStringLiteral("1920x1080"); | ||||
85 | QTest::newRow("720x480") << QStringLiteral("720x480") << QStringLiteral("1920x1200"); | ||||
86 | QTest::newRow("640x480") << QStringLiteral("640x480") << QStringLiteral("1440x1080"); | ||||
87 | QTest::newRow("1366x768") << QStringLiteral("1366x768") << QStringLiteral("1920x1080"); | ||||
88 | QTest::newRow("1600x814") << QStringLiteral("1600x814") << QStringLiteral("1920x1080"); | ||||
89 | } | ||||
90 | | ||||
91 | void TestResolutions::testResolutions() | ||||
92 | { | ||||
93 | QFETCH(QString, resolution); | ||||
94 | QFETCH(QString, expected); | ||||
95 | | ||||
96 | m_image.setTargetSize( resSize( resolution ) ); | ||||
97 | QString preferred = m_image.findPreferedImage(m_images); | ||||
98 | | ||||
99 | qDebug() << "For a screen size of " << formatResolution(resolution) | ||||
100 | << " the " << formatResolution(preferred) << " wallpaper was preferred"; | ||||
101 | | ||||
102 | QCOMPARE(preferred, expected); | ||||
103 | } | ||||
104 | | ||||
105 | QTEST_MAIN(TestResolutions) | ||||
106 | #include "testfindpreferredimage.moc" |