Skip to content

Commit

Permalink
[lipstick] Fix unit test failures. Fixes JB#52791
Browse files Browse the repository at this point in the history
  • Loading branch information
adenexter committed Mar 19, 2021
1 parent b1572fd commit d67ee41
Show file tree
Hide file tree
Showing 19 changed files with 84 additions and 177 deletions.
12 changes: 10 additions & 2 deletions src/compositor/lipstickcompositor.h
Expand Up @@ -16,12 +16,11 @@
#ifndef LIPSTICKCOMPOSITOR_H
#define LIPSTICKCOMPOSITOR_H

#include <QtCompositorVersion>

#include <QQuickWindow>
#include "lipstickglobal.h"
#include "homeapplication.h"
#include <QQmlParserStatus>
#include <QtCompositorVersion>
#if QTCOMPOSITOR_VERSION >= QT_VERSION_CHECK(5, 6, 0)
#include <QWaylandQuickOutput>
#endif
Expand All @@ -34,6 +33,11 @@
#include <QDBusContext>
#include <QDBusMessage>

#ifdef LIPSTICK_UNIT_TEST_STUB
#undef Q_DECL_OVERRIDE
#define Q_DECL_OVERRIDE
#endif

class WindowModel;
class LipstickCompositorWindow;
class LipstickCompositorProcWindow;
Expand Down Expand Up @@ -67,7 +71,9 @@ typedef QWaylandClient WaylandClient;

class LIPSTICK_EXPORT LipstickCompositor
: public QQuickWindow
#ifndef LIPSTICK_UNIT_TEST_STUB
, public QWaylandQuickCompositor
#endif
, public QQmlParserStatus
, public QDBusContext
{
Expand Down Expand Up @@ -231,8 +237,10 @@ private slots:

static LipstickCompositor *m_instance;

#ifndef LIPSTICK_UNIT_TEST_STUB
#if QTCOMPOSITOR_VERSION >= QT_VERSION_CHECK(5, 6, 0)
QWaylandQuickOutput m_output;
#endif
#endif

int m_totalWindowCount;
Expand Down
2 changes: 2 additions & 0 deletions src/notifications/lipsticknotification.cpp
Expand Up @@ -152,10 +152,12 @@ void LipstickNotification::setAppIcon(const QString &appIcon, int source)
bool sourceChanged = false;

if (appIcon != m_appIcon) {
iconChanged = true;
m_appIcon = appIcon;
}

if (source != m_appIconOrigin) {
sourceChanged = true;
m_appIconOrigin = source;
}

Expand Down
1 change: 1 addition & 0 deletions src/notifications/notificationpreviewpresenter.cpp
Expand Up @@ -34,6 +34,7 @@
#include <QDBusPendingCall>
#include <QGuiApplication>
#include <QQmlContext>
#include <QWaylandSurface>

namespace {

Expand Down
1 change: 0 additions & 1 deletion src/usbmodeselector.cpp
Expand Up @@ -18,7 +18,6 @@
#include <QQmlContext>
#include <QScreen>
#include <qusbmoded.h>
#include "homewindow.h"
#include "utilities/closeeventeater.h"
#include "notifications/notificationmanager.h"
#include "notifications/lipsticknotification.h"
Expand Down
4 changes: 2 additions & 2 deletions src/usbmodeselector.h
Expand Up @@ -21,7 +21,6 @@
#include <QStringList>
#include "lipstickglobal.h"

class HomeWindow;
class QUsbModed;

namespace NemoDeviceLock {
Expand Down Expand Up @@ -54,6 +53,7 @@ class LIPSTICK_EXPORT USBModeSelector : public QObject
Host,
Locked
};
Q_ENUM(Notification)

explicit USBModeSelector(NemoDeviceLock::DeviceLock *deviceLock, QObject *parent = 0);

Expand Down Expand Up @@ -128,7 +128,7 @@ class LIPSTICK_EXPORT USBModeSelector : public QObject
void preparingModeChanged(const QString &preparing);

//! Sent to request a mode notification be shown to the user.
void showNotification(Notification type);
void showNotification(USBModeSelector::Notification type);

//! Sent to request an error be displayed to the user.
void showError(const QString &errorCode);
Expand Down
22 changes: 0 additions & 22 deletions tests/stubs/lipstickcompositor_stub.h
Expand Up @@ -385,9 +385,6 @@ LipstickCompositorStub *gLipstickCompositorStub = &gDefaultLipstickCompositorStu

// 4. CREATE A PROXY WHICH CALLS THE STUB
LipstickCompositor::LipstickCompositor()
#if QTCOMPOSITOR_VERSION >= QT_VERSION_CHECK(5, 6, 0)
: m_output(this, this, QString(), QString())
#endif
{
gLipstickCompositorStub->LipstickCompositorConstructor();
}
Expand Down Expand Up @@ -630,23 +627,4 @@ void LipstickCompositor::processQueuedSetUpdatesEnabledCalls()
{
}

#if QTCOMPOSITOR_VERSION >= QT_VERSION_CHECK(5, 6, 0)
QWaylandQuickCompositor::QWaylandQuickCompositor(const char *, ExtensionFlags)
{
}

QWaylandOutput::QWaylandOutput(QWaylandCompositor *, QWindow *, const QString &, const QString &)
: d_ptr(nullptr)
{
}
#else
QWaylandCompositor::QWaylandCompositor(QWindow *, const char *, QWaylandCompositor::ExtensionFlags)
{
}

QWaylandQuickCompositor::QWaylandQuickCompositor(QQuickWindow *, const char *, QWaylandCompositor::ExtensionFlags)
{
}
#endif

#endif
3 changes: 1 addition & 2 deletions tests/ut_lipsticknotification/ut_lipsticknotification.cpp
Expand Up @@ -92,6 +92,7 @@ void Ut_Notification::testGettersAndSetters()
expireTimeout = 2;
notification.setAppName(appName);
notification.setDisambiguatedAppName(disambiguatedAppName);
notification.setAppIcon(appIcon);
notification.setSummary(summary);
notification.setBody(body);
notification.setActions(actions);
Expand Down Expand Up @@ -160,7 +161,6 @@ void Ut_Notification::testSignals()
LipstickNotification notification(QString(), QString(), QString(), 0, QString(), QString(), QString(), QStringList(), hints, 0);
QSignalSpy summarySpy(&notification, SIGNAL(summaryChanged()));
QSignalSpy bodySpy(&notification, SIGNAL(bodyChanged()));
QSignalSpy appIconSpy(&notification, SIGNAL(appIconChanged()));
QSignalSpy timestampSpy(&notification, SIGNAL(timestampChanged()));
QSignalSpy previewSummarySpy(&notification, SIGNAL(previewSummaryChanged()));
QSignalSpy previewBodySpy(&notification, SIGNAL(previewBodyChanged()));
Expand All @@ -178,7 +178,6 @@ void Ut_Notification::testSignals()

hints.insert(LipstickNotification::HINT_TIMESTAMP, "2012-10-01 18:04:19");
notification.setHints(hints);
QCOMPARE(appIconSpy.count(), 1);
QCOMPARE(timestampSpy.count(), 1);

notification.setHints(hints);
Expand Down
Expand Up @@ -20,6 +20,8 @@
#include "ngfclient_stub.h"
#include "ut_notificationfeedbackplayer.h"

#include <QWaylandSurface>

NotificationManager::NotificationManager(QObject *parent, bool owner) : QObject(parent)
{
Q_UNUSED(owner)
Expand Down Expand Up @@ -163,8 +165,9 @@ void Ut_NotificationFeedbackPlayer::testWithoutFeedbackId()
notification->setHints(QVariantHash());
player->addNotification(1);

// Check that NGFAdapter::play() was not called for the feedback
QCOMPARE(gClientStub->stubCallCount("play"), 0);
// Check that NGFAdapter::play() was called with the default feedback
QCOMPARE(gClientStub->stubCallCount("play"), 1);
QCOMPARE(gClientStub->stubLastCallTo("play").parameter<QString>(0), QString("default"));
}

void Ut_NotificationFeedbackPlayer::testMultipleFeedbackIds()
Expand Down Expand Up @@ -265,12 +268,12 @@ void Ut_NotificationFeedbackPlayer::testUpdateNotification()
notification->setHints(hints);
player->addNotification(1);

// Check that NGFAdapter::stop() was called again
QCOMPARE(gClientStub->stubCallCount("stop"), 6);
QCOMPARE(gClientStub->stubLastCallTo("stop").parameter<quint32>(0), 1u);
QCOMPARE(gClientStub->stubCallCount("play"), 4);
QCOMPARE(gClientStub->stubLastCallTo("play").parameter<QString>(0), QString("default"));

// Check that NGFAdapter::play() was not called again
QCOMPARE(gClientStub->stubCallCount("play"), 3);
// Check that NGFAdapter::stop() was called again
QCOMPARE(gClientStub->stubCallCount("stop"), 7);
QCOMPARE(gClientStub->stubLastCallTo("stop").parameter<QString>(0), QString("default"));
}

void Ut_NotificationFeedbackPlayer::testUpdateNotificationAfterRestart()
Expand Down
Expand Up @@ -2,8 +2,10 @@ include(../common.pri)
TARGET = ut_notificationfeedbackplayer
INCLUDEPATH += $$NOTIFICATIONSRCDIR $$COMPOSITORSRCDIR $$TOUCHSCREENSRCDIR /usr/include/ngf-qt5 $$DEVICESTATE
CONFIG += link_pkgconfig
QT += dbus compositor quick
DEFINES += QT_COMPOSITOR_QUICK
QT += dbus quick compositor

DEFINES += \
LIPSTICK_UNIT_TEST_STUB

HEADERS += \
ut_notificationfeedbackplayer.h \
Expand Down
8 changes: 4 additions & 4 deletions tests/ut_notificationlistmodel/ut_notificationlistmodel.cpp
Expand Up @@ -185,9 +185,7 @@ void Ut_NotificationListModel::testRemoteActions()
actions.append("Default Remote Action");
actions.append("alternate");
actions.append("Alternate Remote Action");
actions.append("invalid");
actions.append("Invalid Remote Action");
actions.append("also-invalid");

QVariantHash hints;
hints.insert(LipstickNotification::HINT_REMOTE_ACTION_PREFIX + QStringLiteral("default"), "dbus-call-default-action");
hints.insert(LipstickNotification::HINT_REMOTE_ACTION_ICON_PREFIX + QStringLiteral("default"), "icon-s-default");
Expand All @@ -202,11 +200,13 @@ void Ut_NotificationListModel::testRemoteActions()
QCOMPARE(modelNotification, &notification);
QVariantList remoteActions(modelNotification->remoteActions());
QCOMPARE(remoteActions.count(), 2);

QVariantMap remoteAction(remoteActions.at(0).value<QVariantMap>());
QCOMPARE(remoteAction["name"].toString(), QStringLiteral("default"));
QCOMPARE(remoteAction["displayName"].toString(), QStringLiteral("Default Remote Action"));
QCOMPARE(remoteAction["icon"].toString(), QStringLiteral("icon-s-default"));
remoteAction = remoteActions.at(1).value<QVariantMap>();;

remoteAction = remoteActions.at(1).value<QVariantMap>();
QCOMPARE(remoteAction["name"].toString(), QStringLiteral("alternate"));
QCOMPARE(remoteAction["displayName"].toString(), QStringLiteral("Alternate Remote Action"));
QCOMPARE(remoteAction["icon"].toString(), QString());
Expand Down
8 changes: 7 additions & 1 deletion tests/ut_notificationmanager/ut_notificationmanager.cpp
Expand Up @@ -58,7 +58,7 @@ void Ut_NotificationManager::testCapabilities()
{
// Check the supported capabilities includes all the Nemo hints
QStringList capabilities = NotificationManager::instance()->GetCapabilities();
QCOMPARE(capabilities.count(), 14);
QCOMPARE(capabilities.count(), 11);
QCOMPARE((bool)capabilities.contains("body"), true);
QCOMPARE((bool)capabilities.contains("actions"), true);
QCOMPARE((bool)capabilities.contains("persistence"), true);
Expand Down Expand Up @@ -135,6 +135,8 @@ void Ut_NotificationManager::testModifyingCategoryDefinitionUpdatesNotifications
// The updated notifications should be marked as restored until modified
QCOMPARE(manager->notification(id1)->restored(), false);
QCOMPARE(manager->notification(id2)->restored(), true);

manager->closeNotifications(manager->notificationIds());
}

void Ut_NotificationManager::testUninstallingCategoryDefinitionRemovesNotifications()
Expand All @@ -160,6 +162,8 @@ void Ut_NotificationManager::testUninstallingCategoryDefinitionRemovesNotificati
QCOMPARE(removedSpy.last().at(0).toUInt(), id2);
QVERIFY(manager->notification(id1) != 0);
QCOMPARE(manager->notification(id2), (LipstickNotification *)0);

manager->closeNotifications(manager->notificationIds());
}

void Ut_NotificationManager::testActionIsInvokedIfDefined()
Expand Down Expand Up @@ -302,6 +306,8 @@ void Ut_NotificationManager::testListingNotifications()
QCOMPARE(notifications.at(0).category(), QVariant("category3"));
QCOMPARE(notifications.at(0).expireTimeout(), 3);
#endif

manager->closeNotifications(manager->notificationIds());
}

void Ut_NotificationManager::testRemoveUserRemovableNotifications()
Expand Down
Expand Up @@ -35,6 +35,8 @@ Q_DECLARE_METATYPE(LipstickNotification*)

#include "homewindow.h"

#include <QWaylandSurface>

HomeWindow::HomeWindow()
{
}
Expand Down
Expand Up @@ -3,6 +3,9 @@ TARGET = ut_notificationpreviewpresenter
INCLUDEPATH += $$SRCDIR $$NOTIFICATIONSRCDIR $$UTILITYSRCDIR $$TOUCHSCREENSRCDIR $$SRCDIR/compositor $$DEVICESTATE $$SCREENLOCKSRCDIR
QT += qml quick dbus compositor

DEFINES += \
LIPSTICK_UNIT_TEST_STUB

# unit test and unit
SOURCES += \
ut_notificationpreviewpresenter.cpp \
Expand Down
5 changes: 2 additions & 3 deletions tests/ut_screenlock/ut_screenlock.cpp
Expand Up @@ -127,11 +127,10 @@ void Ut_ScreenLock::testToggleEventEater()

// Make sure the screen locking signals are sent and the eater UI is shown/hidden
screenLock->setEventEaterEnabled(true);
TouchScreen *touchScreen = HomeApplication::instance()->touchScreen();
QCOMPARE(touchScreen->eventFilter(0, &event), true);
QCOMPARE(gTouchScreen->eventFilter(0, &event), true);

screenLock->setEventEaterEnabled(false);
QCOMPARE(touchScreen->eventFilter(0, &event), false);
QCOMPARE(gTouchScreen->eventFilter(0, &event), false);
}

void Ut_ScreenLock::testUnlockScreenWhenLocked()
Expand Down
6 changes: 3 additions & 3 deletions tests/ut_shutdownscreen/ut_shutdownscreen.cpp
Expand Up @@ -95,19 +95,19 @@ void Ut_ShutdownScreen::testSystemState()
QCOMPARE(qQuickViews.count(), 0);
QCOMPARE(gNotificationManagerStub->stubCallCount("Notify"), 1);
QCOMPARE(gNotificationManagerStub->stubLastCallTo("Notify").parameter<QString>(4), qtTrId("qtn_shut_high_temp"));
QCOMPARE(gNotificationManagerStub->stubLastCallTo("Notify").parameter<QString>(2), QString());
QCOMPARE(gNotificationManagerStub->stubLastCallTo("Notify").parameter<QString>(2), QString("icon-system-warning"));

shutdownScreen->applySystemState(DeviceState::DeviceState::ShutdownDeniedUSB);
QCOMPARE(qQuickViews.count(), 0);
QCOMPARE(gNotificationManagerStub->stubCallCount("Notify"), 2);
QCOMPARE(gNotificationManagerStub->stubLastCallTo("Notify").parameter<QString>(4), qtTrId("qtn_shut_unplug_usb"));
QCOMPARE(gNotificationManagerStub->stubLastCallTo("Notify").parameter<QString>(2), QString());
QCOMPARE(gNotificationManagerStub->stubLastCallTo("Notify").parameter<QString>(2), QString("icon-system-usb"));

shutdownScreen->applySystemState(DeviceState::DeviceState::BatteryStateEmpty);
QCOMPARE(qQuickViews.count(), 0);
QCOMPARE(gNotificationManagerStub->stubCallCount("Notify"), 3);
QCOMPARE(gNotificationManagerStub->stubLastCallTo("Notify").parameter<QString>(4), qtTrId("qtn_shut_batt_empty"));
QCOMPARE(gNotificationManagerStub->stubLastCallTo("Notify").parameter<QString>(2), QString());
QCOMPARE(gNotificationManagerStub->stubLastCallTo("Notify").parameter<QString>(2), QString("icon-system-battery"));

shutdownScreen->applySystemState(DeviceState::DeviceState::Shutdown);
QCOMPARE(qQuickViews.count(), 1);
Expand Down
6 changes: 3 additions & 3 deletions tests/ut_thermalnotifier/ut_thermalnotifier.cpp
Expand Up @@ -72,17 +72,17 @@ void Ut_ThermalNotifier::testThermalState()
thermalNotifier->applyThermalState(DeviceState::Thermal::Warning);
QCOMPARE(gNotificationManagerStub->stubCallCount("Notify"), 1);
QCOMPARE(gNotificationManagerStub->stubLastCallTo("Notify").parameter<QString>(4), qtTrId("qtn_shut_high_temp_warning"));
QCOMPARE(gNotificationManagerStub->stubLastCallTo("Notify").parameter<QString>(2), QString());
QCOMPARE(gNotificationManagerStub->stubLastCallTo("Notify").parameter<QString>(2), QString("icon-system-warning"));

thermalNotifier->applyThermalState(DeviceState::Thermal::Alert);
QCOMPARE(gNotificationManagerStub->stubCallCount("Notify"), 2);
QCOMPARE(gNotificationManagerStub->stubLastCallTo("Notify").parameter<QString>(4), qtTrId("qtn_shut_high_temp_alert"));
QCOMPARE(gNotificationManagerStub->stubLastCallTo("Notify").parameter<QString>(2), QString());
QCOMPARE(gNotificationManagerStub->stubLastCallTo("Notify").parameter<QString>(2), QString("icon-system-warning"));

thermalNotifier->applyThermalState(DeviceState::Thermal::LowTemperatureWarning);
QCOMPARE(gNotificationManagerStub->stubCallCount("Notify"), 3);
QCOMPARE(gNotificationManagerStub->stubLastCallTo("Notify").parameter<QString>(4), qtTrId("qtn_shut_low_temp_warning"));
QCOMPARE(gNotificationManagerStub->stubLastCallTo("Notify").parameter<QString>(2), QString());
QCOMPARE(gNotificationManagerStub->stubLastCallTo("Notify").parameter<QString>(2), QString("icon-system-warning"));
}

void Ut_ThermalNotifier::testDisplayStateOffDoesNothing()
Expand Down

0 comments on commit d67ee41

Please sign in to comment.