Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
XMLParser_ParseFileForError.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 
11 #include "Teuchos_XMLParser.hpp"
13 
14 std::string filename;
15 std::string error;
16 
17 namespace Teuchos {
18 
20  {
22  "filename", &filename, "XML file to parse" );
23  }
24 
26  {
29  while (1) {
30  unsigned char c;
31  TEUCHOS_TEST_FOR_EXCEPTION( stream->readBytes(&c,1) < 1, std::runtime_error, "Failure reading error message from test file." );
32  if (c == '\n') break;
33  if (c != '\r') error.push_back(c);
34  }
35  out << "Expected error string: \"" << error << "\"" << std::endl;
36  bool caughtError = false;
37  try {
38  XMLParser parser(stream);
39  parser.parse();
40  }
41  catch (std::runtime_error &err) {
42  std::string what = err.what();
43  caughtError = true;
44  out << "Caught exception:\n" << what << "\n";
45  TEST_INEQUALITY_CONST( what.find(error), std::string::npos );
46  }
47  TEST_EQUALITY_CONST(caughtError, true);
48  }
49 
50 } // namespace Teuchos
#define TEST_INEQUALITY_CONST(v1, v2)
Assert the inequality of v1 and constant v2.
static CommandLineProcessor & getCLP()
Return the CLP to add options to.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
XMLObject parse()
Consume the XMLInputStream to build an XMLObject.
XMLParser consumes characters from an XMLInputStream object, parsing the XML and using a TreeBuilding...
TEUCHOS_UNIT_TEST(ConstNonconstObjectContainer, create)
void setOption(const char option_true[], const char option_false[], bool *option_val, const char documentation[]=NULL)
Set a boolean option.
virtual unsigned int readBytes(unsigned char *const toFill, const unsigned int maxToRead)=0
Read up to maxToRead bytes from the stream.
Unit testing support.
#define TEST_EQUALITY_CONST(v1, v2)
Assert the equality of v1 and constant v2.
Instantiation of XMLInputSource class for reading XML from a file.
virtual RCP< XMLInputStream > stream() const
Create a FileInputStream.
std::string error
Definition of XMLInputSource derived class for reading XML from a file.
A class providing a simple XML parser. Methods can be overloaded to exploit external XML parsing libr...