[libcalamares] Add name to module descriptor
- introduce basic tests of the data structure - interpret name when passed in as descriptor data
This commit is contained in:
parent
e1e81bb133
commit
e406ae1967
@ -60,7 +60,8 @@ Descriptor::fromDescriptorData( const QVariantMap& moduleDesc )
|
||||
Type t = typeNames().find( moduleDesc.value( "type" ).toString(), typeOk );
|
||||
bool interfaceOk = false;
|
||||
Interface i = interfaceNames().find( moduleDesc.value( "interface" ).toString(), interfaceOk );
|
||||
if ( typeOk && interfaceOk )
|
||||
d.m_name = moduleDesc.value( "name" ).toString();
|
||||
if ( typeOk && interfaceOk && !d.m_name.isEmpty() )
|
||||
{
|
||||
d.m_type = t;
|
||||
d.m_interface = i;
|
||||
|
@ -74,7 +74,7 @@ public:
|
||||
|
||||
bool isValid() const { return m_isValid; }
|
||||
|
||||
QString name() const { return QString(); }
|
||||
QString name() const { return m_name; }
|
||||
Type type() const { return m_type; }
|
||||
Interface interface() const { return m_interface; }
|
||||
|
||||
@ -119,6 +119,7 @@ public:
|
||||
QString script() const { return QString(); }
|
||||
|
||||
private:
|
||||
QString m_name;
|
||||
QString m_directory;
|
||||
Type m_type;
|
||||
Interface m_interface;
|
||||
|
@ -18,6 +18,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "modulesystem/Descriptor.h"
|
||||
#include "modulesystem/InstanceKey.h"
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
@ -40,6 +41,8 @@ private Q_SLOTS:
|
||||
|
||||
void testBadSimpleCases();
|
||||
void testBadFromStringCases();
|
||||
|
||||
void testBasicDescriptor();
|
||||
};
|
||||
|
||||
void
|
||||
@ -136,6 +139,47 @@ ModuleSystemTests::testBadFromStringCases()
|
||||
assert_is_invalid( k0 );
|
||||
}
|
||||
|
||||
void
|
||||
ModuleSystemTests::testBasicDescriptor()
|
||||
{
|
||||
{
|
||||
QVariantMap m;
|
||||
auto d = Calamares::ModuleSystem::Descriptor::fromDescriptorData( m );
|
||||
|
||||
QVERIFY( !d.isValid() );
|
||||
QVERIFY( d.name().isEmpty() );
|
||||
}
|
||||
{
|
||||
QVariantMap m;
|
||||
m.insert( "name", QVariant() );
|
||||
auto d = Calamares::ModuleSystem::Descriptor::fromDescriptorData( m );
|
||||
|
||||
QVERIFY( !d.isValid() );
|
||||
QVERIFY( d.name().isEmpty() );
|
||||
}
|
||||
{
|
||||
QVariantMap m;
|
||||
m.insert( "name", 17 );
|
||||
auto d = Calamares::ModuleSystem::Descriptor::fromDescriptorData( m );
|
||||
|
||||
QVERIFY( !d.isValid() );
|
||||
QVERIFY( !d.name().isEmpty() );
|
||||
QCOMPARE( d.name(), QStringLiteral( "17" ) ); // Strange but true
|
||||
}
|
||||
{
|
||||
QVariantMap m;
|
||||
m.insert( "name", "welcome" );
|
||||
m.insert( "type", "viewmodule" );
|
||||
m.insert( "interface", "qtplugin" );
|
||||
auto d = Calamares::ModuleSystem::Descriptor::fromDescriptorData( m );
|
||||
|
||||
// QVERIFY( !d.isValid() );
|
||||
QCOMPARE( d.name(), QStringLiteral( "welcome" ) );
|
||||
QCOMPARE( d.type(), Calamares::ModuleSystem::Type::View );
|
||||
QCOMPARE( d.interface(), Calamares::ModuleSystem::Interface::QtPlugin );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QTEST_GUILESS_MAIN( ModuleSystemTests )
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user