From 54610323e8998fccca4da289b12c1f2a3836fccc Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Wed, 4 Sep 2013 16:47:41 +0200 Subject: Add tst_QWinTaskbarProgress Change-Id: I4ba748561aef6597762f52d458e951112255f0de Reviewed-by: Friedemann Kleint --- tests/auto/auto.pro | 3 +- .../qwintaskbarprogress/qwintaskbarprogress.pro | 4 + .../tst_qwintaskbarprogress.cpp | 199 +++++++++++++++++++++ 3 files changed, 205 insertions(+), 1 deletion(-) create mode 100644 tests/auto/qwintaskbarprogress/qwintaskbarprogress.pro create mode 100644 tests/auto/qwintaskbarprogress/tst_qwintaskbarprogress.cpp (limited to 'tests') diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 3cab631..1a871c6 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -4,4 +4,5 @@ SUBDIRS += \ cmake \ qwinthumbnailtoolbar \ qpixmap \ - qwintaskbarbutton + qwintaskbarbutton \ + qwintaskbarprogress diff --git a/tests/auto/qwintaskbarprogress/qwintaskbarprogress.pro b/tests/auto/qwintaskbarprogress/qwintaskbarprogress.pro new file mode 100644 index 0000000..76b5697 --- /dev/null +++ b/tests/auto/qwintaskbarprogress/qwintaskbarprogress.pro @@ -0,0 +1,4 @@ +CONFIG += testcase +TARGET = tst_qwintaskbarprogress +QT += testlib winextras +SOURCES += tst_qwintaskbarprogress.cpp diff --git a/tests/auto/qwintaskbarprogress/tst_qwintaskbarprogress.cpp b/tests/auto/qwintaskbarprogress/tst_qwintaskbarprogress.cpp new file mode 100644 index 0000000..aa88276 --- /dev/null +++ b/tests/auto/qwintaskbarprogress/tst_qwintaskbarprogress.cpp @@ -0,0 +1,199 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include + +class tst_QWinTaskbarProgress : public QObject +{ + Q_OBJECT + +private slots: + void testValue(); + void testRange(); + void testPause(); + void testVisibility(); +}; + +void tst_QWinTaskbarProgress::testValue() +{ + QWinTaskbarButton btn; + QWinTaskbarProgress *progress = btn.progress(); + QVERIFY(progress); + QCOMPARE(progress->value(), 0); + QCOMPARE(progress->minimum(), 0); + QCOMPARE(progress->maximum(), 100); + + QSignalSpy valueSpy(progress, SIGNAL(valueChanged(int))); + QVERIFY(valueSpy.isValid()); + + progress->setValue(25); + QCOMPARE(progress->value(), 25); + QCOMPARE(valueSpy.count(), 1); + QCOMPARE(valueSpy.last().at(0).toInt(), 25); + + // under valid range -> no effect + progress->setValue(-50); + QCOMPARE(progress->value(), 25); + QCOMPARE(valueSpy.count(), 1); + + progress->setValue(75); + QCOMPARE(progress->value(), 75); + QCOMPARE(valueSpy.count(), 2); + QCOMPARE(valueSpy.last().at(0).toInt(), 75); + + // over valid range -> no effect + progress->setValue(150); + QCOMPARE(progress->value(), 75); + QCOMPARE(valueSpy.count(), 2); +} + +void tst_QWinTaskbarProgress::testRange() +{ + QWinTaskbarButton btn; + QWinTaskbarProgress *progress = btn.progress(); + QVERIFY(progress); + QCOMPARE(progress->value(), 0); + QCOMPARE(progress->minimum(), 0); + QCOMPARE(progress->maximum(), 100); + + QSignalSpy valueSpy(progress, SIGNAL(valueChanged(int))); + QSignalSpy minimumSpy(progress, SIGNAL(minimumChanged(int))); + QSignalSpy maximumSpy(progress, SIGNAL(maximumChanged(int))); + QVERIFY(valueSpy.isValid()); + QVERIFY(minimumSpy.isValid()); + QVERIFY(maximumSpy.isValid()); + + // value must remain intact + progress->setValue(50); + QCOMPARE(valueSpy.count(), 1); + + progress->setMinimum(25); + QCOMPARE(progress->minimum(), 25); + QCOMPARE(minimumSpy.count(), 1); + QCOMPARE(minimumSpy.last().at(0).toInt(), 25); + + progress->setMaximum(75); + QCOMPARE(progress->maximum(), 75); + QCOMPARE(maximumSpy.count(), 1); + QCOMPARE(maximumSpy.last().at(0).toInt(), 75); + + QCOMPARE(progress->value(), 50); + QCOMPARE(valueSpy.count(), 1); + + // value under valid range -> reset + progress->setMinimum(55); + QCOMPARE(progress->value(), 55); + QCOMPARE(progress->minimum(), 55); + QCOMPARE(valueSpy.count(), 2); + QCOMPARE(valueSpy.last().at(0).toInt(), 55); + QCOMPARE(minimumSpy.count(), 2); + QCOMPARE(minimumSpy.last().at(0).toInt(), 55); + + progress->setValue(70); + QCOMPARE(valueSpy.count(), 3); + + // value over valid range -> reset + progress->setMaximum(65); + QCOMPARE(progress->value(), 55); + QCOMPARE(progress->maximum(), 65); + QCOMPARE(valueSpy.count(), 4); + QCOMPARE(valueSpy.last().at(0).toInt(), 55); + QCOMPARE(maximumSpy.count(), 2); + QCOMPARE(maximumSpy.last().at(0).toInt(), 65); +} + +void tst_QWinTaskbarProgress::testPause() +{ + QWinTaskbarButton btn; + QWinTaskbarProgress *progress = btn.progress(); + QVERIFY(progress); + QVERIFY(!progress->isPaused()); + + QSignalSpy pausedSpy(progress, SIGNAL(pausedChanged(bool))); + QVERIFY(pausedSpy.isValid()); + + progress->setPaused(true); + QVERIFY(progress->isPaused()); + QCOMPARE(pausedSpy.count(), 1); + QCOMPARE(pausedSpy.last().at(0).toBool(), true); + + progress->setPaused(false); + QVERIFY(!progress->isPaused()); + QCOMPARE(pausedSpy.count(), 2); + QCOMPARE(pausedSpy.last().at(0).toBool(), false); + + progress->pause(); + QVERIFY(progress->isPaused()); + QCOMPARE(pausedSpy.count(), 3); + QCOMPARE(pausedSpy.last().at(0).toBool(), true); + + progress->resume(); + QVERIFY(!progress->isPaused()); + QCOMPARE(pausedSpy.count(), 4); + QCOMPARE(pausedSpy.last().at(0).toBool(), false); +} + +void tst_QWinTaskbarProgress::testVisibility() +{ + QWinTaskbarButton btn; + QWinTaskbarProgress *progress = btn.progress(); + QVERIFY(progress); + QVERIFY(!progress->isVisible()); + + QSignalSpy visibleSpy(progress, SIGNAL(visibilityChanged(bool))); + QVERIFY(visibleSpy.isValid()); + + progress->setVisible(true); + QVERIFY(progress->isVisible()); + QCOMPARE(visibleSpy.count(), 1); + QCOMPARE(visibleSpy.last().at(0).toBool(), true); + + progress->setVisible(false); + QVERIFY(!progress->isVisible()); + QCOMPARE(visibleSpy.count(), 2); + QCOMPARE(visibleSpy.last().at(0).toBool(), false); +} + +QTEST_MAIN(tst_QWinTaskbarProgress) + +#include "tst_qwintaskbarprogress.moc" -- cgit v1.2.3