diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index a52dd3f..66bc8ab 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -300,6 +300,15 @@ run bit_endian_test.cpp compile-fail bit_width_fail.cpp : off ; +compile bit_rotate_test_cx.cpp ; +compile bit_countr_test_cx.cpp ; +compile bit_countl_test_cx.cpp ; +compile bit_width_test_cx.cpp ; +compile has_single_bit_test_cx.cpp ; +compile bit_floor_test_cx.cpp ; +compile bit_ceil_test_cx.cpp ; +compile bit_popcount_test_cx.cpp ; + run type_name_test.cpp ; run snprintf_test.cpp ; diff --git a/test/bit_ceil_test_cx.cpp b/test/bit_ceil_test_cx.cpp new file mode 100644 index 0000000..083a84a --- /dev/null +++ b/test/bit_ceil_test_cx.cpp @@ -0,0 +1,26 @@ +// constexpr test for boost/core/bit.hpp (bit_ceil) +// +// Copyright 2023 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include +#include + +#if defined(BOOST_NO_CXX14_CONSTEXPR) + +BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined" ) + +#else + +#include + +#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) + +STATIC_ASSERT( boost::core::bit_ceil( (unsigned char)0x74 ) == 0x80 ); +STATIC_ASSERT( boost::core::bit_ceil( (unsigned short)0x7400 ) == 0x8000 ); +STATIC_ASSERT( boost::core::bit_ceil( 0x740000u ) == 0x800000u ); +STATIC_ASSERT( boost::core::bit_ceil( 0x74000000ul ) == 0x80000000ul ); +STATIC_ASSERT( boost::core::bit_ceil( 0x7400000000ull ) == 0x8000000000ull ); + +#endif diff --git a/test/bit_countl_test_cx.cpp b/test/bit_countl_test_cx.cpp new file mode 100644 index 0000000..6e1b072 --- /dev/null +++ b/test/bit_countl_test_cx.cpp @@ -0,0 +1,33 @@ +// constexpr test for boost/core/bit.hpp (countl_zero, countl_one) +// +// Copyright 2023 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include +#include + +#if defined(BOOST_NO_CXX14_CONSTEXPR) + +BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined" ) + +#else + +#include +#include + +#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) + +STATIC_ASSERT( boost::core::countl_zero( (unsigned char)0x1F ) == CHAR_BIT - 5 ); +STATIC_ASSERT( boost::core::countl_zero( (unsigned short)0x1F ) == sizeof(unsigned short) * CHAR_BIT - 5 ); +STATIC_ASSERT( boost::core::countl_zero( 0x1Fu ) == sizeof(unsigned int) * CHAR_BIT - 5 ); +STATIC_ASSERT( boost::core::countl_zero( 0x1Ful ) == sizeof(unsigned long) * CHAR_BIT - 5 ); +STATIC_ASSERT( boost::core::countl_zero( 0x1Full ) == sizeof(unsigned long long) * CHAR_BIT - 5 ); + +STATIC_ASSERT( boost::core::countl_one( (unsigned char)~0x1Fu ) == CHAR_BIT - 5 ); +STATIC_ASSERT( boost::core::countl_one( (unsigned short)~0x1Fu ) == sizeof(unsigned short) * CHAR_BIT - 5 ); +STATIC_ASSERT( boost::core::countl_one( ~0x1Fu ) == sizeof(unsigned int) * CHAR_BIT - 5 ); +STATIC_ASSERT( boost::core::countl_one( ~0x1Ful ) == sizeof(unsigned long) * CHAR_BIT - 5 ); +STATIC_ASSERT( boost::core::countl_one( ~0x1Full ) == sizeof(unsigned long long) * CHAR_BIT - 5 ); + +#endif diff --git a/test/bit_countr_test_cx.cpp b/test/bit_countr_test_cx.cpp new file mode 100644 index 0000000..ba1d702 --- /dev/null +++ b/test/bit_countr_test_cx.cpp @@ -0,0 +1,33 @@ +// constexpr test for boost/core/bit.hpp (countr_zero, countr_one) +// +// Copyright 2023 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include +#include + +#if defined(BOOST_NO_CXX14_CONSTEXPR) + +BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined" ) + +#else + +#include +#include + +#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) + +STATIC_ASSERT( boost::core::countr_zero( (unsigned char)0xF8 ) == 3 ); +STATIC_ASSERT( boost::core::countr_zero( (unsigned short)0xF800 ) == 11 ); +STATIC_ASSERT( boost::core::countr_zero( 0xF80000u ) == 19 ); +STATIC_ASSERT( boost::core::countr_zero( 0xF8000000ul ) == 27 ); +STATIC_ASSERT( boost::core::countr_zero( 0xF800000000ull ) == 35 ); + +STATIC_ASSERT( boost::core::countr_one( (unsigned char)~0xF8u ) == 3 ); +STATIC_ASSERT( boost::core::countr_one( (unsigned short)~0xF800u ) == 11 ); +STATIC_ASSERT( boost::core::countr_one( ~0xF80000u ) == 19 ); +STATIC_ASSERT( boost::core::countr_one( ~0xF8000000ul ) == 27 ); +STATIC_ASSERT( boost::core::countr_one( ~0xF800000000ull ) == 35 ); + +#endif diff --git a/test/bit_floor_test_cx.cpp b/test/bit_floor_test_cx.cpp new file mode 100644 index 0000000..4fb6fd1 --- /dev/null +++ b/test/bit_floor_test_cx.cpp @@ -0,0 +1,26 @@ +// constexpr test for boost/core/bit.hpp (bit_floor) +// +// Copyright 2023 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include +#include + +#if defined(BOOST_NO_CXX14_CONSTEXPR) + +BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined" ) + +#else + +#include + +#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) + +STATIC_ASSERT( boost::core::bit_floor( (unsigned char)0x74 ) == 0x40 ); +STATIC_ASSERT( boost::core::bit_floor( (unsigned short)0x7400 ) == 0x4000 ); +STATIC_ASSERT( boost::core::bit_floor( 0x740000u ) == 0x400000u ); +STATIC_ASSERT( boost::core::bit_floor( 0x74000000ul ) == 0x40000000ul ); +STATIC_ASSERT( boost::core::bit_floor( 0x7400000000ull ) == 0x4000000000ull ); + +#endif diff --git a/test/bit_popcount_test.cpp b/test/bit_popcount_test.cpp index 30d4777..f2f8aa2 100644 --- a/test/bit_popcount_test.cpp +++ b/test/bit_popcount_test.cpp @@ -1,4 +1,4 @@ -// Test for boost/core/bit.hpp (bit_ceil) +// Test for boost/core/bit.hpp (popcount) // // Copyright 2020 Peter Dimov // Distributed under the Boost Software License, Version 1.0. diff --git a/test/bit_popcount_test_cx.cpp b/test/bit_popcount_test_cx.cpp new file mode 100644 index 0000000..0513591 --- /dev/null +++ b/test/bit_popcount_test_cx.cpp @@ -0,0 +1,26 @@ +// constexpr test for boost/core/bit.hpp (popcount) +// +// Copyright 2023 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include +#include + +#if defined(BOOST_NO_CXX14_CONSTEXPR) + +BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined" ) + +#else + +#include + +#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) + +STATIC_ASSERT( boost::core::popcount( (unsigned char)0x74 ) == 4 ); +STATIC_ASSERT( boost::core::popcount( (unsigned short)0x7400 ) == 4 ); +STATIC_ASSERT( boost::core::popcount( 0x740000u ) == 4 ); +STATIC_ASSERT( boost::core::popcount( 0x74000000ul ) == 4 ); +STATIC_ASSERT( boost::core::popcount( 0x7400000000ull ) == 4 ); + +#endif diff --git a/test/bit_rotate_test_cx.cpp b/test/bit_rotate_test_cx.cpp new file mode 100644 index 0000000..eff6f4b --- /dev/null +++ b/test/bit_rotate_test_cx.cpp @@ -0,0 +1,33 @@ +// constexpr test for boost/core/bit.hpp (rotl, rotr) +// +// Copyright 2023 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include +#include + +#if defined(BOOST_NO_CXX14_CONSTEXPR) + +BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined" ) + +#else + +#include +#include + +#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) + +STATIC_ASSERT( boost::core::rotl( (std::uint8_t)0x11, 1 ) == 0x22 ); +STATIC_ASSERT( boost::core::rotr( (std::uint8_t)0x11, 1 ) == 0x88 ); + +STATIC_ASSERT( boost::core::rotl( (std::uint16_t)0x1111, 1 ) == 0x2222 ); +STATIC_ASSERT( boost::core::rotr( (std::uint16_t)0x1111, 1 ) == 0x8888 ); + +STATIC_ASSERT( boost::core::rotl( (std::uint32_t)0x11111111, 1 ) == 0x22222222 ); +STATIC_ASSERT( boost::core::rotr( (std::uint32_t)0x11111111, 1 ) == 0x88888888 ); + +STATIC_ASSERT( boost::core::rotl( (std::uint64_t)0x1111111111111111, 1 ) == 0x2222222222222222 ); +STATIC_ASSERT( boost::core::rotr( (std::uint64_t)0x1111111111111111, 1 ) == 0x8888888888888888 ); + +#endif diff --git a/test/bit_width_test_cx.cpp b/test/bit_width_test_cx.cpp new file mode 100644 index 0000000..a9ca81b --- /dev/null +++ b/test/bit_width_test_cx.cpp @@ -0,0 +1,26 @@ +// constexpr test for boost/core/bit.hpp (bit_width) +// +// Copyright 2023 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include +#include + +#if defined(BOOST_NO_CXX14_CONSTEXPR) + +BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined" ) + +#else + +#include + +#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) + +STATIC_ASSERT( boost::core::bit_width( (unsigned char)0x74 ) == 7 ); +STATIC_ASSERT( boost::core::bit_width( (unsigned short)0x7400 ) == 15 ); +STATIC_ASSERT( boost::core::bit_width( 0x740000u ) == 23 ); +STATIC_ASSERT( boost::core::bit_width( 0x74000000ul ) == 31 ); +STATIC_ASSERT( boost::core::bit_width( 0x7400000000ull ) == 39 ); + +#endif diff --git a/test/has_single_bit_test_cx.cpp b/test/has_single_bit_test_cx.cpp new file mode 100644 index 0000000..d1a1bd2 --- /dev/null +++ b/test/has_single_bit_test_cx.cpp @@ -0,0 +1,35 @@ +// constexpr test for boost/core/bit.hpp (has_single_bit) +// +// Copyright 2023 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include +#include + +#if defined(BOOST_NO_CXX14_CONSTEXPR) + +BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined" ) + +#else + +#include + +#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) + +STATIC_ASSERT( boost::core::has_single_bit( (unsigned char)0x80 ) == true ); +STATIC_ASSERT( boost::core::has_single_bit( (unsigned char)0x90 ) == false ); + +STATIC_ASSERT( boost::core::has_single_bit( (unsigned short)0x8000 ) == true ); +STATIC_ASSERT( boost::core::has_single_bit( (unsigned short)0x9000 ) == false ); + +STATIC_ASSERT( boost::core::has_single_bit( 0x800000u ) == true ); +STATIC_ASSERT( boost::core::has_single_bit( 0x900000u ) == false ); + +STATIC_ASSERT( boost::core::has_single_bit( 0x80000000ul ) == true ); +STATIC_ASSERT( boost::core::has_single_bit( 0x90000000ul ) == false ); + +STATIC_ASSERT( boost::core::has_single_bit( 0x8000000000ull ) == true ); +STATIC_ASSERT( boost::core::has_single_bit( 0x9000000000ull ) == false ); + +#endif