[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
parent
4230a0d331
commit
9db9f172bc
|
@ -44,6 +44,7 @@ private Q_SLOTS:
|
||||||
void assignmentBeforeRetrieve();
|
void assignmentBeforeRetrieve();
|
||||||
void assignmentAfterRetrieve();
|
void assignmentAfterRetrieve();
|
||||||
void discard();
|
void discard();
|
||||||
|
void testQueryTree();
|
||||||
private:
|
private:
|
||||||
void testEmpty(WindowGeometry &geometry);
|
void testEmpty(WindowGeometry &geometry);
|
||||||
void testGeometry(WindowGeometry &geometry, const QRect &rect);
|
void testGeometry(WindowGeometry &geometry, const QRect &rect);
|
||||||
|
@ -210,5 +211,38 @@ void TestXcbWrapper::discard()
|
||||||
delete geometry;
|
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)
|
KWIN_TEST_MAIN(TestXcbWrapper)
|
||||||
#include "test_xcb_wrapper.moc"
|
#include "test_xcb_wrapper.moc"
|
||||||
|
|
|
@ -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) {}
|
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() {
|
inline WindowId *children() {
|
||||||
|
if (data()->children_len == 0) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
return xcb_query_tree_children(data());
|
return xcb_query_tree_children(data());
|
||||||
}
|
}
|
||||||
inline xcb_window_t parent() {
|
inline xcb_window_t parent() {
|
||||||
|
|
Loading…
Reference in New Issue