]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /* Copyright (c) 2002,2003 CrystalClear Software, Inc. |
2 | * Use, modification and distribution is subject to the | |
3 | * Boost Software License, Version 1.0. (See accompanying | |
4 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) | |
5 | * Author: Jeff Garland | |
6 | */ | |
7 | ||
8 | #include "boost/config.hpp" | |
9 | #include "boost/date_time/constrained_value.hpp" | |
10 | #include "testfrmwk.hpp" | |
11 | #include <iostream> | |
12 | ||
13 | class bad_day {}; //exception type | |
14 | ||
15 | ||
16 | class day_value_policies | |
17 | { | |
18 | public: | |
19 | typedef unsigned int value_type; | |
20effc67 TL |
20 | static BOOST_CXX14_CONSTEXPR unsigned int min BOOST_PREVENT_MACRO_SUBSTITUTION () { return 0; }; |
21 | static BOOST_CXX14_CONSTEXPR unsigned int max BOOST_PREVENT_MACRO_SUBSTITUTION () { return 31;}; | |
7c673cae FG |
22 | static void on_error(unsigned int&, unsigned int, boost::CV::violation_enum) |
23 | { | |
24 | throw bad_day(); | |
25 | } | |
26 | }; | |
27 | ||
28 | struct range_error {}; //exception type | |
29 | typedef boost::CV::simple_exception_policy<int,1,10,range_error> one_to_ten_range_policy; | |
30 | ||
31 | int main() | |
32 | { | |
33 | using namespace boost::CV; | |
34 | constrained_value<day_value_policies> cv1(0), cv2(31); | |
35 | check("not equal", cv1 != cv2); | |
36 | check("equal", cv1 == cv1); | |
37 | check("greater", cv2 > cv1); | |
38 | check("greater or equal ", cv2 >= cv1); | |
39 | //various running of the conversion operator | |
40 | std::cout << cv1 << std::endl; | |
41 | unsigned int i = cv1; | |
42 | check("test conversion", i == cv1); | |
43 | ||
20effc67 TL |
44 | #ifdef BOOST_NO_CXX14_CONSTEXPR |
45 | check("constexpr not configured", true); | |
46 | #else | |
47 | //check constexpr case | |
48 | constexpr constrained_value<day_value_policies> cv3(1); | |
49 | static_assert(cv3 == 1, "constexpr construction/conversion"); | |
50 | check("constexpr constrained value construct and equal", true); | |
51 | #endif | |
7c673cae FG |
52 | |
53 | try { | |
11fdf7f2 TL |
54 | constrained_value<one_to_ten_range_policy> cv3(11); |
55 | std::cout << "Not Reachable: " << cv3 << " "; | |
7c673cae FG |
56 | check("got range exception max", false); |
57 | } | |
f67539c2 | 58 | catch(range_error&) { |
7c673cae FG |
59 | check("got range exception max", true); |
60 | } | |
61 | ||
62 | try { | |
63 | constrained_value<one_to_ten_range_policy> cv3(0); | |
64 | std::cout << "Not Reachable: " << cv3 << " "; | |
65 | check("got range exception min", false); | |
66 | } | |
f67539c2 | 67 | catch(range_error&) { |
7c673cae FG |
68 | check("got range exception min", true); |
69 | } | |
70 | ||
71 | try { | |
72 | constrained_value<one_to_ten_range_policy> cv4(1); | |
73 | cv4 = 12; | |
74 | check("range exception on assign", false); | |
75 | } | |
f67539c2 | 76 | catch(range_error&) { |
7c673cae FG |
77 | check("range exception on assign", true); |
78 | } | |
79 | ||
80 | return printTestStats(); | |
81 | } | |
82 |