]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add tests.
authorWolfgang Bangerth <bangerth@colostate.edu>
Mon, 17 Apr 2017 22:17:19 +0000 (16:17 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Tue, 18 Apr 2017 01:48:54 +0000 (19:48 -0600)
tests/parameter_handler/parameter_handler_action_01.cc [new file with mode: 0644]
tests/parameter_handler/parameter_handler_action_01.output [new file with mode: 0644]
tests/parameter_handler/parameter_handler_action_02.cc [new file with mode: 0644]
tests/parameter_handler/parameter_handler_action_02.output [new file with mode: 0644]

diff --git a/tests/parameter_handler/parameter_handler_action_01.cc b/tests/parameter_handler/parameter_handler_action_01.cc
new file mode 100644 (file)
index 0000000..c961a1b
--- /dev/null
@@ -0,0 +1,61 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2002 - 2017 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 at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+
+// check the ParameterHandler::add_action() function
+
+
+#include "../tests.h"
+#include <deal.II/base/logstream.h>
+#include <deal.II/base/parameter_handler.h>
+#include <fstream>
+
+
+void check (const char *p)
+{
+  std::string parameter_set_by_action;
+
+  ParameterHandler prm;
+  prm.declare_entry ("test_1", "-1,0",
+                     Patterns::List(Patterns::Integer(-1,1),2,3));
+  prm.add_action ("test_1",
+                  [&](const std::string &s)
+  {
+    deallog << "In action:" << s << std::endl;
+    parameter_set_by_action = s;
+    return true;
+  });
+
+
+  std::ifstream in(p);
+
+  deallog << "Reading parameters" << std::endl;
+  prm.read_input (in);
+
+  deallog << "test_1=" << prm.get ("test_1") << std::endl;
+  deallog << "Saved parameter: " << parameter_set_by_action << std::endl;
+}
+
+
+
+int main ()
+{
+  initlog();
+
+  check (SOURCE_DIR "/prm/parameter_handler_1.prm");
+
+  return 0;
+}
diff --git a/tests/parameter_handler/parameter_handler_action_01.output b/tests/parameter_handler/parameter_handler_action_01.output
new file mode 100644 (file)
index 0000000..f5a0575
--- /dev/null
@@ -0,0 +1,6 @@
+
+DEAL::In action:-1,0
+DEAL::Reading parameters
+DEAL::In action:1,0,1
+DEAL::test_1=1,0,1
+DEAL::Saved parameter: 1,0,1
diff --git a/tests/parameter_handler/parameter_handler_action_02.cc b/tests/parameter_handler/parameter_handler_action_02.cc
new file mode 100644 (file)
index 0000000..d432c02
--- /dev/null
@@ -0,0 +1,69 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2002 - 2017 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 at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+
+// check the ParameterHandler::add_action() function. like _01, but
+// attach a second action
+
+
+#include "../tests.h"
+#include <deal.II/base/logstream.h>
+#include <deal.II/base/parameter_handler.h>
+#include <fstream>
+
+
+void check (const char *p)
+{
+  std::string parameter_set_by_action;
+
+  ParameterHandler prm;
+  prm.declare_entry ("test_1", "-1,0",
+                     Patterns::List(Patterns::Integer(-1,1),2,3));
+  prm.add_action ("test_1",
+                  [&](const std::string &s)
+  {
+    deallog << "In action 1:" << s << std::endl;
+    parameter_set_by_action = s;
+    return true;
+  });
+  prm.add_action ("test_1",
+                  [&](const std::string &s)
+  {
+    deallog << "In action 2:" << s << std::endl;
+    parameter_set_by_action = s + " some modification";
+    return true;
+  });
+
+
+  std::ifstream in(p);
+
+  deallog << "Reading parameters" << std::endl;
+  prm.read_input (in);
+
+  deallog << "test_1=" << prm.get ("test_1") << std::endl;
+  deallog << "Saved parameter: " << parameter_set_by_action << std::endl;
+}
+
+
+
+int main ()
+{
+  initlog();
+
+  check (SOURCE_DIR "/prm/parameter_handler_1.prm");
+
+  return 0;
+}
diff --git a/tests/parameter_handler/parameter_handler_action_02.output b/tests/parameter_handler/parameter_handler_action_02.output
new file mode 100644 (file)
index 0000000..5726fdb
--- /dev/null
@@ -0,0 +1,8 @@
+
+DEAL::In action 1:-1,0
+DEAL::In action 2:-1,0
+DEAL::Reading parameters
+DEAL::In action 1:1,0,1
+DEAL::In action 2:1,0,1
+DEAL::test_1=1,0,1
+DEAL::Saved parameter: 1,0,1 some modification

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.