diff options
Diffstat (limited to 'src/boost/libs/logic/test')
-rw-r--r-- | src/boost/libs/logic/test/Jamfile.v2 | 62 | ||||
-rw-r--r-- | src/boost/libs/logic/test/compile-fail/implicit.cpp | 23 | ||||
-rw-r--r-- | src/boost/libs/logic/test/compile-fail/implicit_int_1.cpp | 16 | ||||
-rw-r--r-- | src/boost/libs/logic/test/compile-fail/implicit_int_2.cpp | 16 | ||||
-rw-r--r-- | src/boost/libs/logic/test/compile-fail/implicit_int_3.cpp | 16 | ||||
-rw-r--r-- | src/boost/libs/logic/test/compile-fail/operator_less_1.cpp | 16 | ||||
-rw-r--r-- | src/boost/libs/logic/test/compile-fail/operator_less_2.cpp | 15 | ||||
-rw-r--r-- | src/boost/libs/logic/test/compile/decl_header.cpp | 24 | ||||
-rw-r--r-- | src/boost/libs/logic/test/tribool_io_test.cpp | 210 | ||||
-rw-r--r-- | src/boost/libs/logic/test/tribool_rename_test.cpp | 123 | ||||
-rw-r--r-- | src/boost/libs/logic/test/tribool_test.cpp | 154 |
11 files changed, 675 insertions, 0 deletions
diff --git a/src/boost/libs/logic/test/Jamfile.v2 b/src/boost/libs/logic/test/Jamfile.v2 new file mode 100644 index 00000000..994f2b6b --- /dev/null +++ b/src/boost/libs/logic/test/Jamfile.v2 @@ -0,0 +1,62 @@ +# Tribool library + +# Copyright (C) 2002-2003 Douglas Gregor + +# Use, modification and distribution is subject to the Boost Software License, +# Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +# For more information, see http://www.boost.org/ + +import path ; +import os ; +import regex ; +import testing ; + +local self = logic ; + +rule test-expected-failures +{ + local all_rules = ; + local file ; + local tests_path = [ path.make $(BOOST_ROOT)/libs/$(self)/test/compile-fail ] ; + for file in [ path.glob-tree $(tests_path) : *.cpp ] + { + local rel_file = [ path.relative-to $(tests_path) $(file) ] ; + local test_name = [ regex.replace [ regex.replace $(rel_file) "/" "-" ] ".cpp" "" ] ; + local decl_test_name = cf-$(test_name) ; + # ECHO $(rel_file) ; + all_rules += [ compile-fail $(file) : : $(decl_test_name) ] ; + } + + # ECHO All rules: $(all_rules) ; + return $(all_rules) ; +} + +rule test-header-isolation +{ + local all_rules = ; + local file ; + local headers_path = [ path.make $(BOOST_ROOT)/libs/$(self)/include ] ; + for file in [ path.glob-tree $(headers_path) : *.hpp ] + { + local rel_file = [ path.relative-to $(headers_path) $(file) ] ; + # Note: The test name starts with '~' in order to group these tests in the test report table, preferably at the end. + # All '/' are replaced with '-' because apparently test scripts have a problem with test names containing slashes. + local test_name = [ regex.replace $(rel_file) "/" "-" ] ; + local decl_test_name = ~hdr-decl-$(test_name) ; + # ECHO $(rel_file) ; + all_rules += [ compile compile/decl_header.cpp : <define>"BOOST_TEST_HEADER=$(rel_file)" <dependency>$(file) : $(decl_test_name) ] ; + } + + # ECHO All rules: $(all_rules) ; + return $(all_rules) ; +} + + test-suite logic : + [ test-expected-failures ] + [ test-header-isolation ] + [ run tribool_test.cpp ] + [ run tribool_rename_test.cpp ] + [ run tribool_io_test.cpp ] + ; diff --git a/src/boost/libs/logic/test/compile-fail/implicit.cpp b/src/boost/libs/logic/test/compile-fail/implicit.cpp new file mode 100644 index 00000000..ba56bfb8 --- /dev/null +++ b/src/boost/libs/logic/test/compile-fail/implicit.cpp @@ -0,0 +1,23 @@ +// Copyright 2018 James E. King III. Use, modification and +// distribution is subject to the Boost Software License, Version +// 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/logic/tribool.hpp> + +int main(int, char*[]) +{ + using boost::logic::indeterminate; + using boost::logic::tribool; + + tribool i(indeterminate); + +#if !defined( BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS ) + bool b = i; // expect to see: no viable conversion from 'boost::logic::tribool' to 'bool' + return (int)b; +#else +#error in c++03 explicit conversions are allowed +#endif + // NOTREACHED + return 0; +} diff --git a/src/boost/libs/logic/test/compile-fail/implicit_int_1.cpp b/src/boost/libs/logic/test/compile-fail/implicit_int_1.cpp new file mode 100644 index 00000000..4e889550 --- /dev/null +++ b/src/boost/libs/logic/test/compile-fail/implicit_int_1.cpp @@ -0,0 +1,16 @@ +// Copyright 2018 James E. King III. Use, modification and +// distribution is subject to the Boost Software License, Version +// 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/logic/tribool.hpp> + +int main(int, char*[]) +{ + using boost::logic::indeterminate; + using boost::logic::tribool; + + tribool i(indeterminate); + + return i; // expect to see: error: no viable conversion from returned value of type 'boost::logic::tribool' to function return type 'int' +} diff --git a/src/boost/libs/logic/test/compile-fail/implicit_int_2.cpp b/src/boost/libs/logic/test/compile-fail/implicit_int_2.cpp new file mode 100644 index 00000000..1401caaa --- /dev/null +++ b/src/boost/libs/logic/test/compile-fail/implicit_int_2.cpp @@ -0,0 +1,16 @@ +// Copyright 2018 James E. King III. Use, modification and +// distribution is subject to the Boost Software License, Version +// 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/logic/tribool.hpp> + +int main(int, char*[]) +{ + using boost::logic::indeterminate; + using boost::logic::tribool; + + tribool i(indeterminate); + + return i + 1; // expect to see: error: invalid operands to binary expression ('boost::logic::tribool' and 'int') +} diff --git a/src/boost/libs/logic/test/compile-fail/implicit_int_3.cpp b/src/boost/libs/logic/test/compile-fail/implicit_int_3.cpp new file mode 100644 index 00000000..b6548c5a --- /dev/null +++ b/src/boost/libs/logic/test/compile-fail/implicit_int_3.cpp @@ -0,0 +1,16 @@ +// Copyright 2018 James E. King III. Use, modification and +// distribution is subject to the Boost Software License, Version +// 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/logic/tribool.hpp> + +int main(int, char*[]) +{ + using boost::logic::indeterminate; + using boost::logic::tribool; + + tribool i(indeterminate); + + return i << 1; // expect to see: error: invalid operands to binary expression ('boost::logic::tribool' and 'int') +} diff --git a/src/boost/libs/logic/test/compile-fail/operator_less_1.cpp b/src/boost/libs/logic/test/compile-fail/operator_less_1.cpp new file mode 100644 index 00000000..31be7aee --- /dev/null +++ b/src/boost/libs/logic/test/compile-fail/operator_less_1.cpp @@ -0,0 +1,16 @@ +// Copyright 2018 James E. King III. Use, modification and +// distribution is subject to the Boost Software License, Version +// 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/logic/tribool.hpp> + +int main(int, char*[]) +{ + using boost::logic::tribool; + + tribool f; // false + tribool t(true); // true + + return f < t; // expect to see: error: invalid operands to binary expression ('boost::logic::tribool' and 'boost::logic::tribool') +} diff --git a/src/boost/libs/logic/test/compile-fail/operator_less_2.cpp b/src/boost/libs/logic/test/compile-fail/operator_less_2.cpp new file mode 100644 index 00000000..53fc359a --- /dev/null +++ b/src/boost/libs/logic/test/compile-fail/operator_less_2.cpp @@ -0,0 +1,15 @@ +// Copyright 2018 James E. King III. Use, modification and +// distribution is subject to the Boost Software License, Version +// 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/logic/tribool.hpp> + +int main(int, char*[]) +{ + using boost::logic::tribool; + + tribool t(true); + + return t < 1; // expect to see: error: invalid operands to binary expression ('boost::logic::tribool' and 'int') +} diff --git a/src/boost/libs/logic/test/compile/decl_header.cpp b/src/boost/libs/logic/test/compile/decl_header.cpp new file mode 100644 index 00000000..2a286261 --- /dev/null +++ b/src/boost/libs/logic/test/compile/decl_header.cpp @@ -0,0 +1,24 @@ +/* + * Copyright Andrey Semashev 2015. + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + */ +/*! + * \file decl_header.cpp + * \author Andrey Semashev + * \date 21.06.2015 + * + * \brief This file contains a test boilerplate for checking that every + * public header is self-contained and does not have any missing + * #includes. + */ + +#define BOOST_TEST_INCLUDE_HEADER() <BOOST_TEST_HEADER> + +#include BOOST_TEST_INCLUDE_HEADER() + +int main(int, char*[]) +{ + return 0; +} diff --git a/src/boost/libs/logic/test/tribool_io_test.cpp b/src/boost/libs/logic/test/tribool_io_test.cpp new file mode 100644 index 00000000..c2d50212 --- /dev/null +++ b/src/boost/libs/logic/test/tribool_io_test.cpp @@ -0,0 +1,210 @@ +// Copyright Douglas Gregor 2002-2004. Use, modification and +// distribution is subject to the Boost Software License, Version +// 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +#include <boost/logic/tribool.hpp> +#include <boost/logic/tribool_io.hpp> +#include <boost/test/minimal.hpp> +#include <sstream> +#include <string> +#include <iostream> +#include <ios> // for std::boolalpha + +#ifndef BOOST_NO_STD_LOCALE +# include <locale> +#endif + +int test_main(int, char*[]) +{ + using namespace boost::logic; + + tribool x; + + #if !defined(BOOST_NO_CWCHAR) && !defined(BOOST_NO_STD_WSTRING) + std::wostringstream wout; + wout << std::boolalpha << tribool(false); + BOOST_CHECK(wout.str() == L"false"); + wout.str(std::wstring()); + wout << std::boolalpha << tribool(true); + BOOST_CHECK(wout.str() == L"true"); + wout.str(std::wstring()); + wout << std::boolalpha << tribool(indeterminate); + BOOST_CHECK(wout.str() == L"indeterminate"); + #endif + + // Check tribool output + std::ostringstream out; + + // Output false (noboolalpha) + out.str(std::string()); + x = false; + out << x; + std::cout << "Output false (noboolalpha): " << out.str() << std::endl; + BOOST_CHECK(out.str() == "0"); + + // Output true (noboolalpha) + out.str(std::string()); + x = true; + out << x; + std::cout << "Output true (noboolalpha): " << out.str() << std::endl; + BOOST_CHECK(out.str() == "1"); + + // Output indeterminate (noboolalpha) + out.str(std::string()); + x = indeterminate; + out << x; + std::cout << "Output indeterminate (noboolalpha): " << out.str() + << std::endl; + BOOST_CHECK(out.str() == "2"); + + // Output indeterminate (noboolalpha) + out.str(std::string()); + out << indeterminate; + std::cout << "Output indeterminate (noboolalpha): " << out.str() + << std::endl; + BOOST_CHECK(out.str() == "2"); + +#ifndef BOOST_NO_STD_LOCALE + const std::numpunct<char>& punct = + BOOST_USE_FACET(std::numpunct<char>, out.getloc()); + + // Output false (boolalpha) + out.str(std::string()); + x = false; + out << std::boolalpha << x; + std::cout << "Output false (boolalpha): " << out.str() << std::endl; + BOOST_CHECK(out.str() == punct.falsename()); + + // Output true (boolalpha) + out.str(std::string()); + x = true; + out << std::boolalpha << x; + std::cout << "Output true (boolalpha): " << out.str() << std::endl; + + BOOST_CHECK(out.str() == punct.truename()); + + // Output indeterminate (boolalpha - default name) + out.str(std::string()); + x = indeterminate; + out << std::boolalpha << x; + std::cout << "Output indeterminate (boolalpha - default name): " << out.str() + << std::endl; + BOOST_CHECK(out.str() == "indeterminate"); + + // Output indeterminate (boolalpha - default name) + out.str(std::string()); + out << std::boolalpha << indeterminate; + std::cout << "Output indeterminate (boolalpha - default name): " << out.str() + << std::endl; + BOOST_CHECK(out.str() == "indeterminate"); + +# if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) + // No template constructors, so we can't build the test locale +# else + // Give indeterminate a new name, and output it via boolalpha + std::locale global; + std::locale test_locale(global, new indeterminate_name<char>("maybe")); + out.imbue(test_locale); + out.str(std::string()); + out << std::boolalpha << x; + std::cout << "Output indeterminate (boolalpha - \"maybe\"): " << out.str() + << std::endl; + BOOST_CHECK(out.str() == "maybe"); +# endif +#endif // ! BOOST_NO_STD_LOCALE + + // Checking tribool input + + // Input false (noboolalpha) + { + std::istringstream in("0"); + std::cout << "Input \"0\" (checks for false)" << std::endl; + in >> x; + BOOST_CHECK(x == false); + } + + // Input true (noboolalpha) + { + std::istringstream in("1"); + std::cout << "Input \"1\" (checks for true)" << std::endl; + in >> x; + BOOST_CHECK(x == true); + } + + // Input false (noboolalpha) + { + std::istringstream in("2"); + std::cout << "Input \"2\" (checks for indeterminate)" << std::endl; + in >> x; + BOOST_CHECK(indeterminate(x)); + } + + // Input bad number (noboolalpha) + { + std::istringstream in("3"); + std::cout << "Input \"3\" (checks for failure)" << std::endl; + BOOST_CHECK(!(in >> x)); + } + + // Input false (boolalpha) + { + std::istringstream in("false"); + std::cout << "Input \"false\" (checks for false)" << std::endl; + in >> std::boolalpha >> x; + BOOST_CHECK(x == false); + } + + // Input true (boolalpha) + { + std::istringstream in("true"); + std::cout << "Input \"true\" (checks for true)" << std::endl; + in >> std::boolalpha >> x; + BOOST_CHECK(x == true); + } + + // Input indeterminate (boolalpha) + { + std::istringstream in("indeterminate"); + std::cout << "Input \"indeterminate\" (checks for indeterminate)" + << std::endl; + in >> std::boolalpha >> x; + BOOST_CHECK(indeterminate(x)); + } + + // Input bad string (boolalpha) + { + std::istringstream in("bad"); + std::cout << "Input \"bad\" (checks for failure)" + << std::endl; + BOOST_CHECK(!(in >> std::boolalpha >> x)); + } + +#if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) + // No template constructors, so we can't build the test locale +#elif !defined(BOOST_NO_STD_LOCALE) + + // Input indeterminate named "maybe" (boolalpha) + { + std::istringstream in("maybe"); + in.imbue(test_locale); + std::cout << "Input \"maybe\" (checks for indeterminate, uses locales)" + << std::endl; + in >> std::boolalpha >> x; + BOOST_CHECK(indeterminate(x)); + } + + // Input indeterminate named "true_or_false" (boolalpha) + { + std::locale my_locale(global, + new indeterminate_name<char>("true_or_false")); + std::istringstream in("true_or_false"); + in.imbue(my_locale); + std::cout << "Input \"true_or_false\" (checks for indeterminate)" + << std::endl; + in >> std::boolalpha >> x; + BOOST_CHECK(indeterminate(x)); + } +#endif + + return 0; +} diff --git a/src/boost/libs/logic/test/tribool_rename_test.cpp b/src/boost/libs/logic/test/tribool_rename_test.cpp new file mode 100644 index 00000000..3a5b066b --- /dev/null +++ b/src/boost/libs/logic/test/tribool_rename_test.cpp @@ -0,0 +1,123 @@ +// Copyright Douglas Gregor 2002-2003. Use, modification and +// distribution is subject to the Boost Software License, Version +// 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// For more information, see http://www.boost.org + +#include <boost/logic/tribool.hpp> +#include <boost/test/minimal.hpp> +#include <iostream> + +BOOST_TRIBOOL_THIRD_STATE(maybe) + +int test_main(int,char*[]) +{ + using namespace boost::logic; + + tribool x; // false + tribool y(true); // true + tribool z(maybe); // maybe + + BOOST_CHECK(!x); + BOOST_CHECK(x == false); + BOOST_CHECK(false == x); + BOOST_CHECK(x != true); + BOOST_CHECK(true != x); + BOOST_CHECK(maybe(x == maybe)); + BOOST_CHECK(maybe(maybe == x)); + BOOST_CHECK(maybe(x != maybe)); + BOOST_CHECK(maybe(maybe != x)); + BOOST_CHECK(x == x); + BOOST_CHECK(!(x != x)); + BOOST_CHECK(!(x && true)); + BOOST_CHECK(!(true && x)); + BOOST_CHECK(x || true); + BOOST_CHECK(true || x); + + BOOST_CHECK(y); + BOOST_CHECK(y == true); + BOOST_CHECK(true == y); + BOOST_CHECK(y != false); + BOOST_CHECK(false != y); + BOOST_CHECK(maybe(y == maybe)); + BOOST_CHECK(maybe(maybe == y)); + BOOST_CHECK(maybe(y != maybe)); + BOOST_CHECK(maybe(maybe != y)); + BOOST_CHECK(y == y); + BOOST_CHECK(!(y != y)); + + BOOST_CHECK(maybe(z || !z)); + BOOST_CHECK(maybe(z == true)); + BOOST_CHECK(maybe(true == z)); + BOOST_CHECK(maybe(z == false)); + BOOST_CHECK(maybe(false == z)); + BOOST_CHECK(maybe(z == maybe)); + BOOST_CHECK(maybe(maybe == z)); + BOOST_CHECK(maybe(z != maybe)); + BOOST_CHECK(maybe(maybe != z)); + BOOST_CHECK(maybe(z == z)); + BOOST_CHECK(maybe(z != z)); + + BOOST_CHECK(!(x == y)); + BOOST_CHECK(x != y); + BOOST_CHECK(maybe(x == z)); + BOOST_CHECK(maybe(x != z)); + BOOST_CHECK(maybe(y == z)); + BOOST_CHECK(maybe(y != z)); + + BOOST_CHECK(!(x && y)); + BOOST_CHECK(x || y); + BOOST_CHECK(!(x && z)); + BOOST_CHECK(maybe(y && z)); + BOOST_CHECK(maybe(z && z)); + BOOST_CHECK(maybe(z || z)); + BOOST_CHECK(maybe(x || z)); + BOOST_CHECK(y || z); + + BOOST_CHECK(maybe(y && maybe)); + BOOST_CHECK(maybe(maybe && y)); + BOOST_CHECK(!(x && maybe)); + BOOST_CHECK(!(maybe && x)); + + BOOST_CHECK(maybe || y); + BOOST_CHECK(y || maybe); + BOOST_CHECK(maybe(x || maybe)); + BOOST_CHECK(maybe(maybe || x)); + + // Test the if (z) ... else (!z) ... else ... idiom + if (z) { + BOOST_CHECK(false); + } + else if (!z) { + BOOST_CHECK(false); + } + else { + BOOST_CHECK(true); + } + + z = true; + if (z) { + BOOST_CHECK(true); + } + else if (!z) { + BOOST_CHECK(false); + } + else { + BOOST_CHECK(false); + } + + z = false; + if (z) { + BOOST_CHECK(false); + } + else if (!z) { + BOOST_CHECK(true); + } + else { + BOOST_CHECK(false); + } + + std::cout << "no errors detected\n"; + return 0; +} diff --git a/src/boost/libs/logic/test/tribool_test.cpp b/src/boost/libs/logic/test/tribool_test.cpp new file mode 100644 index 00000000..3781e373 --- /dev/null +++ b/src/boost/libs/logic/test/tribool_test.cpp @@ -0,0 +1,154 @@ +// Copyright Douglas Gregor 2002-2003. Use, modification and +// distribution is subject to the Boost Software License, Version +// 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/config.hpp> +#include <boost/logic/tribool.hpp> +#include <boost/test/minimal.hpp> +#include <iostream> + +int test_main(int, char*[]) +{ + using namespace boost::logic; + + tribool x; // false + tribool y(true); // true + tribool z(indeterminate); // indeterminate + +#if defined( BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS ) + // c++03 allows for implicit conversion to bool + // c++11 uses an explicit conversion operator so this would not compile + // and that is tested in the compile-fail/implicit.cpp file + // so we check the conversion to ensure it is sane + bool bx = x; + BOOST_CHECK(bx == false); + bool by = y; + BOOST_CHECK(by == true); + bool bz = z; + BOOST_CHECK(bz == false); +#endif + + BOOST_CHECK(!x); + BOOST_CHECK(x == false); + BOOST_CHECK(false == x); + BOOST_CHECK(x != true); + BOOST_CHECK(true != x); + BOOST_CHECK(indeterminate(x == indeterminate)); + BOOST_CHECK(indeterminate(indeterminate == x)); + BOOST_CHECK(indeterminate(x != indeterminate)); + BOOST_CHECK(indeterminate(indeterminate != x)); + BOOST_CHECK(x == x); + BOOST_CHECK(!(x != x)); + BOOST_CHECK(!(x && true)); + BOOST_CHECK(!(true && x)); + BOOST_CHECK(x || true); + BOOST_CHECK(true || x); + + BOOST_CHECK(y); + BOOST_CHECK(y == true); + BOOST_CHECK(true == y); + BOOST_CHECK(y != false); + BOOST_CHECK(false != y); + BOOST_CHECK(indeterminate(y == indeterminate)); + BOOST_CHECK(indeterminate(indeterminate == y)); + BOOST_CHECK(indeterminate(y != indeterminate)); + BOOST_CHECK(indeterminate(indeterminate != y)); + BOOST_CHECK(y == y); + BOOST_CHECK(!(y != y)); + + BOOST_CHECK(indeterminate(z || !z)); + BOOST_CHECK(indeterminate(z == true)); + BOOST_CHECK(indeterminate(true == z)); + BOOST_CHECK(indeterminate(z == false)); + BOOST_CHECK(indeterminate(false == z)); + BOOST_CHECK(indeterminate(z == indeterminate)); + BOOST_CHECK(indeterminate(indeterminate == z)); + BOOST_CHECK(indeterminate(z != indeterminate)); + BOOST_CHECK(indeterminate(indeterminate != z)); + BOOST_CHECK(indeterminate(z == z)); + BOOST_CHECK(indeterminate(z != z)); + + BOOST_CHECK(!(x == y)); + BOOST_CHECK(x != y); + BOOST_CHECK(indeterminate(x == z)); + BOOST_CHECK(indeterminate(x != z)); + BOOST_CHECK(indeterminate(y == z)); + BOOST_CHECK(indeterminate(y != z)); + + BOOST_CHECK(!(x && y)); + BOOST_CHECK(x || y); + BOOST_CHECK(!(x && z)); + BOOST_CHECK(indeterminate(y && z)); + BOOST_CHECK(indeterminate(z && z)); + BOOST_CHECK(indeterminate(z || z)); + BOOST_CHECK(indeterminate(x || z)); + BOOST_CHECK(y || z); + + BOOST_CHECK(indeterminate(y && indeterminate)); + BOOST_CHECK(indeterminate(indeterminate && y)); + BOOST_CHECK(!(x && indeterminate)); + BOOST_CHECK(!(indeterminate && x)); + + BOOST_CHECK(indeterminate || y); + BOOST_CHECK(y || indeterminate); + BOOST_CHECK(indeterminate(x || indeterminate)); + BOOST_CHECK(indeterminate(indeterminate || x)); + + // Test the if (z) ... else (!z) ... else ... idiom + if (z) { + BOOST_CHECK(false); + } + else if (!z) { + BOOST_CHECK(false); + } + else { + BOOST_CHECK(true); + } + + z = true; + if (z) { + BOOST_CHECK(true); + } + else if (!z) { + BOOST_CHECK(false); + } + else { + BOOST_CHECK(false); + } + + z = false; + if (z) { + BOOST_CHECK(false); + } + else if (!z) { + BOOST_CHECK(true); + } + else { + BOOST_CHECK(false); + } + +#if !defined(BOOST_NO_CXX11_CONSTEXPR) + constexpr bool res_ors = indeterminate(false || tribool(false) || false || indeterminate); // true + BOOST_CHECK(res_ors); + char array_ors[res_ors ? 2 : 3]; + BOOST_CHECK(sizeof(array_ors) / sizeof(char) == 2); + + constexpr bool res_ands = !indeterminate(!(true && tribool(true) && true && indeterminate)); // false + BOOST_CHECK(!res_ands); + char array_ands[res_ands ? 2 : 3]; + BOOST_CHECK(sizeof(array_ands) / sizeof(char) == 3); + + constexpr bool res_safe_bool = static_cast<bool>( tribool(true) ); + BOOST_STATIC_ASSERT(res_safe_bool); + +// gcc 4.6 chokes on the xxx assignment +# if !BOOST_WORKAROUND(BOOST_GCC, < 40700) + constexpr tribool xxx = (tribool(true) || tribool(indeterminate)); + BOOST_STATIC_ASSERT(xxx); +# endif +#endif + + std::cout << "no errors detected\n"; + return 0; +} |