From f1a47a9f0a16e7ba9a9e5b2e09a7906876b5e8f8 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 24 Aug 2021 10:24:11 +0200 Subject: [PATCH] [welcome] Add (stub) test for the Config object This crashes because there's no translations object yet, but that is an internal issue. --- src/modules/welcome/CMakeLists.txt | 10 +++ src/modules/welcome/Tests.cpp | 61 +++++++++++++++++++ .../welcome/tests/1a-checkinternet.conf | 3 + 3 files changed, 74 insertions(+) create mode 100644 src/modules/welcome/Tests.cpp create mode 100644 src/modules/welcome/tests/1a-checkinternet.conf diff --git a/src/modules/welcome/CMakeLists.txt b/src/modules/welcome/CMakeLists.txt index 924062652..4895d4b80 100644 --- a/src/modules/welcome/CMakeLists.txt +++ b/src/modules/welcome/CMakeLists.txt @@ -42,3 +42,13 @@ calamares_add_plugin( welcome Qt5::Network SHARED_LIB ) + +calamares_add_test( + welcometest + SOURCES + Config.cpp + Tests.cpp + LIBRARIES + Qt5::Widgets + Calamares::calamaresui +) diff --git a/src/modules/welcome/Tests.cpp b/src/modules/welcome/Tests.cpp new file mode 100644 index 000000000..366de416f --- /dev/null +++ b/src/modules/welcome/Tests.cpp @@ -0,0 +1,61 @@ +/* === This file is part of Calamares - === + * + * SPDX-FileCopyrightText: 2021 Adriaan de Groot + * SPDX-License-Identifier: GPL-3.0-or-later + * + * Calamares is Free Software: see the License-Identifier above. + * + */ + +#include "Config.h" + +#include "utils/Logger.h" +#include "utils/Yaml.h" + +#include + +class WelcomeTests : public QObject +{ + Q_OBJECT +public: + WelcomeTests(); + ~WelcomeTests() override {} + +private Q_SLOTS: + void initTestCase(); + + void testOneUrl(); +}; + +WelcomeTests::WelcomeTests() {} + +void +WelcomeTests::initTestCase() +{ + Logger::setupLogLevel( Logger::LOGDEBUG ); + cDebug() << "Welcome test started."; +} + +void +WelcomeTests::testOneUrl() +{ + Config c; + + // BUILD_AS_TEST is the source-directory path + QString filename = QStringLiteral( "1a-checkinternet.conf" ); + QFile fi( QString( "%1/%2" ).arg( BUILD_AS_TEST, filename ) ); + QVERIFY( fi.exists() ); + + bool ok = false; + const auto map = CalamaresUtils::loadYaml( fi, &ok ); + QVERIFY( ok ); + QVERIFY( map.count() > 0 ); + QVERIFY( map.contains( "requirements" ) ); +} + + +QTEST_GUILESS_MAIN( WelcomeTests ) + +#include "utils/moc-warnings.h" + +#include "Tests.moc" diff --git a/src/modules/welcome/tests/1a-checkinternet.conf b/src/modules/welcome/tests/1a-checkinternet.conf new file mode 100644 index 000000000..d2140f201 --- /dev/null +++ b/src/modules/welcome/tests/1a-checkinternet.conf @@ -0,0 +1,3 @@ +--- +requirements: + internetCheckUrl: http://example.com