[libcalamares] Add name to module descriptor

- introduce basic tests of the data structure
- interpret name when passed in as descriptor data
main
Adriaan de Groot 5 years ago
parent e1e81bb133
commit e406ae1967

@ -60,7 +60,8 @@ Descriptor::fromDescriptorData( const QVariantMap& moduleDesc )
Type t = typeNames().find( moduleDesc.value( "type" ).toString(), typeOk ); Type t = typeNames().find( moduleDesc.value( "type" ).toString(), typeOk );
bool interfaceOk = false; bool interfaceOk = false;
Interface i = interfaceNames().find( moduleDesc.value( "interface" ).toString(), interfaceOk ); 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_type = t;
d.m_interface = i; d.m_interface = i;

@ -74,7 +74,7 @@ public:
bool isValid() const { return m_isValid; } bool isValid() const { return m_isValid; }
QString name() const { return QString(); } QString name() const { return m_name; }
Type type() const { return m_type; } Type type() const { return m_type; }
Interface interface() const { return m_interface; } Interface interface() const { return m_interface; }
@ -119,6 +119,7 @@ public:
QString script() const { return QString(); } QString script() const { return QString(); }
private: private:
QString m_name;
QString m_directory; QString m_directory;
Type m_type; Type m_type;
Interface m_interface; Interface m_interface;

@ -18,6 +18,7 @@
* *
*/ */
#include "modulesystem/Descriptor.h"
#include "modulesystem/InstanceKey.h" #include "modulesystem/InstanceKey.h"
#include <QtTest/QtTest> #include <QtTest/QtTest>
@ -40,6 +41,8 @@ private Q_SLOTS:
void testBadSimpleCases(); void testBadSimpleCases();
void testBadFromStringCases(); void testBadFromStringCases();
void testBasicDescriptor();
}; };
void void
@ -136,6 +139,47 @@ ModuleSystemTests::testBadFromStringCases()
assert_is_invalid( k0 ); 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 ) QTEST_GUILESS_MAIN( ModuleSystemTests )

Loading…
Cancel
Save