| 1 | // Copyright Antony Polukhin, 2016-2024. |
| 2 | // |
| 3 | // Distributed under the Boost Software License, Version 1.0. (See |
| 4 | // accompanying file LICENSE_1_0.txt or copy at |
| 5 | // http://www.boost.org/LICENSE_1_0.txt) |
| 6 | |
| 7 | #include <boost/stacktrace/detail/to_dec_array.hpp> |
| 8 | #include <boost/stacktrace/detail/to_hex_array.hpp> |
| 9 | #include <boost/stacktrace/detail/try_dec_convert.hpp> |
| 10 | |
| 11 | #include <boost/core/lightweight_test.hpp> |
| 12 | #include <string> |
| 13 | #include <iostream> |
| 14 | |
| 15 | |
| 16 | void test_to_hex_array() { |
| 17 | const void* ptr = 0; |
| 18 | BOOST_TEST(std::string(boost::stacktrace::detail::to_hex_array(ptr).data()).find("0x0" ) != std::string::npos); |
| 19 | |
| 20 | ptr = reinterpret_cast<const void*>(0x10); |
| 21 | BOOST_TEST(std::string(boost::stacktrace::detail::to_hex_array(ptr).data()).find("10" ) != std::string::npos); |
| 22 | |
| 23 | ptr = reinterpret_cast<void*>(0x19); |
| 24 | BOOST_TEST(std::string(boost::stacktrace::detail::to_hex_array(ptr).data()).find("19" ) != std::string::npos); |
| 25 | |
| 26 | ptr = reinterpret_cast<void*>(0x999999); |
| 27 | BOOST_TEST(std::string(boost::stacktrace::detail::to_hex_array(ptr).data()).find("999999" ) != std::string::npos); |
| 28 | } |
| 29 | |
| 30 | void test_to_dec_array() { |
| 31 | BOOST_TEST_EQ(std::string(boost::stacktrace::detail::to_dec_array(0).data()), std::string("0" )); |
| 32 | BOOST_TEST_EQ(std::string(boost::stacktrace::detail::to_dec_array(10).data()), std::string("10" )); |
| 33 | BOOST_TEST_EQ(std::string(boost::stacktrace::detail::to_dec_array(19).data()), std::string("19" )); |
| 34 | BOOST_TEST_EQ(std::string(boost::stacktrace::detail::to_dec_array(999999).data()), std::string("999999" )); |
| 35 | } |
| 36 | |
| 37 | void test_try_dec_convert() { |
| 38 | std::size_t res = 0; |
| 39 | |
| 40 | BOOST_TEST(boost::stacktrace::detail::try_dec_convert("0" , res)); |
| 41 | BOOST_TEST(res == 0); |
| 42 | |
| 43 | BOOST_TEST(boost::stacktrace::detail::try_dec_convert("+0" , res)); |
| 44 | BOOST_TEST(res == 0); |
| 45 | |
| 46 | BOOST_TEST(boost::stacktrace::detail::try_dec_convert("10" , res)); |
| 47 | BOOST_TEST(res == 10); |
| 48 | |
| 49 | BOOST_TEST(boost::stacktrace::detail::try_dec_convert("19" , res)); |
| 50 | BOOST_TEST(res == 19); |
| 51 | |
| 52 | BOOST_TEST(boost::stacktrace::detail::try_dec_convert("+19" , res)); |
| 53 | BOOST_TEST(res == 19); |
| 54 | |
| 55 | BOOST_TEST(boost::stacktrace::detail::try_dec_convert("9999" , res)); |
| 56 | BOOST_TEST(res == 9999); |
| 57 | |
| 58 | BOOST_TEST(!boost::stacktrace::detail::try_dec_convert("q" , res)); |
| 59 | BOOST_TEST(!boost::stacktrace::detail::try_dec_convert("0z" , res)); |
| 60 | BOOST_TEST(!boost::stacktrace::detail::try_dec_convert("0u" , res)); |
| 61 | BOOST_TEST(!boost::stacktrace::detail::try_dec_convert("+0u" , res)); |
| 62 | } |
| 63 | |
| 64 | |
| 65 | int main() { |
| 66 | test_to_hex_array(); |
| 67 | test_to_dec_array(); |
| 68 | test_try_dec_convert(); |
| 69 | |
| 70 | return boost::report_errors(); |
| 71 | } |
| 72 | |