예제 #1
0
파일: test_coding.py 프로젝트: jetty840/s3g
 def test_unpack_response(self):
   expected_data = [1,'a','b','c']
   b = bytearray()
   b.extend(Encoder.encode_uint32(1))
   for data in expected_data[1:]:
     b.append(data)
   data = Encoder.unpack_response('<Iccc',b)
   for i in range(0, len(expected_data)):
     assert(data[i] == expected_data[i])
예제 #2
0
파일: test_coding.py 프로젝트: jetty840/s3g
 def test_unpack_response_with_string(self):
   expected_data = [1, 'a', 'b', 'c', 'ABCDE\x00']
   b = bytearray()
   b.extend(Encoder.encode_uint32(1))
   for data in expected_data[1:-1]:
     b.append(data)
   b.extend(expected_data[-1])
   data = Encoder.unpack_response_with_string('<Iccc',b)
   for expected, d in zip(expected_data, data):
     self.assertEqual(expected, d)
예제 #3
0
파일: test_coding.py 프로젝트: jetty840/s3g
 def test_unpack_response_with_string_no_format(self):
   expected_string = 'abcde\x00'
   b = bytearray()
   b.extend(expected_string)
   data = Encoder.unpack_response_with_string('',b)
   assert(len(data) == 1)
   assert data[0] == expected_string
예제 #4
0
파일: test_coding.py 프로젝트: jetty840/s3g
 def test_decode_bitfield(self):
   cases = [
     [[True for i in range(8)], 255],
     [[False for i in range(8)], 0],
     [[True, False, True, False, True, False, True, False], 85],
     ]
   for case in cases:
     self.assertEqual(case[0], Encoder.decode_bitfield(case[1]))
예제 #5
0
파일: test_coding.py 프로젝트: jetty840/s3g
 def test_encode_int32(self):
   cases = [
     [0,            '\x00\x00\x00\x00'],
     [-2147483648,  '\x00\x00\x00\x80'],
     [2147483647,   '\xFF\xFF\xFF\x7F'],
   ]
   for case in cases:
     assert Encoder.encode_int32(case[0]) == case[1]
예제 #6
0
파일: test_coding.py 프로젝트: jetty840/s3g
 def test_decode_uint16(self):
   cases = [
     [0,       '\x00\x00'],
     [32767,   '\xFF\x7F'],
     [65535,   '\xFF\xFF'],
   ]
   for case in cases:
     self.assertEqual(Encoder.decode_uint16(case[1]), case[0])
예제 #7
0
파일: test_coding.py 프로젝트: jetty840/s3g
 def test_decode_uint16_bytearray(self):
   byteArrayCases = [
     [0,       bytearray('\x00\x00')],
     [32767,   bytearray('\xff\x7f')],
     [65535,   bytearray('\xff\xff')],
   ]
   for case in byteArrayCases:
     self.assertEqual(Encoder.decode_uint16(case[1]), case[0])
예제 #8
0
파일: test_coding.py 프로젝트: jetty840/s3g
 def test_decode_int32_bytearray(self):
   cases = [
     [0, bytearray('\x00\x00\x00\x00')],
     [-65536,  '\x00\x00\xFF\xFF'],
     [16,      '\x10\x00\x00\x00'],
   ]
   for case in cases:
     self.assertEqual(case[0], Encoder.decode_int32(case[1]))
예제 #9
0
파일: test_coding.py 프로젝트: jetty840/s3g
 def test_encode_uint16(self):
   cases = [
     [0,       '\x00\x00'],
     [32767,   '\xFF\x7F'],
     [65535,   '\xFF\xFF'],
   ]
   for case in cases:
     assert Encoder.encode_uint16(case[0]) == case[1]
예제 #10
0
파일: test_coding.py 프로젝트: jetty840/s3g
 def test_encode_uint32(self):
   cases = [
     [0,            '\x00\x00\x00\x00'],
     [2147483647,   '\xFF\xFF\xFF\x7F'],
     [4294967295,   '\xFF\xFF\xFF\xFF'],
   ]
   for case in cases:
     assert Encoder.encode_uint32(case[0]) == case[1]
예제 #11
0
파일: test_packet.py 프로젝트: jetty840/s3g
  def test_got_payload(self):
    expected_payload = bytearray('abcde')

    packet = bytearray()
    packet.append(constants.header)
    packet.append(len(expected_payload))
    packet.extend(expected_payload)
    packet.append(Encoder.CalculateCRC(expected_payload))

    payload = Encoder.decode_packet(packet)
    assert payload == expected_payload
예제 #12
0
파일: test_coding.py 프로젝트: jetty840/s3g
 def test_encode_axes(self):
   cases = [
     [['X', 'Y', 'Z', 'A', 'B'], 0x1F],
     [['x','y','z','a','b'], 0x1F],
     [['x'],                 0x01],
     [['y'],                 0x02],
     [['z'],                 0x04],
     [['a'],                 0x08],
     [['b'],                 0x10],
     [[],                    0x00],
   ]
   for case in cases:
     assert Encoder.encode_axes(case[0]) == case[1]
예제 #13
0
파일: test_packet.py 프로젝트: jetty840/s3g
 def test_packet_crc(self):
   payload = 'abcd'
   packet = Encoder.encode_payload(payload)
   assert packet[6] == Encoder.CalculateCRC(payload);
예제 #14
0
파일: test_packet.py 프로젝트: jetty840/s3g
 def test_packet_length_field(self):
   payload = 'abcd'
   packet = Encoder.encode_payload(payload)
   assert packet[1] == len(payload)
예제 #15
0
파일: test_packet.py 프로젝트: jetty840/s3g
  def test_packet_header(self):
    payload = 'abcd'
    packet = Encoder.encode_payload(payload)

    assert packet[0] == constants.header
예제 #16
0
파일: test_packet.py 프로젝트: jetty840/s3g
 def test_packet_length(self):
   payload = 'abcd'
   packet = Encoder.encode_payload(payload)
   assert len(packet) == len(payload) + 3
예제 #17
0
파일: test_coding.py 프로젝트: jetty840/s3g
 def test_unpack_response_with_string_empty_string(self):
   expected_string = '\x00'
   b = bytearray()
   b.append(expected_string)
   data = Encoder.unpack_response_with_string('', b)
   self.assertEqual(expected_string, data[0])