Add support for Modes in Output

This commit is contained in:
Martin Gräßlin 2014-09-23 15:56:13 +02:00
parent eb9e5a178f
commit 809519f058

View file

@ -75,9 +75,9 @@ void TestWaylandOutput::init()
QVERIFY(m_display->isRunning());
m_serverOutput = m_display->createOutput(this);
m_serverOutput->addMode(QSize(800, 600));
m_serverOutput->addMode(QSize(800, 600), OutputInterface::ModeFlags(OutputInterface::ModeFlag::Preferred));
m_serverOutput->addMode(QSize(1024, 768));
m_serverOutput->addMode(QSize(1280, 1024));
m_serverOutput->addMode(QSize(1280, 1024), OutputInterface::ModeFlags(), 90000);
m_serverOutput->setCurrentMode(QSize(1024, 768));
m_serverOutput->create();
@ -161,6 +161,7 @@ void TestWaylandOutput::testRegistry()
void TestWaylandOutput::testModeChanges()
{
using namespace KWayland::Client;
KWayland::Client::Registry registry;
QSignalSpy announced(&registry, SIGNAL(outputAnnounced(quint32,quint32)));
registry.create(m_connection->display());
@ -172,22 +173,81 @@ void TestWaylandOutput::testModeChanges()
KWayland::Client::Output output;
QSignalSpy outputChanged(&output, SIGNAL(changed()));
QVERIFY(outputChanged.isValid());
QSignalSpy modeAddedSpy(&output, SIGNAL(modeAdded(KWayland::Client::Output::Mode)));
QVERIFY(modeAddedSpy.isValid());
output.setup(registry.bindOutput(announced.first().first().value<quint32>(), announced.first().last().value<quint32>()));
wl_display_flush(m_connection->display());
QVERIFY(outputChanged.wait());
QCOMPARE(modeAddedSpy.count(), 3);
QCOMPARE(modeAddedSpy.at(0).first().value<Output::Mode>().size, QSize(800, 600));
QCOMPARE(modeAddedSpy.at(0).first().value<Output::Mode>().refreshRate, 60000);
QCOMPARE(modeAddedSpy.at(0).first().value<Output::Mode>().flags, Output::Mode::Flags(Output::Mode::Flag::Preferred));
QCOMPARE(modeAddedSpy.at(0).first().value<Output::Mode>().output, QPointer<Output>(&output));
QCOMPARE(modeAddedSpy.at(1).first().value<Output::Mode>().size, QSize(1280, 1024));
QCOMPARE(modeAddedSpy.at(1).first().value<Output::Mode>().refreshRate, 90000);
QCOMPARE(modeAddedSpy.at(1).first().value<Output::Mode>().flags, Output::Mode::Flags(Output::Mode::Flag::None));
QCOMPARE(modeAddedSpy.at(1).first().value<Output::Mode>().output, QPointer<Output>(&output));
QCOMPARE(modeAddedSpy.at(2).first().value<Output::Mode>().size, QSize(1024, 768));
QCOMPARE(modeAddedSpy.at(2).first().value<Output::Mode>().refreshRate, 60000);
QCOMPARE(modeAddedSpy.at(2).first().value<Output::Mode>().flags, Output::Mode::Flags(Output::Mode::Flag::Current));
QCOMPARE(modeAddedSpy.at(2).first().value<Output::Mode>().output, QPointer<Output>(&output));
const QList<Output::Mode> &modes = output.modes();
QCOMPARE(modes.size(), 3);
QCOMPARE(modes.at(0), modeAddedSpy.at(0).first().value<Output::Mode>());
QCOMPARE(modes.at(1), modeAddedSpy.at(1).first().value<Output::Mode>());
QCOMPARE(modes.at(2), modeAddedSpy.at(2).first().value<Output::Mode>());
QCOMPARE(output.pixelSize(), QSize(1024, 768));
// change the current mode
outputChanged.clear();
QSignalSpy modeChangedSpy(&output, SIGNAL(modeChanged(KWayland::Client::Output::Mode)));
QVERIFY(modeChangedSpy.isValid());
m_serverOutput->setCurrentMode(QSize(800, 600));
QVERIFY(outputChanged.wait());
QVERIFY(modeChangedSpy.wait());
if (modeChangedSpy.size() == 1) {
QVERIFY(modeChangedSpy.wait());
}
QCOMPARE(modeChangedSpy.size(), 2);
// the one which lost the current flag
QCOMPARE(modeChangedSpy.first().first().value<Output::Mode>().size, QSize(1024, 768));
QCOMPARE(modeChangedSpy.first().first().value<Output::Mode>().refreshRate, 60000);
QCOMPARE(modeChangedSpy.first().first().value<Output::Mode>().flags, Output::Mode::Flags());
// the one which got the current flag
QCOMPARE(modeChangedSpy.last().first().value<Output::Mode>().size, QSize(800, 600));
QCOMPARE(modeChangedSpy.last().first().value<Output::Mode>().refreshRate, 60000);
QCOMPARE(modeChangedSpy.last().first().value<Output::Mode>().flags, Output::Mode::Flags(Output::Mode::Flag::Current | Output::Mode::Flag::Preferred));
QVERIFY(!outputChanged.isEmpty());
QCOMPARE(output.pixelSize(), QSize(800, 600));
const QList<Output::Mode> &modes2 = output.modes();
QCOMPARE(modes2.at(0).size, QSize(1280, 1024));
QCOMPARE(modes2.at(0).refreshRate, 90000);
QCOMPARE(modes2.at(0).flags, Output::Mode::Flag::None);
QCOMPARE(modes2.at(1).size, QSize(1024, 768));
QCOMPARE(modes2.at(1).refreshRate, 60000);
QCOMPARE(modes2.at(1).flags, Output::Mode::Flag::None);
QCOMPARE(modes2.at(2).size, QSize(800, 600));
QCOMPARE(modes2.at(2).refreshRate, 60000);
QCOMPARE(modes2.at(2).flags, Output::Mode::Flag::Current | Output::Mode::Flag::Preferred);
// change once more
outputChanged.clear();
m_serverOutput->setCurrentMode(QSize(1280, 1024));
QVERIFY(outputChanged.wait());
modeChangedSpy.clear();
m_serverOutput->setCurrentMode(QSize(1280, 1024), 90000);
QVERIFY(modeChangedSpy.wait());
if (modeChangedSpy.size() == 1) {
QVERIFY(modeChangedSpy.wait());
}
QCOMPARE(modeChangedSpy.size(), 2);
// the one which lost the current flag
QCOMPARE(modeChangedSpy.first().first().value<Output::Mode>().size, QSize(800, 600));
QCOMPARE(modeChangedSpy.first().first().value<Output::Mode>().refreshRate, 60000);
QCOMPARE(modeChangedSpy.first().first().value<Output::Mode>().flags, Output::Mode::Flags(Output::Mode::Flag::Preferred));
// the one which got the current flag
QCOMPARE(modeChangedSpy.last().first().value<Output::Mode>().size, QSize(1280, 1024));
QCOMPARE(modeChangedSpy.last().first().value<Output::Mode>().refreshRate, 90000);
QCOMPARE(modeChangedSpy.last().first().value<Output::Mode>().flags, Output::Mode::Flags(Output::Mode::Flag::Current));
QVERIFY(!outputChanged.isEmpty());
QCOMPARE(output.pixelSize(), QSize(1280, 1024));
}