Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Any_UnitTests.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_any.hpp"
12 
13 #include <sstream>
14 
15 namespace {
16 
17 
18 TEUCHOS_UNIT_TEST( any, noThrowComparePrintDouble )
19 {
20  double value = 25.0;
21  auto a = Teuchos::any(value);
22  auto b = Teuchos::any(value);
23  TEST_NOTHROW(a == b);
24  TEST_EQUALITY_CONST(true, b.same(a));
25  std::stringstream ss;
26  TEST_NOTHROW(ss << a);
27 }
28 
29 TEUCHOS_UNIT_TEST( any, throwPrintVector )
30 {
31  std::vector<double> value;
32  auto a = Teuchos::any(value);
33  auto b = Teuchos::any(value);
34  TEST_NOTHROW(a == b);
35  TEST_EQUALITY_CONST(true, b.same(a));
36  std::stringstream ss;
37  TEST_THROW(ss << a, std::runtime_error);
38  TEST_THROW(ss << b, std::runtime_error);
39 }
40 
41 struct NotComparableOrPrintable {
42  int x;
43 };
44 
45 TEUCHOS_UNIT_TEST( any, throwComparePrintStruct )
46 {
47  NotComparableOrPrintable value;
48  value.x = 15;
49  auto a = Teuchos::any(value);
50  auto b = Teuchos::any(value);
51  TEST_THROW(a == b, std::runtime_error);
52  std::stringstream ss;
53  TEST_THROW(ss << a, std::runtime_error);
54  TEST_THROW(ss << b, std::runtime_error);
55 }
56 
57 } // namespace
Modified boost::any class for holding a templated value.
#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)...
#define TEUCHOS_UNIT_TEST(TEST_GROUP, TEST_NAME)
Macro for defining a (non-templated) unit test.
Modified boost::any class, which is a container for a templated value.
Unit testing support.
#define TEST_EQUALITY_CONST(v1, v2)
Assert the equality of v1 and constant v2.