From 7b6ff8dd371c22ad842cb0f54063f8a71668e853 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 3 Aug 2020 15:13:51 +0200 Subject: [PATCH] [libcalamares] Minor tests for parts of RAII --- src/libcalamares/utils/Tests.cpp | 36 ++++++++++++++++++++++++++------ src/libcalamares/utils/Tests.h | 5 ++++- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/libcalamares/utils/Tests.cpp b/src/libcalamares/utils/Tests.cpp index a1bfcd0ed..120a9238b 100644 --- a/src/libcalamares/utils/Tests.cpp +++ b/src/libcalamares/utils/Tests.cpp @@ -1,5 +1,5 @@ /* === This file is part of Calamares - === - * + * * SPDX-FileCopyrightText: 2018 Adriaan de Groot * * @@ -26,6 +26,7 @@ #include "CalamaresUtilsSystem.h" #include "Entropy.h" #include "Logger.h" +#include "RAII.h" #include "UMask.h" #include "Yaml.h" @@ -114,15 +115,16 @@ findConf( const QDir& d ) return mine; } -void LibCalamaresTests::recursiveCompareMap(const QVariantMap& a, const QVariantMap& b, int depth ) +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]; + const auto& av = a[ k ]; + const auto& bv = b[ k ]; if ( av.typeName() != bv.typeName() ) { @@ -130,9 +132,9 @@ void LibCalamaresTests::recursiveCompareMap(const QVariantMap& a, const QVariant cDebug() << Logger::SubEntry << "b type" << bv.typeName() << bv; } QCOMPARE( av.typeName(), bv.typeName() ); - if ( av.canConvert() ) + if ( av.canConvert< QVariantMap >() ) { - recursiveCompareMap( av.toMap(), bv.toMap(), depth+1 ); + recursiveCompareMap( av.toMap(), bv.toMap(), depth + 1 ); } else { @@ -289,3 +291,25 @@ LibCalamaresTests::testOddSizedPrintable() } } } + +void +LibCalamaresTests::testBoolSetter() +{ + bool b = false; + + QVERIFY( !b ); + { + QVERIFY( !b ); + cBoolSetter< true > x( b ); + QVERIFY( b ); + } + QVERIFY( !b ); + + QVERIFY( !b ); + { + QVERIFY( !b ); + cBoolSetter< false > x( b ); + QVERIFY( !b ); // Still! + } + QVERIFY( b ); +} diff --git a/src/libcalamares/utils/Tests.h b/src/libcalamares/utils/Tests.h index 2e1cba016..5a1f3528a 100644 --- a/src/libcalamares/utils/Tests.h +++ b/src/libcalamares/utils/Tests.h @@ -1,5 +1,5 @@ /* === This file is part of Calamares - === - * + * * SPDX-FileCopyrightText: 2018 Adriaan de Groot * * @@ -50,6 +50,9 @@ private Q_SLOTS: void testPrintableEntropy(); void testOddSizedPrintable(); + /** @brief Tests the RAII bits. */ + void testBoolSetter(); + private: void recursiveCompareMap( const QVariantMap& a, const QVariantMap& b, int depth ); };