tests/auto/qdesktopwidget/tst_qdesktopwidget.cpp
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the test suite of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 
       
    43 #include <QtTest/QtTest>
       
    44 #include <QtGui/QDesktopWidget>
       
    45 #include <QDebug>
       
    46 
       
    47 //TESTED_CLASS=
       
    48 
       
    49 class tst_QDesktopWidget : public QObject
       
    50 {
       
    51     Q_OBJECT
       
    52 
       
    53 public:
       
    54     tst_QDesktopWidget();
       
    55     virtual ~tst_QDesktopWidget();
       
    56 
       
    57 public slots:
       
    58     void init();
       
    59     void cleanup();
       
    60 
       
    61 private slots:
       
    62     void numScreens();
       
    63     void primaryScreen();
       
    64     void screenNumberForQWidget();
       
    65     void screenNumberForQPoint();
       
    66     void availableGeometry();
       
    67 };
       
    68 
       
    69 tst_QDesktopWidget::tst_QDesktopWidget()
       
    70 {
       
    71 }
       
    72 
       
    73 tst_QDesktopWidget::~tst_QDesktopWidget()
       
    74 {
       
    75 }
       
    76 
       
    77 void tst_QDesktopWidget::init()
       
    78 {
       
    79 }
       
    80 
       
    81 void tst_QDesktopWidget::cleanup()
       
    82 {
       
    83 }
       
    84 
       
    85 void tst_QDesktopWidget::numScreens()
       
    86 {
       
    87     QDesktopWidget desktop;
       
    88     QVERIFY(desktop.numScreens() > 0);
       
    89 }
       
    90 
       
    91 void tst_QDesktopWidget::primaryScreen()
       
    92 {
       
    93     QDesktopWidget desktop;
       
    94     QVERIFY(desktop.primaryScreen() >= 0);
       
    95     QVERIFY(desktop.primaryScreen() < desktop.numScreens());
       
    96 }
       
    97 
       
    98 void tst_QDesktopWidget::availableGeometry()
       
    99 {
       
   100     QDesktopWidget desktop;
       
   101 
       
   102     QRect total;
       
   103     QRect available;
       
   104 
       
   105     for (int i = 0; i < desktop.screenCount(); ++i) {
       
   106         total = desktop.screenGeometry(i);
       
   107         available = desktop.availableGeometry(i);
       
   108         QVERIFY(total.contains(available));
       
   109     }
       
   110 
       
   111     total = desktop.screenGeometry();
       
   112     available = desktop.availableGeometry();
       
   113     QVERIFY(total.contains(available));
       
   114     QCOMPARE(desktop.availableGeometry(desktop.primaryScreen()), available);
       
   115     QCOMPARE(desktop.screenGeometry(desktop.primaryScreen()), total);
       
   116 }
       
   117 
       
   118 void tst_QDesktopWidget::screenNumberForQWidget()
       
   119 {
       
   120     QDesktopWidget desktop;
       
   121 
       
   122     QCOMPARE(desktop.screenNumber(0), 0);
       
   123 
       
   124     QWidget widget;
       
   125     widget.show();
       
   126     QApplication::processEvents();
       
   127     QVERIFY(widget.isVisible());
       
   128 
       
   129     int widgetScreen = desktop.screenNumber(&widget);
       
   130     QVERIFY(widgetScreen > -1);
       
   131     QVERIFY(widgetScreen < desktop.numScreens());
       
   132 }
       
   133 
       
   134 void tst_QDesktopWidget::screenNumberForQPoint()
       
   135 {
       
   136     // make sure QDesktopWidget::screenNumber(QPoint) returns the correct screen
       
   137     QDesktopWidget *desktopWidget = QApplication::desktop();
       
   138     QRect allScreens;
       
   139     for (int i = 0; i < desktopWidget->numScreens(); ++i) {
       
   140         QRect screenGeometry = desktopWidget->screenGeometry(i);
       
   141         QCOMPARE(desktopWidget->screenNumber(screenGeometry.center()), i);
       
   142         allScreens |= screenGeometry;
       
   143     }
       
   144 
       
   145     // make sure QDesktopWidget::screenNumber(QPoint) returns a valid screen for points that aren't on any screen
       
   146     int screen;
       
   147     screen = desktopWidget->screenNumber(allScreens.topLeft() - QPoint(1, 1));
       
   148 
       
   149 #ifdef Q_WS_QWS
       
   150     QEXPECT_FAIL("", "Task 151710", Abort);
       
   151 #endif
       
   152     QVERIFY(screen >= 0 && screen < desktopWidget->numScreens());
       
   153     screen = desktopWidget->screenNumber(allScreens.topRight() + QPoint(1, 1));
       
   154     QVERIFY(screen >= 0 && screen < desktopWidget->numScreens());
       
   155     screen = desktopWidget->screenNumber(allScreens.bottomLeft() - QPoint(1, 1));
       
   156     QVERIFY(screen >= 0 && screen < desktopWidget->numScreens());
       
   157     screen = desktopWidget->screenNumber(allScreens.bottomRight() + QPoint(1, 1));
       
   158     QVERIFY(screen >= 0 && screen < desktopWidget->numScreens());
       
   159 }
       
   160 
       
   161 QTEST_MAIN(tst_QDesktopWidget)
       
   162 #include "tst_qdesktopwidget.moc"
       
   163