]> https://gitweb.dealii.org/ - dealii.git/commitdiff
test ParameterHandler::MultipleSelection
authorTimo Heister <timo.heister@gmail.com>
Sat, 11 Jul 2015 21:40:28 +0000 (17:40 -0400)
committerTimo Heister <timo.heister@gmail.com>
Sun, 12 Jul 2015 18:52:19 +0000 (14:52 -0400)
tests/bits/parameter_handler_21.cc [new file with mode: 0644]
tests/bits/parameter_handler_21.output [new file with mode: 0644]

diff --git a/tests/bits/parameter_handler_21.cc b/tests/bits/parameter_handler_21.cc
new file mode 100644 (file)
index 0000000..3adef5e
--- /dev/null
@@ -0,0 +1,73 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2002 - 2014 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 Patterns::MultipleSelection
+
+#include "../tests.h"
+#include <deal.II/base/logstream.h>
+#include <deal.II/base/parameter_handler.h>
+#include <fstream>
+#include <sstream>
+
+void check (const char *defaults, const char* defined, const char *input)
+{
+  ParameterHandler prm;
+  prm.declare_entry ("v", defaults, Patterns::MultipleSelection(defined), "");
+  
+  std::stringstream in(input);
+  prm.read_input (in);
+
+  deallog << "defaults='" << defaults
+         << "' defined='" << defined
+         << "' input='" << input
+         << "' result='" << prm.get("v") << "'" << std::endl;
+}
+
+void test()
+{
+  check("","one option","set v=");
+  check("one option","one option","");
+  check("","one option","set v=one option");
+
+  check("","bla|bla 2|1","");
+  check("","bla|bla 2|1","set v=bla 2");
+  check("","bla|bla 2|1","set v=1,bla 2");
+  check("","bla|bla 2|1","set v=bla,bla,bla");
+
+  check("default,alsodefault","default|nodefault|alsodefault","");
+  check("default,alsodefault","default|nodefault|alsodefault","set v=nodefault");
+
+  check("  input 2  ,  have spaces  ","have spaces|input 2","");
+
+  // check correct handling of space in input, default, and values:
+  check("input 2","have spaces|input 2","set v=   input 2  ,   have spaces  ");
+
+  check("","double  spaces|input 2","set v = double  spaces  ,  double  spaces");
+}
+
+
+int main ()
+{
+  std::ofstream logfile("output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);
+
+  test();
+
+  return 0;
+}
diff --git a/tests/bits/parameter_handler_21.output b/tests/bits/parameter_handler_21.output
new file mode 100644 (file)
index 0000000..cd1140f
--- /dev/null
@@ -0,0 +1,13 @@
+
+DEAL::defaults='' defined='one option' input='set v=' result=''
+DEAL::defaults='one option' defined='one option' input='' result='one option'
+DEAL::defaults='' defined='one option' input='set v=one option' result='one option'
+DEAL::defaults='' defined='bla|bla 2|1' input='' result=''
+DEAL::defaults='' defined='bla|bla 2|1' input='set v=bla 2' result='bla 2'
+DEAL::defaults='' defined='bla|bla 2|1' input='set v=1,bla 2' result='1,bla 2'
+DEAL::defaults='' defined='bla|bla 2|1' input='set v=bla,bla,bla' result='bla,bla,bla'
+DEAL::defaults='default,alsodefault' defined='default|nodefault|alsodefault' input='' result='default,alsodefault'
+DEAL::defaults='default,alsodefault' defined='default|nodefault|alsodefault' input='set v=nodefault' result='nodefault'
+DEAL::defaults='  input 2  ,  have spaces  ' defined='have spaces|input 2' input='' result='  input 2  ,  have spaces  '
+DEAL::defaults='input 2' defined='have spaces|input 2' input='set v=   input 2  ,   have spaces  ' result='input 2 , have spaces'
+DEAL::defaults='' defined='double  spaces|input 2' input='set v = double  spaces  ,  double  spaces' result=''

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.