@@ -28,6 +28,7 @@ class BitfieldManTest:public CppUnit::TestFixture {
28
28
CPPUNIT_TEST (testGetSparseMissingUnusedIndex_withMinSplitSize);
29
29
CPPUNIT_TEST (testIsBitSetOffsetRange);
30
30
CPPUNIT_TEST (testGetOffsetCompletedLength);
31
+ CPPUNIT_TEST (testGetOffsetCompletedLength_largeFile);
31
32
CPPUNIT_TEST (testGetMissingUnusedLength);
32
33
CPPUNIT_TEST (testSetBitRange);
33
34
CPPUNIT_TEST (testGetAllMissingIndexes);
@@ -62,6 +63,7 @@ class BitfieldManTest:public CppUnit::TestFixture {
62
63
void testGetSparseMissingUnusedIndex_withMinSplitSize ();
63
64
void testIsBitSetOffsetRange ();
64
65
void testGetOffsetCompletedLength ();
66
+ void testGetOffsetCompletedLength_largeFile ();
65
67
void testGetMissingUnusedLength ();
66
68
void testSetBitRange ();
67
69
void testCountFilteredBlock ();
@@ -484,6 +486,26 @@ void BitfieldManTest::testGetOffsetCompletedLength()
484
486
CPPUNIT_ASSERT_EQUAL ((int64_t )0 , bt.getOffsetCompletedLength (1024 *20 , 1 ));
485
487
}
486
488
489
+ void BitfieldManTest::testGetOffsetCompletedLength_largeFile ()
490
+ {
491
+ // Test for overflow on 32-bit systems.
492
+
493
+ // Total 4TiB, 4MiB block
494
+ BitfieldMan bt (1 << 22 , 1LL << 40 );
495
+ bt.setBit (1 << 11 );
496
+ bt.setBit ((1 << 11 )+1 );
497
+ bt.setBit ((1 << 11 )+2 );
498
+
499
+ // The last piece is missing:
500
+ CPPUNIT_ASSERT_EQUAL ((int64_t )bt.getBlockLength ()*3 ,
501
+ bt.getOffsetCompletedLength (1LL << 33 , 1 << 24 ));
502
+
503
+ // The first piece is missing:
504
+ CPPUNIT_ASSERT_EQUAL ((int64_t )bt.getBlockLength ()*3 ,
505
+ bt.getOffsetCompletedLength
506
+ ((1LL << 33 ) - bt.getBlockLength (), 1 << 24 ));
507
+ }
508
+
487
509
void BitfieldManTest::testGetMissingUnusedLength ()
488
510
{
489
511
int64_t totalLength = 1024 *10 +10 ;
0 commit comments