Example #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
Example #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
Example #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
Example #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
Example #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
Example #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
Example #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
Example #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
Example #9
0
 def ifi_change(self):
     """Message change."""
     return c_uint.from_buffer(self.bytearray[self._get_slicers(5)]).value
Example #10
0
 def ifi_flags(self):
     """Message flags."""
     return c_uint.from_buffer(self.bytearray[self._get_slicers(4)]).value
Example #11
0
 def nl_family(self):
     """AF_NETLINK."""
     return c_uint.from_buffer(self.bytearray[self._get_slicers(0)]).value
Example #12
0
File: netlink.py Project: ewa/libnl
 def nl_family(self):
     """AF_NETLINK."""
     return c_uint.from_buffer(self.bytearray[self._get_slicers(0)]).value
Example #13
0
 def ifi_change(self):
     """Message change."""
     return c_uint.from_buffer(self.bytearray[self._get_slicers(5)]).value
Example #14
0
 def ifi_flags(self):
     """Message flags."""
     return c_uint.from_buffer(self.bytearray[self._get_slicers(4)]).value