Beispiel #1
0
 def setUp(self):
     self._protocol = Protocol('TestProtocol')
     self._protocol.add(UInt(2, 'msgId', 5))
     self._protocol.add(UInt(2, 'length', None))
     self._protocol.add(PDU('length-4'))
     self.tmp = MessageTemplate('FooRequest', self._protocol, {})
     self.tmp.add(UInt(2, 'field_1', 1))
     self.tmp.add(UInt(2, 'field_2', 2))
 def setUp(self):
     self._protocol = Protocol('TestProtocol', little_endian=True)
     self._protocol.add(UInt(2, 'msgId', 5))
     self._protocol.add(UInt(2, 'length', None))
     self._protocol.add(PDU('length-4'))
     self.tmp = MessageTemplate('FooRequest', self._protocol, {})
     self.tmp.add(UInt(2, 'field_1', '0xcafe'))
     self.tmp.add(UInt(2, 'field_2', '0xbabe'))
Beispiel #3
0
 def setUp(self):
     self._protocol = Protocol('TestProtocol')
     self._protocol.add(UInt(2, 'msgId', 5))
     self._protocol.add(UInt(2, 'length', None))
     self._protocol.add(PDU('length-4'))
     self.tmp = MessageTemplate('FooRequest', self._protocol, {})
     self.tmp.add(UInt(2, 'field_1', '0xcafe'))
     self.tmp.add(UInt(2, 'field_2', '0xbabe'))
     self.example = self.tmp.encode({}, {})
Beispiel #4
0
 def test_access_struct(self):
     self._protocol = Protocol('TestProtocol')
     self._protocol.add(UInt(2, 'msgId', 5))
     self._protocol.add(UInt(2, 'length', None))
     self._protocol.add(PDU('length-4'))
     self.tmp = MessageTemplate('StructuredRequest', self._protocol, {})
     struct = get_pair()
     self.tmp.add(struct)
     msg = self.tmp.encode({}, {})
     self.assertEquals(msg.pair.first.int, 1)
 def test_verify_calculated_length(self):
     self._protocol.add(UInt(1, 'name1', 1))
     self._protocol.add(UInt(2, 'length', None))
     self._protocol.add(PDU('length-8'))
     self.assertEqual(self._protocol.header_length(), 3)
 def test_verify_undefined_length(self):
     self._protocol.add(UInt(1, 'name1', None))
     self._protocol.add(UInt(2, 'name2', 5))
     self.assertRaises(Exception, self._protocol.add, PDU('length'))
 def test_header_length_with_pdu(self):
     self._protocol.add(UInt(1, 'name1', None))
     self._protocol.add(UInt(2, 'name2', 5))
     self._protocol.add(UInt(2, 'length', None))
     self._protocol.add(PDU('length'))
     self.assertEqual(self._protocol.header_length(), 5)
Beispiel #8
0
 def test_pdu_field_with_subtractor(self):
     field = PDU('value-8')
     self.assertEquals(field.length.field, 'value')
     self.assertEquals(field.length.calc_value(8), 0)
Beispiel #9
0
 def test_pdu_field_without_subtractor(self):
     field = PDU('value')
     self.assertEquals(field.length.field, 'value')
     self.assertEquals(field.length.calc_value(0), 0)
     self.assertEquals(field.type, 'pdu')
Beispiel #10
0
def _get_template():
    protocol = Protocol('Test')
    protocol.add(UInt(1, 'id', 1))
    protocol.add(UInt(2, 'length', None))
    protocol.add(PDU('length-2'))
    return protocol
 def setUp(self):
     self._protocol = Protocol('TestProtocol')
     self._protocol.add(UInt(2, 'msgId', 5))
     self._protocol.add(UInt(2, 'length', None))
     self._protocol.add(PDU('length-4'))