Improve the TestScreens autotest

This commit is contained in:
Martin Gräßlin 2014-09-25 08:45:23 +02:00
parent 1e2f491176
commit a7cf808dea

View file

@ -21,6 +21,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "../cursor.h" #include "../cursor.h"
#include "mock_screens.h" #include "mock_screens.h"
#include "mock_client.h" #include "mock_client.h"
// frameworks
#include <KConfigGroup>
// Qt // Qt
#include <QtTest/QtTest> #include <QtTest/QtTest>
@ -28,9 +30,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
namespace KWin namespace KWin
{ {
static QPoint s_cursorPos = QPoint();
QPoint Cursor::pos() QPoint Cursor::pos()
{ {
return QPoint(); return s_cursorPos;
} }
} }
@ -39,7 +42,10 @@ class TestScreens : public QObject
{ {
Q_OBJECT Q_OBJECT
private Q_SLOTS: private Q_SLOTS:
void init();
void testCurrentFollowsMouse(); void testCurrentFollowsMouse();
void testReconfigure_data();
void testReconfigure();
void testSize_data(); void testSize_data();
void testSize(); void testSize();
void testCount(); void testCount();
@ -48,8 +54,17 @@ private Q_SLOTS:
void testCurrent_data(); void testCurrent_data();
void testCurrent(); void testCurrent();
void testCurrentClient(); void testCurrentClient();
void testCurrentWithFollowsMouse_data();
void testCurrentWithFollowsMouse();
void testCurrentPoint_data();
void testCurrentPoint();
}; };
void TestScreens::init()
{
KWin::s_cursorPos = QPoint();
}
void TestScreens::testCurrentFollowsMouse() void TestScreens::testCurrentFollowsMouse()
{ {
KWin::MockWorkspace ws; KWin::MockWorkspace ws;
@ -57,8 +72,54 @@ void TestScreens::testCurrentFollowsMouse()
QVERIFY(!screens->isCurrentFollowsMouse()); QVERIFY(!screens->isCurrentFollowsMouse());
screens->setCurrentFollowsMouse(true); screens->setCurrentFollowsMouse(true);
QVERIFY(screens->isCurrentFollowsMouse()); QVERIFY(screens->isCurrentFollowsMouse());
// setting to same should not do anything
screens->setCurrentFollowsMouse(true);
QVERIFY(screens->isCurrentFollowsMouse());
// setting back to other value
screens->setCurrentFollowsMouse(false); screens->setCurrentFollowsMouse(false);
QVERIFY(!screens->isCurrentFollowsMouse()); QVERIFY(!screens->isCurrentFollowsMouse());
// setting to same should not do anything
screens->setCurrentFollowsMouse(false);
QVERIFY(!screens->isCurrentFollowsMouse());
}
void TestScreens::testReconfigure_data()
{
QTest::addColumn<QString>("focusPolicy");
QTest::addColumn<bool>("expectedDefault");
QTest::addColumn<bool>("setting");
QTest::newRow("ClickToFocus") << QStringLiteral("ClickToFocus") << false << true;
QTest::newRow("FocusFollowsMouse") << QStringLiteral("FocusFollowsMouse") << true << false;
QTest::newRow("FocusUnderMouse") << QStringLiteral("FocusUnderMouse") << true << false;
QTest::newRow("FocusStrictlyUnderMouse") << QStringLiteral("FocusStrictlyUnderMouse") << true << false;
}
void TestScreens::testReconfigure()
{
using namespace KWin;
MockWorkspace ws;
Screens::create(&ws);
screens()->reconfigure();
QVERIFY(!screens()->isCurrentFollowsMouse());
QFETCH(QString, focusPolicy);
KSharedConfig::Ptr config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig);
config->group("Windows").writeEntry("FocusPolicy", focusPolicy);
config->group("Windows").sync();
config->sync();
screens()->setConfig(config);
screens()->reconfigure();
QTEST(screens()->isCurrentFollowsMouse(), "expectedDefault");
QFETCH(bool, setting);
config->group("Windows").writeEntry("ActiveMouseScreen", setting);
config->sync();
screens()->reconfigure();
QCOMPARE(screens()->isCurrentFollowsMouse(), setting);
} }
void TestScreens::testSize_data() void TestScreens::testSize_data()
@ -221,11 +282,83 @@ void TestScreens::testCurrentClient()
QCOMPARE(currentChangedSpy.count(), 1); QCOMPARE(currentChangedSpy.count(), 1);
QCOMPARE(screens()->current(), 1); QCOMPARE(screens()->current(), 1);
// setting current with the same client again should not change, though
screens()->setCurrent(client);
QCOMPARE(currentChangedSpy.count(), 1);
// and it should even still be on screen 1 if we make the client non-current again // and it should even still be on screen 1 if we make the client non-current again
ws.setActiveClient(nullptr); ws.setActiveClient(nullptr);
client->setActive(false); client->setActive(false);
QCOMPARE(screens()->current(), 1); QCOMPARE(screens()->current(), 1);
} }
void TestScreens::testCurrentWithFollowsMouse_data()
{
QTest::addColumn< QList<QRect> >("geometries");
QTest::addColumn<QPoint>("cursorPos");
QTest::addColumn<int>("expected");
QTest::newRow("empty") << QList<QRect>{{QRect()}} << QPoint(100, 100) << 0;
QTest::newRow("cloned") << QList<QRect>{{QRect{0, 0, 200, 100}, QRect{0, 0, 200, 100}}} << QPoint(50, 50) << 0;
QTest::newRow("adjacent-0") << QList<QRect>{{QRect{0, 0, 200, 100}, QRect{200, 100, 400, 300}}} << QPoint(199, 99) << 0;
QTest::newRow("adjacent-1") << QList<QRect>{{QRect{0, 0, 200, 100}, QRect{200, 100, 400, 300}}} << QPoint(200, 100) << 1;
QTest::newRow("gap") << QList<QRect>{{QRect{0, 0, 10, 20}, QRect{20, 40, 10, 20}}} << QPoint(15, 30) << 1;
}
void TestScreens::testCurrentWithFollowsMouse()
{
using namespace KWin;
MockWorkspace ws;
MockScreens *mockScreens = static_cast<MockScreens*>(Screens::create(&ws));
QSignalSpy changedSpy(screens(), SIGNAL(changed()));
QVERIFY(changedSpy.isValid());
screens()->setCurrentFollowsMouse(true);
QCOMPARE(screens()->current(), 0);
QFETCH(QList<QRect>, geometries);
mockScreens->setGeometries(geometries);
// first is before it's updated
QVERIFY(changedSpy.wait());
// second is after it's updated
QVERIFY(changedSpy.wait());
QFETCH(QPoint, cursorPos);
KWin::s_cursorPos = cursorPos;
QTEST(screens()->current(), "expected");
}
void TestScreens::testCurrentPoint_data()
{
QTest::addColumn< QList<QRect> >("geometries");
QTest::addColumn<QPoint>("cursorPos");
QTest::addColumn<int>("expected");
QTest::newRow("empty") << QList<QRect>{{QRect()}} << QPoint(100, 100) << 0;
QTest::newRow("cloned") << QList<QRect>{{QRect{0, 0, 200, 100}, QRect{0, 0, 200, 100}}} << QPoint(50, 50) << 0;
QTest::newRow("adjacent-0") << QList<QRect>{{QRect{0, 0, 200, 100}, QRect{200, 100, 400, 300}}} << QPoint(199, 99) << 0;
QTest::newRow("adjacent-1") << QList<QRect>{{QRect{0, 0, 200, 100}, QRect{200, 100, 400, 300}}} << QPoint(200, 100) << 1;
QTest::newRow("gap") << QList<QRect>{{QRect{0, 0, 10, 20}, QRect{20, 40, 10, 20}}} << QPoint(15, 30) << 1;
}
void TestScreens::testCurrentPoint()
{
using namespace KWin;
MockWorkspace ws;
MockScreens *mockScreens = static_cast<MockScreens*>(Screens::create(&ws));
QSignalSpy changedSpy(screens(), SIGNAL(changed()));
QVERIFY(changedSpy.isValid());
QFETCH(QList<QRect>, geometries);
mockScreens->setGeometries(geometries);
// first is before it's updated
QVERIFY(changedSpy.wait());
// second is after it's updated
QVERIFY(changedSpy.wait());
QFETCH(QPoint, cursorPos);
screens()->setCurrent(cursorPos);
QTEST(screens()->current(), "expected");
}
QTEST_MAIN(TestScreens) QTEST_MAIN(TestScreens)
#include "test_screens.moc" #include "test_screens.moc"