Project
Loading...
Searching...
No Matches
test_observer_ptr.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
12#define BOOST_TEST_MODULE Test observer_ptr
13#define BOOST_TEST_MAIN
14#define BOOST_TEST_DYN_LINK
15#include <boost/test/unit_test.hpp>
16#include <functional>
18
23struct A {
24 int i{2};
25 int get() const { return i; }
26};
27
28BOOST_AUTO_TEST_CASE(observer_ptr_A)
29{
30 using namespace o2;
31 A t;
32 int i{1};
33
34 {
35 observer_ptr<int> p{nullptr};
36 BOOST_CHECK(p == nullptr);
37 }
38
39 {
41 BOOST_CHECK(p == nullptr);
42 }
43
44 {
47 BOOST_CHECK(a == b);
48 }
49
50 {
53 BOOST_CHECK(a == b);
54 }
55
56 {
57 const observer_ptr<int> b{&i};
59 BOOST_CHECK(a == b);
60 }
61
62 {
63 observer_ptr<A> pt{&t};
64 A* ptt = pt.release();
65 BOOST_CHECK(ptt == &t);
66 BOOST_CHECK(pt == nullptr);
67 }
68
69 {
71 p.reset();
72 BOOST_CHECK(p == nullptr);
73 p.reset(&t);
74 BOOST_CHECK(p.get() == &t);
75 }
76
77 {
78 A tt{4};
81 p.swap(pp);
82 BOOST_CHECK(p->get() == 4 && pp->get() == 2);
83 p.swap(nullptr);
84 BOOST_CHECK(p == nullptr);
85 std::swap(p, pp);
86 BOOST_CHECK(pp == nullptr);
87 BOOST_CHECK(p->get() == 2);
88 }
89
90 {
92 BOOST_CHECK(p.get() == &t);
93 }
94
95 {
97 BOOST_CHECK((*p).i == 2);
98 }
99
100 {
102 p = &t;
103 BOOST_CHECK(p.get() == &t);
105 pp = p;
106 BOOST_CHECK(pp.get() == &t);
107 }
108
109 //comparisons
110 {
111 A tt{4};
114 observer_ptr<A> p_{&t};
115 observer_ptr<A> n{nullptr};
116 BOOST_CHECK(p != pp);
117 BOOST_CHECK(p == p_);
118 BOOST_CHECK(p != nullptr);
119 BOOST_CHECK(n == nullptr);
120 BOOST_CHECK((&tt > &t) ? pp > p : p > pp);
121 BOOST_CHECK((&tt < &t) ? pp < p : p < pp);
122 BOOST_CHECK((&tt >= &t) ? pp >= p : p >= pp);
123 BOOST_CHECK((&tt <= &t) ? pp <= p : p <= pp);
124 BOOST_CHECK((&t >= &t) ? p >= p : p >= p);
125 BOOST_CHECK((&t <= &t) ? p <= p : p <= p);
126 }
127
128 //hash
129 {
131 BOOST_CHECK(std::hash<o2::observer_ptr<int>>()(p) == std::hash<int*>()(p.get()));
132 }
133}
134// @endcond
int32_t i
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char pp
Definition A.h:16
GLdouble n
Definition glcorearb.h:1982
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
BOOST_AUTO_TEST_CASE(test_headerstack)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
BOOST_CHECK(tree)