14#include <QApplication>
15#include <QLoggingCategory>
18#include <private/qtx11extras_p.h>
23#include <sys/socket.h>
27Q_LOGGING_CATEGORY(KWIN_CORE,
"kwin_core")
36 void cleanupTestCase();
42 void setClientMachineProperty(xcb_window_t window,
const QString &hostname);
47void TestClientMachine::setClientMachineProperty(xcb_window_t window,
const QString &hostname)
49 xcb_change_property(
connection(), XCB_PROP_MODE_REPLACE, window,
50 XCB_ATOM_WM_CLIENT_MACHINE, XCB_ATOM_STRING, 8,
51 hostname.length(), hostname.toLocal8Bit().constData());
54void TestClientMachine::initTestCase()
57 char hostnamebuf[HOST_NAME_MAX];
59 char hostnamebuf[256];
61 if (gethostname(hostnamebuf,
sizeof hostnamebuf) >= 0) {
62 hostnamebuf[
sizeof(hostnamebuf) - 1] = 0;
63 m_hostName = hostnamebuf;
66 addrinfo addressHints;
67 memset(&addressHints, 0,
sizeof(addressHints));
68 addressHints.ai_family = PF_UNSPEC;
69 addressHints.ai_socktype = SOCK_STREAM;
70 addressHints.ai_flags |= AI_CANONNAME;
71 if (getaddrinfo(m_hostName.toLocal8Bit().constData(),
nullptr, &addressHints, &res) == 0) {
72 if (res->ai_canonname) {
73 m_fqdn = QString::fromLocal8Bit(res->ai_canonname);
78 qApp->setProperty(
"x11RootWindow", QVariant::fromValue<quint32>(QX11Info::appRootWindow()));
79 qApp->setProperty(
"x11Connection", QVariant::fromValue<void *>(QX11Info::connection()));
82void TestClientMachine::cleanupTestCase()
86void TestClientMachine::hostName_data()
88 QTest::addColumn<QString>(
"hostName");
89 QTest::addColumn<QString>(
"expectedHost");
90 QTest::addColumn<bool>(
"local");
92 QTest::newRow(
"empty") << QString() << QStringLiteral(
"localhost") <<
true;
93 QTest::newRow(
"localhost") << QStringLiteral(
"localhost") << QStringLiteral(
"localhost") <<
true;
94 QTest::newRow(
"hostname") << m_hostName << m_hostName <<
true;
95 QTest::newRow(
"HOSTNAME") << m_hostName.toUpper() << m_hostName.toUpper() <<
true;
96 QString cutted(m_hostName);
98 QTest::newRow(
"ostname") << cutted << cutted <<
false;
99 QString domain(
"random.name.not.exist.tld");
100 QTest::newRow(
"domain") << domain << domain <<
false;
101 QTest::newRow(
"fqdn") << m_fqdn << m_fqdn <<
true;
102 QTest::newRow(
"FQDN") << m_fqdn.toUpper() << m_fqdn.toUpper() <<
true;
105 QTest::newRow(
"qdn") << cutted << cutted <<
false;
108void TestClientMachine::hostName()
110 const QRect geometry(0, 0, 10, 10);
111 const uint32_t values[] = {
true};
112 Xcb::Window window(geometry, XCB_WINDOW_CLASS_INPUT_ONLY, XCB_CW_OVERRIDE_REDIRECT, values);
113 QFETCH(QString, hostName);
115 setClientMachineProperty(window, hostName);
119 clientMachine.
resolve(window, XCB_WINDOW_NONE);
120 QTEST(clientMachine.
hostName(),
"expectedHost");
128 QCOMPARE(clientMachine.
isLocal(), local);
129 QCOMPARE(spy.isEmpty(), !local);
132void TestClientMachine::emptyHostName()
134 const QRect geometry(0, 0, 10, 10);
135 const uint32_t values[] = {
true};
136 Xcb::Window window(geometry, XCB_WINDOW_CLASS_INPUT_ONLY, XCB_CW_OVERRIDE_REDIRECT, values);
139 clientMachine.
resolve(window, XCB_WINDOW_NONE);
141 QVERIFY(clientMachine.
isLocal());
143 QCOMPARE(spy.isEmpty(),
false);
146Q_CONSTRUCTOR_FUNCTION(forceXcb)
148#include "test_client_machine.moc"
void resolve(xcb_window_t window, xcb_window_t clientLeader)
const QString & hostName() const
static QString localhost()
KWIN_EXPORT xcb_connection_t * connection()
QTEST_MAIN(OnScreenNotificationTest)