This repository has been archived by the owner on Jun 27, 2023. It is now read-only.
forked from tych0/xpyb-ng
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import xcb, xcb.xproto | ||
import struct | ||
import libpry | ||
|
||
# covers xcb.Response too, the base class to xcb.Event | ||
# xcb.Union and xcb.List too, via xproto.ClientMessageEvent | ||
|
||
class uEvent(libpry.AutoTree): | ||
def test_client_message_event(self): | ||
response_type = 33 # ClientMessageEvent | ||
format = 32 | ||
sequence = 0 | ||
window = 1234 | ||
# hardcoded values for these atoms since it doesn't matter here | ||
WM_PROTOCOLS = 268 | ||
WM_DELETE_WINDOW = 266 | ||
|
||
event_raw = struct.pack('BBHII5I', | ||
response_type, | ||
format, | ||
sequence, | ||
window, | ||
WM_PROTOCOLS, | ||
WM_DELETE_WINDOW, | ||
xcb.xproto.Time.CurrentTime, | ||
0, | ||
0, | ||
0 | ||
) | ||
|
||
xcb_event = xcb.Event(event_raw) | ||
|
||
assert ''.join(list(xcb_event)) == event_raw | ||
assert ord(xcb_event[0]) == response_type | ||
assert xcb_event.response_type == response_type | ||
assert xcb_event.sequence == 0 | ||
|
||
xproto_event = xcb.xproto.ClientMessageEvent(xcb_event) | ||
|
||
assert xproto_event.format == format | ||
assert xproto_event.window == window | ||
assert xproto_event.type == WM_PROTOCOLS | ||
|
||
fourbytes = struct.pack('I', WM_DELETE_WINDOW) | ||
|
||
assert xproto_event.data[:4] == fourbytes | ||
assert xproto_event.data.data8[:4] == list(struct.unpack('4B', fourbytes)) | ||
assert xproto_event.data.data16[:2] == list(struct.unpack('2H', fourbytes)) | ||
assert xproto_event.data.data32[0] == WM_DELETE_WINDOW | ||
|
||
|
||
tests = [ | ||
uEvent(), | ||
] |