Extended unit test.
This commit is contained in:
@@ -6,13 +6,39 @@
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
|
||||
enum Value {
|
||||
One = 1,
|
||||
Two,
|
||||
Three
|
||||
};
|
||||
|
||||
namespace string2type {
|
||||
|
||||
template <>
|
||||
Value convert<Value>(const std::string &value) {
|
||||
if (value == "One") {
|
||||
return One;
|
||||
} else if (value == "Two") {
|
||||
return Two;
|
||||
} else if (value == "Three") {
|
||||
return Three;
|
||||
} else {
|
||||
throw std::invalid_argument("unknown string");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct test : attributes {
|
||||
test() : x(0) {
|
||||
test() : x(0), y(One) {
|
||||
REGISTER_ATTRIBUTE(int, x);
|
||||
REGISTER_ATTRIBUTE(Value, y);
|
||||
}
|
||||
|
||||
int x;
|
||||
Value y;
|
||||
};
|
||||
|
||||
struct test_fixture {
|
||||
@@ -44,6 +70,17 @@ BOOST_AUTO_TEST_CASE( test2 )
|
||||
BOOST_CHECK( object.x == 0 );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( test3 )
|
||||
{
|
||||
BOOST_CHECK( object.y == One );
|
||||
|
||||
object.set_attribute("y", "Two");
|
||||
|
||||
BOOST_CHECK( object.y == Two );
|
||||
|
||||
BOOST_CHECK_THROW(object.set_attribute("y", "xxx"), std::invalid_argument);
|
||||
}
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
Reference in New Issue
Block a user