tests/qtp/qtp_wiggly/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 "dialog.h"
       
    44 #include "wigglywidget.h"
       
    45 #include "autotest.h"
       
    46 
       
    47 
       
    48 void autoTest::initTestCase()
       
    49 {
       
    50 }
       
    51 
       
    52 void autoTest::testDefaults()
       
    53 {
       
    54     Dialog dialog(0,false);
       
    55     dialog.show();
       
    56 
       
    57     // Test default values for widget properties
       
    58     //	QCOMPARE( dialog.acceptDrops(), false );
       
    59     //	QCOMPARE( dialog.hasEditFocus(), false );
       
    60     QCOMPARE( dialog.hasFocus(), false );
       
    61     QCOMPARE( dialog.hasMouseTracking(), false );
       
    62     QCOMPARE( dialog.isActiveWindow(), true );
       
    63     QCOMPARE( dialog.isEnabled(), true );
       
    64     QCOMPARE( dialog.isFullScreen(), false );
       
    65     QCOMPARE( dialog.isHidden(), false );
       
    66     QCOMPARE( dialog.isMaximized(), false );
       
    67     QCOMPARE( dialog.isMinimized(), false );
       
    68     QCOMPARE( dialog.isModal(), false );
       
    69     QCOMPARE( dialog.isVisible(), true );
       
    70     QCOMPARE( dialog.isWindow(), true );
       
    71     QCOMPARE( dialog.isWindowModified(), false );
       
    72     QCOMPARE( dialog.underMouse(), false );
       
    73     QCOMPARE( dialog.updatesEnabled(), true );
       
    74 
       
    75     dialog.hide();
       
    76 }
       
    77 
       
    78 void autoTest::testWigglyWidget()
       
    79 {
       
    80     Dialog dialog(0,false);
       
    81     dialog.show();
       
    82 
       
    83     QList<WigglyWidget *> subObjects = dialog.findChildren<WigglyWidget *>();
       
    84     QVERIFY( subObjects.count() == 1 );
       
    85     QWidget *wg = subObjects.at(0);
       
    86 
       
    87     QVERIFY( wg != 0 );
       
    88 
       
    89     // Some sanity checks for wiggle widget
       
    90     QVERIFY( wg->width() > 0 );
       
    91     QVERIFY( wg->height() > 0 );
       
    92 
       
    93     QVERIFY( wg->width() <= dialog.width() );
       
    94     QVERIFY( wg->height() <= dialog.height() );
       
    95 
       
    96     // but not much more to be verified here
       
    97 
       
    98     dialog.hide();
       
    99 }
       
   100 
       
   101 void autoTest::testInputWidget()
       
   102 {
       
   103     Dialog dialog(0,false);
       
   104     dialog.show();
       
   105 
       
   106     QList<QLineEdit *> editObjects = dialog.findChildren<QLineEdit *>();
       
   107     QVERIFY( editObjects.count() == 1 );
       
   108     QLineEdit *le = editObjects.at(0);
       
   109 
       
   110     QList<WigglyWidget *> subObjects = dialog.findChildren<WigglyWidget *>();
       
   111     QVERIFY( subObjects.count() == 1 );
       
   112     WigglyWidget *wg = subObjects.at(0);
       
   113 
       
   114     QVERIFY( le != 0 );
       
   115 
       
   116     // Some sanity checks for text input widget
       
   117     QVERIFY( le->width() > 0 );
       
   118     QVERIFY( le->height() > 0 );
       
   119 
       
   120     QVERIFY( le->width() <= dialog.width() );
       
   121     QVERIFY( le->height() <= dialog.height() );
       
   122 
       
   123     // Tests the generic behaviour of the line edit widget
       
   124     le->setFocus(Qt::OtherFocusReason);
       
   125 
       
   126     QTest::qWait(1000);
       
   127 
       
   128     QTest::keyClick ( le, Qt::Key_Backspace, Qt::NoModifier, 10 );
       
   129     QTest::keyClick ( le, Qt::Key_Backspace, Qt::NoModifier, 10 );
       
   130     QTest::keyClick ( le, Qt::Key_Backspace, Qt::NoModifier, 10 );
       
   131     QTest::keyClick ( le, Qt::Key_Backspace, Qt::NoModifier, 10 );
       
   132     QTest::keyClick ( le, Qt::Key_Backspace, Qt::NoModifier, 10 );
       
   133     QTest::keyClick ( le, Qt::Key_Backspace, Qt::NoModifier, 10 );
       
   134     QTest::keyClick ( le, Qt::Key_Backspace, Qt::NoModifier, 10 );
       
   135 
       
   136     QTest::keyClicks( le, "!!!" );
       
   137     le->clearFocus();
       
   138 
       
   139     // Verifies that edited line information is correctly copied
       
   140     QCOMPARE( le->text(), QString("Hello!!!") );
       
   141     QCOMPARE( le->text(), wg->getText() );
       
   142 
       
   143     QTest::qWait(1000);
       
   144 
       
   145     dialog.hide();
       
   146 }
       
   147