Nektar++
TestConsistentObjectAccess.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: TestConsistentObjectAccess.cpp
4//
5// For more information, please see: http://www.nektar.info
6//
7// The MIT License
8//
9// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10// Department of Aeronautics, Imperial College London (UK), and Scientific
11// Computing and Imaging Institute, University of Utah (USA).
12//
13// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description:
32//
33///////////////////////////////////////////////////////////////////////////////
34
37#include <UnitTests/util.h>
38#include <boost/test/tools/floating_point_comparison.hpp>
39#include <boost/test/unit_test.hpp>
40
42{
43BOOST_AUTO_TEST_CASE(TestValueTypes)
44{
45 double d1 = 1.0;
46 const double d2 = 2.0;
47
48 BOOST_CHECK_EQUAL(d1, ConsistentObjectAccess<double>::reference(d1));
49 BOOST_CHECK_EQUAL(&d1, &ConsistentObjectAccess<double>::reference(d1));
50 BOOST_CHECK_EQUAL(d1, ConsistentObjectAccess<double>::const_reference(d1));
51 BOOST_CHECK_EQUAL(&d1,
53 BOOST_CHECK_EQUAL(&d1, ConsistentObjectAccess<double>::pointer(d1));
54 BOOST_CHECK_EQUAL(&d1, ConsistentObjectAccess<double>::const_pointer(d1));
56
57 BOOST_CHECK_EQUAL(d2, ConsistentObjectAccess<const double>::reference(d2));
58 BOOST_CHECK_EQUAL(&d2,
60 BOOST_CHECK_EQUAL(
62 BOOST_CHECK_EQUAL(
64 BOOST_CHECK_EQUAL(&d2, ConsistentObjectAccess<const double>::pointer(d2));
65 BOOST_CHECK_EQUAL(&d2,
68}
69
70BOOST_AUTO_TEST_CASE(TestPointerTypes)
71{
73 double *d1 = new double(1.0);
74 const double *d2 = new double(2.0);
75
76 BOOST_CHECK_EQUAL(*d1, ConsistentObjectAccess<double *>::reference(d1));
77 BOOST_CHECK_EQUAL(d1, &ConsistentObjectAccess<double *>::reference(d1));
78 BOOST_CHECK_EQUAL(*d1,
80 BOOST_CHECK_EQUAL(d1,
82 BOOST_CHECK_EQUAL(d1, ConsistentObjectAccess<double *>::pointer(d1));
83 BOOST_CHECK_EQUAL(d1, ConsistentObjectAccess<double *>::const_pointer(d1));
86 static_cast<double *>(nullptr)));
87
88 BOOST_CHECK_EQUAL(*d2,
90 BOOST_CHECK_EQUAL(d2,
92 BOOST_CHECK_EQUAL(
94 BOOST_CHECK_EQUAL(
96 BOOST_CHECK_EQUAL(d2, ConsistentObjectAccess<const double *>::pointer(d2));
97 BOOST_CHECK_EQUAL(
101 static_cast<const double *>(nullptr)));
102
103#if defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG)
105 static_cast<double *>(nullptr)),
108 static_cast<const double *>(nullptr)),
111 static_cast<double *>(nullptr)),
114 static_cast<const double *>(nullptr)),
116#endif
117}
118
119BOOST_AUTO_TEST_CASE(TestSharedPointerTypes)
120{
121 double *d1 = new double(1.0);
122 const double *d2 = new double(2.0);
123
124 std::shared_ptr<double> sd1(d1);
125 std::shared_ptr<const double> sd2(d2);
126
127 BOOST_CHECK_EQUAL(
128 *d1, ConsistentObjectAccess<std::shared_ptr<double>>::reference(sd1));
129 BOOST_CHECK_EQUAL(
130 d1, &ConsistentObjectAccess<std::shared_ptr<double>>::reference(sd1));
131 BOOST_CHECK_EQUAL(
132 *d1,
133 ConsistentObjectAccess<std::shared_ptr<double>>::const_reference(sd1));
134 BOOST_CHECK_EQUAL(
135 d1,
136 &ConsistentObjectAccess<std::shared_ptr<double>>::const_reference(sd1));
137 BOOST_CHECK_EQUAL(
138 d1, ConsistentObjectAccess<std::shared_ptr<double>>::pointer(sd1));
139 BOOST_CHECK_EQUAL(
140 d1,
141 ConsistentObjectAccess<std::shared_ptr<double>>::const_pointer(sd1));
142 BOOST_CHECK(
143 ConsistentObjectAccess<std::shared_ptr<double>>::ReferencesObject(sd1));
144 BOOST_CHECK(
145 !ConsistentObjectAccess<std::shared_ptr<double>>::ReferencesObject(
146 std::shared_ptr<double>()));
147
148 BOOST_CHECK_EQUAL(
149 *d2,
150 ConsistentObjectAccess<std::shared_ptr<const double>>::reference(sd2));
151 BOOST_CHECK_EQUAL(
152 d2,
153 &ConsistentObjectAccess<std::shared_ptr<const double>>::reference(sd2));
154 BOOST_CHECK_EQUAL(
155 *d2,
156 ConsistentObjectAccess<std::shared_ptr<const double>>::const_reference(
157 sd2));
158 BOOST_CHECK_EQUAL(
159 d2,
160 &ConsistentObjectAccess<std::shared_ptr<const double>>::const_reference(
161 sd2));
162 BOOST_CHECK_EQUAL(
163 d2,
164 ConsistentObjectAccess<std::shared_ptr<const double>>::pointer(sd2));
165 BOOST_CHECK_EQUAL(
166 d2,
167 ConsistentObjectAccess<std::shared_ptr<const double>>::const_pointer(
168 sd2));
169 BOOST_CHECK(
170 ConsistentObjectAccess<std::shared_ptr<const double>>::ReferencesObject(
171 sd2));
172 BOOST_CHECK(!ConsistentObjectAccess<std::shared_ptr<const double>>::
173 ReferencesObject(std::shared_ptr<const double>()));
174
175#if defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG)
176 BOOST_CHECK_THROW(
177 ConsistentObjectAccess<std::shared_ptr<double>>::const_reference(
178 std::shared_ptr<double>()),
180 BOOST_CHECK_THROW(
181 ConsistentObjectAccess<std::shared_ptr<const double>>::const_reference(
182 std::shared_ptr<const double>()),
184 BOOST_CHECK_THROW(
185 ConsistentObjectAccess<std::shared_ptr<double>>::reference(
186 std::shared_ptr<double>()),
188 BOOST_CHECK_THROW(
189 ConsistentObjectAccess<std::shared_ptr<const double>>::reference(
190 std::shared_ptr<const double>()),
192#endif
193}
194
195} // namespace Nektar::ConsistentObjectAccessUnitTests
void RedirectCerrIfNeeded()
Definition: util.cpp:41