tests/auto/qmultiscreen/tst_qmultiscreen.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 
       
    45 #ifdef Q_WS_QWS
       
    46 
       
    47 //TESTED_CLASS=
       
    48 //TESTED_FILES=
       
    49 
       
    50 #include <qdesktopwidget.h>
       
    51 #include <qscreen_qws.h>
       
    52 #include <qscreendriverfactory_qws.h>
       
    53 #include <qlabel.h>
       
    54 
       
    55 class tst_QMultiScreen : public QObject
       
    56 {
       
    57     Q_OBJECT
       
    58 
       
    59 public:
       
    60     tst_QMultiScreen() : screen(0), oldScreen(0) {}
       
    61     ~tst_QMultiScreen() {}
       
    62 
       
    63 private slots:
       
    64     void initTestCase();
       
    65     void cleanupTestCase();
       
    66     void widgetSetFixedSize();
       
    67     void grabWindow();
       
    68 
       
    69 private:
       
    70     QScreen *screen;
       
    71     QScreen *oldScreen;
       
    72 };
       
    73 
       
    74 void tst_QMultiScreen::cleanupTestCase()
       
    75 {
       
    76     screen->shutdownDevice();
       
    77     screen->disconnect();
       
    78     delete screen;
       
    79     screen = 0;
       
    80 
       
    81     qt_screen = oldScreen;
       
    82 }
       
    83 
       
    84 void tst_QMultiScreen::initTestCase()
       
    85 {
       
    86     oldScreen = qt_screen;
       
    87 
       
    88     QVERIFY(QScreenDriverFactory::keys().contains(QLatin1String("Multi")));
       
    89     QVERIFY(QScreenDriverFactory::keys().contains(QLatin1String("VNC")));
       
    90 
       
    91     const int id = 10;
       
    92     screen = QScreenDriverFactory::create("Multi", id);
       
    93     QVERIFY(screen);
       
    94     QVERIFY(screen->connect(QString("Multi: "
       
    95                                     "VNC:size=640x480:depth=32:offset=0,0:%1 "
       
    96                                     "VNC:size=640x480:depth=32:offset=640,0:%2 "
       
    97                                     "VNC:size=640x480:depth=16:offset=0,480:%3 "
       
    98                                     ":%4")
       
    99                             .arg(id+1).arg(id+2).arg(id+3).arg(id)));
       
   100     QVERIFY(screen->initDevice());
       
   101 
       
   102     QDesktopWidget desktop;
       
   103     QCOMPARE(desktop.numScreens(), 3);
       
   104 }
       
   105 
       
   106 void tst_QMultiScreen::widgetSetFixedSize()
       
   107 {
       
   108     QDesktopWidget desktop;
       
   109     QRect maxRect;
       
   110     for (int i = 0; i < desktop.numScreens(); ++i)
       
   111         maxRect |= desktop.availableGeometry(i);
       
   112 
       
   113     maxRect = maxRect.adjusted(50, 50, -50, -50);
       
   114 
       
   115     // make sure we can set a size larger than a single screen (task 166368)
       
   116     QWidget w;
       
   117     w.setFixedSize(maxRect.size());
       
   118     w.show();
       
   119     QApplication::processEvents();
       
   120     QCOMPARE(w.geometry().size(), maxRect.size());
       
   121 }
       
   122 
       
   123 void tst_QMultiScreen::grabWindow()
       
   124 {
       
   125     QDesktopWidget desktop;
       
   126 
       
   127     QVERIFY(desktop.numScreens() >= 2);
       
   128 
       
   129     const QRect r0 = desktop.availableGeometry(0).adjusted(50, 50, -50, -50);
       
   130     const QRect r1 = desktop.availableGeometry(1).adjusted(60, 60, -60, -60);
       
   131 
       
   132     QWidget w;
       
   133     w.setGeometry(r0);
       
   134     w.show();
       
   135 
       
   136     QLabel l("hi there");
       
   137     l.setGeometry(r1);
       
   138     l.show();
       
   139 
       
   140     QApplication::processEvents();
       
   141     QApplication::sendPostedEvents(); // workaround for glib event loop
       
   142     QVERIFY(desktop.screenNumber(&w) == 0);
       
   143     QVERIFY(desktop.screenNumber(&l) == 1);
       
   144 
       
   145     const QPixmap p0 = QPixmap::grabWindow(w.winId());
       
   146     const QPixmap p1 = QPixmap::grabWindow(l.winId());
       
   147 
       
   148 //     p0.save("w.png", "PNG");
       
   149 //     p1.save("l.png", "PNG");
       
   150     QCOMPARE(p0.size(), w.size());
       
   151     QCOMPARE(p1.size(), l.size());
       
   152 
       
   153     const QImage img0 = p0.toImage();
       
   154     const QImage img1 = p1.toImage();
       
   155 
       
   156 //     QPixmap::grabWidget(&w).toImage().convertToFormat(img0.format()).save("w_img.png", "PNG");
       
   157 //     QPixmap::grabWidget(&l).toImage().convertToFormat(img1.format()).save("l_img.png", "PNG");
       
   158 
       
   159     QImage::Format format = QImage::Format_RGB16;
       
   160     QCOMPARE(img0.convertToFormat(format),
       
   161              QPixmap::grabWidget(&w).toImage().convertToFormat(format));
       
   162     QCOMPARE(img1.convertToFormat(format),
       
   163              QPixmap::grabWidget(&l).toImage().convertToFormat(format));
       
   164 }
       
   165 
       
   166 QTEST_MAIN(tst_QMultiScreen)
       
   167 
       
   168 #include "tst_qmultiscreen.moc"
       
   169 
       
   170 #else // Q_WS_QWS
       
   171 QTEST_NOOP_MAIN
       
   172 #endif