15 #define GETTEXT_DOMAIN "wesnoth-test"
17 #include <boost/test/unit_test.hpp>
61 foo::enumname
e = foo::enumname::string_to_enum(
"name2", foo::enumname::con1);
63 BOOST_CHECK_EQUAL ( e, foo::enumname::con2 );
65 std::string str = foo::enumname::enum_to_string(foo::enumname::con1);
67 BOOST_CHECK_EQUAL ( str,
"name1" );
71 BOOST_CHECK_EQUAL ( str2,
"name2" );
73 bool threw_exception_when_it_wasnt_supposed_to =
false;
79 threw_exception_when_it_wasnt_supposed_to =
true;
82 BOOST_CHECK( !threw_exception_when_it_wasnt_supposed_to );
84 bool threw_exception_when_it_was_supposed_to =
false;
90 threw_exception_when_it_was_supposed_to =
true;
93 BOOST_CHECK( threw_exception_when_it_was_supposed_to );
97 BOOST_CHECK_EQUAL (ss.str(),
"name3");
102 bar::another
e = bar::another::string_to_enum(
"name2", bar::another::val1);
104 BOOST_CHECK_EQUAL ( e, bar::another::val2 );
106 std::string str = bar::another::enum_to_string(bar::another::val1);
108 BOOST_CHECK_EQUAL ( str,
"name1" );
112 BOOST_CHECK_EQUAL ( str2,
"name2" );
114 bool threw_exception_when_it_wasnt_supposed_to =
false;
120 threw_exception_when_it_wasnt_supposed_to =
true;
123 BOOST_CHECK( !threw_exception_when_it_wasnt_supposed_to );
125 bool threw_exception_when_it_was_supposed_to =
false;
131 threw_exception_when_it_was_supposed_to =
true;
134 BOOST_CHECK( threw_exception_when_it_was_supposed_to );
136 std::stringstream ss;
138 BOOST_CHECK_EQUAL (ss.str(),
"name3");
144 foo::enumname e1 = foo::enumname::con1;
145 foo::enumname e2 = foo::enumname::con2;
146 foo::enumname e3 = foo::enumname::con3;
149 cfg[
"t2"] = foo::enumname::enum_to_string(e2);
151 cfg[
"t4"] =
"345646";
153 BOOST_CHECK_EQUAL(cfg[
"t1"].to_enum<foo::enumname>(foo::enumname::con1) , e2);
154 BOOST_CHECK_EQUAL(cfg[
"t2"].to_enum<foo::enumname>(foo::enumname::con1) , e2);
155 BOOST_CHECK_EQUAL(cfg[
"t3"].to_enum<foo::enumname>(foo::enumname::con1) , e2);
157 BOOST_CHECK_EQUAL(cfg[
"t1"].to_enum(e1) , e2);
158 BOOST_CHECK_EQUAL(cfg[
"t2"].to_enum(e1) , e2);
159 BOOST_CHECK_EQUAL(cfg[
"t3"].to_enum(e1) , e2);
162 BOOST_CHECK_EQUAL(cfg[
"t4"].to_enum<foo::enumname>(foo::enumname::con3) , e3);
164 BOOST_CHECK_EQUAL(cfg[
"t1"].str() ,
"name2");
171 foo::enumname e1 = foo::enumname::con1;
172 foo::enumname e2 = foo::enumname::con2;
173 foo::enumname e3 = foo::enumname::con3;
176 cfg[
"t2"] = foo::enumname::enum_to_string(e1);
177 cfg[
"t3"] = e1.to_string();
179 cfg[
"t5"] =
"345646";
181 foo::enumname dummy = foo::enumname::con1;
183 BOOST_CHECK_EQUAL(dummy, e1);
184 BOOST_CHECK_EQUAL(dummy.parse(
"name1"),
true);
185 BOOST_CHECK_EQUAL(dummy, e1);
186 BOOST_CHECK_EQUAL(dummy.parse(
"name2"),
true);
187 BOOST_CHECK_EQUAL(dummy, e2);
188 BOOST_CHECK_EQUAL(dummy.parse(
"name3"),
true);
189 BOOST_CHECK_EQUAL(dummy, e3);
190 BOOST_CHECK_EQUAL(dummy.parse(
"name2 "),
false);
191 BOOST_CHECK_EQUAL(dummy, e3);
192 BOOST_CHECK_EQUAL(dummy.parse(
"kdfg89"),
false);
193 BOOST_CHECK_EQUAL(dummy, e3);
194 BOOST_CHECK_EQUAL(dummy.parse(
"NAME2"),
false);
195 BOOST_CHECK_EQUAL(dummy, e3);
196 BOOST_CHECK_EQUAL(dummy.parse(
""),
false);
197 BOOST_CHECK_EQUAL(dummy, e3);
198 BOOST_CHECK_EQUAL(dummy.parse(
"name2"),
true);
199 BOOST_CHECK_EQUAL(dummy, e2);
207 BOOST_AUTO_TEST_SUITE_END()
#define MAKE_ENUM(NAME, CONTENT)
BOOST_AUTO_TEST_SUITE(test_map_location)
To lexical_cast(From value)
Lexical cast converts one type to another.
Definitions for the interface to Wesnoth Markup Language (WML).
BOOST_AUTO_TEST_CASE(test_make_enum_namespace)
Tests begin.
Templates and utility-routines for strings and numbers.
GLuint const GLchar * name
A config object defines a single node in a WML file, with access to child nodes.
Thrown when a lexical_cast fails.
Defines the MAKE_ENUM macro.
GLsizei const GLcharARB ** string