16 #define GETTEXT_DOMAIN "wesnoth-test"
21 #include <boost/test/unit_test.hpp>
29 #pragma warning(disable:4702)
32 #define LEXICAL_CAST_DEBUG
49 char,
signed char,
unsigned char,
50 short, int, long,
long long,
51 unsigned short,
unsigned int,
unsigned long,
unsigned long long
72 <<
"Expected " << result <<
'\n';
79 template<
typename Test,
typename... Types>
80 constexpr
bool contains_type(std::tuple<Types...>)
82 return (std::is_same_v<Test, Types> || ...);
87 #define TEST_CASE(type_send) \
89 type_send val = value; \
91 BOOST_CHECK_EXCEPTION( \
92 lexical_cast<std::string>(val), const char*, validate); \
99 result =
"specialized - To std::string - From arithmetic";
114 result =
"specialized - To arithmetic - From string";
116 const char* value =
"test";
117 BOOST_CHECK_EXCEPTION(lexical_cast<T>(
119 BOOST_CHECK_EXCEPTION(lexical_cast<T>(
120 const_cast<char*
>(value)),
const char*,
validate);
121 BOOST_CHECK_EXCEPTION(lexical_cast<T>(
122 std::string(value)),
const char*,
validate);
123 BOOST_CHECK_EXCEPTION(lexical_cast<T>(
124 std::string_view(value)),
const char*,
validate);
129 result =
"specialized - To bool - From string";
131 const char* value =
"test";
132 BOOST_CHECK_EXCEPTION(lexical_cast<bool>(
134 BOOST_CHECK_EXCEPTION(lexical_cast<bool>(
135 const_cast<char*
>(value)),
const char*,
validate);
136 BOOST_CHECK_EXCEPTION(lexical_cast<bool>(
137 std::string(value)),
const char*,
validate);
138 BOOST_CHECK_EXCEPTION(lexical_cast<bool>(
139 std::string_view(value)),
const char*,
validate);
147 BOOST_CHECK_EQUAL(lexical_cast<std::string>(
true),
"1");
148 BOOST_CHECK_EQUAL(lexical_cast<std::string>(
false),
"0");
150 BOOST_CHECK_EQUAL(lexical_cast<std::string>(1),
"1");
151 BOOST_CHECK_EQUAL(lexical_cast<std::string>(1u),
"1");
153 BOOST_CHECK_EQUAL(lexical_cast<std::string>(1.2f),
"1.2");
154 BOOST_CHECK_EQUAL(lexical_cast<std::string>(1.2),
"1.2");
156 BOOST_CHECK_EQUAL(lexical_cast<int>(
"1"), 1);
157 BOOST_CHECK_EQUAL(lexical_cast<int>(
"-1"), -1);
158 BOOST_CHECK_EQUAL(lexical_cast<unsigned>(
"1"), 1);
159 BOOST_CHECK_EQUAL(lexical_cast<double>(
"1.2"), 1.2);
162 BOOST_CHECK_EQUAL(lexical_cast_default<int>(
"80%"), 80);
164 BOOST_CHECK_EQUAL(lexical_cast<double>(
"0x11"), 0);
166 std::string a =
"01234567890123456789";
167 BOOST_CHECK_EQUAL(lexical_cast<long long>(a), 1234567890123456789ll);
169 BOOST_CHECK_EQUAL(lexical_cast<double>(a), 1.23456789012345678e18);
170 BOOST_CHECK_EQUAL(lexical_cast_default<long long>(a, 0ll), 1234567890123456789ll);
171 BOOST_CHECK_EQUAL(lexical_cast_default<int>(a, 0), 0);
172 BOOST_CHECK_EQUAL(lexical_cast_default<double>(a, 0.0), 1.23456789012345678e18);
174 std::string
b =
"99999999999999999999";
177 BOOST_CHECK_EQUAL(lexical_cast<double>(
b), 1e20);
178 BOOST_CHECK_EQUAL(lexical_cast_default<long long>(
b, 0ll), 0ll);
179 BOOST_CHECK_EQUAL(lexical_cast_default<int>(
b, 0), 0);
180 BOOST_CHECK_EQUAL(lexical_cast_default<double>(
b, 0.0), 1e20);
static void validate(boost::any &v, const std::vector< std::string > &values, two_strings *, int)
New lexcical_cast header.
Standard logging facilities (interface).
std::tuple< char, signed char, unsigned char, short, int, long, long long, unsigned short, unsigned int, unsigned long, unsigned long long > test_integral_types
BOOST_AUTO_TEST_CASE(test_lexical_cast_bool)
decltype(std::tuple_cat(test_bool_types{}, test_integral_types{})) test_match_types
decltype(std::tuple_cat(test_integral_types{}, test_floating_point_types{})) test_arethmetic_types
std::tuple< float, double, long double > test_floating_point_types
decltype(std::tuple_cat(test_floating_point_types{})) test_nomatch_types
decltype(std::tuple_cat(test_nomatch_types{}, test_match_types{})) test_types
std::tuple< bool > test_bool_types
BOOST_AUTO_TEST_CASE_TEMPLATE(test_lexical_cast_throw, T, test_types)
Thrown when a lexical_cast fails.
#define TEST_CASE(type_send)
BOOST_AUTO_TEST_CASE(test_lexical_cast_result)