From 0f335341f35462282b3955d4183828edf41c55b4 Mon Sep 17 00:00:00 2001 From: danjujan <44864658+danjujan@users.noreply.github.com> Date: Fri, 6 Oct 2023 17:22:39 +0200 Subject: [PATCH] Add GetAllConfigurations2 unittest to detect bug --- unittests/Solver/ConfigurationFactory.cpp | 21 ++++++++++++++ unittests/resources/CMakeLists.txt | 1 + .../xml/test_three_optional_features.xml | 29 +++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 unittests/resources/xml/test_three_optional_features.xml diff --git a/unittests/Solver/ConfigurationFactory.cpp b/unittests/Solver/ConfigurationFactory.cpp index 5170271fa..2a095ea34 100644 --- a/unittests/Solver/ConfigurationFactory.cpp +++ b/unittests/Solver/ConfigurationFactory.cpp @@ -2,6 +2,8 @@ #include "vara/Feature/ConstraintBuilder.h" #include "vara/Feature/FeatureModelBuilder.h" + +#include "Utils/UnittestHelper.h" #include "gtest/gtest.h" namespace vara::solver { @@ -51,6 +53,25 @@ TEST(ConfigurationFactory, GetAllConfigurations) { EXPECT_EQ(ConfigResult.extractValue().size(), 6 * 63); } +TEST(ConfigurationFactory, GetAllConfigurations2) { + auto FM = feature::loadFeatureModel( + getTestResource("test_three_optional_features.xml")); + auto ConfigResult = ConfigurationFactory::getAllConfigs(*FM); + EXPECT_TRUE(ConfigResult); + auto Configs = ConfigResult.extractValue(); + + EXPECT_EQ(Configs.size(), 8); + + auto ConfigsStrings = std::vector(); + for (auto &config : Configs) { + ConfigsStrings.push_back(config.get()->dumpToString()); + } + + auto UniqueConfigs = + std::set(ConfigsStrings.begin(), ConfigsStrings.end()); + EXPECT_EQ(Configs.size(), UniqueConfigs.size()); +} + TEST(ConfigurationFactory, GetNConfigurations) { auto FM = getFeatureModel(); auto ConfigResult = ConfigurationFactory::getNConfigs(*FM, 100); diff --git a/unittests/resources/CMakeLists.txt b/unittests/resources/CMakeLists.txt index a243fcb77..5d47f4336 100644 --- a/unittests/resources/CMakeLists.txt +++ b/unittests/resources/CMakeLists.txt @@ -39,6 +39,7 @@ set(FEATURE_LIB_TEST_FILES xml/test_output_string.xml xml/test_revision_range.xml xml/test_step_function.xml + xml/test_three_optional_features.xml xml/test_with_whitespaces.xml yml/dune_configs.yml ) diff --git a/unittests/resources/xml/test_three_optional_features.xml b/unittests/resources/xml/test_three_optional_features.xml new file mode 100644 index 000000000..d18ea984f --- /dev/null +++ b/unittests/resources/xml/test_three_optional_features.xml @@ -0,0 +1,29 @@ + + + + + + root + + False + + + A + A + root + True + + + B + B + root + True + + + C + C + root + True + + +