]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add test for the read json parameter handler.
authorMFraters <menno.fraters@hotmail.com>
Thu, 8 Mar 2018 15:59:32 +0000 (16:59 +0100)
committerMFraters <menno.fraters@hotmail.com>
Thu, 8 Mar 2018 16:15:42 +0000 (17:15 +0100)
tests/parameter_handler/parameter_handler_read_json.cc [new file with mode: 0644]
tests/parameter_handler/parameter_handler_read_json.output [new file with mode: 0644]
tests/parameter_handler/prm/parameter_handler_read_json.prm [new file with mode: 0644]

diff --git a/tests/parameter_handler/parameter_handler_read_json.cc b/tests/parameter_handler/parameter_handler_read_json.cc
new file mode 100644 (file)
index 0000000..aa8fc57
--- /dev/null
@@ -0,0 +1,82 @@
+// ---------------------------------------------------------------------
+//
+// 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 ParameterHandler::parse_input_from_xml
+
+#include "../tests.h"
+#include <deal.II/base/parameter_handler.h>
+
+
+int main ()
+{
+  std::ofstream logfile("output");
+  deallog.attach(logfile);
+
+  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 ();
+
+  // read from json
+  std::ifstream in (SOURCE_DIR "/prm/parameter_handler_read_json.prm");
+  prm.parse_input_from_json (in);
+
+  // write it out again
+  prm.print_parameters (deallog.get_file_stream(), ParameterHandler::JSON);
+  logfile << std::endl;
+
+  return 0;
+}
diff --git a/tests/parameter_handler/parameter_handler_read_json.output b/tests/parameter_handler/parameter_handler_read_json.output
new file mode 100644 (file)
index 0000000..fd2d434
--- /dev/null
@@ -0,0 +1,69 @@
+
+{
+    "int1":
+    {
+        "value": "2",
+        "default_value": "1",
+        "documentation": "doc 1",
+        "pattern": "0",
+        "pattern_description": "[Integer range -2147483648...2147483647 (inclusive)]"
+    },
+    "int2":
+    {
+        "value": "3",
+        "default_value": "2",
+        "documentation": "doc 2",
+        "pattern": "1",
+        "pattern_description": "[Integer range -2147483648...2147483647 (inclusive)]"
+    },
+    "ss1":
+    {
+        "double_201":
+        {
+            "value": "2.234",
+            "default_value": "1.234",
+            "documentation": "doc 3",
+            "pattern": "2",
+            "pattern_description": "[Double -MAX_DOUBLE...MAX_DOUBLE (inclusive)]"
+        },
+        "ss2":
+        {
+            "double_202":
+            {
+                "value": "5.321",
+                "default_value": "4.321",
+                "documentation": "doc 4",
+                "pattern": "3",
+                "pattern_description": "[Double -MAX_DOUBLE...MAX_DOUBLE (inclusive)]"
+            }
+        }
+    },
+    "Testing_25testing":
+    {
+        "string_26list":
+        {
+            "value": "< & > ; \/",
+            "default_value": "< & > ; \/",
+            "documentation": "docs 1",
+            "pattern": "4",
+            "pattern_description": "[Anything]"
+        },
+        "int_2aint":
+        {
+            "value": "2",
+            "default_value": "2",
+            "documentation": "",
+            "pattern": "5",
+            "pattern_description": "[Integer range -2147483648...2147483647 (inclusive)]"
+        },
+        "double_2bdouble":
+        {
+            "value": "7.1415926",
+            "default_value": "6.1415926",
+            "documentation": "docs 3",
+            "pattern": "6",
+            "pattern_description": "[Double -MAX_DOUBLE...MAX_DOUBLE (inclusive)]"
+        }
+    }
+}
+
diff --git a/tests/parameter_handler/prm/parameter_handler_read_json.prm b/tests/parameter_handler/prm/parameter_handler_read_json.prm
new file mode 100644 (file)
index 0000000..fd2d434
--- /dev/null
@@ -0,0 +1,69 @@
+
+{
+    "int1":
+    {
+        "value": "2",
+        "default_value": "1",
+        "documentation": "doc 1",
+        "pattern": "0",
+        "pattern_description": "[Integer range -2147483648...2147483647 (inclusive)]"
+    },
+    "int2":
+    {
+        "value": "3",
+        "default_value": "2",
+        "documentation": "doc 2",
+        "pattern": "1",
+        "pattern_description": "[Integer range -2147483648...2147483647 (inclusive)]"
+    },
+    "ss1":
+    {
+        "double_201":
+        {
+            "value": "2.234",
+            "default_value": "1.234",
+            "documentation": "doc 3",
+            "pattern": "2",
+            "pattern_description": "[Double -MAX_DOUBLE...MAX_DOUBLE (inclusive)]"
+        },
+        "ss2":
+        {
+            "double_202":
+            {
+                "value": "5.321",
+                "default_value": "4.321",
+                "documentation": "doc 4",
+                "pattern": "3",
+                "pattern_description": "[Double -MAX_DOUBLE...MAX_DOUBLE (inclusive)]"
+            }
+        }
+    },
+    "Testing_25testing":
+    {
+        "string_26list":
+        {
+            "value": "< & > ; \/",
+            "default_value": "< & > ; \/",
+            "documentation": "docs 1",
+            "pattern": "4",
+            "pattern_description": "[Anything]"
+        },
+        "int_2aint":
+        {
+            "value": "2",
+            "default_value": "2",
+            "documentation": "",
+            "pattern": "5",
+            "pattern_description": "[Integer range -2147483648...2147483647 (inclusive)]"
+        },
+        "double_2bdouble":
+        {
+            "value": "7.1415926",
+            "default_value": "6.1415926",
+            "documentation": "docs 3",
+            "pattern": "6",
+            "pattern_description": "[Double -MAX_DOUBLE...MAX_DOUBLE (inclusive)]"
+        }
+    }
+}
+

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.