From 5fabf4b9b5ac1915b6f121822b48a58e49f35083 Mon Sep 17 00:00:00 2001 From: Jens Luedicke Date: Sun, 23 Jan 2011 00:18:58 +0100 Subject: [PATCH] Extended unit test. --- unittest/AttributesTest.cpp | 39 ++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/unittest/AttributesTest.cpp b/unittest/AttributesTest.cpp index d8296ba..3cf5beb 100644 --- a/unittest/AttributesTest.cpp +++ b/unittest/AttributesTest.cpp @@ -6,13 +6,39 @@ #include #include +#include + +enum Value { + One = 1, + Two, + Three +}; + +namespace string2type { + +template <> +Value convert(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()