]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add test.
authorWolfgang Bangerth <bangerth@colostate.edu>
Sat, 10 Jun 2017 00:28:45 +0000 (18:28 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Sat, 10 Jun 2017 00:28:45 +0000 (18:28 -0600)
tests/parameter_handler/save_flags.cc [new file with mode: 0644]
tests/parameter_handler/save_flags.output [new file with mode: 0644]

diff --git a/tests/parameter_handler/save_flags.cc b/tests/parameter_handler/save_flags.cc
new file mode 100644 (file)
index 0000000..091f0fe
--- /dev/null
@@ -0,0 +1,92 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2002 - 2016 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 that ParameterHandler::print_parameters() saves and resets
+// the iostream flags of the stream it writes to
+
+#include "../tests.h"
+#include <deal.II/base/logstream.h>
+#include <deal.II/base/parameter_handler.h>
+#include <fstream>
+#include <iomanip>
+
+
+int main ()
+{
+  std::ofstream logfile("output");
+  deallog.attach(logfile);
+  deallog.threshold_double(1.e-10);
+
+  ParameterHandler prm;
+  prm.declare_entry ("int1",
+                     "1",
+                     Patterns::Integer(),
+                     "doc 1");
+  prm.declare_entry ("int2",
+                     "2",
+                     Patterns::Integer(),
+                     "doc 2");
+  prm.enter_subsection ("ss1");
+  {
+    prm.declare_entry ("double 1",
+                       "1.234",
+                       Patterns::Double(),
+                       "doc 3");
+
+    prm.enter_subsection ("ss2");
+    {
+      prm.declare_entry ("double 2",
+                         "4.321",
+                         Patterns::Double(),
+                         "doc 4");
+    }
+    prm.leave_subsection ();
+  }
+  prm.leave_subsection ();
+
+  // things with strange characters
+  prm.enter_subsection ("Testing%testing");
+  {
+    prm.declare_entry ("string&list",
+                       "< & > ; /",
+                       Patterns::Anything(),
+                       "docs 1");
+    prm.declare_entry ("int*int",
+                       "2",
+                       Patterns::Integer());
+    prm.declare_entry ("double+double",
+                       "6.1415926",
+                       Patterns::Double(),
+                       "docs 3");
+  }
+  prm.leave_subsection ();
+
+  // set a special fill char and verify that it is being used
+  logfile.fill('x');
+  logfile.width(15);
+  logfile << std::left << 42 << std::endl;
+
+  // now let ParameterHandler output its state
+  prm.print_parameters (logfile, ParameterHandler::Description);
+
+  // verify that the special fill char is still available (i.e., that
+  // print_parameters() has saved and restored the stream flags)
+  logfile.width(15);
+  logfile << std::left << 42 << std::endl;
+
+  return 0;
+}
diff --git a/tests/parameter_handler/save_flags.output b/tests/parameter_handler/save_flags.output
new file mode 100644 (file)
index 0000000..6f7ee31
--- /dev/null
@@ -0,0 +1,21 @@
+
+42xxxxxxxxxxxxx
+Listing of Parameters:
+
+set int1  =   An integer n such that -2147483648 <= n <= 2147483647
+              (doc 1)
+set int2  =   An integer n such that -2147483648 <= n <= 2147483647
+              (doc 2)
+subsection Testing%testing
+  set double+double  =   A floating point number v such that -MAX_DOUBLE <= v <= MAX_DOUBLE
+                         (docs 3)
+  set int*int        =   An integer n such that -2147483648 <= n <= 2147483647
+  set string&list    =   Any string
+                         (docs 1)
+subsection ss1
+  set double 1  =   A floating point number v such that -MAX_DOUBLE <= v <= MAX_DOUBLE
+                    (doc 3)
+  subsection ss2
+    set double 2  =   A floating point number v such that -MAX_DOUBLE <= v <= MAX_DOUBLE
+                      (doc 4)
+42xxxxxxxxxxxxx

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.