Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LinearSolverSetupFailure.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 
12 #include <type_traits>
13 
14 namespace { // (anonymous)
15 
16  void throws_LSSF () {
17  throw Trilinos::LinearSolverSetupFailure ("Not an std::runtime_error");
18  }
19 
20  void does_not_throw () {
21  }
22 
23  void throws_runtime_error () {
24  throw std::runtime_error ("Not a LinearSolverSetupFailure");
25  }
26 
27  void catches_LSSF_0 (bool& success, Teuchos::FancyOStream& out) {
28  out << "Test that LinearSolverSetupFailure has a what() method that "
29  "returns something convertible to std::string, and test that the "
30  "resulting message is as expected" << std::endl;
31  Teuchos::OSTab tab1 (out);
32  bool threw = false;
33  try {
34  throws_LSSF ();
35  }
37  threw = true;
38  const std::string msg (e.what ());
39  TEST_ASSERT( msg == "Not an std::runtime_error" );
40  }
41  TEST_ASSERT( threw );
42  }
43 
44  void catches_LSSF_1 (bool& success, Teuchos::FancyOStream& out) {
45  out << "Test that LinearSolverSetupFailure is a subclass of "
46  "std::runtime_error" << std::endl;
47  Teuchos::OSTab tab1 (out);
48 
49  bool first_threw = false;
50  try {
51  throws_LSSF ();
52  }
53  catch (std::runtime_error& e) {
54  first_threw = true;
55  const std::string msg (e.what ());
56  TEST_ASSERT(msg == "Not an std::runtime_error");
57  }
58  TEST_ASSERT( first_threw );
59  static_assert (std::has_virtual_destructor<Trilinos::LinearSolverSetupFailure>::value,
60  "LinearSolverSetupFailure does not have a virtual destructor. "
61  "This is bad for memory safety, because LinearSolverSetupFailure "
62  "inherits from a class with virtual methods.");
63 
64  bool second_threw = false;
65  try {
66  throws_runtime_error ();
67  }
68  catch (std::runtime_error& e) {
69  second_threw = true;
70  const std::string msg (e.what ());
71  TEST_ASSERT(msg == "Not a LinearSolverSetupFailure");
72  }
73  TEST_ASSERT( second_threw );
74  }
75 
76  TEUCHOS_UNIT_TEST( LinearSolverSetupFailure, Test0 )
77  {
78  using std::endl;
79 
80  out << "LinearSolverSetupFailure Test0" << endl;
81  Teuchos::OSTab tab1 (out);
82  TEST_NOTHROW( does_not_throw () ); // sanity-check TEST_NOTHROW macro itself
83  TEST_NOTHROW( catches_LSSF_0 (success, out) );
84  TEST_NOTHROW( catches_LSSF_1 (success, out) );
85  }
86 } // (anonymous)
#define TEST_ASSERT(v1)
Assert the given statement is true.
#define TEST_NOTHROW(code)
Asserr that the statement &#39;code&#39; does not thrown any excpetions.
Declaration and definition of Trilinos::LinearSolverSetupFailure exception class. ...
#define TEUCHOS_UNIT_TEST(TEST_GROUP, TEST_NAME)
Macro for defining a (non-templated) unit test.
Tabbing class for helping to create formated, indented output for a basic_FancyOStream object...
std::ostream subclass that performs the magic of indenting data sent to an std::ostream object among ...
Unit testing support.
Exception reporting failure in setting up a linear solver.