kwin/autotests/onscreennotificationtest.cpp
Vlad Zahorodnii 7fffe99328 build: Add -Wno-unused-parameter compiler option
Due to being a compositor, kwin has to conform to some certain
interfaces. It means a lot of virtual functions and function tables to
integrate with C APIs. Naturally, we not always want to use every
argument in such functions.

Since we get -Wunused-parameter from -Wall, we have to plumb those
unused arguments in order to suppress compiler warnings at the moment.

However, I don't think that extra work is worth it. We cannot change or
alter prototypes in any way to fix the warning the desired way. Q_UNUSED
and similar macros are not good indicators of whether an argument is
used too, we tend to overlook putting or removing those macros. I've
also noticed that Q_UNUSED are not used to guide us with the removal no
longer needed parameters.

Therefore, I think it's worth adding -Wno-unused-parameter compiler
option to stop the compiler producing warnings about unused parameters.
It changes nothing except that we don't need to put Q_UNUSED anymore,
which can be really cumbersome sometimes. Note that it doesn't affect
unused variables, you'll still get a -Wunused-variable compiler warning
if a variable is unused.
2022-10-31 15:50:37 +00:00

122 lines
3.8 KiB
C++

/*
SPDX-FileCopyrightText: 2016 Martin Graesslin <mgraesslin@kde.org>
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
#include "onscreennotificationtest.h"
#include "input.h"
#include "onscreennotification.h"
#include <KConfigGroup>
#include <KSharedConfig>
#include <QQmlEngine>
#include <QSignalSpy>
#include <QTest>
QTEST_MAIN(OnScreenNotificationTest);
namespace KWin
{
void InputRedirection::installInputEventSpy(InputEventSpy *spy)
{
}
void InputRedirection::uninstallInputEventSpy(InputEventSpy *spy)
{
}
InputRedirection *InputRedirection::s_self = nullptr;
}
using KWin::OnScreenNotification;
void OnScreenNotificationTest::show()
{
OnScreenNotification notification;
auto config = KSharedConfig::openConfig(QString(), KSharedConfig::SimpleConfig);
KConfigGroup group = config->group("OnScreenNotification");
group.writeEntry(QStringLiteral("QmlPath"), QString("/does/not/exist.qml"));
group.sync();
notification.setConfig(config);
notification.setEngine(new QQmlEngine(&notification));
notification.setMessage(QStringLiteral("Some text so that we see it in the test"));
QSignalSpy visibleChangedSpy(&notification, &OnScreenNotification::visibleChanged);
QCOMPARE(notification.isVisible(), false);
notification.setVisible(true);
QCOMPARE(notification.isVisible(), true);
QCOMPARE(visibleChangedSpy.count(), 1);
// show again should not trigger
notification.setVisible(true);
QCOMPARE(visibleChangedSpy.count(), 1);
// timer should not have hidden
QTest::qWait(500);
QCOMPARE(notification.isVisible(), true);
// hide again
notification.setVisible(false);
QCOMPARE(notification.isVisible(), false);
QCOMPARE(visibleChangedSpy.count(), 2);
// now show with timer
notification.setTimeout(250);
notification.setVisible(true);
QCOMPARE(notification.isVisible(), true);
QCOMPARE(visibleChangedSpy.count(), 3);
QVERIFY(visibleChangedSpy.wait());
QCOMPARE(notification.isVisible(), false);
QCOMPARE(visibleChangedSpy.count(), 4);
}
void OnScreenNotificationTest::timeout()
{
OnScreenNotification notification;
QSignalSpy timeoutChangedSpy(&notification, &OnScreenNotification::timeoutChanged);
QCOMPARE(notification.timeout(), 0);
notification.setTimeout(1000);
QCOMPARE(notification.timeout(), 1000);
QCOMPARE(timeoutChangedSpy.count(), 1);
notification.setTimeout(1000);
QCOMPARE(timeoutChangedSpy.count(), 1);
notification.setTimeout(0);
QCOMPARE(notification.timeout(), 0);
QCOMPARE(timeoutChangedSpy.count(), 2);
}
void OnScreenNotificationTest::iconName()
{
OnScreenNotification notification;
QSignalSpy iconNameChangedSpy(&notification, &OnScreenNotification::iconNameChanged);
QCOMPARE(notification.iconName(), QString());
notification.setIconName(QStringLiteral("foo"));
QCOMPARE(notification.iconName(), QStringLiteral("foo"));
QCOMPARE(iconNameChangedSpy.count(), 1);
notification.setIconName(QStringLiteral("foo"));
QCOMPARE(iconNameChangedSpy.count(), 1);
notification.setIconName(QStringLiteral("bar"));
QCOMPARE(notification.iconName(), QStringLiteral("bar"));
QCOMPARE(iconNameChangedSpy.count(), 2);
}
void OnScreenNotificationTest::message()
{
OnScreenNotification notification;
QSignalSpy messageChangedSpy(&notification, &OnScreenNotification::messageChanged);
QCOMPARE(notification.message(), QString());
notification.setMessage(QStringLiteral("foo"));
QCOMPARE(notification.message(), QStringLiteral("foo"));
QCOMPARE(messageChangedSpy.count(), 1);
notification.setMessage(QStringLiteral("foo"));
QCOMPARE(messageChangedSpy.count(), 1);
notification.setMessage(QStringLiteral("bar"));
QCOMPARE(notification.message(), QStringLiteral("bar"));
QCOMPARE(messageChangedSpy.count(), 2);
}