tests/qtp/qtp_previewer/autotest.cpp
changeset 3 41300fa6a67c
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
       
     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 examples 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 "mainwindow.h"
       
    44 #include "autotest.h"
       
    45 
       
    46 
       
    47  class aboutThread : public QThread
       
    48  {
       
    49  public:
       
    50      void run();
       
    51      void setMainWindow(MainWindow *aPtr) { iPtr = aPtr; };
       
    52  private:
       
    53      MainWindow *iPtr;
       
    54 
       
    55  };
       
    56 
       
    57  void aboutThread::run()
       
    58  {
       
    59      qDebug() << "entered aboutThread";
       
    60         QTest::qWait(500);
       
    61         QList<QMessageBox *> allDialogs = iPtr->findChildren<QMessageBox *>();
       
    62         QVERIFY( !allDialogs.isEmpty() );
       
    63 
       
    64         QPushButton * okButton;
       
    65         QList<QPushButton *> allPButtons = allDialogs.at(0)->findChildren<QPushButton *>();
       
    66         QVERIFY( allPButtons.count() == 1 );
       
    67 
       
    68         okButton = allPButtons.at(0);
       
    69 
       
    70         QVERIFY(okButton);
       
    71         okButton->click();
       
    72 
       
    73      qDebug() << "exit aboutThread";
       
    74  }
       
    75 
       
    76  class openUrlThread : public QThread
       
    77  {
       
    78  public:
       
    79      void run();
       
    80      void setMainWindow(MainWindow *aPtr) { iPtr = aPtr; };
       
    81  private:
       
    82      MainWindow *iPtr;
       
    83 
       
    84  };
       
    85 
       
    86  void openUrlThread::run()
       
    87  {
       
    88         QTest::qWait(500);
       
    89         QList<QInputDialog *> allDialogs = iPtr->findChildren<QInputDialog *>();
       
    90         QVERIFY( allDialogs.count() == 1 );
       
    91 
       
    92         QPushButton * cancelButton;
       
    93         QPushButton * okButton;
       
    94         QList<QPushButton *> allPButtons = allDialogs.at(0)->findChildren<QPushButton *>();
       
    95         QVERIFY( allPButtons.count() == 2 );
       
    96 
       
    97         for ( int i = 0; i < allPButtons.count(); i++)
       
    98         {
       
    99             if ( allPButtons.at(i)->text() == QString("OK") )
       
   100             {
       
   101                 okButton = allPButtons.at(i);
       
   102             }
       
   103             else if ( allPButtons.at(i)->text() == QString("Cancel") )
       
   104             {
       
   105                 cancelButton = allPButtons.at(i);
       
   106             }
       
   107             else
       
   108             {
       
   109                 QFAIL("This test application does not handle localised texts!");
       
   110             }
       
   111         }
       
   112         QVERIFY(okButton);
       
   113         QVERIFY(cancelButton);
       
   114 
       
   115         QList<QLineEdit *> allLineEdits = allDialogs.at(0)->findChildren<QLineEdit *>();
       
   116         QVERIFY( allLineEdits.count() == 1 );
       
   117         QCOMPARE( allLineEdits.at(0)->text(), QString("http://") );
       
   118 
       
   119         QTest::qWait(100);
       
   120         allLineEdits.at(0)->setText(QString("http://www.google.fi"));
       
   121 
       
   122         QCOMPARE( allLineEdits.at(0)->text(), QString("http://www.google.fi") );
       
   123         QTest::qWait(100);
       
   124 
       
   125         cancelButton->click();
       
   126  }
       
   127 
       
   128 void autoTest::initTestCase()
       
   129 {
       
   130 }
       
   131 
       
   132 void autoTest::testDefaults()
       
   133 {
       
   134 	MainWindow mw;
       
   135 
       
   136 	mw.show();
       
   137 
       
   138 	// Test default values for widget properties
       
   139 //      QCOMPARE( mw.acceptDrops(), false );
       
   140 //	QCOMPARE( mw.hasEditFocus(), false );
       
   141 	QCOMPARE( mw.hasFocus(), false );
       
   142 	QCOMPARE( mw.hasMouseTracking(), false );
       
   143 	QCOMPARE( mw.isActiveWindow(), true );
       
   144 	QCOMPARE( mw.isEnabled(), true );
       
   145 	QCOMPARE( mw.isFullScreen(), false );
       
   146 	QCOMPARE( mw.isHidden(), false );
       
   147 	QCOMPARE( mw.isMaximized(), false );
       
   148 	QCOMPARE( mw.isMinimized(), false );
       
   149 	QCOMPARE( mw.isModal(), false );
       
   150 	QCOMPARE( mw.isVisible(), true );
       
   151 	QCOMPARE( mw.isWindow(), true );
       
   152 	QCOMPARE( mw.isWindowModified(), false );
       
   153 	QCOMPARE( mw.underMouse(), false );
       
   154 	QCOMPARE( mw.updatesEnabled(), true );
       
   155 	
       
   156 	mw.hide();
       
   157 }
       
   158 
       
   159 void autoTest::testMainWindow()
       
   160 {
       
   161         aboutThread executioner;
       
   162         openUrlThread disruptor;
       
   163         MainWindow mw;
       
   164         mw.show();
       
   165 
       
   166         QList<Previewer *> subObjects = mw.findChildren<Previewer *>();
       
   167         QVERIFY( subObjects.count() == 1 );
       
   168         Previewer *prev = subObjects.at(0);
       
   169 
       
   170 	QVERIFY( prev );
       
   171 
       
   172         // Menu items to be tested initiated
       
   173         QMenu *filemenu;
       
   174         QMenu *helpmenu;
       
   175         QList<QMenu *> menuObjects = mw.findChildren<QMenu *>();
       
   176         QVERIFY( menuObjects.count() == 2 );
       
   177 
       
   178         for ( int i = 0; i < menuObjects.count(); i++)
       
   179         {
       
   180             if ( menuObjects.at(i)->title() == QString("&File") )
       
   181             {
       
   182                 filemenu = menuObjects.at(i);
       
   183             }
       
   184             else if ( menuObjects.at(i)->title() == QString("&Help") )
       
   185             {
       
   186                 helpmenu = menuObjects.at(i);
       
   187             }
       
   188             else
       
   189             {
       
   190                 QFAIL("This test application does not handle localisated text items!");
       
   191             }
       
   192         }
       
   193 
       
   194         QVERIFY( filemenu );
       
   195         QVERIFY( !filemenu->isEmpty() );
       
   196         QCOMPARE( filemenu->title(), QString("&File") );
       
   197 
       
   198         QVERIFY( helpmenu );
       
   199         QVERIFY( !helpmenu->isEmpty() );
       
   200         QCOMPARE( helpmenu->title(), QString("&Help") );
       
   201 
       
   202         QAction *openUrl;
       
   203         QAction *about;
       
   204         QList<QAction *> actionObjects = mw.findChildren<QAction *>();
       
   205 
       
   206         QCOMPARE(actionObjects.count(), 9);
       
   207 
       
   208         for ( int i = 0; i < actionObjects.count(); i++)
       
   209         {
       
   210             if ( actionObjects.at(i)->text() == QString("&Open URL...") )
       
   211             {
       
   212                 openUrl = actionObjects.at(i);
       
   213             }
       
   214             else if ( actionObjects.at(i)->text() == QString("&About") )
       
   215             {
       
   216                 about = actionObjects.at(i);
       
   217             }
       
   218             else
       
   219             {
       
   220                 // no test actions for these QACTION items, yet
       
   221             }
       
   222         }
       
   223         QTest::qWait(1000);
       
   224 
       
   225 /*  this part doesn't work yet, investigation underway...
       
   226         filemenu->show();
       
   227         QTest::qWait(500);
       
   228 
       
   229         executioner.setMainWindow(&mw);
       
   230         executioner.start();
       
   231 
       
   232         about->trigger();
       
   233         QTest::qWait(3000);
       
   234 */
       
   235 
       
   236         filemenu->show();
       
   237         QTest::qWait(500);
       
   238 
       
   239         disruptor.setMainWindow(&mw);
       
   240         disruptor.start();
       
   241 
       
   242         openUrl->trigger();
       
   243         QTest::qWait(1000);
       
   244 
       
   245         mw.hide();
       
   246 }
       
   247 
       
   248 void autoTest::testPreviewer()
       
   249 {
       
   250 	MainWindow mw;
       
   251 
       
   252 	mw.show();
       
   253 
       
   254         // What to test here?
       
   255         QList<Previewer *> subObjects = mw.findChildren<Previewer *>();
       
   256         QVERIFY( subObjects.count() == 1 );
       
   257         Previewer *prev = subObjects.at(0);
       
   258 
       
   259 	QVERIFY( prev );
       
   260 
       
   261         mw.hide();
       
   262 }
       
   263