diff --git a/src/libcalamares/utils/Tests.cpp b/src/libcalamares/utils/Tests.cpp index 7a6d52623..a689505e9 100644 --- a/src/libcalamares/utils/Tests.cpp +++ b/src/libcalamares/utils/Tests.cpp @@ -46,26 +46,27 @@ private Q_SLOTS: void testCommands(); - /** @brief Test that all the UMask objects work correctly. */ + /** @section Test that all the UMask objects work correctly. */ void testUmask(); - /** @brief Tests the entropy functions. */ + /** @section Tests the entropy functions. */ void testEntropy(); void testPrintableEntropy(); void testOddSizedPrintable(); - /** @brief Tests the RAII bits. */ + /** @section Tests the RAII bits. */ void testBoolSetter(); void testPointerSetter(); - /** @brief Tests the Traits bits. */ + /** @section Tests the Traits bits. */ void testTraits(); + /** @section Testing the variants-methods */ void testVariantStringListCode(); void testVariantStringListYAMLDashed(); void testVariantStringListYAMLBracketed(); - /** @brief Test smart string truncation. */ + /** @section Test smart string truncation. */ void testStringTruncation(); void testStringTruncationShorter(); void testStringTruncationDegenerate(); @@ -476,17 +477,31 @@ LibCalamaresTests::testVariantStringListCode() QCOMPARE( getStringList( m, key ), QStringList {} ); m.insert( key, 17 ); QCOMPARE( getStringList( m, key ), QStringList {} ); - m.insert( key, QString( "more strings" ) ); - QCOMPARE( getStringList( m, key ), - QStringList { "more strings" } ); // A single string **can** be considered a stringlist! m.insert( key, QVariant {} ); QCOMPARE( getStringList( m, key ), QStringList {} ); } { - // Things that are stringlists + // Things that are **like** stringlists + QVariantMap m; + m.insert( key, QString( "astring" ) ); + QCOMPARE( getStringList( m, key ).count(), 1 ); + QCOMPARE( getStringList( m, key ), + QStringList { "astring" } ); // A single string **can** be considered a stringlist! + m.insert( key, QString( "more strings" ) ); + QCOMPARE( getStringList( m, key ).count(), 1 ); + QCOMPARE( getStringList( m, key ), + QStringList { "more strings" } ); + m.insert( key, QString() ); + QCOMPARE( getStringList( m, key ).count(), 1 ); + QCOMPARE( getStringList( m, key ), QStringList { QString() } ); + } + + { + // Things that are definitely stringlists QVariantMap m; m.insert( key, QStringList { "aap", "noot" } ); + QCOMPARE( getStringList( m, key ).count(), 2 ); QVERIFY( getStringList( m, key ).contains( "aap" ) ); QVERIFY( !getStringList( m, key ).contains( "mies" ) ); } diff --git a/src/libcalamares/utils/Variant.h b/src/libcalamares/utils/Variant.h index e1261f877..ab9e73f90 100644 --- a/src/libcalamares/utils/Variant.h +++ b/src/libcalamares/utils/Variant.h @@ -25,13 +25,17 @@ namespace CalamaresUtils */ DLLEXPORT bool getBool( const QVariantMap& map, const QString& key, bool d = false ); -/** - * Get a string value from a mapping with a given key; returns @p d if no value. +/** @brief Get a string value from a mapping with a given key; returns @p d if no value. + * + * The value must be an actual string; numbers are not automatically converted to strings, + * nor are lists flattened or converted. */ DLLEXPORT QString getString( const QVariantMap& map, const QString& key, const QString& d = QString() ); -/** - * Get a string list from a mapping with a given key; returns @p d if no value. +/** @brief Get a string list from a mapping with a given key; returns @p d if no value. + * + * This is slightly more lenient that getString(), and a single-string value will + * be returned as a 1-item list. */ DLLEXPORT QStringList getStringList( const QVariantMap& map, const QString& key, const QStringList& d = QStringList() );