Exemplo n.º 1
0
def test_maximum():
    """Test maximum valid integer value."""
    assert 127 == c_byte.from_buffer(bytearray(c_byte(127))).value
    assert 2147483647 == c_int.from_buffer(bytearray(c_int(2147483647))).value
    assert 127 == c_int8.from_buffer(bytearray(c_int8(127))).value
    if sys.maxsize > 2**32:  # 64-bit.
        assert 9223372036854775807 == c_long.from_buffer(
            bytearray(c_long(9223372036854775807))).value
    else:
        assert 2147483647 == c_long.from_buffer(bytearray(
            c_long(2147483647))).value
    assert 9223372036854775807 == c_longlong.from_buffer(
        bytearray(c_longlong(9223372036854775807))).value
    assert 65535 == c_uint16.from_buffer(bytearray(c_uint16(65535))).value
    assert 4294967295 == c_uint32.from_buffer(bytearray(
        c_uint32(4294967295))).value
    assert 18446744073709551615 == c_uint64.from_buffer(
        bytearray(c_uint64(18446744073709551615))).value
    assert 255 == c_uint8.from_buffer(bytearray(c_uint8(255))).value
    assert 255 == c_ubyte.from_buffer(bytearray(c_ubyte(255))).value
    assert 4294967295 == c_uint.from_buffer(bytearray(
        c_uint(4294967295))).value
    if sys.maxsize > 2**32:  # 64-bit.
        assert 18446744073709551615 == c_ulong.from_buffer(
            bytearray(c_ulong(18446744073709551615))).value
    else:
        assert 4294967295 == c_ulong.from_buffer(bytearray(
            c_ulong(4294967295))).value
    assert 18446744073709551615 == c_ulonglong.from_buffer(
        bytearray(c_ulonglong(18446744073709551615))).value
    assert 65535 == c_ushort.from_buffer(bytearray(c_ushort(65535))).value
Exemplo n.º 2
0
def test_from_buffer_large():
    """Test .from_buffer attribute."""
    data = b'\xb8~?./3\x02\x14\xb2\x89\xfc6A\xa4\x02\x05f\xdb\xb1\x04\xc3\x891\xad\x8cW\xcd\xda\x04A'
    assert -72 == c_byte.from_buffer(bytearray(data)).value
    assert 775913144 == c_int.from_buffer(bytearray(data)).value
    assert -72 == c_int8.from_buffer(bytearray(data)).value
    if sys.maxsize > 2**32:  # 64-bit.
        assert 1441771108444372664 == c_long.from_buffer(bytearray(data)).value
    else:
        assert 775913144 == c_long.from_buffer(bytearray(data)).value
    assert 1441771108444372664 == c_longlong.from_buffer(bytearray(data)).value
    assert 32440 == c_uint16.from_buffer(bytearray(data)).value
    assert 775913144 == c_uint32.from_buffer(bytearray(data)).value
    assert 1441771108444372664 == c_uint64.from_buffer(bytearray(data)).value
    assert 184 == c_uint8.from_buffer(bytearray(data)).value
    assert 184 == c_ubyte.from_buffer(bytearray(data)).value
    assert 775913144 == c_uint.from_buffer(bytearray(data)).value
    if sys.maxsize > 2**32:  # 64-bit.
        assert 1441771108444372664 == c_ulong.from_buffer(
            bytearray(data)).value
    else:
        assert 775913144 == c_ulong.from_buffer(bytearray(data)).value
    assert 1441771108444372664 == c_ulonglong.from_buffer(
        bytearray(data)).value
    assert 32440 == c_ushort.from_buffer(bytearray(data)).value
Exemplo n.º 3
0
def test_zero():
    """Test zero integer value."""
    assert 0 == c_byte.from_buffer(bytearray(c_byte())).value
    assert 0 == c_int.from_buffer(bytearray(c_int())).value
    assert 0 == c_int8.from_buffer(bytearray(c_int8())).value
    assert 0 == c_long.from_buffer(bytearray(c_long())).value
    assert 0 == c_longlong.from_buffer(bytearray(c_longlong())).value
    assert 0 == c_uint16.from_buffer(bytearray(c_uint16())).value
    assert 0 == c_uint32.from_buffer(bytearray(c_uint32())).value
    assert 0 == c_uint64.from_buffer(bytearray(c_uint64())).value
    assert 0 == c_uint8.from_buffer(bytearray(c_uint8())).value
    assert 0 == c_ubyte.from_buffer(bytearray(c_ubyte())).value
    assert 0 == c_uint.from_buffer(bytearray(c_uint())).value
    assert 0 == c_ulong.from_buffer(bytearray(c_ulong())).value
    assert 0 == c_ulonglong.from_buffer(bytearray(c_ulonglong())).value
    assert 0 == c_ushort.from_buffer(bytearray(c_ushort())).value
Exemplo n.º 4
0
def test_middle():
    """Test with arbitrary positive value."""
    assert 123 == c_byte.from_buffer(bytearray(c_byte(123))).value
    assert 1234567890 == c_int.from_buffer(bytearray(c_int(1234567890))).value
    assert 123 == c_int8.from_buffer(bytearray(c_int8(123))).value
    assert 1234567890 == c_long.from_buffer(bytearray(c_long(1234567890))).value
    assert 1234567890123456789 == c_longlong.from_buffer(bytearray(c_longlong(1234567890123456789))).value
    assert 12345 == c_uint16.from_buffer(bytearray(c_uint16(12345))).value
    assert 1234567890 == c_uint32.from_buffer(bytearray(c_uint32(1234567890))).value
    assert 12345678901234567890 == c_uint64.from_buffer(bytearray(c_uint64(12345678901234567890))).value
    assert 123 == c_uint8.from_buffer(bytearray(c_uint8(123))).value
    assert 123 == c_ubyte.from_buffer(bytearray(c_ubyte(123))).value
    assert 1234567890 == c_uint.from_buffer(bytearray(c_uint(1234567890))).value
    assert 1234567890 == c_ulong.from_buffer(bytearray(c_ulong(1234567890))).value
    assert 12345678901234567890 == c_ulonglong.from_buffer(bytearray(c_ulonglong(12345678901234567890))).value
    assert 12345 == c_ushort.from_buffer(bytearray(c_ushort(12345))).value
Exemplo n.º 5
0
def test_zero():
    """Test zero integer value."""
    assert 0 == c_byte.from_buffer(bytearray(c_byte())).value
    assert 0 == c_int.from_buffer(bytearray(c_int())).value
    assert 0 == c_int8.from_buffer(bytearray(c_int8())).value
    assert 0 == c_long.from_buffer(bytearray(c_long())).value
    assert 0 == c_longlong.from_buffer(bytearray(c_longlong())).value
    assert 0 == c_uint16.from_buffer(bytearray(c_uint16())).value
    assert 0 == c_uint32.from_buffer(bytearray(c_uint32())).value
    assert 0 == c_uint64.from_buffer(bytearray(c_uint64())).value
    assert 0 == c_uint8.from_buffer(bytearray(c_uint8())).value
    assert 0 == c_ubyte.from_buffer(bytearray(c_ubyte())).value
    assert 0 == c_uint.from_buffer(bytearray(c_uint())).value
    assert 0 == c_ulong.from_buffer(bytearray(c_ulong())).value
    assert 0 == c_ulonglong.from_buffer(bytearray(c_ulonglong())).value
    assert 0 == c_ushort.from_buffer(bytearray(c_ushort())).value
Exemplo n.º 6
0
def test_maximum():
    """Test maximum valid integer value."""
    assert 127 == c_byte.from_buffer(bytearray(c_byte(127))).value
    assert 2147483647 == c_int.from_buffer(bytearray(c_int(2147483647))).value
    assert 127 == c_int8.from_buffer(bytearray(c_int8(127))).value
    if sys.maxsize > 2 ** 32:  # 64-bit.
        assert 9223372036854775807 == c_long.from_buffer(bytearray(c_long(9223372036854775807))).value
    else:
        assert 2147483647 == c_long.from_buffer(bytearray(c_long(2147483647))).value
    assert 9223372036854775807 == c_longlong.from_buffer(bytearray(c_longlong(9223372036854775807))).value
    assert 65535 == c_uint16.from_buffer(bytearray(c_uint16(65535))).value
    assert 4294967295 == c_uint32.from_buffer(bytearray(c_uint32(4294967295))).value
    assert 18446744073709551615 == c_uint64.from_buffer(bytearray(c_uint64(18446744073709551615))).value
    assert 255 == c_uint8.from_buffer(bytearray(c_uint8(255))).value
    assert 255 == c_ubyte.from_buffer(bytearray(c_ubyte(255))).value
    assert 4294967295 == c_uint.from_buffer(bytearray(c_uint(4294967295))).value
    if sys.maxsize > 2 ** 32:  # 64-bit.
        assert 18446744073709551615 == c_ulong.from_buffer(bytearray(c_ulong(18446744073709551615))).value
    else:
        assert 4294967295 == c_ulong.from_buffer(bytearray(c_ulong(4294967295))).value
    assert 18446744073709551615 == c_ulonglong.from_buffer(bytearray(c_ulonglong(18446744073709551615))).value
    assert 65535 == c_ushort.from_buffer(bytearray(c_ushort(65535))).value
Exemplo n.º 7
0
def test_middle():
    """Test with arbitrary positive value."""
    assert 123 == c_byte.from_buffer(bytearray(c_byte(123))).value
    assert 1234567890 == c_int.from_buffer(bytearray(c_int(1234567890))).value
    assert 123 == c_int8.from_buffer(bytearray(c_int8(123))).value
    assert 1234567890 == c_long.from_buffer(bytearray(
        c_long(1234567890))).value
    assert 1234567890123456789 == c_longlong.from_buffer(
        bytearray(c_longlong(1234567890123456789))).value
    assert 12345 == c_uint16.from_buffer(bytearray(c_uint16(12345))).value
    assert 1234567890 == c_uint32.from_buffer(bytearray(
        c_uint32(1234567890))).value
    assert 12345678901234567890 == c_uint64.from_buffer(
        bytearray(c_uint64(12345678901234567890))).value
    assert 123 == c_uint8.from_buffer(bytearray(c_uint8(123))).value
    assert 123 == c_ubyte.from_buffer(bytearray(c_ubyte(123))).value
    assert 1234567890 == c_uint.from_buffer(bytearray(
        c_uint(1234567890))).value
    assert 1234567890 == c_ulong.from_buffer(bytearray(
        c_ulong(1234567890))).value
    assert 12345678901234567890 == c_ulonglong.from_buffer(
        bytearray(c_ulonglong(12345678901234567890))).value
    assert 12345 == c_ushort.from_buffer(bytearray(c_ushort(12345))).value
Exemplo n.º 8
0
def test_from_buffer_large():
    """Test .from_buffer attribute."""
    data = b'\xb8~?./3\x02\x14\xb2\x89\xfc6A\xa4\x02\x05f\xdb\xb1\x04\xc3\x891\xad\x8cW\xcd\xda\x04A'
    assert -72 == c_byte.from_buffer(bytearray(data)).value
    assert 775913144 == c_int.from_buffer(bytearray(data)).value
    assert -72 == c_int8.from_buffer(bytearray(data)).value
    if sys.maxsize > 2 ** 32:  # 64-bit.
        assert 1441771108444372664 == c_long.from_buffer(bytearray(data)).value
    else:
        assert 775913144 == c_long.from_buffer(bytearray(data)).value
    assert 1441771108444372664 == c_longlong.from_buffer(bytearray(data)).value
    assert 32440 == c_uint16.from_buffer(bytearray(data)).value
    assert 775913144 == c_uint32.from_buffer(bytearray(data)).value
    assert 1441771108444372664 == c_uint64.from_buffer(bytearray(data)).value
    assert 184 == c_uint8.from_buffer(bytearray(data)).value
    assert 184 == c_ubyte.from_buffer(bytearray(data)).value
    assert 775913144 == c_uint.from_buffer(bytearray(data)).value
    if sys.maxsize > 2 ** 32:  # 64-bit.
        assert 1441771108444372664 == c_ulong.from_buffer(bytearray(data)).value
    else:
        assert 775913144 == c_ulong.from_buffer(bytearray(data)).value
    assert 1441771108444372664 == c_ulonglong.from_buffer(bytearray(data)).value
    assert 32440 == c_ushort.from_buffer(bytearray(data)).value
Exemplo n.º 9
0
 def ifi_change(self):
     """Message change."""
     return c_uint.from_buffer(self.bytearray[self._get_slicers(5)]).value
Exemplo n.º 10
0
 def ifi_flags(self):
     """Message flags."""
     return c_uint.from_buffer(self.bytearray[self._get_slicers(4)]).value
Exemplo n.º 11
0
 def nl_family(self):
     """AF_NETLINK."""
     return c_uint.from_buffer(self.bytearray[self._get_slicers(0)]).value
Exemplo n.º 12
0
Arquivo: netlink.py Projeto: ewa/libnl
 def nl_family(self):
     """AF_NETLINK."""
     return c_uint.from_buffer(self.bytearray[self._get_slicers(0)]).value
Exemplo n.º 13
0
 def ifi_change(self):
     """Message change."""
     return c_uint.from_buffer(self.bytearray[self._get_slicers(5)]).value
Exemplo n.º 14
0
 def ifi_flags(self):
     """Message flags."""
     return c_uint.from_buffer(self.bytearray[self._get_slicers(4)]).value