@ -103,36 +103,43 @@ PartitionSizeTests::testUnitComparison()
QCOMPARE ( original_compare ( u1 , u2 ) , PartitionSize : : unitsComparable ( u1 , u2 ) ) ;
}
/* Operator to make the table in testUnitNormalisation_data easier to write */
constexpr qint64 operator " " _qi ( unsigned long long m )
{
return qint64 ( m ) ;
}
void
PartitionSizeTests : : testUnitNormalisation_data ( )
{
QTest : : addColumn < SizeUnit > ( " u1 " ) ;
QTest : : addColumn < int > ( " v " ) ;
QTest : : addColumn < long > ( " bytes " ) ;
QTest : : newRow ( " none " ) < < SizeUnit : : None < < 16 < < - 1L ;
QTest : : newRow ( " none " ) < < SizeUnit : : None < < 0 < < - 1L ;
QTest : : newRow ( " none " ) < < SizeUnit : : None < < - 2 < < - 1L ;
QTest : : newRow ( " percent " ) < < SizeUnit : : Percent < < 0 < < - 1L ;
QTest : : newRow ( " percent " ) < < SizeUnit : : Percent < < 16 < < - 1L ;
QTest : : newRow ( " percent " ) < < SizeUnit : : Percent < < - 2 < < - 1L ;
QTest : : newRow ( " KiB " ) < < SizeUnit : : KiB < < 0 < < - 1L ;
QTest : : newRow ( " KiB " ) < < SizeUnit : : KiB < < 1 < < 1024L ;
QTest : : newRow ( " KiB " ) < < SizeUnit : : KiB < < 1000 < < 1024000L ;
QTest : : newRow ( " KiB " ) < < SizeUnit : : KiB < < 1024 < < 1024 * 1024L ;
QTest : : newRow ( " KiB " ) < < SizeUnit : : KiB < < - 2 < < - 1L ;
QTest : : newRow ( " MiB " ) < < SizeUnit : : MiB < < 0 < < - 1L ;
QTest : : newRow ( " MiB " ) < < SizeUnit : : MiB < < 1 < < 1024 * 1024L ;
QTest : : newRow ( " MiB " ) < < SizeUnit : : MiB < < 1000 < < 1024 * 1024000L ;
QTest : : newRow ( " MiB " ) < < SizeUnit : : MiB < < 1024 < < 1024 * 1024 * 1024L ;
QTest : : newRow ( " MiB " ) < < SizeUnit : : MiB < < - 2 < < - 1L ;
QTest : : newRow ( " GiB " ) < < SizeUnit : : GiB < < 0 < < - 1L ;
QTest : : newRow ( " GiB " ) < < SizeUnit : : GiB < < 1 < < 1024 * 1024 * 1024L ;
QTest : : newRow ( " GiB " ) < < SizeUnit : : GiB < < 2 < < 2048 * 1024 * 1024L ;
QTest : : addColumn < qint64 > ( " bytes " ) ;
QTest : : newRow ( " none " ) < < SizeUnit : : None < < 16 < < - 1 _qi ;
QTest : : newRow ( " none " ) < < SizeUnit : : None < < 0 < < - 1 _qi ;
QTest : : newRow ( " none " ) < < SizeUnit : : None < < - 2 < < - 1 _qi ;
QTest : : newRow ( " percent " ) < < SizeUnit : : Percent < < 0 < < - 1 _qi ;
QTest : : newRow ( " percent " ) < < SizeUnit : : Percent < < 16 < < - 1 _qi ;
QTest : : newRow ( " percent " ) < < SizeUnit : : Percent < < - 2 < < - 1 _qi ;
QTest : : newRow ( " KiB " ) < < SizeUnit : : KiB < < 0 < < - 1 _qi ;
QTest : : newRow ( " KiB " ) < < SizeUnit : : KiB < < 1 < < 1024 _qi ;
QTest : : newRow ( " KiB " ) < < SizeUnit : : KiB < < 1000 < < 1024000 _qi ;
QTest : : newRow ( " KiB " ) < < SizeUnit : : KiB < < 1024 < < 1024 * 1024 _qi ;
QTest : : newRow ( " KiB " ) < < SizeUnit : : KiB < < - 2 < < - 1 _qi ;
QTest : : newRow ( " MiB " ) < < SizeUnit : : MiB < < 0 < < - 1 _qi ;
QTest : : newRow ( " MiB " ) < < SizeUnit : : MiB < < 1 < < 1024 * 1024 _qi ;
QTest : : newRow ( " MiB " ) < < SizeUnit : : MiB < < 1000 < < 1024 * 1024000 _qi ;
QTest : : newRow ( " MiB " ) < < SizeUnit : : MiB < < 1024 < < 1024 * 1024 * 1024 _qi ;
QTest : : newRow ( " MiB " ) < < SizeUnit : : MiB < < - 2 < < - 1 _qi ;
QTest : : newRow ( " GiB " ) < < SizeUnit : : GiB < < 0 < < - 1 _qi ;
QTest : : newRow ( " GiB " ) < < SizeUnit : : GiB < < 1 < < 1024 _qi * 1024 * 1024 _qi ;
// This one overflows 32-bits, which is why we want 64-bits for the whole table
QTest : : newRow ( " GiB " ) < < SizeUnit : : GiB < < 2 < < 2048 _qi * 1024 * 1024 _qi ;
}
void
@ -140,7 +147,7 @@ PartitionSizeTests::testUnitNormalisation()
{
QFETCH ( SizeUnit , u1 ) ;
QFETCH ( int , v ) ;
QFETCH ( long , bytes ) ;
QFETCH ( qint64 , bytes ) ;
QCOMPARE ( PartitionSize ( v , u1 ) . toBytes ( ) , static_cast < qint64 > ( bytes ) ) ;
QCOMPARE ( PartitionSize ( v , u1 ) . toBytes ( ) , bytes ) ;
}