|
|
|
@ -7,13 +7,17 @@
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "Config.h"
|
|
|
|
|
#include "PackageModel.h"
|
|
|
|
|
#include "PackageTreeItem.h"
|
|
|
|
|
|
|
|
|
|
#include "utils/Logger.h"
|
|
|
|
|
#include "utils/NamedEnum.h"
|
|
|
|
|
#include "utils/Variant.h"
|
|
|
|
|
#include "utils/Yaml.h"
|
|
|
|
|
|
|
|
|
|
#include <KMacroExpander>
|
|
|
|
|
|
|
|
|
|
#include <QtTest/QtTest>
|
|
|
|
|
|
|
|
|
|
class ItemTests : public QObject
|
|
|
|
@ -40,6 +44,9 @@ private Q_SLOTS:
|
|
|
|
|
void testCompare();
|
|
|
|
|
void testModel();
|
|
|
|
|
void testExampleFiles();
|
|
|
|
|
|
|
|
|
|
void testUrlFallback_data();
|
|
|
|
|
void testUrlFallback();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ItemTests::ItemTests() {}
|
|
|
|
@ -326,6 +333,93 @@ ItemTests::testExampleFiles()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ItemTests::testUrlFallback_data()
|
|
|
|
|
{
|
|
|
|
|
QTest::addColumn< QString >( "filename" );
|
|
|
|
|
QTest::addColumn< int >( "status" );
|
|
|
|
|
QTest::addColumn< int >( "count" );
|
|
|
|
|
|
|
|
|
|
using S = Config::Status;
|
|
|
|
|
|
|
|
|
|
QTest::newRow( "bad" ) << "1a-single-bad.conf" << smash( S::FailedBadConfiguration ) << 0;
|
|
|
|
|
QTest::newRow( "empty" ) << "1a-single-empty.conf" << smash( S::FailedNoData ) << 0;
|
|
|
|
|
QTest::newRow( "error" ) << "1a-single-error.conf" << smash( S::FailedBadData ) << 0;
|
|
|
|
|
QTest::newRow( "two" ) << "1b-single-small.conf" << smash( S::Ok ) << 2;
|
|
|
|
|
QTest::newRow( "five" ) << "1b-single-large.conf" << smash( S::Ok ) << 5;
|
|
|
|
|
QTest::newRow( "none" ) << "1c-none.conf" << smash( S::FailedNoData ) << 0;
|
|
|
|
|
QTest::newRow( "unset" ) << "1c-unset.conf" << smash( S::FailedNoData ) << 0;
|
|
|
|
|
// Finds small, then stops
|
|
|
|
|
QTest::newRow( "fallback-small" ) << "1d-fallback-small.conf" << smash( S::Ok ) << 2;
|
|
|
|
|
// Finds large, then stops
|
|
|
|
|
QTest::newRow( "fallback-large" ) << "1d-fallback-large.conf" << smash( S::Ok ) << 5;
|
|
|
|
|
// Finds empty, finds small
|
|
|
|
|
QTest::newRow( "fallback-mixed" ) << "1d-fallback-mixed.conf" << smash( S::Ok ) << 2;
|
|
|
|
|
// Finds empty, then bad
|
|
|
|
|
QTest::newRow( "fallback-bad" ) << "1d-fallback-bad.conf" << smash( S::FailedBadConfiguration ) << 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ItemTests::testUrlFallback()
|
|
|
|
|
{
|
|
|
|
|
Logger::setupLogLevel( Logger::LOGDEBUG );
|
|
|
|
|
QFETCH( QString, filename );
|
|
|
|
|
QFETCH( int, status );
|
|
|
|
|
QFETCH( int, count );
|
|
|
|
|
|
|
|
|
|
cDebug() << "Loading" << filename;
|
|
|
|
|
|
|
|
|
|
// BUILD_AS_TEST is the source-directory path
|
|
|
|
|
QString testdir = QString( "%1/tests" ).arg( BUILD_AS_TEST );
|
|
|
|
|
QFile fi( QString( "%1/%2" ).arg( testdir, filename ) );
|
|
|
|
|
QVERIFY( fi.exists() );
|
|
|
|
|
|
|
|
|
|
Config c;
|
|
|
|
|
|
|
|
|
|
QFile yamlFile( fi.fileName() );
|
|
|
|
|
if ( yamlFile.exists() && yamlFile.open( QFile::ReadOnly | QFile::Text ) )
|
|
|
|
|
{
|
|
|
|
|
QString ba( yamlFile.readAll() );
|
|
|
|
|
QVERIFY( ba.length() > 0 );
|
|
|
|
|
QHash< QString, QString > replace;
|
|
|
|
|
replace.insert( "TESTDIR", testdir );
|
|
|
|
|
QString correctedDocument = KMacroExpander::expandMacros( ba, replace, '$' );
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
YAML::Node yamldoc = YAML::Load( correctedDocument.toUtf8() );
|
|
|
|
|
auto map = CalamaresUtils::yamlToVariant( yamldoc ).toMap();
|
|
|
|
|
QVERIFY( map.count() > 0 );
|
|
|
|
|
c.setConfigurationMap( map );
|
|
|
|
|
}
|
|
|
|
|
catch ( YAML::Exception& e )
|
|
|
|
|
{
|
|
|
|
|
bool badYaml = true;
|
|
|
|
|
QVERIFY( !badYaml );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
QCOMPARE( QStringLiteral( "not found" ), fi.fileName() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Each of the configs sets required to **true**, which is not the default
|
|
|
|
|
QVERIFY( c.required() );
|
|
|
|
|
|
|
|
|
|
// Now give the loader time to complete
|
|
|
|
|
QEventLoop loop;
|
|
|
|
|
connect( &c, &Config::statusReady, &loop, &QEventLoop::quit );
|
|
|
|
|
QSignalSpy spy( &c, &Config::statusReady );
|
|
|
|
|
QTimer::singleShot( std::chrono::seconds(1), &loop, &QEventLoop::quit );
|
|
|
|
|
loop.exec();
|
|
|
|
|
|
|
|
|
|
// Check it didn't time out
|
|
|
|
|
QCOMPARE( spy.count(), 1 );
|
|
|
|
|
// Check YAML-loading results
|
|
|
|
|
QCOMPARE( smash( c.statusCode() ), status );
|
|
|
|
|
QCOMPARE( c.model()->rowCount(), count );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QTEST_GUILESS_MAIN( ItemTests )
|
|
|
|
|
|
|
|
|
|