Project
Loading...
Searching...
No Matches
test_TypeTraits.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14#include "TestClasses.h"
15#include <catch_amalgamated.hpp>
16#include <vector>
17#include <map>
18#include <list>
19#include <gsl/gsl>
20
21using namespace o2::framework;
22
23struct Foo {
24 int x;
25 int y;
26};
27
28// Simple test to do root deserialization.
29TEST_CASE("TestIsSpecialization")
30{
31 std::vector<int> a;
32 std::vector<Foo> b;
33 std::list<int> c;
34 int d;
35
36 bool test1 = is_specialization_v<decltype(a), std::vector>;
37 bool test2 = is_specialization_v<decltype(b), std::vector>;
38 bool test3 = is_specialization_v<decltype(b), std::list>;
39 bool test4 = is_specialization_v<decltype(c), std::list>;
40 bool test5 = is_specialization_v<decltype(c), std::vector>;
41 bool test6 = is_specialization_v<decltype(d), std::vector>;
42 REQUIRE(test1 == true);
43 REQUIRE(test2 == true);
44 REQUIRE(test3 == false);
45 REQUIRE(test4 == true);
46 REQUIRE(test5 == false);
47 REQUIRE(test6 == false);
48
49 ROOTSerialized<decltype(d)> e(d);
50 bool test7 = is_specialization_v<decltype(e), ROOTSerialized>;
51 REQUIRE(test7 == true);
52}
53
54TEST_CASE("TestForceNonMessageable")
55{
56 // a struct explicitly marked to be non-messageable by defining
57 // a type alias provided by the framework type traits
58 struct ExplicitNonMessageable {
59 using non_messageable = o2::framework::MarkAsNonMessageable;
60 };
61
62 // a struct using the same name for the type alias, but which should
63 // not be forced to be non-messageable
64 struct FailedNonMessageable {
65 using non_messageable = int;
66 };
67
68 ExplicitNonMessageable a;
69 Foo b;
70 FailedNonMessageable c;
71
72 REQUIRE(is_forced_non_messageable<decltype(a)>::value == true);
73 REQUIRE(is_forced_non_messageable<decltype(b)>::value == false);
74 REQUIRE(is_forced_non_messageable<decltype(c)>::value == false);
75}
76
77TEST_CASE("TestIsMessageable")
78{
79 int a;
80 Foo b;
81 std::vector<int> c;
84 gsl::span<o2::test::TriviallyCopyable> spantriv;
85 gsl::span<o2::test::Polymorphic> spanpoly;
86
87 REQUIRE(is_messageable<decltype(a)>::value == true);
88 REQUIRE(is_messageable<decltype(b)>::value == true);
89 REQUIRE(is_messageable<decltype(c)>::value == false);
90 REQUIRE(is_messageable<decltype(d)>::value == true);
91 REQUIRE(is_messageable<decltype(e)>::value == false);
92 REQUIRE(is_messageable<ROOTSerialized<decltype(e)>>::value == false);
93 REQUIRE(is_messageable<decltype(spantriv)>::value == false);
94 REQUIRE(is_messageable<decltype(spanpoly)>::value == false);
95}
96
97TEST_CASE("TestIsStlContainer")
98{
99 int a;
101 std::vector<o2::test::Polymorphic> c;
102 std::map<int, o2::test::Polymorphic> d;
103
104 REQUIRE(is_container<decltype(a)>::value == false);
105 REQUIRE(is_container<decltype(b)>::value == false);
106 REQUIRE(is_container<decltype(c)>::value == true);
107 REQUIRE(is_container<decltype(d)>::value == true);
108
109 REQUIRE(has_messageable_value_type<decltype(b)>::value == false);
110 REQUIRE(has_messageable_value_type<std::vector<int>>::value == true);
111 REQUIRE(has_messageable_value_type<decltype(c)>::value == false);
112}
113
114TEST_CASE("TestHasRootStreamer")
115{
118 std::vector<o2::test::Polymorphic> c;
119 int d;
120 Foo e;
121 std::list<o2::test::TriviallyCopyable> f;
122 std::list<int> g;
123
124 REQUIRE(has_root_dictionary<decltype(a)>::value == true);
125 REQUIRE(has_root_dictionary<decltype(b)>::value == true);
126 REQUIRE(has_root_dictionary<decltype(c)>::value == true);
127 REQUIRE(has_root_dictionary<decltype(d)>::value == false);
128 REQUIRE(has_root_dictionary<decltype(e)>::value == false);
129 REQUIRE(has_root_dictionary<decltype(f)>::value == true);
130 REQUIRE(has_root_dictionary<decltype(g)>::value == false);
131}
132
133TEST_CASE("TestIsSpan")
134{
135 gsl::span<int> a;
136 int b;
137 std::vector<char> c;
138 REQUIRE(is_span<decltype(a)>::value == true);
139 REQUIRE(is_span<decltype(b)>::value == false);
140 REQUIRE(is_span<decltype(c)>::value == false);
141}
142
143template <typename A>
144struct FooFoo {
145};
146
147template <typename A>
148struct NoFooFoo {
149};
150
151struct Bar : FooFoo<int> {
152};
153
154struct NoBar : NoFooFoo<int> {
155};
156
157TEST_CASE("BaseOfTemplate")
158{
159 constexpr bool t = base_of_template<std::vector, std::vector<int>>;
160 static_assert(t == true, "This should be true");
161
162 constexpr bool t2 = base_of_template<std::vector, int>;
163 static_assert(t2 == false, "This should be true");
164
165 constexpr bool t3 = base_of_template<FooFoo, Bar>;
166 static_assert(t3 == true, "This should be true");
167
168 constexpr bool t4 = base_of_template<FooFoo, NoBar>;
169 static_assert(t4 == false, "This should be false");
170
171 constexpr bool t5 = base_of_template<NoFooFoo, NoBar>;
172 static_assert(t5 == true, "This should be true");
173}
uint32_t c
Definition RawData.h:2
Type wrappers for enfording a specific serialization method.
GLdouble f
Definition glcorearb.h:310
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLsizei const GLfloat * value
Definition glcorearb.h:819
GLboolean GLboolean g
Definition glcorearb.h:1233
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
TEST_CASE("test_prepareArguments")
constexpr bool is_specialization_v
Definition Traits.h:32