refactor: simplify wayland warnings remove waylandwarnigns dialog test

This commit is contained in:
sithlord48 2025-05-09 22:49:41 -04:00 committed by Nick Bolton
parent 49173b11b9
commit 33edb6ce01
3 changed files with 2 additions and 105 deletions

View file

@ -13,19 +13,6 @@ using namespace deskflow::platform;
namespace deskflow::gui::core { namespace deskflow::gui::core {
//
// WaylandWarnings::Deps
//
void WaylandWarnings::Deps::showWaylandLibraryError(QWidget *parent)
{
messages::showWaylandLibraryError(parent);
}
//
// WaylandWarnings
//
void WaylandWarnings::showOnce(QWidget *parent, bool hasEi, bool hasPortal, bool hasPortalInputCapture) void WaylandWarnings::showOnce(QWidget *parent, bool hasEi, bool hasPortal, bool hasPortalInputCapture)
{ {
const auto mode = Settings::value(Settings::Core::CoreMode).value<Settings::CoreMode>(); const auto mode = Settings::value(Settings::Core::CoreMode).value<Settings::CoreMode>();
@ -34,7 +21,7 @@ void WaylandWarnings::showOnce(QWidget *parent, bool hasEi, bool hasPortal, bool
if (!hasEi || !hasPortal || portalIcProblem) { if (!hasEi || !hasPortal || portalIcProblem) {
if (!m_errorShown) { if (!m_errorShown) {
m_errorShown = true; m_errorShown = true;
m_pDeps->showWaylandLibraryError(parent); messages::showWaylandLibraryError(parent);
} else { } else {
qWarning("missing required wayland lib(s) or feature"); qWarning("missing required wayland lib(s) or feature");
} }

View file

@ -7,7 +7,6 @@
#pragma once #pragma once
#include <QWidget> #include <QWidget>
#include <memory>
#include "platform/Wayland.h" #include "platform/Wayland.h"
@ -16,15 +15,7 @@ namespace deskflow::gui::core {
class WaylandWarnings class WaylandWarnings
{ {
public: public:
struct Deps explicit WaylandWarnings() = default;
{
virtual ~Deps() = default;
virtual void showWaylandLibraryError(QWidget *parent);
};
explicit WaylandWarnings(std::shared_ptr<Deps> deps = std::make_shared<Deps>()) : m_pDeps(deps)
{
}
void showOnce( void showOnce(
QWidget *parent, bool hasEi = platform::kHasEi, bool hasPortal = platform::kHasPortal, QWidget *parent, bool hasEi = platform::kHasEi, bool hasPortal = platform::kHasPortal,
@ -33,7 +24,6 @@ public:
private: private:
bool m_errorShown{false}; bool m_errorShown{false};
std::shared_ptr<Deps> m_pDeps;
}; };
} // namespace deskflow::gui::core } // namespace deskflow::gui::core

View file

@ -1,80 +0,0 @@
/*
* Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2024 Symless Ltd.
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
*/
#include "gui/core/WaylandWarnings.h"
#include "gui/core/CoreProcess.h"
#include <gmock/gmock.h>
#include <gtest/gtest.h>
using namespace deskflow::gui;
using namespace deskflow::gui::core;
namespace {
struct MockDeps : public WaylandWarnings::Deps
{
MOCK_METHOD(void, showWaylandLibraryError, (QWidget *), (override));
};
} // namespace
TEST(WaylandWarningsTests, showOnce_serverNoEi_showLibraryError)
{
const auto deps = std::make_shared<MockDeps>();
const bool hasEi = false;
const bool hasPortal = false;
const bool hasPortalIC = false;
WaylandWarnings waylandWarnings(deps);
Settings::setValue(Settings::Core::CoreMode, Settings::CoreMode::Server);
EXPECT_CALL(*deps, showWaylandLibraryError(nullptr)).Times(1);
waylandWarnings.showOnce(nullptr, hasEi, hasPortal, hasPortalIC);
}
TEST(WaylandWarningsTests, showOnce_serverNoPortal_showLibraryError)
{
const auto deps = std::make_shared<MockDeps>();
const bool hasEi = true;
const bool hasPortal = false;
const bool hasPortalIC = false;
WaylandWarnings waylandWarnings(deps);
Settings::setValue(Settings::Core::CoreMode, Settings::CoreMode::Server);
EXPECT_CALL(*deps, showWaylandLibraryError(nullptr)).Times(1);
waylandWarnings.showOnce(nullptr, hasEi, hasPortal, hasPortalIC);
}
TEST(WaylandWarningsTests, showOnce_serverNoPortalIc_showLibraryError)
{
const auto deps = std::make_shared<MockDeps>();
const bool hasEi = true;
const bool hasPortal = true;
const bool hasPortalIC = false;
WaylandWarnings waylandWarnings(deps);
Settings::setValue(Settings::Core::CoreMode, Settings::CoreMode::Server);
EXPECT_CALL(*deps, showWaylandLibraryError(nullptr)).Times(1);
waylandWarnings.showOnce(nullptr, hasEi, hasPortal, hasPortalIC);
}
TEST(WaylandWarningsTests, showOnce_failureCalledTwice_messageOnlyShownOnce)
{
const auto deps = std::make_shared<MockDeps>();
const bool hasEi = false;
const bool hasPortal = false;
const bool hasPortalIC = false;
WaylandWarnings waylandWarnings(deps);
Settings::setValue(Settings::Core::CoreMode, Settings::CoreMode::Server);
EXPECT_CALL(*deps, showWaylandLibraryError(nullptr)).Times(1);
waylandWarnings.showOnce(nullptr, hasEi, hasPortal, hasPortalIC);
waylandWarnings.showOnce(nullptr, hasEi, hasPortal, hasPortalIC);
}