]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/test/karma/int3.cpp
bump version to 18.2.4-pve3
[ceph.git] / ceph / src / boost / libs / spirit / test / karma / int3.cpp
1 // Copyright (c) 2001-2011 Hartmut Kaiser
2 //
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6 #include <boost/spirit/include/karma_int.hpp>
7
8 #include <boost/mpl/vector.hpp>
9 #include <boost/mpl/for_each.hpp>
10 #include <boost/mpl/if.hpp>
11 #include <boost/mpl/bool.hpp>
12
13 #include <boost/phoenix/core.hpp>
14 #include <boost/phoenix/operator.hpp>
15
16 #include <boost/spirit/include/karma_char.hpp>
17 #include <boost/spirit/include/karma_numeric.hpp>
18 #include <boost/spirit/include/karma_directive.hpp>
19 #include <boost/spirit/include/karma_action.hpp>
20 #include <boost/spirit/include/karma_phoenix_attributes.hpp>
21
22 #include <boost/limits.hpp>
23 #include "test.hpp"
24 #include <sstream>
25
26 using namespace spirit_test;
27
28 template <typename T>
29 std::string to_string(T v)
30 {
31 std::stringstream ss;
32 ss << v;
33 return ss.str();
34 }
35
36 ///////////////////////////////////////////////////////////////////////////////
37 struct test_minmax
38 {
39 template <typename T>
40 void operator()(T) const
41 {
42 using namespace boost::spirit;
43 using namespace boost::phoenix;
44
45 T minval = (std::numeric_limits<T>::min)();
46 T maxval = (std::numeric_limits<T>::max)();
47
48 std::string expected_minval = to_string(minval);
49 std::string expected_maxval = to_string(maxval);
50
51 // create a correct generator type from the given integer type
52 typedef typename
53 boost::mpl::if_<
54 boost::mpl::bool_<std::numeric_limits<T>::is_signed>,
55 karma::int_generator<T>,
56 karma::uint_generator<T>
57 >::type
58 int_generator_type;
59
60 int_generator_type const gen = int_generator_type();
61
62 BOOST_TEST(test(expected_maxval, gen, maxval));
63 BOOST_TEST(test(expected_minval, gen, minval));
64 BOOST_TEST(test(expected_maxval, gen(maxval)));
65 BOOST_TEST(test(expected_minval, gen(minval)));
66 BOOST_TEST(test(expected_maxval, gen(maxval), maxval));
67 BOOST_TEST(test(expected_minval, gen(minval), minval));
68 BOOST_TEST(!test("", gen(maxval), maxval-1));
69 BOOST_TEST(!test("", gen(minval), minval+1));
70 BOOST_TEST(test(expected_maxval, lit(maxval)));
71 BOOST_TEST(test(expected_minval, lit(minval)));
72
73 BOOST_TEST(test_delimited(expected_maxval + " ", gen, maxval, char(' ')));
74 BOOST_TEST(test_delimited(expected_minval + " ", gen, minval, char(' ')));
75 BOOST_TEST(test_delimited(expected_maxval + " ", gen(maxval), char(' ')));
76 BOOST_TEST(test_delimited(expected_minval + " ", gen(minval), char(' ')));
77 BOOST_TEST(test_delimited(expected_maxval + " ", gen(maxval), maxval, char(' ')));
78 BOOST_TEST(test_delimited(expected_minval + " ", gen(minval), minval, char(' ')));
79 BOOST_TEST(!test_delimited("", gen(maxval), maxval-1, char(' ')));
80 BOOST_TEST(!test_delimited("", gen(minval), minval+1, char(' ')));
81 BOOST_TEST(test_delimited(expected_maxval + " ", lit(maxval), char(' ')));
82 BOOST_TEST(test_delimited(expected_minval + " ", lit(minval), char(' ')));
83
84 // action tests
85 BOOST_TEST(test(expected_maxval, gen[_1 = val(maxval)]));
86 BOOST_TEST(test(expected_minval, gen[_1 = val(minval)]));
87
88 // optional tests
89 boost::optional<T> optmin, optmax(maxval);
90
91 BOOST_TEST(!test("", gen, optmin));
92 BOOST_TEST(!test("", gen(minval), optmin));
93
94 optmin = minval;
95 BOOST_TEST(test(expected_minval, gen, optmin));
96 BOOST_TEST(test(expected_maxval, gen, optmax));
97 BOOST_TEST(test(expected_minval, gen(minval), optmin));
98 BOOST_TEST(test(expected_maxval, gen(maxval), optmax));
99
100 // Phoenix expression tests (only supported while including
101 // karma_phoenix_attributes.hpp
102 namespace phoenix = boost::phoenix;
103
104 BOOST_TEST(test("1", gen, phoenix::val(1)));
105
106 T val = 1;
107 BOOST_TEST(test("1", gen, phoenix::ref(val)));
108 BOOST_TEST(test("2", gen, ++phoenix::ref(val)));
109 }
110 };
111
112 ///////////////////////////////////////////////////////////////////////////////
113 int
114 main()
115 {
116 using namespace boost::spirit;
117
118 // test boundary values
119 typedef boost::mpl::vector<
120 #ifdef BOOST_HAS_LONG_LONG
121 boost::long_long_type, boost::ulong_long_type,
122 #endif
123 short, unsigned short,
124 int, unsigned int,
125 long, unsigned long
126 > integer_types;
127 boost::mpl::for_each<integer_types>(test_minmax());
128
129 return boost::report_errors();
130 }
131