From c6463a30eacaffa482968712c2b0e76f317cb8e9 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 8 Apr 2020 14:19:11 +0200 Subject: [PATCH] [libcalamares] Be far more detailed in comparing maps - just comparing a==b (both QVariantMap) gives a not-so-informative message, so go through the keys looking for differences. --- src/libcalamares/utils/Tests.cpp | 37 ++++++++++++++++++++++++++++++-- src/libcalamares/utils/Tests.h | 3 +++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/libcalamares/utils/Tests.cpp b/src/libcalamares/utils/Tests.cpp index d50abef39..b529e7149 100644 --- a/src/libcalamares/utils/Tests.cpp +++ b/src/libcalamares/utils/Tests.cpp @@ -109,16 +109,49 @@ findConf( const QDir& d ) return mine; } +void LibCalamaresTests::recursiveCompareMap(const QVariantMap& a, const QVariantMap& b, int depth ) +{ + cDebug() << "Comparing depth" << depth << a.count() << b.count(); + QCOMPARE( a.keys(), b.keys() ); + for ( const auto& k : a.keys() ) + { + cDebug() << Logger::SubEntry << k; + const auto& av = a[k]; + const auto& bv = b[k]; + + if ( av.typeName() != bv.typeName() ) + { + cDebug() << Logger::SubEntry << "a type" << av.typeName() << av; + cDebug() << Logger::SubEntry << "b type" << bv.typeName() << bv; + } + QCOMPARE( av.typeName(), bv.typeName() ); + if ( av.canConvert() ) + { + recursiveCompareMap( av.toMap(), bv.toMap(), depth+1 ); + } + else + { + QCOMPARE( av, bv ); + } + } +} + void LibCalamaresTests::testLoadSaveYamlExtended() { + bool loaded_ok; for ( const auto& confname : findConf( QDir( "../src" ) ) ) { + loaded_ok = true; cDebug() << "Testing" << confname; - auto map = CalamaresUtils::loadYaml( confname ); + auto map = CalamaresUtils::loadYaml( confname, &loaded_ok ); + QVERIFY( loaded_ok ); QVERIFY( CalamaresUtils::saveYaml( "out.yaml", map ) ); - auto othermap = CalamaresUtils::loadYaml( "out.yaml" ); + auto othermap = CalamaresUtils::loadYaml( "out.yaml", &loaded_ok ); + QVERIFY( loaded_ok ); + QCOMPARE( map.keys(), othermap.keys() ); + recursiveCompareMap( map, othermap, 0 ); QCOMPARE( map, othermap ); } QFile::remove( "out.yaml" ); diff --git a/src/libcalamares/utils/Tests.h b/src/libcalamares/utils/Tests.h index f9908c74c..49df8ed74 100644 --- a/src/libcalamares/utils/Tests.h +++ b/src/libcalamares/utils/Tests.h @@ -44,6 +44,9 @@ private Q_SLOTS: void testEntropy(); void testPrintableEntropy(); void testOddSizedPrintable(); + +private: + void recursiveCompareMap( const QVariantMap& a, const QVariantMap& b, int depth ); }; #endif