From 6826b9eb946c75b5c56122bee96f97199efc8f6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Wed, 29 Apr 2015 14:13:20 +0200 Subject: [PATCH] [autotests] Adjust to changes regarding AbstractClient We need a Mock for AbstractClient and our mock Client needs to inherit from it. --- autotests/CMakeLists.txt | 3 + autotests/abstract_client.h | 1 + autotests/mock_abstract_client.cpp | 94 ++++++++++++++++++++++++++++++ autotests/mock_abstract_client.h | 62 ++++++++++++++++++++ autotests/mock_client.cpp | 64 +------------------- autotests/mock_client.h | 26 +-------- autotests/mock_workspace.cpp | 10 ++-- autotests/mock_workspace.h | 13 +++-- 8 files changed, 176 insertions(+), 97 deletions(-) create mode 100644 autotests/abstract_client.h create mode 100644 autotests/mock_abstract_client.cpp create mode 100644 autotests/mock_abstract_client.h diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt index bc49fabc75..502fd510cb 100644 --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -197,6 +197,7 @@ target_link_libraries(effectversionplugin kwineffects) ######################################################## set( testScreens_SRCS test_screens.cpp + mock_abstract_client.cpp mock_client.cpp mock_screens.cpp mock_workspace.cpp @@ -224,6 +225,7 @@ ecm_mark_as_test(testScreens) ######################################################## set( testXRandRScreens_SRCS test_xrandr_screens.cpp + mock_abstract_client.cpp mock_client.cpp mock_screens.cpp mock_workspace.cpp @@ -259,6 +261,7 @@ ecm_mark_as_test(testXRandRScreens) ######################################################## set( testScreenEdges_SRCS test_screen_edges.cpp + mock_abstract_client.cpp mock_client.cpp mock_screens.cpp mock_workspace.cpp diff --git a/autotests/abstract_client.h b/autotests/abstract_client.h new file mode 100644 index 0000000000..d5228a1e9f --- /dev/null +++ b/autotests/abstract_client.h @@ -0,0 +1 @@ +#include "mock_abstract_client.h" \ No newline at end of file diff --git a/autotests/mock_abstract_client.cpp b/autotests/mock_abstract_client.cpp new file mode 100644 index 0000000000..047b39ed01 --- /dev/null +++ b/autotests/mock_abstract_client.cpp @@ -0,0 +1,94 @@ +/******************************************************************** +KWin - the KDE window manager +This file is part of the KDE project. + +Copyright (C) 2014 Martin Gräßlin + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*********************************************************************/ +#include "mock_abstract_client.h" + +namespace KWin +{ + +AbstractClient::AbstractClient(QObject *parent) + : QObject(parent) + , m_active(false) + , m_screen(0) + , m_fullscreen(false) + , m_hiddenInternal(false) + , m_geometry() +{ +} + +AbstractClient::~AbstractClient() = default; + +bool AbstractClient::isActive() const +{ + return m_active; +} + +void AbstractClient::setActive(bool active) +{ + m_active = active; +} + +void AbstractClient::setScreen(int screen) +{ + m_screen = screen; +} + +bool AbstractClient::isOnScreen(int screen) const +{ + // TODO: mock checking client geometry + return screen == m_screen; +} + +int AbstractClient::screen() const +{ + return m_screen; +} + +void AbstractClient::setFullScreen(bool set) +{ + m_fullscreen = set; +} + +bool AbstractClient::isFullScreen() const +{ + return m_fullscreen; +} + +bool AbstractClient::isHiddenInternal() const +{ + return m_hiddenInternal; +} + +void AbstractClient::setHiddenInternal(bool set) +{ + m_hiddenInternal = set; +} + +void AbstractClient::setGeometry(const QRect &rect) +{ + m_geometry = rect; + emit geometryChanged(); +} + +QRect AbstractClient::geometry() const +{ + return m_geometry; +} + +} diff --git a/autotests/mock_abstract_client.h b/autotests/mock_abstract_client.h new file mode 100644 index 0000000000..7ce495b0ad --- /dev/null +++ b/autotests/mock_abstract_client.h @@ -0,0 +1,62 @@ +/******************************************************************** +KWin - the KDE window manager +This file is part of the KDE project. + +Copyright (C) 2014 Martin Gräßlin + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*********************************************************************/ +#ifndef KWIN_MOCK_ABSTRACT_CLIENT_H +#define KWIN_MOCK_ABSTRACT_CLIENT_H + +#include +#include + +namespace KWin +{ + +class AbstractClient : public QObject +{ + Q_OBJECT +public: + explicit AbstractClient(QObject *parent); + virtual ~AbstractClient(); + + int screen() const; + bool isOnScreen(int screen) const; + bool isActive() const; + bool isFullScreen() const; + bool isHiddenInternal() const; + QRect geometry() const; + + void setActive(bool active); + void setScreen(int screen); + void setFullScreen(bool set); + void setHiddenInternal(bool set); + void setGeometry(const QRect &rect); + +Q_SIGNALS: + void geometryChanged(); + +private: + bool m_active; + int m_screen; + bool m_fullscreen; + bool m_hiddenInternal; + QRect m_geometry; +}; + +} + +#endif diff --git a/autotests/mock_client.cpp b/autotests/mock_client.cpp index bdd17371d0..2305565074 100644 --- a/autotests/mock_client.cpp +++ b/autotests/mock_client.cpp @@ -23,77 +23,15 @@ namespace KWin { Client::Client(QObject *parent) - : QObject(parent) - , m_active(false) - , m_screen(0) - , m_fullscreen(false) - , m_hiddenInternal(false) - , m_geometry() + : AbstractClient(parent) { } Client::~Client() = default; -bool Client::isActive() const -{ - return m_active; -} - -void Client::setActive(bool active) -{ - m_active = active; -} - -void Client::setScreen(int screen) -{ - m_screen = screen; -} - -bool Client::isOnScreen(int screen) const -{ - // TODO: mock checking client geometry - return screen == m_screen; -} - -int Client::screen() const -{ - return m_screen; -} - void Client::showOnScreenEdge() { setHiddenInternal(false); } -void Client::setFullScreen(bool set) -{ - m_fullscreen = set; -} - -bool Client::isFullScreen() const -{ - return m_fullscreen; -} - -bool Client::isHiddenInternal() const -{ - return m_hiddenInternal; -} - -void Client::setHiddenInternal(bool set) -{ - m_hiddenInternal = set; -} - -void Client::setGeometry(const QRect &rect) -{ - m_geometry = rect; - emit geometryChanged(); -} - -QRect Client::geometry() const -{ - return m_geometry; -} - } diff --git a/autotests/mock_client.h b/autotests/mock_client.h index ee267ffba1..78553f7b3f 100644 --- a/autotests/mock_client.h +++ b/autotests/mock_client.h @@ -20,43 +20,23 @@ along with this program. If not, see . #ifndef KWIN_MOCK_CLIENT_H #define KWIN_MOCK_CLIENT_H +#include + #include #include namespace KWin { -class Client : public QObject +class Client : public AbstractClient { Q_OBJECT public: explicit Client(QObject *parent); virtual ~Client(); - int screen() const; - bool isOnScreen(int screen) const; - bool isActive() const; - bool isFullScreen() const; - bool isHiddenInternal() const; - QRect geometry() const; - - void setActive(bool active); - void setScreen(int screen); - void setFullScreen(bool set); - void setHiddenInternal(bool set); - void setGeometry(const QRect &rect); - void showOnScreenEdge(); -Q_SIGNALS: - void geometryChanged(); - -private: - bool m_active; - int m_screen; - bool m_fullscreen; - bool m_hiddenInternal; - QRect m_geometry; }; } diff --git a/autotests/mock_workspace.cpp b/autotests/mock_workspace.cpp index 1373b21f6c..3f75e9e61a 100644 --- a/autotests/mock_workspace.cpp +++ b/autotests/mock_workspace.cpp @@ -18,7 +18,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ #include "mock_workspace.h" -#include "mock_client.h" +#include "mock_abstract_client.h" namespace KWin { @@ -39,22 +39,22 @@ MockWorkspace::~MockWorkspace() s_self = nullptr; } -Client *MockWorkspace::activeClient() const +AbstractClient *MockWorkspace::activeClient() const { return m_activeClient; } -void MockWorkspace::setActiveClient(Client *c) +void MockWorkspace::setActiveClient(AbstractClient *c) { m_activeClient = c; } -Client *MockWorkspace::getMovingClient() const +AbstractClient *MockWorkspace::getMovingClient() const { return m_movingClient; } -void MockWorkspace::setMovingClient(Client *c) +void MockWorkspace::setMovingClient(AbstractClient *c) { m_movingClient = c; } diff --git a/autotests/mock_workspace.h b/autotests/mock_workspace.h index f1ce913dd1..c6ffc51945 100644 --- a/autotests/mock_workspace.h +++ b/autotests/mock_workspace.h @@ -26,6 +26,7 @@ along with this program. If not, see . namespace KWin { +class AbstractClient; class Client; class X11EventFilter; @@ -38,14 +39,14 @@ class MockWorkspace : public QObject public: explicit MockWorkspace(QObject *parent = nullptr); virtual ~MockWorkspace(); - Client *activeClient() const; - Client *getMovingClient() const; + AbstractClient *activeClient() const; + AbstractClient *getMovingClient() const; void setShowingDesktop(bool showing); bool showingDesktop() const; QRect clientArea(clientAreaOption, int screen, int desktop) const; - void setActiveClient(Client *c); - void setMovingClient(Client *c); + void setActiveClient(AbstractClient *c); + void setMovingClient(AbstractClient *c); void registerEventFilter(X11EventFilter *filter); void unregisterEventFilter(X11EventFilter *filter); @@ -56,8 +57,8 @@ Q_SIGNALS: void clientRemoved(KWin::Client*); private: - Client *m_activeClient; - Client *m_movingClient; + AbstractClient *m_activeClient; + AbstractClient *m_movingClient; bool m_showingDesktop; static Workspace *s_self; };