33
33
('python', {'_gc_module': _groupcompress_py}),
35
if CompiledGroupCompressFeature.available():
36
from bzrlib import _groupcompress_pyx
35
if compiled_groupcompress_feature.available():
36
gc_module = compiled_groupcompress_feature.module
37
37
scenarios.append(('C',
38
{'_gc_module': _groupcompress_pyx}))
38
{'_gc_module': gc_module}))
39
39
two_way_scenarios.extend([
40
('CC', {'make_delta': _groupcompress_pyx.make_delta,
41
'apply_delta': _groupcompress_pyx.apply_delta}),
40
('CC', {'make_delta': gc_module.make_delta,
41
'apply_delta': gc_module.apply_delta}),
42
42
('PC', {'make_delta': _groupcompress_py.make_delta,
43
'apply_delta': _groupcompress_pyx.apply_delta}),
44
('CP', {'make_delta': _groupcompress_pyx.make_delta,
43
'apply_delta': gc_module.apply_delta}),
44
('CP', {'make_delta': gc_module.make_delta,
45
45
'apply_delta': _groupcompress_py.apply_delta}),
47
47
to_adapt, result = tests.split_suite_by_condition(
186
173
'N\x90\x1d\x1ewhich is meant to differ from\n\x91:\x13',
176
def test_make_delta_with_large_copies(self):
177
# We want to have a copy that is larger than 64kB, which forces us to
178
# issue multiple copy instructions.
179
big_text = _text3 * 1220
180
delta = self.make_delta(big_text, big_text)
182
'\xdc\x86\x0a' # Encoding the length of the uncompressed text
183
'\x80' # Copy 64kB, starting at byte 0
184
'\x84\x01' # and another 64kB starting at 64kB
185
'\xb4\x02\x5c\x83', # And the bit of tail.
186
None, # Both implementations should be identical
189
189
def test_apply_delta_is_typesafe(self):
190
190
self.apply_delta(_text1, 'M\x90M')
191
191
self.assertRaises(TypeError, self.apply_delta, object(), 'M\x90M')
251
251
# This test isn't multiplied, because we only have DeltaIndex for the
253
253
# We call this here, because _test_needs_features happens after setUp
254
self.requireFeature(CompiledGroupCompressFeature)
255
from bzrlib import _groupcompress_pyx
256
self._gc_module = _groupcompress_pyx
254
self.requireFeature(compiled_groupcompress_feature)
255
self._gc_module = compiled_groupcompress_feature.module
258
257
def test_repr(self):
259
258
di = self._gc_module.DeltaIndex('test text\n')
260
259
self.assertEqual('DeltaIndex(1, 10)', repr(di))
261
def test_first_add_source_doesnt_index_until_make_delta(self):
262
di = self._gc_module.DeltaIndex()
263
self.assertFalse(di._has_index())
264
di.add_source(_text1, 0)
265
self.assertFalse(di._has_index())
266
# However, asking to make a delta will trigger the index to be
267
# generated, and will generate a proper delta
268
delta = di.make_delta(_text2)
269
self.assertTrue(di._has_index())
270
self.assertEqual('N\x90/\x1fdiffer from\nagainst other text\n', delta)
272
def test_second_add_source_triggers_make_index(self):
273
di = self._gc_module.DeltaIndex()
274
self.assertFalse(di._has_index())
275
di.add_source(_text1, 0)
276
self.assertFalse(di._has_index())
277
di.add_source(_text2, 0)
278
self.assertTrue(di._has_index())
262
280
def test_make_delta(self):
263
281
di = self._gc_module.DeltaIndex(_text1)
264
282
delta = di.make_delta(_text2)
358
376
self.assertEqual((exp_offset, exp_length, exp_newpos), out)
360
378
def test_encode_no_length(self):
361
self.assertEncode('\x80', 0, None)
362
self.assertEncode('\x81\x01', 1, None)
363
self.assertEncode('\x81\x0a', 10, None)
364
self.assertEncode('\x81\xff', 255, None)
365
self.assertEncode('\x82\x01', 256, None)
366
self.assertEncode('\x83\x01\x01', 257, None)
367
self.assertEncode('\x8F\xff\xff\xff\xff', 0xFFFFFFFF, None)
368
self.assertEncode('\x8E\xff\xff\xff', 0xFFFFFF00, None)
369
self.assertEncode('\x8D\xff\xff\xff', 0xFFFF00FF, None)
370
self.assertEncode('\x8B\xff\xff\xff', 0xFF00FFFF, None)
371
self.assertEncode('\x87\xff\xff\xff', 0x00FFFFFF, None)
372
self.assertEncode('\x8F\x04\x03\x02\x01', 0x01020304, None)
379
self.assertEncode('\x80', 0, 64*1024)
380
self.assertEncode('\x81\x01', 1, 64*1024)
381
self.assertEncode('\x81\x0a', 10, 64*1024)
382
self.assertEncode('\x81\xff', 255, 64*1024)
383
self.assertEncode('\x82\x01', 256, 64*1024)
384
self.assertEncode('\x83\x01\x01', 257, 64*1024)
385
self.assertEncode('\x8F\xff\xff\xff\xff', 0xFFFFFFFF, 64*1024)
386
self.assertEncode('\x8E\xff\xff\xff', 0xFFFFFF00, 64*1024)
387
self.assertEncode('\x8D\xff\xff\xff', 0xFFFF00FF, 64*1024)
388
self.assertEncode('\x8B\xff\xff\xff', 0xFF00FFFF, 64*1024)
389
self.assertEncode('\x87\xff\xff\xff', 0x00FFFFFF, 64*1024)
390
self.assertEncode('\x8F\x04\x03\x02\x01', 0x01020304, 64*1024)
374
392
def test_encode_no_offset(self):
375
393
self.assertEncode('\x90\x01', 0, 1)