summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/widgets/qcheckbox/tst_qcheckbox.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/widgets/widgets/qcheckbox/tst_qcheckbox.cpp')
-rw-r--r--tests/auto/widgets/widgets/qcheckbox/tst_qcheckbox.cpp96
1 files changed, 55 insertions, 41 deletions
diff --git a/tests/auto/widgets/widgets/qcheckbox/tst_qcheckbox.cpp b/tests/auto/widgets/widgets/qcheckbox/tst_qcheckbox.cpp
index 33fb6b482a..42eb81d3c7 100644
--- a/tests/auto/widgets/widgets/qcheckbox/tst_qcheckbox.cpp
+++ b/tests/auto/widgets/widgets/qcheckbox/tst_qcheckbox.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -41,6 +16,7 @@ private slots:
void initTestCase();
void setChecked();
+ void setCheckedSignal();
void setTriState();
void setText_data();
void setText();
@@ -50,7 +26,7 @@ private slots:
void toggle();
void pressed();
void toggled();
- void stateChanged();
+ void checkStateChanged();
void foregroundRole();
void minimumSizeHint();
};
@@ -84,6 +60,25 @@ void tst_QCheckBox::setChecked()
QVERIFY(!testWidget.isChecked());
}
+void tst_QCheckBox::setCheckedSignal()
+{
+ QCheckBox testWidget;
+ testWidget.setCheckState(Qt::Unchecked);
+ QSignalSpy checkStateChangedSpy(&testWidget, &QCheckBox::checkStateChanged);
+ testWidget.setCheckState(Qt::Checked);
+ testWidget.setCheckState(Qt::Checked);
+ QTRY_COMPARE(checkStateChangedSpy.size(), 1); // get signal only once
+ QCOMPARE(testWidget.checkState(), Qt::Checked);
+ testWidget.setCheckState(Qt::Unchecked);
+ testWidget.setCheckState(Qt::Unchecked);
+ QTRY_COMPARE(checkStateChangedSpy.size(), 2); // get signal only once
+ QCOMPARE(testWidget.checkState(), Qt::Unchecked);
+ testWidget.setCheckState(Qt::PartiallyChecked);
+ testWidget.setCheckState(Qt::PartiallyChecked);
+ QTRY_COMPARE(checkStateChangedSpy.size(), 3); // get signal only once
+ QCOMPARE(testWidget.checkState(), Qt::PartiallyChecked);
+}
+
void tst_QCheckBox::setTriState()
{
QCheckBox testWidget;
@@ -213,30 +208,49 @@ void tst_QCheckBox::toggled()
QCOMPARE(click_count, 0);
}
-void tst_QCheckBox::stateChanged()
+void tst_QCheckBox::checkStateChanged()
{
QCheckBox testWidget;
- int cur_state = -1;
+ QCOMPARE(testWidget.checkState(), Qt::Unchecked);
+
+ Qt::CheckState cur_state = Qt::Unchecked;
+ QSignalSpy checkStateChangedSpy(&testWidget, &QCheckBox::checkStateChanged);
+#if QT_DEPRECATED_SINCE(6, 9)
+ QT_IGNORE_DEPRECATIONS(
QSignalSpy stateChangedSpy(&testWidget, &QCheckBox::stateChanged);
- connect(&testWidget, &QCheckBox::stateChanged, this, [&](int state) { ++cur_state = state; });
+ )
+#endif
+ connect(&testWidget, &QCheckBox::checkStateChanged, this, [&](auto state) { cur_state = state; });
testWidget.setChecked(true);
- QCoreApplication::processEvents();
- QCOMPARE(cur_state, 2);
+ QTRY_COMPARE(checkStateChangedSpy.size(), 1);
+#if QT_DEPRECATED_SINCE(6, 9)
+ QCOMPARE(stateChangedSpy.size(), 1);
+#endif
+ QCOMPARE(cur_state, Qt::Checked);
+ QCOMPARE(testWidget.checkState(), Qt::Checked);
- cur_state = -1;
testWidget.setChecked(false);
- QCoreApplication::processEvents();
- QCOMPARE(cur_state, 0);
+ QTRY_COMPARE(checkStateChangedSpy.size(), 2);
+#if QT_DEPRECATED_SINCE(6, 9)
+ QCOMPARE(stateChangedSpy.size(), 2);
+#endif
+ QCOMPARE(cur_state, Qt::Unchecked);
+ QCOMPARE(testWidget.checkState(), Qt::Unchecked);
- cur_state = -1;
testWidget.setCheckState(Qt::PartiallyChecked);
- QCoreApplication::processEvents();
- QCOMPARE(cur_state, 1);
+ QTRY_COMPARE(checkStateChangedSpy.size(), 3);
+#if QT_DEPRECATED_SINCE(6, 9)
+ QCOMPARE(stateChangedSpy.size(), 3);
+#endif
+ QCOMPARE(cur_state, Qt::PartiallyChecked);
+ QCOMPARE(testWidget.checkState(), Qt::PartiallyChecked);
- QCOMPARE(stateChangedSpy.count(), 3);
testWidget.setCheckState(Qt::PartiallyChecked);
QCoreApplication::processEvents();
- QCOMPARE(stateChangedSpy.count(), 3);
+ QCOMPARE(checkStateChangedSpy.size(), 3);
+#if QT_DEPRECATED_SINCE(6, 9)
+ QCOMPARE(stateChangedSpy.size(), 3);
+#endif
}
void tst_QCheckBox::isToggleButton()