// Boost.Geometry (aka GGL, Generic Geometry Library) // Unit Test // Copyright (c) 2015, Oracle and/or its affiliates. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle // Licensed under the Boost Software License version 1.0. // http://www.boost.org/users/license.html #ifndef BOOST_TEST_MODULE #define BOOST_TEST_MODULE test_promote_integral #endif #if !defined(BOOST_GEOMETRY_NO_MULTIPRECISION_INTEGER) #include #endif #include #include #include #include #include #include #include #if defined(BOOST_GEOMETRY_TEST_DEBUG) && defined(BOOST_HAS_INT128) std::ostream& operator<<(std::ostream& os, boost::int128_type i) { os << double(i); return os; } #endif namespace bg = boost::geometry; template inline void test_promote_integral() { typedef typename bg::promote_integral::type promoted_integral_type; bool const same_types = boost::is_same < promoted_integral_type, ExpectedPromotedType >::type::value; BOOST_CHECK(same_types); #ifdef BOOST_GEOMETRY_TEST_DEBUG std::cout << "type : " << typeid(Type).name() << ", sizeof: " << sizeof(Type) << ", max value: " << std::numeric_limits::max() << std::endl; std::cout << "detected promoted type : " << typeid(promoted_integral_type).name() << ", sizeof: " << sizeof(promoted_integral_type) << ", max value: " << std::numeric_limits::max() << std::endl; std::cout << "expected promoted type : " << typeid(ExpectedPromotedType).name() << ", sizeof: " << sizeof(ExpectedPromotedType) << ", max value: " << std::numeric_limits::max() << std::endl; std::cout << std::endl; #endif } template void test_promotion() { if (sizeof(short) >= 2 * sizeof(T)) { test_promote_integral(); } else if (sizeof(int) >= 2 * sizeof(T)) { test_promote_integral(); } else if (sizeof(long) >= 2 * sizeof(T)) { test_promote_integral(); } #if defined(BOOST_HAS_LONG_LONG) else if (sizeof(boost::long_long_type) >= 2 * sizeof(T)) { test_promote_integral(); } #endif #if defined(BOOST_HAS_INT128) else if (sizeof(boost::int128_type) >= 2 * sizeof(T)) { test_promote_integral(); } #endif else { #if !defined(BOOST_GEOMETRY_NO_MULTIPRECISION_INTEGER) namespace bm = boost::multiprecision; typedef bm::number < bm::cpp_int_backend < 2 * CHAR_BIT * sizeof(T), 2 * CHAR_BIT * sizeof(T), bm::signed_magnitude, bm::unchecked, void > > multiprecision_integer_type; test_promote_integral(); #else test_promote_integral(); #endif } } BOOST_AUTO_TEST_CASE( test_char ) { test_promotion(); } BOOST_AUTO_TEST_CASE( test_short ) { test_promotion(); } BOOST_AUTO_TEST_CASE( test_int ) { test_promotion(); } BOOST_AUTO_TEST_CASE( test_long ) { test_promotion(); } #ifdef BOOST_HAS_LONG_LONG BOOST_AUTO_TEST_CASE( test_long_long ) { test_promotion(); } #endif #if defined(BOOST_HAS_INT128) BOOST_AUTO_TEST_CASE( test_int128 ) { test_promotion(); } #endif BOOST_AUTO_TEST_CASE( test_custom_types ) { namespace bm = boost::multiprecision; typedef bm::number < bm::cpp_int_backend < 17, 17, bm::signed_magnitude, bm::unchecked, void > > custom_integral_type1; typedef bm::number < bm::cpp_int_backend < 500, 500, bm::signed_magnitude, bm::unchecked, void > > custom_integral_type2; // for user defined number types we do not do any promotion test_promote_integral(); test_promote_integral(); } BOOST_AUTO_TEST_CASE( test_floating_point ) { // for floating-point types we do not do any promotion test_promote_integral(); test_promote_integral(); test_promote_integral(); #ifdef HAVE_TTMATH test_promote_integral(); #endif }