~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test__dirstate_helpers.py

Merge fix for overflow issues in pack_stat from 2.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
    errors,
26
26
    osutils,
27
27
    tests,
 
28
    _dirstate_helpers_py,
28
29
    )
29
30
from bzrlib.tests import (
30
31
    test_dirstate,
1337
1338
        state._sha1_provider = UppercaseSHA1Provider()
1338
1339
        self.assertChangedFileIds(['file-id'], tree)
1339
1340
 
 
1341
 
 
1342
class TestPackStat(tests.TestCase):
 
1343
    """Check packed representaton of stat values is robust on all inputs"""
 
1344
 
 
1345
    # GZ 2011-09-26: Should parametrise against all pack_stat implementations
 
1346
 
 
1347
    @staticmethod
 
1348
    def pack(statlike_tuple):
 
1349
        return dirstate.pack_stat(os.stat_result(statlike_tuple))
 
1350
 
 
1351
    @staticmethod
 
1352
    def unpack_field(packed_string, stat_field):
 
1353
        return _dirstate_helpers_py._unpack_stat(packed_string)[stat_field]
 
1354
 
 
1355
    def test_result(self):
 
1356
        self.assertEqual("AAAQAAAAABAAAAARAAAAAgAAAAEAAIHk",
 
1357
            self.pack((33252, 1, 2, 0, 0, 0, 4096, 15.5, 16.5, 17.5)))
 
1358
 
 
1359
    def test_giant_inode(self):
 
1360
        packed = self.pack((33252, 0xF80000ABC, 0, 0, 0, 0, 0, 0, 0, 0))
 
1361
        self.assertEqual(0x80000ABC, self.unpack_field(packed, "st_ino"))
 
1362
 
 
1363
    def test_giant_size(self):
 
1364
        packed = self.pack((33252, 0, 0, 0, 0, 0, (1 << 33) + 4096, 0, 0, 0))
 
1365
        self.assertEqual(4096, self.unpack_field(packed, "st_size"))
 
1366
 
 
1367
    def test_fractional_mtime(self):
 
1368
        packed = self.pack((33252, 0, 0, 0, 0, 0, 0, 0, 16.9375, 0))
 
1369
        self.assertEqual(16, self.unpack_field(packed, "st_mtime"))
 
1370
 
 
1371
    def test_ancient_mtime(self):
 
1372
        packed = self.pack((33252, 0, 0, 0, 0, 0, 0, 0, -11644473600.0, 0))
 
1373
        self.assertEqual(1240428288, self.unpack_field(packed, "st_mtime"))
 
1374
 
 
1375
    def test_distant_mtime(self):
 
1376
        packed = self.pack((33252, 0, 0, 0, 0, 0, 0, 0, 64060588800.0, 0))
 
1377
        self.assertEqual(3931046656, self.unpack_field(packed, "st_mtime"))
 
1378
 
 
1379
    def test_fractional_ctime(self):
 
1380
        packed = self.pack((33252, 0, 0, 0, 0, 0, 0, 0, 0, 17.5625))
 
1381
        self.assertEqual(17, self.unpack_field(packed, "st_ctime"))
 
1382
 
 
1383
    def test_ancient_ctime(self):
 
1384
        packed = self.pack((33252, 0, 0, 0, 0, 0, 0, 0, 0, -11644473600.0))
 
1385
        self.assertEqual(1240428288, self.unpack_field(packed, "st_ctime"))
 
1386
 
 
1387
    def test_distant_ctime(self):
 
1388
        packed = self.pack((33252, 0, 0, 0, 0, 0, 0, 0, 0, 64060588800.0))
 
1389
        self.assertEqual(3931046656, self.unpack_field(packed, "st_ctime"))
 
1390
 
 
1391
    def test_negative_dev(self):
 
1392
        packed = self.pack((33252, 0, -0xFFFFFCDE, 0, 0, 0, 0, 0, 0, 0))
 
1393
        self.assertEqual(0x322, self.unpack_field(packed, "st_dev"))