Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "unit.hpp"
00021 #include <rtt-fwd.hpp>
00022 #include <internal/DataSources.hpp>
00023 #include <os/fosi.h>
00024 #include <boost/lambda/lambda.hpp>
00025
00026 #include "datasource_fixture.hpp"
00027 #include "marsh/PropertyBagIntrospector.hpp"
00028 #include "types/EnumTypeInfo.hpp"
00029 #include "marsh/PropertyLoader.hpp"
00030 #include "TaskContext.hpp"
00031
00032 using namespace boost::lambda;
00033
00034 typedef enum
00035 {
00036 A, B, C
00037 } TheEnum;
00038
00039 class EnumTypeTest
00040 {
00041 public:
00042 TheEnum enum1;
00043 TheEnum enum2;
00044
00045 AssignableDataSource<TheEnum>::shared_ptr a;
00046 AssignableDataSource<TheEnum>::shared_ptr b;
00047 TypeInfo* ti;
00048 TypeInfo* ts;
00049
00050 EnumTypeTest()
00051 {
00052
00053 a = new ValueDataSource<TheEnum>( A );
00054 b = new ValueDataSource<TheEnum>( B );
00055
00056 Types()->addType( new EnumTypeInfo<TheEnum>("TheEnum") );
00057 }
00058 ~EnumTypeTest()
00059 {
00060 }
00061 };
00062
00063
00064
00065 BOOST_FIXTURE_TEST_SUITE( EnumTypeTestSuite, EnumTypeTest )
00066
00067
00068 BOOST_AUTO_TEST_CASE( testEnumIntConversion )
00069 {
00070
00071 BOOST_REQUIRE( Types()->type("TheEnum") );
00072 BOOST_REQUIRE( Types()->type("int") );
00073
00074
00075 BOOST_CHECK( Types()->type("int")->convert( a ) );
00076 BOOST_CHECK( Types()->type("int")->convert( b ) );
00077
00078
00079 BOOST_CHECK( Types()->type("TheEnum")->convert( Types()->type("int")->convert(a) ) );
00080 BOOST_CHECK( Types()->type("TheEnum")->convert( Types()->type("int")->convert(b) ) );
00081
00082
00083 PropertyBag result;
00084 Property<TheEnum> pa("a","", a );
00085 Property<TheEnum> pb("a","", b );
00086 PropertyBagIntrospector pbi(result);
00087 pbi.introspect( &pa);
00088 BOOST_REQUIRE_EQUAL( result.size(), 1);
00089 BOOST_CHECK( result.getItem(0)->getTypeInfo() == Types()->type("int") );
00090 DataSource<int>::shared_ptr dint = DataSource<int>::narrow( result.getItem(0)->getDataSource().get() );
00091 BOOST_CHECK_EQUAL(dint->get(), (int)A );
00092
00093 pbi.introspect( &pb);
00094 BOOST_REQUIRE_EQUAL( result.size(), 2);
00095 BOOST_CHECK( result.getItem(1)->getTypeInfo() == Types()->type("int") );
00096 dint = DataSource<int>::narrow( result.getItem(1)->getDataSource().get() );
00097 BOOST_REQUIRE( dint );
00098 BOOST_CHECK_EQUAL(dint->get(), (int)B );
00099 }
00100
00101
00102
00103 BOOST_AUTO_TEST_CASE( testEnumSaveIntProperties )
00104 {
00105 TaskContext tc("TC");
00106 PropertyLoader pl(&tc);
00107 enum1 = A;
00108 enum2 = B;
00109 tc.addProperty("enum1", enum1 );
00110 tc.addProperty("enum2", enum2 );
00111
00112
00113 BOOST_CHECK( pl.save("enum_type_test_int_save.cpf", true) );
00114
00115 enum1 = B;
00116 enum2 = A;
00117
00118
00119 BOOST_CHECK( pl.load("enum_type_test_int_save.cpf") );
00120
00121 BOOST_CHECK_EQUAL( enum1, A);
00122 BOOST_CHECK_EQUAL( enum2, B);
00123 }
00124
00125 BOOST_AUTO_TEST_SUITE_END()
00126