From 57e369904be60ea6f433bcb1e0c47363b25519c1 Mon Sep 17 00:00:00 2001 From: bangerth Date: Mon, 20 Dec 2010 14:16:47 +0000 Subject: [PATCH] Some more tests. git-svn-id: https://svn.dealii.org/trunk@23023 0785d39b-7218-0410-832d-ea1e28bc413d --- .../parameter_handler_read_xml_error_02.cc | 83 +++++++++++++++++++ .../cmp/generic | 2 + .../parameter_handler_read_xml_error_02/prm | 4 + .../parameter_handler_read_xml_error_03.cc | 83 +++++++++++++++++++ .../cmp/generic | 2 + .../parameter_handler_read_xml_error_03/prm | 5 ++ 6 files changed, 179 insertions(+) create mode 100644 tests/bits/parameter_handler_read_xml_error_02.cc create mode 100644 tests/bits/parameter_handler_read_xml_error_02/cmp/generic create mode 100644 tests/bits/parameter_handler_read_xml_error_02/prm create mode 100644 tests/bits/parameter_handler_read_xml_error_03.cc create mode 100644 tests/bits/parameter_handler_read_xml_error_03/cmp/generic create mode 100644 tests/bits/parameter_handler_read_xml_error_03/prm diff --git a/tests/bits/parameter_handler_read_xml_error_02.cc b/tests/bits/parameter_handler_read_xml_error_02.cc new file mode 100644 index 0000000000..581fbf5f20 --- /dev/null +++ b/tests/bits/parameter_handler_read_xml_error_02.cc @@ -0,0 +1,83 @@ +//---------------------------- parameter_handler_read_xml_error_02.cc --------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2002, 2003, 2004, 2005, 2010 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//---------------------------- parameter_handler_read_xml_error_02.cc --------------------------- + + +// check ParameterHandler::read_input_from_xml. try to read a file that is not +// valid XML (the last end-tag is missing) + +#include "../tests.h" +#include +#include +#include + + +int main () +{ + std::ofstream logfile("parameter_handler_read_xml_error_02/output"); + deallog.attach(logfile); + deallog.depth_console(0); + 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 (); + + // read from XML + std::ifstream in ("parameter_handler_read_xml_error_02/prm"); + bool result = prm.read_input_from_xml (in); + Assert (result == false, ExcInternalError()); + + deallog << "OK" << std::endl; + + return 0; +} diff --git a/tests/bits/parameter_handler_read_xml_error_02/cmp/generic b/tests/bits/parameter_handler_read_xml_error_02/cmp/generic new file mode 100644 index 0000000000..0fd8fc12f0 --- /dev/null +++ b/tests/bits/parameter_handler_read_xml_error_02/cmp/generic @@ -0,0 +1,2 @@ + +DEAL::OK diff --git a/tests/bits/parameter_handler_read_xml_error_02/prm b/tests/bits/parameter_handler_read_xml_error_02/prm new file mode 100644 index 0000000000..d19001e919 --- /dev/null +++ b/tests/bits/parameter_handler_read_xml_error_02/prm @@ -0,0 +1,4 @@ + + +21doc 10[Integer range -2147483648...2147483647 (inclusive)]32doc 21[Integer range -2147483648...2147483647 (inclusive)]2.2341.234doc 32[Double -1.79769e+308...1.79769e+308 (inclusive)]5.3214.321doc 43[Double -1.79769e+308...1.79769e+308 (inclusive)]__< & > ; /< & > ; /docs 14[Anything]__22 +5[Integer range -2147483648...2147483647 (inclusive)]7.14159266.1415926docs 36[Double -1.79769e+308...1.79769e+308 (inclusive)] diff --git a/tests/bits/parameter_handler_read_xml_error_03.cc b/tests/bits/parameter_handler_read_xml_error_03.cc new file mode 100644 index 0000000000..53e0ded22b --- /dev/null +++ b/tests/bits/parameter_handler_read_xml_error_03.cc @@ -0,0 +1,83 @@ +//---------------------------- parameter_handler_read_xml_error_03.cc --------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2002, 2003, 2004, 2005, 2010 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//---------------------------- parameter_handler_read_xml_error_03.cc --------------------------- + + +// check ParameterHandler::read_input_from_xml. try to read a file that is not +// valid XML (there is more than one top-level element) + +#include "../tests.h" +#include +#include +#include + + +int main () +{ + std::ofstream logfile("parameter_handler_read_xml_error_03/output"); + deallog.attach(logfile); + deallog.depth_console(0); + 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 (); + + // read from XML + std::ifstream in ("parameter_handler_read_xml_error_03/prm"); + bool result = prm.read_input_from_xml (in); + Assert (result == false, ExcInternalError()); + + deallog << "OK" << std::endl; + + return 0; +} diff --git a/tests/bits/parameter_handler_read_xml_error_03/cmp/generic b/tests/bits/parameter_handler_read_xml_error_03/cmp/generic new file mode 100644 index 0000000000..0fd8fc12f0 --- /dev/null +++ b/tests/bits/parameter_handler_read_xml_error_03/cmp/generic @@ -0,0 +1,2 @@ + +DEAL::OK diff --git a/tests/bits/parameter_handler_read_xml_error_03/prm b/tests/bits/parameter_handler_read_xml_error_03/prm new file mode 100644 index 0000000000..51dbfc6965 --- /dev/null +++ b/tests/bits/parameter_handler_read_xml_error_03/prm @@ -0,0 +1,5 @@ + + +21doc 10[Integer range -2147483648...2147483647 (inclusive)]32doc 21[Integer range -2147483648...2147483647 (inclusive)]2.2341.234doc 32[Double -1.79769e+308...1.79769e+308 (inclusive)]5.3214.321doc 43[Double -1.79769e+308...1.79769e+308 (inclusive)]__< & > ; /< & > ; /docs 14[Anything]__22 +5[Integer range -2147483648...2147483647 (inclusive)]7.14159266.1415926docs 36[Double -1.79769e+308...1.79769e+308 (inclusive)] + -- 2.39.5