tests/auto/q3dateedit/tst_q3dateedit.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 <q3datetimeedit.h>
       
    46 #include <qapplication.h>
       
    47 #include <qgroupbox.h>
       
    48 
       
    49 //TESTED_CLASS=
       
    50 //TESTED_FILES=qt3support/widgets/q3action.h qt3support/widgets/q3action.cpp
       
    51 
       
    52 class tst_Q3DateEdit : public QObject
       
    53 {
       
    54     Q_OBJECT
       
    55 
       
    56 public:
       
    57     tst_Q3DateEdit();
       
    58     virtual ~tst_Q3DateEdit();
       
    59 
       
    60 
       
    61 
       
    62 public slots:
       
    63     void initTestCase();
       
    64     void init();
       
    65     void cleanup();
       
    66 private slots:
       
    67     void enabledPropagation();
       
    68 
       
    69 private:
       
    70     Q3DateEdit* testWidget;
       
    71 };
       
    72 
       
    73 tst_Q3DateEdit::tst_Q3DateEdit()
       
    74 {
       
    75 }
       
    76 
       
    77 tst_Q3DateEdit::~tst_Q3DateEdit()
       
    78 {
       
    79 
       
    80 }
       
    81 
       
    82 void tst_Q3DateEdit::initTestCase()
       
    83 {
       
    84     testWidget = new Q3DateEdit( 0, "testWidget" );
       
    85     testWidget->show();
       
    86     qApp->setActiveWindow(testWidget);
       
    87     qApp->setMainWidget( testWidget );
       
    88     QTest::qWait(100);
       
    89 }
       
    90 
       
    91 void tst_Q3DateEdit::init()
       
    92 {
       
    93 }
       
    94 
       
    95 void tst_Q3DateEdit::cleanup()
       
    96 {
       
    97 }
       
    98 
       
    99 
       
   100 void tst_Q3DateEdit::enabledPropagation()
       
   101 {
       
   102     // Check a QDateEdit on its own
       
   103     testWidget->setEnabled(TRUE);
       
   104     QVERIFY(testWidget->isEnabled());
       
   105     testWidget->setEnabled(FALSE);
       
   106     QVERIFY(!testWidget->isEnabled());
       
   107     testWidget->setEnabled(TRUE);
       
   108     QVERIFY(testWidget->isEnabled());
       
   109 
       
   110     // Now check a QDateEdit on a QWidget
       
   111     QWidget w;
       
   112     Q3DateEdit *childOfW = new Q3DateEdit(&w, "childOfW");
       
   113     w.show();
       
   114     QVERIFY(childOfW->isEnabled());
       
   115     QObjectList children = childOfW->children();
       
   116     int i;
       
   117     for (i = 0; i < children.count(); ++i) {
       
   118         if (children.at(i)->isWidgetType())
       
   119 	    QVERIFY(static_cast<QWidget *>(children.at(i))->isEnabled());
       
   120     }
       
   121     w.setEnabled(FALSE);
       
   122     QVERIFY(!childOfW->isEnabled());
       
   123     for (i = 0; i < children.count(); ++i) {
       
   124         if (children.at(i)->isWidgetType())
       
   125 	    QVERIFY(!static_cast<QWidget *>(children.at(i))->isEnabled());
       
   126     }
       
   127     w.setEnabled(TRUE);
       
   128     QVERIFY(childOfW->isEnabled());
       
   129     for (i = 0; i < children.count(); ++i) {
       
   130         if (children.at(i)->isWidgetType())
       
   131 	    QVERIFY(static_cast<QWidget *>(children.at(i))->isEnabled());
       
   132     }
       
   133 
       
   134     // Now check a QDateEdit on a non-checkable QGroupBox
       
   135     QGroupBox *gb = new QGroupBox(&w, "nonCheckGroupBox");
       
   136     Q3DateEdit *childOfGB = new Q3DateEdit(gb, "childOfGB");
       
   137     gb->show();
       
   138     QVERIFY(childOfGB->isEnabled());
       
   139     children = childOfGB->children();
       
   140     for (i = 0; i < children.count(); ++i) {
       
   141         if (children.at(i)->isWidgetType())
       
   142 	    QVERIFY(static_cast<QWidget *>(children.at(i))->isEnabled());
       
   143     }
       
   144 
       
   145     gb->setEnabled(FALSE);
       
   146     QVERIFY(!childOfGB->isEnabled());
       
   147     for (i = 0; i < children.count(); ++i) {
       
   148         if (children.at(i)->isWidgetType())
       
   149 	    QVERIFY(!static_cast<QWidget *>(children.at(i))->isEnabled());
       
   150     }
       
   151     gb->setEnabled(TRUE);
       
   152     QVERIFY(childOfGB->isEnabled());
       
   153     for (i = 0; i < children.count(); ++i) {
       
   154         if (children.at(i)->isWidgetType())
       
   155 	    QVERIFY(static_cast<QWidget *>(children.at(i))->isEnabled());
       
   156     }
       
   157 
       
   158     // Now check a QDateEdit on a checkable QGroupBox
       
   159     QGroupBox *cgb = new QGroupBox(&w, "checkGroupBox");
       
   160     cgb->setCheckable(TRUE);
       
   161     Q3DateEdit *childOfCGB = new Q3DateEdit(cgb, "childOfCGB");
       
   162     cgb->show();
       
   163     QVERIFY(childOfCGB->isEnabled());
       
   164     children = childOfCGB->children();
       
   165     for (i = 0; i < children.count(); ++i) {
       
   166         if (children.at(i)->isWidgetType())
       
   167 	    QVERIFY(static_cast<QWidget *>(children.at(i))->isEnabled());
       
   168     }
       
   169     cgb->setChecked(FALSE);
       
   170     QVERIFY(!childOfCGB->isEnabled());
       
   171     for (i = 0; i < children.count(); ++i) {
       
   172         if (children.at(i)->isWidgetType())
       
   173 	    QVERIFY(!static_cast<QWidget *>(children.at(i))->isEnabled());
       
   174     }
       
   175     cgb->setChecked(TRUE);
       
   176     QVERIFY(childOfCGB->isEnabled());
       
   177     for (i = 0; i < children.count(); ++i) {
       
   178         if (children.at(i)->isWidgetType())
       
   179 	    QVERIFY(static_cast<QWidget *>(children.at(i))->isEnabled());
       
   180     }
       
   181 }
       
   182 
       
   183 
       
   184 QTEST_MAIN(tst_Q3DateEdit)
       
   185 #include "tst_q3dateedit.moc"
       
   186