diff options
author | Ilya Etingof <etingof@gmail.com> | 2017-09-08 20:52:36 +0200 |
---|---|---|
committer | Ilya Etingof <etingof@gmail.com> | 2017-09-10 14:29:29 +0200 |
commit | d35f412398a54a93ac141d88c41dac411bd05453 (patch) | |
tree | c36ccc6dfe8e34909922f9cc6e999378a69956f5 /tests | |
parent | c324055b318fa2c01249819c44836214efdfb90e (diff) | |
download | pyasn1-d35f412398a54a93ac141d88c41dac411bd05453.tar.gz |
WIP: hole types implementation
Diffstat (limited to 'tests')
-rw-r--r-- | tests/codec/ber/test_decoder.py | 57 |
1 files changed, 55 insertions, 2 deletions
diff --git a/tests/codec/ber/test_decoder.py b/tests/codec/ber/test_decoder.py index d2f02ad..45cd530 100644 --- a/tests/codec/ber/test_decoder.py +++ b/tests/codec/ber/test_decoder.py @@ -10,7 +10,7 @@ try: except ImportError: import unittest -from pyasn1.type import tag, namedtype, univ, char +from pyasn1.type import tag, namedtype, univ, char, definedby from pyasn1.codec.ber import decoder, eoo from pyasn1.compat.octets import ints2octs, str2octs, null from pyasn1.error import PyAsn1Error @@ -720,7 +720,7 @@ class SequenceDecoderWithSchemaTestCase(unittest.TestCase): def testDefMode(self): self.__init() assert decoder.decode( - ints2octs((48, 128, 5, 0, 0, 0)), asn1Spec=self.s + ints2octs((48, 2, 5, 0)), asn1Spec=self.s ) == (self.s, null) def testIndefMode(self): @@ -823,6 +823,59 @@ class SequenceDecoderWithSchemaTestCase(unittest.TestCase): ) == (self.s, null) +class SequenceDecoderWithIntegerHoleTypesTestCase(unittest.TestCase): + def setUp(self): + definedBy = definedby.DefinedBy( + 'id', + [(1, univ.Integer()), + (2, univ.OctetString())] + ) + self.s = univ.Sequence( + componentType=namedtype.NamedTypes( + namedtype.NamedType('id', univ.Integer()), + namedtype.NamedType('blob', univ.Any(), definedBy=definedBy) + ) + ) + + # def testChoiceOne(self): + # s, r = decoder.decode( + # ints2octs((48, 6, 2, 1, 1, 2, 1, 12)), + # asn1Spec=self.s + # ) + # assert not r + # assert s[0] == 1 + # assert s[1] == ints2octs((2, 1, 12)) + # + # def testChoiceTwo(self): + # s, r = decoder.decode( + # ints2octs((48, 16, 2, 1, 2, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)), + # asn1Spec=self.s + # ) + # assert not r + # assert s[0] == 1 + # assert s[1] == ints2octs((4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)) + + def testChoiceOneResolveHoles(self): + s, r = decoder.decode( + ints2octs((48, 6, 2, 1, 1, 2, 1, 12)), asn1Spec=self.s +# TODO +# resolveHoleTypes=True + ) + assert not r + assert s[0] == 1 + assert s[1] == 12 + + def testChoiceTwoResolveHoles(self): + s, r = decoder.decode( + ints2octs((48, 16, 2, 1, 2, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)), asn1Spec=self.s +# TODO +# resolveHoleTypes = True + ) + assert not r + assert s[0] == 2 + assert s[1] == univ.OctetString('quick brown') + + class SetDecoderTestCase(unittest.TestCase): def setUp(self): self.s = univ.Set( |