[Xcb::Wrapper] Add a unit test for Xcb::Tree

Based on the test Tree::children() is extended for a test case on no
children which used to return a garbage pointer.
icc-effect-5.14.5
Martin Gräßlin 2014-04-14 10:31:37 +02:00
parent 4230a0d331
commit 9db9f172bc
2 changed files with 37 additions and 0 deletions

View File

@ -44,6 +44,7 @@ private Q_SLOTS:
void assignmentBeforeRetrieve();
void assignmentAfterRetrieve();
void discard();
void testQueryTree();
private:
void testEmpty(WindowGeometry &geometry);
void testGeometry(WindowGeometry &geometry, const QRect &rect);
@ -210,5 +211,38 @@ void TestXcbWrapper::discard()
delete geometry;
}
void TestXcbWrapper::testQueryTree()
{
m_testWindow = createWindow();
QVERIFY(m_testWindow != noneWindow());
Tree tree(m_testWindow);
// should have root as parent
QCOMPARE(tree.parent(), static_cast<xcb_window_t>(QX11Info::appRootWindow()));
// shouldn't have any children
QCOMPARE(tree->children_len, uint16_t(0));
QVERIFY(!tree.children());
// query for root
Tree root(QX11Info::appRootWindow());
// shouldn't have a parent
QCOMPARE(root.parent(), xcb_window_t(XCB_WINDOW_NONE));
QVERIFY(root->children_len > 0);
xcb_window_t *children = root.children();
bool found = false;
for (int i = 0; i < xcb_query_tree_children_length(root.data()); ++i) {
if (children[i] == tree.window()) {
found = true;
break;
}
}
QVERIFY(found);
// query for not existing window
Tree doesntExist(XCB_WINDOW_NONE);
QCOMPARE(doesntExist.parent(), xcb_window_t(XCB_WINDOW_NONE));
QVERIFY(doesntExist.isNull());
QVERIFY(doesntExist.isRetrieved());
}
KWIN_TEST_MAIN(TestXcbWrapper)
#include "test_xcb_wrapper.moc"

View File

@ -243,6 +243,9 @@ public:
explicit Tree(WindowId window) : Wrapper<xcb_query_tree_reply_t, xcb_query_tree_cookie_t, &xcb_query_tree_reply, &xcb_query_tree_unchecked>(window) {}
inline WindowId *children() {
if (data()->children_len == 0) {
return nullptr;
}
return xcb_query_tree_children(data());
}
inline xcb_window_t parent() {