diff --git a/src/modules/contextualprocess/CMakeLists.txt b/src/modules/contextualprocess/CMakeLists.txt index df27dc938..2cf8d3879 100644 --- a/src/modules/contextualprocess/CMakeLists.txt +++ b/src/modules/contextualprocess/CMakeLists.txt @@ -7,3 +7,22 @@ calamares_add_plugin( contextualprocess calamares SHARED_LIB ) + +if( ECM_FOUND ) + find_package( Qt5 COMPONENTS Test REQUIRED ) + include( ECMAddTests ) + + ecm_add_test( + Tests.cpp + ContextualProcessJob.cpp # Builds it a second time + TEST_NAME + contextualprocesstest + LINK_LIBRARIES + ${CALAMARES_LIBRARIES} + calamaresui + ${YAMLCPP_LIBRARY} + Qt5::Core + Qt5::Test + ) + set_target_properties( contextualprocesstest PROPERTIES AUTOMOC TRUE ) +endif() diff --git a/src/modules/contextualprocess/Tests.cpp b/src/modules/contextualprocess/Tests.cpp new file mode 100644 index 000000000..ed6d4f278 --- /dev/null +++ b/src/modules/contextualprocess/Tests.cpp @@ -0,0 +1,71 @@ +/* === This file is part of Calamares - === + * + * Copyright 2017, Adriaan de Groot + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#include "Tests.h" +#include "ContextualProcessJob.h" + +#include "utils/CommandList.h" +#include "utils/YamlUtils.h" + +#include + +#include + +#include +#include + +QTEST_GUILESS_MAIN( ContextualProcessTests ) + +using CommandList = CalamaresUtils::CommandList; + +ContextualProcessTests::ContextualProcessTests() +{ +} + +ContextualProcessTests::~ContextualProcessTests() +{ +} + +void +ContextualProcessTests::initTestCase() +{ +} + +void +ContextualProcessTests::testProcessListSampleConfig() +{ + YAML::Node doc; + + QStringList dirs { "src/modules/contextualprocess", "." }; + for ( const auto& dir : dirs ) + { + QString filename = dir + "/contextualprocess.conf"; + if ( QFileInfo::exists( filename ) ) + { + doc = YAML::LoadFile( filename.toStdString() ); + break; + } + } + + ContextualProcessJob job; + job.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc ).toMap() ); + + QCOMPARE(job.count(), 1); // Only "firmwareType" + QCOMPARE(job.count("firmwareType"), 4); +} + diff --git a/src/modules/contextualprocess/Tests.h b/src/modules/contextualprocess/Tests.h new file mode 100644 index 000000000..1708e53f0 --- /dev/null +++ b/src/modules/contextualprocess/Tests.h @@ -0,0 +1,37 @@ +/* === This file is part of Calamares - === + * + * Copyright 2018, Adriaan de Groot + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#ifndef TESTS_H +#define TESTS_H + +#include + +class ContextualProcessTests : public QObject +{ + Q_OBJECT +public: + ContextualProcessTests(); + ~ContextualProcessTests() override; + +private Q_SLOTS: + void initTestCase(); + // Check the sample config file is processed correctly + void testProcessListSampleConfig(); +}; + +#endif