diff --git a/test/util/Jamfile.v2 b/test/util/Jamfile.v2 index bfb647dc7..70a463777 100644 --- a/test/util/Jamfile.v2 +++ b/test/util/Jamfile.v2 @@ -1,11 +1,11 @@ # Boost.Geometry (aka GGL, Generic Geometry Library) # -# Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands. -# Copyright (c) 2008-2014 Bruno Lalande, Paris, France. -# Copyright (c) 2009-2014 Mateusz Loskot, London, UK. +# Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands. +# Copyright (c) 2008-2015 Bruno Lalande, Paris, France. +# Copyright (c) 2009-2015 Mateusz Loskot, London, UK. # -# This file was modified by Oracle on 2014. -# Modifications copyright (c) 2014, Oracle and/or its affiliates. +# This file was modified by Oracle on 2014, 2015. +# Modifications copyright (c) 2014-2015, Oracle and/or its affiliates. # # Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle # @@ -18,6 +18,7 @@ test-suite boost-geometry-util [ run calculation_type.cpp ] [ run for_each_coordinate.cpp ] [ run math_sqrt.cpp ] + [ run promote_integral.cpp ] [ run range.cpp ] [ run rational.cpp ] [ run select_most_precise.cpp ] diff --git a/test/util/promote_integral.cpp b/test/util/promote_integral.cpp new file mode 100644 index 000000000..49f38d3f5 --- /dev/null +++ b/test/util/promote_integral.cpp @@ -0,0 +1,206 @@ +// 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 + +#if !defined(BOOST_GEOMETRY_NO_MULTIPRECISION_INTEGER) +#include +#endif + +#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 + +#if !defined(BOOST_GEOMETRY_NO_MULTIPRECISION_INTEGER) +BOOST_AUTO_TEST_CASE( test_custom_types ) +{ + namespace bm = boost::multiprecision; + typedef bm::number + < + bm::cpp_int_backend + < + CHAR_BIT * sizeof(short) + 1, + CHAR_BIT * sizeof(short) + 1, + 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(); +} +#endif + +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 +}