From d86e9de5cb69746d9d64b2b671978042c7a34ebd Mon Sep 17 00:00:00 2001 From: Matthias Maier Date: Mon, 22 Jan 2024 16:17:59 -0600 Subject: [PATCH] ParameterAcceptor: check that we set values correctly for multiple live objects of the same class Closes #16520 --- .../parameter_acceptor_12.cc | 52 +++++++++++++++++++ .../parameter_acceptor_12.output | 3 ++ 2 files changed, 55 insertions(+) create mode 100644 tests/parameter_handler/parameter_acceptor_12.cc create mode 100644 tests/parameter_handler/parameter_acceptor_12.output diff --git a/tests/parameter_handler/parameter_acceptor_12.cc b/tests/parameter_handler/parameter_acceptor_12.cc new file mode 100644 index 0000000000..d4af2c21e6 --- /dev/null +++ b/tests/parameter_handler/parameter_acceptor_12.cc @@ -0,0 +1,52 @@ +//----------------------------------------------------------- +// +// Copyright (C) 2023 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE.md at +// the top level directory of deal.II. +// +//----------------------------------------------------------- + + +// Test that we set parameters for multiple instances of the same class +// correctly + +#include + +#include "../tests.h" + +struct Foo : public dealii::ParameterAcceptor +{ + Foo() + : dealii::ParameterAcceptor("A subsection") + { + add_parameter("A parameter", a); + } + int a = 1; +}; + +int +main() +{ + initlog(); + + Foo foo_1; + Foo foo_2; + Foo foo_3; + + deallog << foo_1.a << " - " << foo_2.a << " - " << foo_3.a << std::endl; + + std::stringstream parameters; + parameters << "subsection A subsection\n" + << "set A parameter = 2\n" + << "end" << std::endl; + ParameterAcceptor::initialize(parameters); + + deallog << foo_1.a << " - " << foo_2.a << " - " << foo_3.a << std::endl; +} diff --git a/tests/parameter_handler/parameter_acceptor_12.output b/tests/parameter_handler/parameter_acceptor_12.output new file mode 100644 index 0000000000..36ee19b469 --- /dev/null +++ b/tests/parameter_handler/parameter_acceptor_12.output @@ -0,0 +1,3 @@ + +DEAL::1 - 1 - 1 +DEAL::2 - 2 - 2 -- 2.39.5