1
/****************************************************************************
2
**
3
** Copyright (C) 2012 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
** GNU Lesser General Public License Usage
11
** This file may be used under the terms of the GNU Lesser General Public
12
** License version 2.1 as published by the Free Software Foundation and
13
** appearing in the file LICENSE.LGPL included in the packaging of this
14
** file. Please review the following information to ensure the GNU Lesser
15
** General Public License version 2.1 requirements will be met:
16
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17
**
18
** In addition, as a special exception, Nokia gives you certain additional
19
** rights. These rights are described in the Nokia Qt LGPL Exception
20
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21
**
22
** GNU General Public License Usage
23
** Alternatively, this file may be used under the terms of the GNU General
24
** Public License version 3.0 as published by the Free Software Foundation
25
** and appearing in the file LICENSE.GPL included in the packaging of this
26
** file. Please review the following information to ensure the GNU General
27
** Public License version 3.0 requirements will be met:
28
** http://www.gnu.org/copyleft/gpl.html.
29
**
30
** Other Usage
31
** Alternatively, this file may be used in accordance with the terms and
32
** conditions contained in a signed written agreement between you and Nokia.
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"