| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the test suite of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
| 21 | ** included in the packaging of this file. Please review the following |
| 22 | ** information to ensure the GNU General Public License requirements will |
| 23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
| 24 | ** |
| 25 | ** $QT_END_LICENSE$ |
| 26 | ** |
| 27 | ****************************************************************************/ |
| 28 | |
| 29 | #include <qtest.h> |
| 30 | #include <QDebug> |
| 31 | #include <QQmlEngine> |
| 32 | #include <QtQuick/QQuickItem> |
| 33 | #include <QtQuick/QQuickView> |
| 34 | #include <QtGui/QScreen> |
| 35 | #include "../../shared/util.h" |
| 36 | #include <QtQuick/private/qquickscreen_p.h> |
| 37 | #include <QDebug> |
| 38 | class tst_qquickscreen : public QQmlDataTest |
| 39 | { |
| 40 | Q_OBJECT |
| 41 | private slots: |
| 42 | void basicProperties(); |
| 43 | void screenOnStartup(); |
| 44 | void fullScreenList(); |
| 45 | }; |
| 46 | |
| 47 | void tst_qquickscreen::basicProperties() |
| 48 | { |
| 49 | QQuickView view; |
| 50 | view.setSource(testFileUrl(fileName: "screen.qml" )); |
| 51 | view.show(); |
| 52 | QVERIFY(QTest::qWaitForWindowExposed(&view)); |
| 53 | |
| 54 | QQuickItem* root = view.rootObject(); |
| 55 | QVERIFY(root); |
| 56 | |
| 57 | QScreen* screen = view.screen(); |
| 58 | QVERIFY(screen); |
| 59 | |
| 60 | QCOMPARE(screen->size().width(), root->property("w" ).toInt()); |
| 61 | QCOMPARE(screen->size().height(), root->property("h" ).toInt()); |
| 62 | QCOMPARE(int(screen->orientation()), root->property("curOrientation" ).toInt()); |
| 63 | QCOMPARE(int(screen->primaryOrientation()), root->property("priOrientation" ).toInt()); |
| 64 | QCOMPARE(int(screen->orientationUpdateMask()), root->property("updateMask" ).toInt()); |
| 65 | QCOMPARE(screen->devicePixelRatio(), root->property("devicePixelRatio" ).toReal()); |
| 66 | QVERIFY(screen->devicePixelRatio() >= 1.0); |
| 67 | QCOMPARE(screen->geometry().x(), root->property("vx" ).toInt()); |
| 68 | QCOMPARE(screen->geometry().y(), root->property("vy" ).toInt()); |
| 69 | |
| 70 | QVERIFY(root->property("screenCount" ).toInt() == QGuiApplication::screens().count()); |
| 71 | } |
| 72 | |
| 73 | void tst_qquickscreen::screenOnStartup() |
| 74 | { |
| 75 | // We expect QQuickScreen to fall back to the primary screen |
| 76 | QQmlEngine engine; |
| 77 | QQmlComponent component(&engine, testFileUrl(fileName: "screen.qml" )); |
| 78 | |
| 79 | QScopedPointer<QQuickItem> root(qobject_cast<QQuickItem*>(object: component.create())); |
| 80 | QVERIFY(root); |
| 81 | |
| 82 | QScreen* screen = QGuiApplication::primaryScreen(); |
| 83 | QVERIFY(screen); |
| 84 | |
| 85 | QCOMPARE(screen->size().width(), root->property("w" ).toInt()); |
| 86 | QCOMPARE(screen->size().height(), root->property("h" ).toInt()); |
| 87 | QCOMPARE(int(screen->orientation()), root->property("curOrientation" ).toInt()); |
| 88 | QCOMPARE(int(screen->primaryOrientation()), root->property("priOrientation" ).toInt()); |
| 89 | QCOMPARE(int(screen->orientationUpdateMask()), root->property("updateMask" ).toInt()); |
| 90 | QCOMPARE(screen->devicePixelRatio(), root->property("devicePixelRatio" ).toReal()); |
| 91 | QVERIFY(screen->devicePixelRatio() >= 1.0); |
| 92 | QCOMPARE(screen->geometry().x(), root->property("vx" ).toInt()); |
| 93 | QCOMPARE(screen->geometry().y(), root->property("vy" ).toInt()); |
| 94 | } |
| 95 | |
| 96 | void tst_qquickscreen::fullScreenList() |
| 97 | { |
| 98 | QQuickView view; |
| 99 | view.setSource(testFileUrl(fileName: "screen.qml" )); |
| 100 | view.show(); |
| 101 | QVERIFY(QTest::qWaitForWindowExposed(&view)); |
| 102 | |
| 103 | QQuickItem* root = view.rootObject(); |
| 104 | QVERIFY(root); |
| 105 | |
| 106 | QJSValue screensArray = root->property(name: "allScreens" ).value<QJSValue>(); |
| 107 | QVERIFY(screensArray.isArray()); |
| 108 | int length = screensArray.property(name: "length" ).toInt(); |
| 109 | const QList<QScreen *> screenList = QGuiApplication::screens(); |
| 110 | QVERIFY(length == screenList.count()); |
| 111 | |
| 112 | for (int i = 0; i < length; ++i) { |
| 113 | QQuickScreenInfo *info = qobject_cast<QQuickScreenInfo *>(object: screensArray.property(arrayIndex: i).toQObject()); |
| 114 | QVERIFY(info != nullptr); |
| 115 | QCOMPARE(screenList[i]->name(), info->name()); |
| 116 | QCOMPARE(screenList[i]->manufacturer(), info->manufacturer()); |
| 117 | QCOMPARE(screenList[i]->model(), info->model()); |
| 118 | QCOMPARE(screenList[i]->serialNumber(), info->serialNumber()); |
| 119 | QCOMPARE(screenList[i]->size().width(), info->width()); |
| 120 | QCOMPARE(screenList[i]->size().height(), info->height()); |
| 121 | QCOMPARE(screenList[i]->availableVirtualGeometry().width(), info->desktopAvailableWidth()); |
| 122 | QCOMPARE(screenList[i]->availableVirtualGeometry().height(), info->desktopAvailableHeight()); |
| 123 | QCOMPARE(screenList[i]->devicePixelRatio(), info->devicePixelRatio()); |
| 124 | QCOMPARE(screenList[i]->geometry().x(), info->virtualX()); |
| 125 | QCOMPARE(screenList[i]->geometry().y(), info->virtualY()); |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | QTEST_MAIN(tst_qquickscreen) |
| 130 | |
| 131 | #include "tst_qquickscreen.moc" |
| 132 | |