Пример #1
0
 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]
Пример #2
0
 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])
Пример #3
0
 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)