~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bencode.py

  • Committer: Jelmer Vernooij
  • Date: 2009-05-28 01:28:44 UTC
  • mto: (4398.5.1 bencode_serializer)
  • mto: This revision was merged to the branch mainline in revision 4410.
  • Revision ID: jelmer@samba.org-20090528012844-ico452ygxwwcvr4z
add handling of deep nesting.

Show diffs side-by-side

added added

removed removed

Lines of Context:
110
110
        self._check(['asd', 'xy'], 'l3:asd2:xye')
111
111
        self._check([['Alice', 'Bob'], [2, 3]], 'll5:Alice3:Bobeli2ei3eee')
112
112
 
 
113
    def test_list_deepnested(self):
 
114
        self._run_check_error(RuntimeError, ("l" * 10000) + ("e" * 10000))
 
115
 
113
116
    def test_malformed_list(self):
114
117
        self._run_check_error(ValueError, 'l')
115
118
        self._run_check_error(ValueError, 'l01:ae')
124
127
        self._check({'spam.mp3': {'author': 'Alice', 'length': 100000}},
125
128
                            'd8:spam.mp3d6:author5:Alice6:lengthi100000eee')
126
129
 
 
130
    def test_dict_deepnested(self):
 
131
        self._run_check_error(RuntimeError, ("d0:" * 10000) + 'i1e' + ("e" * 10000))
 
132
 
127
133
    def test_malformed_dict(self):
128
134
        self._run_check_error(ValueError, 'd')
129
135
        self._run_check_error(ValueError, 'defoobar')
189
195
        self._check('li1ei2ei3ee', (1, 2, 3))
190
196
        self._check('ll5:Alice3:Bobeli2ei3eee', (('Alice', 'Bob'), (2, 3)))
191
197
 
 
198
    def test_list_deep_nested(self):
 
199
        top = []
 
200
        l = top
 
201
        for i in range(10000):
 
202
            l.append([])
 
203
            l = l[0]
 
204
        self.assertRaises(RuntimeError, self.bencode.bencode, 
 
205
            top)
 
206
 
192
207
    def test_dict(self):
193
208
        self._check('de', {})
194
209
        self._check('d3:agei25e4:eyes4:bluee', {'age': 25, 'eyes': 'blue'})
196
211
                            {'spam.mp3': {'author': 'Alice',
197
212
                                          'length': 100000}})
198
213
 
 
214
    def test_dict_deep_nested(self):
 
215
        d = top = {}
 
216
        for i in range(10000):
 
217
            d[''] = {}
 
218
            d = d['']
 
219
        self.assertRaises(RuntimeError, self.bencode.bencode, 
 
220
            top)
 
221
 
199
222
    def test_bencached(self):
200
223
        self._check('i3e', self.bencode.Bencached(self.bencode.bencode(3)))
201
224