tests/auto/qdial/tst_qdial.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 #include <QDial>
       
    46 
       
    47 class tst_QDial : public QObject
       
    48 {
       
    49     Q_OBJECT
       
    50 public:
       
    51     tst_QDial();
       
    52 
       
    53 private slots:
       
    54     void getSetCheck();
       
    55     void valueChanged();
       
    56     void sliderMoved();
       
    57 };
       
    58 
       
    59 // Testing get/set functions
       
    60 void tst_QDial::getSetCheck()
       
    61 {
       
    62     QDial obj1;
       
    63     // bool QDial::notchesVisible()
       
    64     // void QDial::setNotchesVisible(bool)
       
    65     obj1.setNotchesVisible(false);
       
    66     QCOMPARE(false, obj1.notchesVisible());
       
    67     obj1.setNotchesVisible(true);
       
    68     QCOMPARE(true, obj1.notchesVisible());
       
    69 
       
    70     // bool QDial::wrapping()
       
    71     // void QDial::setWrapping(bool)
       
    72     obj1.setWrapping(false);
       
    73     QCOMPARE(false, obj1.wrapping());
       
    74     obj1.setWrapping(true);
       
    75     QCOMPARE(true, obj1.wrapping());
       
    76 }
       
    77 
       
    78 tst_QDial::tst_QDial()
       
    79 {
       
    80 }
       
    81 
       
    82 void tst_QDial::valueChanged()
       
    83 {
       
    84     QDial dial;
       
    85     dial.setMinimum(0);
       
    86     dial.setMaximum(100);
       
    87     QSignalSpy spy(&dial, SIGNAL(valueChanged(int)));
       
    88     dial.setValue(50);
       
    89     QCOMPARE(spy.count(), 1);
       
    90     spy.clear();
       
    91     dial.setValue(25);
       
    92     QCOMPARE(spy.count(), 1);
       
    93     spy.clear();
       
    94     // repeat!
       
    95     dial.setValue(25);
       
    96     QCOMPARE(spy.count(), 0);
       
    97 }
       
    98 
       
    99 void tst_QDial::sliderMoved()
       
   100 {
       
   101     //this tests that when dragging the arrow that the sliderMoved signal is emitted
       
   102     //even if tracking is set to false
       
   103     QDial dial;
       
   104     dial.setTracking(false);
       
   105     dial.setMinimum(0);
       
   106     dial.setMaximum(100);
       
   107 
       
   108     dial.show();
       
   109 
       
   110     QPoint init(dial.width()/4, dial.height()/2);
       
   111 
       
   112     QMouseEvent pressevent(QEvent::MouseButtonPress, init,
       
   113         Qt::LeftButton, Qt::LeftButton, 0);
       
   114     qApp->sendEvent(&dial, &pressevent);
       
   115 
       
   116     QSignalSpy sliderspy(&dial, SIGNAL(sliderMoved(int)));
       
   117     QSignalSpy valuespy(&dial, SIGNAL(valueChanged(int)));
       
   118 
       
   119 
       
   120     { //move on top of the slider
       
   121         init = QPoint(dial.width()/2, dial.height()/4);
       
   122         QMouseEvent moveevent(QEvent::MouseMove, init,
       
   123             Qt::LeftButton, Qt::LeftButton, 0);
       
   124         qApp->sendEvent(&dial, &moveevent);
       
   125         QCOMPARE( sliderspy.count(), 1);
       
   126         QCOMPARE( valuespy.count(), 0);
       
   127     }
       
   128 
       
   129 
       
   130     { //move on the right of the slider
       
   131         init = QPoint(dial.width()*3/4, dial.height()/2);
       
   132         QMouseEvent moveevent(QEvent::MouseMove, init,
       
   133             Qt::LeftButton, Qt::LeftButton, 0);
       
   134         qApp->sendEvent(&dial, &moveevent);
       
   135         QCOMPARE( sliderspy.count(), 2);
       
   136         QCOMPARE( valuespy.count(), 0);
       
   137     }
       
   138 
       
   139     QMouseEvent releaseevent(QEvent::MouseButtonRelease, init,
       
   140         Qt::LeftButton, Qt::LeftButton, 0);
       
   141     qApp->sendEvent(&dial, &releaseevent);
       
   142     QCOMPARE( valuespy.count(), 1); // valuechanged signal should be called at this point
       
   143 
       
   144 }
       
   145 
       
   146 QTEST_MAIN(tst_QDial)
       
   147 #include "tst_qdial.moc"