Ejemplo n.º 1
0
 def test_field_output(self):
     a = Field('a', 8)
     b = Sequence('b', [a])
     lookup = ResultParameters([b])
     self.assertEqual([Param('result', Param.OUT, EntryType(a))], lookup.get_params(a))
     self.assertEqual([Param('magic unknown param', Param.OUT, EntryType(a))], lookup.get_passed_variables(b, b.children[0]))
     self.assertEqual([Param('result', Param.OUT, EntryType(b))], lookup.get_params(b))
Ejemplo n.º 2
0
 def test_hidden_entry_visible_child(self):
     # If an entry is hidden, but it has visible children, we want the entry
     # to be hidden regardless.
     a = Field('a', 8)
     b = Sequence('', [a])
     lookup = ResultParameters([b])
     self.assertEqual([], lookup.get_params(b))
     self.assertEqual([], lookup.get_params(a))
Ejemplo n.º 3
0
 def test_visible_common_in_hidden_context(self):
     a = Field('a', 8)
     b = Sequence('b:', [a])
     lookup = ResultParameters([a, b])
     self.assertEqual([Param('result', Param.OUT, EntryType(a))],
             lookup.get_params(a))
     self.assertEqual([], lookup.get_params(b))
     self.assertEqual([Local('unused a', EntryType(a))], lookup.get_locals(b))
     self.assertEqual([Param('unused a', Param.OUT, EntryType(a))],
         lookup.get_passed_variables(b, b.children[0]))
Ejemplo n.º 4
0
 def test_sequence_value(self):
     a = Field('a:', 8, Field.INTEGER)
     b = Sequence('b', [a], parse('${a:}'))
     lookup = ResultParameters([b])
     self.assertEqual([], lookup.get_params(a))
     self.assertEqual([Param('result', Param.OUT, EntryType(b))],
             lookup.get_params(b))
     self.assertEqual([], lookup.get_locals(a))
     self.assertEqual([], lookup.get_locals(b))
     self.assertEqual([], lookup.get_passed_variables(b, b.children[0]))
Ejemplo n.º 5
0
 def test_hidden_reference(self):
     # Test a visible common reference that is hidden through its reference
     # name. This is common for integers defined at the common level.
     #
     # Note that in this case 'b' won't have an output, because all of the
     # fields it defines are hidden, and so doesn't have a type itself.
     a = Field('a', 8, Field.INTEGER)
     b = Sequence('b', [Child('a:', a)])
     lookup = ResultParameters([a, b])
     self.assertEqual([Param('result', Param.OUT, EntryType(a))], lookup.get_params(a))
     self.assertEqual([], lookup.get_params(b))
     self.assertEqual([Local('unused a:', EntryType(a))], lookup.get_locals(b))
     self.assertEqual([Param('unused a:', Param.OUT, EntryType(a))], lookup.get_passed_variables(b, b.children[0]))
Ejemplo n.º 6
0
    def test_recursive_common(self):
        # Test a recursive parser to decode xml style data

        embedded = Sequence('embedded', [])
        digit = Field('data', 8, constraints=[Minimum(ord('0')), Maximum(ord('9'))])
        item = Choice('item', [embedded, digit])
        embedded.children = [
                Field('', length=8, format=Field.TEXT, constraints=[Equals('<')]),
                item,
                Field('', length=8, format=Field.TEXT, constraints=[Equals('>')])]

        # Lets just test that we can decode things correctly...
        list(item.decode(Data('8')))
        list(item.decode(Data('<5>')))
        list(item.decode(Data('<<7>>')))
        self.assertRaises(bdec.DecodeError, list, item.decode(Data('a')))
        self.assertRaises(bdec.DecodeError, list, item.decode(Data('<5')))

        lookup = ResultParameters([item])
        self.assertEqual([Param('result', Param.OUT, EntryType(item))], lookup.get_params(item))
        self.assertEqual([Param('result', Param.OUT, EntryType(embedded))], lookup.get_params(embedded))
Ejemplo n.º 7
0
 def test_hidden_field(self):
     a = Field('', 8)
     lookup = ResultParameters([a])
     self.assertEqual([], lookup.get_params(a))