@ -20,7 +20,10 @@
# include "PartitionSize.h"
Q_DECLARE_METATYPE ( Calamares : : SizeUnit )
using SizeUnit = CalamaresUtils : : Partition : : SizeUnit ;
using PartitionSize = CalamaresUtils : : Partition : : PartitionSize ;
Q_DECLARE_METATYPE ( SizeUnit )
# include "utils/Logger.h"
@ -41,28 +44,26 @@ PartitionSizeTests::initTestCase()
{
}
void
void
PartitionSizeTests : : testUnitComparison_data ( )
{
QTest : : addColumn < Calamares: : SizeUnit> ( " u1 " ) ;
QTest : : addColumn < Calamares: : SizeUnit> ( " u2 " ) ;
QTest : : addColumn < SizeUnit> ( " u1 " ) ;
QTest : : addColumn < SizeUnit> ( " u2 " ) ;
QTest : : addColumn < bool > ( " comparable " ) ;
using Calamares : : SizeUnit ;
QTest : : newRow ( " nones " ) < < SizeUnit : : None < < SizeUnit : : None < < false ;
QTest : : newRow ( " none+% " ) < < SizeUnit : : None < < SizeUnit : : Percent < < false ;
QTest : : newRow ( " %+none " ) < < SizeUnit : : Percent < < SizeUnit : : None < < false ;
QTest : : newRow ( " KiB+none " ) < < SizeUnit : : KiB < < SizeUnit : : None < < false ;
QTest : : newRow ( " none+MiB " ) < < SizeUnit : : None < < SizeUnit : : MiB < < false ;
QTest : : newRow ( " KiB+KiB " ) < < SizeUnit : : KiB < < SizeUnit : : KiB < < true ;
QTest : : newRow ( " KiB+MiB " ) < < SizeUnit : : KiB < < SizeUnit : : MiB < < true ;
QTest : : newRow ( " KiB+GiB " ) < < SizeUnit : : KiB < < SizeUnit : : GiB < < true ;
QTest : : newRow ( " MiB+MiB " ) < < SizeUnit : : MiB < < SizeUnit : : MiB < < true ;
QTest : : newRow ( " MiB+GiB " ) < < SizeUnit : : MiB < < SizeUnit : : GiB < < true ;
QTest : : newRow ( " GiB+GiB " ) < < SizeUnit : : GiB < < SizeUnit : : GiB < < true ;
QTest : : newRow ( " %+None " ) < < SizeUnit : : Percent < < SizeUnit : : None < < false ;
QTest : : newRow ( " %+% " ) < < SizeUnit : : Percent < < SizeUnit : : Percent < < true ;
QTest : : newRow ( " %+KiB " ) < < SizeUnit : : Percent < < SizeUnit : : KiB < < false ;
@ -70,53 +71,51 @@ PartitionSizeTests::testUnitComparison_data()
static bool
original_compare ( Calamares: : SizeUnit m_unit , Calamares : : SizeUnit other_m_unit )
original_compare ( SizeUnit m_unit , SizeUnit other_m_unit )
{
if ( ( m_unit = = Calamares: : SizeUnit: : None | | other_m_unit = = Calamares : : SizeUnit : : None ) | |
( m_unit = = Calamares: : SizeUnit: : Percent & & other_m_unit ! = Calamares : : SizeUnit : : Percent ) | |
( m_unit ! = Calamares: : SizeUnit: : Percent & & other_m_unit = = Calamares : : SizeUnit : : Percent ) )
if ( ( m_unit = = SizeUnit: : None | | other_m_unit = = SizeUnit : : None ) | |
( m_unit = = SizeUnit: : Percent & & other_m_unit ! = SizeUnit : : Percent ) | |
( m_unit ! = SizeUnit: : Percent & & other_m_unit = = SizeUnit : : Percent ) )
return false ;
return true ;
}
void
void
PartitionSizeTests : : testUnitComparison ( )
{
QFETCH ( Calamares: : SizeUnit, u1 ) ;
QFETCH ( Calamares: : SizeUnit, u2 ) ;
QFETCH ( SizeUnit, u1 ) ;
QFETCH ( SizeUnit, u2 ) ;
QFETCH ( bool , comparable ) ;
if ( comparable )
{
QVERIFY ( Calamares: : PartitionSize: : unitsComparable ( u1 , u2 ) ) ;
QVERIFY ( Calamares: : PartitionSize: : unitsComparable ( u2 , u1 ) ) ;
QVERIFY ( PartitionSize: : unitsComparable ( u1 , u2 ) ) ;
QVERIFY ( PartitionSize: : unitsComparable ( u2 , u1 ) ) ;
}
else
{
QVERIFY ( ! Calamares: : PartitionSize: : unitsComparable ( u1 , u2 ) ) ;
QVERIFY ( ! Calamares: : PartitionSize: : unitsComparable ( u2 , u1 ) ) ;
QVERIFY ( ! PartitionSize: : unitsComparable ( u1 , u2 ) ) ;
QVERIFY ( ! PartitionSize: : unitsComparable ( u2 , u1 ) ) ;
}
QCOMPARE ( original_compare ( u1 , u2 ) , Calamares: : PartitionSize: : unitsComparable ( u1 , u2 ) ) ;
QCOMPARE ( original_compare ( u1 , u2 ) , PartitionSize: : unitsComparable ( u1 , u2 ) ) ;
}
void
void
PartitionSizeTests : : testUnitNormalisation_data ( )
{
QTest : : addColumn < Calamares: : SizeUnit> ( " u1 " ) ;
QTest : : addColumn < SizeUnit> ( " u1 " ) ;
QTest : : addColumn < int > ( " v " ) ;
QTest : : addColumn < long > ( " bytes " ) ;
using Calamares : : SizeUnit ;
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 ;
@ -134,12 +133,12 @@ PartitionSizeTests::testUnitNormalisation_data()
QTest : : newRow ( " GiB " ) < < SizeUnit : : GiB < < 2 < < 2048 * 1024 * 1024L ;
}
void
void
PartitionSizeTests : : testUnitNormalisation ( )
{
QFETCH ( Calamares: : SizeUnit, u1 ) ;
QFETCH ( SizeUnit, u1 ) ;
QFETCH ( int , v ) ;
QFETCH ( long , bytes ) ;
QCOMPARE ( Calamares: : PartitionSize( v , u1 ) . toBytes ( ) , static_cast < qint64 > ( bytes ) ) ;
QCOMPARE ( PartitionSize( v , u1 ) . toBytes ( ) , static_cast < qint64 > ( bytes ) ) ;
}