From: MFraters Date: Thu, 8 Mar 2018 15:59:32 +0000 (+0100) Subject: Add test for the read json parameter handler. X-Git-Tag: v9.0.0-rc1~337^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=af101705f5366a74ad662d34c049d6c6d79c423f;p=dealii.git Add test for the read json parameter handler. --- diff --git a/tests/parameter_handler/parameter_handler_read_json.cc b/tests/parameter_handler/parameter_handler_read_json.cc new file mode 100644 index 0000000000..aa8fc57c98 --- /dev/null +++ b/tests/parameter_handler/parameter_handler_read_json.cc @@ -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 + + +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 index 0000000000..fd2d434348 --- /dev/null +++ b/tests/parameter_handler/parameter_handler_read_json.output @@ -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 index 0000000000..fd2d434348 --- /dev/null +++ b/tests/parameter_handler/prm/parameter_handler_read_json.prm @@ -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)]" + } + } +} +