src/boost_ci.cpp

90.9% Lines (10/11) 100.0% Functions (2/2)
src/boost_ci.cpp
Line TLA Hits Source Code
1 //
2 // Copyright (c) 2022 Alexander Grund
3 //
4 // Use, modification and distribution is subject to the Boost Software License,
5 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7
8 #define BOOST_BOOST_CI_SOURCE
9
10 #include <boost/boost-ci/boost_ci.hpp>
11 // Just some dependency on another Boost library
12 #include <boost/atomic/atomic.hpp>
13
14 // Some simple struct big enough so that the atomic is forced to use a lock
15 // forcing it to call into the library
16 struct X
17 {
18 double x, y, z;
19 5 explicit X(int value = 0): x(value), y(value), z(value) {}
20 };
21
22 namespace boost
23 {
24 namespace boost_ci
25 {
26 // Some function to test
27 3 int get_answer(const int isMsvc)
28 {
29 3 boost::atomic<X> answer;
30 // Specifically crafted condition to check for coverage from MSVC and non MSVC builds
31 3 if(isMsvc == 1)
32 answer = X(21);
33 3 else if(isMsvc == 0)
34 4 answer = X(42);
35 else
36 1 throw example_error();
37 #ifdef BOOST_NO_CXX11_SMART_PTR
38 return answer.load().x;
39 #else
40 // Just use some stdlib feature combined with a Boost.Config feature as demonstration
41 4 auto ptr = std::unique_ptr<int>(new int(answer.load().x));
42 4 return *ptr;
43 #endif
44 2 }
45 }
46 }
47