Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
XMLParameterListHelpers_AnonSublists.cpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Teuchos: Common Tools Package
4 //
5 // Copyright 2004 NTESS and the Teuchos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
13 #include "Teuchos_XMLParser.hpp"
16 
17 using std::string;
18 using std::endl;
19 
20 namespace Teuchos {
21 
22  TEUCHOS_UNIT_TEST( XMLParameterListHelpers, anonymousSublists )
23  {
24  // the sublists are missing names; that is allowed now
25  string anon_sublist(
26  "<ParameterList name=\"Parent\">\n"
27  " <ParameterList>\n"
28  " <Parameter name=\"param_a\" type=\"string\" value=\"a\"/>\n"
29  " <ParameterList>\n"
30  " <Parameter name=\"param_b\" type=\"string\" value=\"b\"/>\n"
31  " </ParameterList>\n"
32  " </ParameterList>\n"
33  "</ParameterList>\n");
34  StringInputSource src(anon_sublist);
35  XMLParser parser(src.stream());
36  XMLObject xmlprob = parser.parse();
38  ParameterList plTest;
39  TEST_NOTHROW( plTest = pl2xml.toParameterList(xmlprob) );
40  out << plTest;
41  }
42 
43  TEUCHOS_UNIT_TEST( XMLParameterListHelpers, anonymousParam )
44  {
45  // one parameter is missing a name; but all parameters are required to have a name
46  string anon_param(
47  "<ParameterList name=\"Parent\">\n"
48  " <ParameterList>\n"
49  " <Parameter name=\"param_a\" type=\"string\" value=\"a\"/>\n"
50  " <ParameterList>\n"
51  " <Parameter type=\"string\" value=\"b\"/>\n"
52  " </ParameterList>\n"
53  " </ParameterList>\n"
54  "</ParameterList>\n");
55  StringInputSource src(anon_param);
56  XMLParser parser(src.stream());
57  XMLObject xmlprob = parser.parse();
59  ParameterList plTest;
60  // this exception name is mis-spelled; oh well
61  TEST_THROW( plTest = pl2xml.toParameterList(xmlprob), NoNameAttributeExecption);
62  }
63 
64 
65 } // namespace Teuchos
Writes an XML object to a parameter list.
#define TEST_NOTHROW(code)
Asserr that the statement &#39;code&#39; does not thrown any excpetions.
#define TEST_THROW(code, ExceptType)
Assert that the statement &#39;code&#39; throws the exception &#39;ExceptType&#39; (otherwise the test fails)...
XMLParser consumes characters from an XMLInputStream object, parsing the XML and using a TreeBuilding...
TEUCHOS_UNIT_TEST(ConstNonconstObjectContainer, create)
Thrown when a parameter entry tag is missing it&#39;s name attribute.
Representation of an XML data tree. XMLObject is a ref-counted handle to a XMLObjectImplem object...
Writes a ParameterList to an XML object.
Unit testing support.
virtual RCP< XMLInputStream > stream() const
Create a StringInputStream.
RCP< ParameterList > toParameterList(const XMLObject &xml, RCP< DependencySheet > depSheet) const
A list of parameters of arbitrary type.
Definition of XMLInputSource derived class for reading XML from a std::string.
A collection of Exceptions that can be potentially thrown when converting a ParameterList to and from...
Writes an XML object to a parameter list.
Instantiation of XMLInputSource class for reading XML from a std::string.
A class providing a simple XML parser. Methods can be overloaded to exploit external XML parsing libr...