15 #define GETTEXT_DOMAIN "wesnoth-test"
19 #include <boost/test/unit_test.hpp>
21 #include <boost/mpl/vector.hpp>
22 #include <boost/mpl/copy.hpp>
23 #include <boost/mpl/back_inserter.hpp>
24 #include <boost/mpl/contains.hpp>
25 #include <boost/test/test_case_template.hpp>
33 #pragma warning(disable:4702)
36 #define LEXICAL_CAST_DEBUG
43 typedef boost::mpl::vector<
53 char,
signed char,
unsigned char,
54 short,
int, long,
long long,
55 unsigned short,
unsigned int,
unsigned long,
unsigned long long
58 typedef boost::mpl::vector<
59 float, double,
long double
62 typedef boost::mpl::copy<
64 boost::mpl::back_inserter<test_match_types>
75 std::cerr <<
"Received " << str <<
'\n'
76 <<
"Expected " << result <<
'\n';
85 #define TEST_CASE(type_send, initializer) \
87 type_send val = initializer value; \
89 BOOST_CHECK_EXCEPTION( \
90 lexical_cast<std::string>(val), const char*, validate); \
101 ?
"specialized - To std::string - From integral (pointer)"
119 typedef boost::mpl::vector<
126 test_lexical_cast_signed, T, test_lexical_cast_signed_types)
128 result =
"specialized - To signed - From (const) char*";
130 const char* value =
"test";
131 BOOST_CHECK_EXCEPTION(lexical_cast<T>(
133 BOOST_CHECK_EXCEPTION(lexical_cast<T>(
134 const_cast<char*>(value)),
const char*,
validate);
136 result =
"specialized - To signed - From std::string";
138 BOOST_CHECK_EXCEPTION(lexical_cast<T>(
144 result =
"specialized - To long long - From (const) char*";
146 const char* value =
"test";
147 BOOST_CHECK_EXCEPTION(lexical_cast<long long>(
149 BOOST_CHECK_EXCEPTION(lexical_cast<long long>(
150 const_cast<char*>(value)),
const char*,
validate);
152 result =
"specialized - To long long - From std::string";
154 BOOST_CHECK_EXCEPTION(lexical_cast<long long>(
158 typedef boost::mpl::vector<
166 test_lexical_cast_unsigned, T, test_lexical_cast_unsigned_types)
168 result =
"specialized - To unsigned - From (const) char*";
170 const char* value =
"test";
171 BOOST_CHECK_EXCEPTION(lexical_cast<T>(
173 BOOST_CHECK_EXCEPTION(lexical_cast<T>(
174 const_cast<char*>(value)),
const char*,
validate);
176 result =
"specialized - To unsigned - From std::string";
178 BOOST_CHECK_EXCEPTION(lexical_cast<T>(
185 result =
"specialized - To unsigned long long - From (const) char*";
187 const char* value =
"test";
188 BOOST_CHECK_EXCEPTION(lexical_cast<unsigned long long>(
190 BOOST_CHECK_EXCEPTION(lexical_cast<unsigned long long>(
191 const_cast<char*>(value)),
const char*,
validate);
193 result =
"specialized - To unsigned long long - From std::string";
195 BOOST_CHECK_EXCEPTION(lexical_cast<unsigned long long>(
203 BOOST_CHECK_EQUAL(lexical_cast<std::string>(
true),
"1");
204 BOOST_CHECK_EQUAL(lexical_cast<std::string>(
false),
"0");
206 BOOST_CHECK_EQUAL(lexical_cast<std::string>(1),
"1");
207 BOOST_CHECK_EQUAL(lexical_cast<std::string>(1u),
"1");
209 BOOST_CHECK_EQUAL(lexical_cast<std::string>(1.2
f),
"1.2");
210 BOOST_CHECK_EQUAL(lexical_cast<std::string>(1.2),
"1.2");
212 BOOST_CHECK_EQUAL(lexical_cast<int>(
"1"), 1);
213 BOOST_CHECK_EQUAL(lexical_cast<int>(
"-1"), -1);
214 BOOST_CHECK_EQUAL(lexical_cast<unsigned>(
"1"), 1);
BOOST_AUTO_TEST_CASE(test_lexical_cast_long_long)
GLuint GLuint GLsizei GLenum type
BOOST_AUTO_TEST_CASE_TEMPLATE(test_lexical_cast_throw, T, test_types)
New lexcical_cast header.
BOOST_AUTO_TEST_CASE(test_lexical_cast_result)
GLsizei const GLfloat * value
#define TEST_CASE(type_send, initializer)
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
boost::mpl::vector< signed char, short, int, long > test_lexical_cast_signed_types
boost::mpl::vector< bool, unsigned char, unsigned short, unsigned int, unsigned long > test_lexical_cast_unsigned_types
static void validate(boost::any &v, const std::vector< std::string > &values, two_strings *, int)
boost::mpl::vector< float, double, long double > test_nomatch_types
boost::mpl::copy< test_nomatch_types, boost::mpl::back_inserter< test_match_types > >::type test_types
static const char * match(MatchState *ms, const char *s, const char *p)
boost::mpl::vector< bool, char, signed char, unsigned char, short, int, long, long long, unsigned short, unsigned int, unsigned long, unsigned long long > test_match_types
GLsizei const GLcharARB ** string