Merge branch 'clang-warnings'
This commit is contained in:
commit
63507801b7
@ -193,6 +193,7 @@ if( CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
|
|||||||
)
|
)
|
||||||
string( APPEND CMAKE_CXX_FLAGS " ${CLANG_WARNINGS}" )
|
string( APPEND CMAKE_CXX_FLAGS " ${CLANG_WARNINGS}" )
|
||||||
endforeach()
|
endforeach()
|
||||||
|
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNOTREACHED='//'" )
|
||||||
|
|
||||||
# Third-party code where we don't care so much about compiler warnings
|
# Third-party code where we don't care so much about compiler warnings
|
||||||
# (because it's uncomfortable to patch) get different flags; use
|
# (because it's uncomfortable to patch) get different flags; use
|
||||||
@ -211,12 +212,15 @@ if( CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
|
|||||||
set( CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined" )
|
set( CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined" )
|
||||||
|
|
||||||
set( CALAMARES_AUTOMOC_OPTIONS "-butils/moc-warnings.h" )
|
set( CALAMARES_AUTOMOC_OPTIONS "-butils/moc-warnings.h" )
|
||||||
|
set( CALAMARES_AUTOUIC_OPTIONS --include utils/moc-warnings.h )
|
||||||
else()
|
else()
|
||||||
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--no-undefined" )
|
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--no-undefined" )
|
||||||
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--fatal-warnings -Wnon-virtual-dtor -Woverloaded-virtual -Werror=return-type" )
|
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--fatal-warnings -Wnon-virtual-dtor -Woverloaded-virtual -Werror=return-type" )
|
||||||
|
|
||||||
set( SUPPRESS_3RDPARTY_WARNINGS "" )
|
set( SUPPRESS_3RDPARTY_WARNINGS "" )
|
||||||
set( SUPPRESS_BOOST_WARNINGS "" )
|
set( SUPPRESS_BOOST_WARNINGS "" )
|
||||||
|
|
||||||
|
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNOTREACHED='__builtin_unreachable();'" )
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Use mark_thirdparty_code() to reduce warnings from the compiler
|
# Use mark_thirdparty_code() to reduce warnings from the compiler
|
||||||
|
@ -61,11 +61,6 @@ function(calamares_add_library)
|
|||||||
include_directories(${CMAKE_CURRENT_LIST_DIR})
|
include_directories(${CMAKE_CURRENT_LIST_DIR})
|
||||||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||||
|
|
||||||
if(LIBRARY_UI)
|
|
||||||
qt5_wrap_ui(LIBRARY_UI_SOURCES ${LIBRARY_UI})
|
|
||||||
list(APPEND LIBRARY_SOURCES ${LIBRARY_UI_SOURCES})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# add resources from current dir
|
# add resources from current dir
|
||||||
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/${LIBRARY_RESOURCES}")
|
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/${LIBRARY_RESOURCES}")
|
||||||
qt5_add_resources(LIBRARY_RC_SOURCES "${LIBRARY_RESOURCES}")
|
qt5_add_resources(LIBRARY_RC_SOURCES "${LIBRARY_RESOURCES}")
|
||||||
@ -83,6 +78,9 @@ function(calamares_add_library)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
calamares_automoc(${target})
|
calamares_automoc(${target})
|
||||||
|
if(LIBRARY_UI)
|
||||||
|
calamares_autouic(${target} ${LIBRARY_UI})
|
||||||
|
endif()
|
||||||
|
|
||||||
if(LIBRARY_EXPORT_MACRO)
|
if(LIBRARY_EXPORT_MACRO)
|
||||||
set_target_properties(${target} PROPERTIES COMPILE_DEFINITIONS ${LIBRARY_EXPORT_MACRO})
|
set_target_properties(${target} PROPERTIES COMPILE_DEFINITIONS ${LIBRARY_EXPORT_MACRO})
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
#
|
#
|
||||||
###
|
###
|
||||||
#
|
#
|
||||||
# Helper function for doing automoc on a target.
|
# Helper function for doing automoc on a target, and autoui on a .ui file.
|
||||||
#
|
#
|
||||||
# Sets AUTOMOC TRUE for a target.
|
# Sets AUTOMOC TRUE for a target.
|
||||||
#
|
#
|
||||||
@ -27,6 +27,8 @@
|
|||||||
# libcalamares/utils/moc-warnings.h file to the moc, which in turn
|
# libcalamares/utils/moc-warnings.h file to the moc, which in turn
|
||||||
# reduces compiler warnings in generated MOC code.
|
# reduces compiler warnings in generated MOC code.
|
||||||
#
|
#
|
||||||
|
# If the global variable CALAMARES_AUTOUIC_OPTIONS is set, adds that
|
||||||
|
# to the options passed to uic.
|
||||||
|
|
||||||
function(calamares_automoc TARGET)
|
function(calamares_automoc TARGET)
|
||||||
set_target_properties( ${TARGET} PROPERTIES AUTOMOC TRUE )
|
set_target_properties( ${TARGET} PROPERTIES AUTOMOC TRUE )
|
||||||
@ -34,3 +36,12 @@ function(calamares_automoc TARGET)
|
|||||||
set_target_properties( ${TARGET} PROPERTIES AUTOMOC_MOC_OPTIONS "${CALAMARES_AUTOMOC_OPTIONS}" )
|
set_target_properties( ${TARGET} PROPERTIES AUTOMOC_MOC_OPTIONS "${CALAMARES_AUTOMOC_OPTIONS}" )
|
||||||
endif()
|
endif()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
function(calamares_autouic TARGET)
|
||||||
|
set_target_properties( ${TARGET} PROPERTIES AUTOUIC TRUE )
|
||||||
|
if ( CALAMARES_AUTOUIC_OPTIONS )
|
||||||
|
foreach(S ${ARGN})
|
||||||
|
set_property(SOURCE ${S} PROPERTY AUTOUIC_OPTIONS "${CALAMARES_AUTOUIC_OPTIONS}")
|
||||||
|
endforeach()
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
|
@ -41,8 +41,8 @@ BUILDDIR=$(mktemp -d --suffix=-build --tmpdir=.)
|
|||||||
if test "x$BUILD_DEFAULT" = "xtrue" ; then
|
if test "x$BUILD_DEFAULT" = "xtrue" ; then
|
||||||
rm -rf "$BUILDDIR"
|
rm -rf "$BUILDDIR"
|
||||||
mkdir "$BUILDDIR" || { echo "Could not create build directory." ; exit 1 ; }
|
mkdir "$BUILDDIR" || { echo "Could not create build directory." ; exit 1 ; }
|
||||||
( cd "$BUILDDIR" && cmake .. && make -j4 ) || { echo "Could not perform test-build." ; exit 1 ; }
|
( cd "$BUILDDIR" && cmake .. && make -j4 ) || { echo "Could not perform test-build in $BUILDDIR." ; exit 1 ; }
|
||||||
( cd "$BUILDDIR" && make test ) || { echo "Tests failed." ; exit 1 ; }
|
( cd "$BUILDDIR" && make test ) || { echo "Tests failed in $BUILDDIR." ; exit 1 ; }
|
||||||
fi
|
fi
|
||||||
|
|
||||||
### Build with clang
|
### Build with clang
|
||||||
@ -53,13 +53,13 @@ if test "x$BUILD_CLANG" = "xtrue" ; then
|
|||||||
# Do build again with clang
|
# Do build again with clang
|
||||||
rm -rf "$BUILDDIR"
|
rm -rf "$BUILDDIR"
|
||||||
mkdir "$BUILDDIR" || { echo "Could not create build directory." ; exit 1 ; }
|
mkdir "$BUILDDIR" || { echo "Could not create build directory." ; exit 1 ; }
|
||||||
( cd "$BUILDDIR" && CC=clang CXX=clang++ cmake .. && make -j4 ) || { echo "Could not perform test-build." ; exit 1 ; }
|
( cd "$BUILDDIR" && CC=clang CXX=clang++ cmake .. && make -j4 ) || { echo "Could not perform test-build in $BUILDDIR." ; exit 1 ; }
|
||||||
( cd "$BUILDDIR" && make test ) || { echo "Tests failed." ; exit 1 ; }
|
( cd "$BUILDDIR" && make test ) || { echo "Tests failed in $BUILDDIR." ; exit 1 ; }
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if test "x$BUILD_ONLY" = "xtrue" ; then
|
if test "x$BUILD_ONLY" = "xtrue" ; then
|
||||||
echo "Builds completed, release stopped."
|
echo "Builds completed, release stopped. Build remains in $BUILDDIR."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -167,6 +167,16 @@ if ( ECM_FOUND AND BUILD_TESTING )
|
|||||||
${YAMLCPP_LIBRARY}
|
${YAMLCPP_LIBRARY}
|
||||||
)
|
)
|
||||||
calamares_automoc( geoiptest )
|
calamares_automoc( geoiptest )
|
||||||
|
|
||||||
|
ecm_add_test(
|
||||||
|
partition/Tests.cpp
|
||||||
|
TEST_NAME
|
||||||
|
libcalamarespartitiontest
|
||||||
|
LINK_LIBRARIES
|
||||||
|
calamares
|
||||||
|
Qt5::Test
|
||||||
|
)
|
||||||
|
calamares_automoc( libcalamarespartitiontest )
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if( BUILD_TESTING )
|
if( BUILD_TESTING )
|
||||||
|
@ -25,7 +25,9 @@
|
|||||||
|
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
|
|
||||||
namespace CalamaresUtils::GeoIP
|
namespace CalamaresUtils
|
||||||
|
{
|
||||||
|
namespace GeoIP
|
||||||
{
|
{
|
||||||
|
|
||||||
GeoIPJSON::GeoIPJSON(const QString& attribute)
|
GeoIPJSON::GeoIPJSON(const QString& attribute)
|
||||||
@ -88,6 +90,5 @@ GeoIPJSON::processReply( const QByteArray& data )
|
|||||||
return splitTZString( rawReply( data ) );
|
return splitTZString( rawReply( data ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -21,7 +21,9 @@
|
|||||||
|
|
||||||
#include "Interface.h"
|
#include "Interface.h"
|
||||||
|
|
||||||
namespace CalamaresUtils::GeoIP
|
namespace CalamaresUtils
|
||||||
|
{
|
||||||
|
namespace GeoIP
|
||||||
{
|
{
|
||||||
/** @brief GeoIP lookup for services that return JSON.
|
/** @brief GeoIP lookup for services that return JSON.
|
||||||
*
|
*
|
||||||
@ -46,5 +48,6 @@ public:
|
|||||||
virtual QString rawReply(const QByteArray & ) override;
|
virtual QString rawReply(const QByteArray & ) override;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
#endif
|
#endif
|
||||||
|
@ -23,7 +23,9 @@
|
|||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QtXml/QDomDocument>
|
#include <QtXml/QDomDocument>
|
||||||
|
|
||||||
namespace CalamaresUtils::GeoIP
|
namespace CalamaresUtils
|
||||||
|
{
|
||||||
|
namespace GeoIP
|
||||||
{
|
{
|
||||||
|
|
||||||
GeoIPXML::GeoIPXML( const QString& element )
|
GeoIPXML::GeoIPXML( const QString& element )
|
||||||
@ -87,4 +89,5 @@ GeoIPXML::processReply( const QByteArray& data )
|
|||||||
return RegionZonePair();
|
return RegionZonePair();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -21,7 +21,9 @@
|
|||||||
|
|
||||||
#include "Interface.h"
|
#include "Interface.h"
|
||||||
|
|
||||||
namespace CalamaresUtils::GeoIP
|
namespace CalamaresUtils
|
||||||
|
{
|
||||||
|
namespace GeoIP
|
||||||
{
|
{
|
||||||
/** @brief GeoIP lookup with XML data
|
/** @brief GeoIP lookup with XML data
|
||||||
*
|
*
|
||||||
@ -46,5 +48,6 @@ public:
|
|||||||
virtual QString rawReply(const QByteArray & ) override;
|
virtual QString rawReply(const QByteArray & ) override;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
#endif
|
#endif
|
||||||
|
@ -47,7 +47,9 @@ handlerTypes()
|
|||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace CalamaresUtils::GeoIP
|
namespace CalamaresUtils
|
||||||
|
{
|
||||||
|
namespace GeoIP
|
||||||
{
|
{
|
||||||
|
|
||||||
Handler::Handler()
|
Handler::Handler()
|
||||||
@ -110,9 +112,8 @@ create_interface( Handler::Type t, const QString& selector )
|
|||||||
#else
|
#else
|
||||||
return nullptr;
|
return nullptr;
|
||||||
#endif
|
#endif
|
||||||
default: // there are no others
|
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
NOTREACHED return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static RegionZonePair
|
static RegionZonePair
|
||||||
@ -179,5 +180,5 @@ Handler::queryRaw() const
|
|||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -25,8 +25,9 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QVariantMap>
|
#include <QVariantMap>
|
||||||
|
|
||||||
namespace CalamaresUtils {}
|
namespace CalamaresUtils
|
||||||
namespace CalamaresUtils::GeoIP
|
{
|
||||||
|
namespace GeoIP
|
||||||
{
|
{
|
||||||
|
|
||||||
/** @brief Handle one complete GeoIP lookup.
|
/** @brief Handle one complete GeoIP lookup.
|
||||||
@ -86,6 +87,7 @@ private:
|
|||||||
const QString m_selector;
|
const QString m_selector;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -20,7 +20,9 @@
|
|||||||
|
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
namespace CalamaresUtils::GeoIP
|
namespace CalamaresUtils
|
||||||
|
{
|
||||||
|
namespace GeoIP
|
||||||
{
|
{
|
||||||
|
|
||||||
Interface::Interface(const QString& e)
|
Interface::Interface(const QString& e)
|
||||||
@ -51,4 +53,5 @@ splitTZString( const QString& tz )
|
|||||||
return RegionZonePair( QString(), QString() );
|
return RegionZonePair( QString(), QString() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -27,8 +27,9 @@
|
|||||||
|
|
||||||
class QByteArray;
|
class QByteArray;
|
||||||
|
|
||||||
namespace CalamaresUtils {}
|
namespace CalamaresUtils
|
||||||
namespace CalamaresUtils::GeoIP
|
{
|
||||||
|
namespace GeoIP
|
||||||
{
|
{
|
||||||
/** @brief A Region, Zone pair of strings
|
/** @brief A Region, Zone pair of strings
|
||||||
*
|
*
|
||||||
@ -94,5 +95,6 @@ protected:
|
|||||||
QString m_element; // string for selecting from data
|
QString m_element; // string for selecting from data
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
#endif
|
#endif
|
||||||
|
@ -19,7 +19,9 @@
|
|||||||
|
|
||||||
#include "Label.h"
|
#include "Label.h"
|
||||||
|
|
||||||
namespace CalamaresUtils::Locale
|
namespace CalamaresUtils
|
||||||
|
{
|
||||||
|
namespace Locale
|
||||||
{
|
{
|
||||||
|
|
||||||
Label::Label()
|
Label::Label()
|
||||||
@ -70,4 +72,5 @@ QLocale Label::getLocale( const QString& localeName )
|
|||||||
return QLocale( localeName );
|
return QLocale( localeName );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -23,8 +23,9 @@
|
|||||||
#include <QLocale>
|
#include <QLocale>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
namespace CalamaresUtils {}
|
namespace CalamaresUtils
|
||||||
namespace CalamaresUtils::Locale
|
{
|
||||||
|
namespace Locale
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -120,7 +121,7 @@ protected:
|
|||||||
QString m_englishLabel;
|
QString m_englishLabel;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -22,7 +22,9 @@
|
|||||||
|
|
||||||
#include "CalamaresVersion.h" // For the list of translations
|
#include "CalamaresVersion.h" // For the list of translations
|
||||||
|
|
||||||
namespace CalamaresUtils::Locale
|
namespace CalamaresUtils
|
||||||
|
{
|
||||||
|
namespace Locale
|
||||||
{
|
{
|
||||||
|
|
||||||
LabelModel::LabelModel( const QStringList& locales, QObject* parent )
|
LabelModel::LabelModel( const QStringList& locales, QObject* parent )
|
||||||
@ -121,10 +123,11 @@ LabelModel::find( const QString& countryCode ) const
|
|||||||
return find( [&]( const Label& l ){ return l.language() == c_l.second; } );
|
return find( [&]( const Label& l ){ return l.language() == c_l.second; } );
|
||||||
}
|
}
|
||||||
|
|
||||||
LabelModel* const availableTranslations()
|
LabelModel* availableTranslations()
|
||||||
{
|
{
|
||||||
static LabelModel model( QString( CALAMARES_TRANSLATION_LANGUAGES ).split( ';') );
|
static LabelModel model( QString( CALAMARES_TRANSLATION_LANGUAGES ).split( ';') );
|
||||||
return &model;
|
return &model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -26,8 +26,9 @@
|
|||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
|
||||||
|
|
||||||
namespace CalamaresUtils {}
|
namespace CalamaresUtils
|
||||||
namespace CalamaresUtils::Locale
|
{
|
||||||
|
namespace Locale
|
||||||
{
|
{
|
||||||
|
|
||||||
class DLLEXPORT LabelModel : public QAbstractListModel
|
class DLLEXPORT LabelModel : public QAbstractListModel
|
||||||
@ -78,7 +79,7 @@ private:
|
|||||||
*
|
*
|
||||||
* NOTE: While the model is not typed const, it should be. Do not modify.
|
* NOTE: While the model is not typed const, it should be. Do not modify.
|
||||||
*/
|
*/
|
||||||
DLLEXPORT LabelModel* const availableTranslations();
|
DLLEXPORT LabelModel* availableTranslations();
|
||||||
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
#endif
|
#endif
|
||||||
|
@ -20,7 +20,9 @@
|
|||||||
|
|
||||||
#include "CountryData_p.cpp"
|
#include "CountryData_p.cpp"
|
||||||
|
|
||||||
namespace CalamaresUtils::Locale
|
namespace CalamaresUtils
|
||||||
|
{
|
||||||
|
namespace Locale
|
||||||
{
|
{
|
||||||
|
|
||||||
struct TwoChar
|
struct TwoChar
|
||||||
@ -87,4 +89,5 @@ QLocale::Language languageForCountry(QLocale::Country country)
|
|||||||
return p->l;
|
return p->l;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -24,8 +24,9 @@
|
|||||||
#include <QLocale>
|
#include <QLocale>
|
||||||
#include <QPair>
|
#include <QPair>
|
||||||
|
|
||||||
namespace CalamaresUtils {}
|
namespace CalamaresUtils
|
||||||
namespace CalamaresUtils::Locale
|
{
|
||||||
|
namespace Locale
|
||||||
{
|
{
|
||||||
/* All the functions in this file do lookups of locale data
|
/* All the functions in this file do lookups of locale data
|
||||||
* based on CLDR tables; these are lookups that you can't (easily)
|
* based on CLDR tables; these are lookups that you can't (easily)
|
||||||
@ -48,6 +49,7 @@ namespace CalamaresUtils::Locale
|
|||||||
DLLEXPORT QPair< QLocale::Country, QLocale::Language > countryData( const QString& code );
|
DLLEXPORT QPair< QLocale::Country, QLocale::Language > countryData( const QString& code );
|
||||||
/// @brief Get a likely locale for a 2-letter country code
|
/// @brief Get a likely locale for a 2-letter country code
|
||||||
DLLEXPORT QLocale countryLocale( const QString& code );
|
DLLEXPORT QLocale countryLocale( const QString& code );
|
||||||
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
*
|
*
|
||||||
* Copyright 2019, Collabora Ltd <arnaud.ferraris@collabora.com>
|
* Copyright 2019, Collabora Ltd <arnaud.ferraris@collabora.com>
|
||||||
|
* Copyright 2019, Adriaan de Groot <groot@kde.org>
|
||||||
*
|
*
|
||||||
* Calamares is free software: you can redistribute it and/or modify
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -42,23 +43,23 @@ unitSuffixes()
|
|||||||
PartitionSize::PartitionSize( const QString& s )
|
PartitionSize::PartitionSize( const QString& s )
|
||||||
: NamedSuffix( unitSuffixes(), s )
|
: NamedSuffix( unitSuffixes(), s )
|
||||||
{
|
{
|
||||||
if ( ( unit() == unit_t::Percent ) && ( value() > 100 || value() < 0 ) )
|
if ( ( unit() == SizeUnit::Percent ) && ( value() > 100 || value() < 0 ) )
|
||||||
{
|
{
|
||||||
cDebug() << "Percent value" << value() << "is not valid.";
|
cDebug() << "Percent value" << value() << "is not valid.";
|
||||||
m_value = 0;
|
m_value = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( m_unit == unit_t::None )
|
if ( m_unit == SizeUnit::None )
|
||||||
{
|
{
|
||||||
m_value = s.toInt();
|
m_value = s.toInt();
|
||||||
if ( m_value > 0 )
|
if ( m_value > 0 )
|
||||||
m_unit = unit_t::Byte;
|
m_unit = SizeUnit::Byte;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( m_value <= 0 )
|
if ( m_value <= 0 )
|
||||||
{
|
{
|
||||||
m_value = 0;
|
m_value = 0;
|
||||||
m_unit = unit_t::None;
|
m_unit = SizeUnit::None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,17 +73,17 @@ PartitionSize::toSectors( qint64 totalSectors, qint64 sectorSize ) const
|
|||||||
|
|
||||||
switch ( m_unit )
|
switch ( m_unit )
|
||||||
{
|
{
|
||||||
case unit_t::None:
|
case SizeUnit::None:
|
||||||
return -1;
|
return -1;
|
||||||
case unit_t::Percent:
|
case SizeUnit::Percent:
|
||||||
if ( value() == 100 )
|
if ( value() == 100 )
|
||||||
return totalSectors; // Common-case, avoid futzing around
|
return totalSectors; // Common-case, avoid futzing around
|
||||||
else
|
else
|
||||||
return totalSectors * value() / 100;
|
return totalSectors * value() / 100;
|
||||||
case unit_t::Byte:
|
case SizeUnit::Byte:
|
||||||
case unit_t::KiB:
|
case SizeUnit::KiB:
|
||||||
case unit_t::MiB:
|
case SizeUnit::MiB:
|
||||||
case unit_t::GiB:
|
case SizeUnit::GiB:
|
||||||
return CalamaresUtils::bytesToSectors ( toBytes(), sectorSize );
|
return CalamaresUtils::bytesToSectors ( toBytes(), sectorSize );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,19 +98,19 @@ PartitionSize::toBytes( qint64 totalSectors, qint64 sectorSize ) const
|
|||||||
|
|
||||||
switch ( m_unit )
|
switch ( m_unit )
|
||||||
{
|
{
|
||||||
case unit_t::None:
|
case SizeUnit::None:
|
||||||
return -1;
|
return -1;
|
||||||
case unit_t::Percent:
|
case SizeUnit::Percent:
|
||||||
if ( totalSectors < 1 || sectorSize < 1 )
|
if ( totalSectors < 1 || sectorSize < 1 )
|
||||||
return -1;
|
return -1;
|
||||||
if ( value() == 100 )
|
if ( value() == 100 )
|
||||||
return totalSectors * sectorSize; // Common-case, avoid futzing around
|
return totalSectors * sectorSize; // Common-case, avoid futzing around
|
||||||
else
|
else
|
||||||
return totalSectors * value() / 100;
|
return totalSectors * value() / 100;
|
||||||
case unit_t::Byte:
|
case SizeUnit::Byte:
|
||||||
case unit_t::KiB:
|
case SizeUnit::KiB:
|
||||||
case unit_t::MiB:
|
case SizeUnit::MiB:
|
||||||
case unit_t::GiB:
|
case SizeUnit::GiB:
|
||||||
return toBytes();
|
return toBytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,19 +126,19 @@ PartitionSize::toBytes( qint64 totalBytes ) const
|
|||||||
|
|
||||||
switch ( m_unit )
|
switch ( m_unit )
|
||||||
{
|
{
|
||||||
case unit_t::None:
|
case SizeUnit::None:
|
||||||
return -1;
|
return -1;
|
||||||
case unit_t::Percent:
|
case SizeUnit::Percent:
|
||||||
if ( totalBytes < 1 )
|
if ( totalBytes < 1 )
|
||||||
return -1;
|
return -1;
|
||||||
if ( value() == 100 )
|
if ( value() == 100 )
|
||||||
return totalBytes; // Common-case, avoid futzing around
|
return totalBytes; // Common-case, avoid futzing around
|
||||||
else
|
else
|
||||||
return totalBytes * value() / 100;
|
return totalBytes * value() / 100;
|
||||||
case unit_t::Byte:
|
case SizeUnit::Byte:
|
||||||
case unit_t::KiB:
|
case SizeUnit::KiB:
|
||||||
case unit_t::MiB:
|
case SizeUnit::MiB:
|
||||||
case unit_t::GiB:
|
case SizeUnit::GiB:
|
||||||
return toBytes();
|
return toBytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,86 +154,82 @@ PartitionSize::toBytes() const
|
|||||||
|
|
||||||
switch ( m_unit )
|
switch ( m_unit )
|
||||||
{
|
{
|
||||||
case unit_t::Byte:
|
case SizeUnit::None:
|
||||||
|
case SizeUnit::Percent:
|
||||||
|
return -1;
|
||||||
|
case SizeUnit::Byte:
|
||||||
return value();
|
return value();
|
||||||
case unit_t::KiB:
|
case SizeUnit::KiB:
|
||||||
return CalamaresUtils::KiBtoBytes( static_cast<unsigned long long>( value() ) );
|
return CalamaresUtils::KiBtoBytes( static_cast<unsigned long long>( value() ) );
|
||||||
case unit_t::MiB:
|
case SizeUnit::MiB:
|
||||||
return CalamaresUtils::MiBtoBytes( static_cast<unsigned long long>( value() ) );
|
return CalamaresUtils::MiBtoBytes( static_cast<unsigned long long>( value() ) );
|
||||||
case unit_t::GiB:
|
case SizeUnit::GiB:
|
||||||
return CalamaresUtils::GiBtoBytes( static_cast<unsigned long long>( value() ) );
|
return CalamaresUtils::GiBtoBytes( static_cast<unsigned long long>( value() ) );
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
NOTREACHED return -1;
|
||||||
// Reached only when unit is Percent or None
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
PartitionSize::operator< ( const PartitionSize& other ) const
|
PartitionSize::operator< ( const PartitionSize& other ) const
|
||||||
{
|
{
|
||||||
if ( ( m_unit == unit_t::None || other.m_unit == unit_t::None ) ||
|
if ( !unitsComparable( m_unit, other.m_unit ) )
|
||||||
( m_unit == unit_t::Percent && other.m_unit != unit_t::Percent ) ||
|
|
||||||
( m_unit != unit_t::Percent && other.m_unit == unit_t::Percent ) )
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
switch ( m_unit )
|
switch ( m_unit )
|
||||||
{
|
{
|
||||||
case unit_t::Percent:
|
case SizeUnit::None:
|
||||||
|
return false;
|
||||||
|
case SizeUnit::Percent:
|
||||||
return ( m_value < other.m_value );
|
return ( m_value < other.m_value );
|
||||||
case unit_t::Byte:
|
case SizeUnit::Byte:
|
||||||
case unit_t::KiB:
|
case SizeUnit::KiB:
|
||||||
case unit_t::MiB:
|
case SizeUnit::MiB:
|
||||||
case unit_t::GiB:
|
case SizeUnit::GiB:
|
||||||
return ( toBytes() < other.toBytes () );
|
return ( toBytes() < other.toBytes () );
|
||||||
}
|
}
|
||||||
|
NOTREACHED return false;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
PartitionSize::operator> ( const PartitionSize& other ) const
|
PartitionSize::operator> ( const PartitionSize& other ) const
|
||||||
{
|
{
|
||||||
if ( ( m_unit == unit_t::None || other.m_unit == unit_t::None ) ||
|
if ( !unitsComparable( m_unit, other.m_unit ) )
|
||||||
( m_unit == unit_t::Percent && other.m_unit != unit_t::Percent ) ||
|
|
||||||
( m_unit != unit_t::Percent && other.m_unit == unit_t::Percent ) )
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
switch ( m_unit )
|
switch ( m_unit )
|
||||||
{
|
{
|
||||||
case unit_t::Percent:
|
case SizeUnit::None:
|
||||||
|
return false;
|
||||||
|
case SizeUnit::Percent:
|
||||||
return ( m_value > other.m_value );
|
return ( m_value > other.m_value );
|
||||||
case unit_t::Byte:
|
case SizeUnit::Byte:
|
||||||
case unit_t::KiB:
|
case SizeUnit::KiB:
|
||||||
case unit_t::MiB:
|
case SizeUnit::MiB:
|
||||||
case unit_t::GiB:
|
case SizeUnit::GiB:
|
||||||
return ( toBytes() > other.toBytes () );
|
return ( toBytes() > other.toBytes () );
|
||||||
}
|
}
|
||||||
|
NOTREACHED return false;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
PartitionSize::operator== ( const PartitionSize& other ) const
|
PartitionSize::operator== ( const PartitionSize& other ) const
|
||||||
{
|
{
|
||||||
if ( ( m_unit == unit_t::None || other.m_unit == unit_t::None ) ||
|
if ( !unitsComparable( m_unit, other.m_unit ) )
|
||||||
( m_unit == unit_t::Percent && other.m_unit != unit_t::Percent ) ||
|
|
||||||
( m_unit != unit_t::Percent && other.m_unit == unit_t::Percent ) )
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
switch ( m_unit )
|
switch ( m_unit )
|
||||||
{
|
{
|
||||||
case unit_t::Percent:
|
case SizeUnit::None:
|
||||||
|
return false;
|
||||||
|
case SizeUnit::Percent:
|
||||||
return ( m_value == other.m_value );
|
return ( m_value == other.m_value );
|
||||||
case unit_t::Byte:
|
case SizeUnit::Byte:
|
||||||
case unit_t::KiB:
|
case SizeUnit::KiB:
|
||||||
case unit_t::MiB:
|
case SizeUnit::MiB:
|
||||||
case unit_t::GiB:
|
case SizeUnit::GiB:
|
||||||
return ( toBytes() == other.toBytes () );
|
return ( toBytes() == other.toBytes () );
|
||||||
}
|
}
|
||||||
|
NOTREACHED return false;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Calamares
|
} // namespace Calamares
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
*
|
*
|
||||||
* Copyright 2019, Collabora Ltd <arnaud.ferraris@collabora.com>
|
* Copyright 2019, Collabora Ltd <arnaud.ferraris@collabora.com>
|
||||||
|
* Copyright 2019, Adriaan de Groot <groot@kde.org>
|
||||||
*
|
*
|
||||||
* Calamares is free software: you can redistribute it and/or modify
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -48,7 +49,7 @@ class PartitionSize : public NamedSuffix<SizeUnit, SizeUnit::None>
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PartitionSize() : NamedSuffix() { }
|
PartitionSize() : NamedSuffix() { }
|
||||||
PartitionSize( int v, unit_t u ) : NamedSuffix( v, u ) { }
|
PartitionSize( int v, SizeUnit u ) : NamedSuffix( v, u ) { }
|
||||||
PartitionSize( const QString& );
|
PartitionSize( const QString& );
|
||||||
|
|
||||||
bool isValid() const
|
bool isValid() const
|
||||||
@ -91,11 +92,26 @@ public:
|
|||||||
/** @brief Convert the size to bytes.
|
/** @brief Convert the size to bytes.
|
||||||
*
|
*
|
||||||
* This method is only valid for sizes in Bytes, KiB, MiB or GiB.
|
* 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.
|
* @return the size in bytes, or -1 if it cannot be calculated.
|
||||||
*/
|
*/
|
||||||
qint64 toBytes() const;
|
qint64 toBytes() const;
|
||||||
|
|
||||||
|
/** @brief Are the units comparable?
|
||||||
|
*
|
||||||
|
* None units cannot be compared with anything. Percentages can
|
||||||
|
* be compared with each other, and all the explicit sizes (KiB, ...)
|
||||||
|
* can be compared with each other.
|
||||||
|
*/
|
||||||
|
static constexpr bool unitsComparable( const SizeUnit u1, const SizeUnit u2 )
|
||||||
|
{
|
||||||
|
return !( ( u1 == SizeUnit::None || u2 == SizeUnit::None ) ||
|
||||||
|
( u1 == SizeUnit::Percent && u2 != SizeUnit::Percent ) ||
|
||||||
|
( u1 != SizeUnit::Percent && u2 == SizeUnit::Percent ) );
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Calamares
|
} // namespace Calamares
|
||||||
|
145
src/libcalamares/partition/Tests.cpp
Normal file
145
src/libcalamares/partition/Tests.cpp
Normal file
@ -0,0 +1,145 @@
|
|||||||
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Copyright 2019, Adriaan de Groot <groot@kde.org>
|
||||||
|
*
|
||||||
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Calamares is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Tests.h"
|
||||||
|
|
||||||
|
#include "PartitionSize.h"
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE( Calamares::SizeUnit )
|
||||||
|
|
||||||
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
|
#include <QtTest/QtTest>
|
||||||
|
|
||||||
|
QTEST_GUILESS_MAIN( PartitionSizeTests )
|
||||||
|
|
||||||
|
PartitionSizeTests::PartitionSizeTests()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
PartitionSizeTests::~PartitionSizeTests()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PartitionSizeTests::initTestCase()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PartitionSizeTests::testUnitComparison_data()
|
||||||
|
{
|
||||||
|
QTest::addColumn<Calamares::SizeUnit>("u1");
|
||||||
|
QTest::addColumn<Calamares::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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static bool
|
||||||
|
original_compare( Calamares::SizeUnit m_unit, Calamares::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 ) )
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PartitionSizeTests::testUnitComparison()
|
||||||
|
{
|
||||||
|
QFETCH( Calamares::SizeUnit, u1 );
|
||||||
|
QFETCH( Calamares::SizeUnit, u2 );
|
||||||
|
QFETCH( bool, comparable );
|
||||||
|
|
||||||
|
if ( comparable )
|
||||||
|
{
|
||||||
|
QVERIFY( Calamares::PartitionSize::unitsComparable( u1, u2 ) );
|
||||||
|
QVERIFY( Calamares::PartitionSize::unitsComparable( u2, u1 ) );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QVERIFY( !Calamares::PartitionSize::unitsComparable( u1, u2 ) );
|
||||||
|
QVERIFY( !Calamares::PartitionSize::unitsComparable( u2, u1 ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
QCOMPARE( original_compare( u1, u2 ), Calamares::PartitionSize::unitsComparable( u1, u2 ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PartitionSizeTests::testUnitNormalisation_data()
|
||||||
|
{
|
||||||
|
QTest::addColumn<Calamares::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;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PartitionSizeTests::testUnitNormalisation()
|
||||||
|
{
|
||||||
|
QFETCH( Calamares::SizeUnit, u1 );
|
||||||
|
QFETCH( int, v );
|
||||||
|
QFETCH( long, bytes );
|
||||||
|
|
||||||
|
QCOMPARE( Calamares::PartitionSize( v, u1 ).toBytes(), static_cast<qint64>( bytes ) );
|
||||||
|
}
|
41
src/libcalamares/partition/Tests.h
Normal file
41
src/libcalamares/partition/Tests.h
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Copyright 2019, Adriaan de Groot <groot@kde.org>
|
||||||
|
*
|
||||||
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Calamares is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef LIBCALAMARES_PARTITION_TESTS_H
|
||||||
|
#define LIBCALAMARES_PARTITION_TESTS_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
class PartitionSizeTests : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
PartitionSizeTests();
|
||||||
|
~PartitionSizeTests() override;
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void initTestCase();
|
||||||
|
|
||||||
|
void testUnitComparison_data();
|
||||||
|
void testUnitComparison();
|
||||||
|
|
||||||
|
void testUnitNormalisation_data();
|
||||||
|
void testUnitNormalisation();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
@ -54,6 +54,21 @@ public:
|
|||||||
m_size.isValid();
|
m_size.isValid();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString name() const
|
||||||
|
{
|
||||||
|
return m_fsname.isEmpty() ? m_devicename : m_fsname;
|
||||||
|
}
|
||||||
|
|
||||||
|
Calamares::PartitionSize size() const
|
||||||
|
{
|
||||||
|
return m_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
Calamares::PartitionSize minimumSize() const
|
||||||
|
{
|
||||||
|
return m_atleast;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Calamares::PartitionSize m_size;
|
Calamares::PartitionSize m_size;
|
||||||
Calamares::PartitionSize m_atleast;
|
Calamares::PartitionSize m_atleast;
|
||||||
|
@ -30,9 +30,7 @@
|
|||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
#define private public
|
|
||||||
#include "ResizeFSJob.h"
|
#include "ResizeFSJob.h"
|
||||||
#undef private
|
|
||||||
|
|
||||||
QTEST_GUILESS_MAIN( FSResizerTests )
|
QTEST_GUILESS_MAIN( FSResizerTests )
|
||||||
|
|
||||||
@ -55,10 +53,9 @@ void FSResizerTests::testConfigurationRobust()
|
|||||||
|
|
||||||
// Empty config
|
// Empty config
|
||||||
j.setConfigurationMap( QVariantMap() );
|
j.setConfigurationMap( QVariantMap() );
|
||||||
QVERIFY( j.m_fsname.isEmpty() );
|
QVERIFY( j.name().isEmpty() );
|
||||||
QVERIFY( j.m_devicename.isEmpty() );
|
QCOMPARE( j.size().unit(), Calamares::SizeUnit::None );
|
||||||
QCOMPARE( j.m_size.unit(), Calamares::SizeUnit::None );
|
QCOMPARE( j.minimumSize().unit(), Calamares::SizeUnit::None );
|
||||||
QCOMPARE( j.m_atleast.unit(), Calamares::SizeUnit::None );
|
|
||||||
|
|
||||||
// Config is missing fs and dev, so it isn't valid
|
// Config is missing fs and dev, so it isn't valid
|
||||||
YAML::Node doc0 = YAML::Load( R"(---
|
YAML::Node doc0 = YAML::Load( R"(---
|
||||||
@ -66,12 +63,11 @@ size: 100%
|
|||||||
atleast: 600MiB
|
atleast: 600MiB
|
||||||
)" );
|
)" );
|
||||||
j.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc0 ).toMap() );
|
j.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc0 ).toMap() );
|
||||||
QVERIFY( j.m_fsname.isEmpty() );
|
QVERIFY( j.name().isEmpty() );
|
||||||
QVERIFY( j.m_devicename.isEmpty() );
|
QCOMPARE( j.size().unit(), Calamares::SizeUnit::None );
|
||||||
QCOMPARE( j.m_size.unit(), Calamares::SizeUnit::None );
|
QCOMPARE( j.minimumSize().unit(), Calamares::SizeUnit::None );
|
||||||
QCOMPARE( j.m_atleast.unit(), Calamares::SizeUnit::None );
|
QCOMPARE( j.size().value(), 0 );
|
||||||
QCOMPARE( j.m_size.value(), 0 );
|
QCOMPARE( j.minimumSize().value(), 0 );
|
||||||
QCOMPARE( j.m_atleast.value(), 0 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FSResizerTests::testConfigurationValues()
|
void FSResizerTests::testConfigurationValues()
|
||||||
@ -85,12 +81,11 @@ size: 100%
|
|||||||
atleast: 600MiB
|
atleast: 600MiB
|
||||||
)" );
|
)" );
|
||||||
j.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc0 ).toMap() );
|
j.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc0 ).toMap() );
|
||||||
QVERIFY( !j.m_fsname.isEmpty() );
|
QVERIFY( j.name().isEmpty() );
|
||||||
QVERIFY( j.m_devicename.isEmpty() );
|
QCOMPARE( j.size().unit(), Calamares::SizeUnit::Percent );
|
||||||
QCOMPARE( j.m_size.unit(), Calamares::SizeUnit::Percent );
|
QCOMPARE( j.minimumSize().unit(), Calamares::SizeUnit::MiB );
|
||||||
QCOMPARE( j.m_atleast.unit(), Calamares::SizeUnit::MiB );
|
QCOMPARE( j.size().value(), 100 );
|
||||||
QCOMPARE( j.m_size.value(), 100 );
|
QCOMPARE( j.minimumSize().value(), 600 );
|
||||||
QCOMPARE( j.m_atleast.value(), 600 );
|
|
||||||
|
|
||||||
// Silly config
|
// Silly config
|
||||||
doc0 = YAML::Load( R"(---
|
doc0 = YAML::Load( R"(---
|
||||||
@ -100,12 +95,11 @@ size: 72 MiB
|
|||||||
atleast: 127 %
|
atleast: 127 %
|
||||||
)" );
|
)" );
|
||||||
j.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc0 ).toMap() );
|
j.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc0 ).toMap() );
|
||||||
QVERIFY( !j.m_fsname.isEmpty() );
|
QVERIFY( !j.name().isEmpty() );
|
||||||
QVERIFY( !j.m_devicename.isEmpty() );
|
QCOMPARE( j.size().unit(), Calamares::SizeUnit::MiB );
|
||||||
QCOMPARE( j.m_size.unit(), Calamares::SizeUnit::MiB );
|
QCOMPARE( j.minimumSize().unit(), Calamares::SizeUnit::None );
|
||||||
QCOMPARE( j.m_atleast.unit(), Calamares::SizeUnit::None );
|
QCOMPARE( j.size().value(), 72 );
|
||||||
QCOMPARE( j.m_size.value(), 72 );
|
QCOMPARE( j.minimumSize().value(), 0 );
|
||||||
QCOMPARE( j.m_atleast.value(), 0 );
|
|
||||||
|
|
||||||
// Silly config
|
// Silly config
|
||||||
doc0 = YAML::Load( R"(---
|
doc0 = YAML::Load( R"(---
|
||||||
@ -115,10 +109,9 @@ size: 71MiB
|
|||||||
# atleast: 127%
|
# atleast: 127%
|
||||||
)" );
|
)" );
|
||||||
j.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc0 ).toMap() );
|
j.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc0 ).toMap() );
|
||||||
QVERIFY( !j.m_fsname.isEmpty() );
|
QVERIFY( j.name().isEmpty() );
|
||||||
QVERIFY( j.m_devicename.isEmpty() );
|
QCOMPARE( j.size().unit(), Calamares::SizeUnit::MiB );
|
||||||
QCOMPARE( j.m_size.unit(), Calamares::SizeUnit::MiB );
|
QCOMPARE( j.minimumSize().unit(), Calamares::SizeUnit::None );
|
||||||
QCOMPARE( j.m_atleast.unit(), Calamares::SizeUnit::None );
|
QCOMPARE( j.size().value(), 71 );
|
||||||
QCOMPARE( j.m_size.value(), 71 );
|
QCOMPARE( j.minimumSize().value(), 0 );
|
||||||
QCOMPARE( j.m_atleast.value(), 0 );
|
|
||||||
}
|
}
|
||||||
|
@ -43,9 +43,15 @@ public:
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual ~OEMPage() override;
|
||||||
|
|
||||||
Ui_OEMPage* m_ui;
|
Ui_OEMPage* m_ui;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
OEMPage::~OEMPage()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
OEMViewStep::OEMViewStep(QObject* parent)
|
OEMViewStep::OEMViewStep(QObject* parent)
|
||||||
: Calamares::ViewStep( parent )
|
: Calamares::ViewStep( parent )
|
||||||
|
@ -150,7 +150,7 @@ PartitionLayout::execute( Device *dev, qint64 firstSector,
|
|||||||
const PartitionRole& role )
|
const PartitionRole& role )
|
||||||
{
|
{
|
||||||
QList< Partition* > partList;
|
QList< Partition* > partList;
|
||||||
qint64 size, minSize, maxSize, end;
|
qint64 minSize, maxSize, end;
|
||||||
qint64 totalSize = lastSector - firstSector + 1;
|
qint64 totalSize = lastSector - firstSector + 1;
|
||||||
qint64 availableSize = totalSize;
|
qint64 availableSize = totalSize;
|
||||||
|
|
||||||
@ -161,6 +161,7 @@ PartitionLayout::execute( Device *dev, qint64 firstSector,
|
|||||||
{
|
{
|
||||||
Partition *currentPartition = nullptr;
|
Partition *currentPartition = nullptr;
|
||||||
|
|
||||||
|
qint64 size = -1;
|
||||||
// Calculate partition size
|
// Calculate partition size
|
||||||
if ( part.partSize.isValid() )
|
if ( part.partSize.isValid() )
|
||||||
{
|
{
|
||||||
|
@ -564,7 +564,7 @@ PartitionPage::updateFromCurrentDevice()
|
|||||||
|
|
||||||
QAbstractItemModel* oldModel = m_ui->partitionTreeView->model();
|
QAbstractItemModel* oldModel = m_ui->partitionTreeView->model();
|
||||||
if ( oldModel )
|
if ( oldModel )
|
||||||
disconnect( oldModel, 0, this, 0 );
|
disconnect( oldModel, nullptr, this, nullptr );
|
||||||
|
|
||||||
PartitionModel* model = m_core->partitionModelForDevice( device );
|
PartitionModel* model = m_core->partitionModelForDevice( device );
|
||||||
m_ui->partitionBarsView->setModel( model );
|
m_ui->partitionBarsView->setModel( model );
|
||||||
|
@ -44,7 +44,7 @@ ResizeVolumeGroupDialog::ResizeVolumeGroupDialog( LvmDevice *device,
|
|||||||
for ( const Partition* p : availablePVs )
|
for ( const Partition* p : availablePVs )
|
||||||
pvList()->addItem( new ListPhysicalVolumeWidgetItem( p, false ) );
|
pvList()->addItem( new ListPhysicalVolumeWidgetItem( p, false ) );
|
||||||
|
|
||||||
peSize()->setValue( device->peSize() / Capacity::unitFactor(Capacity::Unit::Byte, Capacity::Unit::MiB) );
|
peSize()->setValue( static_cast<int>( device->peSize() / Capacity::unitFactor(Capacity::Unit::Byte, Capacity::Unit::MiB) ) );
|
||||||
|
|
||||||
vgName()->setEnabled( false );
|
vgName()->setEnabled( false );
|
||||||
peSize()->setEnabled( false );
|
peSize()->setEnabled( false );
|
||||||
|
@ -137,9 +137,9 @@ VolumeGroupBaseDialog::updateTotalSize()
|
|||||||
void
|
void
|
||||||
VolumeGroupBaseDialog::updateTotalSectors()
|
VolumeGroupBaseDialog::updateTotalSectors()
|
||||||
{
|
{
|
||||||
qint32 totalSectors = 0;
|
qint64 totalSectors = 0;
|
||||||
|
|
||||||
qint32 extentSize = ui->peSize->value() * Capacity::unitFactor(Capacity::Unit::Byte, Capacity::Unit::MiB);
|
qint64 extentSize = ui->peSize->value() * Capacity::unitFactor(Capacity::Unit::Byte, Capacity::Unit::MiB);
|
||||||
|
|
||||||
if ( extentSize > 0 )
|
if ( extentSize > 0 )
|
||||||
totalSectors = m_totalSizeValue / extentSize;
|
totalSectors = m_totalSizeValue / extentSize;
|
||||||
|
@ -68,7 +68,7 @@ CreatePartitionTableJob::prettyStatusMessage() const
|
|||||||
|
|
||||||
|
|
||||||
static inline QDebug&
|
static inline QDebug&
|
||||||
operator <<( QDebug& s, PartitionIterator& it )
|
operator <<( QDebug&& s, PartitionIterator& it )
|
||||||
{
|
{
|
||||||
s << ( ( *it ) ? ( *it )->deviceNode() : QString( "<null device>" ) );
|
s << ( ( *it ) ? ( *it )->deviceNode() : QString( "<null device>" ) );
|
||||||
return s;
|
return s;
|
||||||
@ -89,7 +89,7 @@ CreatePartitionTableJob::exec()
|
|||||||
{
|
{
|
||||||
for ( auto it = PartitionIterator::begin( table );
|
for ( auto it = PartitionIterator::begin( table );
|
||||||
it != PartitionIterator::end( table ); ++it )
|
it != PartitionIterator::end( table ); ++it )
|
||||||
cDebug() << *it;
|
cDebug() << it;
|
||||||
|
|
||||||
QProcess lsblk;
|
QProcess lsblk;
|
||||||
lsblk.setProgram( "lsblk" );
|
lsblk.setProgram( "lsblk" );
|
||||||
|
@ -77,7 +77,7 @@ static QByteArray
|
|||||||
generateTestData( qint64 size )
|
generateTestData( qint64 size )
|
||||||
{
|
{
|
||||||
QByteArray ba;
|
QByteArray ba;
|
||||||
ba.resize( size );
|
ba.resize( static_cast<int>( size ) );
|
||||||
// Fill the array explicitly to keep Valgrind happy
|
// Fill the array explicitly to keep Valgrind happy
|
||||||
for ( auto it = ba.data() ; it < ba.data() + size ; ++it )
|
for ( auto it = ba.data() ; it < ba.data() + size ; ++it )
|
||||||
{
|
{
|
||||||
@ -130,6 +130,11 @@ QueueRunner::QueueRunner( JobQueue* queue )
|
|||||||
connect( m_queue, &JobQueue::failed, this, &QueueRunner::onFailed );
|
connect( m_queue, &JobQueue::failed, this, &QueueRunner::onFailed );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QueueRunner::~QueueRunner()
|
||||||
|
{
|
||||||
|
// Nothing to do. We don't own the queue, and disconnect happens automatically
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
QueueRunner::run()
|
QueueRunner::run()
|
||||||
{
|
{
|
||||||
@ -167,7 +172,8 @@ PartitionJobTests::initTestCase()
|
|||||||
QString devicePath = qgetenv( "CALAMARES_TEST_DISK" );
|
QString devicePath = qgetenv( "CALAMARES_TEST_DISK" );
|
||||||
if ( devicePath.isEmpty() )
|
if ( devicePath.isEmpty() )
|
||||||
{
|
{
|
||||||
QSKIP( "Skipping test, CALAMARES_TEST_DISK is not set. It should point to a disk which can be safely formatted" );
|
// The 0 is to keep the macro parameters happy
|
||||||
|
QSKIP( "Skipping test, CALAMARES_TEST_DISK is not set. It should point to a disk which can be safely formatted", 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
QVERIFY( KPMHelpers::initKPMcore() );
|
QVERIFY( KPMHelpers::initKPMcore() );
|
||||||
@ -322,10 +328,10 @@ PartitionJobTests::testCreatePartitionExtended()
|
|||||||
void
|
void
|
||||||
PartitionJobTests::testResizePartition_data()
|
PartitionJobTests::testResizePartition_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn< int >( "oldStartMiB" );
|
QTest::addColumn< unsigned int >( "oldStartMiB" );
|
||||||
QTest::addColumn< int >( "oldSizeMiB" );
|
QTest::addColumn< unsigned int >( "oldSizeMiB" );
|
||||||
QTest::addColumn< int >( "newStartMiB" );
|
QTest::addColumn< unsigned int >( "newStartMiB" );
|
||||||
QTest::addColumn< int >( "newSizeMiB" );
|
QTest::addColumn< unsigned int >( "newSizeMiB" );
|
||||||
|
|
||||||
QTest::newRow("grow") << 10 << 50 << 10 << 70;
|
QTest::newRow("grow") << 10 << 50 << 10 << 70;
|
||||||
QTest::newRow("shrink") << 10 << 70 << 10 << 50;
|
QTest::newRow("shrink") << 10 << 70 << 10 << 50;
|
||||||
@ -336,10 +342,10 @@ PartitionJobTests::testResizePartition_data()
|
|||||||
void
|
void
|
||||||
PartitionJobTests::testResizePartition()
|
PartitionJobTests::testResizePartition()
|
||||||
{
|
{
|
||||||
QFETCH( int, oldStartMiB );
|
QFETCH( unsigned int, oldStartMiB );
|
||||||
QFETCH( int, oldSizeMiB );
|
QFETCH( unsigned int, oldSizeMiB );
|
||||||
QFETCH( int, newStartMiB );
|
QFETCH( unsigned int, newStartMiB );
|
||||||
QFETCH( int, newSizeMiB );
|
QFETCH( unsigned int, newSizeMiB );
|
||||||
|
|
||||||
const qint64 sectorsPerMiB = 1_MiB / m_device->logicalSize();
|
const qint64 sectorsPerMiB = 1_MiB / m_device->logicalSize();
|
||||||
|
|
||||||
|
@ -36,6 +36,7 @@ class QueueRunner : public QObject
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
QueueRunner( Calamares::JobQueue* queue );
|
QueueRunner( Calamares::JobQueue* queue );
|
||||||
|
virtual ~QueueRunner() override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Synchronously runs the queue. Returns true on success
|
* Synchronously runs the queue. Returns true on success
|
||||||
|
Loading…
Reference in New Issue
Block a user