ProtocolTestHelpers.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include "Utilities/ProtocolHelpers.hpp"
7 
8 namespace ProtocolHelpers_detail {
9 
10 template <typename ConformingType, template <class> class Protocol>
11 struct TestProtocolConformanceImpl : std::true_type {
12 #ifdef SPECTRE_ALWAYS_CHECK_PROTOCOL_CONFORMANCE
13  static_assert(
14  tt::conforms_to_v<ConformingType, Protocol>,
15  "The type does not conform to the protocol or does not (publicly) "
16  "inherit from it. The type is listed as the first template parameter to "
17  "`test_protocol_conformance` and the protocol is listed as the second "
18  "template parameter.");
19 #else // SPECTRE_ALWAYS_CHECK_PROTOCOL_CONFORMANCE
20  static_assert(
21  tt::conforms_to_v<ConformingType, Protocol>,
22  "The type does not indicate it conforms to the protocol. The type is "
23  "listed as the first template parameter to `test_protocol_conformance` "
24  "and the protocol is listed as the second template parameter. "
25  "Have you forgotten to (publicly) inherit it from the protocol?");
26  static_assert(
27  Protocol<ConformingType>::value,
28  "The type does not conform to the protocol. The type is "
29  "listed as the first template parameter to `test_protocol_conformance` "
30  "and the protocol is listed as the second template parameter.");
31 #endif // SPECTRE_ALWAYS_CHECK_PROTOCOL_CONFORMANCE
32 };
33 
34 } // namespace ProtocolHelpers_detail
35 
36 /*!
37  * \ingroup ProtocolsGroup
38  * \brief Test that the `ConformingType` conforms to the `Protocol`
39  *
40  * Since the `tt::conforms_to_v` metafunction only checks if a class _indicates_
41  * it conforms to the protocol (unless the
42  * `SPECTRE_ALWAYS_CHECK_PROTOCOL_CONFORMANCE` flag is set), use the
43  * `test_protocol_conformance` metafunction in unit tests to check the class
44  * actually fulfills the requirements defined by the protocol's
45  * `is_conforming_v` metafunction.
46  */
47 template <typename ConformingType, template <class> class Protocol>
48 static constexpr bool test_protocol_conformance =
49  ProtocolHelpers_detail::TestProtocolConformanceImpl<ConformingType,
50  Protocol>::value;
Definition: ProtocolTestHelpers.hpp:8