[libcalamares] Update partition service tests

- Use long so that 2GiB fits in the values
 - Document special case of 0[KMG]iB
This commit is contained in:
Adriaan de Groot 2019-05-13 13:38:30 +02:00
parent 7a368dc1d7
commit 72e1a36752
2 changed files with 23 additions and 22 deletions

View File

@ -92,7 +92,8 @@ public:
/** @brief Convert the size to bytes.
*
* This method is only valid for sizes in Bytes, KiB, MiB or GiB.
* It will return -1 in any other case.
* It will return -1 in any other case. Note that 0KiB and 0MiB and
* 0GiB are considered **invalid** sizes and return -1.
*
* @return the size in bytes, or -1 if it cannot be calculated.
*/

View File

@ -105,33 +105,33 @@ PartitionSizeTests::testUnitNormalisation_data()
{
QTest::addColumn<Calamares::SizeUnit>("u1");
QTest::addColumn<int>("v");
QTest::addColumn<int>("bytes");
QTest::addColumn<long>("bytes");
using Calamares::SizeUnit;
QTest::newRow("none") << SizeUnit::None << 16 << -1;
QTest::newRow("none") << SizeUnit::None << 0 << -1;
QTest::newRow("none") << SizeUnit::None << -2 << -1;
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 << -1;
QTest::newRow("percent") << SizeUnit::Percent << 16 << -1;
QTest::newRow("percent") << SizeUnit::Percent << -2 << -1;
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 << 0;
QTest::newRow("KiB") << SizeUnit::KiB << 1 << 1024;
QTest::newRow("KiB") << SizeUnit::KiB << 1000 << 1024000;
QTest::newRow("KiB") << SizeUnit::KiB << 1024 << 1024 * 1024;
QTest::newRow("KiB") << SizeUnit::KiB << -2 << -1;
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 << 0;
QTest::newRow("MiB") << SizeUnit::MiB << 1 << 1024 * 1024;
QTest::newRow("MiB") << SizeUnit::MiB << 1000 << 1024 * 1024000;
QTest::newRow("MiB") << SizeUnit::MiB << 1024 << 1024 * 1024 * 1024;
QTest::newRow("MiB") << SizeUnit::MiB << -2 << -1;
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 << 0;
QTest::newRow("GiB") << SizeUnit::GiB << 1 << 1024 * 1024 * 1024;
QTest::newRow("GiB") << SizeUnit::GiB << 2 << 2 * 1024 * 1024 * 1024;
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;
}
void
@ -139,7 +139,7 @@ PartitionSizeTests::testUnitNormalisation()
{
QFETCH( Calamares::SizeUnit, u1 );
QFETCH( int, v );
QFETCH( int, bytes );
QFETCH( long, bytes );
QCOMPARE( Calamares::PartitionSize( v, u1 ).toBytes(), static_cast<qint64>( bytes ) );
}