diff --git a/.travis.yml b/.travis.yml index c989c97..246122f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,6 @@ cache: pip python: - 2.7 - - 3.4 - 3.5 - 3.6 - 3.7 diff --git a/setup.py b/setup.py index 13dcfe4..688d177 100755 --- a/setup.py +++ b/setup.py @@ -32,7 +32,6 @@ 'License :: OSI Approved :: MIT License', 'Operating System :: POSIX', 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', diff --git a/tests/test_protocol.py b/tests/test_protocol.py new file mode 100644 index 0000000..a5732ad --- /dev/null +++ b/tests/test_protocol.py @@ -0,0 +1,360 @@ +import struct + +from twisted.trial import unittest + +from txdbus import protocol + + +class TestTransport: + def __init__(self): + self.data = b'' + self.fds = [] + + def sendFileDescriptor(self, fd): + # twisted queues fds to be sent later + self.fds.append(fd) + + def write(self, data): + self.data += data + return len(data) + + +class TestProtocol(protocol.BasicDBusProtocol): + def __init__(self): + self._receivedFDs = [] + self._toBeSentFDs = [] + self.transport = TestTransport() + self.mcalls = [] + self.mrets = [] + self.merrs = [] + self.msigs = [] + + def methodCallReceived(self, mcall): + self.mcalls.append(mcall) + + def methodReturnReceived(self, mret): + self.mrets.append(mret) + + def errorReceived(self, merr): + self.merrs.append(merr) + + def signalReceived(self, msig): + self.msigs.append(msig) + + +class Endian: + LITTLE = ord('l') + BIG = ord('B') + + +class MsgType: + INVALID = 0 + METHOD_CALL = 1 + METHOD_RETURN = 2 + ERROR = 3 + SIGNAL = 4 + + +class Flags: + NONE = 0x0 + NO_REPLY_EXPECTED = 0x1 + NO_AUTO_START = 0x2 + ALLOW_INTERACTIVE_AUTHORIZATION = 0x4 + + +class Version: + ONE = 1 + + +class DataType: + INVALID = 0 + BYTE = ord('y') + BOOLEAN = ord('b') + INT16 = ord('n') + UINT16 = ord('q') + INT32 = ord('i') + UINT32 = ord('u') + INT64 = ord('x') + UINT64 = ord('t') + DOUBLE = ord('d') + STRING = ord('s') + OBJECT_PATH = ord('o') + SIGNATURE = ord('g') + ARRAY = ord('a') + STRUCT_BEGIN = ord('(') + STRUCT_END = ord(')') + VARIANT = ord('v') + DICT_ENTRY = ord('e') + UNIX_FD = ord('h') + + +class HeaderField: + INVALID = 0 + PATH = 1 + INTERFACE = 2 + MEMBER = 3 + ERROR_NAME = 4 + REPLY_SERIAL = 5 + DESTINATION = 6 + SENDER = 7 + SIGNATURE = 8 + UNIX_FDS = 9 + + +def encode_signature(*data_types): + data = bytearray(data_types) + data.append(0) + data.insert(0, len(data_types)) + return data + + +def align(align, offset): + count = offset % align + if not count: + return b'' + return b'\x00' * (align - count) + + +def create_basic_method(path, member): + """Creates raw D-Bus message` with `path` for method `member having no + parameters + """ + serial = 1 + path = path.encode() + member = member.encode() + + headers = bytearray() + headers.append(HeaderField.PATH) + headers += encode_signature(DataType.OBJECT_PATH) + headers += align(4, len(headers)) + headers += struct.pack('