コード例 #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))
コード例 #2
0
 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'))
コード例 #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({}, {})
コード例 #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)
コード例 #5
0
 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)
コード例 #6
0
 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'))
コード例 #7
0
 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)
コード例 #8
0
ファイル: test_primitives.py プロジェクト: yahman72/Rammbock
 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)
コード例 #9
0
ファイル: test_primitives.py プロジェクト: yahman72/Rammbock
 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')
コード例 #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
コード例 #11
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'))