[libcalamares] Fix tests on 32-bit platforms
- The size of a 2GiB partition (in bytes) is larger than the largest 32-bit signed integer; we hit signed overflow while calculating 2^11 * 2^10 * 2^10 and the test fails. - Switch the whole table of sizes to qint64 instead. - For testing purposes only, introduce a _qi suffix for qint64. FIXES #1430
This commit is contained in:
parent
713774ab40
commit
55abe0247b
@ -1,5 +1,5 @@
|
||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||
*
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2019 Adriaan de Groot <groot@kde.org>
|
||||
*
|
||||
* Calamares is free software: you can redistribute it and/or modify
|
||||
@ -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::addColumn< qint64 >( "bytes" );
|
||||
|
||||
QTest::newRow( "none" ) << SizeUnit::None << 16 << -1L;
|
||||
QTest::newRow( "none" ) << SizeUnit::None << 0 << -1L;
|
||||
QTest::newRow( "none" ) << SizeUnit::None << -2 << -1L;
|
||||
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 << -1L;
|
||||
QTest::newRow( "percent" ) << SizeUnit::Percent << 16 << -1L;
|
||||
QTest::newRow( "percent" ) << SizeUnit::Percent << -2 << -1L;
|
||||
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 << -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( "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 << -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( "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 << -1L;
|
||||
QTest::newRow( "GiB" ) << SizeUnit::GiB << 1 << 1024 * 1024 * 1024L;
|
||||
QTest::newRow( "GiB" ) << SizeUnit::GiB << 2 << 2048 * 1024 * 1024L;
|
||||
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 );
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user