| 1 | /* Unit testing for outcomes |
| 2 | (C) 2013-2024 Niall Douglas <http://www.nedproductions.biz/> (6 commits) |
| 3 | |
| 4 | |
| 5 | Boost Software License - Version 1.0 - August 17th, 2003 |
| 6 | |
| 7 | Permission is hereby granted, free of charge, to any person or organization |
| 8 | obtaining a copy of the software and accompanying documentation covered by |
| 9 | this license (the "Software") to use, reproduce, display, distribute, |
| 10 | execute, and transmit the Software, and to prepare derivative works of the |
| 11 | Software, and to permit third-parties to whom the Software is furnished to |
| 12 | do so, all subject to the following: |
| 13 | |
| 14 | The copyright notices in the Software and this entire statement, including |
| 15 | the above license grant, this restriction and the following disclaimer, |
| 16 | must be included in all copies of the Software, in whole or in part, and |
| 17 | all derivative works of the Software, unless such copies or derivative |
| 18 | works are solely in the form of machine-executable object code generated by |
| 19 | a source language processor. |
| 20 | |
| 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 23 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT |
| 24 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE |
| 25 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, |
| 26 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 27 | DEALINGS IN THE SOFTWARE. |
| 28 | */ |
| 29 | |
| 30 | #ifdef _MSC_VER |
| 31 | #pragma warning(disable : 4127) // conditional expression is constant |
| 32 | #pragma warning(disable : 4244) // conversion from int to short |
| 33 | #endif |
| 34 | |
| 35 | #include <boost/outcome.hpp> |
| 36 | #include <boost/test/unit_test.hpp> |
| 37 | #include <boost/test/unit_test_monitor.hpp> |
| 38 | |
| 39 | BOOST_OUTCOME_AUTO_TEST_CASE(works_outcome_comparison, "Tests that the outcome can compare to compatible outcomes" ) |
| 40 | { |
| 41 | #if !defined(__APPLE__) || defined(__cpp_exceptions) |
| 42 | using namespace BOOST_OUTCOME_V2_NAMESPACE; |
| 43 | auto p = boost::copy_exception(e: std::runtime_error("hi" )); |
| 44 | // value comparison |
| 45 | { |
| 46 | outcome<int> a(1), b(2), c(2); |
| 47 | BOOST_CHECK(a == a); |
| 48 | BOOST_CHECK(b == b); |
| 49 | BOOST_CHECK(c == c); |
| 50 | BOOST_CHECK(a != b); |
| 51 | BOOST_CHECK(b == c); |
| 52 | } |
| 53 | // homogeneous outcome comparison |
| 54 | { |
| 55 | outcome<int> a(1), b(2), c(boost::system::errc::invalid_argument), d(p); |
| 56 | BOOST_CHECK(a == a); |
| 57 | BOOST_CHECK(a != b); |
| 58 | BOOST_CHECK(a != c); |
| 59 | BOOST_CHECK(a != d); |
| 60 | BOOST_CHECK(b == b); |
| 61 | BOOST_CHECK(b != c); |
| 62 | BOOST_CHECK(b != d); |
| 63 | BOOST_CHECK(c == c); |
| 64 | BOOST_CHECK(c != d); |
| 65 | BOOST_CHECK(d == d); |
| 66 | outcome<int> e(boost::system::errc::invalid_argument), f(p); |
| 67 | BOOST_CHECK(c == e); |
| 68 | BOOST_CHECK(d == f); |
| 69 | } |
| 70 | // heterogeneous outcome comparison, so outcome<int> to outcome<double> etc |
| 71 | { |
| 72 | outcome<int> a(1); |
| 73 | outcome<double> b(1); |
| 74 | outcome<unsigned short> c(1); |
| 75 | BOOST_CHECK(a == b); |
| 76 | BOOST_CHECK(a == c); |
| 77 | BOOST_CHECK(b == a); |
| 78 | BOOST_CHECK(b == c); |
| 79 | BOOST_CHECK(c == a); |
| 80 | BOOST_CHECK(c == b); |
| 81 | // outcome<void> e(in_place_type<void>); |
| 82 | outcome<unsigned short> f(boost::system::errc::invalid_argument); |
| 83 | outcome<double> g(p); |
| 84 | // BOOST_CHECK(a != e); |
| 85 | BOOST_CHECK(a != f); |
| 86 | BOOST_CHECK(a != g); |
| 87 | // BOOST_CHECK(e != f); |
| 88 | BOOST_CHECK(f != g); |
| 89 | } |
| 90 | // upconverting outcome comparison, so outcome<int>==result<int> etc |
| 91 | { |
| 92 | outcome<int> a(1); |
| 93 | result<int> b(1); |
| 94 | BOOST_CHECK(a == b); |
| 95 | BOOST_CHECK(b == a); |
| 96 | // result<void> e(in_place_type<void>), f(boost::system::errc::invalid_argument); |
| 97 | // BOOST_CHECK(a != e); |
| 98 | // BOOST_CHECK(a != f); |
| 99 | } |
| 100 | // Should I do outcome<int>(5) == 5? Unsure if it's wise |
| 101 | #endif |
| 102 | } |
| 103 | |