Exemplo n.º 1
0
 def test_get_field_name(self):
     length = Length('length-8')
     self.assertEqual(length.field, 'length')
Exemplo n.º 2
0
 def test_trim_field_names(self):
     length = Length('  length - 8  ')
     self.assertEqual(length.field, 'length')
     length = Length('  length +  8  ')
     self.assertEqual(length.field, 'length')
Exemplo n.º 3
0
 def test_dynamic_length_with_multiplier(self):
     length = Length('length*3')
     self.assertEqual(length.calc_value(4), 12)
     self.assertEqual(length.solve_parameter(12), 4)
     self.assertEqual(length.solve_parameter(13), 5)
     self.assertEqual(length.solve_parameter(14), 5)
Exemplo n.º 4
0
 def test_dynamic_length(self):
     length = Length('length')
     self.assertEqual(length.calc_value(18), 18)
     self.assertEqual(length.solve_parameter(18), 18)
Exemplo n.º 5
0
 def test_dynamic_length_with_addition(self):
     length = Length('length+8')
     self.assertEquals(length.calc_value(10), 18)
     self.assertEquals(length.solve_parameter(18), 10)
Exemplo n.º 6
0
 def test_dynamic_length_with_addition(self):
     length = Length('length+8')
     self.assertEqual(length.calc_value(10), 18)
     self.assertEqual(length.solve_parameter(18), 10)
Exemplo n.º 7
0
 def test_create_length_dynamic(self):
     length = Length('length')
     self.assertFalse(length.static)
Exemplo n.º 8
0
 def test_create_length(self):
     length = Length('5')
     self.assertTrue(length.static)
Exemplo n.º 9
0
 def test_decode_static(self):
     stat_len = Length('5')
     self.assertEquals(stat_len.decode(None), 5)
Exemplo n.º 10
0
 def test_decode_dynamic(self):
     msg = Struct('foo', 'foo_type')
     msg['len'] = Field('uint', 'len', to_bin('0x04'))
     dyn_len = Length('len')
     self.assertEquals(dyn_len.decode(msg), 4)
Exemplo n.º 11
0
 def test_decode_dynamic_with_subtractor(self):
     msg = Struct('foo', 'foo_type')
     msg['len'] = Field('uint', 'len', to_bin('0x04'))
     dyn_len = Length('len-2')
     self.assertEquals(dyn_len.decode(msg), 2)
Exemplo n.º 12
0
 def test_dynamic_length(self):
     length = Length('length')
     self.assertEquals(length.calc_value(18), 18)
     self.assertEquals(length.solve_parameter(18), 18)
Exemplo n.º 13
0
 def test_dynamic_length_with_multiplier(self):
     length = Length('length*3')
     self.assertEquals(length.calc_value(4), 12)
     self.assertEquals(length.solve_parameter(12), 4)
     self.assertEquals(length.solve_parameter(13), 5)
     self.assertEquals(length.solve_parameter(14), 5)
Exemplo n.º 14
0
 def test_decode_dynamic_with_subtractor(self):
     msg = Struct('foo', 'foo_type')
     msg['len'] = Field('uint', 'len', to_bin('0x04'))
     dyn_len = Length('len-2')
     self.assertEqual(dyn_len.decode(msg), 2)
Exemplo n.º 15
0
 def test_static_length(self):
     length = Length('5')
     self.assertEqual(length.value, 5)
Exemplo n.º 16
0
 def test_decode_static(self):
     stat_len = Length('5')
     self.assertEqual(stat_len.decode(None), 5)
Exemplo n.º 17
0
 def test_dynamic_length_with_subtractor(self):
     length = Length('length-8')
     self.assertEqual(length.calc_value(18), 10)
     self.assertEqual(length.solve_parameter(10), 18)
Exemplo n.º 18
0
 def _assert_alignment(self, length, alignment, result):
     self.assertEqual(
         Length(length, alignment).decode_lengths(None, None)[1], result)
Exemplo n.º 19
0
 def test_dynamic_length_with_subtractor(self):
     length = Length('length-8')
     self.assertEquals(length.calc_value(18), 10)
     self.assertEquals(length.solve_parameter(10), 18)