Example #1
0
 def _run_test_decode_value(self, typ, cases):
     for decoded, encoded in cases:
         value = Decoder.decode(unhexlify(encoded), self.types.as_type(typ))
         if typ in ('float','double'):
             self.assertEqual(str(decoded)[0:8], str(value)[0:8])
         else:
             self.assertEqual(decoded, value)
Example #2
0
 def test_unhexlify(self):
     self.assertEqual(unhexlify(''), b'')
     self.assertEqual(unhexlify('000102'), b'\x00\x01\x02')
     self.assertEqual(unhexlify('ff'), b'\xFF')
Example #3
0
 def test_decode_class_none(self):
     typ = self.types.as_type('Class(ServiceName.ClassName)')
     value = Decoder.decode(unhexlify('00'), typ)
     self.assertIsNone(value)
Example #4
0
 def test_guid(self):
     self.assertEqual('6f271b39-00dd-4de4-9732-f0d3a68838df', Decoder.guid(unhexlify('391b276fdd00e44d9732f0d3a68838df')))
Example #5
0
 def test_decode_value_delimited(self):
     value = Decoder.decode_delimited(unhexlify('02'+'ac02'), self.types.as_type('int32'))
     self.assertEqual(300, value)
Example #6
0
 def test_decode_class(self):
     typ = self.types.as_type('Class(ServiceName.ClassName)')
     value = Decoder.decode(unhexlify('ac02'), typ)
     self.assertTrue(isinstance(value, typ.python_type))
     self.assertEqual(300, value._object_id)
Example #7
0
 def test_decode_size_and_position(self):
     message = '1c'
     size,position = Decoder.decode_size_and_position(unhexlify(message))
     self.assertEqual(28, size)
     self.assertEqual(1, position)
Example #8
0
 def test_decode_message_delimited(self):
     typ = krpc.schema.KRPC.Request
     message = '1c'+'0a0b536572766963654e616d65120d50726f6365647572654e616d65'
     request = Decoder.decode_delimited(unhexlify(message), self.types.as_type('KRPC.Request'))
     self.assertEqual('ServiceName', request.service)
     self.assertEqual('ProcedureName', request.procedure)
Example #9
0
 def test_decode_unicode_string(self):
     value = Decoder.decode(unhexlify('03e284a2'), self.types.as_type('string'))
     self.assertEqual(b'\xe2\x84\xa2'.decode('utf-8'), value)
Example #10
0
 def test_decode_value(self):
     value = Decoder.decode(unhexlify('ac02'), self.types.as_type('int32'))
     self.assertEqual(int(300), value)
Example #11
0
 def test_decode_message(self):
     message = '0a0b536572766963654e616d65120d50726f6365647572654e616d65'
     request = Decoder.decode(unhexlify(message), self.types.as_type('KRPC.Request'))
     self.assertEqual('ServiceName', request.service)
     self.assertEqual('ProcedureName', request.procedure)
Example #12
0
 def test_decode_message(self):
     message = '0a0b536572766963654e616d65120d50726f6365647572654e616d65'
     call = Decoder.decode(
         unhexlify(message), self.types.procedure_call_type)
     self.assertEqual('ServiceName', call.service)
     self.assertEqual('ProcedureName', call.procedure)
Example #13
0
 def test_message_size(self):
     message = '1c'
     size = Decoder.decode_message_size(unhexlify(message))
     self.assertEqual(28, size)